diff options
| author | Raymond Hettinger <python@rcn.com> | 2006-12-08 04:57:50 (GMT) | 
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2006-12-08 04:57:50 (GMT) | 
| commit | 9c14ffbc7831ba9497ce98dfb951605ab542aefb (patch) | |
| tree | 45620dcd46a00f412c4e0c1bd2951732e62ae830 /Objects/setobject.c | |
| parent | 0c850863a22dbe91fbabdc9c890ceb57bebf8c24 (diff) | |
| download | cpython-9c14ffbc7831ba9497ce98dfb951605ab542aefb.zip cpython-9c14ffbc7831ba9497ce98dfb951605ab542aefb.tar.gz cpython-9c14ffbc7831ba9497ce98dfb951605ab542aefb.tar.bz2  | |
Port Georg's dictobject.c fix keys that were tuples got unpacked on the way to setting a KeyError (svn revision 52535, sf bug
1576657).
Diffstat (limited to 'Objects/setobject.c')
| -rw-r--r-- | Objects/setobject.c | 16 | 
1 files changed, 15 insertions, 1 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 99db926..d33fff9 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -10,6 +10,20 @@  #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;  | 
