@@ -194,18 +194,15 @@ context_switched(PyThreadState *ts)
194
194
195
195
196
196
static int
197
- _PyContext_Enter (PyThreadState * ts , PyObject * octx )
197
+ _PyContext_Enter (PyThreadState * ts , PyContext * ctx )
198
198
{
199
- ENSURE_Context (octx , -1 )
200
- PyContext * ctx = (PyContext * )octx ;
201
-
202
199
if (ctx -> ctx_entered ) {
203
200
_PyErr_Format (ts , PyExc_RuntimeError ,
204
201
"cannot enter context: %R is already entered" , ctx );
205
202
return -1 ;
206
203
}
207
204
208
- ctx -> ctx_prev = ( PyContext * ) ts -> context ; /* borrow */
205
+ ctx -> ctx_prev = ts -> context ; /* borrow */
209
206
ctx -> ctx_entered = 1 ;
210
207
211
208
ts -> context = Py_NewRef (ctx );
@@ -219,16 +216,14 @@ PyContext_Enter(PyObject *octx)
219
216
{
220
217
PyThreadState * ts = _PyThreadState_GET ();
221
218
assert (ts != NULL );
222
- return _PyContext_Enter (ts , octx );
219
+ ENSURE_Context (octx , -1 )
220
+ return _PyContext_Enter (ts , (PyContext * )octx );
223
221
}
224
222
225
223
226
224
static int
227
- _PyContext_Exit (PyThreadState * ts , PyObject * octx )
225
+ _PyContext_Exit (PyThreadState * ts , PyContext * ctx )
228
226
{
229
- ENSURE_Context (octx , -1 )
230
- PyContext * ctx = (PyContext * )octx ;
231
-
232
227
if (!ctx -> ctx_entered ) {
233
228
PyErr_Format (PyExc_RuntimeError ,
234
229
"cannot exit context: %R has not been entered" , ctx );
@@ -243,7 +238,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
243
238
return -1 ;
244
239
}
245
240
246
- Py_SETREF (ts -> context , ( PyObject * ) ctx -> ctx_prev );
241
+ Py_SETREF (ts -> context , ctx -> ctx_prev );
247
242
248
243
ctx -> ctx_prev = NULL ;
249
244
ctx -> ctx_entered = 0 ;
@@ -256,7 +251,8 @@ PyContext_Exit(PyObject *octx)
256
251
{
257
252
PyThreadState * ts = _PyThreadState_GET ();
258
253
assert (ts != NULL );
259
- return _PyContext_Exit (ts , octx );
254
+ ENSURE_Context (octx , -1 )
255
+ return _PyContext_Exit (ts , (PyContext * )octx );
260
256
}
261
257
262
258
@@ -715,14 +711,14 @@ context_run(PyContext *self, PyObject *const *args,
715
711
return NULL ;
716
712
}
717
713
718
- if (_PyContext_Enter (ts , ( PyObject * ) self )) {
714
+ if (_PyContext_Enter (ts , self )) {
719
715
return NULL ;
720
716
}
721
717
722
718
PyObject * call_result = _PyObject_VectorcallTstate (
723
719
ts , args [0 ], args + 1 , nargs - 1 , kwnames );
724
720
725
- if (_PyContext_Exit (ts , ( PyObject * ) self )) {
721
+ if (_PyContext_Exit (ts , self )) {
726
722
Py_XDECREF (call_result );
727
723
return NULL ;
728
724
}
0 commit comments