Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes the 'unref' feature when used on classes with non-public destructors.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12155 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d0d40db326
commit
cca92f4188
6 changed files with 92 additions and 1 deletions
|
|
@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.1 (in progress)
|
Version 2.0.1 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2010-07-08: wsfulton
|
||||||
|
Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes
|
||||||
|
the "unref" feature when used on classes with non-public destructors.
|
||||||
|
|
||||||
2010-06-10: wsfulton
|
2010-06-10: wsfulton
|
||||||
[Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple
|
[Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple
|
||||||
modules and wrapping strings. Patch from 'Number Cruncher'.
|
modules and wrapping strings. Patch from 'Number Cruncher'.
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,8 @@ public class runme
|
||||||
int sum = li_boost_shared_ptr_bits.sum(v);
|
int sum = li_boost_shared_ptr_bits.sum(v);
|
||||||
if (sum != 66)
|
if (sum != 66)
|
||||||
throw new ApplicationException("sum is wrong");
|
throw new ApplicationException("sum is wrong");
|
||||||
|
|
||||||
|
HiddenDestructor hidden = HiddenDestructor.create();
|
||||||
|
hidden.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,8 @@ public class li_boost_shared_ptr_bits_runme {
|
||||||
int sum = li_boost_shared_ptr_bits.sum(v);
|
int sum = li_boost_shared_ptr_bits.sum(v);
|
||||||
if (sum != 66)
|
if (sum != 66)
|
||||||
throw new RuntimeException("sum is wrong");
|
throw new RuntimeException("sum is wrong");
|
||||||
|
|
||||||
|
HiddenDestructor hidden = HiddenDestructor.create();
|
||||||
|
hidden.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,81 @@ int sum(std::vector< boost::shared_ptr<IntHolder> > v) {
|
||||||
|
|
||||||
%template(VectorIntHolder) std::vector< boost::shared_ptr<IntHolder> >;
|
%template(VectorIntHolder) std::vector< boost::shared_ptr<IntHolder> >;
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Test non public destructor - was leading to memory leaks as the destructor was not wrapped
|
||||||
|
// Bug 3024875
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
%shared_ptr(HiddenDestructor)
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
class HiddenDestructor;
|
||||||
|
typedef boost::shared_ptr< HiddenDestructor > FooPtr;
|
||||||
|
|
||||||
|
class HiddenDestructor {
|
||||||
|
public:
|
||||||
|
static FooPtr create();
|
||||||
|
virtual void doit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HiddenDestructor();
|
||||||
|
static void Foo_body( FooPtr self );
|
||||||
|
virtual ~HiddenDestructor();
|
||||||
|
private:
|
||||||
|
HiddenDestructor( const HiddenDestructor& );
|
||||||
|
class Impl;
|
||||||
|
Impl* impl_;
|
||||||
|
|
||||||
|
class FooDeleter {
|
||||||
|
public:
|
||||||
|
void operator()(HiddenDestructor* hidden) {
|
||||||
|
delete hidden;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/* Impl would generally hold a weak_ptr to HiddenDestructor a.s.o, but this stripped down example should suffice */
|
||||||
|
class HiddenDestructor::Impl {
|
||||||
|
public:
|
||||||
|
int mymember;
|
||||||
|
};
|
||||||
|
|
||||||
|
FooPtr HiddenDestructor::create()
|
||||||
|
{
|
||||||
|
FooPtr hidden( new HiddenDestructor(), HiddenDestructor::FooDeleter() );
|
||||||
|
Foo_body( hidden );
|
||||||
|
return hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HiddenDestructor::doit()
|
||||||
|
{
|
||||||
|
// whatever
|
||||||
|
}
|
||||||
|
|
||||||
|
HiddenDestructor::HiddenDestructor()
|
||||||
|
{
|
||||||
|
// cout << "HiddenDestructor::HiddenDestructor()" << endl;
|
||||||
|
// always empty
|
||||||
|
}
|
||||||
|
|
||||||
|
void HiddenDestructor::Foo_body( FooPtr self )
|
||||||
|
{
|
||||||
|
// init self as you would do in ctor
|
||||||
|
self->impl_ = new Impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
HiddenDestructor::~HiddenDestructor()
|
||||||
|
{
|
||||||
|
// cout << "HiddenDestructor::~HiddenDestructor()" << endl;
|
||||||
|
// destruct (e.g. delete Pimpl object)
|
||||||
|
delete impl_;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
////////////////////////////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,6 @@ sum = sum(v)
|
||||||
if sum != 66:
|
if sum != 66:
|
||||||
raise "sum is wrong"
|
raise "sum is wrong"
|
||||||
|
|
||||||
|
################################
|
||||||
|
p = HiddenDestructor.create()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2697,7 +2697,7 @@ int Language::destructorDeclaration(Node *n) {
|
||||||
|
|
||||||
if (!CurrentClass)
|
if (!CurrentClass)
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
if (cplus_mode != PUBLIC)
|
if (cplus_mode != PUBLIC && !Getattr(CurrentClass, "feature:unref"))
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
if (ImportMode)
|
if (ImportMode)
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue