mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
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.
This commit is contained in:
parent
7b2064b4b9
commit
6fd4c8ec77
24 changed files with 114 additions and 248 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue