aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp16
-rw-r--r--libshiboken/basewrapper.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 2dda3a4bc..dc86fa831 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -196,6 +196,22 @@ void SbkBaseWrapper_clearReferences(SbkBaseWrapper* self)
delete self->referredObjects;
}
+bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr)
+{
+ Shiboken::AutoDecRef module(PyImport_ImportModule(moduleName));
+ if (module.isNull())
+ return false;
+
+ Shiboken::AutoDecRef cppApi(PyObject_GetAttrString(module, "_Cpp_Api"));
+ if (cppApi.isNull())
+ return false;
+
+ if (PyCObject_Check(cppApi))
+ *cppApiPtr = reinterpret_cast<PyTypeObject**>(PyCObject_AsVoidPtr(cppApi));
+
+ return true;
+}
+
// Wrapper metatype and base type ----------------------------------------------------------
extern "C"
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index 7d834da0e..e8ea7cc1b 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -256,6 +256,8 @@ void SbkBaseWrapper_Dealloc(PyObject* self)
LIBSHIBOKEN_API PyAPI_FUNC(void) SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self);
+LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr);
+
} // namespace Shiboken
#endif // BASEWRAPPER_H