2002-07-29 21:29:23 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2002-07-29 22:15:14 +00:00
|
|
|
* 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-NULL pointer, and
|
|
|
|
* that a subsequent free of that pointer value is a NOP.
|
2002-07-29 21:29:23 +00:00
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2002-07-30 01:12:58 +00:00
|
|
|
#include "cmemory.h"
|
2002-07-29 21:29:23 +00:00
|
|
|
|
2002-07-30 01:12:58 +00:00
|
|
|
/* uprv_malloc(0) returns a pointer to this read-only data. */
|
2002-07-29 22:15:14 +00:00
|
|
|
static const int32_t zeroMem[] = {0, 0, 0, 0, 0, 0};
|
|
|
|
|
2002-07-29 21:29:23 +00:00
|
|
|
U_CAPI void * U_EXPORT2
|
|
|
|
uprv_malloc(size_t s) {
|
2002-07-29 22:15:14 +00:00
|
|
|
if (s > 0) {
|
|
|
|
return malloc(s);
|
|
|
|
} else {
|
|
|
|
return (void *)zeroMem;
|
|
|
|
}
|
2002-07-29 21:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void * U_EXPORT2
|
|
|
|
uprv_realloc(void * buffer, size_t size) {
|
2002-07-29 22:15:14 +00:00
|
|
|
if (buffer == zeroMem || size == 0) {
|
|
|
|
return uprv_malloc(size);
|
|
|
|
} else {
|
|
|
|
return realloc(buffer, size);
|
|
|
|
}
|
2002-07-29 21:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uprv_free(void *buffer) {
|
2002-07-29 22:15:14 +00:00
|
|
|
if (buffer != zeroMem) {
|
|
|
|
free(buffer);
|
|
|
|
}
|
2002-07-29 21:29:23 +00:00
|
|
|
}
|
|
|
|
|