diff options
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/gcc.go | 16 | ||||
-rw-r--r-- | src/cmd/cgo/main.go | 3 | ||||
-rw-r--r-- | src/cmd/cgo/out.go | 19 | ||||
-rw-r--r-- | src/cmd/cgo/util.go | 2 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index e4e56d8dd..a4d83f1e7 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -66,7 +66,7 @@ func cname(s string) string { // preamble. Multiple occurrences are concatenated with a separating space, // even across files. func (p *Package) ParseFlags(f *File, srcfile string) { - linesIn := strings.Split(f.Preamble, "\n", -1) + linesIn := strings.Split(f.Preamble, "\n") linesOut := make([]string, 0, len(linesIn)) NextLine: @@ -78,7 +78,7 @@ NextLine: } l = strings.TrimSpace(l[4:]) - fields := strings.Split(l, ":", 2) + fields := strings.SplitN(l, ":", 2) if len(fields) != 2 { fatalf("%s: bad #cgo line: %s", srcfile, line) } @@ -230,9 +230,9 @@ func splitQuoted(s string) (r []string, err os.Error) { args = append(args, string(arg[:i])) } if quote != 0 { - err = os.ErrorString("unclosed quote") + err = os.NewError("unclosed quote") } else if escaped { - err = os.ErrorString("unfinished escaping") + err = os.NewError("unfinished escaping") } return args, err } @@ -275,7 +275,7 @@ func (p *Package) loadDefines(f *File) { b.WriteString(f.Preamble) stdout := p.gccDefines(b.Bytes()) - for _, line := range strings.Split(stdout, "\n", -1) { + for _, line := range strings.Split(stdout, "\n") { if len(line) < 9 || line[0:7] != "#define" { continue } @@ -397,7 +397,7 @@ func (p *Package) guessKinds(f *File) []*Name { isConst[i] = true // until proven otherwise } - for _, line := range strings.Split(stderr, "\n", -1) { + for _, line := range strings.Split(stderr, "\n") { if len(line) < 9 || line[0:9] != "cgo-test:" { // the user will see any compiler errors when the code is compiled later. continue @@ -697,7 +697,7 @@ func (p *Package) gccMachine() []string { return nil } -const gccTmp = "_obj/_cgo_.o" +var gccTmp = objDir + "_cgo_.o" // gccCmd returns the gcc command line to use for compiling // the input. @@ -1188,7 +1188,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { if ss, ok := dwarfToName[s]; ok { s = ss } - s = strings.Join(strings.Split(s, " ", -1), "") // strip spaces + s = strings.Join(strings.Split(s, " "), "") // strip spaces name := c.Ident("_Ctype_" + s) typedef[name.Name] = t.Go t.Go = name diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 84aeccc21..be9c2bc4f 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -18,6 +18,7 @@ import ( "go/token" "io" "os" + "path/filepath" "reflect" "strings" ) @@ -228,7 +229,7 @@ func main() { } pkg := f.Package if dir := os.Getenv("CGOPKGPATH"); dir != "" { - pkg = dir + "/" + pkg + pkg = filepath.Join(dir, pkg) } p.PackagePath = pkg p.writeOutput(f, input) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index dbc7bcf69..6802dd1cf 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -14,17 +14,20 @@ import ( "go/printer" "go/token" "os" + "path/filepath" "strings" ) +var objDir = "_obj" + string(filepath.Separator) + // writeDefs creates output files to be compiled by 6g, 6c, and gcc. // (The comments here say 6g and 6c but the code applies to the 8 and 5 tools too.) func (p *Package) writeDefs() { - fgo2 := creat("_obj/_cgo_gotypes.go") - fc := creat("_obj/_cgo_defun.c") - fm := creat("_obj/_cgo_main.c") + fgo2 := creat(objDir + "_cgo_gotypes.go") + fc := creat(objDir + "_cgo_defun.c") + fm := creat(objDir + "_cgo_main.c") - fflg := creat("_obj/_cgo_flags") + fflg := creat(objDir + "_cgo_flags") for k, v := range p.CgoFlags { fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, v) } @@ -145,7 +148,7 @@ func dynimport(obj string) { fatalf("cannot load imported symbols from PE file %s: %v", obj, err) } for _, s := range sym { - ss := strings.Split(s, ":", -1) + ss := strings.Split(s, ":") fmt.Printf("#pragma dynimport %s %s %q\n", ss[0], ss[0], strings.ToLower(ss[1])) } return @@ -285,8 +288,8 @@ func (p *Package) writeOutput(f *File, srcfile string) { base = base[0 : len(base)-3] } base = strings.Map(slashToUnderscore, base) - fgo1 := creat("_obj/" + base + ".cgo1.go") - fgcc := creat("_obj/" + base + ".cgo2.c") + fgo1 := creat(objDir + base + ".cgo1.go") + fgcc := creat(objDir + base + ".cgo2.c") p.GoFiles = append(p.GoFiles, base+".cgo1.go") p.GccFiles = append(p.GccFiles, base+".cgo2.c") @@ -361,7 +364,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) { // Write out the various stubs we need to support functions exported // from Go so that they are callable from C. func (p *Package) writeExports(fgo2, fc, fm *os.File) { - fgcc := creat("_obj/_cgo_export.c") + fgcc := creat(objDir + "_cgo_export.c") fgcch := creat("_cgo_export.h") fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n") diff --git a/src/cmd/cgo/util.go b/src/cmd/cgo/util.go index 1ca24103e..e79b0e1bf 100644 --- a/src/cmd/cgo/util.go +++ b/src/cmd/cgo/util.go @@ -103,7 +103,7 @@ func creat(name string) *os.File { } func slashToUnderscore(c int) int { - if c == '/' { + if c == '/' || c == '\\' || c == ':' { c = '_' } return c |