jitterbug/try.h

26 lines
1 KiB
C
Raw Normal View History

2023-01-16 02:20:53 +02:00
#ifndef __JITTERBUG_TRY_H
#define __JITTERBUG_TRY_H
2023-01-16 16:04:09 +02:00
#include "config.h"
#include "util.h"
2023-01-16 02:20:53 +02:00
#ifdef JB_ENABLE_TRY_TRACE
2023-01-01 05:22:37 +02:00
#define __TRY_TRACE() do { \
printf("trace: %s:%d\n", __FILE__, __LINE__); \
2023-01-16 02:20:53 +02:00
} while(0)
#else
#define __TRY_TRACE()
#endif // JB_ENABLE_TRY_TRACE
2022-12-25 20:54:10 +02:00
2023-01-01 05:22:37 +02:00
// NOTE: The macro(s) below make use of a GCC extension called "Statement Exprs", which is nonstandard.
// More info: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
2023-01-16 16:04:09 +02:00
#define TRYPTR_NIL(M_expr) __extension__({ void* _result = (void*)(M_expr); if (unlikely(!_result)) { __TRY_TRACE(); return (NULL); } _result; })
#define TRYPTR(M_expr) __extension__({ void* _result = (void*)(M_expr); if (unlikely(!_result)) { __TRY_TRACE(); return (-1); } _result; })
2023-01-16 16:04:09 +02:00
#define TRYST_NIL(M_expr) __extension__({ int _result = (int)(M_expr); if (unlikely(_result < 0)) { __TRY_TRACE(); return (NULL); } _result; })
#define TRYST(M_expr) __extension__({ int _result = (int)(M_expr); if (unlikely(_result < 0)) { __TRY_TRACE(); return (-1); } _result; })
2023-01-16 02:20:53 +02:00
#endif // __JITTERBUG_TRY_H