1212#define PY_SSIZE_T_CLEAN
1313
1414#include "Python.h"
15+ #include "frameobject.h"
1516#include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
1617#include "pycore_bitutils.h" // _Py_bswap32()
1718#include "pycore_compile.h" // _PyCompile_CodeGen, _PyCompile_OptimizeCfg, _PyCompile_Assemble
@@ -757,6 +758,38 @@ clear_extension(PyObject *self, PyObject *args)
757758 Py_RETURN_NONE ;
758759}
759760
761+ static PyObject *
762+ iframe_getcode (PyObject * self , PyObject * frame )
763+ {
764+ if (!PyFrame_Check (frame )) {
765+ PyErr_SetString (PyExc_TypeError , "argument must be a frame" );
766+ return NULL ;
767+ }
768+ struct _PyInterpreterFrame * f = ((PyFrameObject * )frame )-> f_frame ;
769+ return PyUnstable_InterpreterFrame_GetCode (f );
770+ }
771+
772+ static PyObject *
773+ iframe_getline (PyObject * self , PyObject * frame )
774+ {
775+ if (!PyFrame_Check (frame )) {
776+ PyErr_SetString (PyExc_TypeError , "argument must be a frame" );
777+ return NULL ;
778+ }
779+ struct _PyInterpreterFrame * f = ((PyFrameObject * )frame )-> f_frame ;
780+ return PyLong_FromLong (PyUnstable_InterpreterFrame_GetLine (f ));
781+ }
782+
783+ static PyObject *
784+ iframe_getlasti (PyObject * self , PyObject * frame )
785+ {
786+ if (!PyFrame_Check (frame )) {
787+ PyErr_SetString (PyExc_TypeError , "argument must be a frame" );
788+ return NULL ;
789+ }
790+ struct _PyInterpreterFrame * f = ((PyFrameObject * )frame )-> f_frame ;
791+ return PyLong_FromLong (PyUnstable_InterpreterFrame_GetLasti (f ));
792+ }
760793
761794static PyMethodDef module_functions [] = {
762795 {"get_configs" , get_configs , METH_NOARGS },
@@ -781,6 +814,9 @@ static PyMethodDef module_functions[] = {
781814 _TESTINTERNALCAPI_ASSEMBLE_CODE_OBJECT_METHODDEF
782815 {"get_interp_settings" , get_interp_settings , METH_VARARGS , NULL },
783816 {"clear_extension" , clear_extension , METH_VARARGS , NULL },
817+ {"iframe_getcode" , iframe_getcode , METH_O , NULL },
818+ {"iframe_getline" , iframe_getline , METH_O , NULL },
819+ {"iframe_getlasti" , iframe_getlasti , METH_O , NULL },
784820 {NULL , NULL } /* sentinel */
785821};
786822
0 commit comments