This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cyclic dependency between <sys/ucontext.h> and <ucontext.h>


> There is a cyclic dependency between the headers <sys/ucontext.h> and
> <ucontext.h> when _XOPEN_SOURCE is defined to 500 or 600: <sys/ucontext.h>
> includes <signal.h> which includes <ucontext.h> which includes
> <sys/ucontext.h>.  The effect is that you'll get a compiler error when
> including <sys/ucontext.h> due to ucontext_t begin undefined.  I don't
> know how to fix that properly, a workaround is to include <ucontext.h>
> instead.

For the record, this is easily reproduced by:
	echo '#include <sys/ucontext.h>' | gcc -c -x c - -D_XOPEN_SOURCE=600

Moving #include <signal.h> outside of #ifndef _SYS_UCONTEXT_H gets around this.
That way, it winds up getting the <signal.h> definitions it needs at the
first inclusion depth, and then the circularity back to <sys/ucontext.h>
does the definitions <ucontext.h> needs, leaving nothing left in the
outermost inclusion depth (_SYS_UCONTEXT_H is already defined).

I believe <ucontext.h> in <signal.h> is only because <signal.h> is supposed
to define the ucontext_t and mcontext_t types.  1003.1-2001 doesn't say it
should declare makecontext et al as well.  That being the case, <signal.h>
can just include <sys/ucontext.h> instead of <ucontext.h> and we won't have
this problem (or the unrequested declarations of makecontext et al).

The following patch does that, and makes the <sys/ucontext.h> test case
compile ok for me.


2003-02-16  Roland McGrath  <roland@redhat.com>

	* signal/signal.h: Include <sys/ucontext.h>, not <ucontext.h>.

--- signal/signal.h.~1.66.~	Wed Oct 23 14:05:37 2002
+++ signal/signal.h	Sun Feb 16 20:40:19 2003
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1999,2000,2001,2002,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -327,7 +327,8 @@ extern int siginterrupt (int __sig, int 
 
 # include <bits/sigstack.h>
 # ifdef __USE_XOPEN
-#  include <ucontext.h>
+/* This will define `ucontext_t' and `mcontext_t'.  */
+#  include <sys/ucontext.h>
 # endif
 
 /* Run signals handlers on the stack specified by SS (if not NULL).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]