From cb0add52df9da75a27c11974ac85862fb4a938b0 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 21 Dec 2025 16:20:13 -0500 Subject: [PATCH] xo-alloc2: working operator* for AAllocIterator --- .../include/xo/alloc2/alloc/RAllocIterator.hpp | 2 ++ .../src/alloc2/IAllocIterator_DArenaIterator.cpp | 2 +- .../IAllocIterator_DX1CollectorIterator.cpp | 2 +- xo-alloc2/utest/DArenaIterator.test.cpp | 16 ++++++++++++++++ xo-alloc2/utest/DX1CollectorIterator.test.cpp | 16 ++++++++++++++++ xo-facet/include/xo/facet/OObject.hpp | 2 ++ xo-facet/include/xo/facet/obj.hpp | 6 ++++++ xo-facet/utest/objectmodel.test.cpp | 2 +- 8 files changed, 45 insertions(+), 3 deletions(-) diff --git a/xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp b/xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp index 6a14218e..73602cc5 100644 --- a/xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp +++ b/xo-alloc2/include/xo/alloc2/alloc/RAllocIterator.hpp @@ -27,6 +27,8 @@ namespace xo { return O::iface()->compare(O::data(), other); } void next() noexcept { O::iface()->next(O::data()); } + AllocInfo operator*() const noexcept { return deref(); } + /** triggers operator++ in obj> **/ void _preincrement() noexcept { this->next(); } diff --git a/xo-alloc2/src/alloc2/IAllocIterator_DArenaIterator.cpp b/xo-alloc2/src/alloc2/IAllocIterator_DArenaIterator.cpp index cfb9a343..dc0e1bc4 100644 --- a/xo-alloc2/src/alloc2/IAllocIterator_DArenaIterator.cpp +++ b/xo-alloc2/src/alloc2/IAllocIterator_DArenaIterator.cpp @@ -32,7 +32,7 @@ namespace xo { if (!other) return cmpresult::incomparable(); - DArenaIterator & other_ix = *other; + DArenaIterator & other_ix = *other.data(); log && log(xtag("&other_ix", &other_ix), xtag("other_ix.arena", other_ix.arena_), diff --git a/xo-alloc2/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp b/xo-alloc2/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp index 2cb22e34..85609f1e 100644 --- a/xo-alloc2/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp +++ b/xo-alloc2/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp @@ -25,7 +25,7 @@ namespace xo { if (!other) return cmpresult::incomparable(); - DX1CollectorIterator & other_ix = *other; + DX1CollectorIterator & other_ix = *other.data(); return ix.compare(other_ix); } diff --git a/xo-alloc2/utest/DArenaIterator.test.cpp b/xo-alloc2/utest/DArenaIterator.test.cpp index a42fc460..a5850710 100644 --- a/xo-alloc2/utest/DArenaIterator.test.cpp +++ b/xo-alloc2/utest/DArenaIterator.test.cpp @@ -269,6 +269,22 @@ namespace xo { REQUIRE(ix == end_ix); } } + + // repeat, this time using range iteration + { + DArena scratch_mm + = DArena::map( + ArenaConfig{ + .size_ = 4*1024, + .hugepage_z_ = 4*1024}); + + for (const auto & info : a1o.alloc_range(scratch_mm)) { + REQUIRE(info.is_valid()); + REQUIRE(info.size() == padding::with_padding(req_z)); + REQUIRE(info.payload().first == mem); + REQUIRE(info.payload().second == mem + info.size()); + } + } } } /*namespace ut*/ diff --git a/xo-alloc2/utest/DX1CollectorIterator.test.cpp b/xo-alloc2/utest/DX1CollectorIterator.test.cpp index 941d1d00..3ae405ee 100644 --- a/xo-alloc2/utest/DX1CollectorIterator.test.cpp +++ b/xo-alloc2/utest/DX1CollectorIterator.test.cpp @@ -198,6 +198,22 @@ namespace xo { REQUIRE(ix == end_ix); } } + + // repeat, this time using range iteration + { + DArena scratch_mm + = DArena::map( + ArenaConfig{ + .size_ = 4*1024, + .hugepage_z_ = 4*1024}); + + for (const auto & info : a1o.alloc_range(scratch_mm)) { + REQUIRE(info.is_valid()); + REQUIRE(info.size() == padding::with_padding(req_z)); + REQUIRE(info.payload().first == mem); + REQUIRE(info.payload().second == mem + info.size()); + } + } } } /*namespace ut*/ } /*namespace xo*/ diff --git a/xo-facet/include/xo/facet/OObject.hpp b/xo-facet/include/xo/facet/OObject.hpp index 0b7e34cc..0a92a4a4 100644 --- a/xo-facet/include/xo/facet/OObject.hpp +++ b/xo-facet/include/xo/facet/OObject.hpp @@ -235,7 +235,9 @@ namespace xo { //iface_ = *std::launder(&iface_); } +#ifdef NOPE DRepr & operator*() { return *data_; } +#endif OObject & operator=(const OObject & oother) { if (this != &oother) { diff --git a/xo-facet/include/xo/facet/obj.hpp b/xo-facet/include/xo/facet/obj.hpp index e514b5bc..6a0aa577 100644 --- a/xo-facet/include/xo/facet/obj.hpp +++ b/xo-facet/include/xo/facet/obj.hpp @@ -96,6 +96,12 @@ namespace xo { return obj(other.template downcast()); } + /** enabled when RRouter provides _preincrement. + * Note we don't need this trick for comparison operators, + * since return type is fixed. + * + * For example see comparison overloads in RAllocIterator.hpp + **/ obj & operator++() noexcept { this->_preincrement(); return *this; } }; diff --git a/xo-facet/utest/objectmodel.test.cpp b/xo-facet/utest/objectmodel.test.cpp index afb27c13..fbeb9440 100644 --- a/xo-facet/utest/objectmodel.test.cpp +++ b/xo-facet/utest/objectmodel.test.cpp @@ -380,7 +380,7 @@ namespace xo { REQUIRE(z1o.argument() == 0.25 * std::numbers::pi); REQUIRE(z1o.magnitude() == 1.0); - *z1o = z1; + *z1o.data() = z1; REQUIRE(z1o.data() == &z2); REQUIRE(z1o.xcoord() == 1.0);