Skip to content

Commit

Permalink
THGeneral.h.in: add generic cleanup mechanism for error macros that d…
Browse files Browse the repository at this point in the history
…o not return
  • Loading branch information
tkoeppe committed Feb 11, 2016
1 parent b33ac90 commit bb0c3fb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/TH/THGeneral.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,27 @@ TH_API void THSetGCHandler( void (*torchGCHandlerFunction)(void *data), void *da
TH_API void THHeapUpdate(long size);

#define THError(...) _THError(__FILE__, __LINE__, __VA_ARGS__)
#define THArgCheck(...) _THArgCheck(__FILE__, __LINE__, __VA_ARGS__)

#define THCleanup(...) __VA_ARGS__

#define THArgCheck(...) \
do { \
_THArgCheck(__FILE__, __LINE__, __VA_ARGS__); \
} while(0)

#define THArgCheckWithCleanup(condition, cleanup, ...) \
do if (!(condition)) { \
cleanup \
_THArgCheck(__FILE__, __LINE__, 0, __VA_ARGS__); \
} while(0)

#define THAssert(exp) \
do { \
if (!(exp)) { \
_THAssertionFailed(__FILE__, __LINE__, #exp, ""); \
} \
} while(0)

#define THAssertMsg(exp, ...) \
do { \
if (!(exp)) { \
Expand Down

0 comments on commit bb0c3fb

Please sign in to comment.