⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memwatch.h

📁 MiniWinOuterSM MiniWinOuterSM
💻 H
📖 第 1 页 / 共 3 页
字号:
/*
** Testing/verification/tracing
**  All of these macros except VERIFY() evaluates to a null statement
**  if MEMWATCH is not defined during compilation.
**  - mwIsReadAddr() checks a memory area for read privilige.
**  - mwIsSafeAddr() checks a memory area for both read & write privilige.
**      This function and mwIsReadAddr() is highly system-specific and
**      may not be implemented. If this is the case, they will default
**      to returning nonzero for any non-NULL pointer.
**  - CHECK() does a complete memory integrity test. Slow!
**  - CHECK_THIS() checks only selected components.
**  - CHECK_BUFFER() checks the indicated buffer for errors.
**  - mwASSERT() or ASSERT() If the expression evaluates to nonzero, execution continues.
**      Otherwise, the ARI handler is called, if present. If not present,
**      the default ARI action is taken (set with mwSetAriAction()).
**      ASSERT() can be disabled by defining MW_NOASSERT.
**  - mwVERIFY() or VERIFY() works just like ASSERT(), but when compiling without
**      MEMWATCH the macro evaluates to the expression.
**      VERIFY() can be disabled by defining MW_NOVERIFY.
**  - mwTRACE() or TRACE() writes some text and data to the log. Use like printf().
**      TRACE() can be disabled by defining MW_NOTRACE.
*/
int   mwIsReadAddr( const void *p, unsigned len );
int   mwIsSafeAddr( void *p, unsigned len );
int   mwTest( const char *file, int line, int mw_test_flags );
int   mwTestBuffer( const char *file, int line, void *p );
int   mwAssert( int, const char*, const char*, int );
int   mwVerify( int, const char*, const char*, int );

/*
** User I/O functions
**  - mwTrace() works like printf(), but dumps output either to the
**      function specified with mwSetOutFunc(), or the log file.
**  - mwPuts() works like puts(), dumps output like mwTrace().
**  - mwSetOutFunc() allows you to give the adress of a function
**      where all user output will go. (exeption: see mwSetAriFunc)
**      Specifying NULL will direct output to the log file.
**  - mwSetAriFunc() gives MEMWATCH the adress of a function to call
**      when an 'Abort, Retry, Ignore' question is called for. The
**      actual error message is NOT printed when you've set this adress,
**      but instead it is passed as an argument. If you call with NULL
**      for an argument, the ARI handler is disabled again. When the
**      handler is disabled, MEMWATCH will automatically take the
**      action specified by mwSetAriAction().
**  - mwSetAriAction() sets the default ARI return value MEMWATCH should
**      use if no ARI handler is specified. Defaults to MW_ARI_ABORT.
**  - mwAriHandler() is an ANSI ARI handler you can use if you like. It
**      dumps output to stderr, and expects input from stdin.
**  - mwBreakOut() is called in certain cases when MEMWATCH feels it would
**      be nice to break into a debugger. If you feel like MEMWATCH, place
**      an execution breakpoint on this function.
*/
void  mwTrace( const char* format_string, ... );
void  mwPuts( const char* text );
void  mwSetOutFunc( void (*func)(int) );
void  mwSetAriFunc( int (*func)(const char*) );
void  mwSetAriAction( int mw_ari_value );
int   mwAriHandler( const char* cause );
void  mwBreakOut( const char* cause );

/*
** Allocation/deallocation functions
**  These functions are the ones actually to perform allocations
**  when running MEMWATCH, for both C and C++ calls.
**  - mwMalloc() debugging allocator
**  - mwMalloc_() always resolves to a clean call of malloc()
**  - mwRealloc() debugging re-allocator
**  - mwRealloc_() always resolves to a clean call of realloc()
**  - mwCalloc() debugging allocator, fills with zeros
**  - mwCalloc_() always resolves to a clean call of calloc()
**  - mwFree() debugging free. Can only free memory which has
**      been allocated by MEMWATCH.
**  - mwFree_() resolves to a) normal free() or b) debugging free.
**      Can free memory allocated by MEMWATCH and malloc() both.
**      Does not generate any runtime errors.
*/
void* mwMalloc( size_t, const char*, int );
void* mwMalloc_( size_t );
void* mwRealloc( void *, size_t, const char*, int );
void* mwRealloc_( void *, size_t );
void* mwCalloc( size_t, size_t, const char*, int );
void* mwCalloc_( size_t, size_t );
void  mwFree( void*, const char*, int );
void  mwFree_( void* );
char* mwStrdup( const char *, const char*, int );

/*
** Enable/disable precompiler block
**  This block of defines and if(n)defs make sure that references
**  to MEMWATCH is completely removed from the code if the MEMWATCH
**  manifest constant is not defined.
*/
#ifndef __MEMWATCH_C
#ifdef MEMWATCH

