null+****@clear*****
null+****@clear*****
2012年 8月 10日 (金) 14:19:25 JST
Kouhei Sutou 2012-08-10 14:19:25 +0900 (Fri, 10 Aug 2012) New Revision: eed5d2ea29f84f73d9103ff76ce289ee7dda9ef0 https://github.com/groonga/groonga/commit/eed5d2ea29f84f73d9103ff76ce289ee7dda9ef0 Merged b4b2245: Merge pull request #24 from groonga/fix-function-detection Log: Fix function detection with a completed argument The current function object detection is very naive. It just looks the Nth prior code. N is the number of arguments. It works well for simple function call such as 'function(arg1, arg2)' but doesn't work well for complex function call such as 'function(column == "value1" || column == "value2")'. The simple function call has 2 codes for arguments. It's the same number as the number of arguments. The comlex function call has 5 codes for arguments. It's not the same number as the number of arguments. This change computes the correct number of codes for arguments. Added files: test/function/suite/select/filter/invalid/function_call_with_argument.expected test/function/suite/select/filter/invalid/function_call_with_argument.test test/function/suite/select/filter/invalid/function_call_with_complex_argument.expected test/function/suite/select/filter/invalid/function_call_with_complex_argument.test test/function/suite/select/filter/invalid/function_call_with_complex_arguments.expected test/function/suite/select/filter/invalid/function_call_with_complex_arguments.test test/function/suite/select/filter/invalid/function_call_without_argument.expected test/function/suite/select/filter/invalid/function_call_without_argument.test Modified files: lib/expr.c Modified: lib/expr.c (+19 -2) =================================================================== --- lib/expr.c 2012-08-10 10:44:52 +0900 (9400a03) +++ lib/expr.c 2012-08-10 14:19:25 +0900 (7c51dd9) @@ -841,9 +841,26 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, { grn_obj *proc = NULL; if (e->codes_curr - nargs > 0) { - proc = e->codes[e->codes_curr - nargs - 1].value; + int i; + grn_expr_code *code; + code = &(e->codes[e->codes_curr - 1]); + for (i = 0; i < nargs; i++) { + int rest_n_codes = 1; + while (rest_n_codes > 0) { + if (!code->value) { + rest_n_codes += code->nargs; + } + rest_n_codes--; + code--; + } + } + proc = code->value; + } + if (!proc) { + ERR(GRN_INVALID_ARGUMENT, "invalid function call expression"); + goto exit; } - if (proc && !function_proc_p(proc)) { + if (!function_proc_p(proc)) { grn_obj buffer; GRN_TEXT_INIT(&buffer, 0); Added: test/function/suite/select/filter/invalid/function_call_with_argument.expected (+5 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_argument.expected 2012-08-10 14:19:25 +0900 (198a951) @@ -0,0 +1,5 @@ +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +select Users --filter '"invalid function"("alice")' +[[[-22,0.0,0.0],"invalid function: <\"invalid function\">"],[]] +#|e| invalid function: <"invalid function"> Added: test/function/suite/select/filter/invalid/function_call_with_argument.test (+3 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_argument.test 2012-08-10 14:19:25 +0900 (30975bb) @@ -0,0 +1,3 @@ +table_create Users TABLE_HASH_KEY ShortText + +select Users --filter '"invalid function"("alice")' Added: test/function/suite/select/filter/invalid/function_call_with_complex_argument.expected (+5 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_complex_argument.expected 2012-08-10 14:19:25 +0900 (8ea8136) @@ -0,0 +1,5 @@ +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +select Users --filter '"invalid function"(_key == "alice" || _key == "bob")' +[[[-22,0.0,0.0],"invalid function: <\"invalid function\">"],[]] +#|e| invalid function: <"invalid function"> Added: test/function/suite/select/filter/invalid/function_call_with_complex_argument.test (+3 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_complex_argument.test 2012-08-10 14:19:25 +0900 (d4b7e2c) @@ -0,0 +1,3 @@ +table_create Users TABLE_HASH_KEY ShortText + +select Users --filter '"invalid function"(_key == "alice" || _key == "bob")' Added: test/function/suite/select/filter/invalid/function_call_with_complex_arguments.expected (+5 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_complex_arguments.expected 2012-08-10 14:19:25 +0900 (89ce15e) @@ -0,0 +1,5 @@ +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +select Users --filter '"invalid function"(_key == "alice" || _key == "bob", _key == "chris" && _id == 1)' +[[[-22,0.0,0.0],"invalid function: <\"invalid function\">"],[]] +#|e| invalid function: <"invalid function"> Added: test/function/suite/select/filter/invalid/function_call_with_complex_arguments.test (+3 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_with_complex_arguments.test 2012-08-10 14:19:25 +0900 (0e1a3b3) @@ -0,0 +1,3 @@ +table_create Users TABLE_HASH_KEY ShortText + +select Users --filter '"invalid function"(_key == "alice" || _key == "bob", _key == "chris" && _id == 1)' Added: test/function/suite/select/filter/invalid/function_call_without_argument.expected (+5 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_without_argument.expected 2012-08-10 14:19:25 +0900 (bc63f5e) @@ -0,0 +1,5 @@ +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +select Users --filter '"invalid function"()' +[[[-22,0.0,0.0],"invalid function: <\"invalid function\">"],[]] +#|e| invalid function: <"invalid function"> Added: test/function/suite/select/filter/invalid/function_call_without_argument.test (+3 -0) 100644 =================================================================== --- /dev/null +++ test/function/suite/select/filter/invalid/function_call_without_argument.test 2012-08-10 14:19:25 +0900 (b1e347b) @@ -0,0 +1,3 @@ +table_create Users TABLE_HASH_KEY ShortText + +select Users --filter '"invalid function"()' -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download