aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-15 18:29:06 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:12:49 -0300
commit18fedbce6893ee76c3dce04f0aaf814c93d57a34 (patch)
treeacfcc6050e0dbf2da513de7f5c30bbddddd1e145
parent39069c1571e3fe2705b4dcb6f58d3b1e50a42911 (diff)
Generate code to release ownership on Python values returned to C++ on virtual methods.
In other words, the following type system snippet will now be recognized by the generator: <modify-argument index="return"> <define-ownership class="native" owner="c++"/> </modify-argument>
-rw-r--r--generator/cppgenerator.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index ecd054c28..a5b06457e 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -743,6 +743,16 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
Indentation indentation(INDENT);
s << INDENT << "Shiboken::Object::invalidate(PyTuple_GET_ITEM(pyargs, ";
s << (argMod.index - 1) << "));" << endl;
+ } else if (argMod.ownerships.contains(TypeSystem::NativeCode)) {
+ if (argMod.index == 0 && argMod.ownerships[TypeSystem::NativeCode] == TypeSystem::CppOwnership) {
+ s << INDENT << "if (Shiboken::Object::checkType(" PYTHON_RETURN_VAR ")) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "Shiboken::Object::releaseOwnership(" PYTHON_RETURN_VAR ");" << endl;
+ s << INDENT << "Py_DECREF((PyObject*) " PYTHON_RETURN_VAR ");" << endl;
+ }
+ s << INDENT << '}' << endl;
+ }
}
}
}