summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2011-03-30 16:37:43 -0300
committerLauro Neto <lauro.neto@openbossa.org>2011-03-31 15:12:36 -0300
commit35db2961d9c945a0666ac96dbbd7c9f0c33b8e08 (patch)
tree2de1eae966c9924704d6997c78c50c5b2c3b1a1b
parent1b992e1bcb85549f892c44c263e312174a8fd20b (diff)
downloadshiboken-35db2961d9c945a0666ac96dbbd7c9f0c33b8e08.tar.gz
shiboken-35db2961d9c945a0666ac96dbbd7c9f0c33b8e08.tar.xz
shiboken-35db2961d9c945a0666ac96dbbd7c9f0c33b8e08.zip
Check for old-style bases before calling tp_new1.0.1
Instead of creating the type instance and them checking for old-style base classes, check for them in the beginning. The later check was causing the new type object to "leak" and failing an assert in the garbage collector. Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Reviewer: Hugo Lima <hugo.lima@openbossa.org>
-rw-r--r--libshiboken/basewrapper.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index ba4911f2..6a15a031 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -202,17 +202,21 @@ void SbkObjectTypeDealloc(PyObject* pyObj)
PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds)
{
- // The meta type creates a new type when the Python programmer extends a wrapped C++ class.
- SbkObjectType* newType = reinterpret_cast<SbkObjectType*>(PyType_Type.tp_new(metatype, args, kwds));
-
- if (!newType)
- return 0;
-
- Shiboken::ObjectType::initPrivateData(newType);
- SbkObjectTypePrivate* d = newType->d;
+ // Check if all bases are new style before calling type.tp_new
+ // Was causing gc assert errors in test_bug704.py when
+ // this check happened after creating the type object.
+ // Argument parsing take from type.tp_new code.
+ PyObject* name;
+ PyObject* pyBases;
+ PyObject* dict;
+ static char* kwlist[] = { "name", "bases", "dict", 0};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:sbktype", kwlist,
+ &name,
+ &PyTuple_Type, &pyBases,
+ &PyDict_Type, &dict))
+ return NULL;
- // Check if all objects are python new style
- PyObject* pyBases = ((PyTypeObject*)newType)->tp_bases;
for(int i=0, i_max=PyTuple_GET_SIZE(pyBases); i < i_max; i++) {
PyObject* baseType = PyTuple_GET_ITEM(pyBases, i);
if (PyClass_Check(baseType)) {
@@ -221,6 +225,14 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k
}
}
+ // The meta type creates a new type when the Python programmer extends a wrapped C++ class.
+ SbkObjectType* newType = reinterpret_cast<SbkObjectType*>(PyType_Type.tp_new(metatype, args, kwds));
+
+ if (!newType)
+ return 0;
+
+ Shiboken::ObjectType::initPrivateData(newType);
+ SbkObjectTypePrivate* d = newType->d;
std::list<SbkObjectType*> bases = Shiboken::getCppBaseClasses(reinterpret_cast<PyTypeObject*>(newType));
if (bases.size() == 1) {