From 43451e3bc17467593df64cb73ce8c0bf9e60045f Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Mon, 19 Mar 2018 10:30:29 +0100 Subject: Fix QSocketNotifier constructor The first argument was modified to be a socket type, but it needs to be an int (file descriptor). Adding a new signature solves the compatibility problem between Python2 and 3. A test case was added. Task-number: PYSIDE-629 Change-Id: Id9dea37459350dfc90d0f0ab9e2e1993d03fe6e4 Reviewed-by: Qt CI Bot Reviewed-by: Friedemann Kleint Reviewed-by: Christian Tismer --- .../PySide2/QtCore/typesystem_core_common.xml | 42 +++++++-------- sources/pyside2/tests/QtCore/CMakeLists.txt | 1 + .../pyside2/tests/QtCore/qsocketnotifier_test.py | 59 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 sources/pyside2/tests/QtCore/qsocketnotifier_test.py diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 403166d4a..f8259063d 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -2994,27 +2994,27 @@ - - - - - - - Shiboken::AutoDecRef fileNo(PyObject_GetAttrString(%PYARG_1, "fileno")); - if (!fileNo.isNull()) { - Shiboken::AutoDecRef fileNoValue(PyObject_CallObject(fileNo, 0)); - if (%CHECKTYPE[int](fileNoValue)) { - int cppFileNoValue = %CONVERTTOCPP[int](fileNoValue); - /* Qt4 version: - * %0 = new %TYPE(cppFileNoValue, %2, %3); - * Qt5 has qintptr instead. - * XXX check if this means a pointer or just the pointer size cast (what I implemented) - */ - qintptr socket = (qintptr)cppFileNoValue; - %0 = new %TYPE(socket, %2, %3); - } - } - + + + + + + + Shiboken::AutoDecRef socket(%PYARG_1); + if (!socket.isNull()) { + // We use qintptr as PyLong, but we check for int + // since it is currently an alias to be Python2 compatible. + // Internally, ints are qlonglongs. + if (%CHECKTYPE[int](socket)) { + int cppSocket = %CONVERTTOCPP[int](socket); + qintptr socket = (qintptr)cppSocket; + %0 = new %TYPE(socket, %2, %3); + } else { + PyErr_SetString(PyExc_TypeError, + "QSocketNotifier: first argument (socket) must be an int."); + } + } + diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 3a08cb45b..bc83aec7a 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -90,6 +90,7 @@ PYSIDE_TEST(qregularexpression_test.py) PYSIDE_TEST(qresource_test.py) PYSIDE_TEST(qsize_test.py) PYSIDE_TEST(qslot_object_test.py) +PYSIDE_TEST(qsocketnotifier_test.py) PYSIDE_TEST(qsrand_test.py) PYSIDE_TEST(qstandardpaths_test.py) PYSIDE_TEST(qstatemachine_test.py) diff --git a/sources/pyside2/tests/QtCore/qsocketnotifier_test.py b/sources/pyside2/tests/QtCore/qsocketnotifier_test.py new file mode 100644 index 000000000..cd7676cef --- /dev/null +++ b/sources/pyside2/tests/QtCore/qsocketnotifier_test.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Unit tests for QUuid''' + +import unittest + +from PySide2.QtWidgets import QApplication +from PySide2.QtCore import QSocketNotifier +import socket +import sys +import os + +class QSocketNotifierTest(unittest.TestCase): + def testClass(self): + app = QApplication([]) + # socketpair is not available on Windows + if os.name != "nt": + w_sock, r_sock = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM) + + self.assertIsInstance(r_sock.fileno(), int) + + notifier = QSocketNotifier(r_sock.fileno(), QSocketNotifier.Read) + + self.assertIsNotNone(notifier) + + w_sock.close() + r_sock.close() + + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3