]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Repair incorrect symbol PyDict_GetItemWithError for Python 2
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Jan 2021 17:57:47 +0000 (12:57 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Jan 2021 18:08:01 +0000 (13:08 -0500)
* ensure on python 2 correct cflags to fail on undefined
symbols take effect

* fail for implicit function declaration

* python 2 does not publish PyDict_GetItemWithError but has
it as _PyDict_GetItemWIthError but only as of Python 2.7.12

Change-Id: I007509afddf7f44ca64e52fa9140be39f815fa7a

lib/sqlalchemy/cextension/immutabledict.c
setup.py

index 9b864bf028c894b80ed485e46bc4f04ec538783e..a185f85b81e30e417095d8f473cff782e86801a4 100644 (file)
@@ -20,6 +20,40 @@ typedef struct {
 static PyTypeObject ImmutableDictType;
 
 
+#if PY_MAJOR_VERSION < 3
+/* For Python 2.7, VENDORED from cPython: https://github.com/python/cpython/commit/1c496178d2c863f135bd4a43e32e0f099480cd06
+   This function was added to Python 2.7.12 as an underscore function.
+
+   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 = (PyDictObject *)op;
+    PyDictEntry *ep;
+    if (!PyDict_Check(op)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+    if (!PyString_CheckExact(key) ||
+        (hash = ((PyStringObject *) key)->ob_shash) == -1)
+    {
+        hash = PyObject_Hash(key);
+        if (hash == -1) {
+            return NULL;
+        }
+    }
+
+    ep = (mp->ma_lookup)(mp, key, hash);
+    if (ep == NULL) {
+        return NULL;
+    }
+    return ep->me_value;
+}
+#endif
 
 static PyObject *
 
index 341b1159ac71f4e808e556b235998c7af2dd9bac..1d2de5a61e82aeb2813b8808abea1af878693351 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -22,9 +22,9 @@ if sys.platform == "win32":
     # Work around issue https://github.com/pypa/setuptools/issues/1902
     ext_errors += (IOError, TypeError)
     extra_compile_args = []
-elif sys.platform == "linux":
+elif sys.platform in ("linux", "linux2"):
     # warn for undefined symbols in .c files
-    extra_compile_args = ["-Wundef"]
+    extra_compile_args = ["-Wundef", "-Werror=implicit-function-declaration"]
 else:
     extra_compile_args = []