Skip to content

Commit f26d146

Browse files
committed
Change remaining_bytes API to take const void* instead of address_t
Add a const void* overload of remaining_bytes alongside the existing address_t version. The testlib API uses const void* so callers don't need address_cast or ds_aal headers. Remove address_t from testlib.h. This makes memory.cc a testlib-only test (no ds_aal.h needed), adding it to the compile-once list.
1 parent c4f359d commit f26d146

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
483483
# These are mitigation-independent and can be compiled once, then linked
484484
# against both fast and check testlib variants.
485485
set(TESTLIB_ONLY_TESTS
486-
bits first_operation memory_usage multi_atexit multi_threadatexit
486+
bits first_operation memory memory_usage multi_atexit multi_threadatexit
487487
redblack statistics teardown
488488
contention external_pointer large_alloc lotsofthreads post_teardown
489489
singlethread startup

src/snmalloc/global/globalalloc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ namespace snmalloc
151151
return snmalloc::remaining_bytes(sizeclass, p);
152152
}
153153

154+
template<SNMALLOC_CONCEPT(IsConfig) Config_ = Config>
155+
size_t SNMALLOC_FAST_PATH_INLINE remaining_bytes(const void* p)
156+
{
157+
return remaining_bytes<Config_>(address_cast(p));
158+
}
159+
154160
/**
155161
* Returns the byte offset into an object.
156162
*

src/test/func/memory/memory.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <array>
22
#include <chrono>
33
#include <iostream>
4-
#include <snmalloc/ds_aal/ds_aal.h>
54
#include <test/opt.h>
65
#include <test/setup.h>
76
#include <test/snmalloc_testlib.h>
@@ -494,8 +493,7 @@ void test_remaining_bytes()
494493
char* p = (char*)snmalloc::alloc(size);
495494
for (size_t offset = 0; offset < size; offset++)
496495
{
497-
auto rem = snmalloc::remaining_bytes(
498-
address_cast(pointer_offset(p, offset)));
496+
auto rem = snmalloc::remaining_bytes(pointer_offset(p, offset));
499497
if (rem != (size - offset))
500498
{
501499
if (rem < (size - offset) || snmalloc::is_owned(p))

src/test/snmalloc_testlib.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace snmalloc
5858
return alloc_size<Config>(p);
5959
}
6060

61-
size_t remaining_bytes(address_t p)
61+
size_t remaining_bytes(const void* p)
6262
{
6363
return remaining_bytes<Config>(p);
6464
}

src/test/snmalloc_testlib.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
namespace snmalloc
2424
{
25-
// Forward declarations sufficient for the API surface.
26-
// address_t: uintptr_t on all non-CHERI platforms.
27-
using address_t = uintptr_t;
28-
2925
template<ZeroMem>
3026
class DefaultConts;
3127
// Uninit / Zero are usable as template arguments even without the full
@@ -55,7 +51,7 @@ namespace snmalloc
5551

5652
// -- Non-template wrappers for Config-templated functions ----------------
5753
size_t alloc_size(const void* p);
58-
size_t remaining_bytes(address_t p);
54+
size_t remaining_bytes(const void* p);
5955
bool is_owned(void* p);
6056
void debug_check_empty(bool* result = nullptr);
6157
void debug_in_use(size_t count);

0 commit comments

Comments
 (0)