[Groonga-commit] groonga/groonga at 2116f2b [master] table_create: simplify error handling

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 28 16:50:16 JST 2018


Kouhei Sutou	2018-03-28 16:50:16 +0900 (Wed, 28 Mar 2018)

  New Revision: 2116f2b8b0aec8f478b20fa50f17e6e43322d12a
  https://github.com/groonga/groonga/commit/2116f2b8b0aec8f478b20fa50f17e6e43322d12a

  Message:
    table_create: simplify error handling

  Modified files:
    lib/proc/proc_table.c

  Modified: lib/proc/proc_table.c (+16 -7)
===================================================================
--- lib/proc/proc_table.c    2018-03-28 16:23:53 +0900 (e37ae1ed0)
+++ lib/proc/proc_table.c    2018-03-28 16:50:16 +0900 (589f76e65)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2009-2016 Brazil
+  Copyright(C) 2009-2018 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -297,12 +297,12 @@ command_table_create(grn_ctx *ctx,
                          GRN_TEXT_VALUE(name),
                          (int)GRN_TEXT_LEN(default_tokenizer_name),
                          GRN_TEXT_VALUE(default_tokenizer_name));
-        grn_obj_remove(ctx, table);
         goto exit;
       }
       grn_obj_set_info(ctx, table,
                        GRN_INFO_DEFAULT_TOKENIZER,
                        default_tokenizer);
+      grn_obj_unlink(ctx, default_tokenizer);
     }
 
     if (GRN_TEXT_LEN(normalizer_name) > 0) {
@@ -320,22 +320,31 @@ command_table_create(grn_ctx *ctx,
                          GRN_TEXT_VALUE(name),
                          (int)GRN_TEXT_LEN(normalizer_name),
                          GRN_TEXT_VALUE(normalizer_name));
-        grn_obj_remove(ctx, table);
         goto exit;
       }
       grn_obj_set_info(ctx, table, GRN_INFO_NORMALIZER, normalizer);
+      grn_obj_unlink(ctx, normalizer);
     }
 
     if (!grn_proc_table_set_token_filters(ctx, table, token_filters_name)) {
-      grn_obj_remove(ctx, table);
       goto exit;
     }
-
-    grn_obj_unlink(ctx, table);
   }
 
 exit :
-  grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS);
+  {
+    grn_bool success = (ctx->rc == GRN_SUCCESS);
+    if (success) {
+      if (table) {
+        grn_obj_unlink(ctx, table);
+      }
+    } else {
+      if (table) {
+        grn_obj_remove(ctx, table);
+      }
+    }
+    grn_ctx_output_bool(ctx, success);
+  }
   return NULL;
 }
 
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180328/218acd27/attachment-0001.htm 



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