summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-05-18 09:10:15 (GMT)
committerGitHub <noreply@github.com>2023-05-18 09:10:15 (GMT)
commitcfa517d5a68bae24cbe8d9fe6b8e0d4935e507d2 (patch)
treec25c67c7ba5b46b22884fc04f62b4429443c99e5 /Modules
parent68b5f08b72e02f62ec787bfbb7aa99bac661daec (diff)
downloadcpython-cfa517d5a68bae24cbe8d9fe6b8e0d4935e507d2.zip
cpython-cfa517d5a68bae24cbe8d9fe6b8e0d4935e507d2.tar.gz
cpython-cfa517d5a68bae24cbe8d9fe6b8e0d4935e507d2.tar.bz2
GH-96803: Document and test new unstable internal frame API functions (GH-104211)
Weaken contract of PyUnstable_InterpreterFrame_GetCode to return PyObject*.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testinternalcapi.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index ea9b6e7..5802f1d 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -12,6 +12,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
+#include "frameobject.h"
#include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
#include "pycore_bitutils.h" // _Py_bswap32()
#include "pycore_compile.h" // _PyCompile_CodeGen, _PyCompile_OptimizeCfg, _PyCompile_Assemble
@@ -757,6 +758,38 @@ clear_extension(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *
+iframe_getcode(PyObject *self, PyObject *frame)
+{
+ if (!PyFrame_Check(frame)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a frame");
+ return NULL;
+ }
+ struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame;
+ return PyUnstable_InterpreterFrame_GetCode(f);
+}
+
+static PyObject *
+iframe_getline(PyObject *self, PyObject *frame)
+{
+ if (!PyFrame_Check(frame)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a frame");
+ return NULL;
+ }
+ struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame;
+ return PyLong_FromLong(PyUnstable_InterpreterFrame_GetLine(f));
+}
+
+static PyObject *
+iframe_getlasti(PyObject *self, PyObject *frame)
+{
+ if (!PyFrame_Check(frame)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a frame");
+ return NULL;
+ }
+ struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame;
+ return PyLong_FromLong(PyUnstable_InterpreterFrame_GetLasti(f));
+}
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
@@ -781,6 +814,9 @@ static PyMethodDef module_functions[] = {
_TESTINTERNALCAPI_ASSEMBLE_CODE_OBJECT_METHODDEF
{"get_interp_settings", get_interp_settings, METH_VARARGS, NULL},
{"clear_extension", clear_extension, METH_VARARGS, NULL},
+ {"iframe_getcode", iframe_getcode, METH_O, NULL},
+ {"iframe_getline", iframe_getline, METH_O, NULL},
+ {"iframe_getlasti", iframe_getlasti, METH_O, NULL},
{NULL, NULL} /* sentinel */
};