diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-12-01 20:27:09 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-12-03 12:53:48 +0100 |
| commit | dd8440dff6ecb7af812a3fb4d7a3f54c4de6f99a (patch) | |
| tree | fda7b370b28058e3ac2cd9541e63d1fee7279d50 | |
| parent | 58c8000d410dafb44ef54010671f4278ddcabe41 (diff) | |
shiboken6: Do not generate reverse comparison operators
This leads to duplicated code in Py_tp_richcompare since
CppGenerator::writeRichCompareFunction() does not handle it
and CPython swaps the arguments itself.
Task-number: PYSIDE-3245
Change-Id: I39e9bf6adb2f737ad5f66327cd5a6f9447e86c9d
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
| -rw-r--r-- | sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp index b375da153..deb6acbec 100644 --- a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp @@ -313,6 +313,12 @@ void AbstractMetaBuilderPrivate::traverseFreeOperatorFunction(const FunctionMode return; } + // Do not synthesize reverse comparison operators. CPython swaps the + // arguments for them by itself in Py_tp_richcompare. + const bool reverseOperator = !firstArgumentIsSelf && !unaryOperator; + if (reverseOperator && item->functionType() == CodeModel::ComparisonOperator) + return; + auto metaFunction = traverseFunction(item, baseoperandClass); if (metaFunction == nullptr) return; @@ -320,7 +326,7 @@ void AbstractMetaBuilderPrivate::traverseFreeOperatorFunction(const FunctionMode auto flags = metaFunction->flags(); // Add free comparison operators to their classes, stripping the first argument. // Strip away first argument, since that is the containing object - if (firstArgumentIsSelf || unaryOperator) { + if (!reverseOperator) { AbstractMetaArgument first = metaFunction->takeArgument(0); if (!unaryOperator && first.type().indirections()) metaFunction->setPointerOperator(true); |
