aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-09-13 17:43:16 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:14 -0300
commitc686942f6efbac4ac43cf859bfdd2c7209b783ea (patch)
tree39254222aca7f5bac8409a0078eaf5bbca2d1cf8 /libshiboken
parent987010cb2c5740bf1cb7af54b2c6dc3142c44805 (diff)
Fix bug 995 - "QDeclarativeView.itemAt returns faulty reference. (leading to SEGFAULT)"
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp13
-rw-r--r--libshiboken/basewrapper.h6
-rw-r--r--libshiboken/basewrapper_p.h2
-rw-r--r--libshiboken/bindingmanager.cpp19
-rw-r--r--libshiboken/bindingmanager.h15
5 files changed, 46 insertions, 9 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 006b9c62a..8ccf89a6b 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -646,14 +646,21 @@ const char* getOriginalName(SbkObjectType* self)
return self->d->original_name;
}
-void setTypeDiscoveryFunction(SbkObjectType* self, TypeDiscoveryFunc func)
+void setTypeDiscoveryFunctionV2(SbkObjectType* self, TypeDiscoveryFuncV2 func)
{
self->d->type_discovery = func;
}
+void setTypeDiscoveryFunction(SbkObjectType* self, TypeDiscoveryFunc func)
+{
+ self->d->type_discovery = (TypeDiscoveryFuncV2)func;
+}
+
TypeDiscoveryFunc getTypeDiscoveryFunction(SbkObjectType* self)
{
- return self->d->type_discovery;
+ // This is an illegal cast because the return value is different,
+ // but nobody ever used this function, so... =]
+ return (TypeDiscoveryFunc)self->d->type_discovery;
}
void copyMultimpleheritance(SbkObjectType* self, SbkObjectType* other)
@@ -1017,7 +1024,7 @@ PyObject* newObject(SbkObjectType* instanceType,
instanceType = reinterpret_cast<SbkObjectType*>(tr->pythonType());
}
if (!tr)
- instanceType = BindingManager::instance().resolveType(cptr, instanceType);
+ instanceType = BindingManager::instance().resolveType(&cptr, instanceType);
}
SbkObject* self = reinterpret_cast<SbkObject*>(SbkObjectTpNew(reinterpret_cast<PyTypeObject*>(instanceType), 0, 0));
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index 334ac6caf..4ce27ee13 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -64,6 +64,7 @@ typedef int* (*MultipleInheritanceInitFunction)(const void*);
*/
typedef void* (*SpecialCastFunction)(void*, SbkObjectType*);
typedef SbkObjectType* (*TypeDiscoveryFunc)(void*, SbkObjectType*);
+typedef void* (*TypeDiscoveryFuncV2)(void*, SbkObjectType*);
typedef void* (*ExtendedToCppFunc)(PyObject*);
typedef bool (*ExtendedIsConvertibleFunc)(PyObject*);
@@ -157,8 +158,9 @@ LIBSHIBOKEN_API void setCastFunction(SbkObjectType* type, SpecialCastFunc
LIBSHIBOKEN_API void setOriginalName(SbkObjectType* self, const char* name);
LIBSHIBOKEN_API const char* getOriginalName(SbkObjectType* self);
-LIBSHIBOKEN_API void setTypeDiscoveryFunction(SbkObjectType* self, TypeDiscoveryFunc func);
-LIBSHIBOKEN_API TypeDiscoveryFunc getTypeDiscoveryFunction(SbkObjectType* self);
+LIBSHIBOKEN_API void setTypeDiscoveryFunctionV2(SbkObjectType* self, TypeDiscoveryFuncV2 func);
+LIBSHIBOKEN_API SBK_DEPRECATED(void setTypeDiscoveryFunction(SbkObjectType* self, TypeDiscoveryFunc func));
+LIBSHIBOKEN_API SBK_DEPRECATED(TypeDiscoveryFunc getTypeDiscoveryFunction(SbkObjectType* self));
LIBSHIBOKEN_API void copyMultimpleheritance(SbkObjectType* self, SbkObjectType* other);
LIBSHIBOKEN_API void setMultipleIheritanceFunction(SbkObjectType* self, MultipleInheritanceInitFunction func);
diff --git a/libshiboken/basewrapper_p.h b/libshiboken/basewrapper_p.h
index 35c9c83df..a00e1ad69 100644
--- a/libshiboken/basewrapper_p.h
+++ b/libshiboken/basewrapper_p.h
@@ -98,7 +98,7 @@ struct SbkObjectTypePrivate
/// Special cast function, null if this class doesn't have multiple inheritance.
SpecialCastFunction mi_specialcast;
- TypeDiscoveryFunc type_discovery;
+ TypeDiscoveryFuncV2 type_discovery;
/// Extended "isConvertible" function to be used when a conversion operator is defined in another module.
ExtendedIsConvertibleFunc ext_isconvertible;
/// Extended "toCpp" function to be used when a conversion operator is defined in another module.
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
index efca2532a..a8d4b0a06 100644
--- a/libshiboken/bindingmanager.cpp
+++ b/libshiboken/bindingmanager.cpp
@@ -71,7 +71,7 @@ public:
}
#endif
- SbkObjectType* identifyType(void* cptr, SbkObjectType* type, SbkObjectType* baseType) const
+ SbkObjectType* identifyType(void** cptr, SbkObjectType* type, SbkObjectType* baseType) const
{
Edges::const_iterator edgesIt = m_edges.find(type);
if (edgesIt != m_edges.end()) {
@@ -83,7 +83,17 @@ public:
return newType;
}
}
- return ((type->d && type->d->type_discovery) ? type->d->type_discovery(cptr, baseType) : 0);
+ void* typeFound = ((type->d && type->d->type_discovery) ? type->d->type_discovery(*cptr, baseType) : 0);
+ if (typeFound) {
+ // This "typeFound != type" is needed for backwards compatibility with old modules using a newer version of
+ // libshiboken because old versions of type_discovery function used to return a SbkObjectType* instead of
+ // a possible variation of the C++ instance pointer (*cptr).
+ if (typeFound != type)
+ *cptr = typeFound;
+ return type;
+ } else {
+ return 0;
+ }
}
};
@@ -265,6 +275,11 @@ void BindingManager::addClassInheritance(SbkObjectType* parent, SbkObjectType* c
SbkObjectType* BindingManager::resolveType(void* cptr, SbkObjectType* type)
{
+ return resolveType(&cptr, type);
+}
+
+SbkObjectType* BindingManager::resolveType(void** cptr, SbkObjectType* type)
+{
SbkObjectType* identifiedType = m_d->classHierarchy.identifyType(cptr, type, type);
return identifiedType ? identifiedType : type;
}
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
index e12558b4f..b43bd77b2 100644
--- a/libshiboken/bindingmanager.h
+++ b/libshiboken/bindingmanager.h
@@ -49,7 +49,20 @@ public:
PyObject* getOverride(const void* cptr, const char* methodName);
void addClassInheritance(SbkObjectType* parent, SbkObjectType* child);
- SbkObjectType* resolveType(void* cptr, SbkObjectType* type);
+ /**
+ * \deprecated Use \fn resolveType(void**, SbkObjectType*), this version is broken when used with multiple inheritance
+ * because the \p cptr pointer of the discovered type may be different of the given \p cptr in case
+ * of multiple inheritance
+ */
+ SBK_DEPRECATED(SbkObjectType* resolveType(void* cptr, SbkObjectType* type));
+ /**
+ * Try to find the correct type of *cptr knowing that it's at least of type \p type.
+ * In case of multiple inheritance this function may change the contents of cptr.
+ * \param cptr a pointer to a pointer to the instance of type \p type
+ * \param type type of *cptr
+ * \warning This function is slow, use it only as last resort.
+ */
+ SbkObjectType* resolveType(void** cptr, SbkObjectType* type);
std::set<SbkObject*> getAllPyObjects();