Removing some casts and uses of void*

This commit is contained in:
Matthew Parkinson
2019-04-25 10:19:42 +01:00
committed by Matthew Parkinson
parent 2c613b4f8a
commit 47428a096c
4 changed files with 11 additions and 12 deletions

View File

@@ -445,7 +445,7 @@ namespace snmalloc
}
else if (size == PMMediumslab)
{
Mediumslab* slab = (Mediumslab*)super;
Mediumslab* slab = Mediumslab::get(p);
RemoteAllocator* target = slab->get_allocator();
// Reading a remote sizeclass won't fail, since the other allocator
@@ -460,7 +460,7 @@ namespace snmalloc
}
# ifndef SNMALLOC_SAFE_CLIENT
if (size > 64 || (void*)super != p)
if (size > 64 || (uintptr_t)super != (uintptr_t)p)
{
error("Not deallocating start of an object");
}
@@ -491,7 +491,7 @@ namespace snmalloc
}
else if (size == PMMediumslab)
{
Mediumslab* slab = (Mediumslab*)super;
Mediumslab* slab = Mediumslab::get(p);
uint8_t sc = slab->get_sizeclass();
size_t slab_end = (size_t)slab + SUPERSLAB_SIZE;
@@ -550,11 +550,9 @@ namespace snmalloc
}
else if (size == PMMediumslab)
{
Superslab* super = Superslab::get(p);
Mediumslab * slab = Mediumslab::get(p);
// Reading a remote sizeclass won't fail, since the other allocator
// can't reuse the slab, as we have no yet deallocated this pointer.
Mediumslab* slab = (Mediumslab*)super;
return sizeclass_to_size(slab->get_sizeclass());
}
@@ -972,7 +970,7 @@ namespace snmalloc
SlabLink* link = sc->get_head();
Slab* slab;
if (link != (SlabLink*)~0)
if ((uintptr_t)link != ~0ULL)
{
slab = link->get_slab();
}

View File

@@ -84,6 +84,8 @@ namespace snmalloc
;
// The remaining values are derived, not configurable.
static constexpr size_t POINTER_BITS =
bits::next_pow2_bits_const(sizeof(uintptr_t));
// Used to isolate values on cache lines to prevent false sharing.
static constexpr size_t CACHELINE_SIZE = 64;

View File

@@ -67,8 +67,8 @@ namespace snmalloc
if (size < SUPERSLAB_SIZE)
error("out of memory");
((PAL*)this)->template notify_using<NoZero>(r, OS_PAGE_SIZE);
PAL::template notify_using<NoZero>(r, OS_PAGE_SIZE);
bump = (size_t)r;
remaining = size;
}
@@ -166,8 +166,7 @@ namespace snmalloc
auto page_start = bits::align_down((size_t)p, OS_PAGE_SIZE);
auto page_end = bits::align_up((size_t)p + size, OS_PAGE_SIZE);
((PAL*)this)
->template notify_using<NoZero>(
PAL::template notify_using<NoZero>(
(void*)page_start, page_end - page_start);
return p;

View File

@@ -158,7 +158,7 @@ extern "C"
void** memptr, size_t alignment, size_t size)
{
if (
((alignment % sizeof(void*)) != 0) ||
((alignment % sizeof(uintptr_t)) != 0) ||
((alignment & (alignment - 1)) != 0) || (alignment == 0))
{
return EINVAL;