contrib/python-zstandard/zstd/common/debug.h
changeset 42070 675775c33ab6
parent 40121 73fef626dae3
equal deleted inserted replaced
42069:668eff08387f 42070:675775c33ab6
    55 #if defined (__cplusplus)
    55 #if defined (__cplusplus)
    56 extern "C" {
    56 extern "C" {
    57 #endif
    57 #endif
    58 
    58 
    59 
    59 
    60 /* static assert is triggered at compile time, leaving no runtime artefact,
    60 /* static assert is triggered at compile time, leaving no runtime artefact.
    61  * but can only work with compile-time constants.
    61  * static assert only works with compile-time constants.
    62  * This variant can only be used inside a function. */
    62  * Also, this variant can only be used inside a function. */
    63 #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
    63 #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
    64 
    64 
    65 
    65 
    66 /* DEBUGLEVEL is expected to be defined externally,
    66 /* DEBUGLEVEL is expected to be defined externally,
    67  * typically through compiler command line.
    67  * typically through compiler command line.
    68  * Value must be a number. */
    68  * Value must be a number. */
    69 #ifndef DEBUGLEVEL
    69 #ifndef DEBUGLEVEL
    70 #  define DEBUGLEVEL 0
    70 #  define DEBUGLEVEL 0
    71 #endif
    71 #endif
    72 
    72 
       
    73 
       
    74 /* DEBUGFILE can be defined externally,
       
    75  * typically through compiler command line.
       
    76  * note : currently useless.
       
    77  * Value must be stderr or stdout */
       
    78 #ifndef DEBUGFILE
       
    79 #  define DEBUGFILE stderr
       
    80 #endif
       
    81 
       
    82 
    73 /* recommended values for DEBUGLEVEL :
    83 /* recommended values for DEBUGLEVEL :
    74  * 0 : no debug, all run-time functions disabled
    84  * 0 : release mode, no debug, all run-time checks disabled
    75  * 1 : no display, enables assert() only
    85  * 1 : enables assert() only, no display
    76  * 2 : reserved, for currently active debug path
    86  * 2 : reserved, for currently active debug path
    77  * 3 : events once per object lifetime (CCtx, CDict, etc.)
    87  * 3 : events once per object lifetime (CCtx, CDict, etc.)
    78  * 4 : events once per frame
    88  * 4 : events once per frame
    79  * 5 : events once per block
    89  * 5 : events once per block
    80  * 6 : events once per sequence (verbose)
    90  * 6 : events once per sequence (verbose)
    81  * 7+: events at every position (*very* verbose)
    91  * 7+: events at every position (*very* verbose)
    82  *
    92  *
    83  * It's generally inconvenient to output traces > 5.
    93  * It's generally inconvenient to output traces > 5.
    84  * In which case, it's possible to selectively enable higher verbosity levels
    94  * In which case, it's possible to selectively trigger high verbosity levels
    85  * by modifying g_debug_level.
    95  * by modifying g_debug_level.
    86  */
    96  */
    87 
    97 
    88 #if (DEBUGLEVEL>=1)
    98 #if (DEBUGLEVEL>=1)
    89 #  include <assert.h>
    99 #  include <assert.h>
    93 #  endif
   103 #  endif
    94 #endif
   104 #endif
    95 
   105 
    96 #if (DEBUGLEVEL>=2)
   106 #if (DEBUGLEVEL>=2)
    97 #  include <stdio.h>
   107 #  include <stdio.h>
    98 extern int g_debuglevel; /* here, this variable is only declared,
   108 extern int g_debuglevel; /* the variable is only declared,
    99                            it actually lives in debug.c,
   109                             it actually lives in debug.c,
   100                            and is shared by the whole process.
   110                             and is shared by the whole process.
   101                            It's typically used to enable very verbose levels
   111                             It's not thread-safe.
   102                            on selective conditions (such as position in src) */
   112                             It's useful when enabling very verbose levels
       
   113                             on selective conditions (such as position in src) */
   103 
   114 
   104 #  define RAWLOG(l, ...) {                                      \
   115 #  define RAWLOG(l, ...) {                                      \
   105                 if (l<=g_debuglevel) {                          \
   116                 if (l<=g_debuglevel) {                          \
   106                     fprintf(stderr, __VA_ARGS__);               \
   117                     fprintf(stderr, __VA_ARGS__);               \
   107             }   }
   118             }   }