When running some Python code from PythonQt the other day, I got a segfault in PythonQtConversion.cpp. It turned out that when an Enum based class is processed by PyObjToQVariant, it's recognised as a sequence (since it's possible to iterate over an Enum in Python), but PySequence_GetItem returns nullptr when the loop gets the value to add to the QVariantList, causing the segfault when calling PyObjToVariant with a null pointer. Unless Enums should be treated in a special way, I assume that the best is to handle them as "normal" classes. In order to do that I created a small patch that checks if val->ob_type->tp_name is "EnumMeta". I'm not sure if this is an acceptable solution, so I'm open for better ways to fix it.
Python 2.7 (with enum34 installed) and 3.6 behave the same.
Files
Supplied files:
pythonqt_run_enum_test.cpp: Minimal application that shows the problem
enumtest.py: Python module with an Enum for use with the test program
handle-enum-when-making-qvariant.diff: My patch
Minimal example
Building
Building the test application (very manual – I ran this on Xubuntu 18.10):
Hi,
Background
When running some Python code from PythonQt the other day, I got a segfault in PythonQtConversion.cpp. It turned out that when an Enum based class is processed by
PyObjToQVariant
, it's recognised as a sequence (since it's possible to iterate over an Enum in Python), butPySequence_GetItem
returns nullptr when the loop gets the value to add to the QVariantList, causing the segfault when callingPyObjToVariant
with a null pointer. Unless Enums should be treated in a special way, I assume that the best is to handle them as "normal" classes. In order to do that I created a small patch that checks ifval->ob_type->tp_name
is "EnumMeta". I'm not sure if this is an acceptable solution, so I'm open for better ways to fix it.Python 2.7 (with enum34 installed) and 3.6 behave the same.
Files
Supplied files:
Minimal example
Building
Building the test application (very manual – I ran this on Xubuntu 18.10):
Expected output
Without the patch, there is a segfault when running the minimal example. With the patch applied, it outputs this:
Links regarding Enum
Last edit: Erik Lundin 2018-11-21
I don't have time to fix this right now, but I added a bug report in our internal bug tracker.
Moved to https://github.com/MeVisLab/pythonqt/pull/1