Yukihiro Matsumoto
3/23/2006 1:50:00 AM
Hi,
In message "Re: bug: segfault when using super and method_missing"
on Thu, 23 Mar 2006 10:09:37 +0900, Brad Hilton <bhilton@vpop.net> writes:
|The following code produces a segfault with ruby-1.8.4 from gentoo,
|as well as with ruby-1.8 from cvs and 1.9 from cvs. There appears to
|be an issue when super is called in the subclass and the parent class
|has method_missing defined. Strangely, if super is called with
|explicit arguments, no segfault occurs. Likewise, if the method
|definition in the subclass is modified slightly (see below) the
|segfault is avoided.
A bug was in super without any argument. The patch attached should
fix the bug. Thank you for reporting it.
matz.
--- eval.c 3 Mar 2006 17:39:26 -0000 1.616.2.165
+++ eval.c 23 Mar 2006 01:48:22 -0000
@@ -5578,7 +5578,18 @@ method_missing(obj, id, argc, argv, call
}
+ if (argc < 0) {
+ VALUE tmp;
- nargv = ALLOCA_N(VALUE, argc+1);
- nargv[0] = ID2SYM(id);
- MEMCPY(nargv+1, argv, VALUE, argc);
+ argc = -argc-1;
+ tmp = splat_value(argv[argc]);
+ nargv = ALLOCA_N(VALUE, argc + RARRAY(tmp)->len + 1);
+ MEMCPY(nargv+1, argv, VALUE, argc);
+ MEMCPY(nargv+1+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
+ argc += RARRAY(tmp)->len;
+ }
+ else {
+ nargv = ALLOCA_N(VALUE, argc+1);
+ MEMCPY(nargv+1, argv, VALUE, argc);
+ }
+ nargv[0] = ID2SYM(id);
return rb_funcall2(obj, missing, argc+1, nargv);