// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * * Copyright (C) 2002-2015, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * * File cmemory.c ICU Heap allocation. * All ICU heap allocation, both for C and C++ new of ICU * class types, comes through these functions. * * If you have a need to replace ICU allocation, this is the * place to do it. * * Note that uprv_malloc(0) returns a non-nullptr pointer, * and that a subsequent free of that pointer value is a NOP. * ****************************************************************************** */ #include "unicode/uclean.h" #include "cmemory.h" #include "putilimp.h" #include "uassert.h" #include <stdlib.h> /* uprv_malloc(0) returns a pointer to this read-only data. */ static const int32_t zeroMem[] = …; /* Function Pointers for user-supplied heap functions */ static const void *pContext; static UMemAllocFn *pAlloc; static UMemReallocFn *pRealloc; static UMemFreeFn *pFree; #if U_DEBUG && defined(UPRV_MALLOC_COUNT) #include <stdio.h> static int n=0; static long b=0; #endif U_CAPI void * U_EXPORT2 uprv_malloc(size_t s) { … } U_CAPI void * U_EXPORT2 uprv_realloc(void * buffer, size_t size) { … } U_CAPI void U_EXPORT2 uprv_free(void *buffer) { … } U_CAPI void * U_EXPORT2 uprv_calloc(size_t num, size_t size) { … } U_CAPI void U_EXPORT2 u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, UErrorCode *status) { … } U_CFUNC UBool cmemory_cleanup() { … }