Patch PythonQt:
- preserve the reference count of arguments passed to wrapped functions - don't dump all over the stack of functions that call PythonQtConv::ConvertPythonToQt - convert :: to _ in value type names
This commit is contained in:
parent
51e031df2b
commit
8422b844b1
|
@ -0,0 +1,15 @@
|
|||
diff --git a/3rdparty/pythonqt/src/PythonQtClassWrapper.cpp b/3rdparty/pythonqt/src/PythonQtClassWrapper.cpp
|
||||
index 4c3e280..411c7bf 100644
|
||||
--- a/3rdparty/pythonqt/src/PythonQtClassWrapper.cpp
|
||||
+++ b/3rdparty/pythonqt/src/PythonQtClassWrapper.cpp
|
||||
@@ -275,7 +275,9 @@ PyObject *PythonQtClassWrapper__init__(PythonQtClassWrapper *type, PyObject *arg
|
||||
if (PyObject_TypeCheck(self, (PyTypeObject*)type->classInfo()->pythonQtClassWrapper())) {
|
||||
PyObject* newargs = PyTuple_New(argc-1);
|
||||
for (int i = 0;i<argc-1; i++) {
|
||||
- PyTuple_SET_ITEM(newargs, i,PyTuple_GET_ITEM(args, i+1));
|
||||
+ PyObject* item = PyTuple_GET_ITEM(args, i+1);
|
||||
+ Py_INCREF(item);
|
||||
+ PyTuple_SET_ITEM(newargs, i, item);
|
||||
}
|
||||
PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self;
|
||||
int result = PythonQtInstanceWrapper_init(wrapper, newargs, NULL);
|
|
@ -0,0 +1,52 @@
|
|||
diff --git a/3rdparty/pythonqt/src/PythonQtConversion.cpp b/3rdparty/pythonqt/src/PythonQtConversion.cpp
|
||||
index 0fbe291..7ea97c4 100644
|
||||
--- a/3rdparty/pythonqt/src/PythonQtConversion.cpp
|
||||
+++ b/3rdparty/pythonqt/src/PythonQtConversion.cpp
|
||||
@@ -519,8 +519,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
||||
{
|
||||
QByteArray bytes = PyObjGetBytes(obj, strict, ok);
|
||||
if (ok) {
|
||||
- PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(bytes), ptr);
|
||||
- ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ if (alreadyAllocatedCPPObject) {
|
||||
+ ptr = alreadyAllocatedCPPObject;
|
||||
+ *reinterpret_cast<QByteArray*>(alreadyAllocatedCPPObject) = bytes;
|
||||
+ } else {
|
||||
+ PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(bytes), ptr);
|
||||
+ ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ }
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -528,8 +533,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
||||
{
|
||||
QString str = PyObjGetString(obj, strict, ok);
|
||||
if (ok) {
|
||||
- PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(str), ptr);
|
||||
- ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ if (alreadyAllocatedCPPObject) {
|
||||
+ ptr = alreadyAllocatedCPPObject;
|
||||
+ *reinterpret_cast<QString*>(alreadyAllocatedCPPObject) = str;
|
||||
+ } else {
|
||||
+ PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(str), ptr);
|
||||
+ ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ }
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -537,8 +547,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
||||
{
|
||||
QStringList l = PyObjToStringList(obj, strict, ok);
|
||||
if (ok) {
|
||||
- PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(l), ptr);
|
||||
- ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ if (alreadyAllocatedCPPObject) {
|
||||
+ ptr = alreadyAllocatedCPPObject;
|
||||
+ *reinterpret_cast<QStringList*>(alreadyAllocatedCPPObject) = l;
|
||||
+ } else {
|
||||
+ PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(l), ptr);
|
||||
+ ptr = (void*)((QVariant*)ptr)->constData();
|
||||
+ }
|
||||
}
|
||||
}
|
||||
break;
|
|
@ -0,0 +1,25 @@
|
|||
diff --git a/3rdparty/pythonqt/src/PythonQt.cpp b/3rdparty/pythonqt/src/PythonQt.cpp
|
||||
index f97bdf1..53cd197 100644
|
||||
--- a/3rdparty/pythonqt/src/PythonQt.cpp
|
||||
+++ b/3rdparty/pythonqt/src/PythonQt.cpp
|
||||
@@ -1144,14 +1144,17 @@ bool PythonQtPrivate::addParentClass(const char* typeName, const char* parentTyp
|
||||
|
||||
void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentTypeName, const char* package, PythonQtQObjectCreatorFunctionCB* wrapperCreator, PythonQtShellSetInstanceWrapperCB* shell, PyObject* module, int typeSlots)
|
||||
{
|
||||
- PythonQtClassInfo* info = lookupClassInfoAndCreateIfNotPresent(typeName);
|
||||
+ QByteArray typeNameCopy(typeName);
|
||||
+ typeNameCopy.replace("::", "_");
|
||||
+
|
||||
+ PythonQtClassInfo* info = lookupClassInfoAndCreateIfNotPresent(typeNameCopy);
|
||||
if (!info->pythonQtClassWrapper()) {
|
||||
info->setTypeSlots(typeSlots);
|
||||
- info->setupCPPObject(typeName);
|
||||
+ info->setupCPPObject(typeNameCopy);
|
||||
createPythonQtClassWrapper(info, package, module);
|
||||
}
|
||||
if (parentTypeName && strcmp(parentTypeName,"")!=0) {
|
||||
- addParentClass(typeName, parentTypeName, 0);
|
||||
+ addParentClass(typeNameCopy, parentTypeName, 0);
|
||||
}
|
||||
if (wrapperCreator) {
|
||||
info->setDecoratorProvider(wrapperCreator);
|
|
@ -1144,14 +1144,17 @@ bool PythonQtPrivate::addParentClass(const char* typeName, const char* parentTyp
|
|||
|
||||
void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentTypeName, const char* package, PythonQtQObjectCreatorFunctionCB* wrapperCreator, PythonQtShellSetInstanceWrapperCB* shell, PyObject* module, int typeSlots)
|
||||
{
|
||||
PythonQtClassInfo* info = lookupClassInfoAndCreateIfNotPresent(typeName);
|
||||
QByteArray typeNameCopy(typeName);
|
||||
typeNameCopy.replace("::", "_");
|
||||
|
||||
PythonQtClassInfo* info = lookupClassInfoAndCreateIfNotPresent(typeNameCopy);
|
||||
if (!info->pythonQtClassWrapper()) {
|
||||
info->setTypeSlots(typeSlots);
|
||||
info->setupCPPObject(typeName);
|
||||
info->setupCPPObject(typeNameCopy);
|
||||
createPythonQtClassWrapper(info, package, module);
|
||||
}
|
||||
if (parentTypeName && strcmp(parentTypeName,"")!=0) {
|
||||
addParentClass(typeName, parentTypeName, 0);
|
||||
addParentClass(typeNameCopy, parentTypeName, 0);
|
||||
}
|
||||
if (wrapperCreator) {
|
||||
info->setDecoratorProvider(wrapperCreator);
|
||||
|
|
|
@ -275,7 +275,9 @@ PyObject *PythonQtClassWrapper__init__(PythonQtClassWrapper *type, PyObject *arg
|
|||
if (PyObject_TypeCheck(self, (PyTypeObject*)type->classInfo()->pythonQtClassWrapper())) {
|
||||
PyObject* newargs = PyTuple_New(argc-1);
|
||||
for (int i = 0;i<argc-1; i++) {
|
||||
PyTuple_SET_ITEM(newargs, i,PyTuple_GET_ITEM(args, i+1));
|
||||
PyObject* item = PyTuple_GET_ITEM(args, i+1);
|
||||
Py_INCREF(item);
|
||||
PyTuple_SET_ITEM(newargs, i, item);
|
||||
}
|
||||
PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self;
|
||||
int result = PythonQtInstanceWrapper_init(wrapper, newargs, NULL);
|
||||
|
|
|
@ -519,8 +519,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
|||
{
|
||||
QByteArray bytes = PyObjGetBytes(obj, strict, ok);
|
||||
if (ok) {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(bytes), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
if (alreadyAllocatedCPPObject) {
|
||||
ptr = alreadyAllocatedCPPObject;
|
||||
*reinterpret_cast<QByteArray*>(alreadyAllocatedCPPObject) = bytes;
|
||||
} else {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(bytes), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -528,8 +533,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
|||
{
|
||||
QString str = PyObjGetString(obj, strict, ok);
|
||||
if (ok) {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(str), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
if (alreadyAllocatedCPPObject) {
|
||||
ptr = alreadyAllocatedCPPObject;
|
||||
*reinterpret_cast<QString*>(alreadyAllocatedCPPObject) = str;
|
||||
} else {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(str), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -537,8 +547,13 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
|
|||
{
|
||||
QStringList l = PyObjToStringList(obj, strict, ok);
|
||||
if (ok) {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(l), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
if (alreadyAllocatedCPPObject) {
|
||||
ptr = alreadyAllocatedCPPObject;
|
||||
*reinterpret_cast<QStringList*>(alreadyAllocatedCPPObject) = l;
|
||||
} else {
|
||||
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_variantStorage, QVariant, QVariant(l), ptr);
|
||||
ptr = (void*)((QVariant*)ptr)->constData();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue