summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-15 18:29:06 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-16 14:11:40 -0300
commitf728e59aa228d5b796b5641bea683333b10919e4 (patch)
treecdb482d3b3e8f0b805d5d65c5028fe9d4292ccdf /generator
parent4b866fc793113e84c276eb972eb99a457074018c (diff)
downloadshiboken-f728e59aa228d5b796b5641bea683333b10919e4.tar.gz
shiboken-f728e59aa228d5b796b5641bea683333b10919e4.tar.xz
shiboken-f728e59aa228d5b796b5641bea683333b10919e4.zip
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>
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 29a70582..7664fb98 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;
+ }
}
}
}