[Numpy-discussion] Change in behavior of PyArray_BYTES(

Matthew Brett matthew.brett at gmail.com
Wed Jul 27 18:50:48 EDT 2011


Hi,

On Wed, Jul 27, 2011 at 3:40 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
> On Wed, Jul 27, 2011 at 5:35 PM, Matthew Brett <matthew.brett at gmail.com>
> wrote:
>>
>> Hi,
>>
>> I was trying to compile matplotlib against current trunk, and hit an
>> error with this line:
>>
>>            char* row0 = PyArray_BYTES(matrix);
>>
>>
>> https://github.com/matplotlib/matplotlib/blob/master/src/agg_py_transforms.cpp
>>
>> The error is:
>>
>> src/agg_py_transforms.cpp:30:26: error: invalid conversion from
>> ‘void*’ to ‘char*’
>>
>> It turned out that the output type of PyArray_BYTES has changed
>> between 1.5.1 and current trunk
>>
>> In 1.5.1, ndarraytypes.h:
>>
>> #define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)
>> (resulting in a char *, from the char * bytes member of PyArrayObject)
>>
>> In current trunk we have this:
>>
>> #define PyArray_BYTES(arr) PyArray_DATA(arr)
>>
>> ifndef NPY_NO_DEPRECATED_API  then this results in:
>>
>> #define PyArray_DATA(obj) ((void *)(((PyArrayObject_fieldaccess
>> *)(obj))->data))
>>
>> giving a void *
>>
>> ifdef NPY_NO_DEPRECATED_API then:
>>
>> static NPY_INLINE char *
>> PyArray_DATA(PyArrayObject *arr)
>> {
>>    return ((PyArrayObject_fieldaccess *)arr)->data;
>> }
>>
>> resulting in a char * (for both PyArray_DATA and PyArray_BYTES.
>>
>> It seems to me that it would be safer to add back this line:
>>
>> #define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)
>>
>> to ndarraytypes.h , within the ifndef NPY_NO_DEPRECATED_API block, to
>> maintain compatibility.
>>
>> Do y'all agree?
>
> Yes, this was an error. Michael Droettboom's pull request to fix it is
> already merged, so if you update against master it should work.
> -Mark

Ah - yes - thanks,

Matthew



More information about the NumPy-Discussion mailing list