[Groonga-commit] groonga/groonga at a0ae39c [mrb-bind-dump-command] mrb: try to bind dump command to replace by mruby (work in progress)

Back to archive index

Masafumi Yokoyama null+****@clear*****
Mon Feb 23 16:20:27 JST 2015


Masafumi Yokoyama	2015-02-23 16:20:27 +0900 (Mon, 23 Feb 2015)

  New Revision: a0ae39cd2f0d478aab0aaa5d204bf205b788e647
  https://github.com/groonga/groonga/commit/a0ae39cd2f0d478aab0aaa5d204bf205b788e647

  Message:
    mrb: try to bind dump command to replace by mruby (work in progress)

  Added files:
    lib/grn_command.h
    plugins/dump.rb
    plugins/dump/Makefile.am
    plugins/dump/dump.rb
    plugins/dump/sources.am
  Copied files:
    plugins/dump/CMakeLists.txt
      (from plugins/CMakeLists.txt)
  Modified files:
    configure.ac
    lib/command.c
    lib/db.c
    lib/proc.c
    lib/sources.am
    plugins/CMakeLists.txt
    plugins/Makefile.am
    plugins/ruby_scripts.am

  Modified: configure.ac (+4 -0)
===================================================================
--- configure.ac    2015-02-23 17:21:46 +0900 (1d74bac)
+++ configure.ac    2015-02-23 16:20:27 +0900 (1e46162)
@@ -236,6 +236,7 @@ AC_CONFIG_FILES([
   plugins/ruby/Makefile
   plugins/token_filters/Makefile
   plugins/sharding/Makefile
+  plugins/dump/Makefile
   examples/Makefile
   examples/dictionary/Makefile
   examples/dictionary/edict/Makefile
@@ -1347,6 +1348,9 @@ AC_SUBST(token_filter_pluginsdir)
 sharding_pluginsdir="\${pluginsdir}/sharding"
 AC_SUBST(sharding_pluginsdir)
 
+dump_pluginsdir="\${pluginsdir}/dump"
+AC_SUBST(dump_pluginsdir)
+
 AC_MSG_CHECKING(for the suffix of plugin shared libraries)
 shrext_cmds=$(./libtool --config | grep '^shrext_cmds=')
 eval $shrext_cmds

  Modified: lib/command.c (+16 -0)
===================================================================
--- lib/command.c    2015-02-23 17:21:46 +0900 (b0f7522)
+++ lib/command.c    2015-02-23 16:20:27 +0900 (0c3878e)
@@ -21,6 +21,7 @@
 #include "grn.h"
 #include "grn_db.h"
 #include "grn_ctx_impl.h"
+#include "grn_plugin.h"
 
 struct _grn_command_input {
   grn_obj *command;
@@ -192,3 +193,18 @@ grn_command_run(grn_ctx *ctx,
   GRN_API_RETURN(ctx->rc);
 }
 
+#ifdef GRN_WITH_MRUBY
+grn_rc
+grn_db_init_dump_command(grn_ctx *ctx)
+{
+  const char *dump_plugin_name = "dump/dump";
+  char *path;
+  path = grn_plugin_find_path(ctx, dump_plugin_name);
+  if (path) {
+    GRN_FREE(path);
+    return grn_plugin_register(ctx, dump_plugin_name);
+  } else {
+    return GRN_NO_SUCH_FILE_OR_DIRECTORY;
+  }
+}
+#endif /* GRN_WITH_MRUBY */

  Modified: lib/db.c (+6 -0)
===================================================================
--- lib/db.c    2015-02-23 17:21:46 +0900 (681d0d9)
+++ lib/db.c    2015-02-23 16:20:27 +0900 (190fbdf)
@@ -25,6 +25,7 @@
 #include "grn_tokenizers.h"
 #include "grn_proc.h"
 #include "grn_plugin.h"
+#include "grn_command.h"
 #include "grn_geo.h"
 #include "grn_scorers.h"
 #include "grn_snip.h"
@@ -258,6 +259,11 @@ grn_db_open(grn_ctx *ctx, const char *path)
             ERRCLR(ctx);
           }
 #endif
+#ifdef GRN_WITH_MRUBY
+          if (grn_db_init_dump_command(ctx)) {
+            ERRCLR(ctx);
+          }
+#endif
           grn_db_init_builtin_tokenizers(ctx);
           grn_db_init_builtin_normalizers(ctx);
           grn_db_init_builtin_scorers(ctx);

  Added: lib/grn_command.h (+32 -0) 100644
===================================================================
--- /dev/null
+++ lib/grn_command.h    2015-02-23 16:20:27 +0900 (2401385)
@@ -0,0 +1,32 @@
+/* -*- c-basic-offset: 2 -*- */
+/* Copyright(C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef GRN_COMMAND_H
+#define GRN_COMMAND_H
+
+#include "grn_ctx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+grn_rc grn_db_init_dump_command(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_COMMAND_H */

  Modified: lib/proc.c (+4 -0)
===================================================================
--- lib/proc.c    2015-02-23 17:21:46 +0900 (68885fb)
+++ lib/proc.c    2015-02-23 16:20:27 +0900 (e1aadde)
@@ -3226,6 +3226,7 @@ dump_all_records(grn_ctx *ctx, grn_obj *outbuf)
   }
 }
 
+#ifndef GRN_WITH_MRUBY
 static grn_obj *
 proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
@@ -3251,6 +3252,7 @@ proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
   }
   return NULL;
 }
