[Groonga-commit] groonga/groonga [module] use the same name for all module exported function. #624

Back to archive index

null+****@clear***** null+****@clear*****
2011年 2月 8日 (火) 16:37:40 JST


Kouhei Sutou	2010-10-22 03:37:57 +0000 (Fri, 22 Oct 2010)

  New Revision: 545baa5f58d1afb990d9061edc5be1ebdb7596fd

  Log:
    use the same name for all module exported function. #624

  Added files:
    lib/module_impl.h
  Modified files:
    lib/Makefile.am
    lib/module.c
    modules/suggest/suggest.c
    modules/tokenizers/mecab.c
    test/unit/fixtures/modules/string.c

  Modified: lib/Makefile.am (+3 -0)
===================================================================
--- lib/Makefile.am    2010-10-22 03:35:18 +0000 (4cfd42f)
+++ lib/Makefile.am    2010-10-22 03:37:57 +0000 (22b6ac6)
@@ -14,6 +14,9 @@ libgroonga_la_LDFLAGS =				\
 
 noinst_HEADERS = com.h io.h ql.h nfkc.h groonga_in.h snip.h store.h str.h ctx.h hash.h db.h pat.h ii.h token.h proc.h util.h module.h output.h geo.h
 
+groonga_includedir = $(pkgincludedir)/groonga
+groonga_include_HEADERS = module_impl.h
+
 EXTRA_DIST = ecmascript.c ecmascript.h ecmascript.y
 
 CLEANFILES = *.gcno *.gcda

  Modified: lib/module.c (+6 -25)
===================================================================
--- lib/module.c    2010-10-22 03:35:18 +0000 (7704d20)
+++ lib/module.c    2010-10-22 03:37:57 +0000 (dbdf9c7)
@@ -20,7 +20,6 @@
 #include "db.h"
 #include "module.h"
 #include "ql.h"
-#include "module.h"
 
 static grn_hash *grn_modules = NULL;
 
@@ -36,7 +35,7 @@ static grn_hash *grn_modules = NULL;
 #  define grn_dl_clear_error
 #else
 #  include <dlfcn.h>
-#  define grn_dl_open(filename)    dlopen(filename, RTLD_LAZY | RTLD_GLOBAL)
+#  define grn_dl_open(filename)    dlopen(filename, RTLD_LAZY | RTLD_LOCAL)
 #  define grn_dl_open_error_label  dlerror()
 #  define grn_dl_close(dl)         (dlclose(dl) == 0)
 #  define grn_dl_close_error_label dlerror()
@@ -58,35 +57,17 @@ grn_module_path(grn_ctx *ctx, grn_id id)
   return _grn_hash_key(ctx, grn_modules, id, &key_size);
 }
 
