From: David N. <co...@kl...> - 2010-12-31 02:05:22
|
Consider the following piece of code (ignoring the memory leak in createBarAndGetId for the sake of simplicity): --- %module(directors="1") director_weird; %feature("director") Foo; %inline %{ struct Foo { virtual ~Foo() {} virtual int id() { return 0; } }; struct Bar : Foo {}; struct Baz : Bar { virtual int id() { return 2; } }; Bar* createBar() { return new Baz; } int createBarAndGetId() { return createBar()->id(); } %} --- Note that createBar really creates and returns a Baz (which overrides Foo::id()), and that the director feature is enabled for Foo. When called from C++, createBar()->id() and createBarAndGetId() obviously return the same value. This assumption also holds when using the code from Python: ( director_weird.createBar().id() == director_weird.createBarAndGetId() ) yields True. However, when createBar().id() is called from Java (or C# and D which share the same basic mechanism for implementing directors), it »resolves« to Foo::id() and yields 0, while createBarAndGetId() still returns 2, of course. This happens because Foo.id() calls Foo_idSwigExplicitFoo in this case, which in turn specifically calls (arg1)->Foo::id(). This is certainly not what I'd expect, and I also got a bug report for the D module related to this, but did this really stay unnoticed in the C# and Java modules for so long? Or am I missing something? David |