Title: Handle Enum when making QVariant by f03el · Pull Request #1 · MeVisLab/pythonqt · GitHub
Open Graph Title: Handle Enum when making QVariant by f03el · Pull Request #1 · MeVisLab/pythonqt
X Title: Handle Enum when making QVariant by f03el · Pull Request #1 · MeVisLab/pythonqt
Description: 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), 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: enumtest.zip: pythonqt_run_enum_test.cpp: Minimal application that shows the problem enumtest.py: Python module with an Enum for use with the test program Minimal example Building Building the test application (very manual – I ran this on Xubuntu 18.10): g++ -fPIC -c `pkg-config --cflags Qt5Core python-3.6 PythonQt-Qt5-Python3` -o pythonqt_run_enum_test.o pythonqt_run_enum_test.cpp g++ -o pythonqt_run_enum_test pythonqt_run_enum_test.o `pkg-config --libs Qt5Core python-3.6 PythonQt-Qt5-Python3` ./pythonqt_run_enum_test Expected output Without the patch, there is a segfault when running the minimal example. With the patch applied, it outputs this: QVariant(QVariantList, (QVariant(QVariantList, (QVariant(QString, "Color"), QVariant(PythonQtObjectPtr, ))), QVariant(QVariantList, (QVariant(QString, "Enum"), QVariant(PythonQtObjectPtr, ))))) Links regarding Enum Python doc: How are Enums different? Source code of Enum
Open Graph Description: 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....
X Description: 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....
Opengraph URL: https://github.com/MeVisLab/pythonqt/pull/1
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4c0136a1-3231-647a-d7ab-8cdfe89928c7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8328:168170:42BE29:573393:697654C7 |
| html-safe-nonce | 3471a3bec2e4da63b00ef3bdf318da67d4d1eb60bd3c96eefcf279cd9604fb0a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzI4OjE2ODE3MDo0MkJFMjk6NTczMzkzOjY5NzY1NEM3IiwidmlzaXRvcl9pZCI6IjgyMDE0NDU2OTIyMjA1Mjc4MTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d57d3a91b4ab06f1a9bd8077a3ea52e27d8d4dd77af4ae79b164a6a75c425ea0 |
| hovercard-subject-tag | pull_request:292049212 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/MeVisLab/pythonqt/pull/1/files |
| twitter:image | https://avatars.githubusercontent.com/u/1366789?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1366789?s=400&v=4 |
| og:image:alt | 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.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 032152924a283b83384255d9489e7b93b54ba01da8d380b05ecd3953b3212411 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/MeVisLab/pythonqt git https://github.com/MeVisLab/pythonqt.git |
| octolytics-dimension-user_id | 15028021 |
| octolytics-dimension-user_login | MeVisLab |
| octolytics-dimension-repository_id | 193056137 |
| octolytics-dimension-repository_nwo | MeVisLab/pythonqt |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193056137 |
| octolytics-dimension-repository_network_root_nwo | MeVisLab/pythonqt |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5b577f6be6482e336e3c30e8daefa30144947b17 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width