From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail
From: Philipp Stephani
Newsgroups: gmane.emacs.bugs
Subject: bug#30373: Support finalizers for functions created in dynamic modules
Date: Mon, 23 Dec 2019 21:41:16 +0100
Message-ID:
References:
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226";
logging-data="243427"; mail-complaints-to="usenet@blaine.gmane.org"
Cc: 30373@debbugs.gnu.org
To: Samir Jindel
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 23 21:42:12 2019
Return-path:
Envelope-to: geb-bug-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([209.51.188.17])
by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.89)
(envelope-from )
id 1ijUWo-0011D0-18
for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Dec 2019 21:42:10 +0100
Original-Received: from localhost ([::1]:32872 helo=lists1p.gnu.org)
by lists.gnu.org with esmtp (Exim 4.90_1)
(envelope-from )
id 1ijUWm-0002YB-PU
for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Dec 2019 15:42:08 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42498)
by lists.gnu.org with esmtp (Exim 4.90_1)
(envelope-from ) id 1ijUWh-0002Xt-E7
for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2019 15:42:04 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1ijUWg-0005TB-9q
for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2019 15:42:03 -0500
Original-Received: from debbugs.gnu.org ([209.51.188.43]:45745)
by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
(Exim 4.71) (envelope-from )
id 1ijUWg-0005Sl-6Z
for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2019 15:42:02 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
(envelope-from ) id 1ijUWg-0001SW-2d
for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2019 15:42:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Philipp Stephani
Original-Sender: "Debbugs-submit"
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Mon, 23 Dec 2019 20:42:02 +0000
Resent-Message-ID:
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 30373
X-GNU-PR-Package: emacs
Original-Received: via spool by 30373-submit@debbugs.gnu.org id=B30373.15771336955573
(code B ref 30373); Mon, 23 Dec 2019 20:42:02 +0000
Original-Received: (at 30373) by debbugs.gnu.org; 23 Dec 2019 20:41:35 +0000
Original-Received: from localhost ([127.0.0.1]:51718 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from )
id 1ijUWE-0001Rp-Vi
for submit@debbugs.gnu.org; Mon, 23 Dec 2019 15:41:35 -0500
Original-Received: from mail-ot1-f41.google.com ([209.85.210.41]:36697)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from ) id 1ijUWD-0001Rd-Hs
for 30373@debbugs.gnu.org; Mon, 23 Dec 2019 15:41:34 -0500
Original-Received: by mail-ot1-f41.google.com with SMTP id 19so11065473otz.3
for <30373@debbugs.gnu.org>; Mon, 23 Dec 2019 12:41:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=nywWsBE52hEXtyOM6YctpShhOR208OjtyPzdUcrIlLE=;
b=Ob2iykpC6A9poMyJpJUHAwySpSEFrImKFPM6cqIojcoe/UzoZ2axhX3Q4hV5F2bX3g
LpmWnfTrgrL9+eDhGQTARQzdF47HeYTebJezO2a/cZA/+o8J7bVjSxd8Jw5EjOK/Bq4I
CXju1JlqUJtVeKIXIQkvOFGI3/KAD7Qlhthh1JzT1A0t+Rs//N0yflXLHPTkk2TPyiAJ
cqumtrPS9tK6//tD1Y67tzl5rTM/xQ5bKZAbalkze/dMUlioNR2lmCC5Q6v2hX1Zw0ig
8bdAwLWtl5izO6L2AyqxxjZyF2A0ke3PM366n7Yi2ubki7zwlB23kJ9Lji2+MtJaOjrL
VEdg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=nywWsBE52hEXtyOM6YctpShhOR208OjtyPzdUcrIlLE=;
b=Y5jx9BajRXMVfQ/+BqG+UqOEsSFbiJP1ZVtnod0fmrzlzE07FSAeGcUc2tklpV8x3L
79FlaXT8kmE6r1t3sY97MvO40wKOE/fQGO7jxMrcyyDTlDjYZPMKX/puZ2WSGs3YI+2h
0EfB8Nophr4TRJ2nTwCx1ZqfOSnOCYZXxI/k9XwbYgXRkzENcF6ukgecv20nZeMCikAW
uyctOD5XPSWWN80bcuL9i41BerYhPP2RUfvRcZXC5uMVtB07jol1JGcPkyN9JBqvVhxh
tTgeuvkxe7qmC48SRFzKAWmiEuspvbrOGq6/E7c9OPDBzjYTTLP+D8cL9wUHiqVG3kzT
AUSw==
X-Gm-Message-State: APjAAAULledyceBN9Sc1FJSeeYTthfVYJPAEg1sHM7YjYWKexFptGTSx
3X7DLttMGznhzu0zZFTuYsXB7BRHoRaP1eEBojE=
X-Google-Smtp-Source: APXvYqy9adkQCL8PN/2AegX2Yzg3mmocp9lYkJjfqfMq1spKBPDeusq6Cc/1A7FA/pHFwvEG+/Xzp/DBL84eoFQ+tCM=
X-Received: by 2002:a9d:4b05:: with SMTP id q5mr22081046otf.174.1577133687651;
Mon, 23 Dec 2019 12:41:27 -0800 (PST)
In-Reply-To:
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 209.51.188.43
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
the Swiss army knife of text editors"
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "bug-gnu-emacs"
Xref: news.gmane.org gmane.emacs.bugs:173687
Archived-At:
Am Di., 6. Feb. 2018 um 22:43 Uhr schrieb Samir Jindel :
>
> 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?