mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +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
|
@ -77,13 +77,7 @@ init_normalization(Parser *p)
|
|||
if (p->normalize) {
|
||||
return 1;
|
||||
}
|
||||
PyObject *m = PyImport_ImportModule("unicodedata");
|
||||
if (!m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
p->normalize = PyObject_GetAttrString(m, "normalize");
|
||||
Py_DECREF(m);
|
||||
p->normalize = _PyImport_GetModuleAttrString("unicodedata", "normalize");
|
||||
if (!p->normalize)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -421,7 +421,7 @@ error:
|
|||
static int
|
||||
fp_setreadl(struct tok_state *tok, const char* enc)
|
||||
{
|
||||
PyObject *readline, *io, *stream;
|
||||
PyObject *readline, *open, *stream;
|
||||
int fd;
|
||||
long pos;
|
||||
|
||||
|
@ -438,13 +438,13 @@ fp_setreadl(struct tok_state *tok, const char* enc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
io = PyImport_ImportModule("io");
|
||||
if (io == NULL) {
|
||||
open = _PyImport_GetModuleAttrString("io", "open");
|
||||
if (open == NULL) {
|
||||
return 0;
|
||||
}
|
||||
stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisOOO",
|
||||
stream = PyObject_CallFunction(open, "isisOOO",
|
||||
fd, "r", -1, enc, Py_None, Py_None, Py_False);
|
||||
Py_DECREF(io);
|
||||
Py_DECREF(open);
|
||||
if (stream == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue