aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken/pep384impl.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-05-25 16:33:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-05-25 16:33:12 +0200
commit39ac266455cc1c0ae970a47c34d3a6bc7372d750 (patch)
tree9577fe06bcb0e3096ef85af929a91eb37b037452 /sources/shiboken2/libshiboken/pep384impl.cpp
parent9115712ef3a1be8b401c9cd306792dbc30c89bf0 (diff)
parent6717d3540fac74c91d9381958a08e60f6532d402 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.14.2
Diffstat (limited to 'sources/shiboken2/libshiboken/pep384impl.cpp')
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp
index c04848eb3..f07cac613 100644
--- a/sources/shiboken2/libshiboken/pep384impl.cpp
+++ b/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -638,6 +638,38 @@ PepType_GetNameStr(PyTypeObject *type)
/*****************************************************************************
*
+ * Newly introduced convenience functions
+ *
+ */
+#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API)
+
+PyObject *
+PyImport_GetModule(PyObject *name)
+{
+ PyObject *m;
+ PyObject *modules = PyImport_GetModuleDict();
+ if (modules == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
+ return NULL;
+ }
+ Py_INCREF(modules);
+ if (PyDict_CheckExact(modules)) {
+ m = PyDict_GetItemWithError(modules, name); /* borrowed */
+ Py_XINCREF(m);
+ }
+ else {
+ m = PyObject_GetItem(modules, name);
+ if (m == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Clear();
+ }
+ }
+ Py_DECREF(modules);
+ return m;
+}
+
+#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API)
+/*****************************************************************************
+ *
* Extra support for name mangling
*
*/