Skip to content

Commit 5f17d0c

Browse files
authored
Merge pull request #214 from Shopify/pz-ary-long
Store valid Ruby fixnum into array
2 parents bc4571d + 01ae592 commit 5f17d0c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

ext/liquid_c/liquid_vm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static inline void vm_stack_reserve_for_write(vm_t *vm, size_t num_values)
166166
c_buffer_reserve_for_write(&vm->stack, num_values * sizeof(VALUE));
167167
}
168168

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

187187
vm->invoking_filter = true;
188-
VALUE result = rb_funcallv(vm->context.strainer, RB_SYM2ID(filter_name), num_args, args);
188+
VALUE result = rb_funcallv(vm->context.strainer, RB_SYM2ID(filter_name), (int)num_args, args);
189189
vm->invoking_filter = false;
190190
return rb_funcall(result, id_to_liquid, 0);
191191
}
@@ -334,13 +334,13 @@ static VALUE vm_render_until_error(VALUE uncast_args)
334334
case OP_BUILTIN_FILTER:
335335
{
336336
VALUE filter_name;
337-
uint8_t num_args;
337+
unsigned long num_args;
338338

339339
if (ip[-1] == OP_FILTER) {
340340
constant_index = (ip[0] << 8) | ip[1];
341341
constant = constants[constant_index];
342342
filter_name = RARRAY_AREF(constant, 0);
343-
num_args = RARRAY_AREF(constant, 1);
343+
num_args = FIX2ULONG(RARRAY_AREF(constant, 1));
344344
ip += 2;
345345
} else {
346346
assert(ip[-1] == OP_BUILTIN_FILTER);

ext/liquid_c/vm_assembler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void vm_assembler_add_filter(vm_assembler_t *code, VALUE filter_name, size_t arg
362362
} else {
363363
VALUE filter_args = rb_ary_new_capa(2);
364364
rb_ary_push(filter_args, filter_name);
365-
rb_ary_push(filter_args, arg_count + 1);
365+
rb_ary_push(filter_args, LONG2FIX((long)(arg_count + 1)));
366366
vm_assembler_add_op_with_constant(code, filter_args, OP_FILTER);
367367
}
368368
}

test/unit/variable_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def test_variable_filter_args
8080
output = variable_strict_parse("name | filter1 : a , b : c , d : e").render!(context, render_opts)
8181
assert_equal('{ filter: :filter1, input: "Bob", args: [1, {"b"=>3, "d"=>5}] }', output)
8282

83+
output = variable_strict_parse("name | filter1: 1, 2, 3, 4, 5, 6, 7").render!(context, render_opts)
84+
assert_equal('{ filter: :filter1, input: "Bob", args: [1, 2, 3, 4, 5, 6, 7] }', output)
85+
8386
assert_raises(Liquid::SyntaxError) do
8487
variable_strict_parse("name | filter : a : b : c : d : e")
8588
end

0 commit comments

Comments
 (0)