emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 c28d4b6: Portability fixes in emacs-module-tests


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-26 c28d4b6: Portability fixes in emacs-module-tests
Date: Fri, 19 Jan 2018 04:21:39 -0500 (EST)

branch: emacs-26
commit c28d4b6d8e1ad3d8c96329239a01af9d1dc048c5
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Portability fixes in emacs-module-tests
    
    * test/Makefile.in (abs_top_srcdir): Add variable, needed by
    CPPFLAGS.
    * test/data/emacs-module/mod-test.c: Include <limits.h>.
    (pT, pZ, T_TYPE, Z_TYPE): Compatibility macros, for systems that
    don't support %td and %zu format specs.
    (emacs_module_init): Use compatibility macros to make the error
    messages print meaningful values (and avoid compiler warnings).
---
 test/Makefile.in                  |  1 +
 test/data/emacs-module/mod-test.c | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/test/Makefile.in b/test/Makefile.in
index e03ffc5..e6b3f77 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -31,6 +31,7 @@
 SHELL = @SHELL@
 
 srcdir = @srcdir@
address@hidden@
 VPATH = $(srcdir)
 
 FIND_DELETE = @FIND_DELETE@
diff --git a/test/data/emacs-module/mod-test.c 
b/test/data/emacs-module/mod-test.c
index c1b1cad..a1c115f 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -20,10 +20,35 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <emacs-module.h>
 
 int plugin_is_GPL_compatible;
 
+#if INTPTR_MAX <= 0
+# error "INTPTR_MAX misconfigured"
+#elif INTPTR_MAX <= INT_MAX || INTPTR_MAX <= LONG_MAX
+# define pT "ld"
+# define pZ "lu"
+# define T_TYPE long
+# define Z_TYPE unsigned long
+#elif INTPTR_MAX <= INT64_MAX
+# ifdef __MINGW32__
+#  define pT "lld"
+#  define pZ "llu"
+#  define T_TYPE long long
+#  define Z_TYPE unsigned long long
+# else
+#  define pT "ld"
+#  define pZ "lu"
+#  define T_TYPE long
+#  define Z_TYPE unsigned long
+# endif
+#else
+# error "INTPTR_MAX too large"
+#endif
+
+
 /* Always return symbol 't'.  */
 static emacs_value
 Fmod_test_return_t (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
@@ -287,9 +312,9 @@ emacs_module_init (struct emacs_runtime *ert)
 {
   if (ert->size < sizeof *ert)
     {
-      fprintf (stderr, "Runtime size of runtime structure (%td bytes) "
-               "smaller than compile-time size (%zu bytes)",
-               ert->size, sizeof *ert);
+      fprintf (stderr, "Runtime size of runtime structure (%"pT" bytes) "
+               "smaller than compile-time size (%"pZ" bytes)",
+               (T_TYPE) ert->size, (Z_TYPE) sizeof (*ert));
       return 1;
     }
 
@@ -297,9 +322,9 @@ emacs_module_init (struct emacs_runtime *ert)
 
   if (env->size < sizeof *env)
     {
-      fprintf (stderr, "Runtime size of environment structure (%td bytes) "
-               "smaller than compile-time size (%zu bytes)",
-               env->size, sizeof *env);
+      fprintf (stderr, "Runtime size of environment structure (%"pT" bytes) "
+               "smaller than compile-time size (%"pZ" bytes)",
+               (T_TYPE) env->size, (Z_TYPE) sizeof (*env));
       return 2;
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]