[uim-commit] r1487 - in branches/r5rs: scm uim

yamaken at freedesktop.org yamaken at freedesktop.org
Mon Sep 12 08:53:51 PDT 2005


Author: yamaken
Date: 2005-09-12 08:53:49 -0700 (Mon, 12 Sep 2005)
New Revision: 1487

Modified:
   branches/r5rs/scm/custom-rt.scm
   branches/r5rs/uim/context.h
   branches/r5rs/uim/editline.c
   branches/r5rs/uim/plugin.c
   branches/r5rs/uim/uim-custom.c
   branches/r5rs/uim/uim.c
Log:
* scm/custom-rt.scm
* uim/uim-custom.c
* uim/editline.c
* uim/plugin.c
* uim/context.h
* uim/uim.c
  - Port r1480-r1484 from trunk


Modified: branches/r5rs/scm/custom-rt.scm
===================================================================
--- branches/r5rs/scm/custom-rt.scm	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/scm/custom-rt.scm	2005-09-12 15:53:49 UTC (rev 1487)
@@ -44,6 +44,8 @@
 (require "key.scm")
 
 (define custom-full-featured? #f)
+;; experimental
+(define custom-enable-mtime-aware-user-conf-reloading? #f)
 
 (define-record 'custom-choice-rec
   '((sym   #f)
@@ -51,9 +53,10 @@
     (desc  "")))
 
 (define custom-required-custom-files ())
-(define custom-reload-group-syms ())
 (define custom-rt-primary-groups ())
 (define custom-set-hooks ())
+;; experimental
+(define custom-group-conf-freshnesses ())  ;; (gsym . mtime)
 
 (define custom-file-path
   (lambda (gsym)
@@ -64,34 +67,35 @@
 				".scm")))
       path)))
 
