]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer intmax_t to int64_t in module code
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Nov 2015 22:03:29 +0000 (14:03 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Nov 2015 22:04:00 +0000 (14:04 -0800)
* modules/mod-test/mod-test.c (sum, Fmod_test_sum):
* src/emacs-module.c (module_extract_integer)
(module_make_integer):
* src/emacs-module.h (struct emacs_env_25):
Prefer intmax_t to int64_t.  This doesn’t change the generated
code on any of the machines Emacs currently ports to, but it’s
at least in theory more future-proof as C99 doesn’t guarantee
that int64_t exists.

modules/mod-test/mod-test.c
src/emacs-module.c
src/emacs-module.h

index e27fb582355dc3b411300e9fba80552487c94f67..79f347f04ab1c5b82c0f4e8faf8ea29514453b7d 100644 (file)
@@ -31,7 +31,8 @@ Fmod_test_return_t (emacs_env *env, int nargs, emacs_value args[], void *data)
 }
 
 /* Expose simple sum function.  */
-static int64_t sum (int64_t a, int64_t b)
+static intmax_t
+sum (intmax_t a, intmax_t b)
 {
   return a + b;
 }
@@ -39,10 +40,10 @@ static int64_t sum (int64_t a, int64_t b)
 static emacs_value
 Fmod_test_sum (emacs_env *env, int nargs, emacs_value args[], void *data)
 {
-  int64_t a = env->extract_integer (env, args[0]);
-  int64_t b = env->extract_integer (env, args[1]);
+  intmax_t a = env->extract_integer (env, args[0]);
+  intmax_t b = env->extract_integer (env, args[1]);
 
-  int64_t r = sum(a, b);
+  intmax_t r = sum (a, b);
 
   return env->make_integer (env, r);
 }
index 4fa01bf5bed569e42ac64a59686155eecd55784e..b39ac7df0579ff21ff6ea6fc602f4e2fa8ba7ce5 100644 (file)
@@ -451,11 +451,9 @@ module_eq (emacs_env *env, emacs_value a, emacs_value b)
   return EQ (value_to_lisp (a), value_to_lisp (b));
 }
 
-static int64_t
+static intmax_t
 module_extract_integer (emacs_env *env, emacs_value n)
 {
-  verify (INT64_MIN <= MOST_NEGATIVE_FIXNUM);
-  verify (INT64_MAX >= MOST_POSITIVE_FIXNUM);
   check_main_thread ();
   eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
   const Lisp_Object l = value_to_lisp (n);
@@ -468,16 +466,11 @@ module_extract_integer (emacs_env *env, emacs_value n)
 }
 
 static emacs_value
-module_make_integer (emacs_env *env, int64_t n)
+module_make_integer (emacs_env *env, intmax_t n)
 {
   check_main_thread ();
   eassert (module_non_local_exit_check (env) == emacs_funcall_exit_return);
-  if (n < MOST_NEGATIVE_FIXNUM)
-    {
-      module_non_local_exit_signal_1 (env, Qunderflow_error, Qnil);
-      return NULL;
-    }
-  if (n > MOST_POSITIVE_FIXNUM)
+  if (! (MOST_NEGATIVE_FIXNUM <= n && n <= MOST_POSITIVE_FIXNUM))
     {
       module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
       return NULL;
index 046959775ac120b97c9cb0e8b03f25db3ae5cf04..2759b1cb0f011bdcbd49cff50cce77469d930858 100644 (file)
@@ -142,10 +142,9 @@ struct emacs_env_25
 
   bool (*eq) (emacs_env *env, emacs_value a, emacs_value b);
 
-  int_fast64_t (*extract_integer) (emacs_env *env,
-                                  emacs_value value);
+  intmax_t (*extract_integer) (emacs_env *env, emacs_value value);
 
-  emacs_value (*make_integer) (emacs_env *env, int_fast64_t value);
+  emacs_value (*make_integer) (emacs_env *env, intmax_t value);
 
   double (*extract_float) (emacs_env *env, emacs_value value);