Kouhei Sutou 2018-10-29 15:31:45 +0900 (Mon, 29 Oct 2018) Revision: 8060160a0b4cd5deee36c710747f89e5686f9a1a https://github.com/groonga/groonga/commit/8060160a0b4cd5deee36c710747f89e5686f9a1a Message: Generalize options open func grn_tokenizer_open_options_func and grn_normalizer_open_options_func are deprecated. Use grn_table_module_open_options_func instead. Modified files: include/groonga/table.h lib/normalizer.c lib/table.c lib/tokenizers.c Modified: include/groonga/table.h (+13 -10) =================================================================== --- include/groonga/table.h 2018-10-29 15:26:46 +0900 (880123182) +++ include/groonga/table.h 2018-10-29 15:31:45 +0900 (3c89afa59) @@ -1,5 +1,7 @@ +/* -*- c-basic-offset: 2 -*- */ /* Copyright(C) 2009-2018 Brazil + Copyright(C) 2018 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 @@ -241,10 +243,12 @@ GRN_API grn_rc grn_table_apply_expr(grn_ctx *ctx, GRN_API grn_id grn_table_find_reference_object(grn_ctx *ctx, grn_obj *table); -typedef void *(*grn_tokenizer_open_options_func)(grn_ctx *ctx, - grn_obj *tokenizer, - grn_obj *values, - void *user_data); +typedef void *(*grn_table_module_open_options_func)(grn_ctx *ctx, + grn_obj *proc, + grn_obj *values, + void *user_data); +/* Deprecated since 8.0.9. Use grn_table_module_option_options_func instead. */ +typedef grn_table_module_open_options_func grn_tokenizer_open_options_func; GRN_API grn_rc grn_table_set_default_tokenizer_options(grn_ctx *ctx, @@ -259,7 +263,7 @@ grn_table_get_default_tokenizer_options(grn_ctx *ctx, GRN_API void * grn_table_cache_default_tokenizer_options(grn_ctx *ctx, grn_obj *table, - grn_tokenizer_open_options_func open_options_func, + grn_table_module_open_options_func open_options_func, grn_close_func close_options_func, void *user_data); @@ -269,10 +273,8 @@ grn_table_get_default_tokenizer_string(grn_ctx *ctx, grn_obj *output); -typedef void *(*grn_normalizer_open_options_func)(grn_ctx *ctx, - grn_obj *string, - grn_obj *values, - void *user_data); +/* Deprecated since 8.0.9. Use grn_table_module_open_options_func instead. */ +typedef grn_table_module_open_options_func grn_normalizer_open_options_func; GRN_API grn_rc grn_table_set_normalizer_options(grn_ctx *ctx, @@ -284,11 +286,12 @@ grn_table_get_normalizer_options(grn_ctx *ctx, grn_obj *table, grn_obj *options); +/* TODO: Remove string argument. It's needless. */ GRN_API void * grn_table_cache_normalizer_options(grn_ctx *ctx, grn_obj *table, grn_obj *string, - grn_normalizer_open_options_func open_options_func, + grn_table_module_open_options_func open_options_func, grn_close_func close_options_func, void *user_data); Modified: lib/normalizer.c (+1 -1) =================================================================== --- lib/normalizer.c 2018-10-29 15:26:46 +0900 (3c664d73f) +++ lib/normalizer.c 2018-10-29 15:31:45 +0900 (bc36b7ed2) @@ -1799,7 +1799,7 @@ nfkc51_next(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) static void * nfkc100_open_options(grn_ctx *ctx, - grn_obj *string, + grn_obj *normalizer, grn_obj *raw_options, void *user_data) { Modified: lib/table.c (+58 -47) =================================================================== --- lib/table.c 2018-10-29 15:26:46 +0900 (4cf6bf969) +++ lib/table.c 2018-10-29 15:31:45 +0900 (28f040e6b) @@ -271,13 +271,8 @@ grn_table_get_module_options(grn_ctx *ctx, typedef struct { const char *context_tag; const char *module_name; - struct { - grn_tokenizer_open_options_func open_options_func; - } tokenizer; - struct { - grn_obj *string; - grn_normalizer_open_options_func open_options_func; - } normalizer; + grn_info_type type; + grn_table_module_open_options_func open_options_func; grn_close_func close_options_func; void *user_data; } grn_table_cache_data; @@ -302,7 +297,8 @@ grn_table_cache_module_options(grn_ctx *ctx, GRN_API_RETURN(NULL); } - if (data->tokenizer.open_options_func) { + switch (data->type) { + case GRN_INFO_DEFAULT_TOKENIZER : switch (table->header.type) { case GRN_TABLE_HASH_KEY : module = &(((grn_hash *)table)->tokenizer); @@ -316,7 +312,8 @@ grn_table_cache_module_options(grn_ctx *ctx, default : break; } - } else if (data->normalizer.open_options_func) { + break; + case GRN_INFO_NORMALIZER : switch (table->header.type) { case GRN_TABLE_HASH_KEY : module = &(((grn_hash *)table)->normalizer); @@ -330,6 +327,9 @@ grn_table_cache_module_options(grn_ctx *ctx, default : break; } + break; + default : + break; } GRN_TEXT_INIT(&raw_options, GRN_OBJ_VECTOR); @@ -344,17 +344,10 @@ grn_table_cache_module_options(grn_ctx *ctx, goto exit; } - if (data->tokenizer.open_options_func) { - options = data->tokenizer.open_options_func(ctx, - table, - &raw_options, - data->user_data); - } else if (data->normalizer.open_options_func) { - options = data->normalizer.open_options_func(ctx, - data->normalizer.string, - &raw_options, - data->user_data); - } + options = data->open_options_func(ctx, + module->proc, + &raw_options, + data->user_data); grn_table_module_set_options(ctx, module, options, @@ -367,35 +360,18 @@ exit : GRN_API_RETURN(module->options); } -static grn_rc -grn_table_get_module_string(grn_ctx *ctx, - grn_obj *table, - grn_obj *output, - grn_info_type type, - const char *module_name, - const char *context_tag) +static void +grn_table_get_module_string_raw(grn_ctx *ctx, + grn_obj *table, + grn_obj *output, + grn_obj *proc, + const char *module_name) { - grn_obj *proc; char name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int name_size; grn_obj options; unsigned int n = 0; - GRN_API_ENTER; - - if (!grn_obj_is_lexicon(ctx, table)) { - ERR(GRN_INVALID_ARGUMENT, - "[table][%s][options][string] table must be key table: %s", - context_tag, - table ? grn_obj_type_to_string(table->header.type) : "(null)"); - GRN_API_RETURN(ctx->rc); - } - - proc = grn_obj_get_info(ctx, table, type, NULL); - if (!proc) { - GRN_API_RETURN(ctx->rc); - } - name_size = grn_obj_name(ctx, proc, name, GRN_TABLE_MAX_KEY_SIZE); GRN_TEXT_PUT(ctx, output, name, name_size); @@ -438,6 +414,38 @@ grn_table_get_module_string(grn_ctx *ctx, GRN_OBJ_FIN(ctx, &option); } GRN_OBJ_FIN(ctx, &options); +} + +static grn_rc +grn_table_get_module_string(grn_ctx *ctx, + grn_obj *table, + grn_obj *output, + grn_info_type type, + const char *module_name, + const char *context_tag) +{ + grn_obj *proc; + + GRN_API_ENTER; + + if (!grn_obj_is_lexicon(ctx, table)) { + ERR(GRN_INVALID_ARGUMENT, + "[table][%s][options][string] table must be key table: %s", + context_tag, + table ? grn_obj_type_to_string(table->header.type) : "(null)"); + GRN_API_RETURN(ctx->rc); + } + + proc = grn_obj_get_info(ctx, table, type, NULL); + if (!proc) { + GRN_API_RETURN(ctx->rc); + } + + grn_table_get_module_string_raw(ctx, table, output, proc, module_name); + + GRN_API_RETURN(ctx->rc); +} + GRN_API_RETURN(ctx->rc); } @@ -469,7 +477,7 @@ grn_table_get_default_tokenizer_options(grn_ctx *ctx, void * grn_table_cache_default_tokenizer_options(grn_ctx *ctx, grn_obj *table, - grn_tokenizer_open_options_func open_options_func, + grn_table_module_open_options_func open_options_func, grn_close_func close_options_func, void *user_data) { @@ -479,6 +487,8 @@ grn_table_cache_default_tokenizer_options(grn_ctx *ctx, data.context_tag = "default-tokenizer"; data.module_name = OPTION_NAME_DEFAULT_TOKENIZER; data.tokenizer.open_options_func = open_options_func; + data.type = GRN_INFO_DEFAULT_TOKENIZER; + data.open_options_func = open_options_func; data.close_options_func = close_options_func; data.user_data = user_data; return grn_table_cache_module_options(ctx, table, &data); @@ -524,8 +534,9 @@ grn_table_get_normalizer_options(grn_ctx *ctx, void * grn_table_cache_normalizer_options(grn_ctx *ctx, grn_obj *table, + /* TODO: Remove me. */ grn_obj *string, - grn_normalizer_open_options_func open_options_func, + grn_table_module_open_options_func open_options_func, grn_close_func close_options_func, void *user_data) { @@ -534,8 +545,8 @@ grn_table_cache_normalizer_options(grn_ctx *ctx, memset(&data, 0, sizeof(data)); data.context_tag = "normalizer"; data.module_name = OPTION_NAME_NORMALIZER; - data.normalizer.string = string; - data.normalizer.open_options_func = open_options_func; + data.type = GRN_INFO_NORMALIZER; + data.open_options_func = open_options_func; data.close_options_func = close_options_func; data.user_data = user_data; return grn_table_cache_module_options(ctx, table, &data); Modified: lib/tokenizers.c (+1 -1) =================================================================== --- lib/tokenizers.c 2018-10-29 15:26:46 +0900 (e988cff7f) +++ lib/tokenizers.c 2018-10-29 15:31:45 +0900 (baf88a15c) @@ -676,7 +676,7 @@ bigramisad_init(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_dat static void * ngram_open_options(grn_ctx *ctx, - grn_obj *lexicon, + grn_obj *tokenizer, grn_obj *raw_options, void *user_data) { -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181029/bcd115f5/attachment-0001.html>