1 /*! \file 2 3 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 4 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 5 2015, 2016, 2017, 2018 6 University Corporation for Atmospheric Research/Unidata. 7 8 See \ref copyright file for more info. 9 10 */ 11 12 #ifndef NCGEN_DEBUG_H 13 #define NCGEN_DEBUG_H 14 15 /********************************************************************* 16 * Copyright 2018, UCAR/Unidata 17 * See netcdf/COPYRIGHT file for copying and redistribution conditions. 18 * $Header: /upc/share/CVS/netcdf-3/ncgen/debug.h,v 1.2 2010/03/31 18:18:34 dmh Exp $ 19 *********************************************************************/ 20 21 #include <stdarg.h> 22 #include <assert.h> 23 #include "generr.h" 24 #include "bytebuffer.h" 25 26 #if 0 27 #define GENDEBUG 2 28 #endif 29 30 #ifdef GENDEBUG 31 # if GENDEBUG > 0 32 # define GENDEBUG1 33 # endif 34 # if GENDEBUG > 1 35 # define GENDEBUG2 36 # endif 37 # if GENDEBUG > 2 38 # define GENDEBUG3 39 # endif 40 #endif 41 42 extern int settrace(int); 43 44 extern int debug; 45 extern int ncgdebug; 46 47 extern void fdebug(const char *fmt, ...); 48 49 #define PANIC(msg) assert(panic(msg)) 50 #define PANIC1(msg,arg) assert(panic(msg,arg)) 51 #define PANIC2(msg,arg1,arg2) assert(panic(msg,arg1,arg2)) 52 #define ASSERT(expr) {if(!(expr)) {panic("assertion failure: %s",#expr);}} 53 extern int panic(const char* fmt, ...); 54 55 /* 56 Provide wrapped versions of XXXalloc for debugging/ 57 The wrapped version: 58 1. fails if size is zero or memory is NULL 59 2. fails if memory is exhausted. 60 3. zeros all allocated memory. 61 */ 62 63 #define emalloc(x) chkmalloc(x) /*note only single arg */ 64 #define ecalloc(x) chkcalloc(x) /*note only single arg */ 65 #define erealloc(p,x) chkrealloc(p,x) 66 #define efree(x) chkfree(x) 67 #define estrdup(x) chkstrdup(x) 68 extern void* chkmalloc(size_t); 69 extern void* chkcalloc(size_t); 70 extern void* chkrealloc(void*,size_t); 71 extern void chkfree(void*); 72 extern char* chkstrdup(const char* s); 73 74 #define MEMCHECK(var,throw) {if((var)==NULL) return (throw);} 75 76 #endif /*NCGEN_DEBUG_H*/ 77