refactor: use GCObjectVisitor api w/ gco_shallow_move

This commit is contained in:
Roland Conybeare 2026-04-06 15:21:48 -04:00
commit 3489699f5d
8 changed files with 51 additions and 15 deletions

View file

@ -64,11 +64,14 @@
nonconst_methods: [
// Opaque shallow_move(obj<ACollector>) noexcept
{
name: "shallow_move",
doc: ["move instance using collector"],
name: "gco_shallow_move",
doc: [
"move instance using object visitor.",
"Arguably abusing the word 'visitor' here",
],
return_type: "Opaque",
args:[
{type: "obj<ACollector>", name: "gc"},
{type: "obj<AGCObjectVisitor>", name: "gc"},
],
const: true,
noexcept: true,

View file

@ -88,9 +88,25 @@
},
],
router_facet_explicit_content: [
"/** convenience: allocate copy for typed pointer **/",
"template <typename T>",
"void * alloc_copy_for(const T * src) noexcept {",
" return O::iface()->alloc_copy(O::data(), (std::byte *)const_cast<T *>(src));",
"}",
"",
"/** visit forward faceted object child pointer in place.",
" Defined in RGCObject.hpp to avoid #include cycle",
"/** convenience: move typed pointer **/",
"template <typename T>",
"T * std_move_for(T * src) noexcept {",
" void * mem = this->alloc_copy_for(src);",
" if (mem) {",
" return new (mem) T(std::move(*src));",
" }",
" return nullptr;",
"}",
"",
"/** visit a gcobject child pointer in place.",
" Defined in RCollector_aux.hpp to avoid #include cycle",
" (for historical reasons - coul d be in RGCObject_aux.hpp?)",
" **/",
"template <typename DRepr>",
"void visit_child(xo::facet::obj<AGCObject,DRepr> * p_obj);",

View file

@ -67,8 +67,9 @@ public:
virtual void _drop(Opaque d) const noexcept = 0;
// nonconst methods
/** move instance using collector **/
virtual Opaque shallow_move(Opaque data, obj<ACollector> gc) const noexcept = 0;
/** move instance using object visitor.
Arguably abusing the word 'visitor' here **/
virtual Opaque gco_shallow_move(Opaque data, obj<AGCObjectVisitor> gc) const noexcept = 0;
/** 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 **/

View file

@ -64,7 +64,7 @@ namespace mm {
// const methods
// nonconst methods
[[noreturn]] Opaque shallow_move(Opaque, obj<ACollector>) const noexcept override;
[[noreturn]] Opaque gco_shallow_move(Opaque, obj<AGCObjectVisitor>) const noexcept override;
[[noreturn]] void visit_gco_children(Opaque, obj<AGCObjectVisitor>) const noexcept override;
///@}

View file

@ -53,8 +53,8 @@ namespace mm {
// const methods
// non-const methods
Opaque shallow_move(Opaque data, obj<ACollector> gc) const noexcept override {
return I::shallow_move(_dcast(data), gc);
Opaque gco_shallow_move(Opaque data, obj<AGCObjectVisitor> gc) const noexcept override {
return I::gco_shallow_move(_dcast(data), gc);
}
void visit_gco_children(Opaque data, obj<AGCObjectVisitor> fn) const noexcept override {
return I::visit_gco_children(_dcast(data), fn);

View file

@ -58,8 +58,8 @@ public:
// const methods
// non-const methods (still const in router!)
Opaque shallow_move(obj<ACollector> gc) noexcept {
return O::iface()->shallow_move(O::data(), gc);
Opaque gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept {
return O::iface()->gco_shallow_move(O::data(), gc);
}
void visit_gco_children(obj<AGCObjectVisitor> fn) noexcept {
return O::iface()->visit_gco_children(O::data(), fn);

View file

@ -46,9 +46,25 @@ public:
///@{
// explicit injected content
/** convenience: allocate copy for typed pointer **/
template <typename T>
void * alloc_copy_for(const T * src) noexcept {
return O::iface()->alloc_copy(O::data(), (std::byte *)const_cast<T *>(src));
}
/** visit forward faceted object child pointer in place.
Defined in RGCObject.hpp to avoid #include cycle
/** convenience: move typed pointer **/
template <typename T>
T * std_move_for(T * src) noexcept {
void * mem = this->alloc_copy_for(src);
if (mem) {
return new (mem) T(std::move(*src));
}
return nullptr;
}
/** visit a gcobject child pointer in place.
Defined in RCollector_aux.hpp to avoid #include cycle
(for historical reasons - coul d be in RGCObject_aux.hpp?)
**/
template <typename DRepr>
void visit_child(xo::facet::obj<AGCObject,DRepr> * p_obj);

View file

@ -36,7 +36,7 @@ IGCObject_Any::_valid
// nonconst methods
auto
IGCObject_Any::shallow_move(Opaque, obj<ACollector>) const noexcept -> Opaque
IGCObject_Any::gco_shallow_move(Opaque, obj<AGCObjectVisitor>) const noexcept -> Opaque
{
_fatal();
}