Commit a2a51b4e authored by Philipp Stephani's avatar Philipp Stephani

Refactoring: Inline a few macros.

Now that CATCHER_ALL catches signals as well, we can simplify
MODULE_HANDLE_NONLOCAL_EXIT a bit.

* src/emacs-module.c (MODULE_SETJMP, MODULE_SETJMP_1): Remove.
(MODULE_HANDLE_NONLOCAL_EXIT): Inline MODULE_SETJMP and
MODULE_SETJMP_1.
parent 4ec02445
Pipeline #1399 passed with stage
in 51 minutes and 27 seconds
...@@ -224,26 +224,19 @@ static bool module_assertions = false; ...@@ -224,26 +224,19 @@ static bool module_assertions = false;
not prepared for long jumps (e.g., the behavior in C++ is undefined not prepared for long jumps (e.g., the behavior in C++ is undefined
if objects with nontrivial destructors would be skipped). if objects with nontrivial destructors would be skipped).
Therefore, catch all non-local exits. There are two kinds of Therefore, catch all non-local exits. There are two kinds of
non-local exits: `signal' and `throw'. The macros in this section non-local exits: `signal' and `throw'. The macro in this section
can be used to catch both. Use macros to avoid additional variants can be used to catch both. Use a macro to avoid additional variants
of `internal_condition_case' etc., and to avoid worrying about of `internal_condition_case' etc., and to avoid worrying about
passing information to the handler functions. */ passing information to the handler functions. */
#if !__has_attribute (cleanup)
#error "__attribute__ ((cleanup)) not supported by this compiler; try GCC"
#endif
/* Place this macro at the beginning of a function returning a number /* Place this macro at the beginning of a function returning a number
or a pointer to handle non-local exits. The function must have an or a pointer to handle non-local exits. The function must have an
ENV parameter. The function will return the specified value if a ENV parameter. The function will return the specified value if a
signal or throw is caught. */ signal or throw is caught. */
#define MODULE_HANDLE_NONLOCAL_EXIT(retval) \
MODULE_SETJMP (CATCHER_ALL, module_handle_nonlocal_exit, retval)
#define MODULE_SETJMP(handlertype, handlerfunc, retval) \
MODULE_SETJMP_1 (handlertype, handlerfunc, retval, \
internal_handler_##handlertype, \
internal_cleanup_##handlertype)
#if !__has_attribute (cleanup)
#error "__attribute__ ((cleanup)) not supported by this compiler; try GCC"
#endif
/* It is very important that pushing the handler doesn't itself raise /* It is very important that pushing the handler doesn't itself raise
a signal. Install the cleanup only after the handler has been a signal. Install the cleanup only after the handler has been
...@@ -253,24 +246,28 @@ static bool module_assertions = false; ...@@ -253,24 +246,28 @@ static bool module_assertions = false;
The do-while forces uses of the macro to be followed by a semicolon. The do-while forces uses of the macro to be followed by a semicolon.
This macro cannot enclose its entire body inside a do-while, as the This macro cannot enclose its entire body inside a do-while, as the
code after the macro may longjmp back into the macro, which means code after the macro may longjmp back into the macro, which means
its local variable C must stay live in later code. */ its local variable INTERNAL_CLEANUP must stay live in later code. */
/* TODO: Make backtraces work if this macros is used. */ /* TODO: Make backtraces work if this macro is used. */
#define MODULE_SETJMP_1(handlertype, handlerfunc, retval, c0, c) \ #define MODULE_HANDLE_NONLOCAL_EXIT(retval) \
if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \
return retval; \ return retval; \
struct handler *c0 = push_handler_nosignal (Qt, handlertype); \ struct handler *internal_handler = \
if (!c0) \ push_handler_nosignal (Qt, CATCHER_ALL); \
if (!internal_handler) \
{ \ { \
module_out_of_memory (env); \ module_out_of_memory (env); \
return retval; \ return retval; \
} \ } \
struct handler *c __attribute__ ((cleanup (module_reset_handlerlist))) \ struct handler *internal_cleanup \
= c0; \ __attribute__ ((cleanup (module_reset_handlerlist))) \
if (sys_setjmp (c->jmp)) \ = internal_handler; \
if (sys_setjmp (internal_cleanup->jmp)) \
{ \ { \
(handlerfunc) (env, c->nonlocal_exit, c->val); \ module_handle_nonlocal_exit (env, \
internal_cleanup->nonlocal_exit, \
internal_cleanup->val); \
return retval; \ return retval; \
} \ } \
do { } while (false) do { } while (false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment