diff options
| author | Philipp Stephani | 2019-04-22 11:36:59 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2019-04-22 11:36:59 +0200 |
| commit | a2a51b4e94d3e058a71815cb309a21b707c3473b (patch) | |
| tree | 26d65596dd58e769f32e50ad788c88e6f769df63 | |
| parent | 4ec02445931e25ea0f9d612b0e6cc5c7a01df1db (diff) | |
| download | emacs-a2a51b4e94d3e058a71815cb309a21b707c3473b.tar.gz emacs-a2a51b4e94d3e058a71815cb309a21b707c3473b.zip | |
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.
| -rw-r--r-- | src/emacs-module.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 2f60ef1f1f4..68bee70626e 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -224,26 +224,19 @@ static bool module_assertions = false; | |||
| 224 | not prepared for long jumps (e.g., the behavior in C++ is undefined | 224 | not prepared for long jumps (e.g., the behavior in C++ is undefined |
| 225 | if objects with nontrivial destructors would be skipped). | 225 | if objects with nontrivial destructors would be skipped). |
| 226 | Therefore, catch all non-local exits. There are two kinds of | 226 | Therefore, catch all non-local exits. There are two kinds of |
| 227 | non-local exits: `signal' and `throw'. The macros in this section | 227 | non-local exits: `signal' and `throw'. The macro in this section |
| 228 | can be used to catch both. Use macros to avoid additional variants | 228 | can be used to catch both. Use a macro to avoid additional variants |
| 229 | of `internal_condition_case' etc., and to avoid worrying about | 229 | of `internal_condition_case' etc., and to avoid worrying about |
| 230 | passing information to the handler functions. */ | 230 | passing information to the handler functions. */ |
| 231 | 231 | ||
| 232 | #if !__has_attribute (cleanup) | ||
| 233 | #error "__attribute__ ((cleanup)) not supported by this compiler; try GCC" | ||
| 234 | #endif | ||
| 235 | |||
| 232 | /* Place this macro at the beginning of a function returning a number | 236 | /* Place this macro at the beginning of a function returning a number |
| 233 | or a pointer to handle non-local exits. The function must have an | 237 | or a pointer to handle non-local exits. The function must have an |
| 234 | ENV parameter. The function will return the specified value if a | 238 | ENV parameter. The function will return the specified value if a |
| 235 | signal or throw is caught. */ | 239 | signal or throw is caught. */ |
| 236 | #define MODULE_HANDLE_NONLOCAL_EXIT(retval) \ | ||
| 237 | MODULE_SETJMP (CATCHER_ALL, module_handle_nonlocal_exit, retval) | ||
| 238 | |||
| 239 | #define MODULE_SETJMP(handlertype, handlerfunc, retval) \ | ||
| 240 | MODULE_SETJMP_1 (handlertype, handlerfunc, retval, \ | ||
| 241 | internal_handler_##handlertype, \ | ||
| 242 | internal_cleanup_##handlertype) | ||
| 243 | |||
| 244 | #if !__has_attribute (cleanup) | ||
| 245 | #error "__attribute__ ((cleanup)) not supported by this compiler; try GCC" | ||
| 246 | #endif | ||
| 247 | 240 | ||
| 248 | /* It is very important that pushing the handler doesn't itself raise | 241 | /* It is very important that pushing the handler doesn't itself raise |
| 249 | a signal. Install the cleanup only after the handler has been | 242 | a signal. Install the cleanup only after the handler has been |
| @@ -253,24 +246,28 @@ static bool module_assertions = false; | |||
| 253 | The do-while forces uses of the macro to be followed by a semicolon. | 246 | The do-while forces uses of the macro to be followed by a semicolon. |
| 254 | This macro cannot enclose its entire body inside a do-while, as the | 247 | This macro cannot enclose its entire body inside a do-while, as the |
| 255 | code after the macro may longjmp back into the macro, which means | 248 | code after the macro may longjmp back into the macro, which means |
| 256 | its local variable C must stay live in later code. */ | 249 | its local variable INTERNAL_CLEANUP must stay live in later code. */ |
| 257 | 250 | ||
| 258 | /* TODO: Make backtraces work if this macros is used. */ | 251 | /* TODO: Make backtraces work if this macro is used. */ |
| 259 | 252 | ||
| 260 | #define MODULE_SETJMP_1(handlertype, handlerfunc, retval, c0, c) \ | 253 | #define MODULE_HANDLE_NONLOCAL_EXIT(retval) \ |
| 261 | if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ | 254 | if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ |
| 262 | return retval; \ | 255 | return retval; \ |
| 263 | struct handler *c0 = push_handler_nosignal (Qt, handlertype); \ | 256 | struct handler *internal_handler = \ |
| 264 | if (!c0) \ | 257 | push_handler_nosignal (Qt, CATCHER_ALL); \ |
| 258 | if (!internal_handler) \ | ||
| 265 | { \ | 259 | { \ |
| 266 | module_out_of_memory (env); \ | 260 | module_out_of_memory (env); \ |
| 267 | return retval; \ | 261 | return retval; \ |
| 268 | } \ | 262 | } \ |
| 269 | struct handler *c __attribute__ ((cleanup (module_reset_handlerlist))) \ | 263 | struct handler *internal_cleanup \ |
| 270 | = c0; \ | 264 | __attribute__ ((cleanup (module_reset_handlerlist))) \ |
| 271 | if (sys_setjmp (c->jmp)) \ | 265 | = internal_handler; \ |
| 266 | if (sys_setjmp (internal_cleanup->jmp)) \ | ||
| 272 | { \ | 267 | { \ |
| 273 | (handlerfunc) (env, c->nonlocal_exit, c->val); \ | 268 | module_handle_nonlocal_exit (env, \ |
| 269 | internal_cleanup->nonlocal_exit, \ | ||
| 270 | internal_cleanup->val); \ | ||
| 274 | return retval; \ | 271 | return retval; \ |
| 275 | } \ | 272 | } \ |
| 276 | do { } while (false) | 273 | do { } while (false) |