diff options
Diffstat (limited to 'sources/shiboken6')
7 files changed, 52 insertions, 0 deletions
diff --git a/sources/shiboken6/doc/typesystem_specifying_types.rst b/sources/shiboken6/doc/typesystem_specifying_types.rst index 7fe4df392..7c3c1ae63 100644 --- a/sources/shiboken6/doc/typesystem_specifying_types.rst +++ b/sources/shiboken6/doc/typesystem_specifying_types.rst @@ -770,6 +770,7 @@ will be generated into specific modules. reset-method="..." instantiations="..." excluded-instantiations="..."/> + to-python="default" </typesystem> @@ -797,6 +798,24 @@ comma-separated list of types to be excluded from instantiating. Typically, this is used to exclude instantiations present in an underlying base module to prevent symbol clashes. +The *optional* **to-python** attribute specifies how a smart pointer +instance is converted to Python: + +.. list-table:: + :header-rows: 1 + + * - Value + + - Meaning + + * - ``default`` + + - A smart pointer instance is returned in all cases + + * - ``null-as-none`` + + - ``None`` is returned if the smart pointer is null. + The *optional* attribute **type** specifies the type: *shared* diff --git a/sources/shiboken6/tests/libsmart/smart.cpp b/sources/shiboken6/tests/libsmart/smart.cpp index 2273040f9..6dd4c3c6b 100644 --- a/sources/shiboken6/tests/libsmart/smart.cpp +++ b/sources/shiboken6/tests/libsmart/smart.cpp @@ -147,6 +147,18 @@ SharedPtr<const Integer> Obj::createSharedPtrConstInteger() return co; } +SharedPtr2<Integer> Obj::createNullSharedPtr2Integer() +{ + return {}; +} + +SharedPtr2<Integer> Obj::createSharedPtr2Integer(int value) +{ + auto *i = new Integer; + i->setValue(value); + return SharedPtr2<Integer>(i); +} + int Obj::takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt) { return pInt->m_int; diff --git a/sources/shiboken6/tests/libsmart/smart_obj.h b/sources/shiboken6/tests/libsmart/smart_obj.h index 9f4f8425d..fceca0b6d 100644 --- a/sources/shiboken6/tests/libsmart/smart_obj.h +++ b/sources/shiboken6/tests/libsmart/smart_obj.h @@ -38,6 +38,9 @@ public: static SharedPtr<Integer> createSharedPtrInteger(int value); static SharedPtr<Integer> createNullSharedPtrInteger(); + static SharedPtr2<Integer> createNullSharedPtr2Integer(); + static SharedPtr2<Integer> createSharedPtr2Integer(int value); + int m_integer; // public for testing member field access. Integer *m_internalInteger; }; diff --git a/sources/shiboken6/tests/libsmart/smart_sharedptr.h b/sources/shiboken6/tests/libsmart/smart_sharedptr.h index dc665810a..7a77b3d6c 100644 --- a/sources/shiboken6/tests/libsmart/smart_sharedptr.h +++ b/sources/shiboken6/tests/libsmart/smart_sharedptr.h @@ -91,4 +91,10 @@ public: std::shared_ptr<T> mPtr; }; +template <class T> +class SharedPtr2 : public SharedPtr<T> { +public: + using SharedPtr<T>::SharedPtr; +}; + #endif // SMART_SHARED_PTR_H diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index 02c4e6596..5b3f4feda 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -13,6 +13,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/obj_wrapper.cpp ${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/sharedptr2_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 diff --git a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py index 64267fba7..761478df0 100644 --- a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py @@ -288,6 +288,14 @@ class SmartPointerTests(unittest.TestCase): o.takeSharedPtrToInteger(None) o.takeSharedPtrToIntegerByConstRef(None) + def testNoneConversion(self): + """PYSIDE-3253: SharedPtr2 is configured to convert to None.""" + valid_ptr = Obj.createSharedPtr2Integer(42) + null_ptr = Obj.createNullSharedPtr2Integer() + self.assertEqual(valid_ptr.value(), 42) + self.assertFalse(valid_ptr is None) + self.assertTrue(null_ptr is None) + def testConstruction(self): p1 = SharedPtr_Integer(integerFromValue(42)) self.assertEqual(p1.value(), 42) diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 4024036fa..69c653286 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -13,6 +13,9 @@ <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" null-check-method="isNull" instantiations="Integer,Smart::Integer2=Test::SmartInteger2Ptr,Obj"/> + <smart-pointer-type name="SharedPtr2" type="shared" getter="data" ref-count-method="useCount" + null-check-method="isNull" to-python="null-as-none" + instantiations="Integer"/> <object-type name="Obj" /> <value-type name="Integer" /> |
