Closed
Conversation
Distinguish Enums from normal PySequences when converting to QVariant.
Collaborator
|
I think the string compare is not a good idea. It costs performance and will also match a user's class that is called EnumMeta.
|
Author
|
@florianlink Thanks for your input! I agree that a string comparison like that not feels great. I'm not sure though how to do what you suggested, so it might take some time to do. Did you have any special method in mind how to import "enum"? |
Collaborator
|
Have a look at PythonQt.cpp where e.g. importlib is imported. You can do
the same for enum and lookup the EnumMeta type from the imported module.
…On Thu 27. Jun 2019 at 14:52, Erik Lundin ***@***.***> wrote:
@florianlink <https://github.com/florianlink> Thanks for your input! I
agree that a string comparison like that not feels great. I'm not sure
though how to do what you suggested, so it might take some time to do. Did
you have any special method in mind how to import "enum"?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1?email_source=notifications&email_token=ABKHPHGKQNE4H3HWNWONKADP4SZXFA5CNFSM4H3TS6GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYXAMIQ#issuecomment-506332706>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKHPHCVXQ3QCIP3HH3KCOTP4SZXFANCNFSM4H3TS6GA>
.
|
Collaborator
|
Current state is not acceptable, closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_GetItemreturns nullptr when the loop gets the value to add to the QVariantList, causing the segfault when callingPyObjToVariantwith 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_nameis "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