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. --- test/data/emacs-module/mod-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/data') diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c index dbdbfecfe6a..85a7f28e50d 100644 --- a/test/data/emacs-module/mod-test.c +++ b/test/data/emacs-module/mod-test.c @@ -27,8 +27,11 @@ along with GNU Emacs. If not, see . */ #include #include +#define EMACS_MODULE_GMP #include +#include + #include "timespec.h" int plugin_is_GPL_compatible; @@ -378,6 +381,21 @@ Fmod_test_add_nanosecond (emacs_env *env, ptrdiff_t nargs, emacs_value *args, return env->make_time (env, time); } +static emacs_value +Fmod_test_double (emacs_env *env, ptrdiff_t nargs, emacs_value *args, + void *data) +{ + assert (nargs == 1); + emacs_value arg = args[0]; + struct emacs_mpz value; + mpz_init (value.value); + env->extract_big_integer (env, arg, &value); + mpz_mul_ui (value.value, value.value, 2); + emacs_value result = env->make_big_integer (env, &value); + mpz_clear (value.value); + return result; +} + /* Lisp utilities for easier readability (simple wrappers). */ /* Provide FEATURE to Emacs. */ @@ -447,6 +465,7 @@ emacs_module_init (struct emacs_runtime *ert) NULL, NULL); DEFUN ("mod-test-sleep-until", Fmod_test_sleep_until, 2, 2, NULL, NULL); DEFUN ("mod-test-add-nanosecond", Fmod_test_add_nanosecond, 1, 1, NULL, NULL); + DEFUN ("mod-test-double", Fmod_test_double, 1, 1, NULL, NULL); #undef DEFUN -- cgit v1.2.1