mirror of
https://github.com/python/cpython.git
synced 2025-07-25 12:14:38 +00:00
Make os.read() return bytes, not bytearray.
This commit is contained in:
parent
82c0dfa3bd
commit
f9e443c49f
1 changed files with 3 additions and 3 deletions
|
@ -4746,18 +4746,18 @@ posix_read(PyObject *self, PyObject *args)
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return posix_error();
|
return posix_error();
|
||||||
}
|
}
|
||||||
buffer = PyBytes_FromStringAndSize((char *)NULL, size);
|
buffer = PyString_FromStringAndSize((char *)NULL, size);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
n = read(fd, PyBytes_AsString(buffer), size);
|
n = read(fd, PyString_AS_STRING(buffer), size);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
Py_DECREF(buffer);
|
Py_DECREF(buffer);
|
||||||
return posix_error();
|
return posix_error();
|
||||||
}
|
}
|
||||||
if (n != size)
|
if (n != size)
|
||||||
PyBytes_Resize(buffer, n);
|
_PyString_Resize(&buffer, n);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue