[Numpy-discussion] Review of issue 825

Charles R Harris charlesr.harris@gmail....
Wed Jun 25 16:32:05 CDT 2008


On Wed, Jun 25, 2008 at 2:04 PM, Neil Muller
<drnlmuller+scipy@gmail.com<drnlmuller%2Bscipy@gmail.com>>
wrote:

> On Wed, Jun 25, 2008 at 7:53 PM, Charles R Harris
> <charlesr.harris@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.
>

Ah, then we should move that to after the checks. Looking at some of the
other code that calls through UNICODE_getitem, I see that there are a ton of
alignment checks and buffer allocations. That is, a ton of code duplication.
The usual check is something like

                    ((((intp)(ip+offset)) % ap->alignment) != 0))

Which may be used to set the flag. I think we should should put this upfront
in UNICODE_getitem, make the copy if needed, check byte order, and then trim
the zeros and proceed. Duplicated code can then be removed at leisure some
point.

Chuck


> An alternative solution is to avoid the long pointer dptr entirely and
> use a different approach to find the string length, but I worry that
> that would obscure the intent of the code with very little positive
> benefit.
>
> --
> Neil Muller
> drnlmuller@gmail.com
>
> I've got a gmail account. Why haven't I become cool?
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080625/91e3e5fe/attachment.html 


More information about the Numpy-discussion mailing list