Fix bug in error handling where __sub would be clobbered.
diff --git a/src/lisp/error.h b/src/lisp/error.h
index d4c47e8..7f95870 100644
--- a/src/lisp/error.h
+++ b/src/lisp/error.h
@@ -37,56 +37,56 @@
char *message;
};
-#define E_INIT() \
- struct error __error; \
- __error.code = EOK; \
- __error.loc.line = 0; \
- __error.safe_state = false; \
- __error.message = NULL; \
- __error.loc.file = NULL;
-#define NEARVAL(val) \
- __error.loc.line = cons_line(val); \
- __error.loc.file = cons_file(val)
+#define E_DEBUG(_e, _m) // edebug(_e, __FILE__, __LINE__, __func__, _m)
+#define E_INIT() \
+ struct error __error = { 0 };
+#define NEARVAL(val) \
+ __error.loc.line = cons_line(val), \
+ __error.loc.file = cons_file(val)
#define NEARIS(is) (is)->getpos((is), &__error.loc.line, &__error.loc.file)
-#define _TRY(expr, m, c) \
- { \
- struct error __sub = (expr); \
- if (__sub.code) \
- { \
- if (!__sub.loc.file || !__sub.loc.line) \
- __sub.loc.file = __error.loc.file, \
- __sub.loc.line = __error.loc.line; \
- if (c) \
- __sub.code = c; \
- if (m) \
- __sub.message = m; \
- return __sub; \
- } \
+#define _TRY(expr, m, c) \
+ { \
+ struct error __sub = (expr); \
+ if (__sub.code) \
+ { \
+ if (!__sub.loc.file || !__sub.loc.line) \
+ __sub.loc.file = __error.loc.file, \
+ __sub.loc.line = __error.loc.line; \
+ if (c) \
+ __sub.code = c; \
+ char *__m = m; \
+ if (__m) \
+ __sub.message = __m; \
+ E_DEBUG(__sub, #expr); \
+ return __sub; \
+ } \
}
#define TRY(expr) _TRY(expr, NULL, 0)
#define TRY_ELSE(expr, c, ...) _TRY(expr, ehsprintf(__VA_ARGS__), c)
#define OKAY() return __error
-#define THROW(_c, ...) \
- { \
- __error.code = (_c); \
- __error.message = ehsprintf(__VA_ARGS__); \
- return __error; \
+#define THROW(_c, ...) \
+ { \
+ __error.code = (_c); \
+ __error.message = ehsprintf(__VA_ARGS__); \
+ E_DEBUG(__error, "throwing"); \
+ return __error; \
}
-#define THROWSAFE(_c) \
- { \
- __error.code = (_c); \
- __error.safe_state = true; \
- return __error; \
+#define THROWSAFE(_c) \
+ { \
+ __error.code = (_c); \
+ __error.safe_state = true; \
+ E_DEBUG(__error, "safe"); \
+ return __error; \
}
#define IS_OKAY(e) ((e).code == EOK)
-#define OKAY_IF(val) \
- { \
- struct error __sub = (val); \
- if (IS_OKAY(__sub)) \
- OKAY(); \
- if (!__sub.safe_state) \
- TRY(__sub) \
+#define OKAY_IF(val) \
+ { \
+ struct error __sub_of = (val); \
+ if (IS_OKAY(__sub_of)) \
+ OKAY(); \
+ if (!__sub_of.safe_state) \
+ TRY(__sub_of); \
}
#define WARN_UNUSED __attribute__((warn_unused_result))
@@ -96,3 +96,5 @@
char *ehsprintf(const char *msg, ...);
void ereport(struct error err);
+
+void edebug(struct error err, char *file, int line, const char *func, const char *why);