[issue38007] Regression: name of PyType_Spec::slots conflicts with Qt macro

Leslie report at bugs.python.org
Wed Sep 11 06:18:49 EDT 2019


Leslie <laszlo.nemeth.pub at gmail.com> added the comment:

Some history and explanation of this problem:

- Qt extends C++ with the following keywords:
  "slots", "signals", "emit"
- This extension is compiled with a Meta-Object-Compiler (MOC) into standard C++.
- Since code using Qt extensions (i.e. headers) generally used "mixed" with standard C++ code, "standard" compiler must be able to compile the Qt specific part, too
  -> the extension keywords are declared as empty macros (i.e. #define slots)

The consequence is that if Qt-based headers are used together with any 3rd party headers, the 3rd party code cannot contain the extension keywords (slots, signals, emit) as C/C++ tokens, because the preprocessor will "delete" them as a result of macro expansion, since the keywords are defined as empty macros.
->
The code won't compile because of syntax errors.

This caused bug https://bugs.python.org/issue1086854 , which was fixed in https://github.com/python/cpython/commit/c255c7bef7621596869f56d887ac3ccd5b536708

The fix renamed the "slots" struct member in Python, thus the conflict was resolved.

Note: the Qt library is, like Python, old, and used in a huge number of projects and products. E.g. Qt is the base platform for KDE development. It's a matter of point of view, which of the two, Qt or Python should be "fixed".

In my PR I used the same solution: renaming the conflicting member.
-------------

Since this time this solution was not welcome, and obviously I'm not the first facing this issue, I was searching for another solutions.

I found that Qt has already provided a solution for this problem.

There are 2 macros: QT_NO_SIGNALS_SLOTS_KEYWORDS and QT_NO_KEYWORDS , which "turn off" defining the extension keywords as macros.
Instead the QT_SLOTS, Q_SIGNALS macros should be used, which very likely do not interfere with any 3rd party library...

Though, these are "official" Qt macros, not very well documented: https://bugreports.qt.io/browse/QTBUG-70564  :)

So by defining QT_NO_KEYWORDS I could resolve this whole issue.

Thanks guys for your patience and attetion!
:)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38007>
_______________________________________


More information about the Python-bugs-list mailing list