Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
5.15.2
-
None
-
-
e1a2fd9524 (pyside/pyside-setup/dev) e1a2fd9524 (pyside/tqtc-pyside-setup/dev) e1a2fd9524 (pyside/tqtc-pyside-setup/tqtc/dev) e1a2fd9524 (pyside/pyside-setup/6.4)
Description
Accessing enums via reference or pointer causes the generated python bindings to either not compile or to silently crash.
Test code
enum TestEnum { ENUM_VALUE_1 = 1, ENUM_VALUE_2 = 2, ENUM_VALUE_3 = 3 }; struct TestCases { void test_08(TestEnum& e) { std::cout << "TestEnum& e = " << e << std::endl; } void test_09(TestEnum* e) { std::cout << "TestEnum* e = " << *e << std::endl; } };
Case 1: Reference to enum
test_08 does not compile
error C2664: 'void TestCases::test_08(TestEnum &)': cannot convert argument 1 from 'TestEnum *' to 'TestEnum &'
generated code
// Call function/method { ::TestEnum *cppArg0; pythonToCpp(pyArg, &cppArg0); if (!PyErr_Occurred()) { // test_08(TestEnum&) cppSelf->test_08(cppArg0); // <--- test_08 accepts a reference } }
possible solution
Dereferencing the pointer works, but leads to the same crash described in case 2
cppSelf->test_08(*cppArg0);
Case 2: Pointer to enum
test_09 silently crashes in python
Python program exits without any output, probably due to memory corruption on the C++ side
The generated code for test_09
// Call function/method { ::TestEnum *cppArg0; pythonToCpp(pyArg, &cppArg0); if (!PyErr_Occurred()) { // test_09(TestEnum*) cppSelf->test_09(cppArg0); } }
possible solution
Apparently, removing the referencing in the pythonToCpp call seems to fix the issue.
pythonToCpp(pyArg, cppArg0);