diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-10-16 04:18:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 04:18:59 (GMT) |
commit | 7b48d02933639c91ebd957b2326d8c352d8eddec (patch) | |
tree | 596ec5fbaa7430ef99a30109b0f0d34aa908655f /Modules | |
parent | 660f10248ba321e7783c07f3801991275e2aee1e (diff) | |
download | cpython-7b48d02933639c91ebd957b2326d8c352d8eddec.zip cpython-7b48d02933639c91ebd957b2326d8c352d8eddec.tar.gz cpython-7b48d02933639c91ebd957b2326d8c352d8eddec.tar.bz2 |
gh-94808: Cover `PyFunction_GetCode`, `PyFunction_GetGlobals`, `PyFunction_GetModule` (#98158)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 76e619d..624e878 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -5658,6 +5658,42 @@ test_macros(PyObject *self, PyObject *Py_UNUSED(args)) Py_RETURN_NONE; } +static PyObject * +function_get_code(PyObject *self, PyObject *func) +{ + PyObject *code = PyFunction_GetCode(func); + if (code != NULL) { + Py_INCREF(code); + return code; + } else { + return NULL; + } +} + +static PyObject * +function_get_globals(PyObject *self, PyObject *func) +{ + PyObject *globals = PyFunction_GetGlobals(func); + if (globals != NULL) { + Py_INCREF(globals); + return globals; + } else { + return NULL; + } +} + +static PyObject * +function_get_module(PyObject *self, PyObject *func) +{ + PyObject *module = PyFunction_GetModule(func); + if (module != NULL) { + Py_INCREF(module); + return module; + } else { + return NULL; + } +} + static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *); static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*); @@ -5942,6 +5978,9 @@ static PyMethodDef TestMethods[] = { {"watch_dict", watch_dict, METH_VARARGS, NULL}, {"unwatch_dict", unwatch_dict, METH_VARARGS, NULL}, {"get_dict_watcher_events", get_dict_watcher_events, METH_NOARGS, NULL}, + {"function_get_code", function_get_code, METH_O, NULL}, + {"function_get_globals", function_get_globals, METH_O, NULL}, + {"function_get_module", function_get_module, METH_O, NULL}, {NULL, NULL} /* sentinel */ }; |