Skip to content

Commit

Permalink
extend memory allocation functions on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
pako-23 committed Sep 11, 2024
1 parent 47bcd6d commit 0c56383
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ all-examples:
cp -a basic_testing.h "$$ex"/tests ;\
$(MAKE) -C "$$ex" clean > /dev/null || test_result=FAIL; \
$(MAKE) -C "$$ex" -j $(PARALLELISM) TEST_COLORS=no > "$$ex".out 2>&1 || test_result=FAIL ; \
cat "$$ex".out ; \
if test -r "$$ex".expected; \
then { IFS=''; while read l; \
do if grep -Fq "$$l" "$$ex".out; \
Expand Down
34 changes: 34 additions & 0 deletions basic_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,40 @@ void * calloc (size_t nmemb, size_t size) {
return p;
}

#ifdef __APPLE__
BT_POSSIBLY_UNUSED
void * valloc (size_t size) {
static void *(*libc_valloc)(size_t) = NULL;

if (!libc_valloc)
libc_valloc = (void *(*)(size_t)) dlsym(RTLD_NEXT, "valloc");

return malloc (size);
}

BT_POSSIBLY_UNUSED
void * aligned_alloc (size_t aligned, size_t size) {
static void *(*libc_aligned_alloc)(size_t, size_t) = NULL;

if (!libc_aligned_alloc)
libc_aligned_alloc = (void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "aligned_alloc");

return malloc (size);
}

BT_POSSIBLY_UNUSED
void * reallocf (void * ptr, size_t size) {
static void *(*libc_reallocf)(void *, size_t) = NULL;

if (!libc_reallocf)
libc_reallocf = (void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "reallocf");

void * ret = realloc (ptr, size);
if (!ret) free (ptr);
return ret;
}
#endif

#ifndef __APPLE__
BT_POSSIBLY_UNUSED
void * reallocarray (void * ptr, size_t nmemb, size_t size) {
Expand Down
3 changes: 2 additions & 1 deletion ex/memory_checks_cpp/tests/08_stdlib_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ TEST (basic_file_operations_no_leak) {
}


#ifndef __APPLE__
static void write_str (char *buf, const char *format, ...) {
va_list ap;

Expand Down Expand Up @@ -385,7 +386,7 @@ TEST (stdio_sprintf_scanf_no_leak) {
CHECK_CMP (x,==,11);
TEST_PASSED;
}

#endif



Expand Down

0 comments on commit 0c56383

Please sign in to comment.