@@ -305,6 +305,9 @@ class type_caster<std::shared_ptr<HeldByDefaultHolder>>
305
305
#endif
306
306
307
307
TEST_SUBMODULE (smart_ptr, m) {
308
+ // Please do not interleave `struct` and `class` definitions with bindings code,
309
+ // but implement `struct`s and `class`es in the anonymous namespace above.
310
+ // This helps keeping the smart_holder branch in sync with master.
308
311
309
312
// test_smart_ptr
310
313
@@ -361,11 +364,13 @@ TEST_SUBMODULE(smart_ptr, m) {
361
364
return good;
362
365
});
363
366
367
+ // test_unique_nodelete
364
368
py::class_<MyObject4, std::unique_ptr<MyObject4, py::nodelete>>(m, " MyObject4" )
365
369
.def (py::init<int >())
366
370
.def_readwrite (" value" , &MyObject4::value)
367
371
.def_static (" cleanup_all_instances" , &MyObject4::cleanupAllInstances);
368
372
373
+ // test_unique_deleter
369
374
py::class_<MyObject4a, std::unique_ptr<MyObject4a, py::nodelete>>(m, " MyObject4a" )
370
375
.def (py::init<int >())
371
376
.def_readwrite (" value" , &MyObject4a::value)
@@ -374,10 +379,12 @@ TEST_SUBMODULE(smart_ptr, m) {
374
379
py::class_<MyObject4b, MyObject4a, std::unique_ptr<MyObject4b>>(m, " MyObject4b" )
375
380
.def (py::init<int >());
376
381
382
+ // test_large_holder
377
383
py::class_<MyObject5, huge_unique_ptr<MyObject5>>(m, " MyObject5" )
378
384
.def (py::init<int >())
379
385
.def_readwrite (" value" , &MyObject5::value);
380
386
387
+ // test_shared_ptr_and_references
381
388
using A = SharedPtrRef::A;
382
389
py::class_<A, std::shared_ptr<A>>(m, " A" );
383
390
py::class_<SharedPtrRef, std::unique_ptr<SharedPtrRef>>(m, " SharedPtrRef" )
@@ -391,6 +398,7 @@ TEST_SUBMODULE(smart_ptr, m) {
391
398
.def (" set_ref" , [](SharedPtrRef &, const A &) { return true ; })
392
399
.def (" set_holder" , [](SharedPtrRef &, std::shared_ptr<A>) { return true ; });
393
400
401
+ // test_shared_ptr_from_this_and_references
394
402
using B = SharedFromThisRef::B;
395
403
py::class_<B, std::shared_ptr<B>>(m, " B" );
396
404
py::class_<SharedFromThisRef, std::unique_ptr<SharedFromThisRef>>(m, " SharedFromThisRef" )
@@ -405,14 +413,17 @@ TEST_SUBMODULE(smart_ptr, m) {
405
413
.def (" set_ref" , [](SharedFromThisRef &, const B &) { return true ; })
406
414
.def (" set_holder" , [](SharedFromThisRef &, std::shared_ptr<B>) { return true ; });
407
415
416
+ // Issue #865: shared_from_this doesn't work with virtual inheritance
408
417
static std::shared_ptr<SharedFromThisVirt> sft (new SharedFromThisVirt ());
409
418
py::class_<SharedFromThisVirt, std::shared_ptr<SharedFromThisVirt>>(m, " SharedFromThisVirt" )
410
419
.def_static (" get" , []() { return sft.get (); });
411
420
421
+ // test_move_only_holder
412
422
py::class_<C, custom_unique_ptr<C>>(m, " TypeWithMoveOnlyHolder" )
413
423
.def_static (" make" , []() { return custom_unique_ptr<C>(new C); })
414
424
.def_static (" make_as_object" , []() { return py::cast (custom_unique_ptr<C>(new C)); });
415
425
426
+ // test_holder_with_addressof_operator
416
427
using HolderWithAddressOf = shared_ptr_with_addressof_operator<TypeForHolderWithAddressOf>;
417
428
py::class_<TypeForHolderWithAddressOf, HolderWithAddressOf>(m, " TypeForHolderWithAddressOf" )
418
429
.def_static (" make" , []() { return HolderWithAddressOf (new TypeForHolderWithAddressOf); })
@@ -422,16 +433,20 @@ TEST_SUBMODULE(smart_ptr, m) {
422
433
.def (" print_object_3" , [](const HolderWithAddressOf &obj) { py::print (obj.get ()->toString ()); })
423
434
.def (" print_object_4" , [](const HolderWithAddressOf *obj) { py::print ((*obj).get ()->toString ()); });
424
435
436
+ // test_move_only_holder_with_addressof_operator
425
437
using MoveOnlyHolderWithAddressOf = unique_ptr_with_addressof_operator<TypeForMoveOnlyHolderWithAddressOf>;
426
438
py::class_<TypeForMoveOnlyHolderWithAddressOf, MoveOnlyHolderWithAddressOf>(m, " TypeForMoveOnlyHolderWithAddressOf" )
427
439
.def_static (" make" , []() { return MoveOnlyHolderWithAddressOf (new TypeForMoveOnlyHolderWithAddressOf (0 )); })
428
440
.def_readwrite (" value" , &TypeForMoveOnlyHolderWithAddressOf::value)
429
441
.def (" print_object" , [](const TypeForMoveOnlyHolderWithAddressOf *obj) { py::print (obj->toString ()); });
430
442
443
+ // test_smart_ptr_from_default
431
444
py::class_<HeldByDefaultHolder, std::unique_ptr<HeldByDefaultHolder>>(m, " HeldByDefaultHolder" )
432
445
.def (py::init<>())
433
446
.def_static (" load_shared_ptr" , [](std::shared_ptr<HeldByDefaultHolder>) {});
434
447
448
+ // test_shared_ptr_gc
449
+ // #187: issue involving std::shared_ptr<> return value policy & garbage collection
435
450
py::class_<ElementBase, std::shared_ptr<ElementBase>>(m, " ElementBase" );
436
451
437
452
py::class_<ElementA, ElementBase, std::shared_ptr<ElementA>>(m, " ElementA" )
0 commit comments