From e290a7d1730c99010272bbff7f497c3041cef46d Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 18 Apr 2019 22:38:29 +0200 Subject: Add module functions to convert from and to big integers. * src/module-env-27.h: Add new module functions to convert big integers. * src/emacs-module.h.in (emacs_mpz): Define if GMP is available. * src/emacs-module.c (module_extract_big_integer) (module_make_big_integer): New functions. (initialize_environment): Use them. * test/data/emacs-module/mod-test.c (Fmod_test_double): New test function. (emacs_module_init): Define it. * test/src/emacs-module-tests.el (mod-test-double): New unit test. * doc/lispref/internals.texi (Module Values): Document new functions. --- doc/lispref/internals.texi | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'doc/lispref/internals.texi') diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index 0e7a1339e76..10f49c569fa 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi @@ -1508,6 +1508,41 @@ function raises the @code{overflow-error} error condition if string. @end deftypefn +If you define the preprocessor macro @code{EMACS_MODULE_GMP} before +including the header @file{emacs-module.h}, you can also convert +between Emacs integers and GMP @code{mpz_t} values. @xref{GMP +Basics,,,gmp}. If @code{EMACS_MODULE_GMP} is defined, +@file{emacs-module.h} wraps @code{mpz_t} in the following structure: + +@deftp struct emacs_mpz value +struct emacs_mpz @{ mpz_t value; @}; +@end deftp + +@noindent +Then you can use the following additional functions: + +@deftypefn Function bool extract_big_integer (emacs_env *@var{env}, emacs_value @var{arg}, struct emacs_mpz *@var{result}) +This function, which is available since Emacs 27, extracts the +integral value of @var{arg} into @var{result}. @var{result} must not +be @code{NULL}. @code{@var{result}->value} must be an initialized +@code{mpz_t} object. @xref{Initializing Integers,,,gmp}. If +@var{arg} is an integer, Emacs will store its value into +@code{@var{result}->value}. After you have finished using +@code{@var{result}->value}, you should free it using @code{mpz_clear} +or similar. +@end deftypefn + +@deftypefn Function emacs_value make_big_integer (emacs_env *@var{env}, const struct emacs_mpz *@var{value}) +This function, which is available since Emacs 27, takes an +arbitrary-sized integer argument and returns a corresponding +@code{emacs_value} object. @var{value} must not be @code{NULL}. +@code{@var{value}->value} must be an initialized @code{mpz_t} object. +@xref{Initializing Integers,,,gmp}. Emacs will return a corresponding +integral object. After you have finished using +@code{@var{value}->value}, you should free it using @code{mpz_clear} +or similar. +@end deftypefn + The @acronym{API} does not provide functions to manipulate Lisp data structures, for example, create lists with @code{cons} and @code{list} (@pxref{Building Lists}), extract list members with @code{car} and -- cgit v1.2.1