[Numpy-discussion] Review of issue 825

Charles R Harris charlesr.harris@gmail....
Wed Jun 25 12:53:12 CDT 2008

On Wed, Jun 25, 2008 at 10:49 AM, Neil Muller

> 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

    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);

Maybe we should be using PyArray_ISBEHAVED_RO(ap) instead.

$[charris@f8 numpy]$ grep "define PyArray_ISBEHAVED" *
ndarrayobject.h:#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m,
ndarrayobject.h:#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m,
$[charris@f8 numpy]$ grep "define PyArray_FLAGSWAP" *
ndarrayobject.h:#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m,
flags) &&       \

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

More information about the Numpy-discussion mailing list