aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/genobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2025-02-16 15:28:01 +0300
committershadchin <shadchin@yandex-team.com>2025-02-16 16:03:50 +0300
commita27b6a96fdc5ca444428ddef4823d0486dcdccb9 (patch)
treeadde5c24d9ea37e1634e7972e27e682a820ab941 /contrib/tools/python3/Objects/genobject.c
parent7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (diff)
downloadydb-a27b6a96fdc5ca444428ddef4823d0486dcdccb9.tar.gz
Update Python 3 to 3.12.9
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
Diffstat (limited to 'contrib/tools/python3/Objects/genobject.c')
-rw-r--r--contrib/tools/python3/Objects/genobject.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/contrib/tools/python3/Objects/genobject.c b/contrib/tools/python3/Objects/genobject.c
index 474abe1094..640a7d906c 100644
--- a/contrib/tools/python3/Objects/genobject.c
+++ b/contrib/tools/python3/Objects/genobject.c
@@ -618,30 +618,19 @@ gen_iternext(PyGenObject *gen)
int
_PyGen_SetStopIterationValue(PyObject *value)
{
- PyObject *e;
-
- if (value == NULL ||
- (!PyTuple_Check(value) && !PyExceptionInstance_Check(value)))
- {
- /* Delay exception instantiation if we can */
- PyErr_SetObject(PyExc_StopIteration, value);
- return 0;
- }
- /* Construct an exception instance manually with
- * PyObject_CallOneArg and pass it to PyErr_SetObject.
- *
- * We do this to handle a situation when "value" is a tuple, in which
- * case PyErr_SetObject would set the value of StopIteration to
- * the first element of the tuple.
- *
- * (See PyErr_SetObject/_PyErr_CreateException code for details.)
- */
- e = PyObject_CallOneArg(PyExc_StopIteration, value);
- if (e == NULL) {
+ assert(!PyErr_Occurred());
+ // Construct an exception instance manually with PyObject_CallOneArg()
+ // but use PyErr_SetRaisedException() instead of PyErr_SetObject() as
+ // PyErr_SetObject(exc_type, value) has a fast path when 'value'
+ // is a tuple, where the value of the StopIteration exception would be
+ // set to 'value[0]' instead of 'value'.
+ PyObject *exc = value == NULL
+ ? PyObject_CallNoArgs(PyExc_StopIteration)
+ : PyObject_CallOneArg(PyExc_StopIteration, value);
+ if (exc == NULL) {
return -1;
}
- PyErr_SetObject(PyExc_StopIteration, e);
- Py_DECREF(e);
+ PyErr_SetRaisedException(exc /* stolen */);
return 0;
}