[Numpy-discussion] Review of issue 825

Charles R Harris charlesr.harris@gmail....
Wed Jun 25 13:46:39 CDT 2008


On Wed, Jun 25, 2008 at 11:53 AM, Charles R Harris <
charlesr.harris@gmail.com> wrote:

>
>
> On Wed, Jun 25, 2008 at 10:49 AM, Neil Muller <drnlmuller+scipy@gmail.com<drnlmuller%2Bscipy@gmail.com>>
> wrote:
>
>> On Wed, Jun 25, 2008 at 5:14 PM, Charles R Harris
>> <charlesr.harris@gmail.com> wrote:
>> > OK, the problem in the UNICODE_{get,set}item routines is converting
>> between
>> > ucs4 and the encoding python is using, which may be ucs2.  But there is
>> > something strange if sparc is using ucs4 (Py_UNICODE_WIDE) and the
>> pointer
>> > ip is aligned on two bytes instead of 4, that would seem to indicate a
>> > problem further up the call chain. Could you check that that is actually
>> > happening, i.e., ip is not 4 byte aligned and Py_UNICODE_WIDE is
>> defined?
>>
>> You need to keep the test case in the 1st comment of the issue in mind
>> here - the problem is extracting the unicode string for a dtype
>> specified as (unsigned char, unicode string). This is allocated as 5
>> bytes, and the string is not correctly aligned within these 5 bytes
>> for access via a long pointer, as is needed for the current check in
>> UNICODE_getitem to work.
>>
>
> Umm, OK. So what we have is a packed structure from which to extract the
> unicode and if we want to have portability it probably needs to remain
> packed. I think the fix should be made generic rather than depending on
> sparc.  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);
>         }
>     }
>

#define NPY_BEHAVED (NPY_ALIGNED | NPY_WRITEABLE)

Looks to me like the NPY_ALIGNED flag is incorrectly set. Can you check
this  by printing the results of

PyArray_CHKFLAGS(ap, NPY_ALIGNED)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080625/3c383b37/attachment.html 


More information about the Numpy-discussion mailing list