allowing redefinition of setjmp()?

Eric Blake
Mon Jan 26 10:19:00 GMT 2015

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:

#  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'

Reading POSIX, I see that Cygwin is compliant, and readline is at fault.
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."

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

In the meantime, I'm resorting to patching up readline code to quit
trying to (re)define setjmp.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Newlib mailing list