]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: accept old and new import format for builtin declarations
authorRobert Griesemer <gri@golang.org>
Wed, 20 Apr 2016 23:41:43 +0000 (16:41 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 21 Apr 2016 00:10:08 +0000 (00:10 +0000)
Test with forceNewExport set to true (but continues to be disabled by
default for now).

Fixes #15322.

Change-Id: I3b893db2206cbb79e66339284f22f4a0b20bf137
Reviewed-on: https://go-review.googlesource.com/22328
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/main.go

index 2afd262fedda8301156771c281853c6a5e11dddb..f6de58462ecd1939c39c1f66a2d8afbc75cbfa7f 100644 (file)
@@ -643,11 +643,24 @@ func loadsys() {
        iota_ = -1000000
        incannedimport = 1
 
-       importpkg = Runtimepkg
-       parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil)
-
-       importpkg = unsafepkg
-       parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil)
+       // The first byte in the binary export format is a 'c' or 'd'
+       // specifying the encoding format. We could just check that
+       // byte, but this is a perhaps more robust. Also, it is not
+       // speed-critical.
+       // TODO(gri) simplify once textual export format has gone
+       if strings.HasPrefix(runtimeimport, "package") {
+               // textual export format
+               importpkg = Runtimepkg
+               parse_import(bufio.NewReader(strings.NewReader(runtimeimport)), nil)
+               importpkg = unsafepkg
+               parse_import(bufio.NewReader(strings.NewReader(unsafeimport)), nil)
+       } else {
+               // binary export format
+               importpkg = Runtimepkg
+               Import(bufio.NewReader(strings.NewReader(runtimeimport)))
+               importpkg = unsafepkg
+               Import(bufio.NewReader(strings.NewReader(unsafeimport)))
+       }
 
        importpkg = nil
        incannedimport = 0