From 4c48e8e53fc566270bb639f09bb2de3d5ddbd5cf Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 19 Feb 2019 08:41:38 -0300 Subject: 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 --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 2 +- sources/shiboken2/tests/libsmart/smart.cpp | 16 ++++++++++++++++ sources/shiboken2/tests/libsmart/smart.h | 10 ++++++++++ sources/shiboken2/tests/smartbinding/CMakeLists.txt | 2 ++ .../shiboken2/tests/smartbinding/smart_pointer_test.py | 13 +++++++++++++ .../shiboken2/tests/smartbinding/typesystem_smart.xml | 4 +++- 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 7fea87c1b..3ce07cf93 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 dbe8efa66..4132c2fc8 100644 --- a/sources/shiboken2/tests/libsmart/smart.cpp +++ b/sources/shiboken2/tests/libsmart/smart.cpp @@ -68,6 +68,12 @@ SharedPtr Obj::giveSharedPtrToInteger() return o; } +SharedPtr Obj::giveSharedPtrToInteger2() +{ + SharedPtr o(new Smart::Integer2); + return o; +} + int Obj::takeSharedPtrToObj(SharedPtr 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 ea64b4439..502187a11 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 giveSharedPtrToObj(); SharedPtr giveSharedPtrToInteger(); + SharedPtr giveSharedPtrToInteger2(); int takeSharedPtrToObj(SharedPtr pObj); int takeSharedPtrToInteger(SharedPtr pInt); diff --git a/sources/shiboken2/tests/smartbinding/CMakeLists.txt b/sources/shiboken2/tests/smartbinding/CMakeLists.txt index 0fb7de825..ed6bcef0a 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 730b4a0da..62bfc0500 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 a2654730d..b2deb18cb 100644 --- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml @@ -17,7 +17,9 @@ - + + + -- cgit v1.2.3