Kouhei Sutou
kou****@clear*****
2009年 4月 8日 (水) 10:46:43 JST
須藤です。 grn_table_create()のドキュメントには * @value_size: keyに対応する値を格納する領域のサイズ(byte長)。tableはcolumnとは別に、 * keyに対応する値を格納する領域を一つだけ持つことができる。 と書いてあり、GRN_TABLE_NO_KEYを指定した場合でも grn_obj_set_value()で値を設定できそうな感じがするのですが、 実際はGRN_NO_MEMORY_AVAILABLEで失敗してしまいます。 これは、意図した挙動(ドキュメントの方が間違っている)でしょ うか? とりあえず、ドキュメントに合わせた場合のテストを書いてみまし た。 diff --git a/test/unit/core/Makefile.am b/test/unit/core/Makefile.am index 5c253cc..60c45c6 100644 --- a/test/unit/core/Makefile.am +++ b/test/unit/core/Makefile.am @@ -11,7 +11,8 @@ noinst_LTLIBRARIES = \ test-performance.la \ test-stress.la \ test-public-context.la \ - test-query.la + test-query.la \ + test-table.la endif INCLUDES = \ @@ -44,3 +45,4 @@ test_performance_la_SOURCES = test-performance.c test_stress_la_SOURCES = test-stress.c test_public_context_la_SOURCES = test-public-context.c test_query_la_SOURCES = test-query.c +test_table_la_SOURCES = test-table.c diff --git a/test/unit/core/test-table.c b/test/unit/core/test-table.c new file mode 100644 index 0000000..c58786f --- /dev/null +++ b/test/unit/core/test-table.c @@ -0,0 +1,68 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2009 Kouhei Sutou <kou****@clear*****> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <groonga.h> + +#include <gcutter.h> +#include <glib/gstdio.h> + +#include "../lib/grn-assertions.h" + +void test_array_set_data(void); + +static grn_logger_info *logger; +static grn_ctx context; +static grn_obj *database; + +void +setup(void) +{ + logger = setup_grn_logger(); + grn_ctx_init(&context, 0, GRN_ENC_DEFAULT); + database = grn_db_create(&context, NULL, NULL); +} + +void +teardown(void) +{ + grn_ctx_fin(&context); + teardown_grn_logger(logger); +} + +void +test_array_set_data(void) +{ + grn_obj *table; + grn_id record_id; + gchar value[] = "sample value"; + grn_obj *record_value; + grn_obj *retrieved_record_value; + + table = grn_table_create(&context, NULL, 0, NULL, + GRN_OBJ_TABLE_NO_KEY, + NULL, sizeof(value), GRN_ENC_DEFAULT); + record_id = grn_table_add(&context, table); + + record_value = grn_obj_open(&context, GRN_BULK, 0, 0); + grn_bulk_write(&context, record_value, value, sizeof(value)); + grn_test_assert(grn_obj_set_value(&context, table, record_id, + record_value, GRN_OBJ_SET)); + + retrieved_record_value = grn_obj_get_value(&context, table, record_id, NULL); + cut_assert_equal_string(value, GRN_BULK_HEAD(retrieved_record_value)); +} あと、このテストがパスする変更です。 diff --git a/lib/hash.c b/lib/hash.c index 00df7b9..ff9157a 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -293,7 +293,7 @@ grn_array_set_value(grn_ctx *ctx, grn_array *array, grn_id id, void *value, int uint8_t res; ARRAY_BITMAP_AT(array, id, res); if (!res) { return GRN_INVALID_ARGUMENT; } - ARRAY_ENTRY_AT(array, id, ee, 0); + ARRAY_ENTRY_AT(array, id, ee, GRN_TABLE_ADD); if (ee) { switch ((flags & GRN_OBJ_SET_MASK)) { case GRN_OBJ_SET : あるいは、こうでしょうか。こっちの方が影響は少なそうですが、 ↑でもよさそうな気はします。 diff --git a/lib/db.c b/lib/db.c index 5e79e58..0053595 100644 --- a/lib/db.c +++ b/lib/db.c @@ -627,11 +627,12 @@ grn_id grn_table_add(grn_ctx *ctx, grn_obj *table) { grn_id id = GRN_ID_NIL; + void *value; GRN_API_ENTER; if (table) { switch (table->header.type) { case GRN_TABLE_NO_KEY : - id = grn_array_add(ctx, (grn_array *)table, NULL); + id = grn_array_add(ctx, (grn_array *)table, &value); break; default : break; -- 須藤 功平 <kou****@clear*****> 株式会社クリアコード (http://www.clear-code.com/)