]> Cypherpunks.ru repositories - gostls13.git/commitdiff
misc/cgo/stdio: make it work on Windows and also test it
authorShenghou Ma <minux.ma@gmail.com>
Wed, 19 Sep 2012 16:27:23 +0000 (00:27 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Wed, 19 Sep 2012 16:27:23 +0000 (00:27 +0800)
use a function to get stdout and stderr, instead of depending
on a specific libc implementation.
also make test/run.go replace \r\n by \n before comparing
output.

        Fixes #2121.
        Part of issue 1741.

R=alex.brainman, rsc, r, remyoudompheng
CC=golang-dev
https://golang.org/cl/5847068

misc/cgo/stdio/stdio.go
misc/cgo/stdio/stdio_netbsd.go [deleted file]
src/run.bat
test/run.go

index 67b7aea1e2a6a66aad963c939e9a76d38443439d..76cb8ad80d65f730314b559508769bd2e1f33adf 100644 (file)
@@ -1,15 +1,22 @@
+// skip
+
 // Copyright 2009 The Go Authors.  All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !netbsd
-
 package stdio
 
 /*
 #include <stdio.h>
+
+// on mingw, stderr and stdout are defined as &_iob[FILENO]
+// on netbsd, they are defined as &__sF[FILENO]
+// and cgo doesn't recognize them, so write a function to get them,
+// instead of depending on internals of libc implementation.
+FILE *getStdout(void) { return stdout; }
+FILE *getStderr(void) { return stderr; }
 */
 import "C"
 
-var Stdout = (*File)(C.stdout)
-var Stderr = (*File)(C.stderr)
+var Stdout = (*File)(C.getStdout())
+var Stderr = (*File)(C.getStderr())
diff --git a/misc/cgo/stdio/stdio_netbsd.go b/misc/cgo/stdio/stdio_netbsd.go
deleted file mode 100644 (file)
index 075c1d0..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2009 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package stdio
-
-/*
-#include <stdio.h>
-
-extern FILE __sF[3];
-*/
-import "C"
-import "unsafe"
-
-var Stdout = (*File)(unsafe.Pointer(&C.__sF[1]))
-var Stderr = (*File)(unsafe.Pointer(&C.__sF[2]))
index 7f4a68889a45e757a3ce85380c3608a15a45f120..4998d815fb3d13f06e0acc55b2a230aa35e4a094 100644 (file)
@@ -70,11 +70,10 @@ if x%CGO_ENABLED% == x0 goto nocgo
 ::if errorlevel 1 goto fail
 ::echo.
 
-:: TODO ..\misc\cgo\stdio
-::echo # ..\misc\cgo\stdio
-::go run %GOROOT%\test\run.go - ..\misc\cgo\stdio
-::if errorlevel 1 goto fail
-::echo.
+echo # ..\misc\cgo\stdio
+go run %GOROOT%\test\run.go - ..\misc\cgo\stdio
+if errorlevel 1 goto fail
+echo.
 
 echo # ..\misc\cgo\test
 go test ..\misc\cgo\test
index b23860692c165a4e8c51af5550b0550e9a4e5c9f..c82c138be5e9e8660d8eddc29a13b7f12654d46d 100644 (file)
@@ -344,7 +344,7 @@ func (t *test) run() {
                if err != nil {
                        t.err = fmt.Errorf("%s\n%s", err, out)
                }
-               if string(out) != t.expectedOutput() {
+               if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
                        t.err = fmt.Errorf("incorrect output\n%s", out)
                }