go.tools/ssa/interp: fix windows build.

- Add missing import.
- platform-specific files syswrite() wrapper presents
  standard API to syscall.Write, even on Windows where
  first arg is a Handle.

Fixes golang/go#7100

R=gri, minux.ma, alex.brainman
CC=golang-codereviews
https://golang.org/cl/52250043
This commit is contained in:
Alan Donovan 2014-01-14 21:47:31 -05:00
parent a0cc29953e
commit 39fe7e6f8e
4 changed files with 17 additions and 2 deletions

View File

@ -5,6 +5,8 @@
package interp
import (
"syscall"
"code.google.com/p/go.tools/ssa"
)
@ -43,3 +45,7 @@ func ext۰syscall۰Write(fn *ssa.Function, args []value) value {
func ext۰syscall۰RawSyscall(fn *ssa.Function, args []value) value {
return tuple{^uintptr(0), uintptr(0), uintptr(0)}
}
func syswrite(fd int, b []byte) (int, error) {
return syscall.Write(fd, b)
}

View File

@ -130,3 +130,7 @@ func ext۰syscall۰Write(fn *ssa.Function, args []value) value {
func ext۰syscall۰RawSyscall(fn *ssa.Function, args []value) value {
return tuple{uintptr(0), uintptr(0), uintptr(syscall.ENOSYS)}
}
func syswrite(fd int, b []byte) (int, error) {
return syscall.Write(fd, b)
}

View File

@ -5,6 +5,8 @@
package interp
import (
"syscall"
"code.google.com/p/go.tools/ssa"
)
@ -41,3 +43,6 @@ func ext۰syscall۰Write(fn *ssa.Function, args []value) value {
func ext۰syscall۰RawSyscall(fn *ssa.Function, args []value) value {
return tuple{uintptr(0), uintptr(0), uintptr(syscall.ENOSYS)}
}
func syswrite(fd int, b []byte) (int, error) {
panic("syswrite not yet implemented")
}

View File

@ -10,7 +10,6 @@ import (
"go/token"
"strings"
"sync"
"syscall"
"unsafe"
"code.google.com/p/go.tools/go/exact"
@ -910,12 +909,13 @@ var capturedOutputMu sync.Mutex
// The print/println built-ins and the write() system call funnel
// through here so they can be captured by the test driver.
func write(fd int, b []byte) (int, error) {
// TODO(adonovan): fix: on Windows, std{out,err} are not 1, 2.
if CapturedOutput != nil && (fd == 1 || fd == 2) {
capturedOutputMu.Lock()
CapturedOutput.Write(b) // ignore errors
capturedOutputMu.Unlock()
}
return syscall.Write(fd, b)
return syswrite(fd, b)
}
// callBuiltin interprets a call to builtin fn with arguments args,