From 0a2dd316ee8ab97b5dfe951d271808cc4fb65a03 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 4 Dec 2025 21:31:55 -0500 Subject: [PATCH] xo-alloc/xo-ordinaltree: refactor rbtree Node alloc progress toward careful gc-aware assignment --- include/xo/allocutil/ObjectVisitor.hpp | 3 +- include/xo/allocutil/gc_allocator_traits.hpp | 61 +++++++++++++------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/include/xo/allocutil/ObjectVisitor.hpp b/include/xo/allocutil/ObjectVisitor.hpp index 08f01d2..df33687 100644 --- a/include/xo/allocutil/ObjectVisitor.hpp +++ b/include/xo/allocutil/ObjectVisitor.hpp @@ -36,7 +36,8 @@ namespace xo { **/ template class ObjectVisitor { - void forward_children(T & target, IAlloc * gc) { (void)target; (void)gc; } + void forward_children(T & target, + IAlloc * gc) { (void)target; (void)gc; } }; #define XO_TRIVIAL_OBJECT_VISITOR(TYPE) \ diff --git a/include/xo/allocutil/gc_allocator_traits.hpp b/include/xo/allocutil/gc_allocator_traits.hpp index 6ddda37..88ab33c 100644 --- a/include/xo/allocutil/gc_allocator_traits.hpp +++ b/include/xo/allocutil/gc_allocator_traits.hpp @@ -10,7 +10,36 @@ #include namespace xo { + class IObject; + namespace gc { + class IAlloc; + + /** object interface for allocators A that don't provide A::gc_object_interface. + * See gc_allocator_traits + **/ + struct FallbackObjectInterface { + /** see also IObject::_requires_gc_hooks **/ + static constexpr bool _requires_gc_hooks = false; + /** see also IObject::_requires_write_barrier **/ + static constexpr bool _requires_write_barrier = false; + + /** see also IObject::_gc_assign_member **/ + template + void _gc_assign_member(T ** lhs, + T * rhs, + AA & alloc) { + (void)alloc; + *lhs = rhs; + } + + virtual void display(std::ostream &) const {} + virtual bool _is_forwarded() const { return false; } + virtual std::size_t _shallow_size() const { assert(false); return 0; } + virtual IObject * _shallow_copy(gc::IAlloc *) const { assert(false); return nullptr; } + virtual std::size_t _forward_children(gc::IAlloc *) { assert(false); return 0; } + }; + /** Extended version of * std::allocator_traits * Introduces additional i/face methods @@ -140,26 +169,12 @@ namespace xo { // gc_allocator_traits::template object_interface // template - struct object_interface { - /** see also IObject::_requires_gc_hooks **/ - static constexpr bool _requires_gc_hooks = false; - /** see also IObject::_requires_write_barrier **/ - static constexpr bool _requires_write_barrier = false; + struct object_interface : public FallbackObjectInterface {}; - /** see also IObject::_gc_assign_member **/ - template - void _gc_assign_member(T ** lhs, - T * rhs, - A & alloc) - { - *lhs = rhs; - } - - virtual bool _is_forwarded() const { return false; } - virtual std::size_t _shallow_size() const { assert(false); return 0; } - }; - - // specialization when A provides gc_object_interface + // specialization when an allocator A + // (which will actuallly be Allocator via SFINAE) + // provides gc_object_interface + // template struct object_interface> : public A::gc_object_interface {}; @@ -179,7 +194,9 @@ namespace xo { * using has_incremental_gc_interface = std::true_type; * }; **/ - static inline constexpr bool has_incremental_gc_interface_v = has_incremental_gc_interface::value; + static inline constexpr + bool + has_incremental_gc_interface_v = has_incremental_gc_interface::value; /** true iff this allocator advertises trivial deallocate * Allocate will include: @@ -188,7 +205,9 @@ namespace xo { * using has_trivial_deallocate = std::true_type; * }; **/ - static inline constexpr bool has_trivial_deallocate_v = has_trivial_deallocate::value; + static inline constexpr + bool + has_trivial_deallocate_v = has_trivial_deallocate::value; }; } /*namespace gc*/ } /*namespace xo*/