Skip to content

Commit

Permalink
[mypyc] Fix Python 3.11 C API errors (#12850)
Browse files Browse the repository at this point in the history
Closes mypyc/mypyc#931
Closes mypyc/mypyc#923

Related CPython modification:

python/cpython#89874
python/cpython#31530
  • Loading branch information
97littleleaf11 committed May 23, 2022
1 parent 3c04092 commit c8efeed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion mypyc/lib-rt/exc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void CPy_RestoreExcInfo(tuple_T3OOO info) {
}

bool CPy_ExceptionMatches(PyObject *type) {
return PyErr_GivenExceptionMatches(CPy_ExcState()->exc_type, type);
return PyErr_GivenExceptionMatches((PyObject *)Py_TYPE(CPy_ExcState()->exc_value), type);
}

PyObject *CPy_GetExcValue(void) {
Expand Down Expand Up @@ -189,6 +189,13 @@ void CPy_TypeError(const char *expected, PyObject *value) {
}
}

// The PyFrameObject type definition (struct _frame) has been moved
// to the internal C API: to the pycore_frame.h header file.
// https://github.com/python/cpython/pull/31530
#if PY_VERSION_HEX >= 0x030b00a6
#include "internal/pycore_frame.h"
#endif

// This function is basically exactly the same with _PyTraceback_Add
// which is available in all the versions we support.
// We're continuing to use this because we'll probably optimize this later.
Expand Down
2 changes: 1 addition & 1 deletion mypyc/lib-rt/misc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int CPy_YieldFromErrorHandle(PyObject *iter, PyObject **outp)
{
_Py_IDENTIFIER(close);
_Py_IDENTIFIER(throw);
PyObject *exc_type = CPy_ExcState()->exc_type;
PyObject *exc_type = (PyObject *)Py_TYPE(CPy_ExcState()->exc_value);
PyObject *type, *value, *traceback;
PyObject *_m;
PyObject *res;
Expand Down

0 comments on commit c8efeed

Please sign in to comment.