mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-9342 implemented patch to support gcc's malloc and alloc_size attributes
X-SVN-Rev: 32151
This commit is contained in:
parent
2ad0aad18c
commit
3ef2d173ca
2 changed files with 32 additions and 3 deletions
|
@ -62,16 +62,16 @@ U_CAPI void uprv_checkValidMemory(const void *p, size_t n);
|
|||
#define uprv_memcmp(buffer1, buffer2, size) U_STANDARD_CPP_NAMESPACE memcmp(buffer1, buffer2,size)
|
||||
|
||||
U_CAPI void * U_EXPORT2
|
||||
uprv_malloc(size_t s);
|
||||
uprv_malloc(size_t s) U_MALLOC_ATTR U_ALLOC_SIZE_ATTR(1);
|
||||
|
||||
U_CAPI void * U_EXPORT2
|
||||
uprv_realloc(void *mem, size_t size);
|
||||
uprv_realloc(void *mem, size_t size) U_ALLOC_SIZE_ATTR(2);
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
uprv_free(void *mem);
|
||||
|
||||
U_CAPI void * U_EXPORT2
|
||||
uprv_calloc(size_t num, size_t size);
|
||||
uprv_calloc(size_t num, size_t size) U_MALLOC_ATTR U_ALLOC_SIZE_ATTR2(1,2);
|
||||
|
||||
/**
|
||||
* This should align the memory properly on any machine.
|
||||
|
|
|
@ -392,6 +392,35 @@
|
|||
# define U_HAVE_DEBUG_LOCATION_NEW 0
|
||||
#endif
|
||||
|
||||
/* Compatibility with non clang compilers */
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_MALLOC_ATTR
|
||||
* Attribute to mark functions as malloc-like
|
||||
* @internal
|
||||
*/
|
||||
#if defined(__GNUC__) && __GNUC__>=3
|
||||
# define U_MALLOC_ATTR __attribute__ ((__malloc__))
|
||||
#else
|
||||
# define U_MALLOC_ATTR
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def U_ALLOC_SIZE_ATTR
|
||||
* Attribute to specify the size of the allocated buffer for malloc-like functions
|
||||
* @internal
|
||||
*/
|
||||
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
|
||||
# define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
|
||||
# define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
|
||||
#else
|
||||
# define U_ALLOC_SIZE_ATTR(X)
|
||||
# define U_ALLOC_SIZE_ATTR2(X,Y)
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
Loading…
Add table
Reference in a new issue