mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
gh-129813, PEP 782: Use PyBytesWriter in _multiprocessing (#139047)
Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize() with the new public PyBytesWriter API. Change also 'read' variable type from int to Py_ssize_t.
This commit is contained in:
parent
263242613f
commit
77a22ef76a
1 changed files with 8 additions and 9 deletions
|
|
@ -109,23 +109,22 @@ static PyObject *
|
||||||
_multiprocessing_recv_impl(PyObject *module, HANDLE handle, int size)
|
_multiprocessing_recv_impl(PyObject *module, HANDLE handle, int size)
|
||||||
/*[clinic end generated code: output=92322781ba9ff598 input=6a5b0834372cee5b]*/
|
/*[clinic end generated code: output=92322781ba9ff598 input=6a5b0834372cee5b]*/
|
||||||
{
|
{
|
||||||
int nread;
|
PyBytesWriter *writer = PyBytesWriter_Create(size);
|
||||||
PyObject *buf;
|
if (!writer) {
|
||||||
|
|
||||||
buf = PyBytes_FromStringAndSize(NULL, size);
|
|
||||||
if (!buf)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
char *buf = PyBytesWriter_GetData(writer);
|
||||||
|
|
||||||
|
Py_ssize_t nread;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
nread = recv((SOCKET) handle, PyBytes_AS_STRING(buf), size, 0);
|
nread = recv((SOCKET) handle, buf, size, 0);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
Py_DECREF(buf);
|
PyBytesWriter_Discard(writer);
|
||||||
return PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
|
return PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
|
||||||
}
|
}
|
||||||
_PyBytes_Resize(&buf, nread);
|
return PyBytesWriter_FinishWithSize(writer, nread);
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue