[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 56aaaf9: Restore XFLOATINT but with restricted args
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 56aaaf9: Restore XFLOATINT but with restricted args |
Date: |
Thu, 2 Mar 2017 16:50:08 -0500 (EST) |
branch: master
commit 56aaaf9bbaf9772ea714b16aa7ed2a9693ac92e3
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Restore XFLOATINT but with restricted args
Turn instances of extract_float into XFLOAT_DATA when possible,
and to a resurrected XFLOATINT when the arg is a number.
The resurrected XFLOATINT is more like XFLOAT and XINT in
that is valid only if its arg is a number. This clarifies
the ways in which floats can be extracted at the C level.
* src/editfns.c (styled_format):
* src/floatfns.c (extract_float, Fexpt):
Use XFLOATINT rather than open-coding it.
* src/fns.c (internal_equal):
* src/image.c (imagemagick_load_image):
* src/xdisp.c (resize_mini_window):
Prefer XFLOAT_DATA to extract_float on values known to be floats.
* src/frame.c (x_set_screen_gamma):
* src/frame.h (NUMVAL):
* src/image.c (x_edge_detection, compute_image_size):
* src/lread.c (read_filtered_event):
* src/window.c (Fset_window_vscroll):
* src/xdisp.c (handle_single_display_spec, try_scrolling)
(redisplay_window, calc_pixel_width_or_height, x_produce_glyphs)
(on_hot_spot_p):
Prefer XFLOATINT to extract_float on values known to be numbers.
* src/lisp.h (XFLOATINT): Bring back this function, except
it now assumes its argument is a number.
---
src/editfns.c | 8 ++------
src/floatfns.c | 12 ++----------
src/fns.c | 6 ++----
src/frame.c | 4 ++--
src/frame.h | 2 +-
src/image.c | 10 +++++-----
src/lisp.h | 6 ++++++
src/lread.c | 2 +-
src/window.c | 4 ++--
src/xdisp.c | 26 +++++++++++++-------------
10 files changed, 36 insertions(+), 44 deletions(-)
diff --git a/src/editfns.c b/src/editfns.c
index e3c8548..8f85f99 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4312,12 +4312,8 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool
message)
char sprintf_buf[SPRINTF_BUFSIZE];
ptrdiff_t sprintf_bytes;
if (conversion == 'e' || conversion == 'f' || conversion == 'g')
- {
- double x = (INTEGERP (args[n])
- ? XINT (args[n])
- : XFLOAT_DATA (args[n]));
- sprintf_bytes = sprintf (sprintf_buf, convspec, prec, x);
- }
+ sprintf_bytes = sprintf (sprintf_buf, convspec, prec,
+ XFLOATINT (args[n]));
else if (conversion == 'c')
{
/* Don't use sprintf here, as it might mishandle prec. */
diff --git a/src/floatfns.c b/src/floatfns.c
index 737fb22..dda0369 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -67,10 +67,7 @@ double
extract_float (Lisp_Object num)
{
CHECK_NUMBER_OR_FLOAT (num);
-
- if (FLOATP (num))
- return XFLOAT_DATA (num);
- return (double) XINT (num);
+ return XFLOATINT (num);
}
/* Trig functions. */
@@ -207,8 +204,6 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
doc: /* Return the exponential ARG1 ** ARG2. */)
(Lisp_Object arg1, Lisp_Object arg2)
{
- double f1, f2, f3;
-
CHECK_NUMBER_OR_FLOAT (arg1);
CHECK_NUMBER_OR_FLOAT (arg2);
if (INTEGERP (arg1) /* common lisp spec */
@@ -232,10 +227,7 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
XSETINT (val, acc);
return val;
}
- f1 = FLOATP (arg1) ? XFLOAT_DATA (arg1) : XINT (arg1);
- f2 = FLOATP (arg2) ? XFLOAT_DATA (arg2) : XINT (arg2);
- f3 = pow (f1, f2);
- return make_float (f3);
+ return make_float (pow (XFLOATINT (arg1), XFLOATINT (arg2)));
}
DEFUN ("log", Flog, Slog, 1, 2, 0,
diff --git a/src/fns.c b/src/fns.c
index b4f416f..1065355 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2158,10 +2158,8 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, int
depth, bool props,
{
case Lisp_Float:
{
- double d1, d2;
-
- d1 = extract_float (o1);
- d2 = extract_float (o2);
+ double d1 = XFLOAT_DATA (o1);
+ double d2 = XFLOAT_DATA (o2);
/* If d is a NaN, then d != d. Two NaNs should be `equal' even
though they are not =. */
return d1 == d2 || (d1 != d1 && d2 != d2);
diff --git a/src/frame.c b/src/frame.c
index daf4245..5e1e2f1 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3530,9 +3530,9 @@ x_set_screen_gamma (struct frame *f, Lisp_Object
new_value, Lisp_Object old_valu
if (NILP (new_value))
f->gamma = 0;
- else if (NUMBERP (new_value) && extract_float (new_value) > 0)
+ else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
/* The value 0.4545 is the normal viewing gamma. */
- f->gamma = 1.0 / (0.4545 * extract_float (new_value));
+ f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
else
signal_error ("Invalid screen-gamma", new_value);
diff --git a/src/frame.h b/src/frame.h
index 6f85f85..5f18901 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -624,7 +624,7 @@ fset_desired_tool_bar_string (struct frame *f, Lisp_Object
val)
INLINE double
NUMVAL (Lisp_Object x)
{
- return NUMBERP (x) ? extract_float (x) : -1;
+ return NUMBERP (x) ? XFLOATINT (x) : -1;
}
INLINE double
diff --git a/src/image.c b/src/image.c
index 3711dd1..3ebf469 100644
--- a/src/image.c
+++ b/src/image.c
@@ -4915,19 +4915,19 @@ x_edge_detection (struct frame *f, struct image *img,
Lisp_Object matrix,
for (i = 0;
i < 9 && CONSP (matrix) && NUMBERP (XCAR (matrix));
++i, matrix = XCDR (matrix))
- trans[i] = extract_float (XCAR (matrix));
+ trans[i] = XFLOATINT (XCAR (matrix));
}
else if (VECTORP (matrix) && ASIZE (matrix) >= 9)
{
for (i = 0; i < 9 && NUMBERP (AREF (matrix, i)); ++i)
- trans[i] = extract_float (AREF (matrix, i));
+ trans[i] = XFLOATINT (AREF (matrix, i));
}
if (NILP (color_adjust))
color_adjust = make_number (0xffff / 2);
if (i == 9 && NUMBERP (color_adjust))
- x_detect_edges (f, img, trans, extract_float (color_adjust));
+ x_detect_edges (f, img, trans, XFLOATINT (color_adjust));
}
@@ -8077,7 +8077,7 @@ compute_image_size (size_t width, size_t height,
value = image_spec_value (spec, QCscale, NULL);
if (NUMBERP (value))
- scale = extract_float (value);
+ scale = XFLOATINT (value);
/* If width and/or height is set in the display spec assume we want
to scale to those values. If either h or w is unspecified, the
@@ -8684,7 +8684,7 @@ imagemagick_load_image (struct frame *f, struct image
*img,
value = image_spec_value (img->spec, QCrotation, NULL);
if (FLOATP (value))
{
- rotation = extract_float (value);
+ rotation = XFLOAT_DATA (value);
status = MagickRotateImage (image_wand, bg_wand, rotation);
if (status == MagickFalse)
{
diff --git a/src/lisp.h b/src/lisp.h
index a910411..220188c 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2803,6 +2803,12 @@ CHECK_NATNUM (Lisp_Object x)
CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); \
} while (false)
+INLINE double
+XFLOATINT (Lisp_Object n)
+{
+ return FLOATP (n) ? XFLOAT_DATA (n) : XINT (n);
+}
+
INLINE void
CHECK_NUMBER_OR_FLOAT (Lisp_Object x)
{
diff --git a/src/lread.c b/src/lread.c
index 1b154b7..5c6a7f9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -601,7 +601,7 @@ read_filtered_event (bool no_switch_frame, bool
ascii_required,
/* Compute timeout. */
if (NUMBERP (seconds))
{
- double duration = extract_float (seconds);
+ double duration = XFLOATINT (seconds);
struct timespec wait_time = dtotimespec (duration);
end_time = timespec_add (current_timespec (), wait_time);
}
diff --git a/src/window.c b/src/window.c
index 3e2eb16..9569044 100644
--- a/src/window.c
+++ b/src/window.c
@@ -7129,8 +7129,8 @@ If PIXELS-P is non-nil, the return value is VSCROLL. */)
int old_dy = w->vscroll;
w->vscroll = - (NILP (pixels_p)
- ? FRAME_LINE_HEIGHT (f) * extract_float (vscroll)
- : extract_float (vscroll));
+ ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
+ : XFLOATINT (vscroll));
w->vscroll = min (w->vscroll, 0);
if (w->vscroll != old_dy)
diff --git a/src/xdisp.c b/src/xdisp.c
index 12f42d1..82c4c77 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -4870,7 +4870,7 @@ handle_single_display_spec (struct it *it, Lisp_Object
spec, Lisp_Object object,
height = safe_call1 (it->font_height,
face->lface[LFACE_HEIGHT_INDEX]);
if (NUMBERP (height))
- new_height = extract_float (height);
+ new_height = XFLOATINT (height);
}
else if (NUMBERP (it->font_height))
{
@@ -4879,7 +4879,7 @@ handle_single_display_spec (struct it *it, Lisp_Object
spec, Lisp_Object object,
f = FACE_FROM_ID (it->f,
lookup_basic_face (it->f, DEFAULT_FACE_ID));
- new_height = (extract_float (it->font_height)
+ new_height = (XFLOATINT (it->font_height)
* XINT (f->lface[LFACE_HEIGHT_INDEX]));
}
else
@@ -4894,7 +4894,7 @@ handle_single_display_spec (struct it *it, Lisp_Object
spec, Lisp_Object object,
unbind_to (count, Qnil);
if (NUMBERP (value))
- new_height = extract_float (value);
+ new_height = XFLOATINT (value);
}
if (new_height > 0)
@@ -4916,7 +4916,7 @@ handle_single_display_spec (struct it *it, Lisp_Object
spec, Lisp_Object object,
return 0;
value = XCAR (XCDR (spec));
- if (NUMBERP (value) && extract_float (value) > 0)
+ if (NUMBERP (value) && XFLOATINT (value) > 0)
it->space_width = value;
}
@@ -4968,7 +4968,7 @@ handle_single_display_spec (struct it *it, Lisp_Object
spec, Lisp_Object object,
if (NUMBERP (value))
{
struct face *face = FACE_FROM_ID (it->f, it->face_id);
- it->voffset = - (extract_float (value)
+ it->voffset = - (XFLOATINT (value)
* (normal_char_height (face->font, -1)));
}
#endif /* HAVE_WINDOW_SYSTEM */
@@ -11058,7 +11058,7 @@ resize_mini_window (struct window *w, bool exact_p)
/* Compute the max. number of lines specified by the user. */
if (FLOATP (Vmax_mini_window_height))
- max_height = extract_float (Vmax_mini_window_height) * total_height;
+ max_height = XFLOAT_DATA (Vmax_mini_window_height) * total_height;
else if (INTEGERP (Vmax_mini_window_height))
max_height = XINT (Vmax_mini_window_height) * unit;
else
@@ -15501,7 +15501,7 @@ try_scrolling (Lisp_Object window, bool just_this_one_p,
height = WINDOW_BOX_TEXT_HEIGHT (w);
if (NUMBERP (aggressive))
{
- double float_amount = extract_float (aggressive) * height;
+ double float_amount = XFLOATINT (aggressive) * height;
int aggressive_scroll = float_amount;
if (aggressive_scroll == 0 && float_amount > 0)
aggressive_scroll = 1;
@@ -15617,7 +15617,7 @@ try_scrolling (Lisp_Object window, bool just_this_one_p,
height = WINDOW_BOX_TEXT_HEIGHT (w);
if (NUMBERP (aggressive))
{
- double float_amount = extract_float (aggressive) * height;
+ double float_amount = XFLOATINT (aggressive) * height;
int aggressive_scroll = float_amount;
if (aggressive_scroll == 0 && float_amount > 0)
aggressive_scroll = 1;
@@ -16968,7 +16968,7 @@ redisplay_window (Lisp_Object window, bool
just_this_one_p)
scroll-*-aggressively. */
if (!scroll_conservatively && NUMBERP (aggressive))
{
- double float_amount = extract_float (aggressive);
+ double float_amount = XFLOATINT (aggressive);
pt_offset = float_amount * WINDOW_BOX_TEXT_HEIGHT (w);
if (pt_offset == 0 && float_amount > 0)
@@ -24557,7 +24557,7 @@ calc_pixel_width_or_height (double *res, struct it *it,
Lisp_Object prop,
int base_unit = (width_p
? FRAME_COLUMN_WIDTH (it->f)
: FRAME_LINE_HEIGHT (it->f));
- return OK_PIXELS (extract_float (prop) * base_unit);
+ return OK_PIXELS (XFLOATINT (prop) * base_unit);
}
if (CONSP (prop))
@@ -24612,7 +24612,7 @@ calc_pixel_width_or_height (double *res, struct it *it,
Lisp_Object prop,
if (NUMBERP (car))
{
double fact;
- pixels = extract_float (car);
+ pixels = XFLOATINT (car);
if (NILP (cdr))
return OK_PIXELS (pixels);
if (calc_pixel_width_or_height (&fact, it, cdr,
@@ -27225,7 +27225,7 @@ x_produce_glyphs (struct it *it)
bool stretched_p
= it->char_to_display == ' ' && !NILP (it->space_width);
if (stretched_p)
- it->pixel_width *= extract_float (it->space_width);
+ it->pixel_width *= XFLOATINT (it->space_width);
/* If face has a box, add the box thickness to the character
height. If character has a box line to the left and/or
@@ -29703,7 +29703,7 @@ on_hot_spot_p (Lisp_Object hot_spot, int x, int y)
&& (lx0 = XCAR (XCAR (circ)), INTEGERP (lx0))
&& (ly0 = XCDR (XCAR (circ)), INTEGERP (ly0)))
{
- double r = extract_float (lr);
+ double r = XFLOATINT (lr);
double dx = XINT (lx0) - x;
double dy = XINT (ly0) - y;
return (dx * dx + dy * dy <= r * r);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 56aaaf9: Restore XFLOATINT but with restricted args,
Paul Eggert <=