|
20 | 20 | #define PY_SSIZE_T_CLEAN
|
21 | 21 |
|
22 | 22 | #include "Python.h"
|
| 23 | +#include "frameobject.h" // PyFrame_New |
23 | 24 | #include "marshal.h" // PyMarshal_WriteLongToFile
|
24 | 25 | #include "structmember.h" // for offsetof(), T_OBJECT
|
25 | 26 | #include <float.h> // FLT_MAX
|
@@ -2839,6 +2840,22 @@ frame_getlasti(PyObject *self, PyObject *frame)
|
2839 | 2840 | return PyLong_FromLong(lasti);
|
2840 | 2841 | }
|
2841 | 2842 |
|
| 2843 | +static PyObject * |
| 2844 | +frame_new(PyObject *self, PyObject *args) |
| 2845 | +{ |
| 2846 | + PyObject *code, *globals, *locals; |
| 2847 | + if (!PyArg_ParseTuple(args, "OOO", &code, &globals, &locals)) { |
| 2848 | + return NULL; |
| 2849 | + } |
| 2850 | + if (!PyCode_Check(code)) { |
| 2851 | + PyErr_SetString(PyExc_TypeError, "argument must be a code object"); |
| 2852 | + return NULL; |
| 2853 | + } |
| 2854 | + PyThreadState *tstate = PyThreadState_Get(); |
| 2855 | + |
| 2856 | + return (PyObject *)PyFrame_New(tstate, (PyCodeObject *)code, globals, locals); |
| 2857 | +} |
| 2858 | + |
2842 | 2859 | static PyObject *
|
2843 | 2860 | test_frame_getvar(PyObject *self, PyObject *args)
|
2844 | 2861 | {
|
@@ -3277,6 +3294,7 @@ static PyMethodDef TestMethods[] = {
|
3277 | 3294 | {"frame_getgenerator", frame_getgenerator, METH_O, NULL},
|
3278 | 3295 | {"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
|
3279 | 3296 | {"frame_getlasti", frame_getlasti, METH_O, NULL},
|
| 3297 | + {"frame_new", frame_new, METH_VARARGS, NULL}, |
3280 | 3298 | {"frame_getvar", test_frame_getvar, METH_VARARGS, NULL},
|
3281 | 3299 | {"frame_getvarstring", test_frame_getvarstring, METH_VARARGS, NULL},
|
3282 | 3300 | {"eval_get_func_name", eval_get_func_name, METH_O, NULL},
|
|
0 commit comments