packagequotes = 1;
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) {
lineno = l->n->lineno;
int peekc;
int peekc1; // second peekc for ...
char* cp; // used for content when bin==nil
+ int importsafe;
};
typedef struct Dlist Dlist;
cannedimports("runtime.builtin", "package runtime\n\n$$\n\n");
else
cannedimports("runtime.builtin", runtimeimport);
+ curio.importsafe = 1;
}
import_package
import_there
}
import_package:
- LPACKAGE sym ';'
+ LPACKAGE sym import_safety ';'
{
importpkg->name = $2->name;
importpkg->direct = 1;
+
+ if(safemode && !curio.importsafe)
+ yyerror("cannot import unsafe package %Z", importpkg->path);
// NOTE(rsc): This is no longer a technical restriction:
// the 6g tool chain would work just fine without giving
yyerror("cannot import package main");
}
+import_safety:
+| LNAME
+ {
+ if(strcmp($1->name, "safe") == 0)
+ curio.importsafe = 1;
+ }
+
import_there:
{
defercheckwidth();
curio.infile = file;
curio.cp = cp;
curio.nlsemi = 0;
+ curio.importsafe = 0;
typecheckok = 1;
incannedimport = 1;
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");
evconst(n);