home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3487 / malloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-15  |  1.8 KB  |  75 lines

  1. /* $Header$ */
  2. /*
  3.  * malloc.h: Debugging malloc utils.
  4.  *
  5.  */
  6. #ifndef _h_malloc
  7. #define _h_malloc
  8.  
  9.  
  10. #ifdef __STDC__
  11. # define P_(a)    a
  12. #else
  13. # define P_(a)  ()
  14. #endif /* __STDC__ */
  15.  
  16. #ifdef __STDC__
  17. # ifndef _MEMALIGN_T
  18. #  define _MEMALIGN_T
  19.    typedef void *memalign_t;
  20. # endif /* _MEMALIGN_T */
  21. # ifndef _PTR_T
  22. #  define _PTR_T
  23.    typedef void *ptr_t;
  24. # endif /* _PTR_T */
  25. #else /* ! __STDC__ */
  26. # ifndef _PTR_T
  27. #  define _PTR_T
  28.    typedef char *ptr_t;
  29. # endif /* _PTR_T */
  30. # ifdef lint
  31.    /* Fool lint to believe that Malloc returns aligned pointers... */
  32. #  ifndef _MEMALIGN_T
  33. #   define _MEMALIGN_T
  34.     typedef union _memalign_t {
  35.     char a; short b; int c; long d; float e; double f; union _memalign_t *g;
  36.     } *memalign_t;
  37. #  endif /* _MEMALIGN_T */
  38. # else
  39. #  ifndef _MEMALIGN_T
  40. #   define _MEMALIGN_T
  41.     typedef char *memalign_t;
  42. #  endif /* _MEMALIGN_T */
  43. # endif /* lint */
  44.  
  45. #endif /* ! __STDC__ */
  46.  
  47. /*
  48.  * Memory allocation macros
  49.  */
  50. #ifdef DEBUG
  51. # define malloc(a)    (ptr_t) DebugMalloc(a, __FILE__, __LINE__)
  52. # define realloc(a, n)    (ptr_t) DebugRealloc(a, n, __FILE__, __LINE__)
  53. # define calloc(a, n)    (ptr_t) DebugCalloc(a, n, __FILE__, __LINE)
  54. # define free(a)    DebugFree(a, __FILE__, __LINE__)
  55. # define MemPtr(a)    DebugMemPtr(a, __FILE__, __LINE__)
  56. # define MemStat()    DebugMemStat()
  57. # define MemChain()    DebugMemChain()
  58. #else
  59. # define MemPtr(a)
  60. # define MemStat()
  61. # define MemChain()
  62. #endif /* DEBUG */
  63.  
  64. #ifdef DEBUG
  65. extern memalign_t DebugMalloc   P_((unsigned, char *, int));
  66. extern memalign_t DebugCalloc   P_((unsigned, unsigned, char *, int));
  67. extern memalign_t DebugRealloc  P_((ptr_t, unsigned, char *, int));
  68. extern memalign_t DebugFree     P_((ptr_t, char *, int));
  69. extern unsigned   DebugMemPtr   P_((ptr_t, char *, int));
  70. extern unsigned   DebugMemStat  P_((void));
  71. extern memalign_t DebugMemChain P_((void));
  72. #endif
  73.  
  74. #endif /* _h_malloc */
  75.