gh-142913: Add test case for interpreter generator w/ overridden opco… · python/cpython@4d5a676

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

@@ -693,6 +693,43 @@ set_eval_frame_record(PyObject *self, PyObject *list)

693693Py_RETURN_NONE;

694694}

695695696+// Defined in interpreter.c

697+externPyObject*

698+Test_EvalFrame(PyThreadState*tstate, _PyInterpreterFrame*frame, intthrowflag);

699+externintTest_EvalFrame_Resumes, Test_EvalFrame_Loads;

700+701+staticPyObject*

702+get_eval_frame_stats(PyObject*self, PyObject*Py_UNUSED(args))

703+{

704+PyObject*res=PyDict_New();

705+if (res==NULL) {

706+returnNULL;

707+ }

708+PyObject*resumes=PyLong_FromLong(Test_EvalFrame_Resumes);

709+if (resumes==NULL||PyDict_SetItemString(res, "resumes", resumes) <0) {

710+Py_XDECREF(resumes);

711+Py_DECREF(res);

712+returnNULL;

713+ }

714+Py_DECREF(resumes);

715+PyObject*loads=PyLong_FromLong(Test_EvalFrame_Loads);

716+if (loads==NULL||PyDict_SetItemString(res, "loads", loads) <0) {

717+Py_XDECREF(loads);

718+Py_DECREF(res);

719+returnNULL;

720+ }

721+Py_DECREF(loads);

722+Test_EvalFrame_Resumes=Test_EvalFrame_Loads=0;

723+returnres;

724+}

725+726+staticPyObject*

727+set_eval_frame_interp(PyObject*self, PyObject*Py_UNUSED(args))

728+{

729+_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), Test_EvalFrame);

730+Py_RETURN_NONE;

731+}

732+696733/*[clinic input]

697734698735_testinternalcapi.compiler_cleandoc -> object

@@ -2531,6 +2568,7 @@ test_threadstate_set_stack_protection(PyObject *self, PyObject *Py_UNUSED(args))

2531256825322569staticPyMethodDefmodule_functions[] = {

25332570 {"get_configs", get_configs, METH_NOARGS},

2571+ {"get_eval_frame_stats", get_eval_frame_stats, METH_NOARGS, NULL},

25342572 {"get_recursion_depth", get_recursion_depth, METH_NOARGS},

25352573 {"get_c_recursion_remaining", get_c_recursion_remaining, METH_NOARGS},

25362574 {"get_stack_pointer", get_stack_pointer, METH_NOARGS},

@@ -2547,6 +2585,7 @@ static PyMethodDef module_functions[] = {

25472585 {"EncodeLocaleEx", encode_locale_ex, METH_VARARGS},

25482586 {"DecodeLocaleEx", decode_locale_ex, METH_VARARGS},

25492587 {"set_eval_frame_default", set_eval_frame_default, METH_NOARGS, NULL},

2588+ {"set_eval_frame_interp", set_eval_frame_interp, METH_NOARGS, NULL},

25502589 {"set_eval_frame_record", set_eval_frame_record, METH_O, NULL},

25512590_TESTINTERNALCAPI_COMPILER_CLEANDOC_METHODDEF

25522591_TESTINTERNALCAPI_NEW_INSTRUCTION_SEQUENCE_METHODDEF