diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-17 16:45:24 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-05 10:39:53 +0200 |
commit | 11941d0709110a7bbdcf8911bb368f86a9a5afeb (patch) | |
tree | ba5fc221332ce97add3eac5e83d2d013798a97c4 | |
parent | 7a3d79fb13d9f1ef31e7ee3e1e2691abf6d615e4 (diff) |
shiboken6: Remove the PyObject_Check helper macro
The macro was there to satisfy the shiboken heuristics which would
generate "PyObject_Check" to check for a PyObject, which is always
true. Remove the macro and handle "true" in the type entry.
[ChangeLog][shiboken6] The macro PyObject_Check()
has been removed.
Task-number: PYSIDE-1660
Change-Id: I86fc1ed3d8773245deb679142a8ff830cbc19883
Reviewed-by: Christian Tismer <tismer@stackless.com>
5 files changed, 10 insertions, 8 deletions
diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index 427b923d1..7c3fac762 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -81,7 +81,7 @@ static const PythonTypes &builtinPythonTypes() {u"PyDateTime"_qs, u"PyDateTime_Check_Check"_qs, TypeSystem::CPythonType::Other}, {u"PyDict"_qs, u"PyDict_Check"_qs, TypeSystem::CPythonType::Other}, // Convenience macro in sbkconverter.h - {u"PyObject"_qs, u"PyObject_Check"_qs, TypeSystem::CPythonType::Other}, + {u"PyObject"_qs, u"true"_qs, TypeSystem::CPythonType::Other}, // shiboken-specific {u"PyPathLike"_qs, u"Shiboken::String::checkPath"_qs, TypeSystem::CPythonType::Other}, {u"PySequence"_qs, u"Shiboken::String::checkIterable"_qs, TypeSystem::CPythonType::Other}, diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 2cb0253bd..50f80c244 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -2076,8 +2076,12 @@ QString CustomConversion::TargetToNativeConversion::sourceTypeCheck() const if (m_d->sourceType != nullptr && m_d->sourceType->isCustom()) { const auto *cte = static_cast<const CustomTypeEntry *>(m_d->sourceType); - if (cte->hasCheckFunction()) - return cte->checkFunction() + u"(%in)"_qs; + if (cte->hasCheckFunction()) { + QString result = cte->checkFunction(); + if (result != u"true") // For PyObject, which is always true + result += u"(%in)"_qs; + return result; + } } return {}; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 284553901..5db3d82e3 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -2399,7 +2399,8 @@ void CppGenerator::writeTypeCheck(TextStream &s, const AbstractMetaType &argType { // TODO-CONVERTER: merge this with the code below. QString typeCheck = cpythonIsConvertibleFunction(argType); - typeCheck.append(u'(' +argumentName + u')'); + if (typeCheck != u"true") // For PyObject, which is always true + typeCheck.append(u'(' +argumentName + u')'); // TODO-CONVERTER ----------------------------------------------------------------------- if (!argType.typeEntry()->isCustom()) { diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 796c60be7..6bcf2313d 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -1015,7 +1015,7 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) const if (metaType.isCString()) return QLatin1String("Shiboken::String::check"); if (metaType.isVoidPointer()) - return QLatin1String("PyObject_Check"); + return u"true"_qs; return cpythonCheckFunction(typeEntry); } diff --git a/sources/shiboken6/libshiboken/sbkconverter.h b/sources/shiboken6/libshiboken/sbkconverter.h index 1f643140a..0cf8e5c0d 100644 --- a/sources/shiboken6/libshiboken/sbkconverter.h +++ b/sources/shiboken6/libshiboken/sbkconverter.h @@ -431,9 +431,6 @@ template<> inline PyTypeObject *SbkType<std::nullptr_t>() { return Py_TYPE(&_Py_ } // namespace Shiboken -// When the user adds a function with an argument unknown for the typesystem, the generator writes type checks as -// TYPENAME_Check, so this macro allows users to add PyObject arguments to their added functions. -#define PyObject_Check(X) true #define SbkChar_Check(X) (PyNumber_Check(X) || Shiboken::String::checkChar(X)) struct PySideQFlagsType; |