summaryrefslogtreecommitdiff
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-03-27 00:58:31 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-03-27 01:06:54 -0700
commitde00a933e4b35b42398582eaba58531e5fdd46ca (patch)
tree1999aba74c99e98e2b101faf65160acb45fd9b52 /src/editfns.c
parent10bedb75c915158b7662d4dfa4afa3a231714268 (diff)
downloademacs-de00a933e4b35b42398582eaba58531e5fdd46ca.tar.gz
Treat out-of-range positions consistently
If a position argument to get-byte etc. is an out-of-range integer, treat it the same regardless of whether it is a fixnum or a bignum. * src/buffer.c (fix_position): New function. * src/buffer.c (validate_region): * src/character.c (Fget_byte): * src/coding.c (Ffind_coding_systems_region_internal) (Fcheck_coding_systems_region): * src/composite.c (Ffind_composition_internal): * src/editfns.c (Fposition_bytes, Fchar_after, Fchar_before) (Finsert_buffer_substring, Fcompare_buffer_substrings) (Fnarrow_to_region): * src/fns.c (Fsecure_hash_algorithms): * src/font.c (Finternal_char_font, Ffont_at): * src/fringe.c (Ffringe_bitmaps_at_pos): * src/search.c (search_command): * src/textprop.c (get_char_property_and_overlay): * src/window.c (Fpos_visible_in_window_p): * src/xdisp.c (Fwindow_text_pixel_size): Use it instead of CHECK_FIXNUM_COERCE_MARKER, so that the code is simpler and treats bignums consistently with fixnums. * src/buffer.h (CHECK_FIXNUM_COERCE_MARKER): Define here rather than in lisp.h, and reimplement in terms of fix_position so that it treats bignums consistently with fixnums. * src/lisp.h (CHECK_FIXNUM_COERCE_MARKER): Move to buffer.h. * src/textprop.c (validate_interval_range): Signal with original bounds rather than modified ones.
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c95
1 files changed, 27 insertions, 68 deletions
diff --git a/src/editfns.c b/src/editfns.c
index cbc1082b2cc..90520d0dced 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -948,10 +948,10 @@ DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
If POSITION is out of range, the value is nil. */)
(Lisp_Object position)
{
- CHECK_FIXNUM_COERCE_MARKER (position);
- if (XFIXNUM (position) < BEG || XFIXNUM (position) > Z)
+ EMACS_INT pos = fix_position (position);
+ if (! (BEG <= pos && pos <= Z))
return Qnil;
- return make_fixnum (CHAR_TO_BYTE (XFIXNUM (position)));
+ return make_fixnum (CHAR_TO_BYTE (pos));
}
DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0,
@@ -1068,11 +1068,11 @@ If POS is out of range, the value is nil. */)
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (pos);
- if (XFIXNUM (pos) < BEGV || XFIXNUM (pos) >= ZV)
+ EMACS_INT p = fix_position (pos);
+ if (! (BEGV <= p && p < ZV))
return Qnil;
- pos_byte = CHAR_TO_BYTE (XFIXNUM (pos));
+ pos_byte = CHAR_TO_BYTE (p);
}
return make_fixnum (FETCH_CHAR (pos_byte));
@@ -1102,12 +1102,12 @@ If POS is out of range, the value is nil. */)
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (pos);
+ EMACS_INT p = fix_position (pos);
- if (XFIXNUM (pos) <= BEGV || XFIXNUM (pos) > ZV)
+ if (! (BEGV < p && p <= ZV))
return Qnil;
- pos_byte = CHAR_TO_BYTE (XFIXNUM (pos));
+ pos_byte = CHAR_TO_BYTE (p);
}
if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
@@ -1726,21 +1726,8 @@ using `string-make-multibyte' or `string-make-unibyte', which see. */)
if (!BUFFER_LIVE_P (bp))
error ("Selecting deleted buffer");
- if (NILP (start))
- b = BUF_BEGV (bp);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start);
- b = XFIXNUM (start);
- }
- if (NILP (end))
- e = BUF_ZV (bp);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end);
- e = XFIXNUM (end);
- }
-
+ b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
+ e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
if (b > e)
temp = b, b = e, e = temp;
@@ -1794,21 +1781,8 @@ determines whether case is significant or ignored. */)
error ("Selecting deleted buffer");
}
- if (NILP (start1))
- begp1 = BUF_BEGV (bp1);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start1);
- begp1 = XFIXNUM (start1);
- }
- if (NILP (end1))
- endp1 = BUF_ZV (bp1);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end1);
- endp1 = XFIXNUM (end1);
- }
-
+ begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
+ endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
if (begp1 > endp1)
temp = begp1, begp1 = endp1, endp1 = temp;
@@ -1832,21 +1806,8 @@ determines whether case is significant or ignored. */)
error ("Selecting deleted buffer");
}
- if (NILP (start2))
- begp2 = BUF_BEGV (bp2);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start2);
- begp2 = XFIXNUM (start2);
- }
- if (NILP (end2))
- endp2 = BUF_ZV (bp2);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end2);
- endp2 = XFIXNUM (end2);
- }
-
+ begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
+ endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
if (begp2 > endp2)
temp = begp2, begp2 = endp2, endp2 = temp;
@@ -2700,29 +2661,27 @@ See also `save-restriction'.
When calling from Lisp, pass two arguments START and END:
positions (integers or markers) bounding the text that should
remain visible. */)
- (register Lisp_Object start, Lisp_Object end)
+ (Lisp_Object start, Lisp_Object end)
{
- CHECK_FIXNUM_COERCE_MARKER (start);
- CHECK_FIXNUM_COERCE_MARKER (end);
+ EMACS_INT s = fix_position (start), e = fix_position (end);
- if (XFIXNUM (start) > XFIXNUM (end))
+ if (e < s)
{
- Lisp_Object tem;
- tem = start; start = end; end = tem;
+ EMACS_INT tem = s; s = e; e = tem;
}
- if (!(BEG <= XFIXNUM (start) && XFIXNUM (start) <= XFIXNUM (end) && XFIXNUM (end) <= Z))
+ if (!(BEG <= s && s <= e && e <= Z))
args_out_of_range (start, end);
- if (BEGV != XFIXNAT (start) || ZV != XFIXNAT (end))
+ if (BEGV != s || ZV != e)
current_buffer->clip_changed = 1;
- SET_BUF_BEGV (current_buffer, XFIXNAT (start));
- SET_BUF_ZV (current_buffer, XFIXNAT (end));
- if (PT < XFIXNAT (start))
- SET_PT (XFIXNAT (start));
- if (PT > XFIXNAT (end))
- SET_PT (XFIXNAT (end));
+ SET_BUF_BEGV (current_buffer, s);
+ SET_BUF_ZV (current_buffer, e);
+ if (PT < s)
+ SET_PT (s);
+ if (e < PT)
+ SET_PT (e);
/* Changing the buffer bounds invalidates any recorded current column. */
invalidate_current_column ();
return Qnil;