refactor: + narrower interface for gc pointer forwarding

add AGCObjectVisitor, instead of requiring ACollector.
This commit is contained in:
Roland Conybeare 2026-04-05 23:53:02 -04:00
commit 72cbffba46
8 changed files with 25 additions and 15 deletions

View file

@ -7,6 +7,7 @@
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
#include <string_view>
@ -47,6 +48,8 @@ namespace xo {
using AAllocator = xo::mm::AAllocator;
/** garbage collector **/
using ACollector = xo::mm::ACollector;
/** object visitor (garbage collector proxy) **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** ppindentinfo for APrintable **/
using ppindentinfo = xo::print::ppindentinfo;
///@}
@ -247,10 +250,10 @@ namespace xo {
/** clone string, using memory from allocator @p mm **/
DString * shallow_move(obj<ACollector> gc) noexcept;
size_type forward_children(obj<ACollector> gc) noexcept;
/** fixup child pointers (trivial for DString, no children)
* note: cref so we can use forward decl
**/
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}

View file

@ -27,6 +27,7 @@ namespace xo {
public:
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using size_type = DString::size_type;
using ppindentinfo = xo::print::ppindentinfo;
@ -92,7 +93,7 @@ namespace xo {
DUniqueString * shallow_move(obj<ACollector> gc) noexcept;
/** fixup child pointers (trivial for DUniqueString, no gc-owned children **/
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}

View file

@ -44,6 +44,7 @@ namespace xo {
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
using Copaque = xo::mm::AGCObject::Copaque;
using Opaque = xo::mm::AGCObject::Opaque;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DString & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DString & self, obj<ACollector> gc) noexcept;
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
Context: provides address of data pointer so it can be updated in place
when @p fn invokes garbage collector reentry point **/
static void visit_gco_children(DString & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -44,6 +44,7 @@ namespace xo {
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
using Copaque = xo::mm::AGCObject::Copaque;
using Opaque = xo::mm::AGCObject::Opaque;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DUniqueString & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DUniqueString & self, obj<ACollector> gc) noexcept;
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
Context: provides address of data pointer so it can be updated in place
when @p fn invokes garbage collector reentry point **/
static void visit_gco_children(DUniqueString & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};