-#define GRN_MODULE_FUNC_PREFIX "grn_module_"
+#define GRN_MODULE_FUNC_PREFIX "grn_module_impl_"
 
 static grn_rc
 grn_module_initialize(grn_ctx *ctx, grn_module *module,
                       grn_dl dl, grn_id id, const char *path)
 {
-  const char *base_name, *extension;
-  char init_func_name[PATH_MAX];
-  char register_func_name[PATH_MAX];
-  char fin_func_name[PATH_MAX];
-
-  base_name = extension = path + strlen(path);
-  for (; path < base_name; base_name--) {
-    if (*base_name == '.') {
-      extension = base_name;
-    }
-    if (*base_name == PATH_SEPARATOR[0]) {
-      base_name++;
-      break;
-    }
-  }
-
   module->dl = dl;
 
 #define GET_SYMBOL(type)                                                \
-  strcpy(type ## _func_name, GRN_MODULE_FUNC_PREFIX #type "_");         \
-  strncat(type ## _func_name, base_name, extension - base_name);        \
   grn_dl_clear_error;                                                   \
-  module->type ## _func = grn_dl_sym(dl, type ## _func_name);           \
+  module->type ## _func = grn_dl_sym(dl, GRN_MODULE_FUNC_PREFIX #type); \
   if (!module->type ## _func) {                                         \
     const char *label;                                                  \
     label = grn_dl_sym_error_label;                                     \
@@ -104,9 +85,9 @@ grn_module_initialize(grn_ctx *ctx, grn_module *module,
         "init func (%s) %sfound, "
         "register func (%s) %sfound and "
         "fin func (%s) %sfound",
-        init_func_name, module->init_func ? "" : "not ",
-        register_func_name, module->register_func ? "" : "not ",
-        fin_func_name, module->fin_func ? "" : "not ");
+        GRN_MODULE_FUNC_PREFIX "init", module->init_func ? "" : "not ",
+        GRN_MODULE_FUNC_PREFIX "register", module->register_func ? "" : "not ",
+        GRN_MODULE_FUNC_PREFIX "fin", module->fin_func ? "" : "not ");
   }
 
   if (!ctx->rc) {

  Added: lib/module_impl.h (+44 -0) 100644
===================================================================
--- /dev/null
+++ lib/module_impl.h    2010-10-22 03:37:57 +0000 (77afa12)
@@ -0,0 +1,44 @@
+/* -*- c-basic-offset: 2 -*- */
+/* Copyright(C) 2010 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+#ifndef GRN_MODULE_IMPL_H
+#define GRN_MODULE_IMPL_H
+
+#include "groonga.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GRN_MODULE_INIT grn_module_impl_init
+#define GRN_MODULE_REGISTER grn_module_impl_register
+#define GRN_MODULE_FIN grn_module_impl_fin
+
+#if defined(_WIN32) || defined(_WIN64)
+#  define GRN_MODULE_EXPORT __declspec(dllexpoert)
+#else /* defined(_WIN32) || defined(_WIN64) */
+#  define GRN_MODULE_EXPORT
+#endif /* defined(_WIN32) || defined(_WIN64) */
+
+GRN_MODULE_EXPORT grn_rc GRN_MODULE_INIT(grn_ctx *ctx);
+GRN_MODULE_EXPORT grn_rc GRN_MODULE_REGISTER(grn_ctx *ctx);
+GRN_MODULE_EXPORT grn_rc GRN_MODULE_FIN(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_MODULE_IMPL_H */

  Modified: modules/suggest/suggest.c (+4 -8)
===================================================================
--- modules/suggest/suggest.c    2010-10-22 03:35:18 +0000 (a0d7f9b)
+++ modules/suggest/suggest.c    2010-10-22 03:37:57 +0000 (5850e5a)
@@ -20,6 +20,7 @@
 #include "ii.h"
 #include "token.h"
 #include "output.h"
+#include "module_impl.h"
 #include <string.h>
 
 #define VAR GRN_PROC_GET_VAR_BY_OFFSET
@@ -506,19 +507,14 @@ func_suggest_preparer(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *us
   return obj;
 }
 
-/* todo : should be replaced to simple macro call */
-GRN_API grn_rc grn_module_init_suggest(grn_ctx *ctx);
-GRN_API grn_rc grn_module_register_suggest(grn_ctx *ctx);
-GRN_API grn_rc grn_module_fin_suggest(grn_ctx *ctx);
-
 grn_rc
-grn_module_init_suggest(grn_ctx *ctx)
+GRN_MODULE_INIT(grn_ctx *ctx)
 {
   return GRN_SUCCESS;
 }
 
 grn_rc
-grn_module_register_suggest(grn_ctx *ctx)
+GRN_MODULE_REGISTER(grn_ctx *ctx)
 {
   /* TODO: offset/limit */
   grn_expr_var vars[] = {
@@ -548,7 +544,7 @@ grn_module_register_suggest(grn_ctx *ctx)
 }
 
 grn_rc
-grn_module_fin_suggest(grn_ctx *ctx)
+GRN_MODULE_FIN(grn_ctx *ctx)
 {
   return GRN_SUCCESS;
 }

  Modified: modules/tokenizers/mecab.c (+5 -8)
===================================================================
--- modules/tokenizers/mecab.c    2010-10-22 03:35:18 +0000 (2de0ffc)
+++ modules/tokenizers/mecab.c    2010-10-22 03:37:57 +0000 (9c24f09)
@@ -21,6 +21,8 @@
 #include <str.h>
 #include <token.h>
 
+#include <module_impl.h>
+
 #include <mecab.h>
 
 #include <string.h>
@@ -199,13 +201,8 @@ check_mecab_dictionary_encoding(grn_ctx *ctx)
 #endif
 }
 
-/* todo : should be replaced to simple macro call */
-GRN_API grn_rc grn_module_init_mecab(grn_ctx *ctx);
-GRN_API grn_rc grn_module_register_mecab(grn_ctx *ctx);
-GRN_API grn_rc grn_module_fin_mecab(grn_ctx *ctx);
-
 grn_rc
-grn_module_init_mecab(grn_ctx *ctx)
+GRN_MODULE_INIT(grn_ctx *ctx)
 {
   sole_mecab = NULL;
   CRITICAL_SECTION_INIT(sole_mecab_lock);
@@ -216,7 +213,7 @@ grn_module_init_mecab(grn_ctx *ctx)
 }
 
 grn_rc
-grn_module_register_mecab(grn_ctx *ctx)
+GRN_MODULE_REGISTER(grn_ctx *ctx)
 {
   grn_obj *obj;
   grn_expr_var vars[] = {
@@ -236,7 +233,7 @@ grn_module_register_mecab(grn_ctx *ctx)
 }
 
 grn_rc
-grn_module_fin_mecab(grn_ctx *ctx)
+GRN_MODULE_FIN(grn_ctx *ctx)
 {
   if (sole_mecab) {
     mecab_destroy(sole_mecab);

  Modified: test/unit/fixtures/modules/string.c (+5 -4)
===================================================================
--- test/unit/fixtures/modules/string.c    2010-10-22 03:35:18 +0000 (69b59e8)
+++ test/unit/fixtures/modules/string.c    2010-10-22 03:37:57 +0000 (7aca6b2)
@@ -18,7 +18,8 @@
 
 #include <string.h>
 
-#include "str.h"
+#include <str.h>
+#include <module_impl.h>
 
 static grn_obj *
 func_str_len(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
@@ -44,13 +45,13 @@ func_str_len(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 }
 
 grn_rc
-grn_module_init_string(grn_ctx *ctx)
+GRN_MODULE_INIT(grn_ctx *ctx)
 {
   return GRN_SUCCESS;
 }
 
 grn_rc
-grn_module_register_string(grn_ctx *ctx)
+GRN_MODULE_REGISTER(grn_ctx *ctx)
 {
   grn_proc_create(ctx, "str_len", strlen("str_len"), GRN_PROC_FUNCTION,
                   func_str_len, NULL, NULL, 0, NULL);
@@ -59,7 +60,7 @@ grn_module_register_string(grn_ctx *ctx)
 }
 
 grn_rc
-grn_module_fin_string(grn_ctx *ctx)
+GRN_MODULE_FIN(grn_ctx *ctx)
 {
   return GRN_SUCCESS;
 }




Groonga-commit メーリングリストの案内
Back to archive index