all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Philipp Stephani <phst@google.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: [PATCH] Change module interface to no longer use GMP objects directly.
Date: Tue, 19 Nov 2019 22:12:17 +0100	[thread overview]
Message-ID: <CAArVCkQcz8g2riLmdTfyYN7ed0-5-NQX7qAqSDE4fX9zTc0umQ@mail.gmail.com> (raw)
In-Reply-To: <089f3d06-e227-27da-c8fe-afcbbbbc934a@cs.ucla.edu>

Am Mo., 18. Nov. 2019 um 22:21 Uhr schrieb Paul Eggert <eggert@cs.ucla.edu>:
>
> Thanks. I like the idea of decoupling Emacs modules from GMP.
>
> The proposed approach will typically require copying bignum data twice
> to do a conversion, even if modules use GMP themselves. Shouldn't there
> be a shortcut for modules using GMP, so that they can use
> mpz_limbs_write and mpz_limbs_finish and bypass one of the copies? We
> can do that even if the module interface itself doesn't include gmp.h or
> assume GMP. For example, the Emacs module interface could define a type
> emacs_limb_t that happens to be the same size and representation as
> mpz_limb_t when Emacs is implemented via GMP, and the example function
> could look like the attached handwavy file "bigt.c". (It might be
> possible to avoid even the remaining copy in some cases; I didn't
> investigate this.)

This sounds like a rather complex and probably premature optimization.
The current "unsigned long" type is identical to mpz_limb_t on most
platforms, and module authors can make use of that if they wish and
have profiled their code.

>
> Without such a shortcut, then we are to some extent giving up on
> efficiency, and in that case shouldn't we just ask people to convert to
> text and back, thus simplifying the interface?

With that argument you could argue that even fixed integer or float
conversions are unneeded because users could convert them to strings
as well. However, they are separate data types, so they deserve their
own interface.

>
> On 11/17/19 10:38 AM, Philipp Stephani wrote:
>
>  > +@deftypefn Function bool extract_big_integer (emacs_env *@var{env},
> emacs_value @var{arg}, int *@var{sign}, ptrdiff_t *@var{count}, unsigned
> long *@var{magnitude})
>  > +This function, which is available since Emacs 27,
>
> Should we be more systematic about saying which Emacs versions support
> which parts of the module API?

Sure, but that's for a different commit.

>
> Uses of 'unsigned long' should be changed to a more-abstract integer
> type like 'emacs_limb_t', to give the implementation more leeway to
> change in future versions.

