Skip to content

Commit 1427086

Browse files
jhassesaghul
authored andcommitted
Restore compatibility with Python 3.12
python/cpython@7644935
1 parent ce76162 commit 1427086

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.github/workflows/python-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
# would use windows-latest, but distutils tries to build against the version of MSVC that python was compiled with
2121
# https://github.com/pypa/setuptools/blob/main/setuptools/_distutils/msvc9compiler.py#L403
2222
os: [ "ubuntu-latest", "macos-12", "windows-2019" ]
23-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
23+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
2424
#os: [ "ubuntu-latest" ]
2525
#python-version: ["3.8"]
2626

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
if '32 bit' in sys.version:
2626
extra_objects = ['src/switch_x86_msvc.obj']
27-
os.system('ml /nologo /c /Fo src\switch_x86_msvc.obj src\switch_x86_msvc.asm')
27+
os.system('ml /nologo /c /Fo src\\switch_x86_msvc.obj src\\switch_x86_msvc.asm')
2828
else:
2929
extra_objects = ['src/switch_x64_msvc.obj']
30-
os.system('ml64 /nologo /c /Fo src\switch_x64_msvc.obj src\switch_x64_msvc.asm')
30+
os.system('ml64 /nologo /c /Fo src\\switch_x64_msvc.obj src\\switch_x64_msvc.asm')
3131

3232
ext_modules = [Extension('fibers._cfibers',
3333
sources=glob.glob('src/*.c'),

src/fibers.c

+15
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ stacklet__callback(stacklet_handle h, void *arg)
241241
self->ts.exc_state.exc_type = NULL;
242242
self->ts.exc_state.exc_traceback = NULL;
243243
#else
244+
#if PY_MINOR_VERSION < 12
244245
self->ts.recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
246+
#else
247+
self->ts.recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining;
248+
self->ts.c_recursion_remaining = tstate->c_recursion_remaining;
249+
#endif
245250
self->ts.cframe = NULL;
246251
self->ts.datastack_chunk = NULL;
247252
self->ts.datastack_top = NULL;
@@ -307,7 +312,12 @@ do_switch(Fiber *self, PyObject *value)
307312
current->ts.exc_state.exc_type = tstate->exc_state.exc_type;
308313
current->ts.exc_state.exc_traceback = tstate->exc_state.exc_traceback;
309314
#else
315+
#if PY_MINOR_VERSION < 12
310316
current->ts.recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
317+
#else
318+
current->ts.recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining;
319+
current->ts.c_recursion_remaining = tstate->c_recursion_remaining;
320+
#endif
311321
current->ts.frame = PyThreadState_GetFrame(tstate);
312322
Py_XDECREF(current->ts.frame);
313323
current->ts.cframe = tstate->cframe;
@@ -360,7 +370,12 @@ do_switch(Fiber *self, PyObject *value)
360370
tstate->exc_state.exc_type = current->ts.exc_state.exc_type;
361371
tstate->exc_state.exc_traceback = current->ts.exc_state.exc_traceback;
362372
#else
373+
#if PY_MINOR_VERSION < 12
363374
tstate->recursion_remaining = tstate->recursion_limit - current->ts.recursion_depth;
375+
#else
376+
tstate->py_recursion_remaining = tstate->py_recursion_limit - current->ts.recursion_depth;
377+
tstate->c_recursion_remaining = current->ts.c_recursion_remaining;
378+
#endif
364379
tstate->cframe = current->ts.cframe;
365380
tstate->datastack_chunk = current->ts.datastack_chunk;
366381
tstate->datastack_top = current->ts.datastack_top;

src/fibers.h

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ typedef struct _fiber {
3838
#endif
3939
struct _frame *frame;
4040
int recursion_depth;
41+
#if PY_MINOR_VERSION >= 12
42+
int c_recursion_remaining;
43+
#endif
4144
_PyErr_StackItem exc_state;
4245
} ts;
4346
} Fiber;

0 commit comments

Comments
 (0)