Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2065

Shiboken2 enum reference and pointer bindings cause crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 5.15.2
    • Shiboken
    • None
    • Windows
    • e1a2fd9524 (pyside/pyside-setup/dev) e1a2fd9524 (pyside/tqtc-pyside-setup/dev) e1a2fd9524 (pyside/tqtc-pyside-setup/tqtc/dev) e1a2fd9524 (pyside/pyside-setup/6.4), aa0969f57 (tqtc/lts-6.2)

    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);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            cerno_b cerno_b
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: