Mercurial > pytave
changeset 47:c83754e57d26 pytave-fixint
Fix compilation on 32-bit x86.
author | David Grundberg <individ@acc.umu.se> |
---|---|
date | Wed, 03 Jun 2009 15:28:22 +0200 |
parents | 095e26d93935 |
children | 22e74c46bea2 a1c05dd1d173 |
files | octave_to_python.cc python_to_octave.cc |
diffstat | 2 files changed, 38 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/octave_to_python.cc Tue May 26 11:41:26 2009 +0200 +++ b/octave_to_python.cc Wed Jun 03 15:28:22 2009 +0200 @@ -117,13 +117,14 @@ template <class CLASS, size_t bytes> inline static PyArrayObject *create_uint_array(CLASS value) { if (bytes == sizeof(int)) { - boost::integral_constant<bool, bytes==sizeof(int)> inst; + boost::integral_constant<bool, bytes == sizeof(int)> inst; return create_array<unsigned int, CLASS>(value, PyArray_UINT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant<bool, bytes==sizeof(char)> inst; + boost::integral_constant<bool, bytes == sizeof(char)> inst; return create_array<unsigned char, CLASS>(value, PyArray_UBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant<bool, bytes==sizeof(short)> inst; + boost::integral_constant<bool, + bytes == sizeof(short) && bytes != sizeof(int)> inst; return create_array<unsigned short, CLASS>(value, PyArray_USHORT, inst); } else { ostringstream os; @@ -135,17 +136,21 @@ template <class CLASS, size_t bytes> inline static PyArrayObject *create_sint_array(CLASS value) { - if (bytes == sizeof(long)) { - boost::integral_constant<bool, bytes==sizeof(long)> inst; + if (bytes == sizeof(int)) { + // We test int first since we prefer int to other datatypes of the + // same size. + boost::integral_constant<bool, bytes == sizeof(int)> inst; + return create_array<signed int, CLASS>(value, PyArray_INT, inst); + } else if (bytes == sizeof(long)) { + boost::integral_constant<bool, + bytes==sizeof(long) && bytes != sizeof(int)> inst; return create_array<long, CLASS>(value, PyArray_LONG, inst); - } else if (bytes == sizeof(int)) { - boost::integral_constant<bool, bytes==sizeof(int)> inst; - return create_array<signed int, CLASS>(value, PyArray_INT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant<bool, bytes==sizeof(char)> inst; + boost::integral_constant<bool, bytes == sizeof(char)> inst; return create_array<signed char, CLASS>(value, PyArray_SBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant<bool, bytes==sizeof(short)> inst; + boost::integral_constant<bool, + bytes==sizeof(short) && bytes != sizeof(int)> inst; return create_array<signed short, CLASS>(value, PyArray_SHORT, inst); } else { ostringstream os; @@ -220,7 +225,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,
--- a/python_to_octave.cc Tue May 26 11:41:26 2009 +0200 +++ b/python_to_octave.cc Wed Jun 03 15:28:22 2009 +0200 @@ -108,7 +108,28 @@ (matrix, pyarr); \ break; \ - switch (pyarr->descr->type_num) { + // Prefer int to other types of the same size. + // E.g. on 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)