debug.h 2.38 KB
Newer Older
Benoit Steiner's avatar
Benoit Steiner committed
1 2 3 4 5 6 7 8

/* VideoLAN VLANbridge: Debug macros
 *
 * Definition file
 *
 * You need to include <stdio.h> before including this file
*/

Benoit Steiner's avatar
Benoit Steiner committed
9 10
#ifndef _DEBUG_H
#define _DEBUG_H
Benoit Steiner's avatar
Benoit Steiner committed
11 12 13 14 15 16 17 18 19 20 21 22


/*******************************************************************************
 * ASSERT
 *******************************************************************************
 * This macro is used to test that a pointer is not nul. It insert the needed
 * code when the program is compiled with the debug option, but does nothing
 * in release program.
 *******************************************************************************/
#ifdef DEBUG
#define ASSERT(p_Mem)								\
if (!(p_Mem))									\
Benoit Steiner's avatar
Benoit Steiner committed
23
    printf("Assert error: %s line %d (variable %s at address %p)\n",     	\
Benoit Steiner's avatar
Benoit Steiner committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                 __FILE__, __LINE__, #p_Mem, &p_Mem);

#else
#define ASSERT(p_Mem)

#endif
    

/*******************************************************************************
 * RZERO
 *******************************************************************************
 * This macro is used to initialise a variable to 0. It is very useful when
 * used with the ASSERT macro. It also only insert the needed code when the
 * program is compiled with the debug option.
 *******************************************************************************/
#ifdef DEBUG
#define RZERO(r_Var)								\
bzero(&(r_Var), sizeof((r_Var)));

#else
#define RZERO(r_Var)

#endif


/*******************************************************************************
 * PZERO
 *******************************************************************************
 * This macro is used to initiase the memory pointed out by a pointer to 0.
 * It has the same purpose than RZERO, but for pointers.
 *******************************************************************************/
#ifdef DEBUG
#define PZERO(p_Mem)								\
bzero((p_Mem), sizeof(*(p_Mem)));

#else
#define PZERO(p_Mem)

#endif


/*******************************************************************************
 * AZERO
 *******************************************************************************
 * This macro is used to initiase an array of variables to 0.
 * It has the same purpose than RZERO or PZERO, but for array
 *******************************************************************************/
#ifdef DEBUG
#define AZERO(p_Array, i_Size)	       						\
bzero((p_Array), (i_Size)*sizeof(*(p_Array)));

#else
#define ZERO(p_Array, i_Size)

#endif
Benoit Steiner's avatar
Benoit Steiner committed
79 80 81


#endif