##// END OF EJS Templates
fixed bad reference counting and borrowed references...
florianlink -
r19:4f416979f8bf
parent child
Show More
@@ -293,13 +293,14 void PythonQtPrivate::registerClass(const QMetaObject* metaobject, const char* p
293 PythonQtClassInfo* PythonQtPrivate::createPythonQtClassInfo(const QMetaObject* meta, const char* cppClassName, const char* package)
293 PythonQtClassInfo* PythonQtPrivate::createPythonQtClassInfo(const QMetaObject* meta, const char* cppClassName, const char* package)
294 {
294 {
295 PythonQtClassInfo* info = new PythonQtClassInfo(meta, cppClassName);
295 PythonQtClassInfo* info = new PythonQtClassInfo(meta, cppClassName);
296 PythonQtObjectPtr pack = packageByName(package);
296 PyObject* pack = packageByName(package);
297 PyObject* pyobj = (PyObject*)createNewPythonQtClassWrapper(info, package);
297 PyObject* pyobj = (PyObject*)createNewPythonQtClassWrapper(info, package);
298 PyModule_AddObject(pack, meta?meta->className():cppClassName, pyobj);
298 PyModule_AddObject(pack, meta?meta->className():cppClassName, pyobj);
299 if (package && strncmp(package,"Qt",2)==0) {
299 if (package && strncmp(package,"Qt",2)==0) {
300 // since PyModule_AddObject steals the reference, we need a incref once more...
301 Py_INCREF(pyobj);
300 // put all qt objects into Qt as well
302 // put all qt objects into Qt as well
301 PythonQtObjectPtr pack = packageByName("Qt");
303 PyModule_AddObject(packageByName("Qt"), meta?meta->className():cppClassName, pyobj);
302 PyModule_AddObject(pack, meta?meta->className():cppClassName, pyobj);
303 }
304 }
304 info->setPythonQtClassWrapper(pyobj);
305 info->setPythonQtClassWrapper(pyobj);
305 return info;
306 return info;
@@ -474,8 +475,6 PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla
474 Py_DECREF(args);
475 Py_DECREF(args);
475 Py_DECREF(className);
476 Py_DECREF(className);
476
477
477 //TODO XXX why is this incref needed? It looks like the types get garbage collected somehow?!
478 Py_INCREF((PyObject*)result);
479 return result;
478 return result;
480 }
479 }
481
480
@@ -1016,7 +1015,7 static PyMethodDef PythonQtMethods[] = {
1016
1015
1017 void PythonQt::initPythonQtModule(bool redirectStdOut)
1016 void PythonQt::initPythonQtModule(bool redirectStdOut)
1018 {
1017 {
1019 _p->_pythonQtModule.setNewRef(Py_InitModule("PythonQt", PythonQtMethods));
1018 _p->_pythonQtModule = Py_InitModule("PythonQt", PythonQtMethods);
1020
1019
1021 if (redirectStdOut) {
1020 if (redirectStdOut) {
1022 PythonQtObjectPtr sys;
1021 PythonQtObjectPtr sys;
@@ -1055,15 +1054,17 void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentT
1055 }
1054 }
1056 }
1055 }
1057
1056
1058 PythonQtObjectPtr PythonQtPrivate::packageByName(const char* name)
1057 PyObject* PythonQtPrivate::packageByName(const char* name)
1059 {
1058 {
1060 if (name==NULL || name[0]==0) {
1059 if (name==NULL || name[0]==0) {
1061 return _pythonQtModule;
1060 return _pythonQtModule;
1062 }
1061 }
1063 PythonQtObjectPtr v = _packages.value(name);
1062 PyObject* v = _packages.value(name);
1064 if (!v) {
1063 if (!v) {
1065 v.setNewRef(PyImport_AddModule((QByteArray("PythonQt.") + name).constData()));
1064 v = PyImport_AddModule((QByteArray("PythonQt.") + name).constData());
1066 _packages.insert(name, v);
1065 _packages.insert(name, v);
1066 // AddObject steals the reference, so increment it!
1067 Py_INCREF(v);
1067 PyModule_AddObject(_pythonQtModule, name, v);
1068 PyModule_AddObject(_pythonQtModule, name, v);
1068 }
1069 }
1069 return v;
1070 return v;
@@ -451,8 +451,8 private:
451 //! create a new class info and python wrapper type
451 //! create a new class info and python wrapper type
452 PythonQtClassInfo* createPythonQtClassInfo(const QMetaObject* meta, const char* cppClassName, const char* package);
452 PythonQtClassInfo* createPythonQtClassInfo(const QMetaObject* meta, const char* cppClassName, const char* package);
453
453
454 //! get/create new package module
454 //! get/create new package module (the returned object is a borrowed reference)
455 PythonQtObjectPtr packageByName(const char* name);
455 PyObject* packageByName(const char* name);
456
456
457 //! get the wrapper for a given pointer (and remove a wrapper of an already destroyed qobject)
457 //! get the wrapper for a given pointer (and remove a wrapper of an already destroyed qobject)
458 PythonQtInstanceWrapper* findWrapperAndRemoveUnused(void* obj);
458 PythonQtInstanceWrapper* findWrapperAndRemoveUnused(void* obj);
@@ -495,7 +495,7 private:
495 QHash<QByteArray , PythonQtSlotInfo *> _constructorSlots;
495 QHash<QByteArray , PythonQtSlotInfo *> _constructorSlots;
496 QHash<QByteArray , PythonQtSlotInfo *> _destructorSlots;
496 QHash<QByteArray , PythonQtSlotInfo *> _destructorSlots;
497
497
498 QHash<QByteArray, PythonQtObjectPtr> _packages;
498 QHash<QByteArray, PyObject*> _packages;
499
499
500 PythonQtClassInfo* _currentClassInfoForClassWrapperCreation;
500 PythonQtClassInfo* _currentClassInfoForClassWrapperCreation;
501
501
General Comments 0
You need to be logged in to leave comments. Login now