Skip to content

Commit

Permalink
Add requirement to erase to have the target already inserted
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Nov 2, 2024
1 parent 40c2fbe commit f8c3eb4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.255_amd64.deb
sudo apt install build/meevax_0.5.256_amd64.deb
```

or
Expand Down Expand Up @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.255.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.256.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.255_amd64.deb`
| `package` | Generate debian package `meevax_0.5.256_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.255
0.5.256
38 changes: 29 additions & 9 deletions include/meevax/memory/collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ inline namespace memory

auto operator delete(void * data) noexcept -> void
{
using pointer = typename std::allocator_traits<allocator_type>::pointer;
allocator.deallocate(reinterpret_cast<pointer>(data), 1);
allocator.deallocate(reinterpret_cast<typename std::allocator_traits<allocator_type>::pointer>(data), 1);
}
};

Expand All @@ -188,6 +187,7 @@ inline namespace memory
{
if (*this)
{
assert(not mutators.contains(this));
mutators.insert(this);
}
}
Expand All @@ -197,6 +197,7 @@ inline namespace memory
{
if (top)
{
assert(not mutators.contains(this));
mutators.insert(this);
}
}
Expand All @@ -210,8 +211,9 @@ inline namespace memory

~mutator()
{
if (not cleared)
if (pointer::operator bool() and not cleared)
{
assert(mutators.contains(this));
mutators.erase(this);
}
}
Expand All @@ -228,22 +230,38 @@ inline namespace memory
return *this;
}

auto reset(mutator const& other) -> void
auto reset(mutator const& after) -> void
{
if (pointer::reset(other); other)
auto const before = pointer::operator bool();

pointer::reset(after);

if (before)
{
mutators.insert(this);
if (not after)
{
assert(mutators.contains(this));
mutators.erase(this);
}
}
else
else if (after)
{
mutators.erase(this);
assert(not mutators.contains(this));
mutators.insert(this);
}
}

auto reset(std::nullptr_t = nullptr) -> void
{
auto const before = pointer::operator bool();

pointer::reset();
mutators.erase(this);

if (before)
{
assert(mutators.contains(this));
mutators.erase(this);
}
}

template <typename U>
Expand Down Expand Up @@ -449,6 +467,7 @@ inline namespace memory
for (auto&& object : objects)
{
delete object;
assert(objects.contains(object));
objects.erase(object);
}
}
Expand Down Expand Up @@ -581,6 +600,7 @@ inline namespace memory
{
for (auto marked_object : marked_objects)
{
assert(objects.contains(marked_object));
objects.erase(marked_object);
}

Expand Down
12 changes: 2 additions & 10 deletions include/meevax/memory/integer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,8 @@ inline namespace memory
template <typename... Ts>
auto erase(std::size_t i, Ts&&... xs) noexcept
{
/*
Somewhere there is code that tries to remove an element that was not
inserted, which would imply wasteful work.
*/
// assert(data[i]);

if (data[i]) // TODO REMOVE THIS CHECK
{
data[i]->erase(std::forward<decltype(xs)>(xs)...);
}
assert(data[i]);
data[i]->erase(std::forward<decltype(xs)>(xs)...);
}

auto erase(T value) noexcept
Expand Down
38 changes: 18 additions & 20 deletions include/meevax/memory/nan_boxing_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,24 @@ inline namespace memory

constexpr nan_boxing_pointer(nan_boxing_pointer const&) = default;

auto reset(nan_boxing_pointer const& value) -> void
{
data = value.data;
}

#define DEFINE(TYPE, ...) \
explicit nan_boxing_pointer(TYPE const& value __VA_ARGS__) noexcept \
: data { reinterpret_cast<pointer>( \
signature_##TYPE | bit_cast<uintN_t<sizeof(TYPE)>>(value)) } \
: data { reinterpret_cast<pointer>(signature_##TYPE | bit_cast<uintN_t<sizeof(TYPE)>>(value)) } \
{} \
\
auto reset(TYPE const& value __VA_ARGS__) noexcept -> void \
{ \
data = reinterpret_cast<pointer>( \
signature_##TYPE | bit_cast<uintN_t<sizeof(TYPE)>>(value)); \
} static_assert(true)

DEFINE(double, );
DEFINE(T1, );
DEFINE(T2, );
DEFINE(T3, );
DEFINE(T4, );
DEFINE(T5, );
DEFINE(T6, );
DEFINE(pointer, = nullptr);
data = reinterpret_cast<pointer>(signature_##TYPE | bit_cast<uintN_t<sizeof(TYPE)>>(value)); \
}

DEFINE(double, )
DEFINE(T1, )
DEFINE(T2, )
DEFINE(T3, )
DEFINE(T4, )
DEFINE(T5, )
DEFINE(T6, )
DEFINE(pointer, = nullptr)

#undef DEFINE

Expand Down Expand Up @@ -126,7 +119,7 @@ inline namespace memory

explicit operator bool() const noexcept
{
return get() != nullptr;
return dereferenceable() ? unsafe_get() != nullptr : false;
}

template <typename U>
Expand Down Expand Up @@ -163,6 +156,11 @@ inline namespace memory
return type() == typeid(std::decay_t<U>);
}

auto reset(nan_boxing_pointer const& value) -> void
{
data = value.data;
}

auto payload() const noexcept
{
return reinterpret_cast<std::uintptr_t>(data) & mask_payload;
Expand Down

0 comments on commit f8c3eb4

Please sign in to comment.