From patchwork Wed Nov 2 16:50:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 123300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6B629B6F7E for ; Thu, 3 Nov 2011 03:50:53 +1100 (EST) Received: (qmail 29331 invoked by alias); 2 Nov 2011 16:50:47 -0000 Received: (qmail 29295 invoked by uid 22791); 2 Nov 2011 16:50:45 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, TW_ZJ, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Nov 2011 16:50:29 +0000 Received: by qam2 with SMTP id 2so378318qam.20 for ; Wed, 02 Nov 2011 09:50:28 -0700 (PDT) Received: by 10.68.39.98 with SMTP id o2mr5955420pbk.119.1320252627550; Wed, 02 Nov 2011 09:50:27 -0700 (PDT) Received: by 10.68.39.98 with SMTP id o2mr5955385pbk.119.1320252627376; Wed, 02 Nov 2011 09:50:27 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id 4sm6041816pbj.18.2011.11.02.09.50.24 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 Nov 2011 09:50:26 -0700 (PDT) From: Ian Lance Taylor To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Re: -fdump-go-spec option does not handle redefinitions References: Date: Wed, 02 Nov 2011 09:50:19 -0700 In-Reply-To: (Uros Bizjak's message of "Wed, 2 Nov 2011 10:10:39 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Uros Bizjak 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 -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