[uim-commit] r1881 - branches/r5rs/uim

yamaken at freedesktop.org yamaken at freedesktop.org
Wed Oct 26 10:08:14 PDT 2005


Author: yamaken
Date: 2005-10-26 10:08:04 -0700 (Wed, 26 Oct 2005)
New Revision: 1881

Modified:
   branches/r5rs/uim/editline.c
   branches/r5rs/uim/plugin.c
   branches/r5rs/uim/uim-compat-scm.c
   branches/r5rs/uim/uim-custom.c
   branches/r5rs/uim/uim-scm.c
   branches/r5rs/uim/uim-scm.h
Log:
* uim/uim-custom.c
* uim/uim-compat-scm.c
* uim/editline.c
* uim/plugin.c
* uim/uim-scm.c
* uim/uim-scm.h
  - Port r1825 from trunk


Modified: branches/r5rs/uim/editline.c
===================================================================
--- branches/r5rs/uim/editline.c	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/editline.c	2005-10-26 17:08:04 UTC (rev 1881)
@@ -59,9 +59,7 @@
 static char *prompt(EditLine *e);
 
 #if UIM_SCM_GCC4_READY_GC
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_lisp,
-				      uim_editline_readline_internal,
-				      (void));
+static uim_lisp uim_editline_readline_internal(void);
 #endif
 
 void
@@ -92,7 +90,7 @@
 {
   uim_lisp ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_editline_readline_internal, ());
+  UIM_SCM_GC_PROTECTED_CALL(ret, uim_lisp, uim_editline_readline_internal, ());
 
   return ret;
 }

Modified: branches/r5rs/uim/plugin.c
===================================================================
--- branches/r5rs/uim/plugin.c	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/plugin.c	2005-10-26 17:08:04 UTC (rev 1881)
@@ -68,9 +68,8 @@
 #endif
 
 #if UIM_SCM_GCC4_READY_GC
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_lisp, plugin_unload_internal,
-				      (uim_lisp _name));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(void, uim_quit_plugin_internal, (void));
+static uim_lisp plugin_unload_internal(uim_lisp _name);
+static void uim_quit_plugin_internal(void);
 #endif
 
 
@@ -199,7 +198,7 @@
 {
   uim_lisp ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, plugin_unload_internal, (_name));
+  UIM_SCM_GC_PROTECTED_CALL(ret, uim_lisp, plugin_unload_internal, (_name));
 
   return ret;
 }
@@ -258,7 +257,7 @@
 uim_quit_plugin(void)
 #if UIM_SCM_GCC4_READY_GC
 {
-  UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC(uim_quit_plugin_internal, ());
+  UIM_SCM_GC_PROTECTED_CALL_VOID(uim_quit_plugin_internal, ());
 }
 
 static void

Modified: branches/r5rs/uim/uim-compat-scm.c
===================================================================
--- branches/r5rs/uim/uim-compat-scm.c	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/uim-compat-scm.c	2005-10-26 17:08:04 UTC (rev 1881)
@@ -40,12 +40,8 @@
 #include "uim-internal.h"
 
 #if UIM_SCM_GCC4_READY_GC
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(int,
-				      uim_scm_symbol_value_int_internal,
-				      (const char *symbol_str));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(char *,
-				      uim_scm_symbol_value_str_internal,
-				      (const char *symbol_str));
+static int uim_scm_symbol_value_int_internal(const char *symbol_str);
+static char *uim_scm_symbol_value_str_internal(const char *symbol_str);
 #endif
 
 static uim_lisp return_val;
@@ -72,8 +68,7 @@
 {
   int ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_symbol_value_int_internal,
-				 (symbol_str));
+  UIM_SCM_GC_PROTECTED_CALL(ret, int, uim_scm_symbol_value_int_internal, (symbol_str));
 
   return ret;
 }
@@ -117,8 +112,8 @@
 {
   char *ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_symbol_value_str_internal,
-				 (symbol_str));
+  UIM_SCM_GC_PROTECTED_CALL(ret, char *, uim_scm_symbol_value_str_internal,
+			    (symbol_str));
 
   return ret;
 }

