[Numpy-svn] r5617 - in branches/1.1.x/numpy/core: include/numpy src

numpy-svn@scip... numpy-svn@scip...
Wed Aug 6 15:55:10 CDT 2008


Author: oliphant
Date: 2008-08-06 15:55:08 -0500 (Wed, 06 Aug 2008)
New Revision: 5617

Modified:
   branches/1.1.x/numpy/core/include/numpy/ndarrayobject.h
   branches/1.1.x/numpy/core/src/arraymethods.c
   branches/1.1.x/numpy/core/src/arrayobject.c
   branches/1.1.x/numpy/core/src/arraytypes.inc.src
Log:
Backport fields with titles iteration fix from ticket #877 which is in r5616 back to NumPy 1.1.1 branch.

Modified: branches/1.1.x/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- branches/1.1.x/numpy/core/include/numpy/ndarrayobject.h	2008-08-06 17:34:56 UTC (rev 5616)
+++ branches/1.1.x/numpy/core/include/numpy/ndarrayobject.h	2008-08-06 20:55:08 UTC (rev 5617)
@@ -2003,8 +2003,28 @@
 
 #include "old_defines.h"
 
+/* 
+   Check to see if this key in the dictionary is the "title" 
+   entry of the tuple (i.e. a duplicate dictionary entry in the fields
+   dict. 
+*/
+
+#define NPY_TITLE_KEY(key, value) ((PyTuple_GET_SIZE((value))==3) && \
+				   (PyTuple_GET_ITEM((value), 2) == (key)))
+
+
+/* Define python version independent deprecation macro */
+
+#if PY_VERSION_HEX >= 0x02050000
+#define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1)
+#else
+#define DEPRECATE(msg) PyErr_Warn(PyExc_DeprecationWarning,msg)
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif
 
+
 #endif /* NPY_NDARRAYOBJECT_H */

Modified: branches/1.1.x/numpy/core/src/arraymethods.c
===================================================================
--- branches/1.1.x/numpy/core/src/arraymethods.c	2008-08-06 17:34:56 UTC (rev 5616)
+++ branches/1.1.x/numpy/core/src/arraymethods.c	2008-08-06 20:55:08 UTC (rev 5617)
@@ -1006,6 +1006,7 @@
         int offset;
         Py_ssize_t pos=0;
         while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) return;
             _deepcopy_call(iptr + offset, optr + offset, new,

Modified: branches/1.1.x/numpy/core/src/arrayobject.c
===================================================================
--- branches/1.1.x/numpy/core/src/arrayobject.c	2008-08-06 17:34:56 UTC (rev 5616)
+++ branches/1.1.x/numpy/core/src/arrayobject.c	2008-08-06 20:55:08 UTC (rev 5617)
@@ -15,6 +15,7 @@
 
   maintainer email:  oliphant.travis@ieee.org
 
+
   Numarray design (which provided guidance) by
   Space Science Telescope Institute
   (J. Todd Miller, Perry Greenfield, Rick White)
@@ -170,6 +171,7 @@
         Py_ssize_t pos=0;
 
         while (PyDict_Next(descr->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) {
                 return;
@@ -201,8 +203,10 @@
             PyArray_Descr *new;
             int offset;
             Py_ssize_t pos=0;
+
             while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-                if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+		if NPY_TITLE_KEY(key, value) continue;
+		if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                       &title)) {
                     return;
                 }
@@ -4811,6 +4815,7 @@
 
         op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
         while (PyDict_Next(self->descr->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             a = PyArray_EnsureAnyArray(array_subscript(self, key));
             if (a==NULL) {
                 Py_XDECREF(res);
@@ -5703,6 +5708,7 @@
         int offset;
         Py_ssize_t pos=0;
         while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) return;
             _putzero(optr + offset, zero, new);
@@ -5873,6 +5879,7 @@
         int offset;
         Py_ssize_t pos=0;
         while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) return;
             _fillobject(optr + offset, obj, new);
@@ -11290,6 +11297,7 @@
         int offset;
         Py_ssize_t pos=0;
         while(PyDict_Next(self->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) return -1;
             if (!_arraydescr_isnative(new)) return 0;
@@ -11561,6 +11569,7 @@
         int offset;
         Py_ssize_t pos=0;
         while (PyDict_Next(self->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                                   &title)) {
                 PyErr_Clear();
@@ -11754,6 +11763,7 @@
         /* make new dictionary with replaced */
         /* PyArray_Descr Objects */
         while(PyDict_Next(self->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyString_Check(key) ||          \
                 !PyTuple_Check(value) ||                    \
                 ((len=PyTuple_GET_SIZE(value)) < 2))

Modified: branches/1.1.x/numpy/core/src/arraytypes.inc.src
===================================================================
--- branches/1.1.x/numpy/core/src/arraytypes.inc.src	2008-08-06 17:34:56 UTC (rev 5616)
+++ branches/1.1.x/numpy/core/src/arraytypes.inc.src	2008-08-06 20:55:08 UTC (rev 5617)
@@ -1307,6 +1307,7 @@
         Py_ssize_t pos=0;
         descr = arr->descr;
         while (PyDict_Next(descr->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                         &title)) {
                 arr->descr=descr;return;
@@ -1358,6 +1359,7 @@
         Py_ssize_t pos=0;
         descr = arr->descr;  /* Save it */
         while (PyDict_Next(descr->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                         &title)) {
                 arr->descr=descr;return;
@@ -1597,6 +1599,7 @@
         descr = ap->descr;
         savedflags = ap->flags;
         while (PyDict_Next(descr->fields, &pos, &key, &value)) {
+	    if NPY_TITLE_KEY(key, value) continue;
             if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
                         &title)) {PyErr_Clear(); continue;}
             ap->descr = new;



More information about the Numpy-svn mailing list