summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-01-06 17:54:47 (GMT)
committerGitHub <noreply@github.com>2025-01-06 17:54:47 (GMT)
commitf826beca0cedb8e4b92896544c75fd0d9dcb0446 (patch)
tree87630b6e28e141a0e687e04d2f66d8e4cde21b99 /Modules
parentb9c693dcca01537eee1ef716ffebc632be37594b (diff)
downloadcpython-f826beca0cedb8e4b92896544c75fd0d9dcb0446.zip
cpython-f826beca0cedb8e4b92896544c75fd0d9dcb0446.tar.gz
cpython-f826beca0cedb8e4b92896544c75fd0d9dcb0446.tar.bz2
GH-128375: Better instrument for `FOR_ITER` (GH-128445)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index cd90141..a0a1f8a 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3415,6 +3415,26 @@ test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
Py_RETURN_NONE;
}
+static PyObject*
+code_offset_to_line(PyObject* self, PyObject* const* args, Py_ssize_t nargsf)
+{
+ Py_ssize_t nargs = _PyVectorcall_NARGS(nargsf);
+ if (nargs != 2) {
+ PyErr_SetString(PyExc_TypeError, "code_offset_to_line takes 2 arguments");
+ return NULL;
+ }
+ int offset;
+ if (PyLong_AsInt32(args[1], &offset) < 0) {
+ return NULL;
+ }
+ PyCodeObject *code = (PyCodeObject *)args[0];
+ if (!PyCode_Check(code)) {
+ PyErr_SetString(PyExc_TypeError, "first arg must be a code object");
+ return NULL;
+ }
+ return PyLong_FromInt32(PyCode_Addr2Line(code, offset));
+}
+
static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
@@ -3557,6 +3577,7 @@ static PyMethodDef TestMethods[] = {
{"finalize_thread_hang", finalize_thread_hang, METH_O, NULL},
{"type_freeze", type_freeze, METH_VARARGS},
{"test_atexit", test_atexit, METH_NOARGS},
+ {"code_offset_to_line", _PyCFunction_CAST(code_offset_to_line), METH_FASTCALL},
{NULL, NULL} /* sentinel */
};