FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-129813, PEP 782: Use PyBytesWriter in _ssl by vstinner · Pull Request #138929 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 12 additions & 10 deletions Modules/_ssl.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

writer = PyBytesWriter_Create(len);
if (writer == NULL) {
goto error;
}
mem = PyBytes_AS_STRING(dest);
mem = PyBytesWriter_GetData(writer);
}
else {
mem = buffer->buf;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL