@@ -1002,6 +1002,32 @@ get_executor(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
10021002 return (PyObject * )PyUnstable_GetExecutor ((PyCodeObject * )code , ioffset );
10031003}
10041004
1005+ static PyObject *
1006+ add_executor_dependency (PyObject * self , PyObject * args )
1007+ {
1008+ PyObject * exec ;
1009+ PyObject * obj ;
1010+ if (!PyArg_ParseTuple (args , "OO" , & exec , & obj )) {
1011+ return NULL ;
1012+ }
1013+ /* No way to tell in general if exec is an executor, so we only accept
1014+ * counting_executor */
1015+ if (strcmp (Py_TYPE (exec )-> tp_name , "counting_executor" )) {
1016+ PyErr_SetString (PyExc_TypeError , "argument must be a counting_executor" );
1017+ return NULL ;
1018+ }
1019+ _Py_Executor_DependsOn ((_PyExecutorObject * )exec , obj );
1020+ Py_RETURN_NONE ;
1021+ }
1022+
1023+ static PyObject *
1024+ invalidate_executors (PyObject * self , PyObject * obj )
1025+ {
1026+ PyInterpreterState * interp = PyInterpreterState_Get ();
1027+ _Py_Executors_InvalidateDependency (interp , obj );
1028+ Py_RETURN_NONE ;
1029+ }
1030+
10051031static int _pending_callback (void * arg )
10061032{
10071033 /* we assume the argument is callable object to which we own a reference */
@@ -1565,6 +1591,8 @@ static PyMethodDef module_functions[] = {
15651591 {"get_executor" , _PyCFunction_CAST (get_executor ), METH_FASTCALL , NULL },
15661592 {"get_counter_optimizer" , get_counter_optimizer , METH_NOARGS , NULL },
15671593 {"get_uop_optimizer" , get_uop_optimizer , METH_NOARGS , NULL },
1594+ {"add_executor_dependency" , add_executor_dependency , METH_VARARGS , NULL },
1595+ {"invalidate_executors" , invalidate_executors , METH_O , NULL },
15681596 {"pending_threadfunc" , _PyCFunction_CAST (pending_threadfunc ),
15691597 METH_VARARGS | METH_KEYWORDS },
15701598 {"pending_identify" , pending_identify , METH_VARARGS , NULL },
0 commit comments