emacs-diffs
[Top][All Lists]
Advanced

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

feature/native-comp 05b08f2 1/3: * Handle setjmp() taking two arguments


From: Andrea Corallo
Subject: feature/native-comp 05b08f2 1/3: * Handle setjmp() taking two arguments in Windows.
Date: Wed, 20 May 2020 15:45:17 -0400 (EDT)

branch: feature/native-comp
commit 05b08f26444213ce93aff668a80a81a820c73feb
Author: Nicolás Bértolo <address@hidden>
Commit: Andrea Corallo <address@hidden>

    * Handle setjmp() taking two arguments in Windows.
    
    * src/comp.c: Add `define_setjmp_deps()` and `emit_setjmp()` which
    abstract over this difference in behavior between operating systems.
    
    WARNING: Not all cases are handled by this patch. The Mingw-64
    setjmp.h header deals with many other combinations. I don't think it
    is a good idea to replicate the logic of that header inside
    emacs. (Maybe a few lines in the configure script could be added to
    handle this problem?)
---
 src/comp.c | 47 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/src/comp.c b/src/comp.c
index 87b86dd..3fa3361 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -22,6 +22,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_NATIVE_COMP
 
+#include <setjmp.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <signal.h>
@@ -74,10 +75,15 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
   gcc_jit_block *(name) =                              \
     gcc_jit_function_new_block ((func), STR (name))
 
-#ifdef HAVE__SETJMP
-#define SETJMP _setjmp
+#ifndef WINDOWSNT
+# ifdef HAVE__SETJMP
+#  define SETJMP _setjmp
+# else
+#  define SETJMP setjmp
+# endif
 #else
-#define SETJMP setjmp
+/* snippet from MINGW-64 setjmp.h */
+# define SETJMP _setjmp
 #endif
 #define SETJMP_NAME SETJMP
 
@@ -1493,6 +1499,30 @@ emit_limple_call_ref (Lisp_Object insn, bool direct)
                        direct);
 }
 
+static gcc_jit_rvalue *
+emit_setjmp (gcc_jit_rvalue *buf)
+{
+#ifndef WINDOWSNT
+  gcc_jit_rvalue *args[] = {buf};
+  return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 1, 
args,
+                   false);
+#else
+  /* _setjmp (buf, __builtin_frame_address (0)) */
+  gcc_jit_rvalue *args[2];
+
+  args[0] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, 
comp.unsigned_type, 0);
+
+  args[1] = gcc_jit_context_new_call (comp.ctxt,
+                                      NULL,
+                                      gcc_jit_context_get_builtin_function 
(comp.ctxt,
+                                        "__builtin_frame_address"),
+                                      1, args);
+  args[0] = buf;
+  return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 2, 
args,
+                    false);
+#endif
+}
+
 /* Register an handler for a non local exit.  */
 
 static void
@@ -1519,8 +1549,7 @@ emit_limple_push_handler (gcc_jit_rvalue *handler, 
gcc_jit_rvalue *handler_type,
        NULL);
 
   gcc_jit_rvalue *res;
-  res =
-    emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 1, args, 
false);
+  res = emit_setjmp (args[0]);
   emit_cond_jump (res, handler_bb, guarded_bb);
 }
 
@@ -2079,8 +2108,14 @@ declare_runtime_imported_funcs (void)
   args[1] = comp.int_type;
   ADD_IMPORTED (push_handler, comp.handler_ptr_type, 2, args);
 
+#ifndef WINDOWSNT
   args[0] = gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.jmp_buf_s));
   ADD_IMPORTED (SETJMP_NAME, comp.int_type, 1, args);
+#else
+  args[0] = gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.jmp_buf_s));
+  args[1] = comp.void_ptr_type;
+  ADD_IMPORTED (SETJMP_NAME, comp.int_type, 2, args);
+#endif
 
   ADD_IMPORTED (record_unwind_protect_excursion, comp.void_type, 0, NULL);
 
@@ -2320,7 +2355,7 @@ define_jmp_buf (void)
       gcc_jit_context_new_array_type (comp.ctxt,
                                      NULL,
                                      comp.char_type,
-                                     sizeof (jmp_buf)),
+                                     sizeof (sys_jmp_buf)),
       "stuff");
   comp.jmp_buf_s =
     gcc_jit_context_new_struct_type (comp.ctxt,



reply via email to

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