-(define prepend-new-reload-group-syms
-  (lambda (gsym path)
-    (set! custom-reload-group-syms
-	  (cons (cons gsym 0) custom-reload-group-syms))))
+;; experimental
+(define custom-update-group-conf-freshness
+  (lambda (gsym)
+    (let ((mtime (file-mtime (custom-file-path gsym))))
+      (set! custom-group-conf-freshnesses
+	    (alist-replace (cons gsym mtime)
+			   custom-group-conf-freshnesses))
+      #t)))
 
-(define update-gsym-mtime
-  (lambda (gsym path)
-    (set-cdr! (assq gsym custom-reload-group-syms)
-	      (file-mtime path))
-	      #t))
+;; experimental
+(define custom-group-conf-updated?
+  (lambda (gsym)
+    (let ((prev-mtime (assq-cdr gsym custom-group-conf-freshnesses)))
+      (or (not prev-mtime)
+	  (not (= (file-mtime (custom-file-path gsym))
+		  prev-mtime))))))
 
+;; experimental
 (define custom-load-updated-group-conf
   (lambda (gsym)
-    (let ((path (custom-file-path gsym)))
-      (if (not (memq gsym (map (lambda (x) (car x)) custom-reload-group-syms)))
-	  (prepend-new-reload-group-syms gsym path))
-      (if (= (file-mtime path)
-	     (cdr (assq gsym custom-reload-group-syms)))
-	  #t ; File isn't modified, no need to reload. 
-	  (if (try-load path)
-	      (update-gsym-mtime gsym path)
-	      #f)))))
+    (or (not (custom-group-conf-updated? gsym))
+	(and (try-load (custom-file-path gsym))
+	     (custom-update-group-conf-freshness gsym)))))
 
 ;; full implementation
 ;; This proc is existing for DUMB loading. No more processing such as
 ;; mtime comparation or history recording must not be added. Please
 ;; keep in mind responsibility separation, and don't alter an API
-;; specification previously stabilized without discussion.
+;; specification previously stabilized, without discussion.
 ;;   -- YamaKen 2005-08-09
 (define custom-load-group-conf
   (lambda (gsym)
@@ -108,7 +112,9 @@
       (let* ((post-groups (custom-list-primary-groups))
 	     (new-groups (list-tail post-groups (length pre-groups))))
 	(if (not (getenv "LIBUIM_VANILLA"))
-	    (for-each custom-load-group-conf
+	    (for-each (lambda (gsym)
+			(custom-load-group-conf gsym)
+			(custom-update-group-conf-freshness gsym))
 		      (reverse new-groups)))))))
 
 ;; full implementation
@@ -243,9 +249,9 @@
   (lambda (context custom-sym val)
     (custom-set-value! custom-sym val)))
 
-;; custom-reload-configs can switch its procedure definition from 2
-;; implementations. custom-reload-customs is selectable since the
-;; latter new code breaks the semantics of custom variable
+;; custom-reload-user-configs can switch its behavior by
+;; custom-enable-mtime-aware-user-conf-reloading? since the
+;; experimental code breaks the semantics of custom variable
 ;; broadcasting.
 ;;
 ;; For example, an arbitrary uim-enabled process can update a custom
@@ -256,12 +262,11 @@
 ;;
 ;; To make the latter code default, a discussion is required.
 ;;   -- YamaKen 2005-08-09
-(define custom-reload-configs
-  (if #f
-      custom-reload-customs  ;; original behavior
-      (lambda ()
-	(let ((group-syms (map (lambda (x) (car x)) custom-reload-group-syms)))
-	  (if (null? group-syms)
-	      #f ;; No file should be loaded.
-	      (for-each custom-load-updated-group-conf
-			(reverse group-syms)))))))
+(define custom-reload-user-configs
+  (lambda ()
+    (and (not (getenv "LIBUIM_VANILLA"))
+	 (let ((load-conf (if custom-enable-mtime-aware-user-conf-reloading?
+			      custom-load-updated-group-conf
+			      custom-load-group-conf)))  ;; original behavior
+	   (for-each load-conf (custom-list-primary-groups))
+	   (custom-call-all-hook-procs custom-set-hooks)))))

Modified: branches/r5rs/uim/context.h
===================================================================
--- branches/r5rs/uim/context.h	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/uim/context.h	2005-09-12 15:53:49 UTC (rev 1487)
@@ -139,8 +139,10 @@
 
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
-  #define UIM_NEW_MUTEX(mtx)                pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER
-  #define UIM_NEW_MUTEX_STATIC(mtx)  static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER
+  #define UIM_DEFINE_MUTEX(mtx)                                              \
+           pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER
+  #define UIM_DEFINE_MUTEX_STATIC(mtx)                                       \
+    static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER
   #define UIM_LOCK_MUTEX(mtx)    pthread_mutex_lock(&mtx)
   #define UIM_UNLOCK_MUTEX(mtx)  pthread_mutex_unlock(&mtx)
 #else

Modified: branches/r5rs/uim/editline.c
===================================================================
--- branches/r5rs/uim/editline.c	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/uim/editline.c	2005-09-12 15:53:49 UTC (rev 1487)
@@ -30,11 +30,27 @@
   SUCH DAMAGE.
 */
 
+/*
+ * Currently defined as 1 to be compatible with previous code. If no
+ * distro packagers need this, please remove
+ */
+#define UIM_EDITLINE_SEPARATED_BUILD 1
+
+#include <histedit.h>
+
+#if UIM_EDITLINE_SEPARATED_BUILD
 #include <uim/uim.h>
 #include <uim/uim-scm.h>
+#include <uim/uim-compat-scm.h>
 #include <uim/plugin.h>
+#else
+#include "uim.h"
+#include "uim-scm.h"
+#include "uim-compat-scm.h"
+#include "plugin.h"
+#endif
 
-#include <histedit.h>
+#include "editline.h"
 
 static EditLine *el;
 static History *hist;

Modified: branches/r5rs/uim/plugin.c
===================================================================
--- branches/r5rs/uim/plugin.c	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/uim/plugin.c	2005-09-12 15:53:49 UTC (rev 1487)
@@ -71,7 +71,7 @@
 plugin_load(uim_lisp _name)
 {
   const char *plugin_name;
-  char *plugin_lib_filename, *plugin_scm_filename;
+  char *plugin_lib_filename = NULL, *plugin_scm_filename = NULL;
   uim_lisp lib_path = uim_scm_symbol_value("uim-plugin-lib-load-path");
   uim_lisp scm_path = uim_scm_symbol_value("uim-plugin-scm-load-path");
   uim_lisp path_car, path_cdr;
@@ -158,7 +158,7 @@
     return uim_scm_f();
   }
 
-  DPRINTFN(0, (stderr, "Calling plugin_instance_init().\n", plugin_name));
+  DPRINTFN(0, (stderr, "Calling plugin_instance_init() for %s.\n", plugin_name));
   (plugin_instance_init)();
   if (plugin_scm_filename) {
     uim_bool succeeded;

Modified: branches/r5rs/uim/uim-custom.c
===================================================================
--- branches/r5rs/uim/uim-custom.c	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/uim/uim-custom.c	2005-09-12 15:53:49 UTC (rev 1487)
@@ -55,8 +55,23 @@
 #include "context.h"
 #include "uim-helper.h"
 
-#if 1
-/* TODO: make stable */
+#if 0
+/*
+ * The UIM_CUSTOM_EXPERIMENTAL_MTIME_SENSING is disabled since:
+ *
+ * - file_content_is_same() has a bug which may return invalid result
+ *   when the file size is greater than 4095 bytes
+ *
+ * - The codes aim to save custom-groups that some changes are
+ *   applied, but it should not be achieved by such violent method
+ *   (comparing entire content of saved files). Observing updated
+ *   group in uim-custom client program is recommended way
+ *
+ * - It breaks original behavior. See the comment of
+ *   custom-reload-user-configs in custom-rt.scm
+ *
+ *  -- YamaKen 2005-09-12
+ */
 #define UIM_CUSTOM_EXPERIMENTAL_MTIME_SENSING
 #endif
 

Modified: branches/r5rs/uim/uim.c
===================================================================
--- branches/r5rs/uim/uim.c	2005-09-12 15:46:18 UTC (rev 1486)
+++ branches/r5rs/uim/uim.c	2005-09-12 15:53:49 UTC (rev 1487)
@@ -61,8 +61,8 @@
 static int uim_quiting;
 
 /* Definition of mutex */
-UIM_NEW_MUTEX_STATIC(initing_or_quiting);
-UIM_NEW_MUTEX_STATIC(context_array_mtx);
+UIM_DEFINE_MUTEX_STATIC(mtx_initing_or_quiting);
+UIM_DEFINE_MUTEX_STATIC(mtx_context_array);
 
 void
 uim_set_preedit_cb(uim_context uc,
@@ -81,25 +81,25 @@
 get_context_id(uim_context uc)
 {
   int i;
-  UIM_LOCK_MUTEX(context_array_mtx);
+  UIM_LOCK_MUTEX(mtx_context_array);
   for (i = 0; i < CONTEXT_ARRAY_SIZE; i++) {
     if (!context_array[i]) {
       context_array[i] = uc;
       uc->id = i;
-      UIM_UNLOCK_MUTEX(context_array_mtx);
+      UIM_UNLOCK_MUTEX(mtx_context_array);
       return;
     }
   }
   uc->id = -1;
-  UIM_UNLOCK_MUTEX(context_array_mtx);
+  UIM_UNLOCK_MUTEX(mtx_context_array);
 }
 
 static void
 put_context_id(uim_context uc)
 {
-  UIM_LOCK_MUTEX(context_array_mtx);
+  UIM_LOCK_MUTEX(mtx_context_array);
   context_array[uc->id] = NULL;
-  UIM_UNLOCK_MUTEX(context_array_mtx);
+  UIM_UNLOCK_MUTEX(mtx_context_array);
 }
 
 uim_context
@@ -290,9 +290,9 @@
 uim_find_context(int id)
 {
   uim_context uc;
-  UIM_LOCK_MUTEX(context_array_mtx);
+  UIM_LOCK_MUTEX(mtx_context_array);
   uc = context_array[id];
-  UIM_UNLOCK_MUTEX(context_array_mtx);
+  UIM_UNLOCK_MUTEX(mtx_context_array);
   return uc;
 }
 
@@ -365,11 +365,17 @@
 
 /* Tentative name. I followed above uim_prop_update_custom, but prop 
 would not be proper to this function. */
+/*
+ * As I described in doc/HELPER-PROTOCOL, it had wrongly named by my
+ * misunderstanding about what is the 'property' of uim. It should be
+ * renamed along with corresponding procol names when an appropriate
+ * time has come.  -- YamaKen 2005-09-12
+ */
 uim_bool
 uim_prop_reload_configs(void)
 {
-  /* FIXME: proces return value properly. */
-  uim_scm_eval_c_string("(custom-reload-configs)");
+  /* FIXME: handle return value properly. */
+  uim_scm_eval_c_string("(custom-reload-user-configs)");
   return UIM_TRUE;
 }
 
@@ -690,10 +696,10 @@
 int
 uim_init(void)
 {
-  UIM_LOCK_MUTEX(initing_or_quiting);
+  UIM_LOCK_MUTEX(mtx_initing_or_quiting);
 
   if (uim_initialized) {
-    UIM_UNLOCK_MUTEX(initing_or_quiting);
+    UIM_UNLOCK_MUTEX(mtx_initing_or_quiting);
     return 0;
   }
   uim_last_client_encoding = NULL;
@@ -702,7 +708,7 @@
   uim_init_scm();
   uim_initialized = 1;
 
-  UIM_UNLOCK_MUTEX(initing_or_quiting);
+  UIM_UNLOCK_MUTEX(mtx_initing_or_quiting);
   return 0;
 }
 
@@ -711,10 +717,10 @@
 {
   int i;
 
-  UIM_LOCK_MUTEX(initing_or_quiting);
+  UIM_LOCK_MUTEX(mtx_initing_or_quiting);
   
   if (!uim_initialized || uim_quiting) {
-    UIM_UNLOCK_MUTEX(initing_or_quiting);
+    UIM_UNLOCK_MUTEX(mtx_initing_or_quiting);
     return;
   }
   /* Some multithreaded applications calls uim_quit bursty. */
@@ -733,5 +739,5 @@
   uim_last_client_encoding = NULL;
   uim_initialized = 0;
   uim_quiting = 0;
-  UIM_UNLOCK_MUTEX(initing_or_quiting);
+  UIM_UNLOCK_MUTEX(mtx_initing_or_quiting);
 }



More information about the uim-commit mailing list