@@ -194,18 +194,15 @@ context_switched(PyThreadState *ts)
194194
195195
196196static int
197- _PyContext_Enter (PyThreadState * ts , PyObject * octx )
197+ _PyContext_Enter (PyThreadState * ts , PyContext * ctx )
198198{
199- ENSURE_Context (octx , -1 )
200- PyContext * ctx = (PyContext * )octx ;
201-
202199 if (ctx -> ctx_entered ) {
203200 _PyErr_Format (ts , PyExc_RuntimeError ,
204201 "cannot enter context: %R is already entered" , ctx );
205202 return -1 ;
206203 }
207204
208- ctx -> ctx_prev = ( PyContext * ) ts -> context ; /* borrow */
205+ ctx -> ctx_prev = ts -> context ; /* borrow */
209206 ctx -> ctx_entered = 1 ;
210207
211208 ts -> context = Py_NewRef (ctx );
@@ -219,16 +216,14 @@ PyContext_Enter(PyObject *octx)
219216{
220217 PyThreadState * ts = _PyThreadState_GET ();
221218 assert (ts != NULL );
222- return _PyContext_Enter (ts , octx );
219+ ENSURE_Context (octx , -1 )
220+ return _PyContext_Enter (ts , (PyContext * )octx );
223221}
224222
225223
226224static int
227- _PyContext_Exit (PyThreadState * ts , PyObject * octx )
225+ _PyContext_Exit (PyThreadState * ts , PyContext * ctx )
228226{
229- ENSURE_Context (octx , -1 )
230- PyContext * ctx = (PyContext * )octx ;
231-
232227 if (!ctx -> ctx_entered ) {
233228 PyErr_Format (PyExc_RuntimeError ,
234229 "cannot exit context: %R has not been entered" , ctx );
@@ -243,7 +238,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
243238 return -1 ;
244239 }
245240
246- Py_SETREF (ts -> context , ( PyObject * ) ctx -> ctx_prev );
241+ Py_SETREF (ts -> context , ctx -> ctx_prev );
247242
248243 ctx -> ctx_prev = NULL ;
249244 ctx -> ctx_entered = 0 ;
@@ -256,7 +251,8 @@ PyContext_Exit(PyObject *octx)
256251{
257252 PyThreadState * ts = _PyThreadState_GET ();
258253 assert (ts != NULL );
259- return _PyContext_Exit (ts , octx );
254+ ENSURE_Context (octx , -1 )
255+ return _PyContext_Exit (ts , (PyContext * )octx );
260256}
261257
262258
@@ -715,14 +711,14 @@ context_run(PyContext *self, PyObject *const *args,
715711 return NULL ;
716712 }
717713
718- if (_PyContext_Enter (ts , ( PyObject * ) self )) {
714+ if (_PyContext_Enter (ts , self )) {
719715 return NULL ;
720716 }
721717
722718 PyObject * call_result = _PyObject_VectorcallTstate (
723719 ts , args [0 ], args + 1 , nargs - 1 , kwnames );
724720
725- if (_PyContext_Exit (ts , ( PyObject * ) self )) {
721+ if (_PyContext_Exit (ts , self )) {
726722 Py_XDECREF (call_result );
727723 return NULL ;
728724 }
0 commit comments