public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Allow usage of union wait for wait() functions and macros
@ 2011-10-05 10:58 Christian Franke
  2011-10-05 13:26 ` Christopher Faylor
  2011-10-05 13:55 ` Eric Blake
  0 siblings, 2 replies; 15+ messages in thread
From: Christian Franke @ 2011-10-05 10:58 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

The file include/sys/wait.h provides union wait but neither the wait() 
functions nor the W*() macros allow to actually use it. Compilation of 
cdrkit 1.1.11 fails because the configure check assumes that union wait 
is the status parameter type if its declaration exists.

The attached patch fixes this. It uses GCC extensions for C and 
overloading for C++. Works also with the old Cygwin gcc-3.

Christian


[-- Attachment #2: cygwin-union_wait.patch --]
[-- Type: text/x-diff, Size: 4445 bytes --]

2011-10-05  Christian Franke  <franke@computer.org>

	* include/cygwin/wait.h: Use new __wait_status_to_int()
	macro to access status value in W*() status checks.
	* include/sys/wait.h: Allow `int' and `union wait' as
	wait status parameter.  Change __wait_status_to_int()
	macro and wait () prototypes accordingly.  Add inline
	functions for C++.  Remove extra `;'.

diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
index bed81b7..e4edba2 100644
--- a/winsup/cygwin/include/cygwin/wait.h
+++ b/winsup/cygwin/include/cygwin/wait.h
@@ -1,6 +1,6 @@
 /* cygwin/wait.h
 
-   Copyright 2006, 2009 Red Hat, Inc.
+   Copyright 2006, 2009, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -16,6 +16,9 @@ details. */
 #define WCONTINUED 8
 #define __W_CONTINUED	0xffff
 
+/* Will be redefined in sys/wait.h.  */
+#define __wait_status_to_int(w)  (w)
+
 /* A status looks like:
       <2 bytes info> <2 bytes code>
 
@@ -25,13 +28,14 @@ details. */
       <code> == 80, there was a core dump.
 */
 
-#define WIFEXITED(w)	(((w) & 0xff) == 0)
-#define WIFSIGNALED(w)	(((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
-#define WIFSTOPPED(w)	(((w) & 0xff) == 0x7f)
-#define WIFCONTINUED(w)	(((w) & 0xffff) == __W_CONTINUED)
-#define WEXITSTATUS(w)	(((w) >> 8) & 0xff)
-#define WTERMSIG(w)	((w) & 0x7f)
+#define WIFEXITED(w)	((__wait_status_to_int(w) & 0xff) == 0)
+#define WIFSIGNALED(w)	((__wait_status_to_int(w) & 0x7f) > 0 \
+			 && ((__wait_status_to_int(w) & 0x7f) < 0x7f))
+#define WIFSTOPPED(w)	((__wait_status_to_int(w) & 0xff) == 0x7f)
+#define WIFCONTINUED(w)	((__wait_status_to_int(w) & 0xffff) == __W_CONTINUED)
+#define WEXITSTATUS(w)	((__wait_status_to_int(w) >> 8) & 0xff)
+#define WTERMSIG(w)	(__wait_status_to_int(w) & 0x7f)
 #define WSTOPSIG	WEXITSTATUS
-#define WCOREDUMP(w)	(WIFSIGNALED(w) && (w & 0x80))
+#define WCOREDUMP(w)	(WIFSIGNALED(w) && (__wait_status_to_int(w) & 0x80))
 
 #endif /* _CYGWIN_WAIT_H */
diff --git a/winsup/cygwin/include/sys/wait.h b/winsup/cygwin/include/sys/wait.h
index 04bbae7..b355222 100644
--- a/winsup/cygwin/include/sys/wait.h
+++ b/winsup/cygwin/include/sys/wait.h
@@ -1,6 +1,6 @@
 /* sys/wait.h
 
-   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006 Red Hat, Inc.
+   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -19,10 +19,25 @@ details. */
 extern "C" {
 #endif
 
-pid_t wait (int *);
-pid_t waitpid (pid_t, int *, int);
-pid_t wait3 (int *__status, int __options, struct rusage *__rusage);
-pid_t wait4 (pid_t __pid, int *__status, int __options, struct rusage *__rusage);
+#if defined(__cplusplus) || defined(__INSIDE_CYGWIN__)
+
+typedef int *__wait_status_ptr_t;
+
+#else
+
+/* Allow `int' and `union wait' for the status.  */
+typedef union
+  {
+    int *__int_ptr;
+    union wait *__union_wait_ptr;
+  } __wait_status_ptr_t  __attribute__ ((__transparent_union__));
+
+#endif
+
+pid_t wait (__wait_status_ptr_t __status);
+pid_t waitpid (pid_t __pid, __wait_status_ptr_t __status, int __options);
+pid_t wait3 (__wait_status_ptr_t __status, int __options, struct rusage *__rusage);
+pid_t wait4 (pid_t __pid, __wait_status_ptr_t __status, int __options, struct rusage *__rusage);
 
 union wait
   {
@@ -49,7 +64,37 @@ union wait
 #define	w_stopval	__wait_stopped.__w_stopval
 
 #ifdef __cplusplus
-};
+}
+#endif
+
+#ifndef __INSIDE_CYGWIN__
+
+/* Used in cygwin/wait.h, redefine to accept `int' and `union wait'.  */
+#undef __wait_status_to_int
+
+#ifdef __cplusplus
+
+inline int __wait_status_to_int (int __status)
+  { return __status; }
+inline int __wait_status_to_int (const union wait & __status)
+  { return __status.w_status; }
+
+/* C++ wait() variants for `union wait'.  */
+inline pid_t wait (union wait *__status)
+  { return wait ((int *) __status); }
+inline pid_t waitpid (pid_t __pid, union wait *__status, int __options)
+  { return waitpid(__pid, (int *) __status, __options); }
+inline pid_t wait3 (union wait *__status, int __options, struct rusage *__rusage)
+  { return wait3 ((int *) __status, __options, __rusage); }
+inline pid_t wait4 (pid_t __pid, union wait *__status, int __options, struct rusage *__rusage)
+  { return wait4 (__pid, (int *) __status, __options, __rusage); }
+
+#else
+
+#define __wait_status_to_int(__status)  (__extension__ \
+  (((union { __typeof(__status) __in; int __out; }) { .__in = (__status) }).__out))
+
+#endif
 #endif
 
 #endif

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-05 10:58 [PATCH] Allow usage of union wait for wait() functions and macros Christian Franke
@ 2011-10-05 13:26 ` Christopher Faylor
  2011-10-05 21:18   ` Christian Franke
  2011-10-05 13:55 ` Eric Blake
  1 sibling, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-10-05 13:26 UTC (permalink / raw)
  To: cygwin-patches

On Wed, Oct 05, 2011 at 12:57:44PM +0200, Christian Franke wrote:
>The file include/sys/wait.h provides union wait but neither the wait() 
>functions nor the W*() macros allow to actually use it. Compilation of 
>cdrkit 1.1.11 fails because the configure check assumes that union wait 
>is the status parameter type if its declaration exists.
>
>The attached patch fixes this. It uses GCC extensions for C and 
>overloading for C++. Works also with the old Cygwin gcc-3.
>
>Christian
>

>2011-10-05  Christian Franke  <franke@computer.org>
>
>	* include/cygwin/wait.h: Use new __wait_status_to_int()
>	macro to access status value in W*() status checks.
>	* include/sys/wait.h: Allow `int' and `union wait' as
>	wait status parameter.  Change __wait_status_to_int()
>	macro and wait () prototypes accordingly.  Add inline
>	functions for C++.  Remove extra `;'.
>
>diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
>index bed81b7..e4edba2 100644
>--- a/winsup/cygwin/include/cygwin/wait.h
>+++ b/winsup/cygwin/include/cygwin/wait.h
>@@ -1,6 +1,6 @@
> /* cygwin/wait.h
> 
>-   Copyright 2006, 2009 Red Hat, Inc.
>+   Copyright 2006, 2009, 2011 Red Hat, Inc.
> 
> This file is part of Cygwin.
> 
>@@ -16,6 +16,9 @@ details. */
> #define WCONTINUED 8
> #define __W_CONTINUED	0xffff
> 
>+/* Will be redefined in sys/wait.h.  */
>+#define __wait_status_to_int(w)  (w)
>+

Why is this necessary?  It doesn't look like it is ever expanded in cygwin/wait.h.
If a redefinition is necessary why not put it all in one place?

And why is redefinition needed inside Cygwin?

> /* A status looks like:
>       <2 bytes info> <2 bytes code>
> 
>@@ -25,13 +28,14 @@ details. */
>       <code> == 80, there was a core dump.
> */
> 
>-#define WIFEXITED(w)	(((w) & 0xff) == 0)
>-#define WIFSIGNALED(w)	(((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
>-#define WIFSTOPPED(w)	(((w) & 0xff) == 0x7f)
>-#define WIFCONTINUED(w)	(((w) & 0xffff) == __W_CONTINUED)
>-#define WEXITSTATUS(w)	(((w) >> 8) & 0xff)
>-#define WTERMSIG(w)	((w) & 0x7f)
>+#define WIFEXITED(w)	((__wait_status_to_int(w) & 0xff) == 0)
>+#define WIFSIGNALED(w)	((__wait_status_to_int(w) & 0x7f) > 0 \
>+			 && ((__wait_status_to_int(w) & 0x7f) < 0x7f))
>+#define WIFSTOPPED(w)	((__wait_status_to_int(w) & 0xff) == 0x7f)
>+#define WIFCONTINUED(w)	((__wait_status_to_int(w) & 0xffff) == __W_CONTINUED)
>+#define WEXITSTATUS(w)	((__wait_status_to_int(w) >> 8) & 0xff)
>+#define WTERMSIG(w)	(__wait_status_to_int(w) & 0x7f)
> #define WSTOPSIG	WEXITSTATUS
>-#define WCOREDUMP(w)	(WIFSIGNALED(w) && (w & 0x80))
>+#define WCOREDUMP(w)	(WIFSIGNALED(w) && (__wait_status_to_int(w) & 0x80))
> 
> #endif /* _CYGWIN_WAIT_H */
>diff --git a/winsup/cygwin/include/sys/wait.h b/winsup/cygwin/include/sys/wait.h
>index 04bbae7..b355222 100644
>--- a/winsup/cygwin/include/sys/wait.h
>+++ b/winsup/cygwin/include/sys/wait.h
>@@ -1,6 +1,6 @@
> /* sys/wait.h
> 
>-   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006 Red Hat, Inc.
>+   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006, 2011 Red Hat, Inc.
> 
> This file is part of Cygwin.
> 
>@@ -19,10 +19,25 @@ details. */
> extern "C" {
> #endif
> 
>-pid_t wait (int *);
>-pid_t waitpid (pid_t, int *, int);
>-pid_t wait3 (int *__status, int __options, struct rusage *__rusage);
>-pid_t wait4 (pid_t __pid, int *__status, int __options, struct rusage *__rusage);
>+#if defined(__cplusplus) || defined(__INSIDE_CYGWIN__)
>+
>+typedef int *__wait_status_ptr_t;
>+
>+#else
>+
>+/* Allow `int' and `union wait' for the status.  */
>+typedef union
>+  {
>+    int *__int_ptr;
>+    union wait *__union_wait_ptr;
>+  } __wait_status_ptr_t  __attribute__ ((__transparent_union__));
>+
>+#endif

