summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-06-14 04:15:26 (GMT)
committerGitHub <noreply@github.com>2022-06-14 04:15:26 (GMT)
commit6fd4c8ec7740523bb81191c013118d9d6959bc9d (patch)
treedf4df3a66a89cb1acff0d7721adb62d5553512e3 /Objects/abstract.c
parent7b2064b4b942e1d3c7fd74b5c463250319bc20fb (diff)
downloadcpython-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 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 93987c2..5d50491 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -526,18 +526,12 @@ _Py_add_one_to_index_C(int nd, Py_ssize_t *index, const Py_ssize_t *shape)
Py_ssize_t
PyBuffer_SizeFromFormat(const char *format)
{
- PyObject *structmodule = NULL;
PyObject *calcsize = NULL;
PyObject *res = NULL;
PyObject *fmt = NULL;
Py_ssize_t itemsize = -1;
- structmodule = PyImport_ImportModule("struct");
- if (structmodule == NULL) {
- return itemsize;
- }
-
- calcsize = PyObject_GetAttrString(structmodule, "calcsize");
+ calcsize = _PyImport_GetModuleAttrString("struct", "calcsize");
if (calcsize == NULL) {
goto done;
}
@@ -558,7 +552,6 @@ PyBuffer_SizeFromFormat(const char *format)
}
done:
- Py_DECREF(structmodule);
Py_XDECREF(calcsize);
Py_XDECREF(fmt);
Py_XDECREF(res);