Skip to content

Commit 2ff2cdf

Browse files
mjp41nwf
authored andcommitted
Add test for external pointer on stack
The external pointer function should work on any memory. This checks it works for the stack.
1 parent 1e1104a commit 2ff2cdf

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/test/func/memory/memory.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ void test_external_pointer_large()
344344

345345
void test_external_pointer_dealloc_bug()
346346
{
347+
std::cout << "Testing external pointer dealloc bug" << std::endl;
347348
auto& alloc = ThreadAlloc::get();
348349
constexpr size_t count = MIN_CHUNK_SIZE;
349350
void* allocs[count];
@@ -364,6 +365,29 @@ void test_external_pointer_dealloc_bug()
364365
}
365366

366367
alloc.dealloc(allocs[0]);
368+
std::cout << "Testing external pointer dealloc bug - done" << std::endl;
369+
}
370+
371+
void test_external_pointer_stack()
372+
{
373+
std::cout << "Testing external pointer stack" << std::endl;
374+
375+
std::array<int, 2000> stack;
376+
377+
auto& alloc = ThreadAlloc::get();
378+
379+
for (size_t i = 0; i < stack.size(); i++)
380+
{
381+
if (alloc.external_pointer(&stack[i]) > &stack[i])
382+
{
383+
std::cout << "Stack pointer: " << &stack[i]
384+
<< " external pointer: " << alloc.external_pointer(&stack[i])
385+
<< std::endl;
386+
abort();
387+
}
388+
}
389+
390+
std::cout << "Testing external pointer stack - done" << std::endl;
367391
}
368392

369393
void test_alloc_16M()
@@ -500,6 +524,7 @@ int main(int argc, char** argv)
500524
test_remaining_bytes();
501525
test_static_sized_allocs();
502526
test_calloc_large_bug();
527+
test_external_pointer_stack();
503528
test_external_pointer_dealloc_bug();
504529
test_external_pointer_large();
505530
test_external_pointer();

0 commit comments

Comments
 (0)