diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-06-14 04:15:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 04:15:26 (GMT) |
commit | 6fd4c8ec7740523bb81191c013118d9d6959bc9d (patch) | |
tree | df4df3a66a89cb1acff0d7721adb62d5553512e3 /Python/pylifecycle.c | |
parent | 7b2064b4b942e1d3c7fd74b5c463250319bc20fb (diff) | |
download | cpython-6fd4c8ec7740523bb81191c013118d9d6959bc9d.zip cpython-6fd4c8ec7740523bb81191c013118d9d6959bc9d.tar.gz cpython-6fd4c8ec7740523bb81191c013118d9d6959bc9d.tar.bz2 |
gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)
It combines PyImport_ImportModule() and PyObject_GetAttrString()
and saves 4-6 lines of code on every use.
Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 31a358f..0937cce 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2342,19 +2342,15 @@ error: static PyStatus init_set_builtins_open(void) { - PyObject *iomod = NULL, *wrapper; + PyObject *wrapper; PyObject *bimod = NULL; PyStatus res = _PyStatus_OK(); - if (!(iomod = PyImport_ImportModule("io"))) { - goto error; - } - if (!(bimod = PyImport_ImportModule("builtins"))) { goto error; } - if (!(wrapper = PyObject_GetAttrString(iomod, "open"))) { + if (!(wrapper = _PyImport_GetModuleAttrString("io", "open"))) { goto error; } @@ -2371,7 +2367,6 @@ error: done: Py_XDECREF(bimod); - Py_XDECREF(iomod); return res; } |