[Groonga-commit] groonga/groonga at 3005430 [master] Extract object_exist command code

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 8 17:00:08 JST 2016


Kouhei Sutou	2016-02-08 17:00:08 +0900 (Mon, 08 Feb 2016)

  New Revision: 3005430e0b555d78218af5257ff24884b05ae070
  https://github.com/groonga/groonga/commit/3005430e0b555d78218af5257ff24884b05ae070

  Message:
    Extract object_exist command code

  Added files:
    lib/proc/proc_object.c
  Modified files:
    lib/grn_proc.h
    lib/proc.c
    lib/proc/sources.am

  Modified: lib/grn_proc.h (+1 -0)
===================================================================
--- lib/grn_proc.h    2016-02-08 16:24:59 +0900 (e1896cf)
+++ lib/grn_proc.h    2016-02-08 17:00:08 +0900 (17368cf)
@@ -39,6 +39,7 @@ void grn_proc_init_inspect(grn_ctx *ctx);
 void grn_proc_init_lock_acquire(grn_ctx *ctx);
 void grn_proc_init_lock_clear(grn_ctx *ctx);
 void grn_proc_init_lock_release(grn_ctx *ctx);
+void grn_proc_init_object_exist(grn_ctx *ctx);
 void grn_proc_init_schema(grn_ctx *ctx);
 void grn_proc_init_table_create(grn_ctx *ctx);
 void grn_proc_init_table_list(grn_ctx *ctx);

  Modified: lib/proc.c (+1 -30)
===================================================================
--- lib/proc.c    2016-02-08 16:24:59 +0900 (b0df3e6)
+++ lib/proc.c    2016-02-08 17:00:08 +0900 (86e0686)
@@ -6257,34 +6257,6 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 }
 
 static grn_obj *
-proc_object_exist(grn_ctx *ctx, int nargs, grn_obj **args,
-                  grn_user_data *user_data)
-{
-  grn_obj *db;
-  grn_obj *name;
-  grn_id id;
-
-  db = grn_ctx_db(ctx);
-  if (!db) {
-    ERR(GRN_INVALID_ARGUMENT, "[object_exist] DB isn't opened");
-    return NULL;
-  }
-
-  name = VAR(0);
-  if (GRN_TEXT_LEN(name) == 0) {
-    ERR(GRN_INVALID_ARGUMENT, "[object_exist] name is missing");
-    GRN_OUTPUT_BOOL(GRN_FALSE);
-    return NULL;
-  }
-
-  id = grn_table_get(ctx, db,
-                     GRN_TEXT_VALUE(name),
-                     GRN_TEXT_LEN(name));
-  GRN_OUTPUT_BOOL(id != GRN_ID_NIL);
-  return NULL;
-}
-
-static grn_obj *
 proc_thread_limit(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
   grn_obj *max_bulk;
@@ -7013,8 +6985,7 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   DEF_VAR(vars[1], "recursive");
   DEF_COMMAND("io_flush", proc_io_flush, 2, vars);
 
-  DEF_VAR(vars[0], "name");
-  DEF_COMMAND("object_exist", proc_object_exist, 1, vars);
+  grn_proc_init_object_exist(ctx);
 
   DEF_VAR(vars[0], "max");
   DEF_COMMAND("thread_limit", proc_thread_limit, 1, vars);

  Added: lib/proc/proc_object.c (+66 -0) 100644
===================================================================
--- /dev/null
+++ lib/proc/proc_object.c    2016-02-08 17:00:08 +0900 (f183a66)
@@ -0,0 +1,66 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2009-2016 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
+*/
+
+#include "../grn_proc.h"
+
+#include <groonga/plugin.h>
+
+static grn_obj *
+command_object_exist(grn_ctx *ctx,
+                     int nargs,
+                     grn_obj **args,
+                     grn_user_data *user_data)
+{
+  grn_obj *db;
+  grn_obj *name;
+  grn_id id;
+
+  db = grn_ctx_db(ctx);
+  if (!db) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[object_exist] DB isn't opened");
+    return NULL;
+  }
+
+  name = grn_plugin_proc_get_var(ctx, user_data, "name", -1);
+  if (GRN_TEXT_LEN(name) == 0) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[object_exist] name is missing");
+    grn_ctx_output_bool(ctx, GRN_FALSE);
+    return NULL;
+  }
+
+  id = grn_table_get(ctx, db,
+                     GRN_TEXT_VALUE(name),
+                     GRN_TEXT_LEN(name));
+  grn_ctx_output_bool(ctx, id != GRN_ID_NIL);
+  return NULL;
+}
+
+void
+grn_proc_init_object_exist(grn_ctx *ctx)
+{
+  grn_expr_var vars[1];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "name", -1);
+  grn_plugin_command_create(ctx,
+                            "object_exist", -1,
+                            command_object_exist,
+                            1,
+                            vars);
+}

  Modified: lib/proc/sources.am (+1 -0)
===================================================================
--- lib/proc/sources.am    2016-02-08 16:24:59 +0900 (98b27a9)
+++ lib/proc/sources.am    2016-02-08 17:00:08 +0900 (cfeff43)
@@ -3,5 +3,6 @@ libgrnproc_la_SOURCES =				\
 	proc_fuzzy_search.c			\
 	proc_inspect.c				\
 	proc_lock.c				\
+	proc_object.c				\
 	proc_schema.c				\
 	proc_table.c
-------------- next part --------------
HTML����������������������������...
Download 



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