Commit 534c33cf authored by Philipp Stephani's avatar Philipp Stephani

Fix return type of make_time.

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.
parent e290a7d1
Pipeline #1435 failed with stage
in 8 minutes and 56 seconds
......@@ -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
......
......@@ -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);
......
......@@ -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. */
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment