aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2017-06-04 18:50:42 +0200
committerPhilipp Stephani2017-06-04 19:50:49 +0200
commit18396997b30c053a905c9a509777625ccc01c3d5 (patch)
tree7541f7661d95ed78e108ea66a24730e47b23daf0 /src
parentdb7438426ae4fd756213d56884dd52473d8f9336 (diff)
downloademacs-18396997b30c053a905c9a509777625ccc01c3d5.tar.gz
emacs-18396997b30c053a905c9a509777625ccc01c3d5.zip
Define helper macro to reduce code duplication
* src/emacs-module.c (MODULE_FUNCTION_BEGIN_NO_CATCH): New helper macro. (MODULE_FUNCTION_BEGIN, module_type_of, module_is_not_nil, module_eq): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index d3c4cac59f6..f2eaa71de3f 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -211,14 +211,25 @@ static emacs_value const module_nil = 0;
211 instead of reporting the error back to Lisp, and also because 211 instead of reporting the error back to Lisp, and also because
212 'eassert' is compiled to nothing in the release version. */ 212 'eassert' is compiled to nothing in the release version. */
213 213
214/* Use MODULE_FUNCTION_BEGIN_NO_CATCH to implement steps 2 and 3 for
215 environment functions that are known to never exit non-locally. On
216 error it will return its argument, which can be a sentinel
217 value. */
218
219#define MODULE_FUNCTION_BEGIN_NO_CATCH(error_retval) \
220 do { \
221 eassert (env != NULL); \
222 check_main_thread (); \
223 if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \
224 return error_retval; \
225 } while (false)
226
214/* Use MODULE_FUNCTION_BEGIN to implement steps 2 through 4 for most 227/* Use MODULE_FUNCTION_BEGIN to implement steps 2 through 4 for most
215 environment functions. On error it will return its argument, which 228 environment functions. On error it will return its argument, which
216 should be a sentinel value. */ 229 should be a sentinel value. */
217 230
218#define MODULE_FUNCTION_BEGIN(error_retval) \ 231#define MODULE_FUNCTION_BEGIN(error_retval) \
219 check_main_thread (); \ 232 MODULE_FUNCTION_BEGIN_NO_CATCH (error_retval); \
220 if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \
221 return error_retval; \
222 MODULE_HANDLE_NONLOCAL_EXIT (error_retval) 233 MODULE_HANDLE_NONLOCAL_EXIT (error_retval)
223 234
224static void 235static void
@@ -416,18 +427,14 @@ module_type_of (emacs_env *env, emacs_value value)
416static bool 427static bool
417module_is_not_nil (emacs_env *env, emacs_value value) 428module_is_not_nil (emacs_env *env, emacs_value value)
418{ 429{
419 check_main_thread (); 430 MODULE_FUNCTION_BEGIN_NO_CATCH (false);
420 if (module_non_local_exit_check (env) != emacs_funcall_exit_return)
421 return false;
422 return ! NILP (value_to_lisp (value)); 431 return ! NILP (value_to_lisp (value));
423} 432}
424 433
425static bool 434static bool
426module_eq (emacs_env *env, emacs_value a, emacs_value b) 435module_eq (emacs_env *env, emacs_value a, emacs_value b)
427{ 436{
428 check_main_thread (); 437 MODULE_FUNCTION_BEGIN_NO_CATCH (false);
429 if (module_non_local_exit_check (env) != emacs_funcall_exit_return)
430 return false;
431 return EQ (value_to_lisp (a), value_to_lisp (b)); 438 return EQ (value_to_lisp (a), value_to_lisp (b));
432} 439}
433 440