This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients chris.jerdonek, gvanrossum, hynek, martin.panter, ned.deily, njs, vstinner, yselivanov
Date 2020-05-04.14:13:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1588601580.87.0.205800632528.issue29587@roundup.psfhosted.org>
In-reply-to
Content
tl; dr I wrote PR 19902 to remove the "XXX" comment.

--

Commit 21893fbb74e8fde2931fbed9b511e2a41362b1ab adds the following code:

    /* XXX It seems like we shouldn't have to check not equal to Py_None
       here because exc_type should only ever be a class.  But not including
       this check was causing crashes on certain tests e.g. on Fedora. */
    if (gen->gi_exc_state.exc_type && gen->gi_exc_state.exc_type != Py_None) { ... }

I don't think that you should mention "Fedora" as a platform impacted by this issue: all platforms should be affected. It's just unclear why the issue was first seen on Fedora.

gen_send_ex() copies tstate->exc_info to gen->gi_exc_state.

tstate->exc_info->exc_type is set at least in the following 3 places in CPython code base:

* ceval.c: POP_EXCEPT opcode: exc_info->exc_type = POP();
* ceval.c: UNWIND_EXCEPT_HANDLER() macro: exc_info->exc_type = POP();
* errors.c: PyErr_SetExcInfo()

I saw in practice POP_EXCEPT and UNWIND_EXCEPT_HANDLER() setting exc_info->exc_type to Py_None (I didn't test PyErr_SetExcInfo()).

_PyErr_GetTopmostException() also handles exc_info->exc_type == Py_None case:

_PyErr_StackItem *
_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}

--

So exc_type=None is not a bug, but it's done on purpose.

If you don't want to get None in genobject.c, we should modify all places which set tstate->exc_info->exc_type. Problem: the structure currently exposed in the public C API (bpo-40429), and I wouldn't be surprised if Cython or greenlet modify tstate->exc_info directly.
History
Date User Action Args
2020-05-04 14:13:00vstinnersetrecipients: + vstinner, gvanrossum, ned.deily, njs, chris.jerdonek, hynek, martin.panter, yselivanov
2020-05-04 14:13:00vstinnersetmessageid: <1588601580.87.0.205800632528.issue29587@roundup.psfhosted.org>
2020-05-04 14:13:00vstinnerlinkissue29587 messages
2020-05-04 14:13:00vstinnercreate