[Numpy-discussion] Review of issue 825
Travis E. Oliphant
oliphant at enthought.com
Thu Jun 26 03:42:36 EDT 2008
Charles R Harris wrote:
>
>
> On Wed, Jun 25, 2008 at 2:04 PM, Neil Muller
> <drnlmuller+scipy at gmail.com <mailto:drnlmuller%2Bscipy at gmail.com>> wrote:
>
> On Wed, Jun 25, 2008 at 7:53 PM, Charles R Harris
> <charlesr.harris at gmail.com <mailto:charlesr.harris at gmail.com>> wrote:
> > But I wonder if this case isn't supposed to be caught by this
> > fragment:
> >
> > if (!PyArray_ISBEHAVED(ap)) {
> > buffer = _pya_malloc(mysize << 2);
> > if (buffer == NULL)
> > return PyErr_NoMemory();
> > alloc = 1;
> > memcpy(buffer, ip, mysize << 2);
> > if (!PyArray_ISNOTSWAPPED(ap)) {
> > byte_swap_vector(buffer, mysize, 4);
> > }
> > }
>
> This actually works fine - the problem is immediately before this,
> with the loop to find the end of the unicode string.
>
This is indeed the problem. No de-referencing of anything but a char
pointer should be done unless you are sure you have an aligned array.
This length-of-string adjustment code should definitely be placed after
the copy is done so that an aligned array is obtained.
The other approach is to check the length of string differently (i.e.
using only byte dereferencing) so that when the string is misaligned
un-necessary copies are not done. But, Chuck's patch looks sufficient.
Best regards,
-Travis
More information about the NumPy-Discussion
mailing list