@@ -722,42 +722,32 @@ Py_LOCAL_INLINE(void) SLP_EXCHANGE_EXCINFO(PyThreadState *tstate, PyTaskletObjec
722
722
PyThreadState * ts_ = (tstate );
723
723
PyTaskletObject * t_ = (task );
724
724
_PyErr_StackItem * exc_info ;
725
- PyObject * c ;
726
725
assert (ts_ );
727
726
assert (t_ );
728
727
exc_info = ts_ -> exc_info ;
729
728
assert (exc_info );
730
729
assert (t_ -> exc_info );
731
730
#if 0
732
- c = PyStackless_GetCurrent ();
731
+ PyObject * c = PyStackless_GetCurrent ();
733
732
fprintf (stderr , "SLP_EXCHANGE_EXCINFO %3d current %14p,\tset task %p = %p,\ttstate %p = %p\n" , __LINE__ , c , t_ , exc_info , ts_ , t_ -> exc_info );
734
733
Py_XDECREF (c );
735
734
#endif
736
735
ts_ -> exc_info = t_ -> exc_info ;
737
736
t_ -> exc_info = exc_info ;
738
- c = ts_ -> context ;
739
- ts_ -> context = t_ -> context ;
740
- t_ -> context = c ;
741
- ts_ -> context_ver ++ ;
742
737
}
743
738
#else
744
739
#define SLP_EXCHANGE_EXCINFO (tstate_ , task_ ) \
745
740
do { \
746
741
PyThreadState *ts_ = (tstate_); \
747
742
PyTaskletObject *t_ = (task_); \
748
743
_PyErr_StackItem *exc_info; \
749
- PyObject *c; \
750
744
assert(ts_); \
751
745
assert(t_); \
752
746
exc_info = ts_->exc_info; \
753
747
assert(exc_info); \
754
748
assert(t_->exc_info); \
755
749
ts_->exc_info = t_->exc_info; \
756
750
t_->exc_info = exc_info; \
757
- c = ts_->context; \
758
- ts_->context = t_->context; \
759
- t_->context = c; \
760
- ts_->context_ver++; \
761
751
} while(0)
762
752
#endif
763
753
@@ -766,13 +756,23 @@ Py_LOCAL_INLINE(void) SLP_UPDATE_TSTATE_ON_SWITCH(PyThreadState *tstate, PyTaskl
766
756
{
767
757
SLP_EXCHANGE_EXCINFO (tstate , prev );
768
758
SLP_EXCHANGE_EXCINFO (tstate , next );
759
+ prev -> context = tstate -> context ;
760
+ tstate -> context = next -> context ;
761
+ tstate -> context_ver ++ ;
762
+ next -> context = NULL ;
769
763
}
770
764
#else
771
765
#define SLP_UPDATE_TSTATE_ON_SWITCH (tstate__ , prev_ , next_ ) \
772
766
do { \
773
767
PyThreadState *ts__ = (tstate__); \
774
- SLP_EXCHANGE_EXCINFO(ts__, (prev_)); \
775
- SLP_EXCHANGE_EXCINFO(ts__, (next_)); \
768
+ PyTaskletObject *prev__ = (prev_); \
769
+ PyTaskletObject *next__ = (next_); \
770
+ SLP_EXCHANGE_EXCINFO(ts__, prev__); \
771
+ SLP_EXCHANGE_EXCINFO(ts__, next__); \
772
+ prev__->context = ts__->context; \
773
+ ts__->context = next__->context; \
774
+ ts__->context_ver++; \
775
+ next__->context = NULL; \
776
776
} while(0)
777
777
#endif
778
778
@@ -1299,8 +1299,6 @@ slp_initialize_main_and_current(void)
1299
1299
assert (task -> exc_state .previous_item == NULL );
1300
1300
assert (task -> exc_info == & task -> exc_state );
1301
1301
assert (task -> context == NULL );
1302
- Py_XINCREF (ts -> context );
1303
- task -> context = ts -> context ;
1304
1302
SLP_EXCHANGE_EXCINFO (ts , task );
1305
1303
1306
1304
NOTIFY_SCHEDULE (ts , NULL , task , -1 );
@@ -1394,11 +1392,9 @@ schedule_task_destruct(PyObject **retval, PyTaskletObject *prev, PyTaskletObject
1394
1392
/* main is exiting */
1395
1393
assert (ts -> st .main == NULL );
1396
1394
assert (ts -> exc_info == & prev -> exc_state );
1395
+ assert (prev -> context == NULL );
1397
1396
SLP_EXCHANGE_EXCINFO (ts , prev );
1398
1397
TASKLET_CLAIMVAL (prev , retval );
1399
- Py_XINCREF (prev -> context );
1400
- Py_XSETREF (ts -> context , prev -> context );
1401
- ts -> context_ver ++ ;
1402
1398
if (PyBomb_Check (* retval ))
1403
1399
* retval = slp_bomb_explode (* retval );
1404
1400
}
0 commit comments