[Numpy-svn] r8070 - trunk/numpy/core/src/multiarray

numpy-svn@scip... numpy-svn@scip...
Fri Jan 15 22:33:05 CST 2010


Author: charris
Date: 2010-01-15 22:33:05 -0600 (Fri, 15 Jan 2010)
New Revision: 8070

Modified:
   trunk/numpy/core/src/multiarray/arraytypes.c.src
Log:
Fix bus error resulting from inlined gcc memcpy alignment assumptions.
Fixes ticket #1336.

Modified: trunk/numpy/core/src/multiarray/arraytypes.c.src
===================================================================
--- trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-01-16 03:32:55 UTC (rev 8069)
+++ trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-01-16 04:33:05 UTC (rev 8070)
@@ -2124,16 +2124,20 @@
 #type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, datetime, timedelta#
 */
 static Bool
-@fname@_nonzero (@type@ *ip, PyArrayObject *ap)
+@fname@_nonzero (char *ip, PyArrayObject *ap)
 {
-    @type@ t1;
-    if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
-        return (Bool) (*ip != 0);
+    if (ap == NULL || PyArray_ISBEHAVED_RO(ap)) {
+        @type@ *ptmp = (@type@ *)ip;
+        return (Bool) (*ptmp != 0);
+    }
     else {
-        /* don't worry about swap, since we are just testing
-           whether or not equal to 0 */
-        memcpy(&t1, ip, sizeof(@type@));
-        return (Bool) (t1 != 0);
+        /*
+         * don't worry about swap, since we are just testing
+         * whether or not equal to 0
+         */
+        @type@ tmp;
+        memcpy(&tmp, ip, sizeof(@type@));
+        return (Bool) (tmp != 0);
     }
 }
 /**end repeat**/
@@ -2143,16 +2147,20 @@
 #type=cfloat, cdouble, clongdouble#
 */
 static Bool
-@fname@_nonzero (@type@ *ip, PyArrayObject *ap)
+@fname@_nonzero (char *ip, PyArrayObject *ap)
 {
-    @type@ t1;
-    if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
-        return (Bool) ((ip->real != 0) || (ip->imag != 0));
+    if (ap == NULL || PyArray_ISBEHAVED_RO(ap)) {
+        @type@ *ptmp = (@type@ *)ip;
+        return (Bool) ((ptmp->real != 0) || (ptmp->imag != 0));
+    }
     else {
-        /* don't worry about swap, since we are just testing
-           whether or not equal to 0 */
-        memcpy(&t1, ip, sizeof(@type@));
-        return (Bool) ((t1.real != 0) || (t1.imag != 0));
+        /*
+         * don't worry about swap, since we are just testing
+         * whether or not equal to 0
+         */
+        @type@ tmp;
+        memcpy(&tmp, ip, sizeof(@type@));
+        return (Bool) ((tmp.real != 0) || (tmp.imag != 0));
     }
 }
 /**end repeat**/



More information about the Numpy-svn mailing list