[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] pvm: Improve PVM assertions by reporting more info
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH v2] pvm: Improve PVM assertions by reporting more info |
Date: |
Sun, 10 Apr 2022 08:59:53 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Supernice.
OK for master!
(And thanks for doing this.)
> 2022-04-09 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * libpoke/pvm.h (pvm_assert): Add more parameters.
> (PVM_ASSERT): New macro.
> * libpoke/pvm.c (pvm_assert): Replace `assert` with an implementation.
> * libpoke/pvm.jitter (PVM_PRINTI): s/pvm_assert/PVM_ASSERT/.
> (PVM_FORMATI): Likewise.
> (PVM_FORMATU): Likewise.
> (exit): Likewise.
> (call): Likewise.
> (asettb): Likewise.
> (strace): Likewise.
> ---
> ChangeLog | 13 +++++++++++++
> libpoke/pvm.c | 15 +++++++++++++--
> libpoke/pvm.h | 12 ++++++++++--
> libpoke/pvm.jitter | 24 ++++++++++++------------
> 4 files changed, 48 insertions(+), 16 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 028753ab..a818abb7 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,16 @@
> +2022-04-09 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> +
> + * libpoke/pvm.h (pvm_assert): Add more parameters.
> + (PVM_ASSERT): New macro.
> + * libpoke/pvm.c (pvm_assert): Replace `assert` with an implementation.
> + * libpoke/pvm.jitter (PVM_PRINTI): s/pvm_assert/PVM_ASSERT/.
> + (PVM_FORMATI): Likewise.
> + (PVM_FORMATU): Likewise.
> + (exit): Likewise.
> + (call): Likewise.
> + (asettb): Likewise.
> + (strace): Likewise.
> +
> 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..9db9eb9b 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 (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..2ce9af5f 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 (int expression, const char *expression_str,
> + const char *filename, int line);
> +
> +#define PVM_ASSERT(expr) pvm_assert ((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..fbef2cff 100644
> --- a/libpoke/pvm.jitter
> +++ b/libpoke/pvm.jitter
> @@ -685,7 +685,7 @@ late-header-c
> break; \
> } \
> \
> - pvm_assert (prec != 0); \
> + PVM_ASSERT (prec != 0); \
> fmt[2] = '0' + (prec / 10); \
> fmt[3] = '0' + prec - (prec / 10 * 10); \
> fmt[4] = '\0'; \
> @@ -795,14 +795,14 @@ late-header-c
> else if ((BASE) == 2) \
> { \
> n = pk_format_binary ((OUT), (OUTLEN), val, JITTER_ARGN0, SIGNED_P,
> 0);\
> - pvm_assert (n == 0); \
> + PVM_ASSERT (n == 0); \
> JITTER_DROP_STACK (); \
> JITTER_DROP_STACK (); \
> JITTER_PUSH_STACK (pvm_make_string ((OUT))); \
> break; \
> } \
> \
> - pvm_assert (prec != 0); \
> + PVM_ASSERT (prec != 0); \
> fmt[2] = '0' + (prec / 10); \
> fmt[3] = '0' + prec - (prec / 10 * 10); \
> fmt[4] = '\0'; \
> @@ -811,7 +811,7 @@ late-header-c
> } \
> \
> n = snprintf ((OUT), (OUTLEN), fmt, (BASE) == 10 ? val : val & mask); \
> - pvm_assert (n < (OUTLEN)); \
> + PVM_ASSERT (n < (OUTLEN)); \
> JITTER_DROP_STACK (); \
> JITTER_DROP_STACK (); \
> JITTER_PUSH_STACK (pvm_make_string ((OUT))); \
> @@ -854,7 +854,7 @@ late-header-c
> else if ((BASE) == 2) \
> { \
> n = pk_format_binary ((OUT), (OUTLEN), val, JITTER_ARGN0, SIGNED_P,
> 0);\
> - pvm_assert (n == 0); \
> + PVM_ASSERT (n == 0); \
> JITTER_DROP_STACK (); \
> JITTER_DROP_STACK (); \
> JITTER_PUSH_STACK (pvm_make_string ((OUT))); \
> @@ -869,7 +869,7 @@ late-header-c
> } \
> \
> n = snprintf ((OUT), (OUTLEN), fmt, (BASE) == 10 ? val : val & mask); \
> - pvm_assert (n < (OUTLEN)); \
> + PVM_ASSERT (n < (OUTLEN)); \
> JITTER_DROP_STACK (); \
> JITTER_DROP_STACK (); \
> JITTER_PUSH_STACK (pvm_make_string ((OUT))); \
> @@ -1167,13 +1167,13 @@ instruction exit ()
> /* Check for the stack sentinel, but only if it was
> installed. */
> if (PVM_STATE_BACKING_FIELD (canary_stack) != NULL)
> - pvm_assert (PVM_STATE_BACKING_FIELD (canary_stack)
> + PVM_ASSERT (PVM_STATE_BACKING_FIELD (canary_stack)
> == JITTER_HEIGHT_STACK ());
> if (PVM_STATE_BACKING_FIELD (canary_returnstack) != NULL)
> - pvm_assert (PVM_STATE_BACKING_FIELD (canary_returnstack)
> + PVM_ASSERT (PVM_STATE_BACKING_FIELD (canary_returnstack)
> == JITTER_HEIGHT_RETURNSTACK ());
> if (PVM_STATE_BACKING_FIELD (canary_exceptionstack) != NULL)
> - pvm_assert (PVM_STATE_BACKING_FIELD (canary_exceptionstack)
> + PVM_ASSERT (PVM_STATE_BACKING_FIELD (canary_exceptionstack)
> == JITTER_HEIGHT_EXCEPTIONSTACK ());
>
> /* Clear pending signals. */
> @@ -1861,7 +1861,7 @@ instruction call ()
> code
> pvm_val closure = JITTER_TOP_STACK ();
>
> - pvm_assert (PVM_VAL_CLS_ENV (closure) != NULL);
> + PVM_ASSERT (PVM_VAL_CLS_ENV (closure) != NULL);
> JITTER_DROP_STACK ();
> PVM_CALL (closure);
> end
> @@ -4887,7 +4887,7 @@ instruction asettb () # ( ARR BOUND -- ARR )
> code
> pvm_val type = PVM_VAL_ARR_TYPE (JITTER_UNDER_TOP_STACK ());
>
> - pvm_assert (PVM_VAL_TYP_CODE (type) == PVM_TYPE_ARRAY);
> + PVM_ASSERT (PVM_VAL_TYP_CODE (type) == PVM_TYPE_ARRAY);
> PVM_VAL_TYP_A_BOUND (type) = JITTER_TOP_STACK ();
> JITTER_DROP_STACK ();
> end
> @@ -6331,7 +6331,7 @@ instruction strace (?n)
> int num_elems = (int) JITTER_ARGN0;
> int num_elems_in_stack;
>
> - pvm_assert (PVM_STATE_BACKING_FIELD (canary_stack) != NULL);
> + PVM_ASSERT (PVM_STATE_BACKING_FIELD (canary_stack) != NULL);
>
> num_elems_in_stack = (pvm_val *)JITTER_HEIGHT_STACK ()
> - (pvm_val *)PVM_STATE_BACKING_FIELD (canary_stack);