Handle Enum when making QVariant #1
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Moved here from https://sourceforge.net/p/pythonqt/discussion/631392/thread/bf34b51907/
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:
enumtest.zip:
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