aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2012-07-10 16:24:36 -0700
committerPaul Eggert2012-07-10 16:24:36 -0700
commite9a9ae0350689d352c2bdfa3af0eb722f587b966 (patch)
tree10ed0298079b06838a525f0a4df780d7600e13fe /lib-src
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 'lib-src')
-rw-r--r--lib-src/ChangeLog3
-rw-r--r--lib-src/profile.c13
2 files changed, 8 insertions, 8 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 449985966a4..0c517b0d571 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,5 +1,8 @@
12012-07-10 Paul Eggert <eggert@cs.ucla.edu> 12012-07-10 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 EMACS_TIME simplification (Bug#11875).
4 * profile.c (TV2): Remove no-longer-needed static var.
5
3 Simplify by avoiding confusing use of strncpy etc. 6 Simplify by avoiding confusing use of strncpy etc.
4 * etags.c (write_classname, C_entries): 7 * etags.c (write_classname, C_entries):
5 Use sprintf rather than strncpy or strncat. 8 Use sprintf rather than strncpy or strncat.
diff --git a/lib-src/profile.c b/lib-src/profile.c
index 02471d89da8..d21f2c28e58 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -36,7 +36,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
36#include <intprops.h> 36#include <intprops.h>
37#include <systime.h> 37#include <systime.h>
38 38
39static EMACS_TIME TV1, TV2; 39static EMACS_TIME TV1;
40static int watch_not_started = 1; /* flag */ 40static int watch_not_started = 1; /* flag */
41static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "." 41static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "."
42 + LOG10_EMACS_TIME_RESOLUTION]; 42 + LOG10_EMACS_TIME_RESOLUTION];
@@ -46,7 +46,7 @@ static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "."
46static void 46static void
47reset_watch (void) 47reset_watch (void)
48{ 48{
49 EMACS_GET_TIME (TV1); 49 TV1 = current_emacs_time ();
50 watch_not_started = 0; 50 watch_not_started = 0;
51} 51}
52 52
@@ -57,14 +57,11 @@ reset_watch (void)
57static char * 57static char *
58get_time (void) 58get_time (void)
59{ 59{
60 uintmax_t s; 60 EMACS_TIME TV2 = sub_emacs_time (current_emacs_time (), TV1);
61 int ns; 61 uintmax_t s = EMACS_SECS (TV2);
62 int ns = EMACS_NSECS (TV2);
62 if (watch_not_started) 63 if (watch_not_started)
63 exit (EXIT_FAILURE); /* call reset_watch first ! */ 64 exit (EXIT_FAILURE); /* call reset_watch first ! */
64 EMACS_GET_TIME (TV2);
65 EMACS_SUB_TIME (TV2, TV2, TV1);
66 s = EMACS_SECS (TV2);
67 ns = EMACS_NSECS (TV2);
68 sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns); 65 sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns);
69 return time_string; 66 return time_string;
70} 67}