aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-02-17 17:23:31 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-17 15:37:11 +0100
commitff581a0d2a7396de69389754e3d0f69ea104dea5 (patch)
tree4286e34b2253e94b96bf4a384a7c3a15d22361e2 /sources
parent18d3754647c4d5e29b48abdad8143b305681a0f9 (diff)
shiboken6: Copy spans in opaque containers
Spans as non-owning containers can be returned by value from functions; so, the Python type should copy and own them. Task-number: PYSIDE-2174 Change-Id: I612ee158272752e5a7a658959d307d87e2a272da Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator_container.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
index a9bec406d..c38e8ce45 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
@@ -54,23 +54,37 @@ static void writeSlot(TextStream &s, const QString &privateObjType,
// Write creation function from C++ reference, used by field accessors
// and getters which are within extern "C"
+
+enum ContainerCreationFlag
+{
+ None = 0,
+ Const = 0x1,
+ Allocate = 0x2
+};
+
+Q_DECLARE_FLAGS(ContainerCreationFlags, ContainerCreationFlag)
+Q_DECLARE_OPERATORS_FOR_FLAGS(ContainerCreationFlags)
+
static void writeContainerCreationFunc(TextStream &s,
const QString &funcName,
const QString &typeFName,
const QString &containerSignature,
- bool isConst = false)
+ ContainerCreationFlags flags = {})
{
// creation function from C++ reference, used by field accessors
// which are within extern "C"
s << "extern \"C\" PyObject *" << funcName << '(';
- if (isConst)
+ if (flags.testFlag(ContainerCreationFlag::Const))
s << "const ";
s << containerSignature << "* ct)\n{\n" << indent
<< "auto *container = PyObject_New(ShibokenContainer, " << typeFName << "());\n"
<< "auto *d = new ShibokenSequenceContainerPrivate<"
<< containerSignature << ">();\n";
- if (isConst) {
+ if (flags.testFlag(ContainerCreationFlag::Allocate)) {
+ s << "d->m_list = new " << containerSignature << "(*ct);\n"
+ << "d->m_ownsList = true;\n";
+ } else if (flags.testFlag(ContainerCreationFlag::Const)) {
s << "d->m_list = const_cast<" << containerSignature << " *>(ct);\n"
<< "d->m_const = true;\n";
} else {
@@ -215,10 +229,15 @@ CppGenerator::OpaqueContainerData
<< "();\nreturn type;\n" << outdent << "}\n\n";
// creation functions from C++ references
+ ContainerCreationFlags flags;
+ if (kind == ContainerTypeEntry::SpanContainer)
+ flags.setFlag(ContainerCreationFlag::Allocate);
+
writeContainerCreationFunc(s, u"create"_s + result.name, typeFName,
- containerType.cppSignature());
+ containerType.cppSignature(), flags);
+ flags.setFlag(ContainerCreationFlag::Const);
writeContainerCreationFunc(s, u"createConst"_s + result.name, typeFName,
- containerType.cppSignature(), true);
+ containerType.cppSignature(), flags);
// Check function
result.checkFunctionName = result.name + u"_Check"_s;