error ("Invalid time specification");
}
+/* Check a return value compatible with that of decode_time_components. */
+static void
+check_time_validity (int validity)
+{
+ if (validity <= 0)
+ {
+ if (validity < 0)
+ time_overflow ();
+ else
+ invalid_time ();
+ }
+}
+
/* A substitute for mktime_z on platforms that lack it. It's not
thread-safe, but should be good enough for Emacs in typical use. */
#ifndef HAVE_TZALLOC
If *DRESULT is not null, store into *DRESULT the number of
seconds since the start of the POSIX Epoch.
- Return true if successful, false if the components are of the
- wrong type or represent a time out of range. */
-bool
+ Return 1 if successful, 0 if the components are of the
+ wrong type, and -1 if the time is out of range. */
+int
decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
Lisp_Object psec,
struct lisp_time *result, double *dresult)
EMACS_INT hi, lo, us, ps;
if (! (INTEGERP (high)
&& INTEGERP (usec) && INTEGERP (psec)))
- return false;
+ return 0;
if (! INTEGERP (low))
{
if (FLOATP (low))
{
double t = XFLOAT_DATA (low);
if (result && ! decode_float_time (t, result))
- return false;
+ return -1;
if (dresult)
*dresult = t;
- return true;
+ return 1;
}
else if (NILP (low))
{
}
if (dresult)
*dresult = now.tv_sec + now.tv_nsec / 1e9;
- return true;
+ return 1;
}
else
- return false;
+ return 0;
}
hi = XINT (high);
if (result)
{
if (! (MOST_NEGATIVE_FIXNUM <= hi && hi <= MOST_POSITIVE_FIXNUM))
- return false;
+ return -1;
result->hi = hi;
result->lo = lo;
result->us = us;
*dresult = (us * 1e6 + ps) / 1e12 + lo + dhi * (1 << LO_TIME_BITS);
}
- return true;
+ return 1;
}
struct timespec
Lisp_Object high, low, usec, psec;
struct lisp_time t;
int len = disassemble_lisp_time (specified_time, &high, &low, &usec, &psec);
- if (! (len && decode_time_components (high, low, usec, psec, &t, 0)))
- invalid_time ();
+ int val = len ? decode_time_components (high, low, usec, psec, &t, 0) : 0;
+ check_time_validity (val);
*plen = len;
return t;
}
{
Lisp_Object high, low, usec, psec;
struct lisp_time t;
- if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
- && decode_time_components (high, low, make_number (0),
- make_number (0), &t, 0)))
- invalid_time ();
- if (! ((TYPE_SIGNED (time_t) ? TIME_T_MIN >> LO_TIME_BITS <= t.hi : 0 <= t.hi)
- && t.hi <= TIME_T_MAX >> LO_TIME_BITS))
- time_overflow ();
+
+ int val = disassemble_lisp_time (specified_time, &high, &low, &usec, &psec);
+ if (val != 0)
+ {
+ val = decode_time_components (high, low, make_number (0),
+ make_number (0), &t, 0);
+ if (0 < val
+ && ! ((TYPE_SIGNED (time_t)
+ ? TIME_T_MIN >> LO_TIME_BITS <= t.hi
+ : 0 <= t.hi)
+ && t.hi <= TIME_T_MAX >> LO_TIME_BITS))
+ val = -1;
+ }
+ check_time_validity (val);
return (t.hi << LO_TIME_BITS) + t.lo;
}
static bool
decode_timer (Lisp_Object timer, struct timespec *result)
{
- Lisp_Object *vector;
+ Lisp_Object *vec;
if (! (VECTORP (timer) && ASIZE (timer) == 9))
return 0;
- vector = XVECTOR (timer)->contents;
- if (! NILP (vector[0]))
+ vec = XVECTOR (timer)->contents;
+ if (! NILP (vec[0]))
return 0;
- if (! INTEGERP (vector[2]))
+ if (! INTEGERP (vec[2]))
return false;
struct lisp_time t;
- if (! decode_time_components (vector[1], vector[2], vector[3], vector[8],
- &t, 0))
+ if (decode_time_components (vec[1], vec[2], vec[3], vec[8], &t, 0) <= 0)
return false;
*result = lisp_to_timespec (t);
return timespec_valid_p (*result);
/* defined in editfns.c */
extern Lisp_Object make_lisp_time (struct timespec);
-extern bool decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object,
- Lisp_Object, struct lisp_time *, double *);
+extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object,
+ Lisp_Object, struct lisp_time *, double *);
extern struct timespec lisp_to_timespec (struct lisp_time);
extern struct timespec lisp_time_argument (Lisp_Object);
#endif