mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-129813, PEP 782: Use PyBytesWriter in _ssl (#138929)
Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize() with the new public PyBytesWriter API.
This commit is contained in:
parent
b0a8073f1b
commit
446587c58e
1 changed files with 12 additions and 10 deletions
|
|
@ -2891,7 +2891,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
|
|||
int group_right_1, Py_buffer *buffer)
|
||||
/*[clinic end generated code: output=49b16e6406023734 input=80ed30436df01a71]*/
|
||||
{
|
||||
PyObject *dest = NULL;
|
||||
PyBytesWriter *writer = NULL;
|
||||
char *mem;
|
||||
size_t count = 0;
|
||||
int retval;
|
||||
|
|
@ -2918,14 +2918,16 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
|
|||
}
|
||||
|
||||
if (!group_right_1) {
|
||||
dest = PyBytes_FromStringAndSize(NULL, len);
|
||||
if (dest == NULL)
|
||||
goto error;
|
||||
if (len == 0) {
|
||||
Py_XDECREF(sock);
|
||||
return dest;
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||
}
|
||||
mem = PyBytes_AS_STRING(dest);
|
||||
|
||||
writer = PyBytesWriter_Create(len);
|
||||
if (writer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
mem = PyBytesWriter_GetData(writer);
|
||||
}
|
||||
else {
|
||||
mem = buffer->buf;
|
||||
|
|
@ -3003,8 +3005,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
|
|||
done:
|
||||
Py_XDECREF(sock);
|
||||
if (!group_right_1) {
|
||||
_PyBytes_Resize(&dest, count);
|
||||
return dest;
|
||||
return PyBytesWriter_FinishWithSize(writer, count);
|
||||
}
|
||||
else {
|
||||
return PyLong_FromSize_t(count);
|
||||
|
|
@ -3013,8 +3014,9 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
|
|||
error:
|
||||
PySSL_ChainExceptions(self);
|
||||
Py_XDECREF(sock);
|
||||
if (!group_right_1)
|
||||
Py_XDECREF(dest);
|
||||
if (!group_right_1) {
|
||||
PyBytesWriter_Discard(writer);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue