aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-06-07 13:22:39 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-06-07 16:03:38 +0200
commit65c9fd04c80f14adff22428abcaa125569b32ee4 (patch)
treec2b18890a4b8054dc5602861fae52327fb39d498
parent22c9f7bf46d8c3d9be8ab348e4217790a69033cc (diff)
Lazy Load: Fix smart pointers with converters to smart pointers to pointee base
Smart pointers for which additional conversions to smart pointers to base classes of the pointee were registered after the type creation caused a crash with the lazy loading since getConverter() returned 0. Move these functions into the wrapper source and register them from the type creation functions. Task-number: PYSIDE-2404 Change-Id: I5f151748018c9cd84487ca92dee9cf4a42f7e4a7 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp23
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp2
-rw-r--r--sources/shiboken6/libshiboken/sbkmodule.cpp1
3 files changed, 5 insertions, 21 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index ef4409c91..97a38a08d 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5619,6 +5619,9 @@ void CppGenerator::writeClassRegister(TextStream &s,
writeConverterRegister(s, metaClass, classContext);
s << '\n';
+ if (classContext.forSmartPointer())
+ writeSmartPointerConverterInitialization(s, classContext.preciseType());
+
// class inject-code target/beginning
if (!classTypeEntry->codeSnips().isEmpty()) {
writeClassCodeSnips(s, classTypeEntry->codeSnips(),
@@ -6359,18 +6362,6 @@ bool CppGenerator::finishGeneration()
s << '\n';
}
- // Implicit smart pointers conversions
- const auto &smartPointersList = api().instantiatedSmartPointers();
- if (!smartPointersList.isEmpty()) {
- s << "// SmartPointers converters.\n\n";
- for (const auto &smp : smartPointersList) {
- s << "// C++ to Python conversion for smart pointer type '"
- << smp.type.cppSignature() << "'.\n";
- writeSmartPointerConverterFunctions(s, smp.type);
- }
- s << '\n';
- }
-
s << "static struct PyModuleDef moduledef = {\n"
<< " /* m_base */ PyModuleDef_HEAD_INIT,\n"
<< " /* m_name */ \"" << moduleName() << "\",\n"
@@ -6485,14 +6476,6 @@ bool CppGenerator::finishGeneration()
s << '\n';
}
- if (!smartPointersList.isEmpty()) {
- s << '\n';
- for (const auto &smp : smartPointersList) {
- writeSmartPointerConverterInitialization(s, smp.type);
- s << '\n';
- }
- }
-
if (!extendedConverters.isEmpty()) {
s << '\n';
for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) {
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
index a00c2ba50..44b76f181 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator_smartpointer.cpp
@@ -213,6 +213,8 @@ void CppGenerator::generateSmartPointerClass(TextStream &s, const GeneratorConte
s << '\n';
writeConverterFunctions(s, metaClass, classContext);
+ // Implicit smart pointers conversions
+ writeSmartPointerConverterFunctions(s, classContext.preciseType());
writeClassRegister(s, metaClass, classContext, signatureStream);
// class inject-code native/end
diff --git a/sources/shiboken6/libshiboken/sbkmodule.cpp b/sources/shiboken6/libshiboken/sbkmodule.cpp
index 63c71e618..6b080d5fb 100644
--- a/sources/shiboken6/libshiboken/sbkmodule.cpp
+++ b/sources/shiboken6/libshiboken/sbkmodule.cpp
@@ -300,7 +300,6 @@ static bool isImportStar(PyObject *module)
// PYSIDE-2404: These modules produce ambiguous names which we cannot handle, yet.
static std::unordered_set<std::string> dontLazyLoad{
- "smart",
"testbinding"
};