null+****@clear*****
null+****@clear*****
2010年 9月 14日 (火) 11:50:02 JST
Kouhei Sutou 2010-09-14 02:50:02 +0000 (Tue, 14 Sep 2010) New Revision: af40715f461a7085d55bdd6e97cb9024370c6e5b Log: add command_version to context. Modified files: groonga.h lib/ctx.c lib/ql.h test/unit/core/test-context.c Modified: groonga.h (+37 -0) =================================================================== --- groonga.h 2010-09-15 05:09:48 +0000 (da4311e) +++ groonga.h 2010-09-14 02:50:02 +0000 (9017f29) @@ -126,6 +126,12 @@ typedef enum { } grn_encoding; typedef enum { + GRN_COMMAND_VERSION_DEFAULT = 0, + GRN_COMMAND_VERSION_1, + GRN_COMMAND_VERSION_MAX +} grn_command_version; + +typedef enum { GRN_LOG_NONE = 0, GRN_LOG_EMERG, GRN_LOG_ALERT, @@ -242,6 +248,37 @@ GRN_API grn_rc grn_set_default_encoding(grn_encoding encoding); GRN_API const char *grn_get_version(void); GRN_API const char *grn_get_package(void); +/** + * grn_get_default_command_version: + * + * デフォルトのcommand_versionを返します。 + **/ +GRN_API grn_command_version grn_get_default_command_version(void); + +/** + * grn_set_default_command_version: + * @encoding: 変更後のデフォルトのcommand_versionを指定します。 + * + * デフォルトのcommand_versionを変更します。 + **/ +GRN_API grn_rc grn_set_default_command_version(grn_command_version version); + +/** + * grn_ctx_get_command_version: + * + * command_versionを返します。 + **/ +GRN_API grn_command_version grn_ctx_get_command_version(grn_ctx *ctx); + +/** + * grn_ctx_set_command_version: + * @encoding: 変更後のcommand_versionを指定します。 + * + * command_versionを変更します。 + **/ +GRN_API grn_rc grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version); + + /* obj */ typedef unsigned short int grn_obj_flags; Modified: lib/ctx.c (+46 -0) =================================================================== --- lib/ctx.c 2010-09-15 05:09:48 +0000 (9006377) +++ lib/ctx.c 2010-09-14 02:50:02 +0000 (0c5989c) @@ -277,6 +277,12 @@ grn_ctx_impl_init(grn_ctx *ctx) GRN_TEXT_INIT(&ctx->impl->names, GRN_OBJ_VECTOR); GRN_UINT32_INIT(&ctx->impl->levels, GRN_OBJ_VECTOR); + if (ctx == &grn_gctx) { + ctx->impl->command_version = GRN_COMMAND_VERSION_MAX - 1; + } else { + ctx->impl->command_version = grn_get_default_command_version(); + } + ctx->impl->phs = NIL; ctx->impl->code = NIL; ctx->impl->dump = NIL; @@ -705,6 +711,18 @@ grn_set_default_encoding(grn_encoding encoding) } } +grn_command_version +grn_get_default_command_version(void) +{ + return grn_ctx_get_command_version(&grn_gctx); +} + +grn_rc +grn_set_default_command_version(grn_command_version version) +{ + return grn_ctx_set_command_version(&grn_gctx, version); +} + static int alloc_count = 0; grn_rc @@ -759,6 +777,34 @@ grn_ctx_close(grn_ctx *ctx) return rc; } +grn_command_version +grn_ctx_get_command_version(grn_ctx *ctx) +{ + if (ctx->impl) { + return ctx->impl->command_version; + } else { + return GRN_COMMAND_VERSION_MAX - 1; + } +} + +grn_rc +grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version) +{ + switch (version) { + case GRN_COMMAND_VERSION_DEFAULT : + ctx->impl->command_version = GRN_COMMAND_VERSION_MAX - 1; + return GRN_SUCCESS; + default : + if (GRN_COMMAND_VERSION_DEFAULT < version && + version < GRN_COMMAND_VERSION_MAX) { + ctx->impl->command_version = version; + return GRN_SUCCESS; + } else { + return GRN_INVALID_ARGUMENT; + } + } +} + grn_content_type grn_get_ctype(grn_obj *var) { Modified: lib/ql.h (+3 -0) =================================================================== --- lib/ql.h 2010-09-15 05:09:48 +0000 (a385f1c) +++ lib/ql.h 2010-09-14 02:50:02 +0000 (f78fcd4) @@ -201,6 +201,9 @@ struct _grn_ctx_impl { grn_obj names; grn_obj levels; + /* command portion */ + grn_command_version command_version; + /* ql portion */ uint32_t ncells; uint32_t seqno; Modified: test/unit/core/test-context.c (+12 -0) =================================================================== --- test/unit/core/test-context.c 2010-09-15 05:09:48 +0000 (bcb9a91) +++ test/unit/core/test-context.c 2010-09-14 02:50:02 +0000 (dfcb00d) @@ -26,6 +26,7 @@ void test_at_nonexistent(void); void test_dynamic_malloc_change(void); +void test_command_version(void); static grn_ctx *context; static grn_obj *database; @@ -107,3 +108,14 @@ test_dynamic_malloc_change(void) } #endif } + +void +test_command_version(void) +{ + cut_assert_equal_int(GRN_COMMAND_VERSION_MAX - 1, + grn_get_default_command_version()); + + cut_assert_ensure_context(); + cut_assert_equal_int(GRN_COMMAND_VERSION_MAX - 1, + grn_ctx_get_command_version(context)); +}