From c49318f04ad720296bc024c3ac49c423dceb089f Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 6 Jan 2016 14:05:03 -0500 Subject: [PATCH] go/ssa/interp: make os.Pipe intrinsic POSIX-portable; disable on Windows Change-Id: I6c2f495c7c75f86590a0d79f86423ca67d695347 Reviewed-on: https://go-review.googlesource.com/18325 Reviewed-by: Robert Griesemer --- go/ssa/interp/external.go | 15 --------------- go/ssa/interp/external_unix.go | 16 ++++++++++++++++ go/ssa/interp/external_windows.go | 3 +++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/go/ssa/interp/external.go b/go/ssa/interp/external.go index 788f02aec2f..0e3de617270 100644 --- a/go/ssa/interp/external.go +++ b/go/ssa/interp/external.go @@ -237,21 +237,6 @@ func ext۰math۰Log(fr *frame, args []value) value { return math.Log(args[0].(float64)) } -func ext۰os۰Pipe(fr *frame, args []value) value { - // This is an inlining of linux's os.Pipe. - // func os.Pipe() (r *File, w *File, err error) - var p [2]int - if err := syscall.Pipe2(p[:], syscall.O_CLOEXEC); err != nil { - // TODO(adonovan): fix: return an *os.SyscallError. - return tuple{nil, nil, wrapError(err)} - } - - NewFile := fr.i.prog.ImportedPackage("os").Func("NewFile") - r := call(fr.i, fr, 0, NewFile, []value{uintptr(p[0]), "|0"}) - w := call(fr.i, fr, 0, NewFile, []value{uintptr(p[1]), "|1"}) - return tuple{r, w, wrapError(nil)} -} - func ext۰os۰runtime_args(fr *frame, args []value) value { return fr.i.osArgs } diff --git a/go/ssa/interp/external_unix.go b/go/ssa/interp/external_unix.go index c482eabba52..be125866c59 100644 --- a/go/ssa/interp/external_unix.go +++ b/go/ssa/interp/external_unix.go @@ -8,6 +8,22 @@ package interp import "syscall" +func ext۰os۰Pipe(fr *frame, args []value) value { + // func os.Pipe() (r *File, w *File, err error) + + // The portable POSIX pipe(2) call is good enough for our needs. + var p [2]int + if err := syscall.Pipe(p[:]); err != nil { + // TODO(adonovan): fix: return an *os.SyscallError. + return tuple{nil, nil, wrapError(err)} + } + + NewFile := fr.i.prog.ImportedPackage("os").Func("NewFile") + r := call(fr.i, fr, 0, NewFile, []value{uintptr(p[0]), "|0"}) + w := call(fr.i, fr, 0, NewFile, []value{uintptr(p[1]), "|1"}) + return tuple{r, w, wrapError(nil)} +} + func fillStat(st *syscall.Stat_t, stat structure) { stat[0] = st.Dev stat[1] = st.Ino diff --git a/go/ssa/interp/external_windows.go b/go/ssa/interp/external_windows.go index ef28a37138b..24d1a876c71 100644 --- a/go/ssa/interp/external_windows.go +++ b/go/ssa/interp/external_windows.go @@ -6,6 +6,9 @@ package interp import "syscall" +func ext۰os۰Pipe(fr *frame, args []value) value { + panic("os.Pipe not yet implemented") +} func ext۰syscall۰Close(fr *frame, args []value) value { panic("syscall.Close not yet implemented") }