diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-13 13:07:31 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-13 15:06:37 +0200 |
commit | 99a7fe1dac829be9533f2cb9c284401b650a08a1 (patch) | |
tree | 61e248625c7571a01d0cc83730e52ac91c99870f | |
parent | a89915c271c9da86fc0e9ba89552c1678449d6c4 (diff) |
shiboken6: Consistent check of whether to dereference a function argument
Move the condition from the previous
AbstractMetaType::shouldDereferencePointer() to a new function
isWrapperPassedByReference().Introduce a new function
shouldDereferenceArgument(). which does all the checks relevant for
function arguments.
Task-number: PYSIDE-1605
Change-Id: I312ab56eb63031b1c9fb180aab681a9e5acbcd87
Reviewed-by: Christian Tismer <tismer@stackless.com>
4 files changed, 20 insertions, 12 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index 94b55d524..3401a61c9 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -754,12 +754,19 @@ bool AbstractMetaType::isPointerToWrapperType() const return (isObjectType() && d->m_indirections.size() == 1) || isValuePointer(); } -bool AbstractMetaType::shouldDereferencePointer() const +bool AbstractMetaType::isWrapperPassedByReference() const { return d->m_referenceType == LValueReference && isWrapperType() && !isPointer(); } +bool AbstractMetaType::shouldDereferenceArgument() const +{ + return isWrapperPassedByReference() + || valueTypeWithCopyConstructorOnlyPassed() + || isObjectTypeUsedAsValueType(); +} + bool AbstractMetaType::isCppIntegralPrimitive() const { return d->m_typeEntry->isCppIntegralPrimitive(); diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.h b/sources/shiboken6/ApiExtractor/abstractmetatype.h index bb75cc069..6aa682e04 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.h @@ -217,8 +217,11 @@ public: /// Checks if the type is an Object/QObject or pointer to Value Type. /// In other words, tells if the type is "T*" and T has a Python wrapper. bool isPointerToWrapperType() const; - /// Checks if a meta type should be dereferenced by the Python method wrapper passing it to C++. - bool shouldDereferencePointer() const; + /// Wrapper type passed by reference + bool isWrapperPassedByReference() const; + /// Checks if the meta type of an argument should be dereferenced by the Python + /// method wrapper passing it to C++. + bool shouldDereferenceArgument() const; /// Returns true if the type is a C++ integral primitive, /// i.e. bool, char, int, long, and their unsigned counterparts. bool isCppIntegralPrimitive() const; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 66e8de04e..4ad9c35b7 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1266,7 +1266,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, s << '(' << typeCast << ')'; } } - if (func->type().shouldDereferencePointer()) + if (func->type().isWrapperPassedByReference()) s << " *"; s << CPP_RETURN_VAR << ";\n"; } @@ -3328,7 +3328,7 @@ void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, const Abst for (int i = 0; i < containerType.instantiations().count(); ++i) { const AbstractMetaType &type = containerType.instantiations().at(i); QString typeName = getFullTypeName(type); - if (type.valueTypeWithCopyConstructorOnlyPassed()) { + if (type.shouldDereferenceArgument()) { for (int pos = 0; ; ) { const QRegularExpressionMatch match = convertToCppRegEx().match(code, pos); if (!match.hasMatch()) @@ -3597,9 +3597,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr userArgs.append(arg.name() + QLatin1String(CONV_RULE_OUT_VAR_SUFFIX)); } else { const int idx = arg.argumentIndex() - removedArgs; - const bool deRef = arg.type().valueTypeWithCopyConstructorOnlyPassed() - || arg.type().isObjectTypeUsedAsValueType() - || arg.type().shouldDereferencePointer(); + const bool deRef = arg.type().shouldDereferenceArgument(); QString argName; if (deRef) argName += QLatin1Char('*'); @@ -3646,7 +3644,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr firstArg += QLatin1Char(')'); QString secondArg = QLatin1String(CPP_ARG0); if (!func->isUnaryOperator() - && func->arguments().constFirst().type().shouldDereferencePointer()) { + && func->arguments().constFirst().type().shouldDereferenceArgument()) { AbstractMetaType::dereference(&secondArg); } @@ -4983,7 +4981,7 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, if (func->isPointerOperator()) s << '&'; s << CPP_SELF_VAR << ' ' << op << '('; - if (argType.shouldDereferencePointer()) + if (argType.shouldDereferenceArgument()) s << '*'; s << CPP_ARG0 << ");\n" << PYTHON_RETURN_VAR << " = "; diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 16d4107d8..8a24e8327 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -1576,7 +1576,7 @@ ShibokenGenerator::ArgumentVarReplacementList argValue = hasConversionRule ? arg.name() + QLatin1String(CONV_RULE_OUT_VAR_SUFFIX) : QLatin1String(CPP_ARG) + QString::number(argPos); - if (type.shouldDereferencePointer()) + if (type.shouldDereferenceArgument()) AbstractMetaType::dereference(&argValue); } } @@ -1783,7 +1783,7 @@ void ShibokenGenerator::writeCodeSnips(TextStream &s, } if (type.isWrapperType()) { QString replacement = pair.second; - if (type.shouldDereferencePointer()) + if (type.shouldDereferenceArgument()) AbstractMetaType::stripDereference(&replacement); if (type.referenceType() == LValueReference || type.isPointer()) code.replace(u'%' + QString::number(idx) + u'.', replacement + u"->"_qs); |