Fix Java swigReleaseOwnership() and swigTakeOwnership() regression
Fixes segfault when using non-director classes. Restores a dynamic_cast which was previously removed. The dynamic_cast is not needed for the swig_connect_director call ... we'll have to find another solution for #449 for Java. Closes #1184
This commit is contained in:
parent
3ce3ce0683
commit
b4f4ce4fd5
5 changed files with 125 additions and 5 deletions
72
Examples/test-suite/director_ownership.i
Normal file
72
Examples/test-suite/director_ownership.i
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
%module(directors="1") director_ownership
|
||||
|
||||
// Github issue #1184
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") example::ContentBase;
|
||||
%feature("director") example::ContentDerived;
|
||||
|
||||
%newobject example::make_content;
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
namespace example
|
||||
{
|
||||
|
||||
class ContentBase
|
||||
{
|
||||
public:
|
||||
ContentBase() {}
|
||||
virtual ~ContentBase() {}
|
||||
virtual std::string get_name() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ContentDerived: public ContentBase
|
||||
{
|
||||
public:
|
||||
ContentDerived():ContentBase() { m_name = "ContentDerived"; }
|
||||
virtual ~ContentDerived() {}
|
||||
virtual std::string get_name() const override { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
Container() { m_content = 0; }
|
||||
~Container()
|
||||
{
|
||||
clear_content();
|
||||
}
|
||||
// the container takes the ownership of the content
|
||||
void set_content(ContentBase* content)
|
||||
{
|
||||
clear_content();
|
||||
m_content = content;
|
||||
}
|
||||
ContentBase* get_content() { return m_content; }
|
||||
|
||||
private:
|
||||
void clear_content()
|
||||
{
|
||||
if(m_content)
|
||||
{
|
||||
delete m_content;
|
||||
m_content = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ContentBase* m_content;
|
||||
};
|
||||
|
||||
static ContentBase* make_content() { return new ContentDerived(); }
|
||||
|
||||
} // namespace example
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue