# HG changeset patch # User David Grundberg # Date 1244036088 -7200 # Node ID 22e74c46bea2b7da1c1ddbf87dcbeca1b182014b # Parent 2a2f1e2f2be39365e97b057d177ad37d14cc1d4f# Parent c83754e57d2607837ca31b8dab0c06a74181b540 Fix compilation on 32-bit x86. diff -r 2a2f1e2f2be3 -r 22e74c46bea2 ChangeLog --- a/ChangeLog Thu May 28 11:20:17 2009 +0200 +++ b/ChangeLog Wed Jun 03 15:34:48 2009 +0200 @@ -1,3 +1,11 @@ +2009-06-03 David Grundberg + + * octave_to_python.cc (create_uint_array, create_sint_array): + Prefer int to other datatypes of identical size. + (is_1xn_or_0x0): Whitespace. + * python_to_octave.cc (copy_pyarrobj_to_octarray_dispatch): Prefer + int to other datatypes of identical size. + 2009-05-28 Jaroslav Hajek * configure.ac: Remove --enable-float-matrices option. diff -r 2a2f1e2f2be3 -r 22e74c46bea2 octave_to_python.cc --- a/octave_to_python.cc Thu May 28 11:20:17 2009 +0200 +++ b/octave_to_python.cc Wed Jun 03 15:34:48 2009 +0200 @@ -117,13 +117,14 @@ template inline static PyArrayObject *create_uint_array(CLASS value) { if (bytes == sizeof(int)) { - boost::integral_constant inst; + boost::integral_constant inst; return create_array(value, PyArray_UINT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant inst; + boost::integral_constant inst; return create_array(value, PyArray_UBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant inst; + boost::integral_constant inst; return create_array(value, PyArray_USHORT, inst); } else { ostringstream os; @@ -135,17 +136,21 @@ template inline static PyArrayObject *create_sint_array(CLASS value) { - if (bytes == sizeof(long)) { - boost::integral_constant inst; + if (bytes == sizeof(int)) { + // We test int first since we prefer int to other datatypes of the + // same size. + boost::integral_constant inst; + return create_array(value, PyArray_INT, inst); + } else if (bytes == sizeof(long)) { + boost::integral_constant inst; return create_array(value, PyArray_LONG, inst); - } else if (bytes == sizeof(int)) { - boost::integral_constant inst; - return create_array(value, PyArray_INT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant inst; + boost::integral_constant inst; return create_array(value, PyArray_SBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant inst; + boost::integral_constant inst; return create_array(value, PyArray_SHORT, inst); } else { ostringstream os; @@ -218,7 +223,7 @@ } static inline bool is_1xn_or_0x0(const dim_vector& dv) { - return (dv.length() == 2 && (dv(0) == 1 || (dv(0) == 0 && dv(1) == 0))); + return (dv.length() == 2 && (dv(0) == 1 || (dv(0) == 0 && dv(1) == 0))); } static void octcell_to_pyobject(boost::python::object &py_object, diff -r 2a2f1e2f2be3 -r 22e74c46bea2 python_to_octave.cc --- a/python_to_octave.cc Thu May 28 11:20:17 2009 +0200 +++ b/python_to_octave.cc Wed Jun 03 15:34:48 2009 +0200 @@ -106,7 +106,28 @@ (matrix, pyarr); \ break; \ - switch (pyarr->descr->type_num) { + // Prefer int to other types of the same size. + // E.g. on 32-bit x86 architectures: sizeof(long) == sizeof(int). + int type_num = pyarr->descr->type_num; + switch (type_num) { + case PyArray_LONG: + if (sizeof(long) == sizeof(int)) { + type_num = PyArray_INT; + } + break; + case PyArray_SHORT: + if (sizeof(short) == sizeof(int)) { + type_num = PyArray_INT; + } + break; + case PyArray_USHORT: + if (sizeof(unsigned short) == sizeof(unsigned int)) { + type_num = PyArray_UINT; + } + break; + } + + switch (type_num) { // ARRAYCASE(PyArray_CHAR, ) ARRAYCASE(PyArray_UBYTE, unsigned char) ARRAYCASE(PyArray_SBYTE, signed char)