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

shiboken2 generates duplicate const for container INTYPE_#

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.3.1
    • 5.15.6
    • Shiboken
    • None
    • All

    Description

      The "INTYPE_0" variable for a container type like "QList<const char*>" is computed to "const const char*". When using the pyside2 typesystems files this leads to wrong cpp code.

      This template:

      <template name="cpplist_to_pylist_conversion">
          PyObject* %out = PyList_New((int) %in.size());
          %INTYPE::const_iterator it = %in.begin();
          for (int idx = 0; it != %in.end(); ++it, ++idx) {
              %INTYPE_0 cppItem(*it);
              PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem));
          }
          return %out;
      </template>
      

      generates the invalid code:

      // C++ to Python conversion for type 'QList<const char* >'.
      static PyObject *_QList_constcharPTR__CppToPython__QList_constcharPTR_(const void *cppIn) {
          auto &cppInRef = *reinterpret_cast<::QList<const char* > *>(const_cast<void *>(cppIn));
          // TEMPLATE - cpplist_to_pylist_conversion - START
          PyObject* pyOut = PyList_New((int) cppInRef.size());
          ::QList<const char* >::const_iterator it = cppInRef.begin();
          for (int idx = 0; it != cppInRef.end(); ++it, ++idx) {
              const const char* cppItem(*it);                       // <-- here!!!
              PyList_SET_ITEM(pyOut, idx, Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<const char *>(), cppItem));
          }
          return pyOut;
          // TEMPLATE - cpplist_to_pylist_conversion - END
      
      }
      

      The issue is probably in "shiboken2/generator/shiboken2/cppgenerator.cpp" line 3039:

      // cppgenerator.cpp line 3034 - 3044
          QString code = customConversion->nativeToTargetConversion();
          for (int i = 0; i < containerType->instantiations().count(); ++i) {
              AbstractMetaType *type = containerType->instantiations().at(i);
              QString typeName = getFullTypeName(type);
              if (type->isConstant())
                  typeName = QLatin1String("const ") + typeName;
              code.replace(QString::fromLatin1("%INTYPE_%1").arg(i), typeName);
          }
          replaceCppToPythonVariables(code, getFullTypeNameWithoutModifiers(containerType));
          processCodeSnip(code);
          writeCppToPythonFunction(s, code, fixedCppTypeName(containerType));
      

      The same issue probably also effects shiboken6 ( "shiboken6/generator/shiboken/cppgenerator.cpp" line 3475):

      // cppgenerator.cpp line 3469 - 3480
          const auto customConversion = cte->customConversion();
          QString code = customConversion->nativeToTargetConversion();
          for (qsizetype i = 0; i < containerType.instantiations().size(); ++i) {
              const AbstractMetaType &type = containerType.instantiations().at(i);
              QString typeName = getFullTypeName(type);
              if (type.isConstant())
                  typeName = u"const "_s + typeName;
              code.replace(u"%INTYPE_"_s + QString::number(i), typeName);
          }
          replaceCppToPythonVariables(code, getFullTypeNameWithoutModifiers(containerType), true);
          processCodeSnip(code);
          writeCppToPythonFunction(s, code, fixedCppTypeName(containerType));
      

      although I did not test shiboken6

      Attachments

        Issue Links

          Activity

            People

              kleint Friedemann Kleint
              jonnyboss Jonas Bosse
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: