Skip to content

Commit c8efeed

Browse files
[mypyc] Fix Python 3.11 C API errors (#12850)
Closes mypyc/mypyc#931 Closes mypyc/mypyc#923 Related CPython modification: python/cpython#89874 python/cpython#31530
1 parent 3c04092 commit c8efeed

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mypyc/lib-rt/exc_ops.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void CPy_RestoreExcInfo(tuple_T3OOO info) {
7575
}
7676

7777
bool CPy_ExceptionMatches(PyObject *type) {
78-
return PyErr_GivenExceptionMatches(CPy_ExcState()->exc_type, type);
78+
return PyErr_GivenExceptionMatches((PyObject *)Py_TYPE(CPy_ExcState()->exc_value), type);
7979
}
8080

8181
PyObject *CPy_GetExcValue(void) {
@@ -189,6 +189,13 @@ void CPy_TypeError(const char *expected, PyObject *value) {
189189
}
190190
}
191191

192+
// The PyFrameObject type definition (struct _frame) has been moved
193+
// to the internal C API: to the pycore_frame.h header file.
194+
// https://github.com/python/cpython/pull/31530
195+
#if PY_VERSION_HEX >= 0x030b00a6
196+
#include "internal/pycore_frame.h"
197+
#endif
198+
192199
// This function is basically exactly the same with _PyTraceback_Add
193200
// which is available in all the versions we support.
194201
// We're continuing to use this because we'll probably optimize this later.

mypyc/lib-rt/misc_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int CPy_YieldFromErrorHandle(PyObject *iter, PyObject **outp)
4545
{
4646
_Py_IDENTIFIER(close);
4747
_Py_IDENTIFIER(throw);
48-
PyObject *exc_type = CPy_ExcState()->exc_type;
48+
PyObject *exc_type = (PyObject *)Py_TYPE(CPy_ExcState()->exc_value);
4949
PyObject *type, *value, *traceback;
5050
PyObject *_m;
5151
PyObject *res;

0 commit comments

Comments
 (0)