kkaempf / swig-issues

Issues from SWIG (testing)
0 stars 0 forks source link

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

Open SwigAtSF opened 11 years ago

SwigAtSF commented 11 years ago

I have defined an enum Test::NUMBER and a method with a parameter of type vectorTest::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 (line 3045).

The method is called fine if the parameter is std::vector 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

SwigAtSF commented 11 years ago

zipped visual c++ project

SwigAtSF commented 11 years ago

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 >;

SwigAtSF commented 11 years ago

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.

SwigAtSF commented 11 years ago

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 vectortest:Number but rather as vector. That is an acceptable work-around for now, although it would obviously be ideal if enumeration were recognized as such.

SwigAtSF commented 11 years ago

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.

SwigAtSF commented 11 years ago

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

SwigAtSF commented 11 years ago