diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-13 13:45:54 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-24 13:52:35 +0200 |
commit | 79b32f4d4b5154ba8001bafc481fb6edacc10280 (patch) | |
tree | 2ebd4470b1eef8e9cd231213901ac6ca2c454f06 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | d9bad33ad2cd0e49e22c82f8d05422274cbbf1c8 (diff) |
shiboken6: Rewrite conversions
Currently, the isPythonToCpp(Value/Reference/Pointer)Convertible
functions used by the overload decisor return a function pointer. In the case
of isPythonToCppReferenceConvertible, this can be either a pointer
conversion taking a Foo** or a value conversion taking a Foo*.
The function isImplicitConversion(SbkObjectType *, PythonToCppFunc)
is called further down in the generated code to check whether it
is a value or a pointer.
In order to get rid of this, introduce a new version of the
checking function that returns a struct that has the function
and knows its type.
Add an overload of isPythonToCppReferenceConvertible() taking
a SbkConverter for the upcoming opaque containers.
Task-number: PYSIDE-1605
Change-Id: I49f70b85d01500d95208f0f2dd290bf23cb80eff
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index d0dfe7f27..e7648f736 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -59,6 +59,7 @@ #include <cstring> static const char CPP_ARG0[] = "cppArg0"; +const char *CppGenerator::PYTHON_TO_CPPCONVERSION_STRUCT = "Shiboken::Conversions::PythonToCppConversion"; static inline QString reprFunction() { return QStringLiteral("__repr__"); } @@ -1171,7 +1172,8 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, s << "// Check return type\n"; if (func->typeReplaced(0).isEmpty()) { - s << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << " = " + s << PYTHON_TO_CPPCONVERSION_STRUCT + << ' ' << PYTHON_TO_CPP_VAR << " = " << cpythonIsConvertibleFunction(func->type()) << PYTHON_RETURN_VAR << ");\n" << "if (!" << PYTHON_TO_CPP_VAR << ") {\n"; @@ -1864,15 +1866,10 @@ static const char *fullName = ")" << fullPythonFunctionName(rfunc, true) << "\";\nSBK_UNUSED(fullName)\n"; if (maxArgs > 0) { s << "int overloadId = -1;\n" - << "PythonToCppFunc " << PYTHON_TO_CPP_VAR; - if (overloadData.pythonFunctionWrapperUsesListOfArguments()) { - s << "[] = { " << NULL_PTR; - for (int i = 1; i < maxArgs; ++i) - s << ", " << NULL_PTR; - s << " };\n"; - } else { - s << "{};\n"; - } + << PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR; + if (overloadData.pythonFunctionWrapperUsesListOfArguments()) + s << '[' << maxArgs << ']'; + s << ";\n"; writeUnusedVariableCast(s, QLatin1String(PYTHON_TO_CPP_VAR)); } @@ -2684,8 +2681,7 @@ void CppGenerator::writePythonToCppTypeConversion(TextStream &s, if (!defaultValue.isEmpty()) s << "if (" << pythonToCppFunc << ") {\n" << indent; - s << "if (Shiboken::Conversions::isImplicitConversion(reinterpret_cast<PyTypeObject *>(" - << cpythonTypeNameExt(type) << "), " << pythonToCppFunc << "))\n" + s << "if (" << pythonToCppFunc << ".isValue())\n" << indent << pythonToCppFunc << '(' << pyIn << ", &" << cppOutAux << ");\n" << outdent << "else\n" << indent << pythonToCppCall << ";\n" << outdent; @@ -4816,7 +4812,7 @@ void CppGenerator::writeSetterFunctionPreamble(TextStream &s, const QString &nam << "return -1;\n" << outdent << "}\n"; - s << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << "{nullptr};\n" + s << PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR << ";\n" << "if (!"; writeTypeCheck(s, type, QLatin1String("pyIn"), isNumber(type.typeEntry())); s << ") {\n" << indent @@ -4892,7 +4888,7 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, writeCppSelfDefinition(s, context, false, false, true); writeUnusedVariableCast(s, QLatin1String(CPP_SELF_VAR)); s << "PyObject *" << PYTHON_RETURN_VAR << "{};\n" - << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ";\n"; + << PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR << ";\n"; writeUnusedVariableCast(s, QLatin1String(PYTHON_TO_CPP_VAR)); s << '\n'; @@ -6608,7 +6604,7 @@ void CppGenerator::writeDefaultSequenceMethods(TextStream &s, writeCppSelfDefinition(s, context); writeIndexError(s, QLatin1String("list assignment index out of range")); - s << "PythonToCppFunc " << PYTHON_TO_CPP_VAR << ";\n" + s << PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR << ";\n" << "if (!"; writeTypeCheck(s, itemType, QLatin1String("pyArg"), isNumber(itemType.typeEntry())); s << ") {\n"; |