In practice the implementation can't change, since that would break
either source or binary compatibility.
I'm not against a typedef to provide clearer semantics, but then we'd
also have to define EMACS_LIMB_MAX etc., and I see relatively little
benefit in that (since we can't realistically change it anyway later).

>
> The extraction API looks a bit complicated. How about if we simplify it
> so that it (1) never signals an error and (2) it returns the limb count
> instead of always returning 'true' and storing the limb count via a
> pointer. Any too-small array can be reported merely by returning a limb
> count larger than the array size, without changing the array, as in the
> attached sample code.

I'm not feeling strongly about the function in isolation, but the
current interface is modeled after the existing copy_string_contents
(which we can't change), and providing two different interfaces for
"copying an array" would be very confusing and unnecessarily
inconsistent.

>
>  > extracts the
>  > +integral value of @var{arg}.
>
> Need to make it clearer that ARG can be any integer; it need not be a
> bignum.

Ack, I'll make that change.

>
>  > it stores the required array
>  > +size into @code{*count}
>
> It should document that this size cannot exceed (min (PTRDIFF_MAX,
> SIZE_MAX) / sizeof (emacs_limb_t)). No matter what we do inside Emacs,
> it won't exceed that value for various reasons, and documenting this can
> simplify callers.

I'm not sure we should document such facts. It's true that this allows
callers to use malloc without checking for overflow, and it seems this
already follows from the C standard (can an array with total size
larger than SIZE_MAX exist?), but then I'm not convinced that this is
reason enough to add more complicated guarantees here.

>
>  > +  bool success = env->extract_big_integer (env, value, &sign,
> &count, NULL);
>
> Shouldn't that 'value' be 'arg'?

Yeah, that follows from changing the naming conventions in the middle ;)

>
>  > +  mpz_import (value, count, order, size, endian, nails, magnitude);
>
> Shouldn't that 'value' be 'result'?
>
> At this point I stopped detailed review because I wanted your thoughts
> on the bigger questions.



  reply	other threads:[~2019-11-19 21:12 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 13:17 [PATCH 1/2] Add conversions to and from struct timespec to module interface Philipp Stephani
2019-04-23 13:17 ` [PATCH 2/2] Add module functions to convert from and to big integers Philipp Stephani
2019-04-23 14:30   ` Eli Zaretskii
2019-04-23 14:51   ` Paul Eggert
2019-04-23 15:12     ` Philipp Stephani
2019-04-23 15:48       ` Paul Eggert
2019-04-23 15:54         ` Philipp Stephani
2019-11-02 19:17           ` Philipp Stephani
2019-11-03 19:38             ` Stefan Monnier
2019-11-13 18:46               ` Philipp Stephani
2019-11-17 18:38                 ` [PATCH] Change module interface to no longer use GMP objects directly Philipp Stephani
2019-11-18 21:21                   ` Paul Eggert
2019-11-19 21:12                     ` Philipp Stephani [this message]
2019-11-19 21:54                       ` Paul Eggert
2019-11-20 21:06                         ` Philipp Stephani
2019-11-20 21:24                           ` Paul Eggert
2019-11-20 21:30                             ` Philipp Stephani
2019-11-21  1:12                               ` Paul Eggert
2019-11-21 20:31                                 ` Philipp Stephani
2019-11-23  2:13                                   ` Paul Eggert
2019-11-23 20:08                                     ` Philipp Stephani
2019-11-23 23:10                                       ` Paul Eggert
2019-11-23 20:46                                     ` Stefan Monnier
2019-11-23 23:10                                       ` Paul Eggert
2019-11-24  9:28                                         ` Andreas Schwab
2019-11-25 21:03                                           ` Paul Eggert
2019-11-25 21:59                                             ` Philipp Stephani
2019-12-04 20:31                                               ` Philipp Stephani
2019-12-05 14:43                                                 ` Eli Zaretskii
2019-12-08 20:28                                                   ` Philipp Stephani
2019-12-09  3:26                                                     ` Eli Zaretskii
2019-12-09  4:58                                                       ` Paul Eggert
2019-12-09 13:22                                                         ` Eli Zaretskii
2019-12-09 23:15                                                       ` Philipp Stephani
2019-12-10  0:22                                                         ` Paul Eggert
2019-12-10 13:15                                                           ` Philipp Stephani
2019-12-10 15:57                                                           ` Eli Zaretskii
2019-12-14 16:06                                                             ` Philipp Stephani
2019-12-14 19:54                                                               ` Paul Eggert
2019-12-09  0:35                                                   ` Paul Eggert
2019-12-09 13:19                                                     ` Eli Zaretskii
2019-04-23 15:16 ` [PATCH 1/2] Add conversions to and from struct timespec to module interface Paul Eggert
2019-04-23 21:32   ` Philipp Stephani
     [not found]     ` <20190423213218.35618-2-phst@google.com>
2019-04-23 21:43       ` [PATCH 2/2] Add module functions to convert from and to big integers Paul Eggert
2019-04-24 16:03       ` Eli Zaretskii
2019-04-24 16:37         ` Philipp Stephani
2019-04-24 16:51           ` Eli Zaretskii
2019-04-24 16:57           ` Philipp Stephani
2019-04-24 17:11             ` Eli Zaretskii
2019-04-24 17:15               ` Philipp Stephani
2019-04-24 17:23                 ` Eli Zaretskii
2019-04-24 17:28                   ` Philipp Stephani
2019-04-24 17:51                     ` [PATCH] Unbreak build when building without GMP support Philipp Stephani
2019-04-24 18:41                       ` Eli Zaretskii
2019-04-24 18:49                         ` Philipp Stephani
2019-04-24 19:06                           ` Eli Zaretskii
2019-04-24 19:19                             ` Philipp Stephani
2019-04-24 19:30                               ` Eli Zaretskii
2019-04-24 21:15                                 ` Philipp Stephani
2019-04-25  6:04                                   ` Eli Zaretskii
2019-04-25  6:39                                     ` Eli Zaretskii
2019-04-25 10:24                                       ` Philipp Stephani
2019-04-24 21:34                       ` Philipp Stephani
2019-04-24 19:44                     ` [PATCH 2/2] Add module functions to convert from and to big integers Stefan Monnier
2019-04-24 20:15                       ` Paul Eggert
2019-04-24 20:57                         ` Stefan Monnier
2019-04-24 21:17                           ` Philipp Stephani
2019-04-24 23:32                             ` Paul Eggert
2019-04-24 21:19                       ` Philipp Stephani
2019-04-25  0:00                         ` Paul Eggert
2019-04-25  5:33                           ` Eli Zaretskii
2019-04-25 10:41                             ` Philipp Stephani
2019-04-25 13:46                               ` [PATCH 1/2] Require full GMP when building module support Philipp Stephani
2019-04-25 13:46                                 ` [PATCH 2/2] Check for __attribute__ ((cleanup)) during configuration Philipp Stephani
2019-04-25 21:18                                   ` Paul Eggert
2019-04-28 18:12                                     ` Philipp Stephani
2019-04-25 14:37                                 ` [PATCH 1/2] Require full GMP when building module support Eli Zaretskii
2019-04-25 15:06                                   ` Philipp Stephani
2019-04-25 16:14                                     ` Eli Zaretskii
2019-04-25 17:09                                       ` [PATCH] Require full GMP for big integer module functions Philipp Stephani
2019-04-25 21:00                                         ` Paul Eggert
2019-04-28 18:14                                           ` Philipp Stephani
2019-04-28 20:18                                             ` Paul Eggert
2019-04-28 17:10                                       ` [PATCH 1/2] Require full GMP when building module support Philipp Stephani
2019-04-24  7:21     ` [PATCH 1/2] Add conversions to and from struct timespec to module interface Eli Zaretskii
2019-04-24 11:03       ` Philipp Stephani
2019-04-24 11:44         ` Eli Zaretskii

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=CAArVCkQcz8g2riLmdTfyYN7ed0-5-NQX7qAqSDE4fX9zTc0umQ@mail.gmail.com \
    --to=p.stephani2@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=phst@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.