summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKen Jin <kenjin4096@gmail.com>2022-05-03 13:13:13 (GMT)
committerGitHub <noreply@github.com>2022-05-03 13:13:13 (GMT)
commit6c7249f2655749a06b4674a17537f844bd54d217 (patch)
tree15c7131fdf51411d2e8e566347f75e9f0809f508 /Modules
parent1d4a9a45b7ac8c1c5fecc363c988be59500f1ed7 (diff)
downloadcpython-6c7249f2655749a06b4674a17537f844bd54d217.zip
cpython-6c7249f2655749a06b4674a17537f844bd54d217.tar.gz
cpython-6c7249f2655749a06b4674a17537f844bd54d217.tar.bz2
gh-92154: Expose PyCode_GetCode in the C API (GH-92168)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 9073f33..26d8d38 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5931,6 +5931,29 @@ get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
return result;
}
+static PyObject *
+test_code_api(PyObject *self, PyObject *Py_UNUSED(args))
+{
+ PyCodeObject *co = PyCode_NewEmpty("_testcapi", "dummy", 1);
+ if (co == NULL) {
+ return NULL;
+ }
+ PyObject *co_code = PyCode_GetCode(co);
+ if (co_code == NULL) {
+ Py_DECREF(co);
+ return NULL;
+ }
+ assert(PyBytes_CheckExact(co_code));
+ if (PyObject_Length(co_code) == 0) {
+ PyErr_SetString(PyExc_ValueError, "empty co_code");
+ Py_DECREF(co);
+ Py_DECREF(co_code);
+ return NULL;
+ }
+ Py_DECREF(co);
+ Py_DECREF(co_code);
+ Py_RETURN_NONE;
+}
static PyObject *negative_dictoffset(PyObject *, PyObject *);
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
@@ -6227,6 +6250,7 @@ static PyMethodDef TestMethods[] = {
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
{"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},
{NULL, NULL} /* sentinel */
};