summaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken/basewrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/libshiboken/basewrapper.cpp')
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index c9e3b9d1..e820e749 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -831,6 +831,23 @@ void setTypeUserData(SbkObjectType* type, void* userData, DeleteUserDataFunc d_f
sotp->d_func = d_func;
}
+// Try to find the exact type of cptr.
+SbkObjectType *typeForTypeName(const char *typeName)
+{
+ SbkObjectType *result{};
+ if (typeName) {
+ if (PyTypeObject *pyType = Shiboken::Conversions::getPythonTypeObject(typeName))
+ result = reinterpret_cast<SbkObjectType*>(pyType);
+ }
+ return result;
+}
+
+bool hasSpecialCastFunction(SbkObjectType *sbkType)
+{
+ const SbkObjectTypePrivate *d = PepType_SOTP(sbkType);
+ return d != nullptr && d->mi_specialcast != nullptr;
+}
+
} // namespace ObjectType
@@ -1191,7 +1208,6 @@ SbkObject *findColocatedChild(SbkObject *wrapper,
return 0;
}
-
PyObject *newObject(SbkObjectType* instanceType,
void* cptr,
bool hasOwnership,
@@ -1200,13 +1216,9 @@ PyObject *newObject(SbkObjectType* instanceType,
{
// Try to find the exact type of cptr.
if (!isExactType) {
- PyTypeObject* exactType = 0;
- if (typeName) {
- exactType = Shiboken::Conversions::getPythonTypeObject(typeName);
- if (exactType)
- instanceType = reinterpret_cast<SbkObjectType*>(exactType);
- }
- if (!exactType)
+ if (SbkObjectType *exactType = ObjectType::typeForTypeName(typeName))
+ instanceType = exactType;
+ else
instanceType = BindingManager::instance().resolveType(&cptr, instanceType);
}