2018-12-07 06:40:43 +08:00
|
|
|
/*! \file
|
|
|
|
|
|
|
|
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
|
|
|
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
|
|
|
|
2015, 2016, 2017, 2018
|
|
|
|
University Corporation for Atmospheric Research/Unidata.
|
|
|
|
|
|
|
|
See \ref copyright file for more info.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifndef NCGEN_DEBUG_H
|
|
|
|
#define NCGEN_DEBUG_H
|
|
|
|
|
|
|
|
/*********************************************************************
|
2018-12-07 06:40:43 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2010-06-03 21:24:43 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
* $Header: /upc/share/CVS/netcdf-3/ncgen/debug.h,v 1.2 2010/03/31 18:18:34 dmh Exp $
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "generr.h"
|
|
|
|
#include "bytebuffer.h"
|
|
|
|
|
2012-02-14 08:25:32 +08:00
|
|
|
#if 0
|
|
|
|
#define GENDEBUG 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GENDEBUG
|
|
|
|
# if GENDEBUG > 0
|
2013-11-15 06:13:20 +08:00
|
|
|
# define GENDEBUG1
|
2012-02-14 08:25:32 +08:00
|
|
|
# endif
|
|
|
|
# if GENDEBUG > 1
|
2013-11-15 06:13:20 +08:00
|
|
|
# define GENDEBUG2
|
2012-02-14 08:25:32 +08:00
|
|
|
# endif
|
|
|
|
# if GENDEBUG > 2
|
2013-11-15 06:13:20 +08:00
|
|
|
# define GENDEBUG3
|
2012-02-14 08:25:32 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 01:00:38 +08:00
|
|
|
extern int settrace(int);
|
2012-02-14 08:25:32 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
extern int debug;
|
2018-11-16 01:00:38 +08:00
|
|
|
extern int ncgdebug;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
extern void fdebug(const char *fmt, ...);
|
|
|
|
|
2020-05-15 01:20:46 +08:00
|
|
|
#define CHECK_ERR(x) check_err((x),__LINE__,__FILE__,__func__)
|
|
|
|
#define CHECK_ERR2(x,cl) check_err2((x),(cl),__LINE__,__FILE__,__func__)
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#define PANIC(msg) assert(panic(msg))
|
|
|
|
#define PANIC1(msg,arg) assert(panic(msg,arg))
|
|
|
|
#define PANIC2(msg,arg1,arg2) assert(panic(msg,arg1,arg2))
|
|
|
|
#define ASSERT(expr) {if(!(expr)) {panic("assertion failure: %s",#expr);}}
|
|
|
|
extern int panic(const char* fmt, ...);
|
|
|
|
|
|
|
|
/*
|
2017-10-31 05:52:08 +08:00
|
|
|
Provide wrapped versions of XXXalloc for debugging/
|
|
|
|
The wrapped version:
|
|
|
|
1. fails if size is zero or memory is NULL
|
|
|
|
2. fails if memory is exhausted.
|
|
|
|
3. zeros all allocated memory.
|
2010-06-03 21:24:43 +08:00
|
|
|
*/
|
|
|
|
|
2018-11-16 01:00:38 +08:00
|
|
|
#define emalloc(x) chkmalloc(x) /*note only single arg */
|
2017-10-31 05:52:08 +08:00
|
|
|
#define ecalloc(x) chkcalloc(x) /*note only single arg */
|
2010-06-03 21:24:43 +08:00
|
|
|
#define erealloc(p,x) chkrealloc(p,x)
|
|
|
|
#define efree(x) chkfree(x)
|
2017-10-31 05:52:08 +08:00
|
|
|
#define estrdup(x) chkstrdup(x)
|
2018-11-16 01:00:38 +08:00
|
|
|
extern void* chkmalloc(size_t);
|
2017-10-31 05:52:08 +08:00
|
|
|
extern void* chkcalloc(size_t);
|
2010-06-03 21:24:43 +08:00
|
|
|
extern void* chkrealloc(void*,size_t);
|
|
|
|
extern void chkfree(void*);
|
2017-10-31 05:52:08 +08:00
|
|
|
extern char* chkstrdup(const char* s);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#define MEMCHECK(var,throw) {if((var)==NULL) return (throw);}
|
|
|
|
|
|
|
|
#endif /*NCGEN_DEBUG_H*/
|