Skip to content
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

Support exception state stack in Py3.7 #1958

Closed
scoder opened this issue Oct 29, 2017 · 1 comment
Closed

Support exception state stack in Py3.7 #1958

scoder opened this issue Oct 29, 2017 · 1 comment

Comments

@scoder
Copy link
Contributor

scoder commented Oct 29, 2017

CPython 3.7 adds a new exception state stack for generators:
https://bugs.python.org/issue25612

python/cpython@ae3087c#diff-6b7f39a70f95725eaff0aa0640cc17f6R126

typedef struct _err_stackitem {
    /* This struct represents an entry on the exception stack, which is a 
     * per-coroutine state. (Coroutine in the computer science sense, 
     * including the thread and generators).
     * This ensures that the exception state is not impacted by "yields"
     * from an except handler.
     */
    PyObject *exc_type, *exc_value, *exc_traceback;

    struct _err_stackitem *previous_item;

} _PyErr_StackItem;

It is used like this:

     gen->gi_running = 1;
+    gen->gi_exc_state.previous_item = tstate->exc_info;
+    tstate->exc_info = &gen->gi_exc_state;
     result = PyEval_EvalFrameEx(f, exc);
+    tstate->exc_info = gen->gi_exc_state.previous_item;
+    gen->gi_exc_state.previous_item = NULL;
     gen->gi_running = 0;

python/cpython@ae3087c#diff-23c87bfada1d01335a3019b9321502a0R215

Cython should do the same thing in its coroutines in Py3.7+.
The previous Cython changes in #1956 and the problem description in #1955 are incomplete.

@scoder
Copy link
Contributor Author

scoder commented Sep 15, 2018

Implemented in #2607.

@scoder scoder closed this as completed Sep 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant