]> granicus.if.org Git - python/commitdiff
Port Georg's dictobject.c fix keys that were tuples got unpacked on the way to settin...
authorRaymond Hettinger <python@rcn.com>
Fri, 8 Dec 2006 04:57:50 +0000 (04:57 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 8 Dec 2006 04:57:50 +0000 (04:57 +0000)
1576657).

Objects/setobject.c

index 99db926a0deb8ab65b7d06025096bca97e8cba32..d33fff93fe247019c1b428192a39a0580a0e03a0 100644 (file)
 #include "Python.h"
 #include "structmember.h"
 
+/* Set a key error with the specified argument, wrapping it in a
+ * tuple automatically so that tuple keys are not unpacked as the
+ * exception arguments. */
+static void
+set_key_error(PyObject *arg)
+{
+       PyObject *tup;
+       tup = PyTuple_Pack(1, arg);
+       if (!tup)
+               return; /* caller will expect error to be set anyway */
+       PyErr_SetObject(PyExc_KeyError, tup);
+       Py_DECREF(tup);
+}
+
 /* This must be >= 1. */
 #define PERTURB_SHIFT 5
 
@@ -1684,7 +1698,7 @@ set_remove(PySetObject *so, PyObject *key)
                Py_DECREF(tmpkey);
                return result;
        } else if (rv == DISCARD_NOTFOUND) {
-               PyErr_SetObject(PyExc_KeyError, key);
+               set_key_error(key);
                return NULL;
        }
        Py_RETURN_NONE;