From 99b6e9f73b2b6a9e4d415064a271bfe579b8b66c Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Tue, 18 Sep 2012 23:42:18 +0400 Subject: [PATCH] race: cmd/cgo changes This is a part of a bigger change that adds data race detection feature: https://golang.org/cl/6456044 This change breaks circular dependency between runtime/race and syscall packages. R=rsc CC=golang-dev https://golang.org/cl/6498079 --- src/cmd/cgo/main.go | 1 + src/cmd/cgo/out.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 05389bb6968..892b1198f56 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -147,6 +147,7 @@ var gccgo = flag.Bool("gccgo", false, "generate files for use with gccgo") var gccgoprefix = flag.String("gccgoprefix", "", "-fgo-prefix option used with gccgo") var gccgopkgpath = flag.String("gccgopkgpath", "", "-fgo-pkgpath option used with gccgo") var importRuntimeCgo = flag.Bool("import_runtime_cgo", true, "import runtime/cgo in generated code") +var importSyscall = flag.Bool("import_syscall", true, "import syscall in generated code") var goarch, goos string func main() { diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index aa084b65c9a..02ef5873f02 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -51,12 +51,16 @@ func (p *Package) writeDefs() { fmt.Fprintf(fgo2, "// Created by cgo - DO NOT EDIT\n\n") fmt.Fprintf(fgo2, "package %s\n\n", p.PackageName) fmt.Fprintf(fgo2, "import \"unsafe\"\n\n") - fmt.Fprintf(fgo2, "import \"syscall\"\n\n") + if *importSyscall { + fmt.Fprintf(fgo2, "import \"syscall\"\n\n") + } if !*gccgo && *importRuntimeCgo { fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n") } fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n") - fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = syscall.Errno(x) }\n") + if *importSyscall { + fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = syscall.Errno(x) }\n") + } typedefNames := make([]string, 0, len(typedef)) for name := range typedef {