[Python-bugs-list] [ python-Bugs-444842 ] array's buffer_info() -> length in bytes
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 26 Jul 2001 15:56:17 -0700
Bugs item #444842, was opened at 2001-07-26 08:51
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=444842&group_id=5470
Category: Extension Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Armin Rigo (arigo)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: array's buffer_info() -> length in bytes
Initial Comment:
In arraymodule.c, the array's method buffer_info() is
documented to return (address, length), where 'length'
is measured in bytes. Unfortunately, it currently
returns the number of items instead. It should be fixed.
Changing the return value could potentially break code
relying on the actual (undocumented) behavior. On the
other hand, merely changing the documentation to
'officialize' the bug would be a departure from
buffer_info()'s original goal to provide direct raw
memory access.
I think the bug should be fixed, with a note about the
different behavior of previous versions in the docs --
for maximum portability, users can always compute the
length in bytes separately as "len(a)*a.itemsize".
Current users of buffer_info() may already have noticed
the bug and used the above formula to get the length,
so their code won't break.
Fix: in arraymodule.c: array_buffer_info:
PyTuple_SET_ITEM(retval, 1,
PyInt_FromLong((long)(self->ob_size *
self->ob_descr->itemsize)));
The multiplication should not overflow (care was taken
about it at resize time).
Armin
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-07-26 15:56
Message:
Logged In: YES
user_id=31435
Assigned to Guido cuz it's a mess. buffer_info() has
worked this way since it was first checked in (about 4
years ago). Armin is right that it doesn't match the
manual or the docstring, and the docs make more sense than
what it actually does. Dare we "break" this? Does
buffer_info() even serve a purpose now given that arrays
also support the buffer interface?
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=444842&group_id=5470