summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-08 16:40:27 (GMT)
committerGitHub <noreply@github.com>2022-11-08 16:40:27 (GMT)
commit4d5fcca273b24a5566f1507758e5aae60cdf8a98 (patch)
treeac00d021776bd95cddd48ca272e07d8711d73922 /Modules
parentacf4d5d5bdecbc8756276731e09bae245d88518d (diff)
downloadcpython-4d5fcca273b24a5566f1507758e5aae60cdf8a98.zip
cpython-4d5fcca273b24a5566f1507758e5aae60cdf8a98.tar.gz
cpython-4d5fcca273b24a5566f1507758e5aae60cdf8a98.tar.bz2
gh-91248: Add PyFrame_GetVar() function (#95712)
Add PyFrame_GetVar() and PyFrame_GetVarString() functions to get a frame variable by its name. Move PyFrameObject C API tests from test_capi to test_frame.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1624a93..0615c73 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5608,6 +5608,38 @@ frame_getlasti(PyObject *self, PyObject *frame)
}
static PyObject *
+test_frame_getvar(PyObject *self, PyObject *args)
+{
+ PyObject *frame, *name;
+ if (!PyArg_ParseTuple(args, "OO", &frame, &name)) {
+ return NULL;
+ }
+ if (!PyFrame_Check(frame)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a frame");
+ return NULL;
+ }
+
+ return PyFrame_GetVar((PyFrameObject *)frame, name);
+}
+
+static PyObject *
+test_frame_getvarstring(PyObject *self, PyObject *args)
+{
+ PyObject *frame;
+ const char *name;
+ if (!PyArg_ParseTuple(args, "Oy", &frame, &name)) {
+ return NULL;
+ }
+ if (!PyFrame_Check(frame)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a frame");
+ return NULL;
+ }
+
+ return PyFrame_GetVarString((PyFrameObject *)frame, name);
+}
+
+
+static PyObject *
eval_get_func_name(PyObject *self, PyObject *func)
{
return PyUnicode_FromString(PyEval_GetFuncName(func));
@@ -6294,6 +6326,8 @@ static PyMethodDef TestMethods[] = {
{"frame_getgenerator", frame_getgenerator, METH_O, NULL},
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
{"frame_getlasti", frame_getlasti, METH_O, NULL},
+ {"frame_getvar", test_frame_getvar, METH_VARARGS, NULL},
+ {"frame_getvarstring", test_frame_getvarstring, METH_VARARGS, NULL},
{"eval_get_func_name", eval_get_func_name, METH_O, NULL},
{"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},