* src/lisp.h (integer_to_intmax, integer_to_uintmax): New functions.
* src/data.c (cons_to_unsigned, cons_to_signed)
(arith_driver):
* src/dbusbind.c (xd_extract_signed, xd_extract_unsigned):
* src/dispnew.c (sit_for):
* src/editfns.c (styled_format):
* src/emacs-module.c (module_extract_integer):
* src/fileio.c (file_offset):
* src/font.c (font_unparse_xlfd, Fopen_font):
* src/xdisp.c (calc_line_height_property):
* src/process.c (handle_child_signal):
else
{
Lisp_Object hi = CONSP (c) ? XCAR (c) : c;
-
- if (FIXNUMP (hi))
- {
- val = XFIXNUM (hi);
- valid = 0 <= val;
- }
- else
- {
- val = bignum_to_uintmax (hi);
- valid = val != 0;
- }
+ valid = integer_to_uintmax (hi, &val);
if (valid && CONSP (c))
{
else
{
Lisp_Object hi = CONSP (c) ? XCAR (c) : c;
-
- if (FIXNUMP (hi))
- {
- val = XFIXNUM (hi);
- valid = true;
- }
- else if (BIGNUMP (hi))
- {
- val = bignum_to_intmax (hi);
- valid = val != 0;
- }
+ valid = integer_to_intmax (hi, &val);
if (valid && CONSP (c))
{
/* Set NEXT to the next value if it fits, else exit the loop. */
intmax_t next;
- if (FIXNUMP (val))
- next = XFIXNUM (val);
- else if (FLOATP (val))
+ if (! (INTEGERP (val) && integer_to_intmax (val, &next)))
break;
- else
- {
- next = bignum_to_intmax (val);
- if (next == 0)
- break;
- }
/* Set ACCUM to the next operation's result if it fits,
else exit the loop. */
xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi)
{
CHECK_NUMBER (x);
- if (FIXNUMP (x))
+ if (INTEGERP (x))
{
- if (lo <= XFIXNUM (x) && XFIXNUM (x) <= hi)
- return XFIXNUM (x);
+ intmax_t i;
+ if (integer_to_intmax (x, &i) && lo <= i && i <= hi)
+ return i;
}
- else if (FLOATP (x))
+ else
{
double d = XFLOAT_DATA (x);
if (lo <= d && d < 1.0 + hi)
return n;
}
}
- else if (! (MOST_NEGATIVE_FIXNUM <= lo && hi <= MOST_POSITIVE_FIXNUM))
- {
- intmax_t i = bignum_to_intmax (x);
- if (i != 0 && lo <= i && i <= hi)
- return i;
- }
if (xd_in_read_queued_messages)
Fthrow (Qdbus_error, Qnil);
xd_extract_unsigned (Lisp_Object x, uintmax_t hi)
{
CHECK_NUMBER (x);
- if (FIXNUMP (x))
+ if (INTEGERP (x))
{
- if (0 <= XFIXNUM (x) && XFIXNUM (x) <= hi)
- return XFIXNUM (x);
+ uintmax_t i;
+ if (integer_to_uintmax (x, &i) && i <= hi)
+ return i;
}
- else if (FLOATP (x))
+ else
{
double d = XFLOAT_DATA (x);
if (0 <= d && d < 1.0 + hi)
return n;
}
}
- else if (! (hi <= MOST_POSITIVE_FIXNUM))
- {
- uintmax_t i = bignum_to_uintmax (x);
- if (i != 0 && i <= hi)
- return i;
- }
if (xd_in_read_queued_messages)
Fthrow (Qdbus_error, Qnil);
if (display_option > 1)
redisplay_preserve_echo_area (2);
- if (FIXNUMP (timeout))
+ if (INTEGERP (timeout))
{
- sec = XFIXNUM (timeout);
- if (sec <= 0)
- return Qt;
- nsec = 0;
- }
- else if (BIGNUMP (timeout))
- {
- if (NILP (Fnatnump (timeout)))
- return Qt;
- sec = bignum_to_intmax (timeout);
- if (sec == 0)
- sec = WAIT_READING_MAX;
+ if (integer_to_intmax (timeout, &sec))
+ {
+ if (sec <= 0)
+ return Qt;
+ sec = min (sec, WAIT_READING_MAX);
+ }
+ else
+ {
+ if (NILP (Fnatnump (timeout)))
+ return Qt;
+ sec = WAIT_READING_MAX;
+ }
nsec = 0;
}
else if (FLOATP (timeout))
}
else
{
- if (FIXNUMP (arg))
- ldarg = XFIXNUM (arg);
- else
+ if (INTEGERP (arg))
{
- intmax_t iarg = bignum_to_intmax (arg);
- if (iarg != 0)
+ intmax_t iarg;
+ uintmax_t uarg;
+ if (integer_to_intmax (arg, &iarg))
ldarg = iarg;
+ else if (integer_to_uintmax (arg, &uarg))
+ ldarg = uarg;
else
- {
- uintmax_t uarg = bignum_to_uintmax (arg);
- if (uarg != 0)
- ldarg = uarg;
- else
- format_bignum_as_double = true;
- }
+ format_bignum_as_double = true;
}
if (!format_bignum_as_double)
{
MODULE_FUNCTION_BEGIN (0);
Lisp_Object l = value_to_lisp (n);
CHECK_INTEGER (l);
- if (BIGNUMP (l))
- {
- intmax_t i = bignum_to_intmax (l);
- if (i == 0)
- xsignal1 (Qoverflow_error, l);
- return i;
- }
- return XFIXNUM (l);
+ intmax_t i;
+ if (! integer_to_intmax (l, &i))
+ xsignal1 (Qoverflow_error, l);
+ return i;
}
static emacs_value
static off_t
file_offset (Lisp_Object val)
{
- if (RANGED_FIXNUMP (0, val, TYPE_MAXIMUM (off_t)))
- return XFIXNUM (val);
-
- if (BIGNUMP (val))
+ if (INTEGERP (val))
{
- intmax_t v = bignum_to_intmax (val);
- if (0 < v && v <= TYPE_MAXIMUM (off_t))
+ intmax_t v;
+ if (integer_to_intmax (val, &v) && 0 <= v && v <= TYPE_MAXIMUM (off_t))
return v;
}
-
- if (FLOATP (val))
+ else if (FLOATP (val))
{
double v = XFLOAT_DATA (val);
if (0 <= v && v < 1.0 + TYPE_MAXIMUM (off_t))
1 + DBL_MAX_10_EXP + 1)];
if (INTEGERP (val))
{
- intmax_t v = FIXNUMP (val) ? XFIXNUM (val) : bignum_to_intmax (val);
- if (! (0 < v && v <= TYPE_MAXIMUM (uprintmax_t)))
+ intmax_t v;
+ if (! (integer_to_intmax (val, &v)
+ && 0 < v && v <= TYPE_MAXIMUM (uprintmax_t)))
v = pixel_size;
if (v > 0)
{
else
{
CHECK_NUMBER (size);
- if (BIGNUMP (size))
- {
- isize = bignum_to_intmax (size);
- if (isize == 0)
- args_out_of_range (font_entity, size);
- }
- else
- isize = (FLOATP (size)
- ? POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f))
- : XFIXNUM (size));
+ if (FLOATP (size))
+ isize = POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f));
+ else if (! integer_to_intmax (size, &isize))
+ args_out_of_range (font_entity, size);
if (! (INT_MIN <= isize && isize <= INT_MAX))
args_out_of_range (font_entity, size);
if (isize == 0)
extern Lisp_Object make_bignum_str (char const *, int);
extern Lisp_Object double_to_bignum (double);
+/* Converthe integer NUM to *N. Return true if successful, false
+ (possibly setting *N) otherwise. */
+INLINE bool
+integer_to_intmax (Lisp_Object num, intmax_t *n)
+{
+ if (FIXNUMP (num))
+ {
+ *n = XFIXNUM (num);
+ return true;
+ }
+ else
+ {
+ intmax_t i = bignum_to_intmax (num);
+ *n = i;
+ return i != 0;
+ }
+}
+INLINE bool
+integer_to_uintmax (Lisp_Object num, uintmax_t *n)
+{
+ if (FIXNUMP (num))
+ {
+ *n = XFIXNUM (num);
+ return 0 <= XFIXNUM (num);
+ }
+ else
+ {
+ uintmax_t i = bignum_to_uintmax (num);
+ *n = i;
+ return i != 0;
+ }
+}
+
/* Defined in data.c. */
extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object);
extern void notify_variable_watchers (Lisp_Object, Lisp_Object,
xpid = XCAR (head);
if (all_pids_are_fixnums ? FIXNUMP (xpid) : INTEGERP (xpid))
{
- pid_t deleted_pid = (FIXNUMP (xpid) ? XFIXNUM (xpid)
- : bignum_to_intmax (xpid));
+ intmax_t deleted_pid;
+ bool ok = integer_to_intmax (xpid, &deleted_pid);
+ eassert (ok);
if (child_status_changed (deleted_pid, 0, 0))
{
if (STRINGP (XCDR (head)))
/* FIXME: Check for overflow in multiplication or conversion. */
if (FLOATP (val))
height = (int)(XFLOAT_DATA (val) * height);
- else if (FIXNUMP (val))
- height *= XFIXNUM (val);
else
- height *= bignum_to_intmax (val);
+ {
+ intmax_t v;
+ if (integer_to_intmax (val, &v))
+ height *= v;
+ }
return make_fixnum (height);
}