@@ -1807,30 +1807,24 @@ array_array_tolist_impl(arrayobject *self)
18071807@critical_section
18081808array.array.frombytes
18091809
1810- bytes: object
1810+ buffer: Py_buffer
18111811 /
18121812
18131813Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method.
18141814[clinic start generated code]*/
18151815
18161816static PyObject *
1817- array_array_frombytes_impl (arrayobject * self , PyObject * bytes )
1818- /*[clinic end generated code: output=8a48da6fa2f9dcde input=1758523e88df5d98 ]*/
1817+ array_array_frombytes_impl (arrayobject * self , Py_buffer * buffer )
1818+ /*[clinic end generated code: output=d9842c8f7510a516 input=2245f9ea58579960 ]*/
18191819{
1820- Py_buffer buffer = {NULL , NULL };
1821- if (PyObject_GetBuffer (bytes , & buffer , PyBUF_SIMPLE ) != 0 ) {
1822- return NULL ;
1823- }
18241820 int itemsize = self -> ob_descr -> itemsize ;
18251821 Py_ssize_t n ;
1826- if (buffer .itemsize != 1 ) {
1827- PyBuffer_Release (& buffer );
1822+ if (buffer -> itemsize != 1 ) {
18281823 PyErr_SetString (PyExc_TypeError , "a bytes-like object is required" );
18291824 return NULL ;
18301825 }
1831- n = buffer . len ;
1826+ n = buffer -> len ;
18321827 if (n % itemsize != 0 ) {
1833- PyBuffer_Release (& buffer );
18341828 PyErr_SetString (PyExc_ValueError ,
18351829 "bytes length not a multiple of item size" );
18361830 return NULL ;
@@ -1840,17 +1834,14 @@ array_array_frombytes_impl(arrayobject *self, PyObject *bytes)
18401834 Py_ssize_t old_size = Py_SIZE (self );
18411835 if ((n > PY_SSIZE_T_MAX - old_size ) ||
18421836 ((old_size + n ) > PY_SSIZE_T_MAX / itemsize )) {
1843- PyBuffer_Release (& buffer );
18441837 return PyErr_NoMemory ();
18451838 }
18461839 if (array_resize (self , old_size + n ) == -1 ) {
1847- PyBuffer_Release (& buffer );
18481840 return NULL ;
18491841 }
18501842 memcpy (self -> ob_item + old_size * itemsize ,
1851- buffer . buf , n * itemsize );
1843+ buffer -> buf , n * itemsize );
18521844 }
1853- PyBuffer_Release (& buffer );
18541845 Py_RETURN_NONE ;
18551846}
18561847
0 commit comments