| 1 |
/* |
| 2 |
* Copyright (c) 2000-2011 by Hewlett-Packard Development Company. |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
| 6 |
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
| 7 |
* |
| 8 |
* Permission is hereby granted to use or copy this program |
| 9 |
* for any purpose, provided the above notices are retained on all copies. |
| 10 |
* Permission to modify the code and to distribute modified code is granted, |
| 11 |
* provided the above notices are retained, and a notice that the code was |
| 12 |
* modified is included with the above copyright notice. |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef GC_LEAK_DETECTOR_H |
| 16 |
#define GC_LEAK_DETECTOR_H |
| 17 |
|
| 18 |
/* Include leak_detector.h (e.g., via GCC --include directive) */ |
| 19 |
/* to turn libgc into a leak detector. */ |
| 20 |
|
| 21 |
#ifndef GC_DEBUG |
| 22 |
# define GC_DEBUG |
| 23 |
#endif |
| 24 |
#include "gc.h" |
| 25 |
|
| 26 |
#ifndef GC_DONT_INCLUDE_STDLIB |
| 27 |
/* We ensure stdlib.h and string.h are included before */ |
| 28 |
/* redirecting malloc() and the accompanying functions. */ |
| 29 |
# include <stdlib.h> |
| 30 |
# include <string.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#undef malloc |
| 34 |
#define malloc(n) GC_MALLOC(n) |
| 35 |
#undef calloc |
| 36 |
#define calloc(m,n) GC_MALLOC((m)*(n)) |
| 37 |
#undef free |
| 38 |
#define free(p) GC_FREE(p) |
| 39 |
#undef realloc |
| 40 |
#define realloc(p,n) GC_REALLOC(p,n) |
| 41 |
|
| 42 |
#undef strdup |
| 43 |
#define strdup(s) GC_STRDUP(s) |
| 44 |
#undef strndup |
| 45 |
#define strndup(s,n) GC_STRNDUP(s,n) |
| 46 |
|
| 47 |
#ifdef GC_REQUIRE_WCSDUP |
| 48 |
/* The collector should be built with GC_REQUIRE_WCSDUP */ |
| 49 |
/* defined as well to redirect wcsdup(). */ |
| 50 |
# include <wchar.h> |
| 51 |
# undef wcsdup |
| 52 |
# define wcsdup(s) GC_WCSDUP(s) |
| 53 |
#endif |
| 54 |
|
| 55 |
#undef memalign |
| 56 |
#define memalign(a,n) GC_memalign(a,n) |
| 57 |
#undef posix_memalign |
| 58 |
#define posix_memalign(p,a,n) GC_posix_memalign(p,a,n) |
| 59 |
|
| 60 |
#undef malloc_usable_size |
| 61 |
#define malloc_usable_size(p) GC_size(p) |
| 62 |
|
| 63 |
#ifndef CHECK_LEAKS |
| 64 |
# define CHECK_LEAKS() GC_gcollect() |
| 65 |
/* Note 1: CHECK_LEAKS does not have GC prefix (preserved for */ |
| 66 |
/* backward compatibility). */ |
| 67 |
/* Note 2: GC_gcollect() is also called automatically in the */ |
| 68 |
/* leak-finding mode at program exit. */ |
| 69 |
#endif |
| 70 |
|
| 71 |
#endif /* GC_LEAK_DETECTOR_H */ |