diff options
| author | Paul Eggert | 2020-03-27 00:58:31 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-03-27 01:06:54 -0700 |
| commit | de00a933e4b35b42398582eaba58531e5fdd46ca (patch) | |
| tree | 1999aba74c99e98e2b101faf65160acb45fd9b52 /src/buffer.c | |
| parent | 10bedb75c915158b7662d4dfa4afa3a231714268 (diff) | |
| download | emacs-de00a933e4b35b42398582eaba58531e5fdd46ca.tar.gz emacs-de00a933e4b35b42398582eaba58531e5fdd46ca.zip | |
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/buffer.c')
| -rw-r--r-- | src/buffer.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/buffer.c b/src/buffer.c index cc7d4e4817c..70598a7a22a 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -131,6 +131,23 @@ CHECK_OVERLAY (Lisp_Object x) | |||
| 131 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x); | 131 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x); |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | /* Convert the position POS to an EMACS_INT that fits in a fixnum. | ||
| 135 | Yield POS's value if POS is already a fixnum, POS's marker position | ||
| 136 | if POS is a marker, and MOST_NEGATIVE_FIXNUM or | ||
| 137 | MOST_POSITIVE_FIXNUM if POS is a negative or positive bignum. | ||
| 138 | Signal an error if POS is not of the proper form. */ | ||
| 139 | |||
| 140 | EMACS_INT | ||
| 141 | fix_position (Lisp_Object pos) | ||
| 142 | { | ||
| 143 | if (FIXNUMP (pos)) | ||
| 144 | return XFIXNUM (pos); | ||
| 145 | if (MARKERP (pos)) | ||
| 146 | return marker_position (pos); | ||
| 147 | CHECK_TYPE (BIGNUMP (pos), Qinteger_or_marker_p, pos); | ||
| 148 | return !NILP (Fnatnump (pos)) ? MOST_POSITIVE_FIXNUM : MOST_NEGATIVE_FIXNUM; | ||
| 149 | } | ||
| 150 | |||
| 134 | /* These setters are used only in this file, so they can be private. | 151 | /* These setters are used only in this file, so they can be private. |
| 135 | The public setters are inline functions defined in buffer.h. */ | 152 | The public setters are inline functions defined in buffer.h. */ |
| 136 | static void | 153 | static void |
| @@ -2257,19 +2274,20 @@ so the buffer is truly empty after this. */) | |||
| 2257 | } | 2274 | } |
| 2258 | 2275 | ||
| 2259 | void | 2276 | void |
| 2260 | validate_region (register Lisp_Object *b, register Lisp_Object *e) | 2277 | validate_region (Lisp_Object *b, Lisp_Object *e) |
| 2261 | { | 2278 | { |
| 2262 | CHECK_FIXNUM_COERCE_MARKER (*b); | 2279 | EMACS_INT beg = fix_position (*b), end = fix_position (*e); |
| 2263 | CHECK_FIXNUM_COERCE_MARKER (*e); | ||
| 2264 | 2280 | ||
| 2265 | if (XFIXNUM (*b) > XFIXNUM (*e)) | 2281 | if (end < beg) |
| 2266 | { | 2282 | { |
| 2267 | Lisp_Object tem; | 2283 | EMACS_INT tem = beg; beg = end; end = tem; |
| 2268 | tem = *b; *b = *e; *e = tem; | ||
| 2269 | } | 2284 | } |
| 2270 | 2285 | ||
| 2271 | if (! (BEGV <= XFIXNUM (*b) && XFIXNUM (*e) <= ZV)) | 2286 | if (! (BEGV <= beg && end <= ZV)) |
| 2272 | args_out_of_range_3 (Fcurrent_buffer (), *b, *e); | 2287 | args_out_of_range_3 (Fcurrent_buffer (), *b, *e); |
| 2288 | |||
| 2289 | *b = make_fixnum (beg); | ||
| 2290 | *e = make_fixnum (end); | ||
| 2273 | } | 2291 | } |
| 2274 | 2292 | ||
| 2275 | /* Advance BYTE_POS up to a character boundary | 2293 | /* Advance BYTE_POS up to a character boundary |