]>
git.saurik.com Git - apple/libc.git/blob - regex/TRE/lib/xmalloc.h
ce310af5204e663497022b800a8ef6bd36e36568
2 xmalloc.h - Simple malloc debugging library API
4 This software is released under a BSD-style license.
5 See the file LICENSE for details and copyright.
12 void *xmalloc_impl(size_t size
, const char *file
, int line
, const char *func
);
13 void *xcalloc_impl(size_t nmemb
, size_t size
, const char *file
, int line
,
15 void xfree_impl(void *ptr
, const char *file
, int line
, const char *func
);
16 void *xrealloc_impl(void *ptr
, size_t new_size
, const char *file
, int line
,
18 int xmalloc_dump_leaks(void);
19 void xmalloc_configure(int fail_after
);
22 #ifndef XMALLOC_INTERNAL
23 #ifdef MALLOC_DEBUGGING
25 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
26 which contains the name of the function currently being defined.
27 # define __XMALLOC_FUNCTION __PRETTY_FUNCTION__
28 This is broken in G++ before version 2.6.
29 C9x has a similar variable called __func__, but prefer the GCC one since
30 it demangles C++ function names. */
32 # if __GNUC__ > 2 || (__GNUC__ == 2 \
33 && __GNUC_MINOR__ >= (defined __cplusplus ? 6 : 4))
34 # define __XMALLOC_FUNCTION __PRETTY_FUNCTION__
36 # define __XMALLOC_FUNCTION ((const char *) 0)
39 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
40 # define __XMALLOC_FUNCTION __func__
42 # define __XMALLOC_FUNCTION ((const char *) 0)
46 #define xmalloc(size) xmalloc_impl(size, __FILE__, __LINE__, \
48 #define xcalloc(nmemb, size) xcalloc_impl(nmemb, size, __FILE__, __LINE__, \
50 #define xfree(ptr) xfree_impl(ptr, __FILE__, __LINE__, __XMALLOC_FUNCTION)
51 #define xrealloc(ptr, new_size) xrealloc_impl(ptr, new_size, __FILE__, \
52 __LINE__, __XMALLOC_FUNCTION)
58 #define malloc USE_XMALLOC_INSTEAD_OF_MALLOC
59 #define calloc USE_XCALLOC_INSTEAD_OF_CALLOC
60 #define free USE_XFREE_INSTEAD_OF_FREE
61 #define realloc USE_XREALLOC_INSTEAD_OF_REALLOC
63 #else /* !MALLOC_DEBUGGING */
67 #define xmalloc(size) malloc(size)
68 #define xcalloc(nmemb, size) calloc(nmemb, size)
69 #define xfree(ptr) free(ptr)
70 #define xrealloc(ptr, new_size) realloc(ptr, new_size)
72 #endif /* !MALLOC_DEBUGGING */
73 #endif /* !XMALLOC_INTERNAL */
75 #endif /* _XMALLOC_H */