home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / memdebug / memdebug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-08  |  5.6 KB  |  197 lines

  1. /********************************************************************************/
  2. /* REMARK: set tab width to 4 spaces for best format                            */
  3. /********************************************************************************/
  4. /********************************************************************************/
  5. /*                                                                                 */
  6. /* Copyright (C) 1992                                                            */
  7. /* Centre de Recherche Public Henri Tudor (CRP-HT)                                */
  8. /* 6, rue Coudenhove-Kalergi                                                    */
  9. /* L1359 Luxembourg-Kirchberg                                                    */
  10. /*                                                                                 */
  11. /* Authors : Schmit Rene                                                         */
  12. /*                                                                                 */
  13. /* This software may be copied, distributed, ported and modified in source or    */
  14. /* object format as long as :                                                    */
  15. /*                                                                                 */
  16. /*     1) No distribution for commercial purposes is made.                            */
  17. /*     2) No third-party copyrights (such as runtime licenses) are involved        */
  18. /*     3) This copyright notice is not removed or changed.                            */
  19. /*                                                                                 */
  20. /* No responsibility is assumed for any damages that may result                 */
  21. /* from any defect in this software.                                            */
  22. /*                                                                                 */
  23. /********************************************************************************/
  24.  
  25. /*
  26. **    If no memory checking is required (i.e., memdebug is undefined at compilation time)
  27. **        the memory checking functions are wiped out by the following macro definitions.
  28. */
  29.  
  30. #ifndef __memdebug__
  31. #define __memdebug__
  32.  
  33. #include <stdlib.h>
  34.  
  35. #ifndef MEMDEBUG
  36.  
  37. #define VarInfo(p1)
  38. #define generate_MemdebugError()
  39. #define    print_MemdebugStatistics()
  40. #define    check_MemdebugError()        0
  41.  
  42. #define set_MemdebugOptions(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11)
  43.  
  44. /* replaced by above expression, as the preprocessor may have difficulties with the continuation character
  45.  
  46. #define set_MemdebugOptions(p_GeneralStatistics,p_AlphabeticalList,\
  47. p_NotFreeList,p_CallSequenceList,p_SpuriousFreeList,\
  48. p_PrintContents,p_DestroyContents,p_GenerateErrorCount,p_MaximalMemoryAvailable,\
  49. p_StatisticsFileName,p_ErrorFileName)
  50. */
  51.  
  52. #endif
  53.  
  54. /*
  55.     We need the following definitions only when memory checking is required at compilation
  56.         time. This is indicated by defining the memdebug pre-processor symbol.
  57.          
  58.     The VAXC preprocessor doesn't implement stringization: "???"
  59. */
  60.  
  61. #ifdef MEMDEBUG
  62. #ifndef VAX
  63.  
  64. #define malloc(p_Size)                 __check_malloc    (p_Size,            #p_Size,        __FILE__,__LINE__)
  65. #define calloc(p_Number,p_Size)        __check_calloc    (p_Number,    p_Size,    #p_Size,        __FILE__,__LINE__)
  66. #define realloc(p_Name,p_Size)        __check_realloc    (p_Name,    p_Size,    #p_Name,#p_Size,__FILE__,__LINE__)
  67. #define free(p_Name)                 __check_free    (p_Name,            #p_Name,        __FILE__,__LINE__)
  68.  
  69. #else
  70.  
  71. #define malloc(p_Size)                 __check_malloc    (p_Size,            "p_Size",            __FILE__,__LINE__)
  72. #define calloc(p_Number,p_Size)        __check_calloc    (p_Number,    p_Size,    "p_Size",            __FILE__,__LINE__)
  73. #define realloc(p_Name,p_Size)        __check_realloc    (p_Name,    p_Size,    "p_Name","p_Size",    __FILE__,__LINE__)
  74. #define free(p_Name)                 __check_free    (p_Name,            "p_Name",            __FILE__,__LINE__)
  75.  
  76. #endif
  77. #endif
  78.  
  79. /**************************************************************************/
  80. /******************************* Data Types *******************************/
  81. /**************************************************************************/
  82.  
  83. #ifndef __t_biState__
  84. #define __t_biState__
  85.  
  86. /*
  87.     This is kind of a BOOLEAN type, but with more and thus clearer
  88.         names for the different states
  89. */
  90.  
  91. enum t_biState 
  92. {
  93.     c_Off    = 0,
  94.     c_On,
  95.     
  96.     c_False = 0,
  97.     c_True,
  98.     
  99.     c_No    = 0,
  100.     c_Yes
  101. };
  102.  
  103. typedef enum t_biState t_biState;
  104.  
  105. #endif
  106.  
  107. /**************************************************************************/
  108.  
  109. #ifdef _MSDOS
  110. #define __MSDOS__
  111. #endif
  112.  
  113. #ifndef __MSDOS__
  114. #ifndef macintosh
  115. #define macintosh
  116. #endif
  117. #endif
  118.  
  119. #ifdef macintosh
  120. #endif
  121.  
  122. #ifdef __MSDOS__
  123. #endif
  124.  
  125. #ifdef MEMDEBUG
  126.  
  127. #ifdef __cplusplus
  128. extern "C" {
  129. #endif
  130.  
  131. /*************************************************************************/
  132. /************************* Function Prototypes ***************************/
  133. /*************************************************************************/
  134.  
  135. void  * __check_malloc      (    size_t        p_Size,
  136.                             char      * p_SizeExpression,
  137.                             char      * p_FileName,
  138.                             long        p_LineNumber);
  139.                         
  140. void  * __check_calloc      (    size_t        p_Number,
  141.                             size_t        p_Size,
  142.                             char      * p_SizeExpression,
  143.                             char      * p_FileName,
  144.                             long        p_LineNumber);
  145.                         
  146. void  *    __check_realloc      ( void      * p_Pointer,
  147.                             size_t        p_Size,
  148.                             char      *    p_NameString,
  149.                             char      *    p_SizeExpression,
  150.                             char      * p_FileName,
  151.                             long        p_LineNumber);
  152.     
  153. void    __check_free      ( void      * p_Pointer,
  154.                             char      * p_NameString,
  155.                             char      * p_FileName,
  156.                             long        p_LineNumber);
  157.  
  158. void generate_MemdebugError          ( void );
  159. void print_MemdebugStatistics      ( void );
  160. int     check_MemdebugError          ( void );
  161. void set_MemdebugOptions          ( t_biState        p_GeneralStatistics,
  162.                                     t_biState        p_AlphabeticalList,
  163.                                     t_biState        p_NotFreeList,
  164.                                     t_biState        p_CallSequenceList,
  165.         
  166.                                     t_biState        p_SpuriousFreeList,
  167.                                     
  168.                                     t_biState        p_PrintContents,
  169.                                     t_biState        p_DestroyContents,
  170.                                     
  171.                                     long            p_GenerateErrorCount,
  172.                                     unsigned long    p_MaximalMemoryAvailable,
  173.                                     
  174.                                     char          * p_StatisticsFileName,
  175.                                     char          * p_ErrorFileName
  176.                                   );
  177.  
  178.  
  179. #ifdef __cplusplus
  180.  
  181. }    // close the extern "C" declaration
  182.  
  183. /********************************************************************************/
  184.  
  185.  
  186. #define VarInfo(p_VarName)    __set_LineInfo(#p_VarName,__FILE__,__LINE__);
  187.  
  188. void __set_LineInfo (    char  * p_VariableName,
  189.                         char  * p_FileName,
  190.                         int        p_LineNumber);
  191.                         
  192. #endif
  193.  
  194. #endif
  195. #endif
  196.  
  197.