mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-118473: Fix set_asyncgen_hooks not to be partially set when arguments are invalid (#118474)
This commit is contained in:
parent
e272195b3e
commit
8d8275b0cf
3 changed files with 36 additions and 9 deletions
|
@ -1399,12 +1399,6 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
|
|||
Py_TYPE(finalizer)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
if (_PyEval_SetAsyncGenFinalizer(finalizer) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (finalizer == Py_None && _PyEval_SetAsyncGenFinalizer(NULL) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (firstiter && firstiter != Py_None) {
|
||||
|
@ -1414,15 +1408,33 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
|
|||
Py_TYPE(firstiter)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
if (_PyEval_SetAsyncGenFirstiter(firstiter) < 0) {
|
||||
}
|
||||
|
||||
PyObject *cur_finalizer = _PyEval_GetAsyncGenFinalizer();
|
||||
|
||||
if (finalizer && finalizer != Py_None) {
|
||||
if (_PyEval_SetAsyncGenFinalizer(finalizer) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (firstiter == Py_None && _PyEval_SetAsyncGenFirstiter(NULL) < 0) {
|
||||
else if (finalizer == Py_None && _PyEval_SetAsyncGenFinalizer(NULL) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (firstiter && firstiter != Py_None) {
|
||||
if (_PyEval_SetAsyncGenFirstiter(firstiter) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (firstiter == Py_None && _PyEval_SetAsyncGenFirstiter(NULL) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
|
||||
error:
|
||||
_PyEval_SetAsyncGenFinalizer(cur_finalizer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(set_asyncgen_hooks_doc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue