malloc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _MALLOC_H_
  2. #define _MALLOC_H_
  3. #include <stdlib.h>
  4. // 独自メモリマネージャを使用する場合、次のコメントを外してください。
  5. // #define USE_MEMMGR
  6. #if defined(DMALLOC)
  7. # include "dmalloc.h"
  8. # define aMalloc(size) \
  9. dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
  10. # define aMallocA(size) \
  11. dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
  12. # define aCallocA(count,size) \
  13. dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
  14. # define aCalloc(count,size) \
  15. dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
  16. # define aRealloc(ptr,size) \
  17. dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 0)
  18. # define aFree(ptr) free(ptr)
  19. # define aStrdup(ptr) strdup(ptr)
  20. #elif defined(GCOLLECT)
  21. # include "gc.h"
  22. # define aMalloc(n) GC_MALLOC(n)
  23. # define aMallocA(n) GC_MALLOC_ATOMIC(n)
  24. # define aCallocA(m,n) _bcallocA(m,n)
  25. # define aCalloc(m,n) _bcalloc(m,n)
  26. # define aRealloc(p,n) GC_REALLOC(p,n)
  27. # define aFree(n) GC_FREE(n)
  28. # define aStrdup(n) _bstrdup(n)
  29. extern void * _bcalloc(size_t, size_t);
  30. extern void * _bcallocA(size_t, size_t);
  31. extern char * _bstrdup(const char *);
  32. #elif defined(BCHECK)
  33. # define aMalloc(n) malloc(n)
  34. # define aMallocA(n) malloc(n)
  35. # define aCalloc(m,n) calloc(m,n)
  36. # define aCallocA(m,n) calloc(m,n)
  37. # define aRealloc(p,n) realloc(p,n)
  38. # define aFree(n) free(n)
  39. # define aStrdup(n) strdup(n)
  40. #else
  41. #if __STDC_VERSION__ < 199901L
  42. # if __GNUC__ >= 2
  43. # define __func__ __FUNCTION__
  44. # else
  45. # define __func__ ""
  46. # endif
  47. #endif
  48. # define ALC_MARK __FILE__, __LINE__, __func__
  49. void* aMalloc_( size_t size, const char *file, int line, const char *func );
  50. void* aCalloc_( size_t num, size_t size, const char *file, int line, const char *func );
  51. void* aRealloc_( void *p, size_t size, const char *file, int line, const char *func );
  52. void aFree_( void *p, const char *file, int line, const char *func );
  53. void* aStrdup_( const void *p, const char *file, int line, const char *func );
  54. # define aMalloc(n) aMalloc_(n,ALC_MARK)
  55. # define aMallocA(n) aMalloc_(n,ALC_MARK)
  56. # define aCalloc(m,n) aCalloc_(m,n,ALC_MARK)
  57. # define aCallocA(m,n) aCalloc_(m,n,ALC_MARK)
  58. # define aRealloc(p,n) aRealloc_(p,n,ALC_MARK)
  59. # define aStrdup(p) aStrdup_(p,ALC_MARK)
  60. # define aFree(p) do { aFree_(p,ALC_MARK); if(p != NULL) { p = NULL; } } while(0)
  61. #endif
  62. #ifndef USE_MEMMGR
  63. #define do_init_memmgr(file)
  64. #else
  65. int do_init_memmgr(const char* file);
  66. #endif
  67. #endif