Permalink
Browse files

fix a bug where calling a method defined with #define_method with a b…

…lock accepting a splat argument (arity -2) would crash

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5037 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 704a5b8 commit 4856e8aa2dc44476d5556a57614271ccf9823ba3 @lrz lrz committed Dec 16, 2010
Showing with 37 additions and 3 deletions.
  1. +23 −3 compiler.cpp
  2. +2 −0 compiler.h
  3. +12 −0 kernel.c
View
@@ -198,6 +198,8 @@ RoxorCompiler::RoxorCompiler(bool _debug_mode)
asetArrayFunc = get_function("vm_rary_aset");
entryArrayFunc = get_function("vm_ary_entry");
checkArrayFunc = get_function("vm_ary_check");
+ lengthArrayFunc = get_function("vm_ary_length");
+ ptrArrayFunc = get_function("vm_ary_ptr");
newStructFunc = NULL;
newOpaqueFunc = NULL;
newPointerFunc = NULL;
@@ -6618,14 +6620,13 @@ RoxorCompiler::compile_block_caller(rb_vm_block_t *block)
Value *argv;
const int arity = rb_vm_arity_n(block->arity);
- if (arity < 0) {
+ if (arity == -1) {
// VALUE foo(VALUE rcv, SEL sel, int argc, VALUE *argv)
// {
// return rb_vm_block_eval2(block, rcv, sel, argc, argv);
// }
f = cast<Function>(module->getOrInsertFunction("",
- RubyObjTy, RubyObjTy, PtrTy, Int32Ty, RubyObjPtrTy,
- NULL));
+ RubyObjTy, RubyObjTy, PtrTy, Int32Ty, RubyObjPtrTy, NULL));
Function::arg_iterator arg = f->arg_begin();
rcv = arg++;
sel = arg++;
@@ -6634,7 +6635,26 @@ RoxorCompiler::compile_block_caller(rb_vm_block_t *block)
bb = BasicBlock::Create(context, "EntryBlock", f);
}
+ else if (arity == -2) {
+ // VALUE foo(VALUE rcv, SEL sel, VALUE argv)
+ // {
+ // return rb_block_eval2(block, rcv, sel, RARRAY_LEN(argv),
+ // RARRAY_PTR(argv));
+ // }
+ f = cast<Function>(module->getOrInsertFunction("",
+ RubyObjTy, RubyObjTy, PtrTy, RubyObjTy, NULL));
+ Function::arg_iterator arg = f->arg_begin();
+ rcv = arg++;
+ sel = arg++;
+ Value *argv_ary = arg++;
+
+ bb = BasicBlock::Create(context, "EntryBlock", f);
+
+ argc = CallInst::Create(lengthArrayFunc, argv_ary, "", bb);
+ argv = CallInst::Create(ptrArrayFunc, argv_ary, "", bb);
+ }
else {
+ assert(arity >= 0);
// VALUE foo(VALUE rcv, SEL sel, VALUE arg1, ...)
// {
// VALUE argv[n] = {arg1, ...};
View
@@ -188,6 +188,8 @@ class RoxorCompiler {
Function *asetArrayFunc;
Function *entryArrayFunc;
Function *checkArrayFunc;
+ Function *lengthArrayFunc;
+ Function *ptrArrayFunc;
Function *newStructFunc;
Function *newOpaqueFunc;
Function *newPointerFunc;
View
@@ -944,6 +944,18 @@ vm_ary_entry(VALUE ary, int i)
return rb_ary_entry(ary, i);
}
+PRIMITIVE long
+vm_ary_length(VALUE ary)
+{
+ return RARRAY_LEN(ary);
+}
+
+PRIMITIVE const VALUE *
+vm_ary_ptr(VALUE ary)
+{
+ return RARRAY_PTR(ary);
+}
+
PRIMITIVE VALUE
vm_rary_new(int len)
{

0 comments on commit 4856e8a

Please sign in to comment.