@@ -221,17 +221,32 @@ stacklet__callback(stacklet_handle h, void *arg)
221
221
/* set current thread state before starting this new Fiber */
222
222
tstate = PyThreadState_Get ();
223
223
ASSERT (tstate != NULL );
224
+ tstate -> exc_state .exc_value = NULL ;
225
+ #if PY_MINOR_VERSION < 11
224
226
tstate -> frame = NULL ;
225
227
tstate -> exc_state .exc_type = NULL ;
226
- tstate -> exc_state .exc_value = NULL ;
227
228
tstate -> exc_state .exc_traceback = NULL ;
229
+ #else
230
+ tstate -> datastack_chunk = NULL ;
231
+ tstate -> datastack_top = NULL ;
232
+ tstate -> datastack_limit = NULL ;
233
+ tstate -> cframe -> current_frame = NULL ;
234
+ #endif
228
235
tstate -> exc_state .previous_item = NULL ;
229
236
230
- self -> ts .recursion_depth = tstate -> recursion_depth ;
231
237
self -> ts .frame = NULL ;
232
- self -> ts .exc_state .exc_type = NULL ;
233
238
self -> ts .exc_state .exc_value = NULL ;
239
+ #if PY_MINOR_VERSION < 11
240
+ self -> ts .recursion_depth = tstate -> recursion_depth ;
241
+ self -> ts .exc_state .exc_type = NULL ;
234
242
self -> ts .exc_state .exc_traceback = NULL ;
243
+ #else
244
+ self -> ts .recursion_depth = tstate -> recursion_limit - tstate -> recursion_remaining ;
245
+ self -> ts .cframe = NULL ;
246
+ self -> ts .datastack_chunk = NULL ;
247
+ self -> ts .datastack_top = NULL ;
248
+ self -> ts .datastack_limit = NULL ;
249
+ #endif
235
250
self -> ts .exc_state .previous_item = NULL ;
236
251
237
252
if (value == NULL ) {
@@ -285,11 +300,21 @@ do_switch(Fiber *self, PyObject *value)
285
300
tstate = PyThreadState_Get ();
286
301
ASSERT (tstate != NULL );
287
302
ASSERT (tstate -> dict != NULL );
303
+ current -> ts .exc_state .exc_value = tstate -> exc_state .exc_value ;
304
+ #if PY_MINOR_VERSION < 11
288
305
current -> ts .recursion_depth = tstate -> recursion_depth ;
289
306
current -> ts .frame = tstate -> frame ;
290
307
current -> ts .exc_state .exc_type = tstate -> exc_state .exc_type ;
291
- current -> ts .exc_state .exc_value = tstate -> exc_state .exc_value ;
292
308
current -> ts .exc_state .exc_traceback = tstate -> exc_state .exc_traceback ;
309
+ #else
310
+ current -> ts .recursion_depth = tstate -> recursion_limit - tstate -> recursion_remaining ;
311
+ current -> ts .frame = PyThreadState_GetFrame (tstate );
312
+ Py_XDECREF (current -> ts .frame );
313
+ current -> ts .cframe = tstate -> cframe ;
314
+ current -> ts .datastack_chunk = tstate -> datastack_chunk ;
315
+ current -> ts .datastack_top = tstate -> datastack_top ;
316
+ current -> ts .datastack_limit = tstate -> datastack_limit ;
317
+ #endif
293
318
current -> ts .exc_state .previous_item = tstate -> exc_state .previous_item ;
294
319
ASSERT (current -> stacklet_h == NULL );
295
320
@@ -328,17 +353,32 @@ do_switch(Fiber *self, PyObject *value)
328
353
}
329
354
330
355
/* restore state */
356
+ tstate -> exc_state .exc_value = current -> ts .exc_state .exc_value ;
357
+ #if PY_MINOR_VERSION < 11
331
358
tstate -> recursion_depth = current -> ts .recursion_depth ;
332
359
tstate -> frame = current -> ts .frame ;
333
360
tstate -> exc_state .exc_type = current -> ts .exc_state .exc_type ;
334
- tstate -> exc_state .exc_value = current -> ts .exc_state .exc_value ;
335
361
tstate -> exc_state .exc_traceback = current -> ts .exc_state .exc_traceback ;
362
+ #else
363
+ tstate -> recursion_remaining = tstate -> recursion_limit - current -> ts .recursion_depth ;
364
+ tstate -> cframe = current -> ts .cframe ;
365
+ tstate -> datastack_chunk = current -> ts .datastack_chunk ;
366
+ tstate -> datastack_top = current -> ts .datastack_top ;
367
+ tstate -> datastack_limit = current -> ts .datastack_limit ;
368
+ #endif
336
369
tstate -> exc_state .previous_item = current -> ts .exc_state .previous_item ;
337
370
338
371
current -> ts .frame = NULL ;
339
- current -> ts .exc_state .exc_type = NULL ;
340
372
current -> ts .exc_state .exc_value = NULL ;
373
+ #if PY_MINOR_VERSION < 11
374
+ current -> ts .exc_state .exc_type = NULL ;
341
375
current -> ts .exc_state .exc_traceback = NULL ;
376
+ #else
377
+ current -> ts .cframe = NULL ;
378
+ current -> ts .datastack_chunk = NULL ;
379
+ current -> ts .datastack_top = NULL ;
380
+ current -> ts .datastack_limit = NULL ;
381
+ #endif
342
382
current -> ts .exc_state .previous_item = NULL ;
343
383
344
384
return result ;
@@ -590,9 +630,11 @@ Fiber_tp_traverse(Fiber *self, visitproc visit, void *arg)
590
630
Py_VISIT (self -> ts_dict );
591
631
Py_VISIT (self -> parent );
592
632
Py_VISIT (self -> ts .frame );
593
- Py_VISIT (self -> ts .exc_state .exc_type );
594
633
Py_VISIT (self -> ts .exc_state .exc_value );
634
+ #if PY_MINOR_VERSION < 11
635
+ Py_VISIT (self -> ts .exc_state .exc_type );
595
636
Py_VISIT (self -> ts .exc_state .exc_traceback );
637
+ #endif
596
638
Py_VISIT (self -> ts .exc_state .previous_item );
597
639
598
640
return 0 ;
@@ -609,9 +651,11 @@ Fiber_tp_clear(Fiber *self)
609
651
Py_CLEAR (self -> ts_dict );
610
652
Py_CLEAR (self -> parent );
611
653
Py_CLEAR (self -> ts .frame );
612
- Py_CLEAR (self -> ts .exc_state .exc_type );
613
654
Py_CLEAR (self -> ts .exc_state .exc_value );
655
+ #if PY_MINOR_VERSION < 11
656
+ Py_CLEAR (self -> ts .exc_state .exc_type );
614
657
Py_CLEAR (self -> ts .exc_state .exc_traceback );
658
+ #endif
615
659
Py_CLEAR (self -> ts .exc_state .previous_item );
616
660
617
661
return 0 ;
0 commit comments