aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert2013-08-27 11:47:55 -0700
committerPaul Eggert2013-08-27 11:47:55 -0700
commit43aac990c339c0fc3304aa476ebc8ea8467f107e (patch)
tree24f6477d7ec79c7f3529e08c421f309b1180c436 /src/editfns.c
parent278208b8e6917af1e7e2623a3869614fa70059ed (diff)
downloademacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.tar.gz
emacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.zip
Simplify EMACS_TIME-related code.
This portability layer is no longer needed, since Emacs has been using struct timespec as a portability layer for some time. Merge from gnulib, incorporating: 2013-08-27 timespec: new convenience constants and function * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h: Include <time.h> rather than "systime.h"; that's all that's needed now. * src/dispnew.c: Include <timespec.h> rather than "systime.h"; that's all that's needed now. * src/systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. (EMACS_TIME_RESOLUTION): Remove. All uses changed to TIMESPEC_RESOLUTION. (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to LOG10_TIMESPEC_RESOLUTION. (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. (EMACS_NSECS): Remove. All uses changed to tv_nsec. (make_emacs_time): Remove. All used changed to make_timespec. (invalid_timespec): Rename from invalid_emacs_time. All uses changed. (current_timespec): Rename from current_emacs_time. All uses changed. (add_emacs_time): Remove. All uses changed to timespec_add. (sub_emacs_time): Remove. All uses change dot timespec_sub. (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. (current_timespec): Rename from current_emacs_time. All uses changed. (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses changed to timespec_cmp. * src/xgselect.c: Include <timespec.h>, since our .h files don't.
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/editfns.c b/src/editfns.c
index bbaeaea5240..9e36655f3d3 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -64,7 +64,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
64extern Lisp_Object w32_get_internal_run_time (void); 64extern Lisp_Object w32_get_internal_run_time (void);
65#endif 65#endif
66 66
67static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME, 67static Lisp_Object format_time_string (char const *, ptrdiff_t, struct timespec,
68 bool, struct tm *); 68 bool, struct tm *);
69static int tm_diff (struct tm *, struct tm *); 69static int tm_diff (struct tm *, struct tm *);
70static void update_buffer_properties (ptrdiff_t, ptrdiff_t); 70static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
@@ -1420,7 +1420,7 @@ least significant 16 bits. USEC and PSEC are the microsecond and
1420picosecond counts. */) 1420picosecond counts. */)
1421 (void) 1421 (void)
1422{ 1422{
1423 return make_lisp_time (current_emacs_time ()); 1423 return make_lisp_time (current_timespec ());
1424} 1424}
1425 1425
1426DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, 1426DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
@@ -1450,7 +1450,7 @@ does the same thing as `current-time'. */)
1450 usecs -= 1000000; 1450 usecs -= 1000000;
1451 secs++; 1451 secs++;
1452 } 1452 }
1453 return make_lisp_time (make_emacs_time (secs, usecs * 1000)); 1453 return make_lisp_time (make_timespec (secs, usecs * 1000));
1454#else /* ! HAVE_GETRUSAGE */ 1454#else /* ! HAVE_GETRUSAGE */
1455#ifdef WINDOWSNT 1455#ifdef WINDOWSNT
1456 return w32_get_internal_run_time (); 1456 return w32_get_internal_run_time ();
@@ -1481,10 +1481,10 @@ make_time (time_t t)
1481 UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a 1481 UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a
1482 correspondingly negative picosecond count. */ 1482 correspondingly negative picosecond count. */
1483Lisp_Object 1483Lisp_Object
1484make_lisp_time (EMACS_TIME t) 1484make_lisp_time (struct timespec t)
1485{ 1485{
1486 int ns = EMACS_NSECS (t); 1486 int ns = t.tv_nsec;
1487 return make_time_tail (EMACS_SECS (t), list2i (ns / 1000, ns % 1000 * 1000)); 1487 return make_time_tail (t.tv_sec, list2i (ns / 1000, ns % 1000 * 1000));
1488} 1488}
1489 1489
1490/* Decode a Lisp list SPECIFIED_TIME that represents a time. 1490/* Decode a Lisp list SPECIFIED_TIME that represents a time.
@@ -1529,7 +1529,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
1529 list, generate the corresponding time value. 1529 list, generate the corresponding time value.
1530 1530
1531 If RESULT is not null, store into *RESULT the converted time; 1531 If RESULT is not null, store into *RESULT the converted time;
1532 this can fail if the converted time does not fit into EMACS_TIME. 1532 this can fail if the converted time does not fit into struct timespec.
1533 If *DRESULT is not null, store into *DRESULT the number of 1533 If *DRESULT is not null, store into *DRESULT the number of
1534 seconds since the start of the POSIX Epoch. 1534 seconds since the start of the POSIX Epoch.
1535 1535
@@ -1537,7 +1537,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
1537bool 1537bool
1538decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, 1538decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1539 Lisp_Object psec, 1539 Lisp_Object psec,
1540 EMACS_TIME *result, double *dresult) 1540 struct timespec *result, double *dresult)
1541{ 1541{
1542 EMACS_INT hi, lo, us, ps; 1542 EMACS_INT hi, lo, us, ps;
1543 if (! (INTEGERP (high) && INTEGERP (low) 1543 if (! (INTEGERP (high) && INTEGERP (low)
@@ -1565,7 +1565,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1565 /* Return the greatest representable time that is not greater 1565 /* Return the greatest representable time that is not greater
1566 than the requested time. */ 1566 than the requested time. */
1567 time_t sec = hi; 1567 time_t sec = hi;
1568 *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000); 1568 *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000);
1569 } 1569 }
1570 else 1570 else
1571 { 1571 {
@@ -1583,15 +1583,15 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1583/* Decode a Lisp list SPECIFIED_TIME that represents a time. 1583/* Decode a Lisp list SPECIFIED_TIME that represents a time.
1584 If SPECIFIED_TIME is nil, use the current time. 1584 If SPECIFIED_TIME is nil, use the current time.
1585 1585
1586 Round the time down to the nearest EMACS_TIME value. 1586 Round the time down to the nearest struct timespec value.
1587 Return seconds since the Epoch. 1587 Return seconds since the Epoch.
1588 Signal an error if unsuccessful. */ 1588 Signal an error if unsuccessful. */
1589EMACS_TIME 1589struct timespec
1590lisp_time_argument (Lisp_Object specified_time) 1590lisp_time_argument (Lisp_Object specified_time)
1591{ 1591{
1592 EMACS_TIME t; 1592 struct timespec t;
1593 if (NILP (specified_time)) 1593 if (NILP (specified_time))
1594 t = current_emacs_time (); 1594 t = current_timespec ();
1595 else 1595 else
1596 { 1596 {
1597 Lisp_Object high, low, usec, psec; 1597 Lisp_Object high, low, usec, psec;
@@ -1613,12 +1613,12 @@ lisp_seconds_argument (Lisp_Object specified_time)
1613 else 1613 else
1614 { 1614 {
1615 Lisp_Object high, low, usec, psec; 1615 Lisp_Object high, low, usec, psec;
1616 EMACS_TIME t; 1616 struct timespec t;
1617 if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec) 1617 if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
1618 && decode_time_components (high, low, make_number (0), 1618 && decode_time_components (high, low, make_number (0),
1619 make_number (0), &t, 0))) 1619 make_number (0), &t, 0)))
1620 error ("Invalid time specification"); 1620 error ("Invalid time specification");
1621 return EMACS_SECS (t); 1621 return t.tv_sec;
1622 } 1622 }
1623} 1623}
1624 1624
@@ -1639,8 +1639,8 @@ or (if you need time as a string) `format-time-string'. */)
1639 double t; 1639 double t;
1640 if (NILP (specified_time)) 1640 if (NILP (specified_time))
1641 { 1641 {
1642 EMACS_TIME now = current_emacs_time (); 1642 struct timespec now = current_timespec ();
1643 t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9; 1643 t = now.tv_sec + now.tv_nsec / 1e9;
1644 } 1644 }
1645 else 1645 else
1646 { 1646 {
@@ -1758,7 +1758,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".
1758usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) 1758usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */)
1759 (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal) 1759 (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal)
1760{ 1760{
1761 EMACS_TIME t = lisp_time_argument (timeval); 1761 struct timespec t = lisp_time_argument (timeval);
1762 struct tm tm; 1762 struct tm tm;
1763 1763
1764 CHECK_STRING (format_string); 1764 CHECK_STRING (format_string);
@@ -1770,20 +1770,20 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */)
1770 1770
1771static Lisp_Object 1771static Lisp_Object
1772format_time_string (char const *format, ptrdiff_t formatlen, 1772format_time_string (char const *format, ptrdiff_t formatlen,
1773 EMACS_TIME t, bool ut, struct tm *tmp) 1773 struct timespec t, bool ut, struct tm *tmp)
1774{ 1774{
1775 char buffer[4000]; 1775 char buffer[4000];
1776 char *buf = buffer; 1776 char *buf = buffer;
1777 ptrdiff_t size = sizeof buffer; 1777 ptrdiff_t size = sizeof buffer;
1778 size_t len; 1778 size_t len;
1779 Lisp_Object bufstring; 1779 Lisp_Object bufstring;
1780 int ns = EMACS_NSECS (t); 1780 int ns = t.tv_nsec;
1781 struct tm *tm; 1781 struct tm *tm;
1782 USE_SAFE_ALLOCA; 1782 USE_SAFE_ALLOCA;
1783 1783
1784 while (1) 1784 while (1)
1785 { 1785 {
1786 time_t *taddr = emacs_secs_addr (&t); 1786 time_t *taddr = &t.tv_sec;
1787 block_input (); 1787 block_input ();
1788 1788
1789 synchronize_system_time_locale (); 1789 synchronize_system_time_locale ();
@@ -2068,17 +2068,17 @@ in this case, `current-time-zone' returns a list containing nil for
2068the data it can't find. */) 2068the data it can't find. */)
2069 (Lisp_Object specified_time) 2069 (Lisp_Object specified_time)
2070{ 2070{
2071 EMACS_TIME value; 2071 struct timespec value;
2072 int offset; 2072 int offset;
2073 struct tm *t; 2073 struct tm *t;
2074 struct tm localtm; 2074 struct tm localtm;
2075 Lisp_Object zone_offset, zone_name; 2075 Lisp_Object zone_offset, zone_name;
2076 2076
2077 zone_offset = Qnil; 2077 zone_offset = Qnil;
2078 value = make_emacs_time (lisp_seconds_argument (specified_time), 0); 2078 value = make_timespec (lisp_seconds_argument (specified_time), 0);
2079 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); 2079 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
2080 block_input (); 2080 block_input ();
2081 t = gmtime (emacs_secs_addr (&value)); 2081 t = gmtime (&value.tv_sec);
2082 if (t) 2082 if (t)
2083 offset = tm_diff (&localtm, t); 2083 offset = tm_diff (&localtm, t);
2084 unblock_input (); 2084 unblock_input ();