From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Samir Jindel Newsgroups: gmane.emacs.bugs Subject: bug#30373: Support finalizers for functions created in dynamic modules Date: Tue, 6 Feb 2018 22:17:11 +0100 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="f403045e36c8ee3200056491b4ee" X-Trace: blaine.gmane.org 1517953305 31063 195.159.176.226 (6 Feb 2018 21:41:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 6 Feb 2018 21:41:45 +0000 (UTC) To: 30373@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 06 22:41:41 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejAzZ-00078z-C8 for geb-bug-gnu-emacs@m.gmane.org; Tue, 06 Feb 2018 22:41:29 +0100 Original-Received: from localhost ([::1]:39346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejB1a-0003Sx-Mg for geb-bug-gnu-emacs@m.gmane.org; Tue, 06 Feb 2018 16:43:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAkd-0004FA-61 for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:26:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejAkc-0006ob-A9 for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:26:03 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52712) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejAkc-0006oS-5r for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ejAkb-0004fV-RX for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:26:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Samir Jindel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 06 Feb 2018 21:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30373 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.151795233117897 (code B ref -1); Tue, 06 Feb 2018 21:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Feb 2018 21:25:31 +0000 Original-Received: from localhost ([127.0.0.1]:60609 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejAk7-0004eb-Di for submit@debbugs.gnu.org; Tue, 06 Feb 2018 16:25:31 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:38582) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejAcZ-0004SI-6l for submit@debbugs.gnu.org; Tue, 06 Feb 2018 16:17:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejAcT-0000PE-1L for submit@debbugs.gnu.org; Tue, 06 Feb 2018 16:17:37 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:49824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejAcS-0000P4-TR for submit@debbugs.gnu.org; Tue, 06 Feb 2018 16:17:36 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAcR-00055f-Jt for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:17:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejAcQ-0000M6-6V for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:17:35 -0500 Original-Received: from mail-ua0-x229.google.com ([2607:f8b0:400c:c08::229]:42969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejAcP-0000L5-VE for bug-gnu-emacs@gnu.org; Tue, 06 Feb 2018 16:17:34 -0500 Original-Received: by mail-ua0-x229.google.com with SMTP id 47so2142095uau.9 for ; Tue, 06 Feb 2018 13:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=AJMwOAM0/he8vrSzorPSBbQNJT776snTcdi+V8bgdsI=; b=iSfyZGpvYBahrjQmQdJeEuVSxH2Vv3zsJpqw5DHerYgPrxWhgTRCRTBehNHtAfJ80i K6PtMe3wIdHL8GqrhgfyG0HbiGEMbiYBZMiQ6FR4IebJs8/0be9LszGI9bT5Tryxxd3S VwPQnBicmPMqKhrWQhdH2jlKf0AexLrQVAMLq9M3NXEITTilAQ3JuQYyU9wjQQUUtc4w AhFzguGfeXAoDXHCfXFq/xplbM8sLL1gArX9ueTbMnoR9iCJ0kYlNKFFriPY2Bb1i0tk p+BjjweCkYtb+neryt1TvNWNkss9DK0u7kjjul9OREiIyeckxqL8IR8hL1vZ7zo/gKz/ kAfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AJMwOAM0/he8vrSzorPSBbQNJT776snTcdi+V8bgdsI=; b=RxN5zokNVlp/didJqxchkNDJDHnAjBVKFwKvlPXFoFPms4KEUb9lmg70O6yE6qzYhm Iu0LKzCvjaW4m6dJcoxJWV3v92FgL1m+7DHmLz6jojzWGB3Vr5rFlO33L7hP2cmbPNJF QShc2e+9X/4ghXkk7TH4CeQMUFt8SDA+ciFvScPVmz0u4ojDFzL/AtUAYoHKVwoxv3RB 5h2+wBycnn/HlClx+fCb/bguig3WmOsTMnejXqHxF73tkzq4MPS8sYbcHrvaUu1IXV6x irQqbkMJ7BcVrGTed3TKyMjs8KLtb+Kb/LhJu5dBzWc0C0lYg84OKoVtOaD8A+NUZz4D g5TQ== X-Gm-Message-State: APf1xPDHdTm5JSzg97UNUf24ZPoOQhG55U6Qs+LIOZihOztKPGIfLZHv HiheEKownj5JFEeDBaQDIPf4sOsFPK8yEhRZnQI1wRCQDQw= X-Google-Smtp-Source: AH8x225tPvzXECJpMueGtOfNEcsHEFqR+E/bBoEqhuiSGNGi4bvlGaHcA8fIqA9vLdnCu7YN09JeGEv9z1doBr1+ffg= X-Received: by 10.176.83.203 with SMTP id l11mr3694993uaa.167.1517951852053; Tue, 06 Feb 2018 13:17:32 -0800 (PST) Original-Received: by 10.103.195.17 with HTTP; Tue, 6 Feb 2018 13:17:11 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Tue, 06 Feb 2018 16:25:30 -0500 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: 208.118.235.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:142991 Archived-At: --f403045e36c8ee3200056491b4ee Content-Type: text/plain; charset="UTF-8" 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. Thanks, Samir Jindel --f403045e36c8ee3200056491b4ee Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I'm very excited by the possibi= lities opened through the new dynamic module interface, "emacs-module.= h".

However, I have a concern about the API f= or creating Lisp functions bound to native functions:

<= div>```c
  emacs_value (*make_function) (emacs=
_env *env,                                                                 =
                                                                =20
        ptrdiff_t min_arity,                                               =
                                                                           =
                          =20
        ptrdiff_t max_arity,                                               =
                                                                           =
                          =20
        emacs_value (*function) (emacs_env *env,                           =
                                                                           =
                          =20
               ptrdiff_t nargs,                                            =
                                                                           =
                          =20
               emacs_value args[],                                         =
                                                                           =
                          =20
               void *)                                                     =
                                                                           =
                          =20
          EMACS_NOEXCEPT,                                                  =
                                                                           =
                          =20
        const char *documentation,                                         =
                                                                           =
                          =20
        void *data); 
```=C2=A0

I presume the= "data" pointer here is provided to enable native functions to wo= rk like closures,
carrying additional, possibly dynamically alloc= ated data. However, this functionality is limited by=C2=A0
the ab= sence of a finalization function pointer, like the "user_ptr" val= ues have:

```c
  emacs_=
value (*make_user_ptr) (emacs_env *env,                                    =
                                                                           =
                  =20
        void (*fin) (void *) EMACS_NOEXCEPT,                               =
                                                                           =
                          =20
        void *ptr);                                                        =
                                                                           =
                           
```

Without t= he ability to provide a finalizer, a module can only safely make the "= data" pointer to
"make_function" point to static m= emory.

Thanks,
Samir Jindel
--f403045e36c8ee3200056491b4ee--