[uim-commit] r1515 - trunk/uim

yamaken at freedesktop.org yamaken at freedesktop.org
Sun Sep 18 04:52:15 PDT 2005


Author: yamaken
Date: 2005-09-18 04:52:12 -0700 (Sun, 18 Sep 2005)
New Revision: 1515

Added:
   trunk/uim/uim-scm-gc.c
Modified:
   trunk/uim/Makefile.am
   trunk/uim/uim-scm.c
   trunk/uim/uim-scm.h
Log:
* This commit adds the experimental GCC4-ready stack
  protection. Although the codes are closely similar to the equivalent
  for SigScheme rescently implemented by me, I commit these codes
  under the copyright of uim as separately originated from me

* uim/uim-scm.h
  - (UIM_SCM_GCC4_READY_GC): New macro. It will be removed once the
    stability of the feature is confirmed
  - (UIM_SCM_NOINLINE, 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): New macro
  - (uim_scm_gc_protect_stack): Change type definition of the version
    for #if UIM_SCM_GCC4_READY_GC
  - (uim_scm_gc_ensure_uninlined_func): New function
* uim/uim-scm.c
  - (uim_scm_gc_protect, uim_scm_gc_protect_stack,
    uim_scm_gc_unprotect_stack): Enclose by #if !UIM_SCM_GCC4_READY_GC
* uim/uim-scm-gc.c
  - New file
  - (uim_scm_gc_protect, uim_scm_gc_unprotect_stack): Moved from
    uim-scm.c
  - (uim_scm_gc_protect_stack):
    * Moved from uim-scm.c
    * Change the type definition and implementation for
      UIM_SCM_GCC4_READY_GC
  - (uim_scm_gc_ensure_uninlined_func): New function
* uim/Makefile.am
  - (libuim_la_SOURCES): Add uim-scm-gc.c


Modified: trunk/uim/Makefile.am
===================================================================
--- trunk/uim/Makefile.am	2005-09-18 10:22:13 UTC (rev 1514)
+++ trunk/uim/Makefile.am	2005-09-18 11:52:12 UTC (rev 1515)
@@ -12,8 +12,9 @@
 pkginclude_HEADERS = uim.h uim-util.h uim-helper.h uim-im-switcher.h \
 		uim-scm.h uim-custom.h plugin.h
 
-libuim_la_SOURCES = uim.c uim-scm.c uim-util.c uim-func.c uim-key.c \
-		siod.h context.h gettext.h uim-encoding.h\
+libuim_la_SOURCES = uim.c uim-util.c uim-func.c uim-key.c \
+		context.h gettext.h uim-encoding.h\
+		siod.h  uim-scm.c uim-scm-gc.c \
 		uim-helper.c uim-helper-client.c \
 		intl.c \
 		uim-ipc.c \

Added: trunk/uim/uim-scm-gc.c
===================================================================
--- trunk/uim/uim-scm-gc.c	2005-09-18 10:22:13 UTC (rev 1514)
+++ trunk/uim/uim-scm-gc.c	2005-09-18 11:52:12 UTC (rev 1515)
@@ -0,0 +1,66 @@
+/*
+
+  Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+#include "siod.h"
+#include "uim-scm.h"
+
+
+#if UIM_SCM_GCC4_READY_GC
+void
+uim_scm_gc_protect(uim_lisp *location)
+{
+  gc_protect((LISP *)location);
+}
+
+uim_lisp *
+uim_scm_gc_protect_stack(uim_lisp *stack_start)
+{
+  LISP stack_start;
+
+  siod_gc_protect_stack(&stack_start);
+
+  return (uim_lisp *)stack_start;
+}
+
+void
+uim_scm_gc_unprotect_stack(uim_lisp *stack_start)
+{
+  siod_gc_unprotect_stack((LISP *)stack_start);
+}
+
+uim_func_ptr
+uim_scm_gc_ensure_uninlined_func(uim_func_ptr func)
+{
+  return func;
+}
+#endif /* UIM_SCM_GCC4_READY_GC */

Modified: trunk/uim/uim-scm.c
===================================================================
--- trunk/uim/uim-scm.c	2005-09-18 10:22:13 UTC (rev 1514)
+++ trunk/uim/uim-scm.c	2005-09-18 11:52:12 UTC (rev 1515)
@@ -179,6 +179,7 @@
   return (uim_lisp)funcptrcons(func_ptr);
 }
 
+#if !UIM_SCM_GCC4_READY_GC
 void
 uim_scm_gc_protect(uim_lisp *location)
 {
@@ -196,6 +197,7 @@
 {
   siod_gc_unprotect_stack((LISP *)stack_start);
 }
+#endif /* UIM_SCM_GCC4_READY_GC */
 
 uim_bool
 uim_scm_is_alive(void)

Modified: trunk/uim/uim-scm.h
===================================================================
--- trunk/uim/uim-scm.h	2005-09-18 10:22:13 UTC (rev 1514)
+++ trunk/uim/uim-scm.h	2005-09-18 11:52:12 UTC (rev 1515)
@@ -59,6 +59,8 @@
 #endif
 
 
+#define UIM_SCM_GCC4_READY_GC 0
+
 /*
   uim companion tools should treat lisp object as opaque. struct
   uim_opaque exists only for type check and has no actual definition.
@@ -88,12 +90,53 @@
 void
 uim_scm_set_lib_path(const char *path);
 
+#if UIM_SCM_GCC4_READY_GC
+#ifdef __GNUC__
+#define UIM_SCM_NOINLINE __attribute__((noinline))
+#else
+#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)
+
+#define UIM_SCM_GC_CALL_PROTECTED_FUNC_INTERNAL(exp_ret, func, args)         \
+    do {                                                                     \
+        UIM_SCM_GC_PROTECTED_FUNC_T(func) fp;                                \
+        uim_lisp *stack_start;                                               \
+                                                                             \
+        stack_start = uim_scm_gc_protect_stack();                            \
+        fp = (UIM_SCM_GC_PROTECTED_FUNC_T(func))                             \
+                  uim_scm_gc_ensure_uninlined_func((uim_func_ptr)&func);     \
+        exp_ret (*fp)args;                                                   \
+        uim_scm_gc_unprotect_stack(stack_start);                             \
+    } while (/* CONSTCOND */ 0)
+
 void
 uim_scm_gc_protect(uim_lisp *location);
+uim_lisp *
+uim_scm_gc_protect_stack(void);
 void
+uim_scm_gc_unprotect_stack(uim_lisp *stack_start);
+uim_func_ptr
+uim_scm_gc_ensure_uninlined_func(uim_func_ptr func);
+#else /* UIM_SCM_GCC4_READY_GC */
+void
+uim_scm_gc_protect(uim_lisp *location);
+void
 uim_scm_gc_protect_stack(uim_lisp *stack_start);
 void
 uim_scm_gc_unprotect_stack(uim_lisp *stack_start);
+#endif /* UIM_SCM_GCC4_READY_GC */
 
 /* evaluations */
 uim_bool



More information about the uim-commit mailing list