commit 643e0b8d2857ed63cb9e94731a30d8ed0e9ca889 (HEAD, refs/remotes/origin/master) Author: Eli Zaretskii Date: Sun Jun 12 11:30:14 2016 +0300 Fix printf-related compilation warnings on MinGW * src/conf_post.h (ATTRIBUTE_FORMAT_PRINTF) [__MINGW32__]: Use '__ms_printf__', not '__gnu_printf__', as the latter is not what MS 'printf' supports, and causes bogus compilation warnings. * src/lisp.h (pI) [__MINGW32__]: Define to "I64", as MS 'printf' doesn't support the "ll" modifier. diff --git a/src/conf_post.h b/src/conf_post.h index 6f48fd6..e21e73e 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -252,12 +252,17 @@ extern int emacs_setenv_TZ (char const *); #endif #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ - ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) -#else +# ifdef __MINGW32__ +# define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + ATTRIBUTE_FORMAT ((__ms_printf__, formatstring_parameter, first_argument)) +#else /* !__MINGW32__ */ +# define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) +#endif /* !__MINGW32__ */ +#else /* __GNUC__ < 4.4 */ # define ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) -#endif +#endif /* __GNUC__ < 4.4 */ #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST #define ATTRIBUTE_UNUSED _GL_UNUSED diff --git a/src/lisp.h b/src/lisp.h index 3c6bf34..a0d0610 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -88,7 +88,11 @@ typedef unsigned long EMACS_UINT; typedef long long int EMACS_INT; typedef unsigned long long int EMACS_UINT; # define EMACS_INT_MAX LLONG_MAX -# define pI "ll" +# ifdef __MINGW32__ +# define pI "I64" +# else +# define pI "ll" +# endif # else # error "INTPTR_MAX too large" # endif commit 5932ffcd028af9fc70c9f8e731f2776a9753d81d Author: Paul Eggert Date: Sat Jun 11 23:48:13 2016 -0700 emacs_strerror cleanups * src/buffer.c, src/emacs.c, src/lread.c: Don’t include coding.h; no longer needed, now that emacs_strerror is declared by lisp.h. * src/coding.c (emacs_strerror): Remove; moved to emacs.c. * src/coding.h (emacs_strerror) [emacs]: Remove decl; moved to lisp.h. * src/emacs.c (emacs_strerror): Move here from coding.c. Do not convert result string; this is now the caller’s responsibility, as some need conversion and others don’t. * src/fileio.c (report_file_errno, report_file_notify_error): Use emacs_strerror rather than rolling it ourselves. * src/lisp.h (emacs_strerror): Move decl here from coding.h. * src/lread.c (dir_warning): Just call emacs_strerror rather than both strerror and emacs_strerror. Convert its result from locale-coding-system, since it no longer does that conversion. * src/sound.c (sound_perror): * src/sysdep.c (emacs_perror, str_collate): Use emacs_strerror, not strerror. diff --git a/src/buffer.c b/src/buffer.c index af8c732..b4b8304 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -30,7 +30,6 @@ along with GNU Emacs. If not, see . */ #include #include "lisp.h" -#include "coding.h" #include "intervals.h" #include "systime.h" #include "window.h" diff --git a/src/coding.c b/src/coding.c index 3f7d111..804b628 100644 --- a/src/coding.c +++ b/src/coding.c @@ -11303,24 +11303,4 @@ internal character representation. */); #endif staticpro (&system_eol_type); } - -char * -emacs_strerror (int error_number) -{ - char *str; - - synchronize_system_messages_locale (); - str = strerror (error_number); - - if (! NILP (Vlocale_coding_system)) - { - Lisp_Object dec = code_convert_string_norecord (build_string (str), - Vlocale_coding_system, - 0); - str = SSDATA (dec); - } - - return str; -} - #endif /* emacs */ diff --git a/src/coding.h b/src/coding.h index 93ddff0..426be62 100644 --- a/src/coding.h +++ b/src/coding.h @@ -768,8 +768,6 @@ extern Lisp_Object preferred_coding_system (void); #ifdef emacs -extern char *emacs_strerror (int); - /* Coding system to be used to encode text for terminal display when terminal coding system is nil. */ extern struct coding_system safe_terminal_coding; diff --git a/src/emacs.c b/src/emacs.c index b8ba86f..bb85733 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -66,7 +66,6 @@ along with GNU Emacs. If not, see . */ #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ -#include "coding.h" #include "intervals.h" #include "character.h" #include "buffer.h" @@ -2226,6 +2225,15 @@ synchronize_system_messages_locale (void) #endif } #endif /* HAVE_SETLOCALE */ + +/* Return a diagnostic string for ERROR_NUMBER, in the wording + and encoding appropriate for the current locale. */ +char * +emacs_strerror (int error_number) +{ + synchronize_system_messages_locale (); + return strerror (error_number); +} Lisp_Object diff --git a/src/fileio.c b/src/fileio.c index 9984045..facc4be 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -185,8 +185,7 @@ void report_file_errno (char const *string, Lisp_Object name, int errorno) { Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); - synchronize_system_messages_locale (); - char *str = strerror (errorno); + char *str = emacs_strerror (errorno); AUTO_STRING (unibyte_str, str); Lisp_Object errstring = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); @@ -214,12 +213,11 @@ report_file_error (char const *string, Lisp_Object name) void report_file_notify_error (const char *string, Lisp_Object name) { - Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); - synchronize_system_messages_locale (); - char *str = strerror (errno); + char *str = emacs_strerror (errno); AUTO_STRING (unibyte_str, str); Lisp_Object errstring = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); + Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); Lisp_Object errdata = Fcons (errstring, data); xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); diff --git a/src/lisp.h b/src/lisp.h index 4042f4d..3c6bf34 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4131,6 +4131,7 @@ INLINE void fixup_locale (void) {} INLINE void synchronize_system_messages_locale (void) {} INLINE void synchronize_system_time_locale (void) {} #endif +extern char *emacs_strerror (int); extern void shut_down_emacs (int, Lisp_Object); /* True means don't do interactive redisplay and don't change tty modes. */ diff --git a/src/lread.c b/src/lread.c index b08ce17..9f804ac 100644 --- a/src/lread.c +++ b/src/lread.c @@ -36,7 +36,6 @@ along with GNU Emacs. If not, see . */ #include "character.h" #include "buffer.h" #include "charset.h" -#include "coding.h" #include #include "commands.h" #include "keyboard.h" @@ -4484,18 +4483,24 @@ void dir_warning (char const *use, Lisp_Object dirname) { static char const format[] = "Warning: %s '%s': %s\n"; - int access_errno = errno; - fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), - strerror (access_errno)); + char *diagnostic = emacs_strerror (errno); + fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), diagnostic); /* Don't log the warning before we've initialized!! */ if (initialized) { - char const *diagnostic = emacs_strerror (access_errno); + ptrdiff_t diaglen = strlen (diagnostic); + AUTO_STRING_WITH_LEN (diag, diagnostic, diaglen); + if (! NILP (Vlocale_coding_system)) + { + Lisp_Object s + = code_convert_string_norecord (diag, Vlocale_coding_system, false); + diagnostic = SSDATA (s); + diaglen = SBYTES (s); + } USE_SAFE_ALLOCA; char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1) - + strlen (use) + SBYTES (dirname) - + strlen (diagnostic)); + + strlen (use) + SBYTES (dirname) + diaglen); ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname), diagnostic); message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname)); diff --git a/src/sound.c b/src/sound.c index 8671d4a..f5f5701 100644 --- a/src/sound.c +++ b/src/sound.c @@ -310,7 +310,7 @@ sound_perror (const char *msg) } #endif if (saved_errno != 0) - error ("%s: %s", msg, strerror (saved_errno)); + error ("%s: %s", msg, emacs_strerror (saved_errno)); else error ("%s", msg); } diff --git a/src/sysdep.c b/src/sysdep.c index a99c208..56142a5 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2498,7 +2498,7 @@ void emacs_perror (char const *message) { int err = errno; - char const *error_string = strerror (err); + char const *error_string = emacs_strerror (err); char const *command = (initial_argv && initial_argv[0] ? initial_argv[0] : "emacs"); /* Write it out all at once, if it's short; this is less likely to @@ -3865,7 +3865,7 @@ str_collate (Lisp_Object s1, Lisp_Object s2, locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, SSDATA (locale), 0); if (!loc) - error ("Invalid locale %s: %s", SSDATA (locale), strerror (errno)); + error ("Invalid locale %s: %s", SSDATA (locale), emacs_strerror (errno)); if (! NILP (ignore_case)) for (int i = 1; i < 3; i++) @@ -3896,10 +3896,10 @@ str_collate (Lisp_Object s1, Lisp_Object s2, } # ifndef HAVE_NEWLOCALE if (err) - error ("Invalid locale or string for collation: %s", strerror (err)); + error ("Invalid locale or string for collation: %s", emacs_strerror (err)); # else if (err) - error ("Invalid string for collation: %s", strerror (err)); + error ("Invalid string for collation: %s", emacs_strerror (err)); # endif SAFE_FREE ();