Skip to content

Commit

Permalink
cmd/compile: read safemode bit from package header
Browse files Browse the repository at this point in the history
Ignore respective bit in export data, but leave the info to
minimize format changes for 1.7. Scheduled to remove by 1.8.

For #15772.

Change-Id: Ifb3beea655367308a4e2d5dc8cb625915f904287
Reviewed-on: https://go-review.googlesource.com/23285
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
griesemer committed May 20, 2016
1 parent cc0d8c8 commit 054a721
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/cmd/compile/internal/gc/bimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func Import(in *bufio.Reader) {
// --- compiler-specific export data ---

// read compiler-specific flags
importpkg.Safe = p.bool()

// read but ignore safemode bit (see issue #15772)
p.bool() // formerly: importpkg.Safe = p.bool()

// phase 2
objcount = 0
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/compile/internal/gc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,21 @@ func importfile(f *Val, indent []byte) {
}
}

// process header lines
for {
p, err = imp.ReadString('\n')
if err != nil {
log.Fatalf("reading input: %v", err)
}
if p == "\n" {
break // header ends with blank line
}
if strings.HasPrefix(p, "safe") {
importpkg.Safe = true
break // ok to ignore rest
}
}

// assume files move (get installed)
// so don't record the full path.
linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
Expand Down
6 changes: 1 addition & 5 deletions src/cmd/compile/internal/gc/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,8 @@ func (p *parser) import_package() {
p.import_error()
}

importsafe := false
// read but skip "safe" bit (see issue #15772)
if p.tok == LNAME {
if p.sym_.Name == "safe" {
importsafe = true
}
p.next()
}
p.want(';')
Expand All @@ -413,7 +410,6 @@ func (p *parser) import_package() {
} else if importpkg.Name != name {
Yyerror("conflicting names %s and %s for package %q", importpkg.Name, name, importpkg.Path)
}
importpkg.Safe = importsafe

typecheckok = true
defercheckwidth()
Expand Down

0 comments on commit 054a721

Please sign in to comment.