[Groonga-commit] groonga/groonga [master] grn_proc_create() accepts -1

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Nov 19 11:13:34 JST 2012


Kouhei Sutou	2012-11-19 11:13:34 +0900 (Mon, 19 Nov 2012)

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

  Log:
    grn_proc_create() accepts -1
    
    It means that name is NULL terminated string. Name size is computed in
    grn_proc_create().

  Modified files:
    include/groonga.h
    lib/db.c
    lib/proc.c

  Modified: include/groonga.h (+3 -1)
===================================================================
--- include/groonga.h    2012-11-19 11:04:34 +0900 (8d50e7f)
+++ include/groonga.h    2012-11-19 11:13:34 +0900 (fb39a3a)
@@ -632,6 +632,8 @@ GRN_API const char *grn_plugin_get_suffix(void);
 /**
  * grn_proc_create:
  * @name: 作成するprocの名前。
+ * @name_size: The number of bytes of @name. If -1 is specified, @name
+ *             is handled as a NULL terminated string.
  * @type: procの種類。
  * @init: 初期化関数のポインタ
  * @next: 実処理関数のポインタ
@@ -658,7 +660,7 @@ typedef enum {
 } grn_proc_type;
 
 GRN_API grn_obj *grn_proc_create(grn_ctx *ctx,
-                                 const char *name, unsigned int name_size, grn_proc_type type,
+                                 const char *name, int name_size, grn_proc_type type,
                                  grn_proc_func *init, grn_proc_func *next, grn_proc_func *fin,
                                  unsigned int nvars, grn_expr_var *vars);
 /**

  Modified: lib/db.c (+4 -1)
===================================================================
--- lib/db.c    2012-11-19 11:04:34 +0900 (4a31490)
+++ lib/db.c    2012-11-19 11:13:34 +0900 (cab6c84)
@@ -532,7 +532,7 @@ grn_type_open(grn_ctx *ctx, grn_obj_spec *spec)
 }
 
 grn_obj *
-grn_proc_create(grn_ctx *ctx, const char *name, unsigned int name_size, grn_proc_type type,
+grn_proc_create(grn_ctx *ctx, const char *name, int name_size, grn_proc_type type,
                 grn_proc_func *init, grn_proc_func *next, grn_proc_func *fin,
                 unsigned int nvars, grn_expr_var *vars)
 {
@@ -548,6 +548,9 @@ grn_proc_create(grn_ctx *ctx, const char *name, unsigned int name_size, grn_proc
   }
   GRN_API_ENTER;
   range = path ? grn_plugin_get(ctx, path) : GRN_ID_NIL;
+  if (name && name_size == -1) {
+    name_size = strlen(name);
+  }
   if (grn_db_check_name(ctx, name, name_size)) {
     GRN_DB_CHECK_NAME_ERR("[proc][create]", name, name_size);
     GRN_API_RETURN(NULL);

  Modified: lib/proc.c (+12 -12)
===================================================================
--- lib/proc.c    2012-11-19 11:04:34 +0900 (6121d9c)
+++ lib/proc.c    2012-11-19 11:13:34 +0900 (ec012fb)
@@ -3446,53 +3446,53 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   DEF_COMMAND("truncate", proc_truncate, 1, vars);
 
   DEF_VAR(vars[0], "seed");
-  grn_proc_create(ctx, "rand", 4, GRN_PROC_FUNCTION, func_rand,
+  grn_proc_create(ctx, "rand", -1, GRN_PROC_FUNCTION, func_rand,
                   NULL, NULL, 0, vars);
 
-  grn_proc_create(ctx, "now", 3, GRN_PROC_FUNCTION, func_now,
+  grn_proc_create(ctx, "now", -1, GRN_PROC_FUNCTION, func_now,
                   NULL, NULL, 0, vars);
 
-  grn_proc_create(ctx, "max", 3, GRN_PROC_FUNCTION, func_max,
+  grn_proc_create(ctx, "max", -1, GRN_PROC_FUNCTION, func_max,
                   NULL, NULL, 0, vars);
-  grn_proc_create(ctx, "min", 3, GRN_PROC_FUNCTION, func_min,
+  grn_proc_create(ctx, "min", -1, GRN_PROC_FUNCTION, func_min,
                   NULL, NULL, 0, vars);
 
   {
     grn_obj *selector_proc;
 
-    selector_proc = grn_proc_create(ctx, "geo_in_circle", 13, GRN_PROC_FUNCTION,
+    selector_proc = grn_proc_create(ctx, "geo_in_circle", -1, GRN_PROC_FUNCTION,
                                     func_geo_in_circle, NULL, NULL, 0, NULL);
     grn_proc_set_selector(ctx, selector_proc, grn_selector_geo_in_circle);
 
-    selector_proc = grn_proc_create(ctx, "geo_in_rectangle", 16,
+    selector_proc = grn_proc_create(ctx, "geo_in_rectangle", -1,
                                     GRN_PROC_FUNCTION,
                                     func_geo_in_rectangle, NULL, NULL, 0, NULL);
     grn_proc_set_selector(ctx, selector_proc, grn_selector_geo_in_rectangle);
   }
 
-  grn_proc_create(ctx, "geo_distance", 12, GRN_PROC_FUNCTION,
+  grn_proc_create(ctx, "geo_distance", -1, GRN_PROC_FUNCTION,
                   func_geo_distance, NULL, NULL, 0, NULL);
 
   /* deprecated. */
-  grn_proc_create(ctx, "geo_distance2", 13, GRN_PROC_FUNCTION,
+  grn_proc_create(ctx, "geo_distance2", -1, GRN_PROC_FUNCTION,
                   func_geo_distance2, NULL, NULL, 0, NULL);
 
   /* deprecated. */
-  grn_proc_create(ctx, "geo_distance3", 13, GRN_PROC_FUNCTION,
+  grn_proc_create(ctx, "geo_distance3", -1, GRN_PROC_FUNCTION,
                   func_geo_distance3, NULL, NULL, 0, NULL);
 
-  grn_proc_create(ctx, "edit_distance", 13, GRN_PROC_FUNCTION,
+  grn_proc_create(ctx, "edit_distance", -1, GRN_PROC_FUNCTION,
                   func_edit_distance, NULL, NULL, 0, NULL);
 
   {
     grn_obj *selector_proc;
 
-    selector_proc = grn_proc_create(ctx, "all_records", 11, GRN_PROC_FUNCTION,
+    selector_proc = grn_proc_create(ctx, "all_records", -1, GRN_PROC_FUNCTION,
                                     func_all_records, NULL, NULL, 0, NULL);
     grn_proc_set_selector(ctx, selector_proc, selector_all_records);
   }
 
   /* experimental */
-  grn_proc_create(ctx, "snippet_html", 12, GRN_PROC_FUNCTION,
+  grn_proc_create(ctx, "snippet_html", -1, GRN_PROC_FUNCTION,
                   func_snippet_html, NULL, NULL, 0, NULL);
 }
-------------- next part --------------
HTML����������������������������...
Download 



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