aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-03-02 13:48:47 -0800
committerPaul Eggert2017-03-02 13:50:03 -0800
commit56aaaf9bbaf9772ea714b16aa7ed2a9693ac92e3 (patch)
tree00d5a4ce84331590cbb4b11b532f054585922219
parentdacafa8c30cdae92f934512664fd2d322d91432b (diff)
downloademacs-56aaaf9bbaf9772ea714b16aa7ed2a9693ac92e3.tar.gz
emacs-56aaaf9bbaf9772ea714b16aa7ed2a9693ac92e3.zip
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.
-rw-r--r--src/editfns.c8
-rw-r--r--src/floatfns.c12
-rw-r--r--src/fns.c6
-rw-r--r--src/frame.c4
-rw-r--r--src/frame.h2
-rw-r--r--src/image.c10
-rw-r--r--src/lisp.h6
-rw-r--r--src/lread.c2
-rw-r--r--src/window.c4
-rw-r--r--src/xdisp.c26
10 files changed, 36 insertions, 44 deletions
diff --git a/src/editfns.c b/src/editfns.c
index e3c8548b5a4..8f85f99b94c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4312,12 +4312,8 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
4312 char sprintf_buf[SPRINTF_BUFSIZE]; 4312 char sprintf_buf[SPRINTF_BUFSIZE];
4313 ptrdiff_t sprintf_bytes; 4313 ptrdiff_t sprintf_bytes;
4314 if (conversion == 'e' || conversion == 'f' || conversion == 'g') 4314 if (conversion == 'e' || conversion == 'f' || conversion == 'g')
4315 { 4315 sprintf_bytes = sprintf (sprintf_buf, convspec, prec,
4316 double x = (INTEGERP (args[n]) 4316 XFLOATINT (args[n]));
4317 ? XINT (args[n])
4318 : XFLOAT_DATA (args[n]));
4319 sprintf_bytes = sprintf (sprintf_buf, convspec, prec, x);
4320 }
4321 else if (conversion == 'c') 4317 else if (conversion == 'c')
4322 { 4318 {
4323 /* Don't use sprintf here, as it might mishandle prec. */ 4319 /* Don't use sprintf here, as it might mishandle prec. */
diff --git a/src/floatfns.c b/src/floatfns.c
index 737fb22091e..dda03698093 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -67,10 +67,7 @@ double
67extract_float (Lisp_Object num) 67extract_float (Lisp_Object num)
68{ 68{
69 CHECK_NUMBER_OR_FLOAT (num); 69 CHECK_NUMBER_OR_FLOAT (num);
70 70 return XFLOATINT (num);
71 if (FLOATP (num))
72 return XFLOAT_DATA (num);
73 return (double) XINT (num);
74} 71}
75 72
76/* Trig functions. */ 73/* Trig functions. */
@@ -207,8 +204,6 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
207 doc: /* Return the exponential ARG1 ** ARG2. */) 204 doc: /* Return the exponential ARG1 ** ARG2. */)
208 (Lisp_Object arg1, Lisp_Object arg2) 205 (Lisp_Object arg1, Lisp_Object arg2)
209{ 206{
210 double f1, f2, f3;
211
212 CHECK_NUMBER_OR_FLOAT (arg1); 207 CHECK_NUMBER_OR_FLOAT (arg1);
213 CHECK_NUMBER_OR_FLOAT (arg2); 208 CHECK_NUMBER_OR_FLOAT (arg2);
214 if (INTEGERP (arg1) /* common lisp spec */ 209 if (INTEGERP (arg1) /* common lisp spec */
@@ -232,10 +227,7 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
232 XSETINT (val, acc); 227 XSETINT (val, acc);
233 return val; 228 return val;
234 } 229 }
235 f1 = FLOATP (arg1) ? XFLOAT_DATA (arg1) : XINT (arg1); 230 return make_float (pow (XFLOATINT (arg1), XFLOATINT (arg2)));
236 f2 = FLOATP (arg2) ? XFLOAT_DATA (arg2) : XINT (arg2);
237 f3 = pow (f1, f2);
238 return make_float (f3);
239} 231}
240 232
241DEFUN ("log", Flog, Slog, 1, 2, 0, 233DEFUN ("log", Flog, Slog, 1, 2, 0,
diff --git a/src/fns.c b/src/fns.c
index b4f416f4f52..10653558eb5 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,
2158 { 2158 {
2159 case Lisp_Float: 2159 case Lisp_Float:
2160 { 2160 {
2161 double d1, d2; 2161 double d1 = XFLOAT_DATA (o1);
2162 2162 double d2 = XFLOAT_DATA (o2);
2163 d1 = extract_float (o1);
2164 d2 = extract_float (o2);
2165 /* If d is a NaN, then d != d. Two NaNs should be `equal' even 2163 /* If d is a NaN, then d != d. Two NaNs should be `equal' even
2166 though they are not =. */ 2164 though they are not =. */
2167 return d1 == d2 || (d1 != d1 && d2 != d2); 2165 return d1 == d2 || (d1 != d1 && d2 != d2);
diff --git a/src/frame.c b/src/frame.c
index daf424567df..5e1e2f19906 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
3530 3530
3531 if (NILP (new_value)) 3531 if (NILP (new_value))
3532 f->gamma = 0; 3532 f->gamma = 0;
3533 else if (NUMBERP (new_value) && extract_float (new_value) > 0) 3533 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3534 /* The value 0.4545 is the normal viewing gamma. */ 3534 /* The value 0.4545 is the normal viewing gamma. */
3535 f->gamma = 1.0 / (0.4545 * extract_float (new_value)); 3535 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3536 else 3536 else
3537 signal_error ("Invalid screen-gamma", new_value); 3537 signal_error ("Invalid screen-gamma", new_value);
3538 3538
diff --git a/src/frame.h b/src/frame.h
index 6f85f85e795..5f18901a17c 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -624,7 +624,7 @@ fset_desired_tool_bar_string (struct frame *f, Lisp_Object val)
624INLINE double 624INLINE double
625NUMVAL (Lisp_Object x) 625NUMVAL (Lisp_Object x)
626{ 626{
627 return NUMBERP (x) ? extract_float (x) : -1; 627 return NUMBERP (x) ? XFLOATINT (x) : -1;
628} 628}
629 629
630INLINE double 630INLINE double
diff --git a/src/image.c b/src/image.c
index 3711dd18d69..3ebf469e8b3 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,
4915 for (i = 0; 4915 for (i = 0;
4916 i < 9 && CONSP (matrix) && NUMBERP (XCAR (matrix)); 4916 i < 9 && CONSP (matrix) && NUMBERP (XCAR (matrix));
4917 ++i, matrix = XCDR (matrix)) 4917 ++i, matrix = XCDR (matrix))
4918 trans[i] = extract_float (XCAR (matrix)); 4918 trans[i] = XFLOATINT (XCAR (matrix));
4919 } 4919 }
4920 else if (VECTORP (matrix) && ASIZE (matrix) >= 9) 4920 else if (VECTORP (matrix) && ASIZE (matrix) >= 9)
4921 { 4921 {
4922 for (i = 0; i < 9 && NUMBERP (AREF (matrix, i)); ++i) 4922 for (i = 0; i < 9 && NUMBERP (AREF (matrix, i)); ++i)
4923 trans[i] = extract_float (AREF (matrix, i)); 4923 trans[i] = XFLOATINT (AREF (matrix, i));
4924 } 4924 }
4925 4925
4926 if (NILP (color_adjust)) 4926 if (NILP (color_adjust))
4927 color_adjust = make_number (0xffff / 2); 4927 color_adjust = make_number (0xffff / 2);
4928 4928
4929 if (i == 9 && NUMBERP (color_adjust)) 4929 if (i == 9 && NUMBERP (color_adjust))
4930 x_detect_edges (f, img, trans, extract_float (color_adjust)); 4930 x_detect_edges (f, img, trans, XFLOATINT (color_adjust));
4931} 4931}
4932 4932
4933 4933
@@ -8077,7 +8077,7 @@ compute_image_size (size_t width, size_t height,
8077 8077
8078 value = image_spec_value (spec, QCscale, NULL); 8078 value = image_spec_value (spec, QCscale, NULL);
8079 if (NUMBERP (value)) 8079 if (NUMBERP (value))
8080 scale = extract_float (value); 8080 scale = XFLOATINT (value);
8081 8081
8082 /* If width and/or height is set in the display spec assume we want 8082 /* If width and/or height is set in the display spec assume we want
8083 to scale to those values. If either h or w is unspecified, the 8083 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,
8684 value = image_spec_value (img->spec, QCrotation, NULL); 8684 value = image_spec_value (img->spec, QCrotation, NULL);
8685 if (FLOATP (value)) 8685 if (FLOATP (value))
8686 { 8686 {
8687 rotation = extract_float (value); 8687 rotation = XFLOAT_DATA (value);
8688 status = MagickRotateImage (image_wand, bg_wand, rotation); 8688 status = MagickRotateImage (image_wand, bg_wand, rotation);
8689 if (status == MagickFalse) 8689 if (status == MagickFalse)
8690 { 8690 {
diff --git a/src/lisp.h b/src/lisp.h
index a9104110469..220188cdb87 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2803,6 +2803,12 @@ CHECK_NATNUM (Lisp_Object x)
2803 CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); \ 2803 CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); \
2804 } while (false) 2804 } while (false)
2805 2805
2806INLINE double
2807XFLOATINT (Lisp_Object n)
2808{
2809 return FLOATP (n) ? XFLOAT_DATA (n) : XINT (n);
2810}
2811
2806INLINE void 2812INLINE void
2807CHECK_NUMBER_OR_FLOAT (Lisp_Object x) 2813CHECK_NUMBER_OR_FLOAT (Lisp_Object x)
2808{ 2814{
diff --git a/src/lread.c b/src/lread.c
index 1b154b7326e..5c6a7f97f52 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -601,7 +601,7 @@ read_filtered_event (bool no_switch_frame, bool ascii_required,
601 /* Compute timeout. */ 601 /* Compute timeout. */
602 if (NUMBERP (seconds)) 602 if (NUMBERP (seconds))
603 { 603 {
604 double duration = extract_float (seconds); 604 double duration = XFLOATINT (seconds);
605 struct timespec wait_time = dtotimespec (duration); 605 struct timespec wait_time = dtotimespec (duration);
606 end_time = timespec_add (current_timespec (), wait_time); 606 end_time = timespec_add (current_timespec (), wait_time);
607 } 607 }
diff --git a/src/window.c b/src/window.c
index 3e2eb1664c8..95690443f8e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -7129,8 +7129,8 @@ If PIXELS-P is non-nil, the return value is VSCROLL. */)
7129 int old_dy = w->vscroll; 7129 int old_dy = w->vscroll;
7130 7130
7131 w->vscroll = - (NILP (pixels_p) 7131 w->vscroll = - (NILP (pixels_p)
7132 ? FRAME_LINE_HEIGHT (f) * extract_float (vscroll) 7132 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
7133 : extract_float (vscroll)); 7133 : XFLOATINT (vscroll));
7134 w->vscroll = min (w->vscroll, 0); 7134 w->vscroll = min (w->vscroll, 0);
7135 7135
7136 if (w->vscroll != old_dy) 7136 if (w->vscroll != old_dy)
diff --git a/src/xdisp.c b/src/xdisp.c
index 12f42d14cec..82c4c775c16 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,
4870 height = safe_call1 (it->font_height, 4870 height = safe_call1 (it->font_height,
4871 face->lface[LFACE_HEIGHT_INDEX]); 4871 face->lface[LFACE_HEIGHT_INDEX]);
4872 if (NUMBERP (height)) 4872 if (NUMBERP (height))
4873 new_height = extract_float (height); 4873 new_height = XFLOATINT (height);
4874 } 4874 }
4875 else if (NUMBERP (it->font_height)) 4875 else if (NUMBERP (it->font_height))
4876 { 4876 {
@@ -4879,7 +4879,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4879 4879
4880 f = FACE_FROM_ID (it->f, 4880 f = FACE_FROM_ID (it->f,
4881 lookup_basic_face (it->f, DEFAULT_FACE_ID)); 4881 lookup_basic_face (it->f, DEFAULT_FACE_ID));
4882 new_height = (extract_float (it->font_height) 4882 new_height = (XFLOATINT (it->font_height)
4883 * XINT (f->lface[LFACE_HEIGHT_INDEX])); 4883 * XINT (f->lface[LFACE_HEIGHT_INDEX]));
4884 } 4884 }
4885 else 4885 else
@@ -4894,7 +4894,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4894 unbind_to (count, Qnil); 4894 unbind_to (count, Qnil);
4895 4895
4896 if (NUMBERP (value)) 4896 if (NUMBERP (value))
4897 new_height = extract_float (value); 4897 new_height = XFLOATINT (value);
4898 } 4898 }
4899 4899
4900 if (new_height > 0) 4900 if (new_height > 0)
@@ -4916,7 +4916,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4916 return 0; 4916 return 0;
4917 4917
4918 value = XCAR (XCDR (spec)); 4918 value = XCAR (XCDR (spec));
4919 if (NUMBERP (value) && extract_float (value) > 0) 4919 if (NUMBERP (value) && XFLOATINT (value) > 0)
4920 it->space_width = value; 4920 it->space_width = value;
4921 } 4921 }
4922 4922
@@ -4968,7 +4968,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4968 if (NUMBERP (value)) 4968 if (NUMBERP (value))
4969 { 4969 {
4970 struct face *face = FACE_FROM_ID (it->f, it->face_id); 4970 struct face *face = FACE_FROM_ID (it->f, it->face_id);
4971 it->voffset = - (extract_float (value) 4971 it->voffset = - (XFLOATINT (value)
4972 * (normal_char_height (face->font, -1))); 4972 * (normal_char_height (face->font, -1)));
4973 } 4973 }
4974#endif /* HAVE_WINDOW_SYSTEM */ 4974#endif /* HAVE_WINDOW_SYSTEM */
@@ -11058,7 +11058,7 @@ resize_mini_window (struct window *w, bool exact_p)
11058 11058
11059 /* Compute the max. number of lines specified by the user. */ 11059 /* Compute the max. number of lines specified by the user. */
11060 if (FLOATP (Vmax_mini_window_height)) 11060 if (FLOATP (Vmax_mini_window_height))
11061 max_height = extract_float (Vmax_mini_window_height) * total_height; 11061 max_height = XFLOAT_DATA (Vmax_mini_window_height) * total_height;
11062 else if (INTEGERP (Vmax_mini_window_height)) 11062 else if (INTEGERP (Vmax_mini_window_height))
11063 max_height = XINT (Vmax_mini_window_height) * unit; 11063 max_height = XINT (Vmax_mini_window_height) * unit;
11064 else 11064 else
@@ -15501,7 +15501,7 @@ try_scrolling (Lisp_Object window, bool just_this_one_p,
15501 height = WINDOW_BOX_TEXT_HEIGHT (w); 15501 height = WINDOW_BOX_TEXT_HEIGHT (w);
15502 if (NUMBERP (aggressive)) 15502 if (NUMBERP (aggressive))
15503 { 15503 {
15504 double float_amount = extract_float (aggressive) * height; 15504 double float_amount = XFLOATINT (aggressive) * height;
15505 int aggressive_scroll = float_amount; 15505 int aggressive_scroll = float_amount;
15506 if (aggressive_scroll == 0 && float_amount > 0) 15506 if (aggressive_scroll == 0 && float_amount > 0)
15507 aggressive_scroll = 1; 15507 aggressive_scroll = 1;
@@ -15617,7 +15617,7 @@ try_scrolling (Lisp_Object window, bool just_this_one_p,
15617 height = WINDOW_BOX_TEXT_HEIGHT (w); 15617 height = WINDOW_BOX_TEXT_HEIGHT (w);
15618 if (NUMBERP (aggressive)) 15618 if (NUMBERP (aggressive))
15619 { 15619 {
15620 double float_amount = extract_float (aggressive) * height; 15620 double float_amount = XFLOATINT (aggressive) * height;
15621 int aggressive_scroll = float_amount; 15621 int aggressive_scroll = float_amount;
15622 if (aggressive_scroll == 0 && float_amount > 0) 15622 if (aggressive_scroll == 0 && float_amount > 0)
15623 aggressive_scroll = 1; 15623 aggressive_scroll = 1;
@@ -16968,7 +16968,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
16968 scroll-*-aggressively. */ 16968 scroll-*-aggressively. */
16969 if (!scroll_conservatively && NUMBERP (aggressive)) 16969 if (!scroll_conservatively && NUMBERP (aggressive))
16970 { 16970 {
16971 double float_amount = extract_float (aggressive); 16971 double float_amount = XFLOATINT (aggressive);
16972 16972
16973 pt_offset = float_amount * WINDOW_BOX_TEXT_HEIGHT (w); 16973 pt_offset = float_amount * WINDOW_BOX_TEXT_HEIGHT (w);
16974 if (pt_offset == 0 && float_amount > 0) 16974 if (pt_offset == 0 && float_amount > 0)
@@ -24557,7 +24557,7 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
24557 int base_unit = (width_p 24557 int base_unit = (width_p
24558 ? FRAME_COLUMN_WIDTH (it->f) 24558 ? FRAME_COLUMN_WIDTH (it->f)
24559 : FRAME_LINE_HEIGHT (it->f)); 24559 : FRAME_LINE_HEIGHT (it->f));
24560 return OK_PIXELS (extract_float (prop) * base_unit); 24560 return OK_PIXELS (XFLOATINT (prop) * base_unit);
24561 } 24561 }
24562 24562
24563 if (CONSP (prop)) 24563 if (CONSP (prop))
@@ -24612,7 +24612,7 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
24612 if (NUMBERP (car)) 24612 if (NUMBERP (car))
24613 { 24613 {
24614 double fact; 24614 double fact;
24615 pixels = extract_float (car); 24615 pixels = XFLOATINT (car);
24616 if (NILP (cdr)) 24616 if (NILP (cdr))
24617 return OK_PIXELS (pixels); 24617 return OK_PIXELS (pixels);
24618 if (calc_pixel_width_or_height (&fact, it, cdr, 24618 if (calc_pixel_width_or_height (&fact, it, cdr,
@@ -27225,7 +27225,7 @@ x_produce_glyphs (struct it *it)
27225 bool stretched_p 27225 bool stretched_p
27226 = it->char_to_display == ' ' && !NILP (it->space_width); 27226 = it->char_to_display == ' ' && !NILP (it->space_width);
27227 if (stretched_p) 27227 if (stretched_p)
27228 it->pixel_width *= extract_float (it->space_width); 27228 it->pixel_width *= XFLOATINT (it->space_width);
27229 27229
27230 /* If face has a box, add the box thickness to the character 27230 /* If face has a box, add the box thickness to the character
27231 height. If character has a box line to the left and/or 27231 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)
29703 && (lx0 = XCAR (XCAR (circ)), INTEGERP (lx0)) 29703 && (lx0 = XCAR (XCAR (circ)), INTEGERP (lx0))
29704 && (ly0 = XCDR (XCAR (circ)), INTEGERP (ly0))) 29704 && (ly0 = XCDR (XCAR (circ)), INTEGERP (ly0)))
29705 { 29705 {
29706 double r = extract_float (lr); 29706 double r = XFLOATINT (lr);
29707 double dx = XINT (lx0) - x; 29707 double dx = XINT (lx0) - x;
29708 double dy = XINT (ly0) - y; 29708 double dy = XINT (ly0) - y;
29709 return (dx * dx + dy * dy <= r * r); 29709 return (dx * dx + dy * dy <= r * r);