path: root/sources/pyside2/PySide2/QtWidgets
diff options
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-01-31 14:04:45 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-01-31 16:57:20 +0000
commit819f7b47b1fcdc2ed88bdd07383bbd37a76848ac (patch)
treeb9f8233fb2e5b515353ea6694ffd731595022fdf /sources/pyside2/PySide2/QtWidgets
parent4939437004cdce2d718da806daf1d90f7499e410 (diff)
Add code to invalidate objs on QListWidget.clear
As reported on PYSIDE-264, when an item of an already cleared QListWidget was being accessed, a segfault happened when trying to access this deleted data. Due to the lack of an invalidation process of the python objects when clear() was called, the generated validation step before accessing the data had no effect. This was solved injecting code to set their parents to NULL, and invalidating them. The outcome of trying to access deleted data then will be a RuntimeError, instead of a segfault. A test case is provided. Task-number: PYSIDE-264 Change-Id: If52dd85827500c96a078a8f9d61921a275fb28f9 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/QtWidgets')
1 files changed, 16 insertions, 0 deletions
diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
index 2c380dac..92ff3c08 100644
--- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
+++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
@@ -2149,6 +2149,22 @@
<parent index="this" action="remove"/>
+ <modify-function signature="clear()">
+ <inject-code class="target" position="beginning">
+ Shiboken::BindingManager &amp;bm = Shiboken::BindingManager::instance();
+ PyObject *pyObj;
+ for (int i = 0; i &lt; %CPPSELF.count(); i++) {
+ QListWidgetItem *item = %CPPSELF.item(i);
+ if ((pyObj = reinterpret_cast&lt;PyObject*&gt;(bm.retrieveWrapper(item))) != 0) {
+ Py_INCREF(pyObj);
+ Shiboken::Object::setParent(NULL, pyObj);
+ Shiboken::Object::invalidate(pyObj);
+ Py_DECREF(pyObj);
+ }
+ }
+ </inject-code>
+ </modify-function>
<object-type name="QWidget">