mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Factor-out the common code for setting a KeyError.
This commit is contained in:
parent
7f5c22c022
commit
69492dab07
4 changed files with 20 additions and 33 deletions
|
@ -11,20 +11,6 @@
|
|||
#include "structmember.h"
|
||||
#include "stringlib/eq.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
|
||||
#define LINEAR_PROBES 9
|
||||
|
@ -1948,7 +1934,7 @@ set_remove(PySetObject *so, PyObject *key)
|
|||
}
|
||||
|
||||
if (rv == DISCARD_NOTFOUND) {
|
||||
set_key_error(key);
|
||||
_PyErr_SetKeyError(key);
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue