diff options
author | Georg Brandl <georg@python.org> | 2006-10-29 18:31:42 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-10-29 18:31:42 (GMT) |
commit | b9f4ad3a9a01ba249a3a2d668f96935b31c78d82 (patch) | |
tree | deb728f59d7ae8ec78f482c3959636a3fe9ec543 /Objects/dictobject.c | |
parent | f733a013b2d1546e58dd6d4d3cdcb083e2176bea (diff) | |
download | cpython-b9f4ad3a9a01ba249a3a2d668f96935b31c78d82.zip cpython-b9f4ad3a9a01ba249a3a2d668f96935b31c78d82.tar.gz cpython-b9f4ad3a9a01ba249a3a2d668f96935b31c78d82.tar.bz2 |
Bug #1576657: when setting a KeyError for a tuple key, make sure that
the tuple isn't used as the "exception arguments tuple".
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e127d96..1fcfe1c 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -12,6 +12,19 @@ typedef PyDictEntry dictentry; typedef PyDictObject dictobject; +/* 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); +} + /* Define this out if you don't want conversion statistics on exit. */ #undef SHOW_CONVERSION_COUNTS @@ -665,7 +678,7 @@ PyDict_DelItem(PyObject *op, PyObject *key) if (ep == NULL) return -1; if (ep->me_value == NULL) { - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return -1; } old_key = ep->me_key; @@ -974,7 +987,7 @@ dict_subscript(dictobject *mp, register PyObject *key) return PyObject_CallFunctionObjArgs(missing, (PyObject *)mp, key, NULL); } - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return NULL; } else @@ -1746,7 +1759,7 @@ dict_pop(dictobject *mp, PyObject *args) Py_INCREF(deflt); return deflt; } - PyErr_SetObject(PyExc_KeyError, key); + set_key_error(key); return NULL; } old_key = ep->me_key; |