return isupperrune(r);
}
+static int
+initname(char *s)
+{
+ return strcmp(s, "init") == 0;
+}
+
void
autoexport(Node *n, int ctxt)
{
return;
if(n->ntype && n->ntype->op == OTFUNC && n->ntype->left) // method
return;
- if(exportname(n->sym->name) || strcmp(n->sym->name, "init") == 0)
+ if(exportname(n->sym->name) || initname(n->sym->name))
exportsym(n);
else
packagesym(n);
// mark the symbol so it is not reexported
if(s->def == N) {
- if(exportname(s->name))
+ if(exportname(s->name) || initname(s->name))
s->flags |= SymExport;
else
s->flags |= SymPackage; // package scope
{
Node *n;
- if(!exportname(s->name) && !mypackage(s))
+ if(!exportname(s->name) && !initname(s->name) && !mypackage(s))
return;
importsym(s, ONAME);
/*
* hand-craft the following initialization code
- * var initdone·<file> uint8 (1)
- * func Init·<file>() (2)
- * if initdone·<file> != 0 { (3)
- * if initdone·<file> == 2 (4)
+ * var initdone· uint8 (1)
+ * func init() (2)
+ * if initdone· != 0 { (3)
+ * if initdone· == 2 (4)
* return
* throw(); (5)
* }
- * initdone.<file> = 1; (6)
+ * initdone· = 1; (6)
* // over all matching imported symbols
- * <pkg>.init·<file>() (7)
+ * <pkg>.init() (7)
* { <init stmts> } (8)
- * init·<file>() // if any (9)
- * initdone.<file> = 2; (10)
+ * init·<n>() // if any (9)
+ * initdone· = 2; (10)
* return (11)
* }
*/
// are there any imported init functions
for(h=0; h<NHASH; h++)
for(s = hash[h]; s != S; s = s->link) {
- if(s->name[0] != 'I' || strncmp(s->name, "Init·", 6) != 0)
+ if(s->name[0] != 'i' || strcmp(s->name, "init") != 0)
continue;
if(s->def == N)
continue;
// (2)
maxarg = 0;
- snprint(namebuf, sizeof(namebuf), "Init·");
-
- // this is a botch since we need a known name to
- // call the top level init function out of rt0
- if(strcmp(localpkg->name, "main") == 0)
- snprint(namebuf, sizeof(namebuf), "init");
+ snprint(namebuf, sizeof(namebuf), "init");
fn = nod(ODCLFUNC, N, N);
initsym = lookup(namebuf);
// (7)
for(h=0; h<NHASH; h++)
for(s = hash[h]; s != S; s = s->link) {
- if(s->name[0] != 'I' || strncmp(s->name, "Init·", 6) != 0)
+ if(s->name[0] != 'i' || strcmp(s->name, "init") != 0)
continue;
if(s->def == N)
continue;
--- /dev/null
+// errchk $G -e $D/$F.go
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "runtime"
+
+func init() {
+}
+
+func main() {
+ init() // ERROR "undefined: init"
+ runtime.init() // ERROR "unexported.*runtime\.init"
+ var _ = init // ERROR "undefined: init"
+}