Skip to content

Commit

Permalink
#2063: Update char* to std::byte* in pool_header
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable authored and cwschilly committed Sep 20, 2024
1 parent 8739ed7 commit c66d6e5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/vt/pool/header/pool_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

namespace vt { namespace pool {

/*static*/ char* HeaderManager::setHeader(
size_t const& num_bytes, size_t const& oversize, char* buffer
/*static*/ std::byte* HeaderManager::setHeader(
size_t const& num_bytes, size_t const& oversize, std::byte* buffer
) {
AllocView view;
view.buffer = buffer;
Expand All @@ -58,19 +58,19 @@ namespace vt { namespace pool {
return buf_start;
}

/*static*/ size_t HeaderManager::getHeaderBytes(char* buffer) {
/*static*/ size_t HeaderManager::getHeaderBytes(std::byte* buffer) {
AllocView view;
view.buffer = buffer - sizeof(Header);
return view.layout->prealloc.alloc_size;
}

/*static*/ size_t HeaderManager::getHeaderOversizeBytes(char* buffer) {
/*static*/ size_t HeaderManager::getHeaderOversizeBytes(std::byte* buffer) {
AllocView view;
view.buffer = buffer - sizeof(Header);
return view.layout->prealloc.oversize;
}

/*static*/ char* HeaderManager::getHeaderPtr(char* buffer) {
/*static*/ std::byte* HeaderManager::getHeaderPtr(std::byte* buffer) {
return buffer - sizeof(Header);
}

Expand Down
12 changes: 6 additions & 6 deletions src/vt/pool/header/pool_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ struct AllocLayout {

union AllocView {
AllocLayout* layout;
char* buffer;
std::byte* buffer;
};

struct HeaderManager {
static char* setHeader(
size_t const& num_bytes, size_t const& oversize, char* buffer
static std::byte* setHeader(
size_t const& num_bytes, size_t const& oversize, std::byte* buffer
);
static size_t getHeaderBytes(char* buffer);
static size_t getHeaderOversizeBytes(char* buffer);
static char* getHeaderPtr(char* buffer);
static size_t getHeaderBytes(std::byte* buffer);
static size_t getHeaderOversizeBytes(std::byte* buffer);
static std::byte* getHeaderPtr(std::byte* buffer);
};

}} /* end namespace vt::pool */
Expand Down
26 changes: 13 additions & 13 deletions src/vt/pool/pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void* Pool::tryPooledAlloc(size_t const& num_bytes, size_t const& oversize) {
}

bool Pool::tryPooledDealloc(void* const buf) {
auto buf_char = static_cast<char*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_char);
auto const& oversize = HeaderManagerType::getHeaderOversizeBytes(buf_char);
auto buf_byte = reinterpret_cast<std::byte*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_byte);
auto const& oversize = HeaderManagerType::getHeaderOversizeBytes(buf_byte);
ePoolSize const pool_type = getPoolType(actual_alloc_size, oversize);

if (pool_type != ePoolSize::Malloc) {
Expand Down Expand Up @@ -147,7 +147,7 @@ void Pool::poolDealloc(void* const buf, ePoolSize const pool_type) {
void* Pool::defaultAlloc(size_t const& num_bytes, size_t const& oversize) {
auto alloc_buf = std::malloc(num_bytes + oversize + sizeof(HeaderType));
return HeaderManagerType::setHeader(
num_bytes, oversize, static_cast<char*>(alloc_buf)
num_bytes, oversize, reinterpret_cast<std::byte*>(alloc_buf)
);
}

Expand Down Expand Up @@ -178,9 +178,9 @@ void* Pool::alloc(size_t const& num_bytes, size_t oversize) {
}

void Pool::dealloc(void* const buf) {
auto buf_char = static_cast<char*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_char);
auto const& ptr_actual = HeaderManagerType::getHeaderPtr(buf_char);
auto buf_byte = reinterpret_cast<std::byte*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_byte);
auto const& ptr_actual = HeaderManagerType::getHeaderPtr(buf_byte);

vt_debug_print(
normal, pool,
Expand All @@ -201,9 +201,9 @@ void Pool::dealloc(void* const buf) {

Pool::SizeType Pool::remainingSize(void* const buf) const {
#if vt_check_enabled(memory_pool)
auto buf_char = static_cast<char*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_char);
auto const& oversize = HeaderManagerType::getHeaderOversizeBytes(buf_char);
auto buf_byte = reinterpret_cast<std::byte*>(buf);
auto const& actual_alloc_size = HeaderManagerType::getHeaderBytes(buf_byte);
auto const& oversize = HeaderManagerType::getHeaderOversizeBytes(buf_byte);

ePoolSize const pool_type = getPoolType(actual_alloc_size, oversize);

Expand All @@ -220,8 +220,8 @@ Pool::SizeType Pool::remainingSize(void* const buf) const {
}

Pool::SizeType Pool::allocatedSize(void* const buf) const {
auto buf_char = static_cast<char*>(buf);
return HeaderManagerType::getHeaderBytes(buf_char) + HeaderManagerType::getHeaderOversizeBytes(buf_char);
auto buf_byte = reinterpret_cast<std::byte*>(buf);
return HeaderManagerType::getHeaderBytes(buf_byte) + HeaderManagerType::getHeaderOversizeBytes(buf_byte);
}

bool
Expand All @@ -231,7 +231,7 @@ Pool::tryGrowAllocation(void* buf, size_t grow_amount) {
if ( remainingSize(buf) < grow_amount )
return false;

auto *header = reinterpret_cast<Header*>(HeaderManagerType::getHeaderPtr(reinterpret_cast<char*>(buf)));
auto *header = reinterpret_cast<Header*>(HeaderManagerType::getHeaderPtr(reinterpret_cast<std::byte*>(buf)));
header->alloc_size += grow_amount;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vt/pool/static_sized/memory_pool_equal.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void* MemoryPoolEqual<num_bytes_t, use_header>::alloc(
void* ptr_ret = ptr;
if (use_header) {
ptr_ret = HeaderManagerType::setHeader(
sz, oversize, static_cast<char*>(ptr)
sz, oversize, reinterpret_cast<std::byte*>(ptr)
);
}

Expand All @@ -124,7 +124,7 @@ void MemoryPoolEqual<num_bytes_t, use_header>::dealloc(void* const t) {
cur_slot_ - 1 >= 0, "Must be greater than zero"
);

auto t_char = static_cast<char*>(t);
auto t_char = reinterpret_cast<std::byte*>(t);
void* ptr_actual = t;
if (use_header) {
ptr_actual = HeaderManagerType::getHeaderPtr(t_char);
Expand Down

0 comments on commit c66d6e5

Please sign in to comment.