poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] pkl: make PK_UNREACHABLE more verbose


From: Mohammad-Reza Nabipoor
Subject: [PATCH v2] pkl: make PK_UNREACHABLE more verbose
Date: Tue, 14 Feb 2023 21:04:08 +0100

2023-02-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * common/pk-utils.h (pk_unreachable): New function declaration.
        (PK_UNREACHABLE): Changed the macro to use `pk_unreachable'.
        * common/pk-utils.c (pk_unreachable): New function definition.
---
 ChangeLog         |  6 ++++++
 common/pk-utils.c |  9 +++++++++
 common/pk-utils.h | 17 ++++++++++-------
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4261944e..ccdbb8e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-02-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * common/pk-utils.h (pk_unreachable): New function declaration.
+       (PK_UNREACHABLE): Changed the macro to use `pk_unreachable'.
+       * common/pk-utils.c (pk_unreachable): New function definition.
+
 2023-02-14  Hannes Domani  <ssbssa@yahoo.de>
 
        * pickles/pe.pk: Add size_of_stack_reserve.
diff --git a/common/pk-utils.c b/common/pk-utils.c
index 612f8a89..f5874d31 100644
--- a/common/pk-utils.c
+++ b/common/pk-utils.c
@@ -222,3 +222,12 @@ pk_str_trim (char **str)
   while (isspace (*--end));
   *(end + 1) = '\0';
 }
+
+void
+pk_unreachable (const char *funcname, const char *filename, int line)
+{
+  fprintf (stderr, "unreachable reached in function %s (%s:%d)\n", funcname,
+           filename, line);
+  fflush (NULL);
+  abort ();
+}
diff --git a/common/pk-utils.h b/common/pk-utils.h
index a4dba8e1..37713413 100644
--- a/common/pk-utils.h
+++ b/common/pk-utils.h
@@ -66,13 +66,16 @@ char *pk_str_replace (const char *in, const char *search, 
const char *replace);
 /* Left and rigth trim the given string from whitespaces.  */
 void pk_str_trim (char **str);
 
+/* This function is called when the program reaches a supposedly
+   unreachable point; print an error message and abort the execution.
+
+   FUNCNAME is the name of function in which PK_UNREACHABLE is invoked.
+   FILENAME and LINE are the location information of invocation
+   of this function.  */
+void pk_unreachable (const char *funcname, const char *filename, int line)
+    __attribute__ ((noreturn));
+
 /* Diagnoses reaching unreachable code, and aborts.  */
-#define PK_UNREACHABLE() \
-  do                                                    \
-    {                                                   \
-      assert (0 && "Reached unreachable code.");        \
-      abort ();                                         \
-    }                                                   \
-  while (0)
+#define PK_UNREACHABLE() pk_unreachable (__func__, __FILE__, __LINE__)
 
 #endif /* ! PK_UTILS_H */
-- 
2.39.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]