home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / LYLeaks.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  4.1 KB  |  150 lines

  1. #ifndef __LYLEAKS_H
  2. /*
  3.  *    Avoid include redundancy
  4.  *    Include only if finding memory leaks.
  5.  */
  6. #define __LYLEAKS_H
  7.  
  8. /*
  9.  *    Copyright (c) 1994, University of Kansas, All Rights Reserved
  10.  *
  11.  *    Include File:    LYLeaks.h
  12.  *    Purpose:    Header to convert requests for allocation to Lynx
  13.  *                custom functions to track memory leaks.
  14.  *    Remarks/Portability/Dependencies/Restrictions:
  15.  *        For the stdlib.h allocation functions to be overriden by the
  16.  *            Lynx memory tracking functions all modules allocating,
  17.  *            freeing, or resizing memory must have LY_FIND_LEAKS
  18.  *            defined before including this file.
  19.  *        This header file should be included in every source file which
  20.  *            does any memory manipulation through use of the
  21.  *            stdlib.h memory functions.
  22.  *        For proper reporting of memory leaks, the function LYLeaks
  23.  *            should be registered for execution by atexit as the
  24.  *            very first executable statement in main.
  25.  *        This code is slow and should not be used except in debugging
  26.  *            circumstances (don't define LY_FIND_LEAKS).
  27.  *        If you are using LY_FIND_LEAKS and don't want the LYLeak*
  28.  *            memory functions to be used in a certain file,
  29.  *            define NO_MEMORY_TRACKING before including this file.
  30.  *        The only safe way to call the LYLeak* functions is to use
  31.  *            the below macros because they depend on the static
  32.  *            string created by __FILE__ to not be dynamic in
  33.  *            nature (don't free it and assume will exist at all
  34.  *            times during execution).
  35.  *    Revision History:
  36.  *        05-26-94    created for Lynx 2-3-1, Garrett Arch Blythe
  37.  */
  38.  
  39. /*
  40.  *    Required includes
  41.  */
  42. #include <stdlib.h>
  43. #include "HTUtils.h"
  44.  
  45. /*
  46.  *    Constant defines
  47.  */
  48. #define MAX_CONTENT_LENGTH 50
  49. #ifdef VMS
  50. #define LEAKAGE_SINK "sys$login:Lynx.leaks"
  51. #else
  52. #define LEAKAGE_SINK "Lynx.leaks"
  53. #endif /* VMS */
  54.  
  55. /*
  56.  *    Data structures
  57.  */
  58. typedef struct SourceLocation_tag    {
  59.     /*
  60.      *    The file name and line number of where an event took place.
  61.      */
  62.     CONST char *cp_FileName;
  63.     short ssi_LineNumber;
  64. }
  65. SourceLocation;
  66.  
  67. typedef struct AllocationList_tag    {
  68.     /*
  69.      *    A singly linked list.
  70.      */
  71.     struct AllocationList_tag *ALp_Next;
  72.  
  73.     /*
  74.      *    The memory pointer allocated.
  75.      *    If set to NULL, then an invalid request was made.
  76.      *    The invalid pointer also.
  77.      */
  78.     void *vp_Alloced;
  79.     void *vp_BadRequest;
  80.  
  81.     /*
  82.      *    The size in bytes of the allocated memory.
  83.      */
  84.     size_t st_Bytes;
  85.  
  86.     /*
  87.      *    The source location of specific event (calloc, malloc, free).
  88.      *    realloc kept separate since will track last realloc on pointer.
  89.      */
  90.     SourceLocation SL_memory;
  91.     SourceLocation SL_realloc;
  92. }
  93. AllocationList;
  94.  
  95. /*
  96.  *    Global variable declarations
  97.  */
  98.  
  99. /*
  100.  *    Macros
  101.  */
  102. #if defined(LY_FIND_LEAKS) && !defined(NO_MEMORY_TRACKING)
  103. /*
  104.  *    Only use these macros if we are to track memory allocations.
  105.  *    The reason for using a macro instead of a define is that we want
  106.  *        to track where the initial allocation took place or where
  107.  *        the last reallocation took place.
  108.  *    Track where the allocation took place by the __FILE__ and __LINE__
  109.  *        defines which are automatic to the compiler.
  110.  */
  111. #ifdef malloc
  112. #undef malloc
  113. #endif /* malloc */
  114. #define malloc(st_bytes) LYLeakMalloc(st_bytes, __FILE__, __LINE__)
  115.  
  116. #ifdef calloc
  117. #undef calloc
  118. #endif /* calloc */
  119. #define calloc(st_number, st_bytes) LYLeakCalloc(st_number, st_bytes, \
  120.     __FILE__, __LINE__)
  121.  
  122. #ifdef realloc
  123. #undef realloc
  124. #endif /* realloc */
  125. #define realloc(vp_alloced, st_newbytes) LYLeakRealloc(vp_alloced, \
  126.     st_newbytes, __FILE__, __LINE__)
  127.  
  128. #ifdef free
  129. #undef free
  130. #endif /* free */
  131. #define free(vp_alloced) LYLeakFree(vp_alloced, __FILE__, __LINE__)
  132.  
  133. #endif /* LY_FIND_LEAKS && !NO_MEMORY_TRACKING */
  134.  
  135. /*
  136.  *    Function declarations
  137.  *    See the appropriate source file for usage.
  138.  */
  139. PUBLIC void LYLeaks NOPARAMS;
  140. PUBLIC void *LYLeakMalloc PARAMS((size_t st_bytes, CONST char *cp_File, CONST
  141.     short ssi_Line));
  142. PUBLIC void *LYLeakCalloc PARAMS((size_t st_number, size_t st_bytes, CONST char
  143.     *cp_File, CONST short ssi_Line));
  144. PUBLIC void *LYLeakRealloc PARAMS((void *vp_alloced, size_t st_newbytes, CONST
  145.     char *cp_File, CONST short ssi_Line));
  146. PUBLIC void LYLeakFree PARAMS((void *vp_alloced, CONST char *cp_File, CONST
  147.     short ssi_Line));
  148.  
  149. #endif /* __LYLEAKS_H */
  150.