home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / dbgint.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  6KB  |  267 lines

  1. /***
  2. *dbgint.h - Supports debugging features of the C runtime library.
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Support CRT debugging features.
  8. *
  9. *       [Internal]
  10. *
  11. ****/
  12.  
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif  /* _MSC_VER > 1000 */
  16.  
  17. #ifndef _INC_DBGINT
  18. #define _INC_DBGINT
  19.  
  20. #ifndef _CRTBLD
  21. /*
  22.  * This is an internal C runtime header file. It is used when building
  23.  * the C runtimes only. It is not to be used as a public header file.
  24.  */
  25. #error ERROR: Use of C runtime library internal header file.
  26. #endif  /* _CRTBLD */
  27.  
  28. #include <crtdbg.h>
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif  /* __cplusplus */
  33.  
  34. #ifndef _DEBUG
  35.  
  36.  /****************************************************************************
  37.  *
  38.  * Debug OFF
  39.  * Debug OFF
  40.  * Debug OFF
  41.  *
  42.  ***************************************************************************/
  43.  
  44. #ifdef __cplusplus
  45.  
  46. #define _new_crt                        new
  47.  
  48. #endif  /* __cplusplus */
  49.  
  50. #define _malloc_crt                     malloc
  51. #define _calloc_crt                     calloc
  52. #define _realloc_crt                    realloc
  53. #define _expand_crt                     _expand
  54. #define _free_crt                       free
  55. #define _msize_crt                      _msize
  56.  
  57.  
  58. #define _malloc_base                    malloc
  59. #define _nh_malloc_base                 _nh_malloc
  60. #define _nh_malloc_dbg(s, n, t, f, l)   _nh_malloc(s, n)
  61. #define _heap_alloc_base                _heap_alloc
  62. #define _heap_alloc_dbg(s, t, f, l)     _heap_alloc(s)
  63. #define _calloc_base                    calloc
  64. #define _realloc_base                   realloc
  65. #define _expand_base                    _expand
  66. #define _free_base                      free
  67. #define _msize_base                     _msize
  68.  
  69. #ifdef _MT
  70.  
  71. #define _calloc_dbg_lk(c, s, t, f, l)   _calloc_lk(c, s)
  72. #define _realloc_dbg_lk(p, s, t, f, l)  _realloc_lk(p, s)
  73. #define _free_base_lk                   _free_lk
  74. #define _free_dbg_lk(p, t)              _free_lk(p)
  75.  
  76. #else  /* _MT */
  77.  
  78. #define _calloc_dbg_lk(c, s, t, f, l)   calloc(c, s)
  79. #define _realloc_dbg_lk(p, s, t, f, l)  realloc(p, s)
  80. #define _free_base_lk                   free
  81. #define _free_dbg_lk(p, t)              free(p)
  82.  
  83. #endif  /* _MT */
  84.  
  85.  
  86. #else  /* _DEBUG */
  87.  
  88.  
  89.  /****************************************************************************
  90.  *
  91.  * Debug ON
  92.  * Debug ON
  93.  * Debug ON
  94.  *
  95.  ***************************************************************************/
  96.  
  97. #define _THISFILE   __FILE__
  98.  
  99. #ifdef __cplusplus
  100.  
  101. #define _new_crt        new(_CRT_BLOCK, _THISFILE, __LINE__)
  102.  
  103. #endif  /* __cplusplus */
  104.  
  105. #define _malloc_crt(s)      _malloc_dbg(s, _CRT_BLOCK, _THISFILE, __LINE__)
  106. #define _calloc_crt(c, s)   _calloc_dbg(c, s, _CRT_BLOCK, _THISFILE, __LINE__)
  107. #define _realloc_crt(p, s)  _realloc_dbg(p, s, _CRT_BLOCK, _THISFILE, __LINE__)
  108. #define _expand_crt(p, s)   _expand_dbg(p, s, _CRT_BLOCK)
  109. #define _free_crt(p)        _free_dbg(p, _CRT_BLOCK)
  110. #define _msize_crt(p)       _msize_dbg(p, _CRT_BLOCK)
  111.  
  112. /*
  113.  * Prototypes for malloc, free, realloc, etc are in malloc.h
  114.  */
  115.  
  116. void * __cdecl _malloc_base(
  117.         size_t
  118.         );
  119.  
  120. void * __cdecl _nh_malloc_base (
  121.         size_t,
  122.         int
  123.         );
  124.  
  125. void * __cdecl _nh_malloc_dbg (
  126.         size_t,
  127.         int,
  128.         int,
  129.         const char *,
  130.         int
  131.         );
  132.  
  133. void * __cdecl _heap_alloc_base(
  134.         size_t
  135.         );
  136.  
  137. void * __cdecl _heap_alloc_dbg(
  138.         size_t,
  139.         int,
  140.         const char *,
  141.         int
  142.         );
  143.  
  144. void * __cdecl _calloc_base(
  145.         size_t,
  146.         size_t
  147.         );
  148.  
  149. void * __cdecl _realloc_base(
  150.         void *,
  151.         size_t
  152.         );
  153.  
  154. void * __cdecl _expand_base(
  155.         void *,
  156.         size_t
  157.         );
  158.  
  159. void __cdecl _free_base(
  160.         void *
  161.         );
  162.  
  163. size_t __cdecl _msize_base (
  164.         void *
  165.         );
  166.  
  167. #ifdef _MT
  168.  
  169. /*
  170.  * Prototypes and macros for multi-thread support
  171.  */
  172.  
  173.  
  174. void * __cdecl _calloc_dbg_lk(
  175.         size_t,
  176.         size_t,
  177.         int,
  178.         char *,
  179.         int
  180.         );
  181.  
  182.  
  183. void * __cdecl _realloc_dbg_lk(
  184.         void *,
  185.         size_t,
  186.         int,
  187.         const char *,
  188.         int
  189.         );
  190.  
  191.  
  192. void __cdecl _free_base_lk(
  193.         void *
  194.         );
  195.  
  196. void __cdecl _free_dbg_lk(
  197.         void *,
  198.         int
  199.         );
  200.  
  201. #else  /* _MT */
  202.  
  203. #define _calloc_dbg_lk                  _calloc_dbg
  204. #define _realloc_dbg_lk                 _realloc_dbg
  205. #define _free_base_lk                   _free_base
  206. #define _free_dbg_lk                    _free_dbg
  207.  
  208. #endif  /* _MT */
  209.  
  210. /*
  211.  * For diagnostic purpose, blocks are allocated with extra information and
  212.  * stored in a doubly-linked list.  This makes all blocks registered with
  213.  * how big they are, when they were allocated, and what they are used for.
  214.  */
  215.  
  216. #define nNoMansLandSize 4
  217.  
  218. typedef struct _CrtMemBlockHeader
  219. {
  220.         struct _CrtMemBlockHeader * pBlockHeaderNext;
  221.         struct _CrtMemBlockHeader * pBlockHeaderPrev;
  222.         char *                      szFileName;
  223.         int                         nLine;
  224.         size_t                      nDataSize;
  225.         int                         nBlockUse;
  226.         long                        lRequest;
  227.         unsigned char               gap[nNoMansLandSize];
  228.         /* followed by:
  229.          *  unsigned char           data[nDataSize];
  230.          *  unsigned char           anotherGap[nNoMansLandSize];
  231.          */
  232. } _CrtMemBlockHeader;
  233.  
  234. #define pbData(pblock) ((unsigned char *)((_CrtMemBlockHeader *)pblock + 1))
  235. #define pHdr(pbData) (((_CrtMemBlockHeader *)pbData)-1)
  236.  
  237.  
  238. _CRTIMP void __cdecl _CrtSetDbgBlockType(
  239.         void *,
  240.         int
  241.         );
  242.  
  243. #define _BLOCK_TYPE_IS_VALID(use) (_BLOCK_TYPE(use) == _CLIENT_BLOCK || \
  244.                                               (use) == _NORMAL_BLOCK || \
  245.                                    _BLOCK_TYPE(use) == _CRT_BLOCK    || \
  246.                                               (use) == _IGNORE_BLOCK)
  247.  
  248. extern _CRT_ALLOC_HOOK _pfnAllocHook; /* defined in dbghook.c */
  249.  
  250. int __cdecl _CrtDefaultAllocHook(
  251.         int,
  252.         void *,
  253.         size_t,
  254.         int,
  255.         long,
  256.         const unsigned char *,
  257.         int
  258.         );
  259.  
  260. #endif  /* _DEBUG */
  261.  
  262. #ifdef __cplusplus
  263. }
  264. #endif  /* __cplusplus */
  265.  
  266. #endif  /* _INC_DBGINT */
  267.