aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-06 11:59:13 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-14 12:31:14 +0100
commitfce275e1de88b6d5bdd1c9612b910fa68d1db3f1 (patch)
tree598036bb8219988dbe07007bc5a12e7d9ff72e74
parent52e3888582ac3f3db322d7113734ce43dc325099 (diff)
shiboken6: Handle returning primitive types by pointer
This manifests in QtDataVisualization's const QBarDataArray *QBarDataProxy::array() const where QBarDataArray is handled as a primitive type. This required adapting a code snippet which was relying on the argument QString* being treated as QString. Task-number: PYSIDE-2206 Change-Id: Ib05f01d7b54e103cf5bb71be86ffa9b5067ca3fb Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/pyside6/PySide6/glue/qtwidgets.cpp2
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp7
-rw-r--r--sources/shiboken6/tests/libsample/functions.cpp5
-rw-r--r--sources/shiboken6/tests/libsample/functions.h1
-rw-r--r--sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/typesystem_sample.xml1
6 files changed, 16 insertions, 4 deletions
diff --git a/sources/pyside6/PySide6/glue/qtwidgets.cpp b/sources/pyside6/PySide6/glue/qtwidgets.cpp
index c22c81ba1..3d1c1c3b2 100644
--- a/sources/pyside6/PySide6/glue/qtwidgets.cpp
+++ b/sources/pyside6/PySide6/glue/qtwidgets.cpp
@@ -74,7 +74,7 @@ PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QFormLayout::ItemRole](_role));
%END_ALLOW_THREADS
%PYARG_0 = PyTuple_New(2);
PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
-PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG5_TYPE](%5));
+PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](%5));
// @snippet qfiledialog-return
// @snippet qwidget-addaction-glue
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 071fa1f66..a092e92f7 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -1013,9 +1013,10 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaT
result += u'&';
return result;
}
- return QStringLiteral("Shiboken::Conversions::copyToPython(%1, %2")
- .arg(converterObject(type),
- (type.isCString() || type.isVoidPointer()) ? QString() : u"&"_s);
+
+ const auto indirections = type.indirections() - 1;
+ return u"Shiboken::Conversions::copyToPython("_s + converterObject(type)
+ + u", "_s + AbstractMetaType::dereferencePrefix(indirections);
}
QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaClassCPtr &metaClass)
diff --git a/sources/shiboken6/tests/libsample/functions.cpp b/sources/shiboken6/tests/libsample/functions.cpp
index 29c148346..6f46f89df 100644
--- a/sources/shiboken6/tests/libsample/functions.cpp
+++ b/sources/shiboken6/tests/libsample/functions.cpp
@@ -115,6 +115,11 @@ int acceptInt(int x)
return x;
}
+const int *acceptIntReturnPtr(int x)
+{
+ return new int(x);
+}
+
unsigned int acceptUInt(unsigned int x)
{
return x;
diff --git a/sources/shiboken6/tests/libsample/functions.h b/sources/shiboken6/tests/libsample/functions.h
index 3eb41beaf..31d21902d 100644
--- a/sources/shiboken6/tests/libsample/functions.h
+++ b/sources/shiboken6/tests/libsample/functions.h
@@ -49,6 +49,7 @@ LIBSAMPLE_API unsigned long long doubleUnsignedLongLong(unsigned long long value
LIBSAMPLE_API short doubleShort(short value);
LIBSAMPLE_API int acceptInt(int x);
+LIBSAMPLE_API const int *acceptIntReturnPtr(int x);
LIBSAMPLE_API unsigned int acceptUInt(unsigned int x);
LIBSAMPLE_API long acceptLong(long x);
LIBSAMPLE_API unsigned long acceptULong(unsigned long x);
diff --git a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py
index 45cf534a6..790ed39d5 100644
--- a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py
+++ b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py
@@ -18,6 +18,10 @@ class PrimitiveReferenceArgumentTest(unittest.TestCase):
'''C++ signature: int acceptIntReference(int&)'''
self.assertEqual(sample.acceptIntReference(123), 123)
+ def testIntReturnPtr(self):
+ '''C++ signature: const int *acceptIntReturnPtr(int x)'''
+ self.assertEqual(sample.acceptIntReturnPtr(123), 123)
+
def testOddBoolReferenceArgument(self):
'''C++ signature: OddBool acceptOddBoolReference(OddBool&)'''
self.assertEqual(sample.acceptOddBoolReference(True), True)
diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml
index d0f98be46..25d303a27 100644
--- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml
@@ -400,6 +400,7 @@
<function signature="returnNullValueTypePointer()" />
<function signature="returnNullObjectTypePointer()" />
<function signature="acceptInt(int)" />
+ <function signature="acceptIntReturnPtr(int)"/>
<function signature="acceptUInt(unsigned int)" />
<function signature="acceptLong(long)" />
<function signature="acceptULong(unsigned long)" />