aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c27
-rw-r--r--src/emacs-module.h.in10
-rw-r--r--src/lisp.h1
-rw-r--r--src/module-env-27.h8
4 files changed, 46 insertions, 0 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index e46af30ce84..e203ce1d348 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -70,6 +70,7 @@ To add a new module function, proceed as follows:
70 70
71#include <config.h> 71#include <config.h>
72 72
73#define EMACS_MODULE_GMP
73#include "emacs-module.h" 74#include "emacs-module.h"
74 75
75#include <stdarg.h> 76#include <stdarg.h>
@@ -79,7 +80,10 @@ To add a new module function, proceed as follows:
79#include <stdlib.h> 80#include <stdlib.h>
80#include <time.h> 81#include <time.h>
81 82
83#include <gmp.h>
84
82#include "lisp.h" 85#include "lisp.h"
86#include "bignum.h"
83#include "dynlib.h" 87#include "dynlib.h"
84#include "coding.h" 88#include "coding.h"
85#include "keyboard.h" 89#include "keyboard.h"
@@ -752,6 +756,27 @@ module_make_time (emacs_env *env, struct timespec time)
752 return lisp_to_value (env, make_lisp_time (time)); 756 return lisp_to_value (env, make_lisp_time (time));
753} 757}
754 758
759static void
760module_extract_big_integer (emacs_env *env, emacs_value value,
761 struct emacs_mpz *result)
762{
763 MODULE_FUNCTION_BEGIN ();
764 Lisp_Object o = value_to_lisp (value);
765 CHECK_INTEGER (o);
766 if (FIXNUMP (o))
767 mpz_set_intmax (result->value, XFIXNUM (o));
768 else
769 mpz_set (result->value, XBIGNUM (o)->value);
770}
771
772static emacs_value
773module_make_big_integer (emacs_env *env, const struct emacs_mpz *value)
774{
775 MODULE_FUNCTION_BEGIN (NULL);
776 mpz_set (mpz[0], value->value);
777 return lisp_to_value (env, make_integer_mpz ());
778}
779
755 780
756/* Subroutines. */ 781/* Subroutines. */
757 782
@@ -1157,6 +1182,8 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv)
1157 env->process_input = module_process_input; 1182 env->process_input = module_process_input;
1158 env->extract_time = module_extract_time; 1183 env->extract_time = module_extract_time;
1159 env->make_time = module_make_time; 1184 env->make_time = module_make_time;
1185 env->extract_big_integer = module_extract_big_integer;
1186 env->make_big_integer = module_make_big_integer;
1160 Vmodule_environments = Fcons (make_mint_ptr (env), Vmodule_environments); 1187 Vmodule_environments = Fcons (make_mint_ptr (env), Vmodule_environments);
1161 return env; 1188 return env;
1162} 1189}
diff --git a/src/emacs-module.h.in b/src/emacs-module.h.in
index bfbe226dd90..e61aadfc3ac 100644
--- a/src/emacs-module.h.in
+++ b/src/emacs-module.h.in
@@ -28,6 +28,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
28#include <stdbool.h> 28#include <stdbool.h>
29#endif 29#endif
30 30
31#ifdef EMACS_MODULE_GMP
32#include <gmp.h>
33#endif
34
31#if defined __cplusplus && __cplusplus >= 201103L 35#if defined __cplusplus && __cplusplus >= 201103L
32# define EMACS_NOEXCEPT noexcept 36# define EMACS_NOEXCEPT noexcept
33#else 37#else
@@ -94,6 +98,12 @@ enum emacs_process_input_result
94 emacs_process_input_quit = 1 98 emacs_process_input_quit = 1
95}; 99};
96 100
101#ifdef EMACS_MODULE_GMP
102struct emacs_mpz { mpz_t value; };
103#else
104struct emacs_mpz; /* no definition */
105#endif
106
97struct emacs_env_25 107struct emacs_env_25
98{ 108{
99@module_env_snippet_25@ 109@module_env_snippet_25@
diff --git a/src/lisp.h b/src/lisp.h
index d803f160006..703fe76d64e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4151,6 +4151,7 @@ extern void *unexec_realloc (void *, size_t);
4151extern void unexec_free (void *); 4151extern void unexec_free (void *);
4152#endif 4152#endif
4153 4153
4154#define EMACS_MODULE_GMP
4154#include "emacs-module.h" 4155#include "emacs-module.h"
4155 4156
4156/* Function prototype for the module Lisp functions. */ 4157/* Function prototype for the module Lisp functions. */
diff --git a/src/module-env-27.h b/src/module-env-27.h
index e63843f8d63..00de3009007 100644
--- a/src/module-env-27.h
+++ b/src/module-env-27.h
@@ -8,3 +8,11 @@
8 8
9 emacs_value (*make_time) (emacs_env *env, struct timespec time) 9 emacs_value (*make_time) (emacs_env *env, struct timespec time)
10 EMACS_ATTRIBUTE_NONNULL (1); 10 EMACS_ATTRIBUTE_NONNULL (1);
11
12 void (*extract_big_integer) (emacs_env *env, emacs_value value,
13 struct emacs_mpz *result)
14 EMACS_ATTRIBUTE_NONNULL (1, 3);
15
16 emacs_value (*make_big_integer) (emacs_env *env,
17 const struct emacs_mpz *value)
18 EMACS_ATTRIBUTE_NONNULL (1, 2);