diff options
author | Andreas Becker <atayoohoo@googlemail.com> | 2011-05-07 20:35:03 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2011-05-07 20:35:03 +0100 |
commit | a09ce46818fd4d5e08b3af9a478501cd8ef5b4fe (patch) | |
tree | 187c9164d436201442794dee227627e2b9173124 /pyuno/source/module/pyuno_runtime.cxx | |
parent | 7cf799064f5d64bca62626dc73723c2c5e95ca00 (diff) |
Port PyUno to support Python 3
Diffstat (limited to 'pyuno/source/module/pyuno_runtime.cxx')
-rw-r--r-- | pyuno/source/module/pyuno_runtime.cxx | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index ed34ddf3b6cf..61d05d8321f5 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -72,8 +72,7 @@ namespace pyuno static PyTypeObject RuntimeImpl_Type = { - PyObject_HEAD_INIT (&PyType_Type) - 0, + PyVarObject_HEAD_INIT (&PyType_Type, 0) const_cast< char * >("pyuno_runtime"), sizeof (RuntimeImpl), 0, @@ -81,7 +80,7 @@ static PyTypeObject RuntimeImpl_Type = (printfunc) 0, (getattrfunc) 0, (setattrfunc) 0, - (cmpfunc) 0, + 0, (reprfunc) 0, 0, 0, @@ -445,7 +444,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const { sal_Int32 l = 0; a >>= l; - return PyRef( PyInt_FromLong (l), SAL_NO_ACQUIRE ); + return PyRef( PyLong_FromLong (l), SAL_NO_ACQUIRE ); } case typelib_TypeClass_UNSIGNED_LONG: { @@ -666,6 +665,8 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con { } + // In Python 3, there is no PyInt type. +#if PY_MAJOR_VERSION < 3 else if (PyInt_Check (o)) { if( o == Py_True ) @@ -680,7 +681,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con } else { - sal_Int32 l = (sal_Int32) PyInt_AsLong( o ); + sal_Int32 l = (sal_Int32) PyLong_AsLong( o ); if( l < 128 && l >= -128 ) { sal_Int8 b = (sal_Int8 ) l; @@ -697,8 +698,24 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con } } } +#endif /* PY_MAJOR_VERSION < 3 */ else if (PyLong_Check (o)) { +#if PY_MAJOR_VERSION >= 3 + // Convert the Python 3 booleans that are actually of type PyLong. + if(o == Py_True) + { + sal_Bool b = sal_True; + a = Any(&b, getBooleanCppuType()); + } + else if(o == Py_False) + { + sal_Bool b = sal_False; + a = Any(&b, getBooleanCppuType()); + } + else + { +#endif /* PY_MAJOR_VERSION >= 3 */ sal_Int64 l = (sal_Int64)PyLong_AsLong (o); if( l < 128 && l >= -128 ) { @@ -720,16 +737,19 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con { a <<= l; } +#if PY_MAJOR_VERSION >= 3 + } +#endif } else if (PyFloat_Check (o)) { double d = PyFloat_AsDouble (o); a <<= d; } - else if (PyString_Check (o)) - a <<= pyString2ustring(o); - else if( PyUnicode_Check( o ) ) - a <<= pyString2ustring(o); + else if (PyString_Check(o) || PyUnicode_Check(o)) + { + a <<= pyString2ustring(o); + } else if (PyTuple_Check (o)) { Sequence<Any> s (PyTuple_Size (o)); |