bug: segfault when using super and method_missing

Discussion in 'Ruby' started by Brad Hilton, Mar 23, 2006.

  1. Brad Hilton

    Brad Hilton Guest

    Hello,

    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.

    Thanks,
    Brad

    ------------------------------------
    class BaseClass
    def method_missing(*args)
    p args
    end
    end

    class Article < BaseClass

    # if this is defined as title=(arg) the segfault does not occur
    def title=(*args)
    super(args) # works
    super(*args) # works
    super # segfault...
    end
    end

    a = Article.new
    a.body = 'body'
    a.title = 'foo'
    -------------------------------
     
    Brad Hilton, Mar 23, 2006
    #1
    1. Advertising

  2. RE : segfault when using super and method_missing

    Hi,

    This works for me. I've tried both:

    ruby 1.8.2 (2004-12-25) [i386-mswin32] (Windows)
    ruby 1.8.4 (2005-12-24) [i386-linux] (gentoo linux)

    Just a guess, but maybe you compiled ruby with to much optimizations in
    CFLAGS ? Mine are

    CFLAGS="-O2 -fomit-frame-pointer"

    Hope this helps...

    Guillaume

    > Brad Hilton wrote:
    >
    > Hello,
    >
    > 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.
    >
    > Thanks,
    > Brad
    >
    > ------------------------------------
    > class BaseClass
    > def method_missing(*args)
    > p args
    > end
    > end
    >
    > class Article < BaseClass
    >
    > # if this is defined as title=(arg) the segfault does not occur
    > def title=(*args)
    > super(args) # works
    > super(*args) # works
    > super # segfault...
    > end
    > end
    >
    > a = Article.new
    > a.body = 'body'
    > a.title = 'foo'
    > -------------------------------
     
    Guillaume Benny, Mar 23, 2006
    #2
    1. Advertising

  3. Hi,

    In message "Re: bug: segfault when using super and method_missing"
    on Thu, 23 Mar 2006 10:09:37 +0900, Brad Hilton <> 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);
     
    Yukihiro Matsumoto, Mar 23, 2006
    #3
  4. Brad Hilton wrote:
    > Hello,
    >
    > The following code produces a segfault with ruby-1.8.4 from gentoo, as


    It's ok on

    ruby 1.8.4 (2005-12-24) [i686-linux]

    built from source with the default options (on ubuntu).

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, Mar 23, 2006
    #4
  5. Hi,

    In message "Re: bug: segfault when using super and method_missing"
    on Thu, 23 Mar 2006 10:50:01 +0900, Joel VanderWerf <> writes:

    |It's ok on
    |
    |ruby 1.8.4 (2005-12-24) [i686-linux]
    |
    |built from source with the default options (on ubuntu).

    It happens only on CVS top.

    matz.
     
    Yukihiro Matsumoto, Mar 23, 2006
    #5
  6. Brad Hilton

    Brad Hilton Guest

    On Mar 22, 2006, at 5:49 PM, Yukihiro Matsumoto wrote:
    >
    > A bug was in super without any argument. The patch attached should
    > fix the bug. Thank you for reporting it.


    Thanks for your help and the quick patch!

    -Brad
     
    Brad Hilton, Mar 23, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,843
    Darryl Pierce
    Feb 24, 2005
  2. Fernando Rodriguez

    Getting the super class via the super() function

    Fernando Rodriguez, Nov 21, 2003, in forum: Python
    Replies:
    2
    Views:
    738
    Bob Willan
    Nov 22, 2003
  3. Kerim Borchaev

    super. could there be a simpler super?

    Kerim Borchaev, Jan 15, 2004, in forum: Python
    Replies:
    4
    Views:
    484
    Michele Simionato
    Jan 15, 2004
  4. Andrey Vul
    Replies:
    8
    Views:
    706
    Richard Bos
    Jul 30, 2010
  5. Hugh Sasse Staff Elec Eng

    Inheriting variables, super, and "not super"?

    Hugh Sasse Staff Elec Eng, Dec 9, 2003, in forum: Ruby
    Replies:
    7
    Views:
    136
    Hugh Sasse Staff Elec Eng
    Dec 11, 2003
Loading...

Share This Page