pyside / PySide

ATTENTION: This project is deprecated, please refer to PySide2
https://wiki.qt.io/PySide2
GNU Lesser General Public License v2.1
291 stars 66 forks source link

64-bit `long` raises incorrect OverflowError (possibly related to QVariant conversion) #126

Open codewarrior0 opened 9 years ago

codewarrior0 commented 9 years ago

An OverflowError is raised when passing a 64-bit long value through the data method of a QSortFilterProxyModel. This only occurs on Linux. No error occurs and the correct value is returned on Windows. In both cases, 64-bit builds of Python 2.7.8 and PySide 1.2.2 are used.

First, here is the minimal example needed to reproduce this error:

from PySide import QtGui, QtCore
from PySide.QtCore import Qt

class TestModel(QtCore.QAbstractListModel):
    def rowCount(self, parent=None):
        return 1

    def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return (1 << 45)

def main():
    model = TestModel()
    proxyModel = QtGui.QSortFilterProxyModel()
    proxyModel.setSourceModel(model)
    val = proxyModel.data(proxyModel.index(0, 0, QtCore.QModelIndex()))
    assert (1<<45) == val

if __name__ == '__main__':
    main()

And the error that results:

    val = proxyModel.data(proxyModel.index(0, 0, QtCore.QModelIndex()))
OverflowError

This error is surprising, and is not justified by any of the other reasons for raising an OverflowError (e.g. passing a 64-bit value into a Qt function whose argument type is int or short). This is because QAbstractItemModel and subclasses have a QVariant return type for data().

I have not tested this with debug builds of PySide, so this is only my suspicion: The CppWrapper for TestModel will convert the Py_Long returned by the Python data method into a QVariant, and this is where the OverflowError occurs.