emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 2c29280: Fix warnings about formats in printf-like


From: Eli Zaretskii
Subject: [Emacs-diffs] master 2c29280: Fix warnings about formats in printf-like functions on MS-Windows
Date: Thu, 14 Sep 2017 13:40:13 -0400 (EDT)

branch: master
commit 2c29280e7a360f55a8110bb1e3985cc09eb94577
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix warnings about formats in printf-like functions on MS-Windows
    
    * src/lisp.h (pI) [__MINGW32__]: Provide definition that will
    hopefully DTRT with both MinGW64 and mingw.org's MinGW.  See
    http://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00171.html
    for the details.
    * src/conf_post.h (PRINTF_ARCHETYPE) [MINGW_W64]: Separate
    definition specific to MinGW64.
    (PRINTF_ARCHETYPE) [__MINGW32__]: For mingw.org's MinGW, use
    __mingw_printf__ in ANSI-compatible mode.
---
 src/conf_post.h | 22 +++++++++++++++++++++-
 src/lisp.h      | 11 +++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/conf_post.h b/src/conf_post.h
index 096a677..febdb8b 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -255,7 +255,27 @@ extern int emacs_setenv_TZ (char const *);
 #if GNUC_PREREQ (4, 4, 0) && defined __GLIBC_MINOR__
 # define PRINTF_ARCHETYPE __gnu_printf__
 #elif GNUC_PREREQ (4, 4, 0) && defined __MINGW32__
-# define PRINTF_ARCHETYPE __ms_printf__
+# ifdef MINGW_W64
+/* When __USE_MINGW_ANSI_STDIO is non-zero (as set by config.h),
+   MinGW64 replaces printf* with its own versions that are
+   __gnu_printf__ compatible, and emits warnings for MS native %I64d
+   format spec.  */
+#  if __USE_MINGW_ANSI_STDIO
+#   define PRINTF_ARCHETYPE __gnu_printf__
+#  else
+#   define PRINTF_ARCHETYPE __ms_printf__
+#  endif
+# else /* mingw.org's MinGW */
+/* Starting from runtime v5.0.0, mingw.org's MinGW with GCC 6 and
+   later turns on __USE_MINGW_ANSI_STDIO by default, replaces printf*
+   with its own __mingw_printf__ version, which still recognizes
+   %I64d.  */
+#  if GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5
+#   define PRINTF_ARCHETYPE __mingw_printf__
+#  else  /* __MINGW32_MAJOR_VERSION < 5 */
+#   define PRINTF_ARCHETYPE __ms_printf__
+#  endif  /* __MINGW32_MAJOR_VERSION < 5 */
+# endif         /* MinGW */
 #else
 # define PRINTF_ARCHETYPE __printf__
 #endif
diff --git a/src/lisp.h b/src/lisp.h
index 40e84ec..c5aea9c 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -94,9 +94,16 @@ typedef long long int EMACS_INT;
 typedef unsigned long long int EMACS_UINT;
 enum { EMACS_INT_WIDTH = LLONG_WIDTH, EMACS_UINT_WIDTH = ULLONG_WIDTH };
 #  define EMACS_INT_MAX LLONG_MAX
-#  ifdef __MINGW32__
+/* MinGW supports %lld only if __USE_MINGW_ANSI_STDIO is non-zero,
+   which is arranged by config.h, and (for mingw.org) if GCC is 6.0 or
+   later and the runtime version is 5.0.0 or later.  Otherwise,
+   printf-like functions are declared with __ms_printf__ attribute,
+   which will cause a warning for %lld etc.  */
+#  if defined __MINGW32__                                              \
+  && (!defined __USE_MINGW_ANSI_STDIO                                  \
+      || !(GNUC_PREREQ (6, 0, 0) && __MINGW32_MAJOR_VERSION >= 5))
 #   define pI "I64"
-#  else
+#  else         /* ! MinGW */
 #   define pI "ll"
 #  endif
 # else



reply via email to

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