File: err_macros.h

package info (click to toggle)
cf-python 1.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,996 kB
  • sloc: python: 51,733; ansic: 2,736; makefile: 78; sh: 2
file content (36 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/* error-checking macros */

/* these are to allow a compact way of incorporating error-checking of 
 * the return value of a function call, without obfuscating the basic purpose
 * of the line of code, which is executing the function call.
 *
 * CKI used for integer functions which return negative value on failure
 * CKP used for pointer functions which return NULL on failure
 * CKF for floats for good measure (probably not used)
 *
 * put the ERRBLK (or ERRBLKI or ERRBLKP) at the end of the subroutine
 */

#define FLT_ERR -1e38

#ifdef DEBUG
#define ERR abort();
#else
/* ERR: unconditional branch */
#define ERR goto err;
#endif

#define CKI(i) if ((i) < 0){ ERR }
#define CKP(p) if ((p) == NULL){ ERR }
#define CKF(f) if ((f) == FLT_ERR){ ERR }

/* ERRIF: conditional branch */
#define ERRIF(i) if (i){ ERR }

#define GRIPE gripe(__func__);
#define SWITCH_BUG switch_bug(__func__); ERR;
#define ERRBLK(rtn) err: GRIPE; return (rtn);
#define ERRBLKI ERRBLK(-1);
#define ERRBLKP ERRBLK(NULL);
#define ERRBLKF ERRBLK(FLT_ERR);