[uim-commit] r1825 - trunk/uim
yamaken at freedesktop.org
yamaken at freedesktop.org
Thu Oct 6 11:49:04 PDT 2005
Author: yamaken
Date: 2005-10-06 11:48:56 -0700 (Thu, 06 Oct 2005)
New Revision: 1825
Modified:
trunk/uim/editline.c
trunk/uim/plugin.c
trunk/uim/uim-compat-scm.c
trunk/uim/uim-custom.c
trunk/uim/uim-scm.c
trunk/uim/uim-scm.h
Log:
* This commit revises the stack protection API again. Thank you Jun
Inoue for basic concepts and many ideas
* uim/uim-scm.h
- (uim_scm_uninlined_func_ptr): Removed
- (UIM_SCM_GC_PROTECTED_FUNC_T, UIM_SCM_GC_PROTECTED_FUNC_DECL,
UIM_SCM_GC_CALL_PROTECTED_FUNC,
UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC,
UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL): Removed
- (UIM_SCM_GC_PROTECTED_CALL, UIM_SCM_GC_PROTECTED_CALL_VOID,
UIM_SCM_GC_PROTECTED_CALL_INTERNAL): New macro
* uim/uim-scm.c
- (uim_scm_uninlined_func_ptr): Removed
- (uim_scm_c_int_internal, uim_scm_refer_c_str_internal,
uim_scm_eval_internal, siod_init_subr_internal,
uim_scm_eval_c_string_internal): Defined as normal function to
follow the new API
- (uim_scm_c_int, uim_scm_refer_c_str, uim_scm_eval,
uim_scm_eval_c_string, siod_init_subr): Follow the new API
* uim/uim-compat-scm.c
- (uim_scm_symbol_value_int_internal,
uim_scm_symbol_value_str_internal): Defined as normal function to
follow the new API
- (uim_scm_symbol_value_int, uim_scm_symbol_value_str): Follow the
new API
* uim/plugin.c
- (plugin_unload_internal, uim_quit_plugin_internal): Defined as
normal function to follow the new API
- (plugin_unload, uim_quit_plugin): Follow the new API
* uim/uim-custom.c
- (literalize_string_internal, custom_cb_add_internal): Defined as
normal function to follow the new API
- (literalize_string, custom_cb_add): Follow the new API
* uim/editline.c
- (uim_editline_readline_internal): Defined as normal function to
follow the new API
- (uim_editline_readline): Follow the new API
Modified: trunk/uim/editline.c
===================================================================
--- trunk/uim/editline.c 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/editline.c 2005-10-06 18:48:56 UTC (rev 1825)
@@ -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: trunk/uim/plugin.c
===================================================================
--- trunk/uim/plugin.c 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/plugin.c 2005-10-06 18:48:56 UTC (rev 1825)
@@ -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: trunk/uim/uim-compat-scm.c
===================================================================
--- trunk/uim/uim-compat-scm.c 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/uim-compat-scm.c 2005-10-06 18:48:56 UTC (rev 1825)
@@ -42,12 +42,8 @@
#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;
@@ -80,8 +76,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;
}
@@ -125,8 +120,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: trunk/uim/uim-custom.c
===================================================================
--- trunk/uim/uim-custom.c 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/uim-custom.c 2005-10-06 18:48:56 UTC (rev 1825)
@@ -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;
}
@@ -1413,9 +1411,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: trunk/uim/uim-scm.c
===================================================================
--- trunk/uim/uim-scm.c 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/uim-scm.c 2005-10-06 18:48:56 UTC (rev 1825)
@@ -60,22 +60,11 @@
static void siod_init_subr(const char *name, long type, SUBR_FUNC fcn);
#if UIM_SCM_GCC4_READY_GC
-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(void,
- siod_init_subr_internal,
- (const char *name, long type,
- SUBR_FUNC fcn));
-static UIM_SCM_GC_PROTECTED_FUNC_DECL(uim_lisp,
- uim_scm_eval_c_string_internal,
- (const char *str));
+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 void siod_init_subr_internal(const char *name, long type, SUBR_FUNC fcn);
+static uim_lisp uim_scm_eval_c_string_internal(const char *str);
#endif
static uim_lisp true_sym;
@@ -88,8 +77,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 */
@@ -123,7 +111,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;
}
@@ -172,7 +160,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;
}
@@ -376,7 +364,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;
}
@@ -407,7 +395,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;
}
@@ -502,8 +490,7 @@
siod_init_subr(const char *name, long type, SUBR_FUNC fcn)
#if UIM_SCM_GCC4_READY_GC
{
- UIM_SCM_GC_CALL_PROTECTED_VOID_FUNC(siod_init_subr_internal,
- (name, type, fcn));
+ UIM_SCM_GC_PROTECTED_CALL_VOID(siod_init_subr_internal, (name, type, fcn));
}
static void
Modified: trunk/uim/uim-scm.h
===================================================================
--- trunk/uim/uim-scm.h 2005-10-06 18:10:39 UTC (rev 1824)
+++ trunk/uim/uim-scm.h 2005-10-06 18:48:56 UTC (rev 1825)
@@ -77,27 +77,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 */
@@ -123,39 +109,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