Could you add a comment here and at the #else indicating what they refer to
like #else /* !(defined(__cplusplus) || defined(__INSIDE_CYGWIN__)) and
#endif (defined(__cplusplus) || defined(__INSIDE_CYGWIN__) ?

Also since Cygwin is C++ why do you need the __INSIDE_CYGWIN__ here?

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-05 10:58 [PATCH] Allow usage of union wait for wait() functions and macros Christian Franke
  2011-10-05 13:26 ` Christopher Faylor
@ 2011-10-05 13:55 ` Eric Blake
  1 sibling, 0 replies; 15+ messages in thread
From: Eric Blake @ 2011-10-05 13:55 UTC (permalink / raw)
  To: cygwin-patches

On 10/05/2011 04:57 AM, Christian Franke wrote:
> The file include/sys/wait.h provides union wait but neither the wait()
> functions nor the W*() macros allow to actually use it. Compilation of
> cdrkit 1.1.11 fails because the configure check assumes that union wait
> is the status parameter type if its declaration exists.
>
> The attached patch fixes this. It uses GCC extensions for C and
> overloading for C++. Works also with the old Cygwin gcc-3.
>

> +/* Will be redefined in sys/wait.h.  */
> +#define __wait_status_to_int(w)  (w)
> +
>   /* A status looks like:
>         <2 bytes info>  <2 bytes code>

As long as you're touching this code, fix this incorrect comment.

A status is 16 bits, and looks like:
   <1 byte info> <1 byte code>

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-05 13:26 ` Christopher Faylor
@ 2011-10-05 21:18   ` Christian Franke
  2011-10-06  2:37     ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christian Franke @ 2011-10-05 21:18 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1926 bytes --]

Christopher Faylor wrote:
> On Wed, Oct 05, 2011 at 12:57:44PM +0200, Christian Franke wrote:
>> ...
>> diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
>> index bed81b7..e4edba2 100644
>> --- a/winsup/cygwin/include/cygwin/wait.h
>> +++ b/winsup/cygwin/include/cygwin/wait.h
>> @@ -1,6 +1,6 @@
>> /* cygwin/wait.h
>>
>> -   Copyright 2006, 2009 Red Hat, Inc.
>> +   Copyright 2006, 2009, 2011 Red Hat, Inc.
>>
>> This file is part of Cygwin.
>>
>> @@ -16,6 +16,9 @@ details. */
>> #define WCONTINUED 8
>> #define __W_CONTINUED	0xffff
>>
>> +/* Will be redefined in sys/wait.h.  */
>> +#define __wait_status_to_int(w)  (w)
>> +
> Why is this necessary?  It doesn't look like it is ever expanded in cygwin/wait.h.

