@@ -1920,7 +1920,6 @@ static PyObject *
1920
1920
_winapi_PeekNamedPipe_impl (PyObject * module , HANDLE handle , int size )
1921
1921
/*[clinic end generated code: output=d0c3e29e49d323dd input=c7aa53bfbce69d70]*/
1922
1922
{
1923
- PyObject * buf = NULL ;
1924
1923
DWORD nread , navail , nleft ;
1925
1924
BOOL ret ;
1926
1925
@@ -1930,20 +1929,26 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size)
1930
1929
}
1931
1930
1932
1931
if (size ) {
1933
- buf = PyBytes_FromStringAndSize ( NULL , size );
1934
- if (! buf )
1932
+ PyBytesWriter * writer = PyBytesWriter_Create ( size );
1933
+ if (writer == NULL ) {
1935
1934
return NULL ;
1935
+ }
1936
+ char * buf = PyBytesWriter_GetData (writer );
1937
+
1936
1938
Py_BEGIN_ALLOW_THREADS
1937
- ret = PeekNamedPipe (handle , PyBytes_AS_STRING ( buf ) , size , & nread ,
1939
+ ret = PeekNamedPipe (handle , buf , size , & nread ,
1938
1940
& navail , & nleft );
1939
1941
Py_END_ALLOW_THREADS
1940
1942
if (!ret ) {
1941
- Py_DECREF ( buf );
1943
+ PyBytesWriter_Discard ( writer );
1942
1944
return PyErr_SetExcFromWindowsErr (PyExc_OSError , 0 );
1943
1945
}
1944
- if (_PyBytes_Resize (& buf , nread ))
1946
+
1947
+ PyObject * res = PyBytesWriter_FinishWithSize (writer , nread );
1948
+ if (res == NULL ) {
1945
1949
return NULL ;
1946
- return Py_BuildValue ("NII" , buf , navail , nleft );
1950
+ }
1951
+ return Py_BuildValue ("NII" , res , navail , nleft );
1947
1952
}
1948
1953
else {
1949
1954
Py_BEGIN_ALLOW_THREADS
0 commit comments