leak_detector.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef GC_LEAK_DETECTOR_H
  15. #define GC_LEAK_DETECTOR_H
  16. /* Include leak_detector.h (e.g., via GCC --include directive) */
  17. /* to turn BoehmGC into a Leak Detector. */
  18. #ifndef GC_DEBUG
  19. # define GC_DEBUG
  20. #endif
  21. #include "gc.h"
  22. #ifndef GC_DONT_INCLUDE_STDLIB
  23. /* We ensure stdlib.h and string.h are included before */
  24. /* redirecting malloc() and the accompanying functions. */
  25. # include <stdlib.h>
  26. # include <string.h>
  27. #endif
  28. #undef malloc
  29. #define malloc(n) GC_MALLOC(n)
  30. #undef calloc
  31. #define calloc(m,n) GC_MALLOC((m)*(n))
  32. #undef free
  33. #define free(p) GC_FREE(p)
  34. #undef realloc
  35. #define realloc(p,n) GC_REALLOC(p,n)
  36. #undef strdup
  37. #define strdup(s) GC_STRDUP(s)
  38. #undef strndup
  39. #define strndup(s,n) GC_STRNDUP(s,n)
  40. #ifdef GC_REQUIRE_WCSDUP
  41. /* The collector should be built with GC_REQUIRE_WCSDUP */
  42. /* defined as well to redirect wcsdup(). */
  43. # include <wchar.h>
  44. # undef wcsdup
  45. # define wcsdup(s) GC_WCSDUP(s)
  46. #endif
  47. #undef memalign
  48. #define memalign(a,n) GC_memalign(a,n)
  49. #undef posix_memalign
  50. #define posix_memalign(p,a,n) GC_posix_memalign(p,a,n)
  51. #ifndef CHECK_LEAKS
  52. # define CHECK_LEAKS() GC_gcollect()
  53. /* Note 1: CHECK_LEAKS does not have GC prefix (preserved for */
  54. /* backward compatibility). */
  55. /* Note 2: GC_gcollect() is also called automatically in the */
  56. /* leak-finding mode at program exit. */
  57. #endif
  58. #endif /* GC_LEAK_DETECTOR_H */