Naoya Murakami
null+****@clear*****
Thu Dec 21 20:31:36 JST 2017
Naoya Murakami 2017-12-21 20:31:36 +0900 (Thu, 21 Dec 2017) New Revision: 7d9f9abd9e201b5696235d75420cf87dfa57064f https://github.com/groonga/groonga/commit/7d9f9abd9e201b5696235d75420cf87dfa57064f Merged 9cfbc20: Merge pull request #790 from naoa/index_column_source_records Message: Add grn_proc_func_arg_int64() It is useful for retrieve argument of function as int64 Modified files: lib/grn_proc.h lib/proc.c Modified: lib/grn_proc.h (+2 -0) =================================================================== --- lib/grn_proc.h 2017-12-21 17:44:27 +0900 (961ce3e46) +++ lib/grn_proc.h 2017-12-21 20:31:36 +0900 (84bd53c04) @@ -94,6 +94,8 @@ grn_operator grn_proc_option_value_mode(grn_ctx *ctx, grn_operator default_mode, const char *context); +int64_t grn_proc_func_arg_int64(grn_ctx *ctx, grn_obj *arg, + const char *context); void grn_proc_output_object_name(grn_ctx *ctx, grn_obj *obj); void grn_proc_output_object_id_name(grn_ctx *ctx, grn_id id); Modified: lib/proc.c (+52 -0) =================================================================== --- lib/proc.c 2017-12-21 17:44:27 +0900 (4781b7a1b) +++ lib/proc.c 2017-12-21 20:31:36 +0900 (6ae10fa9b) @@ -808,6 +808,58 @@ grn_proc_option_value_content_type(grn_ctx *ctx, return grn_content_type_parse(ctx, option, default_value); } +int64_t +grn_proc_func_arg_int64(grn_ctx *ctx, grn_obj *arg, const char *context) +{ + int64_t value; + + if (!grn_type_id_is_number_family(ctx, arg->header.domain)) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, arg); + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "%s: value must be a number: <%.*s>", + context, + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return 0; + } + + if (arg->header.domain == GRN_DB_INT32) { + value = GRN_INT32_VALUE(arg); + } else if (arg->header.domain == GRN_DB_INT64) { + value = GRN_INT64_VALUE(arg); + } else { + grn_obj buffer; + grn_rc rc; + + GRN_INT64_INIT(&buffer, 0); + rc = grn_obj_cast(ctx, arg, &buffer, GRN_FALSE); + if (rc == GRN_SUCCESS) { + value = GRN_INT64_VALUE(&buffer); + } + GRN_OBJ_FIN(ctx, &buffer); + + if (rc != GRN_SUCCESS) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, arg); + GRN_PLUGIN_ERROR(ctx, rc, + "%s: " + "failed to cast value to number: <%.*s>", + context, + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return 0; + } + } + return value; +} + static grn_obj * proc_cache_limit(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171221/cafa7774/attachment-0001.htm