Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store valid Ruby fixnum into array #214

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/liquid_c/liquid_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static inline void vm_stack_reserve_for_write(vm_t *vm, size_t num_values)
c_buffer_reserve_for_write(&vm->stack, num_values * sizeof(VALUE));
}

static VALUE vm_invoke_filter(vm_t *vm, VALUE filter_name, int num_args)
static VALUE vm_invoke_filter(vm_t *vm, VALUE filter_name, size_t num_args)
{
VALUE *popped_args = vm_stack_pop_n(vm, num_args);
/* We have to copy popped_args_ptr to the stack because the VM
Expand All @@ -185,7 +185,7 @@ static VALUE vm_invoke_filter(vm_t *vm, VALUE filter_name, int num_args)
}

vm->invoking_filter = true;
VALUE result = rb_funcallv(vm->context.strainer, RB_SYM2ID(filter_name), num_args, args);
VALUE result = rb_funcallv(vm->context.strainer, RB_SYM2ID(filter_name), (int)num_args, args);
vm->invoking_filter = false;
return rb_funcall(result, id_to_liquid, 0);
}
Expand Down Expand Up @@ -334,13 +334,13 @@ static VALUE vm_render_until_error(VALUE uncast_args)
case OP_BUILTIN_FILTER:
{
VALUE filter_name;
uint8_t num_args;
unsigned long num_args;

if (ip[-1] == OP_FILTER) {
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
filter_name = RARRAY_AREF(constant, 0);
num_args = RARRAY_AREF(constant, 1);
num_args = FIX2ULONG(RARRAY_AREF(constant, 1));
ip += 2;
} else {
assert(ip[-1] == OP_BUILTIN_FILTER);
Expand Down
2 changes: 1 addition & 1 deletion ext/liquid_c/vm_assembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void vm_assembler_add_filter(vm_assembler_t *code, VALUE filter_name, size_t arg
} else {
VALUE filter_args = rb_ary_new_capa(2);
rb_ary_push(filter_args, filter_name);
rb_ary_push(filter_args, arg_count + 1);
rb_ary_push(filter_args, LONG2FIX((long)(arg_count + 1)));
vm_assembler_add_op_with_constant(code, filter_args, OP_FILTER);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/unit/variable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def test_variable_filter_args
output = variable_strict_parse("name | filter1 : a , b : c , d : e").render!(context, render_opts)
assert_equal('{ filter: :filter1, input: "Bob", args: [1, {"b"=>3, "d"=>5}] }', output)

output = variable_strict_parse("name | filter1: 1, 2, 3, 4, 5, 6, 7").render!(context, render_opts)
assert_equal('{ filter: :filter1, input: "Bob", args: [1, 2, 3, 4, 5, 6, 7] }', output)

assert_raises(Liquid::SyntaxError) do
variable_strict_parse("name | filter : a : b : c : d : e")
end
Expand Down
Loading