From 534c33cf375182c97291d2dd242f936df5953321 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Wed, 24 Apr 2019 13:17:53 +0200 Subject: [PATCH] Fix return type of make_time. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit make_time is documented to return a (TICKS . HZ) pair, so we can’t use make_lisp_time. Introduce a new conversion function instead. * src/emacs-module.c (module_make_time): Use timespec_to_lisp to correct return type. * src/timefns.c (timespec_to_lisp): New function. (make_lisp_time): Use it. * test/src/emacs-module-tests.el (mod-test-add-nanosecond/valid): Check return type. --- src/emacs-module.c | 2 +- src/systime.h | 1 + src/timefns.c | 9 ++++++++- test/src/emacs-module-tests.el | 8 ++++++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/emacs-module.c b/src/emacs-module.c index e203ce1d348..41ce9ef03e4 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -753,7 +753,7 @@ static emacs_value module_make_time (emacs_env *env, struct timespec time) { MODULE_FUNCTION_BEGIN (NULL); - return lisp_to_value (env, make_lisp_time (time)); + return lisp_to_value (env, timespec_to_lisp (time)); } static void diff --git a/src/systime.h b/src/systime.h index 89af0c5e3df..125b2f1385e 100644 --- a/src/systime.h +++ b/src/systime.h @@ -89,6 +89,7 @@ struct lisp_time /* defined in timefns.c */ extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST; extern Lisp_Object make_lisp_time (struct timespec); +extern Lisp_Object timespec_to_lisp (struct timespec); extern bool list4_to_timespec (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, struct timespec *); extern struct timespec lisp_time_argument (Lisp_Object); diff --git a/src/timefns.c b/src/timefns.c index cb953d1b4ce..71280aea06a 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -528,7 +528,14 @@ make_lisp_time (struct timespec t) make_fixnum (ns / 1000), make_fixnum (ns % 1000 * 1000)); } else - return Fcons (timespec_ticks (t), timespec_hz); + return timespec_to_lisp (t); +} + +/* Return (TICKS . HZ) for time T. */ +struct Lisp_Object +timespec_to_lisp (struct timespec t) +{ + return Fcons (timespec_ticks (t), timespec_hz); } /* Convert T to a Lisp timestamp. FORM specifies the timestamp format. */ diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 78f238140da..9eb38cd4548 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -326,8 +326,12 @@ Interactively, you can try hitting \\[keyboard-quit] to quit." ;; New (TICKS . HZ) format. '(123456789 . 1000000000))) (ert-info ((format "input: %s" input)) - (should (time-equal-p (mod-test-add-nanosecond input) - (time-add input '(0 0 0 1000))))))) + (let ((result (mod-test-add-nanosecond input))) + (should (consp result)) + (should (integerp (car result))) + (should (integerp (cdr result))) + (should (cl-plusp (cdr result))) + (should (time-equal-p result (time-add input '(0 0 0 1000)))))))) (ert-deftest mod-test-add-nanosecond/nil () (should (<= (float-time (mod-test-add-nanosecond nil)) -- 2.39.2