Menu

#1102 [ruby] Segfault with "using" declaration with templates

None
closed-fixed
ruby (61)
5
2023-08-05
2010-07-24
No

If a template is instantiated which has a -> operator overload, and the class wrapped by the template contains a "using" declaration for members inherited from a base class, SWIG segfaults. The problem appears to affect only ruby (seems to be in documentation generation code?) generation. Attached is the smallest example I could come up with. The bug is in 1.3.40 and 2.0.0.

Discussion

  • Jason Turner

    Jason Turner - 2010-07-24

    sample illustrating crash

     
  • Olly Betts

    Olly Betts - 2010-10-01
    • summary: Segfault with "using" declaration with ruby and templates --> [ruby] Segfault with "using" declaration with templates
    • assigned_to: gga73 --> wsfulton
     
  • Olly Betts

    Olly Betts - 2010-10-01

    The issue is that the node for the method lacks a parent reference, so this code can't now get the classname in this case.

    I've committed a change to trunk r12237 which avoids the segfault by leaving out the classname if the parent reference isn't present.

    The generated string only seems to be used in an exception message, so it's largely cosmetic, but I suspect my "fix" is really just working around the issue - either the parent reference should be getting set on the method node, or the code should be finding the class name in a different way.

    But I'm not familiar enough with how this should work to know what's wrong here - assigning to William for comments (if my change is suitable, please just close the ticket).

     
  • Olly Betts

    Olly Betts - 2022-02-01

    There's still no parentNode on the fun nodes for OptionalDerived but there is for those from Derived, so the exception messages for the former lack the classname:

    $ grep -A2 'Ruby_Format_OverloadedError( ' Test_SWIG_Crash_wrap.cxx
      Ruby_Format_OverloadedError( argc, 3, "fun", 
        "    void fun()\n"
        "    void fun(float)\n");
    --
      Ruby_Format_OverloadedError( argc, 3, "Derived.fun", 
        "    void Derived.fun(int)\n"
        "    void Derived.fun(float)\n");
    
     
  • Olly Betts

    Olly Betts - 2023-08-05
    • status: open --> closed-fixed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2023-08-05

    This is fixed in current git master which generates code with Derived.fun in both chunks of code shown above.

    git bisect shows the commit fixing it as being:

    commit 49e60c7d5617f482026e8585d02ddc3f8244e2e5
    Author: William S Fulton <wsf@fultondesigns.co.uk>
    Date:   Sat Jun 24 11:43:15 2023 +0100
    
        Fix directors and allprotected mode and using declarations.
    
        Fixes recently introduced seg fault, but this has never worked properly.
    
        Closes #2616
    
     CHANGES.current                                  |  5 ++++
     Examples/test-suite/allprotected.i               | 31 ++++++++++++++++++++++++
     Examples/test-suite/csharp/allprotected_runme.cs | 14 +++++++++++
     Examples/test-suite/d/allprotected_runme.2.d     | 16 ++++++++++++
     Examples/test-suite/java/allprotected_runme.java | 13 ++++++++++
     Source/Modules/lang.cxx                          | 19 +++++++++------
     Source/Modules/typepass.cxx                      |  3 +++
     7 files changed, 94 insertions(+), 7 deletions(-)
    

    FIx should be in upcoming 4.2.0 release.

     

Log in to post a comment.