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 /Parser/tokenizer.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 'Parser/tokenizer.c')
-rw-r--r-- | Parser/tokenizer.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index d5b549c..952265e 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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; } |