From: SourceForge.net <no...@so...> - 2009-01-07 01:11:46
|
Patches item #2408020, was opened at 2008-12-08 16:32 Message generated for change (Comment added) made by jwhitley You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=301645&aid=2408020&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: John Whitley (jwhitley) Assigned to: Nobody/Anonymous (nobody) Summary: [ruby] std::vector and -minherit load failure Initial Comment: Version : SWIG 1.3.36 Repro steps: 1) Create a SWIG Ruby interface that uses std::vector for some type, e.g. Foo. 2) Specialize template via: %template (FooVector) std::vector<Foo>; 2) Build and attempt to load the extension Actual result: Load fails with an exception since the generated line in the method section for FooVector's wrapper code: rb_define_alias(cFooVector.klass, "delete_if", "reject!") This is because rb_define_alias is called _before_ rb_include_module(cFooVector.klass, cFooVector.mImpl) when multiple inheritance support is employed. Expected result: Loads correctly. Notes: This is a bug introduced during the Ruby STL upgrades between 1.3.31 and 1.3.36. The attached patch fixes the problem by moving the rb_include_module() call to the head of the wrapped function's init section. Note that it is perfectly acceptable to do the include operation in Ruby before methods are defined on the included module. ---------------------------------------------------------------------- Comment By: John Whitley (jwhitley) Date: 2009-01-06 17:11 Message: I can get a repro with the temp.i code; see below for excpetion. An key note: I'm interfacing with Ruby 1.8.7 p72. I'm building both Ruby and the SWIG extension with VC8 (VS2005), but I don't think that's relevant here since the issue appears to be Ruby API semantics, not the compilation environment. >ruby -e 'require "temp"' (eval): undefined method `reject!' for class `Temp::VectMultipleDerived' (NameError) from -e:1 Again, with the patch provided, this code works as expected. ---------------------------------------------------------------------- Comment By: William Fulton (wsfulton) Date: 2008-12-29 05:11 Message: I can't replicate the problem. Please supply a testcase. I've tried with the interface file below with swig -c++ -ruby -minherit ../temp.i // File: temp.i %module temp %include <std_vector.i> %inline %{ struct Struct { double num; Struct() : num(0.0) {} Struct(double d) : num(d) {} }; struct Base1 { }; struct MultipleDerived : Struct, Base1 { }; %} %template(VectMultipleDerived) std::vector<MultipleDerived>; %inline %{ std::vector<MultipleDerived> vect_multiple_derived(std::vector<MultipleDerived> v) { return v; } %} and ruby code: require 'temp' include Temp vmd = VectMultipleDerived.new() vmd2 = vect_multiple_derived(vmd) ---------------------------------------------------------------------- Comment By: John Whitley (jwhitley) Date: 2008-12-09 13:52 Message: On rereading, my prose above about the problem ... is lacking. Let me try again: the issue is that rb_define_alias() is called on cFooVector.klass, but the "reject!" method isn't yet defined on that class since rb_include_module() hasn't been called yet. ("reject!" is defined on cFooVector.mImpl, under -minherit). Thus Ruby throws an exception on the rb_define_alias call since the target method doesn't exist. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=301645&aid=2408020&group_id=1645 |