[uim-commit] r205 - in trunk: scm uim
omote@freedesktop.org
omote@freedesktop.org
Sun Jan 9 18:13:11 PST 2005
Author: omote
Date: 2005-01-09 18:13:07 -0800 (Sun, 09 Jan 2005)
New Revision: 205
Modified:
trunk/scm/plugin.scm
trunk/uim/plugin.c
trunk/uim/plugin.h
Log:
* This commit drops 'struct _uim_plugin_info' and 'struct _plugin_list'.
All plugin's information will be stored to 'plugin-alist' and
'plugin-funcs-alist' by Scheme. But because 'uim_quit_plugin' does not work
well for now, all sections are surrounded by '#if 0'.
* uim/plugin.c:
- (plugin_load): Store plugin's informations to 'plugin-alist'.
- (uim_quit_plugin): Get plugin's informations from 'plugin-alist'
- (uim_plugin_instance_query): Removed. Replaced by 'plugin-list-query'.
* uim/plugin.h:
- Remove 'struct _uim_plugin_info' and 'struct _plugin_list'.
* uim/plugin.scm:
- (plugin-alist): New variable.
- (plugin-func-alist): New variable.
- (plugin-list-append): New function.
- (plugin-list-query): New function.
- (plugin-list-query-library): New function.
- (plugin-list-query-instance-init): New function.
- (plugin-list-query-instance-quit): New function.
Modified: trunk/scm/plugin.scm
===================================================================
--- trunk/scm/plugin.scm 2005-01-10 00:36:34 UTC (rev 204)
+++ trunk/scm/plugin.scm 2005-01-10 02:13:07 UTC (rev 205)
@@ -57,3 +57,34 @@
;; 'print' prevents testing framework from normal run.
;;(print uim-plugin-lib-load-path)
;;(print uim-plugin-scm-load-path)
+(define plugin-alist ())
+(define plugin-func-alist ())
+
+(define plugin-list-append
+ (lambda (plugin-name library init quit)
+ (let
+ ((funcs (list init quit)))
+ (set! plugin-alist
+ (append plugin-alist
+ (list (list plugin-name library funcs)))))))
+
+(define plugin-list-query
+ (lambda (plugin-name)
+ (assoc plugin-name plugin-alist)))
+
+(define plugin-list-query-library
+ (lambda (plugin-name)
+ (let ((plugin-entry (plugin-list-query plugin-name)))
+ (nth 1 plugin-entry))))
+
+(define plugin-list-query-instance-init
+ (lambda (plugin-name)
+ (let* ((plugin-entry (plugin-list-query plugin-name))
+ (plugin-funcs (nth 2 plugin-entry)))
+ (car plugin-funcs))))
+
+(define plugin-list-query-instance-quit
+ (lambda (plugin-name)
+ (let* ((plugin-entry (plugin-list-query plugin-name))
+ (plugin-funcs (nth 2 plugin-entry)))
+ (nth 1 plugin-funcs))))
Modified: trunk/uim/plugin.c
===================================================================
--- trunk/uim/plugin.c 2005-01-10 00:36:34 UTC (rev 204)
+++ trunk/uim/plugin.c 2005-01-10 02:13:07 UTC (rev 205)
@@ -48,6 +48,7 @@
#include "config.h"
#include "uim.h"
#include "uim-scm.h"
+#include "uim-compat-scm.h"
#ifndef UIM_SCM_NESTED_EVAL
#include "uim-compat-scm.h"
#endif
@@ -61,13 +62,8 @@
#define PLUGIN_PREFIX "libuim-"
#define PLUGIN_SUFFIX ".so"
-static uim_plugin_info_list *uim_plugin_list = NULL;
-static void plugin_list_append(uim_plugin_info_list *entry);
-
static uim_lisp
plugin_load(uim_lisp _name) {
- uim_plugin_info *info;
- uim_plugin_info_list *info_list_entry;
char *plugin_name;
char *plugin_lib_filename, *plugin_scm_filename;
#ifdef UIM_SCM_NESTED_EVAL
@@ -78,6 +74,9 @@
uim_lisp scm_path = uim_scm_symbol_value("uim-plugin-scm-load-path");
#endif
uim_lisp path_car, path_cdr;
+ void *library;
+ void (*plugin_instance_init)(void);
+ void (*plugin_instance_quit)(void);
size_t len;
@@ -129,47 +128,47 @@
return uim_scm_f();
}
- info_list_entry = malloc(sizeof(uim_plugin_info_list));
- info = malloc(sizeof(uim_plugin_info));
-
- info->library = dlopen(plugin_lib_filename, RTLD_NOW);
+ library = dlopen(plugin_lib_filename, RTLD_NOW);
free(plugin_lib_filename);
- if(info->library == NULL) {
+ if(library == NULL) {
fprintf(stderr, "load failed %s\n", dlerror());
+ free(plugin_scm_filename);
+ free(plugin_name);
return uim_scm_f();
}
- info->plugin_instance_init = (void (*)(void))dlfunc(info->library,
- "uim_plugin_instance_init");
- info->plugin_instance_quit = (void (*)(void))dlfunc(info->library,
- "uim_plugin_instance_quit");
- if(info->plugin_instance_init) {
- (info->plugin_instance_init)();
- } else {
+ plugin_instance_init = (void (*)(void))dlfunc(library,
+ "uim_plugin_instance_init");
+ plugin_instance_quit = (void (*)(void))dlfunc(library,
+ "uim_plugin_instance_quit");
+ if(!plugin_instance_init) {
fprintf(stderr, "%s plugin init failed\n", plugin_name);
+ free(plugin_scm_filename);
+ free(plugin_name);
+ return uim_scm_f();
}
- /* plugin_list_append(uim_plugin_entry); */
+ (plugin_instance_init)();
uim_scm_require_file(plugin_scm_filename);
+
+ {
+ uim_lisp form, stack_start;
+ uim_scm_gc_protect_stack(&stack_start);
+ form = uim_scm_list5(uim_scm_make_symbol("plugin-list-append"),
+ _name,
+ uim_scm_make_ptr(library),
+ uim_scm_make_ptr((void *)plugin_instance_init),
+ uim_scm_make_ptr((void *)plugin_instance_quit));
+ uim_scm_eval(form);
+ uim_scm_gc_unprotect_stack(&stack_start);
+ }
free(plugin_scm_filename);
free(plugin_name);
+
return uim_scm_t();
}
-static void plugin_list_append(uim_plugin_info_list *entry)
-{
- uim_plugin_info_list *cur;
-
- if(uim_plugin_list != NULL) {
- for(cur = uim_plugin_list; cur->next != NULL; cur = cur->next)
- ;
- cur->next = entry;
- } else {
- uim_plugin_list = entry;
- }
-}
-
static uim_lisp
plugin_unload(uim_lisp _name)
{
@@ -180,14 +179,6 @@
/* Called from uim_init */
void uim_init_plugin(void)
{
- /* This function is called before scheme files are loaded. Plugin's search
- * path(both .so and .scm) should be got from plugin.scm.
- */
- char *plugin_lib_dir_env;
- char *plugin_scm_dir_env;
- struct passwd *pw;
- size_t len;
-
uim_scm_init_subr_1("load-plugin", plugin_load);
uim_scm_init_subr_1("unload-plugin", plugin_unload);
@@ -197,19 +188,29 @@
/* Called from uim_quit */
void uim_quit_plugin(void)
{
- uim_plugin_info_list *cur;
- for(cur = uim_plugin_list; cur != NULL; cur = cur->next)
- {
- (*((cur->plugin)->plugin_instance_quit))();
- dlclose((cur->plugin)->library);
- }
-}
+#if 0
+ /* XXX: This code does not work well */
+ uim_lisp list_car, list_cdr;
+ uim_lisp alist = uim_scm_eval_c_string("plugin-alist");
-#if 0
-int
-uim_plugin_instance_query(struct _uim_plugin_info *info)
-{
- /* XXX: not implemented */
- return 0;
+ for(list_car = uim_scm_car(alist), list_cdr = uim_scm_cdr(alist);
+ list_car != uim_scm_f();
+ list_car = uim_scm_car(list_cdr), list_cdr = uim_scm_cdr(list_cdr))
+ {
+ uim_lisp name;
+ void *library;
+ void (*plugin_instance_quit)(void);
+
+ name = uim_scm_car(list_car);
+
+ UIM_EVAL_FSTRING1(NULL, "(plugin-list-query-library \"%s\")", uim_scm_c_str(name));
+ library = uim_scm_c_ptr(uim_scm_return_value());
+
+ UIM_EVAL_FSTRING1(NULL, "(plugin-list-query-instance-quit \"%s\")", uim_scm_c_str(name));
+ plugin_instance_quit = (void (*)(void))uim_scm_c_ptr(uim_scm_return_value());
+
+ (plugin_instance_quit)();
+ dlclose(library);
+ }
+#endif
}
-#endif
Modified: trunk/uim/plugin.h
===================================================================
--- trunk/uim/plugin.h 2005-01-10 00:36:34 UTC (rev 204)
+++ trunk/uim/plugin.h 2005-01-10 02:13:07 UTC (rev 205)
@@ -35,23 +35,6 @@
#ifndef _uim_plugin_h_included_
#define _uim_plugin_h_included_
-typedef struct _uim_plugin_info {
- char *name; /* XXX: should have in scm? */
- char *description; /* XXX: should have in scm? */
- char *author; /* XXX: should have in scm? */
- char *version; /* XXX: should have in scm? */
- void (*plugin_instance_init)(void);
- void (*plugin_instance_quit)(void);
- void *library;
- /* void *plugin_unload; */
-/* void *plugin_extra_funcs */
-} uim_plugin_info;
-
-typedef struct _plugin_list {
- uim_plugin_info *plugin;
- struct _plugin_list *next;
-} uim_plugin_info_list;
-
void uim_plugin_instance_init(void);
void uim_plugin_instance_quit(void);
More information about the Uim-commit
mailing list