Commit c8ad1a4d authored by Russ Cox's avatar Russ Cox

cgo, gotest: use error instead of os.Error in generated code

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5319057
parent 08a073a1
...@@ -59,7 +59,7 @@ struct_, union_, or enum_, as in C.struct_stat. ...@@ -59,7 +59,7 @@ struct_, union_, or enum_, as in C.struct_stat.
Any C function that returns a value may be called in a multiple Any C function that returns a value may be called in a multiple
assignment context to retrieve both the return value and the assignment context to retrieve both the return value and the
C errno variable as an os.Error. For example: C errno variable as an error. For example:
n, err := C.atoi("abc") n, err := C.atoi("abc")
......
...@@ -48,7 +48,7 @@ func (p *Package) writeDefs() { ...@@ -48,7 +48,7 @@ func (p *Package) writeDefs() {
fmt.Fprintf(fgo2, "import \"os\"\n\n") fmt.Fprintf(fgo2, "import \"os\"\n\n")
fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n") fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n")
fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n") fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n")
fmt.Fprintf(fgo2, "func _Cerrno(dst *os.Error, x int) { *dst = os.Errno(x) }\n") fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = os.Errno(x) }\n")
for name, def := range typedef { for name, def := range typedef {
fmt.Fprintf(fgo2, "type %s ", name) fmt.Fprintf(fgo2, "type %s ", name)
...@@ -203,7 +203,7 @@ func (p *Package) structType(n *Name) (string, int64) { ...@@ -203,7 +203,7 @@ func (p *Package) structType(n *Name) (string, int64) {
off += pad off += pad
} }
if n.AddError { if n.AddError {
fmt.Fprint(&buf, "\t\tvoid *e[2]; /* os.Error */\n") fmt.Fprint(&buf, "\t\tvoid *e[2]; /* error */\n")
off += 2 * p.PtrSize off += 2 * p.PtrSize
} }
if off == 0 { if off == 0 {
...@@ -217,9 +217,9 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) { ...@@ -217,9 +217,9 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) {
name := n.Go name := n.Go
gtype := n.FuncType.Go gtype := n.FuncType.Go
if n.AddError { if n.AddError {
// Add "os.Error" to return type list. // Add "error" to return type list.
// Type list is known to be 0 or 1 element - it's a C function. // Type list is known to be 0 or 1 element - it's a C function.
err := &ast.Field{Type: ast.NewIdent("os.Error")} err := &ast.Field{Type: ast.NewIdent("error")}
l := gtype.Results.List l := gtype.Results.List
if len(l) == 0 { if len(l) == 0 {
l = []*ast.Field{err} l = []*ast.Field{err}
......
...@@ -401,7 +401,6 @@ func writeTestmainGo() { ...@@ -401,7 +401,6 @@ func writeTestmainGo() {
fmt.Fprintf(b, "import target_test %q\n", "./_xtest_") fmt.Fprintf(b, "import target_test %q\n", "./_xtest_")
} }
fmt.Fprintf(b, "import %q\n", "testing") fmt.Fprintf(b, "import %q\n", "testing")
fmt.Fprintf(b, "import %q\n", "os")
fmt.Fprintf(b, "import %q\n", "regexp") fmt.Fprintf(b, "import %q\n", "regexp")
fmt.Fprintln(b) // for gofmt fmt.Fprintln(b) // for gofmt
...@@ -454,7 +453,7 @@ var testBody = ` ...@@ -454,7 +453,7 @@ var testBody = `
var matchPat string var matchPat string
var matchRe *regexp.Regexp var matchRe *regexp.Regexp
func matchString(pat, str string) (result bool, err os.Error) { func matchString(pat, str string) (result bool, err error) {
if matchRe == nil || matchPat != pat { if matchRe == nil || matchPat != pat {
matchPat = pat matchPat = pat
matchRe, err = regexp.Compile(matchPat) matchRe, err = regexp.Compile(matchPat)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment