aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-03-19 10:30:29 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-05-09 11:32:52 +0000
commit43451e3bc17467593df64cb73ce8c0bf9e60045f (patch)
tree00f85921652ffcd15d1d7fb1be4b8519462364ac /sources/pyside2
parent9dc1aa57dfbf9c684e5c75451dd028b88099c348 (diff)
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 <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2')
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml42
-rw-r--r--sources/pyside2/tests/QtCore/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/QtCore/qsocketnotifier_test.py59
3 files changed, 81 insertions, 21 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index 403166d4..f8259063 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -2994,27 +2994,27 @@
<object-type name="QSocketNotifier">
<enum-type name="Type"/>
- <add-function signature="QSocketNotifier(PyObject*,QSocketNotifier::Type,QObject*)">
- <modify-argument index="3">
- <replace-default-expression with="0" />
- <rename to="parent" />
- </modify-argument>
- <inject-code>
- 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);
- }
- }
- </inject-code>
+ <add-function signature="QSocketNotifier(PyObject*, QSocketNotifier::Type, QObject*)">
+ <modify-argument index="3">
+ <replace-default-expression with="0" />
+ <rename to="parent" />
+ </modify-argument>
+ <inject-code>
+ 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.");
+ }
+ }
+ </inject-code>
</add-function>
</object-type>
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt
index 3a08cb45..bc83aec7 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 00000000..cd7676ce
--- /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()