diff options
author | Bill Fisher <william.w.fisher@gmail.com> | 2022-12-24 05:47:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 05:47:10 (GMT) |
commit | 57e727af3fda446dc79d65e2d17297d1194892ed (patch) | |
tree | 333ac7be95840708d5b6339accb6594f655a19d6 /Modules | |
parent | b914054d9de574f5b3489f8601482eac5a7699e0 (diff) | |
download | cpython-57e727af3fda446dc79d65e2d17297d1194892ed.zip cpython-57e727af3fda446dc79d65e2d17297d1194892ed.tar.gz cpython-57e727af3fda446dc79d65e2d17297d1194892ed.tar.bz2 |
[3.11] gh-99110: Initialize frame->previous in init_frame to fix segmentation fault (GH-100182) (#100478)
(cherry picked from commit 88d565f32a709140664444c6dea20ecd35a10e94)
Co-authored-by: Bill Fisher <william.w.fisher@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 70242d7..bb7de22 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -22,6 +22,7 @@ #include "Python.h" #include "datetime.h" // PyDateTimeAPI +#include "frameobject.h" // PyFrame_New #include "marshal.h" // PyMarshal_WriteLongToFile #include "structmember.h" // PyMemberDef #include <float.h> // FLT_MAX @@ -6001,6 +6002,22 @@ frame_getlasti(PyObject *self, PyObject *frame) } static PyObject * +frame_new(PyObject *self, PyObject *args) +{ + PyObject *code, *globals, *locals; + if (!PyArg_ParseTuple(args, "OOO", &code, &globals, &locals)) { + return NULL; + } + if (!PyCode_Check(code)) { + PyErr_SetString(PyExc_TypeError, "argument must be a code object"); + return NULL; + } + PyThreadState *tstate = PyThreadState_Get(); + + return (PyObject *)PyFrame_New(tstate, (PyCodeObject *)code, globals, locals); +} + +static PyObject * eval_get_func_name(PyObject *self, PyObject *func) { return PyUnicode_FromString(PyEval_GetFuncName(func)); @@ -6492,6 +6509,7 @@ 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_new", frame_new, 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}, |