[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3] pkl, libpoke: report exception in pk{l, }_load functions
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH v3] pkl, libpoke: report exception in pk{l, }_load functions |
Date: |
Fri, 06 Oct 2023 13:08:01 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> /* Compile commands written in Poke. */
> - if (pk_load (poke_compiler, "pk-cmd") != PK_OK)
> - pk_fatal ("unable to load the pk-cmd module");
> + if (pk_load (poke_compiler, "pk-cmd", &exception) != PK_OK)
> + {
> + poke_handle_exception (exception);
> + pk_fatal ("unable to load the pk-cmd module");
> + }
> }
That should be:
if (pk_load (poke_compiler, "pk-cmd", &exception) != PK_OK
|| exception != PK_NULL)
{
if (exception != PK_NULL)
poke_handle_exception (exception);
pk_fatal ("unable to load the pk-cmd module");
}
> void
> diff --git a/poke/poke.c b/poke/poke.c
> index d6ecf596..e2fb326d 100644
> --- a/poke/poke.c
> +++ b/poke/poke.c
> @@ -651,15 +651,19 @@ initialize (int argc, char *argv[])
> free (newpaths);
> }
>
> - /* The Poke hyperlinks facilities must be loaded before poke.pk and
> - the cmd subsystem. This is done even if the hserver is
> - disabled. */
> - if (pk_load (poke_compiler, "pk-hserver") != PK_OK)
> - pk_fatal ("unable to load the pk-hserver module");
> -
> - /* Load poke.pk */
> - if (pk_load (poke_compiler, "poke") != PK_OK)
> - pk_fatal ("unable to load the poke module");
> + {
> + pk_val exception;
> +
> + /* The Poke hyperlinks facilities must be loaded before poke.pk and
> + the cmd subsystem. This is done even if the hserver is
> + disabled. */
> + if (pk_load (poke_compiler, "pk-hserver", &exception) != PK_OK)
> + pk_fatal ("unable to load the pk-hserver module");
> +
> + /* Load poke.pk */
> + if (pk_load (poke_compiler, "poke", &exception) != PK_OK)
> + pk_fatal ("unable to load the poke module");
> + }
And the same above. Loading poke.pk and pk-hserver.pk may result in a
run-time exception.
> /* Set the values of a few global variables defined in poke.pk. */
> {
> diff --git a/pokefmt/pokefmt.l b/pokefmt/pokefmt.l
> index fffda29f..891f7832 100644
> --- a/pokefmt/pokefmt.l
> +++ b/pokefmt/pokefmt.l
> @@ -503,7 +503,8 @@ poke_init (struct poke *pk, const char *poke_src_file,
> FILE *output)
> free (user_load_path);
> }
>
> - if (pk_load (pk->compiler, "pokefmt") != PK_OK)
> + if (pk_load (pk->compiler, "pokefmt", &pexc) != PK_OK)
> + /* There's no default exception handler yet to handle `pexc'. */
> errx (1, "pk_load() failed for pokefmt.pk");
Similar situation, only this time you cannot handle the exception. But
you should handle the situatio pexc != PK_NULL.
> if (pk_decl_val (pk->compiler, "pokefmt_expr_printer") == PK_NULL)
> diff --git a/testsuite/poke.libpoke/api.c b/testsuite/poke.libpoke/api.c
> index 906998b1..805c16e7 100644
> --- a/testsuite/poke.libpoke/api.c
> +++ b/testsuite/poke.libpoke/api.c
> @@ -117,6 +117,24 @@ test_pk_keyword_p (pk_compiler pkc)
> T ("pk_keyword_p_2", !pk_keyword_p (pkc, "foo"));
> }
>
> +static void
> +test_pk_load (pk_compiler pkc)
> +{
> + /* An invalid value for pk_val, just to make sure pk_load is
> + modifying it. */
> + pk_val exception = 0;
> +
> + T ("pk_load_1", pk_load (pkc, "std", &exception) == PK_OK);
> + T ("pk_load_1 exception", exception == PK_NULL);
> +
> + exception = 0; /* Again resetting to an invalid value. */
> +
> + T ("pk_load_2", pk_load (pkc, "a-module_which-does_not-exist",
> + &exception) == PK_ERROR);
> + /* Still has the invalid value. */
> + T ("pk_load_1 exception", exception == 0);
> +}
> +
> int
> main ()
> {
> @@ -124,8 +142,9 @@ main ()
>
> pkc = test_pk_compiler_new ();
>
> - test_pk_compiler_free (pkc);
> test_pk_keyword_p (pkc);
> + test_pk_load (pkc);
> + test_pk_compiler_free (pkc);
>
> return 0;
> }
- Re: [PATCH 2/2] pkl, libpoke: report exception in pk{l, }_load functions, Jose E. Marchesi, 2023/10/03
- [PATCH v2 1/3] libpoke: use nonnull attribute for pk_compile_* functions, Mohammad-Reza Nabipoor, 2023/10/03
- [PATCH v2 2/3] pkl, libpoke: report exception in pk{l, }_load functions, Mohammad-Reza Nabipoor, 2023/10/03
- Re: [PATCH v2 2/3] pkl,libpoke: report exception in pk{l,}_load functions, Jose E. Marchesi, 2023/10/04
- [PATCH v3] pkl,libpoke: report exception in pk{l,}_load functions, Mohammad-Reza Nabipoor, 2023/10/05
- Re: [PATCH v3] pkl, libpoke: report exception in pk{l, }_load functions,
Jose E. Marchesi <=
- [PATCH v2 3/3] pkl: fix comment for `pkl_execute_{file,buffer}', Mohammad-Reza Nabipoor, 2023/10/03
Re: [PATCH v2 1/3] libpoke: use nonnull attribute for pk_compile_* functions, Jose E. Marchesi, 2023/10/04