poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 2/3] libpoke: add `pk_{s,g}et_user_data' functions


From: Jose E. Marchesi
Subject: Re: [PATCH 2/3] libpoke: add `pk_{s,g}et_user_data' functions
Date: Tue, 14 Nov 2023 20:30:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

> 2023-11-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>
>       * libpoke/libpoke.h (pk_set_user_data): New function to register an
>       opaque data pointer.
>       (pk_get_user_data): New function to retrieve the registered opaque
>       data pointer.
>       * libpoke/libpoke.c (struct _pk_compiler): Add new field `user_data'.
>       (pk_set_user_data): New function impl.
>       (pk_get_user_data): Likewise.
>       * testsuite/poke.libpoke/api.c (main): Add tests for new functions.
> ---
>  ChangeLog                    | 11 +++++++++++
>  libpoke/libpoke.c            | 15 +++++++++++++++
>  libpoke/libpoke.h            |  5 +++++
>  testsuite/poke.libpoke/api.c |  2 ++
>  4 files changed, 33 insertions(+)
>
> diff --git a/ChangeLog b/ChangeLog
> index 42d1e9f8..594e2014 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,14 @@
> +2023-11-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * libpoke/libpoke.h (pk_set_user_data): New function to register an
> +     opaque data pointer.
> +     (pk_get_user_data): New function to retrieve the registered opaque
> +     data pointer.
> +     * libpoke/libpoke.c (struct _pk_compiler): Add new field `user_data'.
> +     (pk_set_user_data): New function impl.
> +     (pk_get_user_data): Likewise.
> +     * testsuite/poke.libpoke/api.c (main): Add tests for new functions.
> +
>  2023-11-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * common/pk-utils.h (pk_print_binary): Remove function decl.
> diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
> index 9ed02a50..f1d896ae 100644
> --- a/libpoke/libpoke.c
> +++ b/libpoke/libpoke.c
> @@ -44,6 +44,7 @@ struct _pk_compiler
>    ios completion_ios;
>    int completion_idx;
>    struct pkl_ast_node_iter completion_iter;
> +  void *user_data;
>  };
>  
>  struct pk_term_if libpoke_term_if;
> @@ -134,6 +135,20 @@ pk_errno (pk_compiler pkc)
>    return PK_ERROR;
>  }
>  
> +void
> +pk_set_user_data (pk_compiler pkc, void *user_data)
> +{
> +  pkc->status = PK_OK;
> +  pkc->user_data = user_data;
> +}
> +
> +void *
> +pk_get_user_data (pk_compiler pkc)
> +{
> +  pkc->status = PK_OK;
> +  return pkc->user_data;
> +}
> +
>  int
>  pk_compile_file (pk_compiler pkc, const char *filename,
>                   pk_val *exit_exception)
> diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
> index 66575a70..1ac05fda 100644
> --- a/libpoke/libpoke.h
> +++ b/libpoke/libpoke.h
> @@ -166,6 +166,11 @@ void pk_unregister_thread (void) LIBPOKE_API;
>  
>  int pk_errno (pk_compiler pkc) LIBPOKE_API;
>  
> +/* Set/get user-defined opaque data to the compiler instance.  */

Please explain in the comment that this pointer is then accessible to
several callbacks from libpoke.

Given that, OK for master.
Thanks!

> +
> +void pk_set_user_data (pk_compiler pkc, void *user_data) LIBPOKE_API;
> +void *pk_get_user_data (pk_compiler pkc) LIBPOKE_API;
> +
>  /* Compile and execute a Poke program from the given file FILENAME.
>  
>     EXIT_EXCEPTION is a pointer to a pk_val variable that is set to an
> diff --git a/testsuite/poke.libpoke/api.c b/testsuite/poke.libpoke/api.c
> index 471e5c18..5bdbb9bc 100644
> --- a/testsuite/poke.libpoke/api.c
> +++ b/testsuite/poke.libpoke/api.c
> @@ -237,9 +237,11 @@ main ()
>  
>    pkc = test_pk_compiler_new ();
>  
> +  pk_set_user_data (pkc, (uintptr_t)0xdeadbeef);
>    test_pk_keyword_p (pkc);
>    test_pk_load (pkc);
>    test_pk_ios (pkc);
> +  T ("pk_get_user_data", pk_get_user_data (pkc) == (uintptr_t)0xdeadbeef);
>    test_pk_compiler_free (pkc);
>  
>    return 0;



reply via email to

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