xo-alloc2: bugfix for DX1CollectorIterator
This commit is contained in:
parent
4fb50592ac
commit
eb8b89450f
6 changed files with 73 additions and 5 deletions
|
|
@ -16,6 +16,14 @@ namespace xo {
|
|||
incomparable = 1,
|
||||
};
|
||||
|
||||
extern const char * comparison2str(comparison x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os, comparison x) {
|
||||
os << comparison2str(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
struct cmpresult {
|
||||
cmpresult() : err_{comparison::invalid}, cmp_{0} {}
|
||||
cmpresult(comparison err, std::int16_t cmp) : err_{err}, cmp_{cmp} {}
|
||||
|
|
@ -35,6 +43,8 @@ namespace xo {
|
|||
return cmpresult::greater();
|
||||
}
|
||||
|
||||
/** print to stream **/
|
||||
void display(std::ostream & os) const;
|
||||
|
||||
bool is_equal() const { return (err_ == comparison::comparable) && (cmp_ == 0); }
|
||||
|
||||
|
|
@ -50,7 +60,8 @@ namespace xo {
|
|||
inline std::ostream & operator<<(std::ostream & os,
|
||||
const cmpresult & x)
|
||||
{
|
||||
os << "<cmpresult " << xtag("err", x.err_) << xtag("cmp", x.cmp_) << ">";
|
||||
x.display(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ set(SELF_LIB xo_alloc2)
|
|||
set(SELF_SRCS
|
||||
|
||||
AllocInfo.cpp
|
||||
cmpresult.cpp
|
||||
|
||||
AAllocator.cpp
|
||||
DArena.cpp
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ namespace xo {
|
|||
cmpresult
|
||||
DArenaIterator::compare(const DArenaIterator & other_ix) const noexcept
|
||||
{
|
||||
scope log(XO_DEBUG(false),
|
||||
xtag("arena", arena_),
|
||||
xtag("pos", pos_),
|
||||
xtag("other.arena", other_ix.arena_),
|
||||
xtag("other.pos", other_ix.pos_));
|
||||
|
||||
if (is_invalid() || (arena_ != other_ix.arena_))
|
||||
return cmpresult::incomparable();
|
||||
|
||||
|
|
|
|||
|
|
@ -238,11 +238,21 @@ namespace xo {
|
|||
DX1Collector::end() const noexcept {
|
||||
generation gen_hi = generation{config_.n_generation_};
|
||||
|
||||
/** valid iterator for end points to end of last DArena.
|
||||
* otherwise will interfere with working compare
|
||||
* (since invalid iterators are incomparable)
|
||||
**/
|
||||
|
||||
const DArena * arena
|
||||
= get_space(role::to_space(),
|
||||
generation(config_.n_generation_ - 1));
|
||||
DArenaIterator arena_end = arena->end();
|
||||
|
||||
return DX1CollectorIterator(this,
|
||||
gen_hi,
|
||||
gen_hi,
|
||||
DArenaIterator(),
|
||||
DArenaIterator());
|
||||
arena_end,
|
||||
arena_end);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace xo {
|
|||
cmpresult
|
||||
DX1CollectorIterator::compare(const DX1CollectorIterator & other_ix) const noexcept
|
||||
{
|
||||
scope log(XO_DEBUG(true),
|
||||
scope log(XO_DEBUG(false),
|
||||
xtag("is_valid", is_valid()),
|
||||
xtag("other_ix.is_valid", other_ix.is_valid()) );
|
||||
|
||||
|
|
@ -71,7 +71,11 @@ namespace xo {
|
|||
/* both iterators refer to the same arena,
|
||||
* so can compare their arena iterators directly
|
||||
*/
|
||||
return arena_ix_.compare(other_ix.arena_ix_);
|
||||
cmpresult retval = arena_ix_.compare(other_ix.arena_ix_);
|
||||
|
||||
log && log(xtag("retval", retval));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
36
xo-alloc2/src/alloc2/cmpresult.cpp
Normal file
36
xo-alloc2/src/alloc2/cmpresult.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/** @file cmpresult.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "cmpresult.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
const char *
|
||||
comparison2str(comparison x)
|
||||
{
|
||||
switch (x) {
|
||||
case comparison::invalid:
|
||||
return "?comparison";
|
||||
case comparison::comparable:
|
||||
return "cmp";
|
||||
case comparison::incomparable:
|
||||
return "!cmp";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cmpresult::display(std::ostream & os) const
|
||||
{
|
||||
os << "<cmpresult "
|
||||
<< xtag("err", err_)
|
||||
<< xtag("cmp", cmp_)
|
||||
<< ">";
|
||||
}
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end cmpresult.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue