aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp15
-rw-r--r--libshiboken/autodecref.h2
2 files changed, 8 insertions, 9 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index f1287b727..4fdc065eb 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -362,10 +362,10 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << INDENT << "Shiboken::GilState gil;" << endl;
- s << INDENT << "PyObject* py_override = BindingManager::instance().getOverride(this, \"";
- s << func->name() << "\");" << endl;
+ s << INDENT << "Shiboken::AutoDecRef py_override(BindingManager::instance().getOverride(this, \"";
+ s << func->name() << "\"));" << endl;
- s << INDENT << "if (!py_override) {" << endl;
+ s << INDENT << "if (py_override.isNull()) {" << endl;
{
Indentation indentation(INDENT);
if (func->isAbstract()) {
@@ -389,9 +389,9 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << ';' << endl;
s << INDENT << '}' << endl << endl;
- s << INDENT << "PyObject* pyargs = ";
+ s << INDENT << "Shiboken::AutoDecRef pyargs(";
if (func->arguments().isEmpty()) {
- s << "PyTuple_New(0);" << endl;
+ s << "PyTuple_New(0));" << endl;
} else {
QStringList argConversions;
foreach (const AbstractMetaArgument* arg, func->arguments()) {
@@ -423,7 +423,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << "Py_BuildValue(\"(" << getFormatUnitString(func) << ")\"," << endl;
s << argConversions.join(",\n") << endl;
- s << INDENT << ");" << endl;
+ s << INDENT << "));" << endl;
}
s << endl;
@@ -471,9 +471,6 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
writeCodeSnips(s, snips, CodeSnip::End, TypeSystem::NativeCode, func, lastArg);
}
- s << INDENT << "Py_XDECREF(pyargs);" << endl;
- s << INDENT << "Py_XDECREF(py_override);" << endl;
-
if (type) {
s << INDENT << "return ";
s << (shouldDereferenceAbstractMetaTypePointer(func->type()) ? "*" : "") << CPP_RETURN_VAR;
diff --git a/libshiboken/autodecref.h b/libshiboken/autodecref.h
index c5c1e9605..9e8bc6619 100644
--- a/libshiboken/autodecref.h
+++ b/libshiboken/autodecref.h
@@ -57,9 +57,11 @@ public:
Py_XDECREF(m_pyobj);
}
+ bool isNull() const { return m_pyobj == 0; }
/// Returns the pointer of the Python object being held.
PyObject* object() { return m_pyobj; }
operator PyObject*() { return m_pyobj; }
+ operator PyTupleObject*() { return reinterpret_cast<PyTupleObject*>(m_pyobj); }
operator bool() const { return m_pyobj; }
PyObject* operator->() { return m_pyobj; }
private: