emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

_setjmp woes in image.c


From: Eli Zaretskii
Subject: _setjmp woes in image.c
Date: Mon, 13 Jan 2014 22:43:22 +0200

This trick:

  /* Possibly inefficient/inexact substitutes for _setjmp and _longjmp.
     Do not use sys_setjmp, as PNG supports only jmp_buf.  The _longjmp
     substitute may munge the signal mask, but that should be OK here.
     MinGW (MS-Windows) uses _setjmp and defines setjmp to _setjmp in
     the system header setjmp.h; don't mess up that.  */
  #ifndef HAVE__SETJMP
  # define _setjmp(j) setjmp (j)
  # define _longjmp longjmp
  #endif

causes compilation failures with MinGW64.  That's because its _setjmp
accepts 2 arguments, not one, and its setjmp.h system header does this:

  #define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))

Because _setjmp accepts 2 arguments, the configure test for _setjmp
fails, and HAVE__SETJMP is not defined.  Then the above snippet in
image.c defines a _macro_ _setjmp which accepts 1 argument, and that
causes compilation errors when compiling this part:

  if (sys_setjmp (mgr->setjmp_buffer))

because sys_setjmp expands to setjmp, which expands to a call to
_setjmp with 2 arguments.

So I want to propose the fix below.  Can it cause trouble to other
platforms?  Is there a better fix?


=== modified file 'src/image.c'
--- src/image.c 2014-01-07 21:14:32 +0000
+++ src/image.c 2014-01-13 17:55:27 +0000
@@ -5613,8 +5613,10 @@ init_png_functions (void)
    substitute may munge the signal mask, but that should be OK here.
    MinGW (MS-Windows) uses _setjmp and defines setjmp to _setjmp in
    the system header setjmp.h; don't mess up that.  */
-#ifndef HAVE__SETJMP
-# define _setjmp(j) setjmp (j)
+#ifdef HAVE__SETJMP
+# define SETJMP(j) _setjmp (j)
+#else  /* !HAVE__SETJMP */
+# define SETJMP(j) setjmp (j)
 # define _longjmp longjmp
 #endif
 
@@ -5810,7 +5812,7 @@ png_load_body (struct frame *f, struct i
 
   /* Set error jump-back.  We come back here when the PNG library
      detects an error.  */
-  if (_setjmp (PNG_JMPBUF (png_ptr)))
+  if (SETJMP (PNG_JMPBUF (png_ptr)))
     {
     error:
       if (c->png_ptr)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]