summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-05-10 19:08:24 (GMT)
committerGitHub <noreply@github.com>2024-05-10 19:08:24 (GMT)
commitaa36f83c1670f1e41fa9432a20e5c4a88ee9012c (patch)
tree2dfa668791a82aa1e7725c75e74ed1baa09ae8fa /Python/errors.c
parentec9d12be9648ee60a2eb02d67069d74f8b314df9 (diff)
downloadcpython-aa36f83c1670f1e41fa9432a20e5c4a88ee9012c.zip
cpython-aa36f83c1670f1e41fa9432a20e5c4a88ee9012c.tar.gz
cpython-aa36f83c1670f1e41fa9432a20e5c4a88ee9012c.tar.bz2
gh-118702: Implement vectorcall for BaseException (#118703)
* BaseException_vectorcall() now creates a tuple from 'args' array. * Creation an exception using BaseException_vectorcall() is now a single function call, rather than having to call BaseException_new() and then BaseException_init(). Calling BaseException_init() is inefficient since it overrides the 'args' attribute. * _PyErr_SetKeyError() now uses PyObject_CallOneArg() to create the KeyError instance to use BaseException_vectorcall().
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 433253b..ad6b7db 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -257,13 +257,14 @@ void
_PyErr_SetKeyError(PyObject *arg)
{
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *tup = PyTuple_Pack(1, arg);
- if (!tup) {
+ PyObject *exc = PyObject_CallOneArg(PyExc_KeyError, arg);
+ if (!exc) {
/* caller will expect error to be set anyway */
return;
}
- _PyErr_SetObject(tstate, PyExc_KeyError, tup);
- Py_DECREF(tup);
+
+ _PyErr_SetObject(tstate, (PyObject*)Py_TYPE(exc), exc);
+ Py_DECREF(exc);
}
void