[Groonga-commit] groonga/groonga at 394825f [master] grn_obj_cast: return GRN_INVALID_ARGUMENT for not found record

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 22 19:08:53 JST 2015


Kouhei Sutou	2015-04-22 19:08:53 +0900 (Wed, 22 Apr 2015)

  New Revision: 394825f1ac04757c20d70e8eb7c668147ea4f57a
  https://github.com/groonga/groonga/commit/394825f1ac04757c20d70e8eb7c668147ea4f57a

  Message:
    grn_obj_cast: return GRN_INVALID_ARGUMENT for not found record
    
    It's not a problem but it may be backward incompatible...
    How to test it...?

  Modified files:
    lib/db.c
    lib/expr.c
    test/unit/core/test-cast-table.c

  Modified: lib/db.c (+10 -2)
===================================================================
--- lib/db.c    2015-04-22 18:47:14 +0900 (0b18a3c)
+++ lib/db.c    2015-04-22 19:08:53 +0900 (357df82)
@@ -5243,7 +5243,11 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
       if (GRN_BULK_VSIZE(p_key)) {\
         id = addp ? grn_table_add_by_key(ctx, table, p_key, NULL)\
                   : grn_table_get_by_key(ctx, table, p_key);\
-        if (id) { GRN_RECORD_SET(ctx, dest, id); }\
+        if (id) {\
+          GRN_RECORD_SET(ctx, dest, id);\
+        } else {\
+          rc = GRN_INVALID_ARGUMENT;\
+        }\
       } else {\
         GRN_RECORD_SET(ctx, dest, GRN_ID_NIL);\
       }\
@@ -5253,7 +5257,11 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
       GRN_UINT32_INIT(&record_id, 0);\
       grn_obj_cast(ctx, src, &record_id, GRN_TRUE);\
       id = GRN_UINT32_VALUE(&record_id);\
-      if (id) { GRN_RECORD_SET(ctx, dest, id); }\
+      if (id) {\
+        GRN_RECORD_SET(ctx, dest, id);\
+      } else {\
+        rc = GRN_INVALID_ARGUMENT;\
+      }\
     }\
   } else {\
     rc = GRN_FUNCTION_NOT_IMPLEMENTED;\

  Modified: lib/expr.c (+1 -2)
===================================================================
--- lib/expr.c    2015-04-22 18:47:14 +0900 (07e2408)
+++ lib/expr.c    2015-04-22 19:08:53 +0900 (08a8b0a)
@@ -728,8 +728,7 @@ grn_expr_append_obj_resolve_const(grn_ctx *ctx,
   grn_obj dest;
 
   GRN_OBJ_INIT(&dest, GRN_BULK, 0, to_domain);
-  if (!grn_obj_cast(ctx, obj, &dest, GRN_FALSE) &&
-      GRN_BULK_VSIZE(&dest) > 0) {
+  if (!grn_obj_cast(ctx, obj, &dest, GRN_FALSE)) {
     grn_obj_reinit(ctx, obj, to_domain, 0);
     grn_bulk_write(ctx, obj, GRN_BULK_HEAD(&dest), GRN_BULK_VSIZE(&dest));
   }

  Modified: test/unit/core/test-cast-table.c (+5 -3)
===================================================================
--- test/unit/core/test-cast-table.c    2015-04-22 18:47:14 +0900 (ec7b7d3)
+++ test/unit/core/test-cast-table.c    2015-04-22 19:08:53 +0900 (74abdfd)
@@ -122,13 +122,14 @@ cut_teardown(void)
 }
 
 static void
-cast_text(const gchar *text)
+cast_text(grn_rc expected_rc, const gchar *text)
 {
   grn_obj_reinit(&context, &src, GRN_DB_TEXT, 0);
   if (text) {
     GRN_TEXT_PUTS(&context, &src, text);
   }
-  grn_test_assert(grn_obj_cast(&context, &src, &dest, GRN_FALSE));
+  grn_test_assert_equal_rc(expected_rc,
+                           grn_obj_cast(&context, &src, &dest, GRN_FALSE));
 }
 
 void
@@ -154,11 +155,12 @@ test_text_to_table(gconstpointer data)
   gsize expected_size;
 
   grn_obj_reinit(&context, &dest, users, 0);
-  cast_text(gcut_data_get_string(data, "text"));
   expected_size = gcut_data_get_size(data, "expected-size");
   if (expected_size == 0) {
+    cast_text(GRN_INVALID_ARGUMENT, gcut_data_get_string(data, "text"));
     cut_assert_equal_uint(0, GRN_BULK_VSIZE(&dest));
   } else {
+    cast_text(GRN_SUCCESS, gcut_data_get_string(data, "text"));
     grn_test_assert_equal_record_id(&context,
                                     grn_ctx_at(&context, users),
                                     gcut_data_get_uint(data, "expected"),
-------------- next part --------------
HTML����������������������������...
다운로드 



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