Back to index

tetex-bin  3.0
alloc-debug.h
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include "xdvi-config.h"    /* for xmalloc etc. */
00004 
00005 #ifndef ALLOC_DEBUG_H__
00006 #define ALLOC_DEBUG_H__
00007 
00008 
00009 /*
00010  * Simplistic macros to help finding `hot spots'/bugs in memory handling.
00011  * Require that MALLOC(x) is never a single statement following an if(),
00012  * else() etc. without braces, and never in the middle of a variable
00013  * declarations list.
00014  */
00015 
00016 /* #define DEBUG_MEMORY_HANDLING */
00017 
00018 #ifdef DEBUG_MEMORY_HANDLING
00019 #define XMALLOC(x,y) ( \
00020        fprintf(stderr, "=== %s:%d: malloc(%p (%s), %d)\n", __FILE__, __LINE__, x, #x, y), \
00021        xmalloc(y))
00022 #define XREALLOC(x,y) ( \
00023        fprintf(stderr, "=== %s:%d: realloc(%p (%s), %d)\n", __FILE__, __LINE__, x, #x, y), \
00024        xrealloc(x, y))
00025 #define FREE(x)      ( \
00026        fprintf(stderr, "=== %s:%d: free(%p (%s))\n", __FILE__, __LINE__, x, #x), \
00027        free(x))
00028 #else
00029 #define XMALLOC(x,y) xmalloc(y)
00030 #define XREALLOC(x,y) xrealloc(x,y)
00031 #define FREE(x) free(x)
00032 #endif
00033 
00034 #endif /* ALLOC_DEBUG_H__ */