Explorar el Código

BF: Fix param widget test crash on garbage collection

Without a parent widget passed to load_parameter_widget (and a
reference, that keeps it during the loop's body) the input widget (or
parts thereof) may be picked up by garbage collection and lead to a
seg fault during cleanup.
Benjamin Poldrack hace 1 año
padre
commit
a0ddb46fda
Se han modificado 1 ficheros con 14 adiciones y 9 borrados
  1. 14 9
      datalad_gooey/tests/test_param_widget.py

+ 14 - 9
datalad_gooey/tests/test_param_widget.py

@@ -1,6 +1,8 @@
 import functools
 from pathlib import Path
 
+from PySide6.QtWidgets import QWidget
+
 from ..param_widgets import (
     BoolParamWidget,
     StrParamWidget,
@@ -28,24 +30,27 @@ def test_GooeyParamWidgetMixin():
             (PathParamWidget, str(Path.cwd()), None),
             # cannot include MultiValueInputWidget, leads to Python segfault
             # on garbage collection?!
-            # (functools.partial(
-            #     MultiValueInputWidget, PathParamWidget),
-            #  [str(Path.cwd()), 'temp'],
-            #  'mypath'),
-            # (functools.partial(
-            #     MultiValueInputWidget, PathParamWidget),
-            #  [str(Path.cwd()), 'temp'],
-            #  None),
+            (functools.partial(
+                MultiValueInputWidget, PathParamWidget),
+             [str(Path.cwd()), 'temp'],
+             'mypath'),
+            (functools.partial(
+                MultiValueInputWidget, PathParamWidget),
+             [str(Path.cwd()), 'temp'],
+             None),
 
     ):
         # this is how all parameter widgets are instantiated
+        parent = QWidget()  # we need parent to stick around,
+                            # so nothing gets picked up by GC
         pw = load_parameter_widget(
-            None,
+            parent,
             pw_factory,
             name='peewee',
             docs='EXPLAIN!',
             default=default,
         )
+
         # If nothing was set yet, we expect `_NoValue` as the "representation of
         # default" here:
         assert pw.get_gooey_param_spec() == {'peewee': _NoValue}, \