unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: master d0c77a1: Remove some assumptions about timestamp format
Date: Wed, 26 Sep 2018 11:24:51 +0200	[thread overview]
Message-ID: <87o9ck6270.fsf@gmx.de> (raw)
In-Reply-To: <b58efb93-3a91-de6a-014b-198c89603270@cs.ucla.edu> (Paul Eggert's message of "Tue, 25 Sep 2018 18:09:39 -0700")

Paul Eggert <eggert@cs.ucla.edu> writes:

Hi Paul,

> A constant like that would make things clearer, yes. Either 0 or (0 0
> 0 0) or (0 0) should do, so I suggest just 0 as it's simplest. While
> you're at it, you might consider changing the number from 0 to a
> negative value, say -1 (the value that POSIX uses for invalid time_t),
> since that's less likely to collide with actual file timestamps
> (timestamp 0 is far more common than timestamp -1 in real filesystems
> in my experience).

There is already invalid_timespec() in systime.h. What about the
following patch?

--8<---------------cut here---------------start------------->8---
diff --git a/src/editfns.c b/src/editfns.c
index 8c7491beed..fc076a52c1 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1592,6 +1592,10 @@ static Lisp_Object
 time_arith (Lisp_Object a, Lisp_Object b,
 	    struct lisp_time (*op) (struct lisp_time, struct lisp_time))
 {
+  if (!NILP (Ftime_equal_p (a, Vinvalid_time)) ||
+      !NILP (Ftime_equal_p (b, Vinvalid_time)))
+    return Vinvalid_time;
+
   int alen, blen;
   struct lisp_time ta = lisp_time_struct (a, &alen);
   struct lisp_time tb = lisp_time_struct (b, &blen);
@@ -1620,6 +1624,7 @@ time_arith (Lisp_Object a, Lisp_Object b,
 DEFUN ("time-add", Ftime_add, Stime_add, 2, 2, 0,
        doc: /* Return the sum of two time values A and B, as a time value.
 A nil value for either argument stands for the current time.
+If time value A or B is equal to `invalid-time', this value is returned.
 See `current-time-string' for the various forms of a time value.  */)
   (Lisp_Object a, Lisp_Object b)
 {
@@ -1630,6 +1635,7 @@ DEFUN ("time-subtract", Ftime_subtract, Stime_subtract, 2, 2, 0,
        doc: /* Return the difference between two time values A and B, as a time value.
 Use `float-time' to convert the difference into elapsed seconds.
 A nil value for either argument stands for the current time.
+If time value A or B is equal to `invalid-time', this value is returned.
 See `current-time-string' for the various forms of a time value.  */)
   (Lisp_Object a, Lisp_Object b)
 {
@@ -1652,6 +1658,19 @@ See `current-time-string' for the various forms of a time value.  */)
 	  ? Qt : Qnil);
 }
 
+DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0,
+       doc: /* Return non-nil if time value T1 is equal to time value T2.
+A nil value for either argument stands for the current time.
+See `current-time-string' for the various forms of a time value.  */)
+  (Lisp_Object t1, Lisp_Object t2)
+{
+  int t1len, t2len;
+  struct lisp_time a = lisp_time_struct (t1, &t1len);
+  struct lisp_time b = lisp_time_struct (t2, &t2len);
+  return
+    a.hi == b.hi && a.lo == b.lo && a.us == b.us && a.ps == b.ps ? Qt : Qnil;
+}
+
 
 DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
        0, 0, 0,
@@ -2287,6 +2306,9 @@ the TZ environment variable.  It can also be a list (as from
 without consideration for daylight saving time.  */)
   (Lisp_Object specified_time, Lisp_Object zone)
 {
+  if (Ftime_equal_p (specified_time, Vinvalid_time))
+      check_time_validity (0);
+
   time_t value = lisp_seconds_argument (specified_time);
   timezone_t tz = tzlookup (zone, false);
 
@@ -5661,6 +5683,10 @@ it to be non-nil.  */);
   binary_as_unsigned = true;
 #endif
 
+  DEFVAR_LISP ("invalid-time", Vinvalid_time,
+	       doc: /* An invalid time value, used as "Don't know" value.  */);
+  Vinvalid_time = make_lisp_time (invalid_timespec ());
+
   defsubr (&Spropertize);
   defsubr (&Schar_equal);
   defsubr (&Sgoto_char);
@@ -5734,6 +5760,7 @@ it to be non-nil.  */);
   defsubr (&Stime_add);
   defsubr (&Stime_subtract);
   defsubr (&Stime_less_p);
+  defsubr (&Stime_equal_p);
   defsubr (&Sget_internal_run_time);
   defsubr (&Sformat_time_string);
   defsubr (&Sfloat_time);
--8<---------------cut here---------------end--------------->8---

> The Tramp code shouldn't care whether the constant is 0 or (0 0) or (0
> 0 0 0) [or -1 or (-1 65535) or (-1 65535 0 0)], because the code
> should compare time stamps via time-less-p (or float-time, if the
> timestamps are known to be small like 0 or -1, or maybe we should add
> time-equal?), not via 'equal'. The idea is that the Lisp timestamp
> format has changed in the past and is likely to change in the future
> and one should not assume any particular format if one wants the code
> to be portable.

Tramp would use only `invalid-time' and `time-equal-p', agnostic to
their implementations. Plus some compatibility code for older Emacsen.

Best regards, Michael.



  reply	other threads:[~2018-09-26  9:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180925021527.10418.61555@vcs0.savannah.gnu.org>
     [not found] ` <20180925021528.9A119204E8@vcs0.savannah.gnu.org>
2018-09-25 10:09   ` master d0c77a1: Remove some assumptions about timestamp format Michael Albinus
2018-09-26  1:09     ` Paul Eggert
2018-09-26  9:24       ` Michael Albinus [this message]
2018-09-26  9:39         ` Eli Zaretskii
2018-09-26  9:43           ` Michael Albinus
2018-09-27 20:46         ` Paul Eggert
2018-09-28  6:32           ` Eli Zaretskii
2018-09-28 10:26             ` Michael Albinus
2018-09-28 17:27               ` Paul Eggert
2018-09-29 13:35                 ` Michael Albinus
2018-09-28 14:45             ` Paul Eggert
2018-09-28 14:54               ` Michael Albinus
2018-09-28  1:50         ` Paul Eggert
2018-09-28 10:35           ` Michael Albinus
2018-09-28 17:39             ` Paul Eggert
2018-09-28 18:06               ` Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format) Stefan Monnier
2018-09-28 18:28                 ` Drew Adams
2018-09-28 19:12                   ` Paul Eggert
2018-09-28 19:26                     ` Naming predicates Stefan Monnier
2018-09-28 19:40                       ` Drew Adams
2018-09-28 19:41                     ` Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format) Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9ck6270.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).