From: Philipp Stephani Date: Sun, 4 Jun 2017 16:50:42 +0000 (+0200) Subject: Define helper macro to reduce code duplication X-Git-Tag: emacs-26.0.90~521^2~170^2~19 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=18396997b30c053a905c9a509777625ccc01c3d5;p=emacs.git 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. --- 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; instead of reporting the error back to Lisp, and also because 'eassert' is compiled to nothing in the release version. */ +/* Use MODULE_FUNCTION_BEGIN_NO_CATCH to implement steps 2 and 3 for + environment functions that are known to never exit non-locally. On + error it will return its argument, which can be a sentinel + value. */ + +#define MODULE_FUNCTION_BEGIN_NO_CATCH(error_retval) \ + do { \ + eassert (env != NULL); \ + check_main_thread (); \ + if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ + return error_retval; \ + } while (false) + /* Use MODULE_FUNCTION_BEGIN to implement steps 2 through 4 for most environment functions. On error it will return its argument, which should be a sentinel value. */ -#define MODULE_FUNCTION_BEGIN(error_retval) \ - check_main_thread (); \ - if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ - return error_retval; \ +#define MODULE_FUNCTION_BEGIN(error_retval) \ + MODULE_FUNCTION_BEGIN_NO_CATCH (error_retval); \ MODULE_HANDLE_NONLOCAL_EXIT (error_retval) static void @@ -416,18 +427,14 @@ module_type_of (emacs_env *env, emacs_value value) static bool module_is_not_nil (emacs_env *env, emacs_value value) { - check_main_thread (); - if (module_non_local_exit_check (env) != emacs_funcall_exit_return) - return false; + MODULE_FUNCTION_BEGIN_NO_CATCH (false); return ! NILP (value_to_lisp (value)); } static bool module_eq (emacs_env *env, emacs_value a, emacs_value b) { - check_main_thread (); - if (module_non_local_exit_check (env) != emacs_funcall_exit_return) - return false; + MODULE_FUNCTION_BEGIN_NO_CATCH (false); return EQ (value_to_lisp (a), value_to_lisp (b)); }