diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-10-04 16:08:45 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:18:19 -0300 |
commit | 7cc329679e14a00b699e944f733cda2ffbb3854f (patch) | |
tree | a2ffb5aec3194526587b0af3b689d5edc6db5272 /libshiboken | |
parent | 301f46c17c26aab4698d5dce76949fec9c31e746 (diff) |
Updated char conversion for works with python3 unicodes.
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/conversions.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h index 2749c2999..ee4666846 100644 --- a/libshiboken/conversions.h +++ b/libshiboken/conversions.h @@ -345,9 +345,10 @@ struct Converter_PyULongInt : Converter_PyInt<T> static inline PyObject* toPython(const T& cppobj) { return PyLong_FromUnsignedLong(cppobj); } }; +#define SbkChar_Check(X) \ + SbkNumber_Check(X) || \ + Shiboken::String::checkChar(X) -/// Check if we can treat the pyobj as a char, i.e. it's a number or a string with just one character. -#define SbkChar_Check(pyobj) (SbkNumber_Check(pyobj) || (PyBytes_Check(pyobj) && PyBytes_GET_SIZE(pyobj) == 1)) /// Specialization to convert char and unsigned char, it accepts Python numbers and strings with just one character. template <typename CharType> @@ -362,11 +363,15 @@ struct CharConverter if (PyBytes_Check(pyobj)) { assert(PyBytes_GET_SIZE(pyobj) == 1); // This check is made on SbkChar_Check return PyBytes_AS_STRING(pyobj)[0]; - } else { + } else if (PyLong_Check(pyobj)) { PY_LONG_LONG result = PyLong_AsLongLong(pyobj); if (OverFlowChecker<CharType>::check(result)) PyErr_SetObject(PyExc_OverflowError, 0); return result; + } else if (Shiboken::String::check(pyobj)) { + return Shiboken::String::toCString(pyobj)[0]; + } else { + return 0; } } }; @@ -377,7 +382,7 @@ template <> struct Converter<char> : CharConverter<char> { // Should we really return a string? using CharConverter<char>::toPython; static inline PyObject* toPython(const char& cppObj) { - return PyBytes_FromFormat("%c", cppObj); + return Shiboken::String::fromFormat("%c", cppObj); } }; template <> struct Converter<signed char> : CharConverter<signed char> {}; |