PyQt class name collision
""" | |
If class is named as Qt class, sometimes PyQt machinery | |
leads to uncaught Python exception inside sipQWidget::qt_metacast, | |
which leads to failed Python assertion if Python is build in debug | |
mode. | |
$ ./python class_name_collision.py | |
python: ../Objects/abstract.c:2050: PyObject_Call: Assertion `(result != ((void *)0) && !PyErr_Occurred()) || (result == ((void *)0) && PyErr_Occurred())' failed. | |
Aborted (core dumped) | |
$ gdb --args ./python class_name_collision.py | |
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9 | |
Copyright (C) 2015 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-linux-gnu". | |
Type "show configuration" for configuration details. | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>. | |
Find the GDB manual and other documentation resources online at: | |
<http://www.gnu.org/software/gdb/documentation/>. | |
For help, type "help". | |
Type "apropos word" to search for commands related to "word"... | |
Reading symbols from ./python...done. | |
(gdb) r | |
Starting program: /mnt/data/bob/qt/PyQt5_5.5.1_env_dbg/bin/python class_name_collision.py | |
[Thread debugging using libthread_db enabled] | |
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". | |
python: ../Objects/abstract.c:2050: PyObject_Call: Assertion `(result != ((void *)0) && !PyErr_Occurred()) || (result == ((void *)0) && PyErr_Occurred())' failed. | |
[New Thread 0x7fffdfa3f700 (LWP 22088)] | |
[New Thread 0x7fffe0483700 (LWP 22087)] | |
[New Thread 0x7fffea8b1700 (LWP 22086)] | |
Program received signal SIGABRT, Aborted. | |
0x00007ffff6ad5cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. | |
(gdb) bt | |
#0 0x00007ffff6ad5cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 | |
#1 0x00007ffff6ad90d8 in __GI_abort () at abort.c:89 | |
#2 0x00007ffff6aceb86 in __assert_fail_base (fmt=0x7ffff6c1f830 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", | |
assertion=assertion@entry=0x704ca8 "(result != ((void *)0) && !PyErr_Occurred()) || (result == ((void *)0) && PyErr_Occurred())", file=file@entry=0x704332 "../Objects/abstract.c", line=line@entry=2050, | |
function=function@entry=0x704f46 <__PRETTY_FUNCTION__.11058> "PyObject_Call") at assert.c:92 | |
#3 0x00007ffff6acec32 in __GI___assert_fail (assertion=0x704ca8 "(result != ((void *)0) && !PyErr_Occurred()) || (result == ((void *)0) && PyErr_Occurred())", file=0x704332 "../Objects/abstract.c", | |
line=2050, function=0x704f46 <__PRETTY_FUNCTION__.11058> "PyObject_Call") at assert.c:101 | |
#4 0x00000000004679a0 in PyObject_Call (func=<built-in method __instancecheck__ of type object at remote 0x7fffed02fa00>, arg=(<sip.wrappertype at remote 0x7fffed24fb40>,), kw=0x0) | |
at ../Objects/abstract.c:2049 | |
#5 0x0000000000468bf0 in PyObject_CallFunctionObjArgs (callable=<built-in method __instancecheck__ of type object at remote 0x7fffed02fa00>) at ../Objects/abstract.c:2332 | |
#6 0x00000000004694f2 in PyObject_IsInstance (inst=<sip.wrappertype at remote 0x7fffed24fb40>, cls=<type at remote 0x7fffed02fa00>) at ../Objects/abstract.c:2522 | |
#7 0x00007fffecd3fb70 in qpycore_qobject_qt_metacast (pySelf=0x7fffec4af718, base=0x7ffff61c2480 <sipTypeDef_QtWidgets_QWidget>, _clname=0x7fffec7b0631 <sipStrings_QtGui+35953> "QPdfWriter", | |
sipCpp=0x7fffffff9f88) at ../qpy/QtCore/qpycore_qobject_helpers.cpp:238 | |
#8 0x00007ffff5e34945 in sipQWidget::qt_metacast (this=0xd18020, _clname=0x7fffec7b0631 <sipStrings_QtGui+35953> "QPdfWriter") at sipQtWidgetspart0.cpp:328332 | |
#9 0x00007fffec76ef9c in QObject::inherits (this=0xd18020, classname=0x7fffec7b0631 <sipStrings_QtGui+35953> "QPdfWriter") at /home/bob/Qt/5.5/gcc_64/include/QtCore/qobject.h:422 | |
#10 0x00007fffec5f6d03 in sipSubClass_QGuiApplication (sipCppRet=0x7fffffffa028) at /mnt/data/bob/qt/PyQt-gpl-5.5.1/sip/QtGui/qguiapplication.sip:137 | |
#11 0x00007fffed035a2c in ?? () from /mnt/data/bob/qt/PyQt5_5.5.1_env_dbg/lib/python3.4/site-packages/sip.so | |
#12 0x00007fffed0421db in ?? () from /mnt/data/bob/qt/PyQt5_5.5.1_env_dbg/lib/python3.4/site-packages/sip.so | |
#13 0x00007ffff5dfce6d in meth_QLayout_parentWidget (sipSelf=<QVBoxLayout at remote 0x7fffec4af7d8>, sipArgs=()) at sipQtWidgetspart0.cpp:302366 | |
#14 0x00000000004c9c0b in PyCFunction_Call (func=<built-in method parentWidget of QVBoxLayout object at remote 0x7fffec4af7d8>, arg=(), kw=0x0) at ../Objects/methodobject.c:93 | |
#15 0x00000000005be480 in call_function (pp_stack=0x7fffffffa5a0, oparg=0) at ../Python/ceval.c:4237 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#16 0x00000000005b689e in PyEval_EvalFrameEx (f=, throwflag=0) at ../Python/ceval.c:2838 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#17 0x00000000005bbae0 in PyEval_EvalCodeEx (_co=<code at remote 0x7ffff7e47a00>, globals=, locals=0x0, args=0x7ffff61ea150, argcount=1, kws=0x0, kwcount=0, defs=0x7ffff61e3e50, defcount=1, kwdefs=0x0, | |
closure=(<cell at remote 0x7ffff7ece598>,)) at ../Python/ceval.c:3588 | |
#18 0x00000000006f7be5 in function_call (func=<function at remote 0x7fffec458058>, arg=(<QWindow at remote 0x7fffec4af718>,), kw=0x0) at ../Objects/funcobject.c:632 | |
#19 0x000000000046791c in PyObject_Call (func=<function at remote 0x7fffec458058>, arg=(<QWindow at remote 0x7fffec4af718>,), kw=0x0) at ../Objects/abstract.c:2040 | |
#20 0x00000000004877a9 in method_call (func=<function at remote 0x7fffec458058>, arg=(<QWindow at remote 0x7fffec4af718>,), kw=0x0) at ../Objects/classobject.c:347 | |
#21 0x000000000046791c in PyObject_Call (func=<method at remote 0x7ffff7eb6bb8>, arg=(), kw=0x0) at ../Objects/abstract.c:2040 | |
#22 0x00000000004fb6a9 in slot_tp_init (self=<QWindow at remote 0x7fffec4af718>, args=(), kwds=0x0) at ../Objects/typeobject.c:6177 | |
#23 0x00000000004e7f95 in type_call (type=0xe673a8, args=(), kwds=0x0) at ../Objects/typeobject.c:898 | |
#24 0x000000000046791c in PyObject_Call (func=<PyQt5.QtCore.pyqtWrapperType at remote 0xe673a8>, arg=(), kw=0x0) at ../Objects/abstract.c:2040 | |
#25 0x00000000005bf45b in do_call (func=<PyQt5.QtCore.pyqtWrapperType at remote 0xe673a8>, pp_stack=0x7fffffffc290, na=0, nk=0) at ../Python/ceval.c:4466 | |
#26 0x00000000005be6de in call_function (pp_stack=0x7fffffffc290, oparg=0) at ../Python/ceval.c:4264 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#27 0x00000000005b689e in PyEval_EvalFrameEx (f=, throwflag=0) at ../Python/ceval.c:2838 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#28 0x00000000005bbae0 in PyEval_EvalCodeEx (_co=<code at remote 0x7ffff61c9e80>, globals=, locals=, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0) | |
at ../Python/ceval.c:3588 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#29 0x00000000005a67f3 in PyEval_EvalCode (co=<code at remote 0x7ffff61c9e80>, globals=, locals=) at ../Python/ceval.c:775 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#30 0x00000000004279f8 in run_mod (mod=0xbe1a20, filename=, globals=, locals=, flags=0x7fffffffdab0, arena=0xb490b0) at ../Python/pythonrun.c:2180 | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
Python Exception <class 'RuntimeError'> Type does not have a target.: | |
#31 0x0000000000427731 in PyRun_FileExFlags (fp=0xb9c940, filename_str=0x7ffff7e3cf78 "class_name_collision.py", start=257, globals=, locals=, closeit=1, flags=0x7fffffffdab0) at ../Python/pythonrun.c:2133 | |
#32 0x0000000000425648 in PyRun_SimpleFileExFlags (fp=0xb9c940, filename=0x7ffff7e3cf78 "class_name_collision.py", closeit=1, flags=0x7fffffffdab0) at ../Python/pythonrun.c:1606 | |
#33 0x0000000000424445 in PyRun_AnyFileExFlags (fp=0xb9c940, filename=0x7ffff7e3cf78 "class_name_collision.py", closeit=1, flags=0x7fffffffdab0) at ../Python/pythonrun.c:1292 | |
#34 0x000000000043f254 in run_file (fp=0xb9c940, filename=0xb0c2c0 L"class_name_collision.py", p_cf=0x7fffffffdab0) at ../Modules/main.c:319 | |
#35 0x000000000043ffea in Py_Main (argc=2, argv=0xb0a020) at ../Modules/main.c:751 | |
#36 0x000000000041e6df in main (argc=2, argv=0x7fffffffdd38) at ../Modules/python.c:69 | |
(gdb) frame 7 | |
#7 0x00007fffecd3fb70 in qpycore_qobject_qt_metacast (pySelf=0x7fffec4af718, base=0x7ffff61c2480 <sipTypeDef_QtWidgets_QWidget>, _clname=0x7fffec7b0631 <sipStrings_QtGui+35953> "QPdfWriter", | |
sipCpp=0x7fffffff9f88) at ../qpy/QtCore/qpycore_qobject_helpers.cpp:238 | |
238 if (!PyObject_IsInstance((PyObject *)pytype, (PyObject *)&qpycore_pyqtWrapperType_Type)) | |
(gdb) list | |
233 | |
234 for (SIP_SSIZE_T i = 0; i < PyTuple_GET_SIZE(mro); ++i) | |
235 { | |
236 PyTypeObject *pytype = (PyTypeObject *)PyTuple_GET_ITEM(mro, i); | |
237 | |
238 if (!PyObject_IsInstance((PyObject *)pytype, (PyObject *)&qpycore_pyqtWrapperType_Type)) | |
239 continue; | |
240 | |
241 const sipTypeDef *td = ((sipWrapperType *)pytype)->type; | |
242 | |
(gdb) | |
""" | |
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout | |
class QWindow(QWidget): | |
def __init__(self, parent=None): | |
super().__init__(parent) | |
self.setLayout(QVBoxLayout()) | |
self.layout().parentWidget() # <-- uncaught exception is generated and asserted here | |
qapp = QApplication([]) | |
qwin = QWindow() | |
qwin.show() | |
qapp.exec() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment