Skip to content

gh-128078: Clear exception in anext before calling _PyGen_SetStopIterationValue #128780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Jan 13, 2025

See #128078 (comment).

@kumaraditya303: There are a couple of other calls to _PyGen_SetStopIterationValue() but I'm not well-versed enough in asyncio to know whether I should clear them or not. The regression test now passes but please confirm whether some other PyErr_Clear() should happen or not.

In async_gen_unwrap_value:

    if (_PyAsyncGenWrappedValue_CheckExact(result)) {
        /* async yield */
        _PyGen_SetStopIterationValue(((_PyAsyncGenWrappedValue*)result)->agw_val);
        Py_DECREF(result);
        gen->ag_running_async = 0;
        return NULL;
    }

In gen_iternext:

    if (gen_send_ex2(gen, NULL, &result, 0, 0) == PYGEN_RETURN) {
        if (result != Py_None) {
            _PyGen_SetStopIterationValue(result);
        }
        Py_CLEAR(result);
    }

In this case, I think we should satisfy assert(!PyErr_Occurred()) since it's PYGEN_RETURN, right? Same question for gen_send_ex and FutureIter_iternext().

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@kumaraditya303
Copy link
Contributor

In this case, I think we should satisfy assert(!PyErr_Occurred()) since it's PYGEN_RETURN, right? Same question for gen_send_ex and FutureIter_iternext().

I have checked them and they all satisfy assert(!PyErr_Occurred()).

@kumaraditya303 kumaraditya303 merged commit 76ffaef into python:main Jan 13, 2025
45 checks passed
@kumaraditya303 kumaraditya303 added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Jan 13, 2025
@miss-islington-app
Copy link

Thanks @picnixz for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @picnixz for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2025
…tStopIterationValue` (pythonGH-128780)

(cherry picked from commit 76ffaef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jan 13, 2025

GH-128784 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2025
…tStopIterationValue` (pythonGH-128780)

(cherry picked from commit 76ffaef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Jan 13, 2025
@bedevere-app
Copy link

bedevere-app bot commented Jan 13, 2025

GH-128785 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jan 13, 2025
kumaraditya303 added a commit that referenced this pull request Jan 13, 2025
…etStopIterationValue` (GH-128780) (#128784)

gh-128078: Clear exception in `anext` before calling `_PyGen_SetStopIterationValue` (GH-128780)
(cherry picked from commit 76ffaef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303 added a commit that referenced this pull request Jan 13, 2025
…etStopIterationValue` (GH-128780) (#128785)

gh-128078: Clear exception in `anext` before calling `_PyGen_SetStopIterationValue` (GH-128780)
(cherry picked from commit 76ffaef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@picnixz picnixz deleted the fix/core/anext-clear-exception-128078 branch January 13, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants