mirror of
https://github.com/golang/go
synced 2024-11-22 01:04:40 -07:00
gc: change -u to require imports to be marked safe
R=ken2 CC=golang-dev https://golang.org/cl/1597043
This commit is contained in:
parent
fe43325b30
commit
d20ad1c75a
@ -268,7 +268,10 @@ dumpexport(void)
|
|||||||
packagequotes = 1;
|
packagequotes = 1;
|
||||||
Bprint(bout, "\n$$ // exports\n");
|
Bprint(bout, "\n$$ // exports\n");
|
||||||
|
|
||||||
Bprint(bout, " package %s\n", localpkg->name);
|
Bprint(bout, " package %s", localpkg->name);
|
||||||
|
if(safemode)
|
||||||
|
Bprint(bout, " safe");
|
||||||
|
Bprint(bout, "\n");
|
||||||
|
|
||||||
for(l=exportlist; l; l=l->next) {
|
for(l=exportlist; l; l=l->next) {
|
||||||
lineno = l->n->lineno;
|
lineno = l->n->lineno;
|
||||||
|
@ -578,6 +578,7 @@ struct Io
|
|||||||
int peekc;
|
int peekc;
|
||||||
int peekc1; // second peekc for ...
|
int peekc1; // second peekc for ...
|
||||||
char* cp; // used for content when bin==nil
|
char* cp; // used for content when bin==nil
|
||||||
|
int importsafe;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Dlist Dlist;
|
typedef struct Dlist Dlist;
|
||||||
|
@ -152,6 +152,7 @@ loadsys:
|
|||||||
cannedimports("runtime.builtin", "package runtime\n\n$$\n\n");
|
cannedimports("runtime.builtin", "package runtime\n\n$$\n\n");
|
||||||
else
|
else
|
||||||
cannedimports("runtime.builtin", runtimeimport);
|
cannedimports("runtime.builtin", runtimeimport);
|
||||||
|
curio.importsafe = 1;
|
||||||
}
|
}
|
||||||
import_package
|
import_package
|
||||||
import_there
|
import_there
|
||||||
@ -236,11 +237,14 @@ import_here:
|
|||||||
}
|
}
|
||||||
|
|
||||||
import_package:
|
import_package:
|
||||||
LPACKAGE sym ';'
|
LPACKAGE sym import_safety ';'
|
||||||
{
|
{
|
||||||
importpkg->name = $2->name;
|
importpkg->name = $2->name;
|
||||||
importpkg->direct = 1;
|
importpkg->direct = 1;
|
||||||
|
|
||||||
|
if(safemode && !curio.importsafe)
|
||||||
|
yyerror("cannot import unsafe package %Z", importpkg->path);
|
||||||
|
|
||||||
// NOTE(rsc): This is no longer a technical restriction:
|
// NOTE(rsc): This is no longer a technical restriction:
|
||||||
// the 6g tool chain would work just fine without giving
|
// the 6g tool chain would work just fine without giving
|
||||||
// special meaning to a package being named main.
|
// special meaning to a package being named main.
|
||||||
@ -250,6 +254,13 @@ import_package:
|
|||||||
yyerror("cannot import package main");
|
yyerror("cannot import package main");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import_safety:
|
||||||
|
| LNAME
|
||||||
|
{
|
||||||
|
if(strcmp($1->name, "safe") == 0)
|
||||||
|
curio.importsafe = 1;
|
||||||
|
}
|
||||||
|
|
||||||
import_there:
|
import_there:
|
||||||
{
|
{
|
||||||
defercheckwidth();
|
defercheckwidth();
|
||||||
|
@ -442,6 +442,7 @@ cannedimports(char *file, char *cp)
|
|||||||
curio.infile = file;
|
curio.infile = file;
|
||||||
curio.cp = cp;
|
curio.cp = cp;
|
||||||
curio.nlsemi = 0;
|
curio.nlsemi = 0;
|
||||||
|
curio.importsafe = 0;
|
||||||
|
|
||||||
typecheckok = 1;
|
typecheckok = 1;
|
||||||
incannedimport = 1;
|
incannedimport = 1;
|
||||||
|
@ -1191,7 +1191,10 @@ ret:
|
|||||||
checkwidth(t);
|
checkwidth(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(safemode && isptrto(t, TANY))
|
|
||||||
|
// TODO(rsc): should not need to check importpkg,
|
||||||
|
// but reflect mentions unsafe.Pointer.
|
||||||
|
if(safemode && !incannedimport && !importpkg && isptrto(t, TANY))
|
||||||
yyerror("cannot use unsafe.Pointer");
|
yyerror("cannot use unsafe.Pointer");
|
||||||
|
|
||||||
evconst(n);
|
evconst(n);
|
||||||
|
Loading…
Reference in New Issue
Block a user