extern "C" void* calloc(size_t nmemb, size_t size) { REF; void* out = __libc_calloc(nmemb, size); DEREF; if (out && D) { D->now_usable.fetchAndAddOrdered(malloc_usable_size(out)); D->now_overhead.fetchAndAddOrdered(CHUNK_OVERHEAD); D->updatePeak(); } return out; }
/* 0.15 requires we track calloc too */ void* calloc(size_t nmemb, size_t sz) { if (!next_calloc) { extern void* __libc_calloc(size_t nmemb, size_t sz); return __libc_calloc(nmemb, sz); /* avoid infinite regress */ } if (test_mode == 2) check(); void* ptr = next_calloc(nmemb, sz); if (test_mode >= 0) track(1, sz, ptr); return ptr; }
void* calloc(size_t n, size_t size) { void* ret; if( !chpl_mem_inited() ) { ret = __libc_calloc(n, size); if( DEBUG_REPLACE_MALLOC ) printf("in early calloc %p = system calloc(%#x)\n", ret, (int) (n*size)); track_system_allocated(ret, n*size, __libc_malloc); return ret; } if( DEBUG_REPLACE_MALLOC ) printf("in calloc\n"); ret = chpl_calloc(n, size); if( DEBUG_REPLACE_MALLOC ) printf("%p = chpl_calloc(%#x)\n", ret, (int) (n*size)); return ret; }
void * fail_prone_calloc(size_t nitems, size_t size) { return drand48() < ALLOC_ERR_PROB ? NULL : __libc_calloc(nitems, size); }
void * fail_countdown_calloc(size_t nitems, size_t size) { if (ALLOC_FAIL_COUNTER >= 0) ALLOC_FAIL_COUNTER--; return ALLOC_FAIL_COUNTER < 0 ? NULL : __libc_calloc(nitems, size); }
void *calloc(size_t nmemb, size_t size) { void *__libc_calloc(size_t nmemb, size_t size); return __libc_calloc(nmemb, size); }