This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


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: allowing redefinition of setjmp()?


Hi Eric,

On Jan 23 15:09, Eric Blake wrote:
> I'm trying to build readline 6.3 for cygwin (in preparation for bash
> 4.3), but ran into a snag.  Readline tries to redefine 'setjmp' in terms
> of 'sigsetjmp' via a wrapper header (presumably faster to wrap the
> problem away than auditing lots of old code to find where setjmp was
> used?), which works on Linux but fails miserably on Cygwin:
> 
> ...
> #if defined (HAVE_POSIX_SIGSETJMP)
> #  define procenv_t     sigjmp_buf
> #  if !defined (__OPENNT)
> #    undef setjmp
> #    define setjmp(x)   sigsetjmp((x), 1)
> ...
> 
> $ printf '#include "config.h"
>     #include <setjmp.h>
>     #include "posixjmp.h"
>     sigsetjmp(a,0)\n' | gcc -E - | tail -n1
> __extension__ ({ sigjump_buf *_sjbuf = &(a); ((*_sjbuf)[(13 * 4)] = 0,
> pthread_sigmask (0, 0, (sigset_t *)((*_sjbuf) + ((13 * 4)+1))),
> sigsetjmp (*_sjbuf)); })
> 
> Basically, because readline's causes two macros to be defined in terms
> of each other, the expansion of sigsetjmp is trying to invoke a function
> named sigsetjmp, but no such function exists on Cygwin, leading to this
> compilation failure:
> 
> readline.c: In function 'readline_internal_char':
> readline.c:541:7: error: implicit declaration of function 'sigsetjmp'
> [-Werror=implicit-function-declaration]
> 
> Reading POSIX, I see that Cygwin is compliant, and readline is at fault.
>  http://pubs.opengroup.org/onlinepubs/9699919799/functions/setjmp.html
> is clear:
> 
> "It is unspecified whether setjmp() is a macro or a function. If a macro
> definition is suppressed in order to access an actual function, or a
> program defines an external identifier with the name setjmp, the
> behavior is undefined."

This needs fixing in readline's autoconf stuff in the first place.
> 
> But as the redefine works in Linux, I'm wondering if we tweak things in
> Cygwin and/or newlib to allow it to work here too.  Maybe by making an
> entry point __setjmp() as an alias for setjmp(), and defining
> sigsetjmp() in terms of __setjmp(), so that when someone adds a #define
> wrapper for setjmp, it is no longer a mutually recursive macro naming
> scenario.
> 
> In the meantime, I'm resorting to patching up readline code to quit
> trying to (re)define setjmp.

Right.  What we could do, but only for Cygwin, is to call _setjmp/
_longjmp in the sigsetjmp/siglongjmp macros.  On Cygwin _setjmp/_longjmp
are just aliases for setjmp/longjmp.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Attachment: pgpgMzPvZ2LkZ.pgp
Description: PGP signature


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