Fix %newobject when used in conjunction with %feature(ref). The code from the ref feature was not always being generated for the function specified by %newobject. Documentation for ref and unref moved from Python to the C++ chapter.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12783 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
86e1051a8b
commit
c794d08597
8 changed files with 262 additions and 160 deletions
|
|
@ -10,14 +10,14 @@ b2 = B.create(a)
|
|||
|
||||
|
||||
if a.ref_count() != 3:
|
||||
print "This program will crash... now"
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
||||
rca = b2.get_rca()
|
||||
b3 = B.create(rca)
|
||||
|
||||
if a.ref_count() != 5:
|
||||
print "This program will crash... now"
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
||||
v = vector_A(2)
|
||||
|
|
@ -27,6 +27,35 @@ v[1] = a
|
|||
x = v[0]
|
||||
del v
|
||||
|
||||
if a.ref_count() != 6:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
# Check %newobject
|
||||
b4 = b2.cloner()
|
||||
if b4.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b5 = global_create(a)
|
||||
if b5.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b6 = Factory.create(a)
|
||||
if b6.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b7 = Factory().create2(a)
|
||||
if b7.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if a.ref_count() != 10:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
del b4
|
||||
del b5
|
||||
del b6
|
||||
del b7
|
||||
|
||||
if a.ref_count() != 6:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
%}
|
||||
|
||||
//
|
||||
// using the %refobject/%unrefobject directives you can active the
|
||||
// ref. counting for RCObj and all its descendents at once
|
||||
// using the %refobject/%unrefobject directives you can activate the
|
||||
// reference counting for RCObj and all its descendents at once
|
||||
//
|
||||
|
||||
%refobject RCObj "$this->addref();"
|
||||
|
|
@ -18,7 +18,10 @@
|
|||
%include "refcount.h"
|
||||
|
||||
%newobject B::create(A* a);
|
||||
%newobject global_create(A* a);
|
||||
%newobject B::cloner();
|
||||
%newobject Factory::create(A* a);
|
||||
%newobject Factory::create2(A* a);
|
||||
|
||||
|
||||
|
||||
|
|
@ -94,6 +97,22 @@
|
|||
RCPtr<A> _a;
|
||||
};
|
||||
|
||||
class B* global_create(A* a)
|
||||
{
|
||||
return new B(a);
|
||||
}
|
||||
|
||||
struct Factory {
|
||||
static B* create(A* a)
|
||||
{
|
||||
return new B(a);
|
||||
}
|
||||
B* create2(A* a)
|
||||
{
|
||||
return new B(a);
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGOCTAVE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue