[Groonga-commit] groonga/groonga at 0adc0c4 [master] Add NormalizerAuto availability check

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Feb 21 12:32:47 JST 2015


Kouhei Sutou	2015-02-21 12:32:47 +0900 (Sat, 21 Feb 2015)

  New Revision: 0adc0c4f1364dd24511fc32fdfecce84fe37a380
  https://github.com/groonga/groonga/commit/0adc0c4f1364dd24511fc32fdfecce84fe37a380

  Message:
    Add NormalizerAuto availability check
    
    GitHub: fix #283
    
    Reported by Tasuku SUENAGA. Thanks!!!

  Modified files:
    lib/string.c
    test/unit/util/test-string.c

  Modified: lib/string.c (+13 -6)
===================================================================
--- lib/string.c    2015-02-20 19:16:03 +0900 (132d512)
+++ lib/string.c    2015-02-21 12:32:47 +0900 (b080f3f)
@@ -140,8 +140,21 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
     return NULL;
   }
 
+  is_normalizer_auto = (normalizer == GRN_NORMALIZER_AUTO);
+  if (is_normalizer_auto) {
+    normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
+    if (!normalizer) {
+      ERR(GRN_INVALID_ARGUMENT,
+          "[string][open] NormalizerAuto normalizer isn't available");
+      return NULL;
+    }
+  }
+
   string = GRN_MALLOCN(grn_string, 1);
   if (!string) {
+    if (is_normalizer_auto) {
+      grn_obj_unlink(ctx, normalizer);
+    }
     GRN_LOG(ctx, GRN_LOG_ALERT,
             "[string][open] failed to allocate memory");
     return NULL;
@@ -163,12 +176,6 @@ grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
     return (grn_obj *)grn_fake_string_open(ctx, string);
   }
 
-  is_normalizer_auto = (normalizer == GRN_NORMALIZER_AUTO);
-  if (is_normalizer_auto) {
-    normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
-  }
-
-  /* TODO: check rc */
   grn_normalizer_normalize(ctx, normalizer, (grn_obj *)string);
   if (ctx->rc) {
     grn_obj_close(ctx, obj);

  Modified: test/unit/util/test-string.c (+28 -2)
===================================================================
--- test/unit/util/test-string.c    2015-02-20 19:16:03 +0900 (b5fe6c2)
+++ test/unit/util/test-string.c    2015-02-21 12:32:47 +0900 (d275f88)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
 /*
-  Copyright (C) 2008-2012  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2008-2015  Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@ void data_normalize(void);
 void test_normalize(gconstpointer data);
 void data_normalize_broken(void);
 void test_normalize_broken(gconstpointer data);
+void test_normalize_without_database(void);
 void data_remove_tokenized_delimiter(void);
 void test_remove_tokenized_delimiter(gconstpointer data);
 void data_charlen_broken(void);
@@ -86,7 +87,9 @@ void
 teardown (void)
 {
   GRN_OBJ_FIN(&context, &buffer);
-  grn_obj_close(&context, database);
+  if (database) {
+    grn_obj_close(&context, database);
+  }
   grn_ctx_fin(&context);
 }
 
@@ -286,6 +289,29 @@ test_normalize_broken(gconstpointer data)
 }
 
 void
+test_normalize_without_database(void)
+{
+  grn_obj *string;
+  const char *input = "Groonga";
+  int flags = 0;
+
+  grn_obj_close(&context, database);
+  database = NULL;
+
+  GRN_CTX_SET_ENCODING(&context, GRN_ENC_UTF8);
+  string = grn_string_open(&context,
+                           input,
+                           strlen(input),
+                           GRN_NORMALIZER_AUTO,
+                           flags);
+  cut_assert_null(string);
+  grn_test_assert_error(GRN_INVALID_ARGUMENT,
+                        "[string][open] "
+                        "NormalizerAuto normalizer isn't available",
+                        &context);
+}
+
+void
 data_remove_tokenized_delimiter(void)
 {
 #define ADD_DATUM(label, expected, input, flags)                        \
-------------- next part --------------
HTML����������������������������...
다운로드 



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