summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-02-09 05:26:03 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-02-09 05:26:03 +0000
commitfc7ac38dec262117bbc30698e0696e9911369207 (patch)
treedcbaf3acc96cb207647f2f5b9dcd2b378bbe5deb /numpy/core/src
parentf1bffaafc8e94cb5e1e94bd0527410108903669c (diff)
downloadnumpy-fc7ac38dec262117bbc30698e0696e9911369207.tar.gz
Fixed reference count problems.
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/arrayobject.c9
-rw-r--r--numpy/core/src/arraytypes.inc.src2
-rw-r--r--numpy/core/src/multiarraymodule.c5
-rw-r--r--numpy/core/src/ucsnarrow.c6
4 files changed, 13 insertions, 9 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 48ce04c52..76be69702 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -1313,7 +1313,7 @@ array_dealloc(PyArrayObject *self) {
PyDimMem_FREE(self->dimensions);
- Py_DECREF(self->descr);
+ Py_XDECREF(self->descr);
self->ob_type->tp_free((PyObject *)self);
}
@@ -4507,7 +4507,9 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
dimensions, strides and descr from it */
PyArrayObject *temp;
- temp = (PyArrayObject *)\
+ /* We would decref newtype here --- temp will
+ steal a reference to it */
+ temp = (PyArrayObject *) \
PyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,
self->dimensions, self->strides,
self->data, self->flags, NULL);
@@ -4515,9 +4517,8 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
self->dimensions = temp->dimensions;
self->nd = temp->nd;
self->strides = temp->strides;
- Py_DECREF(newtype);
newtype = temp->descr;
- /* Fool deallocator */
+ /* Fool deallocator not to delete these*/
temp->nd = 0;
temp->dimensions = NULL;
temp->descr = NULL;
diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src
index e1b17a3a6..b2b005fc4 100644
--- a/numpy/core/src/arraytypes.inc.src
+++ b/numpy/core/src/arraytypes.inc.src
@@ -258,7 +258,7 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap)
Py_DECREF(temp);
return -1;
}
- datalen = PyUnicode_GET_DATA_SIZE(op);
+ datalen = PyUnicode_GET_DATA_SIZE(temp);
#ifdef Py_UNICODE_WIDE
memcpy(ov, ptr, MIN(ap->descr->elsize, datalen));
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index f65c74e88..6fb83c866 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -3363,7 +3363,10 @@ _convert_from_tuple(PyObject *obj)
goto fail;
}
PyArray_DESCR_REPLACE(type);
- type->elsize = itemsize;
+ if (type->type_num == PyArray_UNICODE)
+ type->elsize = itemsize << 2;
+ else
+ type->elsize = itemsize;
}
else {
/* interpret next item as shape (if it's a tuple)
diff --git a/numpy/core/src/ucsnarrow.c b/numpy/core/src/ucsnarrow.c
index 6480303a9..a105ebe27 100644
--- a/numpy/core/src/ucsnarrow.c
+++ b/numpy/core/src/ucsnarrow.c
@@ -26,7 +26,7 @@ PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)
*ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);
}
else {
- *ucs2++ = (Py_UNICODE) (chr);
+ *ucs2++ = (Py_UNICODE) chr;
}
}
return ucs4length + surrpairs;
@@ -50,9 +50,9 @@ PyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs2len, int ucs4l
register Py_UNICODE ch;
register int numchars=0;
- for (i=0; (i < ucs2len-1) && (numchars < ucs4len); i++) {
+ for (i=0; (i < ucs2len) && (numchars < ucs4len); i++) {
ch = *ucs2++;
- if (ch >= 0xd800 || ch <= 0xdfff) {
+ if (ch >= 0xd800 && ch <= 0xdfff) {
/* surrogate pair */
chr = ((PyArray_UCS4)(ch-0xd800)) << 10;
chr += *ucs2++ + 0x2400; /* -0xdc00 + 0x10000 */