Patchwork gccgo branch and darwin

login
register
mail settings
Submitter Ian Taylor
Date Dec. 1, 2010, 10:02 p.m.
Message ID <mcrsjyhdud4.fsf@google.com>
Download mbox | patch
Permalink /patch/73914/
State New
Headers show

Comments

Ian Taylor - Dec. 1, 2010, 10:02 p.m.
Arnaud Lacombe <lacombar@gmail.com> writes:

> On Fri, Nov 19, 2010 at 11:58 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
>
> One nits; is there any reason to use `__xpg_strerror_r()' which is not
> POSIX, versus 'strerror_r()' [0] ?

I did this because on GNU/Linux the POSIX compliant strerror_r is
actually named __xpg_strerror_r.  The <string.h> file is set up such
that that variant is used if strerror_r is called with
-D_XOPEN_SOURCE=600 or _D_POSIX_C_SOURCE=200112L.  If you use
-DGNU_SOURCE, then when calling strerror_r you get the GNU version,
which returns char * rather than int.  This happened because the GNU
version was defined before the POSIX version.


> As RTEMS prototypes has already been mangled to make it return `int'
> instead of the `char *', that would allow to merge all
> `libgo/syscalls/errstr*.go'.

The RTEMS variant assumes the behaviour of the newlib strerror_r.
Declaring it with a return type of int is a bug.


I cleaned up this area to isolate the GNU/Linux dependency with the
following patch.  This should make the code more likely to work on other
systems.  Committed to gccgo branch.

Ian

Patch

diff -r c800c9ea5175 libgo/Makefile.am
--- a/libgo/Makefile.am	Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/Makefile.am	Wed Dec 01 13:56:00 2010 -0800
@@ -1110,6 +1110,7 @@ 
 syscall_sysfile_os_file = syscalls/sysfile_rtems.go
 syscall_syscall_file = syscalls/syscall_stubs.go
 syscall_errstr_file = syscalls/errstr_rtems.go
+syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
 else
 syscall_exec_os_file = syscalls/exec.go
 syscall_socket_os_file = syscalls/socket_linux.go
@@ -1117,10 +1118,16 @@ 
 syscall_sysfile_os_file = syscalls/sysfile_linux.go
 syscall_syscall_file = syscalls/syscall.go
 syscall_errstr_file = syscalls/errstr.go
+if LIBGO_IS_LINUX
+syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
+else
+syscall_errstr_decl_file = syscalls/errstr_decl.go
+endif
 endif
 
 go_syscall_files = \
 	$(syscall_errstr_file) \
+	$(syscall_errstr_decl_file) \
 	syscalls/exec_helpers.go \
 	$(syscall_exec_os_file) \
 	syscalls/socket.go \
diff -r c800c9ea5175 libgo/syscalls/errstr.go
--- a/libgo/syscalls/errstr.go	Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/syscalls/errstr.go	Wed Dec 01 13:56:00 2010 -0800
@@ -6,26 +6,24 @@ 
 
 package syscall
 
-const ENONE = 0;
+const ENONE = 0
 
-// FIXME: The name is only right for glibc.
-func libc_strerror_r(int, *byte, Size_t) int __asm__ ("__xpg_strerror_r")
 func GetErrno() int
 func SetErrno(int)
 
 func Errstr(errno int) string {
 	for len := Size_t(128); ; len *= 2 {
-		b := make([]byte, len);
-		r := libc_strerror_r(errno, &b[0], len);
+		b := make([]byte, len)
+		r := libc_strerror_r(errno, &b[0], len)
 		if r >= 0 {
-			i := 0;
+			i := 0
 			for b[i] != 0 {
-				i++;
+				i++
 			}
-			return string(b[0:i]);
+			return string(b[:i])
 		}
 		if GetErrno() != ERANGE {
-			return "Errstr failure";
+			return "Errstr failure"
 		}
 	}
 }
diff -r c800c9ea5175 libgo/syscalls/errstr_decl.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl.go	Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,9 @@ 
+// errstr.go -- Declare strerror_r.
+
+// Copyright 2010 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 syscall
+
+func libc_strerror_r(int, *byte, Size_t) int __asm__ ("strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_decl_linux.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl_linux.go	Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,9 @@ 
+// errstr_decl_linux.go -- Declare strerror_r for GNU/Linux.
+
+// Copyright 2010 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 syscall
+
+func libc_strerror_r(int, *byte, Size_t) int __asm__ ("__xpg_strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_decl_rtems.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl_rtems.go	Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,10 @@ 
+// errstr.go -- Declare strerror_r for RTEMS.
+
+// Copyright 2010 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 syscall
+
+// RTEMS uses strerror_r in newlib, which is a GNU extension returning a char *.
+func libc_strerror_r(int, *byte, Size_t) *byte __asm__ ("strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_rtems.go
--- a/libgo/syscalls/errstr_rtems.go	Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/syscalls/errstr_rtems.go	Wed Dec 01 13:56:00 2010 -0800
@@ -8,8 +8,6 @@ 
 
 const ENONE = 0
 
-// RTEMS uses strerror_r in newlib, which is a GNU extension returning a char *.
-func libc_strerror_r(int, *byte, Size_t) int __asm__ ("strerror_r")
 func GetErrno() int
 func SetErrno(int)