diff options
author | Mark Shannon <mark@hotpy.org> | 2022-05-13 10:24:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 10:24:45 (GMT) |
commit | 22a1db378c5c381272362c5b2f68ac78a368e136 (patch) | |
tree | 40f828dfe421c885aa841b301c12476465c50c19 /Modules/_testcapimodule.c | |
parent | db388df1d9aff02f791fe01c7c2b28d73982dce6 (diff) | |
download | cpython-22a1db378c5c381272362c5b2f68ac78a368e136.zip cpython-22a1db378c5c381272362c5b2f68ac78a368e136.tar.gz cpython-22a1db378c5c381272362c5b2f68ac78a368e136.tar.bz2 |
GH-92236: Remove spurious "line" event when starting coroutine or generator. (GH-92722)
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 4371bf7..363dbbb 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -5787,6 +5787,51 @@ test_code_api(PyObject *self, PyObject *Py_UNUSED(args)) Py_RETURN_NONE; } +static int +record_func(PyObject *obj, PyFrameObject *f, int what, PyObject *arg) +{ + assert(PyList_Check(obj)); + PyObject *what_obj = NULL; + PyObject *line_obj = NULL; + PyObject *tuple = NULL; + int res = -1; + what_obj = PyLong_FromLong(what); + if (what_obj == NULL) { + goto error; + } + int line = PyFrame_GetLineNumber(f); + line_obj = PyLong_FromLong(line); + if (line_obj == NULL) { + goto error; + } + tuple = PyTuple_Pack(3, what_obj, line_obj, arg); + if (tuple == NULL) { + goto error; + } + PyTuple_SET_ITEM(tuple, 0, what_obj); + if (PyList_Append(obj, tuple)) { + goto error; + } + res = 0; +error: + Py_XDECREF(what_obj); + Py_XDECREF(line_obj); + Py_XDECREF(tuple); + return res; +} + +static PyObject * +settrace_to_record(PyObject *self, PyObject *list) +{ + + if (!PyList_Check(list)) { + PyErr_SetString(PyExc_TypeError, "argument must be a list"); + return NULL; + } + PyEval_SetTrace(record_func, list); + Py_RETURN_NONE; +} + static PyObject *negative_dictoffset(PyObject *, PyObject *); static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *); static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*); @@ -6076,6 +6121,7 @@ static PyMethodDef TestMethods[] = { {"frame_getlasti", frame_getlasti, METH_O, NULL}, {"get_feature_macros", get_feature_macros, METH_NOARGS, NULL}, {"test_code_api", test_code_api, METH_NOARGS, NULL}, + {"settrace_to_record", settrace_to_record, METH_O, NULL}, {NULL, NULL} /* sentinel */ }; |