This would be needed if cygwin/wait.h is included separately without 
sys/wait.h
(e.g. stdlib.h -> cygwin/stdlib.h -> cygwin/wait.h)
and some W*() macro is actually used.


> If a redefinition is necessary why not put it all in one place?

The W*() macros and union wait are closely related. So a probably better 
approach would be to move union wait to cygwin/wait.h and define 
__wait_status_to_int() only there.

But then C++ compile may fail because cygwin/wait.h is sometimes 
included indirectly inside an extern "C" block:
w32api/shlobj.h -> extern "C" { w32api/ole2.h ...-> stdlib.h ...-> 
cygwin/wait.h }


> And why is redefinition needed inside Cygwin?

It is not redefined in the __INSIDE_CYGWIN__ case.


>> ...
>> +
>> +#endif
> Could you add a comment here and at the #else indicating what they refer to
> like #else /* !(defined(__cplusplus) || defined(__INSIDE_CYGWIN__)) and
> #endif (defined(__cplusplus) || defined(__INSIDE_CYGWIN__) ?

OK.


> Also since Cygwin is C++ why do you need the __INSIDE_CYGWIN__ here?

There are still ten *.c files in winsup/cygwin :-)

New patch attached. Also includes the comment fix suggested by Eric Blake.

Christian


[-- Attachment #2: cygwin-union_wait-2.patch --]
[-- Type: text/x-diff, Size: 4883 bytes --]

2011-10-05  Christian Franke  <franke@computer.org>

	* include/cygwin/wait.h: Use new __wait_status_to_int()
	macro to access status value in W*() status checks.
	Fix status description.
	* include/sys/wait.h: Allow `int' and `union wait' as
	wait status parameter.  Change __wait_status_to_int()
	macro and wait () prototypes accordingly.  Add inline
	functions for C++.  Remove extra `;'.

diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
index bed81b7..0f3f763 100644
--- a/winsup/cygwin/include/cygwin/wait.h
+++ b/winsup/cygwin/include/cygwin/wait.h
@@ -1,6 +1,6 @@
 /* cygwin/wait.h
 
-   Copyright 2006, 2009 Red Hat, Inc.
+   Copyright 2006, 2009, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -16,8 +16,11 @@ details. */
 #define WCONTINUED 8
 #define __W_CONTINUED	0xffff
 
-/* A status looks like:
-      <2 bytes info> <2 bytes code>
+/* Will be redefined in sys/wait.h.  */
+#define __wait_status_to_int(w)  (w)
+
+/* A status is 16 bits, and looks like:
+      <1 byte info> <1 byte code>
 
       <code> == 0, child has exited, info is the exit value
       <code> == 1..7e, child has exited, info is the signal number.
@@ -25,13 +28,14 @@ details. */
       <code> == 80, there was a core dump.
 */
 
-#define WIFEXITED(w)	(((w) & 0xff) == 0)
-#define WIFSIGNALED(w)	(((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
-#define WIFSTOPPED(w)	(((w) & 0xff) == 0x7f)
-#define WIFCONTINUED(w)	(((w) & 0xffff) == __W_CONTINUED)
-#define WEXITSTATUS(w)	(((w) >> 8) & 0xff)
-#define WTERMSIG(w)	((w) & 0x7f)
+#define WIFEXITED(w)	((__wait_status_to_int(w) & 0xff) == 0)
+#define WIFSIGNALED(w)	((__wait_status_to_int(w) & 0x7f) > 0 \
+			 && ((__wait_status_to_int(w) & 0x7f) < 0x7f))
+#define WIFSTOPPED(w)	((__wait_status_to_int(w) & 0xff) == 0x7f)
+#define WIFCONTINUED(w)	((__wait_status_to_int(w) & 0xffff) == __W_CONTINUED)
+#define WEXITSTATUS(w)	((__wait_status_to_int(w) >> 8) & 0xff)
+#define WTERMSIG(w)	(__wait_status_to_int(w) & 0x7f)
 #define WSTOPSIG	WEXITSTATUS
-#define WCOREDUMP(w)	(WIFSIGNALED(w) && (w & 0x80))
+#define WCOREDUMP(w)	(WIFSIGNALED(w) && (__wait_status_to_int(w) & 0x80))
 
 #endif /* _CYGWIN_WAIT_H */
diff --git a/winsup/cygwin/include/sys/wait.h b/winsup/cygwin/include/sys/wait.h
index 04bbae7..811417e 100644
--- a/winsup/cygwin/include/sys/wait.h
+++ b/winsup/cygwin/include/sys/wait.h
@@ -1,6 +1,6 @@
 /* sys/wait.h
 
-   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006 Red Hat, Inc.
+   Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2006, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -19,10 +19,25 @@ details. */
 extern "C" {
 #endif
 
-pid_t wait (int *);
-pid_t waitpid (pid_t, int *, int);
-pid_t wait3 (int *__status, int __options, struct rusage *__rusage);
-pid_t wait4 (pid_t __pid, int *__status, int __options, struct rusage *__rusage);
+#if defined(__cplusplus) || defined(__INSIDE_CYGWIN__)
+
+typedef int *__wait_status_ptr_t;
+
+#else /* !(defined(__cplusplus) || defined(__INSIDE_CYGWIN__)) */
+
+/* Allow `int' and `union wait' for the status.  */
+typedef union
+  {
+    int *__int_ptr;
+    union wait *__union_wait_ptr;
+  } __wait_status_ptr_t  __attribute__ ((__transparent_union__));
+
+#endif /* defined(__cplusplus) || defined(__INSIDE_CYGWIN__) */
+
+pid_t wait (__wait_status_ptr_t __status);
+pid_t waitpid (pid_t __pid, __wait_status_ptr_t __status, int __options);
+pid_t wait3 (__wait_status_ptr_t __status, int __options, struct rusage *__rusage);
+pid_t wait4 (pid_t __pid, __wait_status_ptr_t __status, int __options, struct rusage *__rusage);
 
 union wait
   {
@@ -49,7 +64,37 @@ union wait
 #define	w_stopval	__wait_stopped.__w_stopval
 
 #ifdef __cplusplus
-};
+}
 #endif
 
