mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
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).
This commit is contained in:
parent
0c850863a2
commit
9c14ffbc78
1 changed files with 15 additions and 1 deletions
|
@ -10,6 +10,20 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "structmember.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. */
|
/* This must be >= 1. */
|
||||||
#define PERTURB_SHIFT 5
|
#define PERTURB_SHIFT 5
|
||||||
|
|
||||||
|
@ -1684,7 +1698,7 @@ set_remove(PySetObject *so, PyObject *key)
|
||||||
Py_DECREF(tmpkey);
|
Py_DECREF(tmpkey);
|
||||||
return result;
|
return result;
|
||||||
} else if (rv == DISCARD_NOTFOUND) {
|
} else if (rv == DISCARD_NOTFOUND) {
|
||||||
PyErr_SetObject(PyExc_KeyError, key);
|
set_key_error(key);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue