From a81d11a3efb4d511c5c34c8983dc6aab5d619ea1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Jul 2011 14:52:44 -0700 Subject: [PATCH] * editfns.c (pWIDE, pWIDElen, signed_wide, unsigned_wide): Remove, replacing with the new symbols in lisp.h. All uses changed. * fileio.c (make_temp_name): * filelock.c (lock_file_1, lock_file): * xdisp.c (message_dolog): Don't assume PRIdMAX etc. works; this isn't portable to pre-C99 hosts. Use pMd etc. instead. * lisp.h (printmax_t, uprintmax_t, pMd, pMu): New types and macros, replacing the pWIDE etc. symbols removed from editfns.c. --- src/ChangeLog | 10 ++++++++++ src/editfns.c | 40 ++++++++++++++-------------------------- src/fileio.c | 6 +++--- src/filelock.c | 15 ++++++++------- src/lisp.h | 17 +++++++++++++++++ src/xdisp.c | 6 +++--- 6 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8d8e878981..62bf571262 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,15 @@ 2011-07-07 Paul Eggert + * editfns.c (pWIDE, pWIDElen, signed_wide, unsigned_wide): + Remove, replacing with the new symbols in lisp.h. All uses changed. + * fileio.c (make_temp_name): + * filelock.c (lock_file_1, lock_file): + * xdisp.c (message_dolog): + Don't assume PRIdMAX etc. works; this isn't portable to pre-C99 hosts. + Use pMd etc. instead. + * lisp.h (printmax_t, uprintmax_t, pMd, pMu): New types and macros, + replacing the pWIDE etc. symbols removed from editfns.c. + * keyboard.h (num_input_events): Now uintmax_t. This is (very slightly) less likely to mess up due to wraparound. All uses changed. diff --git a/src/editfns.c b/src/editfns.c index bb36d0dee7..e3a7d1f7fa 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3506,22 +3506,6 @@ usage: (propertize STRING &rest PROPERTIES) */) RETURN_UNGCPRO (string); } -/* pWIDE is a conversion for printing large decimal integers (possibly with a - trailing "d" that is ignored). pWIDElen is its length. signed_wide and - unsigned_wide are signed and unsigned types for printing them. Use widest - integers if available so that more floating point values can be converted. */ -#ifdef PRIdMAX -# define pWIDE PRIdMAX -enum { pWIDElen = sizeof PRIdMAX - 2 }; /* Don't count trailing "d". */ -typedef intmax_t signed_wide; -typedef uintmax_t unsigned_wide; -#else -# define pWIDE pI -enum { pWIDElen = sizeof pI - 1 }; -typedef EMACS_INT signed_wide; -typedef EMACS_UINT unsigned_wide; -#endif - DEFUN ("format", Fformat, Sformat, 1, MANY, 0, doc: /* Format a string out of a format-string and arguments. The first argument is a format control string. @@ -3903,7 +3887,11 @@ usage: (format STRING &rest OBJECTS) */) precision is no more than DBL_USEFUL_PRECISION_MAX. On all practical hosts, %f is the worst case. */ SPRINTF_BUFSIZE = - sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX + sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX, + + /* Length of pM (that is, of pMd without the + trailing "d"). */ + pMlen = sizeof pMd - 2 }; verify (0 < USEFUL_PRECISION_MAX); @@ -3916,7 +3904,7 @@ usage: (format STRING &rest OBJECTS) */) /* Copy of conversion specification, modified somewhat. At most three flags F can be specified at once. */ - char convspec[sizeof "%FFF.*d" + pWIDElen]; + char convspec[sizeof "%FFF.*d" + pMlen]; /* Avoid undefined behavior in underlying sprintf. */ if (conversion == 'd' || conversion == 'i') @@ -3924,7 +3912,7 @@ usage: (format STRING &rest OBJECTS) */) /* Create the copy of the conversion specification, with any width and precision removed, with ".*" inserted, - and with pWIDE inserted for integer formats. */ + and with pM inserted for integer formats. */ { char *f = convspec; *f++ = '%'; @@ -3939,8 +3927,8 @@ usage: (format STRING &rest OBJECTS) */) || conversion == 'o' || conversion == 'x' || conversion == 'X') { - memcpy (f, pWIDE, pWIDElen); - f += pWIDElen; + memcpy (f, pMd, pMlen); + f += pMlen; zero_flag &= ~ precision_given; } *f++ = conversion; @@ -3980,7 +3968,7 @@ usage: (format STRING &rest OBJECTS) */) /* For float, maybe we should use "%1.0f" instead so it also works for values outside the integer range. */ - signed_wide x; + printmax_t x; if (INTEGERP (args[n])) x = XINT (args[n]); else @@ -3988,13 +3976,13 @@ usage: (format STRING &rest OBJECTS) */) double d = XFLOAT_DATA (args[n]); if (d < 0) { - x = TYPE_MINIMUM (signed_wide); + x = TYPE_MINIMUM (printmax_t); if (x < d) x = d; } else { - x = TYPE_MAXIMUM (signed_wide); + x = TYPE_MAXIMUM (printmax_t); if (d < x) x = d; } @@ -4004,7 +3992,7 @@ usage: (format STRING &rest OBJECTS) */) else { /* Don't sign-extend for octal or hex printing. */ - unsigned_wide x; + uprintmax_t x; if (INTEGERP (args[n])) x = XUINT (args[n]); else @@ -4014,7 +4002,7 @@ usage: (format STRING &rest OBJECTS) */) x = 0; else { - x = TYPE_MAXIMUM (unsigned_wide); + x = TYPE_MAXIMUM (uprintmax_t); if (d < x) x = d; } diff --git a/src/fileio.c b/src/fileio.c index c6f8dfe468..d4fb038311 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -587,9 +587,9 @@ make_temp_name (Lisp_Object prefix, int base64_p) { Lisp_Object val; int len, clen; - intmax_t pid; + printmax_t pid; char *p, *data; - char pidbuf[INT_BUFSIZE_BOUND (pid_t)]; + char pidbuf[INT_BUFSIZE_BOUND (printmax_t)]; int pidlen; CHECK_STRING (prefix); @@ -611,7 +611,7 @@ make_temp_name (Lisp_Object prefix, int base64_p) else { #ifdef HAVE_LONG_FILE_NAMES - pidlen = sprintf (pidbuf, "%"PRIdMAX, pid); + pidlen = sprintf (pidbuf, "%"pMd, pid); #else pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; diff --git a/src/filelock.c b/src/filelock.c index 18483b6f3f..c28ee7837f 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -337,7 +337,7 @@ static int lock_file_1 (char *lfname, int force) { register int err; - intmax_t boot, pid; + printmax_t boot, pid; const char *user_name; const char *host_name; char *lock_info_str; @@ -354,15 +354,15 @@ lock_file_1 (char *lfname, int force) else host_name = ""; lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) - + 2 * INT_STRLEN_BOUND (intmax_t) + + 2 * INT_STRLEN_BOUND (printmax_t) + sizeof "@.:"); pid = getpid (); if (boot) - sprintf (lock_info_str, "%s@%s.%"PRIdMAX":%"PRIdMAX, + sprintf (lock_info_str, "%s@%s.%"pMd":%"pMd, user_name, host_name, pid, boot); else - sprintf (lock_info_str, "%s@%s.%"PRIdMAX, + sprintf (lock_info_str, "%s@%s.%"pMd, user_name, host_name, pid); err = symlink (lock_info_str, lfname); @@ -542,7 +542,7 @@ lock_file (Lisp_Object fn) register Lisp_Object attack, orig_fn, encoded_fn; register char *lfname, *locker; lock_info_type lock_info; - intmax_t pid; + printmax_t pid; struct gcpro gcpro1; /* Don't do locking while dumping Emacs. @@ -581,9 +581,10 @@ lock_file (Lisp_Object fn) /* Else consider breaking the lock */ locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) - + INT_STRLEN_BOUND (intmax_t) + sizeof "@ (pid )"); + + INT_STRLEN_BOUND (printmax_t) + + sizeof "@ (pid )"); pid = lock_info.pid; - sprintf (locker, "%s@%s (pid %"PRIdMAX")", + sprintf (locker, "%s@%s (pid %"pMd")", lock_info.user, lock_info.host, pid); FREE_LOCK_INFO (lock_info); diff --git a/src/lisp.h b/src/lisp.h index f16a32e633..257c204e3b 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -61,6 +61,23 @@ extern void check_cons_list (void); # define EMACS_UINT unsigned EMACS_INT #endif +/* printmax_t and uprintmax_t are types for printing large integers. + These are the widest integers that are supported for printing. + pMd etc. are conversions for printing them. + On C99 hosts, there's no problem, as even the widest integers work. + Fall back on EMACS_INT on pre-C99 hosts. */ +#ifdef PRIdMAX +typedef intmax_t printmax_t; +typedef uintmax_t uprintmax_t; +# define pMd PRIdMAX +# define pMu PRIuMAX +#else +typedef EMACS_INT printmax_t; +typedef EMACS_UINT uprintmax_t; +# define pMd pI"d" +# define pMu pI"u" +#endif + /* Use pD to format ptrdiff_t values, which suffice for indexes into buffers and strings. Emacs never allocates objects larger than PTRDIFF_MAX bytes, as they cause problems with pointer subtraction. diff --git a/src/xdisp.c b/src/xdisp.c index c1347e2dc2..fcb322e1ed 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8063,7 +8063,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) if (nlflag) { EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; - intmax_t dups; + printmax_t dups; insert_1 ("\n", 1, 1, 0, 0); scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); @@ -8087,12 +8087,12 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) if (dups > 1) { char dupstr[sizeof " [ times]" - + INT_STRLEN_BOUND (intmax_t)]; + + INT_STRLEN_BOUND (printmax_t)]; int duplen; /* If you change this format, don't forget to also change message_log_check_duplicate. */ - sprintf (dupstr, " [%"PRIdMAX" times]", dups); + sprintf (dupstr, " [%"pMd" times]", dups); duplen = strlen (dupstr); TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); insert_1 (dupstr, duplen, 1, 0, 1); -- 2.20.1