+#endif /* GRN_WITH_MRUBY */
 
 static grn_obj *
 proc_cache_limit(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
@@ -6557,8 +6559,10 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   DEF_VAR(vars[0], "max");
   DEF_COMMAND("cache_limit", proc_cache_limit, 1, vars);
 
+#ifndef GRN_WITH_MRUBY
   DEF_VAR(vars[0], "tables");
   DEF_COMMAND("dump", proc_dump, 1, vars);
+#endif /*GRN_WITH_MRUBY */
 
   DEF_VAR(vars[0], "path");
   DEF_COMMAND("register", proc_register, 1, vars);

  Modified: lib/sources.am (+1 -0)
===================================================================
--- lib/sources.am    2015-02-23 17:21:46 +0900 (25e5df5)
+++ lib/sources.am    2015-02-23 16:20:27 +0900 (20cbe17)
@@ -2,6 +2,7 @@ libgroonga_la_SOURCES =				\
 	com.c					\
 	grn_com.h				\
 	command.c				\
+	grn_command.h				\
 	ctx.c					\
 	grn_ctx.h				\
 	grn_ctx_impl.h				\

  Modified: plugins/CMakeLists.txt (+1 -0)
===================================================================
--- plugins/CMakeLists.txt    2015-02-23 17:21:46 +0900 (89a28f5)
+++ plugins/CMakeLists.txt    2015-02-23 16:20:27 +0900 (bd89438)
@@ -20,6 +20,7 @@ add_subdirectory(query_expanders)
 add_subdirectory(ruby)
 add_subdirectory(token_filters)
 add_subdirectory(sharding)
+add_subdirectory(dump)
 
 if(GRN_WITH_MRUBY)
   read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/ruby_scripts.am RUBY_SCRIPTS)

  Modified: plugins/Makefile.am (+2 -1)
===================================================================
--- plugins/Makefile.am    2015-02-23 17:21:46 +0900 (92007ed)
+++ plugins/Makefile.am    2015-02-23 16:20:27 +0900 (f089883)
@@ -5,7 +5,8 @@ SUBDIRS =					\
 	query_expanders				\
 	ruby					\
 	token_filters				\
-	sharding
+	sharding				\
+	dump
 
 EXTRA_DIST =					\
 	CMakeLists.txt

  Added: plugins/dump.rb (+1 -0) 100644
===================================================================
--- /dev/null
+++ plugins/dump.rb    2015-02-23 16:20:27 +0900 (4fc99db)
@@ -0,0 +1 @@
+require "dump/dump"

  Copied: plugins/dump/CMakeLists.txt (+6 -12) 64%
===================================================================
--- plugins/CMakeLists.txt    2015-02-23 17:21:46 +0900 (89a28f5)
+++ plugins/dump/CMakeLists.txt    2015-02-23 16:20:27 +0900 (dc5030d)
@@ -1,4 +1,4 @@
-# Copyright(C) 2012-2015 Brazil
+# Copyright(C) 2015 Brazil
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -13,16 +13,10 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-add_subdirectory(suggest)
-add_subdirectory(tokenizers)
-add_subdirectory(table)
-add_subdirectory(query_expanders)
-add_subdirectory(ruby)
-add_subdirectory(token_filters)
-add_subdirectory(sharding)
-
 if(GRN_WITH_MRUBY)
-  read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/ruby_scripts.am RUBY_SCRIPTS)
-  install(FILES ${RUBY_SCRIPTS}
-    DESTINATION "${GRN_RELATIVE_PLUGINS_DIR}")
+  set(GRN_RELATIVE_DUMP_PLUGINS_DIR "${GRN_RELATIVE_PLUGINS_DIR}/dump")
+
+  read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/sources.am DUMP_SCRIPTS)
+  install(FILES ${DUMP_SCRIPTS}
+    DESTINATION "${GRN_RELATIVE_DUMP_PLUGINS_DIR}")
 endif()

  Added: plugins/dump/Makefile.am (+9 -0) 100644
===================================================================
--- /dev/null
+++ plugins/dump/Makefile.am    2015-02-23 16:20:27 +0900 (79dd8e9)
@@ -0,0 +1,9 @@
+EXTRA_DIST =					\
+	CMakeLists.txt
+
+if WITH_MRUBY
+dist_dump_plugins_DATA =			\
+	$(dump_scripts)
+endif
+
+include sources.am

  Added: plugins/dump/dump.rb (+13 -0) 100644
===================================================================
--- /dev/null
+++ plugins/dump/dump.rb    2015-02-23 16:20:27 +0900 (d1e25a7)
@@ -0,0 +1,13 @@
+module Groonga
+  module Dump
+    class DumpCommand < Command
+      register("dump",
+               [
+               ])
+
+      def run_body(input)
+        writer.write("dump test")
+      end
+    end
+  end
+end

  Added: plugins/dump/sources.am (+2 -0) 100644
===================================================================
--- /dev/null
+++ plugins/dump/sources.am    2015-02-23 16:20:27 +0900 (516b732)
@@ -0,0 +1,2 @@
+dump_scripts =				\
+	dump.rb

  Modified: plugins/ruby_scripts.am (+2 -1)
===================================================================
--- plugins/ruby_scripts.am    2015-02-23 17:21:46 +0900 (0262dbb)
+++ plugins/ruby_scripts.am    2015-02-23 16:20:27 +0900 (30d48d3)
@@ -1,2 +1,3 @@
 ruby_scripts =				\
-	sharding.rb
+	sharding.rb				\
+	dump.rb
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index