Navigation Menu

Skip to content

Commit

Permalink
Fix function detection with a completed argument
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kou committed Aug 10, 2012
1 parent f1111e6 commit eed5d2e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/expr.c
Expand Up @@ -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);
Expand Down
@@ -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">
@@ -0,0 +1,3 @@
table_create Users TABLE_HASH_KEY ShortText

select Users --filter '"invalid function"("alice")'
@@ -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">
@@ -0,0 +1,3 @@
table_create Users TABLE_HASH_KEY ShortText

select Users --filter '"invalid function"(_key == "alice" || _key == "bob")'
@@ -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">
@@ -0,0 +1,3 @@
table_create Users TABLE_HASH_KEY ShortText

select Users --filter '"invalid function"(_key == "alice" || _key == "bob", _key == "chris" && _id == 1)'
@@ -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">
@@ -0,0 +1,3 @@
table_create Users TABLE_HASH_KEY ShortText

select Users --filter '"invalid function"()'

0 comments on commit eed5d2e

Please sign in to comment.