#define mwASSERT(exp)   while(mwAssert((int)(exp),#exp,__FILE__,__LINE__))
#ifndef MW_NOASSERT
#ifndef ASSERT
#define ASSERT          mwASSERT
#endif /* !ASSERT */
#endif /* !MW_NOASSERT */
#define mwVERIFY(exp)   while(mwVerify((int)(exp),#exp,__FILE__,__LINE__))
#ifndef MW_NOVERIFY
#ifndef VERIFY
#define VERIFY          mwVERIFY
#endif /* !VERIFY */
#endif /* !MW_NOVERIFY */
#define mwTRACE         mwTrace
#ifndef MW_NOTRACE
#ifndef MWTRACE
#define MWTRACE           mwTRACE
#endif /* !TRACE */
#endif /* !MW_NOTRACE */

/* some compilers use a define and not a function */
/* for strdup(). */
#ifdef strdup
#undef strdup
#endif

#define malloc(n)       mwMalloc(n,__FILE__,__LINE__)
#define strdup(p)       mwStrdup(p,__FILE__,__LINE__)
#define realloc(p,n)    mwRealloc(p,n,__FILE__,__LINE__)
#define calloc(n,m)     mwCalloc(n,m,__FILE__,__LINE__)
#define free(p)         mwFree(p,__FILE__,__LINE__)
#define CHECK()         mwTest(__FILE__,__LINE__,MW_TEST_ALL)
#define CHECK_THIS(n)   mwTest(__FILE__,__LINE__,n)
#define CHECK_BUFFER(b) mwTestBuffer(__FILE__,__LINE__,b)
#define MARK(p)         mwMark(p,#p,__FILE__,__LINE__)
#define UNMARK(p)       mwUnmark(p,__FILE__,__LINE__)

#else /* MEMWATCH */

#define mwASSERT(exp)
#ifndef MW_NOASSERT
#ifndef ASSERT
#define ASSERT          mwASSERT
#endif /* !ASSERT */
#endif /* !MW_NOASSERT */

#define mwVERIFY(exp)    exp
#ifndef MW_NOVERIFY
#ifndef VERIFY
#define VERIFY          mwVERIFY
#endif /* !VERIFY */
#endif /* !MW_NOVERIFY */

/*lint -esym(773,mwTRACE) */
#define mwTRACE         /*lint -save -e506 */ 1?(void)0:mwDummyTraceFunction /*lint -restore */
#ifndef MW_NOTRACE
#ifndef TRACE
/*lint -esym(773,TRACE) */
#define TRACE           mwTRACE
#endif /* !TRACE */
#endif /* !MW_NOTRACE */

extern void mwDummyTraceFunction(const char *,...);
/*lint -save -e652 */
#define mwDoFlush(n)
#define mwPuts(s)
#define mwInit()
#define mwGrab(n)
#define mwDrop(n)
#define mwLimit(n)
#define mwTest(f,l)
#define mwSetOutFunc(f)
#define mwSetAriFunc(f)
#define mwDefaultAri()
#define mwNomansland()
#define mwStatistics(f)
#define mwMark(p,t,f,n)     (p)
#define mwUnmark(p,f,n)     (p)
#define mwMalloc(n,f,l)     malloc(n)
#define mwStrdup(p,f,l)     strdup(p)
#define mwRealloc(p,n,f,l)  realloc(p,n)
#define mwCalloc(n,m,f,l)   calloc(n,m)
#define mwFree(p)           free(p)
#define mwMalloc_(n)        malloc(n)
#define mwRealloc_(p,n)     realloc(p,n)
#define mwCalloc_(n,m)      calloc(n,m)
#define mwFree_(p)          free(p)
#define mwAssert(e,es,f,l)
#define mwVerify(e,es,f,l)  (e)
#define mwTrace             mwDummyTrace
#define mwTestBuffer(f,l,b) (0)
#define CHECK()
#define CHECK_THIS(n)
#define CHECK_BUFFER(b)
#define MARK(p)             (p)
#define UNMARK(p)           (p)
/*lint -restore */

#endif /* MEMWATCH */
#endif /* !__MEMWATCH_C */

#ifdef __cplusplus
    }
#endif

#if 0 /* 980317: disabled C++ */

/*
** C++ support section
**  Implements the C++ support. Please note that in order to avoid
**  messing up library classes, C++ support is disabled by default.
**  You must NOT enable it until AFTER the inclusion of all header
**  files belonging to code that are not compiled with MEMWATCH, and
**  possibly for some that are! The reason for this is that a C++
**  class may implement it's own new() function, and the preprocessor
**  would substitute this crucial declaration for MEMWATCH new().
**  You can forcibly deny C++ support by defining MEMWATCH_NOCPP.
**  To enble C++ support, you must be compiling C++, MEMWATCH must
**  be defined, MEMWATCH_NOCPP must not be defined, and finally,
**  you must define 'new' to be 'mwNew', and 'delete' to be 'mwDelete'.
**  Unlike C, C++ code can begin executing *way* before main(), for
**  example if a global variable is created. For this reason, you can
**  declare a global variable of the class 'MemWatch'. If this is
**  is the first variable created, it will then check ALL C++ allocations
**  and deallocations. Unfortunately, this evaluation order is not
**  guaranteed by C++, though the compilers I've tried evaluates them
**  in the order encountered.
*/

#endif /* 980317: disabled C++ */

#endif /* __MEMWATCH_H */

/* EOF MEMWATCH.H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -