aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/fileobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Objects/fileobject.c
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Objects/fileobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/fileobject.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/contrib/tools/python3/src/Objects/fileobject.c b/contrib/tools/python3/src/Objects/fileobject.c
index ffe55eb7c3..e99e155f2b 100644
--- a/contrib/tools/python3/src/Objects/fileobject.c
+++ b/contrib/tools/python3/src/Objects/fileobject.c
@@ -32,16 +32,16 @@ PyObject *
PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding,
const char *errors, const char *newline, int closefd)
{
- PyObject *io, *stream;
+ PyObject *open, *stream;
/* import _io in case we are being used to open io.py */
- io = PyImport_ImportModule("_io");
- if (io == NULL)
+ open = _PyImport_GetModuleAttrString("_io", "open");
+ if (open == NULL)
return NULL;
- stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisssO", fd, mode,
+ stream = PyObject_CallFunction(open, "isisssO", fd, mode,
buffering, encoding, errors,
newline, closefd ? Py_True : Py_False);
- Py_DECREF(io);
+ Py_DECREF(open);
if (stream == NULL)
return NULL;
/* ignore name attribute because the name attribute of _BufferedIOMixin
@@ -67,8 +67,7 @@ PyFile_GetLine(PyObject *f, int n)
}
if (result != NULL && !PyBytes_Check(result) &&
!PyUnicode_Check(result)) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_TypeError,
"object.readline() returned non-string");
}
@@ -77,8 +76,7 @@ PyFile_GetLine(PyObject *f, int n)
const char *s = PyBytes_AS_STRING(result);
Py_ssize_t len = PyBytes_GET_SIZE(result);
if (len == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_EOFError,
"EOF when reading a line");
}
@@ -88,24 +86,21 @@ PyFile_GetLine(PyObject *f, int n)
else {
PyObject *v;
v = PyBytes_FromStringAndSize(s, len-1);
- Py_DECREF(result);
- result = v;
+ Py_SETREF(result, v);
}
}
}
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Py_ssize_t len = PyUnicode_GET_LENGTH(result);
if (len == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_EOFError,
"EOF when reading a line");
}
else if (PyUnicode_READ_CHAR(result, len-1) == '\n') {
PyObject *v;
v = PyUnicode_Substring(result, 0, len-1);
- Py_DECREF(result);
- result = v;
+ Py_SETREF(result, v);
}
}
return result;
@@ -499,7 +494,7 @@ PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData) {
PyObject *
PyFile_OpenCodeObject(PyObject *path)
{
- PyObject *iomod, *f = NULL;
+ PyObject *f = NULL;
if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError, "'path' must be 'str', not '%.200s'",
@@ -511,10 +506,10 @@ PyFile_OpenCodeObject(PyObject *path)
if (hook) {
f = hook(path, _PyRuntime.open_code_userdata);
} else {
- iomod = PyImport_ImportModule("_io");
- if (iomod) {
- f = _PyObject_CallMethod(iomod, &_Py_ID(open), "Os", path, "rb");
- Py_DECREF(iomod);
+ PyObject *open = _PyImport_GetModuleAttrString("_io", "open");
+ if (open) {
+ f = PyObject_CallFunction(open, "Os", path, "rb");
+ Py_DECREF(open);
}
}