Skip to content

Commit

Permalink
Move mem check macros to memcheck.h
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed Jun 10, 2015
1 parent 4cd67c0 commit 6799d1c
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion extension/boolexpr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ all: bld/test/run bld/cover/run bld/lib/libboolexpr.a
# Source Code
#===============================================================================

BOOLEXPR_HDRS := boolexpr.h primes-inl.c
BOOLEXPR_HDRS := boolexpr.h memcheck.h primes-inl.c

BOOLEXPR_SRCS := \
argset.c \
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/argset.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* boolexpr.c */
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* boolexpr.c */
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/boolexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


#define READ_ARGS(n, xs) \
Expand Down
48 changes: 0 additions & 48 deletions extension/boolexpr/boolexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,6 @@ extern "C" {
#endif


#define CHECK_NULL(y, x) \
do { \
if ((y = x) == NULL) \
return NULL; \
} while (0)


#define CHECK_NULL_1(y, x, temp) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(temp); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_2(y, x, t0, t1) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(t0); \
BX_DecRef(t1); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_3(y, x, t0, t1, t2) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(t0); \
BX_DecRef(t1); \
BX_DecRef(t2); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_N(y, x, n, temps) \
do { \
if ((y = x) == NULL) { \
for (size_t i = 0; i < n; ++i) \
BX_DecRef(temps[i]); \
free(temps); \
return NULL; \
} \
} while (0)


/* Kind checks */
#define IS_ZERO(ex) (((ex)->kind) == ZERO)
#define IS_ONE(ex) (((ex)->kind) == ONE)
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/bubble.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* util.c */
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* boolexpr.c */
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/flatten.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


#define DUAL(kind) (OP_OR + OP_AND - kind)
Expand Down
61 changes: 61 additions & 0 deletions extension/boolexpr/memcheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
** Filename: memcheck.h
**
** Convenience macros for checking memory allocation
*/


#ifndef MEMCHECK_H
#define MEMCHECK_H


#define CHECK_NULL(y, x) \
do { \
if ((y = x) == NULL) \
return NULL; \
} while (0)


#define CHECK_NULL_1(y, x, temp) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(temp); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_2(y, x, t0, t1) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(t0); \
BX_DecRef(t1); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_3(y, x, t0, t1, t2) \
do { \
if ((y = x) == NULL) { \
BX_DecRef(t0); \
BX_DecRef(t1); \
BX_DecRef(t2); \
return NULL; \
} \
} while (0)


#define CHECK_NULL_N(y, x, n, temps) \
do { \
if ((y = x) == NULL) { \
for (size_t i = 0; i < n; ++i) \
BX_DecRef(temps[i]); \
free(temps); \
return NULL; \
} \
} while (0)


#endif // MEMCHECK_H

1 change: 1 addition & 0 deletions extension/boolexpr/nnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* nnf.c */
Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/product.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* array.c */
Expand Down
2 changes: 2 additions & 0 deletions extension/boolexpr/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


#define CMP(x, y) ((x) < (y) ? -1 : (x) > (y))

Expand Down
1 change: 1 addition & 0 deletions extension/boolexpr/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdlib.h>

#include "boolexpr.h"
#include "memcheck.h"


/* boolexpr.c */
Expand Down

0 comments on commit 6799d1c

Please sign in to comment.