mirror of
https://github.com/python/cpython.git
synced 2026-02-14 03:10:44 +00:00
gh-129813, PEP 782: Use PyBytesWriter in _testclinic (#139048)
Replace PyBytes_FromStringAndSize(NULL, size) with the new public PyBytesWriter API.
This commit is contained in:
parent
8eb106240f
commit
82e1920a01
1 changed files with 6 additions and 6 deletions
|
|
@ -663,16 +663,16 @@ str_converter_encoding_impl(PyObject *module, char *a, char *b, char *c,
|
|||
static PyObject *
|
||||
bytes_from_buffer(Py_buffer *buf)
|
||||
{
|
||||
PyObject *bytes_obj = PyBytes_FromStringAndSize(NULL, buf->len);
|
||||
if (!bytes_obj) {
|
||||
PyBytesWriter *writer = PyBytesWriter_Create(buf->len);
|
||||
if (writer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
void *bytes_obj_buf = ((PyBytesObject *)bytes_obj)->ob_sval;
|
||||
if (PyBuffer_ToContiguous(bytes_obj_buf, buf, buf->len, 'C') < 0) {
|
||||
Py_DECREF(bytes_obj);
|
||||
void *data = PyBytesWriter_GetData(writer);
|
||||
if (PyBuffer_ToContiguous(data, buf, buf->len, 'C') < 0) {
|
||||
PyBytesWriter_Discard(writer);
|
||||
return NULL;
|
||||
}
|
||||
return bytes_obj;
|
||||
return PyBytesWriter_Finish(writer);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue