Hi Neil, On Wed, Jun 25, 2008 at 2:26 PM, Neil Muller <[EMAIL PROTECTED]<[EMAIL PROTECTED]>> wrote:
> On Wed, Jun 25, 2008 at 8:46 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > > > 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) > > For the test listed in the ticket, the array isn't flagged as aligned > - ap->flags = NPY_CONTIGUOUS | NPY_FORTRAN | NPY_WRITEABLE > > I'm under the impression that NPY_ALIGNED refers to the alignment of > the entire entry, though, in which case it's irrelevant here, since > the problem is with the internal alignment of items within a single > array entry. > It looks like it refers to the item. Look at VOID_getitem to see how it is set item by item. Can you try the attached patch? TIA, Chuck
Index: arraytypes.inc.src =================================================================== --- arraytypes.inc.src (revision 5315) +++ arraytypes.inc.src (working copy) @@ -248,49 +248,59 @@ return PyArray_Scalar(ip, ap->descr, NULL); } - /* UNICODE */ static PyObject * UNICODE_getitem(char *ip, PyArrayObject *ap) { - PyObject *obj; - int mysize; - PyArray_UCS4 *dptr; - char *buffer; - int alloc=0; + intp elsize = ap->descr->elsize; + intp mysize = elsize/sizeof(PyArray_UCS4); + int alloc = 0; + PyArray_UCS4 *buffer = NULL; + PyUnicodeObject *obj; - mysize = ap->descr->elsize >> 2; - dptr = (PyArray_UCS4 *)ip + mysize-1; - while(mysize > 0 && *dptr-- == 0) mysize--; - if (!PyArray_ISBEHAVED(ap)) { - buffer = _pya_malloc(mysize << 2); - if (buffer == NULL) - return PyErr_NoMemory(); + if (!PyArray_ISBEHAVED_RO(ap)) { + buffer = malloc(elsize); + if (buffer == NULL) { + PyErr_NoMemory(); + goto fail; + } alloc = 1; - memcpy(buffer, ip, mysize << 2); + memcpy(buffer, ip, elsize); if (!PyArray_ISNOTSWAPPED(ap)) { - byte_swap_vector(buffer, mysize, 4); + byte_swap_vector(buffer, mysize, sizeof(PyArray_UCS4)); } } - else buffer = ip; + else { + buffer = (PyArray_UCS4 *)ip; + } + while(mysize > 0 && buffer[--mysize] == 0); + #ifdef Py_UNICODE_WIDE - obj = PyUnicode_FromUnicode((const Py_UNICODE *)buffer, mysize); + obj = (PyUnicodeObject *)PyUnicode_FromUnicode(buffer, mysize); #else /* create new empty unicode object of length mysize*2 */ - obj = MyPyUnicode_New(mysize*2); - if (obj == NULL) {if (alloc) _pya_free(buffer); return obj;} - mysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, - (PyArray_UCS4 *)buffer, mysize); + obj = (PyUnicodeObject *)MyPyUnicode_New(mysize*2); + if (obj == NULL) { + goto fail; + } + mysize = PyUCS2Buffer_FromUCS4(obj->str, buffer, mysize); /* reset length of unicode object to ucs2size */ - if (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) { - if (alloc) _pya_free(buffer); + if (MyPyUnicode_Resize(obj, mysize) < 0) { Py_DECREF(obj); - return NULL; + goto fail; } #endif - if (alloc) _pya_free(buffer); - return obj; + if (alloc) { + free(buffer); + } + return (PyObject *)obj; + +fail: + if (alloc) { + free(buffer); + } + return NULL; } static int
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion