[Numpy-discussion] record descriptors: trailing unused bytes

Travis Oliphant oliphant.travis at ieee.org
Mon Sep 18 14:46:17 EDT 2006


Martin Wiechert wrote:
> Hi list,
>
> does anybody know, if in C in the PyArray_Descr struct it is safe to manually 
> change descr->elsize and descr->alignment as long as these are compatible and 
> descr->elsize is large enough to hold all fields? Of course I mean before any 
> array is constructed using descr.
>   

Well, you should really make a copy of the PyArray_Descr structure and 
then fill it in as desired unless you are sure that no other arrays have 
are using that particular data-type object to describe their own data:  
PyArray_DescrNew gives you a new copy based on an old one (you just get 
a reference to the funciton pointers in the 'f' member so don't go 
changing those).

I guess your statement about "before any array is constructed using 
descr" means you are sure that there are no other arrays using the old 
elsize and alignment.

Then it should be fine.  There are not supposed to be any assumptions 
about the data-types except for what is explicitly provided in the 
data-type object (PyArray_Descr *).  So, changing them will change the 
data-type and things should ideally work.

-Travis







More information about the NumPy-Discussion mailing list