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

numpy-svn@scip... numpy-svn@scip...
Sat Jul 12 00:14:43 CDT 2008


Author: charris
Date: 2008-07-12 00:14:39 -0500 (Sat, 12 Jul 2008)
New Revision: 5392

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
Log:
Coding style cleanups.
Check return of PyArray_DescrNew for NULL (possible memory error).


Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2008-07-12 05:11:32 UTC (rev 5391)
+++ trunk/numpy/core/src/arraytypes.inc.src	2008-07-12 05:14:39 UTC (rev 5392)
@@ -2475,42 +2475,51 @@
 static PyArray_Descr *
 PyArray_DescrFromType(int type)
 {
-    PyArray_Descr *ret=NULL;
+    PyArray_Descr *ret = NULL;
 
     if (type < PyArray_NTYPES) {
         ret = _builtin_descrs[type];
     }
     else if (type == PyArray_NOTYPE) {
-        /* This needs to not raise an error so
-           that PyArray_DescrFromType(PyArray_NOTYPE)
-           works for backwards-compatible C-API
+        /*
+         * This needs to not raise an error so
+         * that PyArray_DescrFromType(PyArray_NOTYPE)
+         * works for backwards-compatible C-API
          */
         return NULL;
     }
-    else if ((type == PyArray_CHAR) || \
-            (type == PyArray_CHARLTR)) {
+    else if ((type == PyArray_CHAR) || (type == PyArray_CHARLTR)) {
         ret = PyArray_DescrNew(_builtin_descrs[PyArray_STRING]);
+
+        if (ret == NULL) {
+            return NULL;
+        }
         ret->elsize = 1;
         ret->type = PyArray_CHARLTR;
         return ret;
     }
-    else if PyTypeNum_ISUSERDEF(type) {
-        ret = userdescrs[type-PyArray_USERDEF];
+    else if (PyTypeNum_ISUSERDEF(type)) {
+        ret = userdescrs[type - PyArray_USERDEF];
     }
     else {
-        int num=PyArray_NTYPES;
-        if (type < _MAX_LETTER)
+        int num = PyArray_NTYPES;
+        if (type < _MAX_LETTER) {
             num = (int) _letter_to_num[type];
-        if (num >= PyArray_NTYPES)
+        }
+        if (num >= PyArray_NTYPES) {
             ret = NULL;
-        else
+        }
+        else {
             ret = _builtin_descrs[num];
+        }
     }
-    if (ret==NULL) {
+    if (ret == NULL) {
         PyErr_SetString(PyExc_ValueError,
                 "Invalid data-type for array");
     }
-    else Py_INCREF(ret);
+    else {
+        Py_INCREF(ret);
+    }
     return ret;
 }
 



More information about the Numpy-svn mailing list