diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-02-09 00:57:29 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-02-09 00:57:29 +0000 |
commit | 9a4d9271638c5a1e28dc21a2d92d8d5d16d2fbd5 (patch) | |
tree | 732633ef63bbedec4d7bf2198b1b49663da1ded4 /numpy/core/src/arrayobject.c | |
parent | 34b811398d0a7ef3583a0539b1b61b343e55d237 (diff) | |
download | numpy-9a4d9271638c5a1e28dc21a2d92d8d5d16d2fbd5.tar.gz |
Fixing new-unicode branch.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 2444551c7..22f745ebf 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -408,6 +408,12 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems, byte_swap_vector(d1, numitems, itemsize); } + +#ifndef Py_UNICODE_WIDE +#include "ucsnarrow.c" +#endif + + static PyArray_Descr **userdescrs=NULL; #define error_converting(x) (((x) == -1) && PyErr_Occurred()) @@ -861,7 +867,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) } else if (type_num == PyArray_UNICODE) { PyUnicodeObject *uni = (PyUnicodeObject*)obj; - int length = itemsize / sizeof(Py_UNICODE); + int length = itemsize / 4; /* Need an extra slot and need to use Python memory manager */ uni->str = NULL; @@ -876,6 +882,12 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) uni->length = length; uni->hash = -1; uni->defenc = NULL; +#ifndef Py_UNICODE_WIDE + /* Allocate enough for 2-characters per itemsize + get the actual number of characters converted + and reallocate when done. + */ +#endif } else { PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj; @@ -5007,7 +5019,7 @@ discover_itemsize(PyObject *s, int nd, int *itemsize) if ((nd == 0) || PyString_Check(s) || \ PyUnicode_Check(s) || PyBuffer_Check(s)) { if PyUnicode_Check(s) - *itemsize = MAX(*itemsize, sizeof(Py_UNICODE)*n); + *itemsize = MAX(*itemsize, 4*n); else *itemsize = MAX(*itemsize, n); return 0; @@ -5289,7 +5301,7 @@ Array_FromScalar(PyObject *op, PyArray_Descr *typecode) if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) { itemsize = PyObject_Length(op); - if (type == PyArray_UNICODE) itemsize *= sizeof(Py_UNICODE); + if (type == PyArray_UNICODE) itemsize *= 4; } ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode, @@ -5357,7 +5369,7 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) { if (discover_itemsize(s, nd, &itemsize) == -1) goto fail; - if (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE); + if (type == PyArray_UNICODE) itemsize*=4; } if (itemsize != typecode->elsize) { @@ -5529,10 +5541,10 @@ PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran) if (at == NULL) return NULL; if (mpd->type_num == PyArray_STRING && \ at->type_num == PyArray_UNICODE) - at->elsize = mpd->elsize*sizeof(Py_UNICODE); + at->elsize = mpd->elsize*4; if (mpd->type_num == PyArray_UNICODE && at->type_num == PyArray_STRING) - at->elsize = mpd->elsize/sizeof(Py_UNICODE); + at->elsize = mpd->elsize/4; if (at->type_num == PyArray_VOID) at->elsize = mpd->elsize; } @@ -5836,15 +5848,7 @@ _array_typedescr_fromstr(char *str) break; case PyArray_UNICODELTR: type_num = PyArray_UNICODE; - size *= sizeof(Py_UNICODE); - break; - case PyArray_UCS2LTR: - if (sizeof(Py_UNICODE) != 2) _MY_FAIL - type_num = PyArray_UNICODE; - break; - case PyArray_UCS4LTR: - if (sizeof(Py_UNICODE) != 4) _MY_FAIL - type_num = PyArray_UNICODE; + size *= 4; break; case 'V': type_num = PyArray_VOID; @@ -6412,7 +6416,7 @@ PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to) ret = (from->elsize <= to->elsize); } else if (totype == PyArray_UNICODE) { - ret = (from->elsize * sizeof(Py_UNICODE)\ + ret = (from->elsize * 4 \ <= to->elsize); } } |