mirror of
https://github.com/python/cpython
synced 2026-09-29 10:35:30 +03: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
|
|
@ -1950,18 +1950,12 @@ unpacker_free(struct unpacker *x)
|
|||
static struct unpacker *
|
||||
struct_get_unpacker(const char *fmt, Py_ssize_t itemsize)
|
||||
{
|
||||
PyObject *structmodule; /* XXX cache these two */
|
||||
PyObject *Struct = NULL; /* XXX in globals? */
|
||||
PyObject *Struct = NULL; /* XXX cache it in globals? */
|
||||
PyObject *structobj = NULL;
|
||||
PyObject *format = NULL;
|
||||
struct unpacker *x = NULL;
|
||||
|
||||
structmodule = PyImport_ImportModule("struct");
|
||||
if (structmodule == NULL)
|
||||
return NULL;
|
||||
|
||||
Struct = PyObject_GetAttrString(structmodule, "Struct");
|
||||
Py_DECREF(structmodule);
|
||||
Struct = _PyImport_GetModuleAttrString("struct", "Struct");
|
||||
if (Struct == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue