[Groonga-commit] groonga/groonga at 3d3d4c3 [master] cast_loose: support default value

Back to archive index
Kouhei Sutou null+****@clear*****
Thu Oct 11 15:14:33 JST 2018


Kouhei Sutou	2018-10-11 15:14:33 +0900 (Thu, 11 Oct 2018)

  Revision: 3d3d4c32162a1770a7b67f127da1d0dd7dd4d5da
  https://github.com/groonga/groonga/commit/3d3d4c32162a1770a7b67f127da1d0dd7dd4d5da

  Message:
    cast_loose: support default value

  Modified files:
    lib/proc/proc_cast.c

  Modified: lib/proc/proc_cast.c (+9 -4)
===================================================================
--- lib/proc/proc_cast.c    2018-10-11 15:06:25 +0900 (ca1443e0b)
+++ lib/proc/proc_cast.c    2018-10-11 15:14:33 +0900 (6e560bb39)
@@ -27,14 +27,19 @@ func_cast_loose(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_dat
   grn_obj *casted_value = NULL;
 
   if (nargs == 3) {
-    grn_obj *cast_type = args[0];
+    grn_obj *type = args[0];
     grn_obj *cast_value = args[1];
     grn_obj *default_value = args[2];
+    grn_id type_id;
+    grn_rc rc;
 
-    casted_value =
-      grn_plugin_proc_alloc(ctx, user_data, grn_obj_id(ctx, cast_type), 0);
+    type_id = grn_obj_id(ctx, type);
+    casted_value = grn_plugin_proc_alloc(ctx, user_data, type_id, 0);
 
-    grn_obj_cast(ctx, cast_value, casted_value, GRN_FALSE);
+    rc = grn_obj_cast(ctx, cast_value, casted_value, GRN_FALSE);
+    if (rc != GRN_SUCCESS) {
+      grn_obj_cast(ctx, default_value, casted_value, GRN_FALSE);
+    }
   }
 
   return casted_value;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181011/a407495a/attachment-0001.html>


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