Kouhei Sutou
null+****@clear*****
Tue Nov 24 16:02:00 JST 2015
Kouhei Sutou 2015-11-24 16:02:00 +0900 (Tue, 24 Nov 2015) New Revision: 2c474597aa128c694f3f032cfe017f4bdf2700aa https://github.com/groonga/groonga/commit/2c474597aa128c694f3f032cfe017f4bdf2700aa Message: Add grn_obj_is_true() GRN_OBJ_IS_TRUE() is deprecated. Modified files: include/groonga/obj.h lib/db.c lib/expr.c lib/mrb/mrb_index_cursor.c lib/obj.c lib/proc.c Modified: include/groonga/obj.h (+3 -42) =================================================================== --- include/groonga/obj.h 2015-11-24 15:47:19 +0900 (0c76836) +++ include/groonga/obj.h 2015-11-24 16:02:00 +0900 (e8ac280) @@ -23,51 +23,12 @@ extern "C" { #endif +/* Just for backward compatibility. Use grn_obj_is_true() instead. */ #define GRN_OBJ_IS_TRUE(ctx, obj, result) do { \ - grn_obj *obj_ = (obj); \ - if (obj_) { \ - switch (obj_->header.type) { \ - case GRN_BULK : \ - switch (obj_->header.domain) { \ - case GRN_DB_BOOL : \ - result = GRN_BOOL_VALUE(obj_); \ - break; \ - case GRN_DB_INT32 : \ - result = GRN_INT32_VALUE(obj_) != 0; \ - break; \ - case GRN_DB_UINT32 : \ - result = GRN_UINT32_VALUE(obj_) != 0; \ - break; \ - case GRN_DB_FLOAT : \ - { \ - double float_value; \ - float_value = GRN_FLOAT_VALUE(obj_); \ - result = (float_value < -DBL_EPSILON || \ - DBL_EPSILON < float_value); \ - } \ - break; \ - case GRN_DB_SHORT_TEXT : \ - case GRN_DB_TEXT : \ - case GRN_DB_LONG_TEXT : \ - result = GRN_TEXT_LEN(obj_) != 0; \ - break; \ - default : \ - result = GRN_FALSE; \ - break; \ - } \ - break; \ - case GRN_VECTOR : \ - result = GRN_TRUE; \ - break; \ - default : \ - result = GRN_FALSE; \ - break; \ - } \ - } else { \ - result = GRN_FALSE; \ - } \ + result = grn_obj_is_true(ctx, obj); \ } while (0) +GRN_API grn_bool grn_obj_is_true(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_table(grn_ctx *ctx, grn_obj *obj); Modified: lib/db.c (+3 -3) =================================================================== --- lib/db.c 2015-11-24 15:47:19 +0900 (43f66c4) +++ lib/db.c 2015-11-24 16:02:00 +0900 (926f7cb) @@ -12157,11 +12157,11 @@ loader_add(grn_ctx *ctx, grn_obj *key) if (!added && loader->ifexists) { grn_obj *v = grn_expr_get_var_by_offset(ctx, loader->ifexists, 0); grn_obj *result; - unsigned int result_boolean; GRN_RECORD_SET(ctx, v, id); result = grn_expr_exec(ctx, loader->ifexists, 0); - GRN_OBJ_IS_TRUE(ctx, result, result_boolean); - if (!result_boolean) { id = 0; } + if (!grn_obj_is_true(ctx, result)) { + id = 0; + } } return id; } Modified: lib/expr.c (+13 -20) =================================================================== --- lib/expr.c 2015-11-24 15:47:19 +0900 (0e5c820) +++ lib/expr.c 2015-11-24 16:02:00 +0900 (f76207b) @@ -2733,10 +2733,10 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) case GRN_OP_CJUMP : { grn_obj *v; - unsigned int v_boolean; POP1(v); - GRN_OBJ_IS_TRUE(ctx, v, v_boolean); - if (!v_boolean) { code += code->nargs; } + if (!grn_obj_is_true(ctx, v)) { + code += code->nargs; + } } code++; break; @@ -2928,13 +2928,10 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) case GRN_OP_AND : { grn_obj *x, *y; - unsigned int x_boolean, y_boolean; grn_obj *result = NULL; POP2ALLOC1(x, y, res); - GRN_OBJ_IS_TRUE(ctx, x, x_boolean); - if (x_boolean) { - GRN_OBJ_IS_TRUE(ctx, y, y_boolean); - if (y_boolean) { + if (grn_obj_is_true(ctx, x)) { + if (grn_obj_is_true(ctx, y)) { result = y; } } @@ -2953,15 +2950,12 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) case GRN_OP_OR : { grn_obj *x, *y; - unsigned int x_boolean, y_boolean; grn_obj *result; POP2ALLOC1(x, y, res); - GRN_OBJ_IS_TRUE(ctx, x, x_boolean); - if (x_boolean) { + if (grn_obj_is_true(ctx, x)) { result = x; } else { - GRN_OBJ_IS_TRUE(ctx, y, y_boolean); - if (y_boolean) { + if (grn_obj_is_true(ctx, y)) { result = y; } else { result = NULL; @@ -2982,16 +2976,15 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) case GRN_OP_AND_NOT : { grn_obj *x, *y; - grn_bool x_boolean, y_boolean; + grn_bool is_true; POP2ALLOC1(x, y, res); - GRN_OBJ_IS_TRUE(ctx, x, x_boolean); - GRN_OBJ_IS_TRUE(ctx, y, y_boolean); - grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0); - if (!x_boolean || y_boolean) { - GRN_BOOL_SET(ctx, res, GRN_FALSE); + if (!grn_obj_is_true(ctx, x) || grn_obj_is_true(ctx, y)) { + is_true = GRN_FALSE; } else { - GRN_BOOL_SET(ctx, res, GRN_TRUE); + is_true = GRN_TRUE; } + grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0); + GRN_BOOL_SET(ctx, res, is_true); } code++; break; Modified: lib/mrb/mrb_index_cursor.c (+1 -1) =================================================================== --- lib/mrb/mrb_index_cursor.c 2015-11-24 15:47:19 +0900 (ac3b6b3) +++ lib/mrb/mrb_index_cursor.c 2015-11-24 16:02:00 +0900 (0992661) @@ -189,7 +189,7 @@ mrb_grn_index_cursor_select(mrb_state *mrb, mrb_value self) GRN_RECORD_SET(ctx, expr_variable, posting->rid); matched = grn_expr_exec(ctx, expr, 0); if (matched) { - GRN_OBJ_IS_TRUE(ctx, matched, matched_raw); + matched_raw = grn_obj_is_true(ctx, matched); } else { grn_mrb_ctx_check(mrb); } Modified: lib/obj.c (+45 -0) =================================================================== --- lib/obj.c 2015-11-24 15:47:19 +0900 (bfcf9ba) +++ lib/obj.c 2015-11-24 16:02:00 +0900 (580b9c7) @@ -21,6 +21,51 @@ #include "grn_index_column.h" grn_bool +grn_obj_is_true(grn_ctx *ctx, grn_obj *obj) +{ + if (!obj) { + return GRN_FALSE; + } + + switch (obj->header.type) { + case GRN_BULK : + switch (obj->header.domain) { + case GRN_DB_BOOL : + return GRN_BOOL_VALUE(obj); + break; + case GRN_DB_INT32 : + return GRN_INT32_VALUE(obj) != 0; + break; + case GRN_DB_UINT32 : + return GRN_UINT32_VALUE(obj) != 0; + break; + case GRN_DB_FLOAT : { + double float_value; + float_value = GRN_FLOAT_VALUE(obj); + return (float_value < -DBL_EPSILON || + DBL_EPSILON < float_value); + break; + } + case GRN_DB_SHORT_TEXT : + case GRN_DB_TEXT : + case GRN_DB_LONG_TEXT : + return GRN_TEXT_LEN(obj) != 0; + break; + default : + return GRN_FALSE; + break; + } + break; + case GRN_VECTOR : + return GRN_TRUE; + break; + default : + return GRN_FALSE; + break; + } +} + +grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj) { grn_id id; Modified: lib/proc.c (+10 -20) =================================================================== --- lib/proc.c 2015-11-24 15:47:19 +0900 (3b71ad2) +++ lib/proc.c 2015-11-24 16:02:00 +0900 (285ab00) @@ -5722,12 +5722,8 @@ func_between(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) GRN_RECORD_SET(ctx, between_variable, GRN_RECORD_VALUE(variable)); result = grn_expr_exec(ctx, between_expr, 0); - if (result) { - grn_bool result_boolean; - GRN_OBJ_IS_TRUE(ctx, result, result_boolean); - if (result_boolean) { - GRN_BOOL_SET(ctx, found, GRN_TRUE); - } + if (grn_obj_is_true(ctx, result)) { + GRN_BOOL_SET(ctx, found, GRN_TRUE); } grn_obj_unlink(ctx, between_expr); @@ -5916,17 +5912,13 @@ selector_between_sequential_search(grn_ctx *ctx, if (ctx->rc) { break; } - if (result) { - grn_bool result_boolean; - GRN_OBJ_IS_TRUE(ctx, result, result_boolean); - if (result_boolean) { - grn_posting posting; - posting.rid = record_id; - posting.sid = 1; - posting.pos = 0; - posting.weight = 0; - grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op); - } + if (grn_obj_is_true(ctx, result)) { + grn_posting posting; + posting.rid = record_id; + posting.sid = 1; + posting.pos = 0; + posting.weight = 0; + grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op); } } grn_obj_unlink(ctx, expr); @@ -6761,9 +6753,7 @@ proc_range_filter(grn_ctx *ctx, int nargs, grn_obj **args, if (ctx->rc) { break; } - if (result) { - GRN_OBJ_IS_TRUE(ctx, result, result_boolean); - } + result_boolean = grn_obj_is_true(ctx, result); } else { result_boolean = GRN_TRUE; } -------------- next part -------------- HTML����������������������������...Télécharger