aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-07-07 14:52:44 -0700
committerPaul Eggert2011-07-07 14:52:44 -0700
commita81d11a3efb4d511c5c34c8983dc6aab5d619ea1 (patch)
treeb520dcbf5ee7ee4d6d601cbbb3e874265818980c /src
parent3300e6fd43c4059de955cddc37ec4212dab2b085 (diff)
downloademacs-a81d11a3efb4d511c5c34c8983dc6aab5d619ea1.tar.gz
emacs-a81d11a3efb4d511c5c34c8983dc6aab5d619ea1.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/editfns.c40
-rw-r--r--src/fileio.c6
-rw-r--r--src/filelock.c15
-rw-r--r--src/lisp.h17
-rw-r--r--src/xdisp.c6
6 files changed, 55 insertions, 39 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8d8e8789811..62bf5712621 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,15 @@
12011-07-07 Paul Eggert <eggert@cs.ucla.edu> 12011-07-07 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * editfns.c (pWIDE, pWIDElen, signed_wide, unsigned_wide):
4 Remove, replacing with the new symbols in lisp.h. All uses changed.
5 * fileio.c (make_temp_name):
6 * filelock.c (lock_file_1, lock_file):
7 * xdisp.c (message_dolog):
8 Don't assume PRIdMAX etc. works; this isn't portable to pre-C99 hosts.
9 Use pMd etc. instead.
10 * lisp.h (printmax_t, uprintmax_t, pMd, pMu): New types and macros,
11 replacing the pWIDE etc. symbols removed from editfns.c.
12
3 * keyboard.h (num_input_events): Now uintmax_t. 13 * keyboard.h (num_input_events): Now uintmax_t.
4 This is (very slightly) less likely to mess up due to wraparound. 14 This is (very slightly) less likely to mess up due to wraparound.
5 All uses changed. 15 All uses changed.
diff --git a/src/editfns.c b/src/editfns.c
index bb36d0dee71..e3a7d1f7fa1 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3506,22 +3506,6 @@ usage: (propertize STRING &rest PROPERTIES) */)
3506 RETURN_UNGCPRO (string); 3506 RETURN_UNGCPRO (string);
3507} 3507}
3508 3508
3509/* pWIDE is a conversion for printing large decimal integers (possibly with a
3510 trailing "d" that is ignored). pWIDElen is its length. signed_wide and
3511 unsigned_wide are signed and unsigned types for printing them. Use widest
3512 integers if available so that more floating point values can be converted. */
3513#ifdef PRIdMAX
3514# define pWIDE PRIdMAX
3515enum { pWIDElen = sizeof PRIdMAX - 2 }; /* Don't count trailing "d". */
3516typedef intmax_t signed_wide;
3517typedef uintmax_t unsigned_wide;
3518#else
3519# define pWIDE pI
3520enum { pWIDElen = sizeof pI - 1 };
3521typedef EMACS_INT signed_wide;
3522typedef EMACS_UINT unsigned_wide;
3523#endif
3524
3525DEFUN ("format", Fformat, Sformat, 1, MANY, 0, 3509DEFUN ("format", Fformat, Sformat, 1, MANY, 0,
3526 doc: /* Format a string out of a format-string and arguments. 3510 doc: /* Format a string out of a format-string and arguments.
3527The first argument is a format control string. 3511The first argument is a format control string.
@@ -3903,7 +3887,11 @@ usage: (format STRING &rest OBJECTS) */)
3903 precision is no more than DBL_USEFUL_PRECISION_MAX. 3887 precision is no more than DBL_USEFUL_PRECISION_MAX.
3904 On all practical hosts, %f is the worst case. */ 3888 On all practical hosts, %f is the worst case. */
3905 SPRINTF_BUFSIZE = 3889 SPRINTF_BUFSIZE =
3906 sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX 3890 sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX,
3891
3892 /* Length of pM (that is, of pMd without the
3893 trailing "d"). */
3894 pMlen = sizeof pMd - 2
3907 }; 3895 };
3908 verify (0 < USEFUL_PRECISION_MAX); 3896 verify (0 < USEFUL_PRECISION_MAX);
3909 3897
@@ -3916,7 +3904,7 @@ usage: (format STRING &rest OBJECTS) */)
3916 3904
3917 /* Copy of conversion specification, modified somewhat. 3905 /* Copy of conversion specification, modified somewhat.
3918 At most three flags F can be specified at once. */ 3906 At most three flags F can be specified at once. */
3919 char convspec[sizeof "%FFF.*d" + pWIDElen]; 3907 char convspec[sizeof "%FFF.*d" + pMlen];
3920 3908
3921 /* Avoid undefined behavior in underlying sprintf. */ 3909 /* Avoid undefined behavior in underlying sprintf. */
3922 if (conversion == 'd' || conversion == 'i') 3910 if (conversion == 'd' || conversion == 'i')
@@ -3924,7 +3912,7 @@ usage: (format STRING &rest OBJECTS) */)
3924 3912
3925 /* Create the copy of the conversion specification, with 3913 /* Create the copy of the conversion specification, with
3926 any width and precision removed, with ".*" inserted, 3914 any width and precision removed, with ".*" inserted,
3927 and with pWIDE inserted for integer formats. */ 3915 and with pM inserted for integer formats. */
3928 { 3916 {
3929 char *f = convspec; 3917 char *f = convspec;
3930 *f++ = '%'; 3918 *f++ = '%';
@@ -3939,8 +3927,8 @@ usage: (format STRING &rest OBJECTS) */)
3939 || conversion == 'o' || conversion == 'x' 3927 || conversion == 'o' || conversion == 'x'
3940 || conversion == 'X') 3928 || conversion == 'X')
3941 { 3929 {
3942 memcpy (f, pWIDE, pWIDElen); 3930 memcpy (f, pMd, pMlen);
3943 f += pWIDElen; 3931 f += pMlen;
3944 zero_flag &= ~ precision_given; 3932 zero_flag &= ~ precision_given;
3945 } 3933 }
3946 *f++ = conversion; 3934 *f++ = conversion;
@@ -3980,7 +3968,7 @@ usage: (format STRING &rest OBJECTS) */)
3980 /* For float, maybe we should use "%1.0f" 3968 /* For float, maybe we should use "%1.0f"
3981 instead so it also works for values outside 3969 instead so it also works for values outside
3982 the integer range. */ 3970 the integer range. */
3983 signed_wide x; 3971 printmax_t x;
3984 if (INTEGERP (args[n])) 3972 if (INTEGERP (args[n]))
3985 x = XINT (args[n]); 3973 x = XINT (args[n]);
3986 else 3974 else
@@ -3988,13 +3976,13 @@ usage: (format STRING &rest OBJECTS) */)
3988 double d = XFLOAT_DATA (args[n]); 3976 double d = XFLOAT_DATA (args[n]);
3989 if (d < 0) 3977 if (d < 0)
3990 { 3978 {
3991 x = TYPE_MINIMUM (signed_wide); 3979 x = TYPE_MINIMUM (printmax_t);
3992 if (x < d) 3980 if (x < d)
3993 x = d; 3981 x = d;
3994 } 3982 }
3995 else 3983 else
3996 { 3984 {
3997 x = TYPE_MAXIMUM (signed_wide); 3985 x = TYPE_MAXIMUM (printmax_t);
3998 if (d < x) 3986 if (d < x)
3999 x = d; 3987 x = d;
4000 } 3988 }
@@ -4004,7 +3992,7 @@ usage: (format STRING &rest OBJECTS) */)
4004 else 3992 else
4005 { 3993 {
4006 /* Don't sign-extend for octal or hex printing. */ 3994 /* Don't sign-extend for octal or hex printing. */
4007 unsigned_wide x; 3995 uprintmax_t x;
4008 if (INTEGERP (args[n])) 3996 if (INTEGERP (args[n]))
4009 x = XUINT (args[n]); 3997 x = XUINT (args[n]);
4010 else 3998 else
@@ -4014,7 +4002,7 @@ usage: (format STRING &rest OBJECTS) */)
4014 x = 0; 4002 x = 0;
4015 else 4003 else
4016 { 4004 {
4017 x = TYPE_MAXIMUM (unsigned_wide); 4005 x = TYPE_MAXIMUM (uprintmax_t);
4018 if (d < x) 4006 if (d < x)
4019 x = d; 4007 x = d;
4020 } 4008 }
diff --git a/src/fileio.c b/src/fileio.c
index c6f8dfe4683..d4fb0383119 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -587,9 +587,9 @@ make_temp_name (Lisp_Object prefix, int base64_p)
587{ 587{
588 Lisp_Object val; 588 Lisp_Object val;
589 int len, clen; 589 int len, clen;
590 intmax_t pid; 590 printmax_t pid;
591 char *p, *data; 591 char *p, *data;
592 char pidbuf[INT_BUFSIZE_BOUND (pid_t)]; 592 char pidbuf[INT_BUFSIZE_BOUND (printmax_t)];
593 int pidlen; 593 int pidlen;
594 594
595 CHECK_STRING (prefix); 595 CHECK_STRING (prefix);
@@ -611,7 +611,7 @@ make_temp_name (Lisp_Object prefix, int base64_p)
611 else 611 else
612 { 612 {
613#ifdef HAVE_LONG_FILE_NAMES 613#ifdef HAVE_LONG_FILE_NAMES
614 pidlen = sprintf (pidbuf, "%"PRIdMAX, pid); 614 pidlen = sprintf (pidbuf, "%"pMd, pid);
615#else 615#else
616 pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; 616 pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6;
617 pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; 617 pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6;
diff --git a/src/filelock.c b/src/filelock.c
index 18483b6f3f3..c28ee7837fa 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -337,7 +337,7 @@ static int
337lock_file_1 (char *lfname, int force) 337lock_file_1 (char *lfname, int force)
338{ 338{
339 register int err; 339 register int err;
340 intmax_t boot, pid; 340 printmax_t boot, pid;
341 const char *user_name; 341 const char *user_name;
342 const char *host_name; 342 const char *host_name;
343 char *lock_info_str; 343 char *lock_info_str;
@@ -354,15 +354,15 @@ lock_file_1 (char *lfname, int force)
354 else 354 else
355 host_name = ""; 355 host_name = "";
356 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) 356 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name)
357 + 2 * INT_STRLEN_BOUND (intmax_t) 357 + 2 * INT_STRLEN_BOUND (printmax_t)
358 + sizeof "@.:"); 358 + sizeof "@.:");
359 pid = getpid (); 359 pid = getpid ();
360 360
361 if (boot) 361 if (boot)
362 sprintf (lock_info_str, "%s@%s.%"PRIdMAX":%"PRIdMAX, 362 sprintf (lock_info_str, "%s@%s.%"pMd":%"pMd,
363 user_name, host_name, pid, boot); 363 user_name, host_name, pid, boot);
364 else 364 else
365 sprintf (lock_info_str, "%s@%s.%"PRIdMAX, 365 sprintf (lock_info_str, "%s@%s.%"pMd,
366 user_name, host_name, pid); 366 user_name, host_name, pid);
367 367
368 err = symlink (lock_info_str, lfname); 368 err = symlink (lock_info_str, lfname);
@@ -542,7 +542,7 @@ lock_file (Lisp_Object fn)
542 register Lisp_Object attack, orig_fn, encoded_fn; 542 register Lisp_Object attack, orig_fn, encoded_fn;
543 register char *lfname, *locker; 543 register char *lfname, *locker;
544 lock_info_type lock_info; 544 lock_info_type lock_info;
545 intmax_t pid; 545 printmax_t pid;
546 struct gcpro gcpro1; 546 struct gcpro gcpro1;
547 547
548 /* Don't do locking while dumping Emacs. 548 /* Don't do locking while dumping Emacs.
@@ -581,9 +581,10 @@ lock_file (Lisp_Object fn)
581 581
582 /* Else consider breaking the lock */ 582 /* Else consider breaking the lock */
583 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) 583 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host)
584 + INT_STRLEN_BOUND (intmax_t) + sizeof "@ (pid )"); 584 + INT_STRLEN_BOUND (printmax_t)
585 + sizeof "@ (pid )");
585 pid = lock_info.pid; 586 pid = lock_info.pid;
586 sprintf (locker, "%s@%s (pid %"PRIdMAX")", 587 sprintf (locker, "%s@%s (pid %"pMd")",
587 lock_info.user, lock_info.host, pid); 588 lock_info.user, lock_info.host, pid);
588 FREE_LOCK_INFO (lock_info); 589 FREE_LOCK_INFO (lock_info);
589 590
diff --git a/src/lisp.h b/src/lisp.h
index f16a32e6331..257c204e3b0 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -61,6 +61,23 @@ extern void check_cons_list (void);
61# define EMACS_UINT unsigned EMACS_INT 61# define EMACS_UINT unsigned EMACS_INT
62#endif 62#endif
63 63
64/* printmax_t and uprintmax_t are types for printing large integers.
65 These are the widest integers that are supported for printing.
66 pMd etc. are conversions for printing them.
67 On C99 hosts, there's no problem, as even the widest integers work.
68 Fall back on EMACS_INT on pre-C99 hosts. */
69#ifdef PRIdMAX
70typedef intmax_t printmax_t;
71typedef uintmax_t uprintmax_t;
72# define pMd PRIdMAX
73# define pMu PRIuMAX
74#else
75typedef EMACS_INT printmax_t;
76typedef EMACS_UINT uprintmax_t;
77# define pMd pI"d"
78# define pMu pI"u"
79#endif
80
64/* Use pD to format ptrdiff_t values, which suffice for indexes into 81/* Use pD to format ptrdiff_t values, which suffice for indexes into
65 buffers and strings. Emacs never allocates objects larger than 82 buffers and strings. Emacs never allocates objects larger than
66 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction. 83 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
diff --git a/src/xdisp.c b/src/xdisp.c
index c1347e2dc27..fcb322e1edb 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)
8063 if (nlflag) 8063 if (nlflag)
8064 { 8064 {
8065 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; 8065 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte;
8066 intmax_t dups; 8066 printmax_t dups;
8067 insert_1 ("\n", 1, 1, 0, 0); 8067 insert_1 ("\n", 1, 1, 0, 0);
8068 8068
8069 scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); 8069 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)
8087 if (dups > 1) 8087 if (dups > 1)
8088 { 8088 {
8089 char dupstr[sizeof " [ times]" 8089 char dupstr[sizeof " [ times]"
8090 + INT_STRLEN_BOUND (intmax_t)]; 8090 + INT_STRLEN_BOUND (printmax_t)];
8091 int duplen; 8091 int duplen;
8092 8092
8093 /* If you change this format, don't forget to also 8093 /* If you change this format, don't forget to also
8094 change message_log_check_duplicate. */ 8094 change message_log_check_duplicate. */
8095 sprintf (dupstr, " [%"PRIdMAX" times]", dups); 8095 sprintf (dupstr, " [%"pMd" times]", dups);
8096 duplen = strlen (dupstr); 8096 duplen = strlen (dupstr);
8097 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); 8097 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1);
8098 insert_1 (dupstr, duplen, 1, 0, 1); 8098 insert_1 (dupstr, duplen, 1, 0, 1);