From 82e1920a014cbe38bbadce8544b92e6894bc679b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 17 Sep 2025 16:55:30 +0100 Subject: [PATCH] gh-129813, PEP 782: Use PyBytesWriter in _testclinic (#139048) Replace PyBytes_FromStringAndSize(NULL, size) with the new public PyBytesWriter API. --- Modules/_testclinic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_testclinic.c b/Modules/_testclinic.c index 64cefdc7f0b8..69adf7d1a0a9 100644 --- a/Modules/_testclinic.c +++ b/Modules/_testclinic.c @@ -663,16 +663,16 @@ error: 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] -- 2.47.3