emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 534c33c: Fix return type of make_time.


From: Philipp Stephani
Subject: [Emacs-diffs] master 534c33c: Fix return type of make_time.
Date: Wed, 24 Apr 2019 07:19:21 -0400 (EDT)

branch: master
commit 534c33cf375182c97291d2dd242f936df5953321
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    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.
---
 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 e203ce1..41ce9ef 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 89af0c5..125b2f1 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 cb953d1..71280ae 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 78f2381..9eb38cd 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]