unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* _setjmp woes in image.c
@ 2014-01-13 20:43 Eli Zaretskii
  2014-01-14  1:22 ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2014-01-13 20:43 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

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)




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

* Re: _setjmp woes in image.c
  2014-01-13 20:43 _setjmp woes in image.c Eli Zaretskii
@ 2014-01-14  1:22 ` Paul Eggert
  2014-01-14 16:09   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2014-01-14  1:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thanks, your fix would work, but it's
a bit clearer to do something similar for longjmp
and to use names that better suggest why the macros
are there.  I did that in trunk bzr 116021.



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

* Re: _setjmp woes in image.c
  2014-01-14  1:22 ` Paul Eggert
@ 2014-01-14 16:09   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2014-01-14 16:09 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

> Date: Mon, 13 Jan 2014 17:22:32 -0800
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: emacs-devel@gnu.org
> 
> Thanks, your fix would work, but it's
> a bit clearer to do something similar for longjmp
> and to use names that better suggest why the macros
> are there.  I did that in trunk bzr 116021.

Thanks, this builds fine both with MinGW32 and MinGW64.



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

end of thread, other threads:[~2014-01-14 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-13 20:43 _setjmp woes in image.c Eli Zaretskii
2014-01-14  1:22 ` Paul Eggert
2014-01-14 16:09   ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).