@@ -158,13 +158,13 @@ BytesWriter_getvalue(BytesWriterObject *self, PyObject *Py_UNUSED(ignored))
158158static Py_ssize_t
159159BytesWriter_length (BytesWriterObject * self )
160160{
161- return self -> ptr - self -> buf ;
161+ return self -> len ;
162162}
163163
164164static PyObject *
165165BytesWriter_item (BytesWriterObject * self , Py_ssize_t index )
166166{
167- Py_ssize_t length = self -> ptr - self -> buf ;
167+ Py_ssize_t length = self -> len ;
168168
169169 // Check bounds
170170 if (index < 0 || index >= length ) {
@@ -179,7 +179,7 @@ BytesWriter_item(BytesWriterObject *self, Py_ssize_t index)
179179static int
180180BytesWriter_ass_item (BytesWriterObject * self , Py_ssize_t index , PyObject * value )
181181{
182- Py_ssize_t length = self -> ptr - self -> buf ;
182+ Py_ssize_t length = self -> len ;
183183
184184 // Check bounds
185185 if (index < 0 || index >= length ) {
@@ -330,14 +330,14 @@ BytesWriter_truncate(PyObject *self, PyObject *const *args, size_t nargs) {
330330 }
331331
332332 BytesWriterObject * writer = (BytesWriterObject * )self ;
333- Py_ssize_t current_size = writer -> ptr - writer -> buf ;
333+ Py_ssize_t current_size = writer -> len ;
334334
335335 if (size > current_size ) {
336336 PyErr_SetString (PyExc_ValueError , "size cannot be larger than current buffer size" );
337337 return NULL ;
338338 }
339339
340- writer -> ptr = writer -> buf + size ;
340+ writer -> len = size ;
341341 Py_INCREF (Py_None );
342342 return Py_None ;
343343}
@@ -373,13 +373,13 @@ BytesWriter_type_internal(void) {
373373static CPyTagged
374374BytesWriter_len_internal (PyObject * self ) {
375375 BytesWriterObject * writer = (BytesWriterObject * )self ;
376- return ( writer -> ptr - writer -> buf ) << 1 ;
376+ return writer -> len << 1 ;
377377}
378378
379379static char
380380BytesWriter_truncate_internal (PyObject * self , int64_t size ) {
381381 BytesWriterObject * writer = (BytesWriterObject * )self ;
382- Py_ssize_t current_size = writer -> ptr - writer -> buf ;
382+ Py_ssize_t current_size = writer -> len ;
383383
384384 // Validate size is non-negative
385385 if (size < 0 ) {
@@ -393,7 +393,7 @@ BytesWriter_truncate_internal(PyObject *self, int64_t size) {
393393 return CPY_NONE_ERROR ;
394394 }
395395
396- writer -> ptr = writer -> buf + size ;
396+ writer -> len = size ;
397397 return CPY_NONE ;
398398}
399399
0 commit comments