Modified: branches/r5rs/uim/uim-custom.c
===================================================================
--- branches/r5rs/uim/uim-custom.c	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/uim-custom.c	2005-10-26 17:08:04 UTC (rev 1881)
@@ -133,12 +133,10 @@
 static uim_bool uim_custom_save_group(const char *group);
 
 #if UIM_SCM_GCC4_READY_GC
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(char *, literalize_string_internal,
-				      (const char *str));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_bool, custom_cb_add_internal,
-				      (const char *hook, const char *validator,
+static char *literalize_string_internal(const char *str);
+static uim_bool custom_cb_add_internal(const char *hook, const char *validator,
 				       const char *custom_sym, void *ptr,
-				       const char *gate_func, void (*cb)(void)));
+				       const char *gate_func, void (*cb)(void));
 #endif
 
 static const char str_list_arg[] = "uim-custom-c-str-list-arg";
@@ -154,7 +152,7 @@
 {
   char *ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, literalize_string_internal, (str));
+  UIM_SCM_GC_PROTECTED_CALL(ret, char *, literalize_string_internal, (str));
 
   return ret;
 }
@@ -1405,9 +1403,8 @@
 {
   uim_bool ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, custom_cb_add_internal,
-				 (hook, validator, custom_sym, ptr, gate_func,
-				  cb));
+  UIM_SCM_GC_PROTECTED_CALL(ret, uim_bool, custom_cb_add_internal,
+			    (hook, validator, custom_sym, ptr, gate_func, cb));
 
   return ret;
 }

Modified: branches/r5rs/uim/uim-scm.c
===================================================================
--- branches/r5rs/uim/uim-scm.c	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/uim-scm.c	2005-10-26 17:08:04 UTC (rev 1881)
@@ -50,21 +50,11 @@
 static void uim_scm_error(const char *msg, uim_lisp errobj);
 
 #if UIM_SCM_GCC4_READY_GC
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(void,
-				      uim_scm_error_internal,
-				      (const char *msg, uim_lisp errobj));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(int,
-				      uim_scm_c_int_internal,
-				      (uim_lisp integer));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(const char *,
-				      uim_scm_refer_c_str_internal,
-				      (uim_lisp str));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_lisp,
-				      uim_scm_eval_internal,
-				      (uim_lisp obj));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_lisp,
-				      uim_scm_eval_c_string_internal,
-				      (const char *str));
+static void uim_scm_error_internal(const char *msg, uim_lisp errobj);
+static int uim_scm_c_int_internal(uim_lisp integer);
+static const char *uim_scm_refer_c_str_internal(uim_lisp str);
+static uim_lisp uim_scm_eval_internal(uim_lisp obj);
+static uim_lisp uim_scm_eval_c_string_internal(const char *str);
 #endif
 
 static uim_lisp true_sym;
@@ -77,8 +67,7 @@
 #if UIM_SCM_GCC4_READY_GC
 /* See also the comment about these variables in uim-scm.h */
 uim_lisp *(*volatile uim_scm_gc_protect_stack_ptr)(void)
-   = &uim_scm_gc_protect_stack_internal;
-volatile uim_func_ptr uim_scm_uninlined_func_ptr = NULL;
+  = &uim_scm_gc_protect_stack_internal;
 #endif /* UIM_SCM_GCC4_READY_GC */
 
 
@@ -86,7 +75,7 @@
 uim_scm_error(const char *msg, uim_lisp errobj)
 #if UIM_SCM_GCC4_READY_GC
 {
-  UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC(uim_scm_error_internal, (msg, errobj));
+  UIM_SCM_GC_PROTECTED_CALL_VOID(uim_scm_error_internal, (msg, errobj));
 }
 
 static void
@@ -137,7 +126,7 @@
 {
   int ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_c_int_internal, (integer));
+  UIM_SCM_GC_PROTECTED_CALL(ret, int, uim_scm_c_int_internal, (integer));
 
   return ret;
 }
@@ -191,7 +180,7 @@
 {
   const char *ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_refer_c_str_internal, (str));
+  UIM_SCM_GC_PROTECTED_CALL(ret, const char *, uim_scm_refer_c_str_internal, (str));
 
   return ret;
 }
@@ -425,7 +414,7 @@
 {
   uim_lisp ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_eval_internal, (obj));
+  UIM_SCM_GC_PROTECTED_CALL(ret, uim_lisp, uim_scm_eval_internal, (obj));
 
   return ret;
 }
@@ -464,7 +453,7 @@
 {
   uim_lisp ret;
 
-  UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, uim_scm_eval_c_string_internal, (str));
+  UIM_SCM_GC_PROTECTED_CALL(ret, uim_lisp, uim_scm_eval_c_string_internal, (str));
 
   return ret;
 }

