2828
2929#define MAX_EXECUTORS_SIZE 256
3030
31+ #define _PyExecutorObject_CAST (op ) ((_PyExecutorObject *)(op))
32+
3133static bool
3234has_space_for_executor (PyCodeObject * code , _Py_CODEUNIT * instr )
3335{
@@ -199,11 +201,12 @@ get_oparg(PyObject *self, PyObject *Py_UNUSED(ignored))
199201
200202///////////////////// Experimental UOp Optimizer /////////////////////
201203
202- static int executor_clear (_PyExecutorObject * executor );
204+ static int executor_clear (PyObject * executor );
203205static void unlink_executor (_PyExecutorObject * executor );
204206
205207static void
206- uop_dealloc (_PyExecutorObject * self ) {
208+ uop_dealloc (PyObject * op ) {
209+ _PyExecutorObject * self = _PyExecutorObject_CAST (op );
207210 _PyObject_GC_UNTRACK (self );
208211 assert (self -> vm_data .code == NULL );
209212 unlink_executor (self );
@@ -260,15 +263,17 @@ _PyUOpPrint(const _PyUOpInstruction *uop)
260263#endif
261264
262265static Py_ssize_t
263- uop_len (_PyExecutorObject * self )
266+ uop_len (PyObject * op )
264267{
268+ _PyExecutorObject * self = _PyExecutorObject_CAST (op );
265269 return self -> code_size ;
266270}
267271
268272static PyObject *
269- uop_item (_PyExecutorObject * self , Py_ssize_t index )
273+ uop_item (PyObject * op , Py_ssize_t index )
270274{
271- Py_ssize_t len = uop_len (self );
275+ _PyExecutorObject * self = _PyExecutorObject_CAST (op );
276+ Py_ssize_t len = uop_len (op );
272277 if (index < 0 || index >= len ) {
273278 PyErr_SetNone (PyExc_IndexError );
274279 return NULL ;
@@ -304,14 +309,14 @@ uop_item(_PyExecutorObject *self, Py_ssize_t index)
304309}
305310
306311PySequenceMethods uop_as_sequence = {
307- .sq_length = ( lenfunc ) uop_len ,
308- .sq_item = ( ssizeargfunc ) uop_item ,
312+ .sq_length = uop_len ,
313+ .sq_item = uop_item ,
309314};
310315
311316static int
312317executor_traverse (PyObject * o , visitproc visit , void * arg )
313318{
314- _PyExecutorObject * executor = ( _PyExecutorObject * ) o ;
319+ _PyExecutorObject * executor = _PyExecutorObject_CAST ( o ) ;
315320 for (uint32_t i = 0 ; i < executor -> exit_count ; i ++ ) {
316321 Py_VISIT (executor -> exits [i ].executor );
317322 }
@@ -325,7 +330,7 @@ get_jit_code(PyObject *self, PyObject *Py_UNUSED(ignored))
325330 PyErr_SetString (PyExc_RuntimeError , "JIT support not enabled." );
326331 return NULL ;
327332#else
328- _PyExecutorObject * executor = ( _PyExecutorObject * ) self ;
333+ _PyExecutorObject * executor = _PyExecutorObject_CAST ( self ) ;
329334 if (executor -> jit_code == NULL || executor -> jit_size == 0 ) {
330335 Py_RETURN_NONE ;
331336 }
@@ -353,11 +358,11 @@ PyTypeObject _PyUOpExecutor_Type = {
353358 .tp_basicsize = offsetof(_PyExecutorObject , exits ),
354359 .tp_itemsize = 1 ,
355360 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC ,
356- .tp_dealloc = ( destructor ) uop_dealloc ,
361+ .tp_dealloc = uop_dealloc ,
357362 .tp_as_sequence = & uop_as_sequence ,
358363 .tp_methods = uop_executor_methods ,
359364 .tp_traverse = executor_traverse ,
360- .tp_clear = ( inquiry ) executor_clear ,
365+ .tp_clear = executor_clear ,
361366 .tp_is_gc = executor_is_gc ,
362367};
363368
@@ -1422,8 +1427,9 @@ _Py_ExecutorDetach(_PyExecutorObject *executor)
14221427}
14231428
14241429static int
1425- executor_clear (_PyExecutorObject * executor )
1430+ executor_clear (PyObject * op )
14261431{
1432+ _PyExecutorObject * executor = _PyExecutorObject_CAST (op );
14271433 if (!executor -> vm_data .valid ) {
14281434 return 0 ;
14291435 }
@@ -1479,7 +1485,7 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is
14791485 exec = next ;
14801486 }
14811487 for (Py_ssize_t i = 0 ; i < PyList_GET_SIZE (invalidate ); i ++ ) {
1482- _PyExecutorObject * exec = ( _PyExecutorObject * ) PyList_GET_ITEM (invalidate , i );
1488+ PyObject * exec = PyList_GET_ITEM (invalidate , i );
14831489 executor_clear (exec );
14841490 if (is_invalidation ) {
14851491 OPT_STAT_INC (executors_invalidated );
@@ -1506,7 +1512,7 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
15061512 _PyCode_Clear_Executors (executor -> vm_data .code );
15071513 }
15081514 else {
1509- executor_clear (executor );
1515+ executor_clear (( PyObject * ) executor );
15101516 }
15111517 if (is_invalidation ) {
15121518 OPT_STAT_INC (executors_invalidated );
@@ -1540,7 +1546,7 @@ _Py_Executors_InvalidateCold(PyInterpreterState *interp)
15401546 exec = next ;
15411547 }
15421548 for (Py_ssize_t i = 0 ; i < PyList_GET_SIZE (invalidate ); i ++ ) {
1543- _PyExecutorObject * exec = ( _PyExecutorObject * ) PyList_GET_ITEM (invalidate , i );
1549+ PyObject * exec = PyList_GET_ITEM (invalidate , i );
15441550 executor_clear (exec );
15451551 }
15461552 Py_DECREF (invalidate );
0 commit comments