@@ -296,7 +296,7 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo
296
296
if (typeId == cursorId) {
297
297
static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper (" Qt::CursorShape" , NULL );
298
298
if ((PyObject*)obj->ob_type == qtCursorShapeEnum) {
299
- Qt::CursorShape val = (Qt::CursorShape)PyInt_AS_LONG (obj);
299
+ Qt::CursorShape val = (Qt::CursorShape)PyInt_AsLong (obj);
300
300
if (!ptr) {
301
301
PythonQtValueStorage_ADD_VALUE (global_variantStorage, QVariant, QCursor (), ptr);
302
302
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -308,7 +308,7 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo
308
308
// brushes can be created from QColor and from Qt::GlobalColor (and from brushes, but that's the default)
309
309
static PyObject* qtColorClass = PythonQt::priv ()->getClassInfo (" QColor" )->pythonQtClassWrapper ();
310
310
if ((PyObject*)obj->ob_type == qtGlobalColorEnum) {
311
- Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG (obj);
311
+ Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AsLong (obj);
312
312
if (!ptr) {
313
313
PythonQtValueStorage_ADD_VALUE (global_variantStorage, QVariant, QPen (), ptr);
314
314
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -327,7 +327,7 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo
327
327
// brushes can be created from QColor and from Qt::GlobalColor (and from brushes, but that's the default)
328
328
static PyObject* qtColorClass = PythonQt::priv ()->getClassInfo (" QColor" )->pythonQtClassWrapper ();
329
329
if ((PyObject*)obj->ob_type == qtGlobalColorEnum) {
330
- Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG (obj);
330
+ Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AsLong (obj);
331
331
if (!ptr) {
332
332
PythonQtValueStorage_ADD_VALUE (global_variantStorage, QVariant, QBrush (), ptr);
333
333
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -345,7 +345,7 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo
345
345
} else if (typeId == colorId) {
346
346
// colors can be created from Qt::GlobalColor (and from colors, but that's the default)
347
347
if ((PyObject*)obj->ob_type == qtGlobalColorEnum) {
348
- Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG (obj);
348
+ Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AsLong (obj);
349
349
if (!ptr) {
350
350
PythonQtValueStorage_ADD_VALUE (global_variantStorage, QVariant, QColor (), ptr);
351
351
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -707,7 +707,11 @@ QString PythonQtConv::PyObjGetRepresentation(PyObject* val)
707
707
QString r;
708
708
PyObject* str = PyObject_Repr (val);
709
709
if (str) {
710
- r = QString (PyString_AS_STRING (str));
710
+ #ifdef PY3K
711
+ r = PyObjGetString (str);
712
+ #else
713
+ r = QString (PyString_AS_STRING (str));
714
+ #endif
711
715
Py_DECREF (str);
712
716
}
713
717
return r;
@@ -729,10 +733,13 @@ QString PythonQtConv::PyObjGetString(PyObject* val, bool strict, bool& ok) {
729
733
}
730
734
#endif
731
735
} else if (!strict) {
732
- // EXTRA: could also use _Unicode, but why should we?
733
736
PyObject* str = PyObject_Str (val);
734
737
if (str) {
738
+ #ifdef PY3K
739
+ r = QString::fromUtf8 (PyUnicode_AsUTF8 (val));
740
+ #else
735
741
r = QString (PyString_AS_STRING (str));
742
+ #endif
736
743
Py_DECREF (str);
737
744
} else {
738
745
ok = false ;
@@ -747,9 +754,8 @@ QByteArray PythonQtConv::PyObjGetBytes(PyObject* val, bool /*strict*/, bool& ok)
747
754
// TODO: support buffer objects in general
748
755
QByteArray r;
749
756
ok = true ;
750
- if (val->ob_type == &PyBytes_Type) {
751
- long size = PyBytes_GET_SIZE (val);
752
- r = QByteArray (PyBytes_AS_STRING (val), size);
757
+ if (PyBytes_Check (val)) {
758
+ r = QByteArray (PyBytes_AS_STRING (val), PyBytes_GET_SIZE (val));
753
759
} else {
754
760
ok = false ;
755
761
}
@@ -810,9 +816,12 @@ int PythonQtConv::PyObjGetInt(PyObject* val, bool strict, bool &ok) {
810
816
qint64 PythonQtConv::PyObjGetLongLong (PyObject* val, bool strict, bool &ok) {
811
817
qint64 d = 0 ;
812
818
ok = true ;
819
+ #ifndef PY3K
813
820
if (val->ob_type == &PyInt_Type) {
814
821
d = PyInt_AS_LONG (val);
815
- } else if (val->ob_type == &PyLong_Type) {
822
+ } else
823
+ #endif
824
+ if (val->ob_type == &PyLong_Type) {
816
825
d = PyLong_AsLongLong (val);
817
826
} else if (!strict) {
818
827
if (PyObject_TypeCheck (val, &PyInt_Type)) {
@@ -842,9 +851,12 @@ qint64 PythonQtConv::PyObjGetLongLong(PyObject* val, bool strict, bool &ok) {
842
851
quint64 PythonQtConv::PyObjGetULongLong (PyObject* val, bool strict, bool &ok) {
843
852
quint64 d = 0 ;
844
853
ok = true ;
845
- if (PyObject_TypeCheck (val, &PyInt_Type)) {
854
+ #ifndef PY3K
855
+ if (Py_TYPE (val) == &PyInt_Type) {
846
856
d = PyInt_AS_LONG (val);
847
- } else if (val->ob_type == &PyLong_Type) {
857
+ } else
858
+ #endif
859
+ if (Py_TYPE (val) == &PyLong_Type) {
848
860
d = PyLong_AsLongLong (val);
849
861
} else if (!strict) {
850
862
if (PyObject_TypeCheck (val, &PyInt_Type)) {
@@ -877,9 +889,12 @@ double PythonQtConv::PyObjGetDouble(PyObject* val, bool strict, bool &ok) {
877
889
if (val->ob_type == &PyFloat_Type) {
878
890
d = PyFloat_AS_DOUBLE (val);
879
891
} else if (!strict) {
892
+ #ifndef PY3K
880
893
if (PyObject_TypeCheck (val, &PyInt_Type)) {
881
894
d = PyInt_AS_LONG (val);
882
- } else if (val->ob_type == &PyLong_Type) {
895
+ } else
896
+ #endif
897
+ if (PyLong_Check (val)) {
883
898
d = PyLong_AsLong (val);
884
899
} else if (val == Py_False) {
885
900
d = 0 ;
@@ -936,11 +951,13 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
936
951
type = QVariant::String;
937
952
} else if (val == Py_False || val == Py_True) {
938
953
type = QVariant::Bool;
954
+ #ifndef PY3K
939
955
} else if (PyObject_TypeCheck (val, &PyInt_Type)) {
940
956
type = QVariant::Int;
941
- } else if (val->ob_type ==&PyLong_Type) {
957
+ #endif
958
+ } else if (PyLong_Check (val)) {
942
959
type = QVariant::LongLong;
943
- } else if (val-> ob_type ==&PyFloat_Type ) {
960
+ } else if (PyFloat_Check ( val) ) {
944
961
type = QVariant::Double;
945
962
} else if (PyObject_TypeCheck (val, &PythonQtInstanceWrapper_Type)) {
946
963
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val;
@@ -961,9 +978,9 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
961
978
v = qVariantFromValue (myObject);
962
979
}
963
980
return v;
964
- } else if (val-> ob_type ==&PyDict_Type ) {
981
+ } else if (PyDict_Check ( val) ) {
965
982
type = QVariant::Map;
966
- } else if (val-> ob_type ==&PyList_Type || val-> ob_type ==&PyTuple_Type || PySequence_Check (val)) {
983
+ } else if (PyList_Check ( val) || PyTuple_Check ( val) || PySequence_Check (val)) {
967
984
type = QVariant::List;
968
985
} else if (val == Py_None) {
969
986
// none is invalid
0 commit comments