#849 [ruby] vector of enums isn't passed correctly

open
Klaus Kämpf
ruby (61)
5
2012-12-10
2007-08-31
dsomerfield
No

I have defined an enum Test::NUMBER and a method with a parameter of type vector<Test::NUMBER>. I have added an include in the swig file for "std_vector.i" and added a %template directive that should handle the vector.

Instead, I get a segfault coming from _wrap_Test_test_enum_vector in the wrapper file. It seems to fail when calling push_back() on the instance of std::vector<Test::NUMBER > (line 3045).

The method is called fine if the parameter is std::vector<int> or just Test::Number.

Incidentally, the included code is a stripped-down a larger project wherein I originally saw the bug. However, since I was calling the method in a different context, the segfault was not occuring, rather the ENUM values were changed. I have not been able to do a simple repro of this.

If you would like to see the code from the bigger project, I can provide that too, since it is an open-source project.

Version info:

ruby 1.8.5
Windows XP SP 2.
Swig 1.3.31
Microsoft Visual C++ 2005.

Note that if you want to use the VC++ project, paths must be changed in the "Debugging" and "Build Swig" properties and

Discussion

  • dsomerfield
    dsomerfield
    2007-08-31

    zipped visual c++ project

     
    Attachments
  • Logged In: YES
    user_id=961712
    Originator: NO

    This file seems to not have been created with the latest release of swig on SVN, but the much older swig1.31.

    Can you download the latest SVN, compile it and try it? Compilation on windows means you will need to install MSYS and autotools for it (this is kind of a pain, I'll admit -- until there's a proper formal release).

    I'm attaching a simple example that works for that version.

    --------
    %module enumvector

    %include std_vector.i

    %inline {
    namespace test {

    enum Number {
    One,
    Two,
    Three
    };

    }

    }

    // this should work, but it is broken as test::Number is interpreted as
    // a class and there's no type_info() for it (I'll see if this can be fixed easily):
    //
    // %template(EnumVector) std::vector< test::Number >;

    %template(EnumVector) std::vector< int >;

     
  • dsomerfield
    dsomerfield
    2007-09-04

    Logged In: YES
    user_id=1174478
    Originator: YES

    I am trying, but not having much luck with the build under windows. If I get it to work, I will give it a try.

     
  • dsomerfield
    dsomerfield
    2007-09-04

    Logged In: YES
    user_id=1174478
    Originator: YES

    Actually, both the 1.31 and the latest from trunk seem to work fine if you don't declare methods with parameters of type vector<test:Number> but rather as vector<int>. That is an acceptable work-around for now, although it would obviously be ideal if enumeration were recognized as such.

     
  • Olly Betts
    Olly Betts
    2007-09-18

    • summary: vector of enums isn't passed correctly --> [ruby] vector of enums isn't passed correctly
     
  • John Lenz
    John Lenz
    2007-09-18

    Logged In: YES
    user_id=153408
    Originator: NO

    Try the latest svn... I recently fixed a bug very similar to this... I suspect it is fixed now.

     
  •  
    Attachments
  • Logged In: YES
    user_id=961712
    Originator: NO

    Sadly, the bug persists. The problem is how the type_info() is handled as the enum is not interpreted as an int, but as a class. The problem shows up on ruby only because by default the std_vector.i classes know how to print themselves out unlike python or other languages.

    I have attached an even simpler .i file with a Makefile for linux showing the bug. I don't think the problem lies with the ruby module, but how swig's parser handles enums.
    File Added: gga_example.zip

     
  • William Fulton
    William Fulton
    2012-12-10

    • assigned_to: gga73 --> kkaempf