mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-25 23:10:47 -08:00
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.
This commit is contained in:
parent
10bedb75c9
commit
de00a933e4
14 changed files with 111 additions and 164 deletions
42
src/coding.c
42
src/coding.c
|
|
@ -9023,23 +9023,23 @@ DEFUN ("find-coding-systems-region-internal",
|
|||
}
|
||||
else
|
||||
{
|
||||
CHECK_FIXNUM_COERCE_MARKER (start);
|
||||
CHECK_FIXNUM_COERCE_MARKER (end);
|
||||
if (XFIXNUM (start) < BEG || XFIXNUM (end) > Z || XFIXNUM (start) > XFIXNUM (end))
|
||||
EMACS_INT s = fix_position (start);
|
||||
EMACS_INT e = fix_position (end);
|
||||
if (! (BEG <= s && s <= e && e <= Z))
|
||||
args_out_of_range (start, end);
|
||||
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
|
||||
return Qt;
|
||||
start_byte = CHAR_TO_BYTE (XFIXNUM (start));
|
||||
end_byte = CHAR_TO_BYTE (XFIXNUM (end));
|
||||
if (XFIXNUM (end) - XFIXNUM (start) == end_byte - start_byte)
|
||||
start_byte = CHAR_TO_BYTE (s);
|
||||
end_byte = CHAR_TO_BYTE (e);
|
||||
if (e - s == end_byte - start_byte)
|
||||
return Qt;
|
||||
|
||||
if (XFIXNUM (start) < GPT && XFIXNUM (end) > GPT)
|
||||
if (s < GPT && GPT < e)
|
||||
{
|
||||
if ((GPT - XFIXNUM (start)) < (XFIXNUM (end) - GPT))
|
||||
move_gap_both (XFIXNUM (start), start_byte);
|
||||
if (GPT - s < e - GPT)
|
||||
move_gap_both (s, start_byte);
|
||||
else
|
||||
move_gap_both (XFIXNUM (end), end_byte);
|
||||
move_gap_both (e, end_byte);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -9277,25 +9277,25 @@ is nil. */)
|
|||
}
|
||||
else
|
||||
{
|
||||
CHECK_FIXNUM_COERCE_MARKER (start);
|
||||
CHECK_FIXNUM_COERCE_MARKER (end);
|
||||
if (XFIXNUM (start) < BEG || XFIXNUM (end) > Z || XFIXNUM (start) > XFIXNUM (end))
|
||||
EMACS_INT s = fix_position (start);
|
||||
EMACS_INT e = fix_position (end);
|
||||
if (! (BEG <= s && s <= e && e <= Z))
|
||||
args_out_of_range (start, end);
|
||||
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
|
||||
return Qnil;
|
||||
start_byte = CHAR_TO_BYTE (XFIXNUM (start));
|
||||
end_byte = CHAR_TO_BYTE (XFIXNUM (end));
|
||||
if (XFIXNUM (end) - XFIXNUM (start) == end_byte - start_byte)
|
||||
start_byte = CHAR_TO_BYTE (s);
|
||||
end_byte = CHAR_TO_BYTE (e);
|
||||
if (e - s == end_byte - start_byte)
|
||||
return Qnil;
|
||||
|
||||
if (XFIXNUM (start) < GPT && XFIXNUM (end) > GPT)
|
||||
if (s < GPT && GPT < e)
|
||||
{
|
||||
if ((GPT - XFIXNUM (start)) < (XFIXNUM (end) - GPT))
|
||||
move_gap_both (XFIXNUM (start), start_byte);
|
||||
if (GPT - s < e - GPT)
|
||||
move_gap_both (s, start_byte);
|
||||
else
|
||||
move_gap_both (XFIXNUM (end), end_byte);
|
||||
move_gap_both (e, end_byte);
|
||||
}
|
||||
pos = XFIXNUM (start);
|
||||
pos = s;
|
||||
}
|
||||
|
||||
list = Qnil;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue