all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Samir Jindel <sjindel@google.com>
Cc: 30373@debbugs.gnu.org
Subject: bug#30373: Support finalizers for functions created in dynamic modules
Date: Mon, 23 Dec 2019 21:41:16 +0100	[thread overview]
Message-ID: <CAArVCkT9s_2ud9RLW4w+J9Vwwz1ewvVq3wkpuOhdSaYcS=hx8Q@mail.gmail.com> (raw)
In-Reply-To: <CAKjqF1Pd3iVFRjVBz1tdBrxycqhQjhevbhuZOois+yRFMggQ0w@mail.gmail.com>

Am Di., 6. Feb. 2018 um 22:43 Uhr schrieb Samir Jindel <sjindel@google.com>:
>
> Hi,
>
> I'm very excited by the possibilities opened through the new dynamic module interface, "emacs-module.h".
>
> However, I have a concern about the API for creating Lisp functions bound to native functions:
>
> ```c
>
>   emacs_value (*make_function) (emacs_env *env,
>         ptrdiff_t min_arity,
>         ptrdiff_t max_arity,
>         emacs_value (*function) (emacs_env *env,
>                ptrdiff_t nargs,
>                emacs_value args[],
>                void *)
>           EMACS_NOEXCEPT,
>         const char *documentation,
>         void *data);
>
> ```
>
> I presume the "data" pointer here is provided to enable native functions to work like closures,
> carrying additional, possibly dynamically allocated data. However, this functionality is limited by
> the absence of a finalization function pointer, like the "user_ptr" values have:
>
> ```c
>
>   emacs_value (*make_user_ptr) (emacs_env *env,
>         void (*fin) (void *) EMACS_NOEXCEPT,
>         void *ptr);
>
> ```
>
> Without the ability to provide a finalizer, a module can only safely make the "data" pointer to
> "make_function" point to static memory.
>

Sorry for not responding for so long. I think this makes a lot of
sense, and we should definitely introduce function finalizers.
I can think of three possible interface choices for this:
1. Add a make_finalizable_function environment function that is like
make_function but accepts a finalizer.
2. Add a set_function_finalizer(env, emacs_value, void(*)(void))
environment function.
3. Allow set_user_finalizer to also set function finalizers.
I'd lean away from (1) since it makes an already complex interface
even more complex. (2) seems cleanest, but requires adding a new
environment function. (3) would require the least amount of changes,
but it would also be slightly less clean than (2), and would break
backwards compatibility in a subtle way (users relying on
set_user_finalizer raising an error if a non-user-pointer object is
passed would break). Overall, I'd slightly lean towards (2).
Other opinions?





  reply	other threads:[~2019-12-23 20:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06 21:17 bug#30373: Support finalizers for functions created in dynamic modules Samir Jindel
2019-12-23 20:41 ` Philipp Stephani [this message]
2019-12-26  0:04   ` bug#30373: [PATCH] Implement finalizers for module functions (Bug#30373) Philipp Stephani
2020-01-03 18:34     ` Philipp Stephani
2020-01-03 18:44       ` Eli Zaretskii
2020-01-03 18:53         ` Pip Cet
2020-01-03 20:13           ` Eli Zaretskii
2020-01-03 20:49             ` Pip Cet
2020-01-04 19:56               ` Philipp Stephani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAArVCkT9s_2ud9RLW4w+J9Vwwz1ewvVq3wkpuOhdSaYcS=hx8Q@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=30373@debbugs.gnu.org \
    --cc=sjindel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.