diff options
5 files changed, 36 insertions, 2 deletions
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp index 3ee930041..7b62e5833 100644 --- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp @@ -55,3 +55,23 @@ void StdSharedPtrTestBench::printInteger(const std::shared_ptr<Integer> &p) std::cerr << "nullptr"; std::cerr << '\n'; } + +std::shared_ptr<int> StdSharedPtrTestBench::createInt(int v) +{ + return std::make_shared<int>(v); +} + +std::shared_ptr<int> StdSharedPtrTestBench::createNullInt() +{ + return {}; +} + +void StdSharedPtrTestBench::printInt(const std::shared_ptr<int> &p) +{ + std::cerr << __FUNCTION__ << ' '; + if (p.get()) + std::cerr << *p; + else + std::cerr << "nullptr"; + std::cerr << '\n'; +} diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h index 0cf5d78a4..0397013e1 100644 --- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h @@ -44,6 +44,10 @@ public: static std::shared_ptr<Integer> createInteger(int v = 42); static std::shared_ptr<Integer> createNullInteger(); static void printInteger(const std::shared_ptr<Integer> &); + + static std::shared_ptr<int> createInt(int v = 42); + static std::shared_ptr<int> createNullInt(); + static void printInt(const std::shared_ptr<int> &); }; #endif // STDSHAREDPTRTESTBENCH_H diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index 1f89ce096..afe4ba9b9 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -15,6 +15,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrtestbench_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_int_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp ) diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py index 4617f8932..a7d82806a 100644 --- a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py +++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py @@ -46,7 +46,7 @@ def call_func_on_ptr(ptr): class StdSharedPtrTests(unittest.TestCase): - def testIt(self): + def testInteger(self): p = StdSharedPtrTestBench.createInteger() StdSharedPtrTestBench.printInteger(p) self.assertTrue(p) @@ -57,6 +57,13 @@ class StdSharedPtrTests(unittest.TestCase): self.assertFalse(np) self.assertRaises(AttributeError, call_func_on_ptr, np) + def testInt(self): + np = StdSharedPtrTestBench.createNullInt() + StdSharedPtrTestBench.printInt(np) + self.assertFalse(np) + p = StdSharedPtrTestBench.createInt() + StdSharedPtrTestBench.printInt(p) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 2bbb1f56a..83720688d 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -2,6 +2,8 @@ <typesystem package="smart"> <rejection class="*" argument-type="^std::nullptr_t&?$"/> + <primitive-type name="int"/> + <template name="cpplist_to_pylist_convertion"> PyObject *%out = PyList_New(int(%in.size())); int idx = 0; @@ -47,7 +49,7 @@ <smart-pointer-type name="shared_ptr" type="shared" getter="get" value-check-method="operator bool" ref-count-method="use_count" - instantiations="Integer"> + instantiations="Integer,int"> <include file-name="memory" location="global"/> </smart-pointer-type> </namespace-type> |
