[Numpy-svn] r2900 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Jul 26 12:55:11 EDT 2006


Author: oliphant
Date: 2006-07-26 11:55:07 -0500 (Wed, 26 Jul 2006)
New Revision: 2900

Modified:
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Merge non-white space changes from ver1.0 branch.  Change to Py_ssize_t and better error on align=True with array_descr conversion.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-07-26 16:38:32 UTC (rev 2899)
+++ trunk/numpy/core/src/arrayobject.c	2006-07-26 16:55:07 UTC (rev 2900)
@@ -4702,7 +4702,7 @@
 {
         PyObject *base=ap->base;
         void *dummy;
-        int n;
+        Py_ssize_t n;
 
         /* If we own our own data, then no-problem */
         if ((base == NULL) || (ap->flags & OWNDATA)) return TRUE;
@@ -5565,8 +5565,8 @@
                         dims.ptr[0] = (buffer.len-(intp)offset) / itemsize;
                 }
                 else if ((strides.ptr == NULL) && \
-                         buffer.len < itemsize*                         \
-                         PyArray_MultiplyList(dims.ptr, dims.len)) {
+                         (buffer.len < ((intp)itemsize)*                \
+                          PyArray_MultiplyList(dims.ptr, dims.len))) {
                         PyErr_SetString(PyExc_TypeError,
                                         "buffer is too small for "      \
                                         "requested array");
@@ -5684,7 +5684,7 @@
         PyArrayObject *new;
         intp numbytes=0;
         intp offset=0;
-        int buf_len;
+        Py_ssize_t buf_len;
         char *buf;
 
         if (!PyArray_IntpConverter(obj, &newstrides) || \
@@ -5874,7 +5874,7 @@
 array_data_set(PyArrayObject *self, PyObject *op)
 {
         void *buf;
-        int buf_len;
+        Py_ssize_t buf_len;
         int writeable=1;
 
         if (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {
@@ -7832,7 +7832,7 @@
         PyArrayObject *ret;
         PyArray_Descr *type=NULL;
         char *data;
-        int buffer_len;
+        Py_ssize_t buffer_len;
         int res, i, n;
         intp dims[MAX_DIMS], strides[MAX_DIMS];
         int dataflags = BEHAVED;
@@ -7867,7 +7867,7 @@
                 }
                 attr = PyDict_GetItemString(inter, "offset");
                 if (attr) {
-                        long num = PyInt_AsLong(attr);
+                        longlong num = PyLong_AsLongLong(attr);
                         if (error_converting(num)) {
                                 PyErr_SetString(PyExc_TypeError,
                                                 "offset "\
@@ -10445,13 +10445,30 @@
                         conv =  _convert_from_dict(odescr, 1);
                 else if PyList_Check(odescr) {
                         conv = _convert_from_list(odescr, 1, 0);
-                        if ((conv == NULL) && 
-                            (!PyErr_Occurred())) {
-                                PyErr_SetString(PyExc_ValueError,
-                                                "cannot specify align=1 "\
-                                                "with array_descriptor "\
-                                                "specification of the data-"\
-                                                "type.");
+                        if (conv == NULL) {
+                                /* There is an errror.  Possibly it's 
+                                   because we have an array_descriptor.
+                                   Try converting from an array_descriptor. 
+                                   If that fails then raise the old error. 
+                                */
+                                PyObject *type, *value, *traceback;
+                                PyArray_Descr *temp;
+                                PyErr_Fetch(&type, &value, &traceback);
+                                temp = _convert_from_array_descr(odescr);
+                                if (!PyErr_Occurred()) {
+                                        Py_DECREF(temp);
+                                        Py_XDECREF(type);
+                                        Py_XDECREF(value);
+                                        Py_XDECREF(traceback);
+                                        PyErr_SetString(PyExc_ValueError,
+                                                        "align cannot be True" \
+                                                        " with array_descriptor " \
+                                                        "specification.");
+                                }
+                                else {
+                                        PyErr_Restore(type, value, traceback);
+                                }
+                                return NULL;
                         }
                 }
                 else if PyString_Check(odescr)

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2006-07-26 16:38:32 UTC (rev 2899)
+++ trunk/numpy/core/src/arraytypes.inc.src	2006-07-26 16:55:07 UTC (rev 2900)
@@ -554,7 +554,7 @@
         /* Default is to use buffer interface to set item */
         {
                 const void *buffer;
-                int buflen;
+                Py_ssize_t buflen;
                 if (descr->hasobject) {
                         PyErr_SetString(PyExc_ValueError, 
                                         "tried to set void-array with object"
@@ -1370,7 +1370,6 @@
 /**end repeat**/
 
 
-
 #define WHITESPACE " \t\n\r\v\f"
 #define WHITELEN 6
 

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-07-26 16:38:32 UTC (rev 2899)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-07-26 16:55:07 UTC (rev 2900)
@@ -884,7 +884,8 @@
 
         if (PyArray_IsScalar(self, ComplexFloating)) {
                 typecode = _realdescr_fromcomplexscalar(self, &typenum);
-                ret = PyArray_Scalar(scalar_value(self, NULL), typecode, NULL);
+                ret = PyArray_Scalar(scalar_value(self, NULL), 
+                                     typecode, NULL);
                 Py_DECREF(typecode);
                 return ret;
         }
@@ -1226,7 +1227,7 @@
 {
         PyObject *ret=NULL, *obj=NULL, *mod=NULL;
         const char *buffer;
-        int buflen;
+        Py_ssize_t buflen;
 
         /* Return a tuple of (callable object, arguments) */
 




More information about the Numpy-svn mailing list