Add and plumb unsafe_{to,from}_uintptr<T> casts
These encapsulate the wildly powerful reinterpret_cast<> operator where one side is a uintptr_t and the other is a native pointer. In both cases we require the pointer type to be explicitly given.
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
4ad99d7392
commit
26324e8bfc
@@ -20,7 +20,7 @@ int main()
|
||||
auto& global = GlobalChunkmap::pagemap();
|
||||
SNMALLOC_CHECK(&p == &global);
|
||||
// Get a valid heap address
|
||||
uintptr_t addr = reinterpret_cast<uintptr_t>(malloc(42));
|
||||
uintptr_t addr = unsafe_to_uintptr<void>(malloc(42));
|
||||
// Make this very strongly aligned
|
||||
addr &= ~0xfffffULL;
|
||||
void* page = p.page_for_address(addr);
|
||||
|
||||
@@ -212,7 +212,7 @@ int main(int argc, char** argv)
|
||||
//
|
||||
// Note: We cannot use the check or assert macros here because they depend on
|
||||
// `MessageBuilder` working. They are safe to use in any other test.
|
||||
void* fakeptr = reinterpret_cast<void*>(static_cast<uintptr_t>(0x42));
|
||||
void* fakeptr = unsafe_from_uintptr<void>(static_cast<uintptr_t>(0x42));
|
||||
MessageBuilder<1024> b{
|
||||
"testing pointer {} size_t {} message, {} world, null is {}, -123456 is "
|
||||
"{}, 1234567 is {}",
|
||||
|
||||
Reference in New Issue
Block a user