]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make sure that PyDict_GetItem[String]() *never* raises an exception.
authorGuido van Rossum <guido@python.org>
Thu, 14 May 1998 01:00:51 +0000 (01:00 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 14 May 1998 01:00:51 +0000 (01:00 +0000)
If the argument is not a dictionary, simply return NULL.  If the
hash() on the key fails, clear the error.

Objects/dictobject.c

index 06d2dc4f92ccb808dcd370d31ff5e4b935c7b9e3..7fed379ef59570e0bc524d0a57269ab62081536b 100644 (file)
@@ -317,7 +317,6 @@ PyDict_GetItem(op, key)
 {
        long hash;
        if (!PyDict_Check(op)) {
-               PyErr_BadInternalCall();
                return NULL;
        }
        if (((dictobject *)op)->ma_table == NULL)
@@ -328,8 +327,10 @@ PyDict_GetItem(op, key)
 #endif
        {
                hash = PyObject_Hash(key);
-               if (hash == -1)
+               if (hash == -1) {
+                       PyErr_Clear();
                        return NULL;
+               }
        }
        return lookdict((dictobject *)op, key, hash) -> me_value;
 }