summaryrefslogtreecommitdiff
path: root/tests/allocator.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-21 00:14:53 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-21 00:14:53 -0700
commitce974094ace6a33d46d8dcc6ca66a6fcdc014bbd (patch)
treea6c2f594cbc04bd2042dd55c66afc23f51f9b14c /tests/allocator.cpp
parent28e63f66e1e947de276a2181b28906528a483037 (diff)
tests: Fix test compilation
Rename PAGE_SIZE to page_size to avoid define conflict with Android SDK. Minor fixes in several tests.
Diffstat (limited to 'tests/allocator.cpp')
-rw-r--r--tests/allocator.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/allocator.cpp b/tests/allocator.cpp
index 74bbf10..8ca0963 100644
--- a/tests/allocator.cpp
+++ b/tests/allocator.cpp
@@ -23,11 +23,11 @@
namespace
{
- const size_t PAGE_SIZE = 4096;
+ const size_t page_size = 4096;
size_t align_to_page(size_t value)
{
- return (value + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+ return (value + page_size - 1) & ~(page_size - 1);
}
void* allocate_page_aligned(size_t size)
@@ -36,7 +36,7 @@ namespace
// We can't use malloc because of occasional problems with CW on CRT termination
static HANDLE heap = HeapCreate(0, 0, 0);
- void* result = HeapAlloc(heap, 0, size + PAGE_SIZE);
+ void* result = HeapAlloc(heap, 0, size + page_size);
return reinterpret_cast<void*>(align_to_page(reinterpret_cast<size_t>(result)));
}
@@ -45,13 +45,13 @@ namespace
{
size_t aligned_size = align_to_page(size);
- void* ptr = allocate_page_aligned(aligned_size + PAGE_SIZE);
+ void* ptr = allocate_page_aligned(aligned_size + page_size);
if (!ptr) return 0;
char* end = static_cast<char*>(ptr) + aligned_size;
DWORD old_flags;
- VirtualProtect(end, PAGE_SIZE, PAGE_NOACCESS, &old_flags);
+ VirtualProtect(end, page_size, PAGE_NOACCESS, &old_flags);
return end - size;
}
@@ -63,7 +63,7 @@ namespace
void* rptr = static_cast<char*>(ptr) + size - aligned_size;
DWORD old_flags;
- VirtualProtect(rptr, aligned_size + PAGE_SIZE, PAGE_NOACCESS, &old_flags);
+ VirtualProtect(rptr, aligned_size + page_size, PAGE_NOACCESS, &old_flags);
}
}
#elif defined(__APPLE__) || defined(__linux__)
@@ -71,28 +71,28 @@ namespace
namespace
{
- const size_t PAGE_SIZE = 4096;
+ const size_t page_size = 4096;
size_t align_to_page(size_t value)
{
- return (value + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+ return (value + page_size - 1) & ~(page_size - 1);
}
void* allocate_page_aligned(size_t size)
{
- return mmap(0, size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+ return mmap(0, size + page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
}
void* allocate(size_t size)
{
size_t aligned_size = align_to_page(size);
- void* ptr = allocate_page_aligned(aligned_size + PAGE_SIZE);
+ void* ptr = allocate_page_aligned(aligned_size + page_size);
if (!ptr) return 0;
char* end = static_cast<char*>(ptr) + aligned_size;
- int res = mprotect(end, PAGE_SIZE, PROT_NONE);
+ int res = mprotect(end, page_size, PROT_NONE);
assert(res == 0);
(void)!res;
@@ -105,7 +105,7 @@ namespace
void* rptr = static_cast<char*>(ptr) + size - aligned_size;
- int res = mprotect(rptr, aligned_size + PAGE_SIZE, PROT_NONE);
+ int res = mprotect(rptr, aligned_size + page_size, PROT_NONE);
assert(res == 0);
(void)!res;
}