-#endif
+#ifndef __INSIDE_CYGWIN__
+
+/* Used in cygwin/wait.h, redefine to accept `int' and `union wait'.  */
+#undef __wait_status_to_int
+
+#ifdef __cplusplus
+
+inline int __wait_status_to_int (int __status)
+  { return __status; }
+inline int __wait_status_to_int (const union wait & __status)
+  { return __status.w_status; }
+
+/* C++ wait() variants for `union wait'.  */
+inline pid_t wait (union wait *__status)
+  { return wait ((int *) __status); }
+inline pid_t waitpid (pid_t __pid, union wait *__status, int __options)
+  { return waitpid(__pid, (int *) __status, __options); }
+inline pid_t wait3 (union wait *__status, int __options, struct rusage *__rusage)
+  { return wait3 ((int *) __status, __options, __rusage); }
+inline pid_t wait4 (pid_t __pid, union wait *__status, int __options, struct rusage *__rusage)
+  { return wait4 (__pid, (int *) __status, __options, __rusage); }
+
+#else /* !__cplusplus */
+
+#define __wait_status_to_int(__status)  (__extension__ \
+  (((union { __typeof(__status) __in; int __out; }) { .__in = (__status) }).__out))
+
+#endif /* __cplusplus */
+#endif /* !__INSIDE_CYGWIN__ */
+
+#endif /* _SYS_WAIT_H */


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-05 21:18   ` Christian Franke
@ 2011-10-06  2:37     ` Christopher Faylor
  2011-10-06 11:04       ` Christian Franke
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-10-06  2:37 UTC (permalink / raw)
  To: cygwin-patches

On Wed, Oct 05, 2011 at 11:17:58PM +0200, Christian Franke wrote:
>Christopher Faylor wrote:
>> On Wed, Oct 05, 2011 at 12:57:44PM +0200, Christian Franke wrote:
>>> ...
>>> diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
>>> index bed81b7..e4edba2 100644
>>> --- a/winsup/cygwin/include/cygwin/wait.h
>>> +++ b/winsup/cygwin/include/cygwin/wait.h
>>> @@ -1,6 +1,6 @@
>>> /* cygwin/wait.h
>>>
>>> -   Copyright 2006, 2009 Red Hat, Inc.
>>> +   Copyright 2006, 2009, 2011 Red Hat, Inc.
>>>
>>> This file is part of Cygwin.
>>>
>>> @@ -16,6 +16,9 @@ details. */
>>> #define WCONTINUED 8
>>> #define __W_CONTINUED	0xffff
>>>
>>> +/* Will be redefined in sys/wait.h.  */
>>> +#define __wait_status_to_int(w)  (w)
>>> +
>> Why is this necessary?  It doesn't look like it is ever expanded in cygwin/wait.h.
>
>This would be needed if cygwin/wait.h is included separately without 
>sys/wait.h
>(e.g. stdlib.h -> cygwin/stdlib.h -> cygwin/wait.h)
>and some W*() macro is actually used.
>
>
>> If a redefinition is necessary why not put it all in one place?
>
>The W*() macros and union wait are closely related. So a probably better 
>approach would be to move union wait to cygwin/wait.h and define 
>__wait_status_to_int() only there.
>
>But then C++ compile may fail because cygwin/wait.h is sometimes 
>included indirectly inside an extern "C" block:
>w32api/shlobj.h -> extern "C" { w32api/ole2.h ...-> stdlib.h ...-> 
>cygwin/wait.h }

Ok.  I see that Linux's use of similar macros is convoluted too.
I really would rather keep this all together but I guess it isn't
possible without redesigning stdlib.h and */wait.h.

>> And why is redefinition needed inside Cygwin?
>
>It is not redefined in the __INSIDE_CYGWIN__ case.
>
>
>>> ...
>>> +
>>> +#endif
>> Could you add a comment here and at the #else indicating what they refer to
>> like #else /* !(defined(__cplusplus) || defined(__INSIDE_CYGWIN__)) and
>> #endif (defined(__cplusplus) || defined(__INSIDE_CYGWIN__) ?
>
>OK.
>
>
>> Also since Cygwin is C++ why do you need the __INSIDE_CYGWIN__ here?
>
>There are still ten *.c files in winsup/cygwin :-)

% cd winsup/cygwin
% grep wait.h **/*.c
%

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-06  2:37     ` Christopher Faylor
@ 2011-10-06 11:04       ` Christian Franke
  2011-10-06 13:04         ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christian Franke @ 2011-10-06 11:04 UTC (permalink / raw)
  To: cygwin-patches

Christopher Faylor wrote:
> On Wed, Oct 05, 2011 at 11:17:58PM +0200, Christian Franke wrote:
>> Christopher Faylor wrote:
>>> On Wed, Oct 05, 2011 at 12:57:44PM +0200, Christian Franke wrote:
>>>> ...
>>>> diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
>>>> index bed81b7..e4edba2 100644
>>>> --- a/winsup/cygwin/include/cygwin/wait.h
>>>> +++ b/winsup/cygwin/include/cygwin/wait.h
>>>> @@ -1,6 +1,6 @@
>>>> /* cygwin/wait.h
>>>>
>>>> -   Copyright 2006, 2009 Red Hat, Inc.
>>>> +   Copyright 2006, 2009, 2011 Red Hat, Inc.
>>>>
>>>> This file is part of Cygwin.
>>>>
>>>> @@ -16,6 +16,9 @@ details. */
>>>> #define WCONTINUED 8
>>>> #define __W_CONTINUED	0xffff
>>>>
>>>> +/* Will be redefined in sys/wait.h.  */
>>>> +#define __wait_status_to_int(w)  (w)
>>>> +
>>> Why is this necessary?  It doesn't look like it is ever expanded in cygwin/wait.h.
>> This would be needed if cygwin/wait.h is included separately without
>> sys/wait.h
>> (e.g. stdlib.h ->  cygwin/stdlib.h ->  cygwin/wait.h)
>> and some W*() macro is actually used.
>>
>>
>>> If a redefinition is necessary why not put it all in one place?
>> The W*() macros and union wait are closely related. So a probably better
>> approach would be to move union wait to cygwin/wait.h and define
>> __wait_status_to_int() only there.
>>
>> But then C++ compile may fail because cygwin/wait.h is sometimes
>> included indirectly inside an extern "C" block:
>> w32api/shlobj.h ->  extern "C" { w32api/ole2.h ...->  stdlib.h ...->
>> cygwin/wait.h }
> Ok.  I see that Linux's use of similar macros is convoluted too.
> I really would rather keep this all together but I guess it isn't
> possible without redesigning stdlib.h and */wait.h.

Linux uses the following approach for the C++ case:

typedef void *__wait_status_ptr_t;
#define __wait_status_to_int(w)  (*(int*)&(w))

This prevents the C++ inline function problem but is not typesafe at all.

Meantime I found out that the inline functions can be used even if a 
file is included in an extern "C" block. It is possible to nest another 
extern "C++" block:

// w32api/shlobj.h:
extern "C" {
#include ...
   ...
   // cygwin/wait.h:
   ...
   #ifdef __cplusplus
   extern "C++" {
   inline int __wait_status_to_int(int __status) { .... }
   inline int __wait_status_to_int(const union wait &__status) { .... }
   }
   #endif

}

So it would be possible to move union wait and related functions to 
cygwin/wait.h. Possible new problem: This pollutes the stdlib.h 
namespace with 'union wait' and '#define w_termsig' etc..


>>> Also since Cygwin is C++ why do you need the __INSIDE_CYGWIN__ here?
>> There are still ten *.c files in winsup/cygwin :-)
> % cd winsup/cygwin
> % grep wait.h **/*.c
> %

OK, __INSIDE_CYGWIN__ is not needed here in practice (but possibly in 
theory :-)

Would the patch with __INSIDE_CYGWIN__ removed be GTG?

Christian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-06 11:04       ` Christian Franke
@ 2011-10-06 13:04         ` Christopher Faylor
  2011-10-06 16:12           ` Christian Franke
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-10-06 13:04 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Oct 06, 2011 at 01:03:41PM +0200, Christian Franke wrote:
>Christopher Faylor wrote:
>> On Wed, Oct 05, 2011 at 11:17:58PM +0200, Christian Franke wrote:
>>> Christopher Faylor wrote:
>>>> On Wed, Oct 05, 2011 at 12:57:44PM +0200, Christian Franke wrote:
>>>>> ...
>>>>> diff --git a/winsup/cygwin/include/cygwin/wait.h b/winsup/cygwin/include/cygwin/wait.h
>>>>> index bed81b7..e4edba2 100644
>>>>> --- a/winsup/cygwin/include/cygwin/wait.h
>>>>> +++ b/winsup/cygwin/include/cygwin/wait.h
>>>>> @@ -1,6 +1,6 @@
>>>>> /* cygwin/wait.h
>>>>>
>>>>> -   Copyright 2006, 2009 Red Hat, Inc.
>>>>> +   Copyright 2006, 2009, 2011 Red Hat, Inc.
>>>>>
>>>>> This file is part of Cygwin.
>>>>>
>>>>> @@ -16,6 +16,9 @@ details. */
>>>>> #define WCONTINUED 8
>>>>> #define __W_CONTINUED	0xffff
>>>>>
>>>>> +/* Will be redefined in sys/wait.h.  */
>>>>> +#define __wait_status_to_int(w)  (w)
>>>>> +
>>>> Why is this necessary?  It doesn't look like it is ever expanded in cygwin/wait.h.
>>> This would be needed if cygwin/wait.h is included separately without
>>> sys/wait.h
>>> (e.g. stdlib.h ->  cygwin/stdlib.h ->  cygwin/wait.h)
>>> and some W*() macro is actually used.
>>>
>>>
>>>> If a redefinition is necessary why not put it all in one place?
>>> The W*() macros and union wait are closely related. So a probably better
>>> approach would be to move union wait to cygwin/wait.h and define
>>> __wait_status_to_int() only there.
>>>
>>> But then C++ compile may fail because cygwin/wait.h is sometimes
>>> included indirectly inside an extern "C" block:
>>> w32api/shlobj.h ->  extern "C" { w32api/ole2.h ...->  stdlib.h ...->
>>> cygwin/wait.h }
>> Ok.  I see that Linux's use of similar macros is convoluted too.
>> I really would rather keep this all together but I guess it isn't
>> possible without redesigning stdlib.h and */wait.h.
>
>Linux uses the following approach for the C++ case:
>
>typedef void *__wait_status_ptr_t;
>#define __wait_status_to_int(w)  (*(int*)&(w))
>
>This prevents the C++ inline function problem but is not typesafe at all.
>
>Meantime I found out that the inline functions can be used even if a 
>file is included in an extern "C" block. It is possible to nest another 
>extern "C++" block:
>
>// w32api/shlobj.h:
>extern "C" {
>#include ...
>   ...
>   // cygwin/wait.h:
>   ...
>   #ifdef __cplusplus
>   extern "C++" {
>   inline int __wait_status_to_int(int __status) { .... }
>   inline int __wait_status_to_int(const union wait &__status) { .... }
>   }
>   #endif
>
>}
>
>So it would be possible to move union wait and related functions to 
>cygwin/wait.h. Possible new problem: This pollutes the stdlib.h 
>namespace with 'union wait' and '#define w_termsig' etc..
>
>
>>>> Also since Cygwin is C++ why do you need the __INSIDE_CYGWIN__ here?
>>> There are still ten *.c files in winsup/cygwin :-)
>> % cd winsup/cygwin
>> % grep wait.h **/*.c
>> %
>
>OK, __INSIDE_CYGWIN__ is not needed here in practice (but possibly in 
>theory :-)

I would rather see as little __INSIDE_CYGWIN__ as possible
in external headers.

>Would the patch with __INSIDE_CYGWIN__ removed be GTG?

Yes.

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-06 13:04         ` Christopher Faylor
@ 2011-10-06 16:12           ` Christian Franke
  2011-10-06 17:18             ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christian Franke @ 2011-10-06 16:12 UTC (permalink / raw)
  To: cygwin-patches

Christopher Faylor wrote:
> On Thu, Oct 06, 2011 at 01:03:41PM +0200, Christian Franke wrote:
>> ...
>> OK, __INSIDE_CYGWIN__ is not needed here in practice (but possibly in
>> theory :-)
> I would rather see as little __INSIDE_CYGWIN__ as possible
> in external headers.

OK, removed and Cygwin compilation tested.

>> Would the patch with __INSIDE_CYGWIN__ removed be GTG?
> Yes.

Thanks - patch committed.

Christian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-06 16:12           ` Christian Franke
@ 2011-10-06 17:18             ` Christopher Faylor
  2011-12-07 22:36               ` Problem with: " Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-10-06 17:18 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Oct 06, 2011 at 06:12:35PM +0200, Christian Franke wrote:
>Christopher Faylor wrote:
>> On Thu, Oct 06, 2011 at 01:03:41PM +0200, Christian Franke wrote:
>>> ...
>>> OK, __INSIDE_CYGWIN__ is not needed here in practice (but possibly in
>>> theory :-)
>> I would rather see as little __INSIDE_CYGWIN__ as possible
>> in external headers.
>
>OK, removed and Cygwin compilation tested.
>
>>> Would the patch with __INSIDE_CYGWIN__ removed be GTG?
>> Yes.
>
>Thanks - patch committed.

Thanks a lot for the patch.

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-10-06 17:18             ` Christopher Faylor
@ 2011-12-07 22:36               ` Christopher Faylor
  2011-12-07 23:17                 ` Christian Franke
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-12-07 22:36 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Oct 06, 2011 at 01:17:49PM -0400, Christopher Faylor wrote:
>On Thu, Oct 06, 2011 at 06:12:35PM +0200, Christian Franke wrote:
>>Christopher Faylor wrote:
>>> On Thu, Oct 06, 2011 at 01:03:41PM +0200, Christian Franke wrote:
>>>> ...
>>>> OK, __INSIDE_CYGWIN__ is not needed here in practice (but possibly in
>>>> theory :-)
>>> I would rather see as little __INSIDE_CYGWIN__ as possible
>>> in external headers.
>>
>>OK, removed and Cygwin compilation tested.
>>
>>>> Would the patch with __INSIDE_CYGWIN__ removed be GTG?
>>> Yes.
>>
>>Thanks - patch committed.
>
>Thanks a lot for the patch.

I guess this is why there was a __INSIDE_CYGWIN__ test.

Christian, could you submit a new patch to rectify this problem?

cgf

----- Forwarded message from Christian Joensson <christian.joensson> -----

From: Christian Joensson
To: cygwin, GCC Development
Subject: Failure to bootstrap current gcc trunk on cygwin (20111207 snapshot): conflicting declarations in cygwin's /usr/include/sys/wait.h
Date: Wed, 7 Dec 2011 20:14:36 +0100

I am trying to build gcc trunk on cygwin (with the snapshot of
20111207) and get this:

/usr/local/src/trunk/objdir.withada/./prev-gcc/g++
-B/usr/local/src/trunk/objdir.withada/./prev-gcc/
-B/usr/i686-pc-cygwin/bin/ -nostdinc++
-B/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/src/.libs
 -B/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/libsupc++/.libs
 -I/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/include/i686-pc-cygwin
 -I/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/include
 -I/usr/local/src/trunk/gcc/libstdc++-v3/libsupc++
-L/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/src/.libs
 -L/usr/local/src/trunk/objdir.withada/prev-i686-pc-cygwin/libstdc++-v3/libsupc++/.libs
-c   -g -O2 -gtoggle -DIN_GCC    -fno-exceptions -fno-rtti -W -Wall
-Wno-narrowing -Wwrite-strings -Wcast-qual  -Wmissing-format-attribute
-Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror
-fno-common -Wno-error -DHAVE_CONFIG_H -I. -Iada
-I/usr/local/src/trunk/gcc/gcc -I/usr/local/src/trunk/gcc/gcc/ada
-I/usr/local/src/trunk/gcc/gcc/../include
-I/usr/local/src/trunk/gcc/gcc/../libcpp/include -I/usr/include
-I/usr/include  -I/usr/local/src/trunk/gcc/gcc/../libdecnumber
-I/usr/local/src/trunk/gcc/gcc/../libdecnumber/bid -I../libdecnumber
  /usr/local/src/trunk/gcc/gcc/ada/adaint.c -o ada/adaint.o
In file included from /usr/local/src/trunk/gcc/gcc/system.h:346:0,
                 from /usr/local/src/trunk/gcc/gcc/ada/adaint.c:107:
/usr/include/sys/wait.h: In function 'int __wait_status_to_int(const wait&)':
/usr/include/sys/wait.h:77:61: error: declaration of C function 'int
__wait_status_to_int(const wait&)' conflicts with
/usr/include/sys/wait.h:75:12: error: previous declaration 'int
__wait_status_to_int(int)' here
/usr/include/sys/wait.h: In function 'pid_t wait(wait*)':
/usr/include/sys/wait.h:81:40: error: declaration of C function 'pid_t
wait(wait*)' conflicts with
/usr/include/sys/wait.h:37:7: error: previous declaration 'pid_t
wait(__wait_status_ptr_t)' here
/usr/include/sys/wait.h: In function 'pid_t waitpid(pid_t, wait*, int)':
/usr/include/sys/wait.h:83:71: error: declaration of C function 'pid_t
waitpid(pid_t, wait*, int)' conflicts with
/usr/include/sys/wait.h:38:7: error: previous declaration 'pid_t
waitpid(pid_t, __wait_status_ptr_t, int)' here
/usr/include/sys/wait.h: In function 'pid_t wait3(wait*, int, rusage*)':
/usr/include/sys/wait.h:85:81: error: declaration of C function 'pid_t
wait3(wait*, int, rusage*)' conflicts with
/usr/include/sys/wait.h:39:7: error: previous declaration 'pid_t
wait3(__wait_status_ptr_t, int, rusage*)' here
/usr/include/sys/wait.h: In function 'pid_t wait4(pid_t, wait*, int, rusage*)':
/usr/include/sys/wait.h:87:94: error: declaration of C function 'pid_t
wait4(pid_t, wait*, int, rusage*)' conflicts with
/usr/include/sys/wait.h:40:7: error: previous declaration 'pid_t
wait4(pid_t, __wait_status_ptr_t, int, rusage*)' here
Makefile:1054: recipe for target `ada/adaint.o' failed
make[3]: *** [ada/adaint.o] Error 1
make[3]: Leaving directory `/usr/local/src/trunk/objdir.withada/gcc'
Makefile:4140: recipe for target `all-stage2-gcc' failed
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory `/usr/local/src/trunk/objdir.withada'
Makefile:18046: recipe for target `stage2-bubble' failed
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/usr/local/src/trunk/objdir.withada'
Makefile:898: recipe for target `all' failed
make: *** [all] Error 2

$ /usr/local/src/trunk/objdir.withada/prev-gcc/xgcc.exe -v
Using built-in specs.
COLLECT_GCC=/usr/local/src/trunk/objdir.withada/prev-gcc/xgcc
Target: i686-pc-cygwin
Configured with: /usr/local/src/trunk/gcc/configure --prefix=/usr
--exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin
--localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share
--docdir=/usr/share/doc/gcc4 -C --datadir=/usr/share
--infodir=/usr/share/info --mandir=/usr/share/man -v --with-gmp=/usr
--with-mpfr=/usr --enable-bootstrap
--enable-version-specific-runtime-libs --libexecdir=/usr/lib
--enable-static --enable-shared --enable-shared-libgcc
--disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2
--disable-sjlj-exceptions --enable-graphite --enable-lto
--disable-symvers --program-suffix=-4 --enable-libgomp --enable-libssp
--enable-threads=posix --with-arch=i686 --with-tune=generic
--enable-libada CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4
CXX_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake
GNATBIND_FOR_TARGET=gnatbind
--enablelanguages=c,ada,c++,fortran,lto,objc,objc++
Thread model: posix
gcc version 4.7.0 20111207 (experimental) [trunk revision 182082] (GCC)

$ uname -a
CYGWIN_NT-6.1-WOW64 LI004043 1.7.10s(0.255/5/3) 20111207 03:08:14 i686 Cygwin

Does this symptom ring a bell for anyone?

-- 
Cheers,

/ChJ

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



----- End forwarded message -----

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-12-07 22:36               ` Problem with: " Christopher Faylor
@ 2011-12-07 23:17                 ` Christian Franke
  2011-12-08  2:34                   ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christian Franke @ 2011-12-07 23:17 UTC (permalink / raw)
  To: cygwin-patches

Christopher Faylor wrote:
>
> I guess this is why there was a __INSIDE_CYGWIN__ test.
>
> Christian, could you submit a new patch to rectify this problem?

OK, will try soon.


> ...
> /usr/local/src/trunk/objdir.withada/./prev-gcc/g++
> -B/usr/local/src/trunk/objdir.withada/./prev-gcc/
> ...
> -I/usr/local/src/trunk/gcc/gcc/../libdecnumber/bid -I../libdecnumber
>    /usr/local/src/trunk/gcc/gcc/ada/adaint.c -o ada/adaint.o
> In file included from /usr/local/src/trunk/gcc/gcc/system.h:346:0,
>                   from /usr/local/src/trunk/gcc/gcc/ada/adaint.c:107:
> /usr/include/sys/wait.h: In function 'int __wait_status_to_int(const wait&)':
> /usr/include/sys/wait.h:77:61: error: declaration of C function 'int
> __wait_status_to_int(const wait&)' conflicts with
> /usr/include/sys/wait.h:75:12: error: previous declaration 'int
> __wait_status_to_int(int)' here

This suggests that sys/wait.h is included within an extern "C" { ... } 
block.
If this is the case then an extern "C++" {...} block around the C++ 
inline functions of sys/wait.h should fix this.
See:
http://cygwin.com/ml/cygwin-patches/2011-q4/msg00005.html

Christian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-12-07 23:17                 ` Christian Franke
@ 2011-12-08  2:34                   ` Christopher Faylor
  2011-12-08  6:43                     ` Christian Franke
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-12-08  2:34 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Dec 08, 2011 at 12:17:11AM +0100, Christian Franke wrote:
>Christopher Faylor wrote:
>>
>> I guess this is why there was a __INSIDE_CYGWIN__ test.
>>
>> Christian, could you submit a new patch to rectify this problem?
>
>OK, will try soon.
>
>
>> ...
>> /usr/local/src/trunk/objdir.withada/./prev-gcc/g++
>> -B/usr/local/src/trunk/objdir.withada/./prev-gcc/
>> ...
>> -I/usr/local/src/trunk/gcc/gcc/../libdecnumber/bid -I../libdecnumber
>>    /usr/local/src/trunk/gcc/gcc/ada/adaint.c -o ada/adaint.o
>> In file included from /usr/local/src/trunk/gcc/gcc/system.h:346:0,
>>                   from /usr/local/src/trunk/gcc/gcc/ada/adaint.c:107:
>> /usr/include/sys/wait.h: In function 'int __wait_status_to_int(const wait&)':
>> /usr/include/sys/wait.h:77:61: error: declaration of C function 'int
>> __wait_status_to_int(const wait&)' conflicts with
>> /usr/include/sys/wait.h:75:12: error: previous declaration 'int
>> __wait_status_to_int(int)' here
>
>This suggests that sys/wait.h is included within an extern "C" { ... } 
>block.
>If this is the case then an extern "C++" {...} block around the C++ 
>inline functions of sys/wait.h should fix this.
>See:
>http://cygwin.com/ml/cygwin-patches/2011-q4/msg00005.html

Yes, I'm responding to this very thread.

But, I don't see how extern "c++" fixes anything.  #ifdef __cplusplus maybe...

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-12-08  2:34                   ` Christopher Faylor
@ 2011-12-08  6:43                     ` Christian Franke
  2011-12-08 16:26                       ` Christopher Faylor
  0 siblings, 1 reply; 15+ messages in thread
From: Christian Franke @ 2011-12-08  6:43 UTC (permalink / raw)
  To: cygwin-patches

Christopher Faylor wrote:
> On Thu, Dec 08, 2011 at 12:17:11AM +0100, Christian Franke wrote:
>> Christopher Faylor wrote:
>>> ...
>>> /usr/local/src/trunk/objdir.withada/./prev-gcc/g++
>>> -B/usr/local/src/trunk/objdir.withada/./prev-gcc/
>>> ...
>>> -I/usr/local/src/trunk/gcc/gcc/../libdecnumber/bid -I../libdecnumber
>>>     /usr/local/src/trunk/gcc/gcc/ada/adaint.c -o ada/adaint.o
>>> In file included from /usr/local/src/trunk/gcc/gcc/system.h:346:0,
>>>                    from /usr/local/src/trunk/gcc/gcc/ada/adaint.c:107:
>>> /usr/include/sys/wait.h: In function 'int __wait_status_to_int(const wait&)':
>>> /usr/include/sys/wait.h:77:61: error: declaration of C function 'int
>>> __wait_status_to_int(const wait&)' conflicts with
>>> /usr/include/sys/wait.h:75:12: error: previous declaration 'int
>>> __wait_status_to_int(int)' here
>> This suggests that sys/wait.h is included within an extern "C" { ... }
>> block.
>> If this is the case then an extern "C++" {...} block around the C++
>> inline functions of sys/wait.h should fix this.
>> See:
>> http://cygwin.com/ml/cygwin-patches/2011-q4/msg00005.html
> Yes, I'm responding to this very thread.
>
> But, I don't see how extern "c++" fixes anything.  #ifdef __cplusplus maybe...

No, #ifdef __cplusplus won't help. Example:

foo.h:
extern "C" {
#include <sys/wait.h>
}


sys/wait.h:
...
#ifdef __cplusplus
...
inline int __wait_status_to_int(int __status) { .... }
// This fails because both are interpreted as C-functions:
inline int __wait_status_to_int(const union wait &__status) { .... }
...
#endif


Fix:
#ifdef __cplusplus
+extern "C++" {
...
inline int __wait_status_to_int(int __status) { .... }
inline int __wait_status_to_int(const union wait &__status) { .... }
...
+}
#endif


Christian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-12-08  6:43                     ` Christian Franke
@ 2011-12-08 16:26                       ` Christopher Faylor
  2011-12-08 17:02                         ` Christian Franke
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Faylor @ 2011-12-08 16:26 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Dec 08, 2011 at 07:42:48AM +0100, Christian Franke wrote:
>Christopher Faylor wrote:
>> On Thu, Dec 08, 2011 at 12:17:11AM +0100, Christian Franke wrote:
>>> Christopher Faylor wrote:
>>>> ...
>>>> /usr/local/src/trunk/objdir.withada/./prev-gcc/g++
>>>> -B/usr/local/src/trunk/objdir.withada/./prev-gcc/
>>>> ...
>>>> -I/usr/local/src/trunk/gcc/gcc/../libdecnumber/bid -I../libdecnumber
>>>>     /usr/local/src/trunk/gcc/gcc/ada/adaint.c -o ada/adaint.o
>>>> In file included from /usr/local/src/trunk/gcc/gcc/system.h:346:0,
>>>>                    from /usr/local/src/trunk/gcc/gcc/ada/adaint.c:107:
>>>> /usr/include/sys/wait.h: In function 'int __wait_status_to_int(const wait&)':
>>>> /usr/include/sys/wait.h:77:61: error: declaration of C function 'int
>>>> __wait_status_to_int(const wait&)' conflicts with
>>>> /usr/include/sys/wait.h:75:12: error: previous declaration 'int
>>>> __wait_status_to_int(int)' here
>>> This suggests that sys/wait.h is included within an extern "C" { ... }
>>> block.
>>> If this is the case then an extern "C++" {...} block around the C++
>>> inline functions of sys/wait.h should fix this.
>>> See:
>>> http://cygwin.com/ml/cygwin-patches/2011-q4/msg00005.html
>> Yes, I'm responding to this very thread.
>>
>> But, I don't see how extern "c++" fixes anything.  #ifdef __cplusplus maybe...
>
>No, #ifdef __cplusplus won't help. Example:
>
>foo.h:
>extern "C" {
>#include <sys/wait.h>
>}
>
>
>sys/wait.h:
>...
>#ifdef __cplusplus
>...
>inline int __wait_status_to_int(int __status) { .... }
>// This fails because both are interpreted as C-functions:
>inline int __wait_status_to_int(const union wait &__status) { .... }
>...
>#endif
>
>
>Fix:
>#ifdef __cplusplus
>+extern "C++" {
>...
>inline int __wait_status_to_int(int __status) { .... }
>inline int __wait_status_to_int(const union wait &__status) { .... }
>...
>+}
>#endif

I've added that to sys/wait.h.  Thanks.

cgf

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Problem with: Re: [PATCH] Allow usage of union wait for wait() functions and macros
  2011-12-08 16:26                       ` Christopher Faylor
@ 2011-12-08 17:02                         ` Christian Franke
  0 siblings, 0 replies; 15+ messages in thread
From: Christian Franke @ 2011-12-08 17:02 UTC (permalink / raw)
  To: cygwin-patches

Christopher Faylor wrote:
> On Thu, Dec 08, 2011 at 07:42:48AM +0100, Christian Franke wrote:
>> Fix:
>> #ifdef __cplusplus
>> +extern "C++" {
>> ...
>> inline int __wait_status_to_int(int __status) { .... }
>> inline int __wait_status_to_int(const union wait&__status) { .... }
>> ...
>> +}
>> #endif
> I've added that to sys/wait.h.  Thanks.

Unfortunately sys/wait.h 1.6 is incomplete. The extern "C++" block 
should include all overloaded C++ functions. Otherwise g++ issues 
similar errors for the wait*() functions as seen in the original message.

Christian

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-12-08 17:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-05 10:58 [PATCH] Allow usage of union wait for wait() functions and macros Christian Franke
2011-10-05 13:26 ` Christopher Faylor
2011-10-05 21:18   ` Christian Franke
2011-10-06  2:37     ` Christopher Faylor
2011-10-06 11:04       ` Christian Franke
2011-10-06 13:04         ` Christopher Faylor
2011-10-06 16:12           ` Christian Franke
2011-10-06 17:18             ` Christopher Faylor
2011-12-07 22:36               ` Problem with: " Christopher Faylor
2011-12-07 23:17                 ` Christian Franke
2011-12-08  2:34                   ` Christopher Faylor
2011-12-08  6:43                     ` Christian Franke
2011-12-08 16:26                       ` Christopher Faylor
2011-12-08 17:02                         ` Christian Franke
2011-10-05 13:55 ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).