poke-devel
[Top][All Lists]
Advanced

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

[PATCH] pvm: Improve PVM assertions by reporting more info


From: Mohammad-Reza Nabipoor
Subject: [PATCH] pvm: Improve PVM assertions by reporting more info
Date: Sat, 9 Apr 2022 22:07:43 +0430

2022-04-09  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * libpoke/pvm.h (pvm_assert_full): New function.
        (pvm_assert): Changed to a macro that calls `pvm_assert_full`.
        * libpoke/pvm.c (pvm_assert): Removed.
        (pvm_assert_full): New function.
        * libpoke/pvm.jitter (wrapped-functions):
        s/pvm_assert/pvm_assert_full/.
---
 ChangeLog          |  9 +++++++++
 libpoke/pvm.c      | 15 +++++++++++++--
 libpoke/pvm.h      | 12 ++++++++++--
 libpoke/pvm.jitter |  2 +-
 4 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 028753ab..f4f5278f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-04-09  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * libpoke/pvm.h (pvm_assert_full): New function.
+       (pvm_assert): Changed to a macro that calls `pvm_assert_full`.
+       * libpoke/pvm.c (pvm_assert): Removed.
+       (pvm_assert_full): New function.
+       * libpoke/pvm.jitter (wrapped-functions):
+       s/pvm_assert/pvm_assert_full/.
+
 2022-04-09  Jose E. Marchesi  <jemarch@gnu.org>
 
        * pickles/openpgp.pk: New file.
diff --git a/libpoke/pvm.c b/libpoke/pvm.c
index 5aa3f5bf..5c543b56 100644
--- a/libpoke/pvm.c
+++ b/libpoke/pvm.c
@@ -373,7 +373,18 @@ pvm_set_compiler (pvm apvm, pkl_compiler compiler)
 }
 
 void
-pvm_assert (int expression)
+pvm_assert_full (int expression, const char *expression_str,
+                 const char *filename, int line)
 {
-  assert (expression);
+#ifndef NDEBUG
+
+  if (!expression)
+    {
+      fprintf (stderr, "PVM assertion failed: %s (%s:%d)\n", expression_str,
+               filename, line);
+      fflush (NULL);
+      abort ();
+    }
+
+#endif
 }
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index 1ca3d241..6bf27851 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -728,9 +728,17 @@ void pvm_set_compiler (pvm vm, pkl_compiler compiler);
 
 /* The following function is to be used in pvm.jitter, because the
    system `assert' may expand to a macro and is therefore
-   non-wrappeable.  */
+   non-wrappeable.
 
-void pvm_assert (int expression);
+   EXPRESSION is the predicate that is expected to be non-zero.
+   EXPRESSION_STR is the string representation of the EXPRESSION.
+   FILENAME and LINE are the location information of invocation
+   of this function.  */
+
+void pvm_assert_full (int expression, const char *expression_str,
+                      const char *filename, int line);
+
+#define pvm_assert(expr) pvm_assert_full ((expr), #expr, __FILE__, __LINE__)
 
 /* This is defined in the late-c block in pvm.jitter.  */
 
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index 2a40de39..8e56ad40 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -69,7 +69,7 @@ wrapped-functions
   snprintf
   pvm_array_insert
   pvm_array_set
-  pvm_assert
+  pvm_assert_full
   pvm_env_lookup
   pvm_env_register
   pvm_env_pop_frame
-- 
2.35.1




reply via email to

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