use size_t in Allocator

This commit is contained in:
Joshua Warner 2014-05-19 18:39:10 -06:00
parent d92edcc36d
commit a1631c00f9
7 changed files with 40 additions and 34 deletions

View File

@ -18,10 +18,16 @@ namespace util {
class Allocator {
public:
// TODO: use size_t instead of unsigned
virtual void* tryAllocate(unsigned size) = 0;
virtual void* allocate(unsigned size) = 0;
virtual void free(const void* p, unsigned size) = 0;
// Returns null on failure
virtual void* tryAllocate(size_t size) = 0;
// Aborts on failure
virtual void* allocate(size_t size) = 0;
// By contract, size MUST be the original size of the allocated data, and p
// MUST point to the original base of the allocated data. No partial frees.
virtual void free(const void* p, size_t size) = 0;
};
} // namespace util

View File

@ -24,13 +24,13 @@ class FixedAllocator : public Allocator {
public:
FixedAllocator(Aborter* a, Slice<uint8_t> memory);
virtual void* tryAllocate(unsigned size);
virtual void* tryAllocate(size_t size);
void* allocate(unsigned size, unsigned padAlignment);
void* allocate(size_t size, unsigned padAlignment);
virtual void* allocate(unsigned size);
virtual void* allocate(size_t size);
virtual void free(const void* p, unsigned size);
virtual void free(const void* p, size_t size);
Aborter* a;
Slice<uint8_t> memory;

View File

@ -95,7 +95,7 @@ class Zone : public avian::util::Allocator {
}
}
virtual void* tryAllocate(unsigned size)
virtual void* tryAllocate(size_t size)
{
size = pad(size);
if (tryEnsure(size)) {
@ -107,7 +107,7 @@ class Zone : public avian::util::Allocator {
}
}
virtual void* allocate(unsigned size)
virtual void* allocate(size_t size)
{
size = pad(size);
void* p = tryAllocate(size);
@ -146,7 +146,7 @@ class Zone : public avian::util::Allocator {
segment = s;
}
virtual void free(const void*, unsigned)
virtual void free(const void*, size_t)
{
// not supported
abort(s);

View File

@ -60,10 +60,10 @@ class Context;
Aborter* getAborter(Context* c);
void* tryAllocate(Context* c, unsigned size);
void* allocate(Context* c, unsigned size);
void* allocate(Context* c, unsigned size, bool limit);
void free(Context* c, const void* p, unsigned size);
void* tryAllocate(Context* c, size_t size);
void* allocate(Context* c, size_t size);
void* allocate(Context* c, size_t size, bool limit);
void free(Context* c, const void* p, size_t size);
#ifdef USE_ATOMIC_OPERATIONS
inline void markBitAtomic(uintptr_t* map, unsigned i)
@ -1863,7 +1863,7 @@ void collect(Context* c)
}
}
void* allocate(Context* c, unsigned size, bool limit)
void* allocate(Context* c, size_t size, bool limit)
{
ACQUIRE(c->lock);
@ -1888,12 +1888,12 @@ void* allocate(Context* c, unsigned size, bool limit)
return 0;
}
void* tryAllocate(Context* c, unsigned size)
void* tryAllocate(Context* c, size_t size)
{
return allocate(c, size, true);
}
void* allocate(Context* c, unsigned size)
void* allocate(Context* c, size_t size)
{
void* p = allocate(c, size, false);
expect(c->system, p);
@ -1901,7 +1901,7 @@ void* allocate(Context* c, unsigned size)
return p;
}
void free(Context* c, const void* p, unsigned size)
void free(Context* c, const void* p, size_t size)
{
ACQUIRE(c->lock);
@ -1925,7 +1925,7 @@ void free(Context* c, const void* p, unsigned size)
c->count -= size;
}
void free_(Context* c, const void* p, unsigned size)
void free_(Context* c, const void* p, size_t size)
{
free(c, p, size);
}
@ -1963,17 +1963,17 @@ class MyHeap : public Heap {
return local::limitExceeded(&c, pendingAllocation);
}
virtual void* tryAllocate(unsigned size)
virtual void* tryAllocate(size_t size)
{
return local::tryAllocate(&c, size);
}
virtual void* allocate(unsigned size)
virtual void* allocate(size_t size)
{
return local::allocate(&c, size);
}
virtual void free(const void* p, unsigned size)
virtual void free(const void* p, size_t size)
{
free_(&c, p, size);
}

View File

@ -68,12 +68,12 @@ const char* mainClass(const char* jar)
{
}
virtual void* tryAllocate(unsigned size)
virtual void* tryAllocate(size_t size)
{
return s->tryAllocate(size);
}
virtual void* allocate(unsigned size)
virtual void* allocate(size_t size)
{
void* p = tryAllocate(size);
if (p == 0) {
@ -82,7 +82,7 @@ const char* mainClass(const char* jar)
return p;
}
virtual void free(const void* p, unsigned)
virtual void free(const void* p, size_t)
{
s->free(p);
}

View File

@ -1636,12 +1636,12 @@ int main(int ac, char** av)
{
}
virtual void* tryAllocate(unsigned size)
virtual void* tryAllocate(size_t size)
{
return s->tryAllocate(size);
}
virtual void* allocate(unsigned size)
virtual void* allocate(size_t size)
{
void* p = tryAllocate(size);
if (p == 0) {
@ -1650,7 +1650,7 @@ int main(int ac, char** av)
return p;
}
virtual void free(const void* p, unsigned)
virtual void free(const void* p, size_t)
{
s->free(p);
}

View File

@ -20,14 +20,14 @@ FixedAllocator::FixedAllocator(Aborter* a, Slice<uint8_t> memory)
{
}
void* FixedAllocator::tryAllocate(unsigned size)
void* FixedAllocator::tryAllocate(size_t size)
{
return allocate(size);
}
void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
void* FixedAllocator::allocate(size_t size, unsigned padAlignment)
{
unsigned paddedSize = vm::pad(size, padAlignment);
size_t paddedSize = vm::pad(size, padAlignment);
expect(a, offset + paddedSize < memory.count);
void* p = memory.begin() + offset;
@ -35,12 +35,12 @@ void* FixedAllocator::allocate(unsigned size, unsigned padAlignment)
return p;
}
void* FixedAllocator::allocate(unsigned size)
void* FixedAllocator::allocate(size_t size)
{
return allocate(size, vm::BytesPerWord);
}
void FixedAllocator::free(const void* p, unsigned size)
void FixedAllocator::free(const void* p, size_t size)
{
if (p >= memory.begin()
and static_cast<const uint8_t*>(p) + size == memory.begin() + offset) {