diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-25 16:33:12 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-25 16:33:12 +0200 |
commit | 39ac266455cc1c0ae970a47c34d3a6bc7372d750 (patch) | |
tree | 9577fe06bcb0e3096ef85af929a91eb37b037452 /sources/shiboken2/libshiboken/pep384impl.cpp | |
parent | 9115712ef3a1be8b401c9cd306792dbc30c89bf0 (diff) | |
parent | 6717d3540fac74c91d9381958a08e60f6532d402 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.14.2
Change-Id: Id0650ec2b46f3c67eb2c9b400f5b31aab98c3c58
Diffstat (limited to 'sources/shiboken2/libshiboken/pep384impl.cpp')
-rw-r--r-- | sources/shiboken2/libshiboken/pep384impl.cpp | 32 |
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 * */ |