Fixed a bug in Ruby's object tracking functionality. Previously, an object could be returned even if it did not have the correct type. This could occur if a factory class' creation method had a signature returning a base type (like geometry) but in reality a subclass (like Point) was returned. In that case, it would then be impossible to implement a "downcast" method and get back a Ruby object of type Point. Also updated the test-suite to test this situation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8861 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
51537af05a
commit
e66f81f904
3 changed files with 81 additions and 16 deletions
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
%apply SWIGTYPE *DISOWN {Foo* ownedFoo};
|
||||
|
||||
|
||||
%trackobjects ItemA;
|
||||
%trackobjects ItemB;
|
||||
|
||||
%inline %{
|
||||
|
||||
class Foo
|
||||
|
|
@ -92,4 +96,30 @@ public:
|
|||
unowned_ = foo;
|
||||
}
|
||||
};
|
||||
|
||||
class ItemA
|
||||
{
|
||||
};
|
||||
|
||||
class ItemB: public ItemA
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
ItemB* downcast(ItemA* item)
|
||||
{
|
||||
return static_cast<ItemB*>(item);
|
||||
}
|
||||
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
Factory() {}
|
||||
|
||||
ItemA* createItem()
|
||||
{
|
||||
return new ItemB;
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue