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

Classes not found in header files from /usr/include

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.13.2
    • Shiboken
    • None
    • 617282b3a89cb557900343b262859bb6eaa9b2ed (pyside/pyside-setup/5.15)

    Description

      When trying to generate a Python wrapper module for a custom library, all files included from

      /usr/include

      are ignored.

       

      Example: (with assumption that Qsci/qsciapis.h is in /usr/include/Qsci/qsciapis.h)

      In bindings.h:

      #ifndef BINDINGS_H
      #define BINDINGS_H
      #include <Qsci/qsciapis.h>
      #endif // BINDINGS_H

      in bindings.xml

      ...
      <object-type name="QsciAPIs"/>
      ...

      This will lead to shiboken2 telling me that no C++ classes were found.

       

      When I instead have:

      In bindings.h:

      #ifndef BINDINGS_H
      #define BINDINGS_H
      #include <qsciapis.h>
      #endif // BINDINGS_H

       with the same bindings.xml and adding /usr/include/Qsci to the include path of shiboken, everything works smoothly and my C++ class is found.

       

      Digging into the source code I found that during the traversal of the tree of included files System Headers are excluded almost generally, as seen here:

      bool Builder::visitLocation(const CXSourceLocation &location) const
      {
          if (clang_Location_isInSystemHeader(location) == 0)
              return true;
          CXFile file; // void *
          unsigned line;
          unsigned column;
          unsigned offset;
          clang_getExpansionLocation(location, &file, &line, &column, &offset);
          const CXString cxFileName = clang_getFileName(file);
          // Has been observed to be 0 for invalid locations
          if (const char *cFileName = clang_getCString(cxFileName)) {
              // Resolve OpenGL typedefs although the header is considered a system header.
              const bool visitHeader = compareHeaderName(cFileName, "gl.h")
      #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
                      || cStringStartsWith("/usr/include/stdint.h", cFileName)
      #endif
      #if defined(Q_OS_LINUX)
                      || cStringStartsWith("/usr/include/stdlib.h", cFileName)
                      || cStringStartsWith("/usr/include/sys/types.h", cFileName)
      #elif defined(Q_OS_MACOS)
                      // Parse the following system headers to get the correct typdefs for types like
                      // int32_t, which are used in the macOS implementation of OpenGL framework.
                      || compareHeaderName(cFileName, "gltypes.h")
                      || cStringStartsWith("/usr/include/_types", cFileName)
                      || cStringStartsWith("/usr/include/sys/_types", cFileName)
      #endif
                      ;
              clang_disposeString(cxFileName);
              if (visitHeader)
                  return true;
          }
          return false;
      }
      

      Excluding system files makes sense in my naive opinion, however explicitly added files (like in bindings.h) should not be excluded.

      For this kind of purpose (I guess) clang offers an clang_Location_isFromMainFile() function. Unfortunately, the main file as seen from the clang library in shiboken is not bindings.h but some /tmp/*.hpp file. It does not become clear to me why this is necessary and clang is not called directly with the bindings.h file.

      My request regarding this issue is that you either add some note in the documentation, that files from /usr/include even if they are included in bindings.h will be ignored, or somehow check that system files (in the eyes of clang) only get ignored if they are not included in the bindings.h.

      Attachments

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

        Activity

          People

            kleint Friedemann Kleint
            momosomium Morian Sonnet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes