diff options
| author | Paul Eggert | 2022-04-28 12:50:39 -0700 |
|---|---|---|
| committer | Paul Eggert | 2022-04-28 12:54:06 -0700 |
| commit | 083d2708f9ec7f09712488a99fc9eedd3d594ff6 (patch) | |
| tree | 14567fa0ff505ea08a42b5710d0fabd47ff59d03 /src/timefns.c | |
| parent | a41a181db5f3aca043ed42b228dc56a6403c21a5 (diff) | |
| download | emacs-083d2708f9ec7f09712488a99fc9eedd3d594ff6.tar.gz emacs-083d2708f9ec7f09712488a99fc9eedd3d594ff6.zip | |
Change current-time back to list form
Change current-time and related functions back to using the
traditional list form. Also, add a new boolean variable
current-time-list that lets people try out (TICKS . HZ) form,
with the goal of smoothing the transition.
* src/timefns.c (CURRENT_TIME_LIST): Change default back to true.
(current-time-list): New boolean Lisp variable, which defaults to
CURRENT_TIME_LIST. All uses of CURRENT_TIME_LIST changed to
use current_time_list, and all documentation changed.
Diffstat (limited to 'src/timefns.c')
| -rw-r--r-- | src/timefns.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/src/timefns.c b/src/timefns.c index 651e0760e83..bca9a566e08 100644 --- a/src/timefns.c +++ b/src/timefns.c | |||
| @@ -69,11 +69,11 @@ enum { TM_YEAR_BASE = 1900 }; | |||
| 69 | # define FASTER_TIMEFNS 1 | 69 | # define FASTER_TIMEFNS 1 |
| 70 | #endif | 70 | #endif |
| 71 | 71 | ||
| 72 | /* current-time etc. generate (TICKS . HZ) timestamps. | 72 | /* current-time-list defaults to t, typically generating (HI LO US PS) |
| 73 | To change that to the old 4-element list format (HI LO US PS), | 73 | timestamps. To change the default to nil, generating (TICKS . HZ) |
| 74 | compile with -DCURRENT_TIME_LIST=1. */ | 74 | timestamps, compile with -DCURRENT_TIME_LIST=0. */ |
| 75 | #ifndef CURRENT_TIME_LIST | 75 | #ifndef CURRENT_TIME_LIST |
| 76 | enum { CURRENT_TIME_LIST = false }; | 76 | enum { CURRENT_TIME_LIST = true }; |
| 77 | #endif | 77 | #endif |
| 78 | 78 | ||
| 79 | #if FIXNUM_OVERFLOW_P (1000000000) | 79 | #if FIXNUM_OVERFLOW_P (1000000000) |
| @@ -568,7 +568,7 @@ lisp_time_seconds (struct lisp_time t) | |||
| 568 | Lisp_Object | 568 | Lisp_Object |
| 569 | make_lisp_time (struct timespec t) | 569 | make_lisp_time (struct timespec t) |
| 570 | { | 570 | { |
| 571 | if (CURRENT_TIME_LIST) | 571 | if (current_time_list) |
| 572 | { | 572 | { |
| 573 | time_t s = t.tv_sec; | 573 | time_t s = t.tv_sec; |
| 574 | int ns = t.tv_nsec; | 574 | int ns = t.tv_nsec; |
| @@ -1171,13 +1171,13 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract) | |||
| 1171 | } | 1171 | } |
| 1172 | 1172 | ||
| 1173 | /* Return an integer if the timestamp resolution is 1, | 1173 | /* Return an integer if the timestamp resolution is 1, |
| 1174 | otherwise the (TICKS . HZ) form if !CURRENT_TIME_LIST or if | 1174 | otherwise the (TICKS . HZ) form if !current_time_list or if |
| 1175 | either input used (TICKS . HZ) form or the result can't be expressed | 1175 | either input used (TICKS . HZ) form or the result can't be expressed |
| 1176 | exactly in (HI LO US PS) form, otherwise the (HI LO US PS) form | 1176 | exactly in (HI LO US PS) form, otherwise the (HI LO US PS) form |
| 1177 | for backward compatibility. */ | 1177 | for backward compatibility. */ |
| 1178 | return (EQ (hz, make_fixnum (1)) | 1178 | return (EQ (hz, make_fixnum (1)) |
| 1179 | ? ticks | 1179 | ? ticks |
| 1180 | : (!CURRENT_TIME_LIST | 1180 | : (!current_time_list |
| 1181 | || aform == TIMEFORM_TICKS_HZ | 1181 | || aform == TIMEFORM_TICKS_HZ |
| 1182 | || bform == TIMEFORM_TICKS_HZ | 1182 | || bform == TIMEFORM_TICKS_HZ |
| 1183 | || !trillion_factor (hz)) | 1183 | || !trillion_factor (hz)) |
| @@ -1716,7 +1716,7 @@ usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS) */) | |||
| 1716 | time_error (mktime_errno); | 1716 | time_error (mktime_errno); |
| 1717 | 1717 | ||
| 1718 | if (EQ (hz, make_fixnum (1))) | 1718 | if (EQ (hz, make_fixnum (1))) |
| 1719 | return (CURRENT_TIME_LIST | 1719 | return (current_time_list |
| 1720 | ? list2 (hi_time (value), lo_time (value)) | 1720 | ? list2 (hi_time (value), lo_time (value)) |
| 1721 | : INT_TO_INTEGER (value)); | 1721 | : INT_TO_INTEGER (value)); |
| 1722 | else | 1722 | else |
| @@ -1747,7 +1747,7 @@ bits, and USEC and PSEC are the microsecond and picosecond counts. */) | |||
| 1747 | struct lisp_time t; | 1747 | struct lisp_time t; |
| 1748 | enum timeform input_form = decode_lisp_time (time, false, &t, 0); | 1748 | enum timeform input_form = decode_lisp_time (time, false, &t, 0); |
| 1749 | if (NILP (form)) | 1749 | if (NILP (form)) |
| 1750 | form = CURRENT_TIME_LIST ? Qlist : Qt; | 1750 | form = current_time_list ? Qlist : Qt; |
| 1751 | if (EQ (form, Qlist)) | 1751 | if (EQ (form, Qlist)) |
| 1752 | return ticks_hz_list4 (t.ticks, t.hz); | 1752 | return ticks_hz_list4 (t.ticks, t.hz); |
| 1753 | if (EQ (form, Qinteger)) | 1753 | if (EQ (form, Qinteger)) |
| @@ -1762,14 +1762,15 @@ bits, and USEC and PSEC are the microsecond and picosecond counts. */) | |||
| 1762 | 1762 | ||
| 1763 | DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0, | 1763 | DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0, |
| 1764 | doc: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00. | 1764 | doc: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00. |
| 1765 | The time is returned as a pair of integers (TICKS . HZ), where TICKS | 1765 | If the variable `current-time-list' is nil, the time is returned as a |
| 1766 | counts clock ticks and HZ is the clock ticks per second. | 1766 | pair of integers (TICKS . HZ), where TICKS counts clock ticks and HZ |
| 1767 | 1767 | is the clock ticks per second. Otherwise, the time is returned as a | |
| 1768 | In Emacs 28 and earlier, the returned timestamp had the form (HIGH LOW | 1768 | list of integers (HIGH LOW USEC PSEC) where HIGH has the most |
| 1769 | USEC PSEC), where HIGH is the most significant bits of the seconds, | 1769 | significant bits of the seconds, LOW has the least significant 16 |
| 1770 | LOW the least significant 16 bits, and USEC and PSEC are the | 1770 | bits, and USEC and PSEC are the microsecond and picosecond counts. |
| 1771 | microsecond and picosecond counts. Use \(time-convert nil \\='list) | 1771 | |
| 1772 | if you need this older timestamp form. */) | 1772 | You can use `time-convert' to get a particular timestamp form |
| 1773 | regardless of the value of `current-time-list'. */) | ||
| 1773 | (void) | 1774 | (void) |
| 1774 | { | 1775 | { |
| 1775 | return make_lisp_time (current_timespec ()); | 1776 | return make_lisp_time (current_timespec ()); |
| @@ -2025,6 +2026,19 @@ syms_of_timefns (void) | |||
| 2025 | 2026 | ||
| 2026 | DEFSYM (Qencode_time, "encode-time"); | 2027 | DEFSYM (Qencode_time, "encode-time"); |
| 2027 | 2028 | ||
| 2029 | DEFVAR_BOOL ("current-time-list", current_time_list, | ||
| 2030 | doc: /* Whether `current-time' should return list or (TICKS . HZ) form. | ||
| 2031 | |||
| 2032 | This boolean variable is a transition aid. If t, `current-time' and | ||
| 2033 | related functions return timestamps in list form, typically | ||
| 2034 | \(HIGH LOW USEC PSEC); otherwise, they use (TICKS . HZ) form. | ||
| 2035 | Currently this variable defaults to t, for behavior compatible with | ||
| 2036 | previous Emacs versions. Developers are encourage to test | ||
| 2037 | timestamp-related code with this variable set to nil, as it will | ||
| 2038 | default to nil in a future Emacs version, and will be removed in some | ||
| 2039 | version after that. */); | ||
| 2040 | current_time_list = CURRENT_TIME_LIST; | ||
| 2041 | |||
| 2028 | defsubr (&Scurrent_time); | 2042 | defsubr (&Scurrent_time); |
| 2029 | #ifdef CLOCKS_PER_SEC | 2043 | #ifdef CLOCKS_PER_SEC |
| 2030 | defsubr (&Scurrent_cpu_time); | 2044 | defsubr (&Scurrent_cpu_time); |