From c7f13b5e23afd4d5dcf5be548fedbed56d84a48b Mon Sep 17 00:00:00 2001 From: Zack Guard Date: Wed, 11 Jan 2023 21:54:48 +0800 Subject: [PATCH 1/2] Export newCppSharedPtr --- cppstl.nimble | 2 ++ cppstl/std_smartptrs.nim | 2 +- tests/tsmart_ptrs.nim | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cppstl.nimble b/cppstl.nimble index ea55932..1f59bd2 100644 --- a/cppstl.nimble +++ b/cppstl.nimble @@ -27,6 +27,8 @@ task test, "Run the tests": exec "nim cpp -r --gc:arc tests/tcomplex.nim" exec "nim cpp -r tests/tpair.nim" exec "nim cpp -r --gc:arc tests/tpair.nim" + exec "nim cpp -r tests/tsmart_ptrs.nim" + exec "nim cpp -r --gc:arc tests/tsmart_ptrs.nim" # the following should compile and *not* produce a codegen error exec "nim cpp --gc:arc -r tests/tdestructor_codegen_bug.nim" diff --git a/cppstl/std_smartptrs.nim b/cppstl/std_smartptrs.nim index de1fe90..a4e952e 100644 --- a/cppstl/std_smartptrs.nim +++ b/cppstl/std_smartptrs.nim @@ -9,7 +9,7 @@ when not defined(cpp): type CppSharedPtr*[T]{.importcpp: "std::shared_ptr", bycopy.} = object -proc newCppSharedPtr[T](p: ptr T): CppSharedPtr[T] {.constructor, +proc newCppSharedPtr*[T](p: ptr T): CppSharedPtr[T] {.constructor, importcpp: "std::shared_ptr<'*0>(#)".} func makeShared*(T: typedesc): CppSharedPtr[T] {.importcpp: "std::make_shared<'*0>()".} diff --git a/tests/tsmart_ptrs.nim b/tests/tsmart_ptrs.nim index 07b5a2f..e4e3891 100644 --- a/tests/tsmart_ptrs.nim +++ b/tests/tsmart_ptrs.nim @@ -25,6 +25,8 @@ proc init*(T: type UniquePtrObj, name: string): UniquePtrObj = result.name = name result.id = guid +proc cppNew[T](x: typedesc[T]): ptr T {.importcpp: "(new '1)", nodecl.} + proc testShared() = test "SharedPtr": var sp1 = SharedPtrObj.init("ptr_1") @@ -44,6 +46,12 @@ proc testShared() = check: sp1.name == "ptr_3" check sp1.name.len() == 5 + var sp3 = block: + let p = cppNew(Obj) + p[] = sp1.deref + newCppSharedPtr(p) + check sp3.deref == sp1.deref + when defined(gcArc) or defined(gcOrc): check: $(sp1) == "CppShared ptr Obj(id: 1, name: \"ptr_3\")" else: From 8f22821b2a6f4ef50fb28f03b31a314404dc55fd Mon Sep 17 00:00:00 2001 From: Regis Caillaud <35006197+Clonkk@users.noreply.github.com> Date: Thu, 12 Jan 2023 15:52:05 +0100 Subject: [PATCH 2/2] Update cppstl.nimble --- cppstl.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppstl.nimble b/cppstl.nimble index 1f59bd2..67a0580 100644 --- a/cppstl.nimble +++ b/cppstl.nimble @@ -1,6 +1,6 @@ # Package -version = "0.6.1" +version = "0.6.2" author = "Clonkk" description = "Bindings for the C++ Standard Template Library (STL)" license = "MIT"