diff mbox

-fdump-go-spec option does not handle redefinitions

Message ID mcrd3damptg.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Nov. 2, 2011, 4:50 p.m. UTC
Uros Bizjak <ubizjak@gmail.com> writes:

> #defines with arguments are not working at all. Please consider
> following testcase:

You're right: this approach doesn't work for preprocessor macros with
arguments.  Making those work via this approach would be much much
harder.

> Please note missing "struct terminfos" define, so I understand that
> TC[GS]ETS is unknown, but FIOCLEX should be fully defined by
> preceeding definitions.

Fortunately, the value of FIOCLEX is irrelevant.  And as you say, this
approach can't work for TCGETS anyhow.

So let's take a different approach.  This patch drops the use of TCGETS
and TCSETS entirely.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 39e671bf216d libgo/go/exp/terminal/terminal.go
--- a/libgo/go/exp/terminal/terminal.go	Wed Nov 02 08:58:28 2011 -0700
+++ b/libgo/go/exp/terminal/terminal.go	Wed Nov 02 09:42:23 2011 -0700
@@ -17,7 +17,6 @@ 
 import (
 	"os"
 	"syscall"
-	"unsafe"
 )
 
 // State contains the state of a terminal.
@@ -28,7 +27,7 @@ 
 // IsTerminal returns true if the given file descriptor is a terminal.
 func IsTerminal(fd int) bool {
 	var termios syscall.Termios
-	_, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+	e := syscall.Tcgetattr(fd, &termios)
 	return e == 0
 }
 
@@ -37,14 +36,14 @@ 
 // restored.
 func MakeRaw(fd int) (*State, os.Error) {
 	var oldState State
-	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); e != 0 {
+	if e := syscall.Tcgetattr(fd, &oldState.termios); e != 0 {
 		return nil, os.Errno(e)
 	}
 
 	newState := oldState.termios
 	newState.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXON | syscall.IXOFF
 	newState.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.ISIG
-	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
+	if e := syscall.Tcsetattr(fd, syscall.TCSANOW, &newState); e != 0 {
 		return nil, os.Errno(e)
 	}
 
@@ -54,7 +53,7 @@ 
 // Restore restores the terminal connected to the given file descriptor to a
 // previous state.
 func Restore(fd int, state *State) os.Error {
-	_, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
+	e := syscall.Tcsetattr(fd, syscall.TCSANOW, &state.termios)
 	return os.Errno(e)
 }
 
@@ -63,18 +62,18 @@ 
 // returned does not include the \n.
 func ReadPassword(fd int) ([]byte, os.Error) {
 	var oldState syscall.Termios
-	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
+	if e := syscall.Tcgetattr(fd, &oldState); e != 0 {
 		return nil, os.Errno(e)
 	}
 
 	newState := oldState
 	newState.Lflag &^= syscall.ECHO
-	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
+	if e := syscall.Tcsetattr(fd, syscall.TCSANOW, &newState); e != 0 {
 		return nil, os.Errno(e)
 	}
 
 	defer func() {
-		syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0)
+		syscall.Tcsetattr(fd, syscall.TCSANOW, &oldState)
 	}()
 
 	var buf [16]byte
diff -r 39e671bf216d libgo/go/syscall/libcall_posix.go
--- a/libgo/go/syscall/libcall_posix.go	Wed Nov 02 08:58:28 2011 -0700
+++ b/libgo/go/syscall/libcall_posix.go	Wed Nov 02 09:42:23 2011 -0700
@@ -377,3 +377,9 @@ 
 	tv.Usec = Timeval_usec_t(nsec % 1e9 / 1e3)
 	return
 }
+
+//sysnb	Tcgetattr(fd int, p *Termios) (errno int)
+//tcgetattr(fd int, p *Termios) int
+
+//sys	Tcsetattr(fd int, actions int, p *Termios) (errno int)
+//tcsetattr(fd int, actions int, p *Termios) int