From c28d4b6d8e1ad3d8c96329239a01af9d1dc048c5 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 19 Jan 2018 11:20:12 +0200 Subject: [PATCH] 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 . (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 e03ffc5ab01..e6b3f77523c 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -31,6 +31,7 @@ SHELL = @SHELL@ srcdir = @srcdir@ +abs_top_srcdir=@abs_top_srcdir@ 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 c1b1cade04a..a1c115f00d2 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 . */ #include #include #include +#include #include 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; } -- 2.11.4.GIT