emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 1839699 02/14: Define helper macro to reduce code d


From: Philipp Stephani
Subject: [Emacs-diffs] master 1839699 02/14: Define helper macro to reduce code duplication
Date: Sun, 4 Jun 2017 13:54:05 -0400 (EDT)

branch: master
commit 18396997b30c053a905c9a509777625ccc01c3d5
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    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.
---
 src/emacs-module.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/emacs-module.c b/src/emacs-module.c
index d3c4cac..f2eaa71 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));
 }
 



reply via email to

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