فهرست منبع

More visible messaging for premature exit.

scossu 1 ماه پیش
والد
کامیت
979055662c
1فایلهای تغییر یافته به همراه33 افزوده شده و 14 حذف شده
  1. 33 14
      include/lsup/core.h

+ 33 - 14
include/lsup/core.h

@@ -268,49 +268,68 @@ LSUP_strerror (LSUP_rc rc);
  */
 #define LOG_RC(rc) do {                                             \
     if ((rc) < 0) log_error (LSUP_strerror (rc));                   \
-    else if ((rc) > 0) LOG_DEBUG(LSUP_strerror (rc));               \
+    else if ((rc) > 0) LOG_DEBUG (LSUP_strerror (rc));               \
 } while (0);
 
 /// Jump to `marker` if `exp` does not return `LSUP_OK`.
 #define CHECK(exp, marker) do {                                     \
     LSUP_rc _rc = (exp);                                            \
     LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc != LSUP_OK)) goto marker;                     \
+    if (UNLIKELY (_rc != LSUP_OK)) {                                \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        goto marker;                                                \
+    }                                                               \
 } while (0);
 
 /// Jump to `marker` if `exp` returns a negative value (skip warnings).
 #define PCHECK(exp, marker) do {                                    \
     LSUP_rc _rc = (exp);                                            \
-    LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc < LSUP_OK)) goto marker;                      \
+    if (UNLIKELY (_rc < LSUP_OK)) {                                 \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        goto marker;                                                \
+    }                                                               \
 } while (0);
 
 /// Return `exp` return value if it is of `LSUP_rc` type and nonzero.
 #define RCCK(exp) do {                                              \
     LSUP_rc _rc = (exp);                                            \
-    LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc != LSUP_OK)) return _rc;                       \
+    if (UNLIKELY (_rc != LSUP_OK)) {                                \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        return _rc;                                                 \
+    }                                                               \
 } while (0);
 
 /// Return `exp` return value if it is of `LSUP_rc` type and negative (=error)
-#define PRCCK(exp) do {                                              \
+#define PRCCK(exp) do {                                             \
     LSUP_rc _rc = (exp);                                            \
-    LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc < LSUP_OK)) return _rc;                       \
+    if (UNLIKELY (_rc < LSUP_OK)) {                                 \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        return _rc;                                                 \
+    }                                                               \
 } while (0);
 
 /// Return `NULL` if `exp` returns a nonzero value.
 #define RCNL(exp) do {                                              \
     LSUP_rc _rc = (exp);                                            \
-    LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc != LSUP_OK)) return NULL;                      \
+    if (UNLIKELY (_rc != LSUP_OK)) {                                \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        return NULL;                                                \
+    }                                                               \
 } while (0);
 
 /// Return NULL if `exp` returns a negative value (=error)
-#define PRCNL(exp) do {                                              \
+#define PRCNL(exp) do {                                             \
     LSUP_rc _rc = (exp);                                            \
-    LOG_RC(_rc);                                                    \
-    if (UNLIKELY (_rc < LSUP_OK)) return NULL;                      \
+    if (UNLIKELY (_rc < LSUP_OK)) {                                 \
+        log_error ("*** PREMATURE EXIT due to error:");             \
+        LOG_RC(_rc);                                                \
+        return NULL;                                                \
+    }                                                               \
 } while (0);
 
 /// Allocate one pointer with malloc and return rc if it fails.