[Python-bugs-list] [ python-Bugs-444842 ] array's buffer_info() -> length in bytes

noreply@sourceforge.net noreply@sourceforge.net
Thu, 26 Jul 2001 08:51:31 -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: Nobody/Anonymous (nobody)
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

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=444842&group_id=5470