Modified: branches/r5rs/uim/uim-scm.h
===================================================================
--- branches/r5rs/uim/uim-scm.h	2005-10-24 10:17:41 UTC (rev 1880)
+++ branches/r5rs/uim/uim-scm.h	2005-10-26 17:08:04 UTC (rev 1881)
@@ -87,27 +87,13 @@
 
 #if UIM_SCM_GCC4_READY_GC
 /*
- * Variables for ensuring that some function calls be uninlined, to against
- * variable reordering on a stack frame performed in some compilers as
- * anti-stack smashing or optimization. Don't access these variables directly.
+ * The variable to ensure that a call of uim_scm_gc_protect_stack() is
+ * uninlined in portable way through (*f)().
  *
- * Exporting the variables as global symbol ensures that a expression (*f)() is
- * certainly real function call since the variables can be updated from outside
- * of libuim. Therefore, be avoid making the variables static by combining
- * libuim into other codes which enables function inlining for them.
- *
- * Although the volatile qualifier is sufficient to prohibit inlining in
- * ordinary situation, some aggressive (or buggy) compiler may optimize the
- * constraint out when producing self-completed single executable. So I decided
- * that performs both following method as double-insurance.
- *
- *   1. export the variables as global symbol
- *   2. qualify the variables volatile
- *
- *   -- YamaKen 2005-10-04
+ * Don't access this variables directly. Use
+ * UIM_SCM_GC_PROTECTED_CALL*() instead.
  */
 extern uim_lisp *(*volatile uim_scm_gc_protect_stack_ptr)(void);
-extern volatile uim_func_ptr uim_scm_uninlined_func_ptr;
 #endif /* UIM_SCM_GCC4_READY_GC */
 
 
@@ -133,39 +119,34 @@
 #define UIM_SCM_NOINLINE
 #endif /* __GNUC__ */
 
-#define UIM_SCM_GC_PROTECTED_FUNC_T(func) uim_scm_gc_protected_type__##func
-
-#define UIM_SCM_GC_PROTECTED_FUNC_DECL(ret_type, func, args)                 \
-    ret_type func args UIM_SCM_NOINLINE;                                     \
-    typedef ret_type (*UIM_SCM_GC_PROTECTED_FUNC_T(func)) args
-
-#define UIM_SCM_GC_CALL_PROTECTED_FUNC(ret, func, args)                      \
-    UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL(ret = , func, args)
-
-#define UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC(func, args)                      \
-    UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL((void), func, args)
-
 /*
- * Although the volatile qualifier of the 'fp' can remove
- * uim_scm_uninlined_func_ptr, I do it as triple insurance for anti aggressive
- * optimization (including optimizer bugs) -- YamaKen 2005-10-04
+ * Function caller with protecting lisp objects on stack from GC
+ *
+ * The protection is safe against with variable reordering on a stack
+ * frame performed in some compilers as anti-stack smashing or
+ * optimization.
  */
-#define UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL(exp_ret, func, args)         \
+#define UIM_SCM_GC_PROTECTED_CALL(ret, ret_type, func, args)                 \
+    UIM_SCM_GC_PROTECTED_CALL_INTERNAL(ret = , ret_type, func, args)
+
+#define UIM_SCM_GC_PROTECTED_CALL_VOID(func, args)                           \
+    UIM_SCM_GC_PROTECTED_CALL_INTERNAL((void), void, func, args)
+
+#define UIM_SCM_GC_PROTECTED_CALL_INTERNAL(exp_ret, ret_type, func, args)    \
     do {                                                                     \
-        volatile UIM_SCM_GC_PROTECTED_FUNC_T(func) fp;                       \
+        /* ensure that func is uninlined */                                  \
+        ret_type (*volatile fp)() = (ret_type (*)())&func;                   \
         uim_lisp *stack_start;                                               \
                                                                              \
+        if (0) exp_ret func args;  /* compile-time type check */             \
         stack_start = uim_scm_gc_protect_stack();                            \
-        /* ensure that func is uninlined */                                  \
-        uim_scm_uninlined_func_ptr = (uim_func_ptr)&func;                    \
-        fp = (UIM_SCM_GC_PROTECTED_FUNC_T(func))uim_scm_uninlined_func_ptr;  \
         exp_ret (*fp)args;                                                   \
         uim_scm_gc_unprotect_stack(stack_start);                             \
     } while (/* CONSTCOND */ 0)
 
 /*
  * Ordinary programs should not call these functions directly. Use
- * UIM_SCM_GC_CALL_PROTECTED_*FUNC() instead.
+ * UIM_SCM_GC_PROTECTED_CALL*() instead.
  */
 #ifdef __GNUC__
 #define uim_scm_gc_protect_stack uim_scm_gc_protect_stack_internal



More information about the uim-commit mailing list