diff options
author | alandonovan <adonovan@google.com> | 2020-11-18 13:34:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 13:34:35 -0500 |
commit | e55f603d8c797b182566012861c5784481d00df4 (patch) | |
tree | a86fd908868514e8c1301fec696d4838fc30ee67 | |
parent | a5c0cc49931aeca4ff5eedc21ba1c2d1b37ae780 (diff) | |
download | starlark-go-e55f603d8c797b182566012861c5784481d00df4.tar.gz |
starlark: use portable syscall wrapper for mmap (#321)
Also, add test to ensure that new dependencies (such as golang.org/x/sys/unix)
are not added casually.
Fixes #320
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | starlark/eval_test.go | 23 | ||||
-rw-r--r-- | starlark/int_posix64.go | 14 |
3 files changed, 27 insertions, 12 deletions
@@ -6,5 +6,5 @@ require ( github.com/chzyer/logex v1.1.10 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect - golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect + golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 ) diff --git a/starlark/eval_test.go b/starlark/eval_test.go index 703f09b..3725d17 100644 --- a/starlark/eval_test.go +++ b/starlark/eval_test.go @@ -8,6 +8,7 @@ import ( "bytes" "fmt" "math" + "os/exec" "path/filepath" "sort" "strings" @@ -891,3 +892,25 @@ func TestExecutionSteps(t *testing.T) { t.Errorf("execution returned error %q, want cancellation", err) } } + +// TestDeps fails if the interpreter proper (not the REPL, etc) sprouts new external dependencies. +// We may expand the list of permitted dependencies, but should do so deliberately, not casually. +func TestDeps(t *testing.T) { + cmd := exec.Command("go", "list", "-deps") + out, err := cmd.Output() + if err != nil { + t.Skipf("'go list' failed: %s", err) + } + for _, pkg := range strings.Split(string(out), "\n") { + // Does pkg have form "domain.name/dir"? + slash := strings.IndexByte(pkg, '/') + dot := strings.IndexByte(pkg, '.') + if 0 < dot && dot < slash { + if strings.HasPrefix(pkg, "go.starlark.net/") || + strings.HasPrefix(pkg, "golang.org/x/sys/") { + continue // permitted dependencies + } + t.Errorf("new interpreter dependency: %s", pkg) + } + } +} diff --git a/starlark/int_posix64.go b/starlark/int_posix64.go index 19db123..1f13d66 100644 --- a/starlark/int_posix64.go +++ b/starlark/int_posix64.go @@ -22,9 +22,9 @@ import ( "log" "math" "math/big" - "runtime" - "syscall" "unsafe" + + "golang.org/x/sys/unix" ) // intImpl represents a union of (int32, *big.Int) in a single pointer, @@ -59,15 +59,7 @@ func makeBigInt(x *big.Int) Int { return Int{intImpl(x)} } var smallints = reserveAddresses(1 << 32) func reserveAddresses(len int) uintptr { - // Use syscall to avoid golang.org/x/sys/unix dependency. - MAP_ANON := 0x1000 // darwin (and all BSDs) - switch runtime.GOOS { - case "linux", "android": - MAP_ANON = 0x20 - case "solaris": - MAP_ANON = 0x100 - } - b, err := syscall.Mmap(-1, 0, len, syscall.PROT_READ, syscall.MAP_PRIVATE|MAP_ANON) + b, err := unix.Mmap(-1, 0, len, unix.PROT_READ, unix.MAP_PRIVATE|unix.MAP_ANON) if err != nil { log.Fatalf("mmap: %v", err) } |