aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-10 16:24:36 -0700
committerPaul Eggert2012-07-10 16:24:36 -0700
commite9a9ae0350689d352c2bdfa3af0eb722f587b966 (patch)
tree10ed0298079b06838a525f0a4df780d7600e13fe /src/editfns.c
parentffacb12679a1e001981c2e0f690b327eda652d04 (diff)
downloademacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.tar.gz
emacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.zip
EMACS_TIME simplification (Bug#11875).
This replaces macros (which typically do not work in GDB) with functions, typedefs and enums, making the code easier to debug. The functional style also makes code easier to read and maintain. * lib-src/profile.c (TV2): Remove no-longer-needed static var. * src/systime.h: Include <sys/time.h> on all hosts, not just if WINDOWSNT, since 'struct timeval' is needed in general. (EMACS_TIME): Now a typedef, not a macro. (EMACS_TIME_RESOLUTION, LOG10_EMACS_TIME_RESOLUTION): Now constants, not macros. (EMACS_SECS, EMACS_NSECS, EMACS_TIME_SIGN, EMACS_TIME_VALID_P) (EMACS_TIME_FROM_DOUBLE, EMACS_TIME_TO_DOUBLE, EMACS_TIME_EQ) (EMACS_TIME_NE, EMACS_TIME_GT, EMACS_TIME_GE, EMACS_TIME_LT) (EMACS_TIME_LE): Now functions, not macros. (EMACS_SET_SECS, EMACS_SET_NSECS, EMACS_SET_SECS_NSECS) (EMACS_SET_USECS, EMACS_SET_SECS_USECS): Remove these macros, which are not functions. All uses rewritten to use: (make_emacs_time): New function. (EMACS_SECS_ADDR, EMACS_SET_INVALID_TIME, EMACS_GET_TIME) (EMACS_ADD_TIME, EMACS_SUB_TIME): Remove these macros, which are not functions. All uses rewritten to use the following, respectively: (emacs_secs_addr, invalid_emacs_time, get_emacs_time) (add_emacs_time, sub_emacs_time): New functions. * src/atimer.c: Don't include <sys/time.h>, as "systime.h" does this. * src/fileio.c (Fcopy_file): * src/xterm.c (XTflash): Get the current time closer to when it's used. * src/makefile.w32-in ($(BLD)/atimer.$(O)): Update dependencies.
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/editfns.c b/src/editfns.c
index e48097ab3a6..32d11faa216 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1408,10 +1408,7 @@ least significant 16 bits. USEC and PSEC are the microsecond and
1408picosecond counts. */) 1408picosecond counts. */)
1409 (void) 1409 (void)
1410{ 1410{
1411 EMACS_TIME t; 1411 return make_lisp_time (current_emacs_time ());
1412
1413 EMACS_GET_TIME (t);
1414 return make_lisp_time (t);
1415} 1412}
1416 1413
1417DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, 1414DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
@@ -1428,7 +1425,6 @@ does the same thing as `current-time'. */)
1428 struct rusage usage; 1425 struct rusage usage;
1429 time_t secs; 1426 time_t secs;
1430 int usecs; 1427 int usecs;
1431 EMACS_TIME t;
1432 1428
1433 if (getrusage (RUSAGE_SELF, &usage) < 0) 1429 if (getrusage (RUSAGE_SELF, &usage) < 0)
1434 /* This shouldn't happen. What action is appropriate? */ 1430 /* This shouldn't happen. What action is appropriate? */
@@ -1442,8 +1438,7 @@ does the same thing as `current-time'. */)
1442 usecs -= 1000000; 1438 usecs -= 1000000;
1443 secs++; 1439 secs++;
1444 } 1440 }
1445 EMACS_SET_SECS_USECS (t, secs, usecs); 1441 return make_lisp_time (make_emacs_time (secs, usecs * 1000));
1446 return make_lisp_time (t);
1447#else /* ! HAVE_GETRUSAGE */ 1442#else /* ! HAVE_GETRUSAGE */
1448#ifdef WINDOWSNT 1443#ifdef WINDOWSNT
1449 return w32_get_internal_run_time (); 1444 return w32_get_internal_run_time ();
@@ -1560,8 +1555,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1560 /* Return the greatest representable time that is not greater 1555 /* Return the greatest representable time that is not greater
1561 than the requested time. */ 1556 than the requested time. */
1562 time_t sec = hi; 1557 time_t sec = hi;
1563 EMACS_SET_SECS_NSECS (*result, (sec << 16) + lo, 1558 *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000);
1564 us * 1000 + ps / 1000);
1565 } 1559 }
1566 else 1560 else
1567 { 1561 {
@@ -1587,7 +1581,7 @@ lisp_time_argument (Lisp_Object specified_time)
1587{ 1581{
1588 EMACS_TIME t; 1582 EMACS_TIME t;
1589 if (NILP (specified_time)) 1583 if (NILP (specified_time))
1590 EMACS_GET_TIME (t); 1584 t = current_emacs_time ();
1591 else 1585 else
1592 { 1586 {
1593 Lisp_Object high, low, usec, psec; 1587 Lisp_Object high, low, usec, psec;
@@ -1635,8 +1629,7 @@ or (if you need time as a string) `format-time-string'. */)
1635 double t; 1629 double t;
1636 if (NILP (specified_time)) 1630 if (NILP (specified_time))
1637 { 1631 {
1638 EMACS_TIME now; 1632 EMACS_TIME now = current_emacs_time ();
1639 EMACS_GET_TIME (now);
1640 t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9; 1633 t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9;
1641 } 1634 }
1642 else 1635 else
@@ -1780,11 +1773,12 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1780 1773
1781 while (1) 1774 while (1)
1782 { 1775 {
1776 time_t *taddr = emacs_secs_addr (&t);
1783 BLOCK_INPUT; 1777 BLOCK_INPUT;
1784 1778
1785 synchronize_system_time_locale (); 1779 synchronize_system_time_locale ();
1786 1780
1787 tm = ut ? gmtime (EMACS_SECS_ADDR (t)) : localtime (EMACS_SECS_ADDR (t)); 1781 tm = ut ? gmtime (taddr) : localtime (taddr);
1788 if (! tm) 1782 if (! tm)
1789 { 1783 {
1790 UNBLOCK_INPUT; 1784 UNBLOCK_INPUT;
@@ -2065,10 +2059,10 @@ the data it can't find. */)
2065 Lisp_Object zone_offset, zone_name; 2059 Lisp_Object zone_offset, zone_name;
2066 2060
2067 zone_offset = Qnil; 2061 zone_offset = Qnil;
2068 EMACS_SET_SECS_NSECS (value, lisp_seconds_argument (specified_time), 0); 2062 value = make_emacs_time (lisp_seconds_argument (specified_time), 0);
2069 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); 2063 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
2070 BLOCK_INPUT; 2064 BLOCK_INPUT;
2071 t = gmtime (EMACS_SECS_ADDR (value)); 2065 t = gmtime (emacs_secs_addr (&value));
2072 if (t) 2066 if (t)
2073 offset = tm_diff (&localtm, t); 2067 offset = tm_diff (&localtm, t);
2074 UNBLOCK_INPUT; 2068 UNBLOCK_INPUT;