summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.araujo@kdab.com>2019-02-19 08:41:38 -0300
committerRenato Araujo Oliveira Filho <renato.araujo@kdab.com>2019-02-21 11:58:51 +0000
commit4c48e8e53fc566270bb639f09bb2de3d5ddbd5cf (patch)
tree11901392577797f3d733305a42224a57a75cc787
parent2137f859ec204c8adbb024f348e20a5b87c1792c (diff)
Fix smart pointers with namespace
Use the cppName when looking for metatype while generating smart pointer getter function Change-Id: Ib3a632dd7f667a6bf7c487cfb673f0e55cbddde9 Fixes: PYSIDE-948 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp2
-rw-r--r--sources/shiboken2/tests/libsmart/smart.cpp16
-rw-r--r--sources/shiboken2/tests/libsmart/smart.h10
-rw-r--r--sources/shiboken2/tests/smartbinding/CMakeLists.txt2
-rw-r--r--sources/shiboken2/tests/smartbinding/smart_pointer_test.py13
-rw-r--r--sources/shiboken2/tests/smartbinding/typesystem_smart.xml4
6 files changed, 45 insertions, 2 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 7fea87c1..3ce07cf9 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -515,7 +515,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
// Replace the return type of the raw pointer getter method with the actual
// return type.
QString innerTypeName =
- classContext.preciseType()->getSmartPointerInnerType()->name();
+ classContext.preciseType()->getSmartPointerInnerType()->cppSignature();
QString pointerToInnerTypeName = innerTypeName + QLatin1Char('*');
// @TODO: This possibly leaks, but there are a bunch of other places where this
// is done, so this will be fixed in bulk with all the other cases, because the
diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp
index dbe8efa6..4132c2fc 100644
--- a/sources/shiboken2/tests/libsmart/smart.cpp
+++ b/sources/shiboken2/tests/libsmart/smart.cpp
@@ -68,6 +68,12 @@ SharedPtr<Integer> Obj::giveSharedPtrToInteger()
return o;
}
+SharedPtr<Smart::Integer2> Obj::giveSharedPtrToInteger2()
+{
+ SharedPtr<Smart::Integer2> o(new Smart::Integer2);
+ return o;
+}
+
int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj)
{
pObj->printObj();
@@ -172,3 +178,13 @@ void Registry::setShouldPrint(bool flag)
{
m_printStuff = flag;
}
+
+Smart::Integer2::Integer2()
+ : Integer ()
+{
+}
+
+Smart::Integer2::Integer2(const Smart::Integer2 &other)
+ : Integer (other)
+{
+}
diff --git a/sources/shiboken2/tests/libsmart/smart.h b/sources/shiboken2/tests/libsmart/smart.h
index ea64b443..502187a1 100644
--- a/sources/shiboken2/tests/libsmart/smart.h
+++ b/sources/shiboken2/tests/libsmart/smart.h
@@ -189,6 +189,15 @@ public:
int m_int;
};
+namespace Smart {
+class LIB_SMART_API Integer2 : public Integer {
+public:
+ Integer2();
+ Integer2(const Integer2 &other);
+};
+}
+
+
// Couldn't name it Object because it caused some namespace clashes.
class LIB_SMART_API Obj {
public:
@@ -199,6 +208,7 @@ public:
Integer takeInteger(Integer val);
SharedPtr<Obj> giveSharedPtrToObj();
SharedPtr<Integer> giveSharedPtrToInteger();
+ SharedPtr<Smart::Integer2> giveSharedPtrToInteger2();
int takeSharedPtrToObj(SharedPtr<Obj> pObj);
int takeSharedPtrToInteger(SharedPtr<Integer> pInt);
diff --git a/sources/shiboken2/tests/smartbinding/CMakeLists.txt b/sources/shiboken2/tests/smartbinding/CMakeLists.txt
index 0fb7de82..ed6bcef0 100644
--- a/sources/shiboken2/tests/smartbinding/CMakeLists.txt
+++ b/sources/shiboken2/tests/smartbinding/CMakeLists.txt
@@ -11,6 +11,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/integer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_obj_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/registry_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in"
diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
index 730b4a0d..62bfc050 100644
--- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
+++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py
@@ -143,5 +143,18 @@ class SmartPointerTests(unittest.TestCase):
self.assertEqual(objCount(), 0)
self.assertEqual(integerCount(), 0)
+ def testSmartPointersWithNamespace(self):
+ # Create the main object
+ o = Obj()
+ self.assertEqual(objCount(), 1)
+
+ # Create a shared pointer to an Integer together with an Integer.
+ ptrToInteger = o.giveSharedPtrToInteger2()
+ self.assertEqual(objCount(), 1)
+ self.assertEqual(integerCount(), 2)
+
+ integer = ptrToInteger.data()
+ self.assertTrue(integer)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml
index a2654730..b2deb18c 100644
--- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml
+++ b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml
@@ -17,7 +17,9 @@
<object-type name="Obj" />
<value-type name="Integer" />
-
+ <namespace-type name="Smart" generate="no">
+ <value-type name="Integer2" />
+ </namespace-type>
<!-- Just used to silence the warnings that shiboken doens't know what to do with this type -->
<custom-type name="RefData" />
</typesystem>