diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 4f7c5db34e..d73311fff5 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -237,14 +237,13 @@ import_package: importpkg->name = $2->name; importpkg->direct = 1; - // PGNS: fixme + // NOTE(rsc): This is no longer a technical restriction: + // the 6g tool chain would work just fine without giving + // special meaning to a package being named main. + // Other implementations might need the restriction + // (gccgo does), so it stays in the language and the compiler. if(strcmp($2->name, "main") == 0) yyerror("cannot import package main"); - - // PGNS: This should go away once we get - // rid of the global package name space. - if(localpkg->name && strcmp($2->name, localpkg->name) == 0 && !compiling_runtime) - yyerror("package cannot import itself"); } import_there: diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index bf86df5b82..7e2896822e 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -285,9 +285,7 @@ importfile(Val *f, int line) Strlit *path; char cleanbuf[1024]; - // TODO(rsc): don't bother reloading imports more than once - - // PGNS: canonicalize import path for ./ imports in findpkg. + // TODO(rsc): don't bother reloading imports more than once? if(f->ctype != CTSTR) { yyerror("import statement not a string"); diff --git a/src/cmd/ld/go.c b/src/cmd/ld/go.c index 1797f34d30..4385e463ff 100644 --- a/src/cmd/ld/go.c +++ b/src/cmd/ld/go.c @@ -73,7 +73,7 @@ static int parsepkgdata(char*, char*, char**, char*, char**, char**, char**); void ldpkg(Biobuf *f, char *pkg, int64 len, char *filename) { - char *data, *p0, *p1; + char *data, *p0, *p1, *name; if(debug['g']) return; @@ -111,10 +111,18 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename) return; } p0 += 8; - while(*p0 == ' ' || *p0 == '\t' || *p0 == '\n') + while(p0 < p1 && *p0 == ' ' || *p0 == '\t' || *p0 == '\n') p0++; - while(*p0 != ' ' && *p0 != '\t' && *p0 != '\n') + name = p0; + while(p0 < p1 && *p0 != ' ' && *p0 != '\t' && *p0 != '\n') p0++; + if(p0 < p1) { + *p0++ = '\0'; + if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0) + fprint(2, "%s: %s: not package main (package %s)\n", argv0, filename, name); + else if(strcmp(pkg, "main") != 0 && strcmp(name, "main") == 0) + fprint(2, "%s: %s: importing %s, found package main", argv0, filename, pkg); + } loadpkgdata(filename, pkg, p0, p1 - p0); } @@ -131,7 +139,6 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename) return; } - // PGNS: Should be using import path, not pkg. loadpkgdata(filename, pkg, p0, p1 - p0); // look for dynld section