diff options
| author | Paul Eggert | 2011-07-07 14:52:44 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-07 14:52:44 -0700 |
| commit | a81d11a3efb4d511c5c34c8983dc6aab5d619ea1 (patch) | |
| tree | b520dcbf5ee7ee4d6d601cbbb3e874265818980c /src/editfns.c | |
| parent | 3300e6fd43c4059de955cddc37ec4212dab2b085 (diff) | |
| download | emacs-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/editfns.c')
| -rw-r--r-- | src/editfns.c | 40 |
1 files changed, 14 insertions, 26 deletions
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 | ||
| 3515 | enum { pWIDElen = sizeof PRIdMAX - 2 }; /* Don't count trailing "d". */ | ||
| 3516 | typedef intmax_t signed_wide; | ||
| 3517 | typedef uintmax_t unsigned_wide; | ||
| 3518 | #else | ||
| 3519 | # define pWIDE pI | ||
| 3520 | enum { pWIDElen = sizeof pI - 1 }; | ||
| 3521 | typedef EMACS_INT signed_wide; | ||
| 3522 | typedef EMACS_UINT unsigned_wide; | ||
| 3523 | #endif | ||
| 3524 | |||
| 3525 | DEFUN ("format", Fformat, Sformat, 1, MANY, 0, | 3509 | DEFUN ("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. |
| 3527 | The first argument is a format control string. | 3511 | The 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 | } |