aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.cpp45
-rw-r--r--sources/shiboken2/libshiboken/pep384impl.h11
-rw-r--r--sources/shiboken2/libshiboken/pep384impl_doc.rst10
3 files changed, 66 insertions, 0 deletions
diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp
index 9939bb410..9f51034f3 100644
--- a/sources/shiboken2/libshiboken/pep384impl.cpp
+++ b/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -518,12 +518,57 @@ static PyTypeObject *getFunctionType(void)
return reinterpret_cast<PyTypeObject *>(PepRun_GetResult(prog));
}
+#endif // Py_LIMITED_API || Python 2
+
+/*****************************************************************************
+ *
+ * Support for dictobject.h
+ *
+ */
+
+// PYSIDE-803, PYSIDE-813: We need that GIL-free version from Python 2.7.12 .
+#if PY_VERSION_HEX < 0x03000000
+
+/* Variant of PyDict_GetItem() that doesn't suppress exceptions.
+ This returns NULL *with* an exception set if an exception occurred.
+ It returns NULL *without* an exception set if the key wasn't present.
+*/
+PyObject *
+PyDict_GetItemWithError(PyObject *op, PyObject *key)
+{
+ long hash;
+ PyDictObject *mp = reinterpret_cast<PyDictObject *>(op);
+ PyDictEntry *ep;
+ if (!PyDict_Check(op)) {
+ PyErr_BadInternalCall();
+ return nullptr;
+ }
+ if (!PyString_CheckExact(key) ||
+ (hash = (reinterpret_cast<PyStringObject *>(key))->ob_shash) == -1)
+ {
+ hash = PyObject_Hash(key);
+ if (hash == -1) {
+ return nullptr;
+ }
+ }
+
+ ep = (mp->ma_lookup)(mp, key, hash);
+ if (ep == nullptr) {
+ return nullptr;
+ }
+ return ep->me_value;
+}
+
+#endif
+
/*****************************************************************************
*
* Extra support for signature.cpp
*
*/
+#ifdef Py_LIMITED_API
+
PyTypeObject *PepStaticMethod_TypePtr = nullptr;
static PyTypeObject *
diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h
index 676e6c82d..e735095e8 100644
--- a/sources/shiboken2/libshiboken/pep384impl.h
+++ b/sources/shiboken2/libshiboken/pep384impl.h
@@ -279,6 +279,17 @@ LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
/*****************************************************************************
*
+ * RESOLVED: dictobject.h
+ *
+ * PYSIDE-803, PYSIDE-813: We need PyDict_GetItemWithError in order to
+ * avoid the GIL.
+ */
+#if PY_VERSION_HEX < 0x03000000
+LIBSHIBOKEN_API PyObject *PyDict_GetItemWithError(PyObject *mp, PyObject *key);
+#endif
+
+/*****************************************************************************
+ *
* RESOLVED: methodobject.h
*
*/
diff --git a/sources/shiboken2/libshiboken/pep384impl_doc.rst b/sources/shiboken2/libshiboken/pep384impl_doc.rst
index ac4b053a7..d8ebdbe70 100644
--- a/sources/shiboken2/libshiboken/pep384impl_doc.rst
+++ b/sources/shiboken2/libshiboken/pep384impl_doc.rst
@@ -106,6 +106,16 @@ listobject.h
function calls.
+dictobject.h
+------------
+
+``PyDict_GetItem`` also exists in a ``PyDict_GetItemWithError`` version that does
+not suppress errors. This suppression has the side effect of touching global
+structures. This function exists in Python 2 only since Python 2.7.12 and has
+a different name. We simply implemented the function.
+Needed to avoid the GIL when accessing dictionaries.
+
+
methodobject.h
--------------