aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog965
-rw-r--r--src/alloc.c100
-rw-r--r--src/bidi.c88
-rw-r--r--src/buffer.c259
-rw-r--r--src/buffer.h68
-rw-r--r--src/bytecode.c25
-rw-r--r--src/callint.c10
-rw-r--r--src/callproc.c69
-rw-r--r--src/casefiddle.c42
-rw-r--r--src/casetab.c15
-rw-r--r--src/category.c2
-rw-r--r--src/category.h3
-rw-r--r--src/ccl.c122
-rw-r--r--src/ccl.h2
-rw-r--r--src/character.c113
-rw-r--r--src/character.h30
-rw-r--r--src/charset.c104
-rw-r--r--src/charset.h18
-rw-r--r--src/chartab.c10
-rw-r--r--src/cmds.c155
-rw-r--r--src/coding.c346
-rw-r--r--src/coding.h20
-rw-r--r--src/composite.c121
-rw-r--r--src/composite.h22
-rw-r--r--src/data.c41
-rw-r--r--src/dbusbind.c130
-rw-r--r--src/dired.c43
-rw-r--r--src/dispextern.h114
-rw-r--r--src/dispnew.c109
-rw-r--r--src/doc.c24
-rw-r--r--src/doprnt.c2
-rw-r--r--src/editfns.c219
-rw-r--r--src/emacs.c27
-rw-r--r--src/eval.c222
-rw-r--r--src/fileio.c195
-rw-r--r--src/floatfns.c26
-rw-r--r--src/fns.c328
-rw-r--r--src/font.c65
-rw-r--r--src/font.h2
-rw-r--r--src/fontset.c18
-rw-r--r--src/frame.c61
-rw-r--r--src/frame.h2
-rw-r--r--src/fringe.c12
-rw-r--r--src/ftfont.c10
-rw-r--r--src/gnutls.c19
-rw-r--r--src/gnutls.h8
-rw-r--r--src/gtkutil.c12
-rw-r--r--src/image.c7
-rw-r--r--src/indent.c206
-rw-r--r--src/indent.h44
-rw-r--r--src/insdel.c254
-rw-r--r--src/intervals.c134
-rw-r--r--src/intervals.h34
-rw-r--r--src/keyboard.c151
-rw-r--r--src/keyboard.h4
-rw-r--r--src/keymap.c68
-rw-r--r--src/lisp.h290
-rw-r--r--src/lisp.mk43
-rw-r--r--src/lread.c241
-rw-r--r--src/macros.c15
-rw-r--r--src/makefile.w32-in7
-rw-r--r--src/marker.c95
-rw-r--r--src/menu.c71
-rw-r--r--src/minibuf.c52
-rw-r--r--src/msdos.c2
-rw-r--r--src/nsfns.m14
-rw-r--r--src/nsfont.m8
-rw-r--r--src/nsmenu.m8
-rw-r--r--src/nsselect.m9
-rw-r--r--src/nsterm.m10
-rw-r--r--src/print.c116
-rw-r--r--src/process.c162
-rw-r--r--src/process.h4
-rw-r--r--src/puresize.h4
-rw-r--r--src/ralloc.c6
-rw-r--r--src/scroll.c8
-rw-r--r--src/search.c243
-rw-r--r--src/sound.c26
-rw-r--r--src/syntax.c188
-rw-r--r--src/syntax.h16
-rw-r--r--src/sysdep.c54
-rw-r--r--src/term.c8
-rw-r--r--src/termhooks.h2
-rw-r--r--src/textprop.c49
-rw-r--r--src/undo.c22
-rw-r--r--src/unexmacosx.c19
-rw-r--r--src/w32console.c89
-rw-r--r--src/w32fns.c13
-rw-r--r--src/w32inevt.c59
-rw-r--r--src/w32menu.c2
-rw-r--r--src/w32term.c37
-rw-r--r--src/w32term.h3
-rw-r--r--src/window.c58
-rw-r--r--src/xdisp.c718
-rw-r--r--src/xfaces.c52
-rw-r--r--src/xfns.c38
-rw-r--r--src/xfont.c2
-rw-r--r--src/xmenu.c18
-rw-r--r--src/xml.c4
-rw-r--r--src/xrdb.c2
-rw-r--r--src/xselect.c28
-rw-r--r--src/xterm.c36
-rw-r--r--src/xterm.h11
103 files changed, 4671 insertions, 3591 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8697e70d51d..fabbcbef40d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,964 @@
12012-05-30 Paul Eggert <eggert@cs.ucla.edu>
2
3 * alloc.c, lisp.h (make_pure_vector): Now static.
4
52012-05-30 Stefan Monnier <monnier@iro.umontreal.ca>
6
7 * eval.c (Fdefun, Fdefmacro, Vmacro_declaration_function):
8 Move to byte-run.el.
9 (Fautoload): Do the hash-doc more carefully.
10 * data.c (Fdefalias): Purify definition, except for keymaps.
11 (Qdefun): Move from eval.c.
12 * lisp.h (Qdefun): Remove.
13 * lread.c (read1): Tiny simplification.
14
152012-05-29 Troels Nielsen <bn.troels@gmail.com>
16
17 Do not create empty overlays with the evaporate property (Bug#9642).
18 * buffer.c (Fmove_overlay): Reinstate the earlier fix for
19 Bug#9642, but explicitly check that the buffer the overlay would
20 be moved to is live and rearrange lines to make sure that errors
21 will not put the overlay in an inconsistent state.
22 (Fdelete_overlay): Cosmetics.
23
242012-05-28 Eli Zaretskii <eliz@gnu.org>
25
26 * w32term.c (my_bring_window_to_top): New function.
27 (x_raise_frame): Use handle returned by DeferWindowPos, which
28 could be different from the original one.
29 Call my_bring_window_to_top instead of my_set_foreground_window.
30 (Bug#11513)
31
32 * w32fns.c (w32_wnd_proc): Accept and process WM_EMACS_BRINGTOTOP
33 by calling BringWindowToTop.
34
35 * w32term.h (WM_EMACS_BRINGTOTOP): New message.
36 (WM_EMACS_END): Increase by one.
37
382012-05-28 Paul Eggert <eggert@cs.ucla.edu>
39
40 * bidi.c (bidi_mirror_char): Put eassert before conversion to int.
41 This avoids undefined behavior that might cause the eassert
42 to not catch an out-of-range value.
43
442012-05-28 Juanma Barranquero <lekktu@gmail.com>
45
46 * makefile.w32-in ($(BLD)/w32inevt.$(O), $(BLD)/w32console.$(O)):
47 Update dependencies.
48
492012-05-27 Eli Zaretskii <eliz@gnu.org>
50
51 * bidi.c (bidi_mirror_char): Fix last change.
52
532012-05-27 Andreas Schwab <schwab@linux-m68k.org>
54
55 * unexmacosx.c (copy_data_segment): Truncate after 16 characters
56 when referring to sectname field in printf format.
57
582012-05-27 Paul Eggert <eggert@cs.ucla.edu>
59
60 * lisp.h [REL_ALLOC]: Omit duplicate prototypes.
61 Only r_alloc_inhibit_buffer_relocation needed to be added;
62 the others were already declared.
63
64 * bidi.c (bidi_mirror_char): Don't possibly truncate the integer
65 before checking whether it's out of range. Put the check inside
66 eassert. See
67 <http://lists.gnu.org/archive/html/emacs-devel/2012-05/msg00485.html>.
68
692012-05-27 Ken Brown <kbrown@cornell.edu>
70
71 * callproc.c (Fcall_process): Restore a line that was accidentally
72 commented out in the 2011-02-13 change (bug#11547).
73
742012-05-27 Eli Zaretskii <eliz@gnu.org>
75
76 * lisp.h [REL_ALLOC]: Add prototypes for external functions
77 defined on ralloc.c.
78
79 * buffer.c [REL_ALLOC]: Remove prototypes of
80 r_alloc_reset_variable, r_alloc, r_re_alloc, and r_alloc_free,
81 they are now on lisp.h.
82
83 * ralloc.c (r_alloc_inhibit_buffer_relocation): New function.
84
85 * search.c (search_buffer): Use it to inhibit relocation of buffer
86 text while re_search_2 is doing its job, because re_search_2 is
87 passed C pointers to buffer text. (Bug#11519)
88
89 * msdos.c (internal_terminal_init) <Vwindow_system_version>:
90 Update value to 24.
91
92 * xdisp.c (move_it_to): Under MOVE_TO_Y, when restoring iterator
93 state after an additional call to move_it_in_display_line_to, keep
94 the values of it->max_ascent and it->max_descent found for the
95 entire line.
96 (pos_visible_p): Revert the comparison against bottom_y to what it
97 was in revid eliz@gnu.org-20120513182235-4p6386j761ld0nwb.
98 (Bug#11464)
99
1002012-05-26 Paul Eggert <eggert@cs.ucla.edu>
101
102 Fix coding-related core dumps with gcc -ftrapv.
103 The code was computing A - B, where A and B are pointers, and B is
104 random garbage. This can lead to core dumps on platforms that
105 have special pointer registers, and it also leads to core dumps on
106 x86-64 when compiled with gcc -ftrapv. The fix is to compute
107 A - B only when B is initialized properly.
108 * coding.c (coding_set_source, coding_set_destination): Return void.
109 (coding_change_source, coding_change_destinations): New functions,
110 with the old behaviors of coding_set_source and coding_set_destination.
111 All callers that need an offset changed to use these new functions.
112
1132012-05-26 Glenn Morris <rgm@gnu.org>
114
115 * nsterm.m (ns_init_paths): Don't mess with INFOPATH. (Bug#2791)
116
1172012-05-26 Eli Zaretskii <eliz@gnu.org>
118
119 Extend mouse support on W32 text-mode console.
120 * xdisp.c (draw_row_with_mouse_face):
121 Call tty_draw_row_with_mouse_face for WINDOWSNT as well.
122
123 * w32console.c: Include window.h.
124 (w32con_write_glyphs_with_face, tty_draw_row_with_mouse_face):
125 New functions.
126 (initialize_w32_display): Initialize mouse-highlight data.
127
128 * w32inevt.c: Include termchar.h and window.h.
129 (do_mouse_event): Support mouse-autoselect-window. When the mouse
130 moves, call note_mouse_highlight. If help_echo changed, call
131 gen_help_event to produce help-echo message in the echo area.
132 Call clear_mouse_face if mouse_face_hidden is set in the mouse
133 highlight info.
134
1352012-05-26 Paul Eggert <eggert@cs.ucla.edu>
136
137 * lread.c (read1): Simplify slightly to avoid an overflow warning
138 with GCC 4.7.0 on x86-64.
139
1402012-05-26 Eli Zaretskii <eliz@gnu.org>
141
142 * bidi.c (bidi_mirror_char): Revert last change: an int is
143 definitely wide enough here.
144
1452012-05-25 Paul Eggert <eggert@cs.ucla.edu>
146
147 Fix integer width and related bugs (Bug#9874).
148 * alloc.c (pure_bytes_used_lisp, pure_bytes_used_non_lisp):
149 (allocate_vectorlike, buffer_memory_full, struct sdata, SDATA_SIZE)
150 (string_bytes, check_sblock, allocate_string_data):
151 (compact_small_strings, Fmake_bool_vector, make_string)
152 (make_unibyte_string, make_multibyte_string)
153 (make_string_from_bytes, make_specified_string)
154 (allocate_vectorlike, Fmake_vector, find_string_data_in_pure)
155 (make_pure_string, make_pure_c_string, make_pure_vector, Fpurecopy)
156 (mark_vectorlike):
157 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
158 (allocate_pseudovector):
159 Use int, not EMACS_INT, where int is wide enough.
160 (inhibit_garbage_collection, Fgarbage_collect):
161 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
162 * bidi.c (bidi_mirror_char): Use EMACS_INT, not int, where
163 int might not be wide enough.
164 (bidi_cache_search, bidi_cache_find, bidi_init_it)
165 (bidi_count_bytes, bidi_char_at_pos, bidi_fetch_char)
166 (bidi_at_paragraph_end, bidi_find_paragraph_start)
167 (bidi_paragraph_init, bidi_resolve_explicit, bidi_resolve_weak)
168 (bidi_level_of_next_char, bidi_move_to_visually_next):
169 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
170 * buffer.c (copy_overlays, Fgenerate_new_buffer_name)
171 (Fkill_buffer, Fset_buffer_major_mode)
172 (advance_to_char_boundary, Fbuffer_swap_text)
173 (Fset_buffer_multibyte, overlays_at, overlays_in)
174 (overlay_touches_p, struct sortvec, record_overlay_string)
175 (overlay_strings, recenter_overlay_lists)
176 (adjust_overlays_for_insert, adjust_overlays_for_delete)
177 (fix_start_end_in_overlays, fix_overlays_before, modify_overlay)
178 (Fmove_overlay, Fnext_overlay_change, Fprevious_overlay_change)
179 (Foverlay_recenter, last_overlay_modification_hooks_used)
180 (report_overlay_modification, evaporate_overlays, enlarge_buffer_text):
181 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
182 (validate_region): Omit unnecessary test for b <= e,
183 since that's guaranteed by the previous test.
184 (adjust_overlays_for_delete): Avoid pos + length overflow.
185 (Fmove_overlay, Fdelete_overlay, add_overlay_mod_hooklist)
186 (report_overlay_modification):
187 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
188 (Foverlays_at, Fnext_overlay_change, Fprevious_overlay_change):
189 Omit pointer cast, which isn't needed anyway, and doesn't work
190 after the EMACS_INT -> ptrdiff_t change.
191 (Fmove_overlay): Clip BEG and END to ptrdiff_t to avoid overflow.
192 * buffer.h: Adjust decls to match defn changes elsewhere.
193 (struct buffer_text, struct buffer):
194 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
195 Use EMACS_INT, not int, where int might not be wide enough.
196 * bytecode.c (unmark_byte_stack, exec_byte_code): Use ptrdiff_t,
197 not int, to avoid needless 32-bit limit on 64-bit hosts.
198 (exec_byte_code): Use tighter memory-full test, one that checks
199 for alloca overflow. Don't compute the address of the object just
200 before an array, as that's not portable. Use EMACS_INT, not
201 ptrdiff_t or int, where ptrdiff_t or int might not be wide enough.
202 * callint.c (Fcall_interactively):
203 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
204 * callproc.c (call_process_kill, Fcall_process):
205 Don't assume pid_t fits into an Emacs fixnum.
206 (call_process_cleanup, Fcall_process, child_setup):
207 Don't assume pid_t fits into int.
208 (call_process_cleanup, Fcall_process, delete_temp_file)
209 (Fcall_process_region):
210 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
211 (Fcall_process): Simplify handling of volatile integers.
212 Use int, not EMACS_INT, where int will do.
213 * casefiddle.c (casify_object, casify_region, operate_on_word)
214 (Fupcase_word, Fdowncase_word, Fcapitalize_word):
215 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
216 (casify_object): Avoid integer overflow when overallocating buffer.
217 * casetab.c (set_identity, shuffle): Prefer int to unsigned when
218 either works. Use lint_assume to convince GCC 4.6.1 that it's OK.
219 * category.c (Fchar_category_set): Don't assume fixnum fits in int.
220 * category.h (CATEGORYP): Don't assume arg is nonnegative.
221 * ccl.c (GET_CCL_INT): Remove; no longer needed, since the
222 integers are now checked earlier. All uses replaced with XINT.
223 (ccl_driver):
224 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
225 For CCL_MapSingle, check that content and value are in int range.
226 (ccl_driver, Fregister_code_conversion_map):
227 Check that Vcode_version_map_vector is a vector.
228 (resolve_symbol_ccl_program): Check that vector header is in range.
229 Always copy the vector, so that we can check its contents reliably
230 now rather than having to recheck each instruction as it's being
231 executed. Check that vector words fit in 'int'.
232 (ccl_get_compiled_code, Fregister_ccl_program)
233 (Fregister_code_conversion_map): Use ptrdiff_t, not int, for
234 program indexes, to avoid needless 32-bit limit on 64-bit hosts.
235 (Fccl_execute, Fccl_execute_on_string): Check that initial reg
236 contents are in range.
237 (Fccl_execute_on_string): Check that status is in range.
238 * ccl.h (struct ccl_program.idx): Now ptrdiff_t, not int.
239 * character.c (char_resolve_modifier_mask, Fchar_resolve_modifiers):
240 Accept and return EMACS_INT, not int, because callers can pass values
241 out of 'int' range.
242 (c_string_width, strwidth, lisp_string_width, chars_in_text)
243 (multibyte_chars_in_text, parse_str_as_multibyte)
244 (str_as_multibyte, count_size_as_multibyte, str_to_multibyte)
245 (str_as_unibyte, str_to_unibyte, string_count_byte8)
246 (string_escape_byte8, Fget_byte):
247 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
248 (Funibyte_string): Use CHECK_RANGED_INTEGER, not CHECK_NATNUM, to
249 avoid mishandling large integers.
250 * character.h: Adjust decls to match defn changes elsewhere.
251 * charset.c (load_charset_map_from_file, find_charsets_in_text)
252 (Ffind_charset_region):
253 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
254 (load_charset_map_from_file): Redo idx calculation to avoid overflow.
255 (load_charset_map_from_vector, Fdefine_charset_internal):
256 Don't assume fixnum fits in int.
257 (load_charset_map_from_vector, Fmap_charset_chars):
258 Remove now-unnecessary CHECK_NATNUMs.
259 (Fdefine_charset_internal): Check ranges here, more carefully.
260 Don't rely on undefined behavior with signed left shift overflow.
261 Don't assume unsigned int fits into fixnum, or that fixnum fits
262 into unsigned int. Don't require max_code to be a valid fixnum;
263 that's not true for gb10830 4-byte on a 32-bit host. Allow
264 invalid_code to be a cons, for the same reason. Require code_offset
265 to be a character. Avoid int overflow if max_char is close
266 to INT_MAX.
267 (CODE_POINT_TO_INDEX): On 32-bit hosts, return int, not unsigned;
268 this is intended anyway and avoids some undefined behavior.
269 (load_charset_map): Pass unsigned, not int, as 2nd arg of
270 INDEX_TO_CODE_POINT, as that's what it expects.
271 (Funify_charset, encode_char): Don't stuff unsigned vals into int vars.
272 * charset.h (DECODE_CHAR): Return int, not unsigned;
273 this is what was intended anyway, and it avoids undefined behavior.
274 (CHARSET_OFFSET): Remove unused macro, instead of fixing its
275 integer-overflow issues.
276 (ENCODE_CHAR): Return unsigned on all hosts, not just on 32-bit hosts.
277 Formerly, it returned EMACS_INT on 64-bit hosts in the common case
278 where the argument is EMACS_INT, and this behavior is not intended.
279 * chartab.c (Fmake_char_table, Fset_char_table_range)
280 (uniprop_get_decoder, uniprop_get_encoder):
281 Don't assume fixnum fits in int.
282 * cmds.c (move_point): New function, that does the gist of
283 Fforward_char and Fbackward_char, but does so while checking
284 for integer overflow more accurately.
285 (Fforward_char, Fbackward_char): Use it.
286 (Fforward_line, Fend_of_line, internal_self_insert)
287 (internal_self_insert):
288 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
289 Fix a FIXME, by checking for integer overflow when calculating
290 target_clm and actual_clm.
291 * coding.c (detect_coding_XXX, encode_coding_XXX, CODING_DECODE_CHAR)
292 (CODING_ENCODE_CHAR, CODING_CHAR_CHARSET, CODING_CHAR_CHARSET_P)
293 (ASSURE_DESTINATION, coding_alloc_by_realloc)
294 (coding_alloc_by_making_gap, alloc_destination)
295 (detect_coding_utf_8, encode_coding_utf_8, decode_coding_utf_16)
296 (encode_coding_utf_16, detect_coding_emacs_mule)
297 (decode_coding_emacs_mule, encode_coding_emacs_mule)
298 (detect_coding_iso_2022, decode_coding_iso_2022)
299 (encode_invocation_designation, encode_designation_at_bol)
300 (encode_coding_iso_2022, detect_coding_sjis, detect_coding_big5)
301 (decode_coding_sjis, decode_coding_big5, encode_coding_sjis)
302 (encode_coding_big5, detect_coding_ccl, decode_coding_ccl)
303 (encode_coding_ccl, encode_coding_raw_text)
304 (detect_coding_charset, decode_coding_charset)
305 (encode_coding_charset, detect_eol, decode_eol, produce_chars)
306 (produce_composition, produce_charset, produce_annotation)
307 (decode_coding, handle_composition_annotation)
308 (handle_charset_annotation, consume_chars, decode_coding_gap)
309 (decode_coding_object, encode_coding_object, detect_coding_system)
310 (Ffind_coding_systems_region_internal, Fcheck_coding_systems_region)
311 (code_convert_region, code_convert_string)
312 (Fdefine_coding_system_internal)
313 (coding_set_source, coding_set_destination):
314 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
315 (setup_iso_safe_charsets, consume_chars, Funencodable_char_position)
316 (Fdefine_coding_system_internal):
317 Don't assume fixnums fit in int.
318 (decode_coding_gap, decode_coding_object, encode_coding_object)
319 (Fread_coding_system, Fdetect_coding_region)
320 (Funencodable_char_position, Fcheck_coding_systems_region)
321 (get_translation, handle_composition_annotation, consume_chars):
322 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
323 (consume_chars): Rewrite to not calculate an address outside buffer.
324 (Ffind_operation_coding_system): NATNUMP can eval its arg twice.
325 Don't access memory outside of the args array.
326 (Fdefine_coding_system_internal): Check for charset-id overflow.
327 (ENCODE_ISO_CHARACTER): Use unsigned, not int, to store the unsigned
328 result of ENCODE_CHAR.
329 * coding.h: Adjust decls to match defn changes elsewhere.
330 (struct coding_system):
331 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
332 * composite.c (get_composition_id, find_composition)
333 (run_composition_function, update_compositions)
334 (compose_text, composition_gstring_put_cache)
335 (composition_gstring_p, composition_gstring_width)
336 (fill_gstring_header, fill_gstring_body, autocmp_chars)
337 (composition_compute_stop_pos, composition_reseat_it)
338 (composition_update_it, struct position_record)
339 (find_automatic_composition, composition_adjust_point)
340 (Fcomposition_get_gstring, Ffind_composition_internal):
341 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
342 (update_compositions):
343 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
344 * composite.h: Adjust decls to match defn changes elsewhere.
345 (struct composition):
346 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
347 * data.c (let_shadows_buffer_binding_p, let_shadows_global_binding_p):
348 Do not attempt to compute the address of the object just before a
349 buffer; this is not portable.
350 (Faref, Faset):
351 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
352 (Faset): Use int, not EMACS_INT, where int is wide enough.
353 (Fstring_to_number): Don't assume fixnums fit in int.
354 (Frem): Don't assume arg is nonnegative.
355 * dbusbind.c (xd_append_arg): Check for integers out of range.
356 (Fdbus_call_method): Don't overflow the timeout int.
357 (extract_signed, extract_unsigned): New functions.
358 (XD_CHECK_DBUS_SERIAL): Remove; superseded by extract_unsigned.
359 (xd_get_connection_references): Return ptrdiff_t, not int.
360 All uses changed.
361 (xd_signature, xd_append_arg, xd_retrieve_arg, Fdbus_message_internal)
362 (xd_read_message_1):
363 Use int, not unsigned, where the dbus API uses int.
364 (Fdbus_message_internal): Don't overflow mtype.
365 (syms_of_dbusbind): Allocate right-sized buffer for integers.
366 * dired.c (directory_files_internal, file_name_completion, scmp)
367 (file_name_completion_stat):
368 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
369 (file_name_completion): Don't overflow matchcount.
370 (file_name_completion_stat): Use SAFE_ALLOCA, not alloca.
371 * dispextern.h: Adjust decls to match defn changes elsewhere.
372 (struct text_pos, struct glyph, struct bidi_saved_info)
373 (struct bidi_string_data, struct bidi_it, struct composition_it)
374 (struct it):
375 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
376 (struct display_pos, struct composition_it, struct it):
377 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
378 * dispnew.c (increment_matrix_positions)
379 (increment_row_positions, mode_line_string)
380 (marginal_area_string):
381 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
382 (change_frame_size_1, Fredisplay, Fframe_or_buffer_changed_p):
383 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
384 (duration_to_sec_usec): New function, to check for overflow better.
385 (Fsleep_for, sit_for): Use it.
386 * doc.c (get_doc_string, store_function_docstring):
387 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
388 (get_doc_string, Fsnarf_documentation):
389 Use int, not EMACS_INT, where int is wide enough.
390 (get_doc_string):
391 Use SAFE_ALLOCA, not alloca.
392 Check for overflow when converting EMACS_INT to off_t.
393 * doprnt.c (doprnt):
394 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
395 * editfns.c (init_editfns, Fuser_uid, Fuser_real_uid):
396 Don't assume uid_t fits into fixnum.
397 (buildmark, Fgoto_char, overlays_around, find_field, Fdelete_field)
398 (Ffield_string, Ffield_string_no_properties, Ffield_beginning)
399 (Ffield_end, Fconstrain_to_field, Fline_beginning_position)
400 (Fline_end_position, Fprevious_char, Fchar_after, Fchar_before)
401 (general_insert_function)
402 (Finsert_char, make_buffer_string, make_buffer_string_both)
403 (update_buffer_properties, Fbuffer_substring)
404 (Fbuffer_substring_no_properties, Fcompare_buffer_substrings)
405 (Fsubst_char_in_region, check_translation)
406 (Ftranslate_region_internal, save_restriction_restore, Fformat)
407 (transpose_markers, Ftranspose_regions):
408 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
409 (clip_to_bounds): Move to lisp.h as an inline function).
410 (Fconstrain_to_field): Don't assume integers are nonnegative.
411 (Fline_beginning_position, Fsave_excursion, Fsave_current_buffer):
412 (Fsubst_char_in_region, Fsave_restriction):
413 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
414 (Femacs_pid): Don't assume pid_t fits into fixnum.
415 (lo_time): Use int, not EMACS_INT, when int suffices.
416 (lisp_time_argument): Check for usec out of range.
417 (Fencode_time): Don't assume fixnum fits in int.
418 (Fuser_login_name, Fuser_full_name): Signal an error
419 if a uid argument is out of range, rather than relying on
420 undefined behavior.
421 (Fformat_time_string): Remove now-unnecessary check.
422 lisp_time_argument checks for out-of-range usec now.
423 Use ptrdiff_t, not size_t, where ptrdiff_t will do.
424 * emacs.c (gdb_valbits, gdb_gctypebits): Now int, not EMACS_INT.
425 (gdb_data_seg_bits): Now uintptr_t, not EMACS_INT.
426 (PVEC_FLAG, gdb_array_mark_flag): Now ptrdiff_t, not EMACS_INT.
427 (init_cmdargs, Fdump_emacs):
428 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
429 (Fkill_emacs): Don't assume fixnum fits in int; instead, take just
430 the bottom (typically) 32 bits of the fixnum.
431 * eval.c (specpdl_size, call_debugger):
432 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
433 (when_entered_debugger, Fbacktrace_debug):
434 Don't assume fixnum can fit in int.
435 (Fdefvaralias, Fdefvar): Do not attempt to compute the address of
436 the object just before a buffer; this is not portable.
437 (FletX, Flet, Funwind_protect, do_autoload, Feval, funcall_lambda)
438 (grow_specpdl, unbind_to):
439 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
440 (Fapply, apply_lambda): Don't assume ptrdiff_t can hold fixnum.
441 (grow_specpdl): Simplify allocation by using xpalloc.
442 (Fprog1, Fprog2): Don't assume list length fits in int. Simplify.
443 * fileio.c (Ffind_file_name_handler, Fcopy_file, Frename_file)
444 (Finsert_file_contents, Fwrite_region, Fdo_auto_save):
445 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
446 (Ffind_file_name_handler, non_regular_inserted, Finsert_file_contents)
447 (a_write, e_write):
448 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
449 (Fcopy_file, non_regular_nbytes, read_non_regular)
450 (Finsert_file_contents):
451 Use int, not EMACS_INT, where int is wide enough.
452 (READ_BUF_SIZE): Verify that it fits in int.
453 (Finsert_file_contents): Check that counts are in proper range,
454 rather than assuming fixnums fit into ptrdiff_t etc.
455 Don't assume fixnums fit into int.
456 * floatfns.c (Fexpt): Avoid undefined signed * signed overflow.
457 * fns.c (Fcompare_strings, Fstring_lessp, struct textprop_rec, concat)
458 (string_char_byte_cache_charpos, string_char_byte_cache_bytepos)
459 (string_char_to_byte, string_byte_to_char)
460 (string_make_multibyte, string_to_multibyte)
461 (string_make_unibyte, Fstring_as_unibyte, Fstring_as_multibyte)
462 (Fstring_to_unibyte, Fsubstring, Fsubstring_no_properties)
463 (substring_both, Fdelete, internal_equal, Ffillarray)
464 (Fclear_string, mapcar1)
465 (Fbase64_encode_region, Fbase64_encode_string, base64_encode_1)
466 (Fbase64_decode_region, Fbase64_decode_string, base64_decode_1)
467 (larger_vector, make_hash_table, maybe_resize_hash_table)
468 (hash_lookup, hash_remove_from_table, hash_clear, sweep_weak_table)
469 (Fmaphash, secure_hash):
470 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
471 (concat): Check for string index and length overflow.
472 (Fmapconcat): Don't assume fixnums fit into ptrdiff_t.
473 (Frequire):
474 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
475 (larger_vector): New API (vec, incr_min, size_max) replaces old
476 one (vec, new_size, init). This catches size overflow.
477 INIT was removed because it was always Qnil.
478 All callers changed.
479 (INDEX_SIZE_BOUND): New macro, which calculates more precisely
480 the upper bound on a hash table index size.
481 (make_hash_table, maybe_resize_hash_table): Use it.
482 (secure_hash): Computer start_byte and end_byte only after
483 they're known to be in ptrdiff_t range.
484 * font.c (font_intern_prop, font_at, font_range, Ffont_shape_gstring)
485 (Ffont_get_glyphs, Ffont_at):
486 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
487 (font_style_to_value, font_prop_validate_style, font_expand_wildcards)
488 (Flist_fonts, Fopen_font):
489 Don't assume fixnum can fit in int.
490 (check_gstring): Don't assume index can fit in int.
491 (font_match_p): Check that fixnum is a character, not a nonnegative
492 fixnum, since the later code needs to stuff it into an int.
493 (font_find_for_lface): Use SAFE_ALLOCA_LISP, not alloca.
494 (font_fill_lglyph_metrics): Use unsigned, not EMACS_INT, to avoid
495 conversion overflow issues.
496 (Fopen_font): Check for integer out of range.
497 (Ffont_get_glyphs): Don't assume index can fit in int.
498 * font.h: Adjust decls to match defn changes elsewhere.
499 * fontset.c (reorder_font_vector): Redo score calculation to avoid
500 integer overflow.
501 (num_auto_fontsets, fontset_from_font): Use ptrdiff_t, not
502 printmax_t, where ptrdiff_t is wide enough.
503 (Finternal_char_font):
504 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
505 * frame.c (Fset_mouse_position, Fset_mouse_pixel_position)
506 (Fset_frame_height, Fset_frame_width, Fset_frame_size)
507 (Fset_frame_position, x_set_frame_parameters)
508 (x_set_line_spacing, x_set_border_width)
509 (x_set_internal_border_width, x_set_alpha, x_figure_window_size):
510 Check that fixnums are in proper range for system types.
511 (frame_name_fnn_p, Fframe_parameter, Fmodify_frame_parameters):
512 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
513 (Fmodify_frame_parameters): Don't assume fixnum fits in int.
514 Use SAFE_ALLOCA_LISP, not alloca.
515 * frame.h (struct frame): Use intptr_t, not EMACS_INT, where
516 intptr_t is wide enough.
517 * fringe.c (lookup_fringe_bitmap, get_logical_fringe_bitmap)
518 (Fdefine_fringe_bitmap): Don't assume fixnum fits in int.
519 (Ffringe_bitmaps_at_pos): Don't assume index fits in int.
520 Check for fixnum out of range.
521 * ftfont.c (ftfont_list): Don't assume index fits in int.
522 Check that fixnums are in proper range for system types.
523 (ftfont_shape_by_flt):
524 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
525 * gnutls.c (emacs_gnutls_write, emacs_gnutls_read):
526 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
527 (Fgnutls_error_fatalp, Fgnutls_error_string, Fgnutls_boot):
528 Check that fixnums are in proper range for system types.
529 * gnutls.h: Adjust decls to match defn changes elsewhere.
530 * gtkutil.c (xg_dialog_run):
531 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
532 (update_frame_tool_bar):
533 Check that fixnums are in proper range for system types.
534 * image.c (parse_image_spec): Redo count calculation to avoid overflow.
535 (lookup_image): Check that fixnums are in range for system types.
536 * indent.c (last_known_column, last_known_column_point):
537 (current_column_bol_cache):
538 (skip_invisible, current_column, check_display_width):
539 (check_display_width, scan_for_column, current_column_1)
540 (Findent_to, Fcurrent_indentation, position_indentation)
541 (indented_beyond_p, Fmove_to_column, compute_motion):
542 (Fcompute_motion, Fvertical_motion):
543 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
544 (last_known_column_modified): Use EMACS_INT, not int.
545 (check_display_width):
546 (Fcompute_motion):
547 Check that fixnums and floats are in proper range for system types.
548 (compute_motion): Don't assume index or fixnum fits in int.
549 (compute_motion, Fcompute_motion):
550 Use int, not EMACS_INT, when it is wide enough.
551 (vmotion): Omit local var start_hpos that is always 0; that way
552 we don't need to worry about overflow in expressions involving it.
553 * indent.h: Adjust decls to match defn changes elsewhere.
554 (struct position):
555 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
556 Use int, not EMACS_INT, where int is wide enough.
557 Remove unused members ovstring_chars_done and tab_offset;
558 all uses removed.
559 * insdel.c (move_gap, move_gap_both, gap_left, gap_right)
560 (adjust_markers_for_delete, adjust_markers_for_insert, adjust_point)
561 (adjust_markers_for_replace, make_gap_larger, make_gap_smaller)
562 (make_gap, copy_text, insert, insert_and_inherit)
563 (insert_before_markers, insert_before_markers_and_inherit)
564 (insert_1, count_combining_before, count_combining_after)
565 (insert_1_both, insert_from_string)
566 (insert_from_string_before_markers, insert_from_string_1)
567 (insert_from_gap, insert_from_buffer, insert_from_buffer_1)
568 (adjust_after_replace, adjust_after_insert, replace_range)
569 (replace_range_2, del_range, del_range_1, del_range_byte)
570 (del_range_both, del_range_2, modify_region)
571 (prepare_to_modify_buffer, signal_before_change)
572 (signal_after_change, Fcombine_after_change_execute):
573 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
574 * intervals.c (traverse_intervals, rotate_right, rotate_left)
575 (balance_an_interval, split_interval_right, split_interval_left)
576 (find_interval, next_interval, update_interval)
577 (adjust_intervals_for_insertion, delete_node, delete_interval)
578 (interval_deletion_adjustment, adjust_intervals_for_deletion)
579 (static_offset_intervals, offset_intervals)
580 (merge_interval_right, merge_interval_left, make_new_interval)
581 (graft_intervals_into_buffer, temp_set_point_both)
582 (temp_set_point, set_point, adjust_for_invis_intang)
583 (set_point_both, move_if_not_intangible, get_property_and_range)
584 (get_local_map, copy_intervals, copy_intervals_to_string)
585 (compare_string_intervals, set_intervals_multibyte_1):
586 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
587 * intervals.h: Adjust decls to match defn changes elsewhere.
588 (struct interval):
589 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
590 * keyboard.c (this_command_key_count, this_single_command_key_start)
591 (before_command_key_count, before_command_echo_length, echo_now)
592 (echo_length, recursive_edit_1, Frecursive_edit, Ftrack_mouse)
593 (command_loop_1, safe_run_hooks, read_char, timer_check_2)
594 (menu_item_eval_property, read_key_sequence, Fread_key_sequence)
595 (Fread_key_sequence_vector, Fexecute_extended_command, Fsuspend_emacs):
596 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
597 (last_non_minibuf_size, last_point_position, echo_truncate)
598 (command_loop_1, adjust_point_for_property, read_char, gen_help_event)
599 (make_lispy_position, make_lispy_event, parse_modifiers_uncached)
600 (parse_modifiers, modify_event_symbol, Fexecute_extended_command)
601 (stuff_buffered_input):
602 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
603 (last_auto_save, command_loop_1, read_char):
604 Use EMACS_INT, not int, to avoid integer overflow.
605 (record_char): Avoid overflow in total_keys computation.
606 (parse_modifiers_uncached): Redo index calculation to avoid overflow.
607 * keyboard.h: Adjust decls to match defn changes elsewhere.
608 * keymap.c (Fdefine_key, Fcurrent_active_maps, accessible_keymaps_1)
609 (Fkey_description, Fdescribe_vector, Flookup_key):
610 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
611 (click_position): New function, to check that positions are in range.
612 (Fcurrent_active_maps):
613 (describe_command):
614 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
615 (Faccessible_keymaps, Fkey_description):
616 (preferred_sequence_p):
617 Don't assume fixnum can fit into int.
618 (Fkey_description): Use SAFE_ALLOCA_LISP, not alloca.
619 Check for integer overflow in size calculations.
620 (Ftext_char_description): Use CHECK_CHARACTER, not CHECK_NUMBER, to
621 avoid mishandling large integers.
622 * lisp.h: Adjust decls to match defn changes elsewhere.
623 (ARRAY_MARK_FLAG, PSEUDOVECTOR_FLAG, struct Lisp_String)
624 (struct vectorlike_header, struct Lisp_Subr, struct Lisp_Hash_Table)
625 (struct Lisp_Marker):
626 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
627 (clip_to_bounds): Now an inline function, moved here from editfns.c.
628 (GLYPH_CODE_P): Check for overflow in system types, subsuming the
629 need for GLYPH_CODE_CHAR_VALID_P and doing proper checking ourselves.
630 All callers changed.
631 (GLYPH_CODE_CHAR, GLYPH_CODE_FACE):
632 Assume the arg has valid form, since it always does.
633 (TYPE_RANGED_INTEGERP): Avoid bug when checking against a wide
634 unsigned integer system type.
635 (CHECK_RANGED_INTEGER, CHECK_TYPE_RANGED_INTEGER): New macros.
636 (struct catchtag, specpdl_size, SPECPDL_INDEX, USE_SAFE_ALLOCA):
637 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
638 (struct catchtag): Use EMACS_INT, not int, since it may be a fixnum.
639 (duration_to_sec_usec): New decl.
640 * lread.c (read_from_string_index, read_from_string_index_byte)
641 (read_from_string_limit, readchar, unreadchar, openp)
642 (read_internal_start, read1, oblookup):
643 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
644 (Fload, readevalloop, Feval_buffer, Feval_region):
645 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
646 (openp): Check for out-of-range argument to 'access'.
647 (read1): Use int, not EMACS_INT, where int is wide enough.
648 Don't assume fixnum fits into int.
649 Fix off-by-one error that can read outside a buffer.
650 (read_filtered_event): Use duration_to_sec_usec
651 to do proper overflow checking on durations.
652 * macros.c (Fstart_kbd_macro): Use xpalloc to check for overflow
653 in size calculation.
654 (Fexecute_kbd_macro):
655 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
656 * marker.c (cached_charpos, cached_bytepos, CONSIDER)
657 (byte_char_debug_check, buf_charpos_to_bytepos, verify_bytepos)
658 (buf_bytepos_to_charpos, Fset_marker, set_marker_restricted)
659 (set_marker_both, set_marker_restricted_both, marker_position)
660 (marker_byte_position, Fbuffer_has_markers_at):
661 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
662 (Fset_marker, set_marker_restricted): Don't assume fixnum fits in int.
663 * menu.c (ensure_menu_items): Rename from grow_menu_items.
664 It now merely ensures that the menu is large enough, without
665 necessarily growing it, as this avoids some integer overflow issues.
666 All callers changed.
667 (keymap_panes, parse_single_submenu, Fx_popup_menu):
668 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
669 (parse_single_submenu, Fx_popup_menu): Don't assume fixnum fits in int.
670 Use SAFE_ALLOCA_LISP, not alloca.
671 (find_and_return_menu_selection): Avoid unnecessary casts of pointers
672 to EMACS_INT. Check that fixnums are in proper range for system types.
673 * minibuf.c (minibuf_prompt_width, string_to_object)
674 (Fminibuffer_contents, Fminibuffer_contents_no_properties)
675 (Fminibuffer_completion_contents, Ftry_completion, Fall_completions):
676 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
677 (get_minibuffer, read_minibuf_unwind):
678 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
679 (read_minibuf): Omit unnecessary arg BACKUP_N, which is always nil;
680 this simplifies overflow checking. All callers changed.
681 (read_minibuf, Fread_buffer, Ftry_completion, Fall_completions)
682 (Ftest_completion):
683 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
684 * nsfns.m (check_ns_display_info): Don't assume fixnum fits in long.
685 (x_set_menu_bar_lines, x_set_tool_bar_lines, Fx_create_frame):
686 Check that fixnums are in proper range for system types.
687 (Fx_create_frame, Fx_show_tip):
688 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
689 * nsfont.m (ns_findfonts, nsfont_list_family):
690 Don't assume fixnum fits in long.
691 * nsmenu.m (ns_update_menubar, ns_menu_show, ns_popup_dialog):
692 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
693 (ns_update_menubar): Use intptr_t, not EMACS_INT, when intptr_t is
694 wide enough.
695 * nsselect.m (ns_get_local_selection, clean_local_selection_data):
696 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
697 * print.c (print_buffer_size, print_buffer_pos, print_buffer_pos_byte)
698 (PRINTDECLARE, PRINTPREPARE):
699 (strout, print_string):
700 (print, print_preprocess, print_check_string_charset_prop)
701 (print_object):
702 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
703 (PRINTDECLARE):
704 (temp_output_buffer_setup, Fprin1_to_string, print_object):
705 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
706 (PRINTPREPARE): Use int, not ptrdiff_t, where int is wide enough.
707 (printchar, strout): Use xpalloc to catch size calculation overflow.
708 (Fexternal_debugging_output): Don't overflow EMACS_INT->int conversion.
709 (print_error_message): Use SAFE_ALLOCA, not alloca.
710 (print_object): Use int, not EMACS_INT, where int is wide enough.
711 (print_depth, new_backquote_output, print_number_index):
712 Use ptrdiff_t, not int, where int might not be wide enough.
713 * process.c (Fdelete_process): Don't assume pid fits into EMACS_INT.
714 (Fset_process_window_size, Fformat_network_address)
715 (get_lisp_to_sockaddr_size, set_socket_option, Fmake_network_process)
716 (sigchld_handler):
717 Check that fixnums are in proper range for system types.
718 (Fsignal_process): Simplify by avoiding a goto.
719 Check for process-ids out of pid_t range rather than relying on
720 undefined behavior.
721 (process_tick, update_tick): Use EMACS_INT, not int.
722 (Fformat_network_address, read_process_output, send_process)
723 (Fprocess_send_region, status_notify):
724 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
725 (Fformat_network_address, Fmake_serial_process, Fmake_network_process)
726 (wait_reading_process_output, read_process_output, exec_sentinel):
727 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
728 (conv_lisp_to_sockaddr): Don't assume fixnums fit into int.
729 (Faccept_process_output): Use duration_to_sec_usec to do proper
730 overflow checking on durations.
731 (emacs_get_tty_pgrp, Fprocess_running_child_p, process_send_signal):
732 Don't assume pid_t fits in int.
733 * process.h (struct Lisp_Process): Members tick and update_tick
734 are now of type EMACS_INT, not int.
735 * puresize.h (PURESIZE_RATIO): Shrink this to 8/6 on 32-bit hosts
736 configured --with-wide-int.
737 * scroll.c (calculate_scrolling, calculate_direct_scrolling)
738 (line_ins_del): Use int, not EMACS_INT, where int is wide enough.
739 * search.c (looking_at_1, string_match_1):
740 (fast_string_match, fast_c_string_match_ignore_case)
741 (fast_string_match_ignore_case, fast_looking_at, scan_buffer)
742 (scan_newline, find_before_next_newline, search_command)
743 (trivial_regexp_p, search_buffer, simple_search, boyer_moore)
744 (set_search_regs, wordify):
745 (Freplace_match):
746 (Fmatch_data):
747 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
748 (string_match_1, search_buffer, set_search_regs):
749 (Fmatch_data):
750 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
751 (wordify): Check for overflow in size calculation.
752 (Freplace_match): Avoid potential buffer overflow in search_regs.start.
753 (Fset_match_data): Don't assume fixnum fits in ptrdiff_t.
754 Check that fixnums are in proper range for system types.
755 * sound.c (struct sound_device)
756 (wav_play, au_play, vox_write, alsa_period_size, alsa_write):
757 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
758 (Fplay_sound_internal):
759 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
760 * syntax.c (struct lisp_parse_state, find_start_modiff)
761 (Finternal_describe_syntax_value, scan_lists, scan_sexps_forward):
762 (Fparse_partial_sexp):
763 Don't assume fixnums can fit in int.
764 (struct lisp_parse_state, find_start_pos, find_start_value)
765 (find_start_value_byte, find_start_begv)
766 (update_syntax_table, char_quoted, dec_bytepos)
767 (find_defun_start, prev_char_comend_first, back_comment):
768 (scan_words, skip_chars, skip_syntaxes, forw_comment, Fforward_comment)
769 (scan_lists, Fbackward_prefix_chars, scan_sexps_forward):
770 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
771 (Finternal_describe_syntax_value): Check that match_lisp is a
772 character, not an integer, since the code stuffs it into int.
773 (scan_words, scan_sexps_forward):
774 Check that fixnums are in proper range for system types.
775 (Fforward_word):
776 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
777 (scan_sexps_forward):
778 Use CHARACTERP, not INTEGERP, since the value must fit into int.
779 (Fparse_partial_sexp): Fix doc; element 8 is not ignored.
780 * syntax.h: Adjust decls to match defn changes elsewhere.
781 (struct gl_state_s):
782 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
783 (SETUP_SYNTAX_TABLE_FOR_OBJECT): Use PTRDIFF_MAX, not
784 MOST_POSITIVE_FIXNUM.
785 * sysdep.c (wait_for_termination_1, wait_for_termination)
786 (interruptible_wait_for_termination, mkdir):
787 Don't assume pid_t fits in int; on 64-bit AIX pid_t is 64-bit.
788 (emacs_read, emacs_write):
789 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
790 (system_process_attributes): Don't assume uid_t, gid_t, EMACS_INT,
791 and double all fit in int.
792 * term.c (set_tty_color_mode):
793 Check that fixnums are in proper range for system types.
794 * termhooks.h (struct input_event):
795 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
796 * textprop.c (validate_interval_range, interval_of)
797 (Fadd_text_properties, set_text_properties_1)
798 (Fremove_text_properties, Fremove_list_of_text_properties)
799 (Ftext_property_any, Ftext_property_not_all)
800 (copy_text_properties, text_property_list, extend_property_ranges)
801 (verify_interval_modification):
802 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
803 (Fnext_single_char_property_change)
804 (Fprevious_single_char_property_change):
805 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
806 (copy_text_properties):
807 Check for integer overflow in index calculation.
808 * undo.c (last_boundary_position, record_point, record_insert)
809 (record_delete, record_marker_adjustment, record_change)
810 (record_property_change):
811 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
812 (truncate_undo_list, Fprimitive_undo): Don't assume fixnum fits in int.
813 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
814 * w32fns.c (Fx_create_frame, x_create_tip_frame, Fx_show_tip)
815 (Fx_hide_tip, Fx_file_dialog):
816 * w32menu.c (set_frame_menubar):
817 Use ptrdiff_t, not int, for consistency with rest of code.
818 * window.c (window_scroll_preserve_hpos, window_scroll_preserve_vpos)
819 (select_window, Fdelete_other_windows_internal)
820 (window_scroll_pixel_based, window_scroll_line_based)
821 (Frecenter, Fset_window_configuration):
822 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
823 (Fset_window_hscroll, run_window_configuration_change_hook)
824 (set_window_buffer, temp_output_buffer_show, scroll_command)
825 (Fscroll_other_window, Frecenter):
826 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
827 (Fwindow_line_height, window_scroll, Fscroll_left, Fscroll_right):
828 Don't assume fixnum fits in int.
829 (Fset_window_scroll_bars):
830 Check that fixnums are in proper range for system types.
831 * xdisp.c (help_echo_pos, pos_visible_p, string_pos_nchars_ahead)
832 (string_pos, c_string_pos, number_of_chars, init_iterator)
833 (in_ellipses_for_invisible_text_p, init_from_display_pos)
834 (compute_stop_pos, next_overlay_change, compute_display_string_pos)
835 (compute_display_string_end, handle_face_prop)
836 (face_before_or_after_it_pos, handle_invisible_prop)
837 (handle_display_prop, handle_display_spec, handle_single_display_spec)
838 (display_prop_intangible_p, string_buffer_position_lim)
839 (string_buffer_position, handle_composition_prop, load_overlay_strings)
840 (get_overlay_strings_1, get_overlay_strings)
841 (iterate_out_of_display_property, forward_to_next_line_start)
842 (back_to_previous_visible_line_start, reseat, reseat_to_string)
843 (get_next_display_element, set_iterator_to_next)
844 (get_visually_first_element, compute_stop_pos_backwards)
845 (handle_stop_backwards, next_element_from_buffer)
846 (move_it_in_display_line_to, move_it_in_display_line)
847 (move_it_to, move_it_vertically_backward, move_it_by_lines)
848 (add_to_log, message_dolog, message_log_check_duplicate)
849 (message2, message2_nolog, message3, message3_nolog
850 (with_echo_area_buffer, display_echo_area_1, resize_mini_window_1)
851 (current_message_1, truncate_echo_area, truncate_message_1)
852 (set_message, set_message_1, store_mode_line_noprop)
853 (hscroll_window_tree, debug_delta, debug_delta_bytes, debug_end_vpos)
854 (text_outside_line_unchanged_p, check_point_in_composition)
855 (reconsider_clip_changes)
856 (redisplay_internal, set_cursor_from_row, try_scrolling)
857 (try_cursor_movement, set_vertical_scroll_bar, redisplay_window)
858 (redisplay_window, find_last_unchanged_at_beg_row)
859 (find_first_unchanged_at_end_row, row_containing_pos, try_window_id)
860 (trailing_whitespace_p, find_row_edges, display_line)
861 (RECORD_MAX_MIN_POS, Fcurrent_bidi_paragraph_direction)
862 (display_mode_element, store_mode_line_string)
863 (pint2str, pint2hrstr, decode_mode_spec)
864 (display_count_lines, display_string, draw_glyphs)
865 (x_produce_glyphs, x_insert_glyphs)
866 (rows_from_pos_range, mouse_face_from_buffer_pos)
867 (fast_find_string_pos, mouse_face_from_string_pos)
868 (note_mode_line_or_margin_highlight, note_mouse_highlight):
869 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
870 (safe_call, init_from_display_pos, handle_fontified_prop)
871 (handle_single_display_spec, load_overlay_strings)
872 (with_echo_area_buffer, setup_echo_area_for_printing)
873 (display_echo_area, echo_area_display)
874 (x_consider_frame_title, prepare_menu_bars, update_menu_bar)
875 (update_tool_bar, hscroll_window_tree, redisplay_internal)
876 (redisplay_window, dump_glyph_row, display_mode_line)
877 (Fformat_mode_line, decode_mode_spec, on_hot_spot_p):
878 (handle_display_spec, display_prop_string_p):
879 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
880 (handle_single_display_spec, build_desired_tool_bar_string)
881 (redisplay_tool_bar, scroll_window_tree, Fdump_glyph_matrix)
882 (get_specified_cursor_type):
883 Check that fixnums are in proper range for system types.
884 (struct overlay_entry, resize_mini_window, Fdump_glyph_row)
885 (Flookup_image_map):
886 Don't assume fixnums fit in int.
887 (compare_overlay_entries):
888 Avoid mishandling comparisons due to subtraction overflow.
889 (load_overlay_strings): Use SAFE_NALLOCA, not alloca.
890 (last_escape_glyph_face_id, last_glyphless_glyph_face_id):
891 (handle_tool_bar_click):
892 Use int, not unsigned, since we prefer signed and the signedness
893 doesn't matter here.
894 (get_next_display_element, next_element_from_display_vector):
895 Use int, not EMACS_INT, when int is wide enough.
896 (start_hourglass): Use duration_to_sec_usec to do proper
897 overflow checking on durations.
898 * xfaces.c (Fbitmap_spec_p):
899 Check that fixnums are in proper range for system types.
900 (compare_fonts_by_sort_order):
901 Avoid mishandling comparisons due to subtraction overflow.
902 (Fx_family_fonts, realize_basic_faces):
903 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
904 (Fx_family_fonts):
905 Don't assume fixnum fits in int.
906 Use SAFE_ALLOCA_LISP, not alloca.
907 (merge_face_heights): Remove unnecessary cast to EMACS_INT.
908 (Finternal_make_lisp_face): Don't allocate more than MAX_FACE_ID.
909 (face_at_buffer_position, face_for_overlay_string)
910 (face_at_string_position):
911 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
912 (merge_faces): Use int, not EMACS_INT, where int is wide enough.
913 * xfns.c (x_set_menu_bar_lines, x_set_tool_bar_lines, x_icon_verify)
914 (Fx_show_tip):
915 Check that fixnums are in proper range for system types.
916 (Fx_create_frame, x_create_tip_frame, Fx_show_tip)
917 (Fx_hide_tip, Fx_file_dialog, Fx_select_font):
918 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
919 (Fx_change_window_property): Don't assume fixnums fit in int.
920 * xfont.c (xfont_chars_supported):
921 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
922 * xmenu.c (Fx_popup_dialog, set_frame_menubar)
923 (create_and_show_popup_menu, create_and_show_dialog, xmenu_show):
924 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
925 * xml.c (parse_region):
926 * xrdb.c (magic_file_p):
927 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
928 * xselect.c (TRACE1): Don't assume pid_t promotes to int.
929 (x_get_local_selection, x_reply_selection_request)
930 (x_handle_selection_request, wait_for_property_change):
931 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
932 (selection_data_to_lisp_data): Use short, not EMACS_INT, where
933 short is wide enough.
934 (x_send_client_event): Don't assume fixnum fits in int.
935 * xterm.c (x_x_to_emacs_modifiers):
936 Don't assume EMACS_INT overflows nicely into int.
937 (x_emacs_to_x_modifiers): Use EMACS_INT, not int, because values
938 may come from Lisp.
939 (handle_one_xevent): NATNUMP can eval its arg twice.
940 (x_connection_closed):
941 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
942 * xterm.h: Adjust decls to match defn changes elsewhere.
943 (struct scroll_bar): Use struct vectorlike_header
944 rather than rolling our own approximation.
945 (SCROLL_BAR_VEC_SIZE): Remove; not used.
946
9472012-05-25 Glenn Morris <rgm@gnu.org>
948
949 * lisp.mk (lisp): Update for more files being compiled now.
950
9512012-05-25 Stefan Monnier <monnier@iro.umontreal.ca>
952
953 * lread.c: Remove `read_pure' which makes no difference.
954 (read_pure): Remove var.
955 (unreadpure): Remove function.
956 (readevalloop): Don't call read_list with -1 flag.
957 (read1, read_vector): Don't test read_pure any more.
958 (read_list): Simplify.
959
960 * fileio.c, character.h: Minor style tweaks.
961
12012-05-24 Dmitry Antipov <dmantipov@yandex.ru> 9622012-05-24 Dmitry Antipov <dmantipov@yandex.ru>
2 963
3 * window.h (clip_changed): Remove useless declaration. 964 * window.h (clip_changed): Remove useless declaration.
@@ -144,8 +1105,8 @@
144 1105
145 * xdisp.c (handle_single_display_spec): Return 1 for left-margin 1106 * xdisp.c (handle_single_display_spec): Return 1 for left-margin
146 and right-margin display specs even if the spec is invalid or we 1107 and right-margin display specs even if the spec is invalid or we
147 are on a TTY, and thus unable to display on the fringes. That's 1108 are on a TTY, and thus unable to display on the fringes.
148 because the text with the property will not be displayed anyway, 1109 That's because the text with the property will not be displayed anyway,
149 so we need to signal to the caller that this is a "replacing" 1110 so we need to signal to the caller that this is a "replacing"
150 display spec. This fixes display when the spec is invalid or we 1111 display spec. This fixes display when the spec is invalid or we
151 are on a TTY. 1112 are on a TTY.
diff --git a/src/alloc.c b/src/alloc.c
index 1f422a6d3b0..cf7778c05f6 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -234,11 +234,11 @@ static ptrdiff_t pure_bytes_used_before_overflow;
234 234
235/* Index in pure at which next pure Lisp object will be allocated.. */ 235/* Index in pure at which next pure Lisp object will be allocated.. */
236 236
237static EMACS_INT pure_bytes_used_lisp; 237static ptrdiff_t pure_bytes_used_lisp;
238 238
239/* Number of bytes allocated for non-Lisp objects in pure storage. */ 239/* Number of bytes allocated for non-Lisp objects in pure storage. */
240 240
241static EMACS_INT pure_bytes_used_non_lisp; 241static ptrdiff_t pure_bytes_used_non_lisp;
242 242
243/* If nonzero, this is a warning delivered by malloc and not yet 243/* If nonzero, this is a warning delivered by malloc and not yet
244 displayed. */ 244 displayed. */
@@ -273,6 +273,7 @@ static Lisp_Object Qpost_gc_hook;
273static void mark_buffer (Lisp_Object); 273static void mark_buffer (Lisp_Object);
274static void mark_terminals (void); 274static void mark_terminals (void);
275static void gc_sweep (void); 275static void gc_sweep (void);
276static Lisp_Object make_pure_vector (ptrdiff_t);
276static void mark_glyph_matrix (struct glyph_matrix *); 277static void mark_glyph_matrix (struct glyph_matrix *);
277static void mark_face_cache (struct face_cache *); 278static void mark_face_cache (struct face_cache *);
278 279
@@ -387,7 +388,7 @@ static void *min_heap_address, *max_heap_address;
387static struct mem_node mem_z; 388static struct mem_node mem_z;
388#define MEM_NIL &mem_z 389#define MEM_NIL &mem_z
389 390
390static struct Lisp_Vector *allocate_vectorlike (EMACS_INT); 391static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t);
391static void lisp_free (void *); 392static void lisp_free (void *);
392static void mark_stack (void); 393static void mark_stack (void);
393static int live_vector_p (struct mem_node *, void *); 394static int live_vector_p (struct mem_node *, void *);
@@ -475,7 +476,7 @@ display_malloc_warning (void)
475/* Called if we can't allocate relocatable space for a buffer. */ 476/* Called if we can't allocate relocatable space for a buffer. */
476 477
477void 478void
478buffer_memory_full (EMACS_INT nbytes) 479buffer_memory_full (ptrdiff_t nbytes)
479{ 480{
480 /* If buffers use the relocating allocator, no need to free 481 /* If buffers use the relocating allocator, no need to free
481 spare_memory, because we may have plenty of malloc space left 482 spare_memory, because we may have plenty of malloc space left
@@ -1662,7 +1663,7 @@ struct sdata
1662 1663
1663#ifdef GC_CHECK_STRING_BYTES 1664#ifdef GC_CHECK_STRING_BYTES
1664 1665
1665 EMACS_INT nbytes; 1666 ptrdiff_t nbytes;
1666 unsigned char data[1]; 1667 unsigned char data[1];
1667 1668
1668#define SDATA_NBYTES(S) (S)->nbytes 1669#define SDATA_NBYTES(S) (S)->nbytes
@@ -1677,7 +1678,7 @@ struct sdata
1677 unsigned char data[1]; 1678 unsigned char data[1];
1678 1679
1679 /* When STRING is null. */ 1680 /* When STRING is null. */
1680 EMACS_INT nbytes; 1681 ptrdiff_t nbytes;
1681 } u; 1682 } u;
1682 1683
1683#define SDATA_NBYTES(S) (S)->u.nbytes 1684#define SDATA_NBYTES(S) (S)->u.nbytes
@@ -1787,24 +1788,24 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
1787#define SDATA_SIZE(NBYTES) \ 1788#define SDATA_SIZE(NBYTES) \
1788 ((SDATA_DATA_OFFSET \ 1789 ((SDATA_DATA_OFFSET \
1789 + (NBYTES) + 1 \ 1790 + (NBYTES) + 1 \
1790 + sizeof (EMACS_INT) - 1) \ 1791 + sizeof (ptrdiff_t) - 1) \
1791 & ~(sizeof (EMACS_INT) - 1)) 1792 & ~(sizeof (ptrdiff_t) - 1))
1792 1793
1793#else /* not GC_CHECK_STRING_BYTES */ 1794#else /* not GC_CHECK_STRING_BYTES */
1794 1795
1795/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is 1796/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is
1796 less than the size of that member. The 'max' is not needed when 1797 less than the size of that member. The 'max' is not needed when
1797 SDATA_DATA_OFFSET is a multiple of sizeof (EMACS_INT), because then the 1798 SDATA_DATA_OFFSET is a multiple of sizeof (ptrdiff_t), because then the
1798 alignment code reserves enough space. */ 1799 alignment code reserves enough space. */
1799 1800
1800#define SDATA_SIZE(NBYTES) \ 1801#define SDATA_SIZE(NBYTES) \
1801 ((SDATA_DATA_OFFSET \ 1802 ((SDATA_DATA_OFFSET \
1802 + (SDATA_DATA_OFFSET % sizeof (EMACS_INT) == 0 \ 1803 + (SDATA_DATA_OFFSET % sizeof (ptrdiff_t) == 0 \
1803 ? NBYTES \ 1804 ? NBYTES \
1804 : max (NBYTES, sizeof (EMACS_INT) - 1)) \ 1805 : max (NBYTES, sizeof (ptrdiff_t) - 1)) \
1805 + 1 \ 1806 + 1 \
1806 + sizeof (EMACS_INT) - 1) \ 1807 + sizeof (ptrdiff_t) - 1) \
1807 & ~(sizeof (EMACS_INT) - 1)) 1808 & ~(sizeof (ptrdiff_t) - 1))
1808 1809
1809#endif /* not GC_CHECK_STRING_BYTES */ 1810#endif /* not GC_CHECK_STRING_BYTES */
1810 1811
@@ -1848,10 +1849,10 @@ static int check_string_bytes_count;
1848 1849
1849/* Like GC_STRING_BYTES, but with debugging check. */ 1850/* Like GC_STRING_BYTES, but with debugging check. */
1850 1851
1851EMACS_INT 1852ptrdiff_t
1852string_bytes (struct Lisp_String *s) 1853string_bytes (struct Lisp_String *s)
1853{ 1854{
1854 EMACS_INT nbytes = 1855 ptrdiff_t nbytes =
1855 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte); 1856 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
1856 1857
1857 if (!PURE_POINTER_P (s) 1858 if (!PURE_POINTER_P (s)
@@ -1874,7 +1875,7 @@ check_sblock (struct sblock *b)
1874 { 1875 {
1875 /* Compute the next FROM here because copying below may 1876 /* Compute the next FROM here because copying below may
1876 overwrite data we need to compute it. */ 1877 overwrite data we need to compute it. */
1877 EMACS_INT nbytes; 1878 ptrdiff_t nbytes;
1878 1879
1879 /* Check that the string size recorded in the string is the 1880 /* Check that the string size recorded in the string is the
1880 same as the one recorded in the sdata structure. */ 1881 same as the one recorded in the sdata structure. */
@@ -2020,7 +2021,7 @@ allocate_string_data (struct Lisp_String *s,
2020{ 2021{
2021 struct sdata *data, *old_data; 2022 struct sdata *data, *old_data;
2022 struct sblock *b; 2023 struct sblock *b;
2023 EMACS_INT needed, old_nbytes; 2024 ptrdiff_t needed, old_nbytes;
2024 2025
2025 if (STRING_BYTES_MAX < nbytes) 2026 if (STRING_BYTES_MAX < nbytes)
2026 string_overflow (); 2027 string_overflow ();
@@ -2265,7 +2266,7 @@ compact_small_strings (void)
2265 { 2266 {
2266 /* Compute the next FROM here because copying below may 2267 /* Compute the next FROM here because copying below may
2267 overwrite data we need to compute it. */ 2268 overwrite data we need to compute it. */
2268 EMACS_INT nbytes; 2269 ptrdiff_t nbytes;
2269 2270
2270#ifdef GC_CHECK_STRING_BYTES 2271#ifdef GC_CHECK_STRING_BYTES
2271 /* Check that the string size recorded in the string is the 2272 /* Check that the string size recorded in the string is the
@@ -2395,7 +2396,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2395{ 2396{
2396 register Lisp_Object val; 2397 register Lisp_Object val;
2397 struct Lisp_Bool_Vector *p; 2398 struct Lisp_Bool_Vector *p;
2398 EMACS_INT length_in_chars, length_in_elts; 2399 ptrdiff_t length_in_chars;
2400 EMACS_INT length_in_elts;
2399 int bits_per_value; 2401 int bits_per_value;
2400 2402
2401 CHECK_NATNUM (length); 2403 CHECK_NATNUM (length);
@@ -2403,8 +2405,6 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2403 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR; 2405 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR;
2404 2406
2405 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; 2407 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value;
2406 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2407 / BOOL_VECTOR_BITS_PER_CHAR);
2408 2408
2409 /* We must allocate one more elements than LENGTH_IN_ELTS for the 2409 /* We must allocate one more elements than LENGTH_IN_ELTS for the
2410 slot `size' of the struct Lisp_Bool_Vector. */ 2410 slot `size' of the struct Lisp_Bool_Vector. */
@@ -2416,6 +2416,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2416 p = XBOOL_VECTOR (val); 2416 p = XBOOL_VECTOR (val);
2417 p->size = XFASTINT (length); 2417 p->size = XFASTINT (length);
2418 2418
2419 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2420 / BOOL_VECTOR_BITS_PER_CHAR);
2419 if (length_in_chars) 2421 if (length_in_chars)
2420 { 2422 {
2421 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars); 2423 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars);
@@ -2434,10 +2436,10 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2434 multibyte, depending on the contents. */ 2436 multibyte, depending on the contents. */
2435 2437
2436Lisp_Object 2438Lisp_Object
2437make_string (const char *contents, EMACS_INT nbytes) 2439make_string (const char *contents, ptrdiff_t nbytes)
2438{ 2440{
2439 register Lisp_Object val; 2441 register Lisp_Object val;
2440 EMACS_INT nchars, multibyte_nbytes; 2442 ptrdiff_t nchars, multibyte_nbytes;
2441 2443
2442 parse_str_as_multibyte ((const unsigned char *) contents, nbytes, 2444 parse_str_as_multibyte ((const unsigned char *) contents, nbytes,
2443 &nchars, &multibyte_nbytes); 2445 &nchars, &multibyte_nbytes);
@@ -2454,7 +2456,7 @@ make_string (const char *contents, EMACS_INT nbytes)
2454/* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2456/* Make an unibyte string from LENGTH bytes at CONTENTS. */
2455 2457
2456Lisp_Object 2458Lisp_Object
2457make_unibyte_string (const char *contents, EMACS_INT length) 2459make_unibyte_string (const char *contents, ptrdiff_t length)
2458{ 2460{
2459 register Lisp_Object val; 2461 register Lisp_Object val;
2460 val = make_uninit_string (length); 2462 val = make_uninit_string (length);
@@ -2468,7 +2470,7 @@ make_unibyte_string (const char *contents, EMACS_INT length)
2468 2470
2469Lisp_Object 2471Lisp_Object
2470make_multibyte_string (const char *contents, 2472make_multibyte_string (const char *contents,
2471 EMACS_INT nchars, EMACS_INT nbytes) 2473 ptrdiff_t nchars, ptrdiff_t nbytes)
2472{ 2474{
2473 register Lisp_Object val; 2475 register Lisp_Object val;
2474 val = make_uninit_multibyte_string (nchars, nbytes); 2476 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2482,7 +2484,7 @@ make_multibyte_string (const char *contents,
2482 2484
2483Lisp_Object 2485Lisp_Object
2484make_string_from_bytes (const char *contents, 2486make_string_from_bytes (const char *contents,
2485 EMACS_INT nchars, EMACS_INT nbytes) 2487 ptrdiff_t nchars, ptrdiff_t nbytes)
2486{ 2488{
2487 register Lisp_Object val; 2489 register Lisp_Object val;
2488 val = make_uninit_multibyte_string (nchars, nbytes); 2490 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2500,7 +2502,7 @@ make_string_from_bytes (const char *contents,
2500 2502
2501Lisp_Object 2503Lisp_Object
2502make_specified_string (const char *contents, 2504make_specified_string (const char *contents,
2503 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 2505 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
2504{ 2506{
2505 register Lisp_Object val; 2507 register Lisp_Object val;
2506 2508
@@ -2939,7 +2941,7 @@ enum
2939 with room for LEN Lisp_Objects. */ 2941 with room for LEN Lisp_Objects. */
2940 2942
2941static struct Lisp_Vector * 2943static struct Lisp_Vector *
2942allocate_vectorlike (EMACS_INT len) 2944allocate_vectorlike (ptrdiff_t len)
2943{ 2945{
2944 struct Lisp_Vector *p; 2946 struct Lisp_Vector *p;
2945 size_t nbytes; 2947 size_t nbytes;
@@ -2995,7 +2997,7 @@ allocate_vector (EMACS_INT len)
2995/* Allocate other vector-like structures. */ 2997/* Allocate other vector-like structures. */
2996 2998
2997struct Lisp_Vector * 2999struct Lisp_Vector *
2998allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag) 3000allocate_pseudovector (int memlen, int lisplen, int tag)
2999{ 3001{
3000 struct Lisp_Vector *v = allocate_vectorlike (memlen); 3002 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3001 int i; 3003 int i;
@@ -3059,14 +3061,14 @@ See also the function `vector'. */)
3059 (register Lisp_Object length, Lisp_Object init) 3061 (register Lisp_Object length, Lisp_Object init)
3060{ 3062{
3061 Lisp_Object vector; 3063 Lisp_Object vector;
3062 register EMACS_INT sizei; 3064 register ptrdiff_t sizei;
3063 register EMACS_INT i; 3065 register ptrdiff_t i;
3064 register struct Lisp_Vector *p; 3066 register struct Lisp_Vector *p;
3065 3067
3066 CHECK_NATNUM (length); 3068 CHECK_NATNUM (length);
3067 sizei = XFASTINT (length);
3068 3069
3069 p = allocate_vector (sizei); 3070 p = allocate_vector (XFASTINT (length));
3071 sizei = XFASTINT (length);
3070 for (i = 0; i < sizei; i++) 3072 for (i = 0; i < sizei; i++)
3071 p->contents[i] = init; 3073 p->contents[i] = init;
3072 3074
@@ -4791,14 +4793,14 @@ check_pure_size (void)
4791 address. Return NULL if not found. */ 4793 address. Return NULL if not found. */
4792 4794
4793static char * 4795static char *
4794find_string_data_in_pure (const char *data, EMACS_INT nbytes) 4796find_string_data_in_pure (const char *data, ptrdiff_t nbytes)
4795{ 4797{
4796 int i; 4798 int i;
4797 EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4799 ptrdiff_t skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4798 const unsigned char *p; 4800 const unsigned char *p;
4799 char *non_lisp_beg; 4801 char *non_lisp_beg;
4800 4802
4801 if (pure_bytes_used_non_lisp < nbytes + 1) 4803 if (pure_bytes_used_non_lisp <= nbytes)
4802 return NULL; 4804 return NULL;
4803 4805
4804 /* Set up the Boyer-Moore table. */ 4806 /* Set up the Boyer-Moore table. */
@@ -4862,7 +4864,7 @@ find_string_data_in_pure (const char *data, EMACS_INT nbytes)
4862 4864
4863Lisp_Object 4865Lisp_Object
4864make_pure_string (const char *data, 4866make_pure_string (const char *data,
4865 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 4867 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
4866{ 4868{
4867 Lisp_Object string; 4869 Lisp_Object string;
4868 struct Lisp_String *s; 4870 struct Lisp_String *s;
@@ -4890,7 +4892,7 @@ make_pure_c_string (const char *data)
4890{ 4892{
4891 Lisp_Object string; 4893 Lisp_Object string;
4892 struct Lisp_String *s; 4894 struct Lisp_String *s;
4893 EMACS_INT nchars = strlen (data); 4895 ptrdiff_t nchars = strlen (data);
4894 4896
4895 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4897 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4896 s->size = nchars; 4898 s->size = nchars;
@@ -4936,8 +4938,8 @@ make_pure_float (double num)
4936/* Return a vector with room for LEN Lisp_Objects allocated from 4938/* Return a vector with room for LEN Lisp_Objects allocated from
4937 pure space. */ 4939 pure space. */
4938 4940
4939Lisp_Object 4941static Lisp_Object
4940make_pure_vector (EMACS_INT len) 4942make_pure_vector (ptrdiff_t len)
4941{ 4943{
4942 Lisp_Object new; 4944 Lisp_Object new;
4943 struct Lisp_Vector *p; 4945 struct Lisp_Vector *p;
@@ -4981,8 +4983,8 @@ Does not copy symbols. Copies strings without text properties. */)
4981 else if (COMPILEDP (obj) || VECTORP (obj)) 4983 else if (COMPILEDP (obj) || VECTORP (obj))
4982 { 4984 {
4983 register struct Lisp_Vector *vec; 4985 register struct Lisp_Vector *vec;
4984 register EMACS_INT i; 4986 register ptrdiff_t i;
4985 EMACS_INT size; 4987 ptrdiff_t size;
4986 4988
4987 size = ASIZE (obj); 4989 size = ASIZE (obj);
4988 if (size & PSEUDOVECTOR_FLAG) 4990 if (size & PSEUDOVECTOR_FLAG)
@@ -5034,10 +5036,10 @@ staticpro (Lisp_Object *varaddress)
5034 5036
5035/* Temporarily prevent garbage collection. */ 5037/* Temporarily prevent garbage collection. */
5036 5038
5037int 5039ptrdiff_t
5038inhibit_garbage_collection (void) 5040inhibit_garbage_collection (void)
5039{ 5041{
5040 int count = SPECPDL_INDEX (); 5042 ptrdiff_t count = SPECPDL_INDEX ();
5041 5043
5042 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM)); 5044 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM));
5043 return count; 5045 return count;
@@ -5063,7 +5065,7 @@ See Info node `(elisp)Garbage Collection'. */)
5063 ptrdiff_t i; 5065 ptrdiff_t i;
5064 int message_p; 5066 int message_p;
5065 Lisp_Object total[8]; 5067 Lisp_Object total[8];
5066 int count = SPECPDL_INDEX (); 5068 ptrdiff_t count = SPECPDL_INDEX ();
5067 EMACS_TIME t1, t2, t3; 5069 EMACS_TIME t1, t2, t3;
5068 5070
5069 if (abort_on_gc) 5071 if (abort_on_gc)
@@ -5358,7 +5360,7 @@ See Info node `(elisp)Garbage Collection'. */)
5358 5360
5359 if (!NILP (Vpost_gc_hook)) 5361 if (!NILP (Vpost_gc_hook))
5360 { 5362 {
5361 int gc_count = inhibit_garbage_collection (); 5363 ptrdiff_t gc_count = inhibit_garbage_collection ();
5362 safe_run_hooks (Qpost_gc_hook); 5364 safe_run_hooks (Qpost_gc_hook);
5363 unbind_to (gc_count, Qnil); 5365 unbind_to (gc_count, Qnil);
5364 } 5366 }
@@ -5443,8 +5445,8 @@ ptrdiff_t mark_object_loop_halt EXTERNALLY_VISIBLE;
5443static void 5445static void
5444mark_vectorlike (struct Lisp_Vector *ptr) 5446mark_vectorlike (struct Lisp_Vector *ptr)
5445{ 5447{
5446 EMACS_INT size = ptr->header.size; 5448 ptrdiff_t size = ptr->header.size;
5447 EMACS_INT i; 5449 ptrdiff_t i;
5448 5450
5449 eassert (!VECTOR_MARKED_P (ptr)); 5451 eassert (!VECTOR_MARKED_P (ptr));
5450 VECTOR_MARK (ptr); /* Else mark it */ 5452 VECTOR_MARK (ptr); /* Else mark it */
@@ -6325,7 +6327,7 @@ Lisp_Object
6325which_symbols (Lisp_Object obj, EMACS_INT find_max) 6327which_symbols (Lisp_Object obj, EMACS_INT find_max)
6326{ 6328{
6327 struct symbol_block *sblk; 6329 struct symbol_block *sblk;
6328 int gc_count = inhibit_garbage_collection (); 6330 ptrdiff_t gc_count = inhibit_garbage_collection ();
6329 Lisp_Object found = Qnil; 6331 Lisp_Object found = Qnil;
6330 6332
6331 if (! DEADP (obj)) 6333 if (! DEADP (obj))
diff --git a/src/bidi.c b/src/bidi.c
index b3479b17b16..7a716d3f0b0 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -204,8 +204,16 @@ bidi_mirror_char (int c)
204 val = CHAR_TABLE_REF (bidi_mirror_table, c); 204 val = CHAR_TABLE_REF (bidi_mirror_table, c);
205 if (INTEGERP (val)) 205 if (INTEGERP (val))
206 { 206 {
207 int v = XINT (val); 207 int v;
208 208
209 /* When debugging, check before assigning to V, so that the check
210 isn't broken by undefined behavior due to int overflow. */
211 eassert (CHAR_VALID_P (XINT (val)));
212
213 v = XINT (val);
214
215 /* Minimal test we must do in optimized builds, to prevent weird
216 crashes further down the road. */
209 if (v < 0 || v > MAX_CHAR) 217 if (v < 0 || v > MAX_CHAR)
210 abort (); 218 abort ();
211 219
@@ -378,7 +386,7 @@ bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it)
378 resolved levels in cached states. DIR, if non-zero, means search 386 resolved levels in cached states. DIR, if non-zero, means search
379 in that direction from the last cache hit. */ 387 in that direction from the last cache hit. */
380static inline ptrdiff_t 388static inline ptrdiff_t
381bidi_cache_search (EMACS_INT charpos, int level, int dir) 389bidi_cache_search (ptrdiff_t charpos, int level, int dir)
382{ 390{
383 ptrdiff_t i, i_start; 391 ptrdiff_t i, i_start;
384 392
@@ -562,7 +570,7 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved)
562} 570}
563 571
564static inline bidi_type_t 572static inline bidi_type_t
565bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) 573bidi_cache_find (ptrdiff_t charpos, int level, struct bidi_it *bidi_it)
566{ 574{
567 ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir); 575 ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir);
568 576
@@ -795,7 +803,7 @@ bidi_set_paragraph_end (struct bidi_it *bidi_it)
795 803
796/* Initialize the bidi iterator from buffer/string position CHARPOS. */ 804/* Initialize the bidi iterator from buffer/string position CHARPOS. */
797void 805void
798bidi_init_it (EMACS_INT charpos, EMACS_INT bytepos, int frame_window_p, 806bidi_init_it (ptrdiff_t charpos, ptrdiff_t bytepos, int frame_window_p,
799 struct bidi_it *bidi_it) 807 struct bidi_it *bidi_it)
800{ 808{
801 if (! bidi_initialized) 809 if (! bidi_initialized)
@@ -867,11 +875,11 @@ bidi_line_init (struct bidi_it *bidi_it)
867 are zero-based character positions in S, BEGBYTE is byte position 875 are zero-based character positions in S, BEGBYTE is byte position
868 corresponding to BEG. UNIBYTE, if non-zero, means S is a unibyte 876 corresponding to BEG. UNIBYTE, if non-zero, means S is a unibyte
869 string. */ 877 string. */
870static inline EMACS_INT 878static inline ptrdiff_t
871bidi_count_bytes (const unsigned char *s, const EMACS_INT beg, 879bidi_count_bytes (const unsigned char *s, const ptrdiff_t beg,
872 const EMACS_INT begbyte, const EMACS_INT end, int unibyte) 880 const ptrdiff_t begbyte, const ptrdiff_t end, int unibyte)
873{ 881{
874 EMACS_INT pos = beg; 882 ptrdiff_t pos = beg;
875 const unsigned char *p = s + begbyte, *start = p; 883 const unsigned char *p = s + begbyte, *start = p;
876 884
877 if (unibyte) 885 if (unibyte)
@@ -896,7 +904,7 @@ bidi_count_bytes (const unsigned char *s, const EMACS_INT beg,
896 character from the current buffer. UNIBYTE non-zero means S is a 904 character from the current buffer. UNIBYTE non-zero means S is a
897 unibyte string. */ 905 unibyte string. */
898static inline int 906static inline int
899bidi_char_at_pos (EMACS_INT bytepos, const unsigned char *s, int unibyte) 907bidi_char_at_pos (ptrdiff_t bytepos, const unsigned char *s, int unibyte)
900{ 908{
901 if (s) 909 if (s)
902 { 910 {
@@ -924,12 +932,12 @@ bidi_char_at_pos (EMACS_INT bytepos, const unsigned char *s, int unibyte)
924 string to iterate, or NULL if iterating over a buffer or a Lisp 932 string to iterate, or NULL if iterating over a buffer or a Lisp
925 string; in the latter case, STRING->lstring is the Lisp string. */ 933 string; in the latter case, STRING->lstring is the Lisp string. */
926static inline int 934static inline int
927bidi_fetch_char (EMACS_INT bytepos, EMACS_INT charpos, EMACS_INT *disp_pos, 935bidi_fetch_char (ptrdiff_t bytepos, ptrdiff_t charpos, ptrdiff_t *disp_pos,
928 int *disp_prop, struct bidi_string_data *string, 936 int *disp_prop, struct bidi_string_data *string,
929 int frame_window_p, EMACS_INT *ch_len, EMACS_INT *nchars) 937 int frame_window_p, ptrdiff_t *ch_len, ptrdiff_t *nchars)
930{ 938{
931 int ch; 939 int ch;
932 EMACS_INT endpos 940 ptrdiff_t endpos
933 = (string->s || STRINGP (string->lstring)) ? string->schars : ZV; 941 = (string->s || STRINGP (string->lstring)) ? string->schars : ZV;
934 struct text_pos pos; 942 struct text_pos pos;
935 int len; 943 int len;
@@ -954,7 +962,7 @@ bidi_fetch_char (EMACS_INT bytepos, EMACS_INT charpos, EMACS_INT *disp_pos,
954 } 962 }
955 else if (charpos >= *disp_pos && *disp_prop) 963 else if (charpos >= *disp_pos && *disp_prop)
956 { 964 {
957 EMACS_INT disp_end_pos; 965 ptrdiff_t disp_end_pos;
958 966
959 /* We don't expect to find ourselves in the middle of a display 967 /* We don't expect to find ourselves in the middle of a display
960 property. Hopefully, it will never be needed. */ 968 property. Hopefully, it will never be needed. */
@@ -1061,12 +1069,12 @@ bidi_fetch_char (EMACS_INT bytepos, EMACS_INT charpos, EMACS_INT *disp_pos,
1061 following the buffer position, -1 if position is at the beginning 1069 following the buffer position, -1 if position is at the beginning
1062 of a new paragraph, or -2 if position is neither at beginning nor 1070 of a new paragraph, or -2 if position is neither at beginning nor
1063 at end of a paragraph. */ 1071 at end of a paragraph. */
1064static EMACS_INT 1072static ptrdiff_t
1065bidi_at_paragraph_end (EMACS_INT charpos, EMACS_INT bytepos) 1073bidi_at_paragraph_end (ptrdiff_t charpos, ptrdiff_t bytepos)
1066{ 1074{
1067 Lisp_Object sep_re; 1075 Lisp_Object sep_re;
1068 Lisp_Object start_re; 1076 Lisp_Object start_re;
1069 EMACS_INT val; 1077 ptrdiff_t val;
1070 1078
1071 sep_re = paragraph_separate_re; 1079 sep_re = paragraph_separate_re;
1072 start_re = paragraph_start_re; 1080 start_re = paragraph_start_re;
@@ -1093,12 +1101,12 @@ bidi_at_paragraph_end (EMACS_INT charpos, EMACS_INT bytepos)
1093 Value is the byte position of the paragraph's beginning, or 1101 Value is the byte position of the paragraph's beginning, or
1094 BEGV_BYTE if paragraph_start_re is still not found after looking 1102 BEGV_BYTE if paragraph_start_re is still not found after looking
1095 back MAX_PARAGRAPH_SEARCH lines in the buffer. */ 1103 back MAX_PARAGRAPH_SEARCH lines in the buffer. */
1096static EMACS_INT 1104static ptrdiff_t
1097bidi_find_paragraph_start (EMACS_INT pos, EMACS_INT pos_byte) 1105bidi_find_paragraph_start (ptrdiff_t pos, ptrdiff_t pos_byte)
1098{ 1106{
1099 Lisp_Object re = paragraph_start_re; 1107 Lisp_Object re = paragraph_start_re;
1100 EMACS_INT limit = ZV, limit_byte = ZV_BYTE; 1108 ptrdiff_t limit = ZV, limit_byte = ZV_BYTE;
1101 EMACS_INT n = 0; 1109 ptrdiff_t n = 0;
1102 1110
1103 while (pos_byte > BEGV_BYTE 1111 while (pos_byte > BEGV_BYTE
1104 && n++ < MAX_PARAGRAPH_SEARCH 1112 && n++ < MAX_PARAGRAPH_SEARCH
@@ -1134,14 +1142,14 @@ bidi_find_paragraph_start (EMACS_INT pos, EMACS_INT pos_byte)
1134void 1142void
1135bidi_paragraph_init (bidi_dir_t dir, struct bidi_it *bidi_it, int no_default_p) 1143bidi_paragraph_init (bidi_dir_t dir, struct bidi_it *bidi_it, int no_default_p)
1136{ 1144{
1137 EMACS_INT bytepos = bidi_it->bytepos; 1145 ptrdiff_t bytepos = bidi_it->bytepos;
1138 int string_p = bidi_it->string.s != NULL || STRINGP (bidi_it->string.lstring); 1146 int string_p = bidi_it->string.s != NULL || STRINGP (bidi_it->string.lstring);
1139 EMACS_INT pstartbyte; 1147 ptrdiff_t pstartbyte;
1140 /* Note that begbyte is a byte position, while end is a character 1148 /* Note that begbyte is a byte position, while end is a character
1141 position. Yes, this is ugly, but we are trying to avoid costly 1149 position. Yes, this is ugly, but we are trying to avoid costly
1142 calls to BYTE_TO_CHAR and its ilk. */ 1150 calls to BYTE_TO_CHAR and its ilk. */
1143 EMACS_INT begbyte = string_p ? 0 : BEGV_BYTE; 1151 ptrdiff_t begbyte = string_p ? 0 : BEGV_BYTE;
1144 EMACS_INT end = string_p ? bidi_it->string.schars : ZV; 1152 ptrdiff_t end = string_p ? bidi_it->string.schars : ZV;
1145 1153
1146 /* Special case for an empty buffer. */ 1154 /* Special case for an empty buffer. */
1147 if (bytepos == begbyte && bidi_it->charpos == end) 1155 if (bytepos == begbyte && bidi_it->charpos == end)
@@ -1163,8 +1171,8 @@ bidi_paragraph_init (bidi_dir_t dir, struct bidi_it *bidi_it, int no_default_p)
1163 else if (dir == NEUTRAL_DIR) /* P2 */ 1171 else if (dir == NEUTRAL_DIR) /* P2 */
1164 { 1172 {
1165 int ch; 1173 int ch;
1166 EMACS_INT ch_len, nchars; 1174 ptrdiff_t ch_len, nchars;
1167 EMACS_INT pos, disp_pos = -1; 1175 ptrdiff_t pos, disp_pos = -1;
1168 int disp_prop = 0; 1176 int disp_prop = 0;
1169 bidi_type_t type; 1177 bidi_type_t type;
1170 const unsigned char *s; 1178 const unsigned char *s;
@@ -1260,8 +1268,8 @@ bidi_paragraph_init (bidi_dir_t dir, struct bidi_it *bidi_it, int no_default_p)
1260 bidi_it->paragraph_dir = L2R; /* P3 and HL1 */ 1268 bidi_it->paragraph_dir = L2R; /* P3 and HL1 */
1261 else 1269 else
1262 { 1270 {
1263 EMACS_INT prevpbyte = pstartbyte; 1271 ptrdiff_t prevpbyte = pstartbyte;
1264 EMACS_INT p = BYTE_TO_CHAR (pstartbyte), pbyte = pstartbyte; 1272 ptrdiff_t p = BYTE_TO_CHAR (pstartbyte), pbyte = pstartbyte;
1265 1273
1266 /* Find the beginning of the previous paragraph, if any. */ 1274 /* Find the beginning of the previous paragraph, if any. */
1267 while (pbyte > BEGV_BYTE && prevpbyte >= pstartbyte) 1275 while (pbyte > BEGV_BYTE && prevpbyte >= pstartbyte)
@@ -1525,7 +1533,7 @@ bidi_resolve_explicit (struct bidi_it *bidi_it)
1525{ 1533{
1526 int prev_level = bidi_it->level_stack[bidi_it->stack_idx].level; 1534 int prev_level = bidi_it->level_stack[bidi_it->stack_idx].level;
1527 int new_level = bidi_resolve_explicit_1 (bidi_it); 1535 int new_level = bidi_resolve_explicit_1 (bidi_it);
1528 EMACS_INT eob = bidi_it->string.s ? bidi_it->string.schars : ZV; 1536 ptrdiff_t eob = bidi_it->string.s ? bidi_it->string.schars : ZV;
1529 const unsigned char *s 1537 const unsigned char *s
1530 = (STRINGP (bidi_it->string.lstring) 1538 = (STRINGP (bidi_it->string.lstring)
1531 ? SDATA (bidi_it->string.lstring) 1539 ? SDATA (bidi_it->string.lstring)
@@ -1613,7 +1621,7 @@ bidi_resolve_weak (struct bidi_it *bidi_it)
1613 int next_char; 1621 int next_char;
1614 bidi_type_t type_of_next; 1622 bidi_type_t type_of_next;
1615 struct bidi_it saved_it; 1623 struct bidi_it saved_it;
1616 EMACS_INT eob 1624 ptrdiff_t eob
1617 = ((STRINGP (bidi_it->string.lstring) || bidi_it->string.s) 1625 = ((STRINGP (bidi_it->string.lstring) || bidi_it->string.s)
1618 ? bidi_it->string.schars : ZV); 1626 ? bidi_it->string.schars : ZV);
1619 1627
@@ -1743,7 +1751,7 @@ bidi_resolve_weak (struct bidi_it *bidi_it)
1743 } 1751 }
1744 else if (bidi_it->next_en_pos >=0) 1752 else if (bidi_it->next_en_pos >=0)
1745 { 1753 {
1746 EMACS_INT en_pos = bidi_it->charpos + bidi_it->nchars; 1754 ptrdiff_t en_pos = bidi_it->charpos + bidi_it->nchars;
1747 const unsigned char *s = (STRINGP (bidi_it->string.lstring) 1755 const unsigned char *s = (STRINGP (bidi_it->string.lstring)
1748 ? SDATA (bidi_it->string.lstring) 1756 ? SDATA (bidi_it->string.lstring)
1749 : bidi_it->string.s); 1757 : bidi_it->string.s);
@@ -2030,11 +2038,11 @@ bidi_level_of_next_char (struct bidi_it *bidi_it)
2030 bidi_type_t type; 2038 bidi_type_t type;
2031 int level, prev_level = -1; 2039 int level, prev_level = -1;
2032 struct bidi_saved_info next_for_neutral; 2040 struct bidi_saved_info next_for_neutral;
2033 EMACS_INT next_char_pos = -2; 2041 ptrdiff_t next_char_pos = -2;
2034 2042
2035 if (bidi_it->scan_dir == 1) 2043 if (bidi_it->scan_dir == 1)
2036 { 2044 {
2037 EMACS_INT eob 2045 ptrdiff_t eob
2038 = ((bidi_it->string.s || STRINGP (bidi_it->string.lstring)) 2046 = ((bidi_it->string.s || STRINGP (bidi_it->string.lstring))
2039 ? bidi_it->string.schars : ZV); 2047 ? bidi_it->string.schars : ZV);
2040 2048
@@ -2163,11 +2171,11 @@ bidi_level_of_next_char (struct bidi_it *bidi_it)
2163 && bidi_it->next_for_ws.type == UNKNOWN_BT) 2171 && bidi_it->next_for_ws.type == UNKNOWN_BT)
2164 { 2172 {
2165 int ch; 2173 int ch;
2166 EMACS_INT clen = bidi_it->ch_len; 2174 ptrdiff_t clen = bidi_it->ch_len;
2167 EMACS_INT bpos = bidi_it->bytepos; 2175 ptrdiff_t bpos = bidi_it->bytepos;
2168 EMACS_INT cpos = bidi_it->charpos; 2176 ptrdiff_t cpos = bidi_it->charpos;
2169 EMACS_INT disp_pos = bidi_it->disp_pos; 2177 ptrdiff_t disp_pos = bidi_it->disp_pos;
2170 EMACS_INT nc = bidi_it->nchars; 2178 ptrdiff_t nc = bidi_it->nchars;
2171 struct bidi_string_data bs = bidi_it->string; 2179 struct bidi_string_data bs = bidi_it->string;
2172 bidi_type_t chtype; 2180 bidi_type_t chtype;
2173 int fwp = bidi_it->frame_window_p; 2181 int fwp = bidi_it->frame_window_p;
@@ -2409,7 +2417,7 @@ bidi_move_to_visually_next (struct bidi_it *bidi_it)
2409 bidi_it->separator_limit = bidi_it->string.schars; 2417 bidi_it->separator_limit = bidi_it->string.schars;
2410 else if (bidi_it->bytepos < ZV_BYTE) 2418 else if (bidi_it->bytepos < ZV_BYTE)
2411 { 2419 {
2412 EMACS_INT sep_len 2420 ptrdiff_t sep_len
2413 = bidi_at_paragraph_end (bidi_it->charpos + bidi_it->nchars, 2421 = bidi_at_paragraph_end (bidi_it->charpos + bidi_it->nchars,
2414 bidi_it->bytepos + bidi_it->ch_len); 2422 bidi_it->bytepos + bidi_it->ch_len);
2415 if (bidi_it->nchars <= 0) 2423 if (bidi_it->nchars <= 0)
@@ -2475,6 +2483,6 @@ bidi_dump_cached_states (void)
2475 fputs ("\n", stderr); 2483 fputs ("\n", stderr);
2476 fputs ("pos ", stderr); 2484 fputs ("pos ", stderr);
2477 for (i = 0; i < bidi_cache_idx; i++) 2485 for (i = 0; i < bidi_cache_idx; i++)
2478 fprintf (stderr, "%*"pI"d", ndigits, bidi_cache[i].charpos); 2486 fprintf (stderr, "%*"pD"d", ndigits, bidi_cache[i].charpos);
2479 fputs ("\n", stderr); 2487 fputs ("\n", stderr);
2480} 2488}
diff --git a/src/buffer.c b/src/buffer.c
index 4dcdf7bae69..20260d5a5d8 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -154,7 +154,7 @@ Lisp_Object Qinsert_behind_hooks;
154static void alloc_buffer_text (struct buffer *, ptrdiff_t); 154static void alloc_buffer_text (struct buffer *, ptrdiff_t);
155static void free_buffer_text (struct buffer *b); 155static void free_buffer_text (struct buffer *b);
156static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); 156static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *);
157static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); 157static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
158static Lisp_Object buffer_lisp_local_variables (struct buffer *); 158static Lisp_Object buffer_lisp_local_variables (struct buffer *);
159 159
160/* For debugging; temporary. See set_buffer_internal. */ 160/* For debugging; temporary. See set_buffer_internal. */
@@ -418,7 +418,7 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
418 for (; list; list = list->next) 418 for (; list; list = list->next)
419 { 419 {
420 Lisp_Object overlay, start, end, old_overlay; 420 Lisp_Object overlay, start, end, old_overlay;
421 EMACS_INT charpos; 421 ptrdiff_t charpos;
422 422
423 XSETMISC (old_overlay, list); 423 XSETMISC (old_overlay, list);
424 charpos = marker_position (OVERLAY_START (old_overlay)); 424 charpos = marker_position (OVERLAY_START (old_overlay));
@@ -852,8 +852,8 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
852 (register Lisp_Object name, Lisp_Object ignore) 852 (register Lisp_Object name, Lisp_Object ignore)
853{ 853{
854 register Lisp_Object gentemp, tem; 854 register Lisp_Object gentemp, tem;
855 EMACS_INT count; 855 ptrdiff_t count;
856 char number[INT_BUFSIZE_BOUND (EMACS_INT) + sizeof "<>"]; 856 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
857 857
858 CHECK_STRING (name); 858 CHECK_STRING (name);
859 859
@@ -867,7 +867,7 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
867 count = 1; 867 count = 1;
868 while (1) 868 while (1)
869 { 869 {
870 sprintf (number, "<%"pI"d>", ++count); 870 sprintf (number, "<%"pD"d>", ++count);
871 gentemp = concat2 (name, build_string (number)); 871 gentemp = concat2 (name, build_string (number));
872 tem = Fstring_equal (gentemp, ignore); 872 tem = Fstring_equal (gentemp, ignore);
873 if (!NILP (tem)) 873 if (!NILP (tem))
@@ -1475,7 +1475,7 @@ with SIGHUP. */)
1475 1475
1476 /* Run hooks with the buffer to be killed the current buffer. */ 1476 /* Run hooks with the buffer to be killed the current buffer. */
1477 { 1477 {
1478 int count = SPECPDL_INDEX (); 1478 ptrdiff_t count = SPECPDL_INDEX ();
1479 Lisp_Object arglist[1]; 1479 Lisp_Object arglist[1];
1480 1480
1481 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1481 record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -1751,7 +1751,7 @@ Use this function before selecting the buffer, since it may need to inspect
1751the current buffer's major mode. */) 1751the current buffer's major mode. */)
1752 (Lisp_Object buffer) 1752 (Lisp_Object buffer)
1753{ 1753{
1754 int count; 1754 ptrdiff_t count;
1755 Lisp_Object function; 1755 Lisp_Object function;
1756 1756
1757 CHECK_BUFFER (buffer); 1757 CHECK_BUFFER (buffer);
@@ -1963,16 +1963,15 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1963 tem = *b; *b = *e; *e = tem; 1963 tem = *b; *b = *e; *e = tem;
1964 } 1964 }
1965 1965
1966 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) 1966 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
1967 && XINT (*e) <= ZV))
1968 args_out_of_range (*b, *e); 1967 args_out_of_range (*b, *e);
1969} 1968}
1970 1969
1971/* Advance BYTE_POS up to a character boundary 1970/* Advance BYTE_POS up to a character boundary
1972 and return the adjusted position. */ 1971 and return the adjusted position. */
1973 1972
1974static EMACS_INT 1973static ptrdiff_t
1975advance_to_char_boundary (EMACS_INT byte_pos) 1974advance_to_char_boundary (ptrdiff_t byte_pos)
1976{ 1975{
1977 int c; 1976 int c;
1978 1977
@@ -1985,7 +1984,7 @@ advance_to_char_boundary (EMACS_INT byte_pos)
1985 { 1984 {
1986 /* We should advance BYTE_POS only when C is a constituent of a 1985 /* We should advance BYTE_POS only when C is a constituent of a
1987 multibyte sequence. */ 1986 multibyte sequence. */
1988 EMACS_INT orig_byte_pos = byte_pos; 1987 ptrdiff_t orig_byte_pos = byte_pos;
1989 1988
1990 do 1989 do
1991 { 1990 {
@@ -2057,12 +2056,12 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2057 (void **) &current_buffer->own_text.beg); 2056 (void **) &current_buffer->own_text.beg);
2058#endif /* REL_ALLOC */ 2057#endif /* REL_ALLOC */
2059 2058
2060 swapfield (pt, EMACS_INT); 2059 swapfield (pt, ptrdiff_t);
2061 swapfield (pt_byte, EMACS_INT); 2060 swapfield (pt_byte, ptrdiff_t);
2062 swapfield (begv, EMACS_INT); 2061 swapfield (begv, ptrdiff_t);
2063 swapfield (begv_byte, EMACS_INT); 2062 swapfield (begv_byte, ptrdiff_t);
2064 swapfield (zv, EMACS_INT); 2063 swapfield (zv, ptrdiff_t);
2065 swapfield (zv_byte, EMACS_INT); 2064 swapfield (zv_byte, ptrdiff_t);
2066 eassert (!current_buffer->base_buffer); 2065 eassert (!current_buffer->base_buffer);
2067 eassert (!other_buffer->base_buffer); 2066 eassert (!other_buffer->base_buffer);
2068 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2067 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
@@ -2072,7 +2071,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2072 other_buffer->prevent_redisplay_optimizations_p = 1; 2071 other_buffer->prevent_redisplay_optimizations_p = 1;
2073 swapfield (overlays_before, struct Lisp_Overlay *); 2072 swapfield (overlays_before, struct Lisp_Overlay *);
2074 swapfield (overlays_after, struct Lisp_Overlay *); 2073 swapfield (overlays_after, struct Lisp_Overlay *);
2075 swapfield (overlay_center, EMACS_INT); 2074 swapfield (overlay_center, ptrdiff_t);
2076 swapfield_ (undo_list, Lisp_Object); 2075 swapfield_ (undo_list, Lisp_Object);
2077 swapfield_ (mark, Lisp_Object); 2076 swapfield_ (mark, Lisp_Object);
2078 swapfield_ (enable_multibyte_characters, Lisp_Object); 2077 swapfield_ (enable_multibyte_characters, Lisp_Object);
@@ -2155,7 +2154,7 @@ current buffer is cleared. */)
2155{ 2154{
2156 struct Lisp_Marker *tail, *markers; 2155 struct Lisp_Marker *tail, *markers;
2157 struct buffer *other; 2156 struct buffer *other;
2158 EMACS_INT begv, zv; 2157 ptrdiff_t begv, zv;
2159 int narrowed = (BEG != BEGV || Z != ZV); 2158 int narrowed = (BEG != BEGV || Z != ZV);
2160 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2159 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2161 Lisp_Object old_undo = BVAR (current_buffer, undo_list); 2160 Lisp_Object old_undo = BVAR (current_buffer, undo_list);
@@ -2187,7 +2186,7 @@ current buffer is cleared. */)
2187 2186
2188 if (NILP (flag)) 2187 if (NILP (flag))
2189 { 2188 {
2190 EMACS_INT pos, stop; 2189 ptrdiff_t pos, stop;
2191 unsigned char *p; 2190 unsigned char *p;
2192 2191
2193 /* Do this first, so it can use CHAR_TO_BYTE 2192 /* Do this first, so it can use CHAR_TO_BYTE
@@ -2251,8 +2250,8 @@ current buffer is cleared. */)
2251 } 2250 }
2252 else 2251 else
2253 { 2252 {
2254 EMACS_INT pt = PT; 2253 ptrdiff_t pt = PT;
2255 EMACS_INT pos, stop; 2254 ptrdiff_t pos, stop;
2256 unsigned char *p, *pend; 2255 unsigned char *p, *pend;
2257 2256
2258 /* Be sure not to have a multibyte sequence striding over the GAP. 2257 /* Be sure not to have a multibyte sequence striding over the GAP.
@@ -2268,7 +2267,7 @@ current buffer is cleared. */)
2268 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--; 2267 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--;
2269 if (LEADING_CODE_P (*q)) 2268 if (LEADING_CODE_P (*q))
2270 { 2269 {
2271 EMACS_INT new_gpt = GPT_BYTE - (GPT_ADDR - q); 2270 ptrdiff_t new_gpt = GPT_BYTE - (GPT_ADDR - q);
2272 2271
2273 move_gap_both (new_gpt, new_gpt); 2272 move_gap_both (new_gpt, new_gpt);
2274 } 2273 }
@@ -2352,8 +2351,8 @@ current buffer is cleared. */)
2352 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 2351 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
2353 2352
2354 { 2353 {
2355 EMACS_INT byte = advance_to_char_boundary (PT_BYTE); 2354 ptrdiff_t byte = advance_to_char_boundary (PT_BYTE);
2356 EMACS_INT position; 2355 ptrdiff_t position;
2357 2356
2358 if (byte > GPT_BYTE) 2357 if (byte > GPT_BYTE)
2359 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT; 2358 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT;
@@ -2517,20 +2516,20 @@ swap_out_buffer_local_variables (struct buffer *b)
2517ptrdiff_t 2516ptrdiff_t
2518overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 2517overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2519 ptrdiff_t *len_ptr, 2518 ptrdiff_t *len_ptr,
2520 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2519 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, int change_req)
2521{ 2520{
2522 Lisp_Object overlay, start, end; 2521 Lisp_Object overlay, start, end;
2523 struct Lisp_Overlay *tail; 2522 struct Lisp_Overlay *tail;
2524 ptrdiff_t idx = 0; 2523 ptrdiff_t idx = 0;
2525 ptrdiff_t len = *len_ptr; 2524 ptrdiff_t len = *len_ptr;
2526 Lisp_Object *vec = *vec_ptr; 2525 Lisp_Object *vec = *vec_ptr;
2527 EMACS_INT next = ZV; 2526 ptrdiff_t next = ZV;
2528 EMACS_INT prev = BEGV; 2527 ptrdiff_t prev = BEGV;
2529 int inhibit_storing = 0; 2528 int inhibit_storing = 0;
2530 2529
2531 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2530 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2532 { 2531 {
2533 EMACS_INT startpos, endpos; 2532 ptrdiff_t startpos, endpos;
2534 2533
2535 XSETMISC (overlay, tail); 2534 XSETMISC (overlay, tail);
2536 2535
@@ -2578,7 +2577,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2578 2577
2579 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2578 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2580 { 2579 {
2581 EMACS_INT startpos, endpos; 2580 ptrdiff_t startpos, endpos;
2582 2581
2583 XSETMISC (overlay, tail); 2582 XSETMISC (overlay, tail);
2584 2583
@@ -2651,21 +2650,21 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2651static ptrdiff_t 2650static ptrdiff_t
2652overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2651overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2653 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, 2652 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2654 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2653 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr)
2655{ 2654{
2656 Lisp_Object overlay, ostart, oend; 2655 Lisp_Object overlay, ostart, oend;
2657 struct Lisp_Overlay *tail; 2656 struct Lisp_Overlay *tail;
2658 ptrdiff_t idx = 0; 2657 ptrdiff_t idx = 0;
2659 ptrdiff_t len = *len_ptr; 2658 ptrdiff_t len = *len_ptr;
2660 Lisp_Object *vec = *vec_ptr; 2659 Lisp_Object *vec = *vec_ptr;
2661 EMACS_INT next = ZV; 2660 ptrdiff_t next = ZV;
2662 EMACS_INT prev = BEGV; 2661 ptrdiff_t prev = BEGV;
2663 int inhibit_storing = 0; 2662 int inhibit_storing = 0;
2664 int end_is_Z = end == Z; 2663 int end_is_Z = end == Z;
2665 2664
2666 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2665 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2667 { 2666 {
2668 EMACS_INT startpos, endpos; 2667 ptrdiff_t startpos, endpos;
2669 2668
2670 XSETMISC (overlay, tail); 2669 XSETMISC (overlay, tail);
2671 2670
@@ -2712,7 +2711,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2712 2711
2713 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2712 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2714 { 2713 {
2715 EMACS_INT startpos, endpos; 2714 ptrdiff_t startpos, endpos;
2716 2715
2717 XSETMISC (overlay, tail); 2716 XSETMISC (overlay, tail);
2718 2717
@@ -2768,8 +2767,8 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2768int 2767int
2769mouse_face_overlay_overlaps (Lisp_Object overlay) 2768mouse_face_overlay_overlaps (Lisp_Object overlay)
2770{ 2769{
2771 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 2770 ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay));
2772 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 2771 ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay));
2773 ptrdiff_t n, i, size; 2772 ptrdiff_t n, i, size;
2774 Lisp_Object *v, tem; 2773 Lisp_Object *v, tem;
2775 2774
@@ -2795,14 +2794,14 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2795 2794
2796/* Fast function to just test if we're at an overlay boundary. */ 2795/* Fast function to just test if we're at an overlay boundary. */
2797int 2796int
2798overlay_touches_p (EMACS_INT pos) 2797overlay_touches_p (ptrdiff_t pos)
2799{ 2798{
2800 Lisp_Object overlay; 2799 Lisp_Object overlay;
2801 struct Lisp_Overlay *tail; 2800 struct Lisp_Overlay *tail;
2802 2801
2803 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2802 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2804 { 2803 {
2805 EMACS_INT endpos; 2804 ptrdiff_t endpos;
2806 2805
2807 XSETMISC (overlay ,tail); 2806 XSETMISC (overlay ,tail);
2808 if (!OVERLAYP (overlay)) 2807 if (!OVERLAYP (overlay))
@@ -2817,7 +2816,7 @@ overlay_touches_p (EMACS_INT pos)
2817 2816
2818 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2817 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2819 { 2818 {
2820 EMACS_INT startpos; 2819 ptrdiff_t startpos;
2821 2820
2822 XSETMISC (overlay, tail); 2821 XSETMISC (overlay, tail);
2823 if (!OVERLAYP (overlay)) 2822 if (!OVERLAYP (overlay))
@@ -2835,7 +2834,7 @@ overlay_touches_p (EMACS_INT pos)
2835struct sortvec 2834struct sortvec
2836{ 2835{
2837 Lisp_Object overlay; 2836 Lisp_Object overlay;
2838 EMACS_INT beg, end; 2837 ptrdiff_t beg, end;
2839 EMACS_INT priority; 2838 EMACS_INT priority;
2840}; 2839};
2841 2840
@@ -2958,7 +2957,7 @@ static void
2958record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, 2957record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2959 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size) 2958 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2960{ 2959{
2961 EMACS_INT nbytes; 2960 ptrdiff_t nbytes;
2962 2961
2963 if (ssl->used == ssl->size) 2962 if (ssl->used == ssl->size)
2964 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); 2963 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
@@ -3008,12 +3007,12 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3008 PSTR, if that variable is non-null. The string may be overwritten by 3007 PSTR, if that variable is non-null. The string may be overwritten by
3009 subsequent calls. */ 3008 subsequent calls. */
3010 3009
3011EMACS_INT 3010ptrdiff_t
3012overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3011overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3013{ 3012{
3014 Lisp_Object overlay, window, str; 3013 Lisp_Object overlay, window, str;
3015 struct Lisp_Overlay *ov; 3014 struct Lisp_Overlay *ov;
3016 EMACS_INT startpos, endpos; 3015 ptrdiff_t startpos, endpos;
3017 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3016 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3018 3017
3019 overlay_heads.used = overlay_heads.bytes = 0; 3018 overlay_heads.used = overlay_heads.bytes = 0;
@@ -3083,7 +3082,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3083 if (overlay_heads.bytes || overlay_tails.bytes) 3082 if (overlay_heads.bytes || overlay_tails.bytes)
3084 { 3083 {
3085 Lisp_Object tem; 3084 Lisp_Object tem;
3086 EMACS_INT i; 3085 ptrdiff_t i;
3087 unsigned char *p; 3086 unsigned char *p;
3088 ptrdiff_t total; 3087 ptrdiff_t total;
3089 3088
@@ -3097,7 +3096,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3097 p = overlay_str_buf; 3096 p = overlay_str_buf;
3098 for (i = overlay_tails.used; --i >= 0;) 3097 for (i = overlay_tails.used; --i >= 0;)
3099 { 3098 {
3100 EMACS_INT nbytes; 3099 ptrdiff_t nbytes;
3101 tem = overlay_tails.buf[i].string; 3100 tem = overlay_tails.buf[i].string;
3102 nbytes = copy_text (SDATA (tem), p, 3101 nbytes = copy_text (SDATA (tem), p,
3103 SBYTES (tem), 3102 SBYTES (tem),
@@ -3106,7 +3105,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3106 } 3105 }
3107 for (i = 0; i < overlay_heads.used; ++i) 3106 for (i = 0; i < overlay_heads.used; ++i)
3108 { 3107 {
3109 EMACS_INT nbytes; 3108 ptrdiff_t nbytes;
3110 tem = overlay_heads.buf[i].string; 3109 tem = overlay_heads.buf[i].string;
3111 nbytes = copy_text (SDATA (tem), p, 3110 nbytes = copy_text (SDATA (tem), p,
3112 SBYTES (tem), 3111 SBYTES (tem),
@@ -3133,7 +3132,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3133/* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3132/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3134 3133
3135void 3134void
3136recenter_overlay_lists (struct buffer *buf, EMACS_INT pos) 3135recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3137{ 3136{
3138 Lisp_Object overlay, beg, end; 3137 Lisp_Object overlay, beg, end;
3139 struct Lisp_Overlay *prev, *tail, *next; 3138 struct Lisp_Overlay *prev, *tail, *next;
@@ -3171,7 +3170,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3171 if (OVERLAY_POSITION (end) > pos) 3170 if (OVERLAY_POSITION (end) > pos)
3172 { 3171 {
3173 /* OVERLAY needs to be moved. */ 3172 /* OVERLAY needs to be moved. */
3174 EMACS_INT where = OVERLAY_POSITION (beg); 3173 ptrdiff_t where = OVERLAY_POSITION (beg);
3175 struct Lisp_Overlay *other, *other_prev; 3174 struct Lisp_Overlay *other, *other_prev;
3176 3175
3177 /* Splice the cons cell TAIL out of overlays_before. */ 3176 /* Splice the cons cell TAIL out of overlays_before. */
@@ -3244,7 +3243,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3244 if (OVERLAY_POSITION (end) <= pos) 3243 if (OVERLAY_POSITION (end) <= pos)
3245 { 3244 {
3246 /* OVERLAY needs to be moved. */ 3245 /* OVERLAY needs to be moved. */
3247 EMACS_INT where = OVERLAY_POSITION (end); 3246 ptrdiff_t where = OVERLAY_POSITION (end);
3248 struct Lisp_Overlay *other, *other_prev; 3247 struct Lisp_Overlay *other, *other_prev;
3249 3248
3250 /* Splice the cons cell TAIL out of overlays_after. */ 3249 /* Splice the cons cell TAIL out of overlays_after. */
@@ -3282,7 +3281,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3282} 3281}
3283 3282
3284void 3283void
3285adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length) 3284adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
3286{ 3285{
3287 /* After an insertion, the lists are still sorted properly, 3286 /* After an insertion, the lists are still sorted properly,
3288 but we may need to update the value of the overlay center. */ 3287 but we may need to update the value of the overlay center. */
@@ -3291,13 +3290,13 @@ adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length)
3291} 3290}
3292 3291
3293void 3292void
3294adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length) 3293adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
3295{ 3294{
3296 if (current_buffer->overlay_center < pos) 3295 if (current_buffer->overlay_center < pos)
3297 /* The deletion was to our right. No change needed; the before- and 3296 /* The deletion was to our right. No change needed; the before- and
3298 after-lists are still consistent. */ 3297 after-lists are still consistent. */
3299 ; 3298 ;
3300 else if (current_buffer->overlay_center > pos + length) 3299 else if (current_buffer->overlay_center - pos > length)
3301 /* The deletion was to our left. We need to adjust the center value 3300 /* The deletion was to our left. We need to adjust the center value
3302 to account for the change in position, but the lists are consistent 3301 to account for the change in position, but the lists are consistent
3303 given the new value. */ 3302 given the new value. */
@@ -3316,7 +3315,7 @@ adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length)
3316 Such an overlay might even have negative size at this point. 3315 Such an overlay might even have negative size at this point.
3317 If so, we'll make the overlay empty. */ 3316 If so, we'll make the overlay empty. */
3318void 3317void
3319fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end) 3318fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3320{ 3319{
3321 Lisp_Object overlay; 3320 Lisp_Object overlay;
3322 struct Lisp_Overlay *before_list IF_LINT (= NULL); 3321 struct Lisp_Overlay *before_list IF_LINT (= NULL);
@@ -3329,7 +3328,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3329 current_buffer->overlays_before or overlays_after, depending 3328 current_buffer->overlays_before or overlays_after, depending
3330 which loop we're in. */ 3329 which loop we're in. */
3331 struct Lisp_Overlay *tail, *parent; 3330 struct Lisp_Overlay *tail, *parent;
3332 EMACS_INT startpos, endpos; 3331 ptrdiff_t startpos, endpos;
3333 3332
3334 /* This algorithm shifts links around instead of consing and GCing. 3333 /* This algorithm shifts links around instead of consing and GCing.
3335 The loop invariant is that before_list (resp. after_list) is a 3334 The loop invariant is that before_list (resp. after_list) is a
@@ -3463,12 +3462,12 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3463 was at PREV, and now is at POS. */ 3462 was at PREV, and now is at POS. */
3464 3463
3465void 3464void
3466fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos) 3465fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3467{ 3466{
3468 /* If parent is nil, replace overlays_before; otherwise, parent->next. */ 3467 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3469 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair; 3468 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3470 Lisp_Object tem; 3469 Lisp_Object tem;
3471 EMACS_INT end IF_LINT (= 0); 3470 ptrdiff_t end IF_LINT (= 0);
3472 3471
3473 /* After the insertion, the several overlays may be in incorrect 3472 /* After the insertion, the several overlays may be in incorrect
3474 order. The possibility is that, in the list `overlays_before', 3473 order. The possibility is that, in the list `overlays_before',
@@ -3626,11 +3625,11 @@ for the rear of the overlay advance when text is inserted there
3626/* Mark a section of BUF as needing redisplay because of overlays changes. */ 3625/* Mark a section of BUF as needing redisplay because of overlays changes. */
3627 3626
3628static void 3627static void
3629modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end) 3628modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3630{ 3629{
3631 if (start > end) 3630 if (start > end)
3632 { 3631 {
3633 EMACS_INT temp = start; 3632 ptrdiff_t temp = start;
3634 start = end; 3633 start = end;
3635 end = temp; 3634 end = temp;
3636 } 3635 }
@@ -3677,9 +3676,10 @@ If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3677buffer. */) 3676buffer. */)
3678 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer) 3677 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer)
3679{ 3678{
3680 struct buffer *b, *ob; 3679 struct buffer *b, *ob = 0;
3681 Lisp_Object obuffer; 3680 Lisp_Object obuffer;
3682 int count = SPECPDL_INDEX (); 3681 ptrdiff_t count = SPECPDL_INDEX ();
3682 ptrdiff_t n_beg, n_end, o_beg IF_LINT (= 0), o_end IF_LINT (= 0);
3683 3683
3684 CHECK_OVERLAY (overlay); 3684 CHECK_OVERLAY (overlay);
3685 if (NILP (buffer)) 3685 if (NILP (buffer))
@@ -3688,6 +3688,9 @@ buffer. */)
3688 XSETBUFFER (buffer, current_buffer); 3688 XSETBUFFER (buffer, current_buffer);
3689 CHECK_BUFFER (buffer); 3689 CHECK_BUFFER (buffer);
3690 3690
3691 if (NILP (Fbuffer_live_p (buffer)))
3692 error ("Attempt to move overlay to a dead buffer");
3693
3691 if (MARKERP (beg) 3694 if (MARKERP (beg)
3692 && ! EQ (Fmarker_buffer (beg), buffer)) 3695 && ! EQ (Fmarker_buffer (beg), buffer))
3693 error ("Marker points into wrong buffer"); 3696 error ("Marker points into wrong buffer");
@@ -3698,9 +3701,6 @@ buffer. */)
3698 CHECK_NUMBER_COERCE_MARKER (beg); 3701 CHECK_NUMBER_COERCE_MARKER (beg);
3699 CHECK_NUMBER_COERCE_MARKER (end); 3702 CHECK_NUMBER_COERCE_MARKER (end);
3700 3703
3701 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3702 return Fdelete_overlay (overlay);
3703
3704 if (XINT (beg) > XINT (end)) 3704 if (XINT (beg) > XINT (end))
3705 { 3705 {
3706 Lisp_Object temp; 3706 Lisp_Object temp;
@@ -3711,61 +3711,57 @@ buffer. */)
3711 3711
3712 obuffer = Fmarker_buffer (OVERLAY_START (overlay)); 3712 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
3713 b = XBUFFER (buffer); 3713 b = XBUFFER (buffer);
3714 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; 3714
3715 if (!NILP (obuffer))
3716 {
3717 ob = XBUFFER (obuffer);
3718
3719 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3720 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
3721
3722 ob->overlays_before =
3723 unchain_overlay (ob->overlays_before, XOVERLAY (overlay));
3724 ob->overlays_after =
3725 unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3726 eassert (XOVERLAY (overlay)->next == NULL);
3727 }
3728
3729 /* Set the overlay boundaries, which may clip them. */
3730 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3731 Fset_marker (OVERLAY_END (overlay), end, buffer);
3732
3733 n_beg = marker_position (OVERLAY_START (overlay));
3734 n_end = marker_position (OVERLAY_END (overlay));
3715 3735
3716 /* If the overlay has changed buffers, do a thorough redisplay. */ 3736 /* If the overlay has changed buffers, do a thorough redisplay. */
3717 if (!EQ (buffer, obuffer)) 3737 if (!EQ (buffer, obuffer))
3718 { 3738 {
3719 /* Redisplay where the overlay was. */ 3739 /* Redisplay where the overlay was. */
3720 if (!NILP (obuffer)) 3740 if (ob)
3721 { 3741 modify_overlay (ob, o_beg, o_end);
3722 EMACS_INT o_beg;
3723 EMACS_INT o_end;
3724
3725 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3726 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
3727
3728 modify_overlay (ob, o_beg, o_end);
3729 }
3730 3742
3731 /* Redisplay where the overlay is going to be. */ 3743 /* Redisplay where the overlay is going to be. */
3732 modify_overlay (b, XINT (beg), XINT (end)); 3744 modify_overlay (b, n_beg, n_end);
3733 } 3745 }
3734 else 3746 else
3735 /* Redisplay the area the overlay has just left, or just enclosed. */ 3747 /* Redisplay the area the overlay has just left, or just enclosed. */
3736 { 3748 {
3737 EMACS_INT o_beg, o_end; 3749 if (o_beg == n_beg)
3738 3750 modify_overlay (b, o_end, n_end);
3739 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3751 else if (o_end == n_end)
3740 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3752 modify_overlay (b, o_beg, n_beg);
3741
3742 if (o_beg == XINT (beg))
3743 modify_overlay (b, o_end, XINT (end));
3744 else if (o_end == XINT (end))
3745 modify_overlay (b, o_beg, XINT (beg));
3746 else 3753 else
3747 { 3754 modify_overlay (b, min (o_beg, n_beg), max (o_end, n_end));
3748 if (XINT (beg) < o_beg) o_beg = XINT (beg);
3749 if (XINT (end) > o_end) o_end = XINT (end);
3750 modify_overlay (b, o_beg, o_end);
3751 }
3752 } 3755 }
3753 3756
3754 if (!NILP (obuffer)) 3757 /* Delete the overlay if it is empty after clipping and has the
3755 { 3758 evaporate property. */
3756 ob->overlays_before 3759 if (n_beg == n_end && !NILP (Foverlay_get (overlay, Qevaporate)))
3757 = unchain_overlay (ob->overlays_before, XOVERLAY (overlay)); 3760 return unbind_to (count, Fdelete_overlay (overlay));
3758 ob->overlays_after
3759 = unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3760 eassert (XOVERLAY (overlay)->next == NULL);
3761 }
3762
3763 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3764 Fset_marker (OVERLAY_END (overlay), end, buffer);
3765 3761
3766 /* Put the overlay on the wrong list. */ 3762 /* Put the overlay into the new buffer's overlay lists, first on the
3767 end = OVERLAY_END (overlay); 3763 wrong list. */
3768 if (OVERLAY_POSITION (end) < b->overlay_center) 3764 if (n_end < b->overlay_center)
3769 { 3765 {
3770 XOVERLAY (overlay)->next = b->overlays_after; 3766 XOVERLAY (overlay)->next = b->overlays_after;
3771 b->overlays_after = XOVERLAY (overlay); 3767 b->overlays_after = XOVERLAY (overlay);
@@ -3788,7 +3784,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3788{ 3784{
3789 Lisp_Object buffer; 3785 Lisp_Object buffer;
3790 struct buffer *b; 3786 struct buffer *b;
3791 int count = SPECPDL_INDEX (); 3787 ptrdiff_t count = SPECPDL_INDEX ();
3792 3788
3793 CHECK_OVERLAY (overlay); 3789 CHECK_OVERLAY (overlay);
3794 3790
@@ -3799,9 +3795,12 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3799 b = XBUFFER (buffer); 3795 b = XBUFFER (buffer);
3800 specbind (Qinhibit_quit, Qt); 3796 specbind (Qinhibit_quit, Qt);
3801 3797
3802 b->overlays_before = unchain_overlay (b->overlays_before,XOVERLAY (overlay)); 3798 b->overlays_before
3803 b->overlays_after = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); 3799 = unchain_overlay (b->overlays_before, XOVERLAY (overlay));
3800 b->overlays_after
3801 = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3804 eassert (XOVERLAY (overlay)->next == NULL); 3802 eassert (XOVERLAY (overlay)->next == NULL);
3803
3805 modify_overlay (b, 3804 modify_overlay (b,
3806 marker_position (OVERLAY_START (overlay)), 3805 marker_position (OVERLAY_START (overlay)),
3807 marker_position (OVERLAY_END (overlay))); 3806 marker_position (OVERLAY_END (overlay)));
@@ -3879,7 +3878,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3879 /* Put all the overlays we want in a vector in overlay_vec. 3878 /* Put all the overlays we want in a vector in overlay_vec.
3880 Store the length in len. */ 3879 Store the length in len. */
3881 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3880 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3882 (EMACS_INT *) 0, (EMACS_INT *) 0, 0); 3881 0, 0, 0);
3883 3882
3884 /* Make a list of them all. */ 3883 /* Make a list of them all. */
3885 result = Flist (noverlays, overlay_vec); 3884 result = Flist (noverlays, overlay_vec);
@@ -3927,7 +3926,7 @@ the value is (point-max). */)
3927 (Lisp_Object pos) 3926 (Lisp_Object pos)
3928{ 3927{
3929 ptrdiff_t i, len, noverlays; 3928 ptrdiff_t i, len, noverlays;
3930 EMACS_INT endpos; 3929 ptrdiff_t endpos;
3931 Lisp_Object *overlay_vec; 3930 Lisp_Object *overlay_vec;
3932 3931
3933 CHECK_NUMBER_COERCE_MARKER (pos); 3932 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3939,14 +3938,14 @@ the value is (point-max). */)
3939 Store the length in len. 3938 Store the length in len.
3940 endpos gets the position where the next overlay starts. */ 3939 endpos gets the position where the next overlay starts. */
3941 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3940 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3942 &endpos, (EMACS_INT *) 0, 1); 3941 &endpos, 0, 1);
3943 3942
3944 /* If any of these overlays ends before endpos, 3943 /* If any of these overlays ends before endpos,
3945 use its ending point instead. */ 3944 use its ending point instead. */
3946 for (i = 0; i < noverlays; i++) 3945 for (i = 0; i < noverlays; i++)
3947 { 3946 {
3948 Lisp_Object oend; 3947 Lisp_Object oend;
3949 EMACS_INT oendpos; 3948 ptrdiff_t oendpos;
3950 3949
3951 oend = OVERLAY_END (overlay_vec[i]); 3950 oend = OVERLAY_END (overlay_vec[i]);
3952 oendpos = OVERLAY_POSITION (oend); 3951 oendpos = OVERLAY_POSITION (oend);
@@ -3965,7 +3964,7 @@ If there are no overlay boundaries from (point-min) to POS,
3965the value is (point-min). */) 3964the value is (point-min). */)
3966 (Lisp_Object pos) 3965 (Lisp_Object pos)
3967{ 3966{
3968 EMACS_INT prevpos; 3967 ptrdiff_t prevpos;
3969 Lisp_Object *overlay_vec; 3968 Lisp_Object *overlay_vec;
3970 ptrdiff_t len; 3969 ptrdiff_t len;
3971 3970
@@ -3983,7 +3982,7 @@ the value is (point-min). */)
3983 Store the length in len. 3982 Store the length in len.
3984 prevpos gets the position of the previous change. */ 3983 prevpos gets the position of the previous change. */
3985 overlays_at (XINT (pos), 1, &overlay_vec, &len, 3984 overlays_at (XINT (pos), 1, &overlay_vec, &len,
3986 (EMACS_INT *) 0, &prevpos, 1); 3985 0, &prevpos, 1);
3987 3986
3988 xfree (overlay_vec); 3987 xfree (overlay_vec);
3989 return make_number (prevpos); 3988 return make_number (prevpos);
@@ -4021,9 +4020,11 @@ That makes overlay lookup faster for positions near POS (but perhaps slower
4021for positions far away from POS). */) 4020for positions far away from POS). */)
4022 (Lisp_Object pos) 4021 (Lisp_Object pos)
4023{ 4022{
4023 ptrdiff_t p;
4024 CHECK_NUMBER_COERCE_MARKER (pos); 4024 CHECK_NUMBER_COERCE_MARKER (pos);
4025 4025
4026 recenter_overlay_lists (current_buffer, XINT (pos)); 4026 p = clip_to_bounds (PTRDIFF_MIN, XINT (pos), PTRDIFF_MAX);
4027 recenter_overlay_lists (current_buffer, p);
4027 return Qnil; 4028 return Qnil;
4028} 4029}
4029 4030
@@ -4090,7 +4091,7 @@ VALUE will be returned.*/)
4090static Lisp_Object last_overlay_modification_hooks; 4091static Lisp_Object last_overlay_modification_hooks;
4091 4092
4092/* Number of elements actually used in last_overlay_modification_hooks. */ 4093/* Number of elements actually used in last_overlay_modification_hooks. */
4093static int last_overlay_modification_hooks_used; 4094static ptrdiff_t last_overlay_modification_hooks_used;
4094 4095
4095/* Add one functionlist/overlay pair 4096/* Add one functionlist/overlay pair
4096 to the end of last_overlay_modification_hooks. */ 4097 to the end of last_overlay_modification_hooks. */
@@ -4098,11 +4099,11 @@ static int last_overlay_modification_hooks_used;
4098static void 4099static void
4099add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) 4100add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4100{ 4101{
4101 int oldsize = ASIZE (last_overlay_modification_hooks); 4102 ptrdiff_t oldsize = ASIZE (last_overlay_modification_hooks);
4102 4103
4103 if (last_overlay_modification_hooks_used == oldsize) 4104 if (oldsize - 1 <= last_overlay_modification_hooks_used)
4104 last_overlay_modification_hooks = larger_vector 4105 last_overlay_modification_hooks =
4105 (last_overlay_modification_hooks, oldsize * 2, Qnil); 4106 larger_vector (last_overlay_modification_hooks, 2, -1);
4106 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4107 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
4107 functionlist); last_overlay_modification_hooks_used++; 4108 functionlist); last_overlay_modification_hooks_used++;
4108 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4109 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
@@ -4151,7 +4152,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4151 last_overlay_modification_hooks_used = 0; 4152 last_overlay_modification_hooks_used = 0;
4152 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4153 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4153 { 4154 {
4154 EMACS_INT startpos, endpos; 4155 ptrdiff_t startpos, endpos;
4155 Lisp_Object ostart, oend; 4156 Lisp_Object ostart, oend;
4156 4157
4157 XSETMISC (overlay, tail); 4158 XSETMISC (overlay, tail);
@@ -4188,7 +4189,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4188 4189
4189 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4190 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4190 { 4191 {
4191 EMACS_INT startpos, endpos; 4192 ptrdiff_t startpos, endpos;
4192 Lisp_Object ostart, oend; 4193 Lisp_Object ostart, oend;
4193 4194
4194 XSETMISC (overlay, tail); 4195 XSETMISC (overlay, tail);
@@ -4229,9 +4230,9 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4229 /* Call the functions recorded in last_overlay_modification_hooks. 4230 /* Call the functions recorded in last_overlay_modification_hooks.
4230 First copy the vector contents, in case some of these hooks 4231 First copy the vector contents, in case some of these hooks
4231 do subsequent modification of the buffer. */ 4232 do subsequent modification of the buffer. */
4232 int size = last_overlay_modification_hooks_used; 4233 ptrdiff_t size = last_overlay_modification_hooks_used;
4233 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4234 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
4234 int i; 4235 ptrdiff_t i;
4235 4236
4236 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4237 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
4237 size * sizeof (Lisp_Object)); 4238 size * sizeof (Lisp_Object));
@@ -4271,7 +4272,7 @@ call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after,
4271/* Delete any zero-sized overlays at position POS, if the `evaporate' 4272/* Delete any zero-sized overlays at position POS, if the `evaporate'
4272 property is set. */ 4273 property is set. */
4273void 4274void
4274evaporate_overlays (EMACS_INT pos) 4275evaporate_overlays (ptrdiff_t pos)
4275{ 4276{
4276 Lisp_Object overlay, hit_list; 4277 Lisp_Object overlay, hit_list;
4277 struct Lisp_Overlay *tail; 4278 struct Lisp_Overlay *tail;
@@ -4280,7 +4281,7 @@ evaporate_overlays (EMACS_INT pos)
4280 if (pos <= current_buffer->overlay_center) 4281 if (pos <= current_buffer->overlay_center)
4281 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4282 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4282 { 4283 {
4283 EMACS_INT endpos; 4284 ptrdiff_t endpos;
4284 XSETMISC (overlay, tail); 4285 XSETMISC (overlay, tail);
4285 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4286 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4286 if (endpos < pos) 4287 if (endpos < pos)
@@ -4292,7 +4293,7 @@ evaporate_overlays (EMACS_INT pos)
4292 else 4293 else
4293 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4294 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4294 { 4295 {
4295 EMACS_INT startpos; 4296 ptrdiff_t startpos;
4296 XSETMISC (overlay, tail); 4297 XSETMISC (overlay, tail);
4297 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4298 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4298 if (startpos > pos) 4299 if (startpos > pos)
@@ -4795,7 +4796,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4795 shrink it. */ 4796 shrink it. */
4796 4797
4797void 4798void
4798enlarge_buffer_text (struct buffer *b, EMACS_INT delta) 4799enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
4799{ 4800{
4800 void *p; 4801 void *p;
4801 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 4802 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
diff --git a/src/buffer.h b/src/buffer.h
index 1635a847839..97d891f044b 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -245,12 +245,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
245#define BUF_TEMP_SET_PT(buffer, position) \ 245#define BUF_TEMP_SET_PT(buffer, position) \
246 (temp_set_point ((buffer), (position))) 246 (temp_set_point ((buffer), (position)))
247 247
248extern void set_point (EMACS_INT); 248extern void set_point (ptrdiff_t);
249extern void temp_set_point (struct buffer *, EMACS_INT); 249extern void temp_set_point (struct buffer *, ptrdiff_t);
250extern void set_point_both (EMACS_INT, EMACS_INT); 250extern void set_point_both (ptrdiff_t, ptrdiff_t);
251extern void temp_set_point_both (struct buffer *, 251extern void temp_set_point_both (struct buffer *,
252 EMACS_INT, EMACS_INT); 252 ptrdiff_t, ptrdiff_t);
253extern void enlarge_buffer_text (struct buffer *, EMACS_INT); 253extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
254 254
255 255
256/* Macros for setting the BEGV, ZV or PT of a given buffer. 256/* Macros for setting the BEGV, ZV or PT of a given buffer.
@@ -449,38 +449,38 @@ struct buffer_text
449 into a buffer's text to functions that malloc. */ 449 into a buffer's text to functions that malloc. */
450 unsigned char *beg; 450 unsigned char *beg;
451 451
452 EMACS_INT gpt; /* Char pos of gap in buffer. */ 452 ptrdiff_t gpt; /* Char pos of gap in buffer. */
453 EMACS_INT z; /* Char pos of end of buffer. */ 453 ptrdiff_t z; /* Char pos of end of buffer. */
454 EMACS_INT gpt_byte; /* Byte pos of gap in buffer. */ 454 ptrdiff_t gpt_byte; /* Byte pos of gap in buffer. */
455 EMACS_INT z_byte; /* Byte pos of end of buffer. */ 455 ptrdiff_t z_byte; /* Byte pos of end of buffer. */
456 EMACS_INT gap_size; /* Size of buffer's gap. */ 456 ptrdiff_t gap_size; /* Size of buffer's gap. */
457 int modiff; /* This counts buffer-modification events 457 EMACS_INT modiff; /* This counts buffer-modification events
458 for this buffer. It is incremented for 458 for this buffer. It is incremented for
459 each such event, and never otherwise 459 each such event, and never otherwise
460 changed. */ 460 changed. */
461 int chars_modiff; /* This is modified with character change 461 EMACS_INT chars_modiff; /* This is modified with character change
462 events for this buffer. It is set to 462 events for this buffer. It is set to
463 modiff for each such event, and never 463 modiff for each such event, and never
464 otherwise changed. */ 464 otherwise changed. */
465 int save_modiff; /* Previous value of modiff, as of last 465 EMACS_INT save_modiff; /* Previous value of modiff, as of last
466 time buffer visited or saved a file. */ 466 time buffer visited or saved a file. */
467 467
468 int overlay_modiff; /* Counts modifications to overlays. */ 468 EMACS_INT overlay_modiff; /* Counts modifications to overlays. */
469 469
470 /* Minimum value of GPT - BEG since last redisplay that finished. */ 470 /* Minimum value of GPT - BEG since last redisplay that finished. */
471 EMACS_INT beg_unchanged; 471 ptrdiff_t beg_unchanged;
472 472
473 /* Minimum value of Z - GPT since last redisplay that finished. */ 473 /* Minimum value of Z - GPT since last redisplay that finished. */
474 EMACS_INT end_unchanged; 474 ptrdiff_t end_unchanged;
475 475
476 /* MODIFF as of last redisplay that finished; if it matches MODIFF, 476 /* MODIFF as of last redisplay that finished; if it matches MODIFF,
477 beg_unchanged and end_unchanged contain no useful information. */ 477 beg_unchanged and end_unchanged contain no useful information. */
478 int unchanged_modified; 478 EMACS_INT unchanged_modified;
479 479
480 /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that 480 /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that
481 finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and 481 finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and
482 end_unchanged contain no useful information. */ 482 end_unchanged contain no useful information. */
483 int overlay_unchanged_modified; 483 EMACS_INT overlay_unchanged_modified;
484 484
485 /* Properties of this buffer's text. */ 485 /* Properties of this buffer's text. */
486 INTERVAL intervals; 486 INTERVAL intervals;
@@ -536,17 +536,17 @@ struct buffer
536 struct buffer_text *text; 536 struct buffer_text *text;
537 537
538 /* Char position of point in buffer. */ 538 /* Char position of point in buffer. */
539 EMACS_INT pt; 539 ptrdiff_t pt;
540 /* Byte position of point in buffer. */ 540 /* Byte position of point in buffer. */
541 EMACS_INT pt_byte; 541 ptrdiff_t pt_byte;
542 /* Char position of beginning of accessible range. */ 542 /* Char position of beginning of accessible range. */
543 EMACS_INT begv; 543 ptrdiff_t begv;
544 /* Byte position of beginning of accessible range. */ 544 /* Byte position of beginning of accessible range. */
545 EMACS_INT begv_byte; 545 ptrdiff_t begv_byte;
546 /* Char position of end of accessible range. */ 546 /* Char position of end of accessible range. */
547 EMACS_INT zv; 547 ptrdiff_t zv;
548 /* Byte position of end of accessible range. */ 548 /* Byte position of end of accessible range. */
549 EMACS_INT zv_byte; 549 ptrdiff_t zv_byte;
550 550
551 /* In an indirect buffer, this points to the base buffer. 551 /* In an indirect buffer, this points to the base buffer.
552 In an ordinary buffer, it is 0. */ 552 In an ordinary buffer, it is 0. */
@@ -572,16 +572,16 @@ struct buffer
572 modtime is actually set. */ 572 modtime is actually set. */
573 off_t modtime_size; 573 off_t modtime_size;
574 /* The value of text->modiff at the last auto-save. */ 574 /* The value of text->modiff at the last auto-save. */
575 int auto_save_modified; 575 EMACS_INT auto_save_modified;
576 /* The value of text->modiff at the last display error. 576 /* The value of text->modiff at the last display error.
577 Redisplay of this buffer is inhibited until it changes again. */ 577 Redisplay of this buffer is inhibited until it changes again. */
578 int display_error_modiff; 578 EMACS_INT display_error_modiff;
579 /* The time at which we detected a failure to auto-save, 579 /* The time at which we detected a failure to auto-save,
580 Or 0 if we didn't have a failure. */ 580 Or 0 if we didn't have a failure. */
581 time_t auto_save_failure_time; 581 time_t auto_save_failure_time;
582 /* Position in buffer at which display started 582 /* Position in buffer at which display started
583 the last time this buffer was displayed. */ 583 the last time this buffer was displayed. */
584 EMACS_INT last_window_start; 584 ptrdiff_t last_window_start;
585 585
586 /* Set nonzero whenever the narrowing is changed in this buffer. */ 586 /* Set nonzero whenever the narrowing is changed in this buffer. */
587 int clip_changed; 587 int clip_changed;
@@ -618,7 +618,7 @@ struct buffer
618 struct Lisp_Overlay *overlays_after; 618 struct Lisp_Overlay *overlays_after;
619 619
620 /* Position where the overlay lists are centered. */ 620 /* Position where the overlay lists are centered. */
621 EMACS_INT overlay_center; 621 ptrdiff_t overlay_center;
622 622
623 /* Everything from here down must be a Lisp_Object. */ 623 /* Everything from here down must be a Lisp_Object. */
624 /* buffer-local Lisp variables start at `undo_list', 624 /* buffer-local Lisp variables start at `undo_list',
@@ -901,20 +901,20 @@ extern struct buffer buffer_local_symbols;
901 901
902extern void delete_all_overlays (struct buffer *); 902extern void delete_all_overlays (struct buffer *);
903extern void reset_buffer (struct buffer *); 903extern void reset_buffer (struct buffer *);
904extern void evaporate_overlays (EMACS_INT); 904extern void evaporate_overlays (ptrdiff_t);
905extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 905extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
906 ptrdiff_t *len_ptr, EMACS_INT *next_ptr, 906 ptrdiff_t *len_ptr, ptrdiff_t *next_ptr,
907 EMACS_INT *prev_ptr, int change_req); 907 ptrdiff_t *prev_ptr, int change_req);
908extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *); 908extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
909extern void recenter_overlay_lists (struct buffer *, EMACS_INT); 909extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
910extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **); 910extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
911extern void validate_region (Lisp_Object *, Lisp_Object *); 911extern void validate_region (Lisp_Object *, Lisp_Object *);
912extern void set_buffer_internal (struct buffer *); 912extern void set_buffer_internal (struct buffer *);
913extern void set_buffer_internal_1 (struct buffer *); 913extern void set_buffer_internal_1 (struct buffer *);
914extern void set_buffer_temp (struct buffer *); 914extern void set_buffer_temp (struct buffer *);
915extern void record_buffer (Lisp_Object); 915extern void record_buffer (Lisp_Object);
916extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN; 916extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN;
917extern void fix_overlays_before (struct buffer *, EMACS_INT, EMACS_INT); 917extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
918extern void mmap_set_vars (int); 918extern void mmap_set_vars (int);
919 919
920/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. 920/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
diff --git a/src/bytecode.c b/src/bytecode.c
index 6f945723d38..e2370254f36 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -318,7 +318,7 @@ unmark_byte_stack (void)
318 { 318 {
319 if (stack->byte_string_start != SDATA (stack->byte_string)) 319 if (stack->byte_string_start != SDATA (stack->byte_string))
320 { 320 {
321 int offset = stack->pc - stack->byte_string_start; 321 ptrdiff_t offset = stack->pc - stack->byte_string_start;
322 stack->byte_string_start = SDATA (stack->byte_string); 322 stack->byte_string_start = SDATA (stack->byte_string);
323 stack->pc = stack->byte_string_start + offset; 323 stack->pc = stack->byte_string_start + offset;
324 } 324 }
@@ -435,7 +435,7 @@ Lisp_Object
435exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, 435exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
436 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) 436 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
437{ 437{
438 int count = SPECPDL_INDEX (); 438 ptrdiff_t count = SPECPDL_INDEX ();
439#ifdef BYTE_CODE_METER 439#ifdef BYTE_CODE_METER
440 int this_op = 0; 440 int this_op = 0;
441 int prev_op; 441 int prev_op;
@@ -446,7 +446,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
446#ifdef BYTE_CODE_SAFE 446#ifdef BYTE_CODE_SAFE
447 ptrdiff_t const_length; 447 ptrdiff_t const_length;
448 Lisp_Object *stacke; 448 Lisp_Object *stacke;
449 int bytestr_length; 449 ptrdiff_t bytestr_length;
450#endif 450#endif
451 struct byte_stack stack; 451 struct byte_stack stack;
452 Lisp_Object *top; 452 Lisp_Object *top;
@@ -486,15 +486,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
486 stack.byte_string = bytestr; 486 stack.byte_string = bytestr;
487 stack.pc = stack.byte_string_start = SDATA (bytestr); 487 stack.pc = stack.byte_string_start = SDATA (bytestr);
488 stack.constants = vector; 488 stack.constants = vector;
489 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) < XFASTINT (maxdepth)) 489 if (MAX_ALLOCA / sizeof (Lisp_Object) <= XFASTINT (maxdepth))
490 memory_full (SIZE_MAX); 490 memory_full (SIZE_MAX);
491 top = (Lisp_Object *) alloca (XFASTINT (maxdepth) 491 top = (Lisp_Object *) alloca ((XFASTINT (maxdepth) + 1)
492 * sizeof (Lisp_Object)); 492 * sizeof (Lisp_Object));
493#if BYTE_MAINTAIN_TOP 493#if BYTE_MAINTAIN_TOP
494 stack.bottom = top; 494 stack.bottom = top + 1;
495 stack.top = NULL; 495 stack.top = NULL;
496#endif 496#endif
497 top -= 1;
498 stack.next = byte_stack_list; 497 stack.next = byte_stack_list;
499 byte_stack_list = &stack; 498 byte_stack_list = &stack;
500 499
@@ -943,7 +942,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
943 942
944 case Bsave_window_excursion: /* Obsolete since 24.1. */ 943 case Bsave_window_excursion: /* Obsolete since 24.1. */
945 { 944 {
946 register int count1 = SPECPDL_INDEX (); 945 register ptrdiff_t count1 = SPECPDL_INDEX ();
947 record_unwind_protect (Fset_window_configuration, 946 record_unwind_protect (Fset_window_configuration,
948 Fcurrent_window_configuration (Qnil)); 947 Fcurrent_window_configuration (Qnil));
949 BEFORE_POTENTIAL_GC (); 948 BEFORE_POTENTIAL_GC ();
@@ -1007,13 +1006,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1007 case Bnth: 1006 case Bnth:
1008 { 1007 {
1009 Lisp_Object v1, v2; 1008 Lisp_Object v1, v2;
1009 EMACS_INT n;
1010 BEFORE_POTENTIAL_GC (); 1010 BEFORE_POTENTIAL_GC ();
1011 v1 = POP; 1011 v1 = POP;
1012 v2 = TOP; 1012 v2 = TOP;
1013 CHECK_NUMBER (v2); 1013 CHECK_NUMBER (v2);
1014 op = XINT (v2); 1014 n = XINT (v2);
1015 immediate_quit = 1; 1015 immediate_quit = 1;
1016 while (--op >= 0 && CONSP (v1)) 1016 while (--n >= 0 && CONSP (v1))
1017 v1 = XCDR (v1); 1017 v1 = XCDR (v1);
1018 immediate_quit = 0; 1018 immediate_quit = 0;
1019 TOP = CAR (v1); 1019 TOP = CAR (v1);
@@ -1640,14 +1640,15 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1640 if (CONSP (TOP)) 1640 if (CONSP (TOP))
1641 { 1641 {
1642 /* Exchange args and then do nth. */ 1642 /* Exchange args and then do nth. */
1643 EMACS_INT n;
1643 BEFORE_POTENTIAL_GC (); 1644 BEFORE_POTENTIAL_GC ();
1644 v2 = POP; 1645 v2 = POP;
1645 v1 = TOP; 1646 v1 = TOP;
1646 CHECK_NUMBER (v2); 1647 CHECK_NUMBER (v2);
1647 AFTER_POTENTIAL_GC (); 1648 AFTER_POTENTIAL_GC ();
1648 op = XINT (v2); 1649 n = XINT (v2);
1649 immediate_quit = 1; 1650 immediate_quit = 1;
1650 while (--op >= 0 && CONSP (v1)) 1651 while (--n >= 0 && CONSP (v1))
1651 v1 = XCDR (v1); 1652 v1 = XCDR (v1);
1652 immediate_quit = 0; 1653 immediate_quit = 0;
1653 TOP = CAR (v1); 1654 TOP = CAR (v1);
diff --git a/src/callint.c b/src/callint.c
index c70082e8ae0..506698a4e4e 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -257,11 +257,11 @@ invoke it. If KEYS is omitted or nil, the return value of
257 Lisp_Object teml; 257 Lisp_Object teml;
258 Lisp_Object up_event; 258 Lisp_Object up_event;
259 Lisp_Object enable; 259 Lisp_Object enable;
260 int speccount = SPECPDL_INDEX (); 260 ptrdiff_t speccount = SPECPDL_INDEX ();
261 261
262 /* The index of the next element of this_command_keys to examine for 262 /* The index of the next element of this_command_keys to examine for
263 the 'e' interactive code. */ 263 the 'e' interactive code. */
264 int next_event; 264 ptrdiff_t next_event;
265 265
266 Lisp_Object prefix_arg; 266 Lisp_Object prefix_arg;
267 char *string; 267 char *string;
@@ -276,7 +276,7 @@ invoke it. If KEYS is omitted or nil, the return value of
276 int foo; 276 int foo;
277 int arg_from_tty = 0; 277 int arg_from_tty = 0;
278 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 278 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
279 int key_count; 279 ptrdiff_t key_count;
280 int record_then_fail = 0; 280 int record_then_fail = 0;
281 281
282 Lisp_Object save_this_command, save_last_command; 282 Lisp_Object save_this_command, save_last_command;
@@ -577,7 +577,7 @@ invoke it. If KEYS is omitted or nil, the return value of
577 577
578 case 'k': /* Key sequence. */ 578 case 'k': /* Key sequence. */
579 { 579 {
580 int speccount1 = SPECPDL_INDEX (); 580 ptrdiff_t speccount1 = SPECPDL_INDEX ();
581 specbind (Qcursor_in_echo_area, Qt); 581 specbind (Qcursor_in_echo_area, Qt);
582 /* Prompt in `minibuffer-prompt' face. */ 582 /* Prompt in `minibuffer-prompt' face. */
583 Fput_text_property (make_number (0), 583 Fput_text_property (make_number (0),
@@ -609,7 +609,7 @@ invoke it. If KEYS is omitted or nil, the return value of
609 609
610 case 'K': /* Key sequence to be defined. */ 610 case 'K': /* Key sequence to be defined. */
611 { 611 {
612 int speccount1 = SPECPDL_INDEX (); 612 ptrdiff_t speccount1 = SPECPDL_INDEX ();
613 specbind (Qcursor_in_echo_area, Qt); 613 specbind (Qcursor_in_echo_area, Qt);
614 /* Prompt in `minibuffer-prompt' face. */ 614 /* Prompt in `minibuffer-prompt' face. */
615 Fput_text_property (make_number (0), 615 Fput_text_property (make_number (0),
diff --git a/src/callproc.c b/src/callproc.c
index 9528c9644d8..f7c9971907d 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -102,8 +102,12 @@ static Lisp_Object Fgetenv_internal (Lisp_Object, Lisp_Object);
102static Lisp_Object 102static Lisp_Object
103call_process_kill (Lisp_Object fdpid) 103call_process_kill (Lisp_Object fdpid)
104{ 104{
105 emacs_close (XFASTINT (Fcar (fdpid))); 105 int fd;
106 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL); 106 pid_t pid;
107 CONS_TO_INTEGER (Fcar (fdpid), int, fd);
108 CONS_TO_INTEGER (Fcdr (fdpid), pid_t, pid);
109 emacs_close (fd);
110 EMACS_KILLPG (pid, SIGKILL);
107 synch_process_alive = 0; 111 synch_process_alive = 0;
108 return Qnil; 112 return Qnil;
109} 113}
@@ -112,18 +116,18 @@ static Lisp_Object
112call_process_cleanup (Lisp_Object arg) 116call_process_cleanup (Lisp_Object arg)
113{ 117{
114 Lisp_Object fdpid = Fcdr (arg); 118 Lisp_Object fdpid = Fcdr (arg);
119 int fd;
115#if defined (MSDOS) 120#if defined (MSDOS)
116 Lisp_Object file; 121 Lisp_Object file;
117 int fd;
118#else 122#else
119 int pid; 123 pid_t pid;
120#endif 124#endif
121 125
122 Fset_buffer (Fcar (arg)); 126 Fset_buffer (Fcar (arg));
127 CONS_TO_INTEGER (Fcar (fdpid), int, fd);
123 128
124#if defined (MSDOS) 129#if defined (MSDOS)
125 /* for MSDOS fdpid is really (fd . tempfile) */ 130 /* for MSDOS fdpid is really (fd . tempfile) */
126 fd = XFASTINT (Fcar (fdpid));
127 file = Fcdr (fdpid); 131 file = Fcdr (fdpid);
128 /* FD is -1 and FILE is "" when we didn't actually create a 132 /* FD is -1 and FILE is "" when we didn't actually create a
129 temporary file in call-process. */ 133 temporary file in call-process. */
@@ -132,17 +136,17 @@ call_process_cleanup (Lisp_Object arg)
132 if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0')) 136 if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0'))
133 unlink (SDATA (file)); 137 unlink (SDATA (file));
134#else /* not MSDOS */ 138#else /* not MSDOS */
135 pid = XFASTINT (Fcdr (fdpid)); 139 CONS_TO_INTEGER (Fcdr (fdpid), pid_t, pid);
136 140
137 if (call_process_exited) 141 if (call_process_exited)
138 { 142 {
139 emacs_close (XFASTINT (Fcar (fdpid))); 143 emacs_close (fd);
140 return Qnil; 144 return Qnil;
141 } 145 }
142 146
143 if (EMACS_KILLPG (pid, SIGINT) == 0) 147 if (EMACS_KILLPG (pid, SIGINT) == 0)
144 { 148 {
145 int count = SPECPDL_INDEX (); 149 ptrdiff_t count = SPECPDL_INDEX ();
146 record_unwind_protect (call_process_kill, fdpid); 150 record_unwind_protect (call_process_kill, fdpid);
147 message1 ("Waiting for process to die...(type C-g again to kill it instantly)"); 151 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
148 immediate_quit = 1; 152 immediate_quit = 1;
@@ -153,7 +157,7 @@ call_process_cleanup (Lisp_Object arg)
153 message1 ("Waiting for process to die...done"); 157 message1 ("Waiting for process to die...done");
154 } 158 }
155 synch_process_alive = 0; 159 synch_process_alive = 0;
156 emacs_close (XFASTINT (Fcar (fdpid))); 160 emacs_close (fd);
157#endif /* not MSDOS */ 161#endif /* not MSDOS */
158 return Qnil; 162 return Qnil;
159} 163}
@@ -187,17 +191,16 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
187usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) 191usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
188 (ptrdiff_t nargs, Lisp_Object *args) 192 (ptrdiff_t nargs, Lisp_Object *args)
189{ 193{
190 Lisp_Object infile, buffer, current_dir, path; 194 Lisp_Object infile, buffer, current_dir, path, cleanup_info_tail;
191 volatile int display_p_volatile; 195 int display_p;
192 int fd[2]; 196 int fd[2];
193 int filefd; 197 int filefd;
194 register int pid;
195#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024) 198#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024)
196#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN) 199#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN)
197 char buf[CALLPROC_BUFFER_SIZE_MAX]; 200 char buf[CALLPROC_BUFFER_SIZE_MAX];
198 int bufsize = CALLPROC_BUFFER_SIZE_MIN; 201 int bufsize = CALLPROC_BUFFER_SIZE_MIN;
199 int count = SPECPDL_INDEX (); 202 ptrdiff_t count = SPECPDL_INDEX ();
200 volatile USE_SAFE_ALLOCA; 203 USE_SAFE_ALLOCA;
201 204
202 register const unsigned char **new_argv; 205 register const unsigned char **new_argv;
203 /* File to use for stderr in the child. 206 /* File to use for stderr in the child.
@@ -207,6 +210,9 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
207#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 210#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
208 char *outf, *tempfile = NULL; 211 char *outf, *tempfile = NULL;
209 int outfilefd; 212 int outfilefd;
213 int pid;
214#else
215 pid_t pid;
210#endif 216#endif
211 int fd_output = -1; 217 int fd_output = -1;
212 struct coding_system process_coding; /* coding-system of process output */ 218 struct coding_system process_coding; /* coding-system of process output */
@@ -371,7 +377,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
371 UNGCPRO; 377 UNGCPRO;
372 } 378 }
373 379
374 display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 380 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
375 381
376 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); 382 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
377 if (filefd < 0) 383 if (filefd < 0)
@@ -607,10 +613,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
607 Lisp_Object volatile buffer_volatile = buffer; 613 Lisp_Object volatile buffer_volatile = buffer;
608 Lisp_Object volatile coding_systems_volatile = coding_systems; 614 Lisp_Object volatile coding_systems_volatile = coding_systems;
609 Lisp_Object volatile current_dir_volatile = current_dir; 615 Lisp_Object volatile current_dir_volatile = current_dir;
616 int volatile display_p_volatile = display_p;
610 int volatile fd1_volatile = fd1; 617 int volatile fd1_volatile = fd1;
611 int volatile fd_error_volatile = fd_error; 618 int volatile fd_error_volatile = fd_error;
612 int volatile fd_output_volatile = fd_output; 619 int volatile fd_output_volatile = fd_output;
613 int volatile output_to_buffer_volatile = output_to_buffer; 620 int volatile output_to_buffer_volatile = output_to_buffer;
621 int volatile sa_must_free_volatile = sa_must_free;
622 ptrdiff_t volatile sa_count_volatile = sa_count;
614 unsigned char const **volatile new_argv_volatile = new_argv; 623 unsigned char const **volatile new_argv_volatile = new_argv;
615 624
616 pid = vfork (); 625 pid = vfork ();
@@ -618,10 +627,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
618 buffer = buffer_volatile; 627 buffer = buffer_volatile;
619 coding_systems = coding_systems_volatile; 628 coding_systems = coding_systems_volatile;
620 current_dir = current_dir_volatile; 629 current_dir = current_dir_volatile;
630 display_p = display_p_volatile;
621 fd1 = fd1_volatile; 631 fd1 = fd1_volatile;
622 fd_error = fd_error_volatile; 632 fd_error = fd_error_volatile;
623 fd_output = fd_output_volatile; 633 fd_output = fd_output_volatile;
624 output_to_buffer = output_to_buffer_volatile; 634 output_to_buffer = output_to_buffer_volatile;
635 sa_must_free = sa_must_free_volatile;
636 sa_count = sa_count_volatile;
625 new_argv = new_argv_volatile; 637 new_argv = new_argv_volatile;
626 } 638 }
627 639
@@ -640,7 +652,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
640 652
641 /* GConf causes us to ignore SIGPIPE, make sure it is restored 653 /* GConf causes us to ignore SIGPIPE, make sure it is restored
642 in the child. */ 654 in the child. */
643 //signal (SIGPIPE, SIG_DFL); 655 signal (SIGPIPE, SIG_DFL);
644#ifdef HAVE_WORKING_VFORK 656#ifdef HAVE_WORKING_VFORK
645 pthread_sigmask (SIG_SETMASK, &procmask, 0); 657 pthread_sigmask (SIG_SETMASK, &procmask, 0);
646#endif 658#endif
@@ -694,16 +706,14 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
694 706
695#if defined (MSDOS) 707#if defined (MSDOS)
696 /* MSDOS needs different cleanup information. */ 708 /* MSDOS needs different cleanup information. */
697 record_unwind_protect (call_process_cleanup, 709 cleanup_info_tail = build_string (tempfile ? tempfile : "");
698 Fcons (Fcurrent_buffer (),
699 Fcons (make_number (fd[0]),
700 build_string (tempfile ? tempfile : ""))));
701#else 710#else
711 cleanup_info_tail = INTEGER_TO_CONS (pid);
712#endif /* not MSDOS */
702 record_unwind_protect (call_process_cleanup, 713 record_unwind_protect (call_process_cleanup,
703 Fcons (Fcurrent_buffer (), 714 Fcons (Fcurrent_buffer (),
704 Fcons (make_number (fd[0]), make_number (pid)))); 715 Fcons (INTEGER_TO_CONS (fd[0]),
705#endif /* not MSDOS */ 716 cleanup_info_tail)));
706
707 717
708 if (BUFFERP (buffer)) 718 if (BUFFERP (buffer))
709 Fset_buffer (buffer); 719 Fset_buffer (buffer);
@@ -759,11 +769,10 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
759 769
760 if (output_to_buffer) 770 if (output_to_buffer)
761 { 771 {
762 register EMACS_INT nread; 772 register int nread;
763 int first = 1; 773 int first = 1;
764 EMACS_INT total_read = 0; 774 EMACS_INT total_read = 0;
765 int carryover = 0; 775 int carryover = 0;
766 int display_p = display_p_volatile;
767 int display_on_the_fly = display_p; 776 int display_on_the_fly = display_p;
768 struct coding_system saved_coding; 777 struct coding_system saved_coding;
769 778
@@ -806,7 +815,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
806 else 815 else
807 { /* We have to decode the input. */ 816 { /* We have to decode the input. */
808 Lisp_Object curbuf; 817 Lisp_Object curbuf;
809 int count1 = SPECPDL_INDEX (); 818 ptrdiff_t count1 = SPECPDL_INDEX ();
810 819
811 XSETBUFFER (curbuf, current_buffer); 820 XSETBUFFER (curbuf, current_buffer);
812 /* We cannot allow after-change-functions be run 821 /* We cannot allow after-change-functions be run
@@ -925,7 +934,7 @@ static Lisp_Object
925delete_temp_file (Lisp_Object name) 934delete_temp_file (Lisp_Object name)
926{ 935{
927 /* Suppress jka-compr handling, etc. */ 936 /* Suppress jka-compr handling, etc. */
928 int count = SPECPDL_INDEX (); 937 ptrdiff_t count = SPECPDL_INDEX ();
929 specbind (intern ("file-name-handler-alist"), Qnil); 938 specbind (intern ("file-name-handler-alist"), Qnil);
930 internal_delete_file (name); 939 internal_delete_file (name);
931 unbind_to (count, Qnil); 940 unbind_to (count, Qnil);
@@ -962,7 +971,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
962 struct gcpro gcpro1; 971 struct gcpro gcpro1;
963 Lisp_Object filename_string; 972 Lisp_Object filename_string;
964 register Lisp_Object start, end; 973 register Lisp_Object start, end;
965 int count = SPECPDL_INDEX (); 974 ptrdiff_t count = SPECPDL_INDEX ();
966 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 975 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
967 Lisp_Object coding_systems; 976 Lisp_Object coding_systems;
968 Lisp_Object val, *args2; 977 Lisp_Object val, *args2;
@@ -1039,7 +1048,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1039 val = complement_process_encoding_system (val); 1048 val = complement_process_encoding_system (val);
1040 1049
1041 { 1050 {
1042 int count1 = SPECPDL_INDEX (); 1051 ptrdiff_t count1 = SPECPDL_INDEX ();
1043 1052
1044 specbind (intern ("coding-system-for-write"), val); 1053 specbind (intern ("coding-system-for-write"), val);
1045 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we 1054 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
@@ -1139,7 +1148,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1139 HANDLE handles[3]; 1148 HANDLE handles[3];
1140#endif /* WINDOWSNT */ 1149#endif /* WINDOWSNT */
1141 1150
1142 int pid = getpid (); 1151 pid_t pid = getpid ();
1143 1152
1144 /* Close Emacs's descriptors that this process should not have. */ 1153 /* Close Emacs's descriptors that this process should not have. */
1145 close_process_descs (); 1154 close_process_descs ();
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 80c05aabc7d..278806b3030 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -82,8 +82,8 @@ casify_object (enum case_action flag, Lisp_Object obj)
82 wrong_type_argument (Qchar_or_string_p, obj); 82 wrong_type_argument (Qchar_or_string_p, obj);
83 else if (!STRING_MULTIBYTE (obj)) 83 else if (!STRING_MULTIBYTE (obj))
84 { 84 {
85 EMACS_INT i; 85 ptrdiff_t i;
86 EMACS_INT size = SCHARS (obj); 86 ptrdiff_t size = SCHARS (obj);
87 87
88 obj = Fcopy_sequence (obj); 88 obj = Fcopy_sequence (obj);
89 for (i = 0; i < size; i++) 89 for (i = 0; i < size; i++)
@@ -111,26 +111,20 @@ casify_object (enum case_action flag, Lisp_Object obj)
111 } 111 }
112 else 112 else
113 { 113 {
114 EMACS_INT i, i_byte, size = SCHARS (obj); 114 ptrdiff_t i, i_byte, size = SCHARS (obj);
115 int len; 115 int len;
116 USE_SAFE_ALLOCA; 116 USE_SAFE_ALLOCA;
117 unsigned char *dst, *o; 117 unsigned char *dst, *o;
118 /* Over-allocate by 12%: this is a minor overhead, but should be 118 ptrdiff_t o_size = (size < STRING_BYTES_BOUND / MAX_MULTIBYTE_LENGTH
119 sufficient in 99.999% of the cases to avoid a reallocation. */ 119 ? size * MAX_MULTIBYTE_LENGTH
120 EMACS_INT o_size = SBYTES (obj) + SBYTES (obj) / 8 + MAX_MULTIBYTE_LENGTH; 120 : STRING_BYTES_BOUND);
121 SAFE_ALLOCA (dst, void *, o_size); 121 SAFE_ALLOCA (dst, void *, o_size);
122 o = dst; 122 o = dst;
123 123
124 for (i = i_byte = 0; i < size; i++, i_byte += len) 124 for (i = i_byte = 0; i < size; i++, i_byte += len)
125 { 125 {
126 if ((o - dst) + MAX_MULTIBYTE_LENGTH > o_size) 126 if (o_size - (o - dst) < MAX_MULTIBYTE_LENGTH)
127 { /* Not enough space for the next char: grow the destination. */ 127 string_overflow ();
128 unsigned char *old_dst = dst;
129 o_size += o_size; /* Probably overkill, but extremely rare. */
130 SAFE_ALLOCA (dst, void *, o_size);
131 memcpy (dst, old_dst, o - old_dst);
132 o = dst + (o - old_dst);
133 }
134 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len); 128 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len);
135 if (inword && flag != CASE_CAPITALIZE_UP) 129 if (inword && flag != CASE_CAPITALIZE_UP)
136 c = downcase (c); 130 c = downcase (c);
@@ -199,14 +193,14 @@ casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e)
199 register int c; 193 register int c;
200 register int inword = flag == CASE_DOWN; 194 register int inword = flag == CASE_DOWN;
201 register int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 195 register int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
202 EMACS_INT start, end; 196 ptrdiff_t start, end;
203 EMACS_INT start_byte; 197 ptrdiff_t start_byte;
204 198
205 /* Position of first and last changes. */ 199 /* Position of first and last changes. */
206 EMACS_INT first = -1, last IF_LINT (= 0); 200 ptrdiff_t first = -1, last IF_LINT (= 0);
207 201
208 EMACS_INT opoint = PT; 202 ptrdiff_t opoint = PT;
209 EMACS_INT opoint_byte = PT_BYTE; 203 ptrdiff_t opoint_byte = PT_BYTE;
210 204
211 if (EQ (b, e)) 205 if (EQ (b, e))
212 /* Not modifying because nothing marked */ 206 /* Not modifying because nothing marked */
@@ -351,10 +345,10 @@ character positions to operate on. */)
351} 345}
352 346
353static Lisp_Object 347static Lisp_Object
354operate_on_word (Lisp_Object arg, EMACS_INT *newpoint) 348operate_on_word (Lisp_Object arg, ptrdiff_t *newpoint)
355{ 349{
356 Lisp_Object val; 350 Lisp_Object val;
357 EMACS_INT farend; 351 ptrdiff_t farend;
358 EMACS_INT iarg; 352 EMACS_INT iarg;
359 353
360 CHECK_NUMBER (arg); 354 CHECK_NUMBER (arg);
@@ -376,7 +370,7 @@ See also `capitalize-word'. */)
376 (Lisp_Object arg) 370 (Lisp_Object arg)
377{ 371{
378 Lisp_Object beg, end; 372 Lisp_Object beg, end;
379 EMACS_INT newpoint; 373 ptrdiff_t newpoint;
380 XSETFASTINT (beg, PT); 374 XSETFASTINT (beg, PT);
381 end = operate_on_word (arg, &newpoint); 375 end = operate_on_word (arg, &newpoint);
382 casify_region (CASE_UP, beg, end); 376 casify_region (CASE_UP, beg, end);
@@ -390,7 +384,7 @@ With negative argument, convert previous words but do not move. */)
390 (Lisp_Object arg) 384 (Lisp_Object arg)
391{ 385{
392 Lisp_Object beg, end; 386 Lisp_Object beg, end;
393 EMACS_INT newpoint; 387 ptrdiff_t newpoint;
394 XSETFASTINT (beg, PT); 388 XSETFASTINT (beg, PT);
395 end = operate_on_word (arg, &newpoint); 389 end = operate_on_word (arg, &newpoint);
396 casify_region (CASE_DOWN, beg, end); 390 casify_region (CASE_DOWN, beg, end);
@@ -406,7 +400,7 @@ With negative argument, capitalize previous words but do not move. */)
406 (Lisp_Object arg) 400 (Lisp_Object arg)
407{ 401{
408 Lisp_Object beg, end; 402 Lisp_Object beg, end;
409 EMACS_INT newpoint; 403 ptrdiff_t newpoint;
410 XSETFASTINT (beg, PT); 404 XSETFASTINT (beg, PT);
411 end = operate_on_word (arg, &newpoint); 405 end = operate_on_word (arg, &newpoint);
412 casify_region (CASE_CAPITALIZE, beg, end); 406 casify_region (CASE_CAPITALIZE, beg, end);
diff --git a/src/casetab.c b/src/casetab.c
index dbc72f485f7..c28f0c08d5e 100644
--- a/src/casetab.c
+++ b/src/casetab.c
@@ -194,8 +194,7 @@ set_identity (Lisp_Object table, Lisp_Object c, Lisp_Object elt)
194{ 194{
195 if (NATNUMP (elt)) 195 if (NATNUMP (elt))
196 { 196 {
197 int from; 197 int from, to;
198 unsigned to;
199 198
200 if (CONSP (c)) 199 if (CONSP (c))
201 { 200 {
@@ -204,7 +203,10 @@ set_identity (Lisp_Object table, Lisp_Object c, Lisp_Object elt)
204 } 203 }
205 else 204 else
206 from = to = XINT (c); 205 from = to = XINT (c);
207 for (to++; from < to; from++) 206
207 to++;
208 lint_assume (to <= MAX_CHAR + 1);
209 for (; from < to; from++)
208 CHAR_TABLE_SET (table, from, make_number (from)); 210 CHAR_TABLE_SET (table, from, make_number (from));
209 } 211 }
210} 212}
@@ -219,8 +221,7 @@ shuffle (Lisp_Object table, Lisp_Object c, Lisp_Object elt)
219{ 221{
220 if (NATNUMP (elt)) 222 if (NATNUMP (elt))
221 { 223 {
222 int from; 224 int from, to;
223 unsigned to;
224 225
225 if (CONSP (c)) 226 if (CONSP (c))
226 { 227 {
@@ -230,7 +231,9 @@ shuffle (Lisp_Object table, Lisp_Object c, Lisp_Object elt)
230 else 231 else
231 from = to = XINT (c); 232 from = to = XINT (c);
232 233
233 for (to++; from < to; from++) 234 to++;
235 lint_assume (to <= MAX_CHAR + 1);
236 for (; from < to; from++)
234 { 237 {
235 Lisp_Object tem = Faref (table, elt); 238 Lisp_Object tem = Faref (table, elt);
236 Faset (table, elt, make_number (from)); 239 Faset (table, elt, make_number (from));
diff --git a/src/category.c b/src/category.c
index 819e7cba364..a59ad3da53e 100644
--- a/src/category.c
+++ b/src/category.c
@@ -304,7 +304,7 @@ DEFUN ("char-category-set", Fchar_category_set, Schar_category_set, 1, 1, 0,
304usage: (char-category-set CHAR) */) 304usage: (char-category-set CHAR) */)
305 (Lisp_Object ch) 305 (Lisp_Object ch)
306{ 306{
307 CHECK_NUMBER (ch); 307 CHECK_CHARACTER (ch);
308 return CATEGORY_SET (XFASTINT (ch)); 308 return CATEGORY_SET (XFASTINT (ch));
309} 309}
310 310
diff --git a/src/category.h b/src/category.h
index 737198cc964..423270100b3 100644
--- a/src/category.h
+++ b/src/category.h
@@ -53,8 +53,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
53 The second extra slot is a version number of the category table. 53 The second extra slot is a version number of the category table.
54 But, for the moment, we are not using this slot. */ 54 But, for the moment, we are not using this slot. */
55 55
56#define CATEGORYP(x) \ 56#define CATEGORYP(x) RANGED_INTEGERP (0x20, x, 0x7E)
57 (INTEGERP ((x)) && XFASTINT ((x)) >= 0x20 && XFASTINT ((x)) <= 0x7E)
58 57
59#define CHECK_CATEGORY(x) \ 58#define CHECK_CATEGORY(x) \
60 CHECK_TYPE (CATEGORYP (x), Qcategoryp, x) 59 CHECK_TYPE (CATEGORYP (x), Qcategoryp, x)
diff --git a/src/ccl.c b/src/ccl.c
index bc6322c35b9..5da90ad4f04 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -762,9 +762,6 @@ while (0)
762#define GET_CCL_CODE(code, ccl_prog, ic) \ 762#define GET_CCL_CODE(code, ccl_prog, ic) \
763 GET_CCL_RANGE (code, ccl_prog, ic, CCL_CODE_MIN, CCL_CODE_MAX) 763 GET_CCL_RANGE (code, ccl_prog, ic, CCL_CODE_MIN, CCL_CODE_MAX)
764 764
765#define GET_CCL_INT(var, ccl_prog, ic) \
766 GET_CCL_RANGE (var, ccl_prog, ic, INT_MIN, INT_MAX)
767
768#define IN_INT_RANGE(val) ASCENDING_ORDER (INT_MIN, val, INT_MAX) 765#define IN_INT_RANGE(val) ASCENDING_ORDER (INT_MIN, val, INT_MAX)
769 766
770/* Encode one character CH to multibyte form and write to the current 767/* Encode one character CH to multibyte form and write to the current
@@ -945,14 +942,14 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
945 break; 942 break;
946 943
947 case CCL_SetConst: /* 00000000000000000000rrrXXXXX */ 944 case CCL_SetConst: /* 00000000000000000000rrrXXXXX */
948 GET_CCL_INT (reg[rrr], ccl_prog, ic++); 945 reg[rrr] = XINT (ccl_prog[ic++]);
949 break; 946 break;
950 947
951 case CCL_SetArray: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */ 948 case CCL_SetArray: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
952 i = reg[RRR]; 949 i = reg[RRR];
953 j = field1 >> 3; 950 j = field1 >> 3;
954 if (0 <= i && i < j) 951 if (0 <= i && i < j)
955 GET_CCL_INT (reg[rrr], ccl_prog, ic + i); 952 reg[rrr] = XINT (ccl_prog[ic + i]);
956 ic += j; 953 ic += j;
957 break; 954 break;
958 955
@@ -980,13 +977,13 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
980 break; 977 break;
981 978
982 case CCL_WriteConstJump: /* A--D--D--R--E--S--S-000XXXXX */ 979 case CCL_WriteConstJump: /* A--D--D--R--E--S--S-000XXXXX */
983 GET_CCL_INT (i, ccl_prog, ic); 980 i = XINT (ccl_prog[ic]);
984 CCL_WRITE_CHAR (i); 981 CCL_WRITE_CHAR (i);
985 ic += ADDR; 982 ic += ADDR;
986 break; 983 break;
987 984
988 case CCL_WriteConstReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */ 985 case CCL_WriteConstReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
989 GET_CCL_INT (i, ccl_prog, ic); 986 i = XINT (ccl_prog[ic]);
990 CCL_WRITE_CHAR (i); 987 CCL_WRITE_CHAR (i);
991 ic++; 988 ic++;
992 CCL_READ_CHAR (reg[rrr]); 989 CCL_READ_CHAR (reg[rrr]);
@@ -994,17 +991,17 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
994 break; 991 break;
995 992
996 case CCL_WriteStringJump: /* A--D--D--R--E--S--S-000XXXXX */ 993 case CCL_WriteStringJump: /* A--D--D--R--E--S--S-000XXXXX */
997 GET_CCL_INT (j, ccl_prog, ic++); 994 j = XINT (ccl_prog[ic++]);
998 CCL_WRITE_STRING (j); 995 CCL_WRITE_STRING (j);
999 ic += ADDR - 1; 996 ic += ADDR - 1;
1000 break; 997 break;
1001 998
1002 case CCL_WriteArrayReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */ 999 case CCL_WriteArrayReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
1003 i = reg[rrr]; 1000 i = reg[rrr];
1004 GET_CCL_INT (j, ccl_prog, ic); 1001 j = XINT (ccl_prog[ic]);
1005 if (0 <= i && i < j) 1002 if (0 <= i && i < j)
1006 { 1003 {
1007 GET_CCL_INT (i, ccl_prog, ic + 1 + i); 1004 i = XINT (ccl_prog[ic + 1 + i]);
1008 CCL_WRITE_CHAR (i); 1005 CCL_WRITE_CHAR (i);
1009 } 1006 }
1010 ic += j + 2; 1007 ic += j + 2;
@@ -1022,11 +1019,8 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1022 /* fall through ... */ 1019 /* fall through ... */
1023 case CCL_Branch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */ 1020 case CCL_Branch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1024 { 1021 {
1025 int incr; 1022 int ioff = 0 <= reg[rrr] && reg[rrr] < field1 ? reg[rrr] : field1;
1026 GET_CCL_INT (incr, ccl_prog, 1023 int incr = XINT (ccl_prog[ic + ioff]);
1027 ic + (0 <= reg[rrr] && reg[rrr] < field1
1028 ? reg[rrr]
1029 : field1));
1030 ic += incr; 1024 ic += incr;
1031 } 1025 }
1032 break; 1026 break;
@@ -1045,7 +1039,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1045 case CCL_WriteExprConst: /* 1:00000OPERATION000RRR000XXXXX */ 1039 case CCL_WriteExprConst: /* 1:00000OPERATION000RRR000XXXXX */
1046 rrr = 7; 1040 rrr = 7;
1047 i = reg[RRR]; 1041 i = reg[RRR];
1048 GET_CCL_INT (j, ccl_prog, ic); 1042 j = XINT (ccl_prog[ic]);
1049 op = field1 >> 6; 1043 op = field1 >> 6;
1050 jump_address = ic + 1; 1044 jump_address = ic + 1;
1051 goto ccl_set_expr; 1045 goto ccl_set_expr;
@@ -1078,7 +1072,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1078 /* If FFF is nonzero, the CCL program ID is in the 1072 /* If FFF is nonzero, the CCL program ID is in the
1079 following code. */ 1073 following code. */
1080 if (rrr) 1074 if (rrr)
1081 GET_CCL_INT (prog_id, ccl_prog, ic++); 1075 prog_id = XINT (ccl_prog[ic++]);
1082 else 1076 else
1083 prog_id = field1; 1077 prog_id = field1;
1084 1078
@@ -1121,7 +1115,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1121 i = reg[rrr]; 1115 i = reg[rrr];
1122 if (0 <= i && i < field1) 1116 if (0 <= i && i < field1)
1123 { 1117 {
1124 GET_CCL_INT (j, ccl_prog, ic + i); 1118 j = XINT (ccl_prog[ic + i]);
1125 CCL_WRITE_CHAR (j); 1119 CCL_WRITE_CHAR (j);
1126 } 1120 }
1127 ic += field1; 1121 ic += field1;
@@ -1146,7 +1140,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1146 CCL_SUCCESS; 1140 CCL_SUCCESS;
1147 1141
1148 case CCL_ExprSelfConst: /* 00000OPERATION000000rrrXXXXX */ 1142 case CCL_ExprSelfConst: /* 00000OPERATION000000rrrXXXXX */
1149 GET_CCL_INT (i, ccl_prog, ic++); 1143 i = XINT (ccl_prog[ic++]);
1150 op = field1 >> 6; 1144 op = field1 >> 6;
1151 goto ccl_expr_self; 1145 goto ccl_expr_self;
1152 1146
@@ -1182,7 +1176,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1182 1176
1183 case CCL_SetExprConst: /* 00000OPERATION000RRRrrrXXXXX */ 1177 case CCL_SetExprConst: /* 00000OPERATION000RRRrrrXXXXX */
1184 i = reg[RRR]; 1178 i = reg[RRR];
1185 GET_CCL_INT (j, ccl_prog, ic++); 1179 j = XINT (ccl_prog[ic++]);
1186 op = field1 >> 6; 1180 op = field1 >> 6;
1187 jump_address = ic; 1181 jump_address = ic;
1188 goto ccl_set_expr; 1182 goto ccl_set_expr;
@@ -1199,8 +1193,8 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1199 case CCL_JumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */ 1193 case CCL_JumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */
1200 i = reg[rrr]; 1194 i = reg[rrr];
1201 jump_address = ic + ADDR; 1195 jump_address = ic + ADDR;
1202 GET_CCL_INT (op, ccl_prog, ic++); 1196 op = XINT (ccl_prog[ic++]);
1203 GET_CCL_INT (j, ccl_prog, ic++); 1197 j = XINT (ccl_prog[ic++]);
1204 rrr = 7; 1198 rrr = 7;
1205 goto ccl_set_expr; 1199 goto ccl_set_expr;
1206 1200
@@ -1209,7 +1203,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1209 case CCL_JumpCondExprReg: 1203 case CCL_JumpCondExprReg:
1210 i = reg[rrr]; 1204 i = reg[rrr];
1211 jump_address = ic + ADDR; 1205 jump_address = ic + ADDR;
1212 GET_CCL_INT (op, ccl_prog, ic++); 1206 op = XINT (ccl_prog[ic++]);
1213 GET_CCL_RANGE (j, ccl_prog, ic++, 0, 7); 1207 GET_CCL_RANGE (j, ccl_prog, ic++, 0, 7);
1214 j = reg[j]; 1208 j = reg[j];
1215 rrr = 7; 1209 rrr = 7;
@@ -1290,7 +1284,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1290 1284
1291 case CCL_TranslateCharacterConstTbl: 1285 case CCL_TranslateCharacterConstTbl:
1292 { 1286 {
1293 EMACS_INT eop; 1287 ptrdiff_t eop;
1294 GET_CCL_RANGE (eop, ccl_prog, ic++, 0, 1288 GET_CCL_RANGE (eop, ccl_prog, ic++, 0,
1295 (VECTORP (Vtranslation_table_vector) 1289 (VECTORP (Vtranslation_table_vector)
1296 ? ASIZE (Vtranslation_table_vector) 1290 ? ASIZE (Vtranslation_table_vector)
@@ -1356,10 +1350,11 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1356 case CCL_IterateMultipleMap: 1350 case CCL_IterateMultipleMap:
1357 { 1351 {
1358 Lisp_Object map, content, attrib, value; 1352 Lisp_Object map, content, attrib, value;
1359 EMACS_INT point, size; 1353 EMACS_INT point;
1354 ptrdiff_t size;
1360 int fin_ic; 1355 int fin_ic;
1361 1356
1362 GET_CCL_INT (j, ccl_prog, ic++); /* number of maps. */ 1357 j = XINT (ccl_prog[ic++]); /* number of maps. */
1363 fin_ic = ic + j; 1358 fin_ic = ic + j;
1364 op = reg[rrr]; 1359 op = reg[rrr];
1365 if ((j > reg[RRR]) && (j >= 0)) 1360 if ((j > reg[RRR]) && (j >= 0))
@@ -1376,7 +1371,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1376 1371
1377 for (;i < j;i++) 1372 for (;i < j;i++)
1378 { 1373 {
1379 1374 if (!VECTORP (Vcode_conversion_map_vector)) continue;
1380 size = ASIZE (Vcode_conversion_map_vector); 1375 size = ASIZE (Vcode_conversion_map_vector);
1381 point = XINT (ccl_prog[ic++]); 1376 point = XINT (ccl_prog[ic++]);
1382 if (! (0 <= point && point < size)) continue; 1377 if (! (0 <= point && point < size)) continue;
@@ -1452,7 +1447,8 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1452 case CCL_MapMultiple: 1447 case CCL_MapMultiple:
1453 { 1448 {
1454 Lisp_Object map, content, attrib, value; 1449 Lisp_Object map, content, attrib, value;
1455 int point, size, map_vector_size; 1450 EMACS_INT point;
1451 ptrdiff_t size, map_vector_size;
1456 int map_set_rest_length, fin_ic; 1452 int map_set_rest_length, fin_ic;
1457 int current_ic = this_ic; 1453 int current_ic = this_ic;
1458 1454
@@ -1471,7 +1467,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1471 stack_idx_of_map_multiple = 0; 1467 stack_idx_of_map_multiple = 0;
1472 1468
1473 /* Get number of maps and separators. */ 1469 /* Get number of maps and separators. */
1474 GET_CCL_INT (map_set_rest_length, ccl_prog, ic++); 1470 map_set_rest_length = XINT (ccl_prog[ic++]);
1475 1471
1476 fin_ic = ic + map_set_rest_length; 1472 fin_ic = ic + map_set_rest_length;
1477 op = reg[rrr]; 1473 op = reg[rrr];
@@ -1535,12 +1531,14 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1535 break; 1531 break;
1536 } 1532 }
1537 } 1533 }
1534 if (!VECTORP (Vcode_conversion_map_vector))
1535 CCL_INVALID_CMD;
1538 map_vector_size = ASIZE (Vcode_conversion_map_vector); 1536 map_vector_size = ASIZE (Vcode_conversion_map_vector);
1539 1537
1540 do { 1538 do {
1541 for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--) 1539 for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--)
1542 { 1540 {
1543 GET_CCL_INT (point, ccl_prog, ic); 1541 point = XINT (ccl_prog[ic]);
1544 if (point < 0) 1542 if (point < 0)
1545 { 1543 {
1546 /* +1 is for including separator. */ 1544 /* +1 is for including separator. */
@@ -1657,7 +1655,8 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1657 int point; 1655 int point;
1658 j = XINT (ccl_prog[ic++]); /* map_id */ 1656 j = XINT (ccl_prog[ic++]); /* map_id */
1659 op = reg[rrr]; 1657 op = reg[rrr];
1660 if (j >= ASIZE (Vcode_conversion_map_vector)) 1658 if (! (VECTORP (Vcode_conversion_map_vector)
1659 && j < ASIZE (Vcode_conversion_map_vector)))
1661 { 1660 {
1662 reg[RRR] = -1; 1661 reg[RRR] = -1;
1663 break; 1662 break;
@@ -1670,6 +1669,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1670 } 1669 }
1671 map = XCDR (map); 1670 map = XCDR (map);
1672 if (! (VECTORP (map) 1671 if (! (VECTORP (map)
1672 && 0 < ASIZE (map)
1673 && INTEGERP (AREF (map, 0)) 1673 && INTEGERP (AREF (map, 0))
1674 && XINT (AREF (map, 0)) <= op 1674 && XINT (AREF (map, 0)) <= op
1675 && op - XINT (AREF (map, 0)) + 1 < ASIZE (map))) 1675 && op - XINT (AREF (map, 0)) + 1 < ASIZE (map)))
@@ -1677,20 +1677,20 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1677 reg[RRR] = -1; 1677 reg[RRR] = -1;
1678 break; 1678 break;
1679 } 1679 }
1680 point = XINT (AREF (map, 0)); 1680 point = op - XINT (AREF (map, 0)) + 1;
1681 point = op - point + 1;
1682 reg[RRR] = 0; 1681 reg[RRR] = 0;
1683 content = AREF (map, point); 1682 content = AREF (map, point);
1684 if (NILP (content)) 1683 if (NILP (content))
1685 reg[RRR] = -1; 1684 reg[RRR] = -1;
1686 else if (INTEGERP (content)) 1685 else if (TYPE_RANGED_INTEGERP (int, content))
1687 reg[rrr] = XINT (content); 1686 reg[rrr] = XINT (content);
1688 else if (EQ (content, Qt)); 1687 else if (EQ (content, Qt));
1689 else if (CONSP (content)) 1688 else if (CONSP (content))
1690 { 1689 {
1691 attrib = XCAR (content); 1690 attrib = XCAR (content);
1692 value = XCDR (content); 1691 value = XCDR (content);
1693 if (!INTEGERP (attrib) || !INTEGERP (value)) 1692 if (!INTEGERP (attrib)
1693 || !TYPE_RANGED_INTEGERP (int, value))
1694 continue; 1694 continue;
1695 reg[rrr] = XINT (value); 1695 reg[rrr] = XINT (value);
1696 break; 1696 break;
@@ -1810,8 +1810,8 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1810 function converts symbols of code conversion maps and character 1810 function converts symbols of code conversion maps and character
1811 translation tables embedded in the CCL code into their ID numbers. 1811 translation tables embedded in the CCL code into their ID numbers.
1812 1812
1813 The return value is a vector (CCL itself or a new vector in which 1813 The return value is a new vector in which all symbols are resolved,
1814 all symbols are resolved), Qt if resolving of some symbol failed, 1814 Qt if resolving of some symbol failed,
1815 or nil if CCL contains invalid data. */ 1815 or nil if CCL contains invalid data. */
1816 1816
1817static Lisp_Object 1817static Lisp_Object
@@ -1820,13 +1820,15 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1820 int i, veclen, unresolved = 0; 1820 int i, veclen, unresolved = 0;
1821 Lisp_Object result, contents, val; 1821 Lisp_Object result, contents, val;
1822 1822
1823 result = ccl; 1823 if (! (CCL_HEADER_MAIN < ASIZE (ccl) && ASIZE (ccl) <= INT_MAX))
1824 return Qnil;
1825 result = Fcopy_sequence (ccl);
1824 veclen = ASIZE (result); 1826 veclen = ASIZE (result);
1825 1827
1826 for (i = 0; i < veclen; i++) 1828 for (i = 0; i < veclen; i++)
1827 { 1829 {
1828 contents = AREF (result, i); 1830 contents = AREF (result, i);
1829 if (INTEGERP (contents)) 1831 if (TYPE_RANGED_INTEGERP (int, contents))
1830 continue; 1832 continue;
1831 else if (CONSP (contents) 1833 else if (CONSP (contents)
1832 && SYMBOLP (XCAR (contents)) 1834 && SYMBOLP (XCAR (contents))
@@ -1835,12 +1837,8 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1835 /* This is the new style for embedding symbols. The form is 1837 /* This is the new style for embedding symbols. The form is
1836 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give 1838 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
1837 an index number. */ 1839 an index number. */
1838
1839 if (EQ (result, ccl))
1840 result = Fcopy_sequence (ccl);
1841
1842 val = Fget (XCAR (contents), XCDR (contents)); 1840 val = Fget (XCAR (contents), XCDR (contents));
1843 if (NATNUMP (val)) 1841 if (RANGED_INTEGERP (0, val, INT_MAX))
1844 ASET (result, i, val); 1842 ASET (result, i, val);
1845 else 1843 else
1846 unresolved = 1; 1844 unresolved = 1;
@@ -1851,21 +1849,18 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1851 /* This is the old style for embedding symbols. This style 1849 /* This is the old style for embedding symbols. This style
1852 may lead to a bug if, for instance, a translation table 1850 may lead to a bug if, for instance, a translation table
1853 and a code conversion map have the same name. */ 1851 and a code conversion map have the same name. */
1854 if (EQ (result, ccl))
1855 result = Fcopy_sequence (ccl);
1856
1857 val = Fget (contents, Qtranslation_table_id); 1852 val = Fget (contents, Qtranslation_table_id);
1858 if (NATNUMP (val)) 1853 if (RANGED_INTEGERP (0, val, INT_MAX))
1859 ASET (result, i, val); 1854 ASET (result, i, val);
1860 else 1855 else
1861 { 1856 {
1862 val = Fget (contents, Qcode_conversion_map_id); 1857 val = Fget (contents, Qcode_conversion_map_id);
1863 if (NATNUMP (val)) 1858 if (RANGED_INTEGERP (0, val, INT_MAX))
1864 ASET (result, i, val); 1859 ASET (result, i, val);
1865 else 1860 else
1866 { 1861 {
1867 val = Fget (contents, Qccl_program_idx); 1862 val = Fget (contents, Qccl_program_idx);
1868 if (NATNUMP (val)) 1863 if (RANGED_INTEGERP (0, val, INT_MAX))
1869 ASET (result, i, val); 1864 ASET (result, i, val);
1870 else 1865 else
1871 unresolved = 1; 1866 unresolved = 1;
@@ -1876,6 +1871,11 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1876 return Qnil; 1871 return Qnil;
1877 } 1872 }
1878 1873
1874 if (! (0 <= XINT (AREF (result, CCL_HEADER_BUF_MAG))
1875 && ASCENDING_ORDER (0, XINT (AREF (result, CCL_HEADER_EOF)),
1876 ASIZE (ccl))))
1877 return Qnil;
1878
1879 return (unresolved ? Qt : result); 1879 return (unresolved ? Qt : result);
1880} 1880}
1881 1881
@@ -1886,7 +1886,7 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1886 symbols, return Qnil. */ 1886 symbols, return Qnil. */
1887 1887
1888static Lisp_Object 1888static Lisp_Object
1889ccl_get_compiled_code (Lisp_Object ccl_prog, int *idx) 1889ccl_get_compiled_code (Lisp_Object ccl_prog, ptrdiff_t *idx)
1890{ 1890{
1891 Lisp_Object val, slot; 1891 Lisp_Object val, slot;
1892 1892
@@ -2015,7 +2015,7 @@ programs. */)
2015 error ("Length of vector REGISTERS is not 8"); 2015 error ("Length of vector REGISTERS is not 8");
2016 2016
2017 for (i = 0; i < 8; i++) 2017 for (i = 0; i < 8; i++)
2018 ccl.reg[i] = (INTEGERP (AREF (reg, i)) 2018 ccl.reg[i] = (TYPE_RANGED_INTEGERP (int, AREF (reg, i))
2019 ? XINT (AREF (reg, i)) 2019 ? XINT (AREF (reg, i))
2020 : 0); 2020 : 0);
2021 2021
@@ -2084,7 +2084,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2084 { 2084 {
2085 if (NILP (AREF (status, i))) 2085 if (NILP (AREF (status, i)))
2086 ASET (status, i, make_number (0)); 2086 ASET (status, i, make_number (0));
2087 if (INTEGERP (AREF (status, i))) 2087 if (TYPE_RANGED_INTEGERP (int, AREF (status, i)))
2088 ccl.reg[i] = XINT (AREF (status, i)); 2088 ccl.reg[i] = XINT (AREF (status, i));
2089 } 2089 }
2090 if (INTEGERP (AREF (status, i))) 2090 if (INTEGERP (AREF (status, i)))
@@ -2187,8 +2187,8 @@ If it is nil, just reserve NAME as a CCL program name.
2187Return index number of the registered CCL program. */) 2187Return index number of the registered CCL program. */)
2188 (Lisp_Object name, Lisp_Object ccl_prog) 2188 (Lisp_Object name, Lisp_Object ccl_prog)
2189{ 2189{
2190 int len = ASIZE (Vccl_program_table); 2190 ptrdiff_t len = ASIZE (Vccl_program_table);
2191 int idx; 2191 ptrdiff_t idx;
2192 Lisp_Object resolved; 2192 Lisp_Object resolved;
2193 2193
2194 CHECK_SYMBOL (name); 2194 CHECK_SYMBOL (name);
@@ -2229,7 +2229,7 @@ Return index number of the registered CCL program. */)
2229 2229
2230 if (idx == len) 2230 if (idx == len)
2231 /* Extend the table. */ 2231 /* Extend the table. */
2232 Vccl_program_table = larger_vector (Vccl_program_table, len * 2, Qnil); 2232 Vccl_program_table = larger_vector (Vccl_program_table, 1, -1);
2233 2233
2234 { 2234 {
2235 Lisp_Object elt; 2235 Lisp_Object elt;
@@ -2262,12 +2262,16 @@ DEFUN ("register-code-conversion-map", Fregister_code_conversion_map,
2262Return index number of the registered map. */) 2262Return index number of the registered map. */)
2263 (Lisp_Object symbol, Lisp_Object map) 2263 (Lisp_Object symbol, Lisp_Object map)
2264{ 2264{
2265 int len = ASIZE (Vcode_conversion_map_vector); 2265 ptrdiff_t len;
2266 int i; 2266 ptrdiff_t i;
2267 Lisp_Object idx; 2267 Lisp_Object idx;
2268 2268
2269 CHECK_SYMBOL (symbol); 2269 CHECK_SYMBOL (symbol);
2270 CHECK_VECTOR (map); 2270 CHECK_VECTOR (map);
2271 if (! VECTORP (Vcode_conversion_map_vector))
2272 error ("Invalid code-conversion-map-vector");
2273
2274 len = ASIZE (Vcode_conversion_map_vector);
2271 2275
2272 for (i = 0; i < len; i++) 2276 for (i = 0; i < len; i++)
2273 { 2277 {
@@ -2288,7 +2292,7 @@ Return index number of the registered map. */)
2288 2292
2289 if (i == len) 2293 if (i == len)
2290 Vcode_conversion_map_vector = larger_vector (Vcode_conversion_map_vector, 2294 Vcode_conversion_map_vector = larger_vector (Vcode_conversion_map_vector,
2291 len * 2, Qnil); 2295 1, -1);
2292 2296
2293 idx = make_number (i); 2297 idx = make_number (i);
2294 Fput (symbol, Qcode_conversion_map, map); 2298 Fput (symbol, Qcode_conversion_map, map);
diff --git a/src/ccl.h b/src/ccl.h
index e86154352a3..f55b295027e 100644
--- a/src/ccl.h
+++ b/src/ccl.h
@@ -37,7 +37,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37/* Structure to hold information about running CCL code. Read 37/* Structure to hold information about running CCL code. Read
38 comments in the file ccl.c for the detail of each field. */ 38 comments in the file ccl.c for the detail of each field. */
39struct ccl_program { 39struct ccl_program {
40 int idx; /* Index number of the CCL program. 40 ptrdiff_t idx; /* Index number of the CCL program.
41 -1 means that the program was given 41 -1 means that the program was given
42 by a vector, not by a program 42 by a vector, not by a program
43 name. */ 43 name. */
diff --git a/src/character.c b/src/character.c
index 82bc2bfef4e..b85cedad937 100644
--- a/src/character.c
+++ b/src/character.c
@@ -67,8 +67,8 @@ static Lisp_Object Qchar_script_table;
67/* If character code C has modifier masks, reflect them to the 67/* If character code C has modifier masks, reflect them to the
68 character code if possible. Return the resulting code. */ 68 character code if possible. Return the resulting code. */
69 69
70int 70EMACS_INT
71char_resolve_modifier_mask (int c) 71char_resolve_modifier_mask (EMACS_INT c)
72{ 72{
73 /* A non-ASCII character can't reflect modifier bits to the code. */ 73 /* A non-ASCII character can't reflect modifier bits to the code. */
74 if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) 74 if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
@@ -311,10 +311,10 @@ If the multibyte character does not represent a byte, return -1. */)
311 311
312/* Return width (columns) of C considering the buffer display table DP. */ 312/* Return width (columns) of C considering the buffer display table DP. */
313 313
314static EMACS_INT 314static ptrdiff_t
315char_width (int c, struct Lisp_Char_Table *dp) 315char_width (int c, struct Lisp_Char_Table *dp)
316{ 316{
317 EMACS_INT width = CHAR_WIDTH (c); 317 ptrdiff_t width = CHAR_WIDTH (c);
318 318
319 if (dp) 319 if (dp)
320 { 320 {
@@ -346,7 +346,7 @@ usage: (char-width CHAR) */)
346 (Lisp_Object ch) 346 (Lisp_Object ch)
347{ 347{
348 int c; 348 int c;
349 EMACS_INT width; 349 ptrdiff_t width;
350 350
351 CHECK_CHARACTER (ch); 351 CHECK_CHARACTER (ch);
352 c = XINT (ch); 352 c = XINT (ch);
@@ -361,19 +361,19 @@ usage: (char-width CHAR) */)
361 characters and bytes of the substring in *NCHARS and *NBYTES 361 characters and bytes of the substring in *NCHARS and *NBYTES
362 respectively. */ 362 respectively. */
363 363
364EMACS_INT 364ptrdiff_t
365c_string_width (const unsigned char *str, EMACS_INT len, int precision, 365c_string_width (const unsigned char *str, ptrdiff_t len, int precision,
366 EMACS_INT *nchars, EMACS_INT *nbytes) 366 ptrdiff_t *nchars, ptrdiff_t *nbytes)
367{ 367{
368 EMACS_INT i = 0, i_byte = 0; 368 ptrdiff_t i = 0, i_byte = 0;
369 EMACS_INT width = 0; 369 ptrdiff_t width = 0;
370 struct Lisp_Char_Table *dp = buffer_display_table (); 370 struct Lisp_Char_Table *dp = buffer_display_table ();
371 371
372 while (i_byte < len) 372 while (i_byte < len)
373 { 373 {
374 int bytes; 374 int bytes;
375 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); 375 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
376 EMACS_INT thiswidth = char_width (c, dp); 376 ptrdiff_t thiswidth = char_width (c, dp);
377 377
378 if (precision <= 0) 378 if (precision <= 0)
379 { 379 {
@@ -404,8 +404,8 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision,
404 current buffer. The width is measured by how many columns it 404 current buffer. The width is measured by how many columns it
405 occupies on the screen. */ 405 occupies on the screen. */
406 406
407EMACS_INT 407ptrdiff_t
408strwidth (const char *str, EMACS_INT len) 408strwidth (const char *str, ptrdiff_t len)
409{ 409{
410 return c_string_width ((const unsigned char *) str, len, -1, NULL, NULL); 410 return c_string_width ((const unsigned char *) str, len, -1, NULL, NULL);
411} 411}
@@ -417,26 +417,26 @@ strwidth (const char *str, EMACS_INT len)
417 PRECISION, and set number of characters and bytes of the substring 417 PRECISION, and set number of characters and bytes of the substring
418 in *NCHARS and *NBYTES respectively. */ 418 in *NCHARS and *NBYTES respectively. */
419 419
420EMACS_INT 420ptrdiff_t
421lisp_string_width (Lisp_Object string, EMACS_INT precision, 421lisp_string_width (Lisp_Object string, ptrdiff_t precision,
422 EMACS_INT *nchars, EMACS_INT *nbytes) 422 ptrdiff_t *nchars, ptrdiff_t *nbytes)
423{ 423{
424 EMACS_INT len = SCHARS (string); 424 ptrdiff_t len = SCHARS (string);
425 /* This set multibyte to 0 even if STRING is multibyte when it 425 /* This set multibyte to 0 even if STRING is multibyte when it
426 contains only ascii and eight-bit-graphic, but that's 426 contains only ascii and eight-bit-graphic, but that's
427 intentional. */ 427 intentional. */
428 int multibyte = len < SBYTES (string); 428 int multibyte = len < SBYTES (string);
429 unsigned char *str = SDATA (string); 429 unsigned char *str = SDATA (string);
430 EMACS_INT i = 0, i_byte = 0; 430 ptrdiff_t i = 0, i_byte = 0;
431 EMACS_INT width = 0; 431 ptrdiff_t width = 0;
432 struct Lisp_Char_Table *dp = buffer_display_table (); 432 struct Lisp_Char_Table *dp = buffer_display_table ();
433 433
434 while (i < len) 434 while (i < len)
435 { 435 {
436 EMACS_INT chars, bytes, thiswidth; 436 ptrdiff_t chars, bytes, thiswidth;
437 Lisp_Object val; 437 Lisp_Object val;
438 ptrdiff_t cmp_id; 438 ptrdiff_t cmp_id;
439 EMACS_INT ignore, end; 439 ptrdiff_t ignore, end;
440 440
441 if (find_composition (i, -1, &ignore, &end, &val, string) 441 if (find_composition (i, -1, &ignore, &end, &val, string)
442 && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string)) 442 && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string))
@@ -512,8 +512,8 @@ usage: (string-width STRING) */)
512 However, if the current buffer has enable-multibyte-characters = 512 However, if the current buffer has enable-multibyte-characters =
513 nil, we treat each byte as a character. */ 513 nil, we treat each byte as a character. */
514 514
515EMACS_INT 515ptrdiff_t
516chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) 516chars_in_text (const unsigned char *ptr, ptrdiff_t nbytes)
517{ 517{
518 /* current_buffer is null at early stages of Emacs initialization. */ 518 /* current_buffer is null at early stages of Emacs initialization. */
519 if (current_buffer == 0 519 if (current_buffer == 0
@@ -528,15 +528,15 @@ chars_in_text (const unsigned char *ptr, EMACS_INT nbytes)
528 sequences while assuming that there's no invalid sequence. It 528 sequences while assuming that there's no invalid sequence. It
529 ignores enable-multibyte-characters. */ 529 ignores enable-multibyte-characters. */
530 530
531EMACS_INT 531ptrdiff_t
532multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) 532multibyte_chars_in_text (const unsigned char *ptr, ptrdiff_t nbytes)
533{ 533{
534 const unsigned char *endp = ptr + nbytes; 534 const unsigned char *endp = ptr + nbytes;
535 EMACS_INT chars = 0; 535 ptrdiff_t chars = 0;
536 536
537 while (ptr < endp) 537 while (ptr < endp)
538 { 538 {
539 EMACS_INT len = MULTIBYTE_LENGTH (ptr, endp); 539 int len = MULTIBYTE_LENGTH (ptr, endp);
540 540
541 if (len == 0) 541 if (len == 0)
542 abort (); 542 abort ();
@@ -554,11 +554,12 @@ multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes)
554 represented by 2-byte in a multibyte text. */ 554 represented by 2-byte in a multibyte text. */
555 555
556void 556void
557parse_str_as_multibyte (const unsigned char *str, EMACS_INT len, 557parse_str_as_multibyte (const unsigned char *str, ptrdiff_t len,
558 EMACS_INT *nchars, EMACS_INT *nbytes) 558 ptrdiff_t *nchars, ptrdiff_t *nbytes)
559{ 559{
560 const unsigned char *endp = str + len; 560 const unsigned char *endp = str + len;
561 EMACS_INT n, chars = 0, bytes = 0; 561 int n;
562 ptrdiff_t chars = 0, bytes = 0;
562 563
563 if (len >= MAX_MULTIBYTE_LENGTH) 564 if (len >= MAX_MULTIBYTE_LENGTH)
564 { 565 {
@@ -596,13 +597,13 @@ parse_str_as_multibyte (const unsigned char *str, EMACS_INT len,
596 area and that is enough. Return the number of bytes of the 597 area and that is enough. Return the number of bytes of the
597 resulting text. */ 598 resulting text. */
598 599
599EMACS_INT 600ptrdiff_t
600str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes, 601str_as_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t nbytes,
601 EMACS_INT *nchars) 602 ptrdiff_t *nchars)
602{ 603{
603 unsigned char *p = str, *endp = str + nbytes; 604 unsigned char *p = str, *endp = str + nbytes;
604 unsigned char *to; 605 unsigned char *to;
605 EMACS_INT chars = 0; 606 ptrdiff_t chars = 0;
606 int n; 607 int n;
607 608
608 if (nbytes >= MAX_MULTIBYTE_LENGTH) 609 if (nbytes >= MAX_MULTIBYTE_LENGTH)
@@ -673,11 +674,11 @@ str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes,
673 bytes it may occupy when converted to multibyte string by 674 bytes it may occupy when converted to multibyte string by
674 `str_to_multibyte'. */ 675 `str_to_multibyte'. */
675 676
676EMACS_INT 677ptrdiff_t
677count_size_as_multibyte (const unsigned char *str, EMACS_INT len) 678count_size_as_multibyte (const unsigned char *str, ptrdiff_t len)
678{ 679{
679 const unsigned char *endp = str + len; 680 const unsigned char *endp = str + len;
680 EMACS_INT bytes; 681 ptrdiff_t bytes;
681 682
682 for (bytes = 0; str < endp; str++) 683 for (bytes = 0; str < endp; str++)
683 { 684 {
@@ -696,8 +697,8 @@ count_size_as_multibyte (const unsigned char *str, EMACS_INT len)
696 that we can use LEN bytes at STR as a work area and that is 697 that we can use LEN bytes at STR as a work area and that is
697 enough. */ 698 enough. */
698 699
699EMACS_INT 700ptrdiff_t
700str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes) 701str_to_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t bytes)
701{ 702{
702 unsigned char *p = str, *endp = str + bytes; 703 unsigned char *p = str, *endp = str + bytes;
703 unsigned char *to; 704 unsigned char *to;
@@ -725,8 +726,8 @@ str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes)
725 actually converts characters in the range 0x80..0xFF to 726 actually converts characters in the range 0x80..0xFF to
726 unibyte. */ 727 unibyte. */
727 728
728EMACS_INT 729ptrdiff_t
729str_as_unibyte (unsigned char *str, EMACS_INT bytes) 730str_as_unibyte (unsigned char *str, ptrdiff_t bytes)
730{ 731{
731 const unsigned char *p = str, *endp = str + bytes; 732 const unsigned char *p = str, *endp = str + bytes;
732 unsigned char *to; 733 unsigned char *to;
@@ -767,10 +768,10 @@ str_as_unibyte (unsigned char *str, EMACS_INT bytes)
767 of that character code. 768 of that character code.
768 Note: Currently the arg ACCEPT_LATIN_1 is not used. */ 769 Note: Currently the arg ACCEPT_LATIN_1 is not used. */
769 770
770EMACS_INT 771ptrdiff_t
771str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, int accept_latin_1) 772str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars, int accept_latin_1)
772{ 773{
773 EMACS_INT i; 774 ptrdiff_t i;
774 775
775 for (i = 0; i < chars; i++) 776 for (i = 0; i < chars; i++)
776 { 777 {
@@ -787,14 +788,14 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, i
787} 788}
788 789
789 790
790static EMACS_INT 791static ptrdiff_t
791string_count_byte8 (Lisp_Object string) 792string_count_byte8 (Lisp_Object string)
792{ 793{
793 int multibyte = STRING_MULTIBYTE (string); 794 int multibyte = STRING_MULTIBYTE (string);
794 EMACS_INT nbytes = SBYTES (string); 795 ptrdiff_t nbytes = SBYTES (string);
795 unsigned char *p = SDATA (string); 796 unsigned char *p = SDATA (string);
796 unsigned char *pend = p + nbytes; 797 unsigned char *pend = p + nbytes;
797 EMACS_INT count = 0; 798 ptrdiff_t count = 0;
798 int c, len; 799 int c, len;
799 800
800 if (multibyte) 801 if (multibyte)
@@ -820,10 +821,10 @@ string_count_byte8 (Lisp_Object string)
820Lisp_Object 821Lisp_Object
821string_escape_byte8 (Lisp_Object string) 822string_escape_byte8 (Lisp_Object string)
822{ 823{
823 EMACS_INT nchars = SCHARS (string); 824 ptrdiff_t nchars = SCHARS (string);
824 EMACS_INT nbytes = SBYTES (string); 825 ptrdiff_t nbytes = SBYTES (string);
825 int multibyte = STRING_MULTIBYTE (string); 826 int multibyte = STRING_MULTIBYTE (string);
826 EMACS_INT byte8_count; 827 ptrdiff_t byte8_count;
827 const unsigned char *src, *src_end; 828 const unsigned char *src, *src_end;
828 unsigned char *dst; 829 unsigned char *dst;
829 Lisp_Object val; 830 Lisp_Object val;
@@ -924,7 +925,6 @@ usage: (unibyte-string &rest BYTES) */)
924 (ptrdiff_t n, Lisp_Object *args) 925 (ptrdiff_t n, Lisp_Object *args)
925{ 926{
926 ptrdiff_t i; 927 ptrdiff_t i;
927 int c;
928 unsigned char *buf, *p; 928 unsigned char *buf, *p;
929 Lisp_Object str; 929 Lisp_Object str;
930 USE_SAFE_ALLOCA; 930 USE_SAFE_ALLOCA;
@@ -934,11 +934,8 @@ usage: (unibyte-string &rest BYTES) */)
934 934
935 for (i = 0; i < n; i++) 935 for (i = 0; i < n; i++)
936 { 936 {
937 CHECK_NATNUM (args[i]); 937 CHECK_RANGED_INTEGER (0, args[i], 255);
938 c = XFASTINT (args[i]); 938 *p++ = XINT (args[i]);
939 if (c >= 256)
940 args_out_of_range_3 (args[i], make_number (0), make_number (255));
941 *p++ = c;
942 } 939 }
943 940
944 str = make_string_from_bytes ((char *) buf, n, p - buf); 941 str = make_string_from_bytes ((char *) buf, n, p - buf);
@@ -954,7 +951,7 @@ code. Unresolved modifiers are kept in the value.
954usage: (char-resolve-modifiers CHAR) */) 951usage: (char-resolve-modifiers CHAR) */)
955 (Lisp_Object character) 952 (Lisp_Object character)
956{ 953{
957 int c; 954 EMACS_INT c;
958 955
959 CHECK_NUMBER (character); 956 CHECK_NUMBER (character);
960 c = XINT (character); 957 c = XINT (character);
@@ -974,7 +971,7 @@ character is not ASCII nor 8-bit character, an error is signaled. */)
974 (Lisp_Object position, Lisp_Object string) 971 (Lisp_Object position, Lisp_Object string)
975{ 972{
976 int c; 973 int c;
977 EMACS_INT pos; 974 ptrdiff_t pos;
978 unsigned char *p; 975 unsigned char *p;
979 976
980 if (NILP (string)) 977 if (NILP (string))
diff --git a/src/character.h b/src/character.h
index 88de343b228..a64b48d896c 100644
--- a/src/character.h
+++ b/src/character.h
@@ -434,7 +434,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
434 unsigned char *chp = BYTE_POS_ADDR (BYTEIDX); \ 434 unsigned char *chp = BYTE_POS_ADDR (BYTEIDX); \
435 int chlen; \ 435 int chlen; \
436 \ 436 \
437 OUTPUT= STRING_CHAR_AND_LENGTH (chp, chlen); \ 437 OUTPUT = STRING_CHAR_AND_LENGTH (chp, chlen); \
438 BYTEIDX += chlen; \ 438 BYTEIDX += chlen; \
439 } \ 439 } \
440 else \ 440 else \
@@ -665,7 +665,7 @@ typedef enum {
665 UNICODE_CATEGORY_Cn 665 UNICODE_CATEGORY_Cn
666} unicode_category_t; 666} unicode_category_t;
667 667
668extern int char_resolve_modifier_mask (int); 668extern EMACS_INT char_resolve_modifier_mask (EMACS_INT);
669extern int char_string (unsigned, unsigned char *); 669extern int char_string (unsigned, unsigned char *);
670extern int string_char (const unsigned char *, 670extern int string_char (const unsigned char *,
671 const unsigned char **, int *); 671 const unsigned char **, int *);
@@ -673,19 +673,19 @@ extern int string_char (const unsigned char *,
673extern int translate_char (Lisp_Object, int c); 673extern int translate_char (Lisp_Object, int c);
674extern int char_printable_p (int c); 674extern int char_printable_p (int c);
675extern void parse_str_as_multibyte (const unsigned char *, 675extern void parse_str_as_multibyte (const unsigned char *,
676 EMACS_INT, EMACS_INT *, EMACS_INT *); 676 ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
677extern EMACS_INT count_size_as_multibyte (const unsigned char *, EMACS_INT); 677extern ptrdiff_t count_size_as_multibyte (const unsigned char *, ptrdiff_t);
678extern EMACS_INT str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT, 678extern ptrdiff_t str_as_multibyte (unsigned char *, ptrdiff_t, ptrdiff_t,
679 EMACS_INT *); 679 ptrdiff_t *);
680extern EMACS_INT str_to_multibyte (unsigned char *, EMACS_INT, EMACS_INT); 680extern ptrdiff_t str_to_multibyte (unsigned char *, ptrdiff_t, ptrdiff_t);
681extern EMACS_INT str_as_unibyte (unsigned char *, EMACS_INT); 681extern ptrdiff_t str_as_unibyte (unsigned char *, ptrdiff_t);
682extern EMACS_INT str_to_unibyte (const unsigned char *, unsigned char *, 682extern ptrdiff_t str_to_unibyte (const unsigned char *, unsigned char *,
683 EMACS_INT, int); 683 ptrdiff_t, int);
684extern EMACS_INT strwidth (const char *, EMACS_INT); 684extern ptrdiff_t strwidth (const char *, ptrdiff_t);
685extern EMACS_INT c_string_width (const unsigned char *, EMACS_INT, int, 685extern ptrdiff_t c_string_width (const unsigned char *, ptrdiff_t, int,
686 EMACS_INT *, EMACS_INT *); 686 ptrdiff_t *, ptrdiff_t *);
687extern EMACS_INT lisp_string_width (Lisp_Object, EMACS_INT, 687extern ptrdiff_t lisp_string_width (Lisp_Object, ptrdiff_t,
688 EMACS_INT *, EMACS_INT *); 688 ptrdiff_t *, ptrdiff_t *);
689 689
690extern Lisp_Object Qcharacterp; 690extern Lisp_Object Qcharacterp;
691extern Lisp_Object Vchar_unify_table; 691extern Lisp_Object Vchar_unify_table;
diff --git a/src/charset.c b/src/charset.c
index 7b963a94800..6ecc8d2c4d1 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -118,24 +118,25 @@ int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
118 118
119#define CODE_POINT_TO_INDEX(charset, code) \ 119#define CODE_POINT_TO_INDEX(charset, code) \
120 ((charset)->code_linear_p \ 120 ((charset)->code_linear_p \
121 ? (code) - (charset)->min_code \ 121 ? (int) ((code) - (charset)->min_code) \
122 : (((charset)->code_space_mask[(code) >> 24] & 0x8) \ 122 : (((charset)->code_space_mask[(code) >> 24] & 0x8) \
123 && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4) \ 123 && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4) \
124 && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2) \ 124 && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2) \
125 && ((charset)->code_space_mask[(code) & 0xFF] & 0x1)) \ 125 && ((charset)->code_space_mask[(code) & 0xFF] & 0x1)) \
126 ? (((((code) >> 24) - (charset)->code_space[12]) \ 126 ? (int) (((((code) >> 24) - (charset)->code_space[12]) \
127 * (charset)->code_space[11]) \ 127 * (charset)->code_space[11]) \
128 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \ 128 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \
129 * (charset)->code_space[7]) \ 129 * (charset)->code_space[7]) \
130 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \ 130 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \
131 * (charset)->code_space[3]) \ 131 * (charset)->code_space[3]) \
132 + (((code) & 0xFF) - (charset)->code_space[0]) \ 132 + (((code) & 0xFF) - (charset)->code_space[0]) \
133 - ((charset)->char_index_offset)) \ 133 - ((charset)->char_index_offset)) \
134 : -1) 134 : -1)
135 135
136 136
137/* Convert the character index IDX to code-point CODE for CHARSET. 137/* Return the code-point for the character index IDX in CHARSET.
138 It is assumed that IDX is in a valid range. */ 138 IDX should be an unsigned int variable in a valid range (which is
139 always in nonnegative int range too). IDX contains garbage afterwards. */
139 140
140#define INDEX_TO_CODE_POINT(charset, idx) \ 141#define INDEX_TO_CODE_POINT(charset, idx) \
141 ((charset)->code_linear_p \ 142 ((charset)->code_linear_p \
@@ -363,7 +364,8 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries,
363 && CHARSET_COMPACT_CODES_P (charset)) 364 && CHARSET_COMPACT_CODES_P (charset))
364 for (; from_index < lim_index; from_index++, from_c++) 365 for (; from_index < lim_index; from_index++, from_c++)
365 { 366 {
366 unsigned code = INDEX_TO_CODE_POINT (charset, from_index); 367 unsigned code = from_index;
368 code = INDEX_TO_CODE_POINT (charset, code);
367 369
368 if (NILP (CHAR_TABLE_REF (table, from_c))) 370 if (NILP (CHAR_TABLE_REF (table, from_c)))
369 CHAR_TABLE_SET (table, from_c, make_number (code)); 371 CHAR_TABLE_SET (table, from_c, make_number (code));
@@ -482,7 +484,8 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, int co
482 FILE *fp; 484 FILE *fp;
483 Lisp_Object suffixes; 485 Lisp_Object suffixes;
484 struct charset_map_entries *head, *entries; 486 struct charset_map_entries *head, *entries;
485 int n_entries, count; 487 int n_entries;
488 ptrdiff_t count;
486 USE_SAFE_ALLOCA; 489 USE_SAFE_ALLOCA;
487 490
488 suffixes = Fcons (build_string (".map"), 491 suffixes = Fcons (build_string (".map"),
@@ -534,8 +537,9 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, int co
534 sizeof (struct charset_map_entries)); 537 sizeof (struct charset_map_entries));
535 entries = entries->next; 538 entries = entries->next;
536 memset (entries, 0, sizeof (struct charset_map_entries)); 539 memset (entries, 0, sizeof (struct charset_map_entries));
540 n_entries = 0;
537 } 541 }
538 idx = n_entries % 0x10000; 542 idx = n_entries;
539 entries->entry[idx].from = from; 543 entries->entry[idx].from = from;
540 entries->entry[idx].to = to; 544 entries->entry[idx].to = to;
541 entries->entry[idx].c = c; 545 entries->entry[idx].c = c;
@@ -576,7 +580,7 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
576 { 580 {
577 Lisp_Object val, val2; 581 Lisp_Object val, val2;
578 unsigned from, to; 582 unsigned from, to;
579 int c; 583 EMACS_INT c;
580 int idx; 584 int idx;
581 585
582 val = AREF (vec, i); 586 val = AREF (vec, i);
@@ -584,16 +588,11 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
584 { 588 {
585 val2 = XCDR (val); 589 val2 = XCDR (val);
586 val = XCAR (val); 590 val = XCAR (val);
587 CHECK_NATNUM (val);
588 CHECK_NATNUM (val2);
589 from = XFASTINT (val); 591 from = XFASTINT (val);
590 to = XFASTINT (val2); 592 to = XFASTINT (val2);
591 } 593 }
592 else 594 else
593 { 595 from = to = XFASTINT (val);
594 CHECK_NATNUM (val);
595 from = to = XFASTINT (val);
596 }
597 val = AREF (vec, i + 1); 596 val = AREF (vec, i + 1);
598 CHECK_NATNUM (val); 597 CHECK_NATNUM (val);
599 c = XFASTINT (val); 598 c = XFASTINT (val);
@@ -821,7 +820,6 @@ range of code points (in CHARSET) of target characters. */)
821 from = CHARSET_MIN_CODE (cs); 820 from = CHARSET_MIN_CODE (cs);
822 else 821 else
823 { 822 {
824 CHECK_NATNUM (from_code);
825 from = XINT (from_code); 823 from = XINT (from_code);
826 if (from < CHARSET_MIN_CODE (cs)) 824 if (from < CHARSET_MIN_CODE (cs))
827 from = CHARSET_MIN_CODE (cs); 825 from = CHARSET_MIN_CODE (cs);
@@ -830,7 +828,6 @@ range of code points (in CHARSET) of target characters. */)
830 to = CHARSET_MAX_CODE (cs); 828 to = CHARSET_MAX_CODE (cs);
831 else 829 else
832 { 830 {
833 CHECK_NATNUM (to_code);
834 to = XINT (to_code); 831 to = XINT (to_code);
835 if (to > CHARSET_MAX_CODE (cs)) 832 if (to > CHARSET_MAX_CODE (cs))
836 to = CHARSET_MAX_CODE (cs); 833 to = CHARSET_MAX_CODE (cs);
@@ -876,12 +873,15 @@ usage: (define-charset-internal ...) */)
876 val = args[charset_arg_code_space]; 873 val = args[charset_arg_code_space];
877 for (i = 0, dimension = 0, nchars = 1; ; i++) 874 for (i = 0, dimension = 0, nchars = 1; ; i++)
878 { 875 {
876 Lisp_Object min_byte_obj, max_byte_obj;
879 int min_byte, max_byte; 877 int min_byte, max_byte;
880 878
881 min_byte = XINT (Faref (val, make_number (i * 2))); 879 min_byte_obj = Faref (val, make_number (i * 2));
882 max_byte = XINT (Faref (val, make_number (i * 2 + 1))); 880 max_byte_obj = Faref (val, make_number (i * 2 + 1));
883 if (min_byte < 0 || min_byte > max_byte || max_byte >= 256) 881 CHECK_RANGED_INTEGER (0, min_byte_obj, 255);
884 error ("Invalid :code-space value"); 882 min_byte = XINT (min_byte_obj);
883 CHECK_RANGED_INTEGER (min_byte, max_byte_obj, 255);
884 max_byte = XINT (max_byte_obj);
885 charset.code_space[i * 4] = min_byte; 885 charset.code_space[i * 4] = min_byte;
886 charset.code_space[i * 4 + 1] = max_byte; 886 charset.code_space[i * 4 + 1] = max_byte;
887 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1; 887 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1;
@@ -898,10 +898,8 @@ usage: (define-charset-internal ...) */)
898 charset.dimension = dimension; 898 charset.dimension = dimension;
899 else 899 else
900 { 900 {
901 CHECK_NATNUM (val); 901 CHECK_RANGED_INTEGER (1, val, 4);
902 charset.dimension = XINT (val); 902 charset.dimension = XINT (val);
903 if (charset.dimension < 1 || charset.dimension > 4)
904 args_out_of_range_3 (val, make_number (1), make_number (4));
905 } 903 }
906 904
907 charset.code_linear_p 905 charset.code_linear_p
@@ -927,11 +925,11 @@ usage: (define-charset-internal ...) */)
927 charset.min_code = (charset.code_space[0] 925 charset.min_code = (charset.code_space[0]
928 | (charset.code_space[4] << 8) 926 | (charset.code_space[4] << 8)
929 | (charset.code_space[8] << 16) 927 | (charset.code_space[8] << 16)
930 | (charset.code_space[12] << 24)); 928 | ((unsigned) charset.code_space[12] << 24));
931 charset.max_code = (charset.code_space[1] 929 charset.max_code = (charset.code_space[1]
932 | (charset.code_space[5] << 8) 930 | (charset.code_space[5] << 8)
933 | (charset.code_space[9] << 16) 931 | (charset.code_space[9] << 16)
934 | (charset.code_space[13] << 24)); 932 | ((unsigned) charset.code_space[13] << 24));
935 charset.char_index_offset = 0; 933 charset.char_index_offset = 0;
936 934
937 val = args[charset_arg_min_code]; 935 val = args[charset_arg_min_code];
@@ -941,8 +939,8 @@ usage: (define-charset-internal ...) */)
941 939
942 if (code < charset.min_code 940 if (code < charset.min_code
943 || code > charset.max_code) 941 || code > charset.max_code)
944 args_out_of_range_3 (make_number (charset.min_code), 942 args_out_of_range_3 (make_fixnum_or_float (charset.min_code),
945 make_number (charset.max_code), val); 943 make_fixnum_or_float (charset.max_code), val);
946 charset.char_index_offset = CODE_POINT_TO_INDEX (&charset, code); 944 charset.char_index_offset = CODE_POINT_TO_INDEX (&charset, code);
947 charset.min_code = code; 945 charset.min_code = code;
948 } 946 }
@@ -954,8 +952,8 @@ usage: (define-charset-internal ...) */)
954 952
955 if (code < charset.min_code 953 if (code < charset.min_code
956 || code > charset.max_code) 954 || code > charset.max_code)
957 args_out_of_range_3 (make_number (charset.min_code), 955 args_out_of_range_3 (make_fixnum_or_float (charset.min_code),
958 make_number (charset.max_code), val); 956 make_fixnum_or_float (charset.max_code), val);
959 charset.max_code = code; 957 charset.max_code = code;
960 } 958 }
961 959
@@ -968,18 +966,14 @@ usage: (define-charset-internal ...) */)
968 charset.invalid_code = 0; 966 charset.invalid_code = 0;
969 else 967 else
970 { 968 {
971 XSETINT (val, charset.max_code + 1); 969 if (charset.max_code < UINT_MAX)
972 if (XINT (val) == charset.max_code + 1)
973 charset.invalid_code = charset.max_code + 1; 970 charset.invalid_code = charset.max_code + 1;
974 else 971 else
975 error ("Attribute :invalid-code must be specified"); 972 error ("Attribute :invalid-code must be specified");
976 } 973 }
977 } 974 }
978 else 975 else
979 { 976 charset.invalid_code = cons_to_unsigned (val, UINT_MAX);
980 CHECK_NATNUM (val);
981 charset.invalid_code = XFASTINT (val);
982 }
983 977
984 val = args[charset_arg_iso_final]; 978 val = args[charset_arg_iso_final];
985 if (NILP (val)) 979 if (NILP (val))
@@ -997,9 +991,7 @@ usage: (define-charset-internal ...) */)
997 charset.iso_revision = -1; 991 charset.iso_revision = -1;
998 else 992 else
999 { 993 {
1000 CHECK_NUMBER (val); 994 CHECK_RANGED_INTEGER (-1, val, 63);
1001 if (XINT (val) > 63)
1002 args_out_of_range (make_number (63), val);
1003 charset.iso_revision = XINT (val); 995 charset.iso_revision = XINT (val);
1004 } 996 }
1005 997
@@ -1025,17 +1017,17 @@ usage: (define-charset-internal ...) */)
1025 if (! NILP (args[charset_arg_code_offset])) 1017 if (! NILP (args[charset_arg_code_offset]))
1026 { 1018 {
1027 val = args[charset_arg_code_offset]; 1019 val = args[charset_arg_code_offset];
1028 CHECK_NUMBER (val); 1020 CHECK_CHARACTER (val);
1029 1021
1030 charset.method = CHARSET_METHOD_OFFSET; 1022 charset.method = CHARSET_METHOD_OFFSET;
1031 charset.code_offset = XINT (val); 1023 charset.code_offset = XINT (val);
1032 1024
1033 i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
1034 charset.min_char = i + charset.code_offset;
1035 i = CODE_POINT_TO_INDEX (&charset, charset.max_code); 1025 i = CODE_POINT_TO_INDEX (&charset, charset.max_code);
1036 charset.max_char = i + charset.code_offset; 1026 if (MAX_CHAR - charset.code_offset < i)
1037 if (charset.max_char > MAX_CHAR)
1038 error ("Unsupported max char: %d", charset.max_char); 1027 error ("Unsupported max char: %d", charset.max_char);
1028 charset.max_char = i + charset.code_offset;
1029 i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
1030 charset.min_char = i + charset.code_offset;
1039 1031
1040 i = (charset.min_char >> 7) << 7; 1032 i = (charset.min_char >> 7) << 7;
1041 for (; i < 0x10000 && i <= charset.max_char; i += 128) 1033 for (; i < 0x10000 && i <= charset.max_char; i += 128)
@@ -1106,7 +1098,7 @@ usage: (define-charset-internal ...) */)
1106 car_part = XCAR (elt); 1098 car_part = XCAR (elt);
1107 cdr_part = XCDR (elt); 1099 cdr_part = XCDR (elt);
1108 CHECK_CHARSET_GET_ID (car_part, this_id); 1100 CHECK_CHARSET_GET_ID (car_part, this_id);
1109 CHECK_NUMBER (cdr_part); 1101 CHECK_TYPE_RANGED_INTEGER (int, cdr_part);
1110 offset = XINT (cdr_part); 1102 offset = XINT (cdr_part);
1111 } 1103 }
1112 else 1104 else
@@ -1395,8 +1387,8 @@ Optional third argument DEUNIFY, if non-nil, means to de-unify CHARSET. */)
1395 } 1387 }
1396 else if (CHAR_TABLE_P (Vchar_unify_table)) 1388 else if (CHAR_TABLE_P (Vchar_unify_table))
1397 { 1389 {
1398 int min_code = CHARSET_MIN_CODE (cs); 1390 unsigned min_code = CHARSET_MIN_CODE (cs);
1399 int max_code = CHARSET_MAX_CODE (cs); 1391 unsigned max_code = CHARSET_MAX_CODE (cs);
1400 int min_char = DECODE_CHAR (cs, min_code); 1392 int min_char = DECODE_CHAR (cs, min_code);
1401 int max_char = DECODE_CHAR (cs, max_code); 1393 int max_char = DECODE_CHAR (cs, max_code);
1402 1394
@@ -1511,7 +1503,7 @@ string_xstring_p (Lisp_Object string)
1511 It may lookup a translation table TABLE if supplied. */ 1503 It may lookup a translation table TABLE if supplied. */
1512 1504
1513static void 1505static void
1514find_charsets_in_text (const unsigned char *ptr, EMACS_INT nchars, EMACS_INT nbytes, Lisp_Object charsets, Lisp_Object table, int multibyte) 1506find_charsets_in_text (const unsigned char *ptr, ptrdiff_t nchars, ptrdiff_t nbytes, Lisp_Object charsets, Lisp_Object table, int multibyte)
1515{ 1507{
1516 const unsigned char *pend = ptr + nbytes; 1508 const unsigned char *pend = ptr + nbytes;
1517 1509
@@ -1558,7 +1550,7 @@ only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
1558 (Lisp_Object beg, Lisp_Object end, Lisp_Object table) 1550 (Lisp_Object beg, Lisp_Object end, Lisp_Object table)
1559{ 1551{
1560 Lisp_Object charsets; 1552 Lisp_Object charsets;
1561 EMACS_INT from, from_byte, to, stop, stop_byte; 1553 ptrdiff_t from, from_byte, to, stop, stop_byte;
1562 int i; 1554 int i;
1563 Lisp_Object val; 1555 Lisp_Object val;
1564 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 1556 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -1840,7 +1832,7 @@ encode_char (struct charset *charset, int c)
1840 } 1832 }
1841 else /* method == CHARSET_METHOD_OFFSET */ 1833 else /* method == CHARSET_METHOD_OFFSET */
1842 { 1834 {
1843 int code_index = c - CHARSET_CODE_OFFSET (charset); 1835 unsigned code_index = c - CHARSET_CODE_OFFSET (charset);
1844 1836
1845 code = INDEX_TO_CODE_POINT (charset, code_index); 1837 code = INDEX_TO_CODE_POINT (charset, code_index);
1846 } 1838 }
diff --git a/src/charset.h b/src/charset.h
index 98bf35f644a..516582a3f3d 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -401,7 +401,7 @@ extern Lisp_Object Vchar_charset_set;
401 ? decode_char ((charset), (code)) \ 401 ? decode_char ((charset), (code)) \
402 : (charset)->method == CHARSET_METHOD_OFFSET \ 402 : (charset)->method == CHARSET_METHOD_OFFSET \
403 ? ((charset)->code_linear_p \ 403 ? ((charset)->code_linear_p \
404 ? (code) - (charset)->min_code + (charset)->code_offset \ 404 ? (int) ((code) - (charset)->min_code) + (charset)->code_offset \
405 : decode_char ((charset), (code))) \ 405 : decode_char ((charset), (code))) \
406 : (charset)->method == CHARSET_METHOD_MAP \ 406 : (charset)->method == CHARSET_METHOD_MAP \
407 ? (((charset)->code_linear_p \ 407 ? (((charset)->code_linear_p \
@@ -411,16 +411,6 @@ extern Lisp_Object Vchar_charset_set;
411 : decode_char ((charset), (code))) \ 411 : decode_char ((charset), (code))) \
412 : decode_char ((charset), (code))) 412 : decode_char ((charset), (code)))
413 413
414
415/* If CHARSET is a simple offset base charset, return it's offset,
416 otherwise return -1. */
417#define CHARSET_OFFSET(charset) \
418 (((charset)->method == CHARSET_METHOD_OFFSET \
419 && (charset)->code_linear_p \
420 && ! (charset)->unified_p) \
421 ? (charset)->code_offset - (charset)->min_code \
422 : -1)
423
424extern Lisp_Object charset_work; 414extern Lisp_Object charset_work;
425 415
426/* Return a code point of CHAR in CHARSET. 416/* Return a code point of CHAR in CHARSET.
@@ -430,7 +420,7 @@ extern Lisp_Object charset_work;
430 (verify_expr \ 420 (verify_expr \
431 (sizeof (c) <= sizeof (int), \ 421 (sizeof (c) <= sizeof (int), \
432 (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p \ 422 (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p \
433 ? (c) \ 423 ? (unsigned) (c) \
434 : ((charset)->unified_p \ 424 : ((charset)->unified_p \
435 || (charset)->method == CHARSET_METHOD_SUBSET \ 425 || (charset)->method == CHARSET_METHOD_SUBSET \
436 || (charset)->method == CHARSET_METHOD_SUPERSET) \ 426 || (charset)->method == CHARSET_METHOD_SUPERSET) \
@@ -439,7 +429,7 @@ extern Lisp_Object charset_work;
439 ? (charset)->invalid_code \ 429 ? (charset)->invalid_code \
440 : (charset)->method == CHARSET_METHOD_OFFSET \ 430 : (charset)->method == CHARSET_METHOD_OFFSET \
441 ? ((charset)->code_linear_p \ 431 ? ((charset)->code_linear_p \
442 ? (c) - (charset)->code_offset + (charset)->min_code \ 432 ? (unsigned) ((c) - (charset)->code_offset) + (charset)->min_code \
443 : encode_char (charset, c)) \ 433 : encode_char (charset, c)) \
444 : (charset)->method == CHARSET_METHOD_MAP \ 434 : (charset)->method == CHARSET_METHOD_MAP \
445 ? (((charset)->compact_codes_p \ 435 ? (((charset)->compact_codes_p \
@@ -447,7 +437,7 @@ extern Lisp_Object charset_work;
447 ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \ 437 ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \
448 (NILP (charset_work) \ 438 (NILP (charset_work) \
449 ? (charset)->invalid_code \ 439 ? (charset)->invalid_code \
450 : XFASTINT (charset_work))) \ 440 : (unsigned) XFASTINT (charset_work))) \
451 : encode_char (charset, c)) \ 441 : encode_char (charset, c)) \
452 : encode_char (charset, c)))) 442 : encode_char (charset, c))))
453 443
diff --git a/src/chartab.c b/src/chartab.c
index 8d903749284..e1252962612 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -107,9 +107,9 @@ the char-table has no extra slot. */)
107 else 107 else
108 { 108 {
109 CHECK_NATNUM (n); 109 CHECK_NATNUM (n);
110 n_extras = XINT (n); 110 if (XINT (n) > 10)
111 if (n_extras > 10)
112 args_out_of_range (n, Qnil); 111 args_out_of_range (n, Qnil);
112 n_extras = XINT (n);
113 } 113 }
114 114
115 size = VECSIZE (struct Lisp_Char_Table) - 1 + n_extras; 115 size = VECSIZE (struct Lisp_Char_Table) - 1 + n_extras;
@@ -646,7 +646,7 @@ or a character code. Return VALUE. */)
646 } 646 }
647 else if (EQ (range, Qnil)) 647 else if (EQ (range, Qnil))
648 XCHAR_TABLE (char_table)->defalt = value; 648 XCHAR_TABLE (char_table)->defalt = value;
649 else if (INTEGERP (range)) 649 else if (CHARACTERP (range))
650 char_table_set (char_table, XINT (range), value); 650 char_table_set (char_table, XINT (range), value);
651 else if (CONSP (range)) 651 else if (CONSP (range))
652 { 652 {
@@ -1223,7 +1223,7 @@ static int uniprop_decoder_count
1223static uniprop_decoder_t 1223static uniprop_decoder_t
1224uniprop_get_decoder (Lisp_Object table) 1224uniprop_get_decoder (Lisp_Object table)
1225{ 1225{
1226 int i; 1226 EMACS_INT i;
1227 1227
1228 if (! INTEGERP (XCHAR_TABLE (table)->extras[1])) 1228 if (! INTEGERP (XCHAR_TABLE (table)->extras[1]))
1229 return NULL; 1229 return NULL;
@@ -1303,7 +1303,7 @@ static int uniprop_encoder_count
1303static uniprop_decoder_t 1303static uniprop_decoder_t
1304uniprop_get_encoder (Lisp_Object table) 1304uniprop_get_encoder (Lisp_Object table)
1305{ 1305{
1306 int i; 1306 EMACS_INT i;
1307 1307
1308 if (! INTEGERP (XCHAR_TABLE (table)->extras[2])) 1308 if (! INTEGERP (XCHAR_TABLE (table)->extras[2]))
1309 return NULL; 1309 return NULL;
diff --git a/src/cmds.c b/src/cmds.c
index a020a447eb1..225c26b082c 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -47,6 +47,41 @@ DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
47 return make_number (PT + XINT (n)); 47 return make_number (PT + XINT (n));
48} 48}
49 49
50/* Add N to point; or subtract N if FORWARD is zero. N defaults to 1.
51 Validate the new location. Return nil. */
52static Lisp_Object
53move_point (Lisp_Object n, int forward)
54{
55 /* This used to just set point to point + XINT (n), and then check
56 to see if it was within boundaries. But now that SET_PT can
57 potentially do a lot of stuff (calling entering and exiting
58 hooks, etcetera), that's not a good approach. So we validate the
59 proposed position, then set point. */
60
61 EMACS_INT new_point;
62
63 if (NILP (n))
64 XSETFASTINT (n, 1);
65 else
66 CHECK_NUMBER (n);
67
68 new_point = PT + (forward ? XINT (n) : - XINT (n));
69
70 if (new_point < BEGV)
71 {
72 SET_PT (BEGV);
73 xsignal0 (Qbeginning_of_buffer);
74 }
75 if (new_point > ZV)
76 {
77 SET_PT (ZV);
78 xsignal0 (Qend_of_buffer);
79 }
80
81 SET_PT (new_point);
82 return Qnil;
83}
84
50DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p", 85DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
51 doc: /* Move point N characters forward (backward if N is negative). 86 doc: /* Move point N characters forward (backward if N is negative).
52On reaching end or beginning of buffer, stop and signal error. 87On reaching end or beginning of buffer, stop and signal error.
@@ -56,34 +91,7 @@ right or to the left on the screen. This is in contrast with
56\\[right-char], which see. */) 91\\[right-char], which see. */)
57 (Lisp_Object n) 92 (Lisp_Object n)
58{ 93{
59 if (NILP (n)) 94 return move_point (n, 1);
60 XSETFASTINT (n, 1);
61 else
62 CHECK_NUMBER (n);
63
64 /* This used to just set point to point + XINT (n), and then check
65 to see if it was within boundaries. But now that SET_PT can
66 potentially do a lot of stuff (calling entering and exiting
67 hooks, etcetera), that's not a good approach. So we validate the
68 proposed position, then set point. */
69 {
70 EMACS_INT new_point = PT + XINT (n);
71
72 if (new_point < BEGV)
73 {
74 SET_PT (BEGV);
75 xsignal0 (Qbeginning_of_buffer);
76 }
77 if (new_point > ZV)
78 {
79 SET_PT (ZV);
80 xsignal0 (Qend_of_buffer);
81 }
82
83 SET_PT (new_point);
84 }
85
86 return Qnil;
87} 95}
88 96
89DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p", 97DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
@@ -95,13 +103,7 @@ right or to the left on the screen. This is in contrast with
95\\[left-char], which see. */) 103\\[left-char], which see. */)
96 (Lisp_Object n) 104 (Lisp_Object n)
97{ 105{
98 if (NILP (n)) 106 return move_point (n, 0);
99 XSETFASTINT (n, 1);
100 else
101 CHECK_NUMBER (n);
102
103 XSETINT (n, - XINT (n));
104 return Fforward_char (n);
105} 107}
106 108
107DEFUN ("forward-line", Fforward_line, Sforward_line, 0, 1, "^p", 109DEFUN ("forward-line", Fforward_line, Sforward_line, 0, 1, "^p",
@@ -115,8 +117,8 @@ With positive N, a non-empty line at the end counts as one line
115successfully moved (for the return value). */) 117successfully moved (for the return value). */)
116 (Lisp_Object n) 118 (Lisp_Object n)
117{ 119{
118 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 120 ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
119 EMACS_INT pos, pos_byte; 121 ptrdiff_t pos, pos_byte;
120 EMACS_INT count, shortage; 122 EMACS_INT count, shortage;
121 123
122 if (NILP (n)) 124 if (NILP (n))
@@ -187,7 +189,7 @@ not move. To ignore field boundaries bind `inhibit-field-text-motion'
187to t. */) 189to t. */)
188 (Lisp_Object n) 190 (Lisp_Object n)
189{ 191{
190 EMACS_INT newpos; 192 ptrdiff_t newpos;
191 193
192 if (NILP (n)) 194 if (NILP (n))
193 XSETFASTINT (n, 1); 195 XSETFASTINT (n, 1);
@@ -303,7 +305,7 @@ At the end, it runs `post-self-insert-hook'. */)
303 bitch_at_user (); 305 bitch_at_user ();
304 { 306 {
305 int character = translate_char (Vtranslation_table_for_input, 307 int character = translate_char (Vtranslation_table_for_input,
306 (int) XINT (last_command_event)); 308 XINT (last_command_event));
307 int val = internal_self_insert (character, XFASTINT (n)); 309 int val = internal_self_insert (character, XFASTINT (n));
308 if (val == 2) 310 if (val == 2)
309 nonundocount = 0; 311 nonundocount = 0;
@@ -333,8 +335,8 @@ internal_self_insert (int c, EMACS_INT n)
333 int len; 335 int len;
334 /* Working buffer and pointer for multi-byte form of C. */ 336 /* Working buffer and pointer for multi-byte form of C. */
335 unsigned char str[MAX_MULTIBYTE_LENGTH]; 337 unsigned char str[MAX_MULTIBYTE_LENGTH];
336 EMACS_INT chars_to_delete = 0; 338 ptrdiff_t chars_to_delete = 0;
337 EMACS_INT spaces_to_insert = 0; 339 ptrdiff_t spaces_to_insert = 0;
338 340
339 overwrite = BVAR (current_buffer, overwrite_mode); 341 overwrite = BVAR (current_buffer, overwrite_mode);
340 if (!NILP (Vbefore_change_functions) || !NILP (Vafter_change_functions)) 342 if (!NILP (Vbefore_change_functions) || !NILP (Vafter_change_functions))
@@ -371,50 +373,53 @@ internal_self_insert (int c, EMACS_INT n)
371 /* This is the character after point. */ 373 /* This is the character after point. */
372 int c2 = FETCH_CHAR (PT_BYTE); 374 int c2 = FETCH_CHAR (PT_BYTE);
373 375
376 int cwidth;
377
374 /* Overwriting in binary-mode always replaces C2 by C. 378 /* Overwriting in binary-mode always replaces C2 by C.
375 Overwriting in textual-mode doesn't always do that. 379 Overwriting in textual-mode doesn't always do that.
376 It inserts newlines in the usual way, 380 It inserts newlines in the usual way,
377 and inserts any character at end of line 381 and inserts any character at end of line
378 or before a tab if it doesn't use the whole width of the tab. */ 382 or before a tab if it doesn't use the whole width of the tab. */
379 if (EQ (overwrite, Qoverwrite_mode_binary)) 383 if (EQ (overwrite, Qoverwrite_mode_binary))
380 chars_to_delete = n; 384 chars_to_delete = min (n, PTRDIFF_MAX);
381 else if (c != '\n' && c2 != '\n') 385 else if (c != '\n' && c2 != '\n'
386 && (cwidth = XFASTINT (Fchar_width (make_number (c)))) != 0)
382 { 387 {
383 EMACS_INT pos = PT; 388 ptrdiff_t pos = PT;
384 EMACS_INT pos_byte = PT_BYTE; 389 ptrdiff_t pos_byte = PT_BYTE;
390 ptrdiff_t curcol = current_column ();
385 391
386 /* FIXME: Check for integer overflow when calculating 392 if (n <= (min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX) - curcol) / cwidth)
387 target_clm and actual_clm. */
388
389 /* Column the cursor should be placed at after this insertion.
390 The correct value should be calculated only when necessary. */
391 EMACS_INT target_clm = (current_column ()
392 + n * XINT (Fchar_width (make_number (c))));
393
394 /* The actual cursor position after the trial of moving
395 to column TARGET_CLM. It is greater than TARGET_CLM
396 if the TARGET_CLM is middle of multi-column
397 character. In that case, the new point is set after
398 that character. */
399 EMACS_INT actual_clm
400 = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil));
401
402 chars_to_delete = PT - pos;
403
404 if (actual_clm > target_clm)
405 { 393 {
406 /* We will delete too many columns. Let's fill columns 394 /* Column the cursor should be placed at after this insertion.
407 by spaces so that the remaining text won't move. */ 395 The value should be calculated only when necessary. */
408 EMACS_INT actual = PT_BYTE; 396 ptrdiff_t target_clm = curcol + n * cwidth;
409 DEC_POS (actual); 397
410 if (FETCH_CHAR (actual) == '\t') 398 /* The actual cursor position after the trial of moving
411 /* Rather than add spaces, let's just keep the tab. */ 399 to column TARGET_CLM. It is greater than TARGET_CLM
412 chars_to_delete--; 400 if the TARGET_CLM is middle of multi-column
413 else 401 character. In that case, the new point is set after
414 spaces_to_insert = actual_clm - target_clm; 402 that character. */
403 ptrdiff_t actual_clm
404 = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil));
405
406 chars_to_delete = PT - pos;
407
408 if (actual_clm > target_clm)
409 {
410 /* We will delete too many columns. Let's fill columns
411 by spaces so that the remaining text won't move. */
412 ptrdiff_t actual = PT_BYTE;
413 DEC_POS (actual);
414 if (FETCH_CHAR (actual) == '\t')
415 /* Rather than add spaces, let's just keep the tab. */
416 chars_to_delete--;
417 else
418 spaces_to_insert = actual_clm - target_clm;
419 }
420
421 SET_PT_BOTH (pos, pos_byte);
415 } 422 }
416
417 SET_PT_BOTH (pos, pos_byte);
418 } 423 }
419 hairy = 2; 424 hairy = 2;
420 } 425 }
diff --git a/src/coding.c b/src/coding.c
index eb89563eef4..17e342298b9 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -159,7 +159,7 @@ detect_coding_XXX (struct coding_system *coding,
159 const unsigned char *src = coding->source; 159 const unsigned char *src = coding->source;
160 const unsigned char *src_end = coding->source + coding->src_bytes; 160 const unsigned char *src_end = coding->source + coding->src_bytes;
161 int multibytep = coding->src_multibyte; 161 int multibytep = coding->src_multibyte;
162 EMACS_INT consumed_chars = 0; 162 ptrdiff_t consumed_chars = 0;
163 int found = 0; 163 int found = 0;
164 ...; 164 ...;
165 165
@@ -266,7 +266,7 @@ encode_coding_XXX (struct coding_system *coding)
266 unsigned char *dst = coding->destination + coding->produced; 266 unsigned char *dst = coding->destination + coding->produced;
267 unsigned char *dst_end = coding->destination + coding->dst_bytes; 267 unsigned char *dst_end = coding->destination + coding->dst_bytes;
268 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_; 268 unsigned char *adjusted_dst_end = dst_end - _MAX_BYTES_PRODUCED_IN_LOOP_;
269 EMACS_INT produced_chars = 0; 269 ptrdiff_t produced_chars = 0;
270 270
271 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++) 271 for (; charbuf < charbuf_end && dst < adjusted_dst_end; charbuf++)
272 { 272 {
@@ -847,33 +847,35 @@ static int encode_coding_ccl (struct coding_system *);
847static void decode_coding_raw_text (struct coding_system *); 847static void decode_coding_raw_text (struct coding_system *);
848static int encode_coding_raw_text (struct coding_system *); 848static int encode_coding_raw_text (struct coding_system *);
849 849
850static EMACS_INT coding_set_source (struct coding_system *); 850static void coding_set_source (struct coding_system *);
851static EMACS_INT coding_set_destination (struct coding_system *); 851static ptrdiff_t coding_change_source (struct coding_system *);
852static void coding_alloc_by_realloc (struct coding_system *, EMACS_INT); 852static void coding_set_destination (struct coding_system *);
853static ptrdiff_t coding_change_destination (struct coding_system *);
854static void coding_alloc_by_realloc (struct coding_system *, ptrdiff_t);
853static void coding_alloc_by_making_gap (struct coding_system *, 855static void coding_alloc_by_making_gap (struct coding_system *,
854 EMACS_INT, EMACS_INT); 856 ptrdiff_t, ptrdiff_t);
855static unsigned char *alloc_destination (struct coding_system *, 857static unsigned char *alloc_destination (struct coding_system *,
856 EMACS_INT, unsigned char *); 858 ptrdiff_t, unsigned char *);
857static void setup_iso_safe_charsets (Lisp_Object); 859static void setup_iso_safe_charsets (Lisp_Object);
858static EMACS_INT encode_designation_at_bol (struct coding_system *, 860static ptrdiff_t encode_designation_at_bol (struct coding_system *,
859 int *, int *, unsigned char *); 861 int *, int *, unsigned char *);
860static int detect_eol (const unsigned char *, 862static int detect_eol (const unsigned char *,
861 EMACS_INT, enum coding_category); 863 ptrdiff_t, enum coding_category);
862static Lisp_Object adjust_coding_eol_type (struct coding_system *, int); 864static Lisp_Object adjust_coding_eol_type (struct coding_system *, int);
863static void decode_eol (struct coding_system *); 865static void decode_eol (struct coding_system *);
864static Lisp_Object get_translation_table (Lisp_Object, int, int *); 866static Lisp_Object get_translation_table (Lisp_Object, int, int *);
865static Lisp_Object get_translation (Lisp_Object, int *, int *); 867static Lisp_Object get_translation (Lisp_Object, int *, int *);
866static int produce_chars (struct coding_system *, Lisp_Object, int); 868static int produce_chars (struct coding_system *, Lisp_Object, int);
867static inline void produce_charset (struct coding_system *, int *, 869static inline void produce_charset (struct coding_system *, int *,
868 EMACS_INT); 870 ptrdiff_t);
869static void produce_annotation (struct coding_system *, EMACS_INT); 871static void produce_annotation (struct coding_system *, ptrdiff_t);
870static int decode_coding (struct coding_system *); 872static int decode_coding (struct coding_system *);
871static inline int *handle_composition_annotation (EMACS_INT, EMACS_INT, 873static inline int *handle_composition_annotation (ptrdiff_t, ptrdiff_t,
872 struct coding_system *, 874 struct coding_system *,
873 int *, EMACS_INT *); 875 int *, ptrdiff_t *);
874static inline int *handle_charset_annotation (EMACS_INT, EMACS_INT, 876static inline int *handle_charset_annotation (ptrdiff_t, ptrdiff_t,
875 struct coding_system *, 877 struct coding_system *,
876 int *, EMACS_INT *); 878 int *, ptrdiff_t *);
877static void consume_chars (struct coding_system *, Lisp_Object, int); 879static void consume_chars (struct coding_system *, Lisp_Object, int);
878static int encode_coding (struct coding_system *); 880static int encode_coding (struct coding_system *);
879static Lisp_Object make_conversion_work_buffer (int); 881static Lisp_Object make_conversion_work_buffer (int);
@@ -922,12 +924,12 @@ record_conversion_result (struct coding_system *coding,
922 924
923#define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ 925#define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \
924 do { \ 926 do { \
925 EMACS_INT offset; \ 927 ptrdiff_t offset; \
926 \ 928 \
927 charset_map_loaded = 0; \ 929 charset_map_loaded = 0; \
928 c = DECODE_CHAR (charset, code); \ 930 c = DECODE_CHAR (charset, code); \
929 if (charset_map_loaded \ 931 if (charset_map_loaded \
930 && (offset = coding_set_source (coding))) \ 932 && (offset = coding_change_source (coding))) \
931 { \ 933 { \
932 src += offset; \ 934 src += offset; \
933 src_base += offset; \ 935 src_base += offset; \
@@ -937,12 +939,12 @@ record_conversion_result (struct coding_system *coding,
937 939
938#define CODING_ENCODE_CHAR(coding, dst, dst_end, charset, c, code) \ 940#define CODING_ENCODE_CHAR(coding, dst, dst_end, charset, c, code) \
939 do { \ 941 do { \
940 EMACS_INT offset; \ 942 ptrdiff_t offset; \
941 \ 943 \
942 charset_map_loaded = 0; \ 944 charset_map_loaded = 0; \
943 code = ENCODE_CHAR (charset, c); \ 945 code = ENCODE_CHAR (charset, c); \
944 if (charset_map_loaded \ 946 if (charset_map_loaded \
945 && (offset = coding_set_destination (coding))) \ 947 && (offset = coding_change_destination (coding))) \
946 { \ 948 { \
947 dst += offset; \ 949 dst += offset; \
948 dst_end += offset; \ 950 dst_end += offset; \
@@ -951,12 +953,12 @@ record_conversion_result (struct coding_system *coding,
951 953
952#define CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, code_return, charset) \ 954#define CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, code_return, charset) \
953 do { \ 955 do { \
954 EMACS_INT offset; \ 956 ptrdiff_t offset; \
955 \ 957 \
956 charset_map_loaded = 0; \ 958 charset_map_loaded = 0; \
957 charset = char_charset (c, charset_list, code_return); \ 959 charset = char_charset (c, charset_list, code_return); \
958 if (charset_map_loaded \ 960 if (charset_map_loaded \
959 && (offset = coding_set_destination (coding))) \ 961 && (offset = coding_change_destination (coding))) \
960 { \ 962 { \
961 dst += offset; \ 963 dst += offset; \
962 dst_end += offset; \ 964 dst_end += offset; \
@@ -965,12 +967,12 @@ record_conversion_result (struct coding_system *coding,
965 967
966#define CODING_CHAR_CHARSET_P(coding, dst, dst_end, c, charset, result) \ 968#define CODING_CHAR_CHARSET_P(coding, dst, dst_end, c, charset, result) \
967 do { \ 969 do { \
968 EMACS_INT offset; \ 970 ptrdiff_t offset; \
969 \ 971 \
970 charset_map_loaded = 0; \ 972 charset_map_loaded = 0; \
971 result = CHAR_CHARSET_P (c, charset); \ 973 result = CHAR_CHARSET_P (c, charset); \
972 if (charset_map_loaded \ 974 if (charset_map_loaded \
973 && (offset = coding_set_destination (coding))) \ 975 && (offset = coding_change_destination (coding))) \
974 { \ 976 { \
975 dst += offset; \ 977 dst += offset; \
976 dst_end += offset; \ 978 dst_end += offset; \
@@ -987,7 +989,7 @@ record_conversion_result (struct coding_system *coding,
987 do { \ 989 do { \
988 if (dst + (bytes) >= dst_end) \ 990 if (dst + (bytes) >= dst_end) \
989 { \ 991 { \
990 EMACS_INT more_bytes = charbuf_end - charbuf + (bytes); \ 992 ptrdiff_t more_bytes = charbuf_end - charbuf + (bytes); \
991 \ 993 \
992 dst = alloc_destination (coding, more_bytes, dst); \ 994 dst = alloc_destination (coding, more_bytes, dst); \
993 dst_end = coding->destination + coding->dst_bytes; \ 995 dst_end = coding->destination + coding->dst_bytes; \
@@ -1056,14 +1058,11 @@ record_conversion_result (struct coding_system *coding,
1056 | ((p)[-1] & 0x3F)))) 1058 | ((p)[-1] & 0x3F))))
1057 1059
1058 1060
1059/* Update coding->source from coding->src_object, and return how many 1061/* Set coding->source from coding->src_object. */
1060 bytes coding->source was changed. */
1061 1062
1062static EMACS_INT 1063static void
1063coding_set_source (struct coding_system *coding) 1064coding_set_source (struct coding_system *coding)
1064{ 1065{
1065 const unsigned char *orig = coding->source;
1066
1067 if (BUFFERP (coding->src_object)) 1066 if (BUFFERP (coding->src_object))
1068 { 1067 {
1069 struct buffer *buf = XBUFFER (coding->src_object); 1068 struct buffer *buf = XBUFFER (coding->src_object);
@@ -1082,18 +1081,26 @@ coding_set_source (struct coding_system *coding)
1082 /* Otherwise, the source is C string and is never relocated 1081 /* Otherwise, the source is C string and is never relocated
1083 automatically. Thus we don't have to update anything. */ 1082 automatically. Thus we don't have to update anything. */
1084 } 1083 }
1084}
1085
1086
1087/* Set coding->source from coding->src_object, and return how many
1088 bytes coding->source was changed. */
1089
1090static ptrdiff_t
1091coding_change_source (struct coding_system *coding)
1092{
1093 const unsigned char *orig = coding->source;
1094 coding_set_source (coding);
1085 return coding->source - orig; 1095 return coding->source - orig;
1086} 1096}
1087 1097
1088 1098
1089/* Update coding->destination from coding->dst_object, and return how 1099/* Set coding->destination from coding->dst_object. */
1090 many bytes coding->destination was changed. */
1091 1100
1092static EMACS_INT 1101static void
1093coding_set_destination (struct coding_system *coding) 1102coding_set_destination (struct coding_system *coding)
1094{ 1103{
1095 const unsigned char *orig = coding->destination;
1096
1097 if (BUFFERP (coding->dst_object)) 1104 if (BUFFERP (coding->dst_object))
1098 { 1105 {
1099 if (BUFFERP (coding->src_object) && coding->src_pos < 0) 1106 if (BUFFERP (coding->src_object) && coding->src_pos < 0)
@@ -1118,12 +1125,23 @@ coding_set_destination (struct coding_system *coding)
1118 /* Otherwise, the destination is C string and is never relocated 1125 /* Otherwise, the destination is C string and is never relocated
1119 automatically. Thus we don't have to update anything. */ 1126 automatically. Thus we don't have to update anything. */
1120 } 1127 }
1128}
1129
1130
1131/* Set coding->destination from coding->dst_object, and return how
1132 many bytes coding->destination was changed. */
1133
1134static ptrdiff_t
1135coding_change_destination (struct coding_system *coding)
1136{
1137 const unsigned char *orig = coding->destination;
1138 coding_set_destination (coding);
1121 return coding->destination - orig; 1139 return coding->destination - orig;
1122} 1140}
1123 1141
1124 1142
1125static void 1143static void
1126coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes) 1144coding_alloc_by_realloc (struct coding_system *coding, ptrdiff_t bytes)
1127{ 1145{
1128 if (STRING_BYTES_BOUND - coding->dst_bytes < bytes) 1146 if (STRING_BYTES_BOUND - coding->dst_bytes < bytes)
1129 string_overflow (); 1147 string_overflow ();
@@ -1134,7 +1152,7 @@ coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes)
1134 1152
1135static void 1153static void
1136coding_alloc_by_making_gap (struct coding_system *coding, 1154coding_alloc_by_making_gap (struct coding_system *coding,
1137 EMACS_INT gap_head_used, EMACS_INT bytes) 1155 ptrdiff_t gap_head_used, ptrdiff_t bytes)
1138{ 1156{
1139 if (EQ (coding->src_object, coding->dst_object)) 1157 if (EQ (coding->src_object, coding->dst_object))
1140 { 1158 {
@@ -1142,7 +1160,7 @@ coding_alloc_by_making_gap (struct coding_system *coding,
1142 consumed data at the tail. To preserve those data, we at 1160 consumed data at the tail. To preserve those data, we at
1143 first make the gap size to zero, then increase the gap 1161 first make the gap size to zero, then increase the gap
1144 size. */ 1162 size. */
1145 EMACS_INT add = GAP_SIZE; 1163 ptrdiff_t add = GAP_SIZE;
1146 1164
1147 GPT += gap_head_used, GPT_BYTE += gap_head_used; 1165 GPT += gap_head_used, GPT_BYTE += gap_head_used;
1148 GAP_SIZE = 0; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add; 1166 GAP_SIZE = 0; ZV += add; Z += add; ZV_BYTE += add; Z_BYTE += add;
@@ -1163,10 +1181,10 @@ coding_alloc_by_making_gap (struct coding_system *coding,
1163 1181
1164 1182
1165static unsigned char * 1183static unsigned char *
1166alloc_destination (struct coding_system *coding, EMACS_INT nbytes, 1184alloc_destination (struct coding_system *coding, ptrdiff_t nbytes,
1167 unsigned char *dst) 1185 unsigned char *dst)
1168{ 1186{
1169 EMACS_INT offset = dst - coding->destination; 1187 ptrdiff_t offset = dst - coding->destination;
1170 1188
1171 if (BUFFERP (coding->dst_object)) 1189 if (BUFFERP (coding->dst_object))
1172 { 1190 {
@@ -1267,7 +1285,7 @@ detect_coding_utf_8 (struct coding_system *coding,
1267 const unsigned char *src = coding->source, *src_base; 1285 const unsigned char *src = coding->source, *src_base;
1268 const unsigned char *src_end = coding->source + coding->src_bytes; 1286 const unsigned char *src_end = coding->source + coding->src_bytes;
1269 int multibytep = coding->src_multibyte; 1287 int multibytep = coding->src_multibyte;
1270 EMACS_INT consumed_chars = 0; 1288 ptrdiff_t consumed_chars = 0;
1271 int bom_found = 0; 1289 int bom_found = 0;
1272 int found = 0; 1290 int found = 0;
1273 1291
@@ -1352,7 +1370,7 @@ decode_coding_utf_8 (struct coding_system *coding)
1352 const unsigned char *src_base; 1370 const unsigned char *src_base;
1353 int *charbuf = coding->charbuf + coding->charbuf_used; 1371 int *charbuf = coding->charbuf + coding->charbuf_used;
1354 int *charbuf_end = coding->charbuf + coding->charbuf_size; 1372 int *charbuf_end = coding->charbuf + coding->charbuf_size;
1355 EMACS_INT consumed_chars = 0, consumed_chars_base = 0; 1373 ptrdiff_t consumed_chars = 0, consumed_chars_base = 0;
1356 int multibytep = coding->src_multibyte; 1374 int multibytep = coding->src_multibyte;
1357 enum utf_bom_type bom = CODING_UTF_8_BOM (coding); 1375 enum utf_bom_type bom = CODING_UTF_8_BOM (coding);
1358 int eol_dos = 1376 int eol_dos =
@@ -1503,7 +1521,7 @@ encode_coding_utf_8 (struct coding_system *coding)
1503 int *charbuf_end = charbuf + coding->charbuf_used; 1521 int *charbuf_end = charbuf + coding->charbuf_used;
1504 unsigned char *dst = coding->destination + coding->produced; 1522 unsigned char *dst = coding->destination + coding->produced;
1505 unsigned char *dst_end = coding->destination + coding->dst_bytes; 1523 unsigned char *dst_end = coding->destination + coding->dst_bytes;
1506 EMACS_INT produced_chars = 0; 1524 ptrdiff_t produced_chars = 0;
1507 int c; 1525 int c;
1508 1526
1509 if (CODING_UTF_8_BOM (coding) == utf_with_bom) 1527 if (CODING_UTF_8_BOM (coding) == utf_with_bom)
@@ -1661,7 +1679,7 @@ decode_coding_utf_16 (struct coding_system *coding)
1661 int *charbuf = coding->charbuf + coding->charbuf_used; 1679 int *charbuf = coding->charbuf + coding->charbuf_used;
1662 /* We may produces at most 3 chars in one loop. */ 1680 /* We may produces at most 3 chars in one loop. */
1663 int *charbuf_end = coding->charbuf + coding->charbuf_size - 2; 1681 int *charbuf_end = coding->charbuf + coding->charbuf_size - 2;
1664 EMACS_INT consumed_chars = 0, consumed_chars_base = 0; 1682 ptrdiff_t consumed_chars = 0, consumed_chars_base = 0;
1665 int multibytep = coding->src_multibyte; 1683 int multibytep = coding->src_multibyte;
1666 enum utf_bom_type bom = CODING_UTF_16_BOM (coding); 1684 enum utf_bom_type bom = CODING_UTF_16_BOM (coding);
1667 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); 1685 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding);
@@ -1788,7 +1806,7 @@ encode_coding_utf_16 (struct coding_system *coding)
1788 int safe_room = 8; 1806 int safe_room = 8;
1789 enum utf_bom_type bom = CODING_UTF_16_BOM (coding); 1807 enum utf_bom_type bom = CODING_UTF_16_BOM (coding);
1790 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; 1808 int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian;
1791 EMACS_INT produced_chars = 0; 1809 ptrdiff_t produced_chars = 0;
1792 int c; 1810 int c;
1793 1811
1794 if (bom != utf_without_bom) 1812 if (bom != utf_without_bom)
@@ -1922,7 +1940,7 @@ detect_coding_emacs_mule (struct coding_system *coding,
1922 const unsigned char *src = coding->source, *src_base; 1940 const unsigned char *src = coding->source, *src_base;
1923 const unsigned char *src_end = coding->source + coding->src_bytes; 1941 const unsigned char *src_end = coding->source + coding->src_bytes;
1924 int multibytep = coding->src_multibyte; 1942 int multibytep = coding->src_multibyte;
1925 EMACS_INT consumed_chars = 0; 1943 ptrdiff_t consumed_chars = 0;
1926 int c; 1944 int c;
1927 int found = 0; 1945 int found = 0;
1928 1946
@@ -2392,10 +2410,10 @@ decode_coding_emacs_mule (struct coding_system *coding)
2392 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3) 2410 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3)
2393 /* We can produce up to 2 characters in a loop. */ 2411 /* We can produce up to 2 characters in a loop. */
2394 - 1; 2412 - 1;
2395 EMACS_INT consumed_chars = 0, consumed_chars_base; 2413 ptrdiff_t consumed_chars = 0, consumed_chars_base;
2396 int multibytep = coding->src_multibyte; 2414 int multibytep = coding->src_multibyte;
2397 EMACS_INT char_offset = coding->produced_char; 2415 ptrdiff_t char_offset = coding->produced_char;
2398 EMACS_INT last_offset = char_offset; 2416 ptrdiff_t last_offset = char_offset;
2399 int last_id = charset_ascii; 2417 int last_id = charset_ascii;
2400 int eol_dos = 2418 int eol_dos =
2401 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 2419 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
@@ -2467,7 +2485,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
2467 original pointer to buffer text, and fix up all related 2485 original pointer to buffer text, and fix up all related
2468 pointers after the call. */ 2486 pointers after the call. */
2469 const unsigned char *orig = coding->source; 2487 const unsigned char *orig = coding->source;
2470 EMACS_INT offset; 2488 ptrdiff_t offset;
2471 2489
2472 c = emacs_mule_char (coding, src_base, &nbytes, &nchars, &id, 2490 c = emacs_mule_char (coding, src_base, &nbytes, &nchars, &id,
2473 cmp_status); 2491 cmp_status);
@@ -2648,7 +2666,7 @@ encode_coding_emacs_mule (struct coding_system *coding)
2648 unsigned char *dst = coding->destination + coding->produced; 2666 unsigned char *dst = coding->destination + coding->produced;
2649 unsigned char *dst_end = coding->destination + coding->dst_bytes; 2667 unsigned char *dst_end = coding->destination + coding->dst_bytes;
2650 int safe_room = 8; 2668 int safe_room = 8;
2651 EMACS_INT produced_chars = 0; 2669 ptrdiff_t produced_chars = 0;
2652 Lisp_Object attrs, charset_list; 2670 Lisp_Object attrs, charset_list;
2653 int c; 2671 int c;
2654 int preferred_charset_id = -1; 2672 int preferred_charset_id = -1;
@@ -2941,7 +2959,7 @@ setup_iso_safe_charsets (Lisp_Object attrs)
2941 Lisp_Object request; 2959 Lisp_Object request;
2942 Lisp_Object reg_usage; 2960 Lisp_Object reg_usage;
2943 Lisp_Object tail; 2961 Lisp_Object tail;
2944 int reg94, reg96; 2962 EMACS_INT reg94, reg96;
2945 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); 2963 int flags = XINT (AREF (attrs, coding_attr_iso_flags));
2946 int max_charset_id; 2964 int max_charset_id;
2947 2965
@@ -3012,7 +3030,7 @@ detect_coding_iso_2022 (struct coding_system *coding,
3012 int single_shifting = 0; 3030 int single_shifting = 0;
3013 int id; 3031 int id;
3014 int c, c1; 3032 int c, c1;
3015 EMACS_INT consumed_chars = 0; 3033 ptrdiff_t consumed_chars = 0;
3016 int i; 3034 int i;
3017 int rejected = 0; 3035 int rejected = 0;
3018 int found = 0; 3036 int found = 0;
@@ -3522,7 +3540,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
3522 loop and one more charset annotation at the end. */ 3540 loop and one more charset annotation at the end. */
3523 int *charbuf_end 3541 int *charbuf_end
3524 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); 3542 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3);
3525 EMACS_INT consumed_chars = 0, consumed_chars_base; 3543 ptrdiff_t consumed_chars = 0, consumed_chars_base;
3526 int multibytep = coding->src_multibyte; 3544 int multibytep = coding->src_multibyte;
3527 /* Charsets invoked to graphic plane 0 and 1 respectively. */ 3545 /* Charsets invoked to graphic plane 0 and 1 respectively. */
3528 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); 3546 int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0);
@@ -3532,8 +3550,8 @@ decode_coding_iso_2022 (struct coding_system *coding)
3532 int c; 3550 int c;
3533 struct composition_status *cmp_status = CODING_ISO_CMP_STATUS (coding); 3551 struct composition_status *cmp_status = CODING_ISO_CMP_STATUS (coding);
3534 Lisp_Object attrs = CODING_ID_ATTRS (coding->id); 3552 Lisp_Object attrs = CODING_ID_ATTRS (coding->id);
3535 EMACS_INT char_offset = coding->produced_char; 3553 ptrdiff_t char_offset = coding->produced_char;
3536 EMACS_INT last_offset = char_offset; 3554 ptrdiff_t last_offset = char_offset;
3537 int last_id = charset_ascii; 3555 int last_id = charset_ascii;
3538 int eol_dos = 3556 int eol_dos =
3539 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 3557 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
@@ -4245,7 +4263,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
4245 4263
4246#define ENCODE_ISO_CHARACTER(charset, c) \ 4264#define ENCODE_ISO_CHARACTER(charset, c) \
4247 do { \ 4265 do { \
4248 int code; \ 4266 unsigned code; \
4249 CODING_ENCODE_CHAR (coding, dst, dst_end, (charset), (c), code); \ 4267 CODING_ENCODE_CHAR (coding, dst, dst_end, (charset), (c), code); \
4250 \ 4268 \
4251 if (CHARSET_DIMENSION (charset) == 1) \ 4269 if (CHARSET_DIMENSION (charset) == 1) \
@@ -4262,10 +4280,10 @@ decode_coding_iso_2022 (struct coding_system *coding)
4262static unsigned char * 4280static unsigned char *
4263encode_invocation_designation (struct charset *charset, 4281encode_invocation_designation (struct charset *charset,
4264 struct coding_system *coding, 4282 struct coding_system *coding,
4265 unsigned char *dst, EMACS_INT *p_nchars) 4283 unsigned char *dst, ptrdiff_t *p_nchars)
4266{ 4284{
4267 int multibytep = coding->dst_multibyte; 4285 int multibytep = coding->dst_multibyte;
4268 EMACS_INT produced_chars = *p_nchars; 4286 ptrdiff_t produced_chars = *p_nchars;
4269 int reg; /* graphic register number */ 4287 int reg; /* graphic register number */
4270 int id = CHARSET_ID (charset); 4288 int id = CHARSET_ID (charset);
4271 4289
@@ -4351,7 +4369,7 @@ encode_invocation_designation (struct charset *charset,
4351 If the current block ends before any end-of-line, we may fail to 4369 If the current block ends before any end-of-line, we may fail to
4352 find all the necessary designations. */ 4370 find all the necessary designations. */
4353 4371
4354static EMACS_INT 4372static ptrdiff_t
4355encode_designation_at_bol (struct coding_system *coding, 4373encode_designation_at_bol (struct coding_system *coding,
4356 int *charbuf, int *charbuf_end, 4374 int *charbuf, int *charbuf_end,
4357 unsigned char *dst) 4375 unsigned char *dst)
@@ -4361,7 +4379,7 @@ encode_designation_at_bol (struct coding_system *coding,
4361 /* Table of charsets to be designated to each graphic register. */ 4379 /* Table of charsets to be designated to each graphic register. */
4362 int r[4]; 4380 int r[4];
4363 int c, found = 0, reg; 4381 int c, found = 0, reg;
4364 EMACS_INT produced_chars = 0; 4382 ptrdiff_t produced_chars = 0;
4365 int multibytep = coding->dst_multibyte; 4383 int multibytep = coding->dst_multibyte;
4366 Lisp_Object attrs; 4384 Lisp_Object attrs;
4367 Lisp_Object charset_list; 4385 Lisp_Object charset_list;
@@ -4416,7 +4434,7 @@ encode_coding_iso_2022 (struct coding_system *coding)
4416 int bol_designation 4434 int bol_designation
4417 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL 4435 = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL
4418 && CODING_ISO_BOL (coding)); 4436 && CODING_ISO_BOL (coding));
4419 EMACS_INT produced_chars = 0; 4437 ptrdiff_t produced_chars = 0;
4420 Lisp_Object attrs, eol_type, charset_list; 4438 Lisp_Object attrs, eol_type, charset_list;
4421 int ascii_compatible; 4439 int ascii_compatible;
4422 int c; 4440 int c;
@@ -4446,13 +4464,13 @@ encode_coding_iso_2022 (struct coding_system *coding)
4446 /* We have to produce designation sequences if any now. */ 4464 /* We have to produce designation sequences if any now. */
4447 unsigned char desig_buf[16]; 4465 unsigned char desig_buf[16];
4448 int nbytes; 4466 int nbytes;
4449 EMACS_INT offset; 4467 ptrdiff_t offset;
4450 4468
4451 charset_map_loaded = 0; 4469 charset_map_loaded = 0;
4452 nbytes = encode_designation_at_bol (coding, charbuf, charbuf_end, 4470 nbytes = encode_designation_at_bol (coding, charbuf, charbuf_end,
4453 desig_buf); 4471 desig_buf);
4454 if (charset_map_loaded 4472 if (charset_map_loaded
4455 && (offset = coding_set_destination (coding))) 4473 && (offset = coding_change_destination (coding)))
4456 { 4474 {
4457 dst += offset; 4475 dst += offset;
4458 dst_end += offset; 4476 dst_end += offset;
@@ -4623,7 +4641,7 @@ detect_coding_sjis (struct coding_system *coding,
4623 const unsigned char *src = coding->source, *src_base; 4641 const unsigned char *src = coding->source, *src_base;
4624 const unsigned char *src_end = coding->source + coding->src_bytes; 4642 const unsigned char *src_end = coding->source + coding->src_bytes;
4625 int multibytep = coding->src_multibyte; 4643 int multibytep = coding->src_multibyte;
4626 EMACS_INT consumed_chars = 0; 4644 ptrdiff_t consumed_chars = 0;
4627 int found = 0; 4645 int found = 0;
4628 int c; 4646 int c;
4629 Lisp_Object attrs, charset_list; 4647 Lisp_Object attrs, charset_list;
@@ -4680,7 +4698,7 @@ detect_coding_big5 (struct coding_system *coding,
4680 const unsigned char *src = coding->source, *src_base; 4698 const unsigned char *src = coding->source, *src_base;
4681 const unsigned char *src_end = coding->source + coding->src_bytes; 4699 const unsigned char *src_end = coding->source + coding->src_bytes;
4682 int multibytep = coding->src_multibyte; 4700 int multibytep = coding->src_multibyte;
4683 EMACS_INT consumed_chars = 0; 4701 ptrdiff_t consumed_chars = 0;
4684 int found = 0; 4702 int found = 0;
4685 int c; 4703 int c;
4686 4704
@@ -4731,13 +4749,13 @@ decode_coding_sjis (struct coding_system *coding)
4731 the end. */ 4749 the end. */
4732 int *charbuf_end 4750 int *charbuf_end
4733 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); 4751 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2);
4734 EMACS_INT consumed_chars = 0, consumed_chars_base; 4752 ptrdiff_t consumed_chars = 0, consumed_chars_base;
4735 int multibytep = coding->src_multibyte; 4753 int multibytep = coding->src_multibyte;
4736 struct charset *charset_roman, *charset_kanji, *charset_kana; 4754 struct charset *charset_roman, *charset_kanji, *charset_kana;
4737 struct charset *charset_kanji2; 4755 struct charset *charset_kanji2;
4738 Lisp_Object attrs, charset_list, val; 4756 Lisp_Object attrs, charset_list, val;
4739 EMACS_INT char_offset = coding->produced_char; 4757 ptrdiff_t char_offset = coding->produced_char;
4740 EMACS_INT last_offset = char_offset; 4758 ptrdiff_t last_offset = char_offset;
4741 int last_id = charset_ascii; 4759 int last_id = charset_ascii;
4742 int eol_dos = 4760 int eol_dos =
4743 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 4761 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
@@ -4849,12 +4867,12 @@ decode_coding_big5 (struct coding_system *coding)
4849 the end. */ 4867 the end. */
4850 int *charbuf_end 4868 int *charbuf_end
4851 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); 4869 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2);
4852 EMACS_INT consumed_chars = 0, consumed_chars_base; 4870 ptrdiff_t consumed_chars = 0, consumed_chars_base;
4853 int multibytep = coding->src_multibyte; 4871 int multibytep = coding->src_multibyte;
4854 struct charset *charset_roman, *charset_big5; 4872 struct charset *charset_roman, *charset_big5;
4855 Lisp_Object attrs, charset_list, val; 4873 Lisp_Object attrs, charset_list, val;
4856 EMACS_INT char_offset = coding->produced_char; 4874 ptrdiff_t char_offset = coding->produced_char;
4857 EMACS_INT last_offset = char_offset; 4875 ptrdiff_t last_offset = char_offset;
4858 int last_id = charset_ascii; 4876 int last_id = charset_ascii;
4859 int eol_dos = 4877 int eol_dos =
4860 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 4878 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
@@ -4951,7 +4969,7 @@ encode_coding_sjis (struct coding_system *coding)
4951 unsigned char *dst = coding->destination + coding->produced; 4969 unsigned char *dst = coding->destination + coding->produced;
4952 unsigned char *dst_end = coding->destination + coding->dst_bytes; 4970 unsigned char *dst_end = coding->destination + coding->dst_bytes;
4953 int safe_room = 4; 4971 int safe_room = 4;
4954 EMACS_INT produced_chars = 0; 4972 ptrdiff_t produced_chars = 0;
4955 Lisp_Object attrs, charset_list, val; 4973 Lisp_Object attrs, charset_list, val;
4956 int ascii_compatible; 4974 int ascii_compatible;
4957 struct charset *charset_kanji, *charset_kana; 4975 struct charset *charset_kanji, *charset_kana;
@@ -5045,7 +5063,7 @@ encode_coding_big5 (struct coding_system *coding)
5045 unsigned char *dst = coding->destination + coding->produced; 5063 unsigned char *dst = coding->destination + coding->produced;
5046 unsigned char *dst_end = coding->destination + coding->dst_bytes; 5064 unsigned char *dst_end = coding->destination + coding->dst_bytes;
5047 int safe_room = 4; 5065 int safe_room = 4;
5048 EMACS_INT produced_chars = 0; 5066 ptrdiff_t produced_chars = 0;
5049 Lisp_Object attrs, charset_list, val; 5067 Lisp_Object attrs, charset_list, val;
5050 int ascii_compatible; 5068 int ascii_compatible;
5051 struct charset *charset_big5; 5069 struct charset *charset_big5;
@@ -5123,10 +5141,10 @@ detect_coding_ccl (struct coding_system *coding,
5123 const unsigned char *src = coding->source, *src_base; 5141 const unsigned char *src = coding->source, *src_base;
5124 const unsigned char *src_end = coding->source + coding->src_bytes; 5142 const unsigned char *src_end = coding->source + coding->src_bytes;
5125 int multibytep = coding->src_multibyte; 5143 int multibytep = coding->src_multibyte;
5126 EMACS_INT consumed_chars = 0; 5144 ptrdiff_t consumed_chars = 0;
5127 int found = 0; 5145 int found = 0;
5128 unsigned char *valids; 5146 unsigned char *valids;
5129 EMACS_INT head_ascii = coding->head_ascii; 5147 ptrdiff_t head_ascii = coding->head_ascii;
5130 Lisp_Object attrs; 5148 Lisp_Object attrs;
5131 5149
5132 detect_info->checked |= CATEGORY_MASK_CCL; 5150 detect_info->checked |= CATEGORY_MASK_CCL;
@@ -5163,7 +5181,7 @@ decode_coding_ccl (struct coding_system *coding)
5163 const unsigned char *src_end = coding->source + coding->src_bytes; 5181 const unsigned char *src_end = coding->source + coding->src_bytes;
5164 int *charbuf = coding->charbuf + coding->charbuf_used; 5182 int *charbuf = coding->charbuf + coding->charbuf_used;
5165 int *charbuf_end = coding->charbuf + coding->charbuf_size; 5183 int *charbuf_end = coding->charbuf + coding->charbuf_size;
5166 EMACS_INT consumed_chars = 0; 5184 ptrdiff_t consumed_chars = 0;
5167 int multibytep = coding->src_multibyte; 5185 int multibytep = coding->src_multibyte;
5168 struct ccl_program *ccl = &coding->spec.ccl->ccl; 5186 struct ccl_program *ccl = &coding->spec.ccl->ccl;
5169 int source_charbuf[1024]; 5187 int source_charbuf[1024];
@@ -5235,7 +5253,7 @@ encode_coding_ccl (struct coding_system *coding)
5235 unsigned char *dst = coding->destination + coding->produced; 5253 unsigned char *dst = coding->destination + coding->produced;
5236 unsigned char *dst_end = coding->destination + coding->dst_bytes; 5254 unsigned char *dst_end = coding->destination + coding->dst_bytes;
5237 int destination_charbuf[1024]; 5255 int destination_charbuf[1024];
5238 EMACS_INT produced_chars = 0; 5256 ptrdiff_t produced_chars = 0;
5239 int i; 5257 int i;
5240 Lisp_Object attrs, charset_list; 5258 Lisp_Object attrs, charset_list;
5241 5259
@@ -5323,7 +5341,7 @@ encode_coding_raw_text (struct coding_system *coding)
5323 int *charbuf_end = coding->charbuf + coding->charbuf_used; 5341 int *charbuf_end = coding->charbuf + coding->charbuf_used;
5324 unsigned char *dst = coding->destination + coding->produced; 5342 unsigned char *dst = coding->destination + coding->produced;
5325 unsigned char *dst_end = coding->destination + coding->dst_bytes; 5343 unsigned char *dst_end = coding->destination + coding->dst_bytes;
5326 EMACS_INT produced_chars = 0; 5344 ptrdiff_t produced_chars = 0;
5327 int c; 5345 int c;
5328 5346
5329 if (multibytep) 5347 if (multibytep)
@@ -5406,10 +5424,10 @@ detect_coding_charset (struct coding_system *coding,
5406 const unsigned char *src = coding->source, *src_base; 5424 const unsigned char *src = coding->source, *src_base;
5407 const unsigned char *src_end = coding->source + coding->src_bytes; 5425 const unsigned char *src_end = coding->source + coding->src_bytes;
5408 int multibytep = coding->src_multibyte; 5426 int multibytep = coding->src_multibyte;
5409 EMACS_INT consumed_chars = 0; 5427 ptrdiff_t consumed_chars = 0;
5410 Lisp_Object attrs, valids, name; 5428 Lisp_Object attrs, valids, name;
5411 int found = 0; 5429 int found = 0;
5412 EMACS_INT head_ascii = coding->head_ascii; 5430 ptrdiff_t head_ascii = coding->head_ascii;
5413 int check_latin_extra = 0; 5431 int check_latin_extra = 0;
5414 5432
5415 detect_info->checked |= CATEGORY_MASK_CHARSET; 5433 detect_info->checked |= CATEGORY_MASK_CHARSET;
@@ -5513,12 +5531,12 @@ decode_coding_charset (struct coding_system *coding)
5513 the end. */ 5531 the end. */
5514 int *charbuf_end 5532 int *charbuf_end
5515 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); 5533 = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2);
5516 EMACS_INT consumed_chars = 0, consumed_chars_base; 5534 ptrdiff_t consumed_chars = 0, consumed_chars_base;
5517 int multibytep = coding->src_multibyte; 5535 int multibytep = coding->src_multibyte;
5518 Lisp_Object attrs = CODING_ID_ATTRS (coding->id); 5536 Lisp_Object attrs = CODING_ID_ATTRS (coding->id);
5519 Lisp_Object valids; 5537 Lisp_Object valids;
5520 EMACS_INT char_offset = coding->produced_char; 5538 ptrdiff_t char_offset = coding->produced_char;
5521 EMACS_INT last_offset = char_offset; 5539 ptrdiff_t last_offset = char_offset;
5522 int last_id = charset_ascii; 5540 int last_id = charset_ascii;
5523 int eol_dos = 5541 int eol_dos =
5524 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 5542 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
@@ -5639,7 +5657,7 @@ encode_coding_charset (struct coding_system *coding)
5639 unsigned char *dst = coding->destination + coding->produced; 5657 unsigned char *dst = coding->destination + coding->produced;
5640 unsigned char *dst_end = coding->destination + coding->dst_bytes; 5658 unsigned char *dst_end = coding->destination + coding->dst_bytes;
5641 int safe_room = MAX_MULTIBYTE_LENGTH; 5659 int safe_room = MAX_MULTIBYTE_LENGTH;
5642 EMACS_INT produced_chars = 0; 5660 ptrdiff_t produced_chars = 0;
5643 Lisp_Object attrs, charset_list; 5661 Lisp_Object attrs, charset_list;
5644 int ascii_compatible; 5662 int ascii_compatible;
5645 int c; 5663 int c;
@@ -6188,7 +6206,7 @@ complement_process_encoding_system (Lisp_Object coding_system)
6188#define MAX_EOL_CHECK_COUNT 3 6206#define MAX_EOL_CHECK_COUNT 3
6189 6207
6190static int 6208static int
6191detect_eol (const unsigned char *source, EMACS_INT src_bytes, 6209detect_eol (const unsigned char *source, ptrdiff_t src_bytes,
6192 enum coding_category category) 6210 enum coding_category category)
6193{ 6211{
6194 const unsigned char *src = source, *src_end = src + src_bytes; 6212 const unsigned char *src = source, *src_end = src + src_bytes;
@@ -6549,7 +6567,7 @@ decode_eol (struct coding_system *coding)
6549 } 6567 }
6550 else if (EQ (eol_type, Qdos)) 6568 else if (EQ (eol_type, Qdos))
6551 { 6569 {
6552 EMACS_INT n = 0; 6570 ptrdiff_t n = 0;
6553 6571
6554 if (NILP (coding->dst_object)) 6572 if (NILP (coding->dst_object))
6555 { 6573 {
@@ -6564,9 +6582,9 @@ decode_eol (struct coding_system *coding)
6564 } 6582 }
6565 else 6583 else
6566 { 6584 {
6567 EMACS_INT pos_byte = coding->dst_pos_byte; 6585 ptrdiff_t pos_byte = coding->dst_pos_byte;
6568 EMACS_INT pos = coding->dst_pos; 6586 ptrdiff_t pos = coding->dst_pos;
6569 EMACS_INT pos_end = pos + coding->produced_char - 1; 6587 ptrdiff_t pos_end = pos + coding->produced_char - 1;
6570 6588
6571 while (pos < pos_end) 6589 while (pos < pos_end)
6572 { 6590 {
@@ -6706,8 +6724,8 @@ get_translation (Lisp_Object trans, int *buf, int *buf_end)
6706 { 6724 {
6707 Lisp_Object val = XCAR (trans); 6725 Lisp_Object val = XCAR (trans);
6708 Lisp_Object from = XCAR (val); 6726 Lisp_Object from = XCAR (val);
6709 int len = ASIZE (from); 6727 ptrdiff_t len = ASIZE (from);
6710 int i; 6728 ptrdiff_t i;
6711 6729
6712 for (i = 0; i < len; i++) 6730 for (i = 0; i < len; i++)
6713 { 6731 {
@@ -6729,8 +6747,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6729{ 6747{
6730 unsigned char *dst = coding->destination + coding->produced; 6748 unsigned char *dst = coding->destination + coding->produced;
6731 unsigned char *dst_end = coding->destination + coding->dst_bytes; 6749 unsigned char *dst_end = coding->destination + coding->dst_bytes;
6732 EMACS_INT produced; 6750 ptrdiff_t produced;
6733 EMACS_INT produced_chars = 0; 6751 ptrdiff_t produced_chars = 0;
6734 int carryover = 0; 6752 int carryover = 0;
6735 6753
6736 if (! coding->chars_at_source) 6754 if (! coding->chars_at_source)
@@ -6751,7 +6769,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6751 6769
6752 if (c >= 0) 6770 if (c >= 0)
6753 { 6771 {
6754 EMACS_INT from_nchars = 1, to_nchars = 1; 6772 ptrdiff_t from_nchars = 1, to_nchars = 1;
6755 Lisp_Object trans = Qnil; 6773 Lisp_Object trans = Qnil;
6756 6774
6757 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans); 6775 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
@@ -6828,7 +6846,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6828 if (coding->src_multibyte) 6846 if (coding->src_multibyte)
6829 { 6847 {
6830 int multibytep = 1; 6848 int multibytep = 1;
6831 EMACS_INT consumed_chars = 0; 6849 ptrdiff_t consumed_chars = 0;
6832 6850
6833 while (1) 6851 while (1)
6834 { 6852 {
@@ -6842,7 +6860,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6842 dst_end = (unsigned char *) src; 6860 dst_end = (unsigned char *) src;
6843 if (dst == dst_end) 6861 if (dst == dst_end)
6844 { 6862 {
6845 EMACS_INT offset = src - coding->source; 6863 ptrdiff_t offset = src - coding->source;
6846 6864
6847 dst = alloc_destination (coding, src_end - src + 1, 6865 dst = alloc_destination (coding, src_end - src + 1,
6848 dst); 6866 dst);
@@ -6872,8 +6890,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6872 dst_end = (unsigned char *) src; 6890 dst_end = (unsigned char *) src;
6873 if (dst >= dst_end - 1) 6891 if (dst >= dst_end - 1)
6874 { 6892 {
6875 EMACS_INT offset = src - coding->source; 6893 ptrdiff_t offset = src - coding->source;
6876 EMACS_INT more_bytes; 6894 ptrdiff_t more_bytes;
6877 6895
6878 if (EQ (coding->src_object, coding->dst_object)) 6896 if (EQ (coding->src_object, coding->dst_object))
6879 more_bytes = ((src_end - src) / 2) + 2; 6897 more_bytes = ((src_end - src) / 2) + 2;
@@ -6895,11 +6913,11 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6895 { 6913 {
6896 if (!EQ (coding->src_object, coding->dst_object)) 6914 if (!EQ (coding->src_object, coding->dst_object))
6897 { 6915 {
6898 EMACS_INT require = coding->src_bytes - coding->dst_bytes; 6916 ptrdiff_t require = coding->src_bytes - coding->dst_bytes;
6899 6917
6900 if (require > 0) 6918 if (require > 0)
6901 { 6919 {
6902 EMACS_INT offset = src - coding->source; 6920 ptrdiff_t offset = src - coding->source;
6903 6921
6904 dst = alloc_destination (coding, require, dst); 6922 dst = alloc_destination (coding, require, dst);
6905 coding_set_source (coding); 6923 coding_set_source (coding);
@@ -6927,10 +6945,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6927 */ 6945 */
6928 6946
6929static inline void 6947static inline void
6930produce_composition (struct coding_system *coding, int *charbuf, EMACS_INT pos) 6948produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
6931{ 6949{
6932 int len; 6950 int len;
6933 EMACS_INT to; 6951 ptrdiff_t to;
6934 enum composition_method method; 6952 enum composition_method method;
6935 Lisp_Object components; 6953 Lisp_Object components;
6936 6954
@@ -6971,9 +6989,9 @@ produce_composition (struct coding_system *coding, int *charbuf, EMACS_INT pos)
6971 */ 6989 */
6972 6990
6973static inline void 6991static inline void
6974produce_charset (struct coding_system *coding, int *charbuf, EMACS_INT pos) 6992produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
6975{ 6993{
6976 EMACS_INT from = pos - charbuf[2]; 6994 ptrdiff_t from = pos - charbuf[2];
6977 struct charset *charset = CHARSET_FROM_ID (charbuf[3]); 6995 struct charset *charset = CHARSET_FROM_ID (charbuf[3]);
6978 6996
6979 Fput_text_property (make_number (from), make_number (pos), 6997 Fput_text_property (make_number (from), make_number (pos),
@@ -7006,7 +7024,7 @@ produce_charset (struct coding_system *coding, int *charbuf, EMACS_INT pos)
7006 7024
7007 7025
7008static void 7026static void
7009produce_annotation (struct coding_system *coding, EMACS_INT pos) 7027produce_annotation (struct coding_system *coding, ptrdiff_t pos)
7010{ 7028{
7011 int *charbuf = coding->charbuf; 7029 int *charbuf = coding->charbuf;
7012 int *charbuf_end = charbuf + coding->charbuf_used; 7030 int *charbuf_end = charbuf + coding->charbuf_used;
@@ -7106,7 +7124,7 @@ decode_coding (struct coding_system *coding)
7106 } 7124 }
7107 do 7125 do
7108 { 7126 {
7109 EMACS_INT pos = coding->dst_pos + coding->produced_char; 7127 ptrdiff_t pos = coding->dst_pos + coding->produced_char;
7110 7128
7111 coding_set_source (coding); 7129 coding_set_source (coding);
7112 coding->annotated = 0; 7130 coding->annotated = 0;
@@ -7199,11 +7217,11 @@ decode_coding (struct coding_system *coding)
7199 return BUF. */ 7217 return BUF. */
7200 7218
7201static inline int * 7219static inline int *
7202handle_composition_annotation (EMACS_INT pos, EMACS_INT limit, 7220handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit,
7203 struct coding_system *coding, int *buf, 7221 struct coding_system *coding, int *buf,
7204 EMACS_INT *stop) 7222 ptrdiff_t *stop)
7205{ 7223{
7206 EMACS_INT start, end; 7224 ptrdiff_t start, end;
7207 Lisp_Object prop; 7225 Lisp_Object prop;
7208 7226
7209 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object) 7227 if (! find_composition (pos, limit, &start, &end, &prop, coding->src_object)
@@ -7225,7 +7243,7 @@ handle_composition_annotation (EMACS_INT pos, EMACS_INT limit,
7225 if (method != COMPOSITION_RELATIVE) 7243 if (method != COMPOSITION_RELATIVE)
7226 { 7244 {
7227 Lisp_Object components; 7245 Lisp_Object components;
7228 int len, i, i_byte; 7246 ptrdiff_t i, len, i_byte;
7229 7247
7230 components = COMPOSITION_COMPONENTS (prop); 7248 components = COMPOSITION_COMPONENTS (prop);
7231 if (VECTORP (components)) 7249 if (VECTORP (components))
@@ -7282,9 +7300,9 @@ handle_composition_annotation (EMACS_INT pos, EMACS_INT limit,
7282 property value is non-nil (limiting by LIMIT), and return BUF. */ 7300 property value is non-nil (limiting by LIMIT), and return BUF. */
7283 7301
7284static inline int * 7302static inline int *
7285handle_charset_annotation (EMACS_INT pos, EMACS_INT limit, 7303handle_charset_annotation (ptrdiff_t pos, ptrdiff_t limit,
7286 struct coding_system *coding, int *buf, 7304 struct coding_system *coding, int *buf,
7287 EMACS_INT *stop) 7305 ptrdiff_t *stop)
7288{ 7306{
7289 Lisp_Object val, next; 7307 Lisp_Object val, next;
7290 int id; 7308 int id;
@@ -7311,12 +7329,12 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7311 int *buf_end = coding->charbuf + coding->charbuf_size; 7329 int *buf_end = coding->charbuf + coding->charbuf_size;
7312 const unsigned char *src = coding->source + coding->consumed; 7330 const unsigned char *src = coding->source + coding->consumed;
7313 const unsigned char *src_end = coding->source + coding->src_bytes; 7331 const unsigned char *src_end = coding->source + coding->src_bytes;
7314 EMACS_INT pos = coding->src_pos + coding->consumed_char; 7332 ptrdiff_t pos = coding->src_pos + coding->consumed_char;
7315 EMACS_INT end_pos = coding->src_pos + coding->src_chars; 7333 ptrdiff_t end_pos = coding->src_pos + coding->src_chars;
7316 int multibytep = coding->src_multibyte; 7334 int multibytep = coding->src_multibyte;
7317 Lisp_Object eol_type; 7335 Lisp_Object eol_type;
7318 int c; 7336 int c;
7319 EMACS_INT stop, stop_composition, stop_charset; 7337 ptrdiff_t stop, stop_composition, stop_charset;
7320 int *lookup_buf = NULL; 7338 int *lookup_buf = NULL;
7321 7339
7322 if (! NILP (translation_table)) 7340 if (! NILP (translation_table))
@@ -7365,7 +7383,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7365 7383
7366 if (! multibytep) 7384 if (! multibytep)
7367 { 7385 {
7368 EMACS_INT bytes; 7386 int bytes;
7369 7387
7370 if (coding->encoder == encode_coding_raw_text 7388 if (coding->encoder == encode_coding_raw_text
7371 || coding->encoder == encode_coding_ccl) 7389 || coding->encoder == encode_coding_ccl)
@@ -7396,7 +7414,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7396 *buf++ = c; 7414 *buf++ = c;
7397 else 7415 else
7398 { 7416 {
7399 int from_nchars = 1, to_nchars = 1; 7417 ptrdiff_t from_nchars = 1, to_nchars = 1;
7400 int *lookup_buf_end; 7418 int *lookup_buf_end;
7401 const unsigned char *p = src; 7419 const unsigned char *p = src;
7402 int i; 7420 int i;
@@ -7417,7 +7435,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7417 else 7435 else
7418 { 7436 {
7419 to_nchars = ASIZE (trans); 7437 to_nchars = ASIZE (trans);
7420 if (buf + to_nchars > buf_end) 7438 if (buf_end - buf < to_nchars)
7421 break; 7439 break;
7422 c = XINT (AREF (trans, 0)); 7440 c = XINT (AREF (trans, 0));
7423 } 7441 }
@@ -7591,9 +7609,9 @@ code_conversion_save (int with_work_buf, int multibyte)
7591 7609
7592int 7610int
7593decode_coding_gap (struct coding_system *coding, 7611decode_coding_gap (struct coding_system *coding,
7594 EMACS_INT chars, EMACS_INT bytes) 7612 ptrdiff_t chars, ptrdiff_t bytes)
7595{ 7613{
7596 int count = SPECPDL_INDEX (); 7614 ptrdiff_t count = SPECPDL_INDEX ();
7597 Lisp_Object attrs; 7615 Lisp_Object attrs;
7598 7616
7599 code_conversion_save (0, 0); 7617 code_conversion_save (0, 0);
@@ -7620,7 +7638,7 @@ decode_coding_gap (struct coding_system *coding,
7620 attrs = CODING_ID_ATTRS (coding->id); 7638 attrs = CODING_ID_ATTRS (coding->id);
7621 if (! NILP (CODING_ATTR_POST_READ (attrs))) 7639 if (! NILP (CODING_ATTR_POST_READ (attrs)))
7622 { 7640 {
7623 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; 7641 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
7624 Lisp_Object val; 7642 Lisp_Object val;
7625 7643
7626 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); 7644 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte);
@@ -7668,15 +7686,15 @@ decode_coding_gap (struct coding_system *coding,
7668void 7686void
7669decode_coding_object (struct coding_system *coding, 7687decode_coding_object (struct coding_system *coding,
7670 Lisp_Object src_object, 7688 Lisp_Object src_object,
7671 EMACS_INT from, EMACS_INT from_byte, 7689 ptrdiff_t from, ptrdiff_t from_byte,
7672 EMACS_INT to, EMACS_INT to_byte, 7690 ptrdiff_t to, ptrdiff_t to_byte,
7673 Lisp_Object dst_object) 7691 Lisp_Object dst_object)
7674{ 7692{
7675 int count = SPECPDL_INDEX (); 7693 ptrdiff_t count = SPECPDL_INDEX ();
7676 unsigned char *destination IF_LINT (= NULL); 7694 unsigned char *destination IF_LINT (= NULL);
7677 EMACS_INT dst_bytes IF_LINT (= 0); 7695 ptrdiff_t dst_bytes IF_LINT (= 0);
7678 EMACS_INT chars = to - from; 7696 ptrdiff_t chars = to - from;
7679 EMACS_INT bytes = to_byte - from_byte; 7697 ptrdiff_t bytes = to_byte - from_byte;
7680 Lisp_Object attrs; 7698 Lisp_Object attrs;
7681 int saved_pt = -1, saved_pt_byte IF_LINT (= 0); 7699 int saved_pt = -1, saved_pt_byte IF_LINT (= 0);
7682 int need_marker_adjustment = 0; 7700 int need_marker_adjustment = 0;
@@ -7769,7 +7787,7 @@ decode_coding_object (struct coding_system *coding,
7769 if (! NILP (CODING_ATTR_POST_READ (attrs))) 7787 if (! NILP (CODING_ATTR_POST_READ (attrs)))
7770 { 7788 {
7771 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 7789 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
7772 EMACS_INT prev_Z = Z, prev_Z_BYTE = Z_BYTE; 7790 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
7773 Lisp_Object val; 7791 Lisp_Object val;
7774 7792
7775 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte); 7793 TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte);
@@ -7858,13 +7876,13 @@ decode_coding_object (struct coding_system *coding,
7858void 7876void
7859encode_coding_object (struct coding_system *coding, 7877encode_coding_object (struct coding_system *coding,
7860 Lisp_Object src_object, 7878 Lisp_Object src_object,
7861 EMACS_INT from, EMACS_INT from_byte, 7879 ptrdiff_t from, ptrdiff_t from_byte,
7862 EMACS_INT to, EMACS_INT to_byte, 7880 ptrdiff_t to, ptrdiff_t to_byte,
7863 Lisp_Object dst_object) 7881 Lisp_Object dst_object)
7864{ 7882{
7865 int count = SPECPDL_INDEX (); 7883 ptrdiff_t count = SPECPDL_INDEX ();
7866 EMACS_INT chars = to - from; 7884 ptrdiff_t chars = to - from;
7867 EMACS_INT bytes = to_byte - from_byte; 7885 ptrdiff_t bytes = to_byte - from_byte;
7868 Lisp_Object attrs; 7886 Lisp_Object attrs;
7869 int saved_pt = -1, saved_pt_byte IF_LINT (= 0); 7887 int saved_pt = -1, saved_pt_byte IF_LINT (= 0);
7870 int need_marker_adjustment = 0; 7888 int need_marker_adjustment = 0;
@@ -8112,7 +8130,7 @@ are lower-case). */)
8112 (Lisp_Object prompt, Lisp_Object default_coding_system) 8130 (Lisp_Object prompt, Lisp_Object default_coding_system)
8113{ 8131{
8114 Lisp_Object val; 8132 Lisp_Object val;
8115 int count = SPECPDL_INDEX (); 8133 ptrdiff_t count = SPECPDL_INDEX ();
8116 8134
8117 if (SYMBOLP (default_coding_system)) 8135 if (SYMBOLP (default_coding_system))
8118 default_coding_system = SYMBOL_NAME (default_coding_system); 8136 default_coding_system = SYMBOL_NAME (default_coding_system);
@@ -8164,7 +8182,7 @@ function `define-coding-system'. */)
8164 8182
8165Lisp_Object 8183Lisp_Object
8166detect_coding_system (const unsigned char *src, 8184detect_coding_system (const unsigned char *src,
8167 EMACS_INT src_chars, EMACS_INT src_bytes, 8185 ptrdiff_t src_chars, ptrdiff_t src_bytes,
8168 int highest, int multibytep, 8186 int highest, int multibytep,
8169 Lisp_Object coding_system) 8187 Lisp_Object coding_system)
8170{ 8188{
@@ -8484,8 +8502,8 @@ If optional argument HIGHEST is non-nil, return the coding system of
8484highest priority. */) 8502highest priority. */)
8485 (Lisp_Object start, Lisp_Object end, Lisp_Object highest) 8503 (Lisp_Object start, Lisp_Object end, Lisp_Object highest)
8486{ 8504{
8487 int from, to; 8505 ptrdiff_t from, to;
8488 int from_byte, to_byte; 8506 ptrdiff_t from_byte, to_byte;
8489 8507
8490 CHECK_NUMBER_COERCE_MARKER (start); 8508 CHECK_NUMBER_COERCE_MARKER (start);
8491 CHECK_NUMBER_COERCE_MARKER (end); 8509 CHECK_NUMBER_COERCE_MARKER (end);
@@ -8565,7 +8583,7 @@ DEFUN ("find-coding-systems-region-internal",
8565 (Lisp_Object start, Lisp_Object end, Lisp_Object exclude) 8583 (Lisp_Object start, Lisp_Object end, Lisp_Object exclude)
8566{ 8584{
8567 Lisp_Object coding_attrs_list, safe_codings; 8585 Lisp_Object coding_attrs_list, safe_codings;
8568 EMACS_INT start_byte, end_byte; 8586 ptrdiff_t start_byte, end_byte;
8569 const unsigned char *p, *pbeg, *pend; 8587 const unsigned char *p, *pbeg, *pend;
8570 int c; 8588 int c;
8571 Lisp_Object tail, elt, work_table; 8589 Lisp_Object tail, elt, work_table;
@@ -8659,7 +8677,7 @@ DEFUN ("find-coding-systems-region-internal",
8659 } 8677 }
8660 if (charset_map_loaded) 8678 if (charset_map_loaded)
8661 { 8679 {
8662 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; 8680 ptrdiff_t p_offset = p - pbeg, pend_offset = pend - pbeg;
8663 8681
8664 if (STRINGP (start)) 8682 if (STRINGP (start))
8665 pbeg = SDATA (start); 8683 pbeg = SDATA (start);
@@ -8697,11 +8715,11 @@ for un-encodable characters. In that case, START and END are indexes
8697to the string. */) 8715to the string. */)
8698 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object count, Lisp_Object string) 8716 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object count, Lisp_Object string)
8699{ 8717{
8700 int n; 8718 EMACS_INT n;
8701 struct coding_system coding; 8719 struct coding_system coding;
8702 Lisp_Object attrs, charset_list, translation_table; 8720 Lisp_Object attrs, charset_list, translation_table;
8703 Lisp_Object positions; 8721 Lisp_Object positions;
8704 int from, to; 8722 ptrdiff_t from, to;
8705 const unsigned char *p, *stop, *pend; 8723 const unsigned char *p, *stop, *pend;
8706 int ascii_compatible; 8724 int ascii_compatible;
8707 8725
@@ -8734,11 +8752,10 @@ to the string. */)
8734 CHECK_STRING (string); 8752 CHECK_STRING (string);
8735 CHECK_NATNUM (start); 8753 CHECK_NATNUM (start);
8736 CHECK_NATNUM (end); 8754 CHECK_NATNUM (end);
8755 if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
8756 args_out_of_range_3 (string, start, end);
8737 from = XINT (start); 8757 from = XINT (start);
8738 to = XINT (end); 8758 to = XINT (end);
8739 if (from > to
8740 || to > SCHARS (string))
8741 args_out_of_range_3 (string, start, end);
8742 if (! STRING_MULTIBYTE (string)) 8759 if (! STRING_MULTIBYTE (string))
8743 return Qnil; 8760 return Qnil;
8744 p = SDATA (string) + string_char_to_byte (string, from); 8761 p = SDATA (string) + string_char_to_byte (string, from);
@@ -8824,8 +8841,8 @@ is nil. */)
8824 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system_list) 8841 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system_list)
8825{ 8842{
8826 Lisp_Object list; 8843 Lisp_Object list;
8827 EMACS_INT start_byte, end_byte; 8844 ptrdiff_t start_byte, end_byte;
8828 int pos; 8845 ptrdiff_t pos;
8829 const unsigned char *p, *pbeg, *pend; 8846 const unsigned char *p, *pbeg, *pend;
8830 int c; 8847 int c;
8831 Lisp_Object tail, elt, attrs; 8848 Lisp_Object tail, elt, attrs;
@@ -8898,7 +8915,7 @@ is nil. */)
8898 } 8915 }
8899 if (charset_map_loaded) 8916 if (charset_map_loaded)
8900 { 8917 {
8901 EMACS_INT p_offset = p - pbeg, pend_offset = pend - pbeg; 8918 ptrdiff_t p_offset = p - pbeg, pend_offset = pend - pbeg;
8902 8919
8903 if (STRINGP (start)) 8920 if (STRINGP (start))
8904 pbeg = SDATA (start); 8921 pbeg = SDATA (start);
@@ -8931,7 +8948,7 @@ code_convert_region (Lisp_Object start, Lisp_Object end,
8931 int encodep, int norecord) 8948 int encodep, int norecord)
8932{ 8949{
8933 struct coding_system coding; 8950 struct coding_system coding;
8934 EMACS_INT from, from_byte, to, to_byte; 8951 ptrdiff_t from, from_byte, to, to_byte;
8935 Lisp_Object src_object; 8952 Lisp_Object src_object;
8936 8953
8937 CHECK_NUMBER_COERCE_MARKER (start); 8954 CHECK_NUMBER_COERCE_MARKER (start);
@@ -9019,7 +9036,7 @@ code_convert_string (Lisp_Object string, Lisp_Object coding_system,
9019 Lisp_Object dst_object, int encodep, int nocopy, int norecord) 9036 Lisp_Object dst_object, int encodep, int nocopy, int norecord)
9020{ 9037{
9021 struct coding_system coding; 9038 struct coding_system coding;
9022 EMACS_INT chars, bytes; 9039 ptrdiff_t chars, bytes;
9023 9040
9024 CHECK_STRING (string); 9041 CHECK_STRING (string);
9025 if (NILP (coding_system)) 9042 if (NILP (coding_system))
@@ -9394,9 +9411,9 @@ usage: (find-operation-coding-system OPERATION ARGUMENTS...) */)
9394 error ("Too few arguments"); 9411 error ("Too few arguments");
9395 operation = args[0]; 9412 operation = args[0];
9396 if (!SYMBOLP (operation) 9413 if (!SYMBOLP (operation)
9397 || !NATNUMP (target_idx = Fget (operation, Qtarget_idx))) 9414 || (target_idx = Fget (operation, Qtarget_idx), !NATNUMP (target_idx)))
9398 error ("Invalid first argument"); 9415 error ("Invalid first argument");
9399 if (nargs < 1 + XFASTINT (target_idx)) 9416 if (nargs <= 1 + XFASTINT (target_idx))
9400 error ("Too few arguments for operation `%s'", 9417 error ("Too few arguments for operation `%s'",
9401 SDATA (SYMBOL_NAME (operation))); 9418 SDATA (SYMBOL_NAME (operation)));
9402 target = args[XFASTINT (target_idx) + 1]; 9419 target = args[XFASTINT (target_idx) + 1];
@@ -9615,8 +9632,12 @@ usage: (define-coding-system-internal ...) */)
9615 charset_list = Vemacs_mule_charset_list; 9632 charset_list = Vemacs_mule_charset_list;
9616 } 9633 }
9617 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) 9634 for (tail = charset_list; CONSP (tail); tail = XCDR (tail))
9618 if (max_charset_id < XFASTINT (XCAR (tail))) 9635 {
9619 max_charset_id = XFASTINT (XCAR (tail)); 9636 if (! RANGED_INTEGERP (0, XCAR (tail), INT_MAX - 1))
9637 error ("Invalid charset-list");
9638 if (max_charset_id < XFASTINT (XCAR (tail)))
9639 max_charset_id = XFASTINT (XCAR (tail));
9640 }
9620 } 9641 }
9621 else 9642 else
9622 { 9643 {
@@ -9776,23 +9797,23 @@ usage: (define-coding-system-internal ...) */)
9776 val = Fcar (tail); 9797 val = Fcar (tail);
9777 if (INTEGERP (val)) 9798 if (INTEGERP (val))
9778 { 9799 {
9779 from = to = XINT (val); 9800 if (! (0 <= XINT (val) && XINT (val) <= 255))
9780 if (from < 0 || from > 255)
9781 args_out_of_range_3 (val, make_number (0), make_number (255)); 9801 args_out_of_range_3 (val, make_number (0), make_number (255));
9802 from = to = XINT (val);
9782 } 9803 }
9783 else 9804 else
9784 { 9805 {
9785 CHECK_CONS (val); 9806 CHECK_CONS (val);
9786 CHECK_NATNUM_CAR (val); 9807 CHECK_NATNUM_CAR (val);
9787 CHECK_NATNUM_CDR (val); 9808 CHECK_NUMBER_CDR (val);
9788 from = XINT (XCAR (val)); 9809 if (XINT (XCAR (val)) > 255)
9789 if (from > 255)
9790 args_out_of_range_3 (XCAR (val), 9810 args_out_of_range_3 (XCAR (val),
9791 make_number (0), make_number (255)); 9811 make_number (0), make_number (255));
9792 to = XINT (XCDR (val)); 9812 from = XINT (XCAR (val));
9793 if (to < from || to > 255) 9813 if (! (from <= XINT (XCDR (val)) && XINT (XCDR (val)) <= 255))
9794 args_out_of_range_3 (XCDR (val), 9814 args_out_of_range_3 (XCDR (val),
9795 XCAR (val), make_number (255)); 9815 XCAR (val), make_number (255));
9816 to = XINT (XCDR (val));
9796 } 9817 }
9797 for (i = from; i <= to; i++) 9818 for (i = from; i <= to; i++)
9798 SSET (valids, i, 1); 9819 SSET (valids, i, 1);
@@ -9887,9 +9908,10 @@ usage: (define-coding-system-internal ...) */)
9887 9908
9888 flags = args[coding_arg_iso2022_flags]; 9909 flags = args[coding_arg_iso2022_flags];
9889 CHECK_NATNUM (flags); 9910 CHECK_NATNUM (flags);
9890 i = XINT (flags); 9911 i = XINT (flags) & INT_MAX;
9891 if (EQ (args[coding_arg_charset_list], Qiso_2022)) 9912 if (EQ (args[coding_arg_charset_list], Qiso_2022))
9892 flags = make_number (i | CODING_ISO_FLAG_FULL_SUPPORT); 9913 i |= CODING_ISO_FLAG_FULL_SUPPORT;
9914 flags = make_number (i);
9893 9915
9894 ASET (attrs, coding_attr_iso_initial, initial); 9916 ASET (attrs, coding_attr_iso_initial, initial);
9895 ASET (attrs, coding_attr_iso_usage, reg_usage); 9917 ASET (attrs, coding_attr_iso_usage, reg_usage);
diff --git a/src/coding.h b/src/coding.h
index 908e222cc68..50435282229 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -449,25 +449,25 @@ struct coding_system
449 -1 in setup_coding_system, and updated by detect_coding. So, 449 -1 in setup_coding_system, and updated by detect_coding. So,
450 when this is equal to the byte length of the text being 450 when this is equal to the byte length of the text being
451 converted, we can skip the actual conversion process. */ 451 converted, we can skip the actual conversion process. */
452 EMACS_INT head_ascii; 452 ptrdiff_t head_ascii;
453 453
454 /* The following members are set by encoding/decoding routine. */ 454 /* The following members are set by encoding/decoding routine. */
455 EMACS_INT produced, produced_char, consumed, consumed_char; 455 ptrdiff_t produced, produced_char, consumed, consumed_char;
456 456
457 /* Number of error source data found in a decoding routine. */ 457 /* Number of error source data found in a decoding routine. */
458 int errors; 458 int errors;
459 459
460 /* Store the positions of error source data. */ 460 /* Store the positions of error source data. */
461 EMACS_INT *error_positions; 461 ptrdiff_t *error_positions;
462 462
463 /* Finish status of code conversion. */ 463 /* Finish status of code conversion. */
464 enum coding_result_code result; 464 enum coding_result_code result;
465 465
466 EMACS_INT src_pos, src_pos_byte, src_chars, src_bytes; 466 ptrdiff_t src_pos, src_pos_byte, src_chars, src_bytes;
467 Lisp_Object src_object; 467 Lisp_Object src_object;
468 const unsigned char *source; 468 const unsigned char *source;
469 469
470 EMACS_INT dst_pos, dst_pos_byte, dst_bytes; 470 ptrdiff_t dst_pos, dst_pos_byte, dst_bytes;
471 Lisp_Object dst_object; 471 Lisp_Object dst_object;
472 unsigned char *destination; 472 unsigned char *destination;
473 473
@@ -704,13 +704,13 @@ extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
704extern Lisp_Object complement_process_encoding_system (Lisp_Object); 704extern Lisp_Object complement_process_encoding_system (Lisp_Object);
705 705
706extern int decode_coding_gap (struct coding_system *, 706extern int decode_coding_gap (struct coding_system *,
707 EMACS_INT, EMACS_INT); 707 ptrdiff_t, ptrdiff_t);
708extern void decode_coding_object (struct coding_system *, 708extern void decode_coding_object (struct coding_system *,
709 Lisp_Object, EMACS_INT, EMACS_INT, 709 Lisp_Object, ptrdiff_t, ptrdiff_t,
710 EMACS_INT, EMACS_INT, Lisp_Object); 710 ptrdiff_t, ptrdiff_t, Lisp_Object);
711extern void encode_coding_object (struct coding_system *, 711extern void encode_coding_object (struct coding_system *,
712 Lisp_Object, EMACS_INT, EMACS_INT, 712 Lisp_Object, ptrdiff_t, ptrdiff_t,
713 EMACS_INT, EMACS_INT, Lisp_Object); 713 ptrdiff_t, ptrdiff_t, Lisp_Object);
714 714
715/* Macros for backward compatibility. */ 715/* Macros for backward compatibility. */
716 716
diff --git a/src/composite.c b/src/composite.c
index abf71c275fa..50aca156ba4 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -173,7 +173,7 @@ Lisp_Object composition_temp;
173 If the composition is invalid, return -1. */ 173 If the composition is invalid, return -1. */
174 174
175ptrdiff_t 175ptrdiff_t
176get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, 176get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
177 Lisp_Object prop, Lisp_Object string) 177 Lisp_Object prop, Lisp_Object string)
178{ 178{
179 Lisp_Object id, length, components, key, *key_contents; 179 Lisp_Object id, length, components, key, *key_contents;
@@ -183,7 +183,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
183 EMACS_UINT hash_code; 183 EMACS_UINT hash_code;
184 enum composition_method method; 184 enum composition_method method;
185 struct composition *cmp; 185 struct composition *cmp;
186 EMACS_INT i; 186 ptrdiff_t i;
187 int ch; 187 int ch;
188 188
189 /* Maximum length of a string of glyphs. XftGlyphExtents limits 189 /* Maximum length of a string of glyphs. XftGlyphExtents limits
@@ -284,7 +284,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
284 && VECTORP (AREF (components, 0))) 284 && VECTORP (AREF (components, 0)))
285 { 285 {
286 /* COMPONENTS is a glyph-string. */ 286 /* COMPONENTS is a glyph-string. */
287 EMACS_INT len = ASIZE (key); 287 ptrdiff_t len = ASIZE (key);
288 288
289 for (i = 1; i < len; i++) 289 for (i = 1; i < len; i++)
290 if (! VECTORP (AREF (key, i))) 290 if (! VECTORP (AREF (key, i)))
@@ -292,7 +292,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
292 } 292 }
293 else if (VECTORP (components) || CONSP (components)) 293 else if (VECTORP (components) || CONSP (components))
294 { 294 {
295 EMACS_INT len = ASIZE (key); 295 ptrdiff_t len = ASIZE (key);
296 296
297 /* The number of elements should be odd. */ 297 /* The number of elements should be odd. */
298 if ((len % 2) == 0) 298 if ((len % 2) == 0)
@@ -429,8 +429,8 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
429 This doesn't check the validity of composition. */ 429 This doesn't check the validity of composition. */
430 430
431int 431int
432find_composition (EMACS_INT pos, EMACS_INT limit, 432find_composition (ptrdiff_t pos, ptrdiff_t limit,
433 EMACS_INT *start, EMACS_INT *end, 433 ptrdiff_t *start, ptrdiff_t *end,
434 Lisp_Object *prop, Lisp_Object object) 434 Lisp_Object *prop, Lisp_Object object)
435{ 435{
436 Lisp_Object val; 436 Lisp_Object val;
@@ -469,10 +469,10 @@ find_composition (EMACS_INT pos, EMACS_INT limit,
469 FROM and TO with property PROP. */ 469 FROM and TO with property PROP. */
470 470
471static void 471static void
472run_composition_function (EMACS_INT from, EMACS_INT to, Lisp_Object prop) 472run_composition_function (ptrdiff_t from, ptrdiff_t to, Lisp_Object prop)
473{ 473{
474 Lisp_Object func; 474 Lisp_Object func;
475 EMACS_INT start, end; 475 ptrdiff_t start, end;
476 476
477 func = COMPOSITION_MODIFICATION_FUNC (prop); 477 func = COMPOSITION_MODIFICATION_FUNC (prop);
478 /* If an invalid composition precedes or follows, try to make them 478 /* If an invalid composition precedes or follows, try to make them
@@ -501,13 +501,13 @@ run_composition_function (EMACS_INT from, EMACS_INT to, Lisp_Object prop)
501 change is deletion, FROM == TO. Otherwise, FROM < TO. */ 501 change is deletion, FROM == TO. Otherwise, FROM < TO. */
502 502
503void 503void
504update_compositions (EMACS_INT from, EMACS_INT to, int check_mask) 504update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
505{ 505{
506 Lisp_Object prop; 506 Lisp_Object prop;
507 EMACS_INT start, end; 507 ptrdiff_t start, end;
508 /* The beginning and end of the region to set the property 508 /* The beginning and end of the region to set the property
509 `auto-composed' to nil. */ 509 `auto-composed' to nil. */
510 EMACS_INT min_pos = from, max_pos = to; 510 ptrdiff_t min_pos = from, max_pos = to;
511 511
512 if (inhibit_modification_hooks) 512 if (inhibit_modification_hooks)
513 return; 513 return;
@@ -589,7 +589,7 @@ update_compositions (EMACS_INT from, EMACS_INT to, int check_mask)
589 } 589 }
590 if (min_pos < max_pos) 590 if (min_pos < max_pos)
591 { 591 {
592 int count = SPECPDL_INDEX (); 592 ptrdiff_t count = SPECPDL_INDEX ();
593 593
594 specbind (Qinhibit_read_only, Qt); 594 specbind (Qinhibit_read_only, Qt);
595 specbind (Qinhibit_modification_hooks, Qt); 595 specbind (Qinhibit_modification_hooks, Qt);
@@ -632,7 +632,7 @@ make_composition_value_copy (Lisp_Object list)
632 indices START and END in STRING. */ 632 indices START and END in STRING. */
633 633
634void 634void
635compose_text (EMACS_INT start, EMACS_INT end, Lisp_Object components, 635compose_text (ptrdiff_t start, ptrdiff_t end, Lisp_Object components,
636 Lisp_Object modification_func, Lisp_Object string) 636 Lisp_Object modification_func, Lisp_Object string)
637{ 637{
638 Lisp_Object prop; 638 Lisp_Object prop;
@@ -644,8 +644,8 @@ compose_text (EMACS_INT start, EMACS_INT end, Lisp_Object components,
644} 644}
645 645
646 646
647static Lisp_Object autocmp_chars (Lisp_Object, EMACS_INT, EMACS_INT, 647static Lisp_Object autocmp_chars (Lisp_Object, ptrdiff_t, ptrdiff_t,
648 EMACS_INT, struct window *, 648 ptrdiff_t, struct window *,
649 struct face *, Lisp_Object); 649 struct face *, Lisp_Object);
650 650
651 651
@@ -669,25 +669,25 @@ gstring_lookup_cache (Lisp_Object header)
669} 669}
670 670
671Lisp_Object 671Lisp_Object
672composition_gstring_put_cache (Lisp_Object gstring, EMACS_INT len) 672composition_gstring_put_cache (Lisp_Object gstring, ptrdiff_t len)
673{ 673{
674 struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); 674 struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
675 EMACS_UINT hash; 675 EMACS_UINT hash;
676 Lisp_Object header, copy; 676 Lisp_Object header, copy;
677 EMACS_INT i; 677 ptrdiff_t i;
678 678
679 header = LGSTRING_HEADER (gstring); 679 header = LGSTRING_HEADER (gstring);
680 hash = h->hashfn (h, header); 680 hash = h->hashfn (h, header);
681 if (len < 0) 681 if (len < 0)
682 { 682 {
683 EMACS_INT j, glyph_len = LGSTRING_GLYPH_LEN (gstring); 683 ptrdiff_t j, glyph_len = LGSTRING_GLYPH_LEN (gstring);
684 for (j = 0; j < glyph_len; j++) 684 for (j = 0; j < glyph_len; j++)
685 if (NILP (LGSTRING_GLYPH (gstring, j))) 685 if (NILP (LGSTRING_GLYPH (gstring, j)))
686 break; 686 break;
687 len = j; 687 len = j;
688 } 688 }
689 689
690 lint_assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2); 690 lint_assume (len <= TYPE_MAXIMUM (ptrdiff_t) - 2);
691 copy = Fmake_vector (make_number (len + 2), Qnil); 691 copy = Fmake_vector (make_number (len + 2), Qnil);
692 LGSTRING_SET_HEADER (copy, Fcopy_sequence (header)); 692 LGSTRING_SET_HEADER (copy, Fcopy_sequence (header));
693 for (i = 0; i < len; i++) 693 for (i = 0; i < len; i++)
@@ -713,7 +713,7 @@ int
713composition_gstring_p (Lisp_Object gstring) 713composition_gstring_p (Lisp_Object gstring)
714{ 714{
715 Lisp_Object header; 715 Lisp_Object header;
716 EMACS_INT i; 716 ptrdiff_t i;
717 717
718 if (! VECTORP (gstring) || ASIZE (gstring) < 2) 718 if (! VECTORP (gstring) || ASIZE (gstring) < 2)
719 return 0; 719 return 0;
@@ -741,7 +741,7 @@ composition_gstring_p (Lisp_Object gstring)
741} 741}
742 742
743int 743int
744composition_gstring_width (Lisp_Object gstring, EMACS_INT from, EMACS_INT to, 744composition_gstring_width (Lisp_Object gstring, ptrdiff_t from, ptrdiff_t to,
745 struct font_metrics *metrics) 745 struct font_metrics *metrics)
746{ 746{
747 Lisp_Object *glyph; 747 Lisp_Object *glyph;
@@ -800,8 +800,8 @@ static Lisp_Object gstring_work_headers;
800static Lisp_Object 800static Lisp_Object
801fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, Lisp_Object font_object, Lisp_Object string) 801fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, Lisp_Object font_object, Lisp_Object string)
802{ 802{
803 EMACS_INT from, to, from_byte; 803 ptrdiff_t from, to, from_byte;
804 EMACS_INT len, i; 804 ptrdiff_t len, i;
805 805
806 if (NILP (string)) 806 if (NILP (string))
807 { 807 {
@@ -817,11 +817,11 @@ fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, Lis
817 CHECK_STRING (string); 817 CHECK_STRING (string);
818 if (! STRING_MULTIBYTE (string)) 818 if (! STRING_MULTIBYTE (string))
819 error ("Attempt to shape unibyte text"); 819 error ("Attempt to shape unibyte text");
820 /* FROM and TO are checked by the caller. */ 820 /* The caller checks that START and END are nonnegative integers. */
821 if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
822 args_out_of_range_3 (string, start, end);
821 from = XINT (start); 823 from = XINT (start);
822 to = XINT (end); 824 to = XINT (end);
823 if (from < 0 || from > to || to > SCHARS (string))
824 args_out_of_range_3 (string, start, end);
825 from_byte = string_char_to_byte (string, from); 825 from_byte = string_char_to_byte (string, from);
826 } 826 }
827 827
@@ -860,8 +860,8 @@ fill_gstring_body (Lisp_Object gstring)
860{ 860{
861 Lisp_Object font_object = LGSTRING_FONT (gstring); 861 Lisp_Object font_object = LGSTRING_FONT (gstring);
862 Lisp_Object header = AREF (gstring, 0); 862 Lisp_Object header = AREF (gstring, 0);
863 EMACS_INT len = LGSTRING_CHAR_LEN (gstring); 863 ptrdiff_t len = LGSTRING_CHAR_LEN (gstring);
864 EMACS_INT i; 864 ptrdiff_t i;
865 865
866 for (i = 0; i < len; i++) 866 for (i = 0; i < len; i++)
867 { 867 {
@@ -906,15 +906,15 @@ fill_gstring_body (Lisp_Object gstring)
906 object. Otherwise return nil. */ 906 object. Otherwise return nil. */
907 907
908static Lisp_Object 908static Lisp_Object
909autocmp_chars (Lisp_Object rule, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT limit, struct window *win, struct face *face, Lisp_Object string) 909autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t limit, struct window *win, struct face *face, Lisp_Object string)
910{ 910{
911 int count = SPECPDL_INDEX (); 911 ptrdiff_t count = SPECPDL_INDEX ();
912 FRAME_PTR f = XFRAME (win->frame); 912 FRAME_PTR f = XFRAME (win->frame);
913 Lisp_Object pos = make_number (charpos); 913 Lisp_Object pos = make_number (charpos);
914 EMACS_INT to; 914 ptrdiff_t to;
915 EMACS_INT pt = PT, pt_byte = PT_BYTE; 915 ptrdiff_t pt = PT, pt_byte = PT_BYTE;
916 Lisp_Object re, font_object, lgstring; 916 Lisp_Object re, font_object, lgstring;
917 EMACS_INT len; 917 ptrdiff_t len;
918 918
919 record_unwind_save_match_data (); 919 record_unwind_save_match_data ();
920 re = AREF (rule, 0); 920 re = AREF (rule, 0);
@@ -997,9 +997,9 @@ static Lisp_Object _work_val;
997 composition. */ 997 composition. */
998 998
999void 999void
1000composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, Lisp_Object string) 1000composition_compute_stop_pos (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t endpos, Lisp_Object string)
1001{ 1001{
1002 EMACS_INT start, end; 1002 ptrdiff_t start, end;
1003 int c; 1003 int c;
1004 Lisp_Object prop, val; 1004 Lisp_Object prop, val;
1005 /* This is from forward_to_next_line_start in xdisp.c. */ 1005 /* This is from forward_to_next_line_start in xdisp.c. */
@@ -1109,7 +1109,7 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
1109 int len; 1109 int len;
1110 /* Limit byte position used in fast_looking_at. This is the 1110 /* Limit byte position used in fast_looking_at. This is the
1111 byte position of the character after START. */ 1111 byte position of the character after START. */
1112 EMACS_INT limit; 1112 ptrdiff_t limit;
1113 1113
1114 if (NILP (string)) 1114 if (NILP (string))
1115 p = BYTE_POS_ADDR (bytepos); 1115 p = BYTE_POS_ADDR (bytepos);
@@ -1123,16 +1123,17 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
1123 if (! NILP (val)) 1123 if (! NILP (val))
1124 { 1124 {
1125 Lisp_Object elt; 1125 Lisp_Object elt;
1126 int ridx, back, blen; 1126 int ridx, blen;
1127 1127
1128 for (ridx = 0; CONSP (val); val = XCDR (val), ridx++) 1128 for (ridx = 0; CONSP (val); val = XCDR (val), ridx++)
1129 { 1129 {
1130 elt = XCAR (val); 1130 elt = XCAR (val);
1131 if (VECTORP (elt) && ASIZE (elt) == 3 1131 if (VECTORP (elt) && ASIZE (elt) == 3
1132 && NATNUMP (AREF (elt, 1)) 1132 && NATNUMP (AREF (elt, 1))
1133 && charpos - (back = XFASTINT (AREF (elt, 1))) > endpos) 1133 && charpos - XFASTINT (AREF (elt, 1)) > endpos)
1134 { 1134 {
1135 EMACS_INT cpos = charpos - back, bpos; 1135 ptrdiff_t back = XFASTINT (AREF (elt, 1));
1136 ptrdiff_t cpos = charpos - back, bpos;
1136 1137
1137 if (back == 0) 1138 if (back == 0)
1138 bpos = bytepos; 1139 bpos = bytepos;
@@ -1226,7 +1227,7 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
1226 CMP_IT->stop_pos, and return 0. */ 1227 CMP_IT->stop_pos, and return 0. */
1227 1228
1228int 1229int
1229composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, struct window *w, struct face *face, Lisp_Object string) 1230composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t endpos, struct window *w, struct face *face, Lisp_Object string)
1230{ 1231{
1231 if (endpos < 0) 1232 if (endpos < 0)
1232 endpos = NILP (string) ? BEGV : 0; 1233 endpos = NILP (string) ? BEGV : 0;
@@ -1242,7 +1243,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1242 if (cmp_it->ch < 0) 1243 if (cmp_it->ch < 0)
1243 { 1244 {
1244 /* We are looking at a static composition. */ 1245 /* We are looking at a static composition. */
1245 EMACS_INT start, end; 1246 ptrdiff_t start, end;
1246 Lisp_Object prop; 1247 Lisp_Object prop;
1247 1248
1248 find_composition (charpos, -1, &start, &end, &prop, string); 1249 find_composition (charpos, -1, &start, &end, &prop, string);
@@ -1257,7 +1258,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1257 { 1258 {
1258 Lisp_Object lgstring = Qnil; 1259 Lisp_Object lgstring = Qnil;
1259 Lisp_Object val, elt; 1260 Lisp_Object val, elt;
1260 EMACS_INT i; 1261 ptrdiff_t i;
1261 1262
1262 val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch); 1263 val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch);
1263 for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val)); 1264 for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val));
@@ -1284,7 +1285,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1284 } 1285 }
1285 else 1286 else
1286 { 1287 {
1287 EMACS_INT cpos = charpos, bpos = bytepos; 1288 ptrdiff_t cpos = charpos, bpos = bytepos;
1288 1289
1289 while (1) 1290 while (1)
1290 { 1291 {
@@ -1370,7 +1371,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1370 the cluster, or -1 if the composition is somehow broken. */ 1371 the cluster, or -1 if the composition is somehow broken. */
1371 1372
1372int 1373int
1373composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, Lisp_Object string) 1374composition_update_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff_t bytepos, Lisp_Object string)
1374{ 1375{
1375 int i, c IF_LINT (= 0); 1376 int i, c IF_LINT (= 0);
1376 1377
@@ -1405,7 +1406,7 @@ composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1405 /* automatic composition */ 1406 /* automatic composition */
1406 Lisp_Object gstring = composition_gstring_from_id (cmp_it->id); 1407 Lisp_Object gstring = composition_gstring_from_id (cmp_it->id);
1407 Lisp_Object glyph; 1408 Lisp_Object glyph;
1408 EMACS_INT from; 1409 ptrdiff_t from;
1409 1410
1410 if (cmp_it->nglyphs == 0) 1411 if (cmp_it->nglyphs == 0)
1411 { 1412 {
@@ -1457,7 +1458,7 @@ composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1457 1458
1458struct position_record 1459struct position_record
1459{ 1460{
1460 EMACS_INT pos, pos_byte; 1461 ptrdiff_t pos, pos_byte;
1461 unsigned char *p; 1462 unsigned char *p;
1462}; 1463};
1463 1464
@@ -1496,14 +1497,14 @@ struct position_record
1496 Qnil, and return 0. */ 1497 Qnil, and return 0. */
1497 1498
1498static int 1499static int
1499find_automatic_composition (EMACS_INT pos, EMACS_INT limit, 1500find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit,
1500 EMACS_INT *start, EMACS_INT *end, 1501 ptrdiff_t *start, ptrdiff_t *end,
1501 Lisp_Object *gstring, Lisp_Object string) 1502 Lisp_Object *gstring, Lisp_Object string)
1502{ 1503{
1503 EMACS_INT head, tail, stop; 1504 ptrdiff_t head, tail, stop;
1504 /* Forward limit position of checking a composition taking a 1505 /* Forward limit position of checking a composition taking a
1505 looking-back count into account. */ 1506 looking-back count into account. */
1506 EMACS_INT fore_check_limit; 1507 ptrdiff_t fore_check_limit;
1507 struct position_record cur, prev; 1508 struct position_record cur, prev;
1508 int c; 1509 int c;
1509 Lisp_Object window; 1510 Lisp_Object window;
@@ -1688,10 +1689,10 @@ find_automatic_composition (EMACS_INT pos, EMACS_INT limit,
1688/* Return the adjusted point provided that point is moved from LAST_PT 1689/* Return the adjusted point provided that point is moved from LAST_PT
1689 to NEW_PT. */ 1690 to NEW_PT. */
1690 1691
1691EMACS_INT 1692ptrdiff_t
1692composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt) 1693composition_adjust_point (ptrdiff_t last_pt, ptrdiff_t new_pt)
1693{ 1694{
1694 EMACS_INT i, beg, end; 1695 ptrdiff_t i, beg, end;
1695 Lisp_Object val; 1696 Lisp_Object val;
1696 1697
1697 if (new_pt == BEGV || new_pt == ZV) 1698 if (new_pt == BEGV || new_pt == ZV)
@@ -1712,7 +1713,7 @@ composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt)
1712 return new_pt; 1713 return new_pt;
1713 1714
1714 /* Next check the automatic composition. */ 1715 /* Next check the automatic composition. */
1715 if (! find_automatic_composition (new_pt, (EMACS_INT) -1, &beg, &end, &val, 1716 if (! find_automatic_composition (new_pt, (ptrdiff_t) -1, &beg, &end, &val,
1716 Qnil) 1717 Qnil)
1717 || beg == new_pt) 1718 || beg == new_pt)
1718 return new_pt; 1719 return new_pt;
@@ -1773,7 +1774,7 @@ should be ignored. */)
1773 (Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string) 1774 (Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string)
1774{ 1775{
1775 Lisp_Object gstring, header; 1776 Lisp_Object gstring, header;
1776 EMACS_INT frompos, topos; 1777 ptrdiff_t frompos, topos;
1777 1778
1778 CHECK_NATNUM (from); 1779 CHECK_NATNUM (from);
1779 CHECK_NATNUM (to); 1780 CHECK_NATNUM (to);
@@ -1857,15 +1858,14 @@ See `find-composition' for more details. */)
1857 (Lisp_Object pos, Lisp_Object limit, Lisp_Object string, Lisp_Object detail_p) 1858 (Lisp_Object pos, Lisp_Object limit, Lisp_Object string, Lisp_Object detail_p)
1858{ 1859{
1859 Lisp_Object prop, tail, gstring; 1860 Lisp_Object prop, tail, gstring;
1860 EMACS_INT start, end, from, to; 1861 ptrdiff_t start, end, from, to;
1861 int id; 1862 int id;
1862 1863
1863 CHECK_NUMBER_COERCE_MARKER (pos); 1864 CHECK_NUMBER_COERCE_MARKER (pos);
1864 from = XINT (pos);
1865 if (!NILP (limit)) 1865 if (!NILP (limit))
1866 { 1866 {
1867 CHECK_NUMBER_COERCE_MARKER (limit); 1867 CHECK_NUMBER_COERCE_MARKER (limit);
1868 to = XINT (limit); 1868 to = min (XINT (limit), ZV);
1869 } 1869 }
1870 else 1870 else
1871 to = -1; 1871 to = -1;
@@ -1881,6 +1881,7 @@ See `find-composition' for more details. */)
1881 if (XINT (pos) < BEGV || XINT (pos) > ZV) 1881 if (XINT (pos) < BEGV || XINT (pos) > ZV)
1882 args_out_of_range (Fcurrent_buffer (), pos); 1882 args_out_of_range (Fcurrent_buffer (), pos);
1883 } 1883 }
1884 from = XINT (pos);
1884 1885
1885 if (!find_composition (from, to, &start, &end, &prop, string)) 1886 if (!find_composition (from, to, &start, &end, &prop, string))
1886 { 1887 {
@@ -1893,7 +1894,7 @@ See `find-composition' for more details. */)
1893 } 1894 }
1894 if ((end <= XINT (pos) || start > XINT (pos))) 1895 if ((end <= XINT (pos) || start > XINT (pos)))
1895 { 1896 {
1896 EMACS_INT s, e; 1897 ptrdiff_t s, e;
1897 1898
1898 if (find_automatic_composition (from, to, &s, &e, &gstring, string) 1899 if (find_automatic_composition (from, to, &s, &e, &gstring, string)
1899 && (e <= XINT (pos) ? e > end : s < start)) 1900 && (e <= XINT (pos) ? e > end : s < start))
@@ -1910,7 +1911,7 @@ See `find-composition' for more details. */)
1910 id = COMPOSITION_ID (prop); 1911 id = COMPOSITION_ID (prop);
1911 else 1912 else
1912 { 1913 {
1913 EMACS_INT start_byte = (NILP (string) 1914 ptrdiff_t start_byte = (NILP (string)
1914 ? CHAR_TO_BYTE (start) 1915 ? CHAR_TO_BYTE (start)
1915 : string_char_to_byte (string, start)); 1916 : string_char_to_byte (string, start));
1916 id = get_composition_id (start, start_byte, end - start, prop, string); 1917 id = get_composition_id (start, start_byte, end - start, prop, string);
diff --git a/src/composite.h b/src/composite.h
index 56647503982..845411f5cde 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -186,7 +186,7 @@ struct composition {
186 enum composition_method method; 186 enum composition_method method;
187 187
188 /* Index to the composition hash table. */ 188 /* Index to the composition hash table. */
189 EMACS_INT hash_index; 189 ptrdiff_t hash_index;
190 190
191 /* For which font we have calculated the remaining members. The 191 /* For which font we have calculated the remaining members. The
192 actual type is device dependent. */ 192 actual type is device dependent. */
@@ -216,16 +216,16 @@ extern ptrdiff_t n_compositions;
216 216
217extern Lisp_Object Qcomposition; 217extern Lisp_Object Qcomposition;
218extern Lisp_Object composition_hash_table; 218extern Lisp_Object composition_hash_table;
219extern ptrdiff_t get_composition_id (EMACS_INT, EMACS_INT, EMACS_INT, 219extern ptrdiff_t get_composition_id (ptrdiff_t, ptrdiff_t, ptrdiff_t,
220 Lisp_Object, Lisp_Object); 220 Lisp_Object, Lisp_Object);
221extern int find_composition (EMACS_INT, EMACS_INT, EMACS_INT *, EMACS_INT *, 221extern int find_composition (ptrdiff_t, ptrdiff_t, ptrdiff_t *, ptrdiff_t *,
222 Lisp_Object *, Lisp_Object); 222 Lisp_Object *, Lisp_Object);
223extern void update_compositions (EMACS_INT, EMACS_INT, int); 223extern void update_compositions (ptrdiff_t, ptrdiff_t, int);
224extern void make_composition_value_copy (Lisp_Object); 224extern void make_composition_value_copy (Lisp_Object);
225extern void compose_region (int, int, Lisp_Object, Lisp_Object, 225extern void compose_region (int, int, Lisp_Object, Lisp_Object,
226 Lisp_Object); 226 Lisp_Object);
227extern void syms_of_composite (void); 227extern void syms_of_composite (void);
228extern void compose_text (EMACS_INT, EMACS_INT, Lisp_Object, Lisp_Object, 228extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object,
229 Lisp_Object); 229 Lisp_Object);
230 230
231/* Macros for lispy glyph-string. This is completely different from 231/* Macros for lispy glyph-string. This is completely different from
@@ -298,22 +298,22 @@ struct composition_it;
298struct face; 298struct face;
299struct font_metrics; 299struct font_metrics;
300 300
301extern Lisp_Object composition_gstring_put_cache (Lisp_Object, EMACS_INT); 301extern Lisp_Object composition_gstring_put_cache (Lisp_Object, ptrdiff_t);
302extern Lisp_Object composition_gstring_from_id (ptrdiff_t); 302extern Lisp_Object composition_gstring_from_id (ptrdiff_t);
303extern int composition_gstring_p (Lisp_Object); 303extern int composition_gstring_p (Lisp_Object);
304extern int composition_gstring_width (Lisp_Object, EMACS_INT, EMACS_INT, 304extern int composition_gstring_width (Lisp_Object, ptrdiff_t, ptrdiff_t,
305 struct font_metrics *); 305 struct font_metrics *);
306 306
307extern void composition_compute_stop_pos (struct composition_it *, 307extern void composition_compute_stop_pos (struct composition_it *,
308 EMACS_INT, EMACS_INT, EMACS_INT, 308 ptrdiff_t, ptrdiff_t, ptrdiff_t,
309 Lisp_Object); 309 Lisp_Object);
310extern int composition_reseat_it (struct composition_it *, 310extern int composition_reseat_it (struct composition_it *,
311 EMACS_INT, EMACS_INT, EMACS_INT, 311 ptrdiff_t, ptrdiff_t, ptrdiff_t,
312 struct window *, struct face *, 312 struct window *, struct face *,
313 Lisp_Object); 313 Lisp_Object);
314extern int composition_update_it (struct composition_it *, 314extern int composition_update_it (struct composition_it *,
315 EMACS_INT, EMACS_INT, Lisp_Object); 315 ptrdiff_t, ptrdiff_t, Lisp_Object);
316 316
317extern EMACS_INT composition_adjust_point (EMACS_INT, EMACS_INT); 317extern ptrdiff_t composition_adjust_point (ptrdiff_t, ptrdiff_t);
318 318
319#endif /* not EMACS_COMPOSITE_H */ 319#endif /* not EMACS_COMPOSITE_H */
diff --git a/src/data.c b/src/data.c
index feacea2c08b..defcd06a2ed 100644
--- a/src/data.c
+++ b/src/data.c
@@ -34,6 +34,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
34#include "syssignal.h" 34#include "syssignal.h"
35#include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */ 35#include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
36#include "font.h" 36#include "font.h"
37#include "keymap.h"
37 38
38#include <float.h> 39#include <float.h>
39/* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ 40/* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
@@ -92,6 +93,7 @@ Lisp_Object Qbuffer;
92static Lisp_Object Qchar_table, Qbool_vector, Qhash_table; 93static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
93static Lisp_Object Qsubrp, Qmany, Qunevalled; 94static Lisp_Object Qsubrp, Qmany, Qunevalled;
94Lisp_Object Qfont_spec, Qfont_entity, Qfont_object; 95Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
96static Lisp_Object Qdefun;
95 97
96Lisp_Object Qinteractive_form; 98Lisp_Object Qinteractive_form;
97 99
@@ -130,7 +132,7 @@ args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
130} 132}
131 133
132 134
133/* Data type predicates */ 135/* Data type predicates. */
134 136
135DEFUN ("eq", Feq, Seq, 2, 2, 0, 137DEFUN ("eq", Feq, Seq, 2, 2, 0,
136 doc: /* Return t if the two args are the same Lisp object. */) 138 doc: /* Return t if the two args are the same Lisp object. */)
@@ -656,6 +658,10 @@ determined by DEFINITION. */)
656 if (CONSP (XSYMBOL (symbol)->function) 658 if (CONSP (XSYMBOL (symbol)->function)
657 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload)) 659 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
658 LOADHIST_ATTACH (Fcons (Qt, symbol)); 660 LOADHIST_ATTACH (Fcons (Qt, symbol));
661 if (!NILP (Vpurify_flag)
662 /* If `definition' is a keymap, immutable (and copying) is wrong. */
663 && !KEYMAPP (definition))
664 definition = Fpurecopy (definition);
659 definition = Ffset (symbol, definition); 665 definition = Ffset (symbol, definition);
660 LOADHIST_ATTACH (Fcons (Qdefun, symbol)); 666 LOADHIST_ATTACH (Fcons (Qdefun, symbol));
661 if (!NILP (docstring)) 667 if (!NILP (docstring))
@@ -1075,18 +1081,18 @@ let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol)
1075{ 1081{
1076 struct specbinding *p; 1082 struct specbinding *p;
1077 1083
1078 for (p = specpdl_ptr - 1; p >= specpdl; p--) 1084 for (p = specpdl_ptr; p > specpdl; )
1079 if (p->func == NULL 1085 if ((--p)->func == NULL
1080 && CONSP (p->symbol)) 1086 && CONSP (p->symbol))
1081 { 1087 {
1082 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol)); 1088 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
1083 eassert (let_bound_symbol->redirect != SYMBOL_VARALIAS); 1089 eassert (let_bound_symbol->redirect != SYMBOL_VARALIAS);
1084 if (symbol == let_bound_symbol 1090 if (symbol == let_bound_symbol
1085 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer) 1091 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1086 break; 1092 return 1;
1087 } 1093 }
1088 1094
1089 return p >= specpdl; 1095 return 0;
1090} 1096}
1091 1097
1092static int 1098static int
@@ -1094,11 +1100,11 @@ let_shadows_global_binding_p (Lisp_Object symbol)
1094{ 1100{
1095 struct specbinding *p; 1101 struct specbinding *p;
1096 1102
1097 for (p = specpdl_ptr - 1; p >= specpdl; p--) 1103 for (p = specpdl_ptr; p > specpdl; )
1098 if (p->func == NULL && EQ (p->symbol, symbol)) 1104 if ((--p)->func == NULL && EQ (p->symbol, symbol))
1099 break; 1105 return 1;
1100 1106
1101 return p >= specpdl; 1107 return 0;
1102} 1108}
1103 1109
1104/* Store the value NEWVAL into SYMBOL. 1110/* Store the value NEWVAL into SYMBOL.
@@ -2064,7 +2070,7 @@ or a byte-code object. IDX starts at 0. */)
2064 if (STRINGP (array)) 2070 if (STRINGP (array))
2065 { 2071 {
2066 int c; 2072 int c;
2067 EMACS_INT idxval_byte; 2073 ptrdiff_t idxval_byte;
2068 2074
2069 if (idxval < 0 || idxval >= SCHARS (array)) 2075 if (idxval < 0 || idxval >= SCHARS (array))
2070 args_out_of_range (array, idx); 2076 args_out_of_range (array, idx);
@@ -2092,7 +2098,7 @@ or a byte-code object. IDX starts at 0. */)
2092 } 2098 }
2093 else 2099 else
2094 { 2100 {
2095 int size = 0; 2101 ptrdiff_t size = 0;
2096 if (VECTORP (array)) 2102 if (VECTORP (array))
2097 size = ASIZE (array); 2103 size = ASIZE (array);
2098 else if (COMPILEDP (array)) 2104 else if (COMPILEDP (array))
@@ -2156,7 +2162,8 @@ bool-vector. IDX starts at 0. */)
2156 2162
2157 if (STRING_MULTIBYTE (array)) 2163 if (STRING_MULTIBYTE (array))
2158 { 2164 {
2159 EMACS_INT idxval_byte, prev_bytes, new_bytes, nbytes; 2165 ptrdiff_t idxval_byte, nbytes;
2166 int prev_bytes, new_bytes;
2160 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; 2167 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2161 2168
2162 nbytes = SBYTES (array); 2169 nbytes = SBYTES (array);
@@ -2167,7 +2174,7 @@ bool-vector. IDX starts at 0. */)
2167 if (prev_bytes != new_bytes) 2174 if (prev_bytes != new_bytes)
2168 { 2175 {
2169 /* We must relocate the string data. */ 2176 /* We must relocate the string data. */
2170 EMACS_INT nchars = SCHARS (array); 2177 ptrdiff_t nchars = SCHARS (array);
2171 unsigned char *str; 2178 unsigned char *str;
2172 USE_SAFE_ALLOCA; 2179 USE_SAFE_ALLOCA;
2173 2180
@@ -2474,9 +2481,9 @@ If the base used is not 10, STRING is always parsed as integer. */)
2474 else 2481 else
2475 { 2482 {
2476 CHECK_NUMBER (base); 2483 CHECK_NUMBER (base);
2477 b = XINT (base); 2484 if (! (2 <= XINT (base) && XINT (base) <= 16))
2478 if (b < 2 || b > 16)
2479 xsignal1 (Qargs_out_of_range, base); 2485 xsignal1 (Qargs_out_of_range, base);
2486 b = XINT (base);
2480 } 2487 }
2481 2488
2482 p = SSDATA (string); 2489 p = SSDATA (string);
@@ -2724,7 +2731,7 @@ Both must be integers or markers. */)
2724 CHECK_NUMBER_COERCE_MARKER (x); 2731 CHECK_NUMBER_COERCE_MARKER (x);
2725 CHECK_NUMBER_COERCE_MARKER (y); 2732 CHECK_NUMBER_COERCE_MARKER (y);
2726 2733
2727 if (XFASTINT (y) == 0) 2734 if (XINT (y) == 0)
2728 xsignal0 (Qarith_error); 2735 xsignal0 (Qarith_error);
2729 2736
2730 XSETINT (val, XINT (x) % XINT (y)); 2737 XSETINT (val, XINT (x) % XINT (y));
@@ -3084,6 +3091,8 @@ syms_of_data (void)
3084 DEFSYM (Qbool_vector, "bool-vector"); 3091 DEFSYM (Qbool_vector, "bool-vector");
3085 DEFSYM (Qhash_table, "hash-table"); 3092 DEFSYM (Qhash_table, "hash-table");
3086 3093
3094 DEFSYM (Qdefun, "defun");
3095
3087 DEFSYM (Qfont_spec, "font-spec"); 3096 DEFSYM (Qfont_spec, "font-spec");
3088 DEFSYM (Qfont_entity, "font-entity"); 3097 DEFSYM (Qfont_entity, "font-entity");
3089 DEFSYM (Qfont_object, "font-object"); 3098 DEFSYM (Qfont_object, "font-object");
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 62923b462b5..e506380e607 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -254,22 +254,6 @@ xd_symbol_to_dbus_type (Lisp_Object object)
254#define XD_OBJECT_TO_STRING(object) \ 254#define XD_OBJECT_TO_STRING(object) \
255 SDATA (format2 ("%s", object, Qnil)) 255 SDATA (format2 ("%s", object, Qnil))
256 256
257/* Check whether X is a valid dbus serial number. If valid, set
258 SERIAL to its value. Otherwise, signal an error. */
259#define XD_CHECK_DBUS_SERIAL(x, serial) \
260 do { \
261 dbus_uint32_t DBUS_SERIAL_MAX = -1; \
262 if (NATNUMP (x) && XINT (x) <= DBUS_SERIAL_MAX) \
263 serial = XINT (x); \
264 else if (MOST_POSITIVE_FIXNUM < DBUS_SERIAL_MAX \
265 && FLOATP (x) \
266 && 0 <= XFLOAT_DATA (x) \
267 && XFLOAT_DATA (x) <= DBUS_SERIAL_MAX) \
268 serial = XFLOAT_DATA (x); \
269 else \
270 XD_SIGNAL2 (build_string ("Invalid dbus serial"), x); \
271 } while (0)
272
273#define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ 257#define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \
274 do { \ 258 do { \
275 if (STRINGP (bus)) \ 259 if (STRINGP (bus)) \
@@ -366,9 +350,9 @@ xd_signature_cat (char *signature, char const *x)
366 signature is embedded, or DBUS_TYPE_INVALID. It is needed for the 350 signature is embedded, or DBUS_TYPE_INVALID. It is needed for the
367 check that DBUS_TYPE_DICT_ENTRY occurs only as array element. */ 351 check that DBUS_TYPE_DICT_ENTRY occurs only as array element. */
368static void 352static void
369xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lisp_Object object) 353xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object)
370{ 354{
371 unsigned int subtype; 355 int subtype;
372 Lisp_Object elt; 356 Lisp_Object elt;
373 char const *subsig; 357 char const *subsig;
374 int subsiglen; 358 int subsiglen;
@@ -538,13 +522,67 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
538 XD_DEBUG_MESSAGE ("%s", signature); 522 XD_DEBUG_MESSAGE ("%s", signature);
539} 523}
540 524
525/* Convert X to a signed integer with bounds LO and HI. */
526static intmax_t
527extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi)
528{
529 CHECK_NUMBER_OR_FLOAT (x);
530 if (INTEGERP (x))
531 {
532 if (lo <= XINT (x) && XINT (x) <= hi)
533 return XINT (x);
534 }
535 else
536 {
537 double d = XFLOAT_DATA (x);
538 if (lo <= d && d <= hi)
539 {
540 intmax_t n = d;
541 if (n == d)
542 return n;
543 }
544 }
545 if (xd_in_read_queued_messages)
546 Fthrow (Qdbus_error, Qnil);
547 else
548 args_out_of_range_3 (x,
549 make_fixnum_or_float (lo),
550 make_fixnum_or_float (hi));
551}
552
553/* Convert X to an unsigned integer with bounds 0 and HI. */
554static uintmax_t
555extract_unsigned (Lisp_Object x, uintmax_t hi)
556{
557 CHECK_NUMBER_OR_FLOAT (x);
558 if (INTEGERP (x))
559 {
560 if (0 <= XINT (x) && XINT (x) <= hi)
561 return XINT (x);
562 }
563 else
564 {
565 double d = XFLOAT_DATA (x);
566 if (0 <= d && d <= hi)
567 {
568 uintmax_t n = d;
569 if (n == d)
570 return n;
571 }
572 }
573 if (xd_in_read_queued_messages)
574 Fthrow (Qdbus_error, Qnil);
575 else
576 args_out_of_range_3 (x, make_number (0), make_fixnum_or_float (hi));
577}
578
541/* Append C value, extracted from Lisp OBJECT, to iteration ITER. 579/* Append C value, extracted from Lisp OBJECT, to iteration ITER.
542 DTYPE must be a valid DBusType. It is used to convert Lisp 580 DTYPE must be a valid DBusType. It is used to convert Lisp
543 objects, being arguments of `dbus-call-method' or 581 objects, being arguments of `dbus-call-method' or
544 `dbus-send-signal', into corresponding C values appended as 582 `dbus-send-signal', into corresponding C values appended as
545 arguments to a D-Bus message. */ 583 arguments to a D-Bus message. */
546static void 584static void
547xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) 585xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter)
548{ 586{
549 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 587 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
550 DBusMessageIter subiter; 588 DBusMessageIter subiter;
@@ -572,9 +610,10 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
572 } 610 }
573 611
574 case DBUS_TYPE_INT16: 612 case DBUS_TYPE_INT16:
575 CHECK_NUMBER (object);
576 { 613 {
577 dbus_int16_t val = XINT (object); 614 dbus_int16_t val = extract_signed (object,
615 TYPE_MINIMUM (dbus_int16_t),
616 TYPE_MAXIMUM (dbus_int16_t));
578 int pval = val; 617 int pval = val;
579 XD_DEBUG_MESSAGE ("%c %d", dtype, pval); 618 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
580 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 619 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -583,9 +622,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
583 } 622 }
584 623
585 case DBUS_TYPE_UINT16: 624 case DBUS_TYPE_UINT16:
586 CHECK_NATNUM (object);
587 { 625 {
588 dbus_uint16_t val = XFASTINT (object); 626 dbus_uint16_t val = extract_unsigned (object,
627 TYPE_MAXIMUM (dbus_uint16_t));
589 unsigned int pval = val; 628 unsigned int pval = val;
590 XD_DEBUG_MESSAGE ("%c %u", dtype, pval); 629 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
591 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 630 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -595,7 +634,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
595 634
596 case DBUS_TYPE_INT32: 635 case DBUS_TYPE_INT32:
597 { 636 {
598 dbus_int32_t val = extract_float (object); 637 dbus_int32_t val = extract_signed (object,
638 TYPE_MINIMUM (dbus_int32_t),
639 TYPE_MAXIMUM (dbus_int32_t));
599 int pval = val; 640 int pval = val;
600 XD_DEBUG_MESSAGE ("%c %d", dtype, pval); 641 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
601 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 642 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -608,7 +649,8 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
608 case DBUS_TYPE_UNIX_FD: 649 case DBUS_TYPE_UNIX_FD:
609#endif 650#endif
610 { 651 {
611 dbus_uint32_t val = extract_float (object); 652 dbus_uint32_t val = extract_unsigned (object,
653 TYPE_MAXIMUM (dbus_uint32_t));
612 unsigned int pval = val; 654 unsigned int pval = val;
613 XD_DEBUG_MESSAGE ("%c %u", dtype, pval); 655 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
614 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 656 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -618,7 +660,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
618 660
619 case DBUS_TYPE_INT64: 661 case DBUS_TYPE_INT64:
620 { 662 {
621 dbus_int64_t val = extract_float (object); 663 dbus_int64_t val = extract_signed (object,
664 TYPE_MINIMUM (dbus_int64_t),
665 TYPE_MAXIMUM (dbus_int64_t));
622 printmax_t pval = val; 666 printmax_t pval = val;
623 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); 667 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
624 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 668 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -628,7 +672,8 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
628 672
629 case DBUS_TYPE_UINT64: 673 case DBUS_TYPE_UINT64:
630 { 674 {
631 dbus_uint64_t val = extract_float (object); 675 dbus_uint64_t val = extract_unsigned (object,
676 TYPE_MAXIMUM (dbus_uint64_t));
632 uprintmax_t pval = val; 677 uprintmax_t pval = val;
633 XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); 678 XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval);
634 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 679 if (!dbus_message_iter_append_basic (iter, dtype, &val))
@@ -755,7 +800,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
755 D-Bus message must be a valid DBusType. Compound D-Bus types 800 D-Bus message must be a valid DBusType. Compound D-Bus types
756 result always in a Lisp list. */ 801 result always in a Lisp list. */
757static Lisp_Object 802static Lisp_Object
758xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter) 803xd_retrieve_arg (int dtype, DBusMessageIter *iter)
759{ 804{
760 805
761 switch (dtype) 806 switch (dtype)
@@ -887,7 +932,7 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
887} 932}
888 933
889/* Return the number of references of the shared CONNECTION. */ 934/* Return the number of references of the shared CONNECTION. */
890static int 935static ptrdiff_t
891xd_get_connection_references (DBusConnection *connection) 936xd_get_connection_references (DBusConnection *connection)
892{ 937{
893 ptrdiff_t *refcount; 938 ptrdiff_t *refcount;
@@ -1060,7 +1105,7 @@ this connection to those buses. */)
1060 DBusConnection *connection; 1105 DBusConnection *connection;
1061 DBusError derror; 1106 DBusError derror;
1062 Lisp_Object val; 1107 Lisp_Object val;
1063 int refcount; 1108 ptrdiff_t refcount;
1064 1109
1065 /* Check parameter. */ 1110 /* Check parameter. */
1066 XD_DBUS_VALIDATE_BUS_ADDRESS (bus); 1111 XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
@@ -1130,7 +1175,7 @@ this connection to those buses. */)
1130 1175
1131 /* Return reference counter. */ 1176 /* Return reference counter. */
1132 refcount = xd_get_connection_references (connection); 1177 refcount = xd_get_connection_references (connection);
1133 XD_DEBUG_MESSAGE ("Bus %s, Reference counter %d", 1178 XD_DEBUG_MESSAGE ("Bus %s, Reference counter %"pD"d",
1134 XD_OBJECT_TO_STRING (bus), refcount); 1179 XD_OBJECT_TO_STRING (bus), refcount);
1135 return make_number (refcount); 1180 return make_number (refcount);
1136} 1181}
@@ -1194,8 +1239,8 @@ usage: (dbus-message-internal &rest REST) */)
1194 DBusConnection *connection; 1239 DBusConnection *connection;
1195 DBusMessage *dmessage; 1240 DBusMessage *dmessage;
1196 DBusMessageIter iter; 1241 DBusMessageIter iter;
1197 unsigned int dtype; 1242 int dtype;
1198 unsigned int mtype; 1243 int mtype;
1199 dbus_uint32_t serial = 0; 1244 dbus_uint32_t serial = 0;
1200 unsigned int ui_serial; 1245 unsigned int ui_serial;
1201 int timeout = -1; 1246 int timeout = -1;
@@ -1209,9 +1254,10 @@ usage: (dbus-message-internal &rest REST) */)
1209 handler = Qnil; 1254 handler = Qnil;
1210 1255
1211 CHECK_NATNUM (message_type); 1256 CHECK_NATNUM (message_type);
1212 mtype = XFASTINT (message_type); 1257 if (! (DBUS_MESSAGE_TYPE_INVALID < XFASTINT (message_type)
1213 if ((mtype <= DBUS_MESSAGE_TYPE_INVALID) || (mtype >= DBUS_NUM_MESSAGE_TYPES)) 1258 && XFASTINT (message_type) < DBUS_NUM_MESSAGE_TYPES))
1214 XD_SIGNAL2 (build_string ("Invalid message type"), message_type); 1259 XD_SIGNAL2 (build_string ("Invalid message type"), message_type);
1260 mtype = XFASTINT (message_type);
1215 1261
1216 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) 1262 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1217 || (mtype == DBUS_MESSAGE_TYPE_SIGNAL)) 1263 || (mtype == DBUS_MESSAGE_TYPE_SIGNAL))
@@ -1225,7 +1271,7 @@ usage: (dbus-message-internal &rest REST) */)
1225 } 1271 }
1226 else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */ 1272 else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */
1227 { 1273 {
1228 XD_CHECK_DBUS_SERIAL (args[3], serial); 1274 serial = extract_unsigned (args[3], TYPE_MAXIMUM (dbus_uint32_t));
1229 count = 4; 1275 count = 4;
1230 } 1276 }
1231 1277
@@ -1363,7 +1409,7 @@ usage: (dbus-message-internal &rest REST) */)
1363 if ((count+2 <= nargs) && (EQ ((args[count]), QCdbus_timeout))) 1409 if ((count+2 <= nargs) && (EQ ((args[count]), QCdbus_timeout)))
1364 { 1410 {
1365 CHECK_NATNUM (args[count+1]); 1411 CHECK_NATNUM (args[count+1]);
1366 timeout = XFASTINT (args[count+1]); 1412 timeout = min (XFASTINT (args[count+1]), INT_MAX);
1367 count = count+2; 1413 count = count+2;
1368 } 1414 }
1369 1415
@@ -1449,8 +1495,8 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1449 struct input_event event; 1495 struct input_event event;
1450 DBusMessage *dmessage; 1496 DBusMessage *dmessage;
1451 DBusMessageIter iter; 1497 DBusMessageIter iter;
1452 unsigned int dtype; 1498 int dtype;
1453 unsigned int mtype; 1499 int mtype;
1454 dbus_uint32_t serial; 1500 dbus_uint32_t serial;
1455 unsigned int ui_serial; 1501 unsigned int ui_serial;
1456 const char *uname, *path, *interface, *member; 1502 const char *uname, *path, *interface, *member;
@@ -1698,10 +1744,10 @@ syms_of_dbusbind (void)
1698 { 1744 {
1699#ifdef DBUS_VERSION 1745#ifdef DBUS_VERSION
1700 int major, minor, micro; 1746 int major, minor, micro;
1701 char s[1024]; 1747 char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
1702 dbus_get_version (&major, &minor, &micro); 1748 dbus_get_version (&major, &minor, &micro);
1703 snprintf (s, sizeof s, "%d.%d.%d", major, minor, micro); 1749 sprintf (s, "%d.%d.%d", major, minor, micro);
1704 Vdbus_runtime_version = make_string (s, strlen (s)); 1750 Vdbus_runtime_version = build_string (s);
1705#else 1751#else
1706 Vdbus_runtime_version = Qnil; 1752 Vdbus_runtime_version = Qnil;
1707#endif 1753#endif
diff --git a/src/dired.c b/src/dired.c
index 367bcb4031d..38dfa23c1bf 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -86,7 +86,7 @@ static Lisp_Object Qfile_name_all_completions;
86static Lisp_Object Qfile_attributes; 86static Lisp_Object Qfile_attributes;
87static Lisp_Object Qfile_attributes_lessp; 87static Lisp_Object Qfile_attributes_lessp;
88 88
89static int scmp (const char *, const char *, int); 89static ptrdiff_t scmp (const char *, const char *, ptrdiff_t);
90static Lisp_Object Ffile_attributes (Lisp_Object, Lisp_Object); 90static Lisp_Object Ffile_attributes (Lisp_Object, Lisp_Object);
91 91
92#ifdef WINDOWSNT 92#ifdef WINDOWSNT
@@ -117,11 +117,11 @@ Lisp_Object
117directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, int attrs, Lisp_Object id_format) 117directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, int attrs, Lisp_Object id_format)
118{ 118{
119 DIR *d; 119 DIR *d;
120 int directory_nbytes; 120 ptrdiff_t directory_nbytes;
121 Lisp_Object list, dirfilename, encoded_directory; 121 Lisp_Object list, dirfilename, encoded_directory;
122 struct re_pattern_buffer *bufp = NULL; 122 struct re_pattern_buffer *bufp = NULL;
123 int needsep = 0; 123 int needsep = 0;
124 int count = SPECPDL_INDEX (); 124 ptrdiff_t count = SPECPDL_INDEX ();
125 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 125 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
126 DIRENTRY *dp; 126 DIRENTRY *dp;
127#ifdef WINDOWSNT 127#ifdef WINDOWSNT
@@ -226,7 +226,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m
226 226
227 if (DIRENTRY_NONEMPTY (dp)) 227 if (DIRENTRY_NONEMPTY (dp))
228 { 228 {
229 int len; 229 ptrdiff_t len;
230 int wanted = 0; 230 int wanted = 0;
231 Lisp_Object name, finalname; 231 Lisp_Object name, finalname;
232 struct gcpro gcpro1, gcpro2; 232 struct gcpro gcpro1, gcpro2;
@@ -256,8 +256,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m
256 if (!NILP (full)) 256 if (!NILP (full))
257 { 257 {
258 Lisp_Object fullname; 258 Lisp_Object fullname;
259 int nbytes = len + directory_nbytes + needsep; 259 ptrdiff_t nbytes = len + directory_nbytes + needsep;
260 int nchars; 260 ptrdiff_t nchars;
261 261
262 fullname = make_uninit_multibyte_string (nbytes, nbytes); 262 fullname = make_uninit_multibyte_string (nbytes, nbytes);
263 memcpy (SDATA (fullname), SDATA (directory), 263 memcpy (SDATA (fullname), SDATA (directory),
@@ -449,7 +449,7 @@ static Lisp_Object
449file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, Lisp_Object predicate) 449file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, Lisp_Object predicate)
450{ 450{
451 DIR *d; 451 DIR *d;
452 int bestmatchsize = 0; 452 ptrdiff_t bestmatchsize = 0;
453 int matchcount = 0; 453 int matchcount = 0;
454 /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded. 454 /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded.
455 If ALL_FLAG is 0, BESTMATCH is either nil 455 If ALL_FLAG is 0, BESTMATCH is either nil
@@ -463,7 +463,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
463 well as "." and "..". Until shown otherwise, assume we can't exclude 463 well as "." and "..". Until shown otherwise, assume we can't exclude
464 anything. */ 464 anything. */
465 int includeall = 1; 465 int includeall = 1;
466 int count = SPECPDL_INDEX (); 466 ptrdiff_t count = SPECPDL_INDEX ();
467 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 467 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
468 468
469 elt = Qnil; 469 elt = Qnil;
@@ -502,7 +502,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
502 while (1) 502 while (1)
503 { 503 {
504 DIRENTRY *dp; 504 DIRENTRY *dp;
505 int len; 505 ptrdiff_t len;
506 int canexclude = 0; 506 int canexclude = 0;
507 507
508 errno = 0; 508 errno = 0;
@@ -538,7 +538,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
538 completions when making a list of them. */ 538 completions when making a list of them. */
539 if (!all_flag) 539 if (!all_flag)
540 { 540 {
541 int skip; 541 ptrdiff_t skip;
542 542
543#if 0 /* FIXME: The `scmp' call compares an encoded and a decoded string. */ 543#if 0 /* FIXME: The `scmp' call compares an encoded and a decoded string. */
544 /* If this entry matches the current bestmatch, the only 544 /* If this entry matches the current bestmatch, the only
@@ -568,7 +568,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
568 for (tem = Vcompletion_ignored_extensions; 568 for (tem = Vcompletion_ignored_extensions;
569 CONSP (tem); tem = XCDR (tem)) 569 CONSP (tem); tem = XCDR (tem))
570 { 570 {
571 int elt_len; 571 ptrdiff_t elt_len;
572 char *p1; 572 char *p1;
573 573
574 elt = XCAR (tem); 574 elt = XCAR (tem);
@@ -685,7 +685,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
685 685
686 /* Suitably record this match. */ 686 /* Suitably record this match. */
687 687
688 matchcount++; 688 matchcount += matchcount <= 1;
689 689
690 if (all_flag) 690 if (all_flag)
691 bestmatch = Fcons (name, bestmatch); 691 bestmatch = Fcons (name, bestmatch);
@@ -698,14 +698,14 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
698 { 698 {
699 Lisp_Object zero = make_number (0); 699 Lisp_Object zero = make_number (0);
700 /* FIXME: This is a copy of the code in Ftry_completion. */ 700 /* FIXME: This is a copy of the code in Ftry_completion. */
701 int compare = min (bestmatchsize, SCHARS (name)); 701 ptrdiff_t compare = min (bestmatchsize, SCHARS (name));
702 Lisp_Object cmp 702 Lisp_Object cmp
703 = Fcompare_strings (bestmatch, zero, 703 = Fcompare_strings (bestmatch, zero,
704 make_number (compare), 704 make_number (compare),
705 name, zero, 705 name, zero,
706 make_number (compare), 706 make_number (compare),
707 completion_ignore_case ? Qt : Qnil); 707 completion_ignore_case ? Qt : Qnil);
708 int matchsize 708 ptrdiff_t matchsize
709 = (EQ (cmp, Qt) ? compare 709 = (EQ (cmp, Qt) ? compare
710 : XINT (cmp) < 0 ? - XINT (cmp) - 1 710 : XINT (cmp) < 0 ? - XINT (cmp) - 1
711 : XINT (cmp) - 1); 711 : XINT (cmp) - 1);
@@ -784,10 +784,10 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v
784 Return -1 if strings match, 784 Return -1 if strings match,
785 else number of chars that match at the beginning. */ 785 else number of chars that match at the beginning. */
786 786
787static int 787static ptrdiff_t
788scmp (const char *s1, const char *s2, int len) 788scmp (const char *s1, const char *s2, ptrdiff_t len)
789{ 789{
790 register int l = len; 790 register ptrdiff_t l = len;
791 791
792 if (completion_ignore_case) 792 if (completion_ignore_case)
793 { 793 {
@@ -810,10 +810,12 @@ scmp (const char *s1, const char *s2, int len)
810static int 810static int
811file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr) 811file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr)
812{ 812{
813 int len = NAMLEN (dp); 813 ptrdiff_t len = NAMLEN (dp);
814 int pos = SCHARS (dirname); 814 ptrdiff_t pos = SCHARS (dirname);
815 int value; 815 int value;
816 char *fullname = (char *) alloca (len + pos + 2); 816 char *fullname;
817 USE_SAFE_ALLOCA;
818 SAFE_ALLOCA (fullname, char *, len + pos + 2);
817 819
818#ifdef MSDOS 820#ifdef MSDOS
819 /* Some fields of struct stat are *very* expensive to compute on MS-DOS, 821 /* Some fields of struct stat are *very* expensive to compute on MS-DOS,
@@ -842,6 +844,7 @@ file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_ad
842#ifdef MSDOS 844#ifdef MSDOS
843 _djstat_flags = save_djstat_flags; 845 _djstat_flags = save_djstat_flags;
844#endif /* MSDOS */ 846#endif /* MSDOS */
847 SAFE_FREE ();
845 return value; 848 return value;
846} 849}
847 850
diff --git a/src/dispextern.h b/src/dispextern.h
index b4aa0153846..3076a02b217 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -179,10 +179,10 @@ extern int trace_redisplay_p EXTERNALLY_VISIBLE;
179struct text_pos 179struct text_pos
180{ 180{
181 /* Character position. */ 181 /* Character position. */
182 EMACS_INT charpos; 182 ptrdiff_t charpos;
183 183
184 /* Corresponding byte position. */ 184 /* Corresponding byte position. */
185 EMACS_INT bytepos; 185 ptrdiff_t bytepos;
186}; 186};
187 187
188/* Access character and byte position of POS in a functional form. */ 188/* Access character and byte position of POS in a functional form. */
@@ -253,7 +253,7 @@ struct display_pos
253 is the index of that overlay string in the sequence of overlay 253 is the index of that overlay string in the sequence of overlay
254 strings at `pos' in the order redisplay processes them. A value 254 strings at `pos' in the order redisplay processes them. A value
255 < 0 means that this is not a position in an overlay string. */ 255 < 0 means that this is not a position in an overlay string. */
256 int overlay_string_index; 256 ptrdiff_t overlay_string_index;
257 257
258 /* If this is a position in an overlay string, string_pos is the 258 /* If this is a position in an overlay string, string_pos is the
259 position within that string. */ 259 position within that string. */
@@ -324,7 +324,7 @@ struct glyph
324 buffer, this is a position in that buffer. A value of -1 324 buffer, this is a position in that buffer. A value of -1
325 together with a null object means glyph is a truncation glyph at 325 together with a null object means glyph is a truncation glyph at
326 the start of a row. */ 326 the start of a row. */
327 EMACS_INT charpos; 327 ptrdiff_t charpos;
328 328
329 /* Lisp object source of this glyph. Currently either a buffer or 329 /* Lisp object source of this glyph. Currently either a buffer or
330 a string, if the glyph was produced from characters which came from 330 a string, if the glyph was produced from characters which came from
@@ -1818,7 +1818,7 @@ typedef enum { NEUTRAL_DIR, L2R, R2L } bidi_dir_t;
1818/* Data type for storing information about characters we need to 1818/* Data type for storing information about characters we need to
1819 remember. */ 1819 remember. */
1820struct bidi_saved_info { 1820struct bidi_saved_info {
1821 EMACS_INT bytepos, charpos; /* character's buffer position */ 1821 ptrdiff_t bytepos, charpos; /* character's buffer position */
1822 bidi_type_t type; /* character's resolved bidi type */ 1822 bidi_type_t type; /* character's resolved bidi type */
1823 bidi_type_t type_after_w1; /* original type of the character, after W1 */ 1823 bidi_type_t type_after_w1; /* original type of the character, after W1 */
1824 bidi_type_t orig_type; /* type as we found it in the buffer */ 1824 bidi_type_t orig_type; /* type as we found it in the buffer */
@@ -1835,9 +1835,9 @@ struct bidi_stack {
1835struct bidi_string_data { 1835struct bidi_string_data {
1836 Lisp_Object lstring; /* Lisp string to reorder, or nil */ 1836 Lisp_Object lstring; /* Lisp string to reorder, or nil */
1837 const unsigned char *s; /* string data, or NULL if reordering buffer */ 1837 const unsigned char *s; /* string data, or NULL if reordering buffer */
1838 EMACS_INT schars; /* the number of characters in the string, 1838 ptrdiff_t schars; /* the number of characters in the string,
1839 excluding the terminating null */ 1839 excluding the terminating null */
1840 EMACS_INT bufpos; /* buffer position of lstring, or 0 if N/A */ 1840 ptrdiff_t bufpos; /* buffer position of lstring, or 0 if N/A */
1841 unsigned from_disp_str : 1; /* 1 means the string comes from a 1841 unsigned from_disp_str : 1; /* 1 means the string comes from a
1842 display property */ 1842 display property */
1843 unsigned unibyte : 1; /* 1 means the string is unibyte */ 1843 unsigned unibyte : 1; /* 1 means the string is unibyte */
@@ -1845,14 +1845,14 @@ struct bidi_string_data {
1845 1845
1846/* Data type for reordering bidirectional text. */ 1846/* Data type for reordering bidirectional text. */
1847struct bidi_it { 1847struct bidi_it {
1848 EMACS_INT bytepos; /* iterator's position in buffer/string */ 1848 ptrdiff_t bytepos; /* iterator's position in buffer/string */
1849 EMACS_INT charpos; 1849 ptrdiff_t charpos;
1850 int ch; /* character at that position, or u+FFFC 1850 int ch; /* character at that position, or u+FFFC
1851 ("object replacement character") for a run 1851 ("object replacement character") for a run
1852 of characters covered by a display string */ 1852 of characters covered by a display string */
1853 EMACS_INT nchars; /* its "length", usually 1; it's > 1 for a run 1853 ptrdiff_t nchars; /* its "length", usually 1; it's > 1 for a run
1854 of characters covered by a display string */ 1854 of characters covered by a display string */
1855 EMACS_INT ch_len; /* its length in bytes */ 1855 ptrdiff_t ch_len; /* its length in bytes */
1856 bidi_type_t type; /* bidi type of this character, after 1856 bidi_type_t type; /* bidi type of this character, after
1857 resolving weak and neutral types */ 1857 resolving weak and neutral types */
1858 bidi_type_t type_after_w1; /* original type, after overrides and W1 */ 1858 bidi_type_t type_after_w1; /* original type, after overrides and W1 */
@@ -1866,12 +1866,12 @@ struct bidi_it {
1866 struct bidi_saved_info next_for_neutral; /* surrounding characters for... */ 1866 struct bidi_saved_info next_for_neutral; /* surrounding characters for... */
1867 struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */ 1867 struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */
1868 struct bidi_saved_info next_for_ws; /* character after sequence of ws */ 1868 struct bidi_saved_info next_for_ws; /* character after sequence of ws */
1869 EMACS_INT next_en_pos; /* pos. of next char for determining ET type */ 1869 ptrdiff_t next_en_pos; /* pos. of next char for determining ET type */
1870 bidi_type_t next_en_type; /* type of char at next_en_pos */ 1870 bidi_type_t next_en_type; /* type of char at next_en_pos */
1871 EMACS_INT ignore_bn_limit; /* position until which to ignore BNs */ 1871 ptrdiff_t ignore_bn_limit; /* position until which to ignore BNs */
1872 bidi_dir_t sor; /* direction of start-of-run in effect */ 1872 bidi_dir_t sor; /* direction of start-of-run in effect */
1873 int scan_dir; /* direction of text scan, 1: forw, -1: back */ 1873 int scan_dir; /* direction of text scan, 1: forw, -1: back */
1874 EMACS_INT disp_pos; /* position of display string after ch */ 1874 ptrdiff_t disp_pos; /* position of display string after ch */
1875 int disp_prop; /* if non-zero, there really is a 1875 int disp_prop; /* if non-zero, there really is a
1876 `display' property/string at disp_pos; 1876 `display' property/string at disp_pos;
1877 if 2, the property is a `space' spec */ 1877 if 2, the property is a `space' spec */
@@ -1882,7 +1882,7 @@ struct bidi_it {
1882 struct bidi_stack level_stack[BIDI_MAXLEVEL]; /* stack of embedding levels */ 1882 struct bidi_stack level_stack[BIDI_MAXLEVEL]; /* stack of embedding levels */
1883 struct bidi_string_data string; /* string to reorder */ 1883 struct bidi_string_data string; /* string to reorder */
1884 bidi_dir_t paragraph_dir; /* current paragraph direction */ 1884 bidi_dir_t paragraph_dir; /* current paragraph direction */
1885 EMACS_INT separator_limit; /* where paragraph separator should end */ 1885 ptrdiff_t separator_limit; /* where paragraph separator should end */
1886 unsigned first_elt : 1; /* if non-zero, examine current char first */ 1886 unsigned first_elt : 1; /* if non-zero, examine current char first */
1887 unsigned new_paragraph : 1; /* if non-zero, we expect a new paragraph */ 1887 unsigned new_paragraph : 1; /* if non-zero, we expect a new paragraph */
1888 unsigned frame_window_p : 1; /* non-zero if displaying on a GUI frame */ 1888 unsigned frame_window_p : 1; /* non-zero if displaying on a GUI frame */
@@ -2075,7 +2075,7 @@ enum it_method {
2075struct composition_it 2075struct composition_it
2076{ 2076{
2077 /* Next position at which to check the composition. */ 2077 /* Next position at which to check the composition. */
2078 EMACS_INT stop_pos; 2078 ptrdiff_t stop_pos;
2079 /* ID number of the composition or glyph-string. If negative, we 2079 /* ID number of the composition or glyph-string. If negative, we
2080 are not iterating over a composition now. */ 2080 are not iterating over a composition now. */
2081 ptrdiff_t id; 2081 ptrdiff_t id;
@@ -2093,7 +2093,7 @@ struct composition_it
2093 /* If this is an automatic composition, how many characters to look 2093 /* If this is an automatic composition, how many characters to look
2094 back from the position where a character triggering the 2094 back from the position where a character triggering the
2095 composition exists. */ 2095 composition exists. */
2096 int lookback; 2096 ptrdiff_t lookback;
2097 /* If non-negative, number of glyphs of the glyph-string. */ 2097 /* If non-negative, number of glyphs of the glyph-string. */
2098 int nglyphs; 2098 int nglyphs;
2099 /* Nonzero iff the composition is created while buffer is scanned in 2099 /* Nonzero iff the composition is created while buffer is scanned in
@@ -2104,7 +2104,7 @@ struct composition_it
2104 /** The following members contain information about the current 2104 /** The following members contain information about the current
2105 grapheme cluster. */ 2105 grapheme cluster. */
2106 /* Position of the first character of the current grapheme cluster. */ 2106 /* Position of the first character of the current grapheme cluster. */
2107 EMACS_INT charpos; 2107 ptrdiff_t charpos;
2108 /* Number of characters and bytes of the current grapheme cluster. */ 2108 /* Number of characters and bytes of the current grapheme cluster. */
2109 int nchars, nbytes; 2109 int nchars, nbytes;
2110 /* Indices of the glyphs for the current grapheme cluster. */ 2110 /* Indices of the glyphs for the current grapheme cluster. */
@@ -2129,19 +2129,19 @@ struct it
2129 2129
2130 /* The next position at which to check for face changes, invisible 2130 /* The next position at which to check for face changes, invisible
2131 text, overlay strings, end of text etc., which see. */ 2131 text, overlay strings, end of text etc., which see. */
2132 EMACS_INT stop_charpos; 2132 ptrdiff_t stop_charpos;
2133 2133
2134 /* Previous stop position, i.e. the last one before the current 2134 /* Previous stop position, i.e. the last one before the current
2135 iterator position in `current'. */ 2135 iterator position in `current'. */
2136 EMACS_INT prev_stop; 2136 ptrdiff_t prev_stop;
2137 2137
2138 /* Last stop position iterated across whose bidi embedding level is 2138 /* Last stop position iterated across whose bidi embedding level is
2139 equal to the current paragraph's base embedding level. */ 2139 equal to the current paragraph's base embedding level. */
2140 EMACS_INT base_level_stop; 2140 ptrdiff_t base_level_stop;
2141 2141
2142 /* Maximum string or buffer position + 1. ZV when iterating over 2142 /* Maximum string or buffer position + 1. ZV when iterating over
2143 current_buffer. */ 2143 current_buffer. */
2144 EMACS_INT end_charpos; 2144 ptrdiff_t end_charpos;
2145 2145
2146 /* C string to iterate over. Non-null means get characters from 2146 /* C string to iterate over. Non-null means get characters from
2147 this string, otherwise characters are read from current_buffer 2147 this string, otherwise characters are read from current_buffer
@@ -2150,14 +2150,14 @@ struct it
2150 2150
2151 /* Number of characters in the string (s, or it->string) we iterate 2151 /* Number of characters in the string (s, or it->string) we iterate
2152 over. */ 2152 over. */
2153 EMACS_INT string_nchars; 2153 ptrdiff_t string_nchars;
2154 2154
2155 /* Start and end of a visible region; -1 if the region is not 2155 /* Start and end of a visible region; -1 if the region is not
2156 visible in the window. */ 2156 visible in the window. */
2157 EMACS_INT region_beg_charpos, region_end_charpos; 2157 ptrdiff_t region_beg_charpos, region_end_charpos;
2158 2158
2159 /* Position at which redisplay end trigger functions should be run. */ 2159 /* Position at which redisplay end trigger functions should be run. */
2160 EMACS_INT redisplay_end_trigger_charpos; 2160 ptrdiff_t redisplay_end_trigger_charpos;
2161 2161
2162 /* 1 means multibyte characters are enabled. */ 2162 /* 1 means multibyte characters are enabled. */
2163 unsigned multibyte_p : 1; 2163 unsigned multibyte_p : 1;
@@ -2226,13 +2226,13 @@ struct it
2226 2226
2227 /* Total number of overlay strings to process. This can be > 2227 /* Total number of overlay strings to process. This can be >
2228 OVERLAY_STRING_CHUNK_SIZE. */ 2228 OVERLAY_STRING_CHUNK_SIZE. */
2229 int n_overlay_strings; 2229 ptrdiff_t n_overlay_strings;
2230 2230
2231 /* The charpos where n_overlay_strings was calculated. This should 2231 /* The charpos where n_overlay_strings was calculated. This should
2232 be set at the same time as n_overlay_strings. It is needed 2232 be set at the same time as n_overlay_strings. It is needed
2233 because we show before-strings at the start of invisible text; 2233 because we show before-strings at the start of invisible text;
2234 see handle_invisible_prop in xdisp.c. */ 2234 see handle_invisible_prop in xdisp.c. */
2235 EMACS_INT overlay_strings_charpos; 2235 ptrdiff_t overlay_strings_charpos;
2236 2236
2237 /* Vector of overlays to process. Overlay strings are processed 2237 /* Vector of overlays to process. Overlay strings are processed
2238 OVERLAY_STRING_CHUNK_SIZE at a time. */ 2238 OVERLAY_STRING_CHUNK_SIZE at a time. */
@@ -2259,10 +2259,10 @@ struct it
2259 { 2259 {
2260 Lisp_Object string; 2260 Lisp_Object string;
2261 int string_nchars; 2261 int string_nchars;
2262 EMACS_INT end_charpos; 2262 ptrdiff_t end_charpos;
2263 EMACS_INT stop_charpos; 2263 ptrdiff_t stop_charpos;
2264 EMACS_INT prev_stop; 2264 ptrdiff_t prev_stop;
2265 EMACS_INT base_level_stop; 2265 ptrdiff_t base_level_stop;
2266 struct composition_it cmp_it; 2266 struct composition_it cmp_it;
2267 int face_id; 2267 int face_id;
2268 2268
@@ -2319,7 +2319,7 @@ struct it
2319 2319
2320 /* -1 means selective display hides everything between a \r and the 2320 /* -1 means selective display hides everything between a \r and the
2321 next newline; > 0 means hide lines indented more than that value. */ 2321 next newline; > 0 means hide lines indented more than that value. */
2322 EMACS_INT selective; 2322 ptrdiff_t selective;
2323 2323
2324 /* An enumeration describing what the next display element is 2324 /* An enumeration describing what the next display element is
2325 after a call to get_next_display_element. */ 2325 after a call to get_next_display_element. */
@@ -3017,7 +3017,7 @@ enum tool_bar_item_image
3017 3017
3018/* Defined in bidi.c */ 3018/* Defined in bidi.c */
3019 3019
3020extern void bidi_init_it (EMACS_INT, EMACS_INT, int, struct bidi_it *); 3020extern void bidi_init_it (ptrdiff_t, ptrdiff_t, int, struct bidi_it *);
3021extern void bidi_move_to_visually_next (struct bidi_it *); 3021extern void bidi_move_to_visually_next (struct bidi_it *);
3022extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, int); 3022extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, int);
3023extern int bidi_mirror_char (int); 3023extern int bidi_mirror_char (int);
@@ -3028,11 +3028,11 @@ extern void bidi_unshelve_cache (void *, int);
3028 3028
3029/* Defined in xdisp.c */ 3029/* Defined in xdisp.c */
3030 3030
3031struct glyph_row *row_containing_pos (struct window *, EMACS_INT, 3031struct glyph_row *row_containing_pos (struct window *, ptrdiff_t,
3032 struct glyph_row *, 3032 struct glyph_row *,
3033 struct glyph_row *, int); 3033 struct glyph_row *, int);
3034int line_bottom_y (struct it *); 3034int line_bottom_y (struct it *);
3035int display_prop_intangible_p (Lisp_Object, Lisp_Object, EMACS_INT, EMACS_INT); 3035int display_prop_intangible_p (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3036void resize_echo_area_exactly (void); 3036void resize_echo_area_exactly (void);
3037int resize_mini_window (struct window *, int); 3037int resize_mini_window (struct window *, int);
3038#if defined USE_TOOLKIT_SCROLL_BARS && !defined USE_GTK 3038#if defined USE_TOOLKIT_SCROLL_BARS && !defined USE_GTK
@@ -3054,18 +3054,18 @@ void remember_mouse_glyph (struct frame *, int, int, NativeRectangle *);
3054 3054
3055void mark_window_display_accurate (Lisp_Object, int); 3055void mark_window_display_accurate (Lisp_Object, int);
3056void redisplay_preserve_echo_area (int); 3056void redisplay_preserve_echo_area (int);
3057void init_iterator (struct it *, struct window *, EMACS_INT, 3057void init_iterator (struct it *, struct window *, ptrdiff_t,
3058 EMACS_INT, struct glyph_row *, enum face_id); 3058 ptrdiff_t, struct glyph_row *, enum face_id);
3059void init_iterator_to_row_start (struct it *, struct window *, 3059void init_iterator_to_row_start (struct it *, struct window *,
3060 struct glyph_row *); 3060 struct glyph_row *);
3061void start_display (struct it *, struct window *, struct text_pos); 3061void start_display (struct it *, struct window *, struct text_pos);
3062void move_it_to (struct it *, EMACS_INT, int, int, int, int); 3062void move_it_to (struct it *, ptrdiff_t, int, int, int, int);
3063void move_it_vertically (struct it *, int); 3063void move_it_vertically (struct it *, int);
3064void move_it_vertically_backward (struct it *, int); 3064void move_it_vertically_backward (struct it *, int);
3065void move_it_by_lines (struct it *, int); 3065void move_it_by_lines (struct it *, ptrdiff_t);
3066void move_it_past_eol (struct it *); 3066void move_it_past_eol (struct it *);
3067void move_it_in_display_line (struct it *it, 3067void move_it_in_display_line (struct it *it,
3068 EMACS_INT to_charpos, int to_x, 3068 ptrdiff_t to_charpos, int to_x,
3069 enum move_operation_enum op); 3069 enum move_operation_enum op);
3070int in_display_vector_p (struct it *); 3070int in_display_vector_p (struct it *);
3071int frame_mode_line_height (struct frame *); 3071int frame_mode_line_height (struct frame *);
@@ -3075,15 +3075,15 @@ extern int help_echo_showing_p;
3075extern int current_mode_line_height, current_header_line_height; 3075extern int current_mode_line_height, current_header_line_height;
3076extern Lisp_Object help_echo_string, help_echo_window; 3076extern Lisp_Object help_echo_string, help_echo_window;
3077extern Lisp_Object help_echo_object, previous_help_echo_string; 3077extern Lisp_Object help_echo_object, previous_help_echo_string;
3078extern EMACS_INT help_echo_pos; 3078extern ptrdiff_t help_echo_pos;
3079extern struct frame *last_mouse_frame; 3079extern struct frame *last_mouse_frame;
3080extern int last_tool_bar_item; 3080extern int last_tool_bar_item;
3081extern void reseat_at_previous_visible_line_start (struct it *); 3081extern void reseat_at_previous_visible_line_start (struct it *);
3082extern Lisp_Object lookup_glyphless_char_display (int, struct it *); 3082extern Lisp_Object lookup_glyphless_char_display (int, struct it *);
3083extern EMACS_INT compute_display_string_pos (struct text_pos *, 3083extern ptrdiff_t compute_display_string_pos (struct text_pos *,
3084 struct bidi_string_data *, 3084 struct bidi_string_data *,
3085 int, int *); 3085 int, int *);
3086extern EMACS_INT compute_display_string_end (EMACS_INT, 3086extern ptrdiff_t compute_display_string_end (ptrdiff_t,
3087 struct bidi_string_data *); 3087 struct bidi_string_data *);
3088extern void produce_stretch_glyph (struct it *); 3088extern void produce_stretch_glyph (struct it *);
3089 3089
@@ -3129,7 +3129,7 @@ extern void get_glyph_string_clip_rect (struct glyph_string *,
3129extern Lisp_Object find_hot_spot (Lisp_Object, int, int); 3129extern Lisp_Object find_hot_spot (Lisp_Object, int, int);
3130 3130
3131extern void handle_tool_bar_click (struct frame *, 3131extern void handle_tool_bar_click (struct frame *,
3132 int, int, int, unsigned int); 3132 int, int, int, int);
3133 3133
3134extern void expose_frame (struct frame *, int, int, int, int); 3134extern void expose_frame (struct frame *, int, int, int, int);
3135extern int x_intersect_rectangles (XRectangle *, XRectangle *, 3135extern int x_intersect_rectangles (XRectangle *, XRectangle *,
@@ -3235,19 +3235,19 @@ int lookup_derived_face (struct frame *, Lisp_Object, int, int);
3235void init_frame_faces (struct frame *); 3235void init_frame_faces (struct frame *);
3236void free_frame_faces (struct frame *); 3236void free_frame_faces (struct frame *);
3237void recompute_basic_faces (struct frame *); 3237void recompute_basic_faces (struct frame *);
3238int face_at_buffer_position (struct window *w, EMACS_INT pos, 3238int face_at_buffer_position (struct window *w, ptrdiff_t pos,
3239 EMACS_INT region_beg, EMACS_INT region_end, 3239 ptrdiff_t region_beg, ptrdiff_t region_end,
3240 EMACS_INT *endptr, EMACS_INT limit, 3240 ptrdiff_t *endptr, ptrdiff_t limit,
3241 int mouse, int base_face_id); 3241 int mouse, int base_face_id);
3242int face_for_overlay_string (struct window *w, EMACS_INT pos, 3242int face_for_overlay_string (struct window *w, ptrdiff_t pos,
3243 EMACS_INT region_beg, EMACS_INT region_end, 3243 ptrdiff_t region_beg, ptrdiff_t region_end,
3244 EMACS_INT *endptr, EMACS_INT limit, 3244 ptrdiff_t *endptr, ptrdiff_t limit,
3245 int mouse, Lisp_Object overlay); 3245 int mouse, Lisp_Object overlay);
3246int face_at_string_position (struct window *w, Lisp_Object string, 3246int face_at_string_position (struct window *w, Lisp_Object string,
3247 EMACS_INT pos, EMACS_INT bufpos, 3247 ptrdiff_t pos, ptrdiff_t bufpos,
3248 EMACS_INT region_beg, EMACS_INT region_end, 3248 ptrdiff_t region_beg, ptrdiff_t region_end,
3249 EMACS_INT *endptr, enum face_id, int mouse); 3249 ptrdiff_t *endptr, enum face_id, int mouse);
3250int merge_faces (struct frame *, Lisp_Object, EMACS_INT, int); 3250int merge_faces (struct frame *, Lisp_Object, int, int);
3251int compute_char_face (struct frame *, int, Lisp_Object); 3251int compute_char_face (struct frame *, int, Lisp_Object);
3252void free_all_realized_faces (Lisp_Object); 3252void free_all_realized_faces (Lisp_Object);
3253extern Lisp_Object Qforeground_color, Qbackground_color; 3253extern Lisp_Object Qforeground_color, Qbackground_color;
@@ -3312,11 +3312,11 @@ extern Lisp_Object buffer_posn_from_coords (struct window *,
3312 Lisp_Object *, 3312 Lisp_Object *,
3313 int *, int *, int *, int *); 3313 int *, int *, int *, int *);
3314extern Lisp_Object mode_line_string (struct window *, enum window_part, 3314extern Lisp_Object mode_line_string (struct window *, enum window_part,
3315 int *, int *, EMACS_INT *, 3315 int *, int *, ptrdiff_t *,
3316 Lisp_Object *, 3316 Lisp_Object *,
3317 int *, int *, int *, int *); 3317 int *, int *, int *, int *);
3318extern Lisp_Object marginal_area_string (struct window *, enum window_part, 3318extern Lisp_Object marginal_area_string (struct window *, enum window_part,
3319 int *, int *, EMACS_INT *, 3319 int *, int *, ptrdiff_t *,
3320 Lisp_Object *, 3320 Lisp_Object *,
3321 int *, int *, int *, int *); 3321 int *, int *, int *, int *);
3322extern void redraw_frame (struct frame *); 3322extern void redraw_frame (struct frame *);
@@ -3336,7 +3336,7 @@ void shift_glyph_matrix (struct window *, struct glyph_matrix *,
3336 int, int, int); 3336 int, int, int);
3337void rotate_matrix (struct glyph_matrix *, int, int, int); 3337void rotate_matrix (struct glyph_matrix *, int, int, int);
3338void increment_matrix_positions (struct glyph_matrix *, 3338void increment_matrix_positions (struct glyph_matrix *,
3339 int, int, EMACS_INT, EMACS_INT); 3339 int, int, ptrdiff_t, ptrdiff_t);
3340void blank_row (struct window *, struct glyph_row *, int); 3340void blank_row (struct window *, struct glyph_row *, int);
3341void enable_glyph_matrix_rows (struct glyph_matrix *, int, int, int); 3341void enable_glyph_matrix_rows (struct glyph_matrix *, int, int, int);
3342void clear_glyph_row (struct glyph_row *); 3342void clear_glyph_row (struct glyph_row *);
diff --git a/src/dispnew.c b/src/dispnew.c
index 73c58ceded8..35ccd95e92a 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -114,7 +114,7 @@ static int required_matrix_height (struct window *);
114static int required_matrix_width (struct window *); 114static int required_matrix_width (struct window *);
115static void adjust_frame_glyphs (struct frame *); 115static void adjust_frame_glyphs (struct frame *);
116static void change_frame_size_1 (struct frame *, int, int, int, int, int); 116static void change_frame_size_1 (struct frame *, int, int, int, int, int);
117static void increment_row_positions (struct glyph_row *, EMACS_INT, EMACS_INT); 117static void increment_row_positions (struct glyph_row *, ptrdiff_t, ptrdiff_t);
118static void fill_up_frame_row_with_spaces (struct glyph_row *, int); 118static void fill_up_frame_row_with_spaces (struct glyph_row *, int);
119static void build_frame_matrix_from_window_tree (struct glyph_matrix *, 119static void build_frame_matrix_from_window_tree (struct glyph_matrix *,
120 struct window *); 120 struct window *);
@@ -763,7 +763,7 @@ rotate_matrix (struct glyph_matrix *matrix, int first, int last, int by)
763 763
764void 764void
765increment_matrix_positions (struct glyph_matrix *matrix, int start, int end, 765increment_matrix_positions (struct glyph_matrix *matrix, int start, int end,
766 EMACS_INT delta, EMACS_INT delta_bytes) 766 ptrdiff_t delta, ptrdiff_t delta_bytes)
767{ 767{
768 /* Check that START and END are reasonable values. */ 768 /* Check that START and END are reasonable values. */
769 xassert (start >= 0 && start <= matrix->nrows); 769 xassert (start >= 0 && start <= matrix->nrows);
@@ -1005,7 +1005,7 @@ blank_row (struct window *w, struct glyph_row *row, int y)
1005 1005
1006static void 1006static void
1007increment_row_positions (struct glyph_row *row, 1007increment_row_positions (struct glyph_row *row,
1008 EMACS_INT delta, EMACS_INT delta_bytes) 1008 ptrdiff_t delta, ptrdiff_t delta_bytes)
1009{ 1009{
1010 int area, i; 1010 int area, i;
1011 1011
@@ -2551,8 +2551,7 @@ build_frame_matrix_from_leaf_window (struct glyph_matrix *frame_matrix, struct w
2551 2551
2552 SET_GLYPH_FROM_CHAR (right_border_glyph, '|'); 2552 SET_GLYPH_FROM_CHAR (right_border_glyph, '|');
2553 if (dp 2553 if (dp
2554 && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc)) 2554 && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc)))
2555 && GLYPH_CODE_CHAR_VALID_P (gc))
2556 { 2555 {
2557 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc); 2556 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc);
2558 spec_glyph_lookup_face (w, &right_border_glyph); 2557 spec_glyph_lookup_face (w, &right_border_glyph);
@@ -5492,7 +5491,7 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p
5492 5491
5493Lisp_Object 5492Lisp_Object
5494mode_line_string (struct window *w, enum window_part part, 5493mode_line_string (struct window *w, enum window_part part,
5495 int *x, int *y, EMACS_INT *charpos, Lisp_Object *object, 5494 int *x, int *y, ptrdiff_t *charpos, Lisp_Object *object,
5496 int *dx, int *dy, int *width, int *height) 5495 int *dx, int *dy, int *width, int *height)
5497{ 5496{
5498 struct glyph_row *row; 5497 struct glyph_row *row;
@@ -5561,7 +5560,7 @@ mode_line_string (struct window *w, enum window_part part,
5561 5560
5562Lisp_Object 5561Lisp_Object
5563marginal_area_string (struct window *w, enum window_part part, 5562marginal_area_string (struct window *w, enum window_part part,
5564 int *x, int *y, EMACS_INT *charpos, Lisp_Object *object, 5563 int *x, int *y, ptrdiff_t *charpos, Lisp_Object *object,
5565 int *dx, int *dy, int *width, int *height) 5564 int *dx, int *dy, int *width, int *height)
5566{ 5565{
5567 struct glyph_row *row = w->current_matrix->rows; 5566 struct glyph_row *row = w->current_matrix->rows;
@@ -5758,7 +5757,7 @@ static void
5758change_frame_size_1 (register struct frame *f, int newheight, int newwidth, int pretend, int delay, int safe) 5757change_frame_size_1 (register struct frame *f, int newheight, int newwidth, int pretend, int delay, int safe)
5759{ 5758{
5760 int new_frame_total_cols; 5759 int new_frame_total_cols;
5761 int count = SPECPDL_INDEX (); 5760 ptrdiff_t count = SPECPDL_INDEX ();
5762 5761
5763 /* If we can't deal with the change now, queue it for later. */ 5762 /* If we can't deal with the change now, queue it for later. */
5764 if (delay || (redisplaying_p && !safe)) 5763 if (delay || (redisplaying_p && !safe))
@@ -5979,6 +5978,38 @@ bitch_at_user (void)
5979 Sleeping, Waiting 5978 Sleeping, Waiting
5980 ***********************************************************************/ 5979 ***********************************************************************/
5981 5980
5981/* Convert a positive value DURATION to a seconds count *PSEC plus a
5982 microseconds count *PUSEC, rounding up. On overflow return the
5983 maximal value. */
5984void
5985duration_to_sec_usec (double duration, int *psec, int *pusec)
5986{
5987 int MILLION = 1000000;
5988 int sec = INT_MAX, usec = MILLION - 1;
5989
5990 if (duration < INT_MAX + 1.0)
5991 {
5992 int s = duration;
5993 double usdouble = (duration - s) * MILLION;
5994 int usfloor = usdouble;
5995 int usceil = usfloor + (usfloor < usdouble);
5996
5997 if (usceil < MILLION)
5998 {
5999 sec = s;
6000 usec = usceil;
6001 }
6002 else if (sec < INT_MAX)
6003 {
6004 sec = s + 1;
6005 usec = 0;
6006 }
6007 }
6008
6009 *psec = sec;
6010 *pusec = usec;
6011}
6012
5982DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0, 6013DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
5983 doc: /* Pause, without updating display, for SECONDS seconds. 6014 doc: /* Pause, without updating display, for SECONDS seconds.
5984SECONDS may be a floating-point value, meaning that you can wait for a 6015SECONDS may be a floating-point value, meaning that you can wait for a
@@ -5989,39 +6020,24 @@ Emacs was built without floating point support.
5989 (Lisp_Object seconds, Lisp_Object milliseconds) 6020 (Lisp_Object seconds, Lisp_Object milliseconds)
5990{ 6021{
5991 int sec, usec; 6022 int sec, usec;
6023 double duration = extract_float (seconds);
5992 6024
5993 if (NILP (milliseconds)) 6025 if (!NILP (milliseconds))
5994 XSETINT (milliseconds, 0); 6026 {
5995 else 6027 CHECK_NUMBER (milliseconds);
5996 CHECK_NUMBER (milliseconds); 6028 duration += XINT (milliseconds) / 1000.0;
5997 usec = XINT (milliseconds) * 1000; 6029 }
5998 6030
5999 { 6031 if (! (0 < duration))
6000 double duration = extract_float (seconds); 6032 return Qnil;
6001 sec = (int) duration; 6033
6002 usec += (duration - sec) * 1000000; 6034 duration_to_sec_usec (duration, &sec, &usec);
6003 }
6004 6035
6005#ifndef EMACS_HAS_USECS 6036#ifndef EMACS_HAS_USECS
6006 if (sec == 0 && usec != 0) 6037 if (sec == 0 && usec != 0)
6007 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE); 6038 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE);
6008#endif 6039#endif
6009 6040
6010 /* Assure that 0 <= usec < 1000000. */
6011 if (usec < 0)
6012 {
6013 /* We can't rely on the rounding being correct if usec is negative. */
6014 if (-1000000 < usec)
6015 sec--, usec += 1000000;
6016 else
6017 sec -= -usec / 1000000, usec = 1000000 - (-usec % 1000000);
6018 }
6019 else
6020 sec += usec / 1000000, usec %= 1000000;
6021
6022 if (sec < 0 || (sec == 0 && usec == 0))
6023 return Qnil;
6024
6025 wait_reading_process_output (sec, usec, 0, 0, Qnil, NULL, 0); 6041 wait_reading_process_output (sec, usec, 0, 0, Qnil, NULL, 0);
6026 6042
6027 return Qnil; 6043 return Qnil;
@@ -6052,27 +6068,20 @@ sit_for (Lisp_Object timeout, int reading, int do_display)
6052 if (do_display >= 2) 6068 if (do_display >= 2)
6053 redisplay_preserve_echo_area (2); 6069 redisplay_preserve_echo_area (2);
6054 6070
6055 if (INTEGERP (timeout)) 6071 if (EQ (timeout, Qt))
6056 {
6057 sec = XINT (timeout);
6058 usec = 0;
6059 }
6060 else if (FLOATP (timeout))
6061 {
6062 double seconds = XFLOAT_DATA (timeout);
6063 sec = (int) seconds;
6064 usec = (int) ((seconds - sec) * 1000000);
6065 }
6066 else if (EQ (timeout, Qt))
6067 { 6072 {
6068 sec = 0; 6073 sec = 0;
6069 usec = 0; 6074 usec = 0;
6070 } 6075 }
6071 else 6076 else
6072 wrong_type_argument (Qnumberp, timeout); 6077 {
6078 double duration = extract_float (timeout);
6073 6079
6074 if (sec == 0 && usec == 0 && !EQ (timeout, Qt)) 6080 if (! (0 < duration))
6075 return Qt; 6081 return Qt;
6082
6083 duration_to_sec_usec (duration, &sec, &usec);
6084 }
6076 6085
6077#ifdef SIGIO 6086#ifdef SIGIO
6078 gobble_input (0); 6087 gobble_input (0);
@@ -6096,7 +6105,7 @@ Return t if redisplay was performed, nil if redisplay was preempted
6096immediately by pending input. */) 6105immediately by pending input. */)
6097 (Lisp_Object force) 6106 (Lisp_Object force)
6098{ 6107{
6099 int count; 6108 ptrdiff_t count;
6100 6109
6101 swallow_events (1); 6110 swallow_events (1);
6102 if ((detect_input_pending_run_timers (1) 6111 if ((detect_input_pending_run_timers (1)
@@ -6142,7 +6151,7 @@ pass nil for VARIABLE. */)
6142{ 6151{
6143 Lisp_Object state, tail, frame, buf; 6152 Lisp_Object state, tail, frame, buf;
6144 Lisp_Object *vecp, *end; 6153 Lisp_Object *vecp, *end;
6145 int n; 6154 ptrdiff_t n;
6146 6155
6147 if (! NILP (variable)) 6156 if (! NILP (variable))
6148 { 6157 {
diff --git a/src/doc.c b/src/doc.c
index 9e48a4d49f3..bec20fb0d94 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -86,9 +86,11 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
86 register int fd; 86 register int fd;
87 register char *name; 87 register char *name;
88 register char *p, *p1; 88 register char *p, *p1;
89 EMACS_INT minsize; 89 ptrdiff_t minsize;
90 EMACS_INT offset, position; 90 int offset;
91 EMACS_INT position;
91 Lisp_Object file, tem; 92 Lisp_Object file, tem;
93 USE_SAFE_ALLOCA;
92 94
93 if (INTEGERP (filepos)) 95 if (INTEGERP (filepos))
94 { 96 {
@@ -124,7 +126,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
124 /* sizeof ("../etc/") == 8 */ 126 /* sizeof ("../etc/") == 8 */
125 if (minsize < 8) 127 if (minsize < 8)
126 minsize = 8; 128 minsize = 8;
127 name = (char *) alloca (minsize + SCHARS (file) + 8); 129 SAFE_ALLOCA (name, char *, minsize + SCHARS (file) + 8);
128 strcpy (name, SSDATA (docdir)); 130 strcpy (name, SSDATA (docdir));
129 strcat (name, SSDATA (file)); 131 strcat (name, SSDATA (file));
130 } 132 }
@@ -155,13 +157,16 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
155 /* Make sure we read at least 1024 bytes before `position' 157 /* Make sure we read at least 1024 bytes before `position'
156 so we can check the leading text for consistency. */ 158 so we can check the leading text for consistency. */
157 offset = min (position, max (1024, position % (8 * 1024))); 159 offset = min (position, max (1024, position % (8 * 1024)));
158 if (0 > lseek (fd, position - offset, 0)) 160 if (TYPE_MAXIMUM (off_t) < position
161 || lseek (fd, position - offset, 0) < 0)
159 { 162 {
160 emacs_close (fd); 163 emacs_close (fd);
161 error ("Position %"pI"d out of range in doc string file \"%s\"", 164 error ("Position %"pI"d out of range in doc string file \"%s\"",
162 position, name); 165 position, name);
163 } 166 }
164 167
168 SAFE_FREE ();
169
165 /* Read the doc string into get_doc_string_buffer. 170 /* Read the doc string into get_doc_string_buffer.
166 P points beyond the data just read. */ 171 P points beyond the data just read. */
167 172
@@ -279,7 +284,7 @@ Invalid data in documentation file -- %c followed by code %03o",
279 else 284 else
280 { 285 {
281 /* The data determines whether the string is multibyte. */ 286 /* The data determines whether the string is multibyte. */
282 EMACS_INT nchars = 287 ptrdiff_t nchars =
283 multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer 288 multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer
284 + offset), 289 + offset),
285 to - (get_doc_string_buffer + offset)); 290 to - (get_doc_string_buffer + offset));
@@ -502,8 +507,7 @@ aren't strings. */)
502/* Scanning the DOC files and placing docstring offsets into functions. */ 507/* Scanning the DOC files and placing docstring offsets into functions. */
503 508
504static void 509static void
505store_function_docstring (Lisp_Object obj, EMACS_INT offset) 510store_function_docstring (Lisp_Object obj, ptrdiff_t offset)
506/* Use EMACS_INT because we get offset from pointer subtraction. */
507{ 511{
508 /* Don't use indirect_function here, or defaliases will apply their 512 /* Don't use indirect_function here, or defaliases will apply their
509 docstrings to the base functions (Bug#2603). */ 513 docstrings to the base functions (Bug#2603). */
@@ -560,7 +564,7 @@ the same file name is found in the `doc-directory'. */)
560{ 564{
561 int fd; 565 int fd;
562 char buf[1024 + 1]; 566 char buf[1024 + 1];
563 register EMACS_INT filled; 567 register int filled;
564 register EMACS_INT pos; 568 register EMACS_INT pos;
565 register char *p; 569 register char *p;
566 Lisp_Object sym; 570 Lisp_Object sym;
@@ -595,7 +599,7 @@ the same file name is found in the `doc-directory'. */)
595 599
596 for (beg = buildobj; *beg; beg = end) 600 for (beg = buildobj; *beg; beg = end)
597 { 601 {
598 EMACS_INT len; 602 ptrdiff_t len;
599 603
600 while (*beg && isspace (*beg)) ++beg; 604 while (*beg && isspace (*beg)) ++beg;
601 605
@@ -643,7 +647,7 @@ the same file name is found in the `doc-directory'. */)
643 if (end - p > 4 && end[-2] == '.' 647 if (end - p > 4 && end[-2] == '.'
644 && (end[-1] == 'o' || end[-1] == 'c')) 648 && (end[-1] == 'o' || end[-1] == 'c'))
645 { 649 {
646 EMACS_INT len = end - p - 2; 650 ptrdiff_t len = end - p - 2;
647 char *fromfile = alloca (len + 1); 651 char *fromfile = alloca (len + 1);
648 strncpy (fromfile, &p[2], len); 652 strncpy (fromfile, &p[2], len);
649 fromfile[len] = 0; 653 fromfile[len] = 0;
diff --git a/src/doprnt.c b/src/doprnt.c
index b8eb0f07199..df9ebc11f9c 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -174,7 +174,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
174 if (*fmt == '%') /* Check for a '%' character */ 174 if (*fmt == '%') /* Check for a '%' character */
175 { 175 {
176 ptrdiff_t size_bound = 0; 176 ptrdiff_t size_bound = 0;
177 EMACS_INT width; /* Columns occupied by STRING on display. */ 177 ptrdiff_t width; /* Columns occupied by STRING on display. */
178 enum { 178 enum {
179 pDlen = sizeof pD - 1, 179 pDlen = sizeof pD - 1,
180 pIlen = sizeof pI - 1, 180 pIlen = sizeof pI - 1,
diff --git a/src/editfns.c b/src/editfns.c
index c5ba280c178..8f7b2aee76c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -77,7 +77,7 @@ static void time_overflow (void) NO_RETURN;
77static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object, 77static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object,
78 int, time_t *, struct tm *); 78 int, time_t *, struct tm *);
79static int tm_diff (struct tm *, struct tm *); 79static int tm_diff (struct tm *, struct tm *);
80static void update_buffer_properties (EMACS_INT, EMACS_INT); 80static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
81 81
82static Lisp_Object Qbuffer_access_fontify_functions; 82static Lisp_Object Qbuffer_access_fontify_functions;
83static Lisp_Object Fuser_full_name (Lisp_Object); 83static Lisp_Object Fuser_full_name (Lisp_Object);
@@ -137,8 +137,14 @@ init_editfns (void)
137 /* If the user name claimed in the environment vars differs from 137 /* If the user name claimed in the environment vars differs from
138 the real uid, use the claimed name to find the full name. */ 138 the real uid, use the claimed name to find the full name. */
139 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); 139 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
140 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid ()) 140 if (! NILP (tem))
141 : Vuser_login_name); 141 tem = Vuser_login_name;
142 else
143 {
144 uid_t euid = geteuid ();
145 tem = make_fixnum_or_float (euid);
146 }
147 Vuser_full_name = Fuser_full_name (tem);
142 148
143 p = getenv ("NAME"); 149 p = getenv ("NAME");
144 if (p) 150 if (p)
@@ -203,7 +209,7 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
203} 209}
204 210
205static Lisp_Object 211static Lisp_Object
206buildmark (EMACS_INT charpos, EMACS_INT bytepos) 212buildmark (ptrdiff_t charpos, ptrdiff_t bytepos)
207{ 213{
208 register Lisp_Object mark; 214 register Lisp_Object mark;
209 mark = Fmake_marker (); 215 mark = Fmake_marker ();
@@ -228,17 +234,6 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
228 return buildmark (PT, PT_BYTE); 234 return buildmark (PT, PT_BYTE);
229} 235}
230 236
231EMACS_INT
232clip_to_bounds (EMACS_INT lower, EMACS_INT num, EMACS_INT upper)
233{
234 if (num < lower)
235 return lower;
236 else if (num > upper)
237 return upper;
238 else
239 return num;
240}
241
242DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", 237DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
243 doc: /* Set point to POSITION, a number or marker. 238 doc: /* Set point to POSITION, a number or marker.
244Beginning of buffer is position (point-min), end is (point-max). 239Beginning of buffer is position (point-min), end is (point-max).
@@ -246,7 +241,7 @@ Beginning of buffer is position (point-min), end is (point-max).
246The return value is POSITION. */) 241The return value is POSITION. */)
247 (register Lisp_Object position) 242 (register Lisp_Object position)
248{ 243{
249 EMACS_INT pos; 244 ptrdiff_t pos;
250 245
251 if (MARKERP (position) 246 if (MARKERP (position)
252 && current_buffer == XMARKER (position)->buffer) 247 && current_buffer == XMARKER (position)->buffer)
@@ -326,7 +321,7 @@ overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
326{ 321{
327 Lisp_Object overlay, start, end; 322 Lisp_Object overlay, start, end;
328 struct Lisp_Overlay *tail; 323 struct Lisp_Overlay *tail;
329 EMACS_INT startpos, endpos; 324 ptrdiff_t startpos, endpos;
330 ptrdiff_t idx = 0; 325 ptrdiff_t idx = 0;
331 326
332 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 327 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
@@ -475,7 +470,7 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
475static void 470static void
476find_field (Lisp_Object pos, Lisp_Object merge_at_boundary, 471find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
477 Lisp_Object beg_limit, 472 Lisp_Object beg_limit,
478 EMACS_INT *beg, Lisp_Object end_limit, EMACS_INT *end) 473 ptrdiff_t *beg, Lisp_Object end_limit, ptrdiff_t *end)
479{ 474{
480 /* Fields right before and after the point. */ 475 /* Fields right before and after the point. */
481 Lisp_Object before_field, after_field; 476 Lisp_Object before_field, after_field;
@@ -591,7 +586,7 @@ A field is a region of text with the same `field' property.
591If POS is nil, the value of point is used for POS. */) 586If POS is nil, the value of point is used for POS. */)
592 (Lisp_Object pos) 587 (Lisp_Object pos)
593{ 588{
594 EMACS_INT beg, end; 589 ptrdiff_t beg, end;
595 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 590 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
596 if (beg != end) 591 if (beg != end)
597 del_range (beg, end); 592 del_range (beg, end);
@@ -604,7 +599,7 @@ A field is a region of text with the same `field' property.
604If POS is nil, the value of point is used for POS. */) 599If POS is nil, the value of point is used for POS. */)
605 (Lisp_Object pos) 600 (Lisp_Object pos)
606{ 601{
607 EMACS_INT beg, end; 602 ptrdiff_t beg, end;
608 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 603 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
609 return make_buffer_string (beg, end, 1); 604 return make_buffer_string (beg, end, 1);
610} 605}
@@ -615,7 +610,7 @@ A field is a region of text with the same `field' property.
615If POS is nil, the value of point is used for POS. */) 610If POS is nil, the value of point is used for POS. */)
616 (Lisp_Object pos) 611 (Lisp_Object pos)
617{ 612{
618 EMACS_INT beg, end; 613 ptrdiff_t beg, end;
619 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 614 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
620 return make_buffer_string (beg, end, 0); 615 return make_buffer_string (beg, end, 0);
621} 616}
@@ -630,7 +625,7 @@ If LIMIT is non-nil, it is a buffer position; if the beginning of the field
630is before LIMIT, then LIMIT will be returned instead. */) 625is before LIMIT, then LIMIT will be returned instead. */)
631 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 626 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
632{ 627{
633 EMACS_INT beg; 628 ptrdiff_t beg;
634 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0); 629 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0);
635 return make_number (beg); 630 return make_number (beg);
636} 631}
@@ -645,7 +640,7 @@ If LIMIT is non-nil, it is a buffer position; if the end of the field
645is after LIMIT, then LIMIT will be returned instead. */) 640is after LIMIT, then LIMIT will be returned instead. */)
646 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 641 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
647{ 642{
648 EMACS_INT end; 643 ptrdiff_t end;
649 find_field (pos, escape_from_edge, Qnil, 0, limit, &end); 644 find_field (pos, escape_from_edge, Qnil, 0, limit, &end);
650 return make_number (end); 645 return make_number (end);
651} 646}
@@ -681,7 +676,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
681 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property) 676 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property)
682{ 677{
683 /* If non-zero, then the original point, before re-positioning. */ 678 /* If non-zero, then the original point, before re-positioning. */
684 EMACS_INT orig_point = 0; 679 ptrdiff_t orig_point = 0;
685 int fwd; 680 int fwd;
686 Lisp_Object prev_old, prev_new; 681 Lisp_Object prev_old, prev_new;
687 682
@@ -695,10 +690,10 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
695 CHECK_NUMBER_COERCE_MARKER (new_pos); 690 CHECK_NUMBER_COERCE_MARKER (new_pos);
696 CHECK_NUMBER_COERCE_MARKER (old_pos); 691 CHECK_NUMBER_COERCE_MARKER (old_pos);
697 692
698 fwd = (XFASTINT (new_pos) > XFASTINT (old_pos)); 693 fwd = (XINT (new_pos) > XINT (old_pos));
699 694
700 prev_old = make_number (XFASTINT (old_pos) - 1); 695 prev_old = make_number (XINT (old_pos) - 1);
701 prev_new = make_number (XFASTINT (new_pos) - 1); 696 prev_new = make_number (XINT (new_pos) - 1);
702 697
703 if (NILP (Vinhibit_field_text_motion) 698 if (NILP (Vinhibit_field_text_motion)
704 && !EQ (new_pos, old_pos) 699 && !EQ (new_pos, old_pos)
@@ -723,7 +718,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
723 /* It is possible that NEW_POS is not within the same field as 718 /* It is possible that NEW_POS is not within the same field as
724 OLD_POS; try to move NEW_POS so that it is. */ 719 OLD_POS; try to move NEW_POS so that it is. */
725 { 720 {
726 EMACS_INT shortage; 721 ptrdiff_t shortage;
727 Lisp_Object field_bound; 722 Lisp_Object field_bound;
728 723
729 if (fwd) 724 if (fwd)
@@ -778,8 +773,8 @@ boundaries bind `inhibit-field-text-motion' to t.
778This function does not move point. */) 773This function does not move point. */)
779 (Lisp_Object n) 774 (Lisp_Object n)
780{ 775{
781 EMACS_INT orig, orig_byte, end; 776 ptrdiff_t orig, orig_byte, end;
782 int count = SPECPDL_INDEX (); 777 ptrdiff_t count = SPECPDL_INDEX ();
783 specbind (Qinhibit_point_motion_hooks, Qt); 778 specbind (Qinhibit_point_motion_hooks, Qt);
784 779
785 if (NILP (n)) 780 if (NILP (n))
@@ -819,15 +814,17 @@ boundaries bind `inhibit-field-text-motion' to t.
819This function does not move point. */) 814This function does not move point. */)
820 (Lisp_Object n) 815 (Lisp_Object n)
821{ 816{
822 EMACS_INT end_pos; 817 ptrdiff_t clipped_n;
823 EMACS_INT orig = PT; 818 ptrdiff_t end_pos;
819 ptrdiff_t orig = PT;
824 820
825 if (NILP (n)) 821 if (NILP (n))
826 XSETFASTINT (n, 1); 822 XSETFASTINT (n, 1);
827 else 823 else
828 CHECK_NUMBER (n); 824 CHECK_NUMBER (n);
829 825
830 end_pos = find_before_next_newline (orig, 0, XINT (n) - (XINT (n) <= 0)); 826 clipped_n = clip_to_bounds (PTRDIFF_MIN + 1, XINT (n), PTRDIFF_MAX);
827 end_pos = find_before_next_newline (orig, 0, clipped_n - (clipped_n <= 0));
831 828
832 /* Return END_POS constrained to the current input field. */ 829 /* Return END_POS constrained to the current input field. */
833 return Fconstrain_to_field (make_number (end_pos), make_number (orig), 830 return Fconstrain_to_field (make_number (end_pos), make_number (orig),
@@ -954,7 +951,7 @@ usage: (save-excursion &rest BODY) */)
954 (Lisp_Object args) 951 (Lisp_Object args)
955{ 952{
956 register Lisp_Object val; 953 register Lisp_Object val;
957 int count = SPECPDL_INDEX (); 954 ptrdiff_t count = SPECPDL_INDEX ();
958 955
959 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 956 record_unwind_protect (save_excursion_restore, save_excursion_save ());
960 957
@@ -969,7 +966,7 @@ usage: (save-current-buffer &rest BODY) */)
969 (Lisp_Object args) 966 (Lisp_Object args)
970{ 967{
971 Lisp_Object val; 968 Lisp_Object val;
972 int count = SPECPDL_INDEX (); 969 ptrdiff_t count = SPECPDL_INDEX ();
973 970
974 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); 971 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
975 972
@@ -1095,7 +1092,7 @@ At the beginning of the buffer or accessible region, return 0. */)
1095 XSETFASTINT (temp, 0); 1092 XSETFASTINT (temp, 0);
1096 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 1093 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1097 { 1094 {
1098 EMACS_INT pos = PT_BYTE; 1095 ptrdiff_t pos = PT_BYTE;
1099 DEC_POS (pos); 1096 DEC_POS (pos);
1100 XSETFASTINT (temp, FETCH_CHAR (pos)); 1097 XSETFASTINT (temp, FETCH_CHAR (pos));
1101 } 1098 }
@@ -1149,7 +1146,7 @@ POS is an integer or a marker and defaults to point.
1149If POS is out of range, the value is nil. */) 1146If POS is out of range, the value is nil. */)
1150 (Lisp_Object pos) 1147 (Lisp_Object pos)
1151{ 1148{
1152 register EMACS_INT pos_byte; 1149 register ptrdiff_t pos_byte;
1153 1150
1154 if (NILP (pos)) 1151 if (NILP (pos))
1155 { 1152 {
@@ -1182,7 +1179,7 @@ If POS is out of range, the value is nil. */)
1182 (Lisp_Object pos) 1179 (Lisp_Object pos)
1183{ 1180{
1184 register Lisp_Object val; 1181 register Lisp_Object val;
1185 register EMACS_INT pos_byte; 1182 register ptrdiff_t pos_byte;
1186 1183
1187 if (NILP (pos)) 1184 if (NILP (pos))
1188 { 1185 {
@@ -1242,7 +1239,7 @@ of the user with that uid, or nil if there is no such user. */)
1242 if (NILP (uid)) 1239 if (NILP (uid))
1243 return Vuser_login_name; 1240 return Vuser_login_name;
1244 1241
1245 id = XFLOATINT (uid); 1242 CONS_TO_INTEGER (uid, uid_t, id);
1246 BLOCK_INPUT; 1243 BLOCK_INPUT;
1247 pw = getpwuid (id); 1244 pw = getpwuid (id);
1248 UNBLOCK_INPUT; 1245 UNBLOCK_INPUT;
@@ -1269,14 +1266,7 @@ DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
1269Value is an integer or a float, depending on the value. */) 1266Value is an integer or a float, depending on the value. */)
1270 (void) 1267 (void)
1271{ 1268{
1272 /* Assignment to EMACS_INT stops GCC whining about limited range of 1269 uid_t euid = geteuid ();
1273 data type. */
1274 EMACS_INT euid = geteuid ();
1275
1276 /* Make sure we don't produce a negative UID due to signed integer
1277 overflow. */
1278 if (euid < 0)
1279 return make_float (geteuid ());
1280 return make_fixnum_or_float (euid); 1270 return make_fixnum_or_float (euid);
1281} 1271}
1282 1272
@@ -1285,14 +1275,7 @@ DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
1285Value is an integer or a float, depending on the value. */) 1275Value is an integer or a float, depending on the value. */)
1286 (void) 1276 (void)
1287{ 1277{
1288 /* Assignment to EMACS_INT stops GCC whining about limited range of 1278 uid_t uid = getuid ();
1289 data type. */
1290 EMACS_INT uid = getuid ();
1291
1292 /* Make sure we don't produce a negative UID due to signed integer
1293 overflow. */
1294 if (uid < 0)
1295 return make_float (getuid ());
1296 return make_fixnum_or_float (uid); 1279 return make_fixnum_or_float (uid);
1297} 1280}
1298 1281
@@ -1315,7 +1298,8 @@ name, or nil if there is no such user. */)
1315 return Vuser_full_name; 1298 return Vuser_full_name;
1316 else if (NUMBERP (uid)) 1299 else if (NUMBERP (uid))
1317 { 1300 {
1318 uid_t u = XFLOATINT (uid); 1301 uid_t u;
1302 CONS_TO_INTEGER (uid, uid_t, u);
1319 BLOCK_INPUT; 1303 BLOCK_INPUT;
1320 pw = getpwuid (u); 1304 pw = getpwuid (u);
1321 UNBLOCK_INPUT; 1305 UNBLOCK_INPUT;
@@ -1377,10 +1361,11 @@ get_system_name (void)
1377} 1361}
1378 1362
1379DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0, 1363DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
1380 doc: /* Return the process ID of Emacs, as an integer. */) 1364 doc: /* Return the process ID of Emacs, as a number. */)
1381 (void) 1365 (void)
1382{ 1366{
1383 return make_number (getpid ()); 1367 pid_t pid = getpid ();
1368 return make_fixnum_or_float (pid);
1384} 1369}
1385 1370
1386 1371
@@ -1420,7 +1405,7 @@ hi_time (time_t t)
1420} 1405}
1421 1406
1422/* Return the bottom 16 bits of the time T. */ 1407/* Return the bottom 16 bits of the time T. */
1423static EMACS_INT 1408static int
1424lo_time (time_t t) 1409lo_time (time_t t)
1425{ 1410{
1426 return t & ((1 << 16) - 1); 1411 return t & ((1 << 16) - 1);
@@ -1538,6 +1523,8 @@ lisp_time_argument (Lisp_Object specified_time, time_t *result, int *usec)
1538 else 1523 else
1539 { 1524 {
1540 CHECK_NUMBER (usec_l); 1525 CHECK_NUMBER (usec_l);
1526 if (! (0 <= XINT (usec_l) && XINT (usec_l) < 1000000))
1527 return 0;
1541 *usec = XINT (usec_l); 1528 *usec = XINT (usec_l);
1542 } 1529 }
1543 } 1530 }
@@ -1708,7 +1695,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1708{ 1695{
1709 char buffer[4000]; 1696 char buffer[4000];
1710 char *buf = buffer; 1697 char *buf = buffer;
1711 size_t size = sizeof buffer; 1698 ptrdiff_t size = sizeof buffer;
1712 size_t len; 1699 size_t len;
1713 Lisp_Object bufstring; 1700 Lisp_Object bufstring;
1714 int usec; 1701 int usec;
@@ -1716,8 +1703,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1716 struct tm *tm; 1703 struct tm *tm;
1717 USE_SAFE_ALLOCA; 1704 USE_SAFE_ALLOCA;
1718 1705
1719 if (! (lisp_time_argument (timeval, tval, &usec) 1706 if (! lisp_time_argument (timeval, tval, &usec))
1720 && 0 <= usec && usec < 1000000))
1721 error ("Invalid time specification"); 1707 error ("Invalid time specification");
1722 ns = usec * 1000; 1708 ns = usec * 1000;
1723 1709
@@ -1881,9 +1867,12 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1881 tzstring = SSDATA (zone); 1867 tzstring = SSDATA (zone);
1882 else if (INTEGERP (zone)) 1868 else if (INTEGERP (zone))
1883 { 1869 {
1884 int abszone = eabs (XINT (zone)); 1870 EMACS_INT abszone = eabs (XINT (zone));
1885 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0), 1871 EMACS_INT zone_hr = abszone / (60*60);
1886 abszone / (60*60), (abszone/60) % 60, abszone % 60); 1872 int zone_min = (abszone/60) % 60;
1873 int zone_sec = abszone % 60;
1874 sprintf (tzbuf, "XXX%s%"pI"d:%02d:%02d", "-" + (XINT (zone) < 0),
1875 zone_hr, zone_min, zone_sec);
1887 tzstring = tzbuf; 1876 tzstring = tzbuf;
1888 } 1877 }
1889 else 1878 else
@@ -2189,10 +2178,10 @@ set_time_zone_rule (const char *tzstring)
2189 2178
2190static void 2179static void
2191general_insert_function (void (*insert_func) 2180general_insert_function (void (*insert_func)
2192 (const char *, EMACS_INT), 2181 (const char *, ptrdiff_t),
2193 void (*insert_from_string_func) 2182 void (*insert_from_string_func)
2194 (Lisp_Object, EMACS_INT, EMACS_INT, 2183 (Lisp_Object, ptrdiff_t, ptrdiff_t,
2195 EMACS_INT, EMACS_INT, int), 2184 ptrdiff_t, ptrdiff_t, int),
2196 int inherit, ptrdiff_t nargs, Lisp_Object *args) 2185 int inherit, ptrdiff_t nargs, Lisp_Object *args)
2197{ 2186{
2198 ptrdiff_t argnum; 2187 ptrdiff_t argnum;
@@ -2328,7 +2317,7 @@ from adjoining text, if those properties are sticky. */)
2328 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit) 2317 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
2329{ 2318{
2330 int i, stringlen; 2319 int i, stringlen;
2331 register EMACS_INT n; 2320 register ptrdiff_t n;
2332 int c, len; 2321 int c, len;
2333 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2322 unsigned char str[MAX_MULTIBYTE_LENGTH];
2334 char string[4000]; 2323 char string[4000];
@@ -2404,10 +2393,10 @@ from adjoining text, if those properties are sticky. */)
2404 buffer substrings. */ 2393 buffer substrings. */
2405 2394
2406Lisp_Object 2395Lisp_Object
2407make_buffer_string (EMACS_INT start, EMACS_INT end, int props) 2396make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
2408{ 2397{
2409 EMACS_INT start_byte = CHAR_TO_BYTE (start); 2398 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
2410 EMACS_INT end_byte = CHAR_TO_BYTE (end); 2399 ptrdiff_t end_byte = CHAR_TO_BYTE (end);
2411 2400
2412 return make_buffer_string_both (start, start_byte, end, end_byte, props); 2401 return make_buffer_string_both (start, start_byte, end, end_byte, props);
2413} 2402}
@@ -2428,8 +2417,8 @@ make_buffer_string (EMACS_INT start, EMACS_INT end, int props)
2428 buffer substrings. */ 2417 buffer substrings. */
2429 2418
2430Lisp_Object 2419Lisp_Object
2431make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte, 2420make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
2432 EMACS_INT end, EMACS_INT end_byte, int props) 2421 ptrdiff_t end, ptrdiff_t end_byte, int props)
2433{ 2422{
2434 Lisp_Object result, tem, tem1; 2423 Lisp_Object result, tem, tem1;
2435 2424
@@ -2462,7 +2451,7 @@ make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte,
2462 in the current buffer, if necessary. */ 2451 in the current buffer, if necessary. */
2463 2452
2464static void 2453static void
2465update_buffer_properties (EMACS_INT start, EMACS_INT end) 2454update_buffer_properties (ptrdiff_t start, ptrdiff_t end)
2466{ 2455{
2467 /* If this buffer has some access functions, 2456 /* If this buffer has some access functions,
2468 call them, specifying the range of the buffer being accessed. */ 2457 call them, specifying the range of the buffer being accessed. */
@@ -2501,7 +2490,7 @@ into the result string; if you don't want the text properties,
2501use `buffer-substring-no-properties' instead. */) 2490use `buffer-substring-no-properties' instead. */)
2502 (Lisp_Object start, Lisp_Object end) 2491 (Lisp_Object start, Lisp_Object end)
2503{ 2492{
2504 register EMACS_INT b, e; 2493 register ptrdiff_t b, e;
2505 2494
2506 validate_region (&start, &end); 2495 validate_region (&start, &end);
2507 b = XINT (start); 2496 b = XINT (start);
@@ -2517,7 +2506,7 @@ The two arguments START and END are character positions;
2517they can be in either order. */) 2506they can be in either order. */)
2518 (Lisp_Object start, Lisp_Object end) 2507 (Lisp_Object start, Lisp_Object end)
2519{ 2508{
2520 register EMACS_INT b, e; 2509 register ptrdiff_t b, e;
2521 2510
2522 validate_region (&start, &end); 2511 validate_region (&start, &end);
2523 b = XINT (start); 2512 b = XINT (start);
@@ -2601,8 +2590,8 @@ determines whether case is significant or ignored. */)
2601 register Lisp_Object trt 2590 register Lisp_Object trt
2602 = (!NILP (BVAR (current_buffer, case_fold_search)) 2591 = (!NILP (BVAR (current_buffer, case_fold_search))
2603 ? BVAR (current_buffer, case_canon_table) : Qnil); 2592 ? BVAR (current_buffer, case_canon_table) : Qnil);
2604 EMACS_INT chars = 0; 2593 ptrdiff_t chars = 0;
2605 EMACS_INT i1, i2, i1_byte, i2_byte; 2594 ptrdiff_t i1, i2, i1_byte, i2_byte;
2606 2595
2607 /* Find the first buffer and its substring. */ 2596 /* Find the first buffer and its substring. */
2608 2597
@@ -2763,21 +2752,21 @@ and don't mark the buffer as really changed.
2763Both characters must have the same length of multi-byte form. */) 2752Both characters must have the same length of multi-byte form. */)
2764 (Lisp_Object start, Lisp_Object end, Lisp_Object fromchar, Lisp_Object tochar, Lisp_Object noundo) 2753 (Lisp_Object start, Lisp_Object end, Lisp_Object fromchar, Lisp_Object tochar, Lisp_Object noundo)
2765{ 2754{
2766 register EMACS_INT pos, pos_byte, stop, i, len, end_byte; 2755 register ptrdiff_t pos, pos_byte, stop, i, len, end_byte;
2767 /* Keep track of the first change in the buffer: 2756 /* Keep track of the first change in the buffer:
2768 if 0 we haven't found it yet. 2757 if 0 we haven't found it yet.
2769 if < 0 we've found it and we've run the before-change-function. 2758 if < 0 we've found it and we've run the before-change-function.
2770 if > 0 we've actually performed it and the value is its position. */ 2759 if > 0 we've actually performed it and the value is its position. */
2771 EMACS_INT changed = 0; 2760 ptrdiff_t changed = 0;
2772 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH]; 2761 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH];
2773 unsigned char *p; 2762 unsigned char *p;
2774 int count = SPECPDL_INDEX (); 2763 ptrdiff_t count = SPECPDL_INDEX ();
2775#define COMBINING_NO 0 2764#define COMBINING_NO 0
2776#define COMBINING_BEFORE 1 2765#define COMBINING_BEFORE 1
2777#define COMBINING_AFTER 2 2766#define COMBINING_AFTER 2
2778#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) 2767#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
2779 int maybe_byte_combining = COMBINING_NO; 2768 int maybe_byte_combining = COMBINING_NO;
2780 EMACS_INT last_changed = 0; 2769 ptrdiff_t last_changed = 0;
2781 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2770 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2782 int fromc, toc; 2771 int fromc, toc;
2783 2772
@@ -2837,7 +2826,7 @@ Both characters must have the same length of multi-byte form. */)
2837 stop = min (stop, GPT_BYTE); 2826 stop = min (stop, GPT_BYTE);
2838 while (1) 2827 while (1)
2839 { 2828 {
2840 EMACS_INT pos_byte_next = pos_byte; 2829 ptrdiff_t pos_byte_next = pos_byte;
2841 2830
2842 if (pos_byte >= stop) 2831 if (pos_byte >= stop)
2843 { 2832 {
@@ -2940,7 +2929,7 @@ Both characters must have the same length of multi-byte form. */)
2940} 2929}
2941 2930
2942 2931
2943static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT, 2932static Lisp_Object check_translation (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2944 Lisp_Object); 2933 Lisp_Object);
2945 2934
2946/* Helper function for Ftranslate_region_internal. 2935/* Helper function for Ftranslate_region_internal.
@@ -2950,7 +2939,7 @@ static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT,
2950 element is found, return it. Otherwise return Qnil. */ 2939 element is found, return it. Otherwise return Qnil. */
2951 2940
2952static Lisp_Object 2941static Lisp_Object
2953check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end, 2942check_translation (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t end,
2954 Lisp_Object val) 2943 Lisp_Object val)
2955{ 2944{
2956 int buf_size = 16, buf_used = 0; 2945 int buf_size = 16, buf_used = 0;
@@ -2959,7 +2948,7 @@ check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end,
2959 for (; CONSP (val); val = XCDR (val)) 2948 for (; CONSP (val); val = XCDR (val))
2960 { 2949 {
2961 Lisp_Object elt; 2950 Lisp_Object elt;
2962 EMACS_INT len, i; 2951 ptrdiff_t len, i;
2963 2952
2964 elt = XCAR (val); 2953 elt = XCAR (val);
2965 if (! CONSP (elt)) 2954 if (! CONSP (elt))
@@ -3012,8 +3001,8 @@ It returns the number of characters changed. */)
3012 register unsigned char *tt; /* Trans table. */ 3001 register unsigned char *tt; /* Trans table. */
3013 register int nc; /* New character. */ 3002 register int nc; /* New character. */
3014 int cnt; /* Number of changes made. */ 3003 int cnt; /* Number of changes made. */
3015 EMACS_INT size; /* Size of translate table. */ 3004 ptrdiff_t size; /* Size of translate table. */
3016 EMACS_INT pos, pos_byte, end_pos; 3005 ptrdiff_t pos, pos_byte, end_pos;
3017 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3006 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3018 int string_multibyte IF_LINT (= 0); 3007 int string_multibyte IF_LINT (= 0);
3019 3008
@@ -3291,7 +3280,7 @@ save_restriction_restore (Lisp_Object data)
3291 /* The restriction has changed from the saved one, so restore 3280 /* The restriction has changed from the saved one, so restore
3292 the saved restriction. */ 3281 the saved restriction. */
3293 { 3282 {
3294 EMACS_INT pt = BUF_PT (buf); 3283 ptrdiff_t pt = BUF_PT (buf);
3295 3284
3296 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos); 3285 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
3297 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos); 3286 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
@@ -3349,7 +3338,7 @@ usage: (save-restriction &rest BODY) */)
3349 (Lisp_Object body) 3338 (Lisp_Object body)
3350{ 3339{
3351 register Lisp_Object val; 3340 register Lisp_Object val;
3352 int count = SPECPDL_INDEX (); 3341 ptrdiff_t count = SPECPDL_INDEX ();
3353 3342
3354 record_unwind_protect (save_restriction_restore, save_restriction_save ()); 3343 record_unwind_protect (save_restriction_restore, save_restriction_save ());
3355 val = Fprogn (body); 3344 val = Fprogn (body);
@@ -3567,12 +3556,12 @@ usage: (format STRING &rest OBJECTS) */)
3567 ptrdiff_t n; /* The number of the next arg to substitute */ 3556 ptrdiff_t n; /* The number of the next arg to substitute */
3568 char initial_buffer[4000]; 3557 char initial_buffer[4000];
3569 char *buf = initial_buffer; 3558 char *buf = initial_buffer;
3570 EMACS_INT bufsize = sizeof initial_buffer; 3559 ptrdiff_t bufsize = sizeof initial_buffer;
3571 EMACS_INT max_bufsize = STRING_BYTES_BOUND + 1; 3560 ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1;
3572 char *p; 3561 char *p;
3573 Lisp_Object buf_save_value IF_LINT (= {0}); 3562 Lisp_Object buf_save_value IF_LINT (= {0});
3574 register char *format, *end, *format_start; 3563 register char *format, *end, *format_start;
3575 EMACS_INT formatlen, nchars; 3564 ptrdiff_t formatlen, nchars;
3576 /* Nonzero if the format is multibyte. */ 3565 /* Nonzero if the format is multibyte. */
3577 int multibyte_format = 0; 3566 int multibyte_format = 0;
3578 /* Nonzero if the output should be a multibyte string, 3567 /* Nonzero if the output should be a multibyte string,
@@ -3599,7 +3588,7 @@ usage: (format STRING &rest OBJECTS) */)
3599 info[0] is unused. Unused elements have -1 for start. */ 3588 info[0] is unused. Unused elements have -1 for start. */
3600 struct info 3589 struct info
3601 { 3590 {
3602 EMACS_INT start, end; 3591 ptrdiff_t start, end;
3603 int converted_to_string; 3592 int converted_to_string;
3604 int intervals; 3593 int intervals;
3605 } *info = 0; 3594 } *info = 0;
@@ -3656,7 +3645,7 @@ usage: (format STRING &rest OBJECTS) */)
3656 char *format0 = format; 3645 char *format0 = format;
3657 3646
3658 /* Bytes needed to represent the output of this conversion. */ 3647 /* Bytes needed to represent the output of this conversion. */
3659 EMACS_INT convbytes; 3648 ptrdiff_t convbytes;
3660 3649
3661 if (*format == '%') 3650 if (*format == '%')
3662 { 3651 {
@@ -3683,7 +3672,7 @@ usage: (format STRING &rest OBJECTS) */)
3683 int space_flag = 0; 3672 int space_flag = 0;
3684 int sharp_flag = 0; 3673 int sharp_flag = 0;
3685 int zero_flag = 0; 3674 int zero_flag = 0;
3686 EMACS_INT field_width; 3675 ptrdiff_t field_width;
3687 int precision_given; 3676 int precision_given;
3688 uintmax_t precision = UINTMAX_MAX; 3677 uintmax_t precision = UINTMAX_MAX;
3689 char *num_end; 3678 char *num_end;
@@ -3790,11 +3779,11 @@ usage: (format STRING &rest OBJECTS) */)
3790 { 3779 {
3791 /* handle case (precision[n] >= 0) */ 3780 /* handle case (precision[n] >= 0) */
3792 3781
3793 EMACS_INT width, padding, nbytes; 3782 ptrdiff_t width, padding, nbytes;
3794 EMACS_INT nchars_string; 3783 ptrdiff_t nchars_string;
3795 3784
3796 EMACS_INT prec = -1; 3785 ptrdiff_t prec = -1;
3797 if (precision_given && precision <= TYPE_MAXIMUM (EMACS_INT)) 3786 if (precision_given && precision <= TYPE_MAXIMUM (ptrdiff_t))
3798 prec = precision; 3787 prec = precision;
3799 3788
3800 /* lisp_string_width ignores a precision of 0, but GNU 3789 /* lisp_string_width ignores a precision of 0, but GNU
@@ -3807,7 +3796,7 @@ usage: (format STRING &rest OBJECTS) */)
3807 width = nchars_string = nbytes = 0; 3796 width = nchars_string = nbytes = 0;
3808 else 3797 else
3809 { 3798 {
3810 EMACS_INT nch, nby; 3799 ptrdiff_t nch, nby;
3811 width = lisp_string_width (args[n], prec, &nch, &nby); 3800 width = lisp_string_width (args[n], prec, &nch, &nby);
3812 if (prec < 0) 3801 if (prec < 0)
3813 { 3802 {
@@ -3904,7 +3893,7 @@ usage: (format STRING &rest OBJECTS) */)
3904 verify (0 < USEFUL_PRECISION_MAX); 3893 verify (0 < USEFUL_PRECISION_MAX);
3905 3894
3906 int prec; 3895 int prec;
3907 EMACS_INT padding, sprintf_bytes; 3896 ptrdiff_t padding, sprintf_bytes;
3908 uintmax_t excess_precision, numwidth; 3897 uintmax_t excess_precision, numwidth;
3909 uintmax_t leading_zeros = 0, trailing_zeros = 0; 3898 uintmax_t leading_zeros = 0, trailing_zeros = 0;
3910 3899
@@ -4219,8 +4208,8 @@ usage: (format STRING &rest OBJECTS) */)
4219 4208
4220 if (CONSP (props)) 4209 if (CONSP (props))
4221 { 4210 {
4222 EMACS_INT bytepos = 0, position = 0, translated = 0; 4211 ptrdiff_t bytepos = 0, position = 0, translated = 0;
4223 EMACS_INT argn = 1; 4212 ptrdiff_t argn = 1;
4224 Lisp_Object list; 4213 Lisp_Object list;
4225 4214
4226 /* Adjust the bounds of each text property 4215 /* Adjust the bounds of each text property
@@ -4238,7 +4227,7 @@ usage: (format STRING &rest OBJECTS) */)
4238 for (list = props; CONSP (list); list = XCDR (list)) 4227 for (list = props; CONSP (list); list = XCDR (list))
4239 { 4228 {
4240 Lisp_Object item; 4229 Lisp_Object item;
4241 EMACS_INT pos; 4230 ptrdiff_t pos;
4242 4231
4243 item = XCAR (list); 4232 item = XCAR (list);
4244 4233
@@ -4369,12 +4358,12 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer. */)
4369 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */ 4358 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
4370 4359
4371static void 4360static void
4372transpose_markers (EMACS_INT start1, EMACS_INT end1, 4361transpose_markers (ptrdiff_t start1, ptrdiff_t end1,
4373 EMACS_INT start2, EMACS_INT end2, 4362 ptrdiff_t start2, ptrdiff_t end2,
4374 EMACS_INT start1_byte, EMACS_INT end1_byte, 4363 ptrdiff_t start1_byte, ptrdiff_t end1_byte,
4375 EMACS_INT start2_byte, EMACS_INT end2_byte) 4364 ptrdiff_t start2_byte, ptrdiff_t end2_byte)
4376{ 4365{
4377 register EMACS_INT amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos; 4366 register ptrdiff_t amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos;
4378 register struct Lisp_Marker *marker; 4367 register struct Lisp_Marker *marker;
4379 4368
4380 /* Update point as if it were a marker. */ 4369 /* Update point as if it were a marker. */
@@ -4448,9 +4437,9 @@ any markers that happen to be located in the regions.
4448Transposing beyond buffer boundaries is an error. */) 4437Transposing beyond buffer boundaries is an error. */)
4449 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) 4438 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers)
4450{ 4439{
4451 register EMACS_INT start1, end1, start2, end2; 4440 register ptrdiff_t start1, end1, start2, end2;
4452 EMACS_INT start1_byte, start2_byte, len1_byte, len2_byte; 4441 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte;
4453 EMACS_INT gap, len1, len_mid, len2; 4442 ptrdiff_t gap, len1, len_mid, len2;
4454 unsigned char *start1_addr, *start2_addr, *temp; 4443 unsigned char *start1_addr, *start2_addr, *temp;
4455 4444
4456 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2, tmp_interval3; 4445 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2, tmp_interval3;
@@ -4471,7 +4460,7 @@ Transposing beyond buffer boundaries is an error. */)
4471 /* Swap the regions if they're reversed. */ 4460 /* Swap the regions if they're reversed. */
4472 if (start2 < end1) 4461 if (start2 < end1)
4473 { 4462 {
4474 register EMACS_INT glumph = start1; 4463 register ptrdiff_t glumph = start1;
4475 start1 = start2; 4464 start1 = start2;
4476 start2 = glumph; 4465 start2 = glumph;
4477 glumph = end1; 4466 glumph = end1;
diff --git a/src/emacs.c b/src/emacs.c
index 73be96f73bc..a942878fe00 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -111,15 +111,15 @@ int gdb_use_union EXTERNALLY_VISIBLE = 0;
111#else 111#else
112int gdb_use_union EXTERNALLY_VISIBLE = 1; 112int gdb_use_union EXTERNALLY_VISIBLE = 1;
113#endif 113#endif
114EMACS_INT gdb_valbits EXTERNALLY_VISIBLE = VALBITS; 114int gdb_valbits EXTERNALLY_VISIBLE = VALBITS;
115EMACS_INT gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS; 115int gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS;
116#if defined (DATA_SEG_BITS) && ! defined (USE_LSB_TAG) 116#if defined (DATA_SEG_BITS) && ! defined (USE_LSB_TAG)
117EMACS_INT gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS; 117uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS;
118#else 118#else
119EMACS_INT gdb_data_seg_bits EXTERNALLY_VISIBLE = 0; 119uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = 0;
120#endif 120#endif
121EMACS_INT PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG; 121ptrdiff_t PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG;
122EMACS_INT gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG; 122ptrdiff_t gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG;
123/* GDB might say "No enum type named pvec_type" if we don't have at 123/* GDB might say "No enum type named pvec_type" if we don't have at
124 least one symbol with that type, and then xbacktrace could fail. */ 124 least one symbol with that type, and then xbacktrace could fail. */
125enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK; 125enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK;
@@ -404,7 +404,7 @@ init_cmdargs (int argc, char **argv, int skip_args)
404{ 404{
405 register int i; 405 register int i;
406 Lisp_Object name, dir, handler; 406 Lisp_Object name, dir, handler;
407 int count = SPECPDL_INDEX (); 407 ptrdiff_t count = SPECPDL_INDEX ();
408 Lisp_Object raw_name; 408 Lisp_Object raw_name;
409 409
410 initial_argv = argv; 410 initial_argv = argv;
@@ -2033,10 +2033,15 @@ all of which are called before Emacs is actually killed. */)
2033 if (STRINGP (Vauto_save_list_file_name)) 2033 if (STRINGP (Vauto_save_list_file_name))
2034 unlink (SSDATA (Vauto_save_list_file_name)); 2034 unlink (SSDATA (Vauto_save_list_file_name));
2035 2035
2036 exit_code = EXIT_SUCCESS; 2036 if (INTEGERP (arg))
2037 if (noninteractive && (fflush (stdout) || ferror (stdout))) 2037 exit_code = (XINT (arg) < 0
2038 ? XINT (arg) | INT_MIN
2039 : XINT (arg) & INT_MAX);
2040 else if (noninteractive && (fflush (stdout) || ferror (stdout)))
2038 exit_code = EXIT_FAILURE; 2041 exit_code = EXIT_FAILURE;
2039 exit (INTEGERP (arg) ? XINT (arg) : exit_code); 2042 else
2043 exit_code = EXIT_SUCCESS;
2044 exit (exit_code);
2040} 2045}
2041 2046
2042 2047
@@ -2146,7 +2151,7 @@ You must run Emacs in batch mode in order to dump it. */)
2146{ 2151{
2147 Lisp_Object tem; 2152 Lisp_Object tem;
2148 Lisp_Object symbol; 2153 Lisp_Object symbol;
2149 int count = SPECPDL_INDEX (); 2154 ptrdiff_t count = SPECPDL_INDEX ();
2150 2155
2151 check_pure_size (); 2156 check_pure_size ();
2152 2157
diff --git a/src/eval.c b/src/eval.c
index 3d0e82c2d9f..1da841a4073 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -65,7 +65,7 @@ struct handler *handlerlist;
65int gcpro_level; 65int gcpro_level;
66#endif 66#endif
67 67
68Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun; 68Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp;
69Lisp_Object Qinhibit_quit; 69Lisp_Object Qinhibit_quit;
70Lisp_Object Qand_rest; 70Lisp_Object Qand_rest;
71static Lisp_Object Qand_optional; 71static Lisp_Object Qand_optional;
@@ -90,7 +90,7 @@ Lisp_Object Vautoload_queue;
90 90
91/* Current number of specbindings allocated in specpdl. */ 91/* Current number of specbindings allocated in specpdl. */
92 92
93EMACS_INT specpdl_size; 93ptrdiff_t specpdl_size;
94 94
95/* Pointer to beginning of specpdl. */ 95/* Pointer to beginning of specpdl. */
96 96
@@ -111,7 +111,7 @@ static EMACS_INT lisp_eval_depth;
111 signal the error instead of entering an infinite loop of debugger 111 signal the error instead of entering an infinite loop of debugger
112 invocations. */ 112 invocations. */
113 113
114static int when_entered_debugger; 114static EMACS_INT when_entered_debugger;
115 115
116/* The function from which the last `signal' was called. Set in 116/* The function from which the last `signal' was called. Set in
117 Fsignal. */ 117 Fsignal. */
@@ -183,7 +183,7 @@ static Lisp_Object
183call_debugger (Lisp_Object arg) 183call_debugger (Lisp_Object arg)
184{ 184{
185 int debug_while_redisplaying; 185 int debug_while_redisplaying;
186 int count = SPECPDL_INDEX (); 186 ptrdiff_t count = SPECPDL_INDEX ();
187 Lisp_Object val; 187 Lisp_Object val;
188 EMACS_INT old_max = max_specpdl_size; 188 EMACS_INT old_max = max_specpdl_size;
189 189
@@ -379,23 +379,14 @@ usage: (prog1 FIRST BODY...) */)
379 Lisp_Object val; 379 Lisp_Object val;
380 register Lisp_Object args_left; 380 register Lisp_Object args_left;
381 struct gcpro gcpro1, gcpro2; 381 struct gcpro gcpro1, gcpro2;
382 register int argnum = 0;
383
384 if (NILP (args))
385 return Qnil;
386 382
387 args_left = args; 383 args_left = args;
388 val = Qnil; 384 val = Qnil;
389 GCPRO2 (args, val); 385 GCPRO2 (args, val);
390 386
391 do 387 val = eval_sub (XCAR (args_left));
392 { 388 while (CONSP (args_left = XCDR (args_left)))
393 Lisp_Object tem = eval_sub (XCAR (args_left)); 389 eval_sub (XCAR (args_left));
394 if (!(argnum++))
395 val = tem;
396 args_left = XCDR (args_left);
397 }
398 while (CONSP (args_left));
399 390
400 UNGCPRO; 391 UNGCPRO;
401 return val; 392 return val;
@@ -408,31 +399,12 @@ remaining args, whose values are discarded.
408usage: (prog2 FORM1 FORM2 BODY...) */) 399usage: (prog2 FORM1 FORM2 BODY...) */)
409 (Lisp_Object args) 400 (Lisp_Object args)
410{ 401{
411 Lisp_Object val; 402 struct gcpro gcpro1;
412 register Lisp_Object args_left;
413 struct gcpro gcpro1, gcpro2;
414 register int argnum = -1;
415
416 val = Qnil;
417
418 if (NILP (args))
419 return Qnil;
420
421 args_left = args;
422 val = Qnil;
423 GCPRO2 (args, val);
424
425 do
426 {
427 Lisp_Object tem = eval_sub (XCAR (args_left));
428 if (!(argnum++))
429 val = tem;
430 args_left = XCDR (args_left);
431 }
432 while (CONSP (args_left));
433 403
404 GCPRO1 (args);
405 eval_sub (XCAR (args));
434 UNGCPRO; 406 UNGCPRO;
435 return val; 407 return Fprog1 (XCDR (args));
436} 408}
437 409
438DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0, 410DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
@@ -621,109 +593,6 @@ interactive_p (int exclude_subrs_p)
621} 593}
622 594
623 595
624DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
625 doc: /* Define NAME as a function.
626The definition is (lambda ARGLIST [DOCSTRING] BODY...).
627See also the function `interactive'.
628usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
629 (Lisp_Object args)
630{
631 register Lisp_Object fn_name;
632 register Lisp_Object defn;
633
634 fn_name = Fcar (args);
635 CHECK_SYMBOL (fn_name);
636 defn = Fcons (Qlambda, Fcdr (args));
637 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
638 defn = Ffunction (Fcons (defn, Qnil));
639 if (!NILP (Vpurify_flag))
640 defn = Fpurecopy (defn);
641 if (CONSP (XSYMBOL (fn_name)->function)
642 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
643 LOADHIST_ATTACH (Fcons (Qt, fn_name));
644 Ffset (fn_name, defn);
645 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
646 return fn_name;
647}
648
649DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
650 doc: /* Define NAME as a macro.
651The actual definition looks like
652 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
653When the macro is called, as in (NAME ARGS...),
654the function (lambda ARGLIST BODY...) is applied to
655the list ARGS... as it appears in the expression,
656and the result should be a form to be evaluated instead of the original.
657
658DECL is a declaration, optional, which can specify how to indent
659calls to this macro, how Edebug should handle it, and which argument
660should be treated as documentation. It looks like this:
661 (declare SPECS...)
662The elements can look like this:
663 (indent INDENT)
664 Set NAME's `lisp-indent-function' property to INDENT.
665
666 (debug DEBUG)
667 Set NAME's `edebug-form-spec' property to DEBUG. (This is
668 equivalent to writing a `def-edebug-spec' for the macro.)
669
670 (doc-string ELT)
671 Set NAME's `doc-string-elt' property to ELT.
672
673usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
674 (Lisp_Object args)
675{
676 register Lisp_Object fn_name;
677 register Lisp_Object defn;
678 Lisp_Object lambda_list, doc, tail;
679
680 fn_name = Fcar (args);
681 CHECK_SYMBOL (fn_name);
682 lambda_list = Fcar (Fcdr (args));
683 tail = Fcdr (Fcdr (args));
684
685 doc = Qnil;
686 if (STRINGP (Fcar (tail)))
687 {
688 doc = XCAR (tail);
689 tail = XCDR (tail);
690 }
691
692 if (CONSP (Fcar (tail))
693 && EQ (Fcar (Fcar (tail)), Qdeclare))
694 {
695 if (!NILP (Vmacro_declaration_function))
696 {
697 struct gcpro gcpro1;
698 GCPRO1 (args);
699 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
700 UNGCPRO;
701 }
702
703 tail = Fcdr (tail);
704 }
705
706 if (NILP (doc))
707 tail = Fcons (lambda_list, tail);
708 else
709 tail = Fcons (lambda_list, Fcons (doc, tail));
710
711 defn = Fcons (Qlambda, tail);
712 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
713 defn = Ffunction (Fcons (defn, Qnil));
714 defn = Fcons (Qmacro, defn);
715
716 if (!NILP (Vpurify_flag))
717 defn = Fpurecopy (defn);
718 if (CONSP (XSYMBOL (fn_name)->function)
719 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
720 LOADHIST_ATTACH (Fcons (Qt, fn_name));
721 Ffset (fn_name, defn);
722 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
723 return fn_name;
724}
725
726
727DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0, 596DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
728 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE. 597 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
729Aliased variables always have the same value; setting one sets the other. 598Aliased variables always have the same value; setting one sets the other.
@@ -764,8 +633,8 @@ The return value is BASE-VARIABLE. */)
764 { 633 {
765 struct specbinding *p; 634 struct specbinding *p;
766 635
767 for (p = specpdl_ptr - 1; p >= specpdl; p--) 636 for (p = specpdl_ptr; p > specpdl; )
768 if (p->func == NULL 637 if ((--p)->func == NULL
769 && (EQ (new_alias, 638 && (EQ (new_alias,
770 CONSP (p->symbol) ? XCAR (p->symbol) : p->symbol))) 639 CONSP (p->symbol) ? XCAR (p->symbol) : p->symbol)))
771 error ("Don't know how to make a let-bound variable an alias"); 640 error ("Don't know how to make a let-bound variable an alias");
@@ -842,9 +711,9 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
842 { /* Check if there is really a global binding rather than just a let 711 { /* Check if there is really a global binding rather than just a let
843 binding that shadows the global unboundness of the var. */ 712 binding that shadows the global unboundness of the var. */
844 volatile struct specbinding *pdl = specpdl_ptr; 713 volatile struct specbinding *pdl = specpdl_ptr;
845 while (--pdl >= specpdl) 714 while (pdl > specpdl)
846 { 715 {
847 if (EQ (pdl->symbol, sym) && !pdl->func 716 if (EQ ((--pdl)->symbol, sym) && !pdl->func
848 && EQ (pdl->old_value, Qunbound)) 717 && EQ (pdl->old_value, Qunbound))
849 { 718 {
850 message_with_string ("Warning: defvar ignored because %s is let-bound", 719 message_with_string ("Warning: defvar ignored because %s is let-bound",
@@ -932,7 +801,7 @@ usage: (let* VARLIST BODY...) */)
932 (Lisp_Object args) 801 (Lisp_Object args)
933{ 802{
934 Lisp_Object varlist, var, val, elt, lexenv; 803 Lisp_Object varlist, var, val, elt, lexenv;
935 int count = SPECPDL_INDEX (); 804 ptrdiff_t count = SPECPDL_INDEX ();
936 struct gcpro gcpro1, gcpro2, gcpro3; 805 struct gcpro gcpro1, gcpro2, gcpro3;
937 806
938 GCPRO3 (args, elt, varlist); 807 GCPRO3 (args, elt, varlist);
@@ -995,7 +864,7 @@ usage: (let VARLIST BODY...) */)
995{ 864{
996 Lisp_Object *temps, tem, lexenv; 865 Lisp_Object *temps, tem, lexenv;
997 register Lisp_Object elt, varlist; 866 register Lisp_Object elt, varlist;
998 int count = SPECPDL_INDEX (); 867 ptrdiff_t count = SPECPDL_INDEX ();
999 ptrdiff_t argnum; 868 ptrdiff_t argnum;
1000 struct gcpro gcpro1, gcpro2; 869 struct gcpro gcpro1, gcpro2;
1001 USE_SAFE_ALLOCA; 870 USE_SAFE_ALLOCA;
@@ -1298,7 +1167,7 @@ usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1298 (Lisp_Object args) 1167 (Lisp_Object args)
1299{ 1168{
1300 Lisp_Object val; 1169 Lisp_Object val;
1301 int count = SPECPDL_INDEX (); 1170 ptrdiff_t count = SPECPDL_INDEX ();
1302 1171
1303 record_unwind_protect (Fprogn, Fcdr (args)); 1172 record_unwind_protect (Fprogn, Fcdr (args));
1304 val = eval_sub (Fcar (args)); 1173 val = eval_sub (Fcar (args));
@@ -2042,12 +1911,11 @@ this does nothing and returns nil. */)
2042 /* Only add entries after dumping, because the ones before are 1911 /* Only add entries after dumping, because the ones before are
2043 not useful and else we get loads of them from the loaddefs.el. */ 1912 not useful and else we get loads of them from the loaddefs.el. */
2044 LOADHIST_ATTACH (Fcons (Qautoload, function)); 1913 LOADHIST_ATTACH (Fcons (Qautoload, function));
2045 else 1914 else if (EQ (docstring, make_number (0)))
2046 /* We don't want the docstring in purespace (instead, 1915 /* `read1' in lread.c has found the docstring starting with "\
2047 Snarf-documentation should (hopefully) overwrite it). 1916 and assumed the docstring will be provided by Snarf-documentation, so it
2048 We used to use 0 here, but that leads to accidental sharing in 1917 passed us 0 instead. But that leads to accidental sharing in purecopy's
2049 purecopy's hash-consing, so we use a (hopefully) unique integer 1918 hash-consing, so we use a (hopefully) unique integer instead. */
2050 instead. */
2051 docstring = make_number (XUNTAG (function, Lisp_Symbol)); 1919 docstring = make_number (XUNTAG (function, Lisp_Symbol));
2052 return Ffset (function, 1920 return Ffset (function,
2053 Fpurecopy (list5 (Qautoload, file, docstring, 1921 Fpurecopy (list5 (Qautoload, file, docstring,
@@ -2084,7 +1952,7 @@ un_autoload (Lisp_Object oldqueue)
2084void 1952void
2085do_autoload (Lisp_Object fundef, Lisp_Object funname) 1953do_autoload (Lisp_Object fundef, Lisp_Object funname)
2086{ 1954{
2087 int count = SPECPDL_INDEX (); 1955 ptrdiff_t count = SPECPDL_INDEX ();
2088 Lisp_Object fun; 1956 Lisp_Object fun;
2089 struct gcpro gcpro1, gcpro2, gcpro3; 1957 struct gcpro gcpro1, gcpro2, gcpro3;
2090 1958
@@ -2131,7 +1999,7 @@ DEFUN ("eval", Feval, Seval, 1, 2, 0,
2131If LEXICAL is t, evaluate using lexical scoping. */) 1999If LEXICAL is t, evaluate using lexical scoping. */)
2132 (Lisp_Object form, Lisp_Object lexical) 2000 (Lisp_Object form, Lisp_Object lexical)
2133{ 2001{
2134 int count = SPECPDL_INDEX (); 2002 ptrdiff_t count = SPECPDL_INDEX ();
2135 specbind (Qinternal_interpreter_environment, 2003 specbind (Qinternal_interpreter_environment,
2136 NILP (lexical) ? Qnil : Fcons (Qt, Qnil)); 2004 NILP (lexical) ? Qnil : Fcons (Qt, Qnil));
2137 return unbind_to (count, eval_sub (form)); 2005 return unbind_to (count, eval_sub (form));
@@ -2365,7 +2233,8 @@ Thus, (apply '+ 1 2 '(3 4)) returns 10.
2365usage: (apply FUNCTION &rest ARGUMENTS) */) 2233usage: (apply FUNCTION &rest ARGUMENTS) */)
2366 (ptrdiff_t nargs, Lisp_Object *args) 2234 (ptrdiff_t nargs, Lisp_Object *args)
2367{ 2235{
2368 ptrdiff_t i, numargs; 2236 ptrdiff_t i;
2237 EMACS_INT numargs;
2369 register Lisp_Object spread_arg; 2238 register Lisp_Object spread_arg;
2370 register Lisp_Object *funcall_args; 2239 register Lisp_Object *funcall_args;
2371 Lisp_Object fun, retval; 2240 Lisp_Object fun, retval;
@@ -3015,7 +2884,8 @@ static Lisp_Object
3015apply_lambda (Lisp_Object fun, Lisp_Object args) 2884apply_lambda (Lisp_Object fun, Lisp_Object args)
3016{ 2885{
3017 Lisp_Object args_left; 2886 Lisp_Object args_left;
3018 ptrdiff_t i, numargs; 2887 ptrdiff_t i;
2888 EMACS_INT numargs;
3019 register Lisp_Object *arg_vector; 2889 register Lisp_Object *arg_vector;
3020 struct gcpro gcpro1, gcpro2, gcpro3; 2890 struct gcpro gcpro1, gcpro2, gcpro3;
3021 register Lisp_Object tem; 2891 register Lisp_Object tem;
@@ -3060,7 +2930,7 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
3060 register Lisp_Object *arg_vector) 2930 register Lisp_Object *arg_vector)
3061{ 2931{
3062 Lisp_Object val, syms_left, next, lexenv; 2932 Lisp_Object val, syms_left, next, lexenv;
3063 int count = SPECPDL_INDEX (); 2933 ptrdiff_t count = SPECPDL_INDEX ();
3064 ptrdiff_t i; 2934 ptrdiff_t i;
3065 int optional, rest; 2935 int optional, rest;
3066 2936
@@ -3199,12 +3069,8 @@ DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
3199static void 3069static void
3200grow_specpdl (void) 3070grow_specpdl (void)
3201{ 3071{
3202 register int count = SPECPDL_INDEX (); 3072 register ptrdiff_t count = SPECPDL_INDEX ();
3203 int max_size = 3073 ptrdiff_t max_size = min (max_specpdl_size, PTRDIFF_MAX);
3204 min (max_specpdl_size,
3205 min (max (PTRDIFF_MAX, SIZE_MAX) / sizeof (struct specbinding),
3206 INT_MAX));
3207 int size;
3208 if (max_size <= specpdl_size) 3074 if (max_size <= specpdl_size)
3209 { 3075 {
3210 if (max_specpdl_size < 400) 3076 if (max_specpdl_size < 400)
@@ -3212,9 +3078,7 @@ grow_specpdl (void)
3212 if (max_size <= specpdl_size) 3078 if (max_size <= specpdl_size)
3213 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil); 3079 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
3214 } 3080 }
3215 size = specpdl_size < max_size / 2 ? 2 * specpdl_size : max_size; 3081 specpdl = xpalloc (specpdl, &specpdl_size, 1, max_size, sizeof *specpdl);
3216 specpdl = xnrealloc (specpdl, size, sizeof *specpdl);
3217 specpdl_size = size;
3218 specpdl_ptr = specpdl + count; 3082 specpdl_ptr = specpdl + count;
3219} 3083}
3220 3084
@@ -3344,7 +3208,7 @@ record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
3344} 3208}
3345 3209
3346Lisp_Object 3210Lisp_Object
3347unbind_to (int count, Lisp_Object value) 3211unbind_to (ptrdiff_t count, Lisp_Object value)
3348{ 3212{
3349 Lisp_Object quitf = Vquit_flag; 3213 Lisp_Object quitf = Vquit_flag;
3350 struct gcpro gcpro1, gcpro2; 3214 struct gcpro gcpro1, gcpro2;
@@ -3424,7 +3288,7 @@ The debugger is entered when that frame exits, if the flag is non-nil. */)
3424 (Lisp_Object level, Lisp_Object flag) 3288 (Lisp_Object level, Lisp_Object flag)
3425{ 3289{
3426 register struct backtrace *backlist = backtrace_list; 3290 register struct backtrace *backlist = backtrace_list;
3427 register int i; 3291 register EMACS_INT i;
3428 3292
3429 CHECK_NUMBER (level); 3293 CHECK_NUMBER (level);
3430 3294
@@ -3608,7 +3472,6 @@ before making `inhibit-quit' nil. */);
3608 3472
3609 DEFSYM (Qinteractive, "interactive"); 3473 DEFSYM (Qinteractive, "interactive");
3610 DEFSYM (Qcommandp, "commandp"); 3474 DEFSYM (Qcommandp, "commandp");
3611 DEFSYM (Qdefun, "defun");
3612 DEFSYM (Qand_rest, "&rest"); 3475 DEFSYM (Qand_rest, "&rest");
3613 DEFSYM (Qand_optional, "&optional"); 3476 DEFSYM (Qand_optional, "&optional");
3614 DEFSYM (Qclosure, "closure"); 3477 DEFSYM (Qclosure, "closure");
@@ -3670,23 +3533,16 @@ Note that `debug-on-error', `debug-on-quit' and friends
3670still determine whether to handle the particular condition. */); 3533still determine whether to handle the particular condition. */);
3671 Vdebug_on_signal = Qnil; 3534 Vdebug_on_signal = Qnil;
3672 3535
3673 DEFVAR_LISP ("macro-declaration-function", Vmacro_declaration_function,
3674 doc: /* Function to process declarations in a macro definition.
3675The function will be called with two args MACRO and DECL.
3676MACRO is the name of the macro being defined.
3677DECL is a list `(declare ...)' containing the declarations.
3678The value the function returns is not used. */);
3679 Vmacro_declaration_function = Qnil;
3680
3681 /* When lexical binding is being used, 3536 /* When lexical binding is being used,
3682 vinternal_interpreter_environment is non-nil, and contains an alist 3537 Vinternal_interpreter_environment is non-nil, and contains an alist
3683 of lexically-bound variable, or (t), indicating an empty 3538 of lexically-bound variable, or (t), indicating an empty
3684 environment. The lisp name of this variable would be 3539 environment. The lisp name of this variable would be
3685 `internal-interpreter-environment' if it weren't hidden. 3540 `internal-interpreter-environment' if it weren't hidden.
3686 Every element of this list can be either a cons (VAR . VAL) 3541 Every element of this list can be either a cons (VAR . VAL)
3687 specifying a lexical binding, or a single symbol VAR indicating 3542 specifying a lexical binding, or a single symbol VAR indicating
3688 that this variable should use dynamic scoping. */ 3543 that this variable should use dynamic scoping. */
3689 DEFSYM (Qinternal_interpreter_environment, "internal-interpreter-environment"); 3544 DEFSYM (Qinternal_interpreter_environment,
3545 "internal-interpreter-environment");
3690 DEFVAR_LISP ("internal-interpreter-environment", 3546 DEFVAR_LISP ("internal-interpreter-environment",
3691 Vinternal_interpreter_environment, 3547 Vinternal_interpreter_environment,
3692 doc: /* If non-nil, the current lexical environment of the lisp interpreter. 3548 doc: /* If non-nil, the current lexical environment of the lisp interpreter.
@@ -3717,8 +3573,6 @@ alist of active lexical bindings. */);
3717 defsubr (&Ssetq); 3573 defsubr (&Ssetq);
3718 defsubr (&Squote); 3574 defsubr (&Squote);
3719 defsubr (&Sfunction); 3575 defsubr (&Sfunction);
3720 defsubr (&Sdefun);
3721 defsubr (&Sdefmacro);
3722 defsubr (&Sdefvar); 3576 defsubr (&Sdefvar);
3723 defsubr (&Sdefvaralias); 3577 defsubr (&Sdefvaralias);
3724 defsubr (&Sdefconst); 3578 defsubr (&Sdefconst);
diff --git a/src/fileio.c b/src/fileio.c
index f09ba2c394c..c6e2eea5089 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -148,9 +148,9 @@ Lisp_Object Qfile_name_history;
148static Lisp_Object Qcar_less_than_car; 148static Lisp_Object Qcar_less_than_car;
149 149
150static Lisp_Object Fmake_symbolic_link (Lisp_Object, Lisp_Object, Lisp_Object); 150static Lisp_Object Fmake_symbolic_link (Lisp_Object, Lisp_Object, Lisp_Object);
151static int a_write (int, Lisp_Object, EMACS_INT, EMACS_INT, 151static int a_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t,
152 Lisp_Object *, struct coding_system *); 152 Lisp_Object *, struct coding_system *);
153static int e_write (int, Lisp_Object, EMACS_INT, EMACS_INT, 153static int e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t,
154 struct coding_system *); 154 struct coding_system *);
155 155
156 156
@@ -260,7 +260,7 @@ use the standard functions without calling themselves recursively. */)
260{ 260{
261 /* This function must not munge the match data. */ 261 /* This function must not munge the match data. */
262 Lisp_Object chain, inhibited_handlers, result; 262 Lisp_Object chain, inhibited_handlers, result;
263 int pos = -1; 263 ptrdiff_t pos = -1;
264 264
265 result = Qnil; 265 result = Qnil;
266 CHECK_STRING (filename); 266 CHECK_STRING (filename);
@@ -278,7 +278,7 @@ use the standard functions without calling themselves recursively. */)
278 if (CONSP (elt)) 278 if (CONSP (elt))
279 { 279 {
280 Lisp_Object string = XCAR (elt); 280 Lisp_Object string = XCAR (elt);
281 EMACS_INT match_pos; 281 ptrdiff_t match_pos;
282 Lisp_Object handler = XCDR (elt); 282 Lisp_Object handler = XCDR (elt);
283 Lisp_Object operations = Qnil; 283 Lisp_Object operations = Qnil;
284 284
@@ -877,7 +877,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
877 } 877 }
878 } 878 }
879 879
880 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */ 880 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
881 nm = (char *) alloca (SBYTES (name) + 1); 881 nm = (char *) alloca (SBYTES (name) + 1);
882 memcpy (nm, SSDATA (name), SBYTES (name) + 1); 882 memcpy (nm, SSDATA (name), SBYTES (name) + 1);
883 883
@@ -905,7 +905,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
905 if (drive && IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) 905 if (drive && IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]))
906 nm++; 906 nm++;
907 907
908 /* Discard any previous drive specifier if nm is now in UNC format. */ 908 /* Discard any previous drive specifier if nm is now in UNC format. */
909 if (IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) 909 if (IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]))
910 { 910 {
911 drive = 0; 911 drive = 0;
@@ -970,7 +970,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
970 } 970 }
971 else 971 else
972#endif 972#endif
973 /* drive must be set, so this is okay */ 973 /* Drive must be set, so this is okay. */
974 if (strcmp (nm - 2, SSDATA (name)) != 0) 974 if (strcmp (nm - 2, SSDATA (name)) != 0)
975 { 975 {
976 char temp[] = " :"; 976 char temp[] = " :";
@@ -1016,7 +1016,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1016 if (!(newdir = egetenv ("HOME"))) 1016 if (!(newdir = egetenv ("HOME")))
1017 newdir = ""; 1017 newdir = "";
1018 nm++; 1018 nm++;
1019 /* egetenv may return a unibyte string, which will bite us since 1019 /* `egetenv' may return a unibyte string, which will bite us since
1020 we expect the directory to be multibyte. */ 1020 we expect the directory to be multibyte. */
1021 tem = build_string (newdir); 1021 tem = build_string (newdir);
1022 if (!STRING_MULTIBYTE (tem)) 1022 if (!STRING_MULTIBYTE (tem))
@@ -1058,7 +1058,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1058 use the drive's current directory as the prefix if needed. */ 1058 use the drive's current directory as the prefix if needed. */
1059 if (!newdir && drive) 1059 if (!newdir && drive)
1060 { 1060 {
1061 /* Get default directory if needed to make nm absolute. */ 1061 /* Get default directory if needed to make nm absolute. */
1062 char *adir = NULL; 1062 char *adir = NULL;
1063 if (!IS_DIRECTORY_SEP (nm[0])) 1063 if (!IS_DIRECTORY_SEP (nm[0]))
1064 { 1064 {
@@ -1068,7 +1068,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1068 } 1068 }
1069 if (!adir) 1069 if (!adir)
1070 { 1070 {
1071 /* Either nm starts with /, or drive isn't mounted. */ 1071 /* Either nm starts with /, or drive isn't mounted. */
1072 adir = alloca (4); 1072 adir = alloca (4);
1073 adir[0] = DRIVE_LETTER (drive); 1073 adir[0] = DRIVE_LETTER (drive);
1074 adir[1] = ':'; 1074 adir[1] = ':';
@@ -1080,11 +1080,11 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1080#endif /* DOS_NT */ 1080#endif /* DOS_NT */
1081 1081
1082 /* Finally, if no prefix has been specified and nm is not absolute, 1082 /* Finally, if no prefix has been specified and nm is not absolute,
1083 then it must be expanded relative to default_directory. */ 1083 then it must be expanded relative to default_directory. */
1084 1084
1085 if (1 1085 if (1
1086#ifndef DOS_NT 1086#ifndef DOS_NT
1087 /* /... alone is not absolute on DOS and Windows. */ 1087 /* /... alone is not absolute on DOS and Windows. */
1088 && !IS_DIRECTORY_SEP (nm[0]) 1088 && !IS_DIRECTORY_SEP (nm[0])
1089#endif 1089#endif
1090#ifdef WINDOWSNT 1090#ifdef WINDOWSNT
@@ -1106,7 +1106,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1106#ifdef DOS_NT 1106#ifdef DOS_NT
1107 if (newdir) 1107 if (newdir)
1108 { 1108 {
1109 /* First ensure newdir is an absolute name. */ 1109 /* First ensure newdir is an absolute name. */
1110 if ( 1110 if (
1111 /* Detect MSDOS file names with drive specifiers. */ 1111 /* Detect MSDOS file names with drive specifiers. */
1112 ! (IS_DRIVE (newdir[0]) 1112 ! (IS_DRIVE (newdir[0])
@@ -1121,7 +1121,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1121 Because of the admonition against calling expand-file-name 1121 Because of the admonition against calling expand-file-name
1122 when we have pointers into lisp strings, we accomplish this 1122 when we have pointers into lisp strings, we accomplish this
1123 indirectly by prepending newdir to nm if necessary, and using 1123 indirectly by prepending newdir to nm if necessary, and using
1124 cwd (or the wd of newdir's drive) as the new newdir. */ 1124 cwd (or the wd of newdir's drive) as the new newdir. */
1125 char *adir; 1125 char *adir;
1126 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) 1126 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1]))
1127 { 1127 {
@@ -1146,7 +1146,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1146 newdir = adir; 1146 newdir = adir;
1147 } 1147 }
1148 1148
1149 /* Strip off drive name from prefix, if present. */ 1149 /* Strip off drive name from prefix, if present. */
1150 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) 1150 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1]))
1151 { 1151 {
1152 drive = newdir[0]; 1152 drive = newdir[0];
@@ -1196,7 +1196,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1196 else 1196 else
1197 tlen = 0; 1197 tlen = 0;
1198 1198
1199 /* Now concatenate the directory and name to new space in the stack frame */ 1199 /* Now concatenate the directory and name to new space in the stack frame. */
1200 tlen += strlen (nm) + 1; 1200 tlen += strlen (nm) + 1;
1201#ifdef DOS_NT 1201#ifdef DOS_NT
1202 /* Reserve space for drive specifier and escape prefix, since either 1202 /* Reserve space for drive specifier and escape prefix, since either
@@ -1292,7 +1292,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1292 } 1292 }
1293 1293
1294#ifdef DOS_NT 1294#ifdef DOS_NT
1295 /* At last, set drive name. */ 1295 /* At last, set drive name. */
1296#ifdef WINDOWSNT 1296#ifdef WINDOWSNT
1297 /* Except for network file name. */ 1297 /* Except for network file name. */
1298 if (!(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]))) 1298 if (!(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1])))
@@ -1320,7 +1320,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1320 and perhaps call the corresponding file handler. This is needed 1320 and perhaps call the corresponding file handler. This is needed
1321 for filenames such as "/foo/../user@host:/bar/../baz". Expanding 1321 for filenames such as "/foo/../user@host:/bar/../baz". Expanding
1322 the ".." component gives us "/user@host:/bar/../baz" which needs 1322 the ".." component gives us "/user@host:/bar/../baz" which needs
1323 to be expanded again. */ 1323 to be expanded again. */
1324 handler = Ffind_file_name_handler (result, Qexpand_file_name); 1324 handler = Ffind_file_name_handler (result, Qexpand_file_name);
1325 if (!NILP (handler)) 1325 if (!NILP (handler))
1326 { 1326 {
@@ -1396,7 +1396,7 @@ See also the function `substitute-in-file-name'.")
1396 } 1396 }
1397 } 1397 }
1398 1398
1399 /* Now determine directory to start with and put it in NEWDIR */ 1399 /* Now determine directory to start with and put it in NEWDIR. */
1400 1400
1401 newdir = 0; 1401 newdir = 0;
1402 1402
@@ -1409,17 +1409,17 @@ See also the function `substitute-in-file-name'.")
1409 } 1409 }
1410 else /* ~user/filename */ 1410 else /* ~user/filename */
1411 { 1411 {
1412 /* Get past ~ to user */ 1412 /* Get past ~ to user. */
1413 unsigned char *user = nm + 1; 1413 unsigned char *user = nm + 1;
1414 /* Find end of name. */ 1414 /* Find end of name. */
1415 unsigned char *ptr = (unsigned char *) strchr (user, '/'); 1415 unsigned char *ptr = (unsigned char *) strchr (user, '/');
1416 ptrdiff_t len = ptr ? ptr - user : strlen (user); 1416 ptrdiff_t len = ptr ? ptr - user : strlen (user);
1417 /* Copy the user name into temp storage. */ 1417 /* Copy the user name into temp storage. */
1418 o = (unsigned char *) alloca (len + 1); 1418 o = (unsigned char *) alloca (len + 1);
1419 memcpy (o, user, len); 1419 memcpy (o, user, len);
1420 o[len] = 0; 1420 o[len] = 0;
1421 1421
1422 /* Look up the user name. */ 1422 /* Look up the user name. */
1423 BLOCK_INPUT; 1423 BLOCK_INPUT;
1424 pw = (struct passwd *) getpwnam (o + 1); 1424 pw = (struct passwd *) getpwnam (o + 1);
1425 UNBLOCK_INPUT; 1425 UNBLOCK_INPUT;
@@ -1440,7 +1440,7 @@ See also the function `substitute-in-file-name'.")
1440 newdir = SDATA (defalt); 1440 newdir = SDATA (defalt);
1441 } 1441 }
1442 1442
1443 /* Now concatenate the directory and name to new space in the stack frame */ 1443 /* Now concatenate the directory and name to new space in the stack frame. */
1444 1444
1445 tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1; 1445 tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1;
1446 target = (unsigned char *) alloca (tlen); 1446 target = (unsigned char *) alloca (tlen);
@@ -1456,7 +1456,7 @@ See also the function `substitute-in-file-name'.")
1456 1456
1457 strcat (target, nm); 1457 strcat (target, nm);
1458 1458
1459 /* Now canonicalize by removing /. and /foo/.. if they appear */ 1459 /* Now canonicalize by removing /. and /foo/.. if they appear. */
1460 1460
1461 p = target; 1461 p = target;
1462 o = target; 1462 o = target;
@@ -1528,7 +1528,7 @@ search_embedded_absfilename (char *nm, char *endp)
1528 ) 1528 )
1529 { 1529 {
1530 for (s = p; *s && (!IS_DIRECTORY_SEP (*s)); s++); 1530 for (s = p; *s && (!IS_DIRECTORY_SEP (*s)); s++);
1531 if (p[0] == '~' && s > p + 1) /* we've got "/~something/" */ 1531 if (p[0] == '~' && s > p + 1) /* We've got "/~something/". */
1532 { 1532 {
1533 char *o = alloca (s - p + 1); 1533 char *o = alloca (s - p + 1);
1534 struct passwd *pw; 1534 struct passwd *pw;
@@ -1612,7 +1612,7 @@ those `/' is discarded. */)
1612 (make_specified_string (p, -1, endp - p, multibyte)); 1612 (make_specified_string (p, -1, endp - p, multibyte));
1613 1613
1614 /* See if any variables are substituted into the string 1614 /* See if any variables are substituted into the string
1615 and find the total length of their values in `total' */ 1615 and find the total length of their values in `total'. */
1616 1616
1617 for (p = nm; p != endp;) 1617 for (p = nm; p != endp;)
1618 if (*p != '$') 1618 if (*p != '$')
@@ -1624,7 +1624,7 @@ those `/' is discarded. */)
1624 goto badsubst; 1624 goto badsubst;
1625 else if (*p == '$') 1625 else if (*p == '$')
1626 { 1626 {
1627 /* "$$" means a single "$" */ 1627 /* "$$" means a single "$". */
1628 p++; 1628 p++;
1629 total -= 1; 1629 total -= 1;
1630 substituted = 1; 1630 substituted = 1;
@@ -1644,7 +1644,7 @@ those `/' is discarded. */)
1644 s = p; 1644 s = p;
1645 } 1645 }
1646 1646
1647 /* Copy out the variable name */ 1647 /* Copy out the variable name. */
1648 target = (char *) alloca (s - o + 1); 1648 target = (char *) alloca (s - o + 1);
1649 strncpy (target, o, s - o); 1649 strncpy (target, o, s - o);
1650 target[s - o] = 0; 1650 target[s - o] = 0;
@@ -1652,7 +1652,7 @@ those `/' is discarded. */)
1652 strupr (target); /* $home == $HOME etc. */ 1652 strupr (target); /* $home == $HOME etc. */
1653#endif /* DOS_NT */ 1653#endif /* DOS_NT */
1654 1654
1655 /* Get variable value */ 1655 /* Get variable value. */
1656 o = egetenv (target); 1656 o = egetenv (target);
1657 if (o) 1657 if (o)
1658 { 1658 {
@@ -1674,12 +1674,12 @@ those `/' is discarded. */)
1674 if (!substituted) 1674 if (!substituted)
1675 return filename; 1675 return filename;
1676 1676
1677 /* If substitution required, recopy the string and do it */ 1677 /* If substitution required, recopy the string and do it. */
1678 /* Make space in stack frame for the new copy */ 1678 /* Make space in stack frame for the new copy. */
1679 xnm = (char *) alloca (SBYTES (filename) + total + 1); 1679 xnm = (char *) alloca (SBYTES (filename) + total + 1);
1680 x = xnm; 1680 x = xnm;
1681 1681
1682 /* Copy the rest of the name through, replacing $ constructs with values */ 1682 /* Copy the rest of the name through, replacing $ constructs with values. */
1683 for (p = nm; *p;) 1683 for (p = nm; *p;)
1684 if (*p != '$') 1684 if (*p != '$')
1685 *x++ = *p++; 1685 *x++ = *p++;
@@ -1707,7 +1707,7 @@ those `/' is discarded. */)
1707 s = p; 1707 s = p;
1708 } 1708 }
1709 1709
1710 /* Copy out the variable name */ 1710 /* Copy out the variable name. */
1711 target = (char *) alloca (s - o + 1); 1711 target = (char *) alloca (s - o + 1);
1712 strncpy (target, o, s - o); 1712 strncpy (target, o, s - o);
1713 target[s - o] = 0; 1713 target[s - o] = 0;
@@ -1715,7 +1715,7 @@ those `/' is discarded. */)
1715 strupr (target); /* $home == $HOME etc. */ 1715 strupr (target); /* $home == $HOME etc. */
1716#endif /* DOS_NT */ 1716#endif /* DOS_NT */
1717 1717
1718 /* Get variable value */ 1718 /* Get variable value. */
1719 o = egetenv (target); 1719 o = egetenv (target);
1720 if (!o) 1720 if (!o)
1721 { 1721 {
@@ -1777,7 +1777,7 @@ expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
1777 stat behaves differently depending! */ 1777 stat behaves differently depending! */
1778 if (SCHARS (absname) > 1 1778 if (SCHARS (absname) > 1
1779 && IS_DIRECTORY_SEP (SREF (absname, SBYTES (absname) - 1)) 1779 && IS_DIRECTORY_SEP (SREF (absname, SBYTES (absname) - 1))
1780 && !IS_DEVICE_SEP (SREF (absname, SBYTES (absname)-2))) 1780 && !IS_DEVICE_SEP (SREF (absname, SBYTES (absname) - 2)))
1781 /* We cannot take shortcuts; they might be wrong for magic file names. */ 1781 /* We cannot take shortcuts; they might be wrong for magic file names. */
1782 absname = Fdirectory_file_name (absname); 1782 absname = Fdirectory_file_name (absname);
1783 return absname; 1783 return absname;
@@ -1805,7 +1805,7 @@ barf_or_query_if_file_exists (Lisp_Object absname, const char *querystring,
1805 1805
1806 encoded_filename = ENCODE_FILE (absname); 1806 encoded_filename = ENCODE_FILE (absname);
1807 1807
1808 /* stat is a good way to tell whether the file exists, 1808 /* `stat' is a good way to tell whether the file exists,
1809 regardless of what access permissions it has. */ 1809 regardless of what access permissions it has. */
1810 if (lstat (SSDATA (encoded_filename), &statbuf) >= 0) 1810 if (lstat (SSDATA (encoded_filename), &statbuf) >= 0)
1811 { 1811 {
@@ -1867,12 +1867,12 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
1867 (Lisp_Object file, Lisp_Object newname, Lisp_Object ok_if_already_exists, Lisp_Object keep_time, Lisp_Object preserve_uid_gid, Lisp_Object preserve_selinux_context) 1867 (Lisp_Object file, Lisp_Object newname, Lisp_Object ok_if_already_exists, Lisp_Object keep_time, Lisp_Object preserve_uid_gid, Lisp_Object preserve_selinux_context)
1868{ 1868{
1869 int ifd, ofd; 1869 int ifd, ofd;
1870 EMACS_INT n; 1870 int n;
1871 char buf[16 * 1024]; 1871 char buf[16 * 1024];
1872 struct stat st, out_st; 1872 struct stat st, out_st;
1873 Lisp_Object handler; 1873 Lisp_Object handler;
1874 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1874 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1875 int count = SPECPDL_INDEX (); 1875 ptrdiff_t count = SPECPDL_INDEX ();
1876 int input_file_statable_p; 1876 int input_file_statable_p;
1877 Lisp_Object encoded_file, encoded_newname; 1877 Lisp_Object encoded_file, encoded_newname;
1878#if HAVE_LIBSELINUX 1878#if HAVE_LIBSELINUX
@@ -2265,7 +2265,7 @@ This is what happens in interactive use with M-x. */)
2265 { 2265 {
2266 if (errno == EXDEV) 2266 if (errno == EXDEV)
2267 { 2267 {
2268 int count; 2268 ptrdiff_t count;
2269 symlink_target = Ffile_symlink_p (file); 2269 symlink_target = Ffile_symlink_p (file);
2270 if (! NILP (symlink_target)) 2270 if (! NILP (symlink_target))
2271 Fmake_symbolic_link (symlink_target, newname, 2271 Fmake_symbolic_link (symlink_target, newname,
@@ -3130,6 +3130,8 @@ otherwise, if FILE2 does not exist, the answer is t. */)
3130#ifndef READ_BUF_SIZE 3130#ifndef READ_BUF_SIZE
3131#define READ_BUF_SIZE (64 << 10) 3131#define READ_BUF_SIZE (64 << 10)
3132#endif 3132#endif
3133/* Some buffer offsets are stored in 'int' variables. */
3134verify (READ_BUF_SIZE <= INT_MAX);
3133 3135
3134/* This function is called after Lisp functions to decide a coding 3136/* This function is called after Lisp functions to decide a coding
3135 system are called, or when they cause an error. Before they are 3137 system are called, or when they cause an error. Before they are
@@ -3174,8 +3176,8 @@ decide_coding_unwind (Lisp_Object unwind_data)
3174/* Used to pass values from insert-file-contents to read_non_regular. */ 3176/* Used to pass values from insert-file-contents to read_non_regular. */
3175 3177
3176static int non_regular_fd; 3178static int non_regular_fd;
3177static EMACS_INT non_regular_inserted; 3179static ptrdiff_t non_regular_inserted;
3178static EMACS_INT non_regular_nbytes; 3180static int non_regular_nbytes;
3179 3181
3180 3182
3181/* Read from a non-regular file. 3183/* Read from a non-regular file.
@@ -3186,7 +3188,7 @@ static EMACS_INT non_regular_nbytes;
3186static Lisp_Object 3188static Lisp_Object
3187read_non_regular (Lisp_Object ignore) 3189read_non_regular (Lisp_Object ignore)
3188{ 3190{
3189 EMACS_INT nbytes; 3191 int nbytes;
3190 3192
3191 immediate_quit = 1; 3193 immediate_quit = 1;
3192 QUIT; 3194 QUIT;
@@ -3251,16 +3253,16 @@ variable `last-coding-system-used' to the coding system actually used. */)
3251{ 3253{
3252 struct stat st; 3254 struct stat st;
3253 register int fd; 3255 register int fd;
3254 EMACS_INT inserted = 0; 3256 ptrdiff_t inserted = 0;
3255 int nochange = 0; 3257 int nochange = 0;
3256 register EMACS_INT how_much; 3258 register ptrdiff_t how_much;
3257 off_t beg_offset, end_offset; 3259 off_t beg_offset, end_offset;
3258 register EMACS_INT unprocessed; 3260 register int unprocessed;
3259 int count = SPECPDL_INDEX (); 3261 ptrdiff_t count = SPECPDL_INDEX ();
3260 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 3262 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3261 Lisp_Object handler, val, insval, orig_filename, old_undo; 3263 Lisp_Object handler, val, insval, orig_filename, old_undo;
3262 Lisp_Object p; 3264 Lisp_Object p;
3263 EMACS_INT total = 0; 3265 ptrdiff_t total = 0;
3264 int not_regular = 0; 3266 int not_regular = 0;
3265 int save_errno = 0; 3267 int save_errno = 0;
3266 char read_buf[READ_BUF_SIZE]; 3268 char read_buf[READ_BUF_SIZE];
@@ -3301,7 +3303,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
3301 { 3303 {
3302 val = call6 (handler, Qinsert_file_contents, filename, 3304 val = call6 (handler, Qinsert_file_contents, filename,
3303 visit, beg, end, replace); 3305 visit, beg, end, replace);
3304 if (CONSP (val) && CONSP (XCDR (val))) 3306 if (CONSP (val) && CONSP (XCDR (val))
3307 && RANGED_INTEGERP (0, XCAR (XCDR (val)), ZV - PT))
3305 inserted = XINT (XCAR (XCDR (val))); 3308 inserted = XINT (XCAR (XCDR (val)));
3306 goto handled; 3309 goto handled;
3307 } 3310 }
@@ -3455,7 +3458,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3455 We assume that the 1K-byte and 3K-byte for heading 3458 We assume that the 1K-byte and 3K-byte for heading
3456 and tailing respectively are sufficient for this 3459 and tailing respectively are sufficient for this
3457 purpose. */ 3460 purpose. */
3458 EMACS_INT nread; 3461 int nread;
3459 3462
3460 if (st.st_size <= (1024 * 4)) 3463 if (st.st_size <= (1024 * 4))
3461 nread = emacs_read (fd, read_buf, 1024 * 4); 3464 nread = emacs_read (fd, read_buf, 1024 * 4);
@@ -3565,9 +3568,9 @@ variable `last-coding-system-used' to the coding system actually used. */)
3565 /* same_at_start and same_at_end count bytes, 3568 /* same_at_start and same_at_end count bytes,
3566 because file access counts bytes 3569 because file access counts bytes
3567 and BEG and END count bytes. */ 3570 and BEG and END count bytes. */
3568 EMACS_INT same_at_start = BEGV_BYTE; 3571 ptrdiff_t same_at_start = BEGV_BYTE;
3569 EMACS_INT same_at_end = ZV_BYTE; 3572 ptrdiff_t same_at_end = ZV_BYTE;
3570 EMACS_INT overlap; 3573 ptrdiff_t overlap;
3571 /* There is still a possibility we will find the need to do code 3574 /* There is still a possibility we will find the need to do code
3572 conversion. If that happens, we set this variable to 1 to 3575 conversion. If that happens, we set this variable to 1 to
3573 give up on handling REPLACE in the optimized way. */ 3576 give up on handling REPLACE in the optimized way. */
@@ -3586,7 +3589,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3586 match the text at the beginning of the buffer. */ 3589 match the text at the beginning of the buffer. */
3587 while (1) 3590 while (1)
3588 { 3591 {
3589 EMACS_INT nread, bufpos; 3592 int nread, bufpos;
3590 3593
3591 nread = emacs_read (fd, buffer, sizeof buffer); 3594 nread = emacs_read (fd, buffer, sizeof buffer);
3592 if (nread < 0) 3595 if (nread < 0)
@@ -3695,7 +3698,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3695 3698
3696 if (! giveup_match_end) 3699 if (! giveup_match_end)
3697 { 3700 {
3698 EMACS_INT temp; 3701 ptrdiff_t temp;
3699 3702
3700 /* We win! We can handle REPLACE the optimized way. */ 3703 /* We win! We can handle REPLACE the optimized way. */
3701 3704
@@ -3749,16 +3752,16 @@ variable `last-coding-system-used' to the coding system actually used. */)
3749 in a more optimized way. */ 3752 in a more optimized way. */
3750 if (!NILP (replace) && ! replace_handled && BEGV < ZV) 3753 if (!NILP (replace) && ! replace_handled && BEGV < ZV)
3751 { 3754 {
3752 EMACS_INT same_at_start = BEGV_BYTE; 3755 ptrdiff_t same_at_start = BEGV_BYTE;
3753 EMACS_INT same_at_end = ZV_BYTE; 3756 ptrdiff_t same_at_end = ZV_BYTE;
3754 EMACS_INT same_at_start_charpos; 3757 ptrdiff_t same_at_start_charpos;
3755 EMACS_INT inserted_chars; 3758 ptrdiff_t inserted_chars;
3756 EMACS_INT overlap; 3759 ptrdiff_t overlap;
3757 EMACS_INT bufpos; 3760 ptrdiff_t bufpos;
3758 unsigned char *decoded; 3761 unsigned char *decoded;
3759 EMACS_INT temp; 3762 ptrdiff_t temp;
3760 EMACS_INT this = 0; 3763 ptrdiff_t this = 0;
3761 int this_count = SPECPDL_INDEX (); 3764 ptrdiff_t this_count = SPECPDL_INDEX ();
3762 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3765 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3763 Lisp_Object conversion_buffer; 3766 Lisp_Object conversion_buffer;
3764 struct gcpro gcpro1; 3767 struct gcpro gcpro1;
@@ -3783,8 +3786,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3783 /* We read one bunch by one (READ_BUF_SIZE bytes) to allow 3786 /* We read one bunch by one (READ_BUF_SIZE bytes) to allow
3784 quitting while reading a huge while. */ 3787 quitting while reading a huge while. */
3785 /* `try'' is reserved in some compilers (Microsoft C). */ 3788 /* `try'' is reserved in some compilers (Microsoft C). */
3786 EMACS_INT trytry = min (total - how_much, 3789 int trytry = min (total - how_much, READ_BUF_SIZE - unprocessed);
3787 READ_BUF_SIZE - unprocessed);
3788 3790
3789 /* Allow quitting out of the actual I/O. */ 3791 /* Allow quitting out of the actual I/O. */
3790 immediate_quit = 1; 3792 immediate_quit = 1;
@@ -3975,13 +3977,13 @@ variable `last-coding-system-used' to the coding system actually used. */)
3975 /* Here, we don't do code conversion in the loop. It is done by 3977 /* Here, we don't do code conversion in the loop. It is done by
3976 decode_coding_gap after all data are read into the buffer. */ 3978 decode_coding_gap after all data are read into the buffer. */
3977 { 3979 {
3978 EMACS_INT gap_size = GAP_SIZE; 3980 ptrdiff_t gap_size = GAP_SIZE;
3979 3981
3980 while (how_much < total) 3982 while (how_much < total)
3981 { 3983 {
3982 /* try is reserved in some compilers (Microsoft C) */ 3984 /* try is reserved in some compilers (Microsoft C) */
3983 EMACS_INT trytry = min (total - how_much, READ_BUF_SIZE); 3985 int trytry = min (total - how_much, READ_BUF_SIZE);
3984 EMACS_INT this; 3986 ptrdiff_t this;
3985 3987
3986 if (not_regular) 3988 if (not_regular)
3987 { 3989 {
@@ -4100,7 +4102,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
4100 care of marker adjustment. By this way, we can run Lisp 4102 care of marker adjustment. By this way, we can run Lisp
4101 program safely before decoding the inserted text. */ 4103 program safely before decoding the inserted text. */
4102 Lisp_Object unwind_data; 4104 Lisp_Object unwind_data;
4103 int count1 = SPECPDL_INDEX (); 4105 ptrdiff_t count1 = SPECPDL_INDEX ();
4104 4106
4105 unwind_data = Fcons (BVAR (current_buffer, enable_multibyte_characters), 4107 unwind_data = Fcons (BVAR (current_buffer, enable_multibyte_characters),
4106 Fcons (BVAR (current_buffer, undo_list), 4108 Fcons (BVAR (current_buffer, undo_list),
@@ -4231,7 +4233,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
4231 visit); 4233 visit);
4232 if (! NILP (insval)) 4234 if (! NILP (insval))
4233 { 4235 {
4234 CHECK_NUMBER (insval); 4236 if (! RANGED_INTEGERP (0, insval, ZV - PT))
4237 wrong_type_argument (intern ("inserted-chars"), insval);
4235 inserted = XFASTINT (insval); 4238 inserted = XFASTINT (insval);
4236 } 4239 }
4237 } 4240 }
@@ -4240,8 +4243,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
4240 if (inserted > 0) 4243 if (inserted > 0)
4241 { 4244 {
4242 /* Don't run point motion or modification hooks when decoding. */ 4245 /* Don't run point motion or modification hooks when decoding. */
4243 int count1 = SPECPDL_INDEX (); 4246 ptrdiff_t count1 = SPECPDL_INDEX ();
4244 EMACS_INT old_inserted = inserted; 4247 ptrdiff_t old_inserted = inserted;
4245 specbind (Qinhibit_point_motion_hooks, Qt); 4248 specbind (Qinhibit_point_motion_hooks, Qt);
4246 specbind (Qinhibit_modification_hooks, Qt); 4249 specbind (Qinhibit_modification_hooks, Qt);
4247 4250
@@ -4253,7 +4256,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
4253 { 4256 {
4254 insval = call3 (Qformat_decode, 4257 insval = call3 (Qformat_decode,
4255 Qnil, make_number (inserted), visit); 4258 Qnil, make_number (inserted), visit);
4256 CHECK_NUMBER (insval); 4259 if (! RANGED_INTEGERP (0, insval, ZV - PT))
4260 wrong_type_argument (intern ("inserted-chars"), insval);
4257 inserted = XFASTINT (insval); 4261 inserted = XFASTINT (insval);
4258 } 4262 }
4259 else 4263 else
@@ -4267,15 +4271,16 @@ variable `last-coding-system-used' to the coding system actually used. */)
4267 Hence we temporarily save `point' and `inserted' here and 4271 Hence we temporarily save `point' and `inserted' here and
4268 restore `point' iff format-decode did not insert or delete 4272 restore `point' iff format-decode did not insert or delete
4269 any text. Otherwise we leave `point' at point-min. */ 4273 any text. Otherwise we leave `point' at point-min. */
4270 EMACS_INT opoint = PT; 4274 ptrdiff_t opoint = PT;
4271 EMACS_INT opoint_byte = PT_BYTE; 4275 ptrdiff_t opoint_byte = PT_BYTE;
4272 EMACS_INT oinserted = ZV - BEGV; 4276 ptrdiff_t oinserted = ZV - BEGV;
4273 int ochars_modiff = CHARS_MODIFF; 4277 EMACS_INT ochars_modiff = CHARS_MODIFF;
4274 4278
4275 TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); 4279 TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE);
4276 insval = call3 (Qformat_decode, 4280 insval = call3 (Qformat_decode,
4277 Qnil, make_number (oinserted), visit); 4281 Qnil, make_number (oinserted), visit);
4278 CHECK_NUMBER (insval); 4282 if (! RANGED_INTEGERP (0, insval, ZV - PT))
4283 wrong_type_argument (intern ("inserted-chars"), insval);
4279 if (ochars_modiff == CHARS_MODIFF) 4284 if (ochars_modiff == CHARS_MODIFF)
4280 /* format_decode didn't modify buffer's characters => move 4285 /* format_decode didn't modify buffer's characters => move
4281 point back to position before inserted text and leave 4286 point back to position before inserted text and leave
@@ -4297,7 +4302,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
4297 insval = call1 (XCAR (p), make_number (inserted)); 4302 insval = call1 (XCAR (p), make_number (inserted));
4298 if (!NILP (insval)) 4303 if (!NILP (insval))
4299 { 4304 {
4300 CHECK_NUMBER (insval); 4305 if (! RANGED_INTEGERP (0, insval, ZV - PT))
4306 wrong_type_argument (intern ("inserted-chars"), insval);
4301 inserted = XFASTINT (insval); 4307 inserted = XFASTINT (insval);
4302 } 4308 }
4303 } 4309 }
@@ -4305,16 +4311,17 @@ variable `last-coding-system-used' to the coding system actually used. */)
4305 { 4311 {
4306 /* For the rationale of this see the comment on 4312 /* For the rationale of this see the comment on
4307 format-decode above. */ 4313 format-decode above. */
4308 EMACS_INT opoint = PT; 4314 ptrdiff_t opoint = PT;
4309 EMACS_INT opoint_byte = PT_BYTE; 4315 ptrdiff_t opoint_byte = PT_BYTE;
4310 EMACS_INT oinserted = ZV - BEGV; 4316 ptrdiff_t oinserted = ZV - BEGV;
4311 int ochars_modiff = CHARS_MODIFF; 4317 EMACS_INT ochars_modiff = CHARS_MODIFF;
4312 4318
4313 TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); 4319 TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE);
4314 insval = call1 (XCAR (p), make_number (oinserted)); 4320 insval = call1 (XCAR (p), make_number (oinserted));
4315 if (!NILP (insval)) 4321 if (!NILP (insval))
4316 { 4322 {
4317 CHECK_NUMBER (insval); 4323 if (! RANGED_INTEGERP (0, insval, ZV - PT))
4324 wrong_type_argument (intern ("inserted-chars"), insval);
4318 if (ochars_modiff == CHARS_MODIFF) 4325 if (ochars_modiff == CHARS_MODIFF)
4319 /* after_insert_file_functions didn't modify 4326 /* after_insert_file_functions didn't modify
4320 buffer's characters => move point back to 4327 buffer's characters => move point back to
@@ -4537,7 +4544,7 @@ This calls `write-region-annotate-functions' at the start, and
4537 int save_errno = 0; 4544 int save_errno = 0;
4538 const char *fn; 4545 const char *fn;
4539 struct stat st; 4546 struct stat st;
4540 int count = SPECPDL_INDEX (); 4547 ptrdiff_t count = SPECPDL_INDEX ();
4541 int count1; 4548 int count1;
4542 Lisp_Object handler; 4549 Lisp_Object handler;
4543 Lisp_Object visit_file; 4550 Lisp_Object visit_file;
@@ -4937,13 +4944,13 @@ build_annotations (Lisp_Object start, Lisp_Object end)
4937 The return value is negative in case of system call failure. */ 4944 The return value is negative in case of system call failure. */
4938 4945
4939static int 4946static int
4940a_write (int desc, Lisp_Object string, EMACS_INT pos, 4947a_write (int desc, Lisp_Object string, ptrdiff_t pos,
4941 register EMACS_INT nchars, Lisp_Object *annot, 4948 register ptrdiff_t nchars, Lisp_Object *annot,
4942 struct coding_system *coding) 4949 struct coding_system *coding)
4943{ 4950{
4944 Lisp_Object tem; 4951 Lisp_Object tem;
4945 EMACS_INT nextpos; 4952 ptrdiff_t nextpos;
4946 EMACS_INT lastpos = pos + nchars; 4953 ptrdiff_t lastpos = pos + nchars;
4947 4954
4948 while (NILP (*annot) || CONSP (*annot)) 4955 while (NILP (*annot) || CONSP (*annot))
4949 { 4956 {
@@ -4983,7 +4990,7 @@ a_write (int desc, Lisp_Object string, EMACS_INT pos,
4983 are indexes to the string STRING. */ 4990 are indexes to the string STRING. */
4984 4991
4985static int 4992static int
4986e_write (int desc, Lisp_Object string, EMACS_INT start, EMACS_INT end, 4993e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end,
4987 struct coding_system *coding) 4994 struct coding_system *coding)
4988{ 4995{
4989 if (STRINGP (string)) 4996 if (STRINGP (string))
@@ -5015,8 +5022,8 @@ e_write (int desc, Lisp_Object string, EMACS_INT start, EMACS_INT end,
5015 } 5022 }
5016 else 5023 else
5017 { 5024 {
5018 EMACS_INT start_byte = CHAR_TO_BYTE (start); 5025 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
5019 EMACS_INT end_byte = CHAR_TO_BYTE (end); 5026 ptrdiff_t end_byte = CHAR_TO_BYTE (end);
5020 5027
5021 coding->src_multibyte = (end - start) < (end_byte - start_byte); 5028 coding->src_multibyte = (end - start) < (end_byte - start_byte);
5022 if (CODING_REQUIRE_ENCODING (coding)) 5029 if (CODING_REQUIRE_ENCODING (coding))
@@ -5302,7 +5309,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5302 int do_handled_files; 5309 int do_handled_files;
5303 Lisp_Object oquit; 5310 Lisp_Object oquit;
5304 FILE *stream = NULL; 5311 FILE *stream = NULL;
5305 int count = SPECPDL_INDEX (); 5312 ptrdiff_t count = SPECPDL_INDEX ();
5306 int orig_minibuffer_auto_raise = minibuffer_auto_raise; 5313 int orig_minibuffer_auto_raise = minibuffer_auto_raise;
5307 int old_message_p = 0; 5314 int old_message_p = 0;
5308 struct gcpro gcpro1, gcpro2; 5315 struct gcpro gcpro1, gcpro2;
diff --git a/src/floatfns.c b/src/floatfns.c
index 305c78cae63..eaa1b32eb17 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -484,31 +484,19 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
484 && INTEGERP (arg2) /* don't promote, if both are ints, and */ 484 && INTEGERP (arg2) /* don't promote, if both are ints, and */
485 && 0 <= XINT (arg2)) /* we are sure the result is not fractional */ 485 && 0 <= XINT (arg2)) /* we are sure the result is not fractional */
486 { /* this can be improved by pre-calculating */ 486 { /* this can be improved by pre-calculating */
487 EMACS_INT acc, x, y; /* some binary powers of x then accumulating */ 487 EMACS_INT y; /* some binary powers of x then accumulating */
488 EMACS_UINT acc, x; /* Unsigned so that overflow is well defined. */
488 Lisp_Object val; 489 Lisp_Object val;
489 490
490 x = XINT (arg1); 491 x = XINT (arg1);
491 y = XINT (arg2); 492 y = XINT (arg2);
492 acc = 1; 493 acc = (y & 1 ? x : 1);
493 494
494 if (y < 0) 495 while ((y >>= 1) != 0)
495 { 496 {
496 if (x == 1) 497 x *= x;
497 acc = 1; 498 if (y & 1)
498 else if (x == -1) 499 acc *= x;
499 acc = (y & 1) ? -1 : 1;
500 else
501 acc = 0;
502 }
503 else
504 {
505 while (y > 0)
506 {
507 if (y & 1)
508 acc *= x;
509 x *= x;
510 y >>= 1;
511 }
512 } 500 }
513 XSETINT (val, acc); 501 XSETINT (val, acc);
514 return val; 502 return val;
diff --git a/src/fns.c b/src/fns.c
index aa7284f7ce0..676e53ccbd8 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -246,8 +246,8 @@ If string STR1 is greater, the value is a positive number N;
246 N - 1 is the number of characters that match at the beginning. */) 246 N - 1 is the number of characters that match at the beginning. */)
247 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case) 247 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case)
248{ 248{
249 register EMACS_INT end1_char, end2_char; 249 register ptrdiff_t end1_char, end2_char;
250 register EMACS_INT i1, i1_byte, i2, i2_byte; 250 register ptrdiff_t i1, i1_byte, i2, i2_byte;
251 251
252 CHECK_STRING (str1); 252 CHECK_STRING (str1);
253 CHECK_STRING (str2); 253 CHECK_STRING (str2);
@@ -262,19 +262,23 @@ If string STR1 is greater, the value is a positive number N;
262 if (! NILP (end2)) 262 if (! NILP (end2))
263 CHECK_NATNUM (end2); 263 CHECK_NATNUM (end2);
264 264
265 i1 = XINT (start1);
266 i2 = XINT (start2);
267
268 i1_byte = string_char_to_byte (str1, i1);
269 i2_byte = string_char_to_byte (str2, i2);
270
271 end1_char = SCHARS (str1); 265 end1_char = SCHARS (str1);
272 if (! NILP (end1) && end1_char > XINT (end1)) 266 if (! NILP (end1) && end1_char > XINT (end1))
273 end1_char = XINT (end1); 267 end1_char = XINT (end1);
268 if (end1_char < XINT (start1))
269 args_out_of_range (str1, start1);
274 270
275 end2_char = SCHARS (str2); 271 end2_char = SCHARS (str2);
276 if (! NILP (end2) && end2_char > XINT (end2)) 272 if (! NILP (end2) && end2_char > XINT (end2))
277 end2_char = XINT (end2); 273 end2_char = XINT (end2);
274 if (end2_char < XINT (start2))
275 args_out_of_range (str2, start2);
276
277 i1 = XINT (start1);
278 i2 = XINT (start2);
279
280 i1_byte = string_char_to_byte (str1, i1);
281 i2_byte = string_char_to_byte (str2, i2);
278 282
279 while (i1 < end1_char && i2 < end2_char) 283 while (i1 < end1_char && i2 < end2_char)
280 { 284 {
@@ -337,8 +341,8 @@ Case is significant.
337Symbols are also allowed; their print names are used instead. */) 341Symbols are also allowed; their print names are used instead. */)
338 (register Lisp_Object s1, Lisp_Object s2) 342 (register Lisp_Object s1, Lisp_Object s2)
339{ 343{
340 register EMACS_INT end; 344 register ptrdiff_t end;
341 register EMACS_INT i1, i1_byte, i2, i2_byte; 345 register ptrdiff_t i1, i1_byte, i2, i2_byte;
342 346
343 if (SYMBOLP (s1)) 347 if (SYMBOLP (s1))
344 s1 = SYMBOL_NAME (s1); 348 s1 = SYMBOL_NAME (s1);
@@ -461,8 +465,8 @@ with the original. */)
461struct textprop_rec 465struct textprop_rec
462{ 466{
463 ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */ 467 ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */
464 EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ 468 ptrdiff_t from; /* refer to ARGS[argnum] (argument string) */
465 EMACS_INT to; /* refer to VAL (the target string) */ 469 ptrdiff_t to; /* refer to VAL (the target string) */
466}; 470};
467 471
468static Lisp_Object 472static Lisp_Object
@@ -472,8 +476,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
472 Lisp_Object val; 476 Lisp_Object val;
473 register Lisp_Object tail; 477 register Lisp_Object tail;
474 register Lisp_Object this; 478 register Lisp_Object this;
475 EMACS_INT toindex; 479 ptrdiff_t toindex;
476 EMACS_INT toindex_byte = 0; 480 ptrdiff_t toindex_byte = 0;
477 register EMACS_INT result_len; 481 register EMACS_INT result_len;
478 register EMACS_INT result_len_byte; 482 register EMACS_INT result_len_byte;
479 ptrdiff_t argnum; 483 ptrdiff_t argnum;
@@ -526,10 +530,10 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
526 { 530 {
527 /* We must count the number of bytes needed in the string 531 /* We must count the number of bytes needed in the string
528 as well as the number of characters. */ 532 as well as the number of characters. */
529 EMACS_INT i; 533 ptrdiff_t i;
530 Lisp_Object ch; 534 Lisp_Object ch;
531 int c; 535 int c;
532 EMACS_INT this_len_byte; 536 ptrdiff_t this_len_byte;
533 537
534 if (VECTORP (this) || COMPILEDP (this)) 538 if (VECTORP (this) || COMPILEDP (this))
535 for (i = 0; i < len; i++) 539 for (i = 0; i < len; i++)
@@ -538,6 +542,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
538 CHECK_CHARACTER (ch); 542 CHECK_CHARACTER (ch);
539 c = XFASTINT (ch); 543 c = XFASTINT (ch);
540 this_len_byte = CHAR_BYTES (c); 544 this_len_byte = CHAR_BYTES (c);
545 if (STRING_BYTES_BOUND - result_len_byte < this_len_byte)
546 string_overflow ();
541 result_len_byte += this_len_byte; 547 result_len_byte += this_len_byte;
542 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) 548 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
543 some_multibyte = 1; 549 some_multibyte = 1;
@@ -551,6 +557,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
551 CHECK_CHARACTER (ch); 557 CHECK_CHARACTER (ch);
552 c = XFASTINT (ch); 558 c = XFASTINT (ch);
553 this_len_byte = CHAR_BYTES (c); 559 this_len_byte = CHAR_BYTES (c);
560 if (STRING_BYTES_BOUND - result_len_byte < this_len_byte)
561 string_overflow ();
554 result_len_byte += this_len_byte; 562 result_len_byte += this_len_byte;
555 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) 563 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
556 some_multibyte = 1; 564 some_multibyte = 1;
@@ -560,17 +568,20 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
560 if (STRING_MULTIBYTE (this)) 568 if (STRING_MULTIBYTE (this))
561 { 569 {
562 some_multibyte = 1; 570 some_multibyte = 1;
563 result_len_byte += SBYTES (this); 571 this_len_byte = SBYTES (this);
564 } 572 }
565 else 573 else
566 result_len_byte += count_size_as_multibyte (SDATA (this), 574 this_len_byte = count_size_as_multibyte (SDATA (this),
567 SCHARS (this)); 575 SCHARS (this));
576 if (STRING_BYTES_BOUND - result_len_byte < this_len_byte)
577 string_overflow ();
578 result_len_byte += this_len_byte;
568 } 579 }
569 } 580 }
570 581
571 result_len += len; 582 result_len += len;
572 if (STRING_BYTES_BOUND < result_len) 583 if (MOST_POSITIVE_FIXNUM < result_len)
573 string_overflow (); 584 memory_full (SIZE_MAX);
574 } 585 }
575 586
576 if (! some_multibyte) 587 if (! some_multibyte)
@@ -603,9 +614,9 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
603 for (argnum = 0; argnum < nargs; argnum++) 614 for (argnum = 0; argnum < nargs; argnum++)
604 { 615 {
605 Lisp_Object thislen; 616 Lisp_Object thislen;
606 EMACS_INT thisleni = 0; 617 ptrdiff_t thisleni = 0;
607 register EMACS_INT thisindex = 0; 618 register ptrdiff_t thisindex = 0;
608 register EMACS_INT thisindex_byte = 0; 619 register ptrdiff_t thisindex_byte = 0;
609 620
610 this = args[argnum]; 621 this = args[argnum];
611 if (!CONSP (this)) 622 if (!CONSP (this))
@@ -615,7 +626,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
615 if (STRINGP (this) && STRINGP (val) 626 if (STRINGP (this) && STRINGP (val)
616 && STRING_MULTIBYTE (this) == some_multibyte) 627 && STRING_MULTIBYTE (this) == some_multibyte)
617 { 628 {
618 EMACS_INT thislen_byte = SBYTES (this); 629 ptrdiff_t thislen_byte = SBYTES (this);
619 630
620 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this)); 631 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
621 if (! NULL_INTERVAL_P (STRING_INTERVALS (this))) 632 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
@@ -716,7 +727,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
716 if (num_textprops > 0) 727 if (num_textprops > 0)
717 { 728 {
718 Lisp_Object props; 729 Lisp_Object props;
719 EMACS_INT last_to_end = -1; 730 ptrdiff_t last_to_end = -1;
720 731
721 for (argnum = 0; argnum < num_textprops; argnum++) 732 for (argnum = 0; argnum < num_textprops; argnum++)
722 { 733 {
@@ -740,8 +751,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
740} 751}
741 752
742static Lisp_Object string_char_byte_cache_string; 753static Lisp_Object string_char_byte_cache_string;
743static EMACS_INT string_char_byte_cache_charpos; 754static ptrdiff_t string_char_byte_cache_charpos;
744static EMACS_INT string_char_byte_cache_bytepos; 755static ptrdiff_t string_char_byte_cache_bytepos;
745 756
746void 757void
747clear_string_char_byte_cache (void) 758clear_string_char_byte_cache (void)
@@ -751,12 +762,12 @@ clear_string_char_byte_cache (void)
751 762
752/* Return the byte index corresponding to CHAR_INDEX in STRING. */ 763/* Return the byte index corresponding to CHAR_INDEX in STRING. */
753 764
754EMACS_INT 765ptrdiff_t
755string_char_to_byte (Lisp_Object string, EMACS_INT char_index) 766string_char_to_byte (Lisp_Object string, ptrdiff_t char_index)
756{ 767{
757 EMACS_INT i_byte; 768 ptrdiff_t i_byte;
758 EMACS_INT best_below, best_below_byte; 769 ptrdiff_t best_below, best_below_byte;
759 EMACS_INT best_above, best_above_byte; 770 ptrdiff_t best_above, best_above_byte;
760 771
761 best_below = best_below_byte = 0; 772 best_below = best_below_byte = 0;
762 best_above = SCHARS (string); 773 best_above = SCHARS (string);
@@ -811,12 +822,12 @@ string_char_to_byte (Lisp_Object string, EMACS_INT char_index)
811 822
812/* Return the character index corresponding to BYTE_INDEX in STRING. */ 823/* Return the character index corresponding to BYTE_INDEX in STRING. */
813 824
814EMACS_INT 825ptrdiff_t
815string_byte_to_char (Lisp_Object string, EMACS_INT byte_index) 826string_byte_to_char (Lisp_Object string, ptrdiff_t byte_index)
816{ 827{
817 EMACS_INT i, i_byte; 828 ptrdiff_t i, i_byte;
818 EMACS_INT best_below, best_below_byte; 829 ptrdiff_t best_below, best_below_byte;
819 EMACS_INT best_above, best_above_byte; 830 ptrdiff_t best_above, best_above_byte;
820 831
821 best_below = best_below_byte = 0; 832 best_below = best_below_byte = 0;
822 best_above = SCHARS (string); 833 best_above = SCHARS (string);
@@ -879,7 +890,7 @@ static Lisp_Object
879string_make_multibyte (Lisp_Object string) 890string_make_multibyte (Lisp_Object string)
880{ 891{
881 unsigned char *buf; 892 unsigned char *buf;
882 EMACS_INT nbytes; 893 ptrdiff_t nbytes;
883 Lisp_Object ret; 894 Lisp_Object ret;
884 USE_SAFE_ALLOCA; 895 USE_SAFE_ALLOCA;
885 896
@@ -912,7 +923,7 @@ Lisp_Object
912string_to_multibyte (Lisp_Object string) 923string_to_multibyte (Lisp_Object string)
913{ 924{
914 unsigned char *buf; 925 unsigned char *buf;
915 EMACS_INT nbytes; 926 ptrdiff_t nbytes;
916 Lisp_Object ret; 927 Lisp_Object ret;
917 USE_SAFE_ALLOCA; 928 USE_SAFE_ALLOCA;
918 929
@@ -941,7 +952,7 @@ string_to_multibyte (Lisp_Object string)
941Lisp_Object 952Lisp_Object
942string_make_unibyte (Lisp_Object string) 953string_make_unibyte (Lisp_Object string)
943{ 954{
944 EMACS_INT nchars; 955 ptrdiff_t nchars;
945 unsigned char *buf; 956 unsigned char *buf;
946 Lisp_Object ret; 957 Lisp_Object ret;
947 USE_SAFE_ALLOCA; 958 USE_SAFE_ALLOCA;
@@ -1006,7 +1017,7 @@ If STRING is multibyte and contains a character of charset
1006 1017
1007 if (STRING_MULTIBYTE (string)) 1018 if (STRING_MULTIBYTE (string))
1008 { 1019 {
1009 EMACS_INT bytes = SBYTES (string); 1020 ptrdiff_t bytes = SBYTES (string);
1010 unsigned char *str = (unsigned char *) xmalloc (bytes); 1021 unsigned char *str = (unsigned char *) xmalloc (bytes);
1011 1022
1012 memcpy (str, SDATA (string), bytes); 1023 memcpy (str, SDATA (string), bytes);
@@ -1039,7 +1050,7 @@ If you're not sure, whether to use `string-as-multibyte' or
1039 if (! STRING_MULTIBYTE (string)) 1050 if (! STRING_MULTIBYTE (string))
1040 { 1051 {
1041 Lisp_Object new_string; 1052 Lisp_Object new_string;
1042 EMACS_INT nchars, nbytes; 1053 ptrdiff_t nchars, nbytes;
1043 1054
1044 parse_str_as_multibyte (SDATA (string), 1055 parse_str_as_multibyte (SDATA (string),
1045 SBYTES (string), 1056 SBYTES (string),
@@ -1088,12 +1099,12 @@ an error is signaled. */)
1088 1099
1089 if (STRING_MULTIBYTE (string)) 1100 if (STRING_MULTIBYTE (string))
1090 { 1101 {
1091 EMACS_INT chars = SCHARS (string); 1102 ptrdiff_t chars = SCHARS (string);
1092 unsigned char *str = (unsigned char *) xmalloc (chars); 1103 unsigned char *str = (unsigned char *) xmalloc (chars);
1093 EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0); 1104 ptrdiff_t converted = str_to_unibyte (SDATA (string), str, chars, 0);
1094 1105
1095 if (converted < chars) 1106 if (converted < chars)
1096 error ("Can't convert the %"pI"dth character to unibyte", converted); 1107 error ("Can't convert the %"pD"dth character to unibyte", converted);
1097 string = make_unibyte_string ((char *) str, chars); 1108 string = make_unibyte_string ((char *) str, chars);
1098 xfree (str); 1109 xfree (str);
1099 } 1110 }
@@ -1141,27 +1152,19 @@ value is a new vector that contains the elements between index FROM
1141 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1152 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1142{ 1153{
1143 Lisp_Object res; 1154 Lisp_Object res;
1144 EMACS_INT size; 1155 ptrdiff_t size;
1145 EMACS_INT size_byte = 0;
1146 EMACS_INT from_char, to_char; 1156 EMACS_INT from_char, to_char;
1147 EMACS_INT from_byte = 0, to_byte = 0;
1148 1157
1149 CHECK_VECTOR_OR_STRING (string); 1158 CHECK_VECTOR_OR_STRING (string);
1150 CHECK_NUMBER (from); 1159 CHECK_NUMBER (from);
1151 1160
1152 if (STRINGP (string)) 1161 if (STRINGP (string))
1153 { 1162 size = SCHARS (string);
1154 size = SCHARS (string);
1155 size_byte = SBYTES (string);
1156 }
1157 else 1163 else
1158 size = ASIZE (string); 1164 size = ASIZE (string);
1159 1165
1160 if (NILP (to)) 1166 if (NILP (to))
1161 { 1167 to_char = size;
1162 to_char = size;
1163 to_byte = size_byte;
1164 }
1165 else 1168 else
1166 { 1169 {
1167 CHECK_NUMBER (to); 1170 CHECK_NUMBER (to);
@@ -1169,23 +1172,20 @@ value is a new vector that contains the elements between index FROM
1169 to_char = XINT (to); 1172 to_char = XINT (to);
1170 if (to_char < 0) 1173 if (to_char < 0)
1171 to_char += size; 1174 to_char += size;
1172
1173 if (STRINGP (string))
1174 to_byte = string_char_to_byte (string, to_char);
1175 } 1175 }
1176 1176
1177 from_char = XINT (from); 1177 from_char = XINT (from);
1178 if (from_char < 0) 1178 if (from_char < 0)
1179 from_char += size; 1179 from_char += size;
1180 if (STRINGP (string))
1181 from_byte = string_char_to_byte (string, from_char);
1182
1183 if (!(0 <= from_char && from_char <= to_char && to_char <= size)) 1180 if (!(0 <= from_char && from_char <= to_char && to_char <= size))
1184 args_out_of_range_3 (string, make_number (from_char), 1181 args_out_of_range_3 (string, make_number (from_char),
1185 make_number (to_char)); 1182 make_number (to_char));
1186 1183
1187 if (STRINGP (string)) 1184 if (STRINGP (string))
1188 { 1185 {
1186 ptrdiff_t to_byte =
1187 (NILP (to) ? SBYTES (string) : string_char_to_byte (string, to_char));
1188 ptrdiff_t from_byte = string_char_to_byte (string, from_char);
1189 res = make_specified_string (SSDATA (string) + from_byte, 1189 res = make_specified_string (SSDATA (string) + from_byte,
1190 to_char - from_char, to_byte - from_byte, 1190 to_char - from_char, to_byte - from_byte,
1191 STRING_MULTIBYTE (string)); 1191 STRING_MULTIBYTE (string));
@@ -1209,47 +1209,41 @@ If FROM or TO is negative, it counts from the end.
1209With one argument, just copy STRING without its properties. */) 1209With one argument, just copy STRING without its properties. */)
1210 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1210 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1211{ 1211{
1212 EMACS_INT size, size_byte; 1212 ptrdiff_t size;
1213 EMACS_INT from_char, to_char; 1213 EMACS_INT from_char, to_char;
1214 EMACS_INT from_byte, to_byte; 1214 ptrdiff_t from_byte, to_byte;
1215 1215
1216 CHECK_STRING (string); 1216 CHECK_STRING (string);
1217 1217
1218 size = SCHARS (string); 1218 size = SCHARS (string);
1219 size_byte = SBYTES (string);
1220 1219
1221 if (NILP (from)) 1220 if (NILP (from))
1222 from_char = from_byte = 0; 1221 from_char = 0;
1223 else 1222 else
1224 { 1223 {
1225 CHECK_NUMBER (from); 1224 CHECK_NUMBER (from);
1226 from_char = XINT (from); 1225 from_char = XINT (from);
1227 if (from_char < 0) 1226 if (from_char < 0)
1228 from_char += size; 1227 from_char += size;
1229
1230 from_byte = string_char_to_byte (string, from_char);
1231 } 1228 }
1232 1229
1233 if (NILP (to)) 1230 if (NILP (to))
1234 { 1231 to_char = size;
1235 to_char = size;
1236 to_byte = size_byte;
1237 }
1238 else 1232 else
1239 { 1233 {
1240 CHECK_NUMBER (to); 1234 CHECK_NUMBER (to);
1241
1242 to_char = XINT (to); 1235 to_char = XINT (to);
1243 if (to_char < 0) 1236 if (to_char < 0)
1244 to_char += size; 1237 to_char += size;
1245
1246 to_byte = string_char_to_byte (string, to_char);
1247 } 1238 }
1248 1239
1249 if (!(0 <= from_char && from_char <= to_char && to_char <= size)) 1240 if (!(0 <= from_char && from_char <= to_char && to_char <= size))
1250 args_out_of_range_3 (string, make_number (from_char), 1241 args_out_of_range_3 (string, make_number (from_char),
1251 make_number (to_char)); 1242 make_number (to_char));
1252 1243
1244 from_byte = NILP (from) ? 0 : string_char_to_byte (string, from_char);
1245 to_byte =
1246 NILP (to) ? SBYTES (string) : string_char_to_byte (string, to_char);
1253 return make_specified_string (SSDATA (string) + from_byte, 1247 return make_specified_string (SSDATA (string) + from_byte,
1254 to_char - from_char, to_byte - from_byte, 1248 to_char - from_char, to_byte - from_byte,
1255 STRING_MULTIBYTE (string)); 1249 STRING_MULTIBYTE (string));
@@ -1259,11 +1253,11 @@ With one argument, just copy STRING without its properties. */)
1259 both in characters and in bytes. */ 1253 both in characters and in bytes. */
1260 1254
1261Lisp_Object 1255Lisp_Object
1262substring_both (Lisp_Object string, EMACS_INT from, EMACS_INT from_byte, 1256substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte,
1263 EMACS_INT to, EMACS_INT to_byte) 1257 ptrdiff_t to, ptrdiff_t to_byte)
1264{ 1258{
1265 Lisp_Object res; 1259 Lisp_Object res;
1266 EMACS_INT size; 1260 ptrdiff_t size;
1267 1261
1268 CHECK_VECTOR_OR_STRING (string); 1262 CHECK_VECTOR_OR_STRING (string);
1269 1263
@@ -1597,7 +1591,7 @@ to be sure of changing the value of `foo'. */)
1597{ 1591{
1598 if (VECTORP (seq)) 1592 if (VECTORP (seq))
1599 { 1593 {
1600 EMACS_INT i, n; 1594 ptrdiff_t i, n;
1601 1595
1602 for (i = n = 0; i < ASIZE (seq); ++i) 1596 for (i = n = 0; i < ASIZE (seq); ++i)
1603 if (NILP (Fequal (AREF (seq, i), elt))) 1597 if (NILP (Fequal (AREF (seq, i), elt)))
@@ -1616,7 +1610,7 @@ to be sure of changing the value of `foo'. */)
1616 } 1610 }
1617 else if (STRINGP (seq)) 1611 else if (STRINGP (seq))
1618 { 1612 {
1619 EMACS_INT i, ibyte, nchars, nbytes, cbytes; 1613 ptrdiff_t i, ibyte, nchars, nbytes, cbytes;
1620 int c; 1614 int c;
1621 1615
1622 for (i = nchars = nbytes = ibyte = 0; 1616 for (i = nchars = nbytes = ibyte = 0;
@@ -1668,7 +1662,7 @@ to be sure of changing the value of `foo'. */)
1668 { 1662 {
1669 unsigned char *from = SDATA (seq) + ibyte; 1663 unsigned char *from = SDATA (seq) + ibyte;
1670 unsigned char *to = SDATA (tem) + nbytes; 1664 unsigned char *to = SDATA (tem) + nbytes;
1671 EMACS_INT n; 1665 ptrdiff_t n;
1672 1666
1673 ++nchars; 1667 ++nchars;
1674 nbytes += cbytes; 1668 nbytes += cbytes;
@@ -2075,7 +2069,7 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int
2075 case Lisp_Vectorlike: 2069 case Lisp_Vectorlike:
2076 { 2070 {
2077 register int i; 2071 register int i;
2078 EMACS_INT size = ASIZE (o1); 2072 ptrdiff_t size = ASIZE (o1);
2079 /* Pseudovectors have the type encoded in the size field, so this test 2073 /* Pseudovectors have the type encoded in the size field, so this test
2080 actually checks that the objects have the same type as well as the 2074 actually checks that the objects have the same type as well as the
2081 same size. */ 2075 same size. */
@@ -2142,7 +2136,7 @@ DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
2142ARRAY is a vector, string, char-table, or bool-vector. */) 2136ARRAY is a vector, string, char-table, or bool-vector. */)
2143 (Lisp_Object array, Lisp_Object item) 2137 (Lisp_Object array, Lisp_Object item)
2144{ 2138{
2145 register EMACS_INT size, idx; 2139 register ptrdiff_t size, idx;
2146 2140
2147 if (VECTORP (array)) 2141 if (VECTORP (array))
2148 { 2142 {
@@ -2170,7 +2164,7 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2170 { 2164 {
2171 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2165 unsigned char str[MAX_MULTIBYTE_LENGTH];
2172 int len = CHAR_STRING (charval, str); 2166 int len = CHAR_STRING (charval, str);
2173 EMACS_INT size_byte = SBYTES (array); 2167 ptrdiff_t size_byte = SBYTES (array);
2174 2168
2175 if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len) 2169 if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len)
2176 || SCHARS (array) * len != size_byte) 2170 || SCHARS (array) * len != size_byte)
@@ -2185,18 +2179,16 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2185 else if (BOOL_VECTOR_P (array)) 2179 else if (BOOL_VECTOR_P (array))
2186 { 2180 {
2187 register unsigned char *p = XBOOL_VECTOR (array)->data; 2181 register unsigned char *p = XBOOL_VECTOR (array)->data;
2188 EMACS_INT size_in_chars; 2182 size =
2189 size = XBOOL_VECTOR (array)->size; 2183 ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
2190 size_in_chars 2184 / BOOL_VECTOR_BITS_PER_CHAR);
2191 = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1)
2192 / BOOL_VECTOR_BITS_PER_CHAR);
2193 2185
2194 if (size_in_chars) 2186 if (size)
2195 { 2187 {
2196 memset (p, ! NILP (item) ? -1 : 0, size_in_chars); 2188 memset (p, ! NILP (item) ? -1 : 0, size);
2197 2189
2198 /* Clear any extraneous bits in the last byte. */ 2190 /* Clear any extraneous bits in the last byte. */
2199 p[size_in_chars - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; 2191 p[size - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2200 } 2192 }
2201 } 2193 }
2202 else 2194 else
@@ -2210,7 +2202,7 @@ DEFUN ("clear-string", Fclear_string, Sclear_string,
2210This makes STRING unibyte and may change its length. */) 2202This makes STRING unibyte and may change its length. */)
2211 (Lisp_Object string) 2203 (Lisp_Object string)
2212{ 2204{
2213 EMACS_INT len; 2205 ptrdiff_t len;
2214 CHECK_STRING (string); 2206 CHECK_STRING (string);
2215 len = SBYTES (string); 2207 len = SBYTES (string);
2216 memset (SDATA (string), 0, len); 2208 memset (SDATA (string), 0, len);
@@ -2320,12 +2312,12 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
2320 } 2312 }
2321 else if (STRINGP (seq)) 2313 else if (STRINGP (seq))
2322 { 2314 {
2323 EMACS_INT i_byte; 2315 ptrdiff_t i_byte;
2324 2316
2325 for (i = 0, i_byte = 0; i < leni;) 2317 for (i = 0, i_byte = 0; i < leni;)
2326 { 2318 {
2327 int c; 2319 int c;
2328 EMACS_INT i_before = i; 2320 ptrdiff_t i_before = i;
2329 2321
2330 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte); 2322 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte);
2331 XSETFASTINT (dummy, c); 2323 XSETFASTINT (dummy, c);
@@ -2358,7 +2350,8 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2358{ 2350{
2359 Lisp_Object len; 2351 Lisp_Object len;
2360 register EMACS_INT leni; 2352 register EMACS_INT leni;
2361 ptrdiff_t i, nargs; 2353 EMACS_INT nargs;
2354 ptrdiff_t i;
2362 register Lisp_Object *args; 2355 register Lisp_Object *args;
2363 struct gcpro gcpro1; 2356 struct gcpro gcpro1;
2364 Lisp_Object ret; 2357 Lisp_Object ret;
@@ -2645,7 +2638,7 @@ The normal messages at start and end of loading FILENAME are suppressed. */)
2645 2638
2646 if (NILP (tem)) 2639 if (NILP (tem))
2647 { 2640 {
2648 int count = SPECPDL_INDEX (); 2641 ptrdiff_t count = SPECPDL_INDEX ();
2649 int nesting = 0; 2642 int nesting = 0;
2650 2643
2651 /* This is to make sure that loadup.el gives a clear picture 2644 /* This is to make sure that loadup.el gives a clear picture
@@ -2948,9 +2941,9 @@ static const short base64_char_to_value[128] =
2948 base64 characters. */ 2941 base64 characters. */
2949 2942
2950 2943
2951static EMACS_INT base64_encode_1 (const char *, char *, EMACS_INT, int, int); 2944static ptrdiff_t base64_encode_1 (const char *, char *, ptrdiff_t, int, int);
2952static EMACS_INT base64_decode_1 (const char *, char *, EMACS_INT, int, 2945static ptrdiff_t base64_decode_1 (const char *, char *, ptrdiff_t, int,
2953 EMACS_INT *); 2946 ptrdiff_t *);
2954 2947
2955DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region, 2948DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region,
2956 2, 3, "r", 2949 2, 3, "r",
@@ -2961,9 +2954,9 @@ into shorter lines. */)
2961 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break) 2954 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break)
2962{ 2955{
2963 char *encoded; 2956 char *encoded;
2964 EMACS_INT allength, length; 2957 ptrdiff_t allength, length;
2965 EMACS_INT ibeg, iend, encoded_length; 2958 ptrdiff_t ibeg, iend, encoded_length;
2966 EMACS_INT old_pos = PT; 2959 ptrdiff_t old_pos = PT;
2967 USE_SAFE_ALLOCA; 2960 USE_SAFE_ALLOCA;
2968 2961
2969 validate_region (&beg, &end); 2962 validate_region (&beg, &end);
@@ -3019,7 +3012,7 @@ Optional second argument NO-LINE-BREAK means do not break long lines
3019into shorter lines. */) 3012into shorter lines. */)
3020 (Lisp_Object string, Lisp_Object no_line_break) 3013 (Lisp_Object string, Lisp_Object no_line_break)
3021{ 3014{
3022 EMACS_INT allength, length, encoded_length; 3015 ptrdiff_t allength, length, encoded_length;
3023 char *encoded; 3016 char *encoded;
3024 Lisp_Object encoded_string; 3017 Lisp_Object encoded_string;
3025 USE_SAFE_ALLOCA; 3018 USE_SAFE_ALLOCA;
@@ -3055,12 +3048,12 @@ into shorter lines. */)
3055 return encoded_string; 3048 return encoded_string;
3056} 3049}
3057 3050
3058static EMACS_INT 3051static ptrdiff_t
3059base64_encode_1 (const char *from, char *to, EMACS_INT length, 3052base64_encode_1 (const char *from, char *to, ptrdiff_t length,
3060 int line_break, int multibyte) 3053 int line_break, int multibyte)
3061{ 3054{
3062 int counter = 0; 3055 int counter = 0;
3063 EMACS_INT i = 0; 3056 ptrdiff_t i = 0;
3064 char *e = to; 3057 char *e = to;
3065 int c; 3058 int c;
3066 unsigned int value; 3059 unsigned int value;
@@ -3159,11 +3152,11 @@ Return the length of the decoded text.
3159If the region can't be decoded, signal an error and don't modify the buffer. */) 3152If the region can't be decoded, signal an error and don't modify the buffer. */)
3160 (Lisp_Object beg, Lisp_Object end) 3153 (Lisp_Object beg, Lisp_Object end)
3161{ 3154{
3162 EMACS_INT ibeg, iend, length, allength; 3155 ptrdiff_t ibeg, iend, length, allength;
3163 char *decoded; 3156 char *decoded;
3164 EMACS_INT old_pos = PT; 3157 ptrdiff_t old_pos = PT;
3165 EMACS_INT decoded_length; 3158 ptrdiff_t decoded_length;
3166 EMACS_INT inserted_chars; 3159 ptrdiff_t inserted_chars;
3167 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3160 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3168 USE_SAFE_ALLOCA; 3161 USE_SAFE_ALLOCA;
3169 3162
@@ -3221,7 +3214,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3221 (Lisp_Object string) 3214 (Lisp_Object string)
3222{ 3215{
3223 char *decoded; 3216 char *decoded;
3224 EMACS_INT length, decoded_length; 3217 ptrdiff_t length, decoded_length;
3225 Lisp_Object decoded_string; 3218 Lisp_Object decoded_string;
3226 USE_SAFE_ALLOCA; 3219 USE_SAFE_ALLOCA;
3227 3220
@@ -3253,15 +3246,15 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3253 form. If NCHARS_RETURN is not NULL, store the number of produced 3246 form. If NCHARS_RETURN is not NULL, store the number of produced
3254 characters in *NCHARS_RETURN. */ 3247 characters in *NCHARS_RETURN. */
3255 3248
3256static EMACS_INT 3249static ptrdiff_t
3257base64_decode_1 (const char *from, char *to, EMACS_INT length, 3250base64_decode_1 (const char *from, char *to, ptrdiff_t length,
3258 int multibyte, EMACS_INT *nchars_return) 3251 int multibyte, ptrdiff_t *nchars_return)
3259{ 3252{
3260 EMACS_INT i = 0; /* Used inside READ_QUADRUPLET_BYTE */ 3253 ptrdiff_t i = 0; /* Used inside READ_QUADRUPLET_BYTE */
3261 char *e = to; 3254 char *e = to;
3262 unsigned char c; 3255 unsigned char c;
3263 unsigned long value; 3256 unsigned long value;
3264 EMACS_INT nchars = 0; 3257 ptrdiff_t nchars = 0;
3265 3258
3266 while (1) 3259 while (1)
3267 { 3260 {
@@ -3428,23 +3421,31 @@ get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used)
3428 3421
3429 3422
3430/* Return a Lisp vector which has the same contents as VEC but has 3423/* Return a Lisp vector which has the same contents as VEC but has
3431 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting 3424 at least INCR_MIN more entries, where INCR_MIN is positive.
3432 vector that are not copied from VEC are set to INIT. */ 3425 If NITEMS_MAX is not -1, do not grow the vector to be any larger
3426 than NITEMS_MAX. Entries in the resulting
3427 vector that are not copied from VEC are set to nil. */
3433 3428
3434Lisp_Object 3429Lisp_Object
3435larger_vector (Lisp_Object vec, EMACS_INT new_size, Lisp_Object init) 3430larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
3436{ 3431{
3437 struct Lisp_Vector *v; 3432 struct Lisp_Vector *v;
3438 EMACS_INT i, old_size; 3433 ptrdiff_t i, incr, incr_max, old_size, new_size;
3439 3434 ptrdiff_t C_language_max = min (PTRDIFF_MAX, SIZE_MAX) / sizeof *v->contents;
3435 ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max
3436 ? nitems_max : C_language_max);
3440 xassert (VECTORP (vec)); 3437 xassert (VECTORP (vec));
3438 xassert (0 < incr_min && -1 <= nitems_max);
3441 old_size = ASIZE (vec); 3439 old_size = ASIZE (vec);
3442 xassert (new_size >= old_size); 3440 incr_max = n_max - old_size;
3443 3441 incr = max (incr_min, min (old_size >> 1, incr_max));
3442 if (incr_max < incr)
3443 memory_full (SIZE_MAX);
3444 new_size = old_size + incr;
3444 v = allocate_vector (new_size); 3445 v = allocate_vector (new_size);
3445 memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); 3446 memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents);
3446 for (i = old_size; i < new_size; ++i) 3447 for (i = old_size; i < new_size; ++i)
3447 v->contents[i] = init; 3448 v->contents[i] = Qnil;
3448 XSETVECTOR (vec, v); 3449 XSETVECTOR (vec, v);
3449 return vec; 3450 return vec;
3450} 3451}
@@ -3565,6 +3566,10 @@ hashfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key)
3565 return XUINT (hash); 3566 return XUINT (hash);
3566} 3567}
3567 3568
3569/* An upper bound on the size of a hash table index. It must fit in
3570 ptrdiff_t and be a valid Emacs fixnum. */
3571#define INDEX_SIZE_BOUND \
3572 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX / sizeof (Lisp_Object)))
3568 3573
3569/* Create and initialize a new hash table. 3574/* Create and initialize a new hash table.
3570 3575
@@ -3595,7 +3600,8 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size,
3595{ 3600{
3596 struct Lisp_Hash_Table *h; 3601 struct Lisp_Hash_Table *h;
3597 Lisp_Object table; 3602 Lisp_Object table;
3598 EMACS_INT index_size, i, sz; 3603 EMACS_INT index_size, sz;
3604 ptrdiff_t i;
3599 double index_float; 3605 double index_float;
3600 3606
3601 /* Preconditions. */ 3607 /* Preconditions. */
@@ -3612,10 +3618,10 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size,
3612 3618
3613 sz = XFASTINT (size); 3619 sz = XFASTINT (size);
3614 index_float = sz / XFLOAT_DATA (rehash_threshold); 3620 index_float = sz / XFLOAT_DATA (rehash_threshold);
3615 index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 3621 index_size = (index_float < INDEX_SIZE_BOUND + 1
3616 ? next_almost_prime (index_float) 3622 ? next_almost_prime (index_float)
3617 : MOST_POSITIVE_FIXNUM + 1); 3623 : INDEX_SIZE_BOUND + 1);
3618 if (MOST_POSITIVE_FIXNUM < max (index_size, 2 * sz)) 3624 if (INDEX_SIZE_BOUND < max (index_size, 2 * sz))
3619 error ("Hash table too large"); 3625 error ("Hash table too large");
3620 3626
3621 /* Allocate a table and initialize it. */ 3627 /* Allocate a table and initialize it. */
@@ -3716,9 +3722,9 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3716{ 3722{
3717 if (NILP (h->next_free)) 3723 if (NILP (h->next_free))
3718 { 3724 {
3719 EMACS_INT old_size = HASH_TABLE_SIZE (h); 3725 ptrdiff_t old_size = HASH_TABLE_SIZE (h);
3720 EMACS_INT i, new_size, index_size; 3726 EMACS_INT new_size, index_size, nsize;
3721 EMACS_INT nsize; 3727 ptrdiff_t i;
3722 double index_float; 3728 double index_float;
3723 3729
3724 if (INTEGERP (h->rehash_size)) 3730 if (INTEGERP (h->rehash_size))
@@ -3726,26 +3732,27 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3726 else 3732 else
3727 { 3733 {
3728 double float_new_size = old_size * XFLOAT_DATA (h->rehash_size); 3734 double float_new_size = old_size * XFLOAT_DATA (h->rehash_size);
3729 if (float_new_size < MOST_POSITIVE_FIXNUM + 1) 3735 if (float_new_size < INDEX_SIZE_BOUND + 1)
3730 { 3736 {
3731 new_size = float_new_size; 3737 new_size = float_new_size;
3732 if (new_size <= old_size) 3738 if (new_size <= old_size)
3733 new_size = old_size + 1; 3739 new_size = old_size + 1;
3734 } 3740 }
3735 else 3741 else
3736 new_size = MOST_POSITIVE_FIXNUM + 1; 3742 new_size = INDEX_SIZE_BOUND + 1;
3737 } 3743 }
3738 index_float = new_size / XFLOAT_DATA (h->rehash_threshold); 3744 index_float = new_size / XFLOAT_DATA (h->rehash_threshold);
3739 index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 3745 index_size = (index_float < INDEX_SIZE_BOUND + 1
3740 ? next_almost_prime (index_float) 3746 ? next_almost_prime (index_float)
3741 : MOST_POSITIVE_FIXNUM + 1); 3747 : INDEX_SIZE_BOUND + 1);
3742 nsize = max (index_size, 2 * new_size); 3748 nsize = max (index_size, 2 * new_size);
3743 if (nsize > MOST_POSITIVE_FIXNUM) 3749 if (INDEX_SIZE_BOUND < nsize)
3744 error ("Hash table too large to resize"); 3750 error ("Hash table too large to resize");
3745 3751
3746 h->key_and_value = larger_vector (h->key_and_value, 2 * new_size, Qnil); 3752 h->key_and_value = larger_vector (h->key_and_value,
3747 h->next = larger_vector (h->next, new_size, Qnil); 3753 2 * (new_size - old_size), -1);
3748 h->hash = larger_vector (h->hash, new_size, Qnil); 3754 h->next = larger_vector (h->next, new_size - old_size, -1);
3755 h->hash = larger_vector (h->hash, new_size - old_size, -1);
3749 h->index = Fmake_vector (make_number (index_size), Qnil); 3756 h->index = Fmake_vector (make_number (index_size), Qnil);
3750 3757
3751 /* Update the free list. Do it so that new entries are added at 3758 /* Update the free list. Do it so that new entries are added at
@@ -3773,7 +3780,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3773 if (!NILP (HASH_HASH (h, i))) 3780 if (!NILP (HASH_HASH (h, i)))
3774 { 3781 {
3775 EMACS_UINT hash_code = XUINT (HASH_HASH (h, i)); 3782 EMACS_UINT hash_code = XUINT (HASH_HASH (h, i));
3776 EMACS_INT start_of_bucket = hash_code % ASIZE (h->index); 3783 ptrdiff_t start_of_bucket = hash_code % ASIZE (h->index);
3777 HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket); 3784 HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket);
3778 HASH_INDEX (h, start_of_bucket) = make_number (i); 3785 HASH_INDEX (h, start_of_bucket) = make_number (i);
3779 } 3786 }
@@ -3802,7 +3809,7 @@ hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
3802 /* We need not gcpro idx since it's either an integer or nil. */ 3809 /* We need not gcpro idx since it's either an integer or nil. */
3803 while (!NILP (idx)) 3810 while (!NILP (idx))
3804 { 3811 {
3805 EMACS_INT i = XFASTINT (idx); 3812 ptrdiff_t i = XFASTINT (idx);
3806 if (EQ (key, HASH_KEY (h, i)) 3813 if (EQ (key, HASH_KEY (h, i))
3807 || (h->cmpfn 3814 || (h->cmpfn
3808 && h->cmpfn (h, key, hash_code, 3815 && h->cmpfn (h, key, hash_code,
@@ -3854,7 +3861,7 @@ static void
3854hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) 3861hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
3855{ 3862{
3856 EMACS_UINT hash_code; 3863 EMACS_UINT hash_code;
3857 EMACS_INT start_of_bucket; 3864 ptrdiff_t start_of_bucket;
3858 Lisp_Object idx, prev; 3865 Lisp_Object idx, prev;
3859 3866
3860 hash_code = h->hashfn (h, key); 3867 hash_code = h->hashfn (h, key);
@@ -3865,7 +3872,7 @@ hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
3865 /* We need not gcpro idx, prev since they're either integers or nil. */ 3872 /* We need not gcpro idx, prev since they're either integers or nil. */
3866 while (!NILP (idx)) 3873 while (!NILP (idx))
3867 { 3874 {
3868 EMACS_INT i = XFASTINT (idx); 3875 ptrdiff_t i = XFASTINT (idx);
3869 3876
3870 if (EQ (key, HASH_KEY (h, i)) 3877 if (EQ (key, HASH_KEY (h, i))
3871 || (h->cmpfn 3878 || (h->cmpfn
@@ -3903,7 +3910,7 @@ hash_clear (struct Lisp_Hash_Table *h)
3903{ 3910{
3904 if (h->count > 0) 3911 if (h->count > 0)
3905 { 3912 {
3906 EMACS_INT i, size = HASH_TABLE_SIZE (h); 3913 ptrdiff_t i, size = HASH_TABLE_SIZE (h);
3907 3914
3908 for (i = 0; i < size; ++i) 3915 for (i = 0; i < size; ++i)
3909 { 3916 {
@@ -3941,7 +3948,7 @@ init_weak_hash_tables (void)
3941static int 3948static int
3942sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p) 3949sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
3943{ 3950{
3944 EMACS_INT bucket, n; 3951 ptrdiff_t bucket, n;
3945 int marked; 3952 int marked;
3946 3953
3947 n = ASIZE (h->index) & ~ARRAY_MARK_FLAG; 3954 n = ASIZE (h->index) & ~ARRAY_MARK_FLAG;
@@ -3956,7 +3963,7 @@ sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
3956 prev = Qnil; 3963 prev = Qnil;
3957 for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next) 3964 for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next)
3958 { 3965 {
3959 EMACS_INT i = XFASTINT (idx); 3966 ptrdiff_t i = XFASTINT (idx);
3960 int key_known_to_survive_p = survives_gc_p (HASH_KEY (h, i)); 3967 int key_known_to_survive_p = survives_gc_p (HASH_KEY (h, i));
3961 int value_known_to_survive_p = survives_gc_p (HASH_VALUE (h, i)); 3968 int value_known_to_survive_p = survives_gc_p (HASH_VALUE (h, i));
3962 int remove_p; 3969 int remove_p;
@@ -4522,7 +4529,7 @@ FUNCTION is called with two arguments, KEY and VALUE. */)
4522{ 4529{
4523 struct Lisp_Hash_Table *h = check_hash_table (table); 4530 struct Lisp_Hash_Table *h = check_hash_table (table);
4524 Lisp_Object args[3]; 4531 Lisp_Object args[3];
4525 EMACS_INT i; 4532 ptrdiff_t i;
4526 4533
4527 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) 4534 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
4528 if (!NILP (HASH_HASH (h, i))) 4535 if (!NILP (HASH_HASH (h, i)))
@@ -4571,10 +4578,9 @@ static Lisp_Object
4571secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) 4578secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary)
4572{ 4579{
4573 int i; 4580 int i;
4574 EMACS_INT size; 4581 ptrdiff_t size;
4575 EMACS_INT size_byte = 0;
4576 EMACS_INT start_char = 0, end_char = 0; 4582 EMACS_INT start_char = 0, end_char = 0;
4577 EMACS_INT start_byte = 0, end_byte = 0; 4583 ptrdiff_t start_byte, end_byte;
4578 register EMACS_INT b, e; 4584 register EMACS_INT b, e;
4579 register struct buffer *bp; 4585 register struct buffer *bp;
4580 EMACS_INT temp; 4586 EMACS_INT temp;
@@ -4611,7 +4617,6 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4611 object = code_convert_string (object, coding_system, Qnil, 1, 0, 1); 4617 object = code_convert_string (object, coding_system, Qnil, 1, 0, 1);
4612 4618
4613 size = SCHARS (object); 4619 size = SCHARS (object);
4614 size_byte = SBYTES (object);
4615 4620
4616 if (!NILP (start)) 4621 if (!NILP (start))
4617 { 4622 {
@@ -4621,15 +4626,10 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4621 4626
4622 if (start_char < 0) 4627 if (start_char < 0)
4623 start_char += size; 4628 start_char += size;
4624
4625 start_byte = string_char_to_byte (object, start_char);
4626 } 4629 }
4627 4630
4628 if (NILP (end)) 4631 if (NILP (end))
4629 { 4632 end_char = size;
4630 end_char = size;
4631 end_byte = size_byte;
4632 }
4633 else 4633 else
4634 { 4634 {
4635 CHECK_NUMBER (end); 4635 CHECK_NUMBER (end);
@@ -4638,13 +4638,15 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4638 4638
4639 if (end_char < 0) 4639 if (end_char < 0)
4640 end_char += size; 4640 end_char += size;
4641
4642 end_byte = string_char_to_byte (object, end_char);
4643 } 4641 }
4644 4642
4645 if (!(0 <= start_char && start_char <= end_char && end_char <= size)) 4643 if (!(0 <= start_char && start_char <= end_char && end_char <= size))
4646 args_out_of_range_3 (object, make_number (start_char), 4644 args_out_of_range_3 (object, make_number (start_char),
4647 make_number (end_char)); 4645 make_number (end_char));
4646
4647 start_byte = NILP (start) ? 0 : string_char_to_byte (object, start_char);
4648 end_byte =
4649 NILP (end) ? SBYTES (object) : string_char_to_byte (object, end_char);
4648 } 4650 }
4649 else 4651 else
4650 { 4652 {
@@ -4751,6 +4753,8 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4751 4753
4752 if (STRING_MULTIBYTE (object)) 4754 if (STRING_MULTIBYTE (object))
4753 object = code_convert_string (object, coding_system, Qnil, 1, 0, 0); 4755 object = code_convert_string (object, coding_system, Qnil, 1, 0, 0);
4756 start_byte = 0;
4757 end_byte = SBYTES (object);
4754 } 4758 }
4755 4759
4756 if (EQ (algorithm, Qmd5)) 4760 if (EQ (algorithm, Qmd5))
@@ -4791,7 +4795,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4791 digest = make_uninit_string (digest_size * 2); 4795 digest = make_uninit_string (digest_size * 2);
4792 4796
4793 hash_func (SSDATA (object) + start_byte, 4797 hash_func (SSDATA (object) + start_byte,
4794 SBYTES (object) - (size_byte - end_byte), 4798 end_byte - start_byte,
4795 SSDATA (digest)); 4799 SSDATA (digest));
4796 4800
4797 if (NILP (binary)) 4801 if (NILP (binary))
diff --git a/src/font.c b/src/font.c
index 43b74b5b6f8..16d09af01b3 100644
--- a/src/font.c
+++ b/src/font.c
@@ -238,7 +238,7 @@ font_intern_prop (const char *str, ptrdiff_t len, int force_symbol)
238 ptrdiff_t i; 238 ptrdiff_t i;
239 Lisp_Object tem; 239 Lisp_Object tem;
240 Lisp_Object obarray; 240 Lisp_Object obarray;
241 EMACS_INT nbytes, nchars; 241 ptrdiff_t nbytes, nchars;
242 242
243 if (len == 1 && *str == '*') 243 if (len == 1 && *str == '*')
244 return Qnil; 244 return Qnil;
@@ -364,7 +364,7 @@ font_style_to_value (enum font_property_index prop, Lisp_Object val, int noerror
364 else 364 else
365 { 365 {
366 int i, last_n; 366 int i, last_n;
367 int numeric = XINT (val); 367 EMACS_INT numeric = XINT (val);
368 368
369 for (i = 0, last_n = -1; i < len; i++) 369 for (i = 0, last_n = -1; i < len; i++)
370 { 370 {
@@ -518,7 +518,7 @@ font_prop_validate_style (Lisp_Object style, Lisp_Object val)
518 : FONT_WIDTH_INDEX); 518 : FONT_WIDTH_INDEX);
519 if (INTEGERP (val)) 519 if (INTEGERP (val))
520 { 520 {
521 int n = XINT (val); 521 EMACS_INT n = XINT (val);
522 if (((n >> 4) & 0xF) 522 if (((n >> 4) & 0xF)
523 >= ASIZE (AREF (font_style_table, prop - FONT_WEIGHT_INDEX))) 523 >= ASIZE (AREF (font_style_table, prop - FONT_WEIGHT_INDEX)))
524 val = Qerror; 524 val = Qerror;
@@ -848,7 +848,7 @@ font_expand_wildcards (Lisp_Object *field, int n)
848 848
849 if (INTEGERP (val)) 849 if (INTEGERP (val))
850 { 850 {
851 int numeric = XINT (val); 851 EMACS_INT numeric = XINT (val);
852 852
853 if (i + 1 == n) 853 if (i + 1 == n)
854 from = to = XLFD_ENCODING_INDEX, 854 from = to = XLFD_ENCODING_INDEX,
@@ -1740,7 +1740,8 @@ static int
1740check_gstring (Lisp_Object gstring) 1740check_gstring (Lisp_Object gstring)
1741{ 1741{
1742 Lisp_Object val; 1742 Lisp_Object val;
1743 int i, j; 1743 ptrdiff_t i;
1744 int j;
1744 1745
1745 CHECK_VECTOR (gstring); 1746 CHECK_VECTOR (gstring);
1746 val = AREF (gstring, 0); 1747 val = AREF (gstring, 0);
@@ -2433,7 +2434,7 @@ font_match_p (Lisp_Object spec, Lisp_Object font)
2433 /* All characters in the list must be supported. */ 2434 /* All characters in the list must be supported. */
2434 for (; CONSP (val2); val2 = XCDR (val2)) 2435 for (; CONSP (val2); val2 = XCDR (val2))
2435 { 2436 {
2436 if (! NATNUMP (XCAR (val2))) 2437 if (! CHARACTERP (XCAR (val2)))
2437 continue; 2438 continue;
2438 if (font_encode_char (font, XFASTINT (XCAR (val2))) 2439 if (font_encode_char (font, XFASTINT (XCAR (val2)))
2439 == FONT_INVALID_CODE) 2440 == FONT_INVALID_CODE)
@@ -2445,7 +2446,7 @@ font_match_p (Lisp_Object spec, Lisp_Object font)
2445 /* At most one character in the vector must be supported. */ 2446 /* At most one character in the vector must be supported. */
2446 for (i = 0; i < ASIZE (val2); i++) 2447 for (i = 0; i < ASIZE (val2); i++)
2447 { 2448 {
2448 if (! NATNUMP (AREF (val2, i))) 2449 if (! CHARACTERP (AREF (val2, i)))
2449 continue; 2450 continue;
2450 if (font_encode_char (font, XFASTINT (AREF (val2, i))) 2451 if (font_encode_char (font, XFASTINT (AREF (val2, i)))
2451 != FONT_INVALID_CODE) 2452 != FONT_INVALID_CODE)
@@ -3076,6 +3077,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3076 Lisp_Object foundry[3], *family, registry[3], adstyle[3]; 3077 Lisp_Object foundry[3], *family, registry[3], adstyle[3];
3077 int pixel_size; 3078 int pixel_size;
3078 int i, j, k, l; 3079 int i, j, k, l;
3080 USE_SAFE_ALLOCA;
3079 3081
3080 registry[0] = AREF (spec, FONT_REGISTRY_INDEX); 3082 registry[0] = AREF (spec, FONT_REGISTRY_INDEX);
3081 if (NILP (registry[0])) 3083 if (NILP (registry[0]))
@@ -3164,7 +3166,8 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3164 3166
3165 if (! NILP (alters)) 3167 if (! NILP (alters))
3166 { 3168 {
3167 family = alloca ((sizeof family[0]) * (XINT (Flength (alters)) + 2)); 3169 EMACS_INT alterslen = XFASTINT (Flength (alters));
3170 SAFE_ALLOCA_LISP (family, alterslen + 2);
3168 for (i = 0; CONSP (alters); i++, alters = XCDR (alters)) 3171 for (i = 0; CONSP (alters); i++, alters = XCDR (alters))
3169 family[i] = XCAR (alters); 3172 family[i] = XCAR (alters);
3170 if (NILP (AREF (spec, FONT_FAMILY_INDEX))) 3173 if (NILP (AREF (spec, FONT_FAMILY_INDEX)))
@@ -3206,6 +3209,8 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3206 } 3209 }
3207 } 3210 }
3208 } 3211 }
3212
3213 SAFE_FREE ();
3209 return Qnil; 3214 return Qnil;
3210} 3215}
3211 3216
@@ -3604,7 +3609,7 @@ font_filter_properties (Lisp_Object font,
3604 STRING. */ 3609 STRING. */
3605 3610
3606static Lisp_Object 3611static Lisp_Object
3607font_at (int c, EMACS_INT pos, struct face *face, struct window *w, 3612font_at (int c, ptrdiff_t pos, struct face *face, struct window *w,
3608 Lisp_Object string) 3613 Lisp_Object string)
3609{ 3614{
3610 FRAME_PTR f; 3615 FRAME_PTR f;
@@ -3620,7 +3625,7 @@ font_at (int c, EMACS_INT pos, struct face *face, struct window *w,
3620 { 3625 {
3621 if (multibyte) 3626 if (multibyte)
3622 { 3627 {
3623 EMACS_INT pos_byte = CHAR_TO_BYTE (pos); 3628 ptrdiff_t pos_byte = CHAR_TO_BYTE (pos);
3624 3629
3625 c = FETCH_CHAR (pos_byte); 3630 c = FETCH_CHAR (pos_byte);
3626 } 3631 }
@@ -3634,7 +3639,7 @@ font_at (int c, EMACS_INT pos, struct face *face, struct window *w,
3634 multibyte = STRING_MULTIBYTE (string); 3639 multibyte = STRING_MULTIBYTE (string);
3635 if (multibyte) 3640 if (multibyte)
3636 { 3641 {
3637 EMACS_INT pos_byte = string_char_to_byte (string, pos); 3642 ptrdiff_t pos_byte = string_char_to_byte (string, pos);
3638 3643
3639 str = SDATA (string) + pos_byte; 3644 str = SDATA (string) + pos_byte;
3640 c = STRING_CHAR (str); 3645 c = STRING_CHAR (str);
@@ -3650,7 +3655,7 @@ font_at (int c, EMACS_INT pos, struct face *face, struct window *w,
3650 if (! face) 3655 if (! face)
3651 { 3656 {
3652 int face_id; 3657 int face_id;
3653 EMACS_INT endptr; 3658 ptrdiff_t endptr;
3654 3659
3655 if (STRINGP (string)) 3660 if (STRINGP (string))
3656 face_id = face_at_string_position (w, string, pos, 0, -1, -1, &endptr, 3661 face_id = face_at_string_position (w, string, pos, 0, -1, -1, &endptr,
@@ -3687,9 +3692,9 @@ font_at (int c, EMACS_INT pos, struct face *face, struct window *w,
3687 It is assured that the current buffer (or STRING) is multibyte. */ 3692 It is assured that the current buffer (or STRING) is multibyte. */
3688 3693
3689Lisp_Object 3694Lisp_Object
3690font_range (EMACS_INT pos, EMACS_INT *limit, struct window *w, struct face *face, Lisp_Object string) 3695font_range (ptrdiff_t pos, ptrdiff_t *limit, struct window *w, struct face *face, Lisp_Object string)
3691{ 3696{
3692 EMACS_INT pos_byte, ignore; 3697 ptrdiff_t pos_byte, ignore;
3693 int c; 3698 int c;
3694 Lisp_Object font_object = Qnil; 3699 Lisp_Object font_object = Qnil;
3695 3700
@@ -4095,7 +4100,7 @@ how close they are to PREFER. */)
4095 (Lisp_Object font_spec, Lisp_Object frame, Lisp_Object num, Lisp_Object prefer) 4100 (Lisp_Object font_spec, Lisp_Object frame, Lisp_Object num, Lisp_Object prefer)
4096{ 4101{
4097 Lisp_Object vec, list; 4102 Lisp_Object vec, list;
4098 int n = 0; 4103 EMACS_INT n = 0;
4099 4104
4100 if (NILP (frame)) 4105 if (NILP (frame))
4101 frame = selected_frame; 4106 frame = selected_frame;
@@ -4262,13 +4267,10 @@ void
4262font_fill_lglyph_metrics (Lisp_Object glyph, Lisp_Object font_object) 4267font_fill_lglyph_metrics (Lisp_Object glyph, Lisp_Object font_object)
4263{ 4268{
4264 struct font *font = XFONT_OBJECT (font_object); 4269 struct font *font = XFONT_OBJECT (font_object);
4265 unsigned code; 4270 unsigned code = font->driver->encode_char (font, LGLYPH_CHAR (glyph));
4266 /* ecode used in LGLYPH_SET_CODE to avoid compiler warnings. */
4267 EMACS_INT ecode = font->driver->encode_char (font, LGLYPH_CHAR (glyph));
4268 struct font_metrics metrics; 4271 struct font_metrics metrics;
4269 4272
4270 LGLYPH_SET_CODE (glyph, ecode); 4273 LGLYPH_SET_CODE (glyph, code);
4271 code = ecode;
4272 font->driver->text_extents (font, &code, 1, &metrics); 4274 font->driver->text_extents (font, &code, 1, &metrics);
4273 LGLYPH_SET_LBEARING (glyph, metrics.lbearing); 4275 LGLYPH_SET_LBEARING (glyph, metrics.lbearing);
4274 LGLYPH_SET_RBEARING (glyph, metrics.rbearing); 4276 LGLYPH_SET_RBEARING (glyph, metrics.rbearing);
@@ -4290,7 +4292,7 @@ created glyph-string. Otherwise, the value is nil. */)
4290{ 4292{
4291 struct font *font; 4293 struct font *font;
4292 Lisp_Object font_object, n, glyph; 4294 Lisp_Object font_object, n, glyph;
4293 EMACS_INT i, j, from, to; 4295 ptrdiff_t i, j, from, to;
4294 4296
4295 if (! composition_gstring_p (gstring)) 4297 if (! composition_gstring_p (gstring))
4296 signal_error ("Invalid glyph-string: ", gstring); 4298 signal_error ("Invalid glyph-string: ", gstring);
@@ -4309,8 +4311,7 @@ created glyph-string. Otherwise, the value is nil. */)
4309 if (INTEGERP (n)) 4311 if (INTEGERP (n))
4310 break; 4312 break;
4311 gstring = larger_vector (gstring, 4313 gstring = larger_vector (gstring,
4312 ASIZE (gstring) + LGSTRING_GLYPH_LEN (gstring), 4314 LGSTRING_GLYPH_LEN (gstring), -1);
4313 Qnil);
4314 } 4315 }
4315 if (i == 3 || XINT (n) == 0) 4316 if (i == 3 || XINT (n) == 0)
4316 return Qnil; 4317 return Qnil;
@@ -4518,7 +4519,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4518 doc: /* Open FONT-ENTITY. */) 4519 doc: /* Open FONT-ENTITY. */)
4519 (Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame) 4520 (Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame)
4520{ 4521{
4521 int isize; 4522 EMACS_INT isize;
4522 4523
4523 CHECK_FONT_ENTITY (font_entity); 4524 CHECK_FONT_ENTITY (font_entity);
4524 if (NILP (frame)) 4525 if (NILP (frame))
@@ -4534,6 +4535,8 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4534 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), XFRAME (frame)->resy); 4535 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), XFRAME (frame)->resy);
4535 else 4536 else
4536 isize = XINT (size); 4537 isize = XINT (size);
4538 if (! (INT_MIN <= isize && isize <= INT_MAX))
4539 args_out_of_range (font_entity, size);
4537 if (isize == 0) 4540 if (isize == 0)
4538 isize = 120; 4541 isize = 120;
4539 } 4542 }
@@ -4637,14 +4640,14 @@ the corresponding element is nil. */)
4637 Lisp_Object object) 4640 Lisp_Object object)
4638{ 4641{
4639 struct font *font; 4642 struct font *font;
4640 int i, len; 4643 ptrdiff_t i, len;
4641 Lisp_Object *chars, vec; 4644 Lisp_Object *chars, vec;
4642 USE_SAFE_ALLOCA; 4645 USE_SAFE_ALLOCA;
4643 4646
4644 CHECK_FONT_GET_OBJECT (font_object, font); 4647 CHECK_FONT_GET_OBJECT (font_object, font);
4645 if (NILP (object)) 4648 if (NILP (object))
4646 { 4649 {
4647 EMACS_INT charpos, bytepos; 4650 ptrdiff_t charpos, bytepos;
4648 4651
4649 validate_region (&from, &to); 4652 validate_region (&from, &to);
4650 if (EQ (from, to)) 4653 if (EQ (from, to))
@@ -4750,22 +4753,22 @@ the current buffer. It defaults to the currently selected window. */)
4750 (Lisp_Object position, Lisp_Object window, Lisp_Object string) 4753 (Lisp_Object position, Lisp_Object window, Lisp_Object string)
4751{ 4754{
4752 struct window *w; 4755 struct window *w;
4753 EMACS_INT pos; 4756 ptrdiff_t pos;
4754 4757
4755 if (NILP (string)) 4758 if (NILP (string))
4756 { 4759 {
4757 CHECK_NUMBER_COERCE_MARKER (position); 4760 CHECK_NUMBER_COERCE_MARKER (position);
4758 pos = XINT (position); 4761 if (! (BEGV <= XINT (position) && XINT (position) < ZV))
4759 if (pos < BEGV || pos >= ZV)
4760 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); 4762 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
4763 pos = XINT (position);
4761 } 4764 }
4762 else 4765 else
4763 { 4766 {
4764 CHECK_NUMBER (position); 4767 CHECK_NUMBER (position);
4765 CHECK_STRING (string); 4768 CHECK_STRING (string);
4766 pos = XINT (position); 4769 if (! (0 < XINT (position) && XINT (position) < SCHARS (string)))
4767 if (pos < 0 || pos >= SCHARS (string))
4768 args_out_of_range (string, position); 4770 args_out_of_range (string, position);
4771 pos = XINT (position);
4769 } 4772 }
4770 if (NILP (window)) 4773 if (NILP (window))
4771 window = selected_window; 4774 window = selected_window;
diff --git a/src/font.h b/src/font.h
index ea392d2e3fa..b058be67aa3 100644
--- a/src/font.h
+++ b/src/font.h
@@ -794,7 +794,7 @@ extern int font_unparse_fcname (Lisp_Object font, int pixel_size,
794extern void register_font_driver (struct font_driver *driver, FRAME_PTR f); 794extern void register_font_driver (struct font_driver *driver, FRAME_PTR f);
795extern void free_font_driver_list (FRAME_PTR f); 795extern void free_font_driver_list (FRAME_PTR f);
796extern Lisp_Object font_update_drivers (FRAME_PTR f, Lisp_Object list); 796extern Lisp_Object font_update_drivers (FRAME_PTR f, Lisp_Object list);
797extern Lisp_Object font_range (EMACS_INT, EMACS_INT *, 797extern Lisp_Object font_range (ptrdiff_t, ptrdiff_t *,
798 struct window *, struct face *, 798 struct window *, struct face *,
799 Lisp_Object); 799 Lisp_Object);
800extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object); 800extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object);
diff --git a/src/fontset.c b/src/fontset.c
index 8a61f09f590..b2c7249625e 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -416,9 +416,11 @@ reorder_font_vector (Lisp_Object font_group, struct font *font)
416 416
417 for (tail = Vcharset_ordered_list; 417 for (tail = Vcharset_ordered_list;
418 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail); 418 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
419 score += 0x100, tail = XCDR (tail)) 419 tail = XCDR (tail))
420 if (EQ (encoding, XCAR (tail))) 420 if (EQ (encoding, XCAR (tail)))
421 break; 421 break;
422 else if (score <= min (INT_MAX, MOST_POSITIVE_FIXNUM) - 0x100)
423 score += 0x100;
422 } 424 }
423 else 425 else
424 { 426 {
@@ -787,7 +789,7 @@ make_fontset (Lisp_Object frame, Lisp_Object name, Lisp_Object base)
787 while (!NILP (AREF (Vfontset_table, id))) id++; 789 while (!NILP (AREF (Vfontset_table, id))) id++;
788 790
789 if (id + 1 == size) 791 if (id + 1 == size)
790 Vfontset_table = larger_vector (Vfontset_table, size + 32, Qnil); 792 Vfontset_table = larger_vector (Vfontset_table, 1, -1);
791 793
792 fontset = Fmake_char_table (Qfontset, Qnil); 794 fontset = Fmake_char_table (Qfontset, Qnil);
793 795
@@ -1700,7 +1702,7 @@ FONT-SPEC is a vector, a cons, or a string. See the documentation of
1700static Lisp_Object auto_fontset_alist; 1702static Lisp_Object auto_fontset_alist;
1701 1703
1702/* Number of automatically created fontsets. */ 1704/* Number of automatically created fontsets. */
1703static printmax_t num_auto_fontsets; 1705static ptrdiff_t num_auto_fontsets;
1704 1706
1705/* Return a fontset synthesized from FONT-OBJECT. This is called from 1707/* Return a fontset synthesized from FONT-OBJECT. This is called from
1706 x_new_font when FONT-OBJECT is used for the default ASCII font of a 1708 x_new_font when FONT-OBJECT is used for the default ASCII font of a
@@ -1727,9 +1729,9 @@ fontset_from_font (Lisp_Object font_object)
1727 alias = intern ("fontset-startup"); 1729 alias = intern ("fontset-startup");
1728 else 1730 else
1729 { 1731 {
1730 char temp[sizeof "fontset-auto" + INT_STRLEN_BOUND (printmax_t)]; 1732 char temp[sizeof "fontset-auto" + INT_STRLEN_BOUND (ptrdiff_t)];
1731 1733
1732 sprintf (temp, "fontset-auto%"pMd, num_auto_fontsets - 1); 1734 sprintf (temp, "fontset-auto%"pD"d", num_auto_fontsets - 1);
1733 alias = intern (temp); 1735 alias = intern (temp);
1734 } 1736 }
1735 fontset_spec = copy_font_spec (font_spec); 1737 fontset_spec = copy_font_spec (font_spec);
@@ -1816,7 +1818,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1816 doc: /* For internal use only. */) 1818 doc: /* For internal use only. */)
1817 (Lisp_Object position, Lisp_Object ch) 1819 (Lisp_Object position, Lisp_Object ch)
1818{ 1820{
1819 EMACS_INT pos, pos_byte, dummy; 1821 ptrdiff_t pos, pos_byte, dummy;
1820 int face_id; 1822 int face_id;
1821 int c; 1823 int c;
1822 struct frame *f; 1824 struct frame *f;
@@ -1836,9 +1838,9 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1836 struct window *w; 1838 struct window *w;
1837 1839
1838 CHECK_NUMBER_COERCE_MARKER (position); 1840 CHECK_NUMBER_COERCE_MARKER (position);
1839 pos = XINT (position); 1841 if (! (BEGV <= XINT (position) && XINT (position) < ZV))
1840 if (pos < BEGV || pos >= ZV)
1841 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); 1842 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
1843 pos = XINT (position);
1842 pos_byte = CHAR_TO_BYTE (pos); 1844 pos_byte = CHAR_TO_BYTE (pos);
1843 if (NILP (ch)) 1845 if (NILP (ch))
1844 c = FETCH_CHAR (pos_byte); 1846 c = FETCH_CHAR (pos_byte);
diff --git a/src/frame.c b/src/frame.c
index 1db24cc80e7..e962251f420 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1603,8 +1603,8 @@ before calling this function on it, like this.
1603 (Lisp_Object frame, Lisp_Object x, Lisp_Object y) 1603 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1604{ 1604{
1605 CHECK_LIVE_FRAME (frame); 1605 CHECK_LIVE_FRAME (frame);
1606 CHECK_NUMBER (x); 1606 CHECK_TYPE_RANGED_INTEGER (int, x);
1607 CHECK_NUMBER (y); 1607 CHECK_TYPE_RANGED_INTEGER (int, y);
1608 1608
1609 /* I think this should be done with a hook. */ 1609 /* I think this should be done with a hook. */
1610#ifdef HAVE_WINDOW_SYSTEM 1610#ifdef HAVE_WINDOW_SYSTEM
@@ -1644,8 +1644,8 @@ before calling this function on it, like this.
1644 (Lisp_Object frame, Lisp_Object x, Lisp_Object y) 1644 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1645{ 1645{
1646 CHECK_LIVE_FRAME (frame); 1646 CHECK_LIVE_FRAME (frame);
1647 CHECK_NUMBER (x); 1647 CHECK_TYPE_RANGED_INTEGER (int, x);
1648 CHECK_NUMBER (y); 1648 CHECK_TYPE_RANGED_INTEGER (int, y);
1649 1649
1650 /* I think this should be done with a hook. */ 1650 /* I think this should be done with a hook. */
1651#ifdef HAVE_WINDOW_SYSTEM 1651#ifdef HAVE_WINDOW_SYSTEM
@@ -2037,7 +2037,7 @@ store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2037} 2037}
2038 2038
2039static int 2039static int
2040frame_name_fnn_p (char *str, EMACS_INT len) 2040frame_name_fnn_p (char *str, ptrdiff_t len)
2041{ 2041{
2042 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9') 2042 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2043 { 2043 {
@@ -2321,7 +2321,7 @@ If FRAME is nil, describe the currently selected frame. */)
2321 if (STRINGP (value) && !FRAME_WINDOW_P (f)) 2321 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2322 { 2322 {
2323 const char *color_name; 2323 const char *color_name;
2324 EMACS_INT csz; 2324 ptrdiff_t csz;
2325 2325
2326 if (EQ (parameter, Qbackground_color)) 2326 if (EQ (parameter, Qbackground_color))
2327 { 2327 {
@@ -2397,12 +2397,13 @@ use is not recommended. Explicitly check for a frame-parameter instead. */)
2397#endif 2397#endif
2398 2398
2399 { 2399 {
2400 int length = XINT (Flength (alist)); 2400 EMACS_INT length = XFASTINT (Flength (alist));
2401 int i; 2401 ptrdiff_t i;
2402 Lisp_Object *parms 2402 Lisp_Object *parms;
2403 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); 2403 Lisp_Object *values;
2404 Lisp_Object *values 2404 USE_SAFE_ALLOCA;
2405 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); 2405 SAFE_ALLOCA_LISP (parms, 2 * length);
2406 values = parms + length;
2406 2407
2407 /* Extract parm names and values into those vectors. */ 2408 /* Extract parm names and values into those vectors. */
2408 2409
@@ -2428,6 +2429,8 @@ use is not recommended. Explicitly check for a frame-parameter instead. */)
2428 || EQ (prop, Qbackground_color)) 2429 || EQ (prop, Qbackground_color))
2429 update_face_from_frame_parameter (f, prop, val); 2430 update_face_from_frame_parameter (f, prop, val);
2430 } 2431 }
2432
2433 SAFE_FREE ();
2431 } 2434 }
2432 return Qnil; 2435 return Qnil;
2433} 2436}
@@ -2566,7 +2569,7 @@ but that the idea of the actual height of the frame should not be changed. */)
2566{ 2569{
2567 register struct frame *f; 2570 register struct frame *f;
2568 2571
2569 CHECK_NUMBER (lines); 2572 CHECK_TYPE_RANGED_INTEGER (int, lines);
2570 if (NILP (frame)) 2573 if (NILP (frame))
2571 frame = selected_frame; 2574 frame = selected_frame;
2572 CHECK_LIVE_FRAME (frame); 2575 CHECK_LIVE_FRAME (frame);
@@ -2593,7 +2596,7 @@ but that the idea of the actual width of the frame should not be changed. */)
2593 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend) 2596 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2594{ 2597{
2595 register struct frame *f; 2598 register struct frame *f;
2596 CHECK_NUMBER (cols); 2599 CHECK_TYPE_RANGED_INTEGER (int, cols);
2597 if (NILP (frame)) 2600 if (NILP (frame))
2598 frame = selected_frame; 2601 frame = selected_frame;
2599 CHECK_LIVE_FRAME (frame); 2602 CHECK_LIVE_FRAME (frame);
@@ -2620,8 +2623,8 @@ DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2620 register struct frame *f; 2623 register struct frame *f;
2621 2624
2622 CHECK_LIVE_FRAME (frame); 2625 CHECK_LIVE_FRAME (frame);
2623 CHECK_NUMBER (cols); 2626 CHECK_TYPE_RANGED_INTEGER (int, cols);
2624 CHECK_NUMBER (rows); 2627 CHECK_TYPE_RANGED_INTEGER (int, rows);
2625 f = XFRAME (frame); 2628 f = XFRAME (frame);
2626 2629
2627 /* I think this should be done with a hook. */ 2630 /* I think this should be done with a hook. */
@@ -2652,8 +2655,8 @@ the rightmost or bottommost possible position (that stays within the screen). *
2652 register struct frame *f; 2655 register struct frame *f;
2653 2656
2654 CHECK_LIVE_FRAME (frame); 2657 CHECK_LIVE_FRAME (frame);
2655 CHECK_NUMBER (xoffset); 2658 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2656 CHECK_NUMBER (yoffset); 2659 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2657 f = XFRAME (frame); 2660 f = XFRAME (frame);
2658 2661
2659 /* I think this should be done with a hook. */ 2662 /* I think this should be done with a hook. */
@@ -2872,12 +2875,12 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2872 prop = parms[i]; 2875 prop = parms[i];
2873 val = values[i]; 2876 val = values[i];
2874 2877
2875 if (EQ (prop, Qwidth) && NATNUMP (val)) 2878 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2876 { 2879 {
2877 size_changed = 1; 2880 size_changed = 1;
2878 width = XFASTINT (val); 2881 width = XFASTINT (val);
2879 } 2882 }
2880 else if (EQ (prop, Qheight) && NATNUMP (val)) 2883 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2881 { 2884 {
2882 size_changed = 1; 2885 size_changed = 1;
2883 height = XFASTINT (val); 2886 height = XFASTINT (val);
@@ -2913,7 +2916,7 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2913 } 2916 }
2914 2917
2915 /* Don't die if just one of these was set. */ 2918 /* Don't die if just one of these was set. */
2916 if (EQ (left, Qunbound)) 2919 if (! TYPE_RANGED_INTEGERP (int, left))
2917 { 2920 {
2918 left_no_change = 1; 2921 left_no_change = 1;
2919 if (f->left_pos < 0) 2922 if (f->left_pos < 0)
@@ -2921,7 +2924,7 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2921 else 2924 else
2922 XSETINT (left, f->left_pos); 2925 XSETINT (left, f->left_pos);
2923 } 2926 }
2924 if (EQ (top, Qunbound)) 2927 if (! TYPE_RANGED_INTEGERP (int, top))
2925 { 2928 {
2926 top_no_change = 1; 2929 top_no_change = 1;
2927 if (f->top_pos < 0) 2930 if (f->top_pos < 0)
@@ -2931,14 +2934,14 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2931 } 2934 }
2932 2935
2933 /* If one of the icon positions was not set, preserve or default it. */ 2936 /* If one of the icon positions was not set, preserve or default it. */
2934 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left)) 2937 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2935 { 2938 {
2936 icon_left_no_change = 1; 2939 icon_left_no_change = 1;
2937 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist)); 2940 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2938 if (NILP (icon_left)) 2941 if (NILP (icon_left))
2939 XSETINT (icon_left, 0); 2942 XSETINT (icon_left, 0);
2940 } 2943 }
2941 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top)) 2944 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2942 { 2945 {
2943 icon_top_no_change = 1; 2946 icon_top_no_change = 1;
2944 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist)); 2947 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
@@ -3153,7 +3156,7 @@ x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
3153{ 3156{
3154 if (NILP (new_value)) 3157 if (NILP (new_value))
3155 f->extra_line_spacing = 0; 3158 f->extra_line_spacing = 0;
3156 else if (NATNUMP (new_value)) 3159 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3157 f->extra_line_spacing = XFASTINT (new_value); 3160 f->extra_line_spacing = XFASTINT (new_value);
3158 else 3161 else
3159 signal_error ("Invalid line-spacing", new_value); 3162 signal_error ("Invalid line-spacing", new_value);
@@ -3362,7 +3365,7 @@ x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
3362void 3365void
3363x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 3366x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3364{ 3367{
3365 CHECK_NUMBER (arg); 3368 CHECK_TYPE_RANGED_INTEGER (int, arg);
3366 3369
3367 if (XINT (arg) == f->border_width) 3370 if (XINT (arg) == f->border_width)
3368 return; 3371 return;
@@ -3378,7 +3381,7 @@ x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldva
3378{ 3381{
3379 int old = FRAME_INTERNAL_BORDER_WIDTH (f); 3382 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3380 3383
3381 CHECK_NUMBER (arg); 3384 CHECK_TYPE_RANGED_INTEGER (int, arg);
3382 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg); 3385 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3383 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0) 3386 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3384 FRAME_INTERNAL_BORDER_WIDTH (f) = 0; 3387 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
@@ -4115,7 +4118,7 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
4115 f->top_pos = 0; 4118 f->top_pos = 0;
4116 else 4119 else
4117 { 4120 {
4118 CHECK_NUMBER (tem0); 4121 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4119 f->top_pos = XINT (tem0); 4122 f->top_pos = XINT (tem0);
4120 if (f->top_pos < 0) 4123 if (f->top_pos < 0)
4121 window_prompting |= YNegative; 4124 window_prompting |= YNegative;
@@ -4143,7 +4146,7 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
4143 f->left_pos = 0; 4146 f->left_pos = 0;
4144 else 4147 else
4145 { 4148 {
4146 CHECK_NUMBER (tem1); 4149 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4147 f->left_pos = XINT (tem1); 4150 f->left_pos = XINT (tem1);
4148 if (f->left_pos < 0) 4151 if (f->left_pos < 0)
4149 window_prompting |= XNegative; 4152 window_prompting |= XNegative;
diff --git a/src/frame.h b/src/frame.h
index 9779f4a0926..1a8bff7c3e7 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -322,7 +322,7 @@ struct frame
322 struct x_output *x; /* xterm.h */ 322 struct x_output *x; /* xterm.h */
323 struct w32_output *w32; /* w32term.h */ 323 struct w32_output *w32; /* w32term.h */
324 struct ns_output *ns; /* nsterm.h */ 324 struct ns_output *ns; /* nsterm.h */
325 EMACS_INT nothing; 325 intptr_t nothing;
326 } 326 }
327 output_data; 327 output_data;
328 328
diff --git a/src/fringe.c b/src/fringe.c
index 62c50e0d420..c591d391e9f 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -474,7 +474,7 @@ int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
474int 474int
475lookup_fringe_bitmap (Lisp_Object bitmap) 475lookup_fringe_bitmap (Lisp_Object bitmap)
476{ 476{
477 int bn; 477 EMACS_INT bn;
478 478
479 bitmap = Fget (bitmap, Qfringe); 479 bitmap = Fget (bitmap, Qfringe);
480 if (!INTEGERP (bitmap)) 480 if (!INTEGERP (bitmap))
@@ -696,7 +696,7 @@ static int
696get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p) 696get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
697{ 697{
698 Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm; 698 Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
699 int ln1 = 0, ln2 = 0; 699 EMACS_INT ln1 = 0, ln2 = 0;
700 int ix1 = right_p; 700 int ix1 = right_p;
701 int ix2 = ix1 + (partial_p ? 2 : 0); 701 int ix2 = ix1 + (partial_p ? 2 : 0);
702 702
@@ -1555,7 +1555,7 @@ If BITMAP already exists, the existing definition is replaced. */)
1555 else 1555 else
1556 { 1556 {
1557 CHECK_NUMBER (height); 1557 CHECK_NUMBER (height);
1558 fb.height = min (XINT (height), 255); 1558 fb.height = max (0, min (XINT (height), 255));
1559 if (fb.height > h) 1559 if (fb.height > h)
1560 { 1560 {
1561 fill1 = (fb.height - h) / 2; 1561 fill1 = (fb.height - h) / 2;
@@ -1568,7 +1568,7 @@ If BITMAP already exists, the existing definition is replaced. */)
1568 else 1568 else
1569 { 1569 {
1570 CHECK_NUMBER (width); 1570 CHECK_NUMBER (width);
1571 fb.width = min (XINT (width), 255); 1571 fb.width = max (0, min (XINT (width), 255));
1572 } 1572 }
1573 1573
1574 fb.period = 0; 1574 fb.period = 0;
@@ -1704,7 +1704,7 @@ Return nil if POS is not visible in WINDOW. */)
1704{ 1704{
1705 struct window *w; 1705 struct window *w;
1706 struct glyph_row *row; 1706 struct glyph_row *row;
1707 int textpos; 1707 ptrdiff_t textpos;
1708 1708
1709 if (NILP (window)) 1709 if (NILP (window))
1710 window = selected_window; 1710 window = selected_window;
@@ -1714,6 +1714,8 @@ Return nil if POS is not visible in WINDOW. */)
1714 if (!NILP (pos)) 1714 if (!NILP (pos))
1715 { 1715 {
1716 CHECK_NUMBER_COERCE_MARKER (pos); 1716 CHECK_NUMBER_COERCE_MARKER (pos);
1717 if (! (BEGV <= XINT (pos) && XINT (pos) <= ZV))
1718 args_out_of_range (window, pos);
1717 textpos = XINT (pos); 1719 textpos = XINT (pos);
1718 } 1720 }
1719 else if (w == XWINDOW (selected_window)) 1721 else if (w == XWINDOW (selected_window))
diff --git a/src/ftfont.c b/src/ftfont.c
index 131465b4f85..5545b4b4ae2 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -1033,13 +1033,13 @@ ftfont_list (Lisp_Object frame, Lisp_Object spec)
1033#endif /* HAVE_LIBOTF */ 1033#endif /* HAVE_LIBOTF */
1034 if (VECTORP (chars)) 1034 if (VECTORP (chars))
1035 { 1035 {
1036 int j; 1036 ptrdiff_t j;
1037 1037
1038 if (FcPatternGetCharSet (fontset->fonts[i], FC_CHARSET, 0, &charset) 1038 if (FcPatternGetCharSet (fontset->fonts[i], FC_CHARSET, 0, &charset)
1039 != FcResultMatch) 1039 != FcResultMatch)
1040 continue; 1040 continue;
1041 for (j = 0; j < ASIZE (chars); j++) 1041 for (j = 0; j < ASIZE (chars); j++)
1042 if (NATNUMP (AREF (chars, j)) 1042 if (TYPE_RANGED_INTEGERP (FcChar32, AREF (chars, j))
1043 && FcCharSetHasChar (charset, XFASTINT (AREF (chars, j)))) 1043 && FcCharSetHasChar (charset, XFASTINT (AREF (chars, j))))
1044 break; 1044 break;
1045 if (j == ASIZE (chars)) 1045 if (j == ASIZE (chars))
@@ -2394,8 +2394,8 @@ static Lisp_Object
2394ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, 2394ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
2395 FT_Face ft_face, OTF *otf, FT_Matrix *matrix) 2395 FT_Face ft_face, OTF *otf, FT_Matrix *matrix)
2396{ 2396{
2397 EMACS_INT len = LGSTRING_GLYPH_LEN (lgstring); 2397 ptrdiff_t len = LGSTRING_GLYPH_LEN (lgstring);
2398 EMACS_INT i; 2398 ptrdiff_t i;
2399 struct MFLTFontFT flt_font_ft; 2399 struct MFLTFontFT flt_font_ft;
2400 MFLT *flt = NULL; 2400 MFLT *flt = NULL;
2401 int with_variation_selector = 0; 2401 int with_variation_selector = 0;
@@ -2423,7 +2423,7 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
2423 } 2423 }
2424 2424
2425 len = i; 2425 len = i;
2426 lint_assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2); 2426 lint_assume (len <= STRING_BYTES_BOUND);
2427 2427
2428 if (with_variation_selector) 2428 if (with_variation_selector)
2429 { 2429 {
diff --git a/src/gnutls.c b/src/gnutls.c
index cf471314849..c5e21cc8777 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -351,11 +351,11 @@ emacs_gnutls_transport_set_errno (gnutls_session_t state, int err)
351 fn_gnutls_transport_set_errno (state, err); 351 fn_gnutls_transport_set_errno (state, err);
352} 352}
353 353
354EMACS_INT 354ptrdiff_t
355emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, EMACS_INT nbyte) 355emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte)
356{ 356{
357 ssize_t rtnval = 0; 357 ssize_t rtnval = 0;
358 EMACS_INT bytes_written; 358 ptrdiff_t bytes_written;
359 gnutls_session_t state = proc->gnutls_state; 359 gnutls_session_t state = proc->gnutls_state;
360 360
361 if (proc->gnutls_initstage != GNUTLS_STAGE_READY) 361 if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
@@ -406,8 +406,8 @@ emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, EMACS_INT nbyte)
406 return (bytes_written); 406 return (bytes_written);
407} 407}
408 408
409EMACS_INT 409ptrdiff_t
410emacs_gnutls_read (struct Lisp_Process *proc, char *buf, EMACS_INT nbyte) 410emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
411{ 411{
412 ssize_t rtnval; 412 ssize_t rtnval;
413 gnutls_session_t state = proc->gnutls_state; 413 gnutls_session_t state = proc->gnutls_state;
@@ -599,7 +599,7 @@ usage: (gnutls-error-fatalp ERROR) */)
599 } 599 }
600 } 600 }
601 601
602 if (!NUMBERP (err)) 602 if (! TYPE_RANGED_INTEGERP (int, err))
603 error ("Not an error symbol or code"); 603 error ("Not an error symbol or code");
604 604
605 if (0 == fn_gnutls_error_is_fatal (XINT (err))) 605 if (0 == fn_gnutls_error_is_fatal (XINT (err)))
@@ -631,7 +631,7 @@ usage: (gnutls-error-string ERROR) */)
631 } 631 }
632 } 632 }
633 633
634 if (!NUMBERP (err)) 634 if (! TYPE_RANGED_INTEGERP (int, err))
635 return build_string ("Not an error symbol or code"); 635 return build_string ("Not an error symbol or code");
636 636
637 return build_string (fn_gnutls_strerror (XINT (err))); 637 return build_string (fn_gnutls_strerror (XINT (err)));
@@ -804,7 +804,10 @@ one trustfile (usually a CA bundle). */)
804 error ("gnutls-boot: invalid :hostname parameter"); 804 error ("gnutls-boot: invalid :hostname parameter");
805 c_hostname = SSDATA (hostname); 805 c_hostname = SSDATA (hostname);
806 806
807 if (NUMBERP (loglevel)) 807 state = XPROCESS (proc)->gnutls_state;
808 XPROCESS (proc)->gnutls_p = 1;
809
810 if (TYPE_RANGED_INTEGERP (int, loglevel))
808 { 811 {
809 fn_gnutls_global_set_log_function (gnutls_log_function); 812 fn_gnutls_global_set_log_function (gnutls_log_function);
810 fn_gnutls_global_set_log_level (XINT (loglevel)); 813 fn_gnutls_global_set_log_level (XINT (loglevel));
diff --git a/src/gnutls.h b/src/gnutls.h
index 37b9a2eb4df..2b13908a748 100644
--- a/src/gnutls.h
+++ b/src/gnutls.h
@@ -58,10 +58,10 @@ typedef enum
58 58
59#define GNUTLS_LOG2i(level, max, string, extra) do { if (level <= max) { gnutls_log_function2i (level, "(Emacs) " string, extra); } } while (0) 59#define GNUTLS_LOG2i(level, max, string, extra) do { if (level <= max) { gnutls_log_function2i (level, "(Emacs) " string, extra); } } while (0)
60 60
61extern EMACS_INT 61extern ptrdiff_t
62emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, EMACS_INT nbyte); 62emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte);
63extern EMACS_INT 63extern ptrdiff_t
64emacs_gnutls_read (struct Lisp_Process *proc, char *buf, EMACS_INT nbyte); 64emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte);
65 65
66extern int emacs_gnutls_record_check_pending (gnutls_session_t state); 66extern int emacs_gnutls_record_check_pending (gnutls_session_t state);
67extern void emacs_gnutls_transport_set_errno (gnutls_session_t state, int err); 67extern void emacs_gnutls_transport_set_errno (gnutls_session_t state, int err);
diff --git a/src/gtkutil.c b/src/gtkutil.c
index c8a505273fe..4cf421b6616 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1634,7 +1634,7 @@ xg_maybe_add_timer (gpointer data)
1634static int 1634static int
1635xg_dialog_run (FRAME_PTR f, GtkWidget *w) 1635xg_dialog_run (FRAME_PTR f, GtkWidget *w)
1636{ 1636{
1637 int count = SPECPDL_INDEX (); 1637 ptrdiff_t count = SPECPDL_INDEX ();
1638 struct xg_dialog_data dd; 1638 struct xg_dialog_data dd;
1639 1639
1640 xg_set_screen (w, f); 1640 xg_set_screen (w, f);
@@ -4289,7 +4289,6 @@ xg_make_tool_item (FRAME_PTR f,
4289 rather than the GtkButton specific signals "enter" and 4289 rather than the GtkButton specific signals "enter" and
4290 "leave", so we can have only one callback. The event 4290 "leave", so we can have only one callback. The event
4291 will tell us what kind of event it is. */ 4291 will tell us what kind of event it is. */
4292 /* The EMACS_INT cast avoids a warning. */
4293 g_signal_connect (G_OBJECT (weventbox), 4292 g_signal_connect (G_OBJECT (weventbox),
4294 "enter-notify-event", 4293 "enter-notify-event",
4295 G_CALLBACK (xg_tool_bar_help_callback), 4294 G_CALLBACK (xg_tool_bar_help_callback),
@@ -4415,20 +4414,17 @@ update_frame_tool_bar (FRAME_PTR f)
4415 4414
4416 BLOCK_INPUT; 4415 BLOCK_INPUT;
4417 4416
4418 if (INTEGERP (Vtool_bar_button_margin) 4417 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4419 && XINT (Vtool_bar_button_margin) > 0)
4420 { 4418 {
4421 hmargin = XFASTINT (Vtool_bar_button_margin); 4419 hmargin = XFASTINT (Vtool_bar_button_margin);
4422 vmargin = XFASTINT (Vtool_bar_button_margin); 4420 vmargin = XFASTINT (Vtool_bar_button_margin);
4423 } 4421 }
4424 else if (CONSP (Vtool_bar_button_margin)) 4422 else if (CONSP (Vtool_bar_button_margin))
4425 { 4423 {
4426 if (INTEGERP (XCAR (Vtool_bar_button_margin)) 4424 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin), INT_MAX))
4427 && XINT (XCAR (Vtool_bar_button_margin)) > 0)
4428 hmargin = XFASTINT (XCAR (Vtool_bar_button_margin)); 4425 hmargin = XFASTINT (XCAR (Vtool_bar_button_margin));
4429 4426
4430 if (INTEGERP (XCDR (Vtool_bar_button_margin)) 4427 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4431 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4432 vmargin = XFASTINT (XCDR (Vtool_bar_button_margin)); 4428 vmargin = XFASTINT (XCDR (Vtool_bar_button_margin));
4433 } 4429 }
4434 4430
diff --git a/src/image.c b/src/image.c
index 73490fe2865..a3b64b74997 100644
--- a/src/image.c
+++ b/src/image.c
@@ -771,10 +771,9 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
771 /* Record that we recognized the keyword. If a keywords 771 /* Record that we recognized the keyword. If a keywords
772 was found more than once, it's an error. */ 772 was found more than once, it's an error. */
773 keywords[i].value = value; 773 keywords[i].value = value;
774 ++keywords[i].count;
775
776 if (keywords[i].count > 1) 774 if (keywords[i].count > 1)
777 return 0; 775 return 0;
776 ++keywords[i].count;
778 777
779 /* Check type of value against allowed type. */ 778 /* Check type of value against allowed type. */
780 switch (keywords[i].type) 779 switch (keywords[i].type)
@@ -1754,6 +1753,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1754 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF', 1753 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
1755 `:background COLOR'. */ 1754 `:background COLOR'. */
1756 Lisp_Object ascent, margin, relief, bg; 1755 Lisp_Object ascent, margin, relief, bg;
1756 int relief_bound;
1757 1757
1758 ascent = image_spec_value (spec, QCascent, NULL); 1758 ascent = image_spec_value (spec, QCascent, NULL);
1759 if (INTEGERP (ascent)) 1759 if (INTEGERP (ascent))
@@ -1771,7 +1771,8 @@ lookup_image (struct frame *f, Lisp_Object spec)
1771 } 1771 }
1772 1772
1773 relief = image_spec_value (spec, QCrelief, NULL); 1773 relief = image_spec_value (spec, QCrelief, NULL);
1774 if (INTEGERP (relief)) 1774 relief_bound = INT_MAX - max (img->hmargin, img->vmargin);
1775 if (RANGED_INTEGERP (- relief_bound, relief, relief_bound))
1775 { 1776 {
1776 img->relief = XINT (relief); 1777 img->relief = XINT (relief);
1777 img->hmargin += eabs (img->relief); 1778 img->hmargin += eabs (img->relief);
diff --git a/src/indent.c b/src/indent.c
index 280607f7ecb..32533438e2a 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -45,23 +45,23 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
45 Some things in set last_known_column_point to -1 45 Some things in set last_known_column_point to -1
46 to mark the memorized value as invalid. */ 46 to mark the memorized value as invalid. */
47 47
48static EMACS_INT last_known_column; 48static ptrdiff_t last_known_column;
49 49
50/* Value of point when current_column was called. */ 50/* Value of point when current_column was called. */
51 51
52EMACS_INT last_known_column_point; 52ptrdiff_t last_known_column_point;
53 53
54/* Value of MODIFF when current_column was called. */ 54/* Value of MODIFF when current_column was called. */
55 55
56static int last_known_column_modified; 56static EMACS_INT last_known_column_modified;
57 57
58static EMACS_INT current_column_1 (void); 58static ptrdiff_t current_column_1 (void);
59static EMACS_INT position_indentation (ptrdiff_t); 59static ptrdiff_t position_indentation (ptrdiff_t);
60 60
61/* Cache of beginning of line found by the last call of 61/* Cache of beginning of line found by the last call of
62 current_column. */ 62 current_column. */
63 63
64static EMACS_INT current_column_bol_cache; 64static ptrdiff_t current_column_bol_cache;
65 65
66/* Get the display table to use for the current buffer. */ 66/* Get the display table to use for the current buffer. */
67 67
@@ -204,12 +204,12 @@ width_run_cache_on_off (void)
204 characters immediately following, then *NEXT_BOUNDARY_P 204 characters immediately following, then *NEXT_BOUNDARY_P
205 will equal the return value. */ 205 will equal the return value. */
206 206
207EMACS_INT 207ptrdiff_t
208skip_invisible (EMACS_INT pos, EMACS_INT *next_boundary_p, EMACS_INT to, Lisp_Object window) 208skip_invisible (ptrdiff_t pos, ptrdiff_t *next_boundary_p, ptrdiff_t to, Lisp_Object window)
209{ 209{
210 Lisp_Object prop, position, overlay_limit, proplimit; 210 Lisp_Object prop, position, overlay_limit, proplimit;
211 Lisp_Object buffer, tmp; 211 Lisp_Object buffer, tmp;
212 EMACS_INT end; 212 ptrdiff_t end;
213 int inv_p; 213 int inv_p;
214 214
215 XSETFASTINT (position, pos); 215 XSETFASTINT (position, pos);
@@ -318,13 +318,13 @@ invalidate_current_column (void)
318 last_known_column_point = 0; 318 last_known_column_point = 0;
319} 319}
320 320
321EMACS_INT 321ptrdiff_t
322current_column (void) 322current_column (void)
323{ 323{
324 register EMACS_INT col; 324 register ptrdiff_t col;
325 register unsigned char *ptr, *stop; 325 register unsigned char *ptr, *stop;
326 register int tab_seen; 326 register int tab_seen;
327 EMACS_INT post_tab; 327 ptrdiff_t post_tab;
328 register int c; 328 register int c;
329 int tab_width = SANE_TAB_WIDTH (current_buffer); 329 int tab_width = SANE_TAB_WIDTH (current_buffer);
330 int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 330 int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
@@ -360,7 +360,7 @@ current_column (void)
360 360
361 while (1) 361 while (1)
362 { 362 {
363 EMACS_INT i, n; 363 ptrdiff_t i, n;
364 Lisp_Object charvec; 364 Lisp_Object charvec;
365 365
366 if (ptr == stop) 366 if (ptr == stop)
@@ -400,8 +400,7 @@ current_column (void)
400 next_element_from_display_vector does it. */ 400 next_element_from_display_vector does it. */
401 Lisp_Object entry = AREF (charvec, i); 401 Lisp_Object entry = AREF (charvec, i);
402 402
403 if (GLYPH_CODE_P (entry) 403 if (GLYPH_CODE_P (entry))
404 && GLYPH_CODE_CHAR_VALID_P (entry))
405 c = GLYPH_CODE_CHAR (entry); 404 c = GLYPH_CODE_CHAR (entry);
406 else 405 else
407 c = ' '; 406 c = ' ';
@@ -464,7 +463,7 @@ current_column (void)
464 in ENDPOS. 463 in ENDPOS.
465 Otherwise just return -1. */ 464 Otherwise just return -1. */
466static int 465static int
467check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos) 466check_display_width (ptrdiff_t pos, ptrdiff_t col, ptrdiff_t *endpos)
468{ 467{
469 Lisp_Object val, overlay; 468 Lisp_Object val, overlay;
470 469
@@ -474,19 +473,27 @@ check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos)
474 { /* FIXME: Use calc_pixel_width_or_height. */ 473 { /* FIXME: Use calc_pixel_width_or_height. */
475 Lisp_Object plist = XCDR (val), prop; 474 Lisp_Object plist = XCDR (val), prop;
476 int width = -1; 475 int width = -1;
476 EMACS_INT align_to_max =
477 (col < MOST_POSITIVE_FIXNUM - INT_MAX
478 ? (EMACS_INT) INT_MAX + col
479 : MOST_POSITIVE_FIXNUM);
477 480
478 if ((prop = Fplist_get (plist, QCwidth), NATNUMP (prop))) 481 if ((prop = Fplist_get (plist, QCwidth),
482 RANGED_INTEGERP (0, prop, INT_MAX)))
479 width = XINT (prop); 483 width = XINT (prop);
480 else if (FLOATP (prop)) 484 else if (FLOATP (prop) && 0 <= XFLOAT_DATA (prop)
485 && XFLOAT_DATA (prop) <= INT_MAX)
481 width = (int)(XFLOAT_DATA (prop) + 0.5); 486 width = (int)(XFLOAT_DATA (prop) + 0.5);
482 else if ((prop = Fplist_get (plist, QCalign_to), NATNUMP (prop))) 487 else if ((prop = Fplist_get (plist, QCalign_to),
488 RANGED_INTEGERP (col, prop, align_to_max)))
483 width = XINT (prop) - col; 489 width = XINT (prop) - col;
484 else if (FLOATP (prop)) 490 else if (FLOATP (prop) && col <= XFLOAT_DATA (prop)
491 && (XFLOAT_DATA (prop) <= align_to_max))
485 width = (int)(XFLOAT_DATA (prop) + 0.5) - col; 492 width = (int)(XFLOAT_DATA (prop) + 0.5) - col;
486 493
487 if (width >= 0) 494 if (width >= 0)
488 { 495 {
489 EMACS_INT start; 496 ptrdiff_t start;
490 if (OVERLAYP (overlay)) 497 if (OVERLAYP (overlay))
491 *endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 498 *endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
492 else 499 else
@@ -504,7 +511,7 @@ check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos)
504 PREVCOL gets set to the column of the previous position (it's always 511 PREVCOL gets set to the column of the previous position (it's always
505 strictly smaller than the goal column). */ 512 strictly smaller than the goal column). */
506static void 513static void
507scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) 514scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol)
508{ 515{
509 int tab_width = SANE_TAB_WIDTH (current_buffer); 516 int tab_width = SANE_TAB_WIDTH (current_buffer);
510 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 517 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
@@ -515,13 +522,13 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
515 struct window *w; 522 struct window *w;
516 523
517 /* Start the scan at the beginning of this line with column number 0. */ 524 /* Start the scan at the beginning of this line with column number 0. */
518 register EMACS_INT col = 0, prev_col = 0; 525 register ptrdiff_t col = 0, prev_col = 0;
519 EMACS_INT goal = goalcol ? *goalcol : MOST_POSITIVE_FIXNUM; 526 EMACS_INT goal = goalcol ? *goalcol : MOST_POSITIVE_FIXNUM;
520 EMACS_INT end = endpos ? *endpos : PT; 527 ptrdiff_t end = endpos ? *endpos : PT;
521 EMACS_INT scan, scan_byte; 528 ptrdiff_t scan, scan_byte;
522 EMACS_INT next_boundary; 529 ptrdiff_t next_boundary;
523 { 530 {
524 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 531 ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
525 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1); 532 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
526 current_column_bol_cache = PT; 533 current_column_bol_cache = PT;
527 scan = PT, scan_byte = PT_BYTE; 534 scan = PT, scan_byte = PT_BYTE;
@@ -544,7 +551,7 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
544 /* Occasionally we may need to skip invisible text. */ 551 /* Occasionally we may need to skip invisible text. */
545 while (scan == next_boundary) 552 while (scan == next_boundary)
546 { 553 {
547 EMACS_INT old_scan = scan; 554 ptrdiff_t old_scan = scan;
548 /* This updates NEXT_BOUNDARY to the next place 555 /* This updates NEXT_BOUNDARY to the next place
549 where we might need to skip more invisible text. */ 556 where we might need to skip more invisible text. */
550 scan = skip_invisible (scan, &next_boundary, end, Qnil); 557 scan = skip_invisible (scan, &next_boundary, end, Qnil);
@@ -562,7 +569,7 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
562 prev_col = col; 569 prev_col = col;
563 570
564 { /* Check display property. */ 571 { /* Check display property. */
565 EMACS_INT endp; 572 ptrdiff_t endp;
566 int width = check_display_width (scan, col, &endp); 573 int width = check_display_width (scan, col, &endp);
567 if (width >= 0) 574 if (width >= 0)
568 { 575 {
@@ -608,7 +615,7 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
608 && VECTORP (DISP_CHAR_VECTOR (dp, c))) 615 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
609 { 616 {
610 Lisp_Object charvec; 617 Lisp_Object charvec;
611 EMACS_INT i, n; 618 ptrdiff_t i, n;
612 619
613 /* This character is displayed using a vector of glyphs. 620 /* This character is displayed using a vector of glyphs.
614 Update the column/position based on those glyphs. */ 621 Update the column/position based on those glyphs. */
@@ -622,8 +629,7 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
622 next_element_from_display_vector does it. */ 629 next_element_from_display_vector does it. */
623 Lisp_Object entry = AREF (charvec, i); 630 Lisp_Object entry = AREF (charvec, i);
624 631
625 if (GLYPH_CODE_P (entry) 632 if (GLYPH_CODE_P (entry))
626 && GLYPH_CODE_CHAR_VALID_P (entry))
627 c = GLYPH_CODE_CHAR (entry); 633 c = GLYPH_CODE_CHAR (entry);
628 else 634 else
629 c = ' '; 635 c = ' ';
@@ -698,11 +704,11 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
698 This function handles characters that are invisible 704 This function handles characters that are invisible
699 due to text properties or overlays. */ 705 due to text properties or overlays. */
700 706
701static EMACS_INT 707static ptrdiff_t
702current_column_1 (void) 708current_column_1 (void)
703{ 709{
704 EMACS_INT col = MOST_POSITIVE_FIXNUM; 710 EMACS_INT col = MOST_POSITIVE_FIXNUM;
705 EMACS_INT opoint = PT; 711 ptrdiff_t opoint = PT;
706 712
707 scan_for_column (&opoint, &col, NULL); 713 scan_for_column (&opoint, &col, NULL);
708 return col; 714 return col;
@@ -798,7 +804,7 @@ The return value is COLUMN. */)
798 (Lisp_Object column, Lisp_Object minimum) 804 (Lisp_Object column, Lisp_Object minimum)
799{ 805{
800 EMACS_INT mincol; 806 EMACS_INT mincol;
801 register EMACS_INT fromcol; 807 register ptrdiff_t fromcol;
802 int tab_width = SANE_TAB_WIDTH (current_buffer); 808 int tab_width = SANE_TAB_WIDTH (current_buffer);
803 809
804 CHECK_NUMBER (column); 810 CHECK_NUMBER (column);
@@ -845,7 +851,7 @@ following any initial whitespace. */)
845 (void) 851 (void)
846{ 852{
847 Lisp_Object val; 853 Lisp_Object val;
848 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 854 ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
849 855
850 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1); 856 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
851 857
@@ -854,16 +860,16 @@ following any initial whitespace. */)
854 return val; 860 return val;
855} 861}
856 862
857static EMACS_INT 863static ptrdiff_t
858position_indentation (ptrdiff_t pos_byte) 864position_indentation (ptrdiff_t pos_byte)
859{ 865{
860 register EMACS_INT column = 0; 866 register ptrdiff_t column = 0;
861 int tab_width = SANE_TAB_WIDTH (current_buffer); 867 int tab_width = SANE_TAB_WIDTH (current_buffer);
862 register unsigned char *p; 868 register unsigned char *p;
863 register unsigned char *stop; 869 register unsigned char *stop;
864 unsigned char *start; 870 unsigned char *start;
865 EMACS_INT next_boundary_byte = pos_byte; 871 ptrdiff_t next_boundary_byte = pos_byte;
866 EMACS_INT ceiling = next_boundary_byte; 872 ptrdiff_t ceiling = next_boundary_byte;
867 873
868 p = BYTE_POS_ADDR (pos_byte); 874 p = BYTE_POS_ADDR (pos_byte);
869 /* STOP records the value of P at which we will need 875 /* STOP records the value of P at which we will need
@@ -876,7 +882,7 @@ position_indentation (ptrdiff_t pos_byte)
876 { 882 {
877 while (p == stop) 883 while (p == stop)
878 { 884 {
879 EMACS_INT stop_pos_byte; 885 ptrdiff_t stop_pos_byte;
880 886
881 /* If we have updated P, set POS_BYTE to match. 887 /* If we have updated P, set POS_BYTE to match.
882 The first time we enter the loop, POS_BYTE is already right. */ 888 The first time we enter the loop, POS_BYTE is already right. */
@@ -887,8 +893,8 @@ position_indentation (ptrdiff_t pos_byte)
887 return column; 893 return column;
888 if (pos_byte == next_boundary_byte) 894 if (pos_byte == next_boundary_byte)
889 { 895 {
890 EMACS_INT next_boundary; 896 ptrdiff_t next_boundary;
891 EMACS_INT pos = BYTE_TO_CHAR (pos_byte); 897 ptrdiff_t pos = BYTE_TO_CHAR (pos_byte);
892 pos = skip_invisible (pos, &next_boundary, ZV, Qnil); 898 pos = skip_invisible (pos, &next_boundary, ZV, Qnil);
893 pos_byte = CHAR_TO_BYTE (pos); 899 pos_byte = CHAR_TO_BYTE (pos);
894 next_boundary_byte = CHAR_TO_BYTE (next_boundary); 900 next_boundary_byte = CHAR_TO_BYTE (next_boundary);
@@ -942,10 +948,10 @@ position_indentation (ptrdiff_t pos_byte)
942 preceding line. */ 948 preceding line. */
943 949
944int 950int
945indented_beyond_p (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT column) 951indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column)
946{ 952{
947 EMACS_INT val; 953 ptrdiff_t val;
948 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 954 ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
949 955
950 SET_PT_BOTH (pos, pos_byte); 956 SET_PT_BOTH (pos, pos_byte);
951 while (PT > BEGV && FETCH_BYTE (PT_BYTE) == '\n') 957 while (PT > BEGV && FETCH_BYTE (PT_BYTE) == '\n')
@@ -977,8 +983,8 @@ COLUMN, add spaces/tabs to get there.
977The return value is the current column. */) 983The return value is the current column. */)
978 (Lisp_Object column, Lisp_Object force) 984 (Lisp_Object column, Lisp_Object force)
979{ 985{
980 EMACS_INT pos; 986 ptrdiff_t pos, prev_col;
981 EMACS_INT col, prev_col; 987 EMACS_INT col;
982 EMACS_INT goal; 988 EMACS_INT goal;
983 989
984 CHECK_NATNUM (column); 990 CHECK_NATNUM (column);
@@ -995,13 +1001,13 @@ The return value is the current column. */)
995 if (!NILP (force) && col > goal) 1001 if (!NILP (force) && col > goal)
996 { 1002 {
997 int c; 1003 int c;
998 EMACS_INT pos_byte = PT_BYTE; 1004 ptrdiff_t pos_byte = PT_BYTE;
999 1005
1000 DEC_POS (pos_byte); 1006 DEC_POS (pos_byte);
1001 c = FETCH_CHAR (pos_byte); 1007 c = FETCH_CHAR (pos_byte);
1002 if (c == '\t' && prev_col < goal) 1008 if (c == '\t' && prev_col < goal)
1003 { 1009 {
1004 EMACS_INT goal_pt, goal_pt_byte; 1010 ptrdiff_t goal_pt, goal_pt_byte;
1005 1011
1006 /* Insert spaces in front of the tab to reach GOAL. Do this 1012 /* Insert spaces in front of the tab to reach GOAL. Do this
1007 first so that a marker at the end of the tab gets 1013 first so that a marker at the end of the tab gets
@@ -1100,13 +1106,13 @@ static struct position val_compute_motion;
1100 the scroll bars if they are turned on. */ 1106 the scroll bars if they are turned on. */
1101 1107
1102struct position * 1108struct position *
1103compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_motion, EMACS_INT to, EMACS_INT tovpos, EMACS_INT tohpos, EMACS_INT width, EMACS_INT hscroll, EMACS_INT tab_offset, struct window *win) 1109compute_motion (ptrdiff_t from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_motion, ptrdiff_t to, EMACS_INT tovpos, EMACS_INT tohpos, EMACS_INT width, ptrdiff_t hscroll, int tab_offset, struct window *win)
1104{ 1110{
1105 register EMACS_INT hpos = fromhpos; 1111 register EMACS_INT hpos = fromhpos;
1106 register EMACS_INT vpos = fromvpos; 1112 register EMACS_INT vpos = fromvpos;
1107 1113
1108 register EMACS_INT pos; 1114 register ptrdiff_t pos;
1109 EMACS_INT pos_byte; 1115 ptrdiff_t pos_byte;
1110 register int c = 0; 1116 register int c = 0;
1111 int tab_width = SANE_TAB_WIDTH (current_buffer); 1117 int tab_width = SANE_TAB_WIDTH (current_buffer);
1112 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 1118 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
@@ -1115,38 +1121,38 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1115 = (INTEGERP (BVAR (current_buffer, selective_display)) 1121 = (INTEGERP (BVAR (current_buffer, selective_display))
1116 ? XINT (BVAR (current_buffer, selective_display)) 1122 ? XINT (BVAR (current_buffer, selective_display))
1117 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0); 1123 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0);
1118 int selective_rlen 1124 ptrdiff_t selective_rlen
1119 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp)) 1125 = (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
1120 ? ASIZE (DISP_INVIS_VECTOR (dp)) : 0); 1126 ? ASIZE (DISP_INVIS_VECTOR (dp)) : 0);
1121 /* The next location where the `invisible' property changes, or an 1127 /* The next location where the `invisible' property changes, or an
1122 overlay starts or ends. */ 1128 overlay starts or ends. */
1123 EMACS_INT next_boundary = from; 1129 ptrdiff_t next_boundary = from;
1124 1130
1125 /* For computing runs of characters with similar widths. 1131 /* For computing runs of characters with similar widths.
1126 Invariant: width_run_width is zero, or all the characters 1132 Invariant: width_run_width is zero, or all the characters
1127 from width_run_start to width_run_end have a fixed width of 1133 from width_run_start to width_run_end have a fixed width of
1128 width_run_width. */ 1134 width_run_width. */
1129 EMACS_INT width_run_start = from; 1135 ptrdiff_t width_run_start = from;
1130 EMACS_INT width_run_end = from; 1136 ptrdiff_t width_run_end = from;
1131 EMACS_INT width_run_width = 0; 1137 ptrdiff_t width_run_width = 0;
1132 Lisp_Object *width_table; 1138 Lisp_Object *width_table;
1133 Lisp_Object buffer; 1139 Lisp_Object buffer;
1134 1140
1135 /* The next buffer pos where we should consult the width run cache. */ 1141 /* The next buffer pos where we should consult the width run cache. */
1136 EMACS_INT next_width_run = from; 1142 ptrdiff_t next_width_run = from;
1137 Lisp_Object window; 1143 Lisp_Object window;
1138 1144
1139 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 1145 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
1140 /* If previous char scanned was a wide character, 1146 /* If previous char scanned was a wide character,
1141 this is the column where it ended. Otherwise, this is 0. */ 1147 this is the column where it ended. Otherwise, this is 0. */
1142 EMACS_INT wide_column_end_hpos = 0; 1148 EMACS_INT wide_column_end_hpos = 0;
1143 EMACS_INT prev_pos; /* Previous buffer position. */ 1149 ptrdiff_t prev_pos; /* Previous buffer position. */
1144 EMACS_INT prev_pos_byte; /* Previous buffer position. */ 1150 ptrdiff_t prev_pos_byte; /* Previous buffer position. */
1145 EMACS_INT prev_hpos = 0; 1151 EMACS_INT prev_hpos = 0;
1146 EMACS_INT prev_vpos = 0; 1152 EMACS_INT prev_vpos = 0;
1147 EMACS_INT contin_hpos; /* HPOS of last column of continued line. */ 1153 EMACS_INT contin_hpos; /* HPOS of last column of continued line. */
1148 EMACS_INT prev_tab_offset; /* Previous tab offset. */ 1154 int prev_tab_offset; /* Previous tab offset. */
1149 EMACS_INT continuation_glyph_width; 1155 int continuation_glyph_width;
1150 1156
1151 struct composition_it cmp_it; 1157 struct composition_it cmp_it;
1152 1158
@@ -1195,8 +1201,8 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1195 { 1201 {
1196 while (pos == next_boundary) 1202 while (pos == next_boundary)
1197 { 1203 {
1198 EMACS_INT pos_here = pos; 1204 ptrdiff_t pos_here = pos;
1199 EMACS_INT newpos; 1205 ptrdiff_t newpos;
1200 1206
1201 /* Don't skip invisible if we are already at the margin. */ 1207 /* Don't skip invisible if we are already at the margin. */
1202 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos)) 1208 if (vpos > tovpos || (vpos == tovpos && hpos >= tohpos))
@@ -1230,7 +1236,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1230 to be changed here. */ 1236 to be changed here. */
1231 { 1237 {
1232 unsigned char *ovstr; 1238 unsigned char *ovstr;
1233 EMACS_INT ovlen = overlay_strings (pos, win, &ovstr); 1239 ptrdiff_t ovlen = overlay_strings (pos, win, &ovstr);
1234 hpos += ((multibyte && ovlen > 0) 1240 hpos += ((multibyte && ovlen > 0)
1235 ? strwidth ((char *) ovstr, ovlen) : ovlen); 1241 ? strwidth ((char *) ovstr, ovlen) : ovlen);
1236 } 1242 }
@@ -1305,7 +1311,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1305 1311
1306 if (hpos > width) 1312 if (hpos > width)
1307 { 1313 {
1308 int total_width = width + continuation_glyph_width; 1314 EMACS_INT total_width = width + continuation_glyph_width;
1309 int truncate = 0; 1315 int truncate = 0;
1310 1316
1311 if (!NILP (Vtruncate_partial_width_windows) 1317 if (!NILP (Vtruncate_partial_width_windows)
@@ -1435,7 +1441,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1435 want to skip over it for some other reason. */ 1441 want to skip over it for some other reason. */
1436 if (common_width != 0) 1442 if (common_width != 0)
1437 { 1443 {
1438 EMACS_INT run_end_hpos; 1444 ptrdiff_t run_end_hpos;
1439 1445
1440 /* Don't go past the final buffer posn the user 1446 /* Don't go past the final buffer posn the user
1441 requested. */ 1447 requested. */
@@ -1475,7 +1481,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1475 /* We have to scan the text character-by-character. */ 1481 /* We have to scan the text character-by-character. */
1476 else 1482 else
1477 { 1483 {
1478 EMACS_INT i, n; 1484 ptrdiff_t i, n;
1479 Lisp_Object charvec; 1485 Lisp_Object charvec;
1480 1486
1481 /* Check composition sequence. */ 1487 /* Check composition sequence. */
@@ -1552,8 +1558,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1552 next_element_from_display_vector does it. */ 1558 next_element_from_display_vector does it. */
1553 Lisp_Object entry = AREF (charvec, i); 1559 Lisp_Object entry = AREF (charvec, i);
1554 1560
1555 if (GLYPH_CODE_P (entry) 1561 if (GLYPH_CODE_P (entry))
1556 && GLYPH_CODE_CHAR_VALID_P (entry))
1557 c = GLYPH_CODE_CHAR (entry); 1562 c = GLYPH_CODE_CHAR (entry);
1558 else 1563 else
1559 c = ' '; 1564 c = ' ';
@@ -1676,8 +1681,6 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1676 val_compute_motion.prevhpos = contin_hpos; 1681 val_compute_motion.prevhpos = contin_hpos;
1677 else 1682 else
1678 val_compute_motion.prevhpos = prev_hpos; 1683 val_compute_motion.prevhpos = prev_hpos;
1679 /* We always handle all of them here; none of them remain to do. */
1680 val_compute_motion.ovstring_chars_done = 0;
1681 1684
1682 /* Nonzero if have just continued a line */ 1685 /* Nonzero if have just continued a line */
1683 val_compute_motion.contin = (contin_hpos && prev_hpos == 0); 1686 val_compute_motion.contin = (contin_hpos && prev_hpos == 0);
@@ -1734,7 +1737,8 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1734 struct window *w; 1737 struct window *w;
1735 Lisp_Object bufpos, hpos, vpos, prevhpos; 1738 Lisp_Object bufpos, hpos, vpos, prevhpos;
1736 struct position *pos; 1739 struct position *pos;
1737 EMACS_INT hscroll, tab_offset; 1740 ptrdiff_t hscroll;
1741 int tab_offset;
1738 1742
1739 CHECK_NUMBER_COERCE_MARKER (from); 1743 CHECK_NUMBER_COERCE_MARKER (from);
1740 CHECK_CONS (frompos); 1744 CHECK_CONS (frompos);
@@ -1755,6 +1759,9 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1755 CHECK_CONS (offsets); 1759 CHECK_CONS (offsets);
1756 CHECK_NUMBER_CAR (offsets); 1760 CHECK_NUMBER_CAR (offsets);
1757 CHECK_NUMBER_CDR (offsets); 1761 CHECK_NUMBER_CDR (offsets);
1762 if (! (0 <= XINT (XCAR (offsets)) && XINT (XCAR (offsets)) <= PTRDIFF_MAX
1763 && 0 <= XINT (XCDR (offsets)) && XINT (XCDR (offsets)) <= INT_MAX))
1764 args_out_of_range (XCAR (offsets), XCDR (offsets));
1758 hscroll = XINT (XCAR (offsets)); 1765 hscroll = XINT (XCAR (offsets));
1759 tab_offset = XINT (XCDR (offsets)); 1766 tab_offset = XINT (XCDR (offsets));
1760 } 1767 }
@@ -1808,22 +1815,22 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1808static struct position val_vmotion; 1815static struct position val_vmotion;
1809 1816
1810struct position * 1817struct position *
1811vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w) 1818vmotion (register ptrdiff_t from, register EMACS_INT vtarget, struct window *w)
1812{ 1819{
1813 EMACS_INT hscroll = XINT (w->hscroll); 1820 ptrdiff_t hscroll = XINT (w->hscroll);
1814 struct position pos; 1821 struct position pos;
1815 /* vpos is cumulative vertical position, changed as from is changed */ 1822 /* vpos is cumulative vertical position, changed as from is changed */
1816 register int vpos = 0; 1823 register EMACS_INT vpos = 0;
1817 EMACS_INT prevline; 1824 ptrdiff_t prevline;
1818 register EMACS_INT first; 1825 register ptrdiff_t first;
1819 EMACS_INT from_byte; 1826 ptrdiff_t from_byte;
1820 EMACS_INT lmargin = hscroll > 0 ? 1 - hscroll : 0; 1827 ptrdiff_t lmargin = hscroll > 0 ? 1 - hscroll : 0;
1821 EMACS_INT selective 1828 ptrdiff_t selective
1822 = (INTEGERP (BVAR (current_buffer, selective_display)) 1829 = (INTEGERP (BVAR (current_buffer, selective_display))
1823 ? XINT (BVAR (current_buffer, selective_display)) 1830 ? clip_to_bounds (-1, XINT (BVAR (current_buffer, selective_display)),
1831 PTRDIFF_MAX)
1824 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0); 1832 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0);
1825 Lisp_Object window; 1833 Lisp_Object window;
1826 EMACS_INT start_hpos = 0;
1827 int did_motion; 1834 int did_motion;
1828 /* This is the object we use for fetching character properties. */ 1835 /* This is the object we use for fetching character properties. */
1829 Lisp_Object text_prop_object; 1836 Lisp_Object text_prop_object;
@@ -1862,7 +1869,7 @@ vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
1862 TEXT_PROP_MEANS_INVISIBLE (propval)))) 1869 TEXT_PROP_MEANS_INVISIBLE (propval))))
1863 prevline = find_next_newline_no_quit (prevline - 1, -1); 1870 prevline = find_next_newline_no_quit (prevline - 1, -1);
1864 pos = *compute_motion (prevline, 0, 1871 pos = *compute_motion (prevline, 0,
1865 lmargin + (prevline == BEG ? start_hpos : 0), 1872 lmargin,
1866 0, 1873 0,
1867 from, 1874 from,
1868 /* Don't care for VPOS... */ 1875 /* Don't care for VPOS... */
@@ -1870,10 +1877,7 @@ vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
1870 /* ... nor HPOS. */ 1877 /* ... nor HPOS. */
1871 1 << (BITS_PER_SHORT - 1), 1878 1 << (BITS_PER_SHORT - 1),
1872 -1, hscroll, 1879 -1, hscroll,
1873 /* This compensates for start_hpos 1880 0,
1874 so that a tab as first character
1875 still occupies 8 columns. */
1876 (prevline == BEG ? -start_hpos : 0),
1877 w); 1881 w);
1878 vpos -= pos.vpos; 1882 vpos -= pos.vpos;
1879 first = 0; 1883 first = 0;
@@ -1891,8 +1895,6 @@ vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
1891 val_vmotion.hpos = lmargin; 1895 val_vmotion.hpos = lmargin;
1892 val_vmotion.contin = 0; 1896 val_vmotion.contin = 0;
1893 val_vmotion.prevhpos = 0; 1897 val_vmotion.prevhpos = 0;
1894 val_vmotion.ovstring_chars_done = 0;
1895 val_vmotion.tab_offset = 0; /* For accumulating tab offset. */
1896 return &val_vmotion; 1898 return &val_vmotion;
1897 } 1899 }
1898 1900
@@ -1919,8 +1921,7 @@ vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
1919 TEXT_PROP_MEANS_INVISIBLE (propval)))) 1921 TEXT_PROP_MEANS_INVISIBLE (propval))))
1920 prevline = find_next_newline_no_quit (prevline - 1, -1); 1922 prevline = find_next_newline_no_quit (prevline - 1, -1);
1921 pos = *compute_motion (prevline, 0, 1923 pos = *compute_motion (prevline, 0,
1922 lmargin + (prevline == BEG 1924 lmargin,
1923 ? start_hpos : 0),
1924 0, 1925 0,
1925 from, 1926 from,
1926 /* Don't care for VPOS... */ 1927 /* Don't care for VPOS... */
@@ -1928,21 +1929,20 @@ vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
1928 /* ... nor HPOS. */ 1929 /* ... nor HPOS. */
1929 1 << (BITS_PER_SHORT - 1), 1930 1 << (BITS_PER_SHORT - 1),
1930 -1, hscroll, 1931 -1, hscroll,
1931 (prevline == BEG ? -start_hpos : 0), 1932 0,
1932 w); 1933 w);
1933 did_motion = 1; 1934 did_motion = 1;
1934 } 1935 }
1935 else 1936 else
1936 { 1937 {
1937 pos.hpos = lmargin + (from == BEG ? start_hpos : 0); 1938 pos.hpos = lmargin;
1938 pos.vpos = 0; 1939 pos.vpos = 0;
1939 pos.tab_offset = 0;
1940 did_motion = 0; 1940 did_motion = 0;
1941 } 1941 }
1942 return compute_motion (from, vpos, pos.hpos, did_motion, 1942 return compute_motion (from, vpos, pos.hpos, did_motion,
1943 ZV, vtarget, - (1 << (BITS_PER_SHORT - 1)), 1943 ZV, vtarget, - (1 << (BITS_PER_SHORT - 1)),
1944 -1, hscroll, 1944 -1, hscroll,
1945 pos.tab_offset - (from == BEG ? start_hpos : 0), 1945 0,
1946 w); 1946 w);
1947} 1947}
1948 1948
@@ -2019,8 +2019,8 @@ whether or not it is currently displayed in some window. */)
2019 } 2019 }
2020 else 2020 else
2021 { 2021 {
2022 EMACS_INT it_start; 2022 ptrdiff_t it_start, it_overshoot_count = 0;
2023 int first_x, it_overshoot_count = 0; 2023 int first_x;
2024 int overshoot_handled = 0; 2024 int overshoot_handled = 0;
2025 int disp_string_at_start_p = 0; 2025 int disp_string_at_start_p = 0;
2026 2026
@@ -2097,12 +2097,12 @@ whether or not it is currently displayed in some window. */)
2097 /* Do this even if LINES is 0, so that we move back to the 2097 /* Do this even if LINES is 0, so that we move back to the
2098 beginning of the current line as we ought. */ 2098 beginning of the current line as we ought. */
2099 if (XINT (lines) == 0 || IT_CHARPOS (it) > 0) 2099 if (XINT (lines) == 0 || IT_CHARPOS (it) > 0)
2100 move_it_by_lines (&it, max (INT_MIN, XINT (lines))); 2100 move_it_by_lines (&it, max (PTRDIFF_MIN, XINT (lines)));
2101 } 2101 }
2102 else if (overshoot_handled) 2102 else if (overshoot_handled)
2103 { 2103 {
2104 it.vpos = 0; 2104 it.vpos = 0;
2105 move_it_by_lines (&it, min (INT_MAX, XINT (lines))); 2105 move_it_by_lines (&it, min (PTRDIFF_MAX, XINT (lines)));
2106 } 2106 }
2107 else 2107 else
2108 { 2108 {
@@ -2118,12 +2118,12 @@ whether or not it is currently displayed in some window. */)
2118 move_it_by_lines (&it, 1); 2118 move_it_by_lines (&it, 1);
2119 } 2119 }
2120 if (XINT (lines) > 1) 2120 if (XINT (lines) > 1)
2121 move_it_by_lines (&it, min (INT_MAX, XINT (lines) - 1)); 2121 move_it_by_lines (&it, min (PTRDIFF_MAX, XINT (lines) - 1));
2122 } 2122 }
2123 else 2123 else
2124 { 2124 {
2125 it.vpos = 0; 2125 it.vpos = 0;
2126 move_it_by_lines (&it, min (INT_MAX, XINT (lines))); 2126 move_it_by_lines (&it, min (PTRDIFF_MAX, XINT (lines)));
2127 } 2127 }
2128 } 2128 }
2129 2129
diff --git a/src/indent.h b/src/indent.h
index c5114b812c8..e198137a756 100644
--- a/src/indent.h
+++ b/src/indent.h
@@ -16,51 +16,29 @@ GNU General Public License for more details.
16You should have received a copy of the GNU General Public License 16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18 18
19/* We introduce new member `tab_offset'. We need it because of the
20 existence of wide-column characters. There is a case that the
21 line-break occurs at a wide-column character and the number of
22 columns of the line gets less than width.
23
24 Example (where W_ stands for a wide-column character):
25 ----------
26 abcdefgh\\
27 W_
28 ----------
29
30 To handle this case, we should not calculate the tab offset by
31 tab_offset += width;
32
33 Instead, we must remember tab_offset of the line.
34
35 */
36
37struct position 19struct position
38 { 20 {
39 EMACS_INT bufpos; 21 ptrdiff_t bufpos;
40 EMACS_INT bytepos; 22 ptrdiff_t bytepos;
41 EMACS_INT hpos; 23 EMACS_INT hpos;
42 EMACS_INT vpos; 24 EMACS_INT vpos;
43 EMACS_INT prevhpos; 25 EMACS_INT prevhpos;
44 EMACS_INT contin; 26 int contin;
45 /* Number of characters we have already handled
46 from the before and after strings at this position. */
47 EMACS_INT ovstring_chars_done;
48 EMACS_INT tab_offset;
49 }; 27 };
50 28
51struct position *compute_motion (EMACS_INT from, EMACS_INT fromvpos, 29struct position *compute_motion (ptrdiff_t from, EMACS_INT fromvpos,
52 EMACS_INT fromhpos, int did_motion, 30 EMACS_INT fromhpos, int did_motion,
53 EMACS_INT to, EMACS_INT tovpos, 31 ptrdiff_t to, EMACS_INT tovpos,
54 EMACS_INT tohpos, 32 EMACS_INT tohpos,
55 EMACS_INT width, EMACS_INT hscroll, 33 EMACS_INT width, ptrdiff_t hscroll,
56 EMACS_INT tab_offset, struct window *); 34 int tab_offset, struct window *);
57struct position *vmotion (EMACS_INT from, EMACS_INT vtarget, 35struct position *vmotion (ptrdiff_t from, EMACS_INT vtarget,
58 struct window *); 36 struct window *);
59EMACS_INT skip_invisible (EMACS_INT pos, EMACS_INT *next_boundary_p, 37ptrdiff_t skip_invisible (ptrdiff_t pos, ptrdiff_t *next_boundary_p,
60 EMACS_INT to, Lisp_Object window); 38 ptrdiff_t to, Lisp_Object window);
61 39
62/* Value of point when current_column was called */ 40/* Value of point when current_column was called */
63extern EMACS_INT last_known_column_point; 41extern ptrdiff_t last_known_column_point;
64 42
65/* Functions for dealing with the column cache. */ 43/* Functions for dealing with the column cache. */
66 44
diff --git a/src/insdel.c b/src/insdel.c
index 373b3848f05..148ba221940 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -32,14 +32,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#include "region-cache.h" 32#include "region-cache.h"
33 33
34static void insert_from_string_1 (Lisp_Object string, 34static void insert_from_string_1 (Lisp_Object string,
35 EMACS_INT pos, EMACS_INT pos_byte, 35 ptrdiff_t pos, ptrdiff_t pos_byte,
36 EMACS_INT nchars, EMACS_INT nbytes, 36 ptrdiff_t nchars, ptrdiff_t nbytes,
37 int inherit, int before_markers); 37 int inherit, int before_markers);
38static void insert_from_buffer_1 (struct buffer *buf, 38static void insert_from_buffer_1 (struct buffer *buf,
39 EMACS_INT from, EMACS_INT nchars, 39 ptrdiff_t from, ptrdiff_t nchars,
40 int inherit); 40 int inherit);
41static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap); 41static void gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap);
42static void gap_right (EMACS_INT charpos, EMACS_INT bytepos); 42static void gap_right (ptrdiff_t charpos, ptrdiff_t bytepos);
43 43
44static Lisp_Object Fcombine_after_change_execute (void); 44static Lisp_Object Fcombine_after_change_execute (void);
45 45
@@ -60,7 +60,7 @@ static Lisp_Object combine_after_change_buffer;
60 60
61Lisp_Object Qinhibit_modification_hooks; 61Lisp_Object Qinhibit_modification_hooks;
62 62
63static void signal_before_change (EMACS_INT, EMACS_INT, EMACS_INT *); 63static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
64 64
65#define CHECK_MARKERS() \ 65#define CHECK_MARKERS() \
66 do \ 66 do \
@@ -93,7 +93,7 @@ check_markers (void)
93 Note that this can quit! */ 93 Note that this can quit! */
94 94
95void 95void
96move_gap (EMACS_INT charpos) 96move_gap (ptrdiff_t charpos)
97{ 97{
98 move_gap_both (charpos, charpos_to_bytepos (charpos)); 98 move_gap_both (charpos, charpos_to_bytepos (charpos));
99} 99}
@@ -102,7 +102,7 @@ move_gap (EMACS_INT charpos)
102 Note that this can quit! */ 102 Note that this can quit! */
103 103
104void 104void
105move_gap_both (EMACS_INT charpos, EMACS_INT bytepos) 105move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos)
106{ 106{
107 if (bytepos < GPT_BYTE) 107 if (bytepos < GPT_BYTE)
108 gap_left (charpos, bytepos, 0); 108 gap_left (charpos, bytepos, 0);
@@ -116,11 +116,11 @@ move_gap_both (EMACS_INT charpos, EMACS_INT bytepos)
116 If NEWGAP is nonzero, then don't update beg_unchanged and end_unchanged. */ 116 If NEWGAP is nonzero, then don't update beg_unchanged and end_unchanged. */
117 117
118static void 118static void
119gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap) 119gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap)
120{ 120{
121 register unsigned char *to, *from; 121 register unsigned char *to, *from;
122 register EMACS_INT i; 122 register ptrdiff_t i;
123 EMACS_INT new_s1; 123 ptrdiff_t new_s1;
124 124
125 if (!newgap) 125 if (!newgap)
126 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT); 126 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT);
@@ -171,11 +171,11 @@ gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap)
171 and CHARPOS is the corresponding char position. */ 171 and CHARPOS is the corresponding char position. */
172 172
173static void 173static void
174gap_right (EMACS_INT charpos, EMACS_INT bytepos) 174gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
175{ 175{
176 register unsigned char *to, *from; 176 register unsigned char *to, *from;
177 register EMACS_INT i; 177 register ptrdiff_t i;
178 EMACS_INT new_s1; 178 ptrdiff_t new_s1;
179 179
180 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT); 180 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT);
181 181
@@ -225,12 +225,12 @@ gap_right (EMACS_INT charpos, EMACS_INT bytepos)
225 or inside of the range being deleted. */ 225 or inside of the range being deleted. */
226 226
227void 227void
228adjust_markers_for_delete (EMACS_INT from, EMACS_INT from_byte, 228adjust_markers_for_delete (ptrdiff_t from, ptrdiff_t from_byte,
229 EMACS_INT to, EMACS_INT to_byte) 229 ptrdiff_t to, ptrdiff_t to_byte)
230{ 230{
231 Lisp_Object marker; 231 Lisp_Object marker;
232 register struct Lisp_Marker *m; 232 register struct Lisp_Marker *m;
233 register EMACS_INT charpos; 233 register ptrdiff_t charpos;
234 234
235 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 235 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
236 { 236 {
@@ -290,13 +290,13 @@ adjust_markers_for_delete (EMACS_INT from, EMACS_INT from_byte,
290 or BEFORE_MARKERS is true. */ 290 or BEFORE_MARKERS is true. */
291 291
292static void 292static void
293adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte, 293adjust_markers_for_insert (ptrdiff_t from, ptrdiff_t from_byte,
294 EMACS_INT to, EMACS_INT to_byte, int before_markers) 294 ptrdiff_t to, ptrdiff_t to_byte, int before_markers)
295{ 295{
296 struct Lisp_Marker *m; 296 struct Lisp_Marker *m;
297 int adjusted = 0; 297 int adjusted = 0;
298 EMACS_INT nchars = to - from; 298 ptrdiff_t nchars = to - from;
299 EMACS_INT nbytes = to_byte - from_byte; 299 ptrdiff_t nbytes = to_byte - from_byte;
300 300
301 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 301 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
302 { 302 {
@@ -341,7 +341,7 @@ adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte,
341 intervals. */ 341 intervals. */
342 342
343static void 343static void
344adjust_point (EMACS_INT nchars, EMACS_INT nbytes) 344adjust_point (ptrdiff_t nchars, ptrdiff_t nbytes)
345{ 345{
346 SET_BUF_PT_BOTH (current_buffer, PT + nchars, PT_BYTE + nbytes); 346 SET_BUF_PT_BOTH (current_buffer, PT + nchars, PT_BYTE + nbytes);
347 /* In a single-byte buffer, the two positions must be equal. */ 347 /* In a single-byte buffer, the two positions must be equal. */
@@ -354,14 +354,14 @@ adjust_point (EMACS_INT nchars, EMACS_INT nbytes)
354 an insertion. */ 354 an insertion. */
355 355
356static void 356static void
357adjust_markers_for_replace (EMACS_INT from, EMACS_INT from_byte, 357adjust_markers_for_replace (ptrdiff_t from, ptrdiff_t from_byte,
358 EMACS_INT old_chars, EMACS_INT old_bytes, 358 ptrdiff_t old_chars, ptrdiff_t old_bytes,
359 EMACS_INT new_chars, EMACS_INT new_bytes) 359 ptrdiff_t new_chars, ptrdiff_t new_bytes)
360{ 360{
361 register struct Lisp_Marker *m; 361 register struct Lisp_Marker *m;
362 EMACS_INT prev_to_byte = from_byte + old_bytes; 362 ptrdiff_t prev_to_byte = from_byte + old_bytes;
363 EMACS_INT diff_chars = new_chars - old_chars; 363 ptrdiff_t diff_chars = new_chars - old_chars;
364 EMACS_INT diff_bytes = new_bytes - old_bytes; 364 ptrdiff_t diff_bytes = new_bytes - old_bytes;
365 365
366 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 366 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
367 { 367 {
@@ -390,13 +390,13 @@ buffer_overflow (void)
390/* Make the gap NBYTES_ADDED bytes longer. */ 390/* Make the gap NBYTES_ADDED bytes longer. */
391 391
392static void 392static void
393make_gap_larger (EMACS_INT nbytes_added) 393make_gap_larger (ptrdiff_t nbytes_added)
394{ 394{
395 Lisp_Object tem; 395 Lisp_Object tem;
396 EMACS_INT real_gap_loc; 396 ptrdiff_t real_gap_loc;
397 EMACS_INT real_gap_loc_byte; 397 ptrdiff_t real_gap_loc_byte;
398 EMACS_INT old_gap_size; 398 ptrdiff_t old_gap_size;
399 EMACS_INT current_size = Z_BYTE - BEG_BYTE + GAP_SIZE; 399 ptrdiff_t current_size = Z_BYTE - BEG_BYTE + GAP_SIZE;
400 enum { enough_for_a_while = 2000 }; 400 enum { enough_for_a_while = 2000 };
401 401
402 if (BUF_BYTES_MAX - current_size < nbytes_added) 402 if (BUF_BYTES_MAX - current_size < nbytes_added)
@@ -442,15 +442,15 @@ make_gap_larger (EMACS_INT nbytes_added)
442/* Make the gap NBYTES_REMOVED bytes shorter. */ 442/* Make the gap NBYTES_REMOVED bytes shorter. */
443 443
444static void 444static void
445make_gap_smaller (EMACS_INT nbytes_removed) 445make_gap_smaller (ptrdiff_t nbytes_removed)
446{ 446{
447 Lisp_Object tem; 447 Lisp_Object tem;
448 EMACS_INT real_gap_loc; 448 ptrdiff_t real_gap_loc;
449 EMACS_INT real_gap_loc_byte; 449 ptrdiff_t real_gap_loc_byte;
450 EMACS_INT real_Z; 450 ptrdiff_t real_Z;
451 EMACS_INT real_Z_byte; 451 ptrdiff_t real_Z_byte;
452 EMACS_INT real_beg_unchanged; 452 ptrdiff_t real_beg_unchanged;
453 EMACS_INT new_gap_size; 453 ptrdiff_t new_gap_size;
454 454
455 /* Make sure the gap is at least 20 bytes. */ 455 /* Make sure the gap is at least 20 bytes. */
456 if (GAP_SIZE - nbytes_removed < 20) 456 if (GAP_SIZE - nbytes_removed < 20)
@@ -500,7 +500,7 @@ make_gap_smaller (EMACS_INT nbytes_removed)
500#endif /* USE_MMAP_FOR_BUFFERS || REL_ALLOC || DOUG_LEA_MALLOC */ 500#endif /* USE_MMAP_FOR_BUFFERS || REL_ALLOC || DOUG_LEA_MALLOC */
501 501
502void 502void
503make_gap (EMACS_INT nbytes_added) 503make_gap (ptrdiff_t nbytes_added)
504{ 504{
505 if (nbytes_added >= 0) 505 if (nbytes_added >= 0)
506 make_gap_larger (nbytes_added); 506 make_gap_larger (nbytes_added);
@@ -517,9 +517,9 @@ make_gap (EMACS_INT nbytes_added)
517 517
518 Return the number of bytes stored at TO_ADDR. */ 518 Return the number of bytes stored at TO_ADDR. */
519 519
520EMACS_INT 520ptrdiff_t
521copy_text (const unsigned char *from_addr, unsigned char *to_addr, 521copy_text (const unsigned char *from_addr, unsigned char *to_addr,
522 EMACS_INT nbytes, int from_multibyte, int to_multibyte) 522 ptrdiff_t nbytes, int from_multibyte, int to_multibyte)
523{ 523{
524 if (from_multibyte == to_multibyte) 524 if (from_multibyte == to_multibyte)
525 { 525 {
@@ -528,8 +528,8 @@ copy_text (const unsigned char *from_addr, unsigned char *to_addr,
528 } 528 }
529 else if (from_multibyte) 529 else if (from_multibyte)
530 { 530 {
531 EMACS_INT nchars = 0; 531 ptrdiff_t nchars = 0;
532 EMACS_INT bytes_left = nbytes; 532 ptrdiff_t bytes_left = nbytes;
533 533
534 while (bytes_left > 0) 534 while (bytes_left > 0)
535 { 535 {
@@ -576,11 +576,11 @@ copy_text (const unsigned char *from_addr, unsigned char *to_addr,
576 prepare_to_modify_buffer could relocate the text. */ 576 prepare_to_modify_buffer could relocate the text. */
577 577
578void 578void
579insert (const char *string, EMACS_INT nbytes) 579insert (const char *string, ptrdiff_t nbytes)
580{ 580{
581 if (nbytes > 0) 581 if (nbytes > 0)
582 { 582 {
583 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 583 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
584 insert_1_both (string, len, nbytes, 0, 1, 0); 584 insert_1_both (string, len, nbytes, 0, 1, 0);
585 opoint = PT - len; 585 opoint = PT - len;
586 signal_after_change (opoint, 0, len); 586 signal_after_change (opoint, 0, len);
@@ -591,11 +591,11 @@ insert (const char *string, EMACS_INT nbytes)
591/* Likewise, but inherit text properties from neighboring characters. */ 591/* Likewise, but inherit text properties from neighboring characters. */
592 592
593void 593void
594insert_and_inherit (const char *string, EMACS_INT nbytes) 594insert_and_inherit (const char *string, ptrdiff_t nbytes)
595{ 595{
596 if (nbytes > 0) 596 if (nbytes > 0)
597 { 597 {
598 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 598 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
599 insert_1_both (string, len, nbytes, 1, 1, 0); 599 insert_1_both (string, len, nbytes, 1, 1, 0);
600 opoint = PT - len; 600 opoint = PT - len;
601 signal_after_change (opoint, 0, len); 601 signal_after_change (opoint, 0, len);
@@ -636,11 +636,11 @@ insert_string (const char *s)
636 since gc could happen and relocate it. */ 636 since gc could happen and relocate it. */
637 637
638void 638void
639insert_before_markers (const char *string, EMACS_INT nbytes) 639insert_before_markers (const char *string, ptrdiff_t nbytes)
640{ 640{
641 if (nbytes > 0) 641 if (nbytes > 0)
642 { 642 {
643 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 643 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
644 insert_1_both (string, len, nbytes, 0, 1, 1); 644 insert_1_both (string, len, nbytes, 0, 1, 1);
645 opoint = PT - len; 645 opoint = PT - len;
646 signal_after_change (opoint, 0, len); 646 signal_after_change (opoint, 0, len);
@@ -652,11 +652,11 @@ insert_before_markers (const char *string, EMACS_INT nbytes)
652 652
653void 653void
654insert_before_markers_and_inherit (const char *string, 654insert_before_markers_and_inherit (const char *string,
655 EMACS_INT nbytes) 655 ptrdiff_t nbytes)
656{ 656{
657 if (nbytes > 0) 657 if (nbytes > 0)
658 { 658 {
659 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 659 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
660 insert_1_both (string, len, nbytes, 1, 1, 1); 660 insert_1_both (string, len, nbytes, 1, 1, 1);
661 opoint = PT - len; 661 opoint = PT - len;
662 signal_after_change (opoint, 0, len); 662 signal_after_change (opoint, 0, len);
@@ -667,7 +667,7 @@ insert_before_markers_and_inherit (const char *string,
667/* Subroutine used by the insert functions above. */ 667/* Subroutine used by the insert functions above. */
668 668
669void 669void
670insert_1 (const char *string, EMACS_INT nbytes, 670insert_1 (const char *string, ptrdiff_t nbytes,
671 int inherit, int prepare, int before_markers) 671 int inherit, int prepare, int before_markers)
672{ 672{
673 insert_1_both (string, chars_in_text ((unsigned char *) string, nbytes), 673 insert_1_both (string, chars_in_text ((unsigned char *) string, nbytes),
@@ -683,8 +683,8 @@ insert_1 (const char *string, EMACS_INT nbytes,
683 which combine in this way. Otherwise, return 0. */ 683 which combine in this way. Otherwise, return 0. */
684 684
685int 685int
686count_combining_before (const unsigned char *string, EMACS_INT length, 686count_combining_before (const unsigned char *string, ptrdiff_t length,
687 EMACS_INT pos, EMACS_INT pos_byte) 687 ptrdiff_t pos, ptrdiff_t pos_byte)
688{ 688{
689 int len, combining_bytes; 689 int len, combining_bytes;
690 const unsigned char *p; 690 const unsigned char *p;
@@ -729,11 +729,11 @@ count_combining_before (const unsigned char *string, EMACS_INT length,
729 729
730int 730int
731count_combining_after (const unsigned char *string, 731count_combining_after (const unsigned char *string,
732 EMACS_INT length, EMACS_INT pos, EMACS_INT pos_byte) 732 ptrdiff_t length, ptrdiff_t pos, ptrdiff_t pos_byte)
733{ 733{
734 EMACS_INT opos_byte = pos_byte; 734 ptrdiff_t opos_byte = pos_byte;
735 EMACS_INT i; 735 ptrdiff_t i;
736 EMACS_INT bytes; 736 ptrdiff_t bytes;
737 unsigned char *bufp; 737 unsigned char *bufp;
738 738
739 if (NILP (current_buffer->enable_multibyte_characters)) 739 if (NILP (current_buffer->enable_multibyte_characters))
@@ -793,7 +793,7 @@ count_combining_after (const unsigned char *string,
793 793
794void 794void
795insert_1_both (const char *string, 795insert_1_both (const char *string,
796 EMACS_INT nchars, EMACS_INT nbytes, 796 ptrdiff_t nchars, ptrdiff_t nbytes,
797 int inherit, int prepare, int before_markers) 797 int inherit, int prepare, int before_markers)
798{ 798{
799 if (nchars == 0) 799 if (nchars == 0)
@@ -871,10 +871,10 @@ insert_1_both (const char *string,
871 without insert noticing. */ 871 without insert noticing. */
872 872
873void 873void
874insert_from_string (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, 874insert_from_string (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
875 EMACS_INT length, EMACS_INT length_byte, int inherit) 875 ptrdiff_t length, ptrdiff_t length_byte, int inherit)
876{ 876{
877 EMACS_INT opoint = PT; 877 ptrdiff_t opoint = PT;
878 878
879 if (SCHARS (string) == 0) 879 if (SCHARS (string) == 0)
880 return; 880 return;
@@ -890,11 +890,11 @@ insert_from_string (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
890 890
891void 891void
892insert_from_string_before_markers (Lisp_Object string, 892insert_from_string_before_markers (Lisp_Object string,
893 EMACS_INT pos, EMACS_INT pos_byte, 893 ptrdiff_t pos, ptrdiff_t pos_byte,
894 EMACS_INT length, EMACS_INT length_byte, 894 ptrdiff_t length, ptrdiff_t length_byte,
895 int inherit) 895 int inherit)
896{ 896{
897 EMACS_INT opoint = PT; 897 ptrdiff_t opoint = PT;
898 898
899 if (SCHARS (string) == 0) 899 if (SCHARS (string) == 0)
900 return; 900 return;
@@ -908,12 +908,12 @@ insert_from_string_before_markers (Lisp_Object string,
908/* Subroutine of the insertion functions above. */ 908/* Subroutine of the insertion functions above. */
909 909
910static void 910static void
911insert_from_string_1 (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, 911insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
912 EMACS_INT nchars, EMACS_INT nbytes, 912 ptrdiff_t nchars, ptrdiff_t nbytes,
913 int inherit, int before_markers) 913 int inherit, int before_markers)
914{ 914{
915 struct gcpro gcpro1; 915 struct gcpro gcpro1;
916 EMACS_INT outgoing_nbytes = nbytes; 916 ptrdiff_t outgoing_nbytes = nbytes;
917 INTERVAL intervals; 917 INTERVAL intervals;
918 918
919 /* Make OUTGOING_NBYTES describe the text 919 /* Make OUTGOING_NBYTES describe the text
@@ -1000,7 +1000,7 @@ insert_from_string_1 (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1000 starting at GPT_ADDR. */ 1000 starting at GPT_ADDR. */
1001 1001
1002void 1002void
1003insert_from_gap (EMACS_INT nchars, EMACS_INT nbytes) 1003insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
1004{ 1004{
1005 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 1005 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1006 nchars = nbytes; 1006 nchars = nbytes;
@@ -1046,9 +1046,9 @@ insert_from_gap (EMACS_INT nchars, EMACS_INT nbytes)
1046 1046
1047void 1047void
1048insert_from_buffer (struct buffer *buf, 1048insert_from_buffer (struct buffer *buf,
1049 EMACS_INT charpos, EMACS_INT nchars, int inherit) 1049 ptrdiff_t charpos, ptrdiff_t nchars, int inherit)
1050{ 1050{
1051 EMACS_INT opoint = PT; 1051 ptrdiff_t opoint = PT;
1052 1052
1053 insert_from_buffer_1 (buf, charpos, nchars, inherit); 1053 insert_from_buffer_1 (buf, charpos, nchars, inherit);
1054 signal_after_change (opoint, 0, PT - opoint); 1054 signal_after_change (opoint, 0, PT - opoint);
@@ -1057,13 +1057,13 @@ insert_from_buffer (struct buffer *buf,
1057 1057
1058static void 1058static void
1059insert_from_buffer_1 (struct buffer *buf, 1059insert_from_buffer_1 (struct buffer *buf,
1060 EMACS_INT from, EMACS_INT nchars, int inherit) 1060 ptrdiff_t from, ptrdiff_t nchars, int inherit)
1061{ 1061{
1062 EMACS_INT chunk, chunk_expanded; 1062 ptrdiff_t chunk, chunk_expanded;
1063 EMACS_INT from_byte = buf_charpos_to_bytepos (buf, from); 1063 ptrdiff_t from_byte = buf_charpos_to_bytepos (buf, from);
1064 EMACS_INT to_byte = buf_charpos_to_bytepos (buf, from + nchars); 1064 ptrdiff_t to_byte = buf_charpos_to_bytepos (buf, from + nchars);
1065 EMACS_INT incoming_nbytes = to_byte - from_byte; 1065 ptrdiff_t incoming_nbytes = to_byte - from_byte;
1066 EMACS_INT outgoing_nbytes = incoming_nbytes; 1066 ptrdiff_t outgoing_nbytes = incoming_nbytes;
1067 INTERVAL intervals; 1067 INTERVAL intervals;
1068 1068
1069 /* Make OUTGOING_NBYTES describe the text 1069 /* Make OUTGOING_NBYTES describe the text
@@ -1073,8 +1073,8 @@ insert_from_buffer_1 (struct buffer *buf,
1073 outgoing_nbytes = nchars; 1073 outgoing_nbytes = nchars;
1074 else if (NILP (BVAR (buf, enable_multibyte_characters))) 1074 else if (NILP (BVAR (buf, enable_multibyte_characters)))
1075 { 1075 {
1076 EMACS_INT outgoing_before_gap = 0; 1076 ptrdiff_t outgoing_before_gap = 0;
1077 EMACS_INT outgoing_after_gap = 0; 1077 ptrdiff_t outgoing_after_gap = 0;
1078 1078
1079 if (from < BUF_GPT (buf)) 1079 if (from < BUF_GPT (buf))
1080 { 1080 {
@@ -1191,10 +1191,10 @@ insert_from_buffer_1 (struct buffer *buf,
1191 PREV_TEXT nil means the new text was just inserted. */ 1191 PREV_TEXT nil means the new text was just inserted. */
1192 1192
1193static void 1193static void
1194adjust_after_replace (EMACS_INT from, EMACS_INT from_byte, 1194adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
1195 Lisp_Object prev_text, EMACS_INT len, EMACS_INT len_byte) 1195 Lisp_Object prev_text, ptrdiff_t len, ptrdiff_t len_byte)
1196{ 1196{
1197 EMACS_INT nchars_del = 0, nbytes_del = 0; 1197 ptrdiff_t nchars_del = 0, nbytes_del = 0;
1198 1198
1199#ifdef BYTE_COMBINING_DEBUG 1199#ifdef BYTE_COMBINING_DEBUG
1200 if (count_combining_before (GPT_ADDR, len_byte, from, from_byte) 1200 if (count_combining_before (GPT_ADDR, len_byte, from, from_byte)
@@ -1259,10 +1259,10 @@ adjust_after_replace (EMACS_INT from, EMACS_INT from_byte,
1259 - FROM) may be incorrect, the correct length is NEWLEN. */ 1259 - FROM) may be incorrect, the correct length is NEWLEN. */
1260 1260
1261void 1261void
1262adjust_after_insert (EMACS_INT from, EMACS_INT from_byte, 1262adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
1263 EMACS_INT to, EMACS_INT to_byte, EMACS_INT newlen) 1263 ptrdiff_t to, ptrdiff_t to_byte, ptrdiff_t newlen)
1264{ 1264{
1265 EMACS_INT len = to - from, len_byte = to_byte - from_byte; 1265 ptrdiff_t len = to - from, len_byte = to_byte - from_byte;
1266 1266
1267 if (GPT != to) 1267 if (GPT != to)
1268 move_gap_both (to, to_byte); 1268 move_gap_both (to, to_byte);
@@ -1286,16 +1286,16 @@ adjust_after_insert (EMACS_INT from, EMACS_INT from_byte,
1286 But if MARKERS is 0, don't relocate markers. */ 1286 But if MARKERS is 0, don't relocate markers. */
1287 1287
1288void 1288void
1289replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new, 1289replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1290 int prepare, int inherit, int markers) 1290 int prepare, int inherit, int markers)
1291{ 1291{
1292 EMACS_INT inschars = SCHARS (new); 1292 ptrdiff_t inschars = SCHARS (new);
1293 EMACS_INT insbytes = SBYTES (new); 1293 ptrdiff_t insbytes = SBYTES (new);
1294 EMACS_INT from_byte, to_byte; 1294 ptrdiff_t from_byte, to_byte;
1295 EMACS_INT nbytes_del, nchars_del; 1295 ptrdiff_t nbytes_del, nchars_del;
1296 struct gcpro gcpro1; 1296 struct gcpro gcpro1;
1297 INTERVAL intervals; 1297 INTERVAL intervals;
1298 EMACS_INT outgoing_insbytes = insbytes; 1298 ptrdiff_t outgoing_insbytes = insbytes;
1299 Lisp_Object deletion; 1299 Lisp_Object deletion;
1300 1300
1301 CHECK_MARKERS (); 1301 CHECK_MARKERS ();
@@ -1305,7 +1305,7 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new,
1305 1305
1306 if (prepare) 1306 if (prepare)
1307 { 1307 {
1308 EMACS_INT range_length = to - from; 1308 ptrdiff_t range_length = to - from;
1309 prepare_to_modify_buffer (from, to, &from); 1309 prepare_to_modify_buffer (from, to, &from);
1310 to = from + range_length; 1310 to = from + range_length;
1311 } 1311 }
@@ -1460,12 +1460,12 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new,
1460 prepare_to_modify_buffer and never call signal_after_change. */ 1460 prepare_to_modify_buffer and never call signal_after_change. */
1461 1461
1462void 1462void
1463replace_range_2 (EMACS_INT from, EMACS_INT from_byte, 1463replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1464 EMACS_INT to, EMACS_INT to_byte, 1464 ptrdiff_t to, ptrdiff_t to_byte,
1465 const char *ins, EMACS_INT inschars, EMACS_INT insbytes, 1465 const char *ins, ptrdiff_t inschars, ptrdiff_t insbytes,
1466 int markers) 1466 int markers)
1467{ 1467{
1468 EMACS_INT nbytes_del, nchars_del; 1468 ptrdiff_t nbytes_del, nchars_del;
1469 1469
1470 CHECK_MARKERS (); 1470 CHECK_MARKERS ();
1471 1471
@@ -1567,7 +1567,7 @@ replace_range_2 (EMACS_INT from, EMACS_INT from_byte,
1567 If TO comes before FROM, we delete nothing. */ 1567 If TO comes before FROM, we delete nothing. */
1568 1568
1569void 1569void
1570del_range (EMACS_INT from, EMACS_INT to) 1570del_range (ptrdiff_t from, ptrdiff_t to)
1571{ 1571{
1572 del_range_1 (from, to, 1, 0); 1572 del_range_1 (from, to, 1, 0);
1573} 1573}
@@ -1576,9 +1576,9 @@ del_range (EMACS_INT from, EMACS_INT to)
1576 RET_STRING says to return the deleted text. */ 1576 RET_STRING says to return the deleted text. */
1577 1577
1578Lisp_Object 1578Lisp_Object
1579del_range_1 (EMACS_INT from, EMACS_INT to, int prepare, int ret_string) 1579del_range_1 (ptrdiff_t from, ptrdiff_t to, int prepare, int ret_string)
1580{ 1580{
1581 EMACS_INT from_byte, to_byte; 1581 ptrdiff_t from_byte, to_byte;
1582 Lisp_Object deletion; 1582 Lisp_Object deletion;
1583 struct gcpro gcpro1; 1583 struct gcpro gcpro1;
1584 1584
@@ -1593,7 +1593,7 @@ del_range_1 (EMACS_INT from, EMACS_INT to, int prepare, int ret_string)
1593 1593
1594 if (prepare) 1594 if (prepare)
1595 { 1595 {
1596 EMACS_INT range_length = to - from; 1596 ptrdiff_t range_length = to - from;
1597 prepare_to_modify_buffer (from, to, &from); 1597 prepare_to_modify_buffer (from, to, &from);
1598 to = min (ZV, from + range_length); 1598 to = min (ZV, from + range_length);
1599 } 1599 }
@@ -1612,9 +1612,9 @@ del_range_1 (EMACS_INT from, EMACS_INT to, int prepare, int ret_string)
1612/* Like del_range_1 but args are byte positions, not char positions. */ 1612/* Like del_range_1 but args are byte positions, not char positions. */
1613 1613
1614void 1614void
1615del_range_byte (EMACS_INT from_byte, EMACS_INT to_byte, int prepare) 1615del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte, int prepare)
1616{ 1616{
1617 EMACS_INT from, to; 1617 ptrdiff_t from, to;
1618 1618
1619 /* Make args be valid */ 1619 /* Make args be valid */
1620 if (from_byte < BEGV_BYTE) 1620 if (from_byte < BEGV_BYTE)
@@ -1630,8 +1630,8 @@ del_range_byte (EMACS_INT from_byte, EMACS_INT to_byte, int prepare)
1630 1630
1631 if (prepare) 1631 if (prepare)
1632 { 1632 {
1633 EMACS_INT old_from = from, old_to = Z - to; 1633 ptrdiff_t old_from = from, old_to = Z - to;
1634 EMACS_INT range_length = to - from; 1634 ptrdiff_t range_length = to - from;
1635 prepare_to_modify_buffer (from, to, &from); 1635 prepare_to_modify_buffer (from, to, &from);
1636 to = from + range_length; 1636 to = from + range_length;
1637 1637
@@ -1655,8 +1655,8 @@ del_range_byte (EMACS_INT from_byte, EMACS_INT to_byte, int prepare)
1655 and bytepos. */ 1655 and bytepos. */
1656 1656
1657void 1657void
1658del_range_both (EMACS_INT from, EMACS_INT from_byte, 1658del_range_both (ptrdiff_t from, ptrdiff_t from_byte,
1659 EMACS_INT to, EMACS_INT to_byte, int prepare) 1659 ptrdiff_t to, ptrdiff_t to_byte, int prepare)
1660{ 1660{
1661 /* Make args be valid */ 1661 /* Make args be valid */
1662 if (from_byte < BEGV_BYTE) 1662 if (from_byte < BEGV_BYTE)
@@ -1674,8 +1674,8 @@ del_range_both (EMACS_INT from, EMACS_INT from_byte,
1674 1674
1675 if (prepare) 1675 if (prepare)
1676 { 1676 {
1677 EMACS_INT old_from = from, old_to = Z - to; 1677 ptrdiff_t old_from = from, old_to = Z - to;
1678 EMACS_INT range_length = to - from; 1678 ptrdiff_t range_length = to - from;
1679 prepare_to_modify_buffer (from, to, &from); 1679 prepare_to_modify_buffer (from, to, &from);
1680 to = from + range_length; 1680 to = from + range_length;
1681 1681
@@ -1701,10 +1701,10 @@ del_range_both (EMACS_INT from, EMACS_INT from_byte,
1701 If RET_STRING is true, the deleted area is returned as a string. */ 1701 If RET_STRING is true, the deleted area is returned as a string. */
1702 1702
1703Lisp_Object 1703Lisp_Object
1704del_range_2 (EMACS_INT from, EMACS_INT from_byte, 1704del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1705 EMACS_INT to, EMACS_INT to_byte, int ret_string) 1705 ptrdiff_t to, ptrdiff_t to_byte, int ret_string)
1706{ 1706{
1707 register EMACS_INT nbytes_del, nchars_del; 1707 register ptrdiff_t nbytes_del, nchars_del;
1708 Lisp_Object deletion; 1708 Lisp_Object deletion;
1709 1709
1710 CHECK_MARKERS (); 1710 CHECK_MARKERS ();
@@ -1788,7 +1788,7 @@ del_range_2 (EMACS_INT from, EMACS_INT from_byte,
1788 Otherwise set CHARS_MODIFF to the new value of MODIFF. */ 1788 Otherwise set CHARS_MODIFF to the new value of MODIFF. */
1789 1789
1790void 1790void
1791modify_region (struct buffer *buffer, EMACS_INT start, EMACS_INT end, 1791modify_region (struct buffer *buffer, ptrdiff_t start, ptrdiff_t end,
1792 int preserve_chars_modiff) 1792 int preserve_chars_modiff)
1793{ 1793{
1794 struct buffer *old_buffer = current_buffer; 1794 struct buffer *old_buffer = current_buffer;
@@ -1823,8 +1823,8 @@ modify_region (struct buffer *buffer, EMACS_INT start, EMACS_INT end,
1823 by holding its value temporarily in a marker. */ 1823 by holding its value temporarily in a marker. */
1824 1824
1825void 1825void
1826prepare_to_modify_buffer (EMACS_INT start, EMACS_INT end, 1826prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
1827 EMACS_INT *preserve_ptr) 1827 ptrdiff_t *preserve_ptr)
1828{ 1828{
1829 struct buffer *base_buffer; 1829 struct buffer *base_buffer;
1830 1830
@@ -1885,8 +1885,8 @@ prepare_to_modify_buffer (EMACS_INT start, EMACS_INT end,
1885 : (!NILP (Vselect_active_regions) 1885 : (!NILP (Vselect_active_regions)
1886 && !NILP (Vtransient_mark_mode)))) 1886 && !NILP (Vtransient_mark_mode))))
1887 { 1887 {
1888 EMACS_INT b = XMARKER (BVAR (current_buffer, mark))->charpos; 1888 ptrdiff_t b = XMARKER (BVAR (current_buffer, mark))->charpos;
1889 EMACS_INT e = PT; 1889 ptrdiff_t e = PT;
1890 if (b < e) 1890 if (b < e)
1891 Vsaved_region_selection = make_buffer_string (b, e, 0); 1891 Vsaved_region_selection = make_buffer_string (b, e, 0);
1892 else if (b > e) 1892 else if (b > e)
@@ -1954,14 +1954,14 @@ reset_var_on_error (Lisp_Object val)
1954 by holding its value temporarily in a marker. */ 1954 by holding its value temporarily in a marker. */
1955 1955
1956static void 1956static void
1957signal_before_change (EMACS_INT start_int, EMACS_INT end_int, 1957signal_before_change (ptrdiff_t start_int, ptrdiff_t end_int,
1958 EMACS_INT *preserve_ptr) 1958 ptrdiff_t *preserve_ptr)
1959{ 1959{
1960 Lisp_Object start, end; 1960 Lisp_Object start, end;
1961 Lisp_Object start_marker, end_marker; 1961 Lisp_Object start_marker, end_marker;
1962 Lisp_Object preserve_marker; 1962 Lisp_Object preserve_marker;
1963 struct gcpro gcpro1, gcpro2, gcpro3; 1963 struct gcpro gcpro1, gcpro2, gcpro3;
1964 int count = SPECPDL_INDEX (); 1964 ptrdiff_t count = SPECPDL_INDEX ();
1965 1965
1966 if (inhibit_modification_hooks) 1966 if (inhibit_modification_hooks)
1967 return; 1967 return;
@@ -2032,9 +2032,9 @@ signal_before_change (EMACS_INT start_int, EMACS_INT end_int,
2032 after the change. */ 2032 after the change. */
2033 2033
2034void 2034void
2035signal_after_change (EMACS_INT charpos, EMACS_INT lendel, EMACS_INT lenins) 2035signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins)
2036{ 2036{
2037 int count = SPECPDL_INDEX (); 2037 ptrdiff_t count = SPECPDL_INDEX ();
2038 if (inhibit_modification_hooks) 2038 if (inhibit_modification_hooks)
2039 return; 2039 return;
2040 2040
@@ -2115,9 +2115,9 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
2115 doc: /* This function is for use internally in `combine-after-change-calls'. */) 2115 doc: /* This function is for use internally in `combine-after-change-calls'. */)
2116 (void) 2116 (void)
2117{ 2117{
2118 int count = SPECPDL_INDEX (); 2118 ptrdiff_t count = SPECPDL_INDEX ();
2119 EMACS_INT beg, end, change; 2119 ptrdiff_t beg, end, change;
2120 EMACS_INT begpos, endpos; 2120 ptrdiff_t begpos, endpos;
2121 Lisp_Object tail; 2121 Lisp_Object tail;
2122 2122
2123 if (NILP (combine_after_change_list)) 2123 if (NILP (combine_after_change_list))
@@ -2151,7 +2151,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
2151 tail = XCDR (tail)) 2151 tail = XCDR (tail))
2152 { 2152 {
2153 Lisp_Object elt; 2153 Lisp_Object elt;
2154 EMACS_INT thisbeg, thisend, thischange; 2154 ptrdiff_t thisbeg, thisend, thischange;
2155 2155
2156 /* Extract the info from the next element. */ 2156 /* Extract the info from the next element. */
2157 elt = XCAR (tail); 2157 elt = XCAR (tail);
diff --git a/src/intervals.c b/src/intervals.c
index a750ccd13f7..0b332caf897 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -223,7 +223,7 @@ traverse_intervals_noorder (INTERVAL tree, void (*function) (INTERVAL, Lisp_Obje
223 Pass FUNCTION two args: an interval, and ARG. */ 223 Pass FUNCTION two args: an interval, and ARG. */
224 224
225void 225void
226traverse_intervals (INTERVAL tree, EMACS_INT position, 226traverse_intervals (INTERVAL tree, ptrdiff_t position,
227 void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg) 227 void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg)
228{ 228{
229 while (!NULL_INTERVAL_P (tree)) 229 while (!NULL_INTERVAL_P (tree))
@@ -313,7 +313,7 @@ rotate_right (INTERVAL interval)
313{ 313{
314 INTERVAL i; 314 INTERVAL i;
315 INTERVAL B = interval->left; 315 INTERVAL B = interval->left;
316 EMACS_INT old_total = interval->total_length; 316 ptrdiff_t old_total = interval->total_length;
317 317
318 /* Deal with any Parent of A; make it point to B. */ 318 /* Deal with any Parent of A; make it point to B. */
319 if (! ROOT_INTERVAL_P (interval)) 319 if (! ROOT_INTERVAL_P (interval))
@@ -360,7 +360,7 @@ rotate_left (INTERVAL interval)
360{ 360{
361 INTERVAL i; 361 INTERVAL i;
362 INTERVAL B = interval->right; 362 INTERVAL B = interval->right;
363 EMACS_INT old_total = interval->total_length; 363 ptrdiff_t old_total = interval->total_length;
364 364
365 /* Deal with any parent of A; make it point to B. */ 365 /* Deal with any parent of A; make it point to B. */
366 if (! ROOT_INTERVAL_P (interval)) 366 if (! ROOT_INTERVAL_P (interval))
@@ -399,7 +399,7 @@ rotate_left (INTERVAL interval)
399static INTERVAL 399static INTERVAL
400balance_an_interval (INTERVAL i) 400balance_an_interval (INTERVAL i)
401{ 401{
402 register EMACS_INT old_diff, new_diff; 402 register ptrdiff_t old_diff, new_diff;
403 403
404 while (1) 404 while (1)
405 { 405 {
@@ -499,11 +499,11 @@ balance_intervals (INTERVAL tree)
499 it is still a root after this operation. */ 499 it is still a root after this operation. */
500 500
501INTERVAL 501INTERVAL
502split_interval_right (INTERVAL interval, EMACS_INT offset) 502split_interval_right (INTERVAL interval, ptrdiff_t offset)
503{ 503{
504 INTERVAL new = make_interval (); 504 INTERVAL new = make_interval ();
505 EMACS_INT position = interval->position; 505 ptrdiff_t position = interval->position;
506 EMACS_INT new_length = LENGTH (interval) - offset; 506 ptrdiff_t new_length = LENGTH (interval) - offset;
507 507
508 new->position = position + offset; 508 new->position = position + offset;
509 SET_INTERVAL_PARENT (new, interval); 509 SET_INTERVAL_PARENT (new, interval);
@@ -544,10 +544,10 @@ split_interval_right (INTERVAL interval, EMACS_INT offset)
544 it is still a root after this operation. */ 544 it is still a root after this operation. */
545 545
546INTERVAL 546INTERVAL
547split_interval_left (INTERVAL interval, EMACS_INT offset) 547split_interval_left (INTERVAL interval, ptrdiff_t offset)
548{ 548{
549 INTERVAL new = make_interval (); 549 INTERVAL new = make_interval ();
550 EMACS_INT new_length = offset; 550 ptrdiff_t new_length = offset;
551 551
552 new->position = interval->position; 552 new->position = interval->position;
553 interval->position = interval->position + offset; 553 interval->position = interval->position + offset;
@@ -610,11 +610,11 @@ interval_start_pos (INTERVAL source)
610 will update this cache based on the result of find_interval. */ 610 will update this cache based on the result of find_interval. */
611 611
612INTERVAL 612INTERVAL
613find_interval (register INTERVAL tree, register EMACS_INT position) 613find_interval (register INTERVAL tree, register ptrdiff_t position)
614{ 614{
615 /* The distance from the left edge of the subtree at TREE 615 /* The distance from the left edge of the subtree at TREE
616 to POSITION. */ 616 to POSITION. */
617 register EMACS_INT relative_position; 617 register ptrdiff_t relative_position;
618 618
619 if (NULL_INTERVAL_P (tree)) 619 if (NULL_INTERVAL_P (tree))
620 return NULL_INTERVAL; 620 return NULL_INTERVAL;
@@ -667,7 +667,7 @@ INTERVAL
667next_interval (register INTERVAL interval) 667next_interval (register INTERVAL interval)
668{ 668{
669 register INTERVAL i = interval; 669 register INTERVAL i = interval;
670 register EMACS_INT next_position; 670 register ptrdiff_t next_position;
671 671
672 if (NULL_INTERVAL_P (i)) 672 if (NULL_INTERVAL_P (i))
673 return NULL_INTERVAL; 673 return NULL_INTERVAL;
@@ -742,7 +742,7 @@ previous_interval (register INTERVAL interval)
742 To speed up the process, we assume that the ->position of 742 To speed up the process, we assume that the ->position of
743 I and all its parents is already uptodate. */ 743 I and all its parents is already uptodate. */
744INTERVAL 744INTERVAL
745update_interval (register INTERVAL i, EMACS_INT pos) 745update_interval (register INTERVAL i, ptrdiff_t pos)
746{ 746{
747 if (NULL_INTERVAL_P (i)) 747 if (NULL_INTERVAL_P (i))
748 return NULL_INTERVAL; 748 return NULL_INTERVAL;
@@ -774,7 +774,7 @@ update_interval (register INTERVAL i, EMACS_INT pos)
774 i = i->right; /* Move to the right child */ 774 i = i->right; /* Move to the right child */
775 } 775 }
776 else if (NULL_PARENT (i)) 776 else if (NULL_PARENT (i))
777 error ("Point %"pI"d after end of properties", pos); 777 error ("Point %"pD"d after end of properties", pos);
778 else 778 else
779 i = INTERVAL_PARENT (i); 779 i = INTERVAL_PARENT (i);
780 continue; 780 continue;
@@ -799,10 +799,10 @@ update_interval (register INTERVAL i, EMACS_INT pos)
799 to the root. */ 799 to the root. */
800 800
801static INTERVAL 801static INTERVAL
802adjust_intervals_for_insertion (INTERVAL tree, EMACS_INT position, 802adjust_intervals_for_insertion (INTERVAL tree, ptrdiff_t position,
803 EMACS_INT length) 803 ptrdiff_t length)
804{ 804{
805 register EMACS_INT relative_position; 805 register ptrdiff_t relative_position;
806 register INTERVAL this; 806 register INTERVAL this;
807 807
808 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ 808 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */
@@ -861,13 +861,13 @@ adjust_intervals_for_insertion (INTERVAL tree, EMACS_INT position,
861 861
862static INTERVAL 862static INTERVAL
863adjust_intervals_for_insertion (INTERVAL tree, 863adjust_intervals_for_insertion (INTERVAL tree,
864 EMACS_INT position, EMACS_INT length) 864 ptrdiff_t position, ptrdiff_t length)
865{ 865{
866 register INTERVAL i; 866 register INTERVAL i;
867 register INTERVAL temp; 867 register INTERVAL temp;
868 int eobp = 0; 868 int eobp = 0;
869 Lisp_Object parent; 869 Lisp_Object parent;
870 EMACS_INT offset; 870 ptrdiff_t offset;
871 871
872 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ 872 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */
873 abort (); 873 abort ();
@@ -1226,7 +1226,7 @@ static INTERVAL
1226delete_node (register INTERVAL i) 1226delete_node (register INTERVAL i)
1227{ 1227{
1228 register INTERVAL migrate, this; 1228 register INTERVAL migrate, this;
1229 register EMACS_INT migrate_amt; 1229 register ptrdiff_t migrate_amt;
1230 1230
1231 if (NULL_INTERVAL_P (i->left)) 1231 if (NULL_INTERVAL_P (i->left))
1232 return i->right; 1232 return i->right;
@@ -1259,7 +1259,7 @@ static void
1259delete_interval (register INTERVAL i) 1259delete_interval (register INTERVAL i)
1260{ 1260{
1261 register INTERVAL parent; 1261 register INTERVAL parent;
1262 EMACS_INT amt = LENGTH (i); 1262 ptrdiff_t amt = LENGTH (i);
1263 1263
1264 if (amt > 0) /* Only used on zero-length intervals now. */ 1264 if (amt > 0) /* Only used on zero-length intervals now. */
1265 abort (); 1265 abort ();
@@ -1309,11 +1309,11 @@ delete_interval (register INTERVAL i)
1309 Do this by recursing down TREE to the interval in question, and 1309 Do this by recursing down TREE to the interval in question, and
1310 deleting the appropriate amount of text. */ 1310 deleting the appropriate amount of text. */
1311 1311
1312static EMACS_INT 1312static ptrdiff_t
1313interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, 1313interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from,
1314 register EMACS_INT amount) 1314 register ptrdiff_t amount)
1315{ 1315{
1316 register EMACS_INT relative_position = from; 1316 register ptrdiff_t relative_position = from;
1317 1317
1318 if (NULL_INTERVAL_P (tree)) 1318 if (NULL_INTERVAL_P (tree))
1319 return 0; 1319 return 0;
@@ -1321,7 +1321,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
1321 /* Left branch. */ 1321 /* Left branch. */
1322 if (relative_position < LEFT_TOTAL_LENGTH (tree)) 1322 if (relative_position < LEFT_TOTAL_LENGTH (tree))
1323 { 1323 {
1324 EMACS_INT subtract = interval_deletion_adjustment (tree->left, 1324 ptrdiff_t subtract = interval_deletion_adjustment (tree->left,
1325 relative_position, 1325 relative_position,
1326 amount); 1326 amount);
1327 tree->total_length -= subtract; 1327 tree->total_length -= subtract;
@@ -1332,7 +1332,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
1332 else if (relative_position >= (TOTAL_LENGTH (tree) 1332 else if (relative_position >= (TOTAL_LENGTH (tree)
1333 - RIGHT_TOTAL_LENGTH (tree))) 1333 - RIGHT_TOTAL_LENGTH (tree)))
1334 { 1334 {
1335 EMACS_INT subtract; 1335 ptrdiff_t subtract;
1336 1336
1337 relative_position -= (tree->total_length 1337 relative_position -= (tree->total_length
1338 - RIGHT_TOTAL_LENGTH (tree)); 1338 - RIGHT_TOTAL_LENGTH (tree));
@@ -1347,7 +1347,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
1347 else 1347 else
1348 { 1348 {
1349 /* How much can we delete from this interval? */ 1349 /* How much can we delete from this interval? */
1350 EMACS_INT my_amount = ((tree->total_length 1350 ptrdiff_t my_amount = ((tree->total_length
1351 - RIGHT_TOTAL_LENGTH (tree)) 1351 - RIGHT_TOTAL_LENGTH (tree))
1352 - relative_position); 1352 - relative_position);
1353 1353
@@ -1372,12 +1372,12 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
1372 1372
1373static void 1373static void
1374adjust_intervals_for_deletion (struct buffer *buffer, 1374adjust_intervals_for_deletion (struct buffer *buffer,
1375 EMACS_INT start, EMACS_INT length) 1375 ptrdiff_t start, ptrdiff_t length)
1376{ 1376{
1377 register EMACS_INT left_to_delete = length; 1377 register ptrdiff_t left_to_delete = length;
1378 register INTERVAL tree = BUF_INTERVALS (buffer); 1378 register INTERVAL tree = BUF_INTERVALS (buffer);
1379 Lisp_Object parent; 1379 Lisp_Object parent;
1380 EMACS_INT offset; 1380 ptrdiff_t offset;
1381 1381
1382 GET_INTERVAL_OBJECT (parent, tree); 1382 GET_INTERVAL_OBJECT (parent, tree);
1383 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); 1383 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0);
@@ -1427,7 +1427,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1427 adjust_intervals_for_deletion) from a non-static inline function. */ 1427 adjust_intervals_for_deletion) from a non-static inline function. */
1428 1428
1429void 1429void
1430offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length) 1430offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length)
1431{ 1431{
1432 if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) 1432 if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0)
1433 return; 1433 return;
@@ -1436,7 +1436,7 @@ offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
1436 adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length); 1436 adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length);
1437 else 1437 else
1438 { 1438 {
1439 IF_LINT (if (length < - TYPE_MAXIMUM (EMACS_INT)) abort ();) 1439 IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();)
1440 adjust_intervals_for_deletion (buffer, start, -length); 1440 adjust_intervals_for_deletion (buffer, start, -length);
1441 } 1441 }
1442} 1442}
@@ -1453,7 +1453,7 @@ offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
1453static INTERVAL 1453static INTERVAL
1454merge_interval_right (register INTERVAL i) 1454merge_interval_right (register INTERVAL i)
1455{ 1455{
1456 register EMACS_INT absorb = LENGTH (i); 1456 register ptrdiff_t absorb = LENGTH (i);
1457 register INTERVAL successor; 1457 register INTERVAL successor;
1458 1458
1459 /* Zero out this interval. */ 1459 /* Zero out this interval. */
@@ -1509,7 +1509,7 @@ merge_interval_right (register INTERVAL i)
1509INTERVAL 1509INTERVAL
1510merge_interval_left (register INTERVAL i) 1510merge_interval_left (register INTERVAL i)
1511{ 1511{
1512 register EMACS_INT absorb = LENGTH (i); 1512 register ptrdiff_t absorb = LENGTH (i);
1513 register INTERVAL predecessor; 1513 register INTERVAL predecessor;
1514 1514
1515 /* Zero out this interval. */ 1515 /* Zero out this interval. */
@@ -1603,7 +1603,7 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent)
1603 interval. */ 1603 interval. */
1604 1604
1605static INTERVAL 1605static INTERVAL
1606make_new_interval (INTERVAL intervals, EMACS_INT start, EMACS_INT length) 1606make_new_interval (INTERVAL intervals, ptrdiff_t start, ptrdiff_t length)
1607{ 1607{
1608 INTERVAL slot; 1608 INTERVAL slot;
1609 1609
@@ -1675,13 +1675,13 @@ make_new_interval (INTERVAL intervals, EMACS_INT start, EMACS_INT length)
1675 text... */ 1675 text... */
1676 1676
1677void 1677void
1678graft_intervals_into_buffer (INTERVAL source, EMACS_INT position, 1678graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
1679 EMACS_INT length, struct buffer *buffer, 1679 ptrdiff_t length, struct buffer *buffer,
1680 int inherit) 1680 int inherit)
1681{ 1681{
1682 register INTERVAL under, over, this; 1682 register INTERVAL under, over, this;
1683 register INTERVAL tree; 1683 register INTERVAL tree;
1684 EMACS_INT over_used; 1684 ptrdiff_t over_used;
1685 1685
1686 tree = BUF_INTERVALS (buffer); 1686 tree = BUF_INTERVALS (buffer);
1687 1687
@@ -1863,7 +1863,7 @@ lookup_char_property (Lisp_Object plist, register Lisp_Object prop, int textprop
1863 1863
1864void 1864void
1865temp_set_point_both (struct buffer *buffer, 1865temp_set_point_both (struct buffer *buffer,
1866 EMACS_INT charpos, EMACS_INT bytepos) 1866 ptrdiff_t charpos, ptrdiff_t bytepos)
1867{ 1867{
1868 /* In a single-byte buffer, the two positions must be equal. */ 1868 /* In a single-byte buffer, the two positions must be equal. */
1869 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer) 1869 if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)
@@ -1882,7 +1882,7 @@ temp_set_point_both (struct buffer *buffer,
1882/* Set point "temporarily", without checking any text properties. */ 1882/* Set point "temporarily", without checking any text properties. */
1883 1883
1884void 1884void
1885temp_set_point (struct buffer *buffer, EMACS_INT charpos) 1885temp_set_point (struct buffer *buffer, ptrdiff_t charpos)
1886{ 1886{
1887 temp_set_point_both (buffer, charpos, 1887 temp_set_point_both (buffer, charpos,
1888 buf_charpos_to_bytepos (buffer, charpos)); 1888 buf_charpos_to_bytepos (buffer, charpos));
@@ -1892,7 +1892,7 @@ temp_set_point (struct buffer *buffer, EMACS_INT charpos)
1892 before an intangible character, move to an ok place. */ 1892 before an intangible character, move to an ok place. */
1893 1893
1894void 1894void
1895set_point (EMACS_INT charpos) 1895set_point (ptrdiff_t charpos)
1896{ 1896{
1897 set_point_both (charpos, buf_charpos_to_bytepos (current_buffer, charpos)); 1897 set_point_both (charpos, buf_charpos_to_bytepos (current_buffer, charpos));
1898} 1898}
@@ -1908,8 +1908,8 @@ set_point (EMACS_INT charpos)
1908 Note that `stickiness' is determined by overlay marker insertion types, 1908 Note that `stickiness' is determined by overlay marker insertion types,
1909 if the invisible property comes from an overlay. */ 1909 if the invisible property comes from an overlay. */
1910 1910
1911static EMACS_INT 1911static ptrdiff_t
1912adjust_for_invis_intang (EMACS_INT pos, EMACS_INT test_offs, EMACS_INT adj, 1912adjust_for_invis_intang (ptrdiff_t pos, ptrdiff_t test_offs, ptrdiff_t adj,
1913 int test_intang) 1913 int test_intang)
1914{ 1914{
1915 Lisp_Object invis_propval, invis_overlay; 1915 Lisp_Object invis_propval, invis_overlay;
@@ -1948,18 +1948,18 @@ adjust_for_invis_intang (EMACS_INT pos, EMACS_INT test_offs, EMACS_INT adj,
1948 before an intangible character, move to an ok place. */ 1948 before an intangible character, move to an ok place. */
1949 1949
1950void 1950void
1951set_point_both (EMACS_INT charpos, EMACS_INT bytepos) 1951set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
1952{ 1952{
1953 register INTERVAL to, from, toprev, fromprev; 1953 register INTERVAL to, from, toprev, fromprev;
1954 EMACS_INT buffer_point; 1954 ptrdiff_t buffer_point;
1955 EMACS_INT old_position = PT; 1955 ptrdiff_t old_position = PT;
1956 /* This ensures that we move forward past intangible text when the 1956 /* This ensures that we move forward past intangible text when the
1957 initial position is the same as the destination, in the rare 1957 initial position is the same as the destination, in the rare
1958 instances where this is important, e.g. in line-move-finish 1958 instances where this is important, e.g. in line-move-finish
1959 (simple.el). */ 1959 (simple.el). */
1960 int backwards = (charpos < old_position ? 1 : 0); 1960 int backwards = (charpos < old_position ? 1 : 0);
1961 int have_overlays; 1961 int have_overlays;
1962 EMACS_INT original_position; 1962 ptrdiff_t original_position;
1963 1963
1964 BVAR (current_buffer, point_before_scroll) = Qnil; 1964 BVAR (current_buffer, point_before_scroll) = Qnil;
1965 1965
@@ -2172,7 +2172,7 @@ set_point_both (EMACS_INT charpos, EMACS_INT bytepos)
2172 segment that reaches all the way to point. */ 2172 segment that reaches all the way to point. */
2173 2173
2174void 2174void
2175move_if_not_intangible (EMACS_INT position) 2175move_if_not_intangible (ptrdiff_t position)
2176{ 2176{
2177 Lisp_Object pos; 2177 Lisp_Object pos;
2178 Lisp_Object intangible_propval; 2178 Lisp_Object intangible_propval;
@@ -2235,8 +2235,8 @@ move_if_not_intangible (EMACS_INT position)
2235 nil means the current buffer. */ 2235 nil means the current buffer. */
2236 2236
2237int 2237int
2238get_property_and_range (EMACS_INT pos, Lisp_Object prop, Lisp_Object *val, 2238get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val,
2239 EMACS_INT *start, EMACS_INT *end, Lisp_Object object) 2239 ptrdiff_t *start, ptrdiff_t *end, Lisp_Object object)
2240{ 2240{
2241 INTERVAL i, prev, next; 2241 INTERVAL i, prev, next;
2242 2242
@@ -2279,11 +2279,11 @@ get_property_and_range (EMACS_INT pos, Lisp_Object prop, Lisp_Object *val,
2279 POSITION must be in the accessible part of BUFFER. */ 2279 POSITION must be in the accessible part of BUFFER. */
2280 2280
2281Lisp_Object 2281Lisp_Object
2282get_local_map (register EMACS_INT position, register struct buffer *buffer, 2282get_local_map (register ptrdiff_t position, register struct buffer *buffer,
2283 Lisp_Object type) 2283 Lisp_Object type)
2284{ 2284{
2285 Lisp_Object prop, lispy_position, lispy_buffer; 2285 Lisp_Object prop, lispy_position, lispy_buffer;
2286 EMACS_INT old_begv, old_zv, old_begv_byte, old_zv_byte; 2286 ptrdiff_t old_begv, old_zv, old_begv_byte, old_zv_byte;
2287 2287
2288 /* Perhaps we should just change `position' to the limit. */ 2288 /* Perhaps we should just change `position' to the limit. */
2289 if (position > BUF_ZV (buffer) || position < BUF_BEGV (buffer)) 2289 if (position > BUF_ZV (buffer) || position < BUF_BEGV (buffer))
@@ -2330,10 +2330,10 @@ get_local_map (register EMACS_INT position, register struct buffer *buffer,
2330 The new interval tree has no parent and has a starting-position of 0. */ 2330 The new interval tree has no parent and has a starting-position of 0. */
2331 2331
2332INTERVAL 2332INTERVAL
2333copy_intervals (INTERVAL tree, EMACS_INT start, EMACS_INT length) 2333copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length)
2334{ 2334{
2335 register INTERVAL i, new, t; 2335 register INTERVAL i, new, t;
2336 register EMACS_INT got, prevlen; 2336 register ptrdiff_t got, prevlen;
2337 2337
2338 if (NULL_INTERVAL_P (tree) || length <= 0) 2338 if (NULL_INTERVAL_P (tree) || length <= 0)
2339 return NULL_INTERVAL; 2339 return NULL_INTERVAL;
@@ -2372,7 +2372,7 @@ copy_intervals (INTERVAL tree, EMACS_INT start, EMACS_INT length)
2372 2372
2373void 2373void
2374copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, 2374copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
2375 EMACS_INT position, EMACS_INT length) 2375 ptrdiff_t position, ptrdiff_t length)
2376{ 2376{
2377 INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer), 2377 INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer),
2378 position, length); 2378 position, length);
@@ -2390,8 +2390,8 @@ int
2390compare_string_intervals (Lisp_Object s1, Lisp_Object s2) 2390compare_string_intervals (Lisp_Object s1, Lisp_Object s2)
2391{ 2391{
2392 INTERVAL i1, i2; 2392 INTERVAL i1, i2;
2393 EMACS_INT pos = 0; 2393 ptrdiff_t pos = 0;
2394 EMACS_INT end = SCHARS (s1); 2394 ptrdiff_t end = SCHARS (s1);
2395 2395
2396 i1 = find_interval (STRING_INTERVALS (s1), 0); 2396 i1 = find_interval (STRING_INTERVALS (s1), 0);
2397 i2 = find_interval (STRING_INTERVALS (s2), 0); 2397 i2 = find_interval (STRING_INTERVALS (s2), 0);
@@ -2399,9 +2399,9 @@ compare_string_intervals (Lisp_Object s1, Lisp_Object s2)
2399 while (pos < end) 2399 while (pos < end)
2400 { 2400 {
2401 /* Determine how far we can go before we reach the end of I1 or I2. */ 2401 /* Determine how far we can go before we reach the end of I1 or I2. */
2402 EMACS_INT len1 = (i1 != 0 ? INTERVAL_LAST_POS (i1) : end) - pos; 2402 ptrdiff_t len1 = (i1 != 0 ? INTERVAL_LAST_POS (i1) : end) - pos;
2403 EMACS_INT len2 = (i2 != 0 ? INTERVAL_LAST_POS (i2) : end) - pos; 2403 ptrdiff_t len2 = (i2 != 0 ? INTERVAL_LAST_POS (i2) : end) - pos;
2404 EMACS_INT distance = min (len1, len2); 2404 ptrdiff_t distance = min (len1, len2);
2405 2405
2406 /* If we ever find a mismatch between the strings, 2406 /* If we ever find a mismatch between the strings,
2407 they differ. */ 2407 they differ. */
@@ -2426,8 +2426,8 @@ compare_string_intervals (Lisp_Object s1, Lisp_Object s2)
2426 2426
2427static void 2427static void
2428set_intervals_multibyte_1 (INTERVAL i, int multi_flag, 2428set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
2429 EMACS_INT start, EMACS_INT start_byte, 2429 ptrdiff_t start, ptrdiff_t start_byte,
2430 EMACS_INT end, EMACS_INT end_byte) 2430 ptrdiff_t end, ptrdiff_t end_byte)
2431{ 2431{
2432 /* Fix the length of this interval. */ 2432 /* Fix the length of this interval. */
2433 if (multi_flag) 2433 if (multi_flag)
@@ -2445,11 +2445,11 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
2445 /* Recursively fix the length of the subintervals. */ 2445 /* Recursively fix the length of the subintervals. */
2446 if (i->left) 2446 if (i->left)
2447 { 2447 {
2448 EMACS_INT left_end, left_end_byte; 2448 ptrdiff_t left_end, left_end_byte;
2449 2449
2450 if (multi_flag) 2450 if (multi_flag)
2451 { 2451 {
2452 EMACS_INT temp; 2452 ptrdiff_t temp;
2453 left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i); 2453 left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i);
2454 left_end = BYTE_TO_CHAR (left_end_byte); 2454 left_end = BYTE_TO_CHAR (left_end_byte);
2455 2455
@@ -2478,11 +2478,11 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
2478 } 2478 }
2479 if (i->right) 2479 if (i->right)
2480 { 2480 {
2481 EMACS_INT right_start_byte, right_start; 2481 ptrdiff_t right_start_byte, right_start;
2482 2482
2483 if (multi_flag) 2483 if (multi_flag)
2484 { 2484 {
2485 EMACS_INT temp; 2485 ptrdiff_t temp;
2486 2486
2487 right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i); 2487 right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i);
2488 right_start = BYTE_TO_CHAR (right_start_byte); 2488 right_start = BYTE_TO_CHAR (right_start_byte);
diff --git a/src/intervals.h b/src/intervals.h
index 7d23ce40f49..6a2a8c9d83d 100644
--- a/src/intervals.h
+++ b/src/intervals.h
@@ -27,8 +27,8 @@ struct interval
27{ 27{
28 /* The first group of entries deal with the tree structure. */ 28 /* The first group of entries deal with the tree structure. */
29 29
30 EMACS_INT total_length; /* Length of myself and both children. */ 30 ptrdiff_t total_length; /* Length of myself and both children. */
31 EMACS_INT position; /* Cache of interval's character position. */ 31 ptrdiff_t position; /* Cache of interval's character position. */
32 /* This field is usually updated 32 /* This field is usually updated
33 simultaneously with an interval 33 simultaneously with an interval
34 traversal, there is no guarantee 34 traversal, there is no guarantee
@@ -254,39 +254,39 @@ extern INTERVAL make_interval (void);
254extern INTERVAL create_root_interval (Lisp_Object); 254extern INTERVAL create_root_interval (Lisp_Object);
255extern void copy_properties (INTERVAL, INTERVAL); 255extern void copy_properties (INTERVAL, INTERVAL);
256extern int intervals_equal (INTERVAL, INTERVAL); 256extern int intervals_equal (INTERVAL, INTERVAL);
257extern void traverse_intervals (INTERVAL, EMACS_INT, 257extern void traverse_intervals (INTERVAL, ptrdiff_t,
258 void (*) (INTERVAL, Lisp_Object), 258 void (*) (INTERVAL, Lisp_Object),
259 Lisp_Object); 259 Lisp_Object);
260extern void traverse_intervals_noorder (INTERVAL, 260extern void traverse_intervals_noorder (INTERVAL,
261 void (*) (INTERVAL, Lisp_Object), 261 void (*) (INTERVAL, Lisp_Object),
262 Lisp_Object); 262 Lisp_Object);
263extern INTERVAL split_interval_right (INTERVAL, EMACS_INT); 263extern INTERVAL split_interval_right (INTERVAL, ptrdiff_t);
264extern INTERVAL split_interval_left (INTERVAL, EMACS_INT); 264extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t);
265extern INTERVAL find_interval (INTERVAL, EMACS_INT); 265extern INTERVAL find_interval (INTERVAL, ptrdiff_t);
266extern INTERVAL next_interval (INTERVAL); 266extern INTERVAL next_interval (INTERVAL);
267extern INTERVAL previous_interval (INTERVAL); 267extern INTERVAL previous_interval (INTERVAL);
268extern INTERVAL merge_interval_left (INTERVAL); 268extern INTERVAL merge_interval_left (INTERVAL);
269extern void offset_intervals (struct buffer *, EMACS_INT, EMACS_INT); 269extern void offset_intervals (struct buffer *, ptrdiff_t, ptrdiff_t);
270extern void graft_intervals_into_buffer (INTERVAL, EMACS_INT, EMACS_INT, 270extern void graft_intervals_into_buffer (INTERVAL, ptrdiff_t, ptrdiff_t,
271 struct buffer *, int); 271 struct buffer *, int);
272extern void verify_interval_modification (struct buffer *, 272extern void verify_interval_modification (struct buffer *,
273 EMACS_INT, EMACS_INT); 273 ptrdiff_t, ptrdiff_t);
274extern INTERVAL balance_intervals (INTERVAL); 274extern INTERVAL balance_intervals (INTERVAL);
275extern void copy_intervals_to_string (Lisp_Object, struct buffer *, 275extern void copy_intervals_to_string (Lisp_Object, struct buffer *,
276 EMACS_INT, EMACS_INT); 276 ptrdiff_t, ptrdiff_t);
277extern INTERVAL copy_intervals (INTERVAL, EMACS_INT, EMACS_INT); 277extern INTERVAL copy_intervals (INTERVAL, ptrdiff_t, ptrdiff_t);
278extern int compare_string_intervals (Lisp_Object, Lisp_Object); 278extern int compare_string_intervals (Lisp_Object, Lisp_Object);
279extern Lisp_Object textget (Lisp_Object, Lisp_Object); 279extern Lisp_Object textget (Lisp_Object, Lisp_Object);
280extern Lisp_Object lookup_char_property (Lisp_Object, Lisp_Object, int); 280extern Lisp_Object lookup_char_property (Lisp_Object, Lisp_Object, int);
281extern void move_if_not_intangible (EMACS_INT); 281extern void move_if_not_intangible (ptrdiff_t);
282extern int get_property_and_range (EMACS_INT, Lisp_Object, Lisp_Object *, 282extern int get_property_and_range (ptrdiff_t, Lisp_Object, Lisp_Object *,
283 EMACS_INT *, EMACS_INT *, Lisp_Object); 283 ptrdiff_t *, ptrdiff_t *, Lisp_Object);
284extern Lisp_Object get_local_map (EMACS_INT, struct buffer *, Lisp_Object); 284extern Lisp_Object get_local_map (ptrdiff_t, struct buffer *, Lisp_Object);
285extern INTERVAL update_interval (INTERVAL, EMACS_INT); 285extern INTERVAL update_interval (INTERVAL, ptrdiff_t);
286extern void set_intervals_multibyte (int); 286extern void set_intervals_multibyte (int);
287extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *, 287extern INTERVAL validate_interval_range (Lisp_Object, Lisp_Object *,
288 Lisp_Object *, int); 288 Lisp_Object *, int);
289extern INTERVAL interval_of (EMACS_INT, Lisp_Object); 289extern INTERVAL interval_of (ptrdiff_t, Lisp_Object);
290 290
291/* Defined in xdisp.c. */ 291/* Defined in xdisp.c. */
292extern int invisible_p (Lisp_Object, Lisp_Object); 292extern int invisible_p (Lisp_Object, Lisp_Object);
diff --git a/src/keyboard.c b/src/keyboard.c
index 82609bb4cb2..37ac8192558 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -122,7 +122,7 @@ static Lisp_Object recent_keys;
122 actually mean something. 122 actually mean something.
123 It's easier to staticpro a single Lisp_Object than an array. */ 123 It's easier to staticpro a single Lisp_Object than an array. */
124Lisp_Object this_command_keys; 124Lisp_Object this_command_keys;
125int this_command_key_count; 125ptrdiff_t this_command_key_count;
126 126
127/* 1 after calling Freset_this_command_lengths. 127/* 1 after calling Freset_this_command_lengths.
128 Usually it is 0. */ 128 Usually it is 0. */
@@ -135,16 +135,16 @@ static int raw_keybuf_count;
135 135
136#define GROW_RAW_KEYBUF \ 136#define GROW_RAW_KEYBUF \
137 if (raw_keybuf_count == ASIZE (raw_keybuf)) \ 137 if (raw_keybuf_count == ASIZE (raw_keybuf)) \
138 raw_keybuf = larger_vector (raw_keybuf, raw_keybuf_count * 2, Qnil) \ 138 raw_keybuf = larger_vector (raw_keybuf, 1, -1)
139 139
140/* Number of elements of this_command_keys 140/* Number of elements of this_command_keys
141 that precede this key sequence. */ 141 that precede this key sequence. */
142static int this_single_command_key_start; 142static ptrdiff_t this_single_command_key_start;
143 143
144/* Record values of this_command_key_count and echo_length () 144/* Record values of this_command_key_count and echo_length ()
145 before this command was read. */ 145 before this command was read. */
146static int before_command_key_count; 146static ptrdiff_t before_command_key_count;
147static int before_command_echo_length; 147static ptrdiff_t before_command_echo_length;
148 148
149/* For longjmp to where kbd input is being done. */ 149/* For longjmp to where kbd input is being done. */
150 150
@@ -208,20 +208,20 @@ EMACS_INT command_loop_level;
208Lisp_Object unread_switch_frame; 208Lisp_Object unread_switch_frame;
209 209
210/* Last size recorded for a current buffer which is not a minibuffer. */ 210/* Last size recorded for a current buffer which is not a minibuffer. */
211static EMACS_INT last_non_minibuf_size; 211static ptrdiff_t last_non_minibuf_size;
212 212
213/* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ 213/* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */
214uintmax_t num_input_events; 214uintmax_t num_input_events;
215 215
216/* Value of num_nonmacro_input_events as of last auto save. */ 216/* Value of num_nonmacro_input_events as of last auto save. */
217 217
218static int last_auto_save; 218static EMACS_INT last_auto_save;
219 219
220/* This is like Vthis_command, except that commands never set it. */ 220/* This is like Vthis_command, except that commands never set it. */
221Lisp_Object real_this_command; 221Lisp_Object real_this_command;
222 222
223/* The value of point when the last command was started. */ 223/* The value of point when the last command was started. */
224static EMACS_INT last_point_position; 224static ptrdiff_t last_point_position;
225 225
226/* The buffer that was current when the last command was started. */ 226/* The buffer that was current when the last command was started. */
227static Lisp_Object last_point_position_buffer; 227static Lisp_Object last_point_position_buffer;
@@ -380,7 +380,7 @@ EMACS_TIME timer_check (void);
380 380
381static void record_menu_key (Lisp_Object c); 381static void record_menu_key (Lisp_Object c);
382static void echo_now (void); 382static void echo_now (void);
383static int echo_length (void); 383static ptrdiff_t echo_length (void);
384 384
385static Lisp_Object Qpolling_period; 385static Lisp_Object Qpolling_period;
386 386
@@ -451,9 +451,9 @@ static Lisp_Object make_lispy_movement (struct frame *, Lisp_Object,
451 Lisp_Object, Lisp_Object, 451 Lisp_Object, Lisp_Object,
452 Time); 452 Time);
453#endif 453#endif
454static Lisp_Object modify_event_symbol (EMACS_INT, unsigned, Lisp_Object, 454static Lisp_Object modify_event_symbol (ptrdiff_t, int, Lisp_Object,
455 Lisp_Object, const char *const *, 455 Lisp_Object, const char *const *,
456 Lisp_Object *, EMACS_INT); 456 Lisp_Object *, ptrdiff_t);
457static Lisp_Object make_lispy_switch_frame (Lisp_Object); 457static Lisp_Object make_lispy_switch_frame (Lisp_Object);
458static int help_char_p (Lisp_Object); 458static int help_char_p (Lisp_Object);
459static void save_getcjmp (jmp_buf); 459static void save_getcjmp (jmp_buf);
@@ -618,7 +618,7 @@ echo_now (void)
618{ 618{
619 if (!current_kboard->immediate_echo) 619 if (!current_kboard->immediate_echo)
620 { 620 {
621 int i; 621 ptrdiff_t i;
622 current_kboard->immediate_echo = 1; 622 current_kboard->immediate_echo = 1;
623 623
624 for (i = 0; i < this_command_key_count; i++) 624 for (i = 0; i < this_command_key_count; i++)
@@ -676,7 +676,7 @@ cancel_echoing (void)
676 676
677/* Return the length of the current echo string. */ 677/* Return the length of the current echo string. */
678 678
679static int 679static ptrdiff_t
680echo_length (void) 680echo_length (void)
681{ 681{
682 return (STRINGP (KVAR (current_kboard, echo_string)) 682 return (STRINGP (KVAR (current_kboard, echo_string))
@@ -689,7 +689,7 @@ echo_length (void)
689 switches frames while entering a key sequence. */ 689 switches frames while entering a key sequence. */
690 690
691static void 691static void
692echo_truncate (EMACS_INT nchars) 692echo_truncate (ptrdiff_t nchars)
693{ 693{
694 if (STRINGP (KVAR (current_kboard, echo_string))) 694 if (STRINGP (KVAR (current_kboard, echo_string)))
695 KVAR (current_kboard, echo_string) 695 KVAR (current_kboard, echo_string)
@@ -718,9 +718,7 @@ add_command_key (Lisp_Object key)
718#endif 718#endif
719 719
720 if (this_command_key_count >= ASIZE (this_command_keys)) 720 if (this_command_key_count >= ASIZE (this_command_keys))
721 this_command_keys = larger_vector (this_command_keys, 721 this_command_keys = larger_vector (this_command_keys, 1, -1);
722 2 * ASIZE (this_command_keys),
723 Qnil);
724 722
725 ASET (this_command_keys, this_command_key_count, key); 723 ASET (this_command_keys, this_command_key_count, key);
726 ++this_command_key_count; 724 ++this_command_key_count;
@@ -730,7 +728,7 @@ add_command_key (Lisp_Object key)
730Lisp_Object 728Lisp_Object
731recursive_edit_1 (void) 729recursive_edit_1 (void)
732{ 730{
733 int count = SPECPDL_INDEX (); 731 ptrdiff_t count = SPECPDL_INDEX ();
734 Lisp_Object val; 732 Lisp_Object val;
735 733
736 if (command_loop_level > 0) 734 if (command_loop_level > 0)
@@ -798,7 +796,7 @@ Alternatively, `(throw 'exit t)' makes this function signal an error.
798This function is called by the editor initialization to begin editing. */) 796This function is called by the editor initialization to begin editing. */)
799 (void) 797 (void)
800{ 798{
801 int count = SPECPDL_INDEX (); 799 ptrdiff_t count = SPECPDL_INDEX ();
802 Lisp_Object buffer; 800 Lisp_Object buffer;
803 801
804 /* If we enter while input is blocked, don't lock up here. 802 /* If we enter while input is blocked, don't lock up here.
@@ -1265,7 +1263,7 @@ Normally, mouse motion is ignored.
1265usage: (track-mouse BODY...) */) 1263usage: (track-mouse BODY...) */)
1266 (Lisp_Object args) 1264 (Lisp_Object args)
1267{ 1265{
1268 int count = SPECPDL_INDEX (); 1266 ptrdiff_t count = SPECPDL_INDEX ();
1269 Lisp_Object val; 1267 Lisp_Object val;
1270 1268
1271 record_unwind_protect (tracking_off, do_mouse_tracking); 1269 record_unwind_protect (tracking_off, do_mouse_tracking);
@@ -1316,7 +1314,7 @@ some_mouse_moved (void)
1316static int read_key_sequence (Lisp_Object *, int, Lisp_Object, 1314static int read_key_sequence (Lisp_Object *, int, Lisp_Object,
1317 int, int, int); 1315 int, int, int);
1318void safe_run_hooks (Lisp_Object); 1316void safe_run_hooks (Lisp_Object);
1319static void adjust_point_for_property (EMACS_INT, int); 1317static void adjust_point_for_property (ptrdiff_t, int);
1320 1318
1321/* Cancel hourglass from protect_unwind. 1319/* Cancel hourglass from protect_unwind.
1322 ARG is not used. */ 1320 ARG is not used. */
@@ -1340,7 +1338,7 @@ command_loop_1 (void)
1340 Lisp_Object cmd; 1338 Lisp_Object cmd;
1341 Lisp_Object keybuf[30]; 1339 Lisp_Object keybuf[30];
1342 int i; 1340 int i;
1343 int prev_modiff = 0; 1341 EMACS_INT prev_modiff = 0;
1344 struct buffer *prev_buffer = NULL; 1342 struct buffer *prev_buffer = NULL;
1345#if 0 /* This shouldn't be necessary anymore. --lorentey */ 1343#if 0 /* This shouldn't be necessary anymore. --lorentey */
1346 int was_locked = single_kboard; 1344 int was_locked = single_kboard;
@@ -1412,7 +1410,7 @@ command_loop_1 (void)
1412 { 1410 {
1413 /* Bind inhibit-quit to t so that C-g gets read in 1411 /* Bind inhibit-quit to t so that C-g gets read in
1414 rather than quitting back to the minibuffer. */ 1412 rather than quitting back to the minibuffer. */
1415 int count = SPECPDL_INDEX (); 1413 ptrdiff_t count = SPECPDL_INDEX ();
1416 specbind (Qinhibit_quit, Qt); 1414 specbind (Qinhibit_quit, Qt);
1417 1415
1418 sit_for (Vminibuffer_message_timeout, 0, 2); 1416 sit_for (Vminibuffer_message_timeout, 0, 2);
@@ -1566,7 +1564,7 @@ command_loop_1 (void)
1566 /* Here for a command that isn't executed directly. */ 1564 /* Here for a command that isn't executed directly. */
1567 1565
1568#ifdef HAVE_WINDOW_SYSTEM 1566#ifdef HAVE_WINDOW_SYSTEM
1569 int scount = SPECPDL_INDEX (); 1567 ptrdiff_t scount = SPECPDL_INDEX ();
1570 1568
1571 if (display_hourglass_p 1569 if (display_hourglass_p
1572 && NILP (Vexecuting_kbd_macro)) 1570 && NILP (Vexecuting_kbd_macro))
@@ -1660,9 +1658,9 @@ command_loop_1 (void)
1660 && NILP (Fmemq (Vthis_command, 1658 && NILP (Fmemq (Vthis_command,
1661 Vselection_inhibit_update_commands))) 1659 Vselection_inhibit_update_commands)))
1662 { 1660 {
1663 EMACS_INT beg = 1661 ptrdiff_t beg =
1664 XINT (Fmarker_position (BVAR (current_buffer, mark))); 1662 XINT (Fmarker_position (BVAR (current_buffer, mark)));
1665 EMACS_INT end = PT; 1663 ptrdiff_t end = PT;
1666 if (beg < end) 1664 if (beg < end)
1667 call2 (Qx_set_selection, QPRIMARY, 1665 call2 (Qx_set_selection, QPRIMARY,
1668 make_buffer_string (beg, end, 0)); 1666 make_buffer_string (beg, end, 0));
@@ -1722,16 +1720,16 @@ command_loop_1 (void)
1722 LAST_PT is the last position of point. */ 1720 LAST_PT is the last position of point. */
1723 1721
1724static void 1722static void
1725adjust_point_for_property (EMACS_INT last_pt, int modified) 1723adjust_point_for_property (ptrdiff_t last_pt, int modified)
1726{ 1724{
1727 EMACS_INT beg, end; 1725 ptrdiff_t beg, end;
1728 Lisp_Object val, overlay, tmp; 1726 Lisp_Object val, overlay, tmp;
1729 /* When called after buffer modification, we should temporarily 1727 /* When called after buffer modification, we should temporarily
1730 suppress the point adjustment for automatic composition so that a 1728 suppress the point adjustment for automatic composition so that a
1731 user can keep inserting another character at point or keep 1729 user can keep inserting another character at point or keep
1732 deleting characters around point. */ 1730 deleting characters around point. */
1733 int check_composition = ! modified, check_display = 1, check_invisible = 1; 1731 int check_composition = ! modified, check_display = 1, check_invisible = 1;
1734 EMACS_INT orig_pt = PT; 1732 ptrdiff_t orig_pt = PT;
1735 1733
1736 /* FIXME: cycling is probably not necessary because these properties 1734 /* FIXME: cycling is probably not necessary because these properties
1737 can't be usefully combined anyway. */ 1735 can't be usefully combined anyway. */
@@ -1946,7 +1944,7 @@ safe_run_hooks (Lisp_Object hook)
1946 /* FIXME: our `internal_condition_case' does not provide any way to pass data 1944 /* FIXME: our `internal_condition_case' does not provide any way to pass data
1947 to its body or to its handlers other than via globals such as 1945 to its body or to its handlers other than via globals such as
1948 dynamically-bound variables ;-) */ 1946 dynamically-bound variables ;-) */
1949 int count = SPECPDL_INDEX (); 1947 ptrdiff_t count = SPECPDL_INDEX ();
1950 specbind (Qinhibit_quit, hook); 1948 specbind (Qinhibit_quit, hook);
1951 1949
1952 run_hook_with_args (1, &hook, safe_run_hook_funcall); 1950 run_hook_with_args (1, &hook, safe_run_hook_funcall);
@@ -2284,7 +2282,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2284 int *used_mouse_menu, struct timeval *end_time) 2282 int *used_mouse_menu, struct timeval *end_time)
2285{ 2283{
2286 volatile Lisp_Object c; 2284 volatile Lisp_Object c;
2287 int jmpcount; 2285 ptrdiff_t jmpcount;
2288 jmp_buf local_getcjmp; 2286 jmp_buf local_getcjmp;
2289 jmp_buf save_jump; 2287 jmp_buf save_jump;
2290 volatile int key_already_recorded = 0; 2288 volatile int key_already_recorded = 0;
@@ -2673,7 +2671,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2673 if (INTERACTIVE && NILP (c)) 2671 if (INTERACTIVE && NILP (c))
2674 { 2672 {
2675 int delay_level; 2673 int delay_level;
2676 EMACS_INT buffer_size; 2674 ptrdiff_t buffer_size;
2677 2675
2678 /* Slow down auto saves logarithmically in size of current buffer, 2676 /* Slow down auto saves logarithmically in size of current buffer,
2679 and garbage collect while we're at it. */ 2677 and garbage collect while we're at it. */
@@ -2694,8 +2692,9 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2694 && XINT (Vauto_save_timeout) > 0) 2692 && XINT (Vauto_save_timeout) > 0)
2695 { 2693 {
2696 Lisp_Object tem0; 2694 Lisp_Object tem0;
2697 int timeout = delay_level * XFASTINT (Vauto_save_timeout) / 4; 2695 EMACS_INT timeout = (delay_level
2698 2696 * min (XFASTINT (Vauto_save_timeout) / 4,
2697 MOST_POSITIVE_FIXNUM / delay_level));
2699 save_getcjmp (save_jump); 2698 save_getcjmp (save_jump);
2700 restore_getcjmp (local_getcjmp); 2699 restore_getcjmp (local_getcjmp);
2701 tem0 = sit_for (make_number (timeout), 1, 1); 2700 tem0 = sit_for (make_number (timeout), 1, 1);
@@ -2889,7 +2888,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2889 struct buffer *prev_buffer = current_buffer; 2888 struct buffer *prev_buffer = current_buffer;
2890#if 0 /* This shouldn't be necessary anymore. --lorentey */ 2889#if 0 /* This shouldn't be necessary anymore. --lorentey */
2891 int was_locked = single_kboard; 2890 int was_locked = single_kboard;
2892 int count = SPECPDL_INDEX (); 2891 ptrdiff_t count = SPECPDL_INDEX ();
2893 record_single_kboard_state (); 2892 record_single_kboard_state ();
2894#endif 2893#endif
2895 2894
@@ -3016,9 +3015,10 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
3016 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127) 3015 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127)
3017 { 3016 {
3018 Lisp_Object keys; 3017 Lisp_Object keys;
3019 int key_count, key_count_reset; 3018 ptrdiff_t key_count;
3019 int key_count_reset;
3020 struct gcpro gcpro1; 3020 struct gcpro gcpro1;
3021 int count = SPECPDL_INDEX (); 3021 ptrdiff_t count = SPECPDL_INDEX ();
3022 3022
3023 /* Save the echo status. */ 3023 /* Save the echo status. */
3024 int saved_immediate_echo = current_kboard->immediate_echo; 3024 int saved_immediate_echo = current_kboard->immediate_echo;
@@ -3155,7 +3155,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
3155 /* Process the help character specially if enabled */ 3155 /* Process the help character specially if enabled */
3156 if (!NILP (Vhelp_form) && help_char_p (c)) 3156 if (!NILP (Vhelp_form) && help_char_p (c))
3157 { 3157 {
3158 int count = SPECPDL_INDEX (); 3158 ptrdiff_t count = SPECPDL_INDEX ();
3159 3159
3160 help_form_saved_window_configs 3160 help_form_saved_window_configs
3161 = Fcons (Fcurrent_window_configuration (Qnil), 3161 = Fcons (Fcurrent_window_configuration (Qnil),
@@ -3315,7 +3315,7 @@ record_char (Lisp_Object c)
3315 3315
3316 if (!recorded) 3316 if (!recorded)
3317 { 3317 {
3318 total_keys++; 3318 total_keys += total_keys < NUM_RECENT_KEYS;
3319 ASET (recent_keys, recent_keys_index, c); 3319 ASET (recent_keys, recent_keys_index, c);
3320 if (++recent_keys_index >= NUM_RECENT_KEYS) 3320 if (++recent_keys_index >= NUM_RECENT_KEYS)
3321 recent_keys_index = 0; 3321 recent_keys_index = 0;
@@ -3684,7 +3684,7 @@ kbd_buffer_unget_event (register struct input_event *event)
3684 3684
3685void 3685void
3686gen_help_event (Lisp_Object help, Lisp_Object frame, Lisp_Object window, 3686gen_help_event (Lisp_Object help, Lisp_Object frame, Lisp_Object window,
3687 Lisp_Object object, EMACS_INT pos) 3687 Lisp_Object object, ptrdiff_t pos)
3688{ 3688{
3689 struct input_event event; 3689 struct input_event event;
3690 3690
@@ -4475,7 +4475,7 @@ timer_check_2 (void)
4475 { 4475 {
4476 if (NILP (vector[0])) 4476 if (NILP (vector[0]))
4477 { 4477 {
4478 int count = SPECPDL_INDEX (); 4478 ptrdiff_t count = SPECPDL_INDEX ();
4479 Lisp_Object old_deactivate_mark = Vdeactivate_mark; 4479 Lisp_Object old_deactivate_mark = Vdeactivate_mark;
4480 4480
4481 /* Mark the timer as triggered to prevent problems if the lisp 4481 /* Mark the timer as triggered to prevent problems if the lisp
@@ -5186,7 +5186,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5186 /* It's a click in window WINDOW at frame coordinates (X,Y) */ 5186 /* It's a click in window WINDOW at frame coordinates (X,Y) */
5187 struct window *w = XWINDOW (window); 5187 struct window *w = XWINDOW (window);
5188 Lisp_Object string_info = Qnil; 5188 Lisp_Object string_info = Qnil;
5189 EMACS_INT textpos = -1; 5189 ptrdiff_t textpos = -1;
5190 int col = -1, row = -1; 5190 int col = -1, row = -1;
5191 int dx = -1, dy = -1; 5191 int dx = -1, dy = -1;
5192 int width = -1, height = -1; 5192 int width = -1, height = -1;
@@ -5210,7 +5210,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5210 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE) 5210 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE)
5211 { 5211 {
5212 Lisp_Object string; 5212 Lisp_Object string;
5213 EMACS_INT charpos; 5213 ptrdiff_t charpos;
5214 5214
5215 posn = (part == ON_MODE_LINE) ? Qmode_line : Qheader_line; 5215 posn = (part == ON_MODE_LINE) ? Qmode_line : Qheader_line;
5216 /* Note that mode_line_string takes COL, ROW as pixels and 5216 /* Note that mode_line_string takes COL, ROW as pixels and
@@ -5233,7 +5233,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5233 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN) 5233 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN)
5234 { 5234 {
5235 Lisp_Object string; 5235 Lisp_Object string;
5236 EMACS_INT charpos; 5236 ptrdiff_t charpos;
5237 5237
5238 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin; 5238 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin;
5239 col = wx; 5239 col = wx;
@@ -5461,7 +5461,7 @@ make_lispy_event (struct input_event *event)
5461 Qfunction_key, 5461 Qfunction_key,
5462 KVAR (current_kboard, Vsystem_key_alist), 5462 KVAR (current_kboard, Vsystem_key_alist),
5463 0, &KVAR (current_kboard, system_key_syms), 5463 0, &KVAR (current_kboard, system_key_syms),
5464 TYPE_MAXIMUM (EMACS_INT)); 5464 PTRDIFF_MAX);
5465 } 5465 }
5466 5466
5467 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, 5467 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET,
@@ -5593,9 +5593,10 @@ make_lispy_event (struct input_event *event)
5593 5593
5594 if (button >= ASIZE (button_down_location)) 5594 if (button >= ASIZE (button_down_location))
5595 { 5595 {
5596 ptrdiff_t incr = button - ASIZE (button_down_location) + 1;
5596 button_down_location = larger_vector (button_down_location, 5597 button_down_location = larger_vector (button_down_location,
5597 button + 1, Qnil); 5598 incr, -1);
5598 mouse_syms = larger_vector (mouse_syms, button + 1, Qnil); 5599 mouse_syms = larger_vector (mouse_syms, incr, -1);
5599 } 5600 }
5600 5601
5601 start_pos_ptr = &AREF (button_down_location, button); 5602 start_pos_ptr = &AREF (button_down_location, button);
@@ -5895,7 +5896,9 @@ make_lispy_event (struct input_event *event)
5895 event->modifiers &= ~up_modifier; 5896 event->modifiers &= ~up_modifier;
5896 5897
5897 if (event->code >= ASIZE (mouse_syms)) 5898 if (event->code >= ASIZE (mouse_syms))
5898 mouse_syms = larger_vector (mouse_syms, event->code + 1, Qnil); 5899 mouse_syms = larger_vector (mouse_syms,
5900 event->code - ASIZE (mouse_syms) + 1,
5901 -1);
5899 5902
5900 /* Get the symbol we should use for the mouse click. */ 5903 /* Get the symbol we should use for the mouse click. */
5901 head = modify_event_symbol (event->code, 5904 head = modify_event_symbol (event->code,
@@ -6004,9 +6007,10 @@ make_lispy_event (struct input_event *event)
6004 6007
6005 if (button >= ASIZE (button_down_location)) 6008 if (button >= ASIZE (button_down_location))
6006 { 6009 {
6010 ptrdiff_t incr = button - ASIZE (button_down_location) + 1;
6007 button_down_location = larger_vector (button_down_location, 6011 button_down_location = larger_vector (button_down_location,
6008 button + 1, Qnil); 6012 incr, -1);
6009 mouse_syms = larger_vector (mouse_syms, button + 1, Qnil); 6013 mouse_syms = larger_vector (mouse_syms, incr, -1);
6010 } 6014 }
6011 6015
6012 start_pos_ptr = &AREF (button_down_location, button); 6016 start_pos_ptr = &AREF (button_down_location, button);
@@ -6108,10 +6112,10 @@ make_lispy_switch_frame (Lisp_Object frame)
6108 This doesn't use any caches. */ 6112 This doesn't use any caches. */
6109 6113
6110static int 6114static int
6111parse_modifiers_uncached (Lisp_Object symbol, EMACS_INT *modifier_end) 6115parse_modifiers_uncached (Lisp_Object symbol, ptrdiff_t *modifier_end)
6112{ 6116{
6113 Lisp_Object name; 6117 Lisp_Object name;
6114 EMACS_INT i; 6118 ptrdiff_t i;
6115 int modifiers; 6119 int modifiers;
6116 6120
6117 CHECK_SYMBOL (symbol); 6121 CHECK_SYMBOL (symbol);
@@ -6119,9 +6123,9 @@ parse_modifiers_uncached (Lisp_Object symbol, EMACS_INT *modifier_end)
6119 modifiers = 0; 6123 modifiers = 0;
6120 name = SYMBOL_NAME (symbol); 6124 name = SYMBOL_NAME (symbol);
6121 6125
6122 for (i = 0; i+2 <= SBYTES (name); ) 6126 for (i = 0; i < SBYTES (name) - 1; )
6123 { 6127 {
6124 EMACS_INT this_mod_end = 0; 6128 ptrdiff_t this_mod_end = 0;
6125 int this_mod = 0; 6129 int this_mod = 0;
6126 6130
6127 /* See if the name continues with a modifier word. 6131 /* See if the name continues with a modifier word.
@@ -6318,7 +6322,7 @@ parse_modifiers (Lisp_Object symbol)
6318 return elements; 6322 return elements;
6319 else 6323 else
6320 { 6324 {
6321 EMACS_INT end; 6325 ptrdiff_t end;
6322 int modifiers = parse_modifiers_uncached (symbol, &end); 6326 int modifiers = parse_modifiers_uncached (symbol, &end);
6323 Lisp_Object unmodified; 6327 Lisp_Object unmodified;
6324 Lisp_Object mask; 6328 Lisp_Object mask;
@@ -6484,9 +6488,9 @@ reorder_modifiers (Lisp_Object symbol)
6484 in the symbol's name. */ 6488 in the symbol's name. */
6485 6489
6486static Lisp_Object 6490static Lisp_Object
6487modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object symbol_kind, 6491modify_event_symbol (ptrdiff_t symbol_num, int modifiers, Lisp_Object symbol_kind,
6488 Lisp_Object name_alist_or_stem, const char *const *name_table, 6492 Lisp_Object name_alist_or_stem, const char *const *name_table,
6489 Lisp_Object *symbol_table, EMACS_INT table_size) 6493 Lisp_Object *symbol_table, ptrdiff_t table_size)
6490{ 6494{
6491 Lisp_Object value; 6495 Lisp_Object value;
6492 Lisp_Object symbol_int; 6496 Lisp_Object symbol_int;
@@ -6552,7 +6556,7 @@ modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object s
6552 if (NILP (value)) 6556 if (NILP (value))
6553 { 6557 {
6554 char buf[sizeof "key-" + INT_STRLEN_BOUND (EMACS_INT)]; 6558 char buf[sizeof "key-" + INT_STRLEN_BOUND (EMACS_INT)];
6555 sprintf (buf, "key-%"pI"d", symbol_num); 6559 sprintf (buf, "key-%"pD"d", symbol_num);
6556 value = intern (buf); 6560 value = intern (buf);
6557 } 6561 }
6558 6562
@@ -7592,7 +7596,7 @@ menu_bar_items (Lisp_Object old)
7592 int i = menu_bar_items_index; 7596 int i = menu_bar_items_index;
7593 if (i + 4 > ASIZE (menu_bar_items_vector)) 7597 if (i + 4 > ASIZE (menu_bar_items_vector))
7594 menu_bar_items_vector = 7598 menu_bar_items_vector =
7595 larger_vector (menu_bar_items_vector, 2 * i, Qnil); 7599 larger_vector (menu_bar_items_vector, 4, -1);
7596 /* Add this item. */ 7600 /* Add this item. */
7597 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; 7601 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
7598 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; 7602 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
@@ -7663,7 +7667,7 @@ menu_bar_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy1, void *dumm
7663 { 7667 {
7664 /* If vector is too small, get a bigger one. */ 7668 /* If vector is too small, get a bigger one. */
7665 if (i + 4 > ASIZE (menu_bar_items_vector)) 7669 if (i + 4 > ASIZE (menu_bar_items_vector))
7666 menu_bar_items_vector = larger_vector (menu_bar_items_vector, 2 * i, Qnil); 7670 menu_bar_items_vector = larger_vector (menu_bar_items_vector, 4, -1);
7667 /* Add this item. */ 7671 /* Add this item. */
7668 XVECTOR (menu_bar_items_vector)->contents[i++] = key; 7672 XVECTOR (menu_bar_items_vector)->contents[i++] = key;
7669 XVECTOR (menu_bar_items_vector)->contents[i++] 7673 XVECTOR (menu_bar_items_vector)->contents[i++]
@@ -7707,7 +7711,7 @@ eval_dyn (Lisp_Object form)
7707Lisp_Object 7711Lisp_Object
7708menu_item_eval_property (Lisp_Object sexpr) 7712menu_item_eval_property (Lisp_Object sexpr)
7709{ 7713{
7710 int count = SPECPDL_INDEX (); 7714 ptrdiff_t count = SPECPDL_INDEX ();
7711 Lisp_Object val; 7715 Lisp_Object val;
7712 specbind (Qinhibit_redisplay, Qt); 7716 specbind (Qinhibit_redisplay, Qt);
7713 val = internal_condition_case_1 (eval_dyn, sexpr, Qerror, 7717 val = internal_condition_case_1 (eval_dyn, sexpr, Qerror,
@@ -8432,13 +8436,14 @@ static void
8432append_tool_bar_item (void) 8436append_tool_bar_item (void)
8433{ 8437{
8434 Lisp_Object *to, *from; 8438 Lisp_Object *to, *from;
8439 ptrdiff_t incr =
8440 (ntool_bar_items
8441 - (ASIZE (tool_bar_items_vector) - TOOL_BAR_ITEM_NSLOTS));
8435 8442
8436 /* Enlarge tool_bar_items_vector if necessary. */ 8443 /* Enlarge tool_bar_items_vector if necessary. */
8437 if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS 8444 if (0 < incr)
8438 >= ASIZE (tool_bar_items_vector))
8439 tool_bar_items_vector 8445 tool_bar_items_vector
8440 = larger_vector (tool_bar_items_vector, 8446 = larger_vector (tool_bar_items_vector, incr, -1);
8441 2 * ASIZE (tool_bar_items_vector), Qnil);
8442 8447
8443 /* Append entries from tool_bar_item_properties to the end of 8448 /* Append entries from tool_bar_item_properties to the end of
8444 tool_bar_items_vector. */ 8449 tool_bar_items_vector. */
@@ -9023,15 +9028,15 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9023 int fix_current_buffer) 9028 int fix_current_buffer)
9024{ 9029{
9025 Lisp_Object from_string; 9030 Lisp_Object from_string;
9026 int count = SPECPDL_INDEX (); 9031 ptrdiff_t count = SPECPDL_INDEX ();
9027 9032
9028 /* How many keys there are in the current key sequence. */ 9033 /* How many keys there are in the current key sequence. */
9029 int t; 9034 int t;
9030 9035
9031 /* The length of the echo buffer when we started reading, and 9036 /* The length of the echo buffer when we started reading, and
9032 the length of this_command_keys when we started reading. */ 9037 the length of this_command_keys when we started reading. */
9033 int echo_start IF_LINT (= 0); 9038 ptrdiff_t echo_start IF_LINT (= 0);
9034 int keys_start; 9039 ptrdiff_t keys_start;
9035 9040
9036 /* The number of keymaps we're scanning right now, and the number of 9041 /* The number of keymaps we're scanning right now, and the number of
9037 keymaps we have allocated space for. */ 9042 keymaps we have allocated space for. */
@@ -9287,7 +9292,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9287 while those allow us to restart the entire key sequence, 9292 while those allow us to restart the entire key sequence,
9288 echo_local_start and keys_local_start allow us to throw away 9293 echo_local_start and keys_local_start allow us to throw away
9289 just one key. */ 9294 just one key. */
9290 int echo_local_start IF_LINT (= 0); 9295 ptrdiff_t echo_local_start IF_LINT (= 0);
9291 int keys_local_start; 9296 int keys_local_start;
9292 ptrdiff_t local_first_binding; 9297 ptrdiff_t local_first_binding;
9293 9298
@@ -10175,7 +10180,7 @@ will read just one key sequence. */)
10175 Lisp_Object keybuf[30]; 10180 Lisp_Object keybuf[30];
10176 register int i; 10181 register int i;
10177 struct gcpro gcpro1; 10182 struct gcpro gcpro1;
10178 int count = SPECPDL_INDEX (); 10183 ptrdiff_t count = SPECPDL_INDEX ();
10179 10184
10180 if (!NILP (prompt)) 10185 if (!NILP (prompt))
10181 CHECK_STRING (prompt); 10186 CHECK_STRING (prompt);
@@ -10232,7 +10237,7 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
10232 Lisp_Object keybuf[30]; 10237 Lisp_Object keybuf[30];
10233 register int i; 10238 register int i;
10234 struct gcpro gcpro1; 10239 struct gcpro gcpro1;
10235 int count = SPECPDL_INDEX (); 10240 ptrdiff_t count = SPECPDL_INDEX ();
10236 10241
10237 if (!NILP (prompt)) 10242 if (!NILP (prompt))
10238 CHECK_STRING (prompt); 10243 CHECK_STRING (prompt);
@@ -10660,7 +10665,7 @@ Some operating systems cannot stop the Emacs process and resume it later.
10660On such systems, Emacs starts a subshell instead of suspending. */) 10665On such systems, Emacs starts a subshell instead of suspending. */)
10661 (Lisp_Object stuffstring) 10666 (Lisp_Object stuffstring)
10662{ 10667{
10663 int count = SPECPDL_INDEX (); 10668 ptrdiff_t count = SPECPDL_INDEX ();
10664 int old_height, old_width; 10669 int old_height, old_width;
10665 int width, height; 10670 int width, height;
10666 struct gcpro gcpro1; 10671 struct gcpro gcpro1;
@@ -10716,7 +10721,7 @@ stuff_buffered_input (Lisp_Object stuffstring)
10716 10721
10717 if (STRINGP (stuffstring)) 10722 if (STRINGP (stuffstring))
10718 { 10723 {
10719 register EMACS_INT count; 10724 register ptrdiff_t count;
10720 10725
10721 p = SDATA (stuffstring); 10726 p = SDATA (stuffstring);
10722 count = SBYTES (stuffstring); 10727 count = SBYTES (stuffstring);
diff --git a/src/keyboard.h b/src/keyboard.h
index 19d91c84f79..202972ffbd8 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -202,7 +202,7 @@ extern int poll_suppress_count;
202 sequence; this_command_key_count indicates how many elements 202 sequence; this_command_key_count indicates how many elements
203 actually mean something. */ 203 actually mean something. */
204extern Lisp_Object this_command_keys; 204extern Lisp_Object this_command_keys;
205extern int this_command_key_count; 205extern ptrdiff_t this_command_key_count;
206 206
207/* The frame in which the last input event occurred, or Qmacro if the 207/* The frame in which the last input event occurred, or Qmacro if the
208 last event came from a macro. We use this to determine when to 208 last event came from a macro. We use this to determine when to
@@ -500,7 +500,7 @@ extern void poll_for_input_1 (void);
500extern void show_help_echo (Lisp_Object, Lisp_Object, Lisp_Object, 500extern void show_help_echo (Lisp_Object, Lisp_Object, Lisp_Object,
501 Lisp_Object); 501 Lisp_Object);
502extern void gen_help_event (Lisp_Object, Lisp_Object, Lisp_Object, 502extern void gen_help_event (Lisp_Object, Lisp_Object, Lisp_Object,
503 Lisp_Object, EMACS_INT); 503 Lisp_Object, ptrdiff_t);
504extern void kbd_buffer_store_help_event (Lisp_Object, Lisp_Object); 504extern void kbd_buffer_store_help_event (Lisp_Object, Lisp_Object);
505extern Lisp_Object menu_item_eval_property (Lisp_Object); 505extern Lisp_Object menu_item_eval_property (Lisp_Object);
506extern int kbd_buffer_events_waiting (int); 506extern int kbd_buffer_events_waiting (int);
diff --git a/src/keymap.c b/src/keymap.c
index 9f82175edc0..2a03dda5a5e 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1117,12 +1117,12 @@ binding is altered. If there is no binding for KEY, the new pair
1117binding KEY to DEF is added at the front of KEYMAP. */) 1117binding KEY to DEF is added at the front of KEYMAP. */)
1118 (Lisp_Object keymap, Lisp_Object key, Lisp_Object def) 1118 (Lisp_Object keymap, Lisp_Object key, Lisp_Object def)
1119{ 1119{
1120 register int idx; 1120 register ptrdiff_t idx;
1121 register Lisp_Object c; 1121 register Lisp_Object c;
1122 register Lisp_Object cmd; 1122 register Lisp_Object cmd;
1123 int metized = 0; 1123 int metized = 0;
1124 int meta_bit; 1124 int meta_bit;
1125 int length; 1125 ptrdiff_t length;
1126 struct gcpro gcpro1, gcpro2, gcpro3; 1126 struct gcpro gcpro1, gcpro2, gcpro3;
1127 1127
1128 GCPRO3 (keymap, key, def); 1128 GCPRO3 (keymap, key, def);
@@ -1143,7 +1143,7 @@ binding KEY to DEF is added at the front of KEYMAP. */)
1143 if (VECTORP (def) && ASIZE (def) > 0 && CONSP (AREF (def, 0))) 1143 if (VECTORP (def) && ASIZE (def) > 0 && CONSP (AREF (def, 0)))
1144 { /* DEF is apparently an XEmacs-style keyboard macro. */ 1144 { /* DEF is apparently an XEmacs-style keyboard macro. */
1145 Lisp_Object tmp = Fmake_vector (make_number (ASIZE (def)), Qnil); 1145 Lisp_Object tmp = Fmake_vector (make_number (ASIZE (def)), Qnil);
1146 int i = ASIZE (def); 1146 ptrdiff_t i = ASIZE (def);
1147 while (--i >= 0) 1147 while (--i >= 0)
1148 { 1148 {
1149 Lisp_Object defi = AREF (def, i); 1149 Lisp_Object defi = AREF (def, i);
@@ -1274,10 +1274,10 @@ third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will
1274recognize the default bindings, just as `read-key-sequence' does. */) 1274recognize the default bindings, just as `read-key-sequence' does. */)
1275 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) 1275 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default)
1276{ 1276{
1277 register int idx; 1277 register ptrdiff_t idx;
1278 register Lisp_Object cmd; 1278 register Lisp_Object cmd;
1279 register Lisp_Object c; 1279 register Lisp_Object c;
1280 int length; 1280 ptrdiff_t length;
1281 int t_ok = !NILP (accept_default); 1281 int t_ok = !NILP (accept_default);
1282 struct gcpro gcpro1, gcpro2; 1282 struct gcpro gcpro1, gcpro2;
1283 1283
@@ -1527,6 +1527,19 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1527 return i; 1527 return i;
1528} 1528}
1529 1529
1530/* Return the offset of POSITION, a click position, in the style of
1531 the respective argument of Fkey_binding. */
1532static ptrdiff_t
1533click_position (Lisp_Object position)
1534{
1535 EMACS_INT pos = (INTEGERP (position) ? XINT (position)
1536 : MARKERP (position) ? marker_position (position)
1537 : PT);
1538 if (! (BEGV <= pos && pos <= ZV))
1539 args_out_of_range (Fcurrent_buffer (), position);
1540 return pos;
1541}
1542
1530DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps, 1543DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
1531 0, 2, 0, 1544 0, 2, 0,
1532 doc: /* Return a list of the currently active keymaps. 1545 doc: /* Return a list of the currently active keymaps.
@@ -1535,7 +1548,7 @@ OLP if non-nil indicates that we should obey `overriding-local-map' and
1535like in the respective argument of `key-binding'. */) 1548like in the respective argument of `key-binding'. */)
1536 (Lisp_Object olp, Lisp_Object position) 1549 (Lisp_Object olp, Lisp_Object position)
1537{ 1550{
1538 int count = SPECPDL_INDEX (); 1551 ptrdiff_t count = SPECPDL_INDEX ();
1539 1552
1540 Lisp_Object keymaps = Fcons (current_global_map, Qnil); 1553 Lisp_Object keymaps = Fcons (current_global_map, Qnil);
1541 1554
@@ -1582,10 +1595,7 @@ like in the respective argument of `key-binding'. */)
1582 { 1595 {
1583 Lisp_Object *maps; 1596 Lisp_Object *maps;
1584 int nmaps, i; 1597 int nmaps, i;
1585 EMACS_INT pt 1598 ptrdiff_t pt = click_position (position);
1586 = INTEGERP (position) ? XINT (position)
1587 : MARKERP (position) ? marker_position (position)
1588 : PT;
1589 /* This usually returns the buffer's local map, 1599 /* This usually returns the buffer's local map,
1590 but that can be overridden by a `local-map' property. */ 1600 but that can be overridden by a `local-map' property. */
1591 Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map); 1601 Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map);
@@ -1904,10 +1914,10 @@ accessible_keymaps_1 (Lisp_Object key, Lisp_Object cmd, Lisp_Object args, void *
1904 while (!NILP (tem = Frassq (cmd, maps))) 1914 while (!NILP (tem = Frassq (cmd, maps)))
1905 { 1915 {
1906 Lisp_Object prefix = XCAR (tem); 1916 Lisp_Object prefix = XCAR (tem);
1907 int lim = XINT (Flength (XCAR (tem))); 1917 ptrdiff_t lim = XINT (Flength (XCAR (tem)));
1908 if (lim <= XINT (Flength (thisseq))) 1918 if (lim <= XINT (Flength (thisseq)))
1909 { /* This keymap was already seen with a smaller prefix. */ 1919 { /* This keymap was already seen with a smaller prefix. */
1910 int i = 0; 1920 ptrdiff_t i = 0;
1911 while (i < lim && EQ (Faref (prefix, make_number (i)), 1921 while (i < lim && EQ (Faref (prefix, make_number (i)),
1912 Faref (thisseq, make_number (i)))) 1922 Faref (thisseq, make_number (i))))
1913 i++; 1923 i++;
@@ -1960,7 +1970,7 @@ then the value includes only maps for prefixes that start with PREFIX. */)
1960 (Lisp_Object keymap, Lisp_Object prefix) 1970 (Lisp_Object keymap, Lisp_Object prefix)
1961{ 1971{
1962 Lisp_Object maps, tail; 1972 Lisp_Object maps, tail;
1963 int prefixlen = XINT (Flength (prefix)); 1973 EMACS_INT prefixlen = XFASTINT (Flength (prefix));
1964 1974
1965 /* no need for gcpro because we don't autoload any keymaps. */ 1975 /* no need for gcpro because we don't autoload any keymaps. */
1966 1976
@@ -2048,20 +2058,25 @@ For example, [?\C-x ?l] is converted into the string \"C-x l\".
2048The `kbd' macro is an approximate inverse of this. */) 2058The `kbd' macro is an approximate inverse of this. */)
2049 (Lisp_Object keys, Lisp_Object prefix) 2059 (Lisp_Object keys, Lisp_Object prefix)
2050{ 2060{
2051 int len = 0; 2061 ptrdiff_t len = 0;
2052 int i, i_byte; 2062 EMACS_INT i;
2063 ptrdiff_t i_byte;
2053 Lisp_Object *args; 2064 Lisp_Object *args;
2054 int size = XINT (Flength (keys)); 2065 EMACS_INT size = XINT (Flength (keys));
2055 Lisp_Object list; 2066 Lisp_Object list;
2056 Lisp_Object sep = build_string (" "); 2067 Lisp_Object sep = build_string (" ");
2057 Lisp_Object key; 2068 Lisp_Object key;
2069 Lisp_Object result;
2058 int add_meta = 0; 2070 int add_meta = 0;
2071 USE_SAFE_ALLOCA;
2059 2072
2060 if (!NILP (prefix)) 2073 if (!NILP (prefix))
2061 size += XINT (Flength (prefix)); 2074 size += XINT (Flength (prefix));
2062 2075
2063 /* This has one extra element at the end that we don't pass to Fconcat. */ 2076 /* This has one extra element at the end that we don't pass to Fconcat. */
2064 args = (Lisp_Object *) alloca (size * 4 * sizeof (Lisp_Object)); 2077 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) / 4 < size)
2078 memory_full (SIZE_MAX);
2079 SAFE_ALLOCA_LISP (args, size * 4);
2065 2080
2066 /* In effect, this computes 2081 /* In effect, this computes
2067 (mapconcat 'single-key-description keys " ") 2082 (mapconcat 'single-key-description keys " ")
@@ -2077,11 +2092,14 @@ The `kbd' macro is an approximate inverse of this. */)
2077 if (add_meta) 2092 if (add_meta)
2078 { 2093 {
2079 args[len] = Fsingle_key_description (meta_prefix_char, Qnil); 2094 args[len] = Fsingle_key_description (meta_prefix_char, Qnil);
2080 len += 2; 2095 result = Fconcat (len + 1, args);
2081 } 2096 }
2082 else if (len == 0) 2097 else if (len == 0)
2083 return empty_unibyte_string; 2098 result = empty_unibyte_string;
2084 return Fconcat (len - 1, args); 2099 else
2100 result = Fconcat (len - 1, args);
2101 SAFE_FREE ();
2102 return result;
2085 } 2103 }
2086 2104
2087 if (STRINGP (list)) 2105 if (STRINGP (list))
@@ -2350,7 +2368,7 @@ See Info node `(elisp)Describing Characters' for examples. */)
2350 char str[6]; 2368 char str[6];
2351 int c; 2369 int c;
2352 2370
2353 CHECK_NUMBER (character); 2371 CHECK_CHARACTER (character);
2354 2372
2355 c = XINT (character); 2373 c = XINT (character);
2356 if (!ASCII_CHAR_P (c)) 2374 if (!ASCII_CHAR_P (c))
@@ -2373,8 +2391,8 @@ static int where_is_preferred_modifier;
2373static int 2391static int
2374preferred_sequence_p (Lisp_Object seq) 2392preferred_sequence_p (Lisp_Object seq)
2375{ 2393{
2376 int i; 2394 EMACS_INT i;
2377 int len = XINT (Flength (seq)); 2395 EMACS_INT len = XFASTINT (Flength (seq));
2378 int result = 1; 2396 int result = 1;
2379 2397
2380 for (i = 0; i < len; i++) 2398 for (i = 0; i < len; i++)
@@ -3100,7 +3118,7 @@ static void
3100describe_command (Lisp_Object definition, Lisp_Object args) 3118describe_command (Lisp_Object definition, Lisp_Object args)
3101{ 3119{
3102 register Lisp_Object tem1; 3120 register Lisp_Object tem1;
3103 EMACS_INT column = current_column (); 3121 ptrdiff_t column = current_column ();
3104 int description_column; 3122 int description_column;
3105 3123
3106 /* If column 16 is no good, go to col 32; 3124 /* If column 16 is no good, go to col 32;
@@ -3383,7 +3401,7 @@ This is text showing the elements of vector matched against indices.
3383DESCRIBER is the output function used; nil means use `princ'. */) 3401DESCRIBER is the output function used; nil means use `princ'. */)
3384 (Lisp_Object vector, Lisp_Object describer) 3402 (Lisp_Object vector, Lisp_Object describer)
3385{ 3403{
3386 int count = SPECPDL_INDEX (); 3404 ptrdiff_t count = SPECPDL_INDEX ();
3387 if (NILP (describer)) 3405 if (NILP (describer))
3388 describer = intern ("princ"); 3406 describer = intern ("princ");
3389 specbind (Qstandard_output, Fcurrent_buffer ()); 3407 specbind (Qstandard_output, Fcurrent_buffer ());
diff --git a/src/lisp.h b/src/lisp.h
index fd9ac6ef0e2..1bdd10bb9d1 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -406,14 +406,13 @@ typedef EMACS_INT Lisp_Object;
406#define LISP_MAKE_RVALUE(o) (0+(o)) 406#define LISP_MAKE_RVALUE(o) (0+(o))
407#endif /* USE_LISP_UNION_TYPE */ 407#endif /* USE_LISP_UNION_TYPE */
408 408
409/* In the size word of a vector, this bit means the vector has been marked. 409/* In the size word of a vector, this bit means the vector has been marked. */
410 (Shift -1 left, not 1, to avoid provoking overflow diagnostics.) */
411 410
412#define ARRAY_MARK_FLAG ((EMACS_INT) -1 << (BITS_PER_EMACS_INT - 1)) 411#define ARRAY_MARK_FLAG PTRDIFF_MIN
413 412
414/* In the size word of a struct Lisp_Vector, this bit means it's really 413/* In the size word of a struct Lisp_Vector, this bit means it's really
415 some other vector-like object. */ 414 some other vector-like object. */
416#define PSEUDOVECTOR_FLAG ((EMACS_INT) 1 << (BITS_PER_EMACS_INT - 2)) 415#define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
417 416
418/* In a pseudovector, the size field actually contains a word with one 417/* In a pseudovector, the size field actually contains a word with one
419 PSEUDOVECTOR_FLAG bit set, and exactly one of the following bits to 418 PSEUDOVECTOR_FLAG bit set, and exactly one of the following bits to
@@ -628,6 +627,12 @@ extern Lisp_Object make_number (EMACS_INT);
628#define FIXNUM_OVERFLOW_P(i) \ 627#define FIXNUM_OVERFLOW_P(i) \
629 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM)) 628 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
630 629
630static inline ptrdiff_t
631clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
632{
633 return num < lower ? lower : num <= upper ? num : upper;
634}
635
631/* Extract a value or address from a Lisp_Object. */ 636/* Extract a value or address from a Lisp_Object. */
632 637
633#define XCONS(a) (eassert (CONSP (a)), \ 638#define XCONS(a) (eassert (CONSP (a)), \
@@ -851,7 +856,7 @@ struct Lisp_Cons
851#ifdef GC_CHECK_STRING_BYTES 856#ifdef GC_CHECK_STRING_BYTES
852 857
853struct Lisp_String; 858struct Lisp_String;
854extern EMACS_INT string_bytes (struct Lisp_String *); 859extern ptrdiff_t string_bytes (struct Lisp_String *);
855#define STRING_BYTES(S) string_bytes ((S)) 860#define STRING_BYTES(S) string_bytes ((S))
856 861
857#else /* not GC_CHECK_STRING_BYTES */ 862#else /* not GC_CHECK_STRING_BYTES */
@@ -898,8 +903,8 @@ extern EMACS_INT string_bytes (struct Lisp_String *);
898 903
899struct Lisp_String 904struct Lisp_String
900 { 905 {
901 EMACS_INT size; 906 ptrdiff_t size;
902 EMACS_INT size_byte; 907 ptrdiff_t size_byte;
903 INTERVAL intervals; /* text properties in this string */ 908 INTERVAL intervals; /* text properties in this string */
904 unsigned char *data; 909 unsigned char *data;
905 }; 910 };
@@ -913,7 +918,7 @@ struct Lisp_String
913 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */ 918 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */
914struct vectorlike_header 919struct vectorlike_header
915 { 920 {
916 EMACS_INT size; 921 ptrdiff_t size;
917 922
918 /* Pointer to the next vector-like object. It is generally a buffer or a 923 /* Pointer to the next vector-like object. It is generally a buffer or a
919 Lisp_Vector alias, so for convenience it is a union instead of a 924 Lisp_Vector alias, so for convenience it is a union instead of a
@@ -1108,7 +1113,7 @@ struct Lisp_Bool_Vector
1108 1113
1109struct Lisp_Subr 1114struct Lisp_Subr
1110 { 1115 {
1111 EMACS_INT size; 1116 ptrdiff_t size;
1112 union { 1117 union {
1113 Lisp_Object (*a0) (void); 1118 Lisp_Object (*a0) (void);
1114 Lisp_Object (*a1) (Lisp_Object); 1119 Lisp_Object (*a1) (Lisp_Object);
@@ -1295,7 +1300,7 @@ struct Lisp_Hash_Table
1295 a special way (e.g. because of weakness). */ 1300 a special way (e.g. because of weakness). */
1296 1301
1297 /* Number of key/value entries in the table. */ 1302 /* Number of key/value entries in the table. */
1298 EMACS_INT count; 1303 ptrdiff_t count;
1299 1304
1300 /* Vector of keys and values. The key of item I is found at index 1305 /* Vector of keys and values. The key of item I is found at index
1301 2 * I, the value is found at index 2 * I + 1. 1306 2 * I, the value is found at index 2 * I + 1.
@@ -1410,12 +1415,12 @@ struct Lisp_Marker
1410 That would also allow to preserve it ordered. */ 1415 That would also allow to preserve it ordered. */
1411 struct Lisp_Marker *next; 1416 struct Lisp_Marker *next;
1412 /* This is the char position where the marker points. */ 1417 /* This is the char position where the marker points. */
1413 EMACS_INT charpos; 1418 ptrdiff_t charpos;
1414 /* This is the byte position. 1419 /* This is the byte position.
1415 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly 1420 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
1416 used to implement the functionality of markers, but rather to (ab)use 1421 used to implement the functionality of markers, but rather to (ab)use
1417 markers as a cache for char<->byte mappings). */ 1422 markers as a cache for char<->byte mappings). */
1418 EMACS_INT bytepos; 1423 ptrdiff_t bytepos;
1419}; 1424};
1420 1425
1421/* Forwarding pointer to an int variable. 1426/* Forwarding pointer to an int variable.
@@ -1674,18 +1679,24 @@ typedef struct {
1674 encodes a char code in the lower CHARACTERBITS bits and a (very small) 1679 encodes a char code in the lower CHARACTERBITS bits and a (very small)
1675 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */ 1680 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */
1676 1681
1677#define GLYPH_CODE_CHAR(gc) \ 1682#define GLYPH_CODE_P(gc) \
1678 (CONSP (gc) ? XINT (XCAR (gc)) : INTEGERP (gc) ? (XINT (gc) & ((1 << CHARACTERBITS)-1)) : 0) 1683 (CONSP (gc) \
1684 ? (CHARACTERP (XCAR (gc)) \
1685 && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID)) \
1686 : (RANGED_INTEGERP \
1687 (0, gc, \
1688 (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS \
1689 ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR \
1690 : TYPE_MAXIMUM (EMACS_INT)))))
1679 1691
1680#define GLYPH_CODE_FACE(gc) \ 1692/* The following are valid only if GLYPH_CODE_P (gc). */
1681 (CONSP (gc) ? XINT (XCDR (gc)) : INTEGERP (gc) ? (XINT (gc) >> CHARACTERBITS) : DEFAULT_FACE_ID)
1682 1693
1683/* Return 1 if glyph code from display vector contains valid character code. */ 1694#define GLYPH_CODE_CHAR(gc) \
1684#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc)) 1695 (CONSP (gc) ? XINT (XCAR (gc)) : XINT (gc) & ((1 << CHARACTERBITS) - 1))
1685 1696
1686#define GLYPH_CODE_P(gc) ((CONSP (gc) && INTEGERP (XCAR (gc)) && INTEGERP (XCDR (gc))) || INTEGERP (gc)) 1697#define GLYPH_CODE_FACE(gc) \
1698 (CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS)
1687 1699
1688/* Only called when GLYPH_CODE_P (gc) is true. */
1689#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \ 1700#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \
1690 do \ 1701 do \
1691 { \ 1702 { \
@@ -1745,7 +1756,9 @@ typedef struct {
1745#define RANGED_INTEGERP(lo, x, hi) \ 1756#define RANGED_INTEGERP(lo, x, hi) \
1746 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi)) 1757 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
1747#define TYPE_RANGED_INTEGERP(type, x) \ 1758#define TYPE_RANGED_INTEGERP(type, x) \
1748 RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) 1759 (TYPE_SIGNED (type) \
1760 ? RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) \
1761 : RANGED_INTEGERP (0, x, TYPE_MAXIMUM (type)))
1749 1762
1750#define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x)))) 1763#define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
1751#define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol) 1764#define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
@@ -1868,6 +1881,25 @@ typedef struct {
1868#define CHECK_NATNUM(x) \ 1881#define CHECK_NATNUM(x) \
1869 CHECK_TYPE (NATNUMP (x), Qwholenump, x) 1882 CHECK_TYPE (NATNUMP (x), Qwholenump, x)
1870 1883
1884#define CHECK_RANGED_INTEGER(lo, x, hi) \
1885 do { \
1886 CHECK_NUMBER (x); \
1887 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
1888 args_out_of_range_3 \
1889 (x, \
1890 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
1891 ? MOST_NEGATIVE_FIXNUM \
1892 : (lo)), \
1893 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
1894 } while (0)
1895#define CHECK_TYPE_RANGED_INTEGER(type, x) \
1896 do { \
1897 if (TYPE_SIGNED (type)) \
1898 CHECK_RANGED_INTEGER (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)); \
1899 else \
1900 CHECK_RANGED_INTEGER (0, x, TYPE_MAXIMUM (type)); \
1901 } while (0)
1902
1871#define CHECK_MARKER(x) \ 1903#define CHECK_MARKER(x) \
1872 CHECK_TYPE (MARKERP (x), Qmarkerp, x) 1904 CHECK_TYPE (MARKERP (x), Qmarkerp, x)
1873 1905
@@ -2086,9 +2118,9 @@ struct specbinding
2086 2118
2087extern struct specbinding *specpdl; 2119extern struct specbinding *specpdl;
2088extern struct specbinding *specpdl_ptr; 2120extern struct specbinding *specpdl_ptr;
2089extern EMACS_INT specpdl_size; 2121extern ptrdiff_t specpdl_size;
2090 2122
2091#define SPECPDL_INDEX() ((int) (specpdl_ptr - specpdl)) 2123#define SPECPDL_INDEX() (specpdl_ptr - specpdl)
2092 2124
2093/* Everything needed to describe an active condition case. */ 2125/* Everything needed to describe an active condition case. */
2094struct handler 2126struct handler
@@ -2141,8 +2173,8 @@ struct catchtag
2141 jmp_buf jmp; 2173 jmp_buf jmp;
2142 struct backtrace *backlist; 2174 struct backtrace *backlist;
2143 struct handler *handlerlist; 2175 struct handler *handlerlist;
2144 int lisp_eval_depth; 2176 EMACS_INT lisp_eval_depth;
2145 int pdlcount; 2177 ptrdiff_t pdlcount;
2146 int poll_suppress_count; 2178 int poll_suppress_count;
2147 int interrupt_input_blocked; 2179 int interrupt_input_blocked;
2148 struct byte_stack *byte_stack; 2180 struct byte_stack *byte_stack;
@@ -2548,8 +2580,8 @@ EXFUN (Fread_coding_system, 2);
2548EXFUN (Fread_non_nil_coding_system, 1); 2580EXFUN (Fread_non_nil_coding_system, 1);
2549EXFUN (Ffind_operation_coding_system, MANY); 2581EXFUN (Ffind_operation_coding_system, MANY);
2550EXFUN (Fdecode_coding_string, 4); 2582EXFUN (Fdecode_coding_string, 4);
2551extern Lisp_Object detect_coding_system (const unsigned char *, EMACS_INT, 2583extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
2552 EMACS_INT, int, int, Lisp_Object); 2584 ptrdiff_t, int, int, Lisp_Object);
2553extern void init_coding (void); 2585extern void init_coding (void);
2554extern void init_coding_once (void); 2586extern void init_coding_once (void);
2555extern void syms_of_coding (void); 2587extern void syms_of_coding (void);
@@ -2557,8 +2589,8 @@ extern void syms_of_coding (void);
2557/* Defined in character.c */ 2589/* Defined in character.c */
2558EXFUN (Fchar_width, 1); 2590EXFUN (Fchar_width, 1);
2559EXFUN (Fstring, MANY); 2591EXFUN (Fstring, MANY);
2560extern EMACS_INT chars_in_text (const unsigned char *, EMACS_INT); 2592extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
2561extern EMACS_INT multibyte_chars_in_text (const unsigned char *, EMACS_INT); 2593extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
2562extern int multibyte_char_to_unibyte (int); 2594extern int multibyte_char_to_unibyte (int);
2563extern int multibyte_char_to_unibyte_safe (int); 2595extern int multibyte_char_to_unibyte_safe (int);
2564extern void init_character_once (void); 2596extern void init_character_once (void);
@@ -2585,7 +2617,7 @@ extern void syms_of_syntax (void);
2585extern Lisp_Object QCrehash_size, QCrehash_threshold; 2617extern Lisp_Object QCrehash_size, QCrehash_threshold;
2586enum { NEXT_ALMOST_PRIME_LIMIT = 11 }; 2618enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
2587extern EMACS_INT next_almost_prime (EMACS_INT); 2619extern EMACS_INT next_almost_prime (EMACS_INT);
2588extern Lisp_Object larger_vector (Lisp_Object, EMACS_INT, Lisp_Object); 2620extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
2589extern void sweep_weak_hash_tables (void); 2621extern void sweep_weak_hash_tables (void);
2590extern Lisp_Object Qcursor_in_echo_area; 2622extern Lisp_Object Qcursor_in_echo_area;
2591extern Lisp_Object Qstring_lessp; 2623extern Lisp_Object Qstring_lessp;
@@ -2617,8 +2649,8 @@ EXFUN (Fstring_as_multibyte, 1);
2617EXFUN (Fstring_as_unibyte, 1); 2649EXFUN (Fstring_as_unibyte, 1);
2618EXFUN (Fstring_to_multibyte, 1); 2650EXFUN (Fstring_to_multibyte, 1);
2619EXFUN (Fsubstring, 3); 2651EXFUN (Fsubstring, 3);
2620extern Lisp_Object substring_both (Lisp_Object, EMACS_INT, EMACS_INT, 2652extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
2621 EMACS_INT, EMACS_INT); 2653 ptrdiff_t, ptrdiff_t);
2622EXFUN (Fnth, 2); 2654EXFUN (Fnth, 2);
2623EXFUN (Fnthcdr, 2); 2655EXFUN (Fnthcdr, 2);
2624EXFUN (Fmemq, 2); 2656EXFUN (Fmemq, 2);
@@ -2646,8 +2678,8 @@ extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
2646extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object); 2678extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
2647extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object); 2679extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
2648extern void clear_string_char_byte_cache (void); 2680extern void clear_string_char_byte_cache (void);
2649extern EMACS_INT string_char_to_byte (Lisp_Object, EMACS_INT); 2681extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
2650extern EMACS_INT string_byte_to_char (Lisp_Object, EMACS_INT); 2682extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
2651extern Lisp_Object string_to_multibyte (Lisp_Object); 2683extern Lisp_Object string_to_multibyte (Lisp_Object);
2652extern Lisp_Object string_make_unibyte (Lisp_Object); 2684extern Lisp_Object string_make_unibyte (Lisp_Object);
2653EXFUN (Fcopy_alist, 1); 2685EXFUN (Fcopy_alist, 1);
@@ -2685,48 +2717,48 @@ extern void init_image (void);
2685 2717
2686/* Defined in insdel.c */ 2718/* Defined in insdel.c */
2687extern Lisp_Object Qinhibit_modification_hooks; 2719extern Lisp_Object Qinhibit_modification_hooks;
2688extern void move_gap (EMACS_INT); 2720extern void move_gap (ptrdiff_t);
2689extern void move_gap_both (EMACS_INT, EMACS_INT); 2721extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2690extern void buffer_overflow (void) NO_RETURN; 2722extern void buffer_overflow (void) NO_RETURN;
2691extern void make_gap (EMACS_INT); 2723extern void make_gap (ptrdiff_t);
2692extern EMACS_INT copy_text (const unsigned char *, unsigned char *, 2724extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2693 EMACS_INT, int, int); 2725 ptrdiff_t, int, int);
2694extern int count_combining_before (const unsigned char *, 2726extern int count_combining_before (const unsigned char *,
2695 EMACS_INT, EMACS_INT, EMACS_INT); 2727 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2696extern int count_combining_after (const unsigned char *, 2728extern int count_combining_after (const unsigned char *,
2697 EMACS_INT, EMACS_INT, EMACS_INT); 2729 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2698extern void insert (const char *, EMACS_INT); 2730extern void insert (const char *, ptrdiff_t);
2699extern void insert_and_inherit (const char *, EMACS_INT); 2731extern void insert_and_inherit (const char *, ptrdiff_t);
2700extern void insert_1 (const char *, EMACS_INT, int, int, int); 2732extern void insert_1 (const char *, ptrdiff_t, int, int, int);
2701extern void insert_1_both (const char *, EMACS_INT, EMACS_INT, 2733extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
2702 int, int, int); 2734 int, int, int);
2703extern void insert_from_gap (EMACS_INT, EMACS_INT); 2735extern void insert_from_gap (ptrdiff_t, ptrdiff_t);
2704extern void insert_from_string (Lisp_Object, EMACS_INT, EMACS_INT, 2736extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
2705 EMACS_INT, EMACS_INT, int); 2737 ptrdiff_t, ptrdiff_t, int);
2706extern void insert_from_buffer (struct buffer *, EMACS_INT, EMACS_INT, int); 2738extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2707extern void insert_char (int); 2739extern void insert_char (int);
2708extern void insert_string (const char *); 2740extern void insert_string (const char *);
2709extern void insert_before_markers (const char *, EMACS_INT); 2741extern void insert_before_markers (const char *, ptrdiff_t);
2710extern void insert_before_markers_and_inherit (const char *, EMACS_INT); 2742extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
2711extern void insert_from_string_before_markers (Lisp_Object, EMACS_INT, 2743extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
2712 EMACS_INT, EMACS_INT, 2744 ptrdiff_t, ptrdiff_t,
2713 EMACS_INT, int); 2745 ptrdiff_t, int);
2714extern void del_range (EMACS_INT, EMACS_INT); 2746extern void del_range (ptrdiff_t, ptrdiff_t);
2715extern Lisp_Object del_range_1 (EMACS_INT, EMACS_INT, int, int); 2747extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, int, int);
2716extern void del_range_byte (EMACS_INT, EMACS_INT, int); 2748extern void del_range_byte (ptrdiff_t, ptrdiff_t, int);
2717extern void del_range_both (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, int); 2749extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, int);
2718extern Lisp_Object del_range_2 (EMACS_INT, EMACS_INT, 2750extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
2719 EMACS_INT, EMACS_INT, int); 2751 ptrdiff_t, ptrdiff_t, int);
2720extern void modify_region (struct buffer *, EMACS_INT, EMACS_INT, int); 2752extern void modify_region (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2721extern void prepare_to_modify_buffer (EMACS_INT, EMACS_INT, EMACS_INT *); 2753extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
2722extern void signal_after_change (EMACS_INT, EMACS_INT, EMACS_INT); 2754extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
2723extern void adjust_after_insert (EMACS_INT, EMACS_INT, EMACS_INT, 2755extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2724 EMACS_INT, EMACS_INT); 2756 ptrdiff_t, ptrdiff_t);
2725extern void adjust_markers_for_delete (EMACS_INT, EMACS_INT, 2757extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
2726 EMACS_INT, EMACS_INT); 2758 ptrdiff_t, ptrdiff_t);
2727extern void replace_range (EMACS_INT, EMACS_INT, Lisp_Object, int, int, int); 2759extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, int, int, int);
2728extern void replace_range_2 (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, 2760extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2729 const char *, EMACS_INT, EMACS_INT, int); 2761 const char *, ptrdiff_t, ptrdiff_t, int);
2730extern void syms_of_insdel (void); 2762extern void syms_of_insdel (void);
2731 2763
2732/* Defined in dispnew.c */ 2764/* Defined in dispnew.c */
@@ -2734,6 +2766,7 @@ extern Lisp_Object selected_frame;
2734extern Lisp_Object Vwindow_system; 2766extern Lisp_Object Vwindow_system;
2735EXFUN (Fding, 1); 2767EXFUN (Fding, 1);
2736EXFUN (Fredraw_frame, 1); 2768EXFUN (Fredraw_frame, 1);
2769void duration_to_sec_usec (double, int *, int *);
2737EXFUN (Fsleep_for, 2); 2770EXFUN (Fsleep_for, 2);
2738EXFUN (Fredisplay, 1); 2771EXFUN (Fredisplay, 1);
2739extern Lisp_Object sit_for (Lisp_Object, int, int); 2772extern Lisp_Object sit_for (Lisp_Object, int, int);
@@ -2755,7 +2788,7 @@ extern Lisp_Object QCdata, QCfile;
2755extern Lisp_Object QCmap; 2788extern Lisp_Object QCmap;
2756extern Lisp_Object Qrisky_local_variable; 2789extern Lisp_Object Qrisky_local_variable;
2757extern struct frame *last_glyphless_glyph_frame; 2790extern struct frame *last_glyphless_glyph_frame;
2758extern unsigned last_glyphless_glyph_face_id; 2791extern int last_glyphless_glyph_face_id;
2759extern int last_glyphless_glyph_merged_face_id; 2792extern int last_glyphless_glyph_merged_face_id;
2760extern int noninteractive_need_newline; 2793extern int noninteractive_need_newline;
2761extern Lisp_Object echo_area_buffer[2]; 2794extern Lisp_Object echo_area_buffer[2];
@@ -2771,15 +2804,15 @@ extern void clear_message (int, int);
2771extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); 2804extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2772extern void message1 (const char *); 2805extern void message1 (const char *);
2773extern void message1_nolog (const char *); 2806extern void message1_nolog (const char *);
2774extern void message2 (const char *, EMACS_INT, int); 2807extern void message2 (const char *, ptrdiff_t, int);
2775extern void message2_nolog (const char *, EMACS_INT, int); 2808extern void message2_nolog (const char *, ptrdiff_t, int);
2776extern void message3 (Lisp_Object, EMACS_INT, int); 2809extern void message3 (Lisp_Object, ptrdiff_t, int);
2777extern void message3_nolog (Lisp_Object, EMACS_INT, int); 2810extern void message3_nolog (Lisp_Object, ptrdiff_t, int);
2778extern void message_dolog (const char *, EMACS_INT, int, int); 2811extern void message_dolog (const char *, ptrdiff_t, int, int);
2779extern void message_with_string (const char *, Lisp_Object, int); 2812extern void message_with_string (const char *, Lisp_Object, int);
2780extern void message_log_maybe_newline (void); 2813extern void message_log_maybe_newline (void);
2781extern void update_echo_area (void); 2814extern void update_echo_area (void);
2782extern void truncate_echo_area (EMACS_INT); 2815extern void truncate_echo_area (ptrdiff_t);
2783extern void redisplay (void); 2816extern void redisplay (void);
2784extern void redisplay_preserve_echo_area (int); 2817extern void redisplay_preserve_echo_area (int);
2785extern void prepare_menu_bars (void); 2818extern void prepare_menu_bars (void);
@@ -2788,7 +2821,7 @@ void set_frame_cursor_types (struct frame *, Lisp_Object);
2788extern void syms_of_xdisp (void); 2821extern void syms_of_xdisp (void);
2789extern void init_xdisp (void); 2822extern void init_xdisp (void);
2790extern Lisp_Object safe_eval (Lisp_Object); 2823extern Lisp_Object safe_eval (Lisp_Object);
2791extern int pos_visible_p (struct window *, EMACS_INT, int *, 2824extern int pos_visible_p (struct window *, ptrdiff_t, int *,
2792 int *, int *, int *, int *, int *); 2825 int *, int *, int *, int *, int *);
2793 2826
2794/* Defined in xsettings.c */ 2827/* Defined in xsettings.c */
@@ -2804,7 +2837,7 @@ extern void reset_malloc_hooks (void);
2804extern void uninterrupt_malloc (void); 2837extern void uninterrupt_malloc (void);
2805extern void malloc_warning (const char *); 2838extern void malloc_warning (const char *);
2806extern void memory_full (size_t) NO_RETURN; 2839extern void memory_full (size_t) NO_RETURN;
2807extern void buffer_memory_full (EMACS_INT) NO_RETURN; 2840extern void buffer_memory_full (ptrdiff_t) NO_RETURN;
2808extern int survives_gc_p (Lisp_Object); 2841extern int survives_gc_p (Lisp_Object);
2809extern void mark_object (Lisp_Object); 2842extern void mark_object (Lisp_Object);
2810#if defined REL_ALLOC && !defined SYSTEM_MALLOC 2843#if defined REL_ALLOC && !defined SYSTEM_MALLOC
@@ -2829,26 +2862,25 @@ EXFUN (Fmake_marker, 0);
2829extern void string_overflow (void) NO_RETURN; 2862extern void string_overflow (void) NO_RETURN;
2830EXFUN (Fmake_string, 2); 2863EXFUN (Fmake_string, 2);
2831extern Lisp_Object build_string (const char *); 2864extern Lisp_Object build_string (const char *);
2832extern Lisp_Object make_string (const char *, EMACS_INT); 2865extern Lisp_Object make_string (const char *, ptrdiff_t);
2833extern Lisp_Object make_unibyte_string (const char *, EMACS_INT); 2866extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
2834extern Lisp_Object make_multibyte_string (const char *, EMACS_INT, EMACS_INT); 2867extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
2835extern Lisp_Object make_event_array (int, Lisp_Object *); 2868extern Lisp_Object make_event_array (int, Lisp_Object *);
2836extern Lisp_Object make_uninit_string (EMACS_INT); 2869extern Lisp_Object make_uninit_string (EMACS_INT);
2837extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT); 2870extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
2838extern Lisp_Object make_string_from_bytes (const char *, EMACS_INT, EMACS_INT); 2871extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
2839extern Lisp_Object make_specified_string (const char *, 2872extern Lisp_Object make_specified_string (const char *,
2840 EMACS_INT, EMACS_INT, int); 2873 ptrdiff_t, ptrdiff_t, int);
2841EXFUN (Fpurecopy, 1); 2874EXFUN (Fpurecopy, 1);
2842extern Lisp_Object make_pure_string (const char *, EMACS_INT, EMACS_INT, int); 2875extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, int);
2843extern Lisp_Object make_pure_c_string (const char *data); 2876extern Lisp_Object make_pure_c_string (const char *data);
2844extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); 2877extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
2845extern Lisp_Object make_pure_vector (EMACS_INT);
2846EXFUN (Fgarbage_collect, 0); 2878EXFUN (Fgarbage_collect, 0);
2847EXFUN (Fmake_byte_code, MANY); 2879EXFUN (Fmake_byte_code, MANY);
2848EXFUN (Fmake_bool_vector, 2); 2880EXFUN (Fmake_bool_vector, 2);
2849extern Lisp_Object Qchar_table_extra_slots; 2881extern Lisp_Object Qchar_table_extra_slots;
2850extern struct Lisp_Vector *allocate_vector (EMACS_INT); 2882extern struct Lisp_Vector *allocate_vector (EMACS_INT);
2851extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag); 2883extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag);
2852#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \ 2884#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
2853 ((typ*) \ 2885 ((typ*) \
2854 allocate_pseudovector \ 2886 allocate_pseudovector \
@@ -2862,7 +2894,7 @@ extern int gc_in_progress;
2862extern int abort_on_gc; 2894extern int abort_on_gc;
2863extern Lisp_Object make_float (double); 2895extern Lisp_Object make_float (double);
2864extern void display_malloc_warning (void); 2896extern void display_malloc_warning (void);
2865extern int inhibit_garbage_collection (void); 2897extern ptrdiff_t inhibit_garbage_collection (void);
2866extern Lisp_Object make_save_value (void *, ptrdiff_t); 2898extern Lisp_Object make_save_value (void *, ptrdiff_t);
2867extern void free_marker (Lisp_Object); 2899extern void free_marker (Lisp_Object);
2868extern void free_cons (struct Lisp_Cons *); 2900extern void free_cons (struct Lisp_Cons *);
@@ -2878,6 +2910,7 @@ extern void *r_alloc (void **, size_t);
2878extern void r_alloc_free (void **); 2910extern void r_alloc_free (void **);
2879extern void *r_re_alloc (void **, size_t); 2911extern void *r_re_alloc (void **, size_t);
2880extern void r_alloc_reset_variable (void **, void **); 2912extern void r_alloc_reset_variable (void **, void **);
2913extern void r_alloc_inhibit_buffer_relocation (int);
2881#endif 2914#endif
2882 2915
2883/* Defined in chartab.c */ 2916/* Defined in chartab.c */
@@ -2954,7 +2987,7 @@ EXFUN (Fread_event, 3);
2954extern Lisp_Object check_obarray (Lisp_Object); 2987extern Lisp_Object check_obarray (Lisp_Object);
2955extern Lisp_Object intern (const char *); 2988extern Lisp_Object intern (const char *);
2956extern Lisp_Object intern_c_string (const char *); 2989extern Lisp_Object intern_c_string (const char *);
2957extern Lisp_Object oblookup (Lisp_Object, const char *, EMACS_INT, EMACS_INT); 2990extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
2958#define LOADHIST_ATTACH(x) \ 2991#define LOADHIST_ATTACH(x) \
2959 do { \ 2992 do { \
2960 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \ 2993 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
@@ -2971,7 +3004,7 @@ extern void init_lread (void);
2971extern void syms_of_lread (void); 3004extern void syms_of_lread (void);
2972 3005
2973/* Defined in eval.c. */ 3006/* Defined in eval.c. */
2974extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qdefun, Qmacro; 3007extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
2975extern Lisp_Object Qinhibit_quit, Qclosure; 3008extern Lisp_Object Qinhibit_quit, Qclosure;
2976extern Lisp_Object Qand_rest; 3009extern Lisp_Object Qand_rest;
2977extern Lisp_Object Vautoload_queue; 3010extern Lisp_Object Vautoload_queue;
@@ -3031,7 +3064,7 @@ extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp
3031extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object)); 3064extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
3032extern void specbind (Lisp_Object, Lisp_Object); 3065extern void specbind (Lisp_Object, Lisp_Object);
3033extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); 3066extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
3034extern Lisp_Object unbind_to (int, Lisp_Object); 3067extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3035extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2); 3068extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2);
3036extern void verror (const char *, va_list) 3069extern void verror (const char *, va_list)
3037 NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0); 3070 NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0);
@@ -3083,10 +3116,9 @@ EXFUN (Fuser_login_name, 1);
3083EXFUN (Fsystem_name, 0); 3116EXFUN (Fsystem_name, 0);
3084EXFUN (Fcurrent_time, 0); 3117EXFUN (Fcurrent_time, 0);
3085EXFUN (Fget_internal_run_time, 0); 3118EXFUN (Fget_internal_run_time, 0);
3086extern EMACS_INT clip_to_bounds (EMACS_INT, EMACS_INT, EMACS_INT); 3119extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, int);
3087extern Lisp_Object make_buffer_string (EMACS_INT, EMACS_INT, int); 3120extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3088extern Lisp_Object make_buffer_string_both (EMACS_INT, EMACS_INT, EMACS_INT, 3121 ptrdiff_t, int);
3089 EMACS_INT, int);
3090extern void init_editfns (void); 3122extern void init_editfns (void);
3091const char *get_system_name (void); 3123const char *get_system_name (void);
3092extern void syms_of_editfns (void); 3124extern void syms_of_editfns (void);
@@ -3100,12 +3132,12 @@ extern void nsberror (Lisp_Object) NO_RETURN;
3100EXFUN (Fset_buffer_multibyte, 1); 3132EXFUN (Fset_buffer_multibyte, 1);
3101EXFUN (Foverlay_start, 1); 3133EXFUN (Foverlay_start, 1);
3102EXFUN (Foverlay_end, 1); 3134EXFUN (Foverlay_end, 1);
3103extern void adjust_overlays_for_insert (EMACS_INT, EMACS_INT); 3135extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
3104extern void adjust_overlays_for_delete (EMACS_INT, EMACS_INT); 3136extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
3105extern void fix_start_end_in_overlays (EMACS_INT, EMACS_INT); 3137extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3106extern void report_overlay_modification (Lisp_Object, Lisp_Object, int, 3138extern void report_overlay_modification (Lisp_Object, Lisp_Object, int,
3107 Lisp_Object, Lisp_Object, Lisp_Object); 3139 Lisp_Object, Lisp_Object, Lisp_Object);
3108extern int overlay_touches_p (EMACS_INT); 3140extern int overlay_touches_p (ptrdiff_t);
3109extern Lisp_Object Vbuffer_alist; 3141extern Lisp_Object Vbuffer_alist;
3110EXFUN (Fget_buffer, 1); 3142EXFUN (Fget_buffer, 1);
3111EXFUN (Fget_buffer_create, 1); 3143EXFUN (Fget_buffer_create, 1);
@@ -3139,17 +3171,17 @@ EXFUN (Fmarker_position, 1);
3139EXFUN (Fmarker_buffer, 1); 3171EXFUN (Fmarker_buffer, 1);
3140EXFUN (Fcopy_marker, 2); 3172EXFUN (Fcopy_marker, 2);
3141EXFUN (Fset_marker, 3); 3173EXFUN (Fset_marker, 3);
3142extern EMACS_INT marker_position (Lisp_Object); 3174extern ptrdiff_t marker_position (Lisp_Object);
3143extern EMACS_INT marker_byte_position (Lisp_Object); 3175extern ptrdiff_t marker_byte_position (Lisp_Object);
3144extern void clear_charpos_cache (struct buffer *); 3176extern void clear_charpos_cache (struct buffer *);
3145extern EMACS_INT charpos_to_bytepos (EMACS_INT); 3177extern ptrdiff_t charpos_to_bytepos (ptrdiff_t);
3146extern EMACS_INT buf_charpos_to_bytepos (struct buffer *, EMACS_INT); 3178extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3147extern EMACS_INT buf_bytepos_to_charpos (struct buffer *, EMACS_INT); 3179extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3148extern void unchain_marker (struct Lisp_Marker *marker); 3180extern void unchain_marker (struct Lisp_Marker *marker);
3149extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object); 3181extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3150extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, EMACS_INT, EMACS_INT); 3182extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3151extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object, 3183extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
3152 EMACS_INT, EMACS_INT); 3184 ptrdiff_t, ptrdiff_t);
3153extern void syms_of_marker (void); 3185extern void syms_of_marker (void);
3154 3186
3155/* Defined in fileio.c */ 3187/* Defined in fileio.c */
@@ -3198,18 +3230,18 @@ struct re_registers;
3198extern struct re_pattern_buffer *compile_pattern (Lisp_Object, 3230extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3199 struct re_registers *, 3231 struct re_registers *,
3200 Lisp_Object, int, int); 3232 Lisp_Object, int, int);
3201extern EMACS_INT fast_string_match (Lisp_Object, Lisp_Object); 3233extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3202extern EMACS_INT fast_c_string_match_ignore_case (Lisp_Object, const char *); 3234extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *);
3203extern EMACS_INT fast_string_match_ignore_case (Lisp_Object, Lisp_Object); 3235extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3204extern EMACS_INT fast_looking_at (Lisp_Object, EMACS_INT, EMACS_INT, 3236extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3205 EMACS_INT, EMACS_INT, Lisp_Object); 3237 ptrdiff_t, ptrdiff_t, Lisp_Object);
3206extern EMACS_INT scan_buffer (int, EMACS_INT, EMACS_INT, EMACS_INT, 3238extern ptrdiff_t scan_buffer (int, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3207 EMACS_INT *, int); 3239 ptrdiff_t *, int);
3208extern EMACS_INT scan_newline (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, 3240extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3209 EMACS_INT, int); 3241 EMACS_INT, int);
3210extern EMACS_INT find_next_newline (EMACS_INT, int); 3242extern ptrdiff_t find_next_newline (ptrdiff_t, int);
3211extern EMACS_INT find_next_newline_no_quit (EMACS_INT, EMACS_INT); 3243extern ptrdiff_t find_next_newline_no_quit (ptrdiff_t, ptrdiff_t);
3212extern EMACS_INT find_before_next_newline (EMACS_INT, EMACS_INT, EMACS_INT); 3244extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3213extern void syms_of_search (void); 3245extern void syms_of_search (void);
3214extern void clear_regexp_cache (void); 3246extern void clear_regexp_cache (void);
3215 3247
@@ -3295,9 +3327,9 @@ extern void keys_of_keyboard (void);
3295EXFUN (Fvertical_motion, 2); 3327EXFUN (Fvertical_motion, 2);
3296EXFUN (Findent_to, 2); 3328EXFUN (Findent_to, 2);
3297EXFUN (Fmove_to_column, 2); 3329EXFUN (Fmove_to_column, 2);
3298extern EMACS_INT current_column (void); 3330extern ptrdiff_t current_column (void);
3299extern void invalidate_current_column (void); 3331extern void invalidate_current_column (void);
3300extern int indented_beyond_p (EMACS_INT, EMACS_INT, EMACS_INT); 3332extern int indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3301extern void syms_of_indent (void); 3333extern void syms_of_indent (void);
3302 3334
3303/* Defined in frame.c */ 3335/* Defined in frame.c */
@@ -3429,12 +3461,12 @@ extern Lisp_Object Qapply;
3429extern Lisp_Object Qinhibit_read_only; 3461extern Lisp_Object Qinhibit_read_only;
3430EXFUN (Fundo_boundary, 0); 3462EXFUN (Fundo_boundary, 0);
3431extern void truncate_undo_list (struct buffer *); 3463extern void truncate_undo_list (struct buffer *);
3432extern void record_marker_adjustment (Lisp_Object, EMACS_INT); 3464extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
3433extern void record_insert (EMACS_INT, EMACS_INT); 3465extern void record_insert (ptrdiff_t, ptrdiff_t);
3434extern void record_delete (EMACS_INT, Lisp_Object); 3466extern void record_delete (ptrdiff_t, Lisp_Object);
3435extern void record_first_change (void); 3467extern void record_first_change (void);
3436extern void record_change (EMACS_INT, EMACS_INT); 3468extern void record_change (ptrdiff_t, ptrdiff_t);
3437extern void record_property_change (EMACS_INT, EMACS_INT, 3469extern void record_property_change (ptrdiff_t, ptrdiff_t,
3438 Lisp_Object, Lisp_Object, 3470 Lisp_Object, Lisp_Object,
3439 Lisp_Object); 3471 Lisp_Object);
3440extern void syms_of_undo (void); 3472extern void syms_of_undo (void);
@@ -3480,8 +3512,8 @@ extern void init_sys_modes (struct tty_display_info *);
3480extern void reset_sys_modes (struct tty_display_info *); 3512extern void reset_sys_modes (struct tty_display_info *);
3481extern void init_all_sys_modes (void); 3513extern void init_all_sys_modes (void);
3482extern void reset_all_sys_modes (void); 3514extern void reset_all_sys_modes (void);
3483extern void wait_for_termination (int); 3515extern void wait_for_termination (pid_t);
3484extern void interruptible_wait_for_termination (int); 3516extern void interruptible_wait_for_termination (pid_t);
3485extern void flush_pending_output (int); 3517extern void flush_pending_output (int);
3486extern void child_setup_tty (int); 3518extern void child_setup_tty (int);
3487extern void setup_pty (int); 3519extern void setup_pty (int);
@@ -3490,8 +3522,8 @@ extern EMACS_INT get_random (void);
3490extern void seed_random (long); 3522extern void seed_random (long);
3491extern int emacs_open (const char *, int, int); 3523extern int emacs_open (const char *, int, int);
3492extern int emacs_close (int); 3524extern int emacs_close (int);
3493extern EMACS_INT emacs_read (int, char *, EMACS_INT); 3525extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
3494extern EMACS_INT emacs_write (int, const char *, EMACS_INT); 3526extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
3495enum { READLINK_BUFSIZE = 1024 }; 3527enum { READLINK_BUFSIZE = 1024 };
3496extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); 3528extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
3497 3529
@@ -3718,7 +3750,7 @@ extern void init_system_name (void);
3718extern Lisp_Object safe_alloca_unwind (Lisp_Object); 3750extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3719 3751
3720#define USE_SAFE_ALLOCA \ 3752#define USE_SAFE_ALLOCA \
3721 int sa_count = (int) SPECPDL_INDEX (), sa_must_free = 0 3753 ptrdiff_t sa_count = SPECPDL_INDEX (); int sa_must_free = 0
3722 3754
3723/* SAFE_ALLOCA allocates a simple buffer. */ 3755/* SAFE_ALLOCA allocates a simple buffer. */
3724 3756
diff --git a/src/lisp.mk b/src/lisp.mk
index 4608cc3f687..c9966c6506c 100644
--- a/src/lisp.mk
+++ b/src/lisp.mk
@@ -30,8 +30,9 @@
30## sed -e 's/"[ )].*//' -n -e '/(load "/ s/.*load "//p' loadup.el | \ 30## sed -e 's/"[ )].*//' -n -e '/(load "/ s/.*load "//p' loadup.el | \
31## grep -vE 'site-|ldefs-boot' 31## grep -vE 'site-|ldefs-boot'
32## minus any duplicates. 32## minus any duplicates.
33## Note that you cannot just add a ".elc" extension to every file, 33## Note that you can generally just add a ".elc" extension to every file
34## since some of them are no-byte-compile (eg some language/ ones). 34## that does not have an explicit .el extension, but beware of any
35## no-byte-compile ones.
35 36
36## Confusingly, term/internal is not in loadup, but is unconditionally 37## Confusingly, term/internal is not in loadup, but is unconditionally
37## loaded by pc-win, which is. 38## loaded by pc-win, which is.
@@ -53,7 +54,7 @@ lisp = \
53 $(lispsource)/emacs-lisp/byte-run.elc \ 54 $(lispsource)/emacs-lisp/byte-run.elc \
54 $(lispsource)/emacs-lisp/backquote.elc \ 55 $(lispsource)/emacs-lisp/backquote.elc \
55 $(lispsource)/subr.elc \ 56 $(lispsource)/subr.elc \
56 $(lispsource)/version.el \ 57 $(lispsource)/version.elc \
57 $(lispsource)/widget.elc \ 58 $(lispsource)/widget.elc \
58 $(lispsource)/custom.elc \ 59 $(lispsource)/custom.elc \
59 $(lispsource)/emacs-lisp/map-ynp.elc \ 60 $(lispsource)/emacs-lisp/map-ynp.elc \
@@ -82,28 +83,28 @@ lisp = \
82 $(lispsource)/language/chinese.elc \ 83 $(lispsource)/language/chinese.elc \
83 $(lispsource)/language/cyrillic.elc \ 84 $(lispsource)/language/cyrillic.elc \
84 $(lispsource)/language/indian.elc \ 85 $(lispsource)/language/indian.elc \
85 $(lispsource)/language/sinhala.el \ 86 $(lispsource)/language/sinhala.elc \
86 $(lispsource)/language/english.el \ 87 $(lispsource)/language/english.elc \
87 $(lispsource)/language/ethiopic.elc \ 88 $(lispsource)/language/ethiopic.elc \
88 $(lispsource)/language/european.elc \ 89 $(lispsource)/language/european.elc \
89 $(lispsource)/language/czech.el \ 90 $(lispsource)/language/czech.elc \
90 $(lispsource)/language/slovak.el \ 91 $(lispsource)/language/slovak.elc \
91 $(lispsource)/language/romanian.el \ 92 $(lispsource)/language/romanian.elc \
92 $(lispsource)/language/greek.el \ 93 $(lispsource)/language/greek.elc \
93 $(lispsource)/language/hebrew.elc \ 94 $(lispsource)/language/hebrew.elc \
94 $(lispsource)/language/japanese.el \ 95 $(lispsource)/language/japanese.elc \
95 $(lispsource)/language/korean.el \ 96 $(lispsource)/language/korean.elc \
96 $(lispsource)/language/lao.el \ 97 $(lispsource)/language/lao.elc \
97 $(lispsource)/language/tai-viet.el \ 98 $(lispsource)/language/tai-viet.elc \
98 $(lispsource)/language/thai.el \ 99 $(lispsource)/language/thai.elc \
99 $(lispsource)/language/tibetan.elc \ 100 $(lispsource)/language/tibetan.elc \
100 $(lispsource)/language/vietnamese.elc \ 101 $(lispsource)/language/vietnamese.elc \
101 $(lispsource)/language/misc-lang.el \ 102 $(lispsource)/language/misc-lang.elc \
102 $(lispsource)/language/utf-8-lang.el \ 103 $(lispsource)/language/utf-8-lang.elc \
103 $(lispsource)/language/georgian.el \ 104 $(lispsource)/language/georgian.elc \
104 $(lispsource)/language/khmer.el \ 105 $(lispsource)/language/khmer.elc \
105 $(lispsource)/language/burmese.el \ 106 $(lispsource)/language/burmese.elc \
106 $(lispsource)/language/cham.el \ 107 $(lispsource)/language/cham.elc \
107 $(lispsource)/indent.elc \ 108 $(lispsource)/indent.elc \
108 $(lispsource)/window.elc \ 109 $(lispsource)/window.elc \
109 $(lispsource)/frame.elc \ 110 $(lispsource)/frame.elc \
@@ -120,7 +121,7 @@ lisp = \
120 $(lispsource)/isearch.elc \ 121 $(lispsource)/isearch.elc \
121 $(lispsource)/rfn-eshadow.elc \ 122 $(lispsource)/rfn-eshadow.elc \
122 $(lispsource)/menu-bar.elc \ 123 $(lispsource)/menu-bar.elc \
123 $(lispsource)/paths.el \ 124 $(lispsource)/paths.elc \
124 $(lispsource)/emacs-lisp/lisp.elc \ 125 $(lispsource)/emacs-lisp/lisp.elc \
125 $(lispsource)/textmodes/page.elc \ 126 $(lispsource)/textmodes/page.elc \
126 $(lispsource)/register.elc \ 127 $(lispsource)/register.elc \
diff --git a/src/lread.c b/src/lread.c
index 6b657f61ed0..38b00a66962 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -61,7 +61,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
61#define file_tell ftell 61#define file_tell ftell
62#endif 62#endif
63 63
64/* hash table read constants */ 64/* Hash table read constants. */
65static Lisp_Object Qhash_table, Qdata; 65static Lisp_Object Qhash_table, Qdata;
66static Lisp_Object Qtest, Qsize; 66static Lisp_Object Qtest, Qsize;
67static Lisp_Object Qweakness; 67static Lisp_Object Qweakness;
@@ -105,16 +105,13 @@ static Lisp_Object load_descriptor_list;
105/* File for get_file_char to read from. Use by load. */ 105/* File for get_file_char to read from. Use by load. */
106static FILE *instream; 106static FILE *instream;
107 107
108/* When nonzero, read conses in pure space */
109static int read_pure;
110
111/* For use within read-from-string (this reader is non-reentrant!!) */ 108/* For use within read-from-string (this reader is non-reentrant!!) */
112static EMACS_INT read_from_string_index; 109static ptrdiff_t read_from_string_index;
113static EMACS_INT read_from_string_index_byte; 110static ptrdiff_t read_from_string_index_byte;
114static EMACS_INT read_from_string_limit; 111static ptrdiff_t read_from_string_limit;
115 112
116/* Number of characters read in the current call to Fread or 113/* Number of characters read in the current call to Fread or
117 Fread_from_string. */ 114 Fread_from_string. */
118static EMACS_INT readchar_count; 115static EMACS_INT readchar_count;
119 116
120/* This contains the last string skipped with #@. */ 117/* This contains the last string skipped with #@. */
@@ -187,7 +184,7 @@ static int readbyte_from_string (int, Lisp_Object);
187/* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, 184/* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
188 Qlambda, or a cons, we use this to keep an unread character because 185 Qlambda, or a cons, we use this to keep an unread character because
189 a file stream can't handle multibyte-char unreading. The value -1 186 a file stream can't handle multibyte-char unreading. The value -1
190 means that there's no unread character. */ 187 means that there's no unread character. */
191static int unread_char; 188static int unread_char;
192 189
193static int 190static int
@@ -209,7 +206,7 @@ readchar (Lisp_Object readcharfun, int *multibyte)
209 { 206 {
210 register struct buffer *inbuffer = XBUFFER (readcharfun); 207 register struct buffer *inbuffer = XBUFFER (readcharfun);
211 208
212 EMACS_INT pt_byte = BUF_PT_BYTE (inbuffer); 209 ptrdiff_t pt_byte = BUF_PT_BYTE (inbuffer);
213 210
214 if (pt_byte >= BUF_ZV_BYTE (inbuffer)) 211 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
215 return -1; 212 return -1;
@@ -238,7 +235,7 @@ readchar (Lisp_Object readcharfun, int *multibyte)
238 { 235 {
239 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer; 236 register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
240 237
241 EMACS_INT bytepos = marker_byte_position (readcharfun); 238 ptrdiff_t bytepos = marker_byte_position (readcharfun);
242 239
243 if (bytepos >= BUF_ZV_BYTE (inbuffer)) 240 if (bytepos >= BUF_ZV_BYTE (inbuffer))
244 return -1; 241 return -1;
@@ -372,8 +369,8 @@ unreadchar (Lisp_Object readcharfun, int c)
372 else if (BUFFERP (readcharfun)) 369 else if (BUFFERP (readcharfun))
373 { 370 {
374 struct buffer *b = XBUFFER (readcharfun); 371 struct buffer *b = XBUFFER (readcharfun);
375 EMACS_INT charpos = BUF_PT (b); 372 ptrdiff_t charpos = BUF_PT (b);
376 EMACS_INT bytepos = BUF_PT_BYTE (b); 373 ptrdiff_t bytepos = BUF_PT_BYTE (b);
377 374
378 if (! NILP (BVAR (b, enable_multibyte_characters))) 375 if (! NILP (BVAR (b, enable_multibyte_characters)))
379 BUF_DEC_POS (b, bytepos); 376 BUF_DEC_POS (b, bytepos);
@@ -385,7 +382,7 @@ unreadchar (Lisp_Object readcharfun, int c)
385 else if (MARKERP (readcharfun)) 382 else if (MARKERP (readcharfun))
386 { 383 {
387 struct buffer *b = XMARKER (readcharfun)->buffer; 384 struct buffer *b = XMARKER (readcharfun)->buffer;
388 EMACS_INT bytepos = XMARKER (readcharfun)->bytepos; 385 ptrdiff_t bytepos = XMARKER (readcharfun)->bytepos;
389 386
390 XMARKER (readcharfun)->charpos--; 387 XMARKER (readcharfun)->charpos--;
391 if (! NILP (BVAR (b, enable_multibyte_characters))) 388 if (! NILP (BVAR (b, enable_multibyte_characters)))
@@ -447,7 +444,7 @@ readbyte_from_file (int c, Lisp_Object readcharfun)
447 c = getc (instream); 444 c = getc (instream);
448 445
449#ifdef EINTR 446#ifdef EINTR
450 /* Interrupted reads have been observed while reading over the network */ 447 /* Interrupted reads have been observed while reading over the network. */
451 while (c == EOF && ferror (instream) && errno == EINTR) 448 while (c == EOF && ferror (instream) && errno == EINTR)
452 { 449 {
453 UNBLOCK_INPUT; 450 UNBLOCK_INPUT;
@@ -608,8 +605,11 @@ read_filtered_event (int no_switch_frame, int ascii_required,
608 int sec, usec; 605 int sec, usec;
609 double duration = extract_float (seconds); 606 double duration = extract_float (seconds);
610 607
611 sec = (int) duration; 608 if (0 < duration)
612 usec = (duration - sec) * 1000000; 609 duration_to_sec_usec (duration, &sec, &usec);
610 else
611 sec = usec = 0;
612
613 EMACS_GET_TIME (end_time); 613 EMACS_GET_TIME (end_time);
614 EMACS_SET_SECS_USECS (wait_time, sec, usec); 614 EMACS_SET_SECS_USECS (wait_time, sec, usec);
615 EMACS_ADD_TIME (end_time, end_time, wait_time); 615 EMACS_ADD_TIME (end_time, end_time, wait_time);
@@ -1022,7 +1022,7 @@ Return t if the file exists and loads successfully. */)
1022{ 1022{
1023 register FILE *stream; 1023 register FILE *stream;
1024 register int fd = -1; 1024 register int fd = -1;
1025 int count = SPECPDL_INDEX (); 1025 ptrdiff_t count = SPECPDL_INDEX ();
1026 struct gcpro gcpro1, gcpro2, gcpro3; 1026 struct gcpro gcpro1, gcpro2, gcpro3;
1027 Lisp_Object found, efound, hist_file_name; 1027 Lisp_Object found, efound, hist_file_name;
1028 /* 1 means we printed the ".el is newer" message. */ 1028 /* 1 means we printed the ".el is newer" message. */
@@ -1067,7 +1067,7 @@ Return t if the file exists and loads successfully. */)
1067 1067
1068 1068
1069 /* Avoid weird lossage with null string as arg, 1069 /* Avoid weird lossage with null string as arg,
1070 since it would try to load a directory as a Lisp file */ 1070 since it would try to load a directory as a Lisp file. */
1071 if (SBYTES (file) > 0) 1071 if (SBYTES (file) > 0)
1072 { 1072 {
1073 ptrdiff_t size = SBYTES (file); 1073 ptrdiff_t size = SBYTES (file);
@@ -1171,7 +1171,7 @@ Return t if the file exists and loads successfully. */)
1171 Vload_source_file_function. */ 1171 Vload_source_file_function. */
1172 specbind (Qlexical_binding, Qnil); 1172 specbind (Qlexical_binding, Qnil);
1173 1173
1174 /* Get the name for load-history. */ 1174 /* Get the name for load-history. */
1175 hist_file_name = (! NILP (Vpurify_flag) 1175 hist_file_name = (! NILP (Vpurify_flag)
1176 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file), 1176 ? Fconcat (2, (tmp[0] = Ffile_name_directory (file),
1177 tmp[1] = Ffile_name_nondirectory (found), 1177 tmp[1] = Ffile_name_nondirectory (found),
@@ -1324,7 +1324,7 @@ Return t if the file exists and loads successfully. */)
1324 } 1324 }
1325 unbind_to (count, Qnil); 1325 unbind_to (count, Qnil);
1326 1326
1327 /* Run any eval-after-load forms for this file */ 1327 /* Run any eval-after-load forms for this file. */
1328 if (!NILP (Ffboundp (Qdo_after_load_evaluation))) 1328 if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
1329 call1 (Qdo_after_load_evaluation, hist_file_name) ; 1329 call1 (Qdo_after_load_evaluation, hist_file_name) ;
1330 1330
@@ -1356,7 +1356,7 @@ Return t if the file exists and loads successfully. */)
1356} 1356}
1357 1357
1358static Lisp_Object 1358static Lisp_Object
1359load_unwind (Lisp_Object arg) /* used as unwind-protect function in load */ 1359load_unwind (Lisp_Object arg) /* Used as unwind-protect function in load. */
1360{ 1360{
1361 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; 1361 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1362 if (stream != NULL) 1362 if (stream != NULL)
@@ -1442,16 +1442,16 @@ int
1442openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) 1442openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate)
1443{ 1443{
1444 register int fd; 1444 register int fd;
1445 EMACS_INT fn_size = 100; 1445 ptrdiff_t fn_size = 100;
1446 char buf[100]; 1446 char buf[100];
1447 register char *fn = buf; 1447 register char *fn = buf;
1448 int absolute = 0; 1448 int absolute = 0;
1449 EMACS_INT want_length; 1449 ptrdiff_t want_length;
1450 Lisp_Object filename; 1450 Lisp_Object filename;
1451 struct stat st; 1451 struct stat st;
1452 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 1452 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1453 Lisp_Object string, tail, encoded_fn; 1453 Lisp_Object string, tail, encoded_fn;
1454 EMACS_INT max_suffix_len = 0; 1454 ptrdiff_t max_suffix_len = 0;
1455 1455
1456 CHECK_STRING (str); 1456 CHECK_STRING (str);
1457 1457
@@ -1475,13 +1475,13 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1475 { 1475 {
1476 filename = Fexpand_file_name (str, XCAR (path)); 1476 filename = Fexpand_file_name (str, XCAR (path));
1477 if (!complete_filename_p (filename)) 1477 if (!complete_filename_p (filename))
1478 /* If there are non-absolute elts in PATH (eg ".") */ 1478 /* If there are non-absolute elts in PATH (eg "."). */
1479 /* Of course, this could conceivably lose if luser sets 1479 /* Of course, this could conceivably lose if luser sets
1480 default-directory to be something non-absolute... */ 1480 default-directory to be something non-absolute... */
1481 { 1481 {
1482 filename = Fexpand_file_name (filename, BVAR (current_buffer, directory)); 1482 filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
1483 if (!complete_filename_p (filename)) 1483 if (!complete_filename_p (filename))
1484 /* Give up on this path element! */ 1484 /* Give up on this path element! */
1485 continue; 1485 continue;
1486 } 1486 }
1487 1487
@@ -1561,7 +1561,9 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1561 { 1561 {
1562 /* Check that we can access or open it. */ 1562 /* Check that we can access or open it. */
1563 if (NATNUMP (predicate)) 1563 if (NATNUMP (predicate))
1564 fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1; 1564 fd = (((XFASTINT (predicate) & ~INT_MAX) == 0
1565 && access (pfn, XFASTINT (predicate)) == 0)
1566 ? 1 : -1);
1565 else 1567 else
1566 fd = emacs_open (pfn, O_RDONLY, 0); 1568 fd = emacs_open (pfn, O_RDONLY, 0);
1567 1569
@@ -1606,12 +1608,12 @@ build_load_history (Lisp_Object filename, int entire)
1606 { 1608 {
1607 tem = XCAR (tail); 1609 tem = XCAR (tail);
1608 1610
1609 /* Find the feature's previous assoc list... */ 1611 /* Find the feature's previous assoc list... */
1610 if (!NILP (Fequal (filename, Fcar (tem)))) 1612 if (!NILP (Fequal (filename, Fcar (tem))))
1611 { 1613 {
1612 foundit = 1; 1614 foundit = 1;
1613 1615
1614 /* If we're loading the entire file, remove old data. */ 1616 /* If we're loading the entire file, remove old data. */
1615 if (entire) 1617 if (entire)
1616 { 1618 {
1617 if (NILP (prev)) 1619 if (NILP (prev))
@@ -1653,13 +1655,6 @@ build_load_history (Lisp_Object filename, int entire)
1653} 1655}
1654 1656
1655static Lisp_Object 1657static Lisp_Object
1656unreadpure (Lisp_Object junk) /* Used as unwind-protect function in readevalloop */
1657{
1658 read_pure = 0;
1659 return Qnil;
1660}
1661
1662static Lisp_Object
1663readevalloop_1 (Lisp_Object old) 1658readevalloop_1 (Lisp_Object old)
1664{ 1659{
1665 load_convert_to_unibyte = ! NILP (old); 1660 load_convert_to_unibyte = ! NILP (old);
@@ -1695,7 +1690,7 @@ readevalloop (Lisp_Object readcharfun,
1695{ 1690{
1696 register int c; 1691 register int c;
1697 register Lisp_Object val; 1692 register Lisp_Object val;
1698 int count = SPECPDL_INDEX (); 1693 ptrdiff_t count = SPECPDL_INDEX ();
1699 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1694 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1700 struct buffer *b = 0; 1695 struct buffer *b = 0;
1701 int continue_reading_p; 1696 int continue_reading_p;
@@ -1735,7 +1730,7 @@ readevalloop (Lisp_Object readcharfun,
1735 1730
1736 GCPRO4 (sourcename, readfun, start, end); 1731 GCPRO4 (sourcename, readfun, start, end);
1737 1732
1738 /* Try to ensure sourcename is a truename, except whilst preloading. */ 1733 /* Try to ensure sourcename is a truename, except whilst preloading. */
1739 if (NILP (Vpurify_flag) 1734 if (NILP (Vpurify_flag)
1740 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename)) 1735 && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename))
1741 && !NILP (Ffboundp (Qfile_truename))) 1736 && !NILP (Ffboundp (Qfile_truename)))
@@ -1746,7 +1741,7 @@ readevalloop (Lisp_Object readcharfun,
1746 continue_reading_p = 1; 1741 continue_reading_p = 1;
1747 while (continue_reading_p) 1742 while (continue_reading_p)
1748 { 1743 {
1749 int count1 = SPECPDL_INDEX (); 1744 ptrdiff_t count1 = SPECPDL_INDEX ();
1750 1745
1751 if (b != 0 && NILP (BVAR (b, name))) 1746 if (b != 0 && NILP (BVAR (b, name)))
1752 error ("Reading from killed buffer"); 1747 error ("Reading from killed buffer");
@@ -1800,8 +1795,7 @@ readevalloop (Lisp_Object readcharfun,
1800 1795
1801 if (!NILP (Vpurify_flag) && c == '(') 1796 if (!NILP (Vpurify_flag) && c == '(')
1802 { 1797 {
1803 record_unwind_protect (unreadpure, Qnil); 1798 val = read_list (0, readcharfun);
1804 val = read_list (-1, readcharfun);
1805 } 1799 }
1806 else 1800 else
1807 { 1801 {
@@ -1872,7 +1866,7 @@ DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1872This function preserves the position of point. */) 1866This function preserves the position of point. */)
1873 (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print) 1867 (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print)
1874{ 1868{
1875 int count = SPECPDL_INDEX (); 1869 ptrdiff_t count = SPECPDL_INDEX ();
1876 Lisp_Object tem, buf; 1870 Lisp_Object tem, buf;
1877 1871
1878 if (NILP (buffer)) 1872 if (NILP (buffer))
@@ -1917,7 +1911,7 @@ This function does not move point. */)
1917 (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function) 1911 (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
1918{ 1912{
1919 /* FIXME: Do the eval-sexp-add-defvars dance! */ 1913 /* FIXME: Do the eval-sexp-add-defvars dance! */
1920 int count = SPECPDL_INDEX (); 1914 ptrdiff_t count = SPECPDL_INDEX ();
1921 Lisp_Object tem, cbuf; 1915 Lisp_Object tem, cbuf;
1922 1916
1923 cbuf = Fcurrent_buffer (); 1917 cbuf = Fcurrent_buffer ();
@@ -1929,7 +1923,7 @@ This function does not move point. */)
1929 specbind (Qstandard_output, tem); 1923 specbind (Qstandard_output, tem);
1930 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list)); 1924 specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list));
1931 1925
1932 /* readevalloop calls functions which check the type of start and end. */ 1926 /* `readevalloop' calls functions which check the type of start and end. */
1933 readevalloop (cbuf, 0, BVAR (XBUFFER (cbuf), filename), 1927 readevalloop (cbuf, 0, BVAR (XBUFFER (cbuf), filename),
1934 !NILP (printflag), Qnil, read_function, 1928 !NILP (printflag), Qnil, read_function,
1935 start, end); 1929 start, end);
@@ -1972,16 +1966,16 @@ START and END optionally delimit a substring of STRING from which to read;
1972{ 1966{
1973 Lisp_Object ret; 1967 Lisp_Object ret;
1974 CHECK_STRING (string); 1968 CHECK_STRING (string);
1975 /* read_internal_start sets read_from_string_index. */ 1969 /* `read_internal_start' sets `read_from_string_index'. */
1976 ret = read_internal_start (string, start, end); 1970 ret = read_internal_start (string, start, end);
1977 return Fcons (ret, make_number (read_from_string_index)); 1971 return Fcons (ret, make_number (read_from_string_index));
1978} 1972}
1979 1973
1980/* Function to set up the global context we need in toplevel read 1974/* Function to set up the global context we need in toplevel read
1981 calls. */ 1975 calls. */
1982static Lisp_Object 1976static Lisp_Object
1983read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end) 1977read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
1984/* start, end only used when stream is a string. */ 1978/* `start', `end' only used when stream is a string. */
1985{ 1979{
1986 Lisp_Object retval; 1980 Lisp_Object retval;
1987 1981
@@ -1995,7 +1989,7 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
1995 if (STRINGP (stream) 1989 if (STRINGP (stream)
1996 || ((CONSP (stream) && STRINGP (XCAR (stream))))) 1990 || ((CONSP (stream) && STRINGP (XCAR (stream)))))
1997 { 1991 {
1998 EMACS_INT startval, endval; 1992 ptrdiff_t startval, endval;
1999 Lisp_Object string; 1993 Lisp_Object string;
2000 1994
2001 if (STRINGP (stream)) 1995 if (STRINGP (stream))
@@ -2008,9 +2002,9 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
2008 else 2002 else
2009 { 2003 {
2010 CHECK_NUMBER (end); 2004 CHECK_NUMBER (end);
2011 endval = XINT (end); 2005 if (! (0 <= XINT (end) && XINT (end) <= SCHARS (string)))
2012 if (endval < 0 || endval > SCHARS (string))
2013 args_out_of_range (string, end); 2006 args_out_of_range (string, end);
2007 endval = XINT (end);
2014 } 2008 }
2015 2009
2016 if (NILP (start)) 2010 if (NILP (start))
@@ -2018,9 +2012,9 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
2018 else 2012 else
2019 { 2013 {
2020 CHECK_NUMBER (start); 2014 CHECK_NUMBER (start);
2021 startval = XINT (start); 2015 if (! (0 <= XINT (start) && XINT (start) <= endval))
2022 if (startval < 0 || startval > endval)
2023 args_out_of_range (string, start); 2016 args_out_of_range (string, start);
2017 startval = XINT (start);
2024 } 2018 }
2025 read_from_string_index = startval; 2019 read_from_string_index = startval;
2026 read_from_string_index_byte = string_char_to_byte (string, startval); 2020 read_from_string_index_byte = string_char_to_byte (string, startval);
@@ -2046,7 +2040,7 @@ invalid_syntax (const char *s)
2046 2040
2047 2041
2048/* Use this for recursive reads, in contexts where internal tokens 2042/* Use this for recursive reads, in contexts where internal tokens
2049 are not allowed. */ 2043 are not allowed. */
2050 2044
2051static Lisp_Object 2045static Lisp_Object
2052read0 (Lisp_Object readcharfun) 2046read0 (Lisp_Object readcharfun)
@@ -2073,7 +2067,7 @@ read_escape (Lisp_Object readcharfun, int stringp)
2073{ 2067{
2074 register int c = READCHAR; 2068 register int c = READCHAR;
2075 /* \u allows up to four hex digits, \U up to eight. Default to the 2069 /* \u allows up to four hex digits, \U up to eight. Default to the
2076 behavior for \u, and change this value in the case that \U is seen. */ 2070 behavior for \u, and change this value in the case that \U is seen. */
2077 int unicode_hex_count = 4; 2071 int unicode_hex_count = 4;
2078 2072
2079 switch (c) 2073 switch (c)
@@ -2259,8 +2253,8 @@ read_escape (Lisp_Object readcharfun, int stringp)
2259 while (++count <= unicode_hex_count) 2253 while (++count <= unicode_hex_count)
2260 { 2254 {
2261 c = READCHAR; 2255 c = READCHAR;
2262 /* isdigit and isalpha may be locale-specific, which we don't 2256 /* `isdigit' and `isalpha' may be locale-specific, which we don't
2263 want. */ 2257 want. */
2264 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); 2258 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
2265 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; 2259 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
2266 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; 2260 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
@@ -2414,13 +2408,13 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2414 { 2408 {
2415 /* Accept extended format for hashtables (extensible to 2409 /* Accept extended format for hashtables (extensible to
2416 other types), e.g. 2410 other types), e.g.
2417 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ 2411 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2418 Lisp_Object tmp = read_list (0, readcharfun); 2412 Lisp_Object tmp = read_list (0, readcharfun);
2419 Lisp_Object head = CAR_SAFE (tmp); 2413 Lisp_Object head = CAR_SAFE (tmp);
2420 Lisp_Object data = Qnil; 2414 Lisp_Object data = Qnil;
2421 Lisp_Object val = Qnil; 2415 Lisp_Object val = Qnil;
2422 /* The size is 2 * number of allowed keywords to 2416 /* The size is 2 * number of allowed keywords to
2423 make-hash-table. */ 2417 make-hash-table. */
2424 Lisp_Object params[10]; 2418 Lisp_Object params[10];
2425 Lisp_Object ht; 2419 Lisp_Object ht;
2426 Lisp_Object key = Qnil; 2420 Lisp_Object key = Qnil;
@@ -2432,36 +2426,36 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2432 2426
2433 tmp = CDR_SAFE (tmp); 2427 tmp = CDR_SAFE (tmp);
2434 2428
2435 /* This is repetitive but fast and simple. */ 2429 /* This is repetitive but fast and simple. */
2436 params[param_count] = QCsize; 2430 params[param_count] = QCsize;
2437 params[param_count+1] = Fplist_get (tmp, Qsize); 2431 params[param_count + 1] = Fplist_get (tmp, Qsize);
2438 if (!NILP (params[param_count + 1])) 2432 if (!NILP (params[param_count + 1]))
2439 param_count += 2; 2433 param_count += 2;
2440 2434
2441 params[param_count] = QCtest; 2435 params[param_count] = QCtest;
2442 params[param_count+1] = Fplist_get (tmp, Qtest); 2436 params[param_count + 1] = Fplist_get (tmp, Qtest);
2443 if (!NILP (params[param_count + 1])) 2437 if (!NILP (params[param_count + 1]))
2444 param_count += 2; 2438 param_count += 2;
2445 2439
2446 params[param_count] = QCweakness; 2440 params[param_count] = QCweakness;
2447 params[param_count+1] = Fplist_get (tmp, Qweakness); 2441 params[param_count + 1] = Fplist_get (tmp, Qweakness);
2448 if (!NILP (params[param_count + 1])) 2442 if (!NILP (params[param_count + 1]))
2449 param_count += 2; 2443 param_count += 2;
2450 2444
2451 params[param_count] = QCrehash_size; 2445 params[param_count] = QCrehash_size;
2452 params[param_count+1] = Fplist_get (tmp, Qrehash_size); 2446 params[param_count + 1] = Fplist_get (tmp, Qrehash_size);
2453 if (!NILP (params[param_count + 1])) 2447 if (!NILP (params[param_count + 1]))
2454 param_count += 2; 2448 param_count += 2;
2455 2449
2456 params[param_count] = QCrehash_threshold; 2450 params[param_count] = QCrehash_threshold;
2457 params[param_count+1] = Fplist_get (tmp, Qrehash_threshold); 2451 params[param_count + 1] = Fplist_get (tmp, Qrehash_threshold);
2458 if (!NILP (params[param_count + 1])) 2452 if (!NILP (params[param_count + 1]))
2459 param_count += 2; 2453 param_count += 2;
2460 2454
2461 /* This is the hashtable data. */ 2455 /* This is the hashtable data. */
2462 data = Fplist_get (tmp, Qdata); 2456 data = Fplist_get (tmp, Qdata);
2463 2457
2464 /* Now use params to make a new hashtable and fill it. */ 2458 /* Now use params to make a new hashtable and fill it. */
2465 ht = Fmake_hash_table (param_count, params); 2459 ht = Fmake_hash_table (param_count, params);
2466 2460
2467 while (CONSP (data)) 2461 while (CONSP (data))
@@ -2498,16 +2492,17 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2498 if (c == '[') 2492 if (c == '[')
2499 { 2493 {
2500 Lisp_Object tmp; 2494 Lisp_Object tmp;
2501 EMACS_INT depth, size; 2495 int depth;
2496 ptrdiff_t size;
2502 2497
2503 tmp = read_vector (readcharfun, 0); 2498 tmp = read_vector (readcharfun, 0);
2504 if (!INTEGERP (AREF (tmp, 0))) 2499 size = ASIZE (tmp);
2500 if (size == 0)
2501 error ("Invalid size char-table");
2502 if (! RANGED_INTEGERP (1, AREF (tmp, 0), 3))
2505 error ("Invalid depth in char-table"); 2503 error ("Invalid depth in char-table");
2506 depth = XINT (AREF (tmp, 0)); 2504 depth = XINT (AREF (tmp, 0));
2507 if (depth < 1 || depth > 3) 2505 if (chartab_size[depth] != size - 2)
2508 error ("Invalid depth in char-table");
2509 size = ASIZE (tmp) - 2;
2510 if (chartab_size [depth] != size)
2511 error ("Invalid size char-table"); 2506 error ("Invalid size char-table");
2512 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE); 2507 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2513 return tmp; 2508 return tmp;
@@ -2728,7 +2723,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2728 n for #n#. */ 2723 n for #n#. */
2729 if (c == '=') 2724 if (c == '=')
2730 { 2725 {
2731 /* Make a placeholder for #n# to use temporarily */ 2726 /* Make a placeholder for #n# to use temporarily. */
2732 Lisp_Object placeholder; 2727 Lisp_Object placeholder;
2733 Lisp_Object cell; 2728 Lisp_Object cell;
2734 2729
@@ -2736,10 +2731,10 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2736 cell = Fcons (make_number (n), placeholder); 2731 cell = Fcons (make_number (n), placeholder);
2737 read_objects = Fcons (cell, read_objects); 2732 read_objects = Fcons (cell, read_objects);
2738 2733
2739 /* Read the object itself. */ 2734 /* Read the object itself. */
2740 tem = read0 (readcharfun); 2735 tem = read0 (readcharfun);
2741 2736
2742 /* Now put it everywhere the placeholder was... */ 2737 /* Now put it everywhere the placeholder was... */
2743 substitute_object_in_subtree (tem, placeholder); 2738 substitute_object_in_subtree (tem, placeholder);
2744 2739
2745 /* ...and #n# will use the real value from now on. */ 2740 /* ...and #n# will use the real value from now on. */
@@ -2922,7 +2917,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2922 2917
2923 ch = read_escape (readcharfun, 1); 2918 ch = read_escape (readcharfun, 1);
2924 2919
2925 /* CH is -1 if \ newline has just been seen */ 2920 /* CH is -1 if \ newline has just been seen. */
2926 if (ch == -1) 2921 if (ch == -1)
2927 { 2922 {
2928 if (p == read_buffer) 2923 if (p == read_buffer)
@@ -2937,7 +2932,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2937 force_singlebyte = 1; 2932 force_singlebyte = 1;
2938 else if (! ASCII_CHAR_P (ch)) 2933 else if (! ASCII_CHAR_P (ch))
2939 force_multibyte = 1; 2934 force_multibyte = 1;
2940 else /* i.e. ASCII_CHAR_P (ch) */ 2935 else /* I.e. ASCII_CHAR_P (ch). */
2941 { 2936 {
2942 /* Allow `\C- ' and `\C-?'. */ 2937 /* Allow `\C- ' and `\C-?'. */
2943 if (modifiers == CHAR_CTL) 2938 if (modifiers == CHAR_CTL)
@@ -2987,28 +2982,19 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2987 2982
2988 /* If purifying, and string starts with \ newline, 2983 /* If purifying, and string starts with \ newline,
2989 return zero instead. This is for doc strings 2984 return zero instead. This is for doc strings
2990 that we are really going to find in etc/DOC.nn.nn */ 2985 that we are really going to find in etc/DOC.nn.nn. */
2991 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) 2986 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
2992 return make_number (0); 2987 return make_number (0);
2993 2988
2994 if (force_multibyte) 2989 if (! force_multibyte && force_singlebyte)
2995 /* READ_BUFFER already contains valid multibyte forms. */
2996 ;
2997 else if (force_singlebyte)
2998 { 2990 {
2991 /* READ_BUFFER contains raw 8-bit bytes and no multibyte
2992 forms. Convert it to unibyte. */
2999 nchars = str_as_unibyte ((unsigned char *) read_buffer, 2993 nchars = str_as_unibyte ((unsigned char *) read_buffer,
3000 p - read_buffer); 2994 p - read_buffer);
3001 p = read_buffer + nchars; 2995 p = read_buffer + nchars;
3002 } 2996 }
3003 else
3004 {
3005 /* Otherwise, READ_BUFFER contains only ASCII. */
3006 }
3007 2997
3008 if (read_pure)
3009 return make_pure_string (read_buffer, nchars, p - read_buffer,
3010 (force_multibyte
3011 || (p - read_buffer != nchars)));
3012 return make_specified_string (read_buffer, nchars, p - read_buffer, 2998 return make_specified_string (read_buffer, nchars, p - read_buffer,
3013 (force_multibyte 2999 (force_multibyte
3014 || (p - read_buffer != nchars))); 3000 || (p - read_buffer != nchars)));
@@ -3102,25 +3088,24 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
3102 } 3088 }
3103 { 3089 {
3104 Lisp_Object name, result; 3090 Lisp_Object name, result;
3105 EMACS_INT nbytes = p - read_buffer; 3091 ptrdiff_t nbytes = p - read_buffer;
3106 EMACS_INT nchars 3092 ptrdiff_t nchars
3107 = (multibyte 3093 = (multibyte
3108 ? multibyte_chars_in_text ((unsigned char *) read_buffer, 3094 ? multibyte_chars_in_text ((unsigned char *) read_buffer,
3109 nbytes) 3095 nbytes)
3110 : nbytes); 3096 : nbytes);
3111 3097
3112 if (uninterned_symbol && ! NILP (Vpurify_flag)) 3098 name = ((uninterned_symbol && ! NILP (Vpurify_flag)
3113 name = make_pure_string (read_buffer, nchars, nbytes, multibyte); 3099 ? make_pure_string : make_specified_string)
3114 else 3100 (read_buffer, nchars, nbytes, multibyte));
3115 name = make_specified_string (read_buffer, nchars, nbytes, multibyte);
3116 result = (uninterned_symbol ? Fmake_symbol (name) 3101 result = (uninterned_symbol ? Fmake_symbol (name)
3117 : Fintern (name, Qnil)); 3102 : Fintern (name, Qnil));
3118 3103
3119 if (EQ (Vread_with_symbol_positions, Qt) 3104 if (EQ (Vread_with_symbol_positions, Qt)
3120 || EQ (Vread_with_symbol_positions, readcharfun)) 3105 || EQ (Vread_with_symbol_positions, readcharfun))
3121 Vread_symbol_positions_list = 3106 Vread_symbol_positions_list
3122 Fcons (Fcons (result, make_number (start_position)), 3107 = Fcons (Fcons (result, make_number (start_position)),
3123 Vread_symbol_positions_list); 3108 Vread_symbol_positions_list);
3124 return result; 3109 return result;
3125 } 3110 }
3126 } 3111 }
@@ -3128,7 +3113,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
3128} 3113}
3129 3114
3130 3115
3131/* List of nodes we've seen during substitute_object_in_subtree. */ 3116/* List of nodes we've seen during substitute_object_in_subtree. */
3132static Lisp_Object seen_list; 3117static Lisp_Object seen_list;
3133 3118
3134static void 3119static void
@@ -3136,23 +3121,23 @@ substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder)
3136{ 3121{
3137 Lisp_Object check_object; 3122 Lisp_Object check_object;
3138 3123
3139 /* We haven't seen any objects when we start. */ 3124 /* We haven't seen any objects when we start. */
3140 seen_list = Qnil; 3125 seen_list = Qnil;
3141 3126
3142 /* Make all the substitutions. */ 3127 /* Make all the substitutions. */
3143 check_object 3128 check_object
3144 = substitute_object_recurse (object, placeholder, object); 3129 = substitute_object_recurse (object, placeholder, object);
3145 3130
3146 /* Clear seen_list because we're done with it. */ 3131 /* Clear seen_list because we're done with it. */
3147 seen_list = Qnil; 3132 seen_list = Qnil;
3148 3133
3149 /* The returned object here is expected to always eq the 3134 /* The returned object here is expected to always eq the
3150 original. */ 3135 original. */
3151 if (!EQ (check_object, object)) 3136 if (!EQ (check_object, object))
3152 error ("Unexpected mutation error in reader"); 3137 error ("Unexpected mutation error in reader");
3153} 3138}
3154 3139
3155/* Feval doesn't get called from here, so no gc protection is needed. */ 3140/* Feval doesn't get called from here, so no gc protection is needed. */
3156#define SUBSTITUTE(get_val, set_val) \ 3141#define SUBSTITUTE(get_val, set_val) \
3157 do { \ 3142 do { \
3158 Lisp_Object old_value = get_val; \ 3143 Lisp_Object old_value = get_val; \
@@ -3169,11 +3154,11 @@ substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder)
3169static Lisp_Object 3154static Lisp_Object
3170substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree) 3155substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree)
3171{ 3156{
3172 /* If we find the placeholder, return the target object. */ 3157 /* If we find the placeholder, return the target object. */
3173 if (EQ (placeholder, subtree)) 3158 if (EQ (placeholder, subtree))
3174 return object; 3159 return object;
3175 3160
3176 /* If we've been to this node before, don't explore it again. */ 3161 /* If we've been to this node before, don't explore it again. */
3177 if (!EQ (Qnil, Fmemq (subtree, seen_list))) 3162 if (!EQ (Qnil, Fmemq (subtree, seen_list)))
3178 return subtree; 3163 return subtree;
3179 3164
@@ -3223,7 +3208,7 @@ substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Obj
3223 case Lisp_String: 3208 case Lisp_String:
3224 { 3209 {
3225 /* Check for text properties in each interval. 3210 /* Check for text properties in each interval.
3226 substitute_in_interval contains part of the logic. */ 3211 substitute_in_interval contains part of the logic. */
3227 3212
3228 INTERVAL root_interval = STRING_INTERVALS (subtree); 3213 INTERVAL root_interval = STRING_INTERVALS (subtree);
3229 Lisp_Object arg = Fcons (object, placeholder); 3214 Lisp_Object arg = Fcons (object, placeholder);
@@ -3234,7 +3219,7 @@ substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Obj
3234 return subtree; 3219 return subtree;
3235 } 3220 }
3236 3221
3237 /* Other types don't recurse any further. */ 3222 /* Other types don't recurse any further. */
3238 default: 3223 default:
3239 return subtree; 3224 return subtree;
3240 } 3225 }
@@ -3421,7 +3406,7 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
3421 3406
3422 tem = read_list (1, readcharfun); 3407 tem = read_list (1, readcharfun);
3423 len = Flength (tem); 3408 len = Flength (tem);
3424 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil)); 3409 vector = Fmake_vector (len, Qnil);
3425 3410
3426 size = ASIZE (vector); 3411 size = ASIZE (vector);
3427 ptr = XVECTOR (vector)->contents; 3412 ptr = XVECTOR (vector)->contents;
@@ -3468,7 +3453,7 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
3468 } 3453 }
3469 3454
3470 /* Now handle the bytecode slot. */ 3455 /* Now handle the bytecode slot. */
3471 ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr; 3456 ptr[COMPILED_BYTECODE] = bytestr;
3472 } 3457 }
3473 else if (i == COMPILED_DOC_STRING 3458 else if (i == COMPILED_DOC_STRING
3474 && STRINGP (item) 3459 && STRINGP (item)
@@ -3480,7 +3465,7 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
3480 item = Fstring_as_multibyte (item); 3465 item = Fstring_as_multibyte (item);
3481 } 3466 }
3482 } 3467 }
3483 ptr[i] = read_pure ? Fpurecopy (item) : item; 3468 ptr[i] = item;
3484 otem = XCONS (tem); 3469 otem = XCONS (tem);
3485 tem = Fcdr (tem); 3470 tem = Fcdr (tem);
3486 free_cons (otem); 3471 free_cons (otem);
@@ -3488,17 +3473,11 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
3488 return vector; 3473 return vector;
3489} 3474}
3490 3475
3491/* FLAG = 1 means check for ] to terminate rather than ) and . 3476/* FLAG = 1 means check for ] to terminate rather than ) and . */
3492 FLAG = -1 means check for starting with defun
3493 and make structure pure. */
3494 3477
3495static Lisp_Object 3478static Lisp_Object
3496read_list (int flag, register Lisp_Object readcharfun) 3479read_list (int flag, register Lisp_Object readcharfun)
3497{ 3480{
3498 /* -1 means check next element for defun,
3499 0 means don't check,
3500 1 means already checked and found defun. */
3501 int defunflag = flag < 0 ? -1 : 0;
3502 Lisp_Object val, tail; 3481 Lisp_Object val, tail;
3503 register Lisp_Object elt, tem; 3482 register Lisp_Object elt, tem;
3504 struct gcpro gcpro1, gcpro2; 3483 struct gcpro gcpro1, gcpro2;
@@ -3540,7 +3519,7 @@ read_list (int flag, register Lisp_Object readcharfun)
3540 We don't use Fexpand_file_name because that would make 3519 We don't use Fexpand_file_name because that would make
3541 the directory absolute now. */ 3520 the directory absolute now. */
3542 elt = concat2 (build_string ("../lisp/"), 3521 elt = concat2 (build_string ("../lisp/"),
3543 Ffile_name_nondirectory (elt)); 3522 Ffile_name_nondirectory (elt));
3544 } 3523 }
3545 else if (EQ (elt, Vload_file_name) 3524 else if (EQ (elt, Vload_file_name)
3546 && ! NILP (elt) 3525 && ! NILP (elt)
@@ -3660,24 +3639,18 @@ read_list (int flag, register Lisp_Object readcharfun)
3660 } 3639 }
3661 invalid_syntax ("] in a list"); 3640 invalid_syntax ("] in a list");
3662 } 3641 }
3663 tem = (read_pure && flag <= 0 3642 tem = Fcons (elt, Qnil);
3664 ? pure_cons (elt, Qnil)
3665 : Fcons (elt, Qnil));
3666 if (!NILP (tail)) 3643 if (!NILP (tail))
3667 XSETCDR (tail, tem); 3644 XSETCDR (tail, tem);
3668 else 3645 else
3669 val = tem; 3646 val = tem;
3670 tail = tem; 3647 tail = tem;
3671 if (defunflag < 0)
3672 defunflag = EQ (elt, Qdefun);
3673 else if (defunflag > 0)
3674 read_pure = 1;
3675 } 3648 }
3676} 3649}
3677 3650
3678static Lisp_Object initial_obarray; 3651static Lisp_Object initial_obarray;
3679 3652
3680/* oblookup stores the bucket number here, for the sake of Funintern. */ 3653/* `oblookup' stores the bucket number here, for the sake of Funintern. */
3681 3654
3682static size_t oblookup_last_bucket_number; 3655static size_t oblookup_last_bucket_number;
3683 3656
@@ -3888,7 +3861,7 @@ OBARRAY defaults to the value of the variable `obarray'. */)
3888 Also store the bucket number in oblookup_last_bucket_number. */ 3861 Also store the bucket number in oblookup_last_bucket_number. */
3889 3862
3890Lisp_Object 3863Lisp_Object
3891oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_INT size_byte) 3864oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff_t size_byte)
3892{ 3865{
3893 size_t hash; 3866 size_t hash;
3894 size_t obsize; 3867 size_t obsize;
@@ -3909,7 +3882,7 @@ oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_I
3909 if (EQ (bucket, make_number (0))) 3882 if (EQ (bucket, make_number (0)))
3910 ; 3883 ;
3911 else if (!SYMBOLP (bucket)) 3884 else if (!SYMBOLP (bucket))
3912 error ("Bad data in guts of obarray"); /* Like CADR error message */ 3885 error ("Bad data in guts of obarray"); /* Like CADR error message. */
3913 else 3886 else
3914 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) 3887 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
3915 { 3888 {
@@ -4016,7 +3989,7 @@ defsubr (struct Lisp_Subr *sname)
4016 XSETSUBR (XSYMBOL (sym)->function, sname); 3989 XSETSUBR (XSYMBOL (sym)->function, sname);
4017} 3990}
4018 3991
4019#ifdef NOTDEF /* use fset in subr.el now */ 3992#ifdef NOTDEF /* Use fset in subr.el now! */
4020void 3993void
4021defalias (struct Lisp_Subr *sname, char *string) 3994defalias (struct Lisp_Subr *sname, char *string)
4022{ 3995{
@@ -4361,7 +4334,7 @@ dir_warning (const char *format, Lisp_Object dirname)
4361{ 4334{
4362 fprintf (stderr, format, SDATA (dirname)); 4335 fprintf (stderr, format, SDATA (dirname));
4363 4336
4364 /* Don't log the warning before we've initialized!! */ 4337 /* Don't log the warning before we've initialized!! */
4365 if (initialized) 4338 if (initialized)
4366 { 4339 {
4367 char *buffer; 4340 char *buffer;
diff --git a/src/macros.c b/src/macros.c
index d43e37513f5..3f4f8624479 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -95,13 +95,14 @@ macro before appending to it. */)
95 has put another macro there. */ 95 has put another macro there. */
96 if (current_kboard->kbd_macro_bufsize < len + 30) 96 if (current_kboard->kbd_macro_bufsize < len + 30)
97 { 97 {
98 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) - 30 98 if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
99 < current_kboard->kbd_macro_bufsize) 99 && PTRDIFF_MAX < len + 30)
100 memory_full (SIZE_MAX); 100 memory_full (SIZE_MAX);
101 current_kboard->kbd_macro_buffer 101 current_kboard->kbd_macro_buffer =
102 = (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer, 102 xpalloc (current_kboard->kbd_macro_buffer,
103 (len + 30) * sizeof (Lisp_Object)); 103 &current_kboard->kbd_macro_bufsize,
104 current_kboard->kbd_macro_bufsize = len + 30; 104 len + 30 - current_kboard->kbd_macro_bufsize, -1,
105 sizeof *current_kboard->kbd_macro_buffer);
105 } 106 }
106 107
107 /* Must convert meta modifier when copying string to vector. */ 108 /* Must convert meta modifier when copying string to vector. */
@@ -301,7 +302,7 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
301{ 302{
302 Lisp_Object final; 303 Lisp_Object final;
303 Lisp_Object tem; 304 Lisp_Object tem;
304 int pdlcount = SPECPDL_INDEX (); 305 ptrdiff_t pdlcount = SPECPDL_INDEX ();
305 EMACS_INT repeat = 1; 306 EMACS_INT repeat = 1;
306 struct gcpro gcpro1, gcpro2; 307 struct gcpro gcpro1, gcpro2;
307 EMACS_INT success_count = 0; 308 EMACS_INT success_count = 0;
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 99b1241eab0..0b88f7cd06b 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -1149,6 +1149,7 @@ $(BLD)/w32heap.$(O) : \
1149 1149
1150$(BLD)/w32inevt.$(O) : \ 1150$(BLD)/w32inevt.$(O) : \
1151 $(SRC)/w32inevt.c \ 1151 $(SRC)/w32inevt.c \
1152 $(SRC)/termchar.h \
1152 $(SRC)/w32heap.h \ 1153 $(SRC)/w32heap.h \
1153 $(BLOCKINPUT_H) \ 1154 $(BLOCKINPUT_H) \
1154 $(CONFIG_H) \ 1155 $(CONFIG_H) \
@@ -1157,7 +1158,8 @@ $(BLD)/w32inevt.$(O) : \
1157 $(KEYBOARD_H) \ 1158 $(KEYBOARD_H) \
1158 $(LISP_H) \ 1159 $(LISP_H) \
1159 $(TERMHOOKS_H) \ 1160 $(TERMHOOKS_H) \
1160 $(W32TERM_H) 1161 $(W32TERM_H) \
1162 $(WINDOW_H)
1161 1163
1162$(BLD)/w32proc.$(O) : \ 1164$(BLD)/w32proc.$(O) : \
1163 $(SRC)/w32proc.c \ 1165 $(SRC)/w32proc.c \
@@ -1187,7 +1189,8 @@ $(BLD)/w32console.$(O) : \
1187 $(DISPEXTERN_H) \ 1189 $(DISPEXTERN_H) \
1188 $(FRAME_H) \ 1190 $(FRAME_H) \
1189 $(LISP_H) \ 1191 $(LISP_H) \
1190 $(TERMHOOKS_H) 1192 $(TERMHOOKS_H) \
1193 $(WINDOW_H)
1191 1194
1192$(BLD)/print.$(O) : \ 1195$(BLD)/print.$(O) : \
1193 $(SRC)/print.c \ 1196 $(SRC)/print.c \
diff --git a/src/marker.c b/src/marker.c
index 75d4fe954fd..37953494459 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -26,12 +26,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26/* Record one cached position found recently by 26/* Record one cached position found recently by
27 buf_charpos_to_bytepos or buf_bytepos_to_charpos. */ 27 buf_charpos_to_bytepos or buf_bytepos_to_charpos. */
28 28
29static EMACS_INT cached_charpos; 29static ptrdiff_t cached_charpos;
30static EMACS_INT cached_bytepos; 30static ptrdiff_t cached_bytepos;
31static struct buffer *cached_buffer; 31static struct buffer *cached_buffer;
32static int cached_modiff; 32static int cached_modiff;
33 33
34static void byte_char_debug_check (struct buffer *, EMACS_INT, EMACS_INT); 34static void byte_char_debug_check (struct buffer *, ptrdiff_t, ptrdiff_t);
35 35
36void 36void
37clear_charpos_cache (struct buffer *b) 37clear_charpos_cache (struct buffer *b)
@@ -55,12 +55,12 @@ clear_charpos_cache (struct buffer *b)
55 55
56#define CONSIDER(CHARPOS, BYTEPOS) \ 56#define CONSIDER(CHARPOS, BYTEPOS) \
57{ \ 57{ \
58 EMACS_INT this_charpos = (CHARPOS); \ 58 ptrdiff_t this_charpos = (CHARPOS); \
59 int changed = 0; \ 59 int changed = 0; \
60 \ 60 \
61 if (this_charpos == charpos) \ 61 if (this_charpos == charpos) \
62 { \ 62 { \
63 EMACS_INT value = (BYTEPOS); \ 63 ptrdiff_t value = (BYTEPOS); \
64 if (byte_debug_flag) \ 64 if (byte_debug_flag) \
65 byte_char_debug_check (b, charpos, value); \ 65 byte_char_debug_check (b, charpos, value); \
66 return value; \ 66 return value; \
@@ -85,7 +85,7 @@ clear_charpos_cache (struct buffer *b)
85 { \ 85 { \
86 if (best_above - best_below == best_above_byte - best_below_byte) \ 86 if (best_above - best_below == best_above_byte - best_below_byte) \
87 { \ 87 { \
88 EMACS_INT value = best_below_byte + (charpos - best_below); \ 88 ptrdiff_t value = best_below_byte + (charpos - best_below); \
89 if (byte_debug_flag) \ 89 if (byte_debug_flag) \
90 byte_char_debug_check (b, charpos, value); \ 90 byte_char_debug_check (b, charpos, value); \
91 return value; \ 91 return value; \
@@ -94,9 +94,9 @@ clear_charpos_cache (struct buffer *b)
94} 94}
95 95
96static void 96static void
97byte_char_debug_check (struct buffer *b, EMACS_INT charpos, EMACS_INT bytepos) 97byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
98{ 98{
99 EMACS_INT nchars = 0; 99 ptrdiff_t nchars = 0;
100 100
101 if (bytepos > BUF_GPT_BYTE (b)) 101 if (bytepos > BUF_GPT_BYTE (b))
102 { 102 {
@@ -113,18 +113,18 @@ byte_char_debug_check (struct buffer *b, EMACS_INT charpos, EMACS_INT bytepos)
113 abort (); 113 abort ();
114} 114}
115 115
116EMACS_INT 116ptrdiff_t
117charpos_to_bytepos (EMACS_INT charpos) 117charpos_to_bytepos (ptrdiff_t charpos)
118{ 118{
119 return buf_charpos_to_bytepos (current_buffer, charpos); 119 return buf_charpos_to_bytepos (current_buffer, charpos);
120} 120}
121 121
122EMACS_INT 122ptrdiff_t
123buf_charpos_to_bytepos (struct buffer *b, EMACS_INT charpos) 123buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
124{ 124{
125 struct Lisp_Marker *tail; 125 struct Lisp_Marker *tail;
126 EMACS_INT best_above, best_above_byte; 126 ptrdiff_t best_above, best_above_byte;
127 EMACS_INT best_below, best_below_byte; 127 ptrdiff_t best_below, best_below_byte;
128 128
129 if (charpos < BUF_BEG (b) || charpos > BUF_Z (b)) 129 if (charpos < BUF_BEG (b) || charpos > BUF_Z (b))
130 abort (); 130 abort ();
@@ -242,12 +242,12 @@ buf_charpos_to_bytepos (struct buffer *b, EMACS_INT charpos)
242/* Used for debugging: recompute the bytepos corresponding to CHARPOS 242/* Used for debugging: recompute the bytepos corresponding to CHARPOS
243 in the simplest, most reliable way. */ 243 in the simplest, most reliable way. */
244 244
245extern EMACS_INT verify_bytepos (EMACS_INT charpos) EXTERNALLY_VISIBLE; 245extern ptrdiff_t verify_bytepos (ptrdiff_t charpos) EXTERNALLY_VISIBLE;
246EMACS_INT 246ptrdiff_t
247verify_bytepos (EMACS_INT charpos) 247verify_bytepos (ptrdiff_t charpos)
248{ 248{
249 EMACS_INT below = 1; 249 ptrdiff_t below = 1;
250 EMACS_INT below_byte = 1; 250 ptrdiff_t below_byte = 1;
251 251
252 while (below != charpos) 252 while (below != charpos)
253 { 253 {
@@ -266,12 +266,12 @@ verify_bytepos (EMACS_INT charpos)
266 266
267#define CONSIDER(BYTEPOS, CHARPOS) \ 267#define CONSIDER(BYTEPOS, CHARPOS) \
268{ \ 268{ \
269 EMACS_INT this_bytepos = (BYTEPOS); \ 269 ptrdiff_t this_bytepos = (BYTEPOS); \
270 int changed = 0; \ 270 int changed = 0; \
271 \ 271 \
272 if (this_bytepos == bytepos) \ 272 if (this_bytepos == bytepos) \
273 { \ 273 { \
274 EMACS_INT value = (CHARPOS); \ 274 ptrdiff_t value = (CHARPOS); \
275 if (byte_debug_flag) \ 275 if (byte_debug_flag) \
276 byte_char_debug_check (b, value, bytepos); \ 276 byte_char_debug_check (b, value, bytepos); \
277 return value; \ 277 return value; \
@@ -296,7 +296,7 @@ verify_bytepos (EMACS_INT charpos)
296 { \ 296 { \
297 if (best_above - best_below == best_above_byte - best_below_byte) \ 297 if (best_above - best_below == best_above_byte - best_below_byte) \
298 { \ 298 { \
299 EMACS_INT value = best_below + (bytepos - best_below_byte); \ 299 ptrdiff_t value = best_below + (bytepos - best_below_byte); \
300 if (byte_debug_flag) \ 300 if (byte_debug_flag) \
301 byte_char_debug_check (b, value, bytepos); \ 301 byte_char_debug_check (b, value, bytepos); \
302 return value; \ 302 return value; \
@@ -304,12 +304,12 @@ verify_bytepos (EMACS_INT charpos)
304 } \ 304 } \
305} 305}
306 306
307EMACS_INT 307ptrdiff_t
308buf_bytepos_to_charpos (struct buffer *b, EMACS_INT bytepos) 308buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
309{ 309{
310 struct Lisp_Marker *tail; 310 struct Lisp_Marker *tail;
311 EMACS_INT best_above, best_above_byte; 311 ptrdiff_t best_above, best_above_byte;
312 EMACS_INT best_below, best_below_byte; 312 ptrdiff_t best_below, best_below_byte;
313 313
314 if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b)) 314 if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b))
315 abort (); 315 abort ();
@@ -461,7 +461,8 @@ Then it no longer slows down editing in any buffer.
461Returns MARKER. */) 461Returns MARKER. */)
462 (Lisp_Object marker, Lisp_Object position, Lisp_Object buffer) 462 (Lisp_Object marker, Lisp_Object position, Lisp_Object buffer)
463{ 463{
464 register EMACS_INT charno, bytepos; 464 register ptrdiff_t charno;
465 register ptrdiff_t bytepos;
465 register struct buffer *b; 466 register struct buffer *b;
466 register struct Lisp_Marker *m; 467 register struct Lisp_Marker *m;
467 468
@@ -502,14 +503,7 @@ Returns MARKER. */)
502 } 503 }
503 504
504 CHECK_NUMBER_COERCE_MARKER (position); 505 CHECK_NUMBER_COERCE_MARKER (position);
505 506 charno = clip_to_bounds (BUF_BEG (b), XINT (position), BUF_Z (b));
506 charno = XINT (position);
507
508 if (charno < BUF_BEG (b))
509 charno = BUF_BEG (b);
510 if (charno > BUF_Z (b))
511 charno = BUF_Z (b);
512
513 bytepos = buf_charpos_to_bytepos (b, charno); 507 bytepos = buf_charpos_to_bytepos (b, charno);
514 508
515 /* Every character is at least one byte. */ 509 /* Every character is at least one byte. */
@@ -536,7 +530,8 @@ Returns MARKER. */)
536Lisp_Object 530Lisp_Object
537set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer) 531set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
538{ 532{
539 register EMACS_INT charno, bytepos; 533 register ptrdiff_t charno;
534 register ptrdiff_t bytepos;
540 register struct buffer *b; 535 register struct buffer *b;
541 register struct Lisp_Marker *m; 536 register struct Lisp_Marker *m;
542 537
@@ -577,14 +572,7 @@ set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
577 } 572 }
578 573
579 CHECK_NUMBER_COERCE_MARKER (pos); 574 CHECK_NUMBER_COERCE_MARKER (pos);
580 575 charno = clip_to_bounds (BUF_BEGV (b), XINT (pos), BUF_ZV (b));
581 charno = XINT (pos);
582
583 if (charno < BUF_BEGV (b))
584 charno = BUF_BEGV (b);
585 if (charno > BUF_ZV (b))
586 charno = BUF_ZV (b);
587
588 bytepos = buf_charpos_to_bytepos (b, charno); 576 bytepos = buf_charpos_to_bytepos (b, charno);
589 577
590 /* Every character is at least one byte. */ 578 /* Every character is at least one byte. */
@@ -609,7 +597,7 @@ set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
609 character position and the corresponding byte position. */ 597 character position and the corresponding byte position. */
610 598
611Lisp_Object 599Lisp_Object
612set_marker_both (Lisp_Object marker, Lisp_Object buffer, EMACS_INT charpos, EMACS_INT bytepos) 600set_marker_both (Lisp_Object marker, Lisp_Object buffer, ptrdiff_t charpos, ptrdiff_t bytepos)
613{ 601{
614 register struct buffer *b; 602 register struct buffer *b;
615 register struct Lisp_Marker *m; 603 register struct Lisp_Marker *m;
@@ -657,7 +645,7 @@ set_marker_both (Lisp_Object marker, Lisp_Object buffer, EMACS_INT charpos, EMAC
657 be outside the visible part. */ 645 be outside the visible part. */
658 646
659Lisp_Object 647Lisp_Object
660set_marker_restricted_both (Lisp_Object marker, Lisp_Object buffer, EMACS_INT charpos, EMACS_INT bytepos) 648set_marker_restricted_both (Lisp_Object marker, Lisp_Object buffer, ptrdiff_t charpos, ptrdiff_t bytepos)
661{ 649{
662 register struct buffer *b; 650 register struct buffer *b;
663 register struct Lisp_Marker *m; 651 register struct Lisp_Marker *m;
@@ -767,7 +755,7 @@ unchain_marker (register struct Lisp_Marker *marker)
767 755
768/* Return the char position of marker MARKER, as a C integer. */ 756/* Return the char position of marker MARKER, as a C integer. */
769 757
770EMACS_INT 758ptrdiff_t
771marker_position (Lisp_Object marker) 759marker_position (Lisp_Object marker)
772{ 760{
773 register struct Lisp_Marker *m = XMARKER (marker); 761 register struct Lisp_Marker *m = XMARKER (marker);
@@ -781,12 +769,12 @@ marker_position (Lisp_Object marker)
781 769
782/* Return the byte position of marker MARKER, as a C integer. */ 770/* Return the byte position of marker MARKER, as a C integer. */
783 771
784EMACS_INT 772ptrdiff_t
785marker_byte_position (Lisp_Object marker) 773marker_byte_position (Lisp_Object marker)
786{ 774{
787 register struct Lisp_Marker *m = XMARKER (marker); 775 register struct Lisp_Marker *m = XMARKER (marker);
788 register struct buffer *buf = m->buffer; 776 register struct buffer *buf = m->buffer;
789 register EMACS_INT i = m->bytepos; 777 register ptrdiff_t i = m->bytepos;
790 778
791 if (!buf) 779 if (!buf)
792 error ("Marker does not point anywhere"); 780 error ("Marker does not point anywhere");
@@ -847,14 +835,9 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
847 (Lisp_Object position) 835 (Lisp_Object position)
848{ 836{
849 register struct Lisp_Marker *tail; 837 register struct Lisp_Marker *tail;
850 register EMACS_INT charno; 838 register ptrdiff_t charno;
851
852 charno = XINT (position);
853 839
854 if (charno < BEG) 840 charno = clip_to_bounds (BEG, XINT (position), Z);
855 charno = BEG;
856 if (charno > Z)
857 charno = Z;
858 841
859 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) 842 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
860 if (tail->charpos == charno) 843 if (tail->charpos == charno)
diff --git a/src/menu.c b/src/menu.c
index df86208c7ef..9ccfffd768c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -175,15 +175,17 @@ save_menu_items (void)
175} 175}
176 176
177 177
178/* Make the menu_items vector twice as large. */ 178/* Ensure that there is room for ITEMS items in the menu_items vector. */
179 179
180static void 180static void
181grow_menu_items (void) 181ensure_menu_items (int items)
182{ 182{
183 if ((INT_MAX - MENU_ITEMS_PANE_LENGTH) / 2 < menu_items_allocated) 183 int incr = items - (menu_items_allocated - menu_items_used);
184 memory_full (SIZE_MAX); 184 if (0 < incr)
185 menu_items_allocated *= 2; 185 {
186 menu_items = larger_vector (menu_items, menu_items_allocated, Qnil); 186 menu_items = larger_vector (menu_items, incr, INT_MAX);
187 menu_items_allocated = ASIZE (menu_items);
188 }
187} 189}
188 190
189#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \ 191#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \
@@ -194,9 +196,7 @@ grow_menu_items (void)
194static void 196static void
195push_submenu_start (void) 197push_submenu_start (void)
196{ 198{
197 if (menu_items_used + 1 > menu_items_allocated) 199 ensure_menu_items (1);
198 grow_menu_items ();
199
200 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil; 200 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil;
201 menu_items_submenu_depth++; 201 menu_items_submenu_depth++;
202} 202}
@@ -206,9 +206,7 @@ push_submenu_start (void)
206static void 206static void
207push_submenu_end (void) 207push_submenu_end (void)
208{ 208{
209 if (menu_items_used + 1 > menu_items_allocated) 209 ensure_menu_items (1);
210 grow_menu_items ();
211
212 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda; 210 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda;
213 menu_items_submenu_depth--; 211 menu_items_submenu_depth--;
214} 212}
@@ -220,9 +218,7 @@ push_submenu_end (void)
220static void 218static void
221push_left_right_boundary (void) 219push_left_right_boundary (void)
222{ 220{
223 if (menu_items_used + 1 > menu_items_allocated) 221 ensure_menu_items (1);
224 grow_menu_items ();
225
226 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote; 222 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote;
227} 223}
228 224
@@ -232,9 +228,7 @@ push_left_right_boundary (void)
232static void 228static void
233push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec) 229push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec)
234{ 230{
235 if (menu_items_used + MENU_ITEMS_PANE_LENGTH > menu_items_allocated) 231 ensure_menu_items (MENU_ITEMS_PANE_LENGTH);
236 grow_menu_items ();
237
238 if (menu_items_submenu_depth == 0) 232 if (menu_items_submenu_depth == 0)
239 menu_items_n_panes++; 233 menu_items_n_panes++;
240 XVECTOR (menu_items)->contents[menu_items_used++] = Qt; 234 XVECTOR (menu_items)->contents[menu_items_used++] = Qt;
@@ -253,8 +247,7 @@ push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec)
253static void 247static void
254push_menu_item (Lisp_Object name, Lisp_Object enable, Lisp_Object key, Lisp_Object def, Lisp_Object equiv, Lisp_Object type, Lisp_Object selected, Lisp_Object help) 248push_menu_item (Lisp_Object name, Lisp_Object enable, Lisp_Object key, Lisp_Object def, Lisp_Object equiv, Lisp_Object type, Lisp_Object selected, Lisp_Object help)
255{ 249{
256 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated) 250 ensure_menu_items (MENU_ITEMS_ITEM_LENGTH);
257 grow_menu_items ();
258 251
259 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_NAME, name); 252 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_NAME, name);
260 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_ENABLE, enable); 253 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_ENABLE, enable);
@@ -458,9 +451,9 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
458 and generate menu panes for them in menu_items. */ 451 and generate menu panes for them in menu_items. */
459 452
460static void 453static void
461keymap_panes (Lisp_Object *keymaps, int nmaps) 454keymap_panes (Lisp_Object *keymaps, ptrdiff_t nmaps)
462{ 455{
463 int mapno; 456 ptrdiff_t mapno;
464 457
465 init_menu_items (); 458 init_menu_items ();
466 459
@@ -532,16 +525,17 @@ int
532parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps) 525parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps)
533{ 526{
534 Lisp_Object length; 527 Lisp_Object length;
535 int len; 528 EMACS_INT len;
536 Lisp_Object *mapvec; 529 Lisp_Object *mapvec;
537 int i; 530 ptrdiff_t i;
538 int top_level_items = 0; 531 int top_level_items = 0;
532 USE_SAFE_ALLOCA;
539 533
540 length = Flength (maps); 534 length = Flength (maps);
541 len = XINT (length); 535 len = XINT (length);
542 536
543 /* Convert the list MAPS into a vector MAPVEC. */ 537 /* Convert the list MAPS into a vector MAPVEC. */
544 mapvec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); 538 SAFE_ALLOCA_LISP (mapvec, len);
545 for (i = 0; i < len; i++) 539 for (i = 0; i < len; i++)
546 { 540 {
547 mapvec[i] = Fcar (maps); 541 mapvec[i] = Fcar (maps);
@@ -571,6 +565,7 @@ parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object m
571 } 565 }
572 } 566 }
573 567
568 SAFE_FREE ();
574 return top_level_items; 569 return top_level_items;
575} 570}
576 571
@@ -1006,7 +1001,7 @@ find_and_return_menu_selection (FRAME_PTR f, int keymaps, void *client_data)
1006 { 1001 {
1007 entry 1002 entry
1008 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE]; 1003 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
1009 if ((EMACS_INT)client_data == (EMACS_INT)(&XVECTOR (menu_items)->contents[i])) 1004 if (&XVECTOR (menu_items)->contents[i] == client_data)
1010 { 1005 {
1011 if (keymaps != 0) 1006 if (keymaps != 0)
1012 { 1007 {
@@ -1082,7 +1077,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1082 Lisp_Object x, y, window; 1077 Lisp_Object x, y, window;
1083 int keymaps = 0; 1078 int keymaps = 0;
1084 int for_click = 0; 1079 int for_click = 0;
1085 int specpdl_count = SPECPDL_INDEX (); 1080 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1086 struct gcpro gcpro1; 1081 struct gcpro gcpro1;
1087 1082
1088 if (NILP (position)) 1083 if (NILP (position))
@@ -1175,9 +1170,6 @@ no quit occurs and `x-popup-menu' returns nil. */)
1175 } 1170 }
1176 } 1171 }
1177 1172
1178 CHECK_NUMBER (x);
1179 CHECK_NUMBER (y);
1180
1181 /* Decode where to put the menu. */ 1173 /* Decode where to put the menu. */
1182 1174
1183 if (FRAMEP (window)) 1175 if (FRAMEP (window))
@@ -1200,6 +1192,14 @@ no quit occurs and `x-popup-menu' returns nil. */)
1200 but I don't want to make one now. */ 1192 but I don't want to make one now. */
1201 CHECK_WINDOW (window); 1193 CHECK_WINDOW (window);
1202 1194
1195 CHECK_RANGED_INTEGER ((xpos < INT_MIN - MOST_NEGATIVE_FIXNUM
1196 ? (EMACS_INT) INT_MIN - xpos
1197 : MOST_NEGATIVE_FIXNUM),
1198 x, INT_MAX - xpos);
1199 CHECK_RANGED_INTEGER ((ypos < INT_MIN - MOST_NEGATIVE_FIXNUM
1200 ? (EMACS_INT) INT_MIN - ypos
1201 : MOST_NEGATIVE_FIXNUM),
1202 y, INT_MAX - ypos);
1203 xpos += XINT (x); 1203 xpos += XINT (x);
1204 ypos += XINT (y); 1204 ypos += XINT (y);
1205 1205
@@ -1248,11 +1248,12 @@ no quit occurs and `x-popup-menu' returns nil. */)
1248 else if (CONSP (menu) && KEYMAPP (XCAR (menu))) 1248 else if (CONSP (menu) && KEYMAPP (XCAR (menu)))
1249 { 1249 {
1250 /* We were given a list of keymaps. */ 1250 /* We were given a list of keymaps. */
1251 int nmaps = XFASTINT (Flength (menu)); 1251 EMACS_INT nmaps = XFASTINT (Flength (menu));
1252 Lisp_Object *maps 1252 Lisp_Object *maps;
1253 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 1253 ptrdiff_t i;
1254 int i; 1254 USE_SAFE_ALLOCA;
1255 1255
1256 SAFE_ALLOCA_LISP (maps, nmaps);
1256 title = Qnil; 1257 title = Qnil;
1257 1258
1258 /* The first keymap that has a prompt string 1259 /* The first keymap that has a prompt string
@@ -1276,6 +1277,8 @@ no quit occurs and `x-popup-menu' returns nil. */)
1276 ASET (menu_items, MENU_ITEMS_PANE_NAME, title); 1277 ASET (menu_items, MENU_ITEMS_PANE_NAME, title);
1277 1278
1278 keymaps = 1; 1279 keymaps = 1;
1280
1281 SAFE_FREE ();
1279 } 1282 }
1280 else 1283 else
1281 { 1284 {
diff --git a/src/minibuf.c b/src/minibuf.c
index 05f9419ba34..e9bc36303f9 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -89,7 +89,7 @@ static Lisp_Object minibuf_prompt;
89/* Width of current mini-buffer prompt. Only set after display_line 89/* Width of current mini-buffer prompt. Only set after display_line
90 of the line that contains the prompt. */ 90 of the line that contains the prompt. */
91 91
92static EMACS_INT minibuf_prompt_width; 92static ptrdiff_t minibuf_prompt_width;
93 93
94 94
95/* Put minibuf on currently selected frame's minibuffer. 95/* Put minibuf on currently selected frame's minibuffer.
@@ -172,7 +172,7 @@ without invoking the usual minibuffer commands. */)
172static Lisp_Object read_minibuf_unwind (Lisp_Object); 172static Lisp_Object read_minibuf_unwind (Lisp_Object);
173static Lisp_Object run_exit_minibuf_hook (Lisp_Object); 173static Lisp_Object run_exit_minibuf_hook (Lisp_Object);
174static Lisp_Object read_minibuf (Lisp_Object, Lisp_Object, 174static Lisp_Object read_minibuf (Lisp_Object, Lisp_Object,
175 Lisp_Object, Lisp_Object, 175 Lisp_Object,
176 int, Lisp_Object, 176 int, Lisp_Object,
177 Lisp_Object, Lisp_Object, 177 Lisp_Object, Lisp_Object,
178 int, int); 178 int, int);
@@ -192,7 +192,7 @@ string_to_object (Lisp_Object val, Lisp_Object defalt)
192{ 192{
193 struct gcpro gcpro1, gcpro2; 193 struct gcpro gcpro1, gcpro2;
194 Lisp_Object expr_and_pos; 194 Lisp_Object expr_and_pos;
195 EMACS_INT pos; 195 ptrdiff_t pos;
196 196
197 GCPRO2 (val, defalt); 197 GCPRO2 (val, defalt);
198 198
@@ -210,7 +210,7 @@ string_to_object (Lisp_Object val, Lisp_Object defalt)
210 { 210 {
211 /* Ignore trailing whitespace; any other trailing junk 211 /* Ignore trailing whitespace; any other trailing junk
212 is an error. */ 212 is an error. */
213 EMACS_INT i; 213 ptrdiff_t i;
214 pos = string_char_to_byte (val, pos); 214 pos = string_char_to_byte (val, pos);
215 for (i = pos; i < SBYTES (val); i++) 215 for (i = pos; i < SBYTES (val); i++)
216 { 216 {
@@ -335,7 +335,7 @@ DEFUN ("minibuffer-contents", Fminibuffer_contents,
335If the current buffer is not a minibuffer, return its entire contents. */) 335If the current buffer is not a minibuffer, return its entire contents. */)
336 (void) 336 (void)
337{ 337{
338 EMACS_INT prompt_end = XINT (Fminibuffer_prompt_end ()); 338 ptrdiff_t prompt_end = XINT (Fminibuffer_prompt_end ());
339 return make_buffer_string (prompt_end, ZV, 1); 339 return make_buffer_string (prompt_end, ZV, 1);
340} 340}
341 341
@@ -345,7 +345,7 @@ DEFUN ("minibuffer-contents-no-properties", Fminibuffer_contents_no_properties,
345If the current buffer is not a minibuffer, return its entire contents. */) 345If the current buffer is not a minibuffer, return its entire contents. */)
346 (void) 346 (void)
347{ 347{
348 EMACS_INT prompt_end = XINT (Fminibuffer_prompt_end ()); 348 ptrdiff_t prompt_end = XINT (Fminibuffer_prompt_end ());
349 return make_buffer_string (prompt_end, ZV, 0); 349 return make_buffer_string (prompt_end, ZV, 0);
350} 350}
351 351
@@ -356,7 +356,7 @@ That is what completion commands operate on.
356If the current buffer is not a minibuffer, return its entire contents. */) 356If the current buffer is not a minibuffer, return its entire contents. */)
357 (void) 357 (void)
358{ 358{
359 EMACS_INT prompt_end = XINT (Fminibuffer_prompt_end ()); 359 ptrdiff_t prompt_end = XINT (Fminibuffer_prompt_end ());
360 if (PT < prompt_end) 360 if (PT < prompt_end)
361 error ("Cannot do completion in the prompt"); 361 error ("Cannot do completion in the prompt");
362 return make_buffer_string (prompt_end, PT, 1); 362 return make_buffer_string (prompt_end, PT, 1);
@@ -388,16 +388,16 @@ If the current buffer is not a minibuffer, return its entire contents. */)
388 388
389static Lisp_Object 389static Lisp_Object
390read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, 390read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
391 Lisp_Object backup_n, int expflag, 391 int expflag,
392 Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt, 392 Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt,
393 int allow_props, int inherit_input_method) 393 int allow_props, int inherit_input_method)
394{ 394{
395 Lisp_Object val; 395 Lisp_Object val;
396 int count = SPECPDL_INDEX (); 396 ptrdiff_t count = SPECPDL_INDEX ();
397 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; 397 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
398 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 398 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
399 Lisp_Object enable_multibyte; 399 Lisp_Object enable_multibyte;
400 int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0; 400 EMACS_INT pos = 0;
401 /* String to add to the history. */ 401 /* String to add to the history. */
402 Lisp_Object histstring; 402 Lisp_Object histstring;
403 403
@@ -423,7 +423,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
423 { 423 {
424 if (CONSP (initial)) 424 if (CONSP (initial))
425 { 425 {
426 backup_n = Fcdr (initial); 426 Lisp_Object backup_n = Fcdr (initial);
427 initial = Fcar (initial); 427 initial = Fcar (initial);
428 CHECK_STRING (initial); 428 CHECK_STRING (initial);
429 if (!NILP (backup_n)) 429 if (!NILP (backup_n))
@@ -628,7 +628,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
628 628
629 /* Erase the buffer. */ 629 /* Erase the buffer. */
630 { 630 {
631 int count1 = SPECPDL_INDEX (); 631 ptrdiff_t count1 = SPECPDL_INDEX ();
632 specbind (Qinhibit_read_only, Qt); 632 specbind (Qinhibit_read_only, Qt);
633 specbind (Qinhibit_modification_hooks, Qt); 633 specbind (Qinhibit_modification_hooks, Qt);
634 Ferase_buffer (); 634 Ferase_buffer ();
@@ -802,7 +802,7 @@ get_minibuffer (EMACS_INT depth)
802 } 802 }
803 else 803 else
804 { 804 {
805 int count = SPECPDL_INDEX (); 805 ptrdiff_t count = SPECPDL_INDEX ();
806 /* `reset_buffer' blindly sets the list of overlays to NULL, so we 806 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
807 have to empty the list, otherwise we end up with overlays that 807 have to empty the list, otherwise we end up with overlays that
808 think they belong to this buffer while the buffer doesn't know about 808 think they belong to this buffer while the buffer doesn't know about
@@ -870,7 +870,7 @@ read_minibuf_unwind (Lisp_Object data)
870 870
871 /* Erase the minibuffer we were using at this level. */ 871 /* Erase the minibuffer we were using at this level. */
872 { 872 {
873 int count = SPECPDL_INDEX (); 873 ptrdiff_t count = SPECPDL_INDEX ();
874 /* Prevent error in erase-buffer. */ 874 /* Prevent error in erase-buffer. */
875 specbind (Qinhibit_read_only, Qt); 875 specbind (Qinhibit_read_only, Qt);
876 specbind (Qinhibit_modification_hooks, Qt); 876 specbind (Qinhibit_modification_hooks, Qt);
@@ -978,7 +978,7 @@ and some related functions, which use zero-indexing for POSITION. */)
978 978
979 GCPRO1 (default_value); 979 GCPRO1 (default_value);
980 val = read_minibuf (keymap, initial_contents, prompt, 980 val = read_minibuf (keymap, initial_contents, prompt,
981 Qnil, !NILP (read), 981 !NILP (read),
982 histvar, histpos, default_value, 982 histvar, histpos, default_value,
983 minibuffer_allow_text_properties, 983 minibuffer_allow_text_properties,
984 !NILP (inherit_input_method)); 984 !NILP (inherit_input_method));
@@ -996,7 +996,7 @@ Such arguments are used as in `read-from-minibuffer'.) */)
996{ 996{
997 CHECK_STRING (prompt); 997 CHECK_STRING (prompt);
998 return read_minibuf (Vminibuffer_local_map, initial_contents, 998 return read_minibuf (Vminibuffer_local_map, initial_contents,
999 prompt, Qnil, 1, Qminibuffer_history, 999 prompt, 1, Qminibuffer_history,
1000 make_number (0), Qnil, 0, 0); 1000 make_number (0), Qnil, 0, 0);
1001} 1001}
1002 1002
@@ -1009,7 +1009,7 @@ Such arguments are used as in `read-from-minibuffer'.) */)
1009 (Lisp_Object prompt, Lisp_Object initial_contents) 1009 (Lisp_Object prompt, Lisp_Object initial_contents)
1010{ 1010{
1011 return Feval (read_minibuf (Vread_expression_map, initial_contents, 1011 return Feval (read_minibuf (Vread_expression_map, initial_contents,
1012 prompt, Qnil, 1, Qread_expression_history, 1012 prompt, 1, Qread_expression_history,
1013 make_number (0), Qnil, 0, 0), 1013 make_number (0), Qnil, 0, 0),
1014 Qnil); 1014 Qnil);
1015} 1015}
@@ -1055,7 +1055,7 @@ the current input method and the setting of`enable-multibyte-characters'. */)
1055 (Lisp_Object prompt, Lisp_Object initial, Lisp_Object inherit_input_method) 1055 (Lisp_Object prompt, Lisp_Object initial, Lisp_Object inherit_input_method)
1056{ 1056{
1057 CHECK_STRING (prompt); 1057 CHECK_STRING (prompt);
1058 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, 1058 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt,
1059 0, Qminibuffer_history, make_number (0), Qnil, 0, 1059 0, Qminibuffer_history, make_number (0), Qnil, 0,
1060 !NILP (inherit_input_method)); 1060 !NILP (inherit_input_method));
1061} 1061}
@@ -1136,7 +1136,7 @@ function, instead of the usual behavior. */)
1136 Lisp_Object args[4], result; 1136 Lisp_Object args[4], result;
1137 char *s; 1137 char *s;
1138 ptrdiff_t len; 1138 ptrdiff_t len;
1139 int count = SPECPDL_INDEX (); 1139 ptrdiff_t count = SPECPDL_INDEX ();
1140 1140
1141 if (BUFFERP (def)) 1141 if (BUFFERP (def))
1142 def = BVAR (XBUFFER (def), name); 1142 def = BVAR (XBUFFER (def), name);
@@ -1235,9 +1235,9 @@ is used to further constrain the set of candidates. */)
1235{ 1235{
1236 Lisp_Object bestmatch, tail, elt, eltstring; 1236 Lisp_Object bestmatch, tail, elt, eltstring;
1237 /* Size in bytes of BESTMATCH. */ 1237 /* Size in bytes of BESTMATCH. */
1238 int bestmatchsize = 0; 1238 ptrdiff_t bestmatchsize = 0;
1239 /* These are in bytes, too. */ 1239 /* These are in bytes, too. */
1240 int compare, matchsize; 1240 ptrdiff_t compare, matchsize;
1241 enum { function_table, list_table, obarray_table, hash_table} 1241 enum { function_table, list_table, obarray_table, hash_table}
1242 type = (HASH_TABLE_P (collection) ? hash_table 1242 type = (HASH_TABLE_P (collection) ? hash_table
1243 : VECTORP (collection) ? obarray_table 1243 : VECTORP (collection) ? obarray_table
@@ -1246,9 +1246,9 @@ is used to further constrain the set of candidates. */)
1246 && (!SYMBOLP (XCAR (collection)) 1246 && (!SYMBOLP (XCAR (collection))
1247 || NILP (XCAR (collection))))) 1247 || NILP (XCAR (collection)))))
1248 ? list_table : function_table)); 1248 ? list_table : function_table));
1249 EMACS_INT idx = 0, obsize = 0; 1249 ptrdiff_t idx = 0, obsize = 0;
1250 int matchcount = 0; 1250 int matchcount = 0;
1251 int bindcount = -1; 1251 ptrdiff_t bindcount = -1;
1252 Lisp_Object bucket, zero, end, tem; 1252 Lisp_Object bucket, zero, end, tem;
1253 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1253 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1254 1254
@@ -1511,8 +1511,8 @@ with a space are ignored unless STRING itself starts with a space. */)
1511 : NILP (collection) || (CONSP (collection) 1511 : NILP (collection) || (CONSP (collection)
1512 && (!SYMBOLP (XCAR (collection)) 1512 && (!SYMBOLP (XCAR (collection))
1513 || NILP (XCAR (collection)))); 1513 || NILP (XCAR (collection))));
1514 EMACS_INT idx = 0, obsize = 0; 1514 ptrdiff_t idx = 0, obsize = 0;
1515 int bindcount = -1; 1515 ptrdiff_t bindcount = -1;
1516 Lisp_Object bucket, tem, zero; 1516 Lisp_Object bucket, tem, zero;
1517 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1517 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1518 1518
@@ -1821,7 +1821,7 @@ the values STRING, PREDICATE and `lambda'. */)
1821 /* Reject this element if it fails to match all the regexps. */ 1821 /* Reject this element if it fails to match all the regexps. */
1822 if (CONSP (Vcompletion_regexp_list)) 1822 if (CONSP (Vcompletion_regexp_list))
1823 { 1823 {
1824 int count = SPECPDL_INDEX (); 1824 ptrdiff_t count = SPECPDL_INDEX ();
1825 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil); 1825 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1826 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1826 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1827 regexps = XCDR (regexps)) 1827 regexps = XCDR (regexps))
diff --git a/src/msdos.c b/src/msdos.c
index 5f46829aefd..c6213b566b8 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -1813,7 +1813,7 @@ internal_terminal_init (void)
1813 } 1813 }
1814 1814
1815 Vinitial_window_system = Qpc; 1815 Vinitial_window_system = Qpc;
1816 Vwindow_system_version = make_number (23); /* RE Emacs version */ 1816 Vwindow_system_version = make_number (24); /* RE Emacs version */
1817 tty->terminal->type = output_msdos_raw; 1817 tty->terminal->type = output_msdos_raw;
1818 1818
1819 /* If Emacs was dumped on DOS/V machine, forget the stale VRAM 1819 /* If Emacs was dumped on DOS/V machine, forget the stale VRAM
diff --git a/src/nsfns.m b/src/nsfns.m
index 206c4155d01..5cea73c39ca 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -169,7 +169,7 @@ check_ns_display_info (Lisp_Object frame)
169 struct terminal *t = get_terminal (frame, 1); 169 struct terminal *t = get_terminal (frame, 1);
170 170
171 if (t->type != output_ns) 171 if (t->type != output_ns)
172 error ("Terminal %ld is not a Nextstep display", (long) XINT (frame)); 172 error ("Terminal %"pI"d is not a Nextstep display", XINT (frame));
173 173
174 return t->display_info.ns; 174 return t->display_info.ns;
175 } 175 }
@@ -709,7 +709,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
709 if (FRAME_MINIBUF_ONLY_P (f)) 709 if (FRAME_MINIBUF_ONLY_P (f))
710 return; 710 return;
711 711
712 if (INTEGERP (value)) 712 if (TYPE_RANGED_INTEGERP (int, value))
713 nlines = XINT (value); 713 nlines = XINT (value);
714 else 714 else
715 nlines = 0; 715 nlines = 0;
@@ -741,7 +741,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
741 if (FRAME_MINIBUF_ONLY_P (f)) 741 if (FRAME_MINIBUF_ONLY_P (f))
742 return; 742 return;
743 743
744 if (INTEGERP (value) && XINT (value) >= 0) 744 if (RANGED_INTEGERP (0, value, INT_MAX))
745 nlines = XFASTINT (value); 745 nlines = XFASTINT (value);
746 else 746 else
747 nlines = 0; 747 nlines = 0;
@@ -1136,7 +1136,7 @@ This function is an internal primitive--use `make-frame' instead. */)
1136 int minibuffer_only = 0; 1136 int minibuffer_only = 0;
1137 int window_prompting = 0; 1137 int window_prompting = 0;
1138 int width, height; 1138 int width, height;
1139 int count = specpdl_ptr - specpdl; 1139 ptrdiff_t count = specpdl_ptr - specpdl;
1140 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1140 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1141 Lisp_Object display; 1141 Lisp_Object display;
1142 struct ns_display_info *dpyinfo = NULL; 1142 struct ns_display_info *dpyinfo = NULL;
@@ -1219,9 +1219,9 @@ This function is an internal primitive--use `make-frame' instead. */)
1219 record_unwind_protect (unwind_create_frame, frame); 1219 record_unwind_protect (unwind_create_frame, frame);
1220 1220
1221 f->output_data.ns->window_desc = desc_ctr++; 1221 f->output_data.ns->window_desc = desc_ctr++;
1222 if (!NILP (parent)) 1222 if (TYPE_RANGED_INTEGERP (Window, parent))
1223 { 1223 {
1224 f->output_data.ns->parent_desc = (Window) XFASTINT (parent); 1224 f->output_data.ns->parent_desc = XFASTINT (parent);
1225 f->output_data.ns->explicit_parent = 1; 1225 f->output_data.ns->explicit_parent = 1;
1226 } 1226 }
1227 else 1227 else
@@ -2548,7 +2548,7 @@ Text larger than the specified size is clipped. */)
2548{ 2548{
2549 int root_x, root_y; 2549 int root_x, root_y;
2550 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 2550 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2551 int count = SPECPDL_INDEX (); 2551 ptrdiff_t count = SPECPDL_INDEX ();
2552 struct frame *f; 2552 struct frame *f;
2553 char *str; 2553 char *str;
2554 NSSize size; 2554 NSSize size;
diff --git a/src/nsfont.m b/src/nsfont.m
index 9aa7b0865ab..556102b6f44 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -557,8 +557,8 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch)
557 return ns_fallback_entity (); 557 return ns_fallback_entity ();
558 558
559 if (NSFONT_TRACE) 559 if (NSFONT_TRACE)
560 fprintf (stderr, " Returning %ld entities.\n", 560 fprintf (stderr, " Returning %"pI"d entities.\n",
561 (long) XINT (Flength (list))); 561 XINT (Flength (list)));
562 562
563 return list; 563 return list;
564} 564}
@@ -664,8 +664,8 @@ nsfont_list_family (Lisp_Object frame)
664 /* FIXME: escape the name? */ 664 /* FIXME: escape the name? */
665 665
666 if (NSFONT_TRACE) 666 if (NSFONT_TRACE)
667 fprintf (stderr, "nsfont: list families returning %ld entries\n", 667 fprintf (stderr, "nsfont: list families returning %"pI"d entries\n",
668 (long) XINT (Flength (list))); 668 XINT (Flength (list)));
669 669
670 return list; 670 return list;
671} 671}
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 7a6434941d2..4bfe0cc003a 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -186,7 +186,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
186 int *submenu_top_level_items, *submenu_n_panes; 186 int *submenu_top_level_items, *submenu_n_panes;
187 struct buffer *prev = current_buffer; 187 struct buffer *prev = current_buffer;
188 Lisp_Object buffer; 188 Lisp_Object buffer;
189 int specpdl_count = SPECPDL_INDEX (); 189 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
190 int previous_menu_items_used = f->menu_bar_items_used; 190 int previous_menu_items_used = f->menu_bar_items_used;
191 Lisp_Object *previous_items 191 Lisp_Object *previous_items
192 = (Lisp_Object *) alloca (previous_menu_items_used 192 = (Lisp_Object *) alloca (previous_menu_items_used
@@ -455,7 +455,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
455 wv->enabled = 1; 455 wv->enabled = 1;
456 wv->button_type = BUTTON_TYPE_NONE; 456 wv->button_type = BUTTON_TYPE_NONE;
457 wv->help = Qnil; 457 wv->help = Qnil;
458 wv->call_data = (void *) (EMACS_INT) (-1); 458 wv->call_data = (void *) (intptr_t) (-1);
459 459
460#ifdef NS_IMPL_COCOA 460#ifdef NS_IMPL_COCOA
461 /* we'll update the real copy under app menu when time comes */ 461 /* we'll update the real copy under app menu when time comes */
@@ -792,7 +792,7 @@ ns_menu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
792 EmacsMenu *pmenu; 792 EmacsMenu *pmenu;
793 NSPoint p; 793 NSPoint p;
794 Lisp_Object window, tem, keymap; 794 Lisp_Object window, tem, keymap;
795 int specpdl_count = SPECPDL_INDEX (); 795 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
796 widget_value *wv, *first_wv = 0; 796 widget_value *wv, *first_wv = 0;
797 797
798 p.x = x; p.y = y; 798 p.x = x; p.y = y;
@@ -1429,7 +1429,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1429 dialog = [[EmacsDialogPanel alloc] initFromContents: contents 1429 dialog = [[EmacsDialogPanel alloc] initFromContents: contents
1430 isQuestion: isQ]; 1430 isQuestion: isQ];
1431 { 1431 {
1432 int specpdl_count = SPECPDL_INDEX (); 1432 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1433 record_unwind_protect (pop_down_menu, make_save_value (dialog, 0)); 1433 record_unwind_protect (pop_down_menu, make_save_value (dialog, 0));
1434 popup_activated_flag = 1; 1434 popup_activated_flag = 1;
1435 tem = [dialog runDialogAt: p]; 1435 tem = [dialog runDialogAt: p];
diff --git a/src/nsselect.m b/src/nsselect.m
index 4d901fac2ec..6352d882b7a 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -112,8 +112,8 @@ clean_local_selection_data (Lisp_Object obj)
112 112
113 if (VECTORP (obj)) 113 if (VECTORP (obj))
114 { 114 {
115 int i; 115 ptrdiff_t i;
116 int size = ASIZE (obj); 116 ptrdiff_t size = ASIZE (obj);
117 Lisp_Object copy; 117 Lisp_Object copy;
118 118
119 if (size == 1) 119 if (size == 1)
@@ -184,7 +184,7 @@ ns_get_local_selection (Lisp_Object selection_name,
184{ 184{
185 Lisp_Object local_value; 185 Lisp_Object local_value;
186 Lisp_Object handler_fn, value, type, check; 186 Lisp_Object handler_fn, value, type, check;
187 int count; 187 ptrdiff_t count;
188 188
189 local_value = assq_no_quit (selection_name, Vselection_alist); 189 local_value = assq_no_quit (selection_name, Vselection_alist);
190 190
@@ -297,7 +297,7 @@ ns_string_from_pasteboard (id pb)
297 length = [mstr lengthOfBytesUsingEncoding: NSUTF8StringEncoding]; 297 length = [mstr lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
298 298
299#if ! defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4 299#if ! defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
300 if (!utfStr) 300 if (!utfStr)
301 { 301 {
302 utfStr = [mstr cString]; 302 utfStr = [mstr cString];
303 length = strlen (utfStr); 303 length = strlen (utfStr);
@@ -603,4 +603,3 @@ The functions are called with one argument, the selection type\n\
603 Qforeign_selection = intern_c_string ("foreign-selection"); 603 Qforeign_selection = intern_c_string ("foreign-selection");
604 staticpro (&Qforeign_selection); 604 staticpro (&Qforeign_selection);
605} 605}
606
diff --git a/src/nsterm.m b/src/nsterm.m
index 4b8b2bb4820..8bd2bb283b2 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -379,16 +379,6 @@ ns_init_paths (void)
379 setenv ("EMACSDOC", [resourcePath UTF8String], 1); 379 setenv ("EMACSDOC", [resourcePath UTF8String], 1);
380 } 380 }
381 } 381 }
382
383 if (!getenv ("INFOPATH"))
384 {
385 resourcePath = [resourceDir stringByAppendingPathComponent: @"info"];
386 if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir])
387 if (isDir)
388 setenv ("INFOPATH", [[resourcePath stringByAppendingString: @":"]
389 UTF8String], 1);
390 /* Note, extra colon needed to cause merge w/later user additions. */
391 }
392} 382}
393 383
394 384
diff --git a/src/print.c b/src/print.c
index 5b1ea748799..4284a19d4df 100644
--- a/src/print.c
+++ b/src/print.c
@@ -57,10 +57,10 @@ static Lisp_Object Qfloat_output_format;
57#endif 57#endif
58 58
59/* Avoid actual stack overflow in print. */ 59/* Avoid actual stack overflow in print. */
60static int print_depth; 60static ptrdiff_t print_depth;
61 61
62/* Level of nesting inside outputting backquote in new style. */ 62/* Level of nesting inside outputting backquote in new style. */
63static int new_backquote_output; 63static ptrdiff_t new_backquote_output;
64 64
65/* Detect most circularities to print finite output. */ 65/* Detect most circularities to print finite output. */
66#define PRINT_CIRCLE 200 66#define PRINT_CIRCLE 200
@@ -71,11 +71,11 @@ static Lisp_Object being_printed[PRINT_CIRCLE];
71static char *print_buffer; 71static char *print_buffer;
72 72
73/* Size allocated in print_buffer. */ 73/* Size allocated in print_buffer. */
74static EMACS_INT print_buffer_size; 74static ptrdiff_t print_buffer_size;
75/* Chars stored in print_buffer. */ 75/* Chars stored in print_buffer. */
76static EMACS_INT print_buffer_pos; 76static ptrdiff_t print_buffer_pos;
77/* Bytes stored in print_buffer. */ 77/* Bytes stored in print_buffer. */
78static EMACS_INT print_buffer_pos_byte; 78static ptrdiff_t print_buffer_pos_byte;
79 79
80Lisp_Object Qprint_escape_newlines; 80Lisp_Object Qprint_escape_newlines;
81static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii; 81static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
@@ -88,7 +88,7 @@ static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
88 N the object has been printed so we can refer to it as #N#. 88 N the object has been printed so we can refer to it as #N#.
89 print_number_index holds the largest N already used. 89 print_number_index holds the largest N already used.
90 N has to be striclty larger than 0 since we need to distinguish -N. */ 90 N has to be striclty larger than 0 since we need to distinguish -N. */
91static int print_number_index; 91static ptrdiff_t print_number_index;
92static void print_interval (INTERVAL interval, Lisp_Object printcharfun); 92static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
93 93
94/* GDB resets this to zero on W32 to disable OutputDebugString calls. */ 94/* GDB resets this to zero on W32 to disable OutputDebugString calls. */
@@ -106,9 +106,9 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
106 106
107#define PRINTDECLARE \ 107#define PRINTDECLARE \
108 struct buffer *old = current_buffer; \ 108 struct buffer *old = current_buffer; \
109 EMACS_INT old_point = -1, start_point = -1; \ 109 ptrdiff_t old_point = -1, start_point = -1; \
110 EMACS_INT old_point_byte = -1, start_point_byte = -1; \ 110 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
111 int specpdl_count = SPECPDL_INDEX (); \ 111 ptrdiff_t specpdl_count = SPECPDL_INDEX (); \
112 int free_print_buffer = 0; \ 112 int free_print_buffer = 0; \
113 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \ 113 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
114 Lisp_Object original 114 Lisp_Object original
@@ -124,7 +124,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
124 } \ 124 } \
125 if (MARKERP (printcharfun)) \ 125 if (MARKERP (printcharfun)) \
126 { \ 126 { \
127 EMACS_INT marker_pos; \ 127 ptrdiff_t marker_pos; \
128 if (! XMARKER (printcharfun)->buffer) \ 128 if (! XMARKER (printcharfun)->buffer) \
129 error ("Marker does not point anywhere"); \ 129 error ("Marker does not point anywhere"); \
130 if (XMARKER (printcharfun)->buffer != current_buffer) \ 130 if (XMARKER (printcharfun)->buffer != current_buffer) \
@@ -158,7 +158,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
158 } \ 158 } \
159 else \ 159 else \
160 { \ 160 { \
161 ptrdiff_t new_size = 1000; \ 161 int new_size = 1000; \
162 print_buffer = (char *) xmalloc (new_size); \ 162 print_buffer = (char *) xmalloc (new_size); \
163 print_buffer_size = new_size; \ 163 print_buffer_size = new_size; \
164 free_print_buffer = 1; \ 164 free_print_buffer = 1; \
@@ -235,15 +235,10 @@ printchar (unsigned int ch, Lisp_Object fun)
235 235
236 if (NILP (fun)) 236 if (NILP (fun))
237 { 237 {
238 if (print_buffer_size - len <= print_buffer_pos_byte) 238 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
239 { 239 if (0 < incr)
240 ptrdiff_t new_size; 240 print_buffer =
241 if (STRING_BYTES_BOUND / 2 < print_buffer_size) 241 xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
242 string_overflow ();
243 new_size = print_buffer_size * 2;
244 print_buffer = (char *) xrealloc (print_buffer, new_size);
245 print_buffer_size = new_size;
246 }
247 memcpy (print_buffer + print_buffer_pos_byte, str, len); 242 memcpy (print_buffer + print_buffer_pos_byte, str, len);
248 print_buffer_pos += 1; 243 print_buffer_pos += 1;
249 print_buffer_pos_byte += len; 244 print_buffer_pos_byte += len;
@@ -278,7 +273,7 @@ printchar (unsigned int ch, Lisp_Object fun)
278 to data in a Lisp string. Otherwise that is not safe. */ 273 to data in a Lisp string. Otherwise that is not safe. */
279 274
280static void 275static void
281strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte, 276strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
282 Lisp_Object printcharfun) 277 Lisp_Object printcharfun)
283{ 278{
284 if (size < 0) 279 if (size < 0)
@@ -286,15 +281,9 @@ strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
286 281
287 if (NILP (printcharfun)) 282 if (NILP (printcharfun))
288 { 283 {
289 if (print_buffer_size - size_byte < print_buffer_pos_byte) 284 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
290 { 285 if (0 < incr)
291 ptrdiff_t new_size; 286 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
292 if (STRING_BYTES_BOUND / 2 - size_byte < print_buffer_size)
293 string_overflow ();
294 new_size = print_buffer_size * 2 + size_byte;
295 print_buffer = (char *) xrealloc (print_buffer, new_size);
296 print_buffer_size = new_size;
297 }
298 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte); 287 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
299 print_buffer_pos += size; 288 print_buffer_pos += size;
300 print_buffer_pos_byte += size_byte; 289 print_buffer_pos_byte += size_byte;
@@ -335,7 +324,7 @@ strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
335 else 324 else
336 { 325 {
337 /* PRINTCHARFUN is a Lisp function. */ 326 /* PRINTCHARFUN is a Lisp function. */
338 EMACS_INT i = 0; 327 ptrdiff_t i = 0;
339 328
340 if (size == size_byte) 329 if (size == size_byte)
341 { 330 {
@@ -371,7 +360,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
371{ 360{
372 if (EQ (printcharfun, Qt) || NILP (printcharfun)) 361 if (EQ (printcharfun, Qt) || NILP (printcharfun))
373 { 362 {
374 EMACS_INT chars; 363 ptrdiff_t chars;
375 364
376 if (print_escape_nonascii) 365 if (print_escape_nonascii)
377 string = string_escape_byte8 (string); 366 string = string_escape_byte8 (string);
@@ -387,7 +376,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
387 convert STRING to a multibyte string containing the same 376 convert STRING to a multibyte string containing the same
388 character codes. */ 377 character codes. */
389 Lisp_Object newstr; 378 Lisp_Object newstr;
390 EMACS_INT bytes; 379 ptrdiff_t bytes;
391 380
392 chars = SBYTES (string); 381 chars = SBYTES (string);
393 bytes = count_size_as_multibyte (SDATA (string), chars); 382 bytes = count_size_as_multibyte (SDATA (string), chars);
@@ -405,7 +394,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
405 if (EQ (printcharfun, Qt)) 394 if (EQ (printcharfun, Qt))
406 { 395 {
407 /* Output to echo area. */ 396 /* Output to echo area. */
408 EMACS_INT nbytes = SBYTES (string); 397 ptrdiff_t nbytes = SBYTES (string);
409 char *buffer; 398 char *buffer;
410 399
411 /* Copy the string contents so that relocation of STRING by 400 /* Copy the string contents so that relocation of STRING by
@@ -427,9 +416,9 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
427 { 416 {
428 /* Otherwise, string may be relocated by printing one char. 417 /* Otherwise, string may be relocated by printing one char.
429 So re-fetch the string address for each character. */ 418 So re-fetch the string address for each character. */
430 EMACS_INT i; 419 ptrdiff_t i;
431 EMACS_INT size = SCHARS (string); 420 ptrdiff_t size = SCHARS (string);
432 EMACS_INT size_byte = SBYTES (string); 421 ptrdiff_t size_byte = SBYTES (string);
433 struct gcpro gcpro1; 422 struct gcpro gcpro1;
434 GCPRO1 (string); 423 GCPRO1 (string);
435 if (size == size_byte) 424 if (size == size_byte)
@@ -500,7 +489,7 @@ write_string_1 (const char *data, int size, Lisp_Object printcharfun)
500void 489void
501temp_output_buffer_setup (const char *bufname) 490temp_output_buffer_setup (const char *bufname)
502{ 491{
503 int count = SPECPDL_INDEX (); 492 ptrdiff_t count = SPECPDL_INDEX ();
504 register struct buffer *old = current_buffer; 493 register struct buffer *old = current_buffer;
505 register Lisp_Object buf; 494 register Lisp_Object buf;
506 495
@@ -604,7 +593,7 @@ A printed representation of an object is text which describes that object. */)
604 Lisp_Object printcharfun; 593 Lisp_Object printcharfun;
605 /* struct gcpro gcpro1, gcpro2; */ 594 /* struct gcpro gcpro1, gcpro2; */
606 Lisp_Object save_deactivate_mark; 595 Lisp_Object save_deactivate_mark;
607 int count = SPECPDL_INDEX (); 596 ptrdiff_t count = SPECPDL_INDEX ();
608 struct buffer *previous; 597 struct buffer *previous;
609 598
610 specbind (Qinhibit_modification_hooks, Qt); 599 specbind (Qinhibit_modification_hooks, Qt);
@@ -730,7 +719,7 @@ to make it write to the debugging output. */)
730 (Lisp_Object character) 719 (Lisp_Object character)
731{ 720{
732 CHECK_NUMBER (character); 721 CHECK_NUMBER (character);
733 putc ((int) XINT (character), stderr); 722 putc (XINT (character) & 0xFF, stderr);
734 723
735#ifdef WINDOWSNT 724#ifdef WINDOWSNT
736 /* Send the output to a debugger (nothing happens if there isn't one). */ 725 /* Send the output to a debugger (nothing happens if there isn't one). */
@@ -876,10 +865,13 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
876 if (!NILP (caller) && SYMBOLP (caller)) 865 if (!NILP (caller) && SYMBOLP (caller))
877 { 866 {
878 Lisp_Object cname = SYMBOL_NAME (caller); 867 Lisp_Object cname = SYMBOL_NAME (caller);
879 char *name = alloca (SBYTES (cname)); 868 char *name;
869 USE_SAFE_ALLOCA;
870 SAFE_ALLOCA (name, char *, SBYTES (cname));
880 memcpy (name, SDATA (cname), SBYTES (cname)); 871 memcpy (name, SDATA (cname), SBYTES (cname));
881 message_dolog (name, SBYTES (cname), 0, 0); 872 message_dolog (name, SBYTES (cname), 0, 0);
882 message_dolog (": ", 2, 0, 0); 873 message_dolog (": ", 2, 0, 0);
874 SAFE_FREE ();
883 } 875 }
884 876
885 errname = Fcar (data); 877 errname = Fcar (data);
@@ -1096,11 +1088,9 @@ print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1096 1088
1097 if (HASH_TABLE_P (Vprint_number_table)) 1089 if (HASH_TABLE_P (Vprint_number_table))
1098 { /* Remove unnecessary objects, which appear only once in OBJ; 1090 { /* Remove unnecessary objects, which appear only once in OBJ;
1099 that is, whose status is Qt. 1091 that is, whose status is Qt. */
1100 Maybe a better way to do that is to copy elements to
1101 a new hash table. */
1102 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table); 1092 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
1103 EMACS_INT i; 1093 ptrdiff_t i;
1104 1094
1105 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) 1095 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1106 if (!NILP (HASH_HASH (h, i)) 1096 if (!NILP (HASH_HASH (h, i))
@@ -1134,7 +1124,7 @@ static void
1134print_preprocess (Lisp_Object obj) 1124print_preprocess (Lisp_Object obj)
1135{ 1125{
1136 int i; 1126 int i;
1137 EMACS_INT size; 1127 ptrdiff_t size;
1138 int loop_count = 0; 1128 int loop_count = 0;
1139 Lisp_Object halftail; 1129 Lisp_Object halftail;
1140 1130
@@ -1277,8 +1267,8 @@ print_check_string_charset_prop (INTERVAL interval, Lisp_Object string)
1277 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) 1267 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1278 { 1268 {
1279 int i, c; 1269 int i, c;
1280 EMACS_INT charpos = interval->position; 1270 ptrdiff_t charpos = interval->position;
1281 EMACS_INT bytepos = string_char_to_byte (string, charpos); 1271 ptrdiff_t bytepos = string_char_to_byte (string, charpos);
1282 Lisp_Object charset; 1272 Lisp_Object charset;
1283 1273
1284 charset = XCAR (XCDR (val)); 1274 charset = XCAR (XCDR (val));
@@ -1398,10 +1388,10 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1398 print_string (obj, printcharfun); 1388 print_string (obj, printcharfun);
1399 else 1389 else
1400 { 1390 {
1401 register EMACS_INT i_byte; 1391 register ptrdiff_t i_byte;
1402 struct gcpro gcpro1; 1392 struct gcpro gcpro1;
1403 unsigned char *str; 1393 unsigned char *str;
1404 EMACS_INT size_byte; 1394 ptrdiff_t size_byte;
1405 /* 1 means we must ensure that the next character we output 1395 /* 1 means we must ensure that the next character we output
1406 cannot be taken as part of a hex character escape. */ 1396 cannot be taken as part of a hex character escape. */
1407 int need_nonhex = 0; 1397 int need_nonhex = 0;
@@ -1519,8 +1509,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1519 register unsigned char *p = SDATA (SYMBOL_NAME (obj)); 1509 register unsigned char *p = SDATA (SYMBOL_NAME (obj));
1520 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj)); 1510 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
1521 register int c; 1511 register int c;
1522 int i, i_byte; 1512 ptrdiff_t i, i_byte;
1523 EMACS_INT size_byte; 1513 ptrdiff_t size_byte;
1524 Lisp_Object name; 1514 Lisp_Object name;
1525 1515
1526 name = SYMBOL_NAME (obj); 1516 name = SYMBOL_NAME (obj);
@@ -1711,7 +1701,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1711 ptrdiff_t i; 1701 ptrdiff_t i;
1712 register unsigned char c; 1702 register unsigned char c;
1713 struct gcpro gcpro1; 1703 struct gcpro gcpro1;
1714 EMACS_INT size_in_chars 1704 ptrdiff_t size_in_chars
1715 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) 1705 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
1716 / BOOL_VECTOR_BITS_PER_CHAR); 1706 / BOOL_VECTOR_BITS_PER_CHAR);
1717 1707
@@ -1804,8 +1794,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1804 else if (HASH_TABLE_P (obj)) 1794 else if (HASH_TABLE_P (obj))
1805 { 1795 {
1806 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); 1796 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1807 int i; 1797 ptrdiff_t i;
1808 EMACS_INT real_size, size; 1798 ptrdiff_t real_size, size;
1809#if 0 1799#if 0
1810 strout ("#<hash-table", -1, -1, printcharfun); 1800 strout ("#<hash-table", -1, -1, printcharfun);
1811 if (SYMBOLP (h->test)) 1801 if (SYMBOLP (h->test))
@@ -1816,7 +1806,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1816 PRINTCHAR (' '); 1806 PRINTCHAR (' ');
1817 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun); 1807 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1818 PRINTCHAR (' '); 1808 PRINTCHAR (' ');
1819 sprintf (buf, "%"pI"d/%"pI"d", h->count, ASIZE (h->next)); 1809 sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
1820 strout (buf, -1, -1, printcharfun); 1810 strout (buf, -1, -1, printcharfun);
1821 } 1811 }
1822 sprintf (buf, " %p", h); 1812 sprintf (buf, " %p", h);
@@ -1826,7 +1816,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1826 /* Implement a readable output, e.g.: 1816 /* Implement a readable output, e.g.:
1827 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ 1817 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1828 /* Always print the size. */ 1818 /* Always print the size. */
1829 sprintf (buf, "#s(hash-table size %"pI"d", ASIZE (h->next)); 1819 sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next));
1830 strout (buf, -1, -1, printcharfun); 1820 strout (buf, -1, -1, printcharfun);
1831 1821
1832 if (!NILP (h->test)) 1822 if (!NILP (h->test))
@@ -1910,7 +1900,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1910 } 1900 }
1911 else if (FONTP (obj)) 1901 else if (FONTP (obj))
1912 { 1902 {
1913 EMACS_INT i; 1903 int i;
1914 1904
1915 if (! FONT_OBJECT_P (obj)) 1905 if (! FONT_OBJECT_P (obj))
1916 { 1906 {
@@ -1938,7 +1928,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1938 } 1928 }
1939 else 1929 else
1940 { 1930 {
1941 EMACS_INT size = ASIZE (obj); 1931 ptrdiff_t size = ASIZE (obj);
1942 if (COMPILEDP (obj)) 1932 if (COMPILEDP (obj))
1943 { 1933 {
1944 PRINTCHAR ('#'); 1934 PRINTCHAR ('#');
@@ -1969,7 +1959,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1969 { 1959 {
1970 register int i; 1960 register int i;
1971 register Lisp_Object tem; 1961 register Lisp_Object tem;
1972 EMACS_INT real_size = size; 1962 ptrdiff_t real_size = size;
1973 1963
1974 /* Don't print more elements than the specified maximum. */ 1964 /* Don't print more elements than the specified maximum. */
1975 if (NATNUMP (Vprint_length) 1965 if (NATNUMP (Vprint_length)
@@ -2001,7 +1991,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2001 strout ("in no buffer", -1, -1, printcharfun); 1991 strout ("in no buffer", -1, -1, printcharfun);
2002 else 1992 else
2003 { 1993 {
2004 sprintf (buf, "at %"pI"d", marker_position (obj)); 1994 sprintf (buf, "at %"pD"d", marker_position (obj));
2005 strout (buf, -1, -1, printcharfun); 1995 strout (buf, -1, -1, printcharfun);
2006 strout (" in ", -1, -1, printcharfun); 1996 strout (" in ", -1, -1, printcharfun);
2007 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun); 1997 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
@@ -2015,7 +2005,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2015 strout ("in no buffer", -1, -1, printcharfun); 2005 strout ("in no buffer", -1, -1, printcharfun);
2016 else 2006 else
2017 { 2007 {
2018 sprintf (buf, "from %"pI"d to %"pI"d in ", 2008 sprintf (buf, "from %"pD"d to %"pD"d in ",
2019 marker_position (OVERLAY_START (obj)), 2009 marker_position (OVERLAY_START (obj)),
2020 marker_position (OVERLAY_END (obj))); 2010 marker_position (OVERLAY_END (obj)));
2021 strout (buf, -1, -1, printcharfun); 2011 strout (buf, -1, -1, printcharfun);
@@ -2054,7 +2044,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2054 if (MISCP (obj)) 2044 if (MISCP (obj))
2055 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2045 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2056 else if (VECTORLIKEP (obj)) 2046 else if (VECTORLIKEP (obj))
2057 sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj)); 2047 sprintf (buf, "(PVEC 0x%08"pD"x)", ASIZE (obj));
2058 else 2048 else
2059 sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2049 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2060 strout (buf, -1, -1, printcharfun); 2050 strout (buf, -1, -1, printcharfun);
diff --git a/src/process.c b/src/process.c
index cf6d40052a7..4d59ff0d452 100644
--- a/src/process.c
+++ b/src/process.c
@@ -182,9 +182,9 @@ extern int h_errno;
182#endif 182#endif
183 183
184/* Number of events of change of status of a process. */ 184/* Number of events of change of status of a process. */
185static int process_tick; 185static EMACS_INT process_tick;
186/* Number of events for which the user or sentinel has been notified. */ 186/* Number of events for which the user or sentinel has been notified. */
187static int update_tick; 187static EMACS_INT update_tick;
188 188
189/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */ 189/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
190 190
@@ -774,9 +774,7 @@ nil, indicating the current buffer's process. */)
774 { 774 {
775#ifdef SIGCHLD 775#ifdef SIGCHLD
776 Lisp_Object symbol; 776 Lisp_Object symbol;
777 /* Assignment to EMACS_INT stops GCC whining about limited range 777 pid_t pid = p->pid;
778 of data type. */
779 EMACS_INT pid = p->pid;
780 778
781 /* No problem storing the pid here, as it is still in Vprocess_alist. */ 779 /* No problem storing the pid here, as it is still in Vprocess_alist. */
782 deleted_pid_list = Fcons (make_fixnum_or_float (pid), 780 deleted_pid_list = Fcons (make_fixnum_or_float (pid),
@@ -873,9 +871,7 @@ This is the pid of the external process which PROCESS uses or talks to.
873For a network connection, this value is nil. */) 871For a network connection, this value is nil. */)
874 (register Lisp_Object process) 872 (register Lisp_Object process)
875{ 873{
876 /* Assignment to EMACS_INT stops GCC whining about limited range of 874 pid_t pid;
877 data type. */
878 EMACS_INT pid;
879 875
880 CHECK_PROCESS (process); 876 CHECK_PROCESS (process);
881 pid = XPROCESS (process)->pid; 877 pid = XPROCESS (process)->pid;
@@ -1050,8 +1046,8 @@ DEFUN ("set-process-window-size", Fset_process_window_size,
1050 (register Lisp_Object process, Lisp_Object height, Lisp_Object width) 1046 (register Lisp_Object process, Lisp_Object height, Lisp_Object width)
1051{ 1047{
1052 CHECK_PROCESS (process); 1048 CHECK_PROCESS (process);
1053 CHECK_NATNUM (height); 1049 CHECK_RANGED_INTEGER (0, height, INT_MAX);
1054 CHECK_NATNUM (width); 1050 CHECK_RANGED_INTEGER (0, width, INT_MAX);
1055 1051
1056 if (XPROCESS (process)->infd < 0 1052 if (XPROCESS (process)->infd < 0
1057 || set_window_size (XPROCESS (process)->infd, 1053 || set_window_size (XPROCESS (process)->infd,
@@ -1214,7 +1210,7 @@ Returns nil if format of ADDRESS is invalid. */)
1214 if (VECTORP (address)) /* AF_INET or AF_INET6 */ 1210 if (VECTORP (address)) /* AF_INET or AF_INET6 */
1215 { 1211 {
1216 register struct Lisp_Vector *p = XVECTOR (address); 1212 register struct Lisp_Vector *p = XVECTOR (address);
1217 EMACS_INT size = p->header.size; 1213 ptrdiff_t size = p->header.size;
1218 Lisp_Object args[10]; 1214 Lisp_Object args[10];
1219 int nargs, i; 1215 int nargs, i;
1220 1216
@@ -1243,14 +1239,12 @@ Returns nil if format of ADDRESS is invalid. */)
1243 1239
1244 for (i = 0; i < nargs; i++) 1240 for (i = 0; i < nargs; i++)
1245 { 1241 {
1246 EMACS_INT element = XINT (p->contents[i]); 1242 if (! RANGED_INTEGERP (0, p->contents[i], 65535))
1247
1248 if (element < 0 || element > 65535)
1249 return Qnil; 1243 return Qnil;
1250 1244
1251 if (nargs <= 5 /* IPv4 */ 1245 if (nargs <= 5 /* IPv4 */
1252 && i < 4 /* host, not port */ 1246 && i < 4 /* host, not port */
1253 && element > 255) 1247 && XINT (p->contents[i]) > 255)
1254 return Qnil; 1248 return Qnil;
1255 1249
1256 args[i+1] = p->contents[i]; 1250 args[i+1] = p->contents[i];
@@ -1305,7 +1299,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1305 Lisp_Object buffer, name, program, proc, current_dir, tem; 1299 Lisp_Object buffer, name, program, proc, current_dir, tem;
1306 register unsigned char **new_argv; 1300 register unsigned char **new_argv;
1307 ptrdiff_t i; 1301 ptrdiff_t i;
1308 int count = SPECPDL_INDEX (); 1302 ptrdiff_t count = SPECPDL_INDEX ();
1309 1303
1310 buffer = args[1]; 1304 buffer = args[1];
1311 if (!NILP (buffer)) 1305 if (!NILP (buffer))
@@ -2115,7 +2109,8 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
2115 return sizeof (struct sockaddr_un); 2109 return sizeof (struct sockaddr_un);
2116 } 2110 }
2117#endif 2111#endif
2118 else if (CONSP (address) && INTEGERP (XCAR (address)) && VECTORP (XCDR (address))) 2112 else if (CONSP (address) && TYPE_RANGED_INTEGERP (int, XCAR (address))
2113 && VECTORP (XCDR (address)))
2119 { 2114 {
2120 struct sockaddr *sa; 2115 struct sockaddr *sa;
2121 *familyp = XINT (XCAR (address)); 2116 *familyp = XINT (XCAR (address));
@@ -2138,6 +2133,7 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2138 register struct Lisp_Vector *p; 2133 register struct Lisp_Vector *p;
2139 register unsigned char *cp = NULL; 2134 register unsigned char *cp = NULL;
2140 register int i; 2135 register int i;
2136 EMACS_INT hostport;
2141 2137
2142 memset (sa, 0, len); 2138 memset (sa, 0, len);
2143 2139
@@ -2148,8 +2144,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2148 { 2144 {
2149 struct sockaddr_in *sin = (struct sockaddr_in *) sa; 2145 struct sockaddr_in *sin = (struct sockaddr_in *) sa;
2150 len = sizeof (sin->sin_addr) + 1; 2146 len = sizeof (sin->sin_addr) + 1;
2151 i = XINT (p->contents[--len]); 2147 hostport = XINT (p->contents[--len]);
2152 sin->sin_port = htons (i); 2148 sin->sin_port = htons (hostport);
2153 cp = (unsigned char *)&sin->sin_addr; 2149 cp = (unsigned char *)&sin->sin_addr;
2154 sa->sa_family = family; 2150 sa->sa_family = family;
2155 } 2151 }
@@ -2159,8 +2155,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2159 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; 2155 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
2160 uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr; 2156 uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr;
2161 len = sizeof (sin6->sin6_addr) + 1; 2157 len = sizeof (sin6->sin6_addr) + 1;
2162 i = XINT (p->contents[--len]); 2158 hostport = XINT (p->contents[--len]);
2163 sin6->sin6_port = htons (i); 2159 sin6->sin6_port = htons (hostport);
2164 for (i = 0; i < len; i++) 2160 for (i = 0; i < len; i++)
2165 if (INTEGERP (p->contents[i])) 2161 if (INTEGERP (p->contents[i]))
2166 { 2162 {
@@ -2315,7 +2311,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2315 case SOPT_INT: 2311 case SOPT_INT:
2316 { 2312 {
2317 int optval; 2313 int optval;
2318 if (INTEGERP (val)) 2314 if (TYPE_RANGED_INTEGERP (int, val))
2319 optval = XINT (val); 2315 optval = XINT (val);
2320 else 2316 else
2321 error ("Bad option value for %s", name); 2317 error ("Bad option value for %s", name);
@@ -2354,7 +2350,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2354 2350
2355 linger.l_onoff = 1; 2351 linger.l_onoff = 1;
2356 linger.l_linger = 0; 2352 linger.l_linger = 0;
2357 if (INTEGERP (val)) 2353 if (TYPE_RANGED_INTEGERP (int, val))
2358 linger.l_linger = XINT (val); 2354 linger.l_linger = XINT (val);
2359 else 2355 else
2360 linger.l_onoff = NILP (val) ? 0 : 1; 2356 linger.l_onoff = NILP (val) ? 0 : 1;
@@ -2593,7 +2589,7 @@ usage: (make-serial-process &rest ARGS) */)
2593 struct gcpro gcpro1; 2589 struct gcpro gcpro1;
2594 Lisp_Object name, buffer; 2590 Lisp_Object name, buffer;
2595 Lisp_Object tem, val; 2591 Lisp_Object tem, val;
2596 int specpdl_count = -1; 2592 ptrdiff_t specpdl_count = -1;
2597 2593
2598 if (nargs == 0) 2594 if (nargs == 0)
2599 return Qnil; 2595 return Qnil;
@@ -2893,8 +2889,8 @@ usage: (make-network-process &rest ARGS) */)
2893 int xerrno = 0; 2889 int xerrno = 0;
2894 int s = -1, outch, inch; 2890 int s = -1, outch, inch;
2895 struct gcpro gcpro1; 2891 struct gcpro gcpro1;
2896 int count = SPECPDL_INDEX (); 2892 ptrdiff_t count = SPECPDL_INDEX ();
2897 int count1; 2893 ptrdiff_t count1;
2898 Lisp_Object QCaddress; /* one of QClocal or QCremote */ 2894 Lisp_Object QCaddress; /* one of QClocal or QCremote */
2899 Lisp_Object tem; 2895 Lisp_Object tem;
2900 Lisp_Object name, buffer, host, service, address; 2896 Lisp_Object name, buffer, host, service, address;
@@ -2941,7 +2937,7 @@ usage: (make-network-process &rest ARGS) */)
2941 error ("Network servers not supported"); 2937 error ("Network servers not supported");
2942#else 2938#else
2943 is_server = 1; 2939 is_server = 1;
2944 if (INTEGERP (tem)) 2940 if (TYPE_RANGED_INTEGERP (int, tem))
2945 backlog = XINT (tem); 2941 backlog = XINT (tem);
2946#endif 2942#endif
2947 } 2943 }
@@ -3007,7 +3003,7 @@ usage: (make-network-process &rest ARGS) */)
3007#endif 3003#endif
3008 else if (EQ (tem, Qipv4)) 3004 else if (EQ (tem, Qipv4))
3009 family = AF_INET; 3005 family = AF_INET;
3010 else if (INTEGERP (tem)) 3006 else if (TYPE_RANGED_INTEGERP (int, tem))
3011 family = XINT (tem); 3007 family = XINT (tem);
3012 else 3008 else
3013 error ("Unknown address family"); 3009 error ("Unknown address family");
@@ -3964,7 +3960,7 @@ If JUST-THIS-ONE is an integer, don't run any timers either.
3964Return non-nil if we received any output before the timeout expired. */) 3960Return non-nil if we received any output before the timeout expired. */)
3965 (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) 3961 (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one)
3966{ 3962{
3967 int secs, usecs = 0; 3963 int secs = -1, usecs = 0;
3968 3964
3969 if (! NILP (process)) 3965 if (! NILP (process))
3970 CHECK_PROCESS (process); 3966 CHECK_PROCESS (process);
@@ -3985,22 +3981,12 @@ Return non-nil if we received any output before the timeout expired. */)
3985 3981
3986 if (!NILP (seconds)) 3982 if (!NILP (seconds))
3987 { 3983 {
3988 if (INTEGERP (seconds)) 3984 double duration = extract_float (seconds);
3989 secs = XINT (seconds); 3985 if (0 < duration)
3990 else if (FLOATP (seconds)) 3986 duration_to_sec_usec (duration, &secs, &usecs);
3991 {
3992 double timeout = XFLOAT_DATA (seconds);
3993 secs = (int) timeout;
3994 usecs = (int) ((timeout - (double) secs) * 1000000);
3995 }
3996 else
3997 wrong_type_argument (Qnumberp, seconds);
3998
3999 if (secs < 0 || (secs == 0 && usecs == 0))
4000 secs = -1, usecs = 0;
4001 } 3987 }
4002 else 3988 else if (!NILP (process))
4003 secs = NILP (process) ? -1 : 0; 3989 secs = 0;
4004 3990
4005 return 3991 return
4006 (wait_reading_process_output (secs, usecs, 0, 0, 3992 (wait_reading_process_output (secs, usecs, 0, 0,
@@ -4313,7 +4299,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4313 EMACS_TIME timeout, end_time; 4299 EMACS_TIME timeout, end_time;
4314 int wait_channel = -1; 4300 int wait_channel = -1;
4315 int got_some_input = 0; 4301 int got_some_input = 0;
4316 int count = SPECPDL_INDEX (); 4302 ptrdiff_t count = SPECPDL_INDEX ();
4317 4303
4318 FD_ZERO (&Available); 4304 FD_ZERO (&Available);
4319 FD_ZERO (&Writeok); 4305 FD_ZERO (&Writeok);
@@ -5054,11 +5040,11 @@ read_process_output (Lisp_Object proc, register int channel)
5054 char *chars; 5040 char *chars;
5055 register Lisp_Object outstream; 5041 register Lisp_Object outstream;
5056 register struct Lisp_Process *p = XPROCESS (proc); 5042 register struct Lisp_Process *p = XPROCESS (proc);
5057 register EMACS_INT opoint; 5043 register ptrdiff_t opoint;
5058 struct coding_system *coding = proc_decode_coding_system[channel]; 5044 struct coding_system *coding = proc_decode_coding_system[channel];
5059 int carryover = p->decoding_carryover; 5045 int carryover = p->decoding_carryover;
5060 int readmax = 4096; 5046 int readmax = 4096;
5061 int count = SPECPDL_INDEX (); 5047 ptrdiff_t count = SPECPDL_INDEX ();
5062 Lisp_Object odeactivate; 5048 Lisp_Object odeactivate;
5063 5049
5064 chars = (char *) alloca (carryover + readmax); 5050 chars = (char *) alloca (carryover + readmax);
@@ -5253,10 +5239,10 @@ read_process_output (Lisp_Object proc, register int channel)
5253 else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name))) 5239 else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name)))
5254 { 5240 {
5255 Lisp_Object old_read_only; 5241 Lisp_Object old_read_only;
5256 EMACS_INT old_begv, old_zv; 5242 ptrdiff_t old_begv, old_zv;
5257 EMACS_INT old_begv_byte, old_zv_byte; 5243 ptrdiff_t old_begv_byte, old_zv_byte;
5258 EMACS_INT before, before_byte; 5244 ptrdiff_t before, before_byte;
5259 EMACS_INT opoint_byte; 5245 ptrdiff_t opoint_byte;
5260 Lisp_Object text; 5246 Lisp_Object text;
5261 struct buffer *b; 5247 struct buffer *b;
5262 5248
@@ -5397,7 +5383,7 @@ send_process_trap (int ignore)
5397 5383
5398static void 5384static void
5399send_process (volatile Lisp_Object proc, const char *volatile buf, 5385send_process (volatile Lisp_Object proc, const char *volatile buf,
5400 volatile EMACS_INT len, volatile Lisp_Object object) 5386 volatile ptrdiff_t len, volatile Lisp_Object object)
5401{ 5387{
5402 /* Use volatile to protect variables from being clobbered by longjmp. */ 5388 /* Use volatile to protect variables from being clobbered by longjmp. */
5403 struct Lisp_Process *p = XPROCESS (proc); 5389 struct Lisp_Process *p = XPROCESS (proc);
@@ -5468,8 +5454,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5468 coding->dst_object = Qt; 5454 coding->dst_object = Qt;
5469 if (BUFFERP (object)) 5455 if (BUFFERP (object))
5470 { 5456 {
5471 EMACS_INT from_byte, from, to; 5457 ptrdiff_t from_byte, from, to;
5472 EMACS_INT save_pt, save_pt_byte; 5458 ptrdiff_t save_pt, save_pt_byte;
5473 struct buffer *cur = current_buffer; 5459 struct buffer *cur = current_buffer;
5474 5460
5475 set_buffer_internal (XBUFFER (object)); 5461 set_buffer_internal (XBUFFER (object));
@@ -5523,12 +5509,12 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5523 process_sent_to = proc; 5509 process_sent_to = proc;
5524 while (len > 0) 5510 while (len > 0)
5525 { 5511 {
5526 EMACS_INT this = len; 5512 ptrdiff_t this = len;
5527 5513
5528 /* Send this batch, using one or more write calls. */ 5514 /* Send this batch, using one or more write calls. */
5529 while (this > 0) 5515 while (this > 0)
5530 { 5516 {
5531 EMACS_INT written = 0; 5517 ptrdiff_t written = 0;
5532 int outfd = p->outfd; 5518 int outfd = p->outfd;
5533 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); 5519 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap);
5534#ifdef DATAGRAM_SOCKETS 5520#ifdef DATAGRAM_SOCKETS
@@ -5582,7 +5568,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5582 that may allow the program 5568 that may allow the program
5583 to finish doing output and read more. */ 5569 to finish doing output and read more. */
5584 { 5570 {
5585 EMACS_INT offset = 0; 5571 ptrdiff_t offset = 0;
5586 5572
5587#ifdef BROKEN_PTY_READ_AFTER_EAGAIN 5573#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5588 /* A gross hack to work around a bug in FreeBSD. 5574 /* A gross hack to work around a bug in FreeBSD.
@@ -5666,7 +5652,7 @@ Output from processes can arrive in between bunches. */)
5666 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5652 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5667{ 5653{
5668 Lisp_Object proc; 5654 Lisp_Object proc;
5669 EMACS_INT start1, end1; 5655 ptrdiff_t start1, end1;
5670 5656
5671 proc = get_process (process); 5657 proc = get_process (process);
5672 validate_region (&start, &end); 5658 validate_region (&start, &end);
@@ -5702,10 +5688,10 @@ Output from processes can arrive in between bunches. */)
5702 5688
5703/* Return the foreground process group for the tty/pty that 5689/* Return the foreground process group for the tty/pty that
5704 the process P uses. */ 5690 the process P uses. */
5705static int 5691static pid_t
5706emacs_get_tty_pgrp (struct Lisp_Process *p) 5692emacs_get_tty_pgrp (struct Lisp_Process *p)
5707{ 5693{
5708 int gid = -1; 5694 pid_t gid = -1;
5709 5695
5710#ifdef TIOCGPGRP 5696#ifdef TIOCGPGRP
5711 if (ioctl (p->infd, TIOCGPGRP, &gid) == -1 && ! NILP (p->tty_name)) 5697 if (ioctl (p->infd, TIOCGPGRP, &gid) == -1 && ! NILP (p->tty_name))
@@ -5735,7 +5721,7 @@ return t unconditionally. */)
5735{ 5721{
5736 /* Initialize in case ioctl doesn't exist or gives an error, 5722 /* Initialize in case ioctl doesn't exist or gives an error,
5737 in a way that will cause returning t. */ 5723 in a way that will cause returning t. */
5738 int gid; 5724 pid_t gid;
5739 Lisp_Object proc; 5725 Lisp_Object proc;
5740 struct Lisp_Process *p; 5726 struct Lisp_Process *p;
5741 5727
@@ -5776,7 +5762,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5776{ 5762{
5777 Lisp_Object proc; 5763 Lisp_Object proc;
5778 register struct Lisp_Process *p; 5764 register struct Lisp_Process *p;
5779 int gid; 5765 pid_t gid;
5780 int no_pgrp = 0; 5766 int no_pgrp = 0;
5781 5767
5782 proc = get_process (process); 5768 proc = get_process (process);
@@ -6030,48 +6016,40 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6030{ 6016{
6031 pid_t pid; 6017 pid_t pid;
6032 6018
6033 if (INTEGERP (process))
6034 {
6035 pid = XINT (process);
6036 goto got_it;
6037 }
6038
6039 if (FLOATP (process))
6040 {
6041 pid = (pid_t) XFLOAT_DATA (process);
6042 goto got_it;
6043 }
6044
6045 if (STRINGP (process)) 6019 if (STRINGP (process))
6046 { 6020 {
6047 Lisp_Object tem; 6021 Lisp_Object tem = Fget_process (process);
6048 if (tem = Fget_process (process), NILP (tem)) 6022 if (NILP (tem))
6049 { 6023 {
6050 pid = XINT (Fstring_to_number (process, make_number (10))); 6024 Lisp_Object process_number =
6051 if (pid > 0) 6025 string_to_number (SSDATA (process), 10, 1);
6052 goto got_it; 6026 if (INTEGERP (process_number) || FLOATP (process_number))
6027 tem = process_number;
6053 } 6028 }
6054 process = tem; 6029 process = tem;
6055 } 6030 }
6056 else 6031 else if (!NUMBERP (process))
6057 process = get_process (process); 6032 process = get_process (process);
6058 6033
6059 if (NILP (process)) 6034 if (NILP (process))
6060 return process; 6035 return process;
6061 6036
6062 CHECK_PROCESS (process); 6037 if (NUMBERP (process))
6063 pid = XPROCESS (process)->pid; 6038 CONS_TO_INTEGER (process, pid_t, pid);
6064 if (pid <= 0) 6039 else
6065 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name)); 6040 {
6066 6041 CHECK_PROCESS (process);
6067 got_it: 6042 pid = XPROCESS (process)->pid;
6043 if (pid <= 0)
6044 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name));
6045 }
6068 6046
6069#define parse_signal(NAME, VALUE) \ 6047#define parse_signal(NAME, VALUE) \
6070 else if (!xstrcasecmp (name, NAME)) \ 6048 else if (!xstrcasecmp (name, NAME)) \
6071 XSETINT (sigcode, VALUE) 6049 XSETINT (sigcode, VALUE)
6072 6050
6073 if (INTEGERP (sigcode)) 6051 if (INTEGERP (sigcode))
6074 ; 6052 CHECK_TYPE_RANGED_INTEGER (int, sigcode);
6075 else 6053 else
6076 { 6054 {
6077 char *name; 6055 char *name;
@@ -6334,8 +6312,8 @@ sigchld_handler (int signo)
6334 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) 6312 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail))
6335 { 6313 {
6336 Lisp_Object xpid = XCAR (tail); 6314 Lisp_Object xpid = XCAR (tail);
6337 if ((INTEGERP (xpid) && pid == (pid_t) XINT (xpid)) 6315 if ((INTEGERP (xpid) && pid == XINT (xpid))
6338 || (FLOATP (xpid) && pid == (pid_t) XFLOAT_DATA (xpid))) 6316 || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid)))
6339 { 6317 {
6340 XSETCAR (tail, Qnil); 6318 XSETCAR (tail, Qnil);
6341 goto sigchld_end_of_loop; 6319 goto sigchld_end_of_loop;
@@ -6451,7 +6429,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6451{ 6429{
6452 Lisp_Object sentinel, odeactivate; 6430 Lisp_Object sentinel, odeactivate;
6453 register struct Lisp_Process *p = XPROCESS (proc); 6431 register struct Lisp_Process *p = XPROCESS (proc);
6454 int count = SPECPDL_INDEX (); 6432 ptrdiff_t count = SPECPDL_INDEX ();
6455 int outer_running_asynch_code = running_asynch_code; 6433 int outer_running_asynch_code = running_asynch_code;
6456 int waiting = waiting_for_user_input_p; 6434 int waiting = waiting_for_user_input_p;
6457 6435
@@ -6610,8 +6588,8 @@ status_notify (struct Lisp_Process *deleting_process)
6610 { 6588 {
6611 Lisp_Object tem; 6589 Lisp_Object tem;
6612 struct buffer *old = current_buffer; 6590 struct buffer *old = current_buffer;
6613 EMACS_INT opoint, opoint_byte; 6591 ptrdiff_t opoint, opoint_byte;
6614 EMACS_INT before, before_byte; 6592 ptrdiff_t before, before_byte;
6615 6593
6616 /* Avoid error if buffer is deleted 6594 /* Avoid error if buffer is deleted
6617 (probably that's why the process is dead, too) */ 6595 (probably that's why the process is dead, too) */
diff --git a/src/process.h b/src/process.h
index 3eb94cb196b..edb937893b0 100644
--- a/src/process.h
+++ b/src/process.h
@@ -95,9 +95,9 @@ struct Lisp_Process
95 /* Descriptor by which we write to this process */ 95 /* Descriptor by which we write to this process */
96 int outfd; 96 int outfd;
97 /* Event-count of last event in which this process changed status. */ 97 /* Event-count of last event in which this process changed status. */
98 int tick; 98 EMACS_INT tick;
99 /* Event-count of last such event reported. */ 99 /* Event-count of last such event reported. */
100 int update_tick; 100 EMACS_INT update_tick;
101 /* Size of carryover in decoding. */ 101 /* Size of carryover in decoding. */
102 int decoding_carryover; 102 int decoding_carryover;
103 /* Hysteresis to try to read process output in larger blocks. 103 /* Hysteresis to try to read process output in larger blocks.
diff --git a/src/puresize.h b/src/puresize.h
index 185d2a76ae0..bee82d1e783 100644
--- a/src/puresize.h
+++ b/src/puresize.h
@@ -46,8 +46,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
46/* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */ 46/* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */
47#ifndef PURESIZE_RATIO 47#ifndef PURESIZE_RATIO
48#if EMACS_INT_MAX >> 31 != 0 48#if EMACS_INT_MAX >> 31 != 0
49#if PTRDIFF_MAX >> 31 != 0
49#define PURESIZE_RATIO 10/6 /* Don't surround with `()'. */ 50#define PURESIZE_RATIO 10/6 /* Don't surround with `()'. */
50#else 51#else
52#define PURESIZE_RATIO 8/6 /* Don't surround with `()'. */
53#endif
54#else
51#define PURESIZE_RATIO 1 55#define PURESIZE_RATIO 1
52#endif 56#endif
53#endif 57#endif
diff --git a/src/ralloc.c b/src/ralloc.c
index d736e279520..7fdef69842a 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1139,6 +1139,12 @@ r_alloc_reset_variable (POINTER *old, POINTER *new)
1139 bloc->variable = new; 1139 bloc->variable = new;
1140} 1140}
1141 1141
1142void
1143r_alloc_inhibit_buffer_relocation (int inhibit)
1144{
1145 use_relocatable_buffers = !inhibit;
1146}
1147
1142 1148
1143/*********************************************************************** 1149/***********************************************************************
1144 Initialization 1150 Initialization
diff --git a/src/scroll.c b/src/scroll.c
index 77ea1007ade..abc5c17400a 100644
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -94,7 +94,7 @@ calculate_scrolling (FRAME_PTR frame,
94 int free_at_end) 94 int free_at_end)
95{ 95{
96 register int i, j; 96 register int i, j;
97 EMACS_INT frame_lines = FRAME_LINES (frame); 97 int frame_lines = FRAME_LINES (frame);
98 register struct matrix_elt *p, *p1; 98 register struct matrix_elt *p, *p1;
99 register int cost, cost1; 99 register int cost, cost1;
100 100
@@ -432,7 +432,7 @@ calculate_direct_scrolling (FRAME_PTR frame,
432 int free_at_end) 432 int free_at_end)
433{ 433{
434 register int i, j; 434 register int i, j;
435 EMACS_INT frame_lines = FRAME_LINES (frame); 435 int frame_lines = FRAME_LINES (frame);
436 register struct matrix_elt *p, *p1; 436 register struct matrix_elt *p, *p1;
437 register int cost, cost1, delta; 437 register int cost, cost1, delta;
438 438
@@ -889,8 +889,8 @@ static void
889line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn, 889line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn,
890 register int *ov, register int *mf) 890 register int *ov, register int *mf)
891{ 891{
892 register EMACS_INT i; 892 register int i;
893 register EMACS_INT frame_lines = FRAME_LINES (frame); 893 register int frame_lines = FRAME_LINES (frame);
894 register int insert_overhead = ov1 * 10; 894 register int insert_overhead = ov1 * 10;
895 register int next_insert_cost = ovn * 10; 895 register int next_insert_cost = ovn * 10;
896 896
diff --git a/src/search.c b/src/search.c
index 2bf5f78d93b..5608e344e75 100644
--- a/src/search.c
+++ b/src/search.c
@@ -90,16 +90,16 @@ static Lisp_Object Qinvalid_regexp;
90/* Error condition used for failing searches. */ 90/* Error condition used for failing searches. */
91static Lisp_Object Qsearch_failed; 91static Lisp_Object Qsearch_failed;
92 92
93static void set_search_regs (EMACS_INT, EMACS_INT); 93static void set_search_regs (ptrdiff_t, ptrdiff_t);
94static void save_search_regs (void); 94static void save_search_regs (void);
95static EMACS_INT simple_search (EMACS_INT, unsigned char *, EMACS_INT, 95static EMACS_INT simple_search (EMACS_INT, unsigned char *, ptrdiff_t,
96 EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT, 96 ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t,
97 EMACS_INT, EMACS_INT); 97 ptrdiff_t, ptrdiff_t);
98static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, EMACS_INT, 98static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, ptrdiff_t,
99 Lisp_Object, Lisp_Object, EMACS_INT, 99 Lisp_Object, Lisp_Object, ptrdiff_t,
100 EMACS_INT, int); 100 ptrdiff_t, int);
101static EMACS_INT search_buffer (Lisp_Object, EMACS_INT, EMACS_INT, 101static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t,
102 EMACS_INT, EMACS_INT, EMACS_INT, int, 102 ptrdiff_t, ptrdiff_t, EMACS_INT, int,
103 Lisp_Object, Lisp_Object, int); 103 Lisp_Object, Lisp_Object, int);
104static void matcher_overflow (void) NO_RETURN; 104static void matcher_overflow (void) NO_RETURN;
105 105
@@ -272,8 +272,8 @@ looking_at_1 (Lisp_Object string, int posix)
272{ 272{
273 Lisp_Object val; 273 Lisp_Object val;
274 unsigned char *p1, *p2; 274 unsigned char *p1, *p2;
275 EMACS_INT s1, s2; 275 ptrdiff_t s1, s2;
276 register EMACS_INT i; 276 register ptrdiff_t i;
277 struct re_pattern_buffer *bufp; 277 struct re_pattern_buffer *bufp;
278 278
279 if (running_asynch_code) 279 if (running_asynch_code)
@@ -368,10 +368,10 @@ data if you want to preserve them. */)
368static Lisp_Object 368static Lisp_Object
369string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix) 369string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix)
370{ 370{
371 EMACS_INT val; 371 ptrdiff_t val;
372 struct re_pattern_buffer *bufp; 372 struct re_pattern_buffer *bufp;
373 EMACS_INT pos, pos_byte; 373 EMACS_INT pos;
374 int i; 374 ptrdiff_t pos_byte, i;
375 375
376 if (running_asynch_code) 376 if (running_asynch_code)
377 save_search_regs (); 377 save_search_regs ();
@@ -383,7 +383,7 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int p
383 pos = 0, pos_byte = 0; 383 pos = 0, pos_byte = 0;
384 else 384 else
385 { 385 {
386 EMACS_INT len = SCHARS (string); 386 ptrdiff_t len = SCHARS (string);
387 387
388 CHECK_NUMBER (start); 388 CHECK_NUMBER (start);
389 pos = XINT (start); 389 pos = XINT (start);
@@ -468,10 +468,10 @@ matched by parenthesis constructs in the pattern. */)
468 and return the index of the match, or negative on failure. 468 and return the index of the match, or negative on failure.
469 This does not clobber the match data. */ 469 This does not clobber the match data. */
470 470
471EMACS_INT 471ptrdiff_t
472fast_string_match (Lisp_Object regexp, Lisp_Object string) 472fast_string_match (Lisp_Object regexp, Lisp_Object string)
473{ 473{
474 EMACS_INT val; 474 ptrdiff_t val;
475 struct re_pattern_buffer *bufp; 475 struct re_pattern_buffer *bufp;
476 476
477 bufp = compile_pattern (regexp, 0, Qnil, 477 bufp = compile_pattern (regexp, 0, Qnil,
@@ -491,10 +491,10 @@ fast_string_match (Lisp_Object regexp, Lisp_Object string)
491 This does not clobber the match data. 491 This does not clobber the match data.
492 We assume that STRING contains single-byte characters. */ 492 We assume that STRING contains single-byte characters. */
493 493
494EMACS_INT 494ptrdiff_t
495fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string) 495fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string)
496{ 496{
497 EMACS_INT val; 497 ptrdiff_t val;
498 struct re_pattern_buffer *bufp; 498 struct re_pattern_buffer *bufp;
499 size_t len = strlen (string); 499 size_t len = strlen (string);
500 500
@@ -511,10 +511,10 @@ fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string)
511 511
512/* Like fast_string_match but ignore case. */ 512/* Like fast_string_match but ignore case. */
513 513
514EMACS_INT 514ptrdiff_t
515fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) 515fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string)
516{ 516{
517 EMACS_INT val; 517 ptrdiff_t val;
518 struct re_pattern_buffer *bufp; 518 struct re_pattern_buffer *bufp;
519 519
520 bufp = compile_pattern (regexp, 0, Vascii_canon_table, 520 bufp = compile_pattern (regexp, 0, Vascii_canon_table,
@@ -535,14 +535,14 @@ fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string)
535 indices into the string. This function doesn't modify the match 535 indices into the string. This function doesn't modify the match
536 data. */ 536 data. */
537 537
538EMACS_INT 538ptrdiff_t
539fast_looking_at (Lisp_Object regexp, EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT limit, EMACS_INT limit_byte, Lisp_Object string) 539fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t limit, ptrdiff_t limit_byte, Lisp_Object string)
540{ 540{
541 int multibyte; 541 int multibyte;
542 struct re_pattern_buffer *buf; 542 struct re_pattern_buffer *buf;
543 unsigned char *p1, *p2; 543 unsigned char *p1, *p2;
544 EMACS_INT s1, s2; 544 ptrdiff_t s1, s2;
545 EMACS_INT len; 545 ptrdiff_t len;
546 546
547 if (STRINGP (string)) 547 if (STRINGP (string))
548 { 548 {
@@ -641,9 +641,9 @@ newline_cache_on_off (struct buffer *buf)
641 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do 641 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do
642 except when inside redisplay. */ 642 except when inside redisplay. */
643 643
644EMACS_INT 644ptrdiff_t
645scan_buffer (register int target, EMACS_INT start, EMACS_INT end, 645scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end,
646 EMACS_INT count, EMACS_INT *shortage, int allow_quit) 646 ptrdiff_t count, ptrdiff_t *shortage, int allow_quit)
647{ 647{
648 struct region_cache *newline_cache; 648 struct region_cache *newline_cache;
649 int direction; 649 int direction;
@@ -675,9 +675,9 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end,
675 the position of the last character before the next such 675 the position of the last character before the next such
676 obstacle --- the last character the dumb search loop should 676 obstacle --- the last character the dumb search loop should
677 examine. */ 677 examine. */
678 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end) - 1; 678 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end) - 1;
679 EMACS_INT start_byte = CHAR_TO_BYTE (start); 679 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
680 EMACS_INT tem; 680 ptrdiff_t tem;
681 681
682 /* If we're looking for a newline, consult the newline cache 682 /* If we're looking for a newline, consult the newline cache
683 to see where we can avoid some scanning. */ 683 to see where we can avoid some scanning. */
@@ -748,9 +748,9 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end,
748 while (start > end) 748 while (start > end)
749 { 749 {
750 /* The last character to check before the next obstacle. */ 750 /* The last character to check before the next obstacle. */
751 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end); 751 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end);
752 EMACS_INT start_byte = CHAR_TO_BYTE (start); 752 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
753 EMACS_INT tem; 753 ptrdiff_t tem;
754 754
755 /* Consult the newline cache, if appropriate. */ 755 /* Consult the newline cache, if appropriate. */
756 if (target == '\n' && newline_cache) 756 if (target == '\n' && newline_cache)
@@ -835,8 +835,8 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end,
835 except in special cases. */ 835 except in special cases. */
836 836
837EMACS_INT 837EMACS_INT
838scan_newline (EMACS_INT start, EMACS_INT start_byte, 838scan_newline (ptrdiff_t start, ptrdiff_t start_byte,
839 EMACS_INT limit, EMACS_INT limit_byte, 839 ptrdiff_t limit, ptrdiff_t limit_byte,
840 register EMACS_INT count, int allow_quit) 840 register EMACS_INT count, int allow_quit)
841{ 841{
842 int direction = ((count > 0) ? 1 : -1); 842 int direction = ((count > 0) ? 1 : -1);
@@ -844,7 +844,7 @@ scan_newline (EMACS_INT start, EMACS_INT start_byte,
844 register unsigned char *cursor; 844 register unsigned char *cursor;
845 unsigned char *base; 845 unsigned char *base;
846 846
847 EMACS_INT ceiling; 847 ptrdiff_t ceiling;
848 register unsigned char *ceiling_addr; 848 register unsigned char *ceiling_addr;
849 849
850 int old_immediate_quit = immediate_quit; 850 int old_immediate_quit = immediate_quit;
@@ -930,21 +930,21 @@ scan_newline (EMACS_INT start, EMACS_INT start_byte,
930 return count * direction; 930 return count * direction;
931} 931}
932 932
933EMACS_INT 933ptrdiff_t
934find_next_newline_no_quit (EMACS_INT from, EMACS_INT cnt) 934find_next_newline_no_quit (ptrdiff_t from, ptrdiff_t cnt)
935{ 935{
936 return scan_buffer ('\n', from, 0, cnt, (EMACS_INT *) 0, 0); 936 return scan_buffer ('\n', from, 0, cnt, (ptrdiff_t *) 0, 0);
937} 937}
938 938
939/* Like find_next_newline, but returns position before the newline, 939/* Like find_next_newline, but returns position before the newline,
940 not after, and only search up to TO. This isn't just 940 not after, and only search up to TO. This isn't just
941 find_next_newline (...)-1, because you might hit TO. */ 941 find_next_newline (...)-1, because you might hit TO. */
942 942
943EMACS_INT 943ptrdiff_t
944find_before_next_newline (EMACS_INT from, EMACS_INT to, EMACS_INT cnt) 944find_before_next_newline (ptrdiff_t from, ptrdiff_t to, ptrdiff_t cnt)
945{ 945{
946 EMACS_INT shortage; 946 ptrdiff_t shortage;
947 EMACS_INT pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); 947 ptrdiff_t pos = scan_buffer ('\n', from, to, cnt, &shortage, 1);
948 948
949 if (shortage == 0) 949 if (shortage == 0)
950 pos--; 950 pos--;
@@ -959,7 +959,8 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
959 Lisp_Object count, int direction, int RE, int posix) 959 Lisp_Object count, int direction, int RE, int posix)
960{ 960{
961 register EMACS_INT np; 961 register EMACS_INT np;
962 EMACS_INT lim, lim_byte; 962 EMACS_INT lim;
963 ptrdiff_t lim_byte;
963 EMACS_INT n = direction; 964 EMACS_INT n = direction;
964 965
965 if (!NILP (count)) 966 if (!NILP (count))
@@ -1035,7 +1036,7 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
1035static int 1036static int
1036trivial_regexp_p (Lisp_Object regexp) 1037trivial_regexp_p (Lisp_Object regexp)
1037{ 1038{
1038 EMACS_INT len = SBYTES (regexp); 1039 ptrdiff_t len = SBYTES (regexp);
1039 unsigned char *s = SDATA (regexp); 1040 unsigned char *s = SDATA (regexp);
1040 while (--len >= 0) 1041 while (--len >= 0)
1041 { 1042 {
@@ -1099,13 +1100,13 @@ while (0)
1099static struct re_registers search_regs_1; 1100static struct re_registers search_regs_1;
1100 1101
1101static EMACS_INT 1102static EMACS_INT
1102search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, 1103search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
1103 EMACS_INT lim, EMACS_INT lim_byte, EMACS_INT n, 1104 ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n,
1104 int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix) 1105 int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix)
1105{ 1106{
1106 EMACS_INT len = SCHARS (string); 1107 ptrdiff_t len = SCHARS (string);
1107 EMACS_INT len_byte = SBYTES (string); 1108 ptrdiff_t len_byte = SBYTES (string);
1108 register int i; 1109 register ptrdiff_t i;
1109 1110
1110 if (running_asynch_code) 1111 if (running_asynch_code)
1111 save_search_regs (); 1112 save_search_regs ();
@@ -1121,7 +1122,7 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1121 if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) 1122 if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp)))
1122 { 1123 {
1123 unsigned char *p1, *p2; 1124 unsigned char *p1, *p2;
1124 EMACS_INT s1, s2; 1125 ptrdiff_t s1, s2;
1125 struct re_pattern_buffer *bufp; 1126 struct re_pattern_buffer *bufp;
1126 1127
1127 bufp = compile_pattern (string, 1128 bufp = compile_pattern (string,
@@ -1157,13 +1158,26 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1157 1158
1158 while (n < 0) 1159 while (n < 0)
1159 { 1160 {
1160 EMACS_INT val; 1161 ptrdiff_t val;
1162
1163#ifdef REL_ALLOC
1164 /* re_search_2 below is passed C pointers to buffer text.
1165 If some code called by it causes memory (re)allocation,
1166 buffer text could be relocated on platforms that use
1167 REL_ALLOC, which invalidates those C pointers. So we
1168 inhibit relocation of buffer text for as long as
1169 re_search_2 runs. */
1170 r_alloc_inhibit_buffer_relocation (1);
1171#endif
1161 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, 1172 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
1162 pos_byte - BEGV_BYTE, lim_byte - pos_byte, 1173 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
1163 (NILP (Vinhibit_changing_match_data) 1174 (NILP (Vinhibit_changing_match_data)
1164 ? &search_regs : &search_regs_1), 1175 ? &search_regs : &search_regs_1),
1165 /* Don't allow match past current point */ 1176 /* Don't allow match past current point */
1166 pos_byte - BEGV_BYTE); 1177 pos_byte - BEGV_BYTE);
1178#ifdef REL_ALLOC
1179 r_alloc_inhibit_buffer_relocation (0);
1180#endif
1167 if (val == -2) 1181 if (val == -2)
1168 { 1182 {
1169 matcher_overflow (); 1183 matcher_overflow ();
@@ -1201,12 +1215,21 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1201 } 1215 }
1202 while (n > 0) 1216 while (n > 0)
1203 { 1217 {
1204 EMACS_INT val; 1218 ptrdiff_t val;
1219
1220#ifdef REL_ALLOC
1221 /* See commentary above for the reasons for inhibiting
1222 buffer text relocation here. */
1223 r_alloc_inhibit_buffer_relocation (1);
1224#endif
1205 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, 1225 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
1206 pos_byte - BEGV_BYTE, lim_byte - pos_byte, 1226 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
1207 (NILP (Vinhibit_changing_match_data) 1227 (NILP (Vinhibit_changing_match_data)
1208 ? &search_regs : &search_regs_1), 1228 ? &search_regs : &search_regs_1),
1209 lim_byte - BEGV_BYTE); 1229 lim_byte - BEGV_BYTE);
1230#ifdef REL_ALLOC
1231 r_alloc_inhibit_buffer_relocation (0);
1232#endif
1210 if (val == -2) 1233 if (val == -2)
1211 { 1234 {
1212 matcher_overflow (); 1235 matcher_overflow ();
@@ -1246,8 +1269,8 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1246 else /* non-RE case */ 1269 else /* non-RE case */
1247 { 1270 {
1248 unsigned char *raw_pattern, *pat; 1271 unsigned char *raw_pattern, *pat;
1249 EMACS_INT raw_pattern_size; 1272 ptrdiff_t raw_pattern_size;
1250 EMACS_INT raw_pattern_size_byte; 1273 ptrdiff_t raw_pattern_size_byte;
1251 unsigned char *patbuf; 1274 unsigned char *patbuf;
1252 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 1275 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
1253 unsigned char *base_pat; 1276 unsigned char *base_pat;
@@ -1441,15 +1464,15 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1441 1464
1442static EMACS_INT 1465static EMACS_INT
1443simple_search (EMACS_INT n, unsigned char *pat, 1466simple_search (EMACS_INT n, unsigned char *pat,
1444 EMACS_INT len, EMACS_INT len_byte, Lisp_Object trt, 1467 ptrdiff_t len, ptrdiff_t len_byte, Lisp_Object trt,
1445 EMACS_INT pos, EMACS_INT pos_byte, 1468 ptrdiff_t pos, ptrdiff_t pos_byte,
1446 EMACS_INT lim, EMACS_INT lim_byte) 1469 ptrdiff_t lim, ptrdiff_t lim_byte)
1447{ 1470{
1448 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 1471 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
1449 int forward = n > 0; 1472 int forward = n > 0;
1450 /* Number of buffer bytes matched. Note that this may be different 1473 /* Number of buffer bytes matched. Note that this may be different
1451 from len_byte in a multibyte buffer. */ 1474 from len_byte in a multibyte buffer. */
1452 EMACS_INT match_byte; 1475 ptrdiff_t match_byte;
1453 1476
1454 if (lim > pos && multibyte) 1477 if (lim > pos && multibyte)
1455 while (n > 0) 1478 while (n > 0)
@@ -1457,9 +1480,9 @@ simple_search (EMACS_INT n, unsigned char *pat,
1457 while (1) 1480 while (1)
1458 { 1481 {
1459 /* Try matching at position POS. */ 1482 /* Try matching at position POS. */
1460 EMACS_INT this_pos = pos; 1483 ptrdiff_t this_pos = pos;
1461 EMACS_INT this_pos_byte = pos_byte; 1484 ptrdiff_t this_pos_byte = pos_byte;
1462 EMACS_INT this_len = len; 1485 ptrdiff_t this_len = len;
1463 unsigned char *p = pat; 1486 unsigned char *p = pat;
1464 if (pos + len > lim || pos_byte + len_byte > lim_byte) 1487 if (pos + len > lim || pos_byte + len_byte > lim_byte)
1465 goto stop; 1488 goto stop;
@@ -1503,8 +1526,8 @@ simple_search (EMACS_INT n, unsigned char *pat,
1503 while (1) 1526 while (1)
1504 { 1527 {
1505 /* Try matching at position POS. */ 1528 /* Try matching at position POS. */
1506 EMACS_INT this_pos = pos; 1529 ptrdiff_t this_pos = pos;
1507 EMACS_INT this_len = len; 1530 ptrdiff_t this_len = len;
1508 unsigned char *p = pat; 1531 unsigned char *p = pat;
1509 1532
1510 if (pos + len > lim) 1533 if (pos + len > lim)
@@ -1542,9 +1565,9 @@ simple_search (EMACS_INT n, unsigned char *pat,
1542 while (1) 1565 while (1)
1543 { 1566 {
1544 /* Try matching at position POS. */ 1567 /* Try matching at position POS. */
1545 EMACS_INT this_pos = pos; 1568 ptrdiff_t this_pos = pos;
1546 EMACS_INT this_pos_byte = pos_byte; 1569 ptrdiff_t this_pos_byte = pos_byte;
1547 EMACS_INT this_len = len; 1570 ptrdiff_t this_len = len;
1548 const unsigned char *p = pat + len_byte; 1571 const unsigned char *p = pat + len_byte;
1549 1572
1550 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte) 1573 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte)
@@ -1585,8 +1608,8 @@ simple_search (EMACS_INT n, unsigned char *pat,
1585 while (1) 1608 while (1)
1586 { 1609 {
1587 /* Try matching at position POS. */ 1610 /* Try matching at position POS. */
1588 EMACS_INT this_pos = pos - len; 1611 ptrdiff_t this_pos = pos - len;
1589 EMACS_INT this_len = len; 1612 ptrdiff_t this_len = len;
1590 unsigned char *p = pat; 1613 unsigned char *p = pat;
1591 1614
1592 if (this_pos < lim) 1615 if (this_pos < lim)
@@ -1650,18 +1673,18 @@ simple_search (EMACS_INT n, unsigned char *pat,
1650 1673
1651static EMACS_INT 1674static EMACS_INT
1652boyer_moore (EMACS_INT n, unsigned char *base_pat, 1675boyer_moore (EMACS_INT n, unsigned char *base_pat,
1653 EMACS_INT len_byte, 1676 ptrdiff_t len_byte,
1654 Lisp_Object trt, Lisp_Object inverse_trt, 1677 Lisp_Object trt, Lisp_Object inverse_trt,
1655 EMACS_INT pos_byte, EMACS_INT lim_byte, 1678 ptrdiff_t pos_byte, ptrdiff_t lim_byte,
1656 int char_base) 1679 int char_base)
1657{ 1680{
1658 int direction = ((n > 0) ? 1 : -1); 1681 int direction = ((n > 0) ? 1 : -1);
1659 register EMACS_INT dirlen; 1682 register ptrdiff_t dirlen;
1660 EMACS_INT limit; 1683 ptrdiff_t limit;
1661 int stride_for_teases = 0; 1684 int stride_for_teases = 0;
1662 int BM_tab[0400]; 1685 int BM_tab[0400];
1663 register unsigned char *cursor, *p_limit; 1686 register unsigned char *cursor, *p_limit;
1664 register EMACS_INT i; 1687 register ptrdiff_t i;
1665 register int j; 1688 register int j;
1666 unsigned char *pat, *pat_end; 1689 unsigned char *pat, *pat_end;
1667 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 1690 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -1813,7 +1836,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
1813 char if reverse) of pattern would align in a possible match. */ 1836 char if reverse) of pattern would align in a possible match. */
1814 while (n != 0) 1837 while (n != 0)
1815 { 1838 {
1816 EMACS_INT tail_end; 1839 ptrdiff_t tail_end;
1817 unsigned char *tail_end_ptr; 1840 unsigned char *tail_end_ptr;
1818 1841
1819 /* It's been reported that some (broken) compiler thinks that 1842 /* It's been reported that some (broken) compiler thinks that
@@ -1917,7 +1940,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
1917 cursor += dirlen - i - direction; /* fix cursor */ 1940 cursor += dirlen - i - direction; /* fix cursor */
1918 if (i + direction == 0) 1941 if (i + direction == 0)
1919 { 1942 {
1920 EMACS_INT position, start, end; 1943 ptrdiff_t position, start, end;
1921 1944
1922 cursor -= direction; 1945 cursor -= direction;
1923 1946
@@ -2009,7 +2032,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
2009 pos_byte += dirlen - i - direction; 2032 pos_byte += dirlen - i - direction;
2010 if (i + direction == 0) 2033 if (i + direction == 0)
2011 { 2034 {
2012 EMACS_INT position, start, end; 2035 ptrdiff_t position, start, end;
2013 pos_byte -= direction; 2036 pos_byte -= direction;
2014 2037
2015 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); 2038 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0);
@@ -2050,9 +2073,9 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
2050 Also clear out the match data for registers 1 and up. */ 2073 Also clear out the match data for registers 1 and up. */
2051 2074
2052static void 2075static void
2053set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes) 2076set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes)
2054{ 2077{
2055 int i; 2078 ptrdiff_t i;
2056 2079
2057 if (!NILP (Vinhibit_changing_match_data)) 2080 if (!NILP (Vinhibit_changing_match_data))
2058 return; 2081 return;
@@ -2245,14 +2268,14 @@ since only regular expressions have distinguished subexpressions. */)
2245 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp) 2268 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp)
2246{ 2269{
2247 enum { nochange, all_caps, cap_initial } case_action; 2270 enum { nochange, all_caps, cap_initial } case_action;
2248 register EMACS_INT pos, pos_byte; 2271 register ptrdiff_t pos, pos_byte;
2249 int some_multiletter_word; 2272 int some_multiletter_word;
2250 int some_lowercase; 2273 int some_lowercase;
2251 int some_uppercase; 2274 int some_uppercase;
2252 int some_nonuppercase_initial; 2275 int some_nonuppercase_initial;
2253 register int c, prevc; 2276 register int c, prevc;
2254 ptrdiff_t sub; 2277 ptrdiff_t sub;
2255 EMACS_INT opoint, newpoint; 2278 ptrdiff_t opoint, newpoint;
2256 2279
2257 CHECK_STRING (newtext); 2280 CHECK_STRING (newtext);
2258 2281
@@ -2295,7 +2318,7 @@ since only regular expressions have distinguished subexpressions. */)
2295 if (NILP (fixedcase)) 2318 if (NILP (fixedcase))
2296 { 2319 {
2297 /* Decide how to casify by examining the matched text. */ 2320 /* Decide how to casify by examining the matched text. */
2298 EMACS_INT last; 2321 ptrdiff_t last;
2299 2322
2300 pos = search_regs.start[sub]; 2323 pos = search_regs.start[sub];
2301 last = search_regs.end[sub]; 2324 last = search_regs.end[sub];
@@ -2382,19 +2405,19 @@ since only regular expressions have distinguished subexpressions. */)
2382 if desired. */ 2405 if desired. */
2383 if (NILP (literal)) 2406 if (NILP (literal))
2384 { 2407 {
2385 EMACS_INT lastpos = 0; 2408 ptrdiff_t lastpos = 0;
2386 EMACS_INT lastpos_byte = 0; 2409 ptrdiff_t lastpos_byte = 0;
2387 /* We build up the substituted string in ACCUM. */ 2410 /* We build up the substituted string in ACCUM. */
2388 Lisp_Object accum; 2411 Lisp_Object accum;
2389 Lisp_Object middle; 2412 Lisp_Object middle;
2390 EMACS_INT length = SBYTES (newtext); 2413 ptrdiff_t length = SBYTES (newtext);
2391 2414
2392 accum = Qnil; 2415 accum = Qnil;
2393 2416
2394 for (pos_byte = 0, pos = 0; pos_byte < length;) 2417 for (pos_byte = 0, pos = 0; pos_byte < length;)
2395 { 2418 {
2396 EMACS_INT substart = -1; 2419 ptrdiff_t substart = -1;
2397 EMACS_INT subend = 0; 2420 ptrdiff_t subend = 0;
2398 int delbackslash = 0; 2421 int delbackslash = 0;
2399 2422
2400 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); 2423 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
@@ -2410,8 +2433,8 @@ since only regular expressions have distinguished subexpressions. */)
2410 } 2433 }
2411 else if (c >= '1' && c <= '9') 2434 else if (c >= '1' && c <= '9')
2412 { 2435 {
2413 if (search_regs.start[c - '0'] >= 0 2436 if (c - '0' < search_regs.num_regs
2414 && c <= search_regs.num_regs + '0') 2437 && 0 <= search_regs.start[c - '0'])
2415 { 2438 {
2416 substart = search_regs.start[c - '0']; 2439 substart = search_regs.start[c - '0'];
2417 subend = search_regs.end[c - '0']; 2440 subend = search_regs.end[c - '0'];
@@ -2549,7 +2572,7 @@ since only regular expressions have distinguished subexpressions. */)
2549 2572
2550 if (c == '&') 2573 if (c == '&')
2551 idx = sub; 2574 idx = sub;
2552 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') 2575 else if (c >= '1' && c <= '9' && c - '0' < search_regs.num_regs)
2553 { 2576 {
2554 if (search_regs.start[c - '0'] >= 1) 2577 if (search_regs.start[c - '0'] >= 1)
2555 idx = c - '0'; 2578 idx = c - '0';
@@ -2601,7 +2624,7 @@ since only regular expressions have distinguished subexpressions. */)
2601 { 2624 {
2602 if (buf_multibyte) 2625 if (buf_multibyte)
2603 { 2626 {
2604 EMACS_INT nchars = 2627 ptrdiff_t nchars =
2605 multibyte_chars_in_text (substed, substed_len); 2628 multibyte_chars_in_text (substed, substed_len);
2606 2629
2607 newtext = make_multibyte_string ((char *) substed, nchars, 2630 newtext = make_multibyte_string ((char *) substed, nchars,
@@ -2627,10 +2650,10 @@ since only regular expressions have distinguished subexpressions. */)
2627 2650
2628 /* Adjust search data for this change. */ 2651 /* Adjust search data for this change. */
2629 { 2652 {
2630 EMACS_INT oldend = search_regs.end[sub]; 2653 ptrdiff_t oldend = search_regs.end[sub];
2631 EMACS_INT oldstart = search_regs.start[sub]; 2654 ptrdiff_t oldstart = search_regs.start[sub];
2632 EMACS_INT change = newpoint - search_regs.end[sub]; 2655 ptrdiff_t change = newpoint - search_regs.end[sub];
2633 int i; 2656 ptrdiff_t i;
2634 2657
2635 for (i = 0; i < search_regs.num_regs; i++) 2658 for (i = 0; i < search_regs.num_regs; i++)
2636 { 2659 {
@@ -2723,7 +2746,7 @@ Return value is undefined if the last search failed. */)
2723{ 2746{
2724 Lisp_Object tail, prev; 2747 Lisp_Object tail, prev;
2725 Lisp_Object *data; 2748 Lisp_Object *data;
2726 int i, len; 2749 ptrdiff_t i, len;
2727 2750
2728 if (!NILP (reseat)) 2751 if (!NILP (reseat))
2729 for (tail = reuse; CONSP (tail); tail = XCDR (tail)) 2752 for (tail = reuse; CONSP (tail); tail = XCDR (tail))
@@ -2744,7 +2767,7 @@ Return value is undefined if the last search failed. */)
2744 len = 0; 2767 len = 0;
2745 for (i = 0; i < search_regs.num_regs; i++) 2768 for (i = 0; i < search_regs.num_regs; i++)
2746 { 2769 {
2747 EMACS_INT start = search_regs.start[i]; 2770 ptrdiff_t start = search_regs.start[i];
2748 if (start >= 0) 2771 if (start >= 0)
2749 { 2772 {
2750 if (EQ (last_thing_searched, Qt) 2773 if (EQ (last_thing_searched, Qt)
@@ -2835,11 +2858,13 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2835 2858
2836 /* Allocate registers if they don't already exist. */ 2859 /* Allocate registers if they don't already exist. */
2837 { 2860 {
2838 ptrdiff_t length = XFASTINT (Flength (list)) / 2; 2861 EMACS_INT length = XFASTINT (Flength (list)) / 2;
2839 2862
2840 if (length > search_regs.num_regs) 2863 if (length > search_regs.num_regs)
2841 { 2864 {
2842 ptrdiff_t num_regs = search_regs.num_regs; 2865 ptrdiff_t num_regs = search_regs.num_regs;
2866 if (PTRDIFF_MAX < length)
2867 memory_full (SIZE_MAX);
2843 search_regs.start = 2868 search_regs.start =
2844 xpalloc (search_regs.start, &num_regs, length - num_regs, 2869 xpalloc (search_regs.start, &num_regs, length - num_regs,
2845 min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); 2870 min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t));
@@ -2869,7 +2894,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2869 } 2894 }
2870 else 2895 else
2871 { 2896 {
2872 EMACS_INT from; 2897 Lisp_Object from;
2873 Lisp_Object m; 2898 Lisp_Object m;
2874 2899
2875 m = marker; 2900 m = marker;
@@ -2882,7 +2907,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2882 } 2907 }
2883 2908
2884 CHECK_NUMBER_COERCE_MARKER (marker); 2909 CHECK_NUMBER_COERCE_MARKER (marker);
2885 from = XINT (marker); 2910 from = marker;
2886 2911
2887 if (!NILP (reseat) && MARKERP (m)) 2912 if (!NILP (reseat) && MARKERP (m))
2888 { 2913 {
@@ -2899,8 +2924,20 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2899 XSETFASTINT (marker, 0); 2924 XSETFASTINT (marker, 0);
2900 2925
2901 CHECK_NUMBER_COERCE_MARKER (marker); 2926 CHECK_NUMBER_COERCE_MARKER (marker);
2902 search_regs.start[i] = from; 2927 if ((XINT (from) < 0
2903 search_regs.end[i] = XINT (marker); 2928 ? TYPE_MINIMUM (regoff_t) <= XINT (from)
2929 : XINT (from) <= TYPE_MAXIMUM (regoff_t))
2930 && (XINT (marker) < 0
2931 ? TYPE_MINIMUM (regoff_t) <= XINT (marker)
2932 : XINT (marker) <= TYPE_MAXIMUM (regoff_t)))
2933 {
2934 search_regs.start[i] = XINT (from);
2935 search_regs.end[i] = XINT (marker);
2936 }
2937 else
2938 {
2939 search_regs.start[i] = -1;
2940 }
2904 2941
2905 if (!NILP (reseat) && MARKERP (m)) 2942 if (!NILP (reseat) && MARKERP (m))
2906 { 2943 {
diff --git a/src/sound.c b/src/sound.c
index 9b58c01453a..143653e48e4 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -232,11 +232,11 @@ struct sound_device
232 232
233 /* Return a preferred data size in bytes to be sent to write (below) 233 /* Return a preferred data size in bytes to be sent to write (below)
234 each time. 2048 is used if this is NULL. */ 234 each time. 2048 is used if this is NULL. */
235 EMACS_INT (* period_size) (struct sound_device *sd); 235 ptrdiff_t (* period_size) (struct sound_device *sd);
236 236
237 /* Write NYBTES bytes from BUFFER to device SD. */ 237 /* Write NYBTES bytes from BUFFER to device SD. */
238 void (* write) (struct sound_device *sd, const char *buffer, 238 void (* write) (struct sound_device *sd, const char *buffer,
239 EMACS_INT nbytes); 239 ptrdiff_t nbytes);
240 240
241 /* A place for devices to store additional data. */ 241 /* A place for devices to store additional data. */
242 void *data; 242 void *data;
@@ -288,7 +288,7 @@ static void vox_configure (struct sound_device *);
288static void vox_close (struct sound_device *sd); 288static void vox_close (struct sound_device *sd);
289static void vox_choose_format (struct sound_device *, struct sound *); 289static void vox_choose_format (struct sound_device *, struct sound *);
290static int vox_init (struct sound_device *); 290static int vox_init (struct sound_device *);
291static void vox_write (struct sound_device *, const char *, EMACS_INT); 291static void vox_write (struct sound_device *, const char *, ptrdiff_t);
292static void find_sound_type (struct sound *); 292static void find_sound_type (struct sound *);
293static u_int32_t le2hl (u_int32_t); 293static u_int32_t le2hl (u_int32_t);
294static u_int16_t le2hs (u_int16_t); 294static u_int16_t le2hs (u_int16_t);
@@ -597,9 +597,9 @@ wav_play (struct sound *s, struct sound_device *sd)
597 else 597 else
598 { 598 {
599 char *buffer; 599 char *buffer;
600 EMACS_INT nbytes = 0; 600 ptrdiff_t nbytes = 0;
601 EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048; 601 ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
602 EMACS_INT data_left = header->data_length; 602 ptrdiff_t data_left = header->data_length;
603 603
604 buffer = (char *) alloca (blksize); 604 buffer = (char *) alloca (blksize);
605 lseek (s->fd, sizeof *header, SEEK_SET); 605 lseek (s->fd, sizeof *header, SEEK_SET);
@@ -687,9 +687,9 @@ au_play (struct sound *s, struct sound_device *sd)
687 SBYTES (s->data) - header->data_offset); 687 SBYTES (s->data) - header->data_offset);
688 else 688 else
689 { 689 {
690 EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048; 690 ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
691 char *buffer; 691 char *buffer;
692 EMACS_INT nbytes; 692 ptrdiff_t nbytes;
693 693
694 /* Seek */ 694 /* Seek */
695 lseek (s->fd, header->data_offset, SEEK_SET); 695 lseek (s->fd, header->data_offset, SEEK_SET);
@@ -892,7 +892,7 @@ vox_init (struct sound_device *sd)
892/* Write NBYTES bytes from BUFFER to device SD. */ 892/* Write NBYTES bytes from BUFFER to device SD. */
893 893
894static void 894static void
895vox_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes) 895vox_write (struct sound_device *sd, const char *buffer, ptrdiff_t nbytes)
896{ 896{
897 if (emacs_write (sd->fd, buffer, nbytes) != nbytes) 897 if (emacs_write (sd->fd, buffer, nbytes) != nbytes)
898 sound_perror ("Error writing to sound device"); 898 sound_perror ("Error writing to sound device");
@@ -953,7 +953,7 @@ alsa_open (struct sound_device *sd)
953 alsa_sound_perror (file, err); 953 alsa_sound_perror (file, err);
954} 954}
955 955
956static EMACS_INT 956static ptrdiff_t
957alsa_period_size (struct sound_device *sd) 957alsa_period_size (struct sound_device *sd)
958{ 958{
959 struct alsa_params *p = (struct alsa_params *) sd->data; 959 struct alsa_params *p = (struct alsa_params *) sd->data;
@@ -1156,13 +1156,13 @@ alsa_choose_format (struct sound_device *sd, struct sound *s)
1156/* Write NBYTES bytes from BUFFER to device SD. */ 1156/* Write NBYTES bytes from BUFFER to device SD. */
1157 1157
1158static void 1158static void
1159alsa_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes) 1159alsa_write (struct sound_device *sd, const char *buffer, ptrdiff_t nbytes)
1160{ 1160{
1161 struct alsa_params *p = (struct alsa_params *) sd->data; 1161 struct alsa_params *p = (struct alsa_params *) sd->data;
1162 1162
1163 /* The the third parameter to snd_pcm_writei is frames, not bytes. */ 1163 /* The the third parameter to snd_pcm_writei is frames, not bytes. */
1164 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels; 1164 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
1165 EMACS_INT nwritten = 0; 1165 ptrdiff_t nwritten = 0;
1166 int err; 1166 int err;
1167 1167
1168 while (nwritten < nbytes) 1168 while (nwritten < nbytes)
@@ -1349,7 +1349,7 @@ Internal use only, use `play-sound' instead. */)
1349 (Lisp_Object sound) 1349 (Lisp_Object sound)
1350{ 1350{
1351 Lisp_Object attrs[SOUND_ATTR_SENTINEL]; 1351 Lisp_Object attrs[SOUND_ATTR_SENTINEL];
1352 int count = SPECPDL_INDEX (); 1352 ptrdiff_t count = SPECPDL_INDEX ();
1353 1353
1354#ifndef WINDOWSNT 1354#ifndef WINDOWSNT
1355 Lisp_Object file; 1355 Lisp_Object file;
diff --git a/src/syntax.c b/src/syntax.c
index 7a0e0fd7c52..71da13e7a66 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -111,18 +111,18 @@ Lisp_Object syntax_temp;
111 111
112struct lisp_parse_state 112struct lisp_parse_state
113 { 113 {
114 int depth; /* Depth at end of parsing. */ 114 EMACS_INT depth; /* Depth at end of parsing. */
115 int instring; /* -1 if not within string, else desired terminator. */ 115 int instring; /* -1 if not within string, else desired terminator. */
116 int incomment; /* -1 if in unnestable comment else comment nesting */ 116 EMACS_INT incomment; /* -1 if in unnestable comment else comment nesting */
117 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ 117 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
118 int quoted; /* Nonzero if just after an escape char at end of parsing */ 118 int quoted; /* Nonzero if just after an escape char at end of parsing */
119 int mindepth; /* Minimum depth seen while scanning. */ 119 EMACS_INT mindepth; /* Minimum depth seen while scanning. */
120 /* Char number of most recent start-of-expression at current level */ 120 /* Char number of most recent start-of-expression at current level */
121 EMACS_INT thislevelstart; 121 ptrdiff_t thislevelstart;
122 /* Char number of start of containing expression */ 122 /* Char number of start of containing expression */
123 EMACS_INT prevlevelstart; 123 ptrdiff_t prevlevelstart;
124 EMACS_INT location; /* Char number at which parsing stopped. */ 124 ptrdiff_t location; /* Char number at which parsing stopped. */
125 EMACS_INT comstr_start; /* Position of last comment/string starter. */ 125 ptrdiff_t comstr_start; /* Position of last comment/string starter. */
126 Lisp_Object levelstarts; /* Char numbers of starts-of-expression 126 Lisp_Object levelstarts; /* Char numbers of starts-of-expression
127 of levels (starting from outermost). */ 127 of levels (starting from outermost). */
128 }; 128 };
@@ -135,12 +135,12 @@ struct lisp_parse_state
135 find_start_begv is the BEGV value when it was found. 135 find_start_begv is the BEGV value when it was found.
136 find_start_modiff is the value of MODIFF when it was found. */ 136 find_start_modiff is the value of MODIFF when it was found. */
137 137
138static EMACS_INT find_start_pos; 138static ptrdiff_t find_start_pos;
139static EMACS_INT find_start_value; 139static ptrdiff_t find_start_value;
140static EMACS_INT find_start_value_byte; 140static ptrdiff_t find_start_value_byte;
141static struct buffer *find_start_buffer; 141static struct buffer *find_start_buffer;
142static EMACS_INT find_start_begv; 142static ptrdiff_t find_start_begv;
143static int find_start_modiff; 143static EMACS_INT find_start_modiff;
144 144
145 145
146static Lisp_Object Fsyntax_table_p (Lisp_Object); 146static Lisp_Object Fsyntax_table_p (Lisp_Object);
@@ -148,7 +148,7 @@ static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int);
148static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object); 148static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object);
149static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int); 149static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int);
150static void scan_sexps_forward (struct lisp_parse_state *, 150static void scan_sexps_forward (struct lisp_parse_state *,
151 EMACS_INT, EMACS_INT, EMACS_INT, int, 151 ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT,
152 int, Lisp_Object, int); 152 int, Lisp_Object, int);
153static int in_classes (int, Lisp_Object); 153static int in_classes (int, Lisp_Object);
154 154
@@ -177,7 +177,7 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */
177 start/end of OBJECT. */ 177 start/end of OBJECT. */
178 178
179void 179void
180update_syntax_table (EMACS_INT charpos, EMACS_INT count, int init, 180update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
181 Lisp_Object object) 181 Lisp_Object object)
182{ 182{
183 Lisp_Object tmp_table; 183 Lisp_Object tmp_table;
@@ -339,12 +339,12 @@ update_syntax_table (EMACS_INT charpos, EMACS_INT count, int init,
339 or after. On return global syntax data is good for lookup at CHARPOS. */ 339 or after. On return global syntax data is good for lookup at CHARPOS. */
340 340
341static int 341static int
342char_quoted (EMACS_INT charpos, EMACS_INT bytepos) 342char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos)
343{ 343{
344 register enum syntaxcode code; 344 register enum syntaxcode code;
345 register EMACS_INT beg = BEGV; 345 register ptrdiff_t beg = BEGV;
346 register int quoted = 0; 346 register int quoted = 0;
347 EMACS_INT orig = charpos; 347 ptrdiff_t orig = charpos;
348 348
349 while (charpos > beg) 349 while (charpos > beg)
350 { 350 {
@@ -367,8 +367,8 @@ char_quoted (EMACS_INT charpos, EMACS_INT bytepos)
367/* Return the bytepos one character before BYTEPOS. 367/* Return the bytepos one character before BYTEPOS.
368 We assume that BYTEPOS is not at the start of the buffer. */ 368 We assume that BYTEPOS is not at the start of the buffer. */
369 369
370static inline EMACS_INT 370static inline ptrdiff_t
371dec_bytepos (EMACS_INT bytepos) 371dec_bytepos (ptrdiff_t bytepos)
372{ 372{
373 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 373 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
374 return bytepos - 1; 374 return bytepos - 1;
@@ -391,10 +391,10 @@ dec_bytepos (EMACS_INT bytepos)
391 valid on return from the subroutine, so the caller should explicitly 391 valid on return from the subroutine, so the caller should explicitly
392 update the global data. */ 392 update the global data. */
393 393
394static EMACS_INT 394static ptrdiff_t
395find_defun_start (EMACS_INT pos, EMACS_INT pos_byte) 395find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte)
396{ 396{
397 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 397 ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
398 398
399 if (!open_paren_in_column_0_is_defun_start) 399 if (!open_paren_in_column_0_is_defun_start)
400 { 400 {
@@ -461,7 +461,7 @@ find_defun_start (EMACS_INT pos, EMACS_INT pos_byte)
461/* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */ 461/* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
462 462
463static int 463static int
464prev_char_comend_first (EMACS_INT pos, EMACS_INT pos_byte) 464prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte)
465{ 465{
466 int c, val; 466 int c, val;
467 467
@@ -503,7 +503,7 @@ prev_char_comend_first (EMACS_INT pos, EMACS_INT pos_byte)
503 the returned value (or at FROM, if the search was not successful). */ 503 the returned value (or at FROM, if the search was not successful). */
504 504
505static int 505static int
506back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested, int comstyle, EMACS_INT *charpos_ptr, EMACS_INT *bytepos_ptr) 506back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested, int comstyle, ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr)
507{ 507{
508 /* Look back, counting the parity of string-quotes, 508 /* Look back, counting the parity of string-quotes,
509 and recording the comment-starters seen. 509 and recording the comment-starters seen.
@@ -522,14 +522,14 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
522 inside another comment). 522 inside another comment).
523 Test case: { a (* b } c (* d *) */ 523 Test case: { a (* b } c (* d *) */
524 int comment_lossage = 0; 524 int comment_lossage = 0;
525 EMACS_INT comment_end = from; 525 ptrdiff_t comment_end = from;
526 EMACS_INT comment_end_byte = from_byte; 526 ptrdiff_t comment_end_byte = from_byte;
527 EMACS_INT comstart_pos = 0; 527 ptrdiff_t comstart_pos = 0;
528 EMACS_INT comstart_byte IF_LINT (= 0); 528 ptrdiff_t comstart_byte IF_LINT (= 0);
529 /* Place where the containing defun starts, 529 /* Place where the containing defun starts,
530 or 0 if we didn't come across it yet. */ 530 or 0 if we didn't come across it yet. */
531 EMACS_INT defun_start = 0; 531 ptrdiff_t defun_start = 0;
532 EMACS_INT defun_start_byte = 0; 532 ptrdiff_t defun_start_byte = 0;
533 register enum syntaxcode code; 533 register enum syntaxcode code;
534 int nesting = 1; /* current comment nesting */ 534 int nesting = 1; /* current comment nesting */
535 int c; 535 int c;
@@ -543,7 +543,7 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
543 that determines quote parity to the comment-end. */ 543 that determines quote parity to the comment-end. */
544 while (from != stop) 544 while (from != stop)
545 { 545 {
546 EMACS_INT temp_byte; 546 ptrdiff_t temp_byte;
547 int prev_syntax, com2start, com2end; 547 int prev_syntax, com2start, com2end;
548 int comstart; 548 int comstart;
549 549
@@ -581,7 +581,7 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
581 have %..\n and %{..}%. */ 581 have %..\n and %{..}%. */
582 if (from > stop && (com2end || comstart)) 582 if (from > stop && (com2end || comstart))
583 { 583 {
584 EMACS_INT next = from, next_byte = from_byte; 584 ptrdiff_t next = from, next_byte = from_byte;
585 int next_c, next_syntax; 585 int next_c, next_syntax;
586 DEC_BOTH (next, next_byte); 586 DEC_BOTH (next, next_byte);
587 UPDATE_SYNTAX_TABLE_BACKWARD (next); 587 UPDATE_SYNTAX_TABLE_BACKWARD (next);
@@ -737,7 +737,8 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
737 { 737 {
738 scan_sexps_forward (&state, 738 scan_sexps_forward (&state,
739 defun_start, defun_start_byte, 739 defun_start, defun_start_byte,
740 comment_end, -10000, 0, Qnil, 0); 740 comment_end, TYPE_MINIMUM (EMACS_INT),
741 0, Qnil, 0);
741 defun_start = comment_end; 742 defun_start = comment_end;
742 if (state.incomment == (comnested ? 1 : -1) 743 if (state.incomment == (comnested ? 1 : -1)
743 && state.comstyle == comstyle) 744 && state.comstyle == comstyle)
@@ -1099,13 +1100,13 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1099 first = XCAR (value); 1100 first = XCAR (value);
1100 match_lisp = XCDR (value); 1101 match_lisp = XCDR (value);
1101 1102
1102 if (!INTEGERP (first) || !(NILP (match_lisp) || INTEGERP (match_lisp))) 1103 if (!INTEGERP (first) || !(NILP (match_lisp) || CHARACTERP (match_lisp)))
1103 { 1104 {
1104 insert_string ("invalid"); 1105 insert_string ("invalid");
1105 return syntax; 1106 return syntax;
1106 } 1107 }
1107 1108
1108 syntax_code = XINT (first); 1109 syntax_code = XINT (first) & INT_MAX;
1109 code = (enum syntaxcode) (syntax_code & 0377); 1110 code = (enum syntaxcode) (syntax_code & 0377);
1110 start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code); 1111 start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code);
1111 start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);; 1112 start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);;
@@ -1223,12 +1224,12 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1223 If that many words cannot be found before the end of the buffer, return 0. 1224 If that many words cannot be found before the end of the buffer, return 0.
1224 COUNT negative means scan backward and stop at word beginning. */ 1225 COUNT negative means scan backward and stop at word beginning. */
1225 1226
1226EMACS_INT 1227ptrdiff_t
1227scan_words (register EMACS_INT from, register EMACS_INT count) 1228scan_words (register ptrdiff_t from, register EMACS_INT count)
1228{ 1229{
1229 register EMACS_INT beg = BEGV; 1230 register ptrdiff_t beg = BEGV;
1230 register EMACS_INT end = ZV; 1231 register ptrdiff_t end = ZV;
1231 register EMACS_INT from_byte = CHAR_TO_BYTE (from); 1232 register ptrdiff_t from_byte = CHAR_TO_BYTE (from);
1232 register enum syntaxcode code; 1233 register enum syntaxcode code;
1233 int ch0, ch1; 1234 int ch0, ch1;
1234 Lisp_Object func, pos; 1235 Lisp_Object func, pos;
@@ -1263,7 +1264,7 @@ scan_words (register EMACS_INT from, register EMACS_INT count)
1263 if (! NILP (Ffboundp (func))) 1264 if (! NILP (Ffboundp (func)))
1264 { 1265 {
1265 pos = call2 (func, make_number (from - 1), make_number (end)); 1266 pos = call2 (func, make_number (from - 1), make_number (end));
1266 if (INTEGERP (pos) && XINT (pos) > from) 1267 if (INTEGERP (pos) && from < XINT (pos) && XINT (pos) <= ZV)
1267 { 1268 {
1268 from = XINT (pos); 1269 from = XINT (pos);
1269 from_byte = CHAR_TO_BYTE (from); 1270 from_byte = CHAR_TO_BYTE (from);
@@ -1313,7 +1314,7 @@ scan_words (register EMACS_INT from, register EMACS_INT count)
1313 if (! NILP (Ffboundp (func))) 1314 if (! NILP (Ffboundp (func)))
1314 { 1315 {
1315 pos = call2 (func, make_number (from), make_number (beg)); 1316 pos = call2 (func, make_number (from), make_number (beg));
1316 if (INTEGERP (pos) && XINT (pos) < from) 1317 if (INTEGERP (pos) && BEGV <= XINT (pos) && XINT (pos) < from)
1317 { 1318 {
1318 from = XINT (pos); 1319 from = XINT (pos);
1319 from_byte = CHAR_TO_BYTE (from); 1320 from_byte = CHAR_TO_BYTE (from);
@@ -1357,7 +1358,7 @@ and the function returns nil. Field boundaries are not noticed if
1357 (Lisp_Object arg) 1358 (Lisp_Object arg)
1358{ 1359{
1359 Lisp_Object tmp; 1360 Lisp_Object tmp;
1360 int orig_val, val; 1361 ptrdiff_t orig_val, val;
1361 1362
1362 if (NILP (arg)) 1363 if (NILP (arg))
1363 XSETFASTINT (arg, 1); 1364 XSETFASTINT (arg, 1);
@@ -1432,14 +1433,14 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1432 int *char_ranges IF_LINT (= NULL); 1433 int *char_ranges IF_LINT (= NULL);
1433 int n_char_ranges = 0; 1434 int n_char_ranges = 0;
1434 int negate = 0; 1435 int negate = 0;
1435 register EMACS_INT i, i_byte; 1436 register ptrdiff_t i, i_byte;
1436 /* Set to 1 if the current buffer is multibyte and the region 1437 /* Set to 1 if the current buffer is multibyte and the region
1437 contains non-ASCII chars. */ 1438 contains non-ASCII chars. */
1438 int multibyte; 1439 int multibyte;
1439 /* Set to 1 if STRING is multibyte and it contains non-ASCII 1440 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1440 chars. */ 1441 chars. */
1441 int string_multibyte; 1442 int string_multibyte;
1442 EMACS_INT size_byte; 1443 ptrdiff_t size_byte;
1443 const unsigned char *str; 1444 const unsigned char *str;
1444 int len; 1445 int len;
1445 Lisp_Object iso_classes; 1446 Lisp_Object iso_classes;
@@ -1753,9 +1754,9 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1753 } 1754 }
1754 1755
1755 { 1756 {
1756 EMACS_INT start_point = PT; 1757 ptrdiff_t start_point = PT;
1757 EMACS_INT pos = PT; 1758 ptrdiff_t pos = PT;
1758 EMACS_INT pos_byte = PT_BYTE; 1759 ptrdiff_t pos_byte = PT_BYTE;
1759 unsigned char *p = PT_ADDR, *endp, *stop; 1760 unsigned char *p = PT_ADDR, *endp, *stop;
1760 1761
1761 if (forwardp) 1762 if (forwardp)
@@ -1925,9 +1926,9 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim)
1925 register unsigned int c; 1926 register unsigned int c;
1926 unsigned char fastmap[0400]; 1927 unsigned char fastmap[0400];
1927 int negate = 0; 1928 int negate = 0;
1928 register EMACS_INT i, i_byte; 1929 register ptrdiff_t i, i_byte;
1929 int multibyte; 1930 int multibyte;
1930 EMACS_INT size_byte; 1931 ptrdiff_t size_byte;
1931 unsigned char *str; 1932 unsigned char *str;
1932 1933
1933 CHECK_STRING (string); 1934 CHECK_STRING (string);
@@ -1980,9 +1981,9 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim)
1980 fastmap[i] ^= 1; 1981 fastmap[i] ^= 1;
1981 1982
1982 { 1983 {
1983 EMACS_INT start_point = PT; 1984 ptrdiff_t start_point = PT;
1984 EMACS_INT pos = PT; 1985 ptrdiff_t pos = PT;
1985 EMACS_INT pos_byte = PT_BYTE; 1986 ptrdiff_t pos_byte = PT_BYTE;
1986 unsigned char *p = PT_ADDR, *endp, *stop; 1987 unsigned char *p = PT_ADDR, *endp, *stop;
1987 1988
1988 if (forwardp) 1989 if (forwardp)
@@ -2135,10 +2136,10 @@ in_classes (int c, Lisp_Object iso_classes)
2135 remains valid for forward search starting at the returned position. */ 2136 remains valid for forward search starting at the returned position. */
2136 2137
2137static int 2138static int
2138forw_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, 2139forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
2139 int nesting, int style, int prev_syntax, 2140 EMACS_INT nesting, int style, int prev_syntax,
2140 EMACS_INT *charpos_ptr, EMACS_INT *bytepos_ptr, 2141 ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr,
2141 int *incomment_ptr) 2142 EMACS_INT *incomment_ptr)
2142{ 2143{
2143 register int c, c1; 2144 register int c, c1;
2144 register enum syntaxcode code; 2145 register enum syntaxcode code;
@@ -2240,17 +2241,17 @@ If COUNT comments are found as expected, with nothing except whitespace
2240between them, return t; otherwise return nil. */) 2241between them, return t; otherwise return nil. */)
2241 (Lisp_Object count) 2242 (Lisp_Object count)
2242{ 2243{
2243 register EMACS_INT from; 2244 register ptrdiff_t from;
2244 EMACS_INT from_byte; 2245 ptrdiff_t from_byte;
2245 register EMACS_INT stop; 2246 register ptrdiff_t stop;
2246 register int c, c1; 2247 register int c, c1;
2247 register enum syntaxcode code; 2248 register enum syntaxcode code;
2248 int comstyle = 0; /* style of comment encountered */ 2249 int comstyle = 0; /* style of comment encountered */
2249 int comnested = 0; /* whether the comment is nestable or not */ 2250 int comnested = 0; /* whether the comment is nestable or not */
2250 int found; 2251 int found;
2251 EMACS_INT count1; 2252 EMACS_INT count1;
2252 EMACS_INT out_charpos, out_bytepos; 2253 ptrdiff_t out_charpos, out_bytepos;
2253 int dummy; 2254 EMACS_INT dummy;
2254 2255
2255 CHECK_NUMBER (count); 2256 CHECK_NUMBER (count);
2256 count1 = XINT (count); 2257 count1 = XINT (count);
@@ -2374,7 +2375,7 @@ between them, return t; otherwise return nil. */)
2374 { 2375 {
2375 /* Skip until first preceding unquoted comment_fence. */ 2376 /* Skip until first preceding unquoted comment_fence. */
2376 int fence_found = 0; 2377 int fence_found = 0;
2377 EMACS_INT ini = from, ini_byte = from_byte; 2378 ptrdiff_t ini = from, ini_byte = from_byte;
2378 2379
2379 while (1) 2380 while (1)
2380 { 2381 {
@@ -2457,21 +2458,22 @@ static Lisp_Object
2457scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpflag) 2458scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpflag)
2458{ 2459{
2459 Lisp_Object val; 2460 Lisp_Object val;
2460 register EMACS_INT stop = count > 0 ? ZV : BEGV; 2461 register ptrdiff_t stop = count > 0 ? ZV : BEGV;
2461 register int c, c1; 2462 register int c, c1;
2462 int stringterm; 2463 int stringterm;
2463 int quoted; 2464 int quoted;
2464 int mathexit = 0; 2465 int mathexit = 0;
2465 register enum syntaxcode code, temp_code; 2466 register enum syntaxcode code, temp_code;
2466 int min_depth = depth; /* Err out if depth gets less than this. */ 2467 EMACS_INT min_depth = depth; /* Err out if depth gets less than this. */
2467 int comstyle = 0; /* style of comment encountered */ 2468 int comstyle = 0; /* style of comment encountered */
2468 int comnested = 0; /* whether the comment is nestable or not */ 2469 int comnested = 0; /* whether the comment is nestable or not */
2469 EMACS_INT temp_pos; 2470 ptrdiff_t temp_pos;
2470 EMACS_INT last_good = from; 2471 EMACS_INT last_good = from;
2471 int found; 2472 int found;
2472 EMACS_INT from_byte; 2473 ptrdiff_t from_byte;
2473 EMACS_INT out_bytepos, out_charpos; 2474 ptrdiff_t out_bytepos, out_charpos;
2474 int temp, dummy; 2475 int temp;
2476 EMACS_INT dummy;
2475 int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol; 2477 int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol;
2476 2478
2477 if (depth > 0) min_depth = 0; 2479 if (depth > 0) min_depth = 0;
@@ -2895,11 +2897,11 @@ DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, Sbackward_prefix_chars,
2895This includes chars with "quote" or "prefix" syntax (' or p). */) 2897This includes chars with "quote" or "prefix" syntax (' or p). */)
2896 (void) 2898 (void)
2897{ 2899{
2898 EMACS_INT beg = BEGV; 2900 ptrdiff_t beg = BEGV;
2899 EMACS_INT opoint = PT; 2901 ptrdiff_t opoint = PT;
2900 EMACS_INT opoint_byte = PT_BYTE; 2902 ptrdiff_t opoint_byte = PT_BYTE;
2901 EMACS_INT pos = PT; 2903 ptrdiff_t pos = PT;
2902 EMACS_INT pos_byte = PT_BYTE; 2904 ptrdiff_t pos_byte = PT_BYTE;
2903 int c; 2905 int c;
2904 2906
2905 if (pos <= beg) 2907 if (pos <= beg)
@@ -2940,8 +2942,8 @@ This includes chars with "quote" or "prefix" syntax (' or p). */)
2940 2942
2941static void 2943static void
2942scan_sexps_forward (struct lisp_parse_state *stateptr, 2944scan_sexps_forward (struct lisp_parse_state *stateptr,
2943 EMACS_INT from, EMACS_INT from_byte, EMACS_INT end, 2945 ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t end,
2944 int targetdepth, int stopbefore, 2946 EMACS_INT targetdepth, int stopbefore,
2945 Lisp_Object oldstate, int commentstop) 2947 Lisp_Object oldstate, int commentstop)
2946{ 2948{
2947 struct lisp_parse_state state; 2949 struct lisp_parse_state state;
@@ -2949,23 +2951,23 @@ scan_sexps_forward (struct lisp_parse_state *stateptr,
2949 register enum syntaxcode code; 2951 register enum syntaxcode code;
2950 int c1; 2952 int c1;
2951 int comnested; 2953 int comnested;
2952 struct level { int last, prev; }; 2954 struct level { ptrdiff_t last, prev; };
2953 struct level levelstart[100]; 2955 struct level levelstart[100];
2954 register struct level *curlevel = levelstart; 2956 register struct level *curlevel = levelstart;
2955 struct level *endlevel = levelstart + 100; 2957 struct level *endlevel = levelstart + 100;
2956 register int depth; /* Paren depth of current scanning location. 2958 register EMACS_INT depth; /* Paren depth of current scanning location.
2957 level - levelstart equals this except 2959 level - levelstart equals this except
2958 when the depth becomes negative. */ 2960 when the depth becomes negative. */
2959 int mindepth; /* Lowest DEPTH value seen. */ 2961 EMACS_INT mindepth; /* Lowest DEPTH value seen. */
2960 int start_quoted = 0; /* Nonzero means starting after a char quote */ 2962 int start_quoted = 0; /* Nonzero means starting after a char quote */
2961 Lisp_Object tem; 2963 Lisp_Object tem;
2962 EMACS_INT prev_from; /* Keep one character before FROM. */ 2964 ptrdiff_t prev_from; /* Keep one character before FROM. */
2963 EMACS_INT prev_from_byte; 2965 ptrdiff_t prev_from_byte;
2964 int prev_from_syntax; 2966 int prev_from_syntax;
2965 int boundary_stop = commentstop == -1; 2967 int boundary_stop = commentstop == -1;
2966 int nofence; 2968 int nofence;
2967 int found; 2969 int found;
2968 EMACS_INT out_bytepos, out_charpos; 2970 ptrdiff_t out_bytepos, out_charpos;
2969 int temp; 2971 int temp;
2970 2972
2971 prev_from = from; 2973 prev_from = from;
@@ -3009,7 +3011,7 @@ do { prev_from = from; \
3009 tem = Fcar (oldstate); 3011 tem = Fcar (oldstate);
3010 /* Check whether we are inside string_fence-style string: */ 3012 /* Check whether we are inside string_fence-style string: */
3011 state.instring = (!NILP (tem) 3013 state.instring = (!NILP (tem)
3012 ? (INTEGERP (tem) ? XINT (tem) : ST_STRING_STYLE) 3014 ? (CHARACTERP (tem) ? XFASTINT (tem) : ST_STRING_STYLE)
3013 : -1); 3015 : -1);
3014 3016
3015 oldstate = Fcdr (oldstate); 3017 oldstate = Fcdr (oldstate);
@@ -3029,19 +3031,21 @@ do { prev_from = from; \
3029 tem = Fcar (oldstate); 3031 tem = Fcar (oldstate);
3030 state.comstyle = (NILP (tem) 3032 state.comstyle = (NILP (tem)
3031 ? 0 3033 ? 0
3032 : (EQ (tem, Qsyntax_table) 3034 : (RANGED_INTEGERP (0, tem, ST_COMMENT_STYLE)
3033 ? ST_COMMENT_STYLE 3035 ? XINT (tem)
3034 : INTEGERP (tem) ? XINT (tem) : 1)); 3036 : ST_COMMENT_STYLE));
3035 3037
3036 oldstate = Fcdr (oldstate); 3038 oldstate = Fcdr (oldstate);
3037 tem = Fcar (oldstate); 3039 tem = Fcar (oldstate);
3038 state.comstr_start = NILP (tem) ? -1 : XINT (tem) ; 3040 state.comstr_start =
3041 RANGED_INTEGERP (PTRDIFF_MIN, tem, PTRDIFF_MAX) ? XINT (tem) : -1;
3039 oldstate = Fcdr (oldstate); 3042 oldstate = Fcdr (oldstate);
3040 tem = Fcar (oldstate); 3043 tem = Fcar (oldstate);
3041 while (!NILP (tem)) /* >= second enclosing sexps. */ 3044 while (!NILP (tem)) /* >= second enclosing sexps. */
3042 { 3045 {
3043 /* curlevel++->last ran into compiler bug on Apollo */ 3046 Lisp_Object temhd = Fcar (tem);
3044 curlevel->last = XINT (Fcar (tem)); 3047 if (RANGED_INTEGERP (PTRDIFF_MIN, temhd, PTRDIFF_MAX))
3048 curlevel->last = XINT (temhd);
3045 if (++curlevel == endlevel) 3049 if (++curlevel == endlevel)
3046 curlevel--; /* error ("Nesting too deep for parser"); */ 3050 curlevel--; /* error ("Nesting too deep for parser"); */
3047 curlevel->prev = -1; 3051 curlevel->prev = -1;
@@ -3314,14 +3318,14 @@ Fourth arg STOPBEFORE non-nil means stop when come to
3314 any character that starts a sexp. 3318 any character that starts a sexp.
3315Fifth arg OLDSTATE is a list like what this function returns. 3319Fifth arg OLDSTATE is a list like what this function returns.
3316 It is used to initialize the state of the parse. Elements number 1, 2, 6 3320 It is used to initialize the state of the parse. Elements number 1, 2, 6
3317 and 8 are ignored. 3321 are ignored.
3318Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. 3322Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3319 If it is symbol `syntax-table', stop after the start of a comment or a 3323 If it is symbol `syntax-table', stop after the start of a comment or a
3320 string, or after end of a comment or a string. */) 3324 string, or after end of a comment or a string. */)
3321 (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop) 3325 (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop)
3322{ 3326{
3323 struct lisp_parse_state state; 3327 struct lisp_parse_state state;
3324 int target; 3328 EMACS_INT target;
3325 3329
3326 if (!NILP (targetdepth)) 3330 if (!NILP (targetdepth))
3327 { 3331 {
@@ -3329,7 +3333,7 @@ Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3329 target = XINT (targetdepth); 3333 target = XINT (targetdepth);
3330 } 3334 }
3331 else 3335 else
3332 target = -100000; /* We won't reach this depth */ 3336 target = TYPE_MINIMUM (EMACS_INT); /* We won't reach this depth */
3333 3337
3334 validate_region (&from, &to); 3338 validate_region (&from, &to);
3335 scan_sexps_forward (&state, XINT (from), CHAR_TO_BYTE (XINT (from)), 3339 scan_sexps_forward (&state, XINT (from), CHAR_TO_BYTE (XINT (from)),
diff --git a/src/syntax.h b/src/syntax.h
index a5d7ec5aced..6edb1585795 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21 21
22extern void update_syntax_table (EMACS_INT, EMACS_INT, int, Lisp_Object); 22extern void update_syntax_table (ptrdiff_t, EMACS_INT, int, Lisp_Object);
23 23
24/* The standard syntax table is stored where it will automatically 24/* The standard syntax table is stored where it will automatically
25 be used in all new buffers. */ 25 be used in all new buffers. */
@@ -258,7 +258,7 @@ do \
258 else if (EQ (gl_state.object, Qt)) \ 258 else if (EQ (gl_state.object, Qt)) \
259 { \ 259 { \
260 gl_state.b_property = 0; \ 260 gl_state.b_property = 0; \
261 gl_state.e_property = MOST_POSITIVE_FIXNUM; \ 261 gl_state.e_property = PTRDIFF_MAX; \
262 gl_state.offset = 0; \ 262 gl_state.offset = 0; \
263 } \ 263 } \
264 else \ 264 else \
@@ -277,15 +277,15 @@ while (0)
277struct gl_state_s 277struct gl_state_s
278{ 278{
279 Lisp_Object object; /* The object we are scanning. */ 279 Lisp_Object object; /* The object we are scanning. */
280 EMACS_INT start; /* Where to stop. */ 280 ptrdiff_t start; /* Where to stop. */
281 EMACS_INT stop; /* Where to stop. */ 281 ptrdiff_t stop; /* Where to stop. */
282 int use_global; /* Whether to use global_code 282 int use_global; /* Whether to use global_code
283 or c_s_t. */ 283 or c_s_t. */
284 Lisp_Object global_code; /* Syntax code of current char. */ 284 Lisp_Object global_code; /* Syntax code of current char. */
285 Lisp_Object current_syntax_table; /* Syntax table for current pos. */ 285 Lisp_Object current_syntax_table; /* Syntax table for current pos. */
286 Lisp_Object old_prop; /* Syntax-table prop at prev pos. */ 286 Lisp_Object old_prop; /* Syntax-table prop at prev pos. */
287 EMACS_INT b_property; /* First index where c_s_t is valid. */ 287 ptrdiff_t b_property; /* First index where c_s_t is valid. */
288 EMACS_INT e_property; /* First index where c_s_t is 288 ptrdiff_t e_property; /* First index where c_s_t is
289 not valid. */ 289 not valid. */
290 INTERVAL forward_i; /* Where to start lookup on forward */ 290 INTERVAL forward_i; /* Where to start lookup on forward */
291 INTERVAL backward_i; /* or backward movement. The 291 INTERVAL backward_i; /* or backward movement. The
@@ -295,8 +295,8 @@ struct gl_state_s
295 intervals too, depending 295 intervals too, depending
296 on: */ 296 on: */
297 /* Offset for positions specified to UPDATE_SYNTAX_TABLE. */ 297 /* Offset for positions specified to UPDATE_SYNTAX_TABLE. */
298 EMACS_INT offset; 298 ptrdiff_t offset;
299}; 299};
300 300
301extern struct gl_state_s gl_state; 301extern struct gl_state_s gl_state;
302extern EMACS_INT scan_words (EMACS_INT, EMACS_INT); 302extern ptrdiff_t scan_words (ptrdiff_t, EMACS_INT);
diff --git a/src/sysdep.c b/src/sysdep.c
index 6d1ed3aeb86..a82f802a785 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -304,7 +304,7 @@ int wait_debugging EXTERNALLY_VISIBLE;
304#ifndef MSDOS 304#ifndef MSDOS
305 305
306static void 306static void
307wait_for_termination_1 (int pid, int interruptible) 307wait_for_termination_1 (pid_t pid, int interruptible)
308{ 308{
309 while (1) 309 while (1)
310 { 310 {
@@ -352,14 +352,14 @@ wait_for_termination_1 (int pid, int interruptible)
352 make sure it will get eliminated (not remain forever as a zombie) */ 352 make sure it will get eliminated (not remain forever as a zombie) */
353 353
354void 354void
355wait_for_termination (int pid) 355wait_for_termination (pid_t pid)
356{ 356{
357 wait_for_termination_1 (pid, 0); 357 wait_for_termination_1 (pid, 0);
358} 358}
359 359
360/* Like the above, but allow keyboard interruption. */ 360/* Like the above, but allow keyboard interruption. */
361void 361void
362interruptible_wait_for_termination (int pid) 362interruptible_wait_for_termination (pid_t pid)
363{ 363{
364 wait_for_termination_1 (pid, 1); 364 wait_for_termination_1 (pid, 1);
365} 365}
@@ -1910,8 +1910,8 @@ emacs_close (int fd)
1910/* Read from FILEDESC to a buffer BUF with size NBYTE, retrying if interrupted. 1910/* Read from FILEDESC to a buffer BUF with size NBYTE, retrying if interrupted.
1911 Return the number of bytes read, which might be less than NBYTE. 1911 Return the number of bytes read, which might be less than NBYTE.
1912 On error, set errno and return -1. */ 1912 On error, set errno and return -1. */
1913EMACS_INT 1913ptrdiff_t
1914emacs_read (int fildes, char *buf, EMACS_INT nbyte) 1914emacs_read (int fildes, char *buf, ptrdiff_t nbyte)
1915{ 1915{
1916 register ssize_t rtnval; 1916 register ssize_t rtnval;
1917 1917
@@ -1927,11 +1927,11 @@ emacs_read (int fildes, char *buf, EMACS_INT nbyte)
1927/* Write to FILEDES from a buffer BUF with size NBYTE, retrying if interrupted 1927/* Write to FILEDES from a buffer BUF with size NBYTE, retrying if interrupted
1928 or if a partial write occurs. Return the number of bytes written, setting 1928 or if a partial write occurs. Return the number of bytes written, setting
1929 errno if this is less than NBYTE. */ 1929 errno if this is less than NBYTE. */
1930EMACS_INT 1930ptrdiff_t
1931emacs_write (int fildes, const char *buf, EMACS_INT nbyte) 1931emacs_write (int fildes, const char *buf, ptrdiff_t nbyte)
1932{ 1932{
1933 ssize_t rtnval; 1933 ssize_t rtnval;
1934 EMACS_INT bytes_written; 1934 ptrdiff_t bytes_written;
1935 1935
1936 bytes_written = 0; 1936 bytes_written = 0;
1937 1937
@@ -2166,7 +2166,8 @@ set_file_times (const char *filename, EMACS_TIME atime, EMACS_TIME mtime)
2166int 2166int
2167mkdir (char *dpath, int dmode) 2167mkdir (char *dpath, int dmode)
2168{ 2168{
2169 int cpid, status, fd; 2169 pid_t cpid;
2170 int status, fd;
2170 struct stat statbuf; 2171 struct stat statbuf;
2171 2172
2172 if (stat (dpath, &statbuf) == 0) 2173 if (stat (dpath, &statbuf) == 0)
@@ -2740,7 +2741,10 @@ system_process_attributes (Lisp_Object pid)
2740 char *cmdline = NULL; 2741 char *cmdline = NULL;
2741 ptrdiff_t cmdsize = 0, cmdline_size; 2742 ptrdiff_t cmdsize = 0, cmdline_size;
2742 unsigned char c; 2743 unsigned char c;
2743 int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; 2744 printmax_t proc_id;
2745 int ppid, pgrp, sess, tty, tpgid, thcount;
2746 uid_t uid;
2747 gid_t gid;
2744 unsigned long long u_time, s_time, cutime, cstime, start; 2748 unsigned long long u_time, s_time, cutime, cstime, start;
2745 long priority, niceness, rss; 2749 long priority, niceness, rss;
2746 unsigned long minflt, majflt, cminflt, cmajflt, vsize; 2750 unsigned long minflt, majflt, cminflt, cmajflt, vsize;
@@ -2751,11 +2755,10 @@ system_process_attributes (Lisp_Object pid)
2751 Lisp_Object attrs = Qnil; 2755 Lisp_Object attrs = Qnil;
2752 Lisp_Object cmd_str, decoded_cmd, tem; 2756 Lisp_Object cmd_str, decoded_cmd, tem;
2753 struct gcpro gcpro1, gcpro2; 2757 struct gcpro gcpro1, gcpro2;
2754 EMACS_INT uid_eint, gid_eint;
2755 2758
2756 CHECK_NUMBER_OR_FLOAT (pid); 2759 CHECK_NUMBER_OR_FLOAT (pid);
2757 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 2760 CONS_TO_INTEGER (pid, pid_t, proc_id);
2758 sprintf (procfn, "/proc/%u", proc_id); 2761 sprintf (procfn, "/proc/%"pMd, proc_id);
2759 if (stat (procfn, &st) < 0) 2762 if (stat (procfn, &st) < 0)
2760 return attrs; 2763 return attrs;
2761 2764
@@ -2763,9 +2766,7 @@ system_process_attributes (Lisp_Object pid)
2763 2766
2764 /* euid egid */ 2767 /* euid egid */
2765 uid = st.st_uid; 2768 uid = st.st_uid;
2766 /* Use of EMACS_INT stops GCC whining about limited range of data type. */ 2769 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
2767 uid_eint = uid;
2768 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
2769 BLOCK_INPUT; 2770 BLOCK_INPUT;
2770 pw = getpwuid (uid); 2771 pw = getpwuid (uid);
2771 UNBLOCK_INPUT; 2772 UNBLOCK_INPUT;
@@ -2773,8 +2774,7 @@ system_process_attributes (Lisp_Object pid)
2773 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 2774 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
2774 2775
2775 gid = st.st_gid; 2776 gid = st.st_gid;
2776 gid_eint = gid; 2777 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
2777 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
2778 BLOCK_INPUT; 2778 BLOCK_INPUT;
2779 gr = getgrgid (gid); 2779 gr = getgrgid (gid);
2780 UNBLOCK_INPUT; 2780 UNBLOCK_INPUT;
@@ -3014,15 +3014,16 @@ system_process_attributes (Lisp_Object pid)
3014 struct psinfo pinfo; 3014 struct psinfo pinfo;
3015 int fd; 3015 int fd;
3016 ssize_t nread; 3016 ssize_t nread;
3017 int proc_id, uid, gid; 3017 printmax_t proc_id;
3018 uid_t uid;
3019 gid_t gid;
3018 Lisp_Object attrs = Qnil; 3020 Lisp_Object attrs = Qnil;
3019 Lisp_Object decoded_cmd, tem; 3021 Lisp_Object decoded_cmd, tem;
3020 struct gcpro gcpro1, gcpro2; 3022 struct gcpro gcpro1, gcpro2;
3021 EMACS_INT uid_eint, gid_eint;
3022 3023
3023 CHECK_NUMBER_OR_FLOAT (pid); 3024 CHECK_NUMBER_OR_FLOAT (pid);
3024 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 3025 CONS_TO_INTEGER (pid, pid_t, proc_id);
3025 sprintf (procfn, "/proc/%u", proc_id); 3026 sprintf (procfn, "/proc/%"pMd, proc_id);
3026 if (stat (procfn, &st) < 0) 3027 if (stat (procfn, &st) < 0)
3027 return attrs; 3028 return attrs;
3028 3029
@@ -3030,9 +3031,7 @@ system_process_attributes (Lisp_Object pid)
3030 3031
3031 /* euid egid */ 3032 /* euid egid */
3032 uid = st.st_uid; 3033 uid = st.st_uid;
3033 /* Use of EMACS_INT stops GCC whining about limited range of data type. */ 3034 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
3034 uid_eint = uid;
3035 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
3036 BLOCK_INPUT; 3035 BLOCK_INPUT;
3037 pw = getpwuid (uid); 3036 pw = getpwuid (uid);
3038 UNBLOCK_INPUT; 3037 UNBLOCK_INPUT;
@@ -3040,8 +3039,7 @@ system_process_attributes (Lisp_Object pid)
3040 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 3039 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
3041 3040
3042 gid = st.st_gid; 3041 gid = st.st_gid;
3043 gid_eint = gid; 3042 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
3044 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
3045 BLOCK_INPUT; 3043 BLOCK_INPUT;
3046 gr = getgrgid (gid); 3044 gr = getgrgid (gid);
3047 UNBLOCK_INPUT; 3045 UNBLOCK_INPUT;
@@ -3156,7 +3154,7 @@ system_process_attributes (Lisp_Object pid)
3156 Lisp_Object decoded_comm; 3154 Lisp_Object decoded_comm;
3157 3155
3158 CHECK_NUMBER_OR_FLOAT (pid); 3156 CHECK_NUMBER_OR_FLOAT (pid);
3159 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 3157 CONS_TO_INTEGER (pid, int, proc_id);
3160 mib[3] = proc_id; 3158 mib[3] = proc_id;
3161 3159
3162 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0) 3160 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
diff --git a/src/term.c b/src/term.c
index ce300f9442a..3d7a677374c 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1915,8 +1915,7 @@ produce_special_glyphs (struct it *it, enum display_element_type what)
1915 else 1915 else
1916 SET_GLYPH_FROM_CHAR (glyph, '\\'); 1916 SET_GLYPH_FROM_CHAR (glyph, '\\');
1917 if (it->dp 1917 if (it->dp
1918 && (gc = DISP_CONTINUE_GLYPH (it->dp), GLYPH_CODE_P (gc)) 1918 && (gc = DISP_CONTINUE_GLYPH (it->dp), GLYPH_CODE_P (gc)))
1919 && GLYPH_CODE_CHAR_VALID_P (gc))
1920 { 1919 {
1921 /* FIXME: Should we mirror GC for R2L lines? */ 1920 /* FIXME: Should we mirror GC for R2L lines? */
1922 SET_GLYPH_FROM_GLYPH_CODE (glyph, gc); 1921 SET_GLYPH_FROM_GLYPH_CODE (glyph, gc);
@@ -1928,8 +1927,7 @@ produce_special_glyphs (struct it *it, enum display_element_type what)
1928 /* Truncation glyph. */ 1927 /* Truncation glyph. */
1929 SET_GLYPH_FROM_CHAR (glyph, '$'); 1928 SET_GLYPH_FROM_CHAR (glyph, '$');
1930 if (it->dp 1929 if (it->dp
1931 && (gc = DISP_TRUNC_GLYPH (it->dp), GLYPH_CODE_P (gc)) 1930 && (gc = DISP_TRUNC_GLYPH (it->dp), GLYPH_CODE_P (gc)))
1932 && GLYPH_CODE_CHAR_VALID_P (gc))
1933 { 1931 {
1934 /* FIXME: Should we mirror GC for R2L lines? */ 1932 /* FIXME: Should we mirror GC for R2L lines? */
1935 SET_GLYPH_FROM_GLYPH_CODE (glyph, gc); 1933 SET_GLYPH_FROM_GLYPH_CODE (glyph, gc);
@@ -2279,7 +2277,7 @@ set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
2279 else 2277 else
2280 color_mode = Qnil; 2278 color_mode = Qnil;
2281 2279
2282 mode = INTEGERP (color_mode) ? XINT (color_mode) : 0; 2280 mode = TYPE_RANGED_INTEGERP (int, color_mode) ? XINT (color_mode) : 0;
2283 2281
2284 if (mode != tty->previous_color_mode) 2282 if (mode != tty->previous_color_mode)
2285 { 2283 {
diff --git a/src/termhooks.h b/src/termhooks.h
index 3e74046f137..5df11557844 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -232,7 +232,7 @@ struct input_event
232 For a HELP_EVENT, this is the position within the object 232 For a HELP_EVENT, this is the position within the object
233 (stored in ARG below) where the help was found. */ 233 (stored in ARG below) where the help was found. */
234 /* In WindowsNT, for a mouse wheel event, this is the delta. */ 234 /* In WindowsNT, for a mouse wheel event, this is the delta. */
235 EMACS_INT code; 235 ptrdiff_t code;
236 enum scroll_bar_part part; 236 enum scroll_bar_part part;
237 237
238 int modifiers; /* See enum below for interpretation. */ 238 int modifiers; /* See enum below for interpretation. */
diff --git a/src/textprop.c b/src/textprop.c
index 1e5e4577a00..83d07c56f28 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -120,7 +120,7 @@ INTERVAL
120validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *end, int force) 120validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *end, int force)
121{ 121{
122 register INTERVAL i; 122 register INTERVAL i;
123 EMACS_INT searchpos; 123 ptrdiff_t searchpos;
124 124
125 CHECK_STRING_OR_BUFFER (object); 125 CHECK_STRING_OR_BUFFER (object);
126 CHECK_NUMBER_COERCE_MARKER (*begin); 126 CHECK_NUMBER_COERCE_MARKER (*begin);
@@ -156,7 +156,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *en
156 } 156 }
157 else 157 else
158 { 158 {
159 EMACS_INT len = SCHARS (object); 159 ptrdiff_t len = SCHARS (object);
160 160
161 if (! (0 <= XINT (*begin) && XINT (*begin) <= XINT (*end) 161 if (! (0 <= XINT (*begin) && XINT (*begin) <= XINT (*end)
162 && XINT (*end) <= len)) 162 && XINT (*end) <= len))
@@ -510,10 +510,10 @@ erase_properties (INTERVAL i)
510 POSITION is BEG-based. */ 510 POSITION is BEG-based. */
511 511
512INTERVAL 512INTERVAL
513interval_of (EMACS_INT position, Lisp_Object object) 513interval_of (ptrdiff_t position, Lisp_Object object)
514{ 514{
515 register INTERVAL i; 515 register INTERVAL i;
516 EMACS_INT beg, end; 516 ptrdiff_t beg, end;
517 517
518 if (NILP (object)) 518 if (NILP (object))
519 XSETBUFFER (object, current_buffer); 519 XSETBUFFER (object, current_buffer);
@@ -771,7 +771,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */)
771 else 771 else
772 { 772 {
773 Lisp_Object initial_value, value; 773 Lisp_Object initial_value, value;
774 int count = SPECPDL_INDEX (); 774 ptrdiff_t count = SPECPDL_INDEX ();
775 775
776 if (! NILP (object)) 776 if (! NILP (object))
777 CHECK_BUFFER (object); 777 CHECK_BUFFER (object);
@@ -854,7 +854,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT. */)
854 } 854 }
855 else 855 else
856 { 856 {
857 int count = SPECPDL_INDEX (); 857 ptrdiff_t count = SPECPDL_INDEX ();
858 858
859 if (! NILP (object)) 859 if (! NILP (object))
860 CHECK_BUFFER (object); 860 CHECK_BUFFER (object);
@@ -1136,7 +1136,7 @@ Return t if any property value actually changed, nil otherwise. */)
1136 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object) 1136 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object)
1137{ 1137{
1138 register INTERVAL i, unchanged; 1138 register INTERVAL i, unchanged;
1139 register EMACS_INT s, len; 1139 register ptrdiff_t s, len;
1140 register int modified = 0; 1140 register int modified = 0;
1141 struct gcpro gcpro1; 1141 struct gcpro gcpro1;
1142 1142
@@ -1166,7 +1166,7 @@ Return t if any property value actually changed, nil otherwise. */)
1166 skip it. */ 1166 skip it. */
1167 if (interval_has_all_properties (properties, i)) 1167 if (interval_has_all_properties (properties, i))
1168 { 1168 {
1169 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1169 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1170 if (got >= len) 1170 if (got >= len)
1171 RETURN_UNGCPRO (Qnil); 1171 RETURN_UNGCPRO (Qnil);
1172 len -= got; 1172 len -= got;
@@ -1341,7 +1341,7 @@ void
1341set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object buffer, INTERVAL i) 1341set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object buffer, INTERVAL i)
1342{ 1342{
1343 register INTERVAL prev_changed = NULL_INTERVAL; 1343 register INTERVAL prev_changed = NULL_INTERVAL;
1344 register EMACS_INT s, len; 1344 register ptrdiff_t s, len;
1345 INTERVAL unchanged; 1345 INTERVAL unchanged;
1346 1346
1347 if (XINT (start) < XINT (end)) 1347 if (XINT (start) < XINT (end))
@@ -1434,7 +1434,7 @@ Use `set-text-properties' if you want to remove all text properties. */)
1434 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object) 1434 (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object)
1435{ 1435{
1436 register INTERVAL i, unchanged; 1436 register INTERVAL i, unchanged;
1437 register EMACS_INT s, len; 1437 register ptrdiff_t s, len;
1438 register int modified = 0; 1438 register int modified = 0;
1439 1439
1440 if (NILP (object)) 1440 if (NILP (object))
@@ -1453,7 +1453,7 @@ Use `set-text-properties' if you want to remove all text properties. */)
1453 it covers the entire region. */ 1453 it covers the entire region. */
1454 if (! interval_has_some_properties (properties, i)) 1454 if (! interval_has_some_properties (properties, i))
1455 { 1455 {
1456 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1456 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1457 if (got >= len) 1457 if (got >= len)
1458 return Qnil; 1458 return Qnil;
1459 len -= got; 1459 len -= got;
@@ -1520,7 +1520,7 @@ Return t if any property was actually removed, nil otherwise. */)
1520 (Lisp_Object start, Lisp_Object end, Lisp_Object list_of_properties, Lisp_Object object) 1520 (Lisp_Object start, Lisp_Object end, Lisp_Object list_of_properties, Lisp_Object object)
1521{ 1521{
1522 register INTERVAL i, unchanged; 1522 register INTERVAL i, unchanged;
1523 register EMACS_INT s, len; 1523 register ptrdiff_t s, len;
1524 register int modified = 0; 1524 register int modified = 0;
1525 Lisp_Object properties; 1525 Lisp_Object properties;
1526 properties = list_of_properties; 1526 properties = list_of_properties;
@@ -1541,7 +1541,7 @@ Return t if any property was actually removed, nil otherwise. */)
1541 it covers the entire region. */ 1541 it covers the entire region. */
1542 if (! interval_has_some_properties_list (properties, i)) 1542 if (! interval_has_some_properties_list (properties, i))
1543 { 1543 {
1544 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1544 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1545 if (got >= len) 1545 if (got >= len)
1546 return Qnil; 1546 return Qnil;
1547 len -= got; 1547 len -= got;
@@ -1630,7 +1630,7 @@ markers). If OBJECT is a string, START and END are 0-based indices into it. */
1630 (Lisp_Object start, Lisp_Object end, Lisp_Object property, Lisp_Object value, Lisp_Object object) 1630 (Lisp_Object start, Lisp_Object end, Lisp_Object property, Lisp_Object value, Lisp_Object object)
1631{ 1631{
1632 register INTERVAL i; 1632 register INTERVAL i;
1633 register EMACS_INT e, pos; 1633 register ptrdiff_t e, pos;
1634 1634
1635 if (NILP (object)) 1635 if (NILP (object))
1636 XSETBUFFER (object, current_buffer); 1636 XSETBUFFER (object, current_buffer);
@@ -1666,7 +1666,7 @@ markers). If OBJECT is a string, START and END are 0-based indices into it. */
1666 (Lisp_Object start, Lisp_Object end, Lisp_Object property, Lisp_Object value, Lisp_Object object) 1666 (Lisp_Object start, Lisp_Object end, Lisp_Object property, Lisp_Object value, Lisp_Object object)
1667{ 1667{
1668 register INTERVAL i; 1668 register INTERVAL i;
1669 register EMACS_INT s, e; 1669 register ptrdiff_t s, e;
1670 1670
1671 if (NILP (object)) 1671 if (NILP (object))
1672 XSETBUFFER (object, current_buffer); 1672 XSETBUFFER (object, current_buffer);
@@ -1776,7 +1776,7 @@ copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src, Lisp_
1776 Lisp_Object res; 1776 Lisp_Object res;
1777 Lisp_Object stuff; 1777 Lisp_Object stuff;
1778 Lisp_Object plist; 1778 Lisp_Object plist;
1779 EMACS_INT s, e, e2, p, len; 1779 ptrdiff_t s, e, e2, p, len;
1780 int modified = 0; 1780 int modified = 0;
1781 struct gcpro gcpro1, gcpro2; 1781 struct gcpro gcpro1, gcpro2;
1782 1782
@@ -1788,8 +1788,11 @@ copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src, Lisp_
1788 { 1788 {
1789 Lisp_Object dest_start, dest_end; 1789 Lisp_Object dest_start, dest_end;
1790 1790
1791 e = XINT (pos) + (XINT (end) - XINT (start));
1792 if (MOST_POSITIVE_FIXNUM < e)
1793 args_out_of_range (pos, end);
1791 dest_start = pos; 1794 dest_start = pos;
1792 XSETFASTINT (dest_end, XINT (dest_start) + (XINT (end) - XINT (start))); 1795 XSETFASTINT (dest_end, e);
1793 /* Apply this to a copy of pos; it will try to increment its arguments, 1796 /* Apply this to a copy of pos; it will try to increment its arguments,
1794 which we don't want. */ 1797 which we don't want. */
1795 validate_interval_range (dest, &dest_start, &dest_end, soft); 1798 validate_interval_range (dest, &dest_start, &dest_end, soft);
@@ -1873,12 +1876,12 @@ text_property_list (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp
1873 i = validate_interval_range (object, &start, &end, soft); 1876 i = validate_interval_range (object, &start, &end, soft);
1874 if (!NULL_INTERVAL_P (i)) 1877 if (!NULL_INTERVAL_P (i))
1875 { 1878 {
1876 EMACS_INT s = XINT (start); 1879 ptrdiff_t s = XINT (start);
1877 EMACS_INT e = XINT (end); 1880 ptrdiff_t e = XINT (end);
1878 1881
1879 while (s < e) 1882 while (s < e)
1880 { 1883 {
1881 EMACS_INT interval_end, len; 1884 ptrdiff_t interval_end, len;
1882 Lisp_Object plist; 1885 Lisp_Object plist;
1883 1886
1884 interval_end = i->position + LENGTH (i); 1887 interval_end = i->position + LENGTH (i);
@@ -1956,7 +1959,7 @@ Lisp_Object
1956extend_property_ranges (Lisp_Object list, Lisp_Object new_end) 1959extend_property_ranges (Lisp_Object list, Lisp_Object new_end)
1957{ 1960{
1958 Lisp_Object prev = Qnil, head = list; 1961 Lisp_Object prev = Qnil, head = list;
1959 EMACS_INT max = XINT (new_end); 1962 ptrdiff_t max = XINT (new_end);
1960 1963
1961 for (; CONSP (list); prev = list, list = XCDR (list)) 1964 for (; CONSP (list); prev = list, list = XCDR (list))
1962 { 1965 {
@@ -2010,7 +2013,7 @@ call_mod_hooks (Lisp_Object list, Lisp_Object start, Lisp_Object end)
2010 2013
2011void 2014void
2012verify_interval_modification (struct buffer *buf, 2015verify_interval_modification (struct buffer *buf,
2013 EMACS_INT start, EMACS_INT end) 2016 ptrdiff_t start, ptrdiff_t end)
2014{ 2017{
2015 register INTERVAL intervals = BUF_INTERVALS (buf); 2018 register INTERVAL intervals = BUF_INTERVALS (buf);
2016 register INTERVAL i; 2019 register INTERVAL i;
@@ -2031,7 +2034,7 @@ verify_interval_modification (struct buffer *buf,
2031 2034
2032 if (start > end) 2035 if (start > end)
2033 { 2036 {
2034 EMACS_INT temp = start; 2037 ptrdiff_t temp = start;
2035 start = end; 2038 start = end;
2036 end = temp; 2039 end = temp;
2037 } 2040 }
diff --git a/src/undo.c b/src/undo.c
index b0acd0c216f..9b763984d7f 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -30,7 +30,7 @@ static struct buffer *last_undo_buffer;
30 30
31/* Position of point last time we inserted a boundary. */ 31/* Position of point last time we inserted a boundary. */
32static struct buffer *last_boundary_buffer; 32static struct buffer *last_boundary_buffer;
33static EMACS_INT last_boundary_position; 33static ptrdiff_t last_boundary_position;
34 34
35Lisp_Object Qinhibit_read_only; 35Lisp_Object Qinhibit_read_only;
36 36
@@ -51,7 +51,7 @@ static Lisp_Object pending_boundary;
51 undo record that will be added just after this command terminates. */ 51 undo record that will be added just after this command terminates. */
52 52
53static void 53static void
54record_point (EMACS_INT pt) 54record_point (ptrdiff_t pt)
55{ 55{
56 int at_boundary; 56 int at_boundary;
57 57
@@ -113,7 +113,7 @@ record_point (EMACS_INT pt)
113 because we don't need to record the contents.) */ 113 because we don't need to record the contents.) */
114 114
115void 115void
116record_insert (EMACS_INT beg, EMACS_INT length) 116record_insert (ptrdiff_t beg, ptrdiff_t length)
117{ 117{
118 Lisp_Object lbeg, lend; 118 Lisp_Object lbeg, lend;
119 119
@@ -148,7 +148,7 @@ record_insert (EMACS_INT beg, EMACS_INT length)
148 of the characters in STRING, at location BEG. */ 148 of the characters in STRING, at location BEG. */
149 149
150void 150void
151record_delete (EMACS_INT beg, Lisp_Object string) 151record_delete (ptrdiff_t beg, Lisp_Object string)
152{ 152{
153 Lisp_Object sbeg; 153 Lisp_Object sbeg;
154 154
@@ -176,7 +176,7 @@ record_delete (EMACS_INT beg, Lisp_Object string)
176 won't be inverted automatically by undoing the buffer modification. */ 176 won't be inverted automatically by undoing the buffer modification. */
177 177
178void 178void
179record_marker_adjustment (Lisp_Object marker, EMACS_INT adjustment) 179record_marker_adjustment (Lisp_Object marker, ptrdiff_t adjustment)
180{ 180{
181 if (EQ (BVAR (current_buffer, undo_list), Qt)) 181 if (EQ (BVAR (current_buffer, undo_list), Qt))
182 return; 182 return;
@@ -199,7 +199,7 @@ record_marker_adjustment (Lisp_Object marker, EMACS_INT adjustment)
199 The replacement must not change the number of characters. */ 199 The replacement must not change the number of characters. */
200 200
201void 201void
202record_change (EMACS_INT beg, EMACS_INT length) 202record_change (ptrdiff_t beg, ptrdiff_t length)
203{ 203{
204 record_delete (beg, make_buffer_string (beg, beg + length, 1)); 204 record_delete (beg, make_buffer_string (beg, beg + length, 1));
205 record_insert (beg, length); 205 record_insert (beg, length);
@@ -233,7 +233,7 @@ record_first_change (void)
233 for LENGTH characters starting at position BEG in BUFFER. */ 233 for LENGTH characters starting at position BEG in BUFFER. */
234 234
235void 235void
236record_property_change (EMACS_INT beg, EMACS_INT length, 236record_property_change (ptrdiff_t beg, ptrdiff_t length,
237 Lisp_Object prop, Lisp_Object value, 237 Lisp_Object prop, Lisp_Object value,
238 Lisp_Object buffer) 238 Lisp_Object buffer)
239{ 239{
@@ -308,11 +308,11 @@ truncate_undo_list (struct buffer *b)
308{ 308{
309 Lisp_Object list; 309 Lisp_Object list;
310 Lisp_Object prev, next, last_boundary; 310 Lisp_Object prev, next, last_boundary;
311 int size_so_far = 0; 311 EMACS_INT size_so_far = 0;
312 312
313 /* Make sure that calling undo-outer-limit-function 313 /* Make sure that calling undo-outer-limit-function
314 won't cause another GC. */ 314 won't cause another GC. */
315 int count = inhibit_garbage_collection (); 315 ptrdiff_t count = inhibit_garbage_collection ();
316 316
317 /* Make the buffer current to get its local values of variables such 317 /* Make the buffer current to get its local values of variables such
318 as undo_limit. Also so that Vundo_outer_limit_function can 318 as undo_limit. Also so that Vundo_outer_limit_function can
@@ -451,8 +451,8 @@ Return what remains of the list. */)
451{ 451{
452 struct gcpro gcpro1, gcpro2; 452 struct gcpro gcpro1, gcpro2;
453 Lisp_Object next; 453 Lisp_Object next;
454 int count = SPECPDL_INDEX (); 454 ptrdiff_t count = SPECPDL_INDEX ();
455 register int arg; 455 register EMACS_INT arg;
456 Lisp_Object oldlist; 456 Lisp_Object oldlist;
457 int did_apply = 0; 457 int did_apply = 0;
458 458
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 2e77d3e17bc..a61bbd8eb86 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -809,9 +809,9 @@ copy_data_segment (struct load_command *lc)
809 { 809 {
810 sectp->flags = S_REGULAR; 810 sectp->flags = S_REGULAR;
811 if (!unexec_write (sectp->offset, (void *) sectp->addr, sectp->size)) 811 if (!unexec_write (sectp->offset, (void *) sectp->addr, sectp->size))
812 unexec_error ("cannot write section %s", sectp->sectname); 812 unexec_error ("cannot write section %.16s", sectp->sectname);
813 if (!unexec_write (header_offset, sectp, sizeof (struct section))) 813 if (!unexec_write (header_offset, sectp, sizeof (struct section)))
814 unexec_error ("cannot write section %s's header", sectp->sectname); 814 unexec_error ("cannot write section %.16s's header", sectp->sectname);
815 } 815 }
816 else if (strncmp (sectp->sectname, SECT_BSS, 16) == 0) 816 else if (strncmp (sectp->sectname, SECT_BSS, 16) == 0)
817 { 817 {
@@ -829,15 +829,15 @@ copy_data_segment (struct load_command *lc)
829 my_size = (unsigned long)my_endbss_static - sectp->addr; 829 my_size = (unsigned long)my_endbss_static - sectp->addr;
830 if (!(sectp->addr <= (unsigned long)my_endbss_static 830 if (!(sectp->addr <= (unsigned long)my_endbss_static
831 && my_size <= sectp->size)) 831 && my_size <= sectp->size))
832 unexec_error ("my_endbss_static is not in section %s", 832 unexec_error ("my_endbss_static is not in section %.16s",
833 sectp->sectname); 833 sectp->sectname);
834 if (!unexec_write (sectp->offset, (void *) sectp->addr, my_size)) 834 if (!unexec_write (sectp->offset, (void *) sectp->addr, my_size))
835 unexec_error ("cannot write section %s", sectp->sectname); 835 unexec_error ("cannot write section %.16s", sectp->sectname);
836 if (!unexec_write_zero (sectp->offset + my_size, 836 if (!unexec_write_zero (sectp->offset + my_size,
837 sectp->size - my_size)) 837 sectp->size - my_size))
838 unexec_error ("cannot write section %s", sectp->sectname); 838 unexec_error ("cannot write section %.16s", sectp->sectname);
839 if (!unexec_write (header_offset, sectp, sizeof (struct section))) 839 if (!unexec_write (header_offset, sectp, sizeof (struct section)))
840 unexec_error ("cannot write section %s's header", sectp->sectname); 840 unexec_error ("cannot write section %.16s's header", sectp->sectname);
841 } 841 }
842 else if (strncmp (sectp->sectname, "__la_symbol_ptr", 16) == 0 842 else if (strncmp (sectp->sectname, "__la_symbol_ptr", 16) == 0
843 || strncmp (sectp->sectname, "__nl_symbol_ptr", 16) == 0 843 || strncmp (sectp->sectname, "__nl_symbol_ptr", 16) == 0
@@ -851,12 +851,13 @@ copy_data_segment (struct load_command *lc)
851 || strncmp (sectp->sectname, "__objc_", 7) == 0) 851 || strncmp (sectp->sectname, "__objc_", 7) == 0)
852 { 852 {
853 if (!unexec_copy (sectp->offset, old_file_offset, sectp->size)) 853 if (!unexec_copy (sectp->offset, old_file_offset, sectp->size))
854 unexec_error ("cannot copy section %s", sectp->sectname); 854 unexec_error ("cannot copy section %.16s", sectp->sectname);
855 if (!unexec_write (header_offset, sectp, sizeof (struct section))) 855 if (!unexec_write (header_offset, sectp, sizeof (struct section)))
856 unexec_error ("cannot write section %s's header", sectp->sectname); 856 unexec_error ("cannot write section %.16s's header", sectp->sectname);
857 } 857 }
858 else 858 else
859 unexec_error ("unrecognized section name in __DATA segment"); 859 unexec_error ("unrecognized section %.16s in __DATA segment",
860 sectp->sectname);
860 861
861 printf (" section %-16.16s at %#8lx - %#8lx (sz: %#8lx)\n", 862 printf (" section %-16.16s at %#8lx - %#8lx (sz: %#8lx)\n",
862 sectp->sectname, (long) (sectp->offset), 863 sectp->sectname, (long) (sectp->offset),
diff --git a/src/w32console.c b/src/w32console.c
index e8b0f621b4f..22f329e239d 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -33,6 +33,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "coding.h" 33#include "coding.h"
34#include "disptab.h" 34#include "disptab.h"
35#include "frame.h" 35#include "frame.h"
36#include "window.h"
36#include "termhooks.h" 37#include "termhooks.h"
37#include "termchar.h" 38#include "termchar.h"
38#include "dispextern.h" 39#include "dispextern.h"
@@ -339,6 +340,84 @@ w32con_write_glyphs (struct frame *f, register struct glyph *string,
339 } 340 }
340} 341}
341 342
343/* Used for mouse highlight. */
344static void
345w32con_write_glyphs_with_face (struct frame *f, register int x, register int y,
346 register struct glyph *string, register int len,
347 register int face_id)
348{
349 unsigned char *conversion_buffer;
350 struct coding_system *coding;
351
352 if (len <= 0)
353 return;
354
355 /* If terminal_coding does any conversion, use it, otherwise use
356 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
357 because it always return 1 if the member src_multibyte is 1. */
358 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
359 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
360 /* We are going to write the entire block of glyphs in one go, as
361 they all have the same face. So this _is_ the last block. */
362 coding->mode |= CODING_MODE_LAST_BLOCK;
363
364 conversion_buffer = encode_terminal_code (string, len, coding);
365 if (coding->produced > 0)
366 {
367 DWORD filled, written;
368 /* Compute the character attributes corresponding to the face. */
369 DWORD char_attr = w32_face_attributes (f, face_id);
370 COORD start_coords;
371
372 start_coords.X = x;
373 start_coords.Y = y;
374 /* Set the attribute for these characters. */
375 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
376 coding->produced, start_coords,
377 &filled))
378 DebPrint (("Failed writing console attributes: %d\n", GetLastError ()));
379 else
380 {
381 /* Write the characters. */
382 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
383 filled, start_coords, &written))
384 DebPrint (("Failed writing console characters: %d\n",
385 GetLastError ()));
386 }
387 }
388}
389
390/* Implementation of draw_row_with_mouse_face for W32 console. */
391void
392tty_draw_row_with_mouse_face (struct window *w, struct glyph_row *row,
393 int start_hpos, int end_hpos,
394 enum draw_glyphs_face draw)
395{
396 int nglyphs = end_hpos - start_hpos;
397 struct frame *f = XFRAME (WINDOW_FRAME (w));
398 struct tty_display_info *tty = FRAME_TTY (f);
399 int face_id = tty->mouse_highlight.mouse_face_face_id;
400 int pos_x, pos_y;
401
402 if (end_hpos >= row->used[TEXT_AREA])
403 nglyphs = row->used[TEXT_AREA] - start_hpos;
404
405 pos_y = row->y + WINDOW_TOP_EDGE_Y (w);
406 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos + WINDOW_LEFT_EDGE_X (w);
407
408 if (draw == DRAW_MOUSE_FACE)
409 w32con_write_glyphs_with_face (f, pos_x, pos_y,
410 row->glyphs[TEXT_AREA] + start_hpos,
411 nglyphs, face_id);
412 else if (draw == DRAW_NORMAL_TEXT)
413 {
414 COORD save_coords = cursor_coords;
415
416 w32con_move_cursor (f, pos_y, pos_x);
417 write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
418 w32con_move_cursor (f, save_coords.Y, save_coords.X);
419 }
420}
342 421
343static void 422static void
344w32con_delete_glyphs (struct frame *f, int n) 423w32con_delete_glyphs (struct frame *f, int n)
@@ -570,6 +649,7 @@ void
570initialize_w32_display (struct terminal *term) 649initialize_w32_display (struct terminal *term)
571{ 650{
572 CONSOLE_SCREEN_BUFFER_INFO info; 651 CONSOLE_SCREEN_BUFFER_INFO info;
652 Mouse_HLInfo *hlinfo;
573 653
574 term->rif = 0; /* No window based redisplay on the console. */ 654 term->rif = 0; /* No window based redisplay on the console. */
575 term->cursor_to_hook = w32con_move_cursor; 655 term->cursor_to_hook = w32con_move_cursor;
@@ -600,6 +680,15 @@ initialize_w32_display (struct terminal *term)
600 term->judge_scroll_bars_hook = 0; 680 term->judge_scroll_bars_hook = 0;
601 term->frame_up_to_date_hook = 0; 681 term->frame_up_to_date_hook = 0;
602 682
683 /* Initialize the mouse-highlight data. */
684 hlinfo = &term->display_info.tty->mouse_highlight;
685 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
686 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
687 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
688 hlinfo->mouse_face_mouse_frame = NULL;
689 hlinfo->mouse_face_window = Qnil;
690 hlinfo->mouse_face_hidden = 0;
691
603 /* Initialize interrupt_handle. */ 692 /* Initialize interrupt_handle. */
604 init_crit (); 693 init_crit ();
605 694
diff --git a/src/w32fns.c b/src/w32fns.c
index f5161117f9d..b8dc62f5250 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -3663,6 +3663,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3663 case WM_EMACS_SHOWWINDOW: 3663 case WM_EMACS_SHOWWINDOW:
3664 return ShowWindow ((HWND) wParam, (WPARAM) lParam); 3664 return ShowWindow ((HWND) wParam, (WPARAM) lParam);
3665 3665
3666 case WM_EMACS_BRINGTOTOP:
3666 case WM_EMACS_SETFOREGROUND: 3667 case WM_EMACS_SETFOREGROUND:
3667 { 3668 {
3668 HWND foreground_window; 3669 HWND foreground_window;
@@ -3680,6 +3681,8 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3680 foreground_thread = 0; 3681 foreground_thread = 0;
3681 3682
3682 retval = SetForegroundWindow ((HWND) wParam); 3683 retval = SetForegroundWindow ((HWND) wParam);
3684 if (msg == WM_EMACS_BRINGTOTOP)
3685 retval = BringWindowToTop ((HWND) wParam);
3683 3686
3684 /* Detach from the previous foreground thread. */ 3687 /* Detach from the previous foreground thread. */
3685 if (foreground_thread) 3688 if (foreground_thread)
@@ -4070,7 +4073,7 @@ This function is an internal primitive--use `make-frame' instead. */)
4070 int minibuffer_only = 0; 4073 int minibuffer_only = 0;
4071 long window_prompting = 0; 4074 long window_prompting = 0;
4072 int width, height; 4075 int width, height;
4073 int count = SPECPDL_INDEX (); 4076 ptrdiff_t count = SPECPDL_INDEX ();
4074 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4077 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4075 Lisp_Object display; 4078 Lisp_Object display;
4076 struct w32_display_info *dpyinfo = NULL; 4079 struct w32_display_info *dpyinfo = NULL;
@@ -5173,7 +5176,7 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5173 Lisp_Object name; 5176 Lisp_Object name;
5174 long window_prompting = 0; 5177 long window_prompting = 0;
5175 int width, height; 5178 int width, height;
5176 int count = SPECPDL_INDEX (); 5179 ptrdiff_t count = SPECPDL_INDEX ();
5177 struct gcpro gcpro1, gcpro2, gcpro3; 5180 struct gcpro gcpro1, gcpro2, gcpro3;
5178 struct kboard *kb; 5181 struct kboard *kb;
5179 int face_change_count_before = face_change_count; 5182 int face_change_count_before = face_change_count;
@@ -5522,7 +5525,7 @@ Text larger than the specified size is clipped. */)
5522 int i, width, height, seen_reversed_p; 5525 int i, width, height, seen_reversed_p;
5523 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 5526 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
5524 int old_windows_or_buffers_changed = windows_or_buffers_changed; 5527 int old_windows_or_buffers_changed = windows_or_buffers_changed;
5525 int count = SPECPDL_INDEX (); 5528 ptrdiff_t count = SPECPDL_INDEX ();
5526 5529
5527 specbind (Qinhibit_redisplay, Qt); 5530 specbind (Qinhibit_redisplay, Qt);
5528 5531
@@ -5801,7 +5804,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
5801Value is t if tooltip was open, nil otherwise. */) 5804Value is t if tooltip was open, nil otherwise. */)
5802 (void) 5805 (void)
5803{ 5806{
5804 int count; 5807 ptrdiff_t count;
5805 Lisp_Object deleted, frame, timer; 5808 Lisp_Object deleted, frame, timer;
5806 struct gcpro gcpro1, gcpro2; 5809 struct gcpro gcpro1, gcpro2;
5807 5810
@@ -5923,7 +5926,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5923{ 5926{
5924 struct frame *f = SELECTED_FRAME (); 5927 struct frame *f = SELECTED_FRAME ();
5925 Lisp_Object file = Qnil; 5928 Lisp_Object file = Qnil;
5926 int count = SPECPDL_INDEX (); 5929 ptrdiff_t count = SPECPDL_INDEX ();
5927 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5930 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5928 char filename[MAX_PATH + 1]; 5931 char filename[MAX_PATH + 1];
5929 char init_dir[MAX_PATH + 1]; 5932 char init_dir[MAX_PATH + 1];
diff --git a/src/w32inevt.c b/src/w32inevt.c
index e7a8bf629d6..a85fdbbe435 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -35,8 +35,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35#include "keyboard.h" 35#include "keyboard.h"
36#include "frame.h" 36#include "frame.h"
37#include "dispextern.h" 37#include "dispextern.h"
38#include "window.h"
38#include "blockinput.h" 39#include "blockinput.h"
39#include "termhooks.h" 40#include "termhooks.h"
41#include "termchar.h"
40#include "w32heap.h" 42#include "w32heap.h"
41#include "w32term.h" 43#include "w32term.h"
42 44
@@ -566,7 +568,7 @@ w32_console_mouse_position (FRAME_PTR *f,
566static void 568static void
567mouse_moved_to (int x, int y) 569mouse_moved_to (int x, int y)
568{ 570{
569 /* If we're in the same place, ignore it */ 571 /* If we're in the same place, ignore it. */
570 if (x != movement_pos.X || y != movement_pos.Y) 572 if (x != movement_pos.X || y != movement_pos.Y)
571 { 573 {
572 SELECTED_FRAME ()->mouse_moved = 1; 574 SELECTED_FRAME ()->mouse_moved = 1;
@@ -599,14 +601,63 @@ do_mouse_event (MOUSE_EVENT_RECORD *event,
599 struct input_event *emacs_ev) 601 struct input_event *emacs_ev)
600{ 602{
601 static DWORD button_state = 0; 603 static DWORD button_state = 0;
604 static Lisp_Object last_mouse_window;
602 DWORD but_change, mask; 605 DWORD but_change, mask;
603 int i; 606 int i;
604 607
605 if (event->dwEventFlags == MOUSE_MOVED) 608 if (event->dwEventFlags == MOUSE_MOVED)
606 { 609 {
607 /* For movement events we just note that the mouse has moved 610 FRAME_PTR f = SELECTED_FRAME ();
608 so that emacs will generate drag events. */ 611 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
609 mouse_moved_to (event->dwMousePosition.X, event->dwMousePosition.Y); 612 int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y;
613
614 mouse_moved_to (mx, my);
615
616 if (f->mouse_moved)
617 {
618 if (hlinfo->mouse_face_hidden)
619 {
620 hlinfo->mouse_face_hidden = 0;
621 clear_mouse_face (hlinfo);
622 }
623
624 /* Generate SELECT_WINDOW_EVENTs when needed. */
625 if (!NILP (Vmouse_autoselect_window))
626 {
627 Lisp_Object mouse_window = window_from_coordinates (f, mx, my,
628 0, 0);
629 /* A window will be selected only when it is not
630 selected now, and the last mouse movement event was
631 not in it. A minibuffer window will be selected iff
632 it is active. */
633 if (WINDOWP (mouse_window)
634 && !EQ (mouse_window, last_mouse_window)
635 && !EQ (mouse_window, selected_window))
636 {
637 struct input_event event;
638
639 EVENT_INIT (event);
640 event.kind = SELECT_WINDOW_EVENT;
641 event.frame_or_window = mouse_window;
642 event.arg = Qnil;
643 event.timestamp = movement_time;
644 kbd_buffer_store_event (&event);
645 }
646 last_mouse_window = mouse_window;
647 }
648 else
649 last_mouse_window = Qnil;
650
651 previous_help_echo_string = help_echo_string;
652 help_echo_string = help_echo_object = help_echo_window = Qnil;
653 help_echo_pos = -1;
654 note_mouse_highlight (f, mx, my);
655 /* If the contents of the global variable help_echo has
656 changed (inside note_mouse_highlight), generate a HELP_EVENT. */
657 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
658 gen_help_event (help_echo_string, selected_frame, help_echo_window,
659 help_echo_object, help_echo_pos);
660 }
610 return 0; 661 return 0;
611 } 662 }
612 663
diff --git a/src/w32menu.c b/src/w32menu.c
index 5b95a083d90..2bc4c208956 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -383,7 +383,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
383 383
384 struct buffer *prev = current_buffer; 384 struct buffer *prev = current_buffer;
385 Lisp_Object buffer; 385 Lisp_Object buffer;
386 int specpdl_count = SPECPDL_INDEX (); 386 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
387 int previous_menu_items_used = f->menu_bar_items_used; 387 int previous_menu_items_used = f->menu_bar_items_used;
388 Lisp_Object *previous_items 388 Lisp_Object *previous_items
389 = (Lisp_Object *) alloca (previous_menu_items_used 389 = (Lisp_Object *) alloca (previous_menu_items_used
diff --git a/src/w32term.c b/src/w32term.c
index 2ccd7574332..a90e067a3fd 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -3492,6 +3492,12 @@ my_destroy_window (struct frame * f, HWND hwnd)
3492 (WPARAM) hwnd, 0); 3492 (WPARAM) hwnd, 0);
3493} 3493}
3494 3494
3495static void
3496my_bring_window_to_top (HWND hwnd)
3497{
3498 SendMessage (hwnd, WM_EMACS_BRINGTOTOP, (WPARAM) hwnd, 0);
3499}
3500
3495/* Create a scroll bar and return the scroll bar vector for it. W is 3501/* Create a scroll bar and return the scroll bar vector for it. W is
3496 the Emacs window on which to create the scroll bar. TOP, LEFT, 3502 the Emacs window on which to create the scroll bar. TOP, LEFT,
3497 WIDTH and HEIGHT are the pixel coordinates and dimensions of the 3503 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
@@ -5600,24 +5606,27 @@ x_raise_frame (struct frame *f)
5600 HDWP handle = BeginDeferWindowPos (2); 5606 HDWP handle = BeginDeferWindowPos (2);
5601 if (handle) 5607 if (handle)
5602 { 5608 {
5603 DeferWindowPos (handle, 5609 handle = DeferWindowPos (handle,
5604 FRAME_W32_WINDOW (f), 5610 FRAME_W32_WINDOW (f),
5605 HWND_TOP, 5611 HWND_TOP,
5606 0, 0, 0, 0, 5612 0, 0, 0, 0,
5607 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); 5613 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
5608 5614 if (handle)
5609 DeferWindowPos (handle, 5615 {
5610 GetForegroundWindow (), 5616 handle = DeferWindowPos (handle,
5611 FRAME_W32_WINDOW (f), 5617 GetForegroundWindow (),
5612 0, 0, 0, 0, 5618 FRAME_W32_WINDOW (f),
5613 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); 5619 0, 0, 0, 0,
5614 5620 SWP_NOSIZE | SWP_NOMOVE |
5615 EndDeferWindowPos (handle); 5621 SWP_NOACTIVATE);
5622 if (handle)
5623 EndDeferWindowPos (handle);
5624 }
5616 } 5625 }
5617 } 5626 }
5618 else 5627 else
5619 { 5628 {
5620 my_set_foreground_window (FRAME_W32_WINDOW (f)); 5629 my_bring_window_to_top (FRAME_W32_WINDOW (f));
5621 } 5630 }
5622 5631
5623 UNBLOCK_INPUT; 5632 UNBLOCK_INPUT;
diff --git a/src/w32term.h b/src/w32term.h
index 4528bbd5c0a..68e62b24144 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -576,7 +576,8 @@ do { \
576#define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18) 576#define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18)
577#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) 577#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19)
578#define WM_EMACS_PAINT (WM_EMACS_START + 20) 578#define WM_EMACS_PAINT (WM_EMACS_START + 20)
579#define WM_EMACS_END (WM_EMACS_START + 21) 579#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21)
580#define WM_EMACS_END (WM_EMACS_START + 22)
580 581
581#define WND_FONTWIDTH_INDEX (0) 582#define WND_FONTWIDTH_INDEX (0)
582#define WND_LINEHEIGHT_INDEX (4) 583#define WND_LINEHEIGHT_INDEX (4)
diff --git a/src/window.c b/src/window.c
index 827d3646e49..a10222b1aff 100644
--- a/src/window.c
+++ b/src/window.c
@@ -65,7 +65,7 @@ static int displayed_window_lines (struct window *);
65static struct window *decode_window (Lisp_Object); 65static struct window *decode_window (Lisp_Object);
66static int count_windows (struct window *); 66static int count_windows (struct window *);
67static int get_leaf_windows (struct window *, struct window **, int); 67static int get_leaf_windows (struct window *, struct window **, int);
68static void window_scroll (Lisp_Object, int, int, int); 68static void window_scroll (Lisp_Object, EMACS_INT, int, int);
69static void window_scroll_pixel_based (Lisp_Object, int, int, int); 69static void window_scroll_pixel_based (Lisp_Object, int, int, int);
70static void window_scroll_line_based (Lisp_Object, int, int, int); 70static void window_scroll_line_based (Lisp_Object, int, int, int);
71static int freeze_window_start (struct window *, void *); 71static int freeze_window_start (struct window *, void *);
@@ -129,8 +129,8 @@ static int window_scroll_pixel_based_preserve_x;
129static int window_scroll_pixel_based_preserve_y; 129static int window_scroll_pixel_based_preserve_y;
130 130
131/* Same for window_scroll_line_based. */ 131/* Same for window_scroll_line_based. */
132static int window_scroll_preserve_hpos; 132static EMACS_INT window_scroll_preserve_hpos;
133static int window_scroll_preserve_vpos; 133static EMACS_INT window_scroll_preserve_vpos;
134 134
135static struct window * 135static struct window *
136decode_window (register Lisp_Object window) 136decode_window (register Lisp_Object window)
@@ -380,7 +380,7 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
380 redisplay_window has altered point after scrolling, 380 redisplay_window has altered point after scrolling,
381 because it makes the change only in the window. */ 381 because it makes the change only in the window. */
382 { 382 {
383 register EMACS_INT new_point = marker_position (w->pointm); 383 register ptrdiff_t new_point = marker_position (w->pointm);
384 if (new_point < BEGV) 384 if (new_point < BEGV)
385 SET_PT (BEGV); 385 SET_PT (BEGV);
386 else if (new_point > ZV) 386 else if (new_point > ZV)
@@ -682,10 +682,10 @@ window so that the location of point moves off-window. */)
682 (Lisp_Object window, Lisp_Object ncol) 682 (Lisp_Object window, Lisp_Object ncol)
683{ 683{
684 struct window *w = decode_window (window); 684 struct window *w = decode_window (window);
685 int hscroll; 685 ptrdiff_t hscroll;
686 686
687 CHECK_NUMBER (ncol); 687 CHECK_NUMBER (ncol);
688 hscroll = max (0, XINT (ncol)); 688 hscroll = clip_to_bounds (0, XINT (ncol), PTRDIFF_MAX);
689 689
690 /* Prevent redisplay shortcuts when changing the hscroll. */ 690 /* Prevent redisplay shortcuts when changing the hscroll. */
691 if (XINT (w->hscroll) != hscroll) 691 if (XINT (w->hscroll) != hscroll)
@@ -1497,7 +1497,8 @@ Return nil if window display is not up-to-date. In that case, use
1497 register struct window *w; 1497 register struct window *w;
1498 register struct buffer *b; 1498 register struct buffer *b;
1499 struct glyph_row *row, *end_row; 1499 struct glyph_row *row, *end_row;
1500 int max_y, crop, i, n; 1500 int max_y, crop, i;
1501 EMACS_INT n;
1501 1502
1502 w = decode_window (window); 1503 w = decode_window (window);
1503 1504
@@ -2565,7 +2566,7 @@ window-start value is reasonable when this function is called. */)
2565 struct window *w, *r, *s; 2566 struct window *w, *r, *s;
2566 struct frame *f; 2567 struct frame *f;
2567 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta; 2568 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2568 EMACS_INT startpos IF_LINT (= 0); 2569 ptrdiff_t startpos IF_LINT (= 0);
2569 int top IF_LINT (= 0), new_top, resize_failed; 2570 int top IF_LINT (= 0), new_top, resize_failed;
2570 Mouse_HLInfo *hlinfo; 2571 Mouse_HLInfo *hlinfo;
2571 2572
@@ -2906,7 +2907,7 @@ select_frame_norecord (Lisp_Object frame)
2906void 2907void
2907run_window_configuration_change_hook (struct frame *f) 2908run_window_configuration_change_hook (struct frame *f)
2908{ 2909{
2909 int count = SPECPDL_INDEX (); 2910 ptrdiff_t count = SPECPDL_INDEX ();
2910 Lisp_Object frame, global_wcch 2911 Lisp_Object frame, global_wcch
2911 = Fdefault_value (Qwindow_configuration_change_hook); 2912 = Fdefault_value (Qwindow_configuration_change_hook);
2912 XSETFRAME (frame, f); 2913 XSETFRAME (frame, f);
@@ -2937,7 +2938,7 @@ run_window_configuration_change_hook (struct frame *f)
2937 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook, 2938 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
2938 buffer))) 2939 buffer)))
2939 { 2940 {
2940 int inner_count = SPECPDL_INDEX (); 2941 ptrdiff_t inner_count = SPECPDL_INDEX ();
2941 record_unwind_protect (select_window_norecord, Fselected_window ()); 2942 record_unwind_protect (select_window_norecord, Fselected_window ());
2942 select_window_norecord (window); 2943 select_window_norecord (window);
2943 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, 2944 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
@@ -2972,7 +2973,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
2972{ 2973{
2973 struct window *w = XWINDOW (window); 2974 struct window *w = XWINDOW (window);
2974 struct buffer *b = XBUFFER (buffer); 2975 struct buffer *b = XBUFFER (buffer);
2975 int count = SPECPDL_INDEX (); 2976 ptrdiff_t count = SPECPDL_INDEX ();
2976 int samebuf = EQ (buffer, w->buffer); 2977 int samebuf = EQ (buffer, w->buffer);
2977 2978
2978 w->buffer = buffer; 2979 w->buffer = buffer;
@@ -3203,7 +3204,7 @@ temp_output_buffer_show (register Lisp_Object buf)
3203 /* Run temp-buffer-show-hook, with the chosen window selected 3204 /* Run temp-buffer-show-hook, with the chosen window selected
3204 and its buffer current. */ 3205 and its buffer current. */
3205 { 3206 {
3206 int count = SPECPDL_INDEX (); 3207 ptrdiff_t count = SPECPDL_INDEX ();
3207 Lisp_Object prev_window, prev_buffer; 3208 Lisp_Object prev_window, prev_buffer;
3208 prev_window = selected_window; 3209 prev_window = selected_window;
3209 XSETBUFFER (prev_buffer, old); 3210 XSETBUFFER (prev_buffer, old);
@@ -4194,9 +4195,10 @@ window_internal_height (struct window *w)
4194 respectively. */ 4195 respectively. */
4195 4196
4196static void 4197static void
4197window_scroll (Lisp_Object window, int n, int whole, int noerror) 4198window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4198{ 4199{
4199 immediate_quit = 1; 4200 immediate_quit = 1;
4201 n = clip_to_bounds (INT_MIN, n, INT_MAX);
4200 4202
4201 /* If we must, use the pixel-based version which is much slower than 4203 /* If we must, use the pixel-based version which is much slower than
4202 the line-based one but can handle varying line heights. */ 4204 the line-based one but can handle varying line heights. */
@@ -4297,7 +4299,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4297 /* Maybe modify window start instead of scrolling. */ 4299 /* Maybe modify window start instead of scrolling. */
4298 if (rbot > 0 || w->vscroll < 0) 4300 if (rbot > 0 || w->vscroll < 0)
4299 { 4301 {
4300 EMACS_INT spos; 4302 ptrdiff_t spos;
4301 4303
4302 Fset_window_vscroll (window, make_number (0), Qt); 4304 Fset_window_vscroll (window, make_number (0), Qt);
4303 /* If there are other text lines above the current row, 4305 /* If there are other text lines above the current row,
@@ -4352,7 +4354,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4352 start_display (&it, w, start); 4354 start_display (&it, w, start);
4353 if (whole) 4355 if (whole)
4354 { 4356 {
4355 EMACS_INT start_pos = IT_CHARPOS (it); 4357 ptrdiff_t start_pos = IT_CHARPOS (it);
4356 int dy = WINDOW_FRAME_LINE_HEIGHT (w); 4358 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4357 dy = max ((window_box_height (w) 4359 dy = max ((window_box_height (w)
4358 - next_screen_context_lines * dy), 4360 - next_screen_context_lines * dy),
@@ -4439,8 +4441,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4439 4441
4440 if (! vscrolled) 4442 if (! vscrolled)
4441 { 4443 {
4442 EMACS_INT pos = IT_CHARPOS (it); 4444 ptrdiff_t pos = IT_CHARPOS (it);
4443 EMACS_INT bytepos; 4445 ptrdiff_t bytepos;
4444 4446
4445 /* If in the middle of a multi-glyph character move forward to 4447 /* If in the middle of a multi-glyph character move forward to
4446 the next character. */ 4448 the next character. */
@@ -4510,7 +4512,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4510 } 4512 }
4511 else if (n < 0) 4513 else if (n < 0)
4512 { 4514 {
4513 EMACS_INT charpos, bytepos; 4515 ptrdiff_t charpos, bytepos;
4514 int partial_p; 4516 int partial_p;
4515 4517
4516 /* Save our position, for the 4518 /* Save our position, for the
@@ -4587,12 +4589,12 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4587 in `grep-mode-font-lock-keywords'). So we use a marker to record 4589 in `grep-mode-font-lock-keywords'). So we use a marker to record
4588 the old point position, to prevent crashes in SET_PT_BOTH. */ 4590 the old point position, to prevent crashes in SET_PT_BOTH. */
4589 Lisp_Object opoint_marker = Fpoint_marker (); 4591 Lisp_Object opoint_marker = Fpoint_marker ();
4590 register EMACS_INT pos, pos_byte; 4592 register ptrdiff_t pos, pos_byte;
4591 register int ht = window_internal_height (w); 4593 register int ht = window_internal_height (w);
4592 register Lisp_Object tem; 4594 register Lisp_Object tem;
4593 int lose; 4595 int lose;
4594 Lisp_Object bolp; 4596 Lisp_Object bolp;
4595 EMACS_INT startpos; 4597 ptrdiff_t startpos;
4596 Lisp_Object original_pos = Qnil; 4598 Lisp_Object original_pos = Qnil;
4597 4599
4598 /* If scrolling screen-fulls, compute the number of lines to 4600 /* If scrolling screen-fulls, compute the number of lines to
@@ -4741,7 +4743,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4741static void 4743static void
4742scroll_command (Lisp_Object n, int direction) 4744scroll_command (Lisp_Object n, int direction)
4743{ 4745{
4744 int count = SPECPDL_INDEX (); 4746 ptrdiff_t count = SPECPDL_INDEX ();
4745 4747
4746 xassert (eabs (direction) == 1); 4748 xassert (eabs (direction) == 1);
4747 4749
@@ -4856,7 +4858,7 @@ specifies the window to scroll. This takes precedence over
4856{ 4858{
4857 Lisp_Object window; 4859 Lisp_Object window;
4858 struct window *w; 4860 struct window *w;
4859 int count = SPECPDL_INDEX (); 4861 ptrdiff_t count = SPECPDL_INDEX ();
4860 4862
4861 window = Fother_window_for_scrolling (); 4863 window = Fother_window_for_scrolling ();
4862 w = XWINDOW (window); 4864 w = XWINDOW (window);
@@ -4898,7 +4900,7 @@ by this function. This happens in an interactive call. */)
4898 (register Lisp_Object arg, Lisp_Object set_minimum) 4900 (register Lisp_Object arg, Lisp_Object set_minimum)
4899{ 4901{
4900 Lisp_Object result; 4902 Lisp_Object result;
4901 int hscroll; 4903 EMACS_INT hscroll;
4902 struct window *w = XWINDOW (selected_window); 4904 struct window *w = XWINDOW (selected_window);
4903 4905
4904 if (NILP (arg)) 4906 if (NILP (arg))
@@ -4927,7 +4929,7 @@ by this function. This happens in an interactive call. */)
4927 (register Lisp_Object arg, Lisp_Object set_minimum) 4929 (register Lisp_Object arg, Lisp_Object set_minimum)
4928{ 4930{
4929 Lisp_Object result; 4931 Lisp_Object result;
4930 int hscroll; 4932 EMACS_INT hscroll;
4931 struct window *w = XWINDOW (selected_window); 4933 struct window *w = XWINDOW (selected_window);
4932 4934
4933 if (NILP (arg)) 4935 if (NILP (arg))
@@ -5038,7 +5040,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5038 struct buffer *buf = XBUFFER (w->buffer); 5040 struct buffer *buf = XBUFFER (w->buffer);
5039 struct buffer *obuf = current_buffer; 5041 struct buffer *obuf = current_buffer;
5040 int center_p = 0; 5042 int center_p = 0;
5041 EMACS_INT charpos, bytepos; 5043 ptrdiff_t charpos, bytepos;
5042 EMACS_INT iarg IF_LINT (= 0); 5044 EMACS_INT iarg IF_LINT (= 0);
5043 int this_scroll_margin; 5045 int this_scroll_margin;
5044 5046
@@ -5103,7 +5105,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5103 { 5105 {
5104 struct it it; 5106 struct it it;
5105 struct text_pos pt; 5107 struct text_pos pt;
5106 int nlines = min (INT_MAX, -iarg); 5108 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
5107 int extra_line_spacing; 5109 int extra_line_spacing;
5108 int h = window_box_height (w); 5110 int h = window_box_height (w);
5109 void *itdata = bidi_shelve_cache (); 5111 void *itdata = bidi_shelve_cache ();
@@ -5387,7 +5389,7 @@ the return value is nil. Otherwise the value is t. */)
5387 Lisp_Object frame; 5389 Lisp_Object frame;
5388 Lisp_Object auto_buffer_name; 5390 Lisp_Object auto_buffer_name;
5389 FRAME_PTR f; 5391 FRAME_PTR f;
5390 EMACS_INT old_point = -1; 5392 ptrdiff_t old_point = -1;
5391 5393
5392 CHECK_WINDOW_CONFIGURATION (configuration); 5394 CHECK_WINDOW_CONFIGURATION (configuration);
5393 5395
@@ -6192,7 +6194,7 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6192 6194
6193 if (!NILP (width)) 6195 if (!NILP (width))
6194 { 6196 {
6195 CHECK_NATNUM (width); 6197 CHECK_RANGED_INTEGER (0, width, INT_MAX);
6196 6198
6197 if (XINT (width) == 0) 6199 if (XINT (width) == 0)
6198 vertical_type = Qnil; 6200 vertical_type = Qnil;
diff --git a/src/xdisp.c b/src/xdisp.c
index 90cd3cd9e2c..82dbe4beb3b 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -760,7 +760,7 @@ static Lisp_Object Qinhibit_free_realized_faces;
760Lisp_Object help_echo_string; 760Lisp_Object help_echo_string;
761Lisp_Object help_echo_window; 761Lisp_Object help_echo_window;
762Lisp_Object help_echo_object; 762Lisp_Object help_echo_object;
763EMACS_INT help_echo_pos; 763ptrdiff_t help_echo_pos;
764 764
765/* Temporary variable for XTread_socket. */ 765/* Temporary variable for XTread_socket. */
766 766
@@ -807,33 +807,33 @@ static Lisp_Object get_it_property (struct it *it, Lisp_Object prop);
807 807
808static void handle_line_prefix (struct it *); 808static void handle_line_prefix (struct it *);
809 809
810static void pint2str (char *, int, EMACS_INT); 810static void pint2str (char *, int, ptrdiff_t);
811static void pint2hrstr (char *, int, EMACS_INT); 811static void pint2hrstr (char *, int, ptrdiff_t);
812static struct text_pos run_window_scroll_functions (Lisp_Object, 812static struct text_pos run_window_scroll_functions (Lisp_Object,
813 struct text_pos); 813 struct text_pos);
814static void reconsider_clip_changes (struct window *, struct buffer *); 814static void reconsider_clip_changes (struct window *, struct buffer *);
815static int text_outside_line_unchanged_p (struct window *, 815static int text_outside_line_unchanged_p (struct window *,
816 EMACS_INT, EMACS_INT); 816 ptrdiff_t, ptrdiff_t);
817static void store_mode_line_noprop_char (char); 817static void store_mode_line_noprop_char (char);
818static int store_mode_line_noprop (const char *, int, int); 818static int store_mode_line_noprop (const char *, int, int);
819static void handle_stop (struct it *); 819static void handle_stop (struct it *);
820static void handle_stop_backwards (struct it *, EMACS_INT); 820static void handle_stop_backwards (struct it *, ptrdiff_t);
821static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0); 821static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
822static void ensure_echo_area_buffers (void); 822static void ensure_echo_area_buffers (void);
823static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object); 823static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object);
824static Lisp_Object with_echo_area_buffer_unwind_data (struct window *); 824static Lisp_Object with_echo_area_buffer_unwind_data (struct window *);
825static int with_echo_area_buffer (struct window *, int, 825static int with_echo_area_buffer (struct window *, int,
826 int (*) (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT), 826 int (*) (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t),
827 EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 827 ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
828static void clear_garbaged_frames (void); 828static void clear_garbaged_frames (void);
829static int current_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 829static int current_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
830static void pop_message (void); 830static void pop_message (void);
831static int truncate_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 831static int truncate_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
832static void set_message (const char *, Lisp_Object, EMACS_INT, int); 832static void set_message (const char *, Lisp_Object, ptrdiff_t, int);
833static int set_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 833static int set_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
834static int display_echo_area (struct window *); 834static int display_echo_area (struct window *);
835static int display_echo_area_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 835static int display_echo_area_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
836static int resize_mini_window_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 836static int resize_mini_window_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
837static Lisp_Object unwind_redisplay (Lisp_Object); 837static Lisp_Object unwind_redisplay (Lisp_Object);
838static int string_char_and_length (const unsigned char *, int *); 838static int string_char_and_length (const unsigned char *, int *);
839static struct text_pos display_prop_end (struct it *, Lisp_Object, 839static struct text_pos display_prop_end (struct it *, Lisp_Object,
@@ -846,10 +846,10 @@ static struct glyph_row *get_overlay_arrow_glyph_row (struct window *,
846static void extend_face_to_end_of_line (struct it *); 846static void extend_face_to_end_of_line (struct it *);
847static int append_space_for_newline (struct it *, int); 847static int append_space_for_newline (struct it *, int);
848static int cursor_row_fully_visible_p (struct window *, int, int); 848static int cursor_row_fully_visible_p (struct window *, int, int);
849static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); 849static int try_scrolling (Lisp_Object, int, ptrdiff_t, ptrdiff_t, int, int);
850static int try_cursor_movement (Lisp_Object, struct text_pos, int *); 850static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
851static int trailing_whitespace_p (EMACS_INT); 851static int trailing_whitespace_p (ptrdiff_t);
852static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT); 852static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
853static void push_it (struct it *, struct text_pos *); 853static void push_it (struct it *, struct text_pos *);
854static void iterate_out_of_display_property (struct it *); 854static void iterate_out_of_display_property (struct it *);
855static void pop_it (struct it *); 855static void pop_it (struct it *);
@@ -863,7 +863,7 @@ static Lisp_Object redisplay_window_error (Lisp_Object);
863static Lisp_Object redisplay_window_0 (Lisp_Object); 863static Lisp_Object redisplay_window_0 (Lisp_Object);
864static Lisp_Object redisplay_window_1 (Lisp_Object); 864static Lisp_Object redisplay_window_1 (Lisp_Object);
865static int set_cursor_from_row (struct window *, struct glyph_row *, 865static int set_cursor_from_row (struct window *, struct glyph_row *,
866 struct glyph_matrix *, EMACS_INT, EMACS_INT, 866 struct glyph_matrix *, ptrdiff_t, ptrdiff_t,
867 int, int); 867 int, int);
868static int update_menu_bar (struct frame *, int, int); 868static int update_menu_bar (struct frame *, int, int);
869static int try_window_reusing_current_matrix (struct window *); 869static int try_window_reusing_current_matrix (struct window *);
@@ -875,14 +875,14 @@ static int display_mode_element (struct it *, int, int, int, Lisp_Object, Lisp_O
875static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object); 875static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object);
876static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *); 876static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *);
877static void display_menu_bar (struct window *); 877static void display_menu_bar (struct window *);
878static EMACS_INT display_count_lines (EMACS_INT, EMACS_INT, EMACS_INT, 878static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
879 EMACS_INT *); 879 ptrdiff_t *);
880static int display_string (const char *, Lisp_Object, Lisp_Object, 880static int display_string (const char *, Lisp_Object, Lisp_Object,
881 EMACS_INT, EMACS_INT, struct it *, int, int, int, int); 881 ptrdiff_t, ptrdiff_t, struct it *, int, int, int, int);
882static void compute_line_metrics (struct it *); 882static void compute_line_metrics (struct it *);
883static void run_redisplay_end_trigger_hook (struct it *); 883static void run_redisplay_end_trigger_hook (struct it *);
884static int get_overlay_strings (struct it *, EMACS_INT); 884static int get_overlay_strings (struct it *, ptrdiff_t);
885static int get_overlay_strings_1 (struct it *, EMACS_INT, int); 885static int get_overlay_strings_1 (struct it *, ptrdiff_t, int);
886static void next_overlay_string (struct it *); 886static void next_overlay_string (struct it *);
887static void reseat (struct it *, struct text_pos, int); 887static void reseat (struct it *, struct text_pos, int);
888static void reseat_1 (struct it *, struct text_pos, int); 888static void reseat_1 (struct it *, struct text_pos, int);
@@ -900,14 +900,14 @@ static int next_element_from_image (struct it *);
900static int next_element_from_xwidget(struct it *); 900static int next_element_from_xwidget(struct it *);
901#endif 901#endif
902static int next_element_from_stretch (struct it *); 902static int next_element_from_stretch (struct it *);
903static void load_overlay_strings (struct it *, EMACS_INT); 903static void load_overlay_strings (struct it *, ptrdiff_t);
904static int init_from_display_pos (struct it *, struct window *, 904static int init_from_display_pos (struct it *, struct window *,
905 struct display_pos *); 905 struct display_pos *);
906static void reseat_to_string (struct it *, const char *, 906static void reseat_to_string (struct it *, const char *,
907 Lisp_Object, EMACS_INT, EMACS_INT, int, int); 907 Lisp_Object, ptrdiff_t, ptrdiff_t, int, int);
908static int get_next_display_element (struct it *); 908static int get_next_display_element (struct it *);
909static enum move_it_result 909static enum move_it_result
910 move_it_in_display_line_to (struct it *, EMACS_INT, int, 910 move_it_in_display_line_to (struct it *, ptrdiff_t, int,
911 enum move_operation_enum); 911 enum move_operation_enum);
912void move_it_vertically_backward (struct it *, int); 912void move_it_vertically_backward (struct it *, int);
913static void init_to_row_start (struct it *, struct window *, 913static void init_to_row_start (struct it *, struct window *,
@@ -917,20 +917,20 @@ static int init_to_row_end (struct it *, struct window *,
917static void back_to_previous_line_start (struct it *); 917static void back_to_previous_line_start (struct it *);
918static int forward_to_next_line_start (struct it *, int *, struct bidi_it *); 918static int forward_to_next_line_start (struct it *, int *, struct bidi_it *);
919static struct text_pos string_pos_nchars_ahead (struct text_pos, 919static struct text_pos string_pos_nchars_ahead (struct text_pos,
920 Lisp_Object, EMACS_INT); 920 Lisp_Object, ptrdiff_t);
921static struct text_pos string_pos (EMACS_INT, Lisp_Object); 921static struct text_pos string_pos (ptrdiff_t, Lisp_Object);
922static struct text_pos c_string_pos (EMACS_INT, const char *, int); 922static struct text_pos c_string_pos (ptrdiff_t, const char *, int);
923static EMACS_INT number_of_chars (const char *, int); 923static ptrdiff_t number_of_chars (const char *, int);
924static void compute_stop_pos (struct it *); 924static void compute_stop_pos (struct it *);
925static void compute_string_pos (struct text_pos *, struct text_pos, 925static void compute_string_pos (struct text_pos *, struct text_pos,
926 Lisp_Object); 926 Lisp_Object);
927static int face_before_or_after_it_pos (struct it *, int); 927static int face_before_or_after_it_pos (struct it *, int);
928static EMACS_INT next_overlay_change (EMACS_INT); 928static ptrdiff_t next_overlay_change (ptrdiff_t);
929static int handle_display_spec (struct it *, Lisp_Object, Lisp_Object, 929static int handle_display_spec (struct it *, Lisp_Object, Lisp_Object,
930 Lisp_Object, struct text_pos *, EMACS_INT, int); 930 Lisp_Object, struct text_pos *, ptrdiff_t, int);
931static int handle_single_display_spec (struct it *, Lisp_Object, 931static int handle_single_display_spec (struct it *, Lisp_Object,
932 Lisp_Object, Lisp_Object, 932 Lisp_Object, Lisp_Object,
933 struct text_pos *, EMACS_INT, int, int); 933 struct text_pos *, ptrdiff_t, int, int);
934static int underlying_face_id (struct it *); 934static int underlying_face_id (struct it *);
935static int in_ellipses_for_invisible_text_p (struct display_pos *, 935static int in_ellipses_for_invisible_text_p (struct display_pos *,
936 struct window *); 936 struct window *);
@@ -1262,7 +1262,7 @@ string_from_display_spec (Lisp_Object spec)
1262 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */ 1262 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1263 1263
1264int 1264int
1265pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y, 1265pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y,
1266 int *rtop, int *rbot, int *rowh, int *vpos) 1266 int *rtop, int *rbot, int *rowh, int *vpos)
1267{ 1267{
1268 struct it it; 1268 struct it it;
@@ -1608,7 +1608,7 @@ string_char_and_length (const unsigned char *str, int *len)
1608 in STRING, return the position NCHARS ahead (NCHARS >= 0). */ 1608 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1609 1609
1610static struct text_pos 1610static struct text_pos
1611string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, EMACS_INT nchars) 1611string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, ptrdiff_t nchars)
1612{ 1612{
1613 xassert (STRINGP (string) && nchars >= 0); 1613 xassert (STRINGP (string) && nchars >= 0);
1614 1614
@@ -1636,7 +1636,7 @@ string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, EMACS_INT ncha
1636 for character position CHARPOS in STRING. */ 1636 for character position CHARPOS in STRING. */
1637 1637
1638static inline struct text_pos 1638static inline struct text_pos
1639string_pos (EMACS_INT charpos, Lisp_Object string) 1639string_pos (ptrdiff_t charpos, Lisp_Object string)
1640{ 1640{
1641 struct text_pos pos; 1641 struct text_pos pos;
1642 xassert (STRINGP (string)); 1642 xassert (STRINGP (string));
@@ -1651,7 +1651,7 @@ string_pos (EMACS_INT charpos, Lisp_Object string)
1651 means recognize multibyte characters. */ 1651 means recognize multibyte characters. */
1652 1652
1653static struct text_pos 1653static struct text_pos
1654c_string_pos (EMACS_INT charpos, const char *s, int multibyte_p) 1654c_string_pos (ptrdiff_t charpos, const char *s, int multibyte_p)
1655{ 1655{
1656 struct text_pos pos; 1656 struct text_pos pos;
1657 1657
@@ -1681,14 +1681,14 @@ c_string_pos (EMACS_INT charpos, const char *s, int multibyte_p)
1681/* Value is the number of characters in C string S. MULTIBYTE_P 1681/* Value is the number of characters in C string S. MULTIBYTE_P
1682 non-zero means recognize multibyte characters. */ 1682 non-zero means recognize multibyte characters. */
1683 1683
1684static EMACS_INT 1684static ptrdiff_t
1685number_of_chars (const char *s, int multibyte_p) 1685number_of_chars (const char *s, int multibyte_p)
1686{ 1686{
1687 EMACS_INT nchars; 1687 ptrdiff_t nchars;
1688 1688
1689 if (multibyte_p) 1689 if (multibyte_p)
1690 { 1690 {
1691 EMACS_INT rest = strlen (s); 1691 ptrdiff_t rest = strlen (s);
1692 int len; 1692 int len;
1693 const unsigned char *p = (const unsigned char *) s; 1693 const unsigned char *p = (const unsigned char *) s;
1694 1694
@@ -2404,7 +2404,7 @@ safe_call (ptrdiff_t nargs, Lisp_Object *args)
2404 val = Qnil; 2404 val = Qnil;
2405 else 2405 else
2406 { 2406 {
2407 int count = SPECPDL_INDEX (); 2407 ptrdiff_t count = SPECPDL_INDEX ();
2408 struct gcpro gcpro1; 2408 struct gcpro gcpro1;
2409 2409
2410 GCPRO1 (args[0]); 2410 GCPRO1 (args[0]);
@@ -2554,7 +2554,7 @@ check_window_end (struct window *w)
2554 2554
2555void 2555void
2556init_iterator (struct it *it, struct window *w, 2556init_iterator (struct it *it, struct window *w,
2557 EMACS_INT charpos, EMACS_INT bytepos, 2557 ptrdiff_t charpos, ptrdiff_t bytepos,
2558 struct glyph_row *row, enum face_id base_face_id) 2558 struct glyph_row *row, enum face_id base_face_id)
2559{ 2559{
2560 int highlight_region_p; 2560 int highlight_region_p;
@@ -2645,7 +2645,9 @@ init_iterator (struct it *it, struct window *w,
2645 is invisible. >0 means lines indented more than this value are 2645 is invisible. >0 means lines indented more than this value are
2646 invisible. */ 2646 invisible. */
2647 it->selective = (INTEGERP (BVAR (current_buffer, selective_display)) 2647 it->selective = (INTEGERP (BVAR (current_buffer, selective_display))
2648 ? XINT (BVAR (current_buffer, selective_display)) 2648 ? clip_to_bounds (-1, XINT (BVAR (current_buffer,
2649 selective_display)),
2650 PTRDIFF_MAX)
2649 : (!NILP (BVAR (current_buffer, selective_display)) 2651 : (!NILP (BVAR (current_buffer, selective_display))
2650 ? -1 : 0)); 2652 ? -1 : 0));
2651 it->selective_display_ellipsis_p 2653 it->selective_display_ellipsis_p
@@ -2678,7 +2680,7 @@ init_iterator (struct it *it, struct window *w,
2678 && WINDOWP (minibuf_selected_window) 2680 && WINDOWP (minibuf_selected_window)
2679 && w == XWINDOW (minibuf_selected_window)))) 2681 && w == XWINDOW (minibuf_selected_window))))
2680 { 2682 {
2681 EMACS_INT markpos = marker_position (BVAR (current_buffer, mark)); 2683 ptrdiff_t markpos = marker_position (BVAR (current_buffer, mark));
2682 it->region_beg_charpos = min (PT, markpos); 2684 it->region_beg_charpos = min (PT, markpos);
2683 it->region_end_charpos = max (PT, markpos); 2685 it->region_end_charpos = max (PT, markpos);
2684 } 2686 }
@@ -2692,7 +2694,8 @@ init_iterator (struct it *it, struct window *w,
2692 it->redisplay_end_trigger_charpos 2694 it->redisplay_end_trigger_charpos
2693 = marker_position (w->redisplay_end_trigger); 2695 = marker_position (w->redisplay_end_trigger);
2694 else if (INTEGERP (w->redisplay_end_trigger)) 2696 else if (INTEGERP (w->redisplay_end_trigger))
2695 it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); 2697 it->redisplay_end_trigger_charpos =
2698 clip_to_bounds (PTRDIFF_MIN, XINT (w->redisplay_end_trigger), PTRDIFF_MAX);
2696 2699
2697 it->tab_width = SANE_TAB_WIDTH (current_buffer); 2700 it->tab_width = SANE_TAB_WIDTH (current_buffer);
2698 2701
@@ -2952,7 +2955,7 @@ in_ellipses_for_invisible_text_p (struct display_pos *pos, struct window *w)
2952{ 2955{
2953 Lisp_Object prop, window; 2956 Lisp_Object prop, window;
2954 int ellipses_p = 0; 2957 int ellipses_p = 0;
2955 EMACS_INT charpos = CHARPOS (pos->pos); 2958 ptrdiff_t charpos = CHARPOS (pos->pos);
2956 2959
2957 /* If POS specifies a position in a display vector, this might 2960 /* If POS specifies a position in a display vector, this might
2958 be for an ellipsis displayed for invisible text. We won't 2961 be for an ellipsis displayed for invisible text. We won't
@@ -2984,7 +2987,7 @@ in_ellipses_for_invisible_text_p (struct display_pos *pos, struct window *w)
2984static int 2987static int
2985init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos) 2988init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
2986{ 2989{
2987 EMACS_INT charpos = CHARPOS (pos->pos), bytepos = BYTEPOS (pos->pos); 2990 ptrdiff_t charpos = CHARPOS (pos->pos), bytepos = BYTEPOS (pos->pos);
2988 int i, overlay_strings_with_newlines = 0; 2991 int i, overlay_strings_with_newlines = 0;
2989 2992
2990 /* If POS specifies a position in a display vector, this might 2993 /* If POS specifies a position in a display vector, this might
@@ -3044,7 +3047,7 @@ init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
3044 pos->overlay_string_index is in IT->overlay_strings. */ 3047 pos->overlay_string_index is in IT->overlay_strings. */
3045 if (pos->overlay_string_index >= OVERLAY_STRING_CHUNK_SIZE) 3048 if (pos->overlay_string_index >= OVERLAY_STRING_CHUNK_SIZE)
3046 { 3049 {
3047 int n = pos->overlay_string_index / OVERLAY_STRING_CHUNK_SIZE; 3050 ptrdiff_t n = pos->overlay_string_index / OVERLAY_STRING_CHUNK_SIZE;
3048 it->current.overlay_string_index = 0; 3051 it->current.overlay_string_index = 0;
3049 while (n--) 3052 while (n--)
3050 { 3053 {
@@ -3239,7 +3242,7 @@ compute_stop_pos (struct it *it)
3239{ 3242{
3240 register INTERVAL iv, next_iv; 3243 register INTERVAL iv, next_iv;
3241 Lisp_Object object, limit, position; 3244 Lisp_Object object, limit, position;
3242 EMACS_INT charpos, bytepos; 3245 ptrdiff_t charpos, bytepos;
3243 3246
3244 if (STRINGP (it->string)) 3247 if (STRINGP (it->string))
3245 { 3248 {
@@ -3253,7 +3256,7 @@ compute_stop_pos (struct it *it)
3253 } 3256 }
3254 else 3257 else
3255 { 3258 {
3256 EMACS_INT pos; 3259 ptrdiff_t pos;
3257 3260
3258 /* If end_charpos is out of range for some reason, such as a 3261 /* If end_charpos is out of range for some reason, such as a
3259 misbehaving display function, rationalize it (Bug#5984). */ 3262 misbehaving display function, rationalize it (Bug#5984). */
@@ -3335,7 +3338,7 @@ compute_stop_pos (struct it *it)
3335 3338
3336 if (it->cmp_it.id < 0) 3339 if (it->cmp_it.id < 0)
3337 { 3340 {
3338 EMACS_INT stoppos = it->end_charpos; 3341 ptrdiff_t stoppos = it->end_charpos;
3339 3342
3340 if (it->bidi_p && it->bidi_it.scan_dir < 0) 3343 if (it->bidi_p && it->bidi_it.scan_dir < 0)
3341 stoppos = -1; 3344 stoppos = -1;
@@ -3354,11 +3357,11 @@ compute_stop_pos (struct it *it)
3354 follows. This is like `next-overlay-change' but doesn't use 3357 follows. This is like `next-overlay-change' but doesn't use
3355 xmalloc. */ 3358 xmalloc. */
3356 3359
3357static EMACS_INT 3360static ptrdiff_t
3358next_overlay_change (EMACS_INT pos) 3361next_overlay_change (ptrdiff_t pos)
3359{ 3362{
3360 ptrdiff_t i, noverlays; 3363 ptrdiff_t i, noverlays;
3361 EMACS_INT endpos; 3364 ptrdiff_t endpos;
3362 Lisp_Object *overlays; 3365 Lisp_Object *overlays;
3363 3366
3364 /* Get all overlays at the given position. */ 3367 /* Get all overlays at the given position. */
@@ -3369,7 +3372,7 @@ next_overlay_change (EMACS_INT pos)
3369 for (i = 0; i < noverlays; ++i) 3372 for (i = 0; i < noverlays; ++i)
3370 { 3373 {
3371 Lisp_Object oend; 3374 Lisp_Object oend;
3372 EMACS_INT oendpos; 3375 ptrdiff_t oendpos;
3373 3376
3374 oend = OVERLAY_END (overlays[i]); 3377 oend = OVERLAY_END (overlays[i]);
3375 oendpos = OVERLAY_POSITION (oend); 3378 oendpos = OVERLAY_POSITION (oend);
@@ -3396,7 +3399,7 @@ next_overlay_change (EMACS_INT pos)
3396 strings, non-zero otherwise. It is set to 2 if the display string 3399 strings, non-zero otherwise. It is set to 2 if the display string
3397 uses any kind of `(space ...)' spec that will produce a stretch of 3400 uses any kind of `(space ...)' spec that will produce a stretch of
3398 white space in the text area. */ 3401 white space in the text area. */
3399EMACS_INT 3402ptrdiff_t
3400compute_display_string_pos (struct text_pos *position, 3403compute_display_string_pos (struct text_pos *position,
3401 struct bidi_string_data *string, 3404 struct bidi_string_data *string,
3402 int frame_window_p, int *disp_prop) 3405 int frame_window_p, int *disp_prop)
@@ -3406,10 +3409,10 @@ compute_display_string_pos (struct text_pos *position,
3406 (string && STRINGP (string->lstring)) ? string->lstring : Qnil; 3409 (string && STRINGP (string->lstring)) ? string->lstring : Qnil;
3407 Lisp_Object pos, spec, limpos; 3410 Lisp_Object pos, spec, limpos;
3408 int string_p = (string && (STRINGP (string->lstring) || string->s)); 3411 int string_p = (string && (STRINGP (string->lstring) || string->s));
3409 EMACS_INT eob = string_p ? string->schars : ZV; 3412 ptrdiff_t eob = string_p ? string->schars : ZV;
3410 EMACS_INT begb = string_p ? 0 : BEGV; 3413 ptrdiff_t begb = string_p ? 0 : BEGV;
3411 EMACS_INT bufpos, charpos = CHARPOS (*position); 3414 ptrdiff_t bufpos, charpos = CHARPOS (*position);
3412 EMACS_INT lim = 3415 ptrdiff_t lim =
3413 (charpos < eob - MAX_DISP_SCAN) ? charpos + MAX_DISP_SCAN : eob; 3416 (charpos < eob - MAX_DISP_SCAN) ? charpos + MAX_DISP_SCAN : eob;
3414 struct text_pos tpos; 3417 struct text_pos tpos;
3415 int rv = 0; 3418 int rv = 0;
@@ -3480,14 +3483,14 @@ compute_display_string_pos (struct text_pos *position,
3480 return -1. A display string is either an overlay with `display' 3483 return -1. A display string is either an overlay with `display'
3481 property whose value is a string or a `display' text property whose 3484 property whose value is a string or a `display' text property whose
3482 value is a string. */ 3485 value is a string. */
3483EMACS_INT 3486ptrdiff_t
3484compute_display_string_end (EMACS_INT charpos, struct bidi_string_data *string) 3487compute_display_string_end (ptrdiff_t charpos, struct bidi_string_data *string)
3485{ 3488{
3486 /* OBJECT = nil means current buffer. */ 3489 /* OBJECT = nil means current buffer. */
3487 Lisp_Object object = 3490 Lisp_Object object =
3488 (string && STRINGP (string->lstring)) ? string->lstring : Qnil; 3491 (string && STRINGP (string->lstring)) ? string->lstring : Qnil;
3489 Lisp_Object pos = make_number (charpos); 3492 Lisp_Object pos = make_number (charpos);
3490 EMACS_INT eob = 3493 ptrdiff_t eob =
3491 (STRINGP (object) || (string && string->s)) ? string->schars : ZV; 3494 (STRINGP (object) || (string && string->s)) ? string->schars : ZV;
3492 3495
3493 if (charpos >= eob || (string->s && !STRINGP (object))) 3496 if (charpos >= eob || (string->s && !STRINGP (object)))
@@ -3550,7 +3553,7 @@ handle_fontified_prop (struct it *it)
3550 no amount of fontifying will be able to change it. */ 3553 no amount of fontifying will be able to change it. */
3551 NILP (prop) && IT_CHARPOS (*it) < Z)) 3554 NILP (prop) && IT_CHARPOS (*it) < Z))
3552 { 3555 {
3553 int count = SPECPDL_INDEX (); 3556 ptrdiff_t count = SPECPDL_INDEX ();
3554 Lisp_Object val; 3557 Lisp_Object val;
3555 struct buffer *obuf = current_buffer; 3558 struct buffer *obuf = current_buffer;
3556 int begv = BEGV, zv = ZV; 3559 int begv = BEGV, zv = ZV;
@@ -3647,7 +3650,7 @@ static enum prop_handled
3647handle_face_prop (struct it *it) 3650handle_face_prop (struct it *it)
3648{ 3651{
3649 int new_face_id; 3652 int new_face_id;
3650 EMACS_INT next_stop; 3653 ptrdiff_t next_stop;
3651 3654
3652 if (!STRINGP (it->string)) 3655 if (!STRINGP (it->string))
3653 { 3656 {
@@ -3688,7 +3691,7 @@ handle_face_prop (struct it *it)
3688 else 3691 else
3689 { 3692 {
3690 int base_face_id; 3693 int base_face_id;
3691 EMACS_INT bufpos; 3694 ptrdiff_t bufpos;
3692 int i; 3695 int i;
3693 Lisp_Object from_overlay 3696 Lisp_Object from_overlay
3694 = (it->current.overlay_string_index >= 0 3697 = (it->current.overlay_string_index >= 0
@@ -3808,7 +3811,7 @@ static int
3808face_before_or_after_it_pos (struct it *it, int before_p) 3811face_before_or_after_it_pos (struct it *it, int before_p)
3809{ 3812{
3810 int face_id, limit; 3813 int face_id, limit;
3811 EMACS_INT next_check_charpos; 3814 ptrdiff_t next_check_charpos;
3812 struct it it_copy; 3815 struct it it_copy;
3813 void *it_copy_data = NULL; 3816 void *it_copy_data = NULL;
3814 3817
@@ -3816,7 +3819,7 @@ face_before_or_after_it_pos (struct it *it, int before_p)
3816 3819
3817 if (STRINGP (it->string)) 3820 if (STRINGP (it->string))
3818 { 3821 {
3819 EMACS_INT bufpos, charpos; 3822 ptrdiff_t bufpos, charpos;
3820 int base_face_id; 3823 int base_face_id;
3821 3824
3822 /* No face change past the end of the string (for the case 3825 /* No face change past the end of the string (for the case
@@ -4029,7 +4032,7 @@ handle_invisible_prop (struct it *it)
4029 if (!NILP (prop) 4032 if (!NILP (prop)
4030 && IT_STRING_CHARPOS (*it) < it->end_charpos) 4033 && IT_STRING_CHARPOS (*it) < it->end_charpos)
4031 { 4034 {
4032 EMACS_INT endpos; 4035 ptrdiff_t endpos;
4033 4036
4034 handled = HANDLED_RECOMPUTE_PROPS; 4037 handled = HANDLED_RECOMPUTE_PROPS;
4035 4038
@@ -4048,7 +4051,7 @@ handle_invisible_prop (struct it *it)
4048 && (endpos = XFASTINT (end_charpos)) < XFASTINT (limit)) 4051 && (endpos = XFASTINT (end_charpos)) < XFASTINT (limit))
4049 { 4052 {
4050 struct text_pos old; 4053 struct text_pos old;
4051 EMACS_INT oldpos; 4054 ptrdiff_t oldpos;
4052 4055
4053 old = it->current.string_pos; 4056 old = it->current.string_pos;
4054 oldpos = CHARPOS (old); 4057 oldpos = CHARPOS (old);
@@ -4100,7 +4103,7 @@ handle_invisible_prop (struct it *it)
4100 else 4103 else
4101 { 4104 {
4102 int invis_p; 4105 int invis_p;
4103 EMACS_INT newpos, next_stop, start_charpos, tem; 4106 ptrdiff_t newpos, next_stop, start_charpos, tem;
4104 Lisp_Object pos, prop, overlay; 4107 Lisp_Object pos, prop, overlay;
4105 4108
4106 /* First of all, is there invisible text at this position? */ 4109 /* First of all, is there invisible text at this position? */
@@ -4163,7 +4166,7 @@ handle_invisible_prop (struct it *it)
4163 /* The position newpos is now either ZV or on visible text. */ 4166 /* The position newpos is now either ZV or on visible text. */
4164 if (it->bidi_p) 4167 if (it->bidi_p)
4165 { 4168 {
4166 EMACS_INT bpos = CHAR_TO_BYTE (newpos); 4169 ptrdiff_t bpos = CHAR_TO_BYTE (newpos);
4167 int on_newline = 4170 int on_newline =
4168 bpos == ZV_BYTE || FETCH_BYTE (bpos) == '\n'; 4171 bpos == ZV_BYTE || FETCH_BYTE (bpos) == '\n';
4169 int after_newline = 4172 int after_newline =
@@ -4339,7 +4342,7 @@ handle_display_prop (struct it *it)
4339{ 4342{
4340 Lisp_Object propval, object, overlay; 4343 Lisp_Object propval, object, overlay;
4341 struct text_pos *position; 4344 struct text_pos *position;
4342 EMACS_INT bufpos; 4345 ptrdiff_t bufpos;
4343 /* Nonzero if some property replaces the display of the text itself. */ 4346 /* Nonzero if some property replaces the display of the text itself. */
4344 int display_replaced_p = 0; 4347 int display_replaced_p = 0;
4345 4348
@@ -4404,7 +4407,7 @@ handle_display_prop (struct it *it)
4404static int 4407static int
4405handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object, 4408handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4406 Lisp_Object overlay, struct text_pos *position, 4409 Lisp_Object overlay, struct text_pos *position,
4407 EMACS_INT bufpos, int frame_window_p) 4410 ptrdiff_t bufpos, int frame_window_p)
4408{ 4411{
4409 int replacing_p = 0; 4412 int replacing_p = 0;
4410 int rv; 4413 int rv;
@@ -4443,7 +4446,7 @@ handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4443 } 4446 }
4444 else if (VECTORP (spec)) 4447 else if (VECTORP (spec))
4445 { 4448 {
4446 int i; 4449 ptrdiff_t i;
4447 for (i = 0; i < ASIZE (spec); ++i) 4450 for (i = 0; i < ASIZE (spec); ++i)
4448 if ((rv = handle_single_display_spec (it, AREF (spec, i), object, 4451 if ((rv = handle_single_display_spec (it, AREF (spec, i), object,
4449 overlay, position, bufpos, 4452 overlay, position, bufpos,
@@ -4514,7 +4517,7 @@ display_prop_end (struct it *it, Lisp_Object object, struct text_pos start_pos)
4514static int 4517static int
4515handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object, 4518handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4516 Lisp_Object overlay, struct text_pos *position, 4519 Lisp_Object overlay, struct text_pos *position,
4517 EMACS_INT bufpos, int display_replaced_p, 4520 ptrdiff_t bufpos, int display_replaced_p,
4518 int frame_window_p) 4521 int frame_window_p)
4519{ 4522{
4520 Lisp_Object form; 4523 Lisp_Object form;
@@ -4536,7 +4539,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4536 4539
4537 if (!NILP (form) && !EQ (form, Qt)) 4540 if (!NILP (form) && !EQ (form, Qt))
4538 { 4541 {
4539 int count = SPECPDL_INDEX (); 4542 ptrdiff_t count = SPECPDL_INDEX ();
4540 struct gcpro gcpro1; 4543 struct gcpro gcpro1;
4541 4544
4542 /* Bind `object' to the object having the `display' property, a 4545 /* Bind `object' to the object having the `display' property, a
@@ -4578,7 +4581,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4578 && (EQ (XCAR (it->font_height), Qplus) 4581 && (EQ (XCAR (it->font_height), Qplus)
4579 || EQ (XCAR (it->font_height), Qminus)) 4582 || EQ (XCAR (it->font_height), Qminus))
4580 && CONSP (XCDR (it->font_height)) 4583 && CONSP (XCDR (it->font_height))
4581 && INTEGERP (XCAR (XCDR (it->font_height)))) 4584 && RANGED_INTEGERP (0, XCAR (XCDR (it->font_height)), INT_MAX))
4582 { 4585 {
4583 /* `(+ N)' or `(- N)' where N is an integer. */ 4586 /* `(+ N)' or `(- N)' where N is an integer. */
4584 int steps = XINT (XCAR (XCDR (it->font_height))); 4587 int steps = XINT (XCAR (XCDR (it->font_height)));
@@ -4610,7 +4613,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4610 { 4613 {
4611 /* Evaluate IT->font_height with `height' bound to the 4614 /* Evaluate IT->font_height with `height' bound to the
4612 current specified height to get the new height. */ 4615 current specified height to get the new height. */
4613 int count = SPECPDL_INDEX (); 4616 ptrdiff_t count = SPECPDL_INDEX ();
4614 4617
4615 specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]); 4618 specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]);
4616 value = safe_eval (it->font_height); 4619 value = safe_eval (it->font_height);
@@ -4976,7 +4979,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4976 4979
4977int 4980int
4978display_prop_intangible_p (Lisp_Object prop, Lisp_Object overlay, 4981display_prop_intangible_p (Lisp_Object prop, Lisp_Object overlay,
4979 EMACS_INT charpos, EMACS_INT bytepos) 4982 ptrdiff_t charpos, ptrdiff_t bytepos)
4980{ 4983{
4981 int frame_window_p = FRAME_WINDOW_P (XFRAME (selected_frame)); 4984 int frame_window_p = FRAME_WINDOW_P (XFRAME (selected_frame));
4982 struct text_pos position; 4985 struct text_pos position;
@@ -5057,7 +5060,7 @@ display_prop_string_p (Lisp_Object prop, Lisp_Object string)
5057 else if (VECTORP (prop)) 5060 else if (VECTORP (prop))
5058 { 5061 {
5059 /* A vector of sub-properties. */ 5062 /* A vector of sub-properties. */
5060 int i; 5063 ptrdiff_t i;
5061 for (i = 0; i < ASIZE (prop); ++i) 5064 for (i = 0; i < ASIZE (prop); ++i)
5062 if (single_display_spec_string_p (AREF (prop, i), string)) 5065 if (single_display_spec_string_p (AREF (prop, i), string))
5063 return 1; 5066 return 1;
@@ -5078,9 +5081,9 @@ display_prop_string_p (Lisp_Object prop, Lisp_Object string)
5078 This function may only use code that doesn't eval because it is 5081 This function may only use code that doesn't eval because it is
5079 called asynchronously from note_mouse_highlight. */ 5082 called asynchronously from note_mouse_highlight. */
5080 5083
5081static EMACS_INT 5084static ptrdiff_t
5082string_buffer_position_lim (Lisp_Object string, 5085string_buffer_position_lim (Lisp_Object string,
5083 EMACS_INT from, EMACS_INT to, int back_p) 5086 ptrdiff_t from, ptrdiff_t to, int back_p)
5084{ 5087{
5085 Lisp_Object limit, prop, pos; 5088 Lisp_Object limit, prop, pos;
5086 int found = 0; 5089 int found = 0;
@@ -5126,11 +5129,11 @@ string_buffer_position_lim (Lisp_Object string,
5126 This function may only use code that doesn't eval because it is 5129 This function may only use code that doesn't eval because it is
5127 called asynchronously from note_mouse_highlight. */ 5130 called asynchronously from note_mouse_highlight. */
5128 5131
5129static EMACS_INT 5132static ptrdiff_t
5130string_buffer_position (Lisp_Object string, EMACS_INT around_charpos) 5133string_buffer_position (Lisp_Object string, ptrdiff_t around_charpos)
5131{ 5134{
5132 const int MAX_DISTANCE = 1000; 5135 const int MAX_DISTANCE = 1000;
5133 EMACS_INT found = string_buffer_position_lim (string, around_charpos, 5136 ptrdiff_t found = string_buffer_position_lim (string, around_charpos,
5134 around_charpos + MAX_DISTANCE, 5137 around_charpos + MAX_DISTANCE,
5135 0); 5138 0);
5136 5139
@@ -5153,7 +5156,7 @@ static enum prop_handled
5153handle_composition_prop (struct it *it) 5156handle_composition_prop (struct it *it)
5154{ 5157{
5155 Lisp_Object prop, string; 5158 Lisp_Object prop, string;
5156 EMACS_INT pos, pos_byte, start, end; 5159 ptrdiff_t pos, pos_byte, start, end;
5157 5160
5158 if (STRINGP (it->string)) 5161 if (STRINGP (it->string))
5159 { 5162 {
@@ -5219,7 +5222,7 @@ struct overlay_entry
5219{ 5222{
5220 Lisp_Object overlay; 5223 Lisp_Object overlay;
5221 Lisp_Object string; 5224 Lisp_Object string;
5222 int priority; 5225 EMACS_INT priority;
5223 int after_string_p; 5226 int after_string_p;
5224}; 5227};
5225 5228
@@ -5351,12 +5354,17 @@ compare_overlay_entries (const void *e1, const void *e2)
5351 else 5354 else
5352 result = entry1->after_string_p ? -1 : 1; 5355 result = entry1->after_string_p ? -1 : 1;
5353 } 5356 }
5354 else if (entry1->after_string_p) 5357 else if (entry1->priority != entry2->priority)
5355 /* After-strings sorted in order of decreasing priority. */ 5358 {
5356 result = entry2->priority - entry1->priority; 5359 if (entry1->after_string_p)
5360 /* After-strings sorted in order of decreasing priority. */
5361 result = entry2->priority < entry1->priority ? -1 : 1;
5362 else
5363 /* Before-strings sorted in order of increasing priority. */
5364 result = entry1->priority < entry2->priority ? -1 : 1;
5365 }
5357 else 5366 else
5358 /* Before-strings sorted in order of increasing priority. */ 5367 result = 0;
5359 result = entry1->priority - entry2->priority;
5360 5368
5361 return result; 5369 return result;
5362} 5370}
@@ -5387,15 +5395,17 @@ compare_overlay_entries (const void *e1, const void *e2)
5387 compare_overlay_entries. */ 5395 compare_overlay_entries. */
5388 5396
5389static void 5397static void
5390load_overlay_strings (struct it *it, EMACS_INT charpos) 5398load_overlay_strings (struct it *it, ptrdiff_t charpos)
5391{ 5399{
5392 Lisp_Object overlay, window, str, invisible; 5400 Lisp_Object overlay, window, str, invisible;
5393 struct Lisp_Overlay *ov; 5401 struct Lisp_Overlay *ov;
5394 EMACS_INT start, end; 5402 ptrdiff_t start, end;
5395 int size = 20; 5403 ptrdiff_t size = 20;
5396 int n = 0, i, j, invis_p; 5404 ptrdiff_t n = 0, i, j;
5405 int invis_p;
5397 struct overlay_entry *entries 5406 struct overlay_entry *entries
5398 = (struct overlay_entry *) alloca (size * sizeof *entries); 5407 = (struct overlay_entry *) alloca (size * sizeof *entries);
5408 USE_SAFE_ALLOCA;
5399 5409
5400 if (charpos <= 0) 5410 if (charpos <= 0)
5401 charpos = IT_CHARPOS (*it); 5411 charpos = IT_CHARPOS (*it);
@@ -5411,13 +5421,10 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5411 \ 5421 \
5412 if (n == size) \ 5422 if (n == size) \
5413 { \ 5423 { \
5414 int new_size = 2 * size; \
5415 struct overlay_entry *old = entries; \ 5424 struct overlay_entry *old = entries; \
5416 entries = \ 5425 SAFE_NALLOCA (entries, 2, size); \
5417 (struct overlay_entry *) alloca (new_size \
5418 * sizeof *entries); \
5419 memcpy (entries, old, size * sizeof *entries); \ 5426 memcpy (entries, old, size * sizeof *entries); \
5420 size = new_size; \ 5427 size *= 2; \
5421 } \ 5428 } \
5422 \ 5429 \
5423 entries[n].string = (STRING); \ 5430 entries[n].string = (STRING); \
@@ -5530,6 +5537,7 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5530 } 5537 }
5531 5538
5532 CHECK_IT (it); 5539 CHECK_IT (it);
5540 SAFE_FREE ();
5533} 5541}
5534 5542
5535 5543
@@ -5538,7 +5546,7 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5538 least one overlay string was found. */ 5546 least one overlay string was found. */
5539 5547
5540static int 5548static int
5541get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p) 5549get_overlay_strings_1 (struct it *it, ptrdiff_t charpos, int compute_stop_p)
5542{ 5550{
5543 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to 5551 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5544 process. This fills IT->overlay_strings with strings, and sets 5552 process. This fills IT->overlay_strings with strings, and sets
@@ -5602,7 +5610,7 @@ get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p)
5602 /* Set up the bidi iterator for this overlay string. */ 5610 /* Set up the bidi iterator for this overlay string. */
5603 if (it->bidi_p) 5611 if (it->bidi_p)
5604 { 5612 {
5605 EMACS_INT pos = (charpos > 0 ? charpos : IT_CHARPOS (*it)); 5613 ptrdiff_t pos = (charpos > 0 ? charpos : IT_CHARPOS (*it));
5606 5614
5607 it->bidi_it.string.lstring = it->string; 5615 it->bidi_it.string.lstring = it->string;
5608 it->bidi_it.string.s = NULL; 5616 it->bidi_it.string.s = NULL;
@@ -5620,7 +5628,7 @@ get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p)
5620} 5628}
5621 5629
5622static int 5630static int
5623get_overlay_strings (struct it *it, EMACS_INT charpos) 5631get_overlay_strings (struct it *it, ptrdiff_t charpos)
5624{ 5632{
5625 it->string = Qnil; 5633 it->string = Qnil;
5626 it->method = GET_FROM_BUFFER; 5634 it->method = GET_FROM_BUFFER;
@@ -5706,8 +5714,8 @@ static void
5706iterate_out_of_display_property (struct it *it) 5714iterate_out_of_display_property (struct it *it)
5707{ 5715{
5708 int buffer_p = !STRINGP (it->string); 5716 int buffer_p = !STRINGP (it->string);
5709 EMACS_INT eob = (buffer_p ? ZV : it->end_charpos); 5717 ptrdiff_t eob = (buffer_p ? ZV : it->end_charpos);
5710 EMACS_INT bob = (buffer_p ? BEGV : 0); 5718 ptrdiff_t bob = (buffer_p ? BEGV : 0);
5711 5719
5712 xassert (eob >= CHARPOS (it->position) && CHARPOS (it->position) >= bob); 5720 xassert (eob >= CHARPOS (it->position) && CHARPOS (it->position) >= bob);
5713 5721
@@ -5874,7 +5882,7 @@ static int
5874forward_to_next_line_start (struct it *it, int *skipped_p, 5882forward_to_next_line_start (struct it *it, int *skipped_p,
5875 struct bidi_it *bidi_it_prev) 5883 struct bidi_it *bidi_it_prev)
5876{ 5884{
5877 EMACS_INT old_selective; 5885 ptrdiff_t old_selective;
5878 int newline_found_p, n; 5886 int newline_found_p, n;
5879 const int MAX_NEWLINE_DISTANCE = 500; 5887 const int MAX_NEWLINE_DISTANCE = 500;
5880 5888
@@ -5916,8 +5924,8 @@ forward_to_next_line_start (struct it *it, int *skipped_p,
5916 short-cut. */ 5924 short-cut. */
5917 if (!newline_found_p) 5925 if (!newline_found_p)
5918 { 5926 {
5919 EMACS_INT start = IT_CHARPOS (*it); 5927 ptrdiff_t start = IT_CHARPOS (*it);
5920 EMACS_INT limit = find_next_newline_no_quit (start, 1); 5928 ptrdiff_t limit = find_next_newline_no_quit (start, 1);
5921 Lisp_Object pos; 5929 Lisp_Object pos;
5922 5930
5923 xassert (!STRINGP (it->string)); 5931 xassert (!STRINGP (it->string));
@@ -6015,8 +6023,8 @@ back_to_previous_visible_line_start (struct it *it)
6015 { 6023 {
6016 struct it it2; 6024 struct it it2;
6017 void *it2data = NULL; 6025 void *it2data = NULL;
6018 EMACS_INT pos; 6026 ptrdiff_t pos;
6019 EMACS_INT beg, end; 6027 ptrdiff_t beg, end;
6020 Lisp_Object val, overlay; 6028 Lisp_Object val, overlay;
6021 6029
6022 SAVE_IT (it2, *it, it2data); 6030 SAVE_IT (it2, *it, it2data);
@@ -6169,7 +6177,7 @@ reseat_at_next_visible_line_start (struct it *it, int on_newline_p)
6169static void 6177static void
6170reseat (struct it *it, struct text_pos pos, int force_p) 6178reseat (struct it *it, struct text_pos pos, int force_p)
6171{ 6179{
6172 EMACS_INT original_pos = IT_CHARPOS (*it); 6180 ptrdiff_t original_pos = IT_CHARPOS (*it);
6173 6181
6174 reseat_1 (it, pos, 0); 6182 reseat_1 (it, pos, 0);
6175 6183
@@ -6279,7 +6287,7 @@ reseat_1 (struct it *it, struct text_pos pos, int set_stop_p)
6279 6287
6280static void 6288static void
6281reseat_to_string (struct it *it, const char *s, Lisp_Object string, 6289reseat_to_string (struct it *it, const char *s, Lisp_Object string,
6282 EMACS_INT charpos, EMACS_INT precision, int field_width, 6290 ptrdiff_t charpos, ptrdiff_t precision, int field_width,
6283 int multibyte) 6291 int multibyte)
6284{ 6292{
6285 /* No region in strings. */ 6293 /* No region in strings. */
@@ -6397,7 +6405,7 @@ reseat_to_string (struct it *it, const char *s, Lisp_Object string,
6397 } 6405 }
6398 if (s == NULL && it->multibyte_p) 6406 if (s == NULL && it->multibyte_p)
6399 { 6407 {
6400 EMACS_INT endpos = SCHARS (it->string); 6408 ptrdiff_t endpos = SCHARS (it->string);
6401 if (endpos > it->end_charpos) 6409 if (endpos > it->end_charpos)
6402 endpos = it->end_charpos; 6410 endpos = it->end_charpos;
6403 composition_compute_stop_pos (&it->cmp_it, charpos, -1, endpos, 6411 composition_compute_stop_pos (&it->cmp_it, charpos, -1, endpos,
@@ -6508,11 +6516,11 @@ lookup_glyphless_char_display (int c, struct it *it)
6508 end of buffer (or C string) is reached. */ 6516 end of buffer (or C string) is reached. */
6509 6517
6510static struct frame *last_escape_glyph_frame = NULL; 6518static struct frame *last_escape_glyph_frame = NULL;
6511static unsigned last_escape_glyph_face_id = (1 << FACE_ID_BITS); 6519static int last_escape_glyph_face_id = (1 << FACE_ID_BITS);
6512static int last_escape_glyph_merged_face_id = 0; 6520static int last_escape_glyph_merged_face_id = 0;
6513 6521
6514struct frame *last_glyphless_glyph_frame = NULL; 6522struct frame *last_glyphless_glyph_frame = NULL;
6515unsigned last_glyphless_glyph_face_id = (1 << FACE_ID_BITS); 6523int last_glyphless_glyph_face_id = (1 << FACE_ID_BITS);
6516int last_glyphless_glyph_merged_face_id = 0; 6524int last_glyphless_glyph_merged_face_id = 0;
6517 6525
6518static int 6526static int
@@ -6644,7 +6652,7 @@ get_next_display_element (struct it *it)
6644 Lisp_Object gc; 6652 Lisp_Object gc;
6645 int ctl_len; 6653 int ctl_len;
6646 int face_id; 6654 int face_id;
6647 EMACS_INT lface_id = 0; 6655 int lface_id = 0;
6648 int escape_glyph; 6656 int escape_glyph;
6649 6657
6650 /* Handle control characters with ^. */ 6658 /* Handle control characters with ^. */
@@ -6656,8 +6664,7 @@ get_next_display_element (struct it *it)
6656 g = '^'; /* default glyph for Control */ 6664 g = '^'; /* default glyph for Control */
6657 /* Set IT->ctl_chars[0] to the glyph for `^'. */ 6665 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6658 if (it->dp 6666 if (it->dp
6659 && (gc = DISP_CTRL_GLYPH (it->dp), GLYPH_CODE_P (gc)) 6667 && (gc = DISP_CTRL_GLYPH (it->dp), GLYPH_CODE_P (gc)))
6660 && GLYPH_CODE_CHAR_VALID_P (gc))
6661 { 6668 {
6662 g = GLYPH_CODE_CHAR (gc); 6669 g = GLYPH_CODE_CHAR (gc);
6663 lface_id = GLYPH_CODE_FACE (gc); 6670 lface_id = GLYPH_CODE_FACE (gc);
@@ -6706,8 +6713,7 @@ get_next_display_element (struct it *it)
6706 escape_glyph = '\\'; 6713 escape_glyph = '\\';
6707 6714
6708 if (it->dp 6715 if (it->dp
6709 && (gc = DISP_ESCAPE_GLYPH (it->dp), GLYPH_CODE_P (gc)) 6716 && (gc = DISP_ESCAPE_GLYPH (it->dp), GLYPH_CODE_P (gc)))
6710 && GLYPH_CODE_CHAR_VALID_P (gc))
6711 { 6717 {
6712 escape_glyph = GLYPH_CODE_CHAR (gc); 6718 escape_glyph = GLYPH_CODE_CHAR (gc);
6713 lface_id = GLYPH_CODE_FACE (gc); 6719 lface_id = GLYPH_CODE_FACE (gc);
@@ -6806,7 +6812,7 @@ get_next_display_element (struct it *it)
6806 } 6812 }
6807 else 6813 else
6808 { 6814 {
6809 EMACS_INT pos = (it->s ? -1 6815 ptrdiff_t pos = (it->s ? -1
6810 : STRINGP (it->string) ? IT_STRING_CHARPOS (*it) 6816 : STRINGP (it->string) ? IT_STRING_CHARPOS (*it)
6811 : IT_CHARPOS (*it)); 6817 : IT_CHARPOS (*it));
6812 int c; 6818 int c;
@@ -6858,7 +6864,7 @@ get_next_display_element (struct it *it)
6858 && (it->current.overlay_string_index 6864 && (it->current.overlay_string_index
6859 == it->n_overlay_strings - 1)) 6865 == it->n_overlay_strings - 1))
6860 { 6866 {
6861 EMACS_INT ignore; 6867 ptrdiff_t ignore;
6862 int next_face_id; 6868 int next_face_id;
6863 struct text_pos pos = it->current.pos; 6869 struct text_pos pos = it->current.pos;
6864 INC_TEXT_POS (pos, it->multibyte_p); 6870 INC_TEXT_POS (pos, it->multibyte_p);
@@ -6970,7 +6976,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6970 { 6976 {
6971 /* No more grapheme clusters in this composition. 6977 /* No more grapheme clusters in this composition.
6972 Find the next stop position. */ 6978 Find the next stop position. */
6973 EMACS_INT stop = it->end_charpos; 6979 ptrdiff_t stop = it->end_charpos;
6974 if (it->bidi_it.scan_dir < 0) 6980 if (it->bidi_it.scan_dir < 0)
6975 /* Now we are scanning backward and don't know 6981 /* Now we are scanning backward and don't know
6976 where to stop. */ 6982 where to stop. */
@@ -6998,7 +7004,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6998 { 7004 {
6999 /* No more grapheme clusters in this composition. 7005 /* No more grapheme clusters in this composition.
7000 Find the next stop position. */ 7006 Find the next stop position. */
7001 EMACS_INT stop = it->end_charpos; 7007 ptrdiff_t stop = it->end_charpos;
7002 if (it->bidi_it.scan_dir < 0) 7008 if (it->bidi_it.scan_dir < 0)
7003 /* Now we are scanning backward and don't know 7009 /* Now we are scanning backward and don't know
7004 where to stop. */ 7010 where to stop. */
@@ -7031,7 +7037,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7031 { 7037 {
7032 /* As the scan direction was changed, we must 7038 /* As the scan direction was changed, we must
7033 re-compute the stop position for composition. */ 7039 re-compute the stop position for composition. */
7034 EMACS_INT stop = it->end_charpos; 7040 ptrdiff_t stop = it->end_charpos;
7035 if (it->bidi_it.scan_dir < 0) 7041 if (it->bidi_it.scan_dir < 0)
7036 stop = -1; 7042 stop = -1;
7037 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it), 7043 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
@@ -7161,7 +7167,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7161 it->cmp_it.from = it->cmp_it.to; 7167 it->cmp_it.from = it->cmp_it.to;
7162 else 7168 else
7163 { 7169 {
7164 EMACS_INT stop = it->end_charpos; 7170 ptrdiff_t stop = it->end_charpos;
7165 if (it->bidi_it.scan_dir < 0) 7171 if (it->bidi_it.scan_dir < 0)
7166 stop = -1; 7172 stop = -1;
7167 composition_compute_stop_pos (&it->cmp_it, 7173 composition_compute_stop_pos (&it->cmp_it,
@@ -7180,7 +7186,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7180 it->cmp_it.to = it->cmp_it.from; 7186 it->cmp_it.to = it->cmp_it.from;
7181 else 7187 else
7182 { 7188 {
7183 EMACS_INT stop = it->end_charpos; 7189 ptrdiff_t stop = it->end_charpos;
7184 if (it->bidi_it.scan_dir < 0) 7190 if (it->bidi_it.scan_dir < 0)
7185 stop = -1; 7191 stop = -1;
7186 composition_compute_stop_pos (&it->cmp_it, 7192 composition_compute_stop_pos (&it->cmp_it,
@@ -7212,7 +7218,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7212 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos; 7218 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos;
7213 if (prev_scan_dir != it->bidi_it.scan_dir) 7219 if (prev_scan_dir != it->bidi_it.scan_dir)
7214 { 7220 {
7215 EMACS_INT stop = it->end_charpos; 7221 ptrdiff_t stop = it->end_charpos;
7216 7222
7217 if (it->bidi_it.scan_dir < 0) 7223 if (it->bidi_it.scan_dir < 0)
7218 stop = -1; 7224 stop = -1;
@@ -7301,7 +7307,7 @@ next_element_from_display_vector (struct it *it)
7301 That seemed totally bogus - so I changed it... */ 7307 That seemed totally bogus - so I changed it... */
7302 gc = it->dpvec[it->current.dpvec_index]; 7308 gc = it->dpvec[it->current.dpvec_index];
7303 7309
7304 if (GLYPH_CODE_P (gc) && GLYPH_CODE_CHAR_VALID_P (gc)) 7310 if (GLYPH_CODE_P (gc))
7305 { 7311 {
7306 it->c = GLYPH_CODE_CHAR (gc); 7312 it->c = GLYPH_CODE_CHAR (gc);
7307 it->len = CHAR_BYTES (it->c); 7313 it->len = CHAR_BYTES (it->c);
@@ -7313,7 +7319,7 @@ next_element_from_display_vector (struct it *it)
7313 it->face_id = it->dpvec_face_id; 7319 it->face_id = it->dpvec_face_id;
7314 else 7320 else
7315 { 7321 {
7316 EMACS_INT lface_id = GLYPH_CODE_FACE (gc); 7322 int lface_id = GLYPH_CODE_FACE (gc);
7317 if (lface_id > 0) 7323 if (lface_id > 0)
7318 it->face_id = merge_faces (it->f, Qt, lface_id, 7324 it->face_id = merge_faces (it->f, Qt, lface_id,
7319 it->saved_face_id); 7325 it->saved_face_id);
@@ -7336,8 +7342,8 @@ static void
7336get_visually_first_element (struct it *it) 7342get_visually_first_element (struct it *it)
7337{ 7343{
7338 int string_p = STRINGP (it->string) || it->s; 7344 int string_p = STRINGP (it->string) || it->s;
7339 EMACS_INT eob = (string_p ? it->bidi_it.string.schars : ZV); 7345 ptrdiff_t eob = (string_p ? it->bidi_it.string.schars : ZV);
7340 EMACS_INT bob = (string_p ? 0 : BEGV); 7346 ptrdiff_t bob = (string_p ? 0 : BEGV);
7341 7347
7342 if (STRINGP (it->string)) 7348 if (STRINGP (it->string))
7343 { 7349 {
@@ -7369,7 +7375,7 @@ get_visually_first_element (struct it *it)
7369 } 7375 }
7370 else 7376 else
7371 { 7377 {
7372 EMACS_INT orig_bytepos = it->bidi_it.bytepos; 7378 ptrdiff_t orig_bytepos = it->bidi_it.bytepos;
7373 7379
7374 /* We need to prime the bidi iterator starting at the line's or 7380 /* We need to prime the bidi iterator starting at the line's or
7375 string's beginning, before we will be able to produce the 7381 string's beginning, before we will be able to produce the
@@ -7407,7 +7413,7 @@ get_visually_first_element (struct it *it)
7407 7413
7408 if (STRINGP (it->string) || !it->s) 7414 if (STRINGP (it->string) || !it->s)
7409 { 7415 {
7410 EMACS_INT stop, charpos, bytepos; 7416 ptrdiff_t stop, charpos, bytepos;
7411 7417
7412 if (STRINGP (it->string)) 7418 if (STRINGP (it->string))
7413 { 7419 {
@@ -7721,10 +7727,10 @@ compute_stop_pos_backwards (struct it *it)
7721 struct text_pos pos; 7727 struct text_pos pos;
7722 struct display_pos save_current = it->current; 7728 struct display_pos save_current = it->current;
7723 struct text_pos save_position = it->position; 7729 struct text_pos save_position = it->position;
7724 EMACS_INT charpos = IT_CHARPOS (*it); 7730 ptrdiff_t charpos = IT_CHARPOS (*it);
7725 EMACS_INT where_we_are = charpos; 7731 ptrdiff_t where_we_are = charpos;
7726 EMACS_INT save_stop_pos = it->stop_charpos; 7732 ptrdiff_t save_stop_pos = it->stop_charpos;
7727 EMACS_INT save_end_pos = it->end_charpos; 7733 ptrdiff_t save_end_pos = it->end_charpos;
7728 7734
7729 xassert (NILP (it->string) && !it->s); 7735 xassert (NILP (it->string) && !it->s);
7730 xassert (it->bidi_p); 7736 xassert (it->bidi_p);
@@ -7762,14 +7768,14 @@ compute_stop_pos_backwards (struct it *it)
7762 position. */ 7768 position. */
7763 7769
7764static void 7770static void
7765handle_stop_backwards (struct it *it, EMACS_INT charpos) 7771handle_stop_backwards (struct it *it, ptrdiff_t charpos)
7766{ 7772{
7767 int bufp = !STRINGP (it->string); 7773 int bufp = !STRINGP (it->string);
7768 EMACS_INT where_we_are = (bufp ? IT_CHARPOS (*it) : IT_STRING_CHARPOS (*it)); 7774 ptrdiff_t where_we_are = (bufp ? IT_CHARPOS (*it) : IT_STRING_CHARPOS (*it));
7769 struct display_pos save_current = it->current; 7775 struct display_pos save_current = it->current;
7770 struct text_pos save_position = it->position; 7776 struct text_pos save_position = it->position;
7771 struct text_pos pos1; 7777 struct text_pos pos1;
7772 EMACS_INT next_stop; 7778 ptrdiff_t next_stop;
7773 7779
7774 /* Scan in strict logical order. */ 7780 /* Scan in strict logical order. */
7775 xassert (it->bidi_p); 7781 xassert (it->bidi_p);
@@ -7913,7 +7919,7 @@ next_element_from_buffer (struct it *it)
7913 /* No face changes, overlays etc. in sight, so just return a 7919 /* No face changes, overlays etc. in sight, so just return a
7914 character from current_buffer. */ 7920 character from current_buffer. */
7915 unsigned char *p; 7921 unsigned char *p;
7916 EMACS_INT stop; 7922 ptrdiff_t stop;
7917 7923
7918 /* Maybe run the redisplay end trigger hook. Performance note: 7924 /* Maybe run the redisplay end trigger hook. Performance note:
7919 This doesn't seem to cost measurable time. */ 7925 This doesn't seem to cost measurable time. */
@@ -8102,7 +8108,7 @@ next_element_from_composition (struct it *it)
8102 8108
8103static enum move_it_result 8109static enum move_it_result
8104move_it_in_display_line_to (struct it *it, 8110move_it_in_display_line_to (struct it *it,
8105 EMACS_INT to_charpos, int to_x, 8111 ptrdiff_t to_charpos, int to_x,
8106 enum move_operation_enum op) 8112 enum move_operation_enum op)
8107{ 8113{
8108 enum move_it_result result = MOVE_UNDEFINED; 8114 enum move_it_result result = MOVE_UNDEFINED;
@@ -8112,7 +8118,7 @@ move_it_in_display_line_to (struct it *it,
8112 void *ppos_data = NULL; 8118 void *ppos_data = NULL;
8113 int may_wrap = 0; 8119 int may_wrap = 0;
8114 enum it_method prev_method = it->method; 8120 enum it_method prev_method = it->method;
8115 EMACS_INT prev_pos = IT_CHARPOS (*it); 8121 ptrdiff_t prev_pos = IT_CHARPOS (*it);
8116 int saw_smaller_pos = prev_pos < to_charpos; 8122 int saw_smaller_pos = prev_pos < to_charpos;
8117 8123
8118 /* Don't produce glyphs in produce_glyphs. */ 8124 /* Don't produce glyphs in produce_glyphs. */
@@ -8606,7 +8612,7 @@ move_it_in_display_line_to (struct it *it,
8606/* For external use. */ 8612/* For external use. */
8607void 8613void
8608move_it_in_display_line (struct it *it, 8614move_it_in_display_line (struct it *it,
8609 EMACS_INT to_charpos, int to_x, 8615 ptrdiff_t to_charpos, int to_x,
8610 enum move_operation_enum op) 8616 enum move_operation_enum op)
8611{ 8617{
8612 if (it->line_wrap == WORD_WRAP 8618 if (it->line_wrap == WORD_WRAP
@@ -8649,7 +8655,7 @@ move_it_in_display_line (struct it *it,
8649 displayed to the right of TO_CHARPOS on the screen. */ 8655 displayed to the right of TO_CHARPOS on the screen. */
8650 8656
8651void 8657void
8652move_it_to (struct it *it, EMACS_INT to_charpos, int to_x, int to_y, int to_vpos, int op) 8658move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos, int op)
8653{ 8659{
8654 enum move_it_result skip, skip2 = MOVE_X_REACHED; 8660 enum move_it_result skip, skip2 = MOVE_X_REACHED;
8655 int line_height, line_start_x = 0, reached = 0; 8661 int line_height, line_start_x = 0, reached = 0;
@@ -8753,8 +8759,18 @@ move_it_to (struct it *it, EMACS_INT to_charpos, int to_x, int to_y, int to_vpos
8753 { 8759 {
8754 /* If TO_Y is in this line and TO_X was reached 8760 /* If TO_Y is in this line and TO_X was reached
8755 above, we scanned too far. We have to restore 8761 above, we scanned too far. We have to restore
8756 IT's settings to the ones before skipping. */ 8762 IT's settings to the ones before skipping. But
8763 keep the more accurate values of max_ascent and
8764 max_descent we've found while skipping the rest
8765 of the line, for the sake of callers, such as
8766 pos_visible_p, that need to know the line
8767 height. */
8768 int max_ascent = it->max_ascent;
8769 int max_descent = it->max_descent;
8770
8757 RESTORE_IT (it, &it_backup, backup_data); 8771 RESTORE_IT (it, &it_backup, backup_data);
8772 it->max_ascent = max_ascent;
8773 it->max_descent = max_descent;
8758 reached = 6; 8774 reached = 6;
8759 } 8775 }
8760 else 8776 else
@@ -8916,7 +8932,7 @@ move_it_vertically_backward (struct it *it, int dy)
8916 int nlines, h; 8932 int nlines, h;
8917 struct it it2, it3; 8933 struct it it2, it3;
8918 void *it2data = NULL, *it3data = NULL; 8934 void *it2data = NULL, *it3data = NULL;
8919 EMACS_INT start_pos; 8935 ptrdiff_t start_pos;
8920 8936
8921 move_further_back: 8937 move_further_back:
8922 xassert (dy >= 0); 8938 xassert (dy >= 0);
@@ -8998,7 +9014,7 @@ move_it_vertically_backward (struct it *it, int dy)
8998 && IT_CHARPOS (*it) > BEGV 9014 && IT_CHARPOS (*it) > BEGV
8999 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n') 9015 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
9000 { 9016 {
9001 EMACS_INT nl_pos = 9017 ptrdiff_t nl_pos =
9002 find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1); 9018 find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1);
9003 9019
9004 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS); 9020 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS);
@@ -9108,7 +9124,7 @@ move_it_past_eol (struct it *it)
9108 truncate-lines nil. */ 9124 truncate-lines nil. */
9109 9125
9110void 9126void
9111move_it_by_lines (struct it *it, int dvpos) 9127move_it_by_lines (struct it *it, ptrdiff_t dvpos)
9112{ 9128{
9113 9129
9114 /* The commented-out optimization uses vmotion on terminals. This 9130 /* The commented-out optimization uses vmotion on terminals. This
@@ -9157,7 +9173,7 @@ move_it_by_lines (struct it *it, int dvpos)
9157 { 9173 {
9158 struct it it2; 9174 struct it it2;
9159 void *it2data = NULL; 9175 void *it2data = NULL;
9160 EMACS_INT start_charpos, i; 9176 ptrdiff_t start_charpos, i;
9161 9177
9162 /* Start at the beginning of the screen line containing IT's 9178 /* Start at the beginning of the screen line containing IT's
9163 position. This may actually move vertically backwards, 9179 position. This may actually move vertically backwards,
@@ -9243,7 +9259,7 @@ add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
9243 Lisp_Object args[3]; 9259 Lisp_Object args[3];
9244 Lisp_Object msg, fmt; 9260 Lisp_Object msg, fmt;
9245 char *buffer; 9261 char *buffer;
9246 EMACS_INT len; 9262 ptrdiff_t len;
9247 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 9263 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9248 USE_SAFE_ALLOCA; 9264 USE_SAFE_ALLOCA;
9249 9265
@@ -9292,7 +9308,7 @@ message_log_maybe_newline (void)
9292 so the buffer M must NOT point to a Lisp string. */ 9308 so the buffer M must NOT point to a Lisp string. */
9293 9309
9294void 9310void
9295message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) 9311message_dolog (const char *m, ptrdiff_t nbytes, int nlflag, int multibyte)
9296{ 9312{
9297 const unsigned char *msg = (const unsigned char *) m; 9313 const unsigned char *msg = (const unsigned char *) m;
9298 9314
@@ -9304,8 +9320,8 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9304 struct buffer *oldbuf; 9320 struct buffer *oldbuf;
9305 Lisp_Object oldpoint, oldbegv, oldzv; 9321 Lisp_Object oldpoint, oldbegv, oldzv;
9306 int old_windows_or_buffers_changed = windows_or_buffers_changed; 9322 int old_windows_or_buffers_changed = windows_or_buffers_changed;
9307 EMACS_INT point_at_end = 0; 9323 ptrdiff_t point_at_end = 0;
9308 EMACS_INT zv_at_end = 0; 9324 ptrdiff_t zv_at_end = 0;
9309 Lisp_Object old_deactivate_mark, tem; 9325 Lisp_Object old_deactivate_mark, tem;
9310 struct gcpro gcpro1; 9326 struct gcpro gcpro1;
9311 9327
@@ -9338,7 +9354,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9338 if (multibyte 9354 if (multibyte
9339 && NILP (BVAR (current_buffer, enable_multibyte_characters))) 9355 && NILP (BVAR (current_buffer, enable_multibyte_characters)))
9340 { 9356 {
9341 EMACS_INT i; 9357 ptrdiff_t i;
9342 int c, char_bytes; 9358 int c, char_bytes;
9343 char work[1]; 9359 char work[1];
9344 9360
@@ -9356,7 +9372,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9356 else if (! multibyte 9372 else if (! multibyte
9357 && ! NILP (BVAR (current_buffer, enable_multibyte_characters))) 9373 && ! NILP (BVAR (current_buffer, enable_multibyte_characters)))
9358 { 9374 {
9359 EMACS_INT i; 9375 ptrdiff_t i;
9360 int c, char_bytes; 9376 int c, char_bytes;
9361 unsigned char str[MAX_MULTIBYTE_LENGTH]; 9377 unsigned char str[MAX_MULTIBYTE_LENGTH];
9362 /* Convert a single-byte string to multibyte 9378 /* Convert a single-byte string to multibyte
@@ -9374,7 +9390,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9374 9390
9375 if (nlflag) 9391 if (nlflag)
9376 { 9392 {
9377 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; 9393 ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte;
9378 printmax_t dups; 9394 printmax_t dups;
9379 insert_1 ("\n", 1, 1, 0, 0); 9395 insert_1 ("\n", 1, 1, 0, 0);
9380 9396
@@ -9467,10 +9483,10 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9467 value N > 1 if we should also append " [N times]". */ 9483 value N > 1 if we should also append " [N times]". */
9468 9484
9469static intmax_t 9485static intmax_t
9470message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) 9486message_log_check_duplicate (ptrdiff_t prev_bol_byte, ptrdiff_t this_bol_byte)
9471{ 9487{
9472 EMACS_INT i; 9488 ptrdiff_t i;
9473 EMACS_INT len = Z_BYTE - 1 - this_bol_byte; 9489 ptrdiff_t len = Z_BYTE - 1 - this_bol_byte;
9474 int seen_dots = 0; 9490 int seen_dots = 0;
9475 unsigned char *p1 = BUF_BYTE_ADDRESS (current_buffer, prev_bol_byte); 9491 unsigned char *p1 = BUF_BYTE_ADDRESS (current_buffer, prev_bol_byte);
9476 unsigned char *p2 = BUF_BYTE_ADDRESS (current_buffer, this_bol_byte); 9492 unsigned char *p2 = BUF_BYTE_ADDRESS (current_buffer, this_bol_byte);
@@ -9504,7 +9520,7 @@ message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte)
9504 This may GC, so the buffer M must NOT point to a Lisp string. */ 9520 This may GC, so the buffer M must NOT point to a Lisp string. */
9505 9521
9506void 9522void
9507message2 (const char *m, EMACS_INT nbytes, int multibyte) 9523message2 (const char *m, ptrdiff_t nbytes, int multibyte)
9508{ 9524{
9509 /* First flush out any partial line written with print. */ 9525 /* First flush out any partial line written with print. */
9510 message_log_maybe_newline (); 9526 message_log_maybe_newline ();
@@ -9517,7 +9533,7 @@ message2 (const char *m, EMACS_INT nbytes, int multibyte)
9517/* The non-logging counterpart of message2. */ 9533/* The non-logging counterpart of message2. */
9518 9534
9519void 9535void
9520message2_nolog (const char *m, EMACS_INT nbytes, int multibyte) 9536message2_nolog (const char *m, ptrdiff_t nbytes, int multibyte)
9521{ 9537{
9522 struct frame *sf = SELECTED_FRAME (); 9538 struct frame *sf = SELECTED_FRAME ();
9523 message_enable_multibyte = multibyte; 9539 message_enable_multibyte = multibyte;
@@ -9579,7 +9595,7 @@ message2_nolog (const char *m, EMACS_INT nbytes, int multibyte)
9579 This function cancels echoing. */ 9595 This function cancels echoing. */
9580 9596
9581void 9597void
9582message3 (Lisp_Object m, EMACS_INT nbytes, int multibyte) 9598message3 (Lisp_Object m, ptrdiff_t nbytes, int multibyte)
9583{ 9599{
9584 struct gcpro gcpro1; 9600 struct gcpro gcpro1;
9585 9601
@@ -9611,7 +9627,7 @@ message3 (Lisp_Object m, EMACS_INT nbytes, int multibyte)
9611 and make this cancel echoing. */ 9627 and make this cancel echoing. */
9612 9628
9613void 9629void
9614message3_nolog (Lisp_Object m, EMACS_INT nbytes, int multibyte) 9630message3_nolog (Lisp_Object m, ptrdiff_t nbytes, int multibyte)
9615{ 9631{
9616 struct frame *sf = SELECTED_FRAME (); 9632 struct frame *sf = SELECTED_FRAME ();
9617 message_enable_multibyte = multibyte; 9633 message_enable_multibyte = multibyte;
@@ -9908,12 +9924,12 @@ ensure_echo_area_buffers (void)
9908 9924
9909static int 9925static int
9910with_echo_area_buffer (struct window *w, int which, 9926with_echo_area_buffer (struct window *w, int which,
9911 int (*fn) (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT), 9927 int (*fn) (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t),
9912 EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 9928 ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
9913{ 9929{
9914 Lisp_Object buffer; 9930 Lisp_Object buffer;
9915 int this_one, the_other, clear_buffer_p, rc; 9931 int this_one, the_other, clear_buffer_p, rc;
9916 int count = SPECPDL_INDEX (); 9932 ptrdiff_t count = SPECPDL_INDEX ();
9917 9933
9918 /* If buffers aren't live, make new ones. */ 9934 /* If buffers aren't live, make new ones. */
9919 ensure_echo_area_buffers (); 9935 ensure_echo_area_buffers ();
@@ -10089,7 +10105,7 @@ setup_echo_area_for_printing (int multibyte_p)
10089 10105
10090 if (Z > BEG) 10106 if (Z > BEG)
10091 { 10107 {
10092 int count = SPECPDL_INDEX (); 10108 ptrdiff_t count = SPECPDL_INDEX ();
10093 specbind (Qinhibit_read_only, Qt); 10109 specbind (Qinhibit_read_only, Qt);
10094 /* Note that undo recording is always disabled. */ 10110 /* Note that undo recording is always disabled. */
10095 del_range (BEG, Z); 10111 del_range (BEG, Z);
@@ -10142,14 +10158,14 @@ setup_echo_area_for_printing (int multibyte_p)
10142static int 10158static int
10143display_echo_area (struct window *w) 10159display_echo_area (struct window *w)
10144{ 10160{
10145 int i, no_message_p, window_height_changed_p, count; 10161 int i, no_message_p, window_height_changed_p;
10146 10162
10147 /* Temporarily disable garbage collections while displaying the echo 10163 /* Temporarily disable garbage collections while displaying the echo
10148 area. This is done because a GC can print a message itself. 10164 area. This is done because a GC can print a message itself.
10149 That message would modify the echo area buffer's contents while a 10165 That message would modify the echo area buffer's contents while a
10150 redisplay of the buffer is going on, and seriously confuse 10166 redisplay of the buffer is going on, and seriously confuse
10151 redisplay. */ 10167 redisplay. */
10152 count = inhibit_garbage_collection (); 10168 ptrdiff_t count = inhibit_garbage_collection ();
10153 10169
10154 /* If there is no message, we must call display_echo_area_1 10170 /* If there is no message, we must call display_echo_area_1
10155 nevertheless because it resizes the window. But we will have to 10171 nevertheless because it resizes the window. But we will have to
@@ -10178,7 +10194,7 @@ display_echo_area (struct window *w)
10178 Value is non-zero if height of W was changed. */ 10194 Value is non-zero if height of W was changed. */
10179 10195
10180static int 10196static int
10181display_echo_area_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10197display_echo_area_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10182{ 10198{
10183 intptr_t i1 = a1; 10199 intptr_t i1 = a1;
10184 struct window *w = (struct window *) i1; 10200 struct window *w = (struct window *) i1;
@@ -10242,7 +10258,7 @@ resize_echo_area_exactly (void)
10242 resize_mini_window returns. */ 10258 resize_mini_window returns. */
10243 10259
10244static int 10260static int
10245resize_mini_window_1 (EMACS_INT a1, Lisp_Object exactly, EMACS_INT a3, EMACS_INT a4) 10261resize_mini_window_1 (ptrdiff_t a1, Lisp_Object exactly, ptrdiff_t a3, ptrdiff_t a4)
10246{ 10262{
10247 intptr_t i1 = a1; 10263 intptr_t i1 = a1;
10248 return resize_mini_window ((struct window *) i1, !NILP (exactly)); 10264 return resize_mini_window ((struct window *) i1, !NILP (exactly));
@@ -10292,7 +10308,8 @@ resize_mini_window (struct window *w, int exact_p)
10292 struct it it; 10308 struct it it;
10293 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f)); 10309 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
10294 int total_height = WINDOW_TOTAL_LINES (root) + WINDOW_TOTAL_LINES (w); 10310 int total_height = WINDOW_TOTAL_LINES (root) + WINDOW_TOTAL_LINES (w);
10295 int height, max_height; 10311 int height;
10312 EMACS_INT max_height;
10296 int unit = FRAME_LINE_HEIGHT (f); 10313 int unit = FRAME_LINE_HEIGHT (f);
10297 struct text_pos start; 10314 struct text_pos start;
10298 struct buffer *old_current_buffer = NULL; 10315 struct buffer *old_current_buffer = NULL;
@@ -10421,7 +10438,7 @@ current_message (void)
10421 10438
10422 10439
10423static int 10440static int
10424current_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10441current_message_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10425{ 10442{
10426 intptr_t i1 = a1; 10443 intptr_t i1 = a1;
10427 Lisp_Object *msg = (Lisp_Object *) i1; 10444 Lisp_Object *msg = (Lisp_Object *) i1;
@@ -10500,7 +10517,7 @@ check_message_stack (void)
10500 time we display it---but don't redisplay it now. */ 10517 time we display it---but don't redisplay it now. */
10501 10518
10502void 10519void
10503truncate_echo_area (EMACS_INT nchars) 10520truncate_echo_area (ptrdiff_t nchars)
10504{ 10521{
10505 if (nchars == 0) 10522 if (nchars == 0)
10506 echo_area_buffer[0] = Qnil; 10523 echo_area_buffer[0] = Qnil;
@@ -10522,7 +10539,7 @@ truncate_echo_area (EMACS_INT nchars)
10522 message to at most NCHARS characters. */ 10539 message to at most NCHARS characters. */
10523 10540
10524static int 10541static int
10525truncate_message_1 (EMACS_INT nchars, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10542truncate_message_1 (ptrdiff_t nchars, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10526{ 10543{
10527 if (BEG + nchars < Z) 10544 if (BEG + nchars < Z)
10528 del_range (BEG + nchars, Z); 10545 del_range (BEG + nchars, Z);
@@ -10548,7 +10565,7 @@ truncate_message_1 (EMACS_INT nchars, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4
10548 10565
10549static void 10566static void
10550set_message (const char *s, Lisp_Object string, 10567set_message (const char *s, Lisp_Object string,
10551 EMACS_INT nbytes, int multibyte_p) 10568 ptrdiff_t nbytes, int multibyte_p)
10552{ 10569{
10553 message_enable_multibyte 10570 message_enable_multibyte
10554 = ((s && multibyte_p) 10571 = ((s && multibyte_p)
@@ -10567,7 +10584,7 @@ set_message (const char *s, Lisp_Object string,
10567 current. */ 10584 current. */
10568 10585
10569static int 10586static int
10570set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multibyte_p) 10587set_message_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t nbytes, ptrdiff_t multibyte_p)
10571{ 10588{
10572 intptr_t i1 = a1; 10589 intptr_t i1 = a1;
10573 const char *s = (const char *) i1; 10590 const char *s = (const char *) i1;
@@ -10588,7 +10605,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10588 10605
10589 if (STRINGP (string)) 10606 if (STRINGP (string))
10590 { 10607 {
10591 EMACS_INT nchars; 10608 ptrdiff_t nchars;
10592 10609
10593 if (nbytes == 0) 10610 if (nbytes == 0)
10594 nbytes = SBYTES (string); 10611 nbytes = SBYTES (string);
@@ -10607,7 +10624,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10607 if (multibyte_p && NILP (BVAR (current_buffer, enable_multibyte_characters))) 10624 if (multibyte_p && NILP (BVAR (current_buffer, enable_multibyte_characters)))
10608 { 10625 {
10609 /* Convert from multi-byte to single-byte. */ 10626 /* Convert from multi-byte to single-byte. */
10610 EMACS_INT i; 10627 ptrdiff_t i;
10611 int c, n; 10628 int c, n;
10612 char work[1]; 10629 char work[1];
10613 10630
@@ -10625,7 +10642,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10625 && !NILP (BVAR (current_buffer, enable_multibyte_characters))) 10642 && !NILP (BVAR (current_buffer, enable_multibyte_characters)))
10626 { 10643 {
10627 /* Convert from single-byte to multi-byte. */ 10644 /* Convert from single-byte to multi-byte. */
10628 EMACS_INT i; 10645 ptrdiff_t i;
10629 int c, n; 10646 int c, n;
10630 unsigned char str[MAX_MULTIBYTE_LENGTH]; 10647 unsigned char str[MAX_MULTIBYTE_LENGTH];
10631 10648
@@ -10770,7 +10787,7 @@ echo_area_display (int update_frame_p)
10770 /* Must update other windows. Likewise as in other 10787 /* Must update other windows. Likewise as in other
10771 cases, don't let this update be interrupted by 10788 cases, don't let this update be interrupted by
10772 pending input. */ 10789 pending input. */
10773 int count = SPECPDL_INDEX (); 10790 ptrdiff_t count = SPECPDL_INDEX ();
10774 specbind (Qredisplay_dont_pause, Qt); 10791 specbind (Qredisplay_dont_pause, Qt);
10775 windows_or_buffers_changed = 1; 10792 windows_or_buffers_changed = 1;
10776 redisplay_internal (); 10793 redisplay_internal ();
@@ -10947,7 +10964,7 @@ store_mode_line_noprop (const char *string, int field_width, int precision)
10947{ 10964{
10948 const unsigned char *str = (const unsigned char *) string; 10965 const unsigned char *str = (const unsigned char *) string;
10949 int n = 0; 10966 int n = 0;
10950 EMACS_INT dummy, nbytes; 10967 ptrdiff_t dummy, nbytes;
10951 10968
10952 /* Copy at most PRECISION chars from STR. */ 10969 /* Copy at most PRECISION chars from STR. */
10953 nbytes = strlen (string); 10970 nbytes = strlen (string);
@@ -10992,7 +11009,7 @@ x_consider_frame_title (Lisp_Object frame)
10992 char *title; 11009 char *title;
10993 ptrdiff_t len; 11010 ptrdiff_t len;
10994 struct it it; 11011 struct it it;
10995 int count = SPECPDL_INDEX (); 11012 ptrdiff_t count = SPECPDL_INDEX ();
10996 11013
10997 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) 11014 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
10998 { 11015 {
@@ -11095,7 +11112,7 @@ prepare_menu_bars (void)
11095 if (all_windows) 11112 if (all_windows)
11096 { 11113 {
11097 Lisp_Object tail, frame; 11114 Lisp_Object tail, frame;
11098 int count = SPECPDL_INDEX (); 11115 ptrdiff_t count = SPECPDL_INDEX ();
11099 /* 1 means that update_menu_bar has run its hooks 11116 /* 1 means that update_menu_bar has run its hooks
11100 so any further calls to update_menu_bar shouldn't do so again. */ 11117 so any further calls to update_menu_bar shouldn't do so again. */
11101 int menu_bar_hooks_run = 0; 11118 int menu_bar_hooks_run = 0;
@@ -11212,7 +11229,7 @@ update_menu_bar (struct frame *f, int save_match_data, int hooks_run)
11212 != !NILP (w->region_showing))) 11229 != !NILP (w->region_showing)))
11213 { 11230 {
11214 struct buffer *prev = current_buffer; 11231 struct buffer *prev = current_buffer;
11215 int count = SPECPDL_INDEX (); 11232 ptrdiff_t count = SPECPDL_INDEX ();
11216 11233
11217 specbind (Qinhibit_menubar_update, Qt); 11234 specbind (Qinhibit_menubar_update, Qt);
11218 11235
@@ -11410,7 +11427,7 @@ update_tool_bar (struct frame *f, int save_match_data)
11410 != !NILP (w->region_showing))) 11427 != !NILP (w->region_showing)))
11411 { 11428 {
11412 struct buffer *prev = current_buffer; 11429 struct buffer *prev = current_buffer;
11413 int count = SPECPDL_INDEX (); 11430 ptrdiff_t count = SPECPDL_INDEX ();
11414 Lisp_Object frame, new_tool_bar; 11431 Lisp_Object frame, new_tool_bar;
11415 int new_n_tool_bar; 11432 int new_n_tool_bar;
11416 struct gcpro gcpro1; 11433 struct gcpro gcpro1;
@@ -11548,20 +11565,20 @@ build_desired_tool_bar_string (struct frame *f)
11548 : DEFAULT_TOOL_BAR_BUTTON_RELIEF); 11565 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
11549 hmargin = vmargin = relief; 11566 hmargin = vmargin = relief;
11550 11567
11551 if (INTEGERP (Vtool_bar_button_margin) 11568 if (RANGED_INTEGERP (1, Vtool_bar_button_margin,
11552 && XINT (Vtool_bar_button_margin) > 0) 11569 INT_MAX - max (hmargin, vmargin)))
11553 { 11570 {
11554 hmargin += XFASTINT (Vtool_bar_button_margin); 11571 hmargin += XFASTINT (Vtool_bar_button_margin);
11555 vmargin += XFASTINT (Vtool_bar_button_margin); 11572 vmargin += XFASTINT (Vtool_bar_button_margin);
11556 } 11573 }
11557 else if (CONSP (Vtool_bar_button_margin)) 11574 else if (CONSP (Vtool_bar_button_margin))
11558 { 11575 {
11559 if (INTEGERP (XCAR (Vtool_bar_button_margin)) 11576 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin),
11560 && XINT (XCAR (Vtool_bar_button_margin)) > 0) 11577 INT_MAX - hmargin))
11561 hmargin += XFASTINT (XCAR (Vtool_bar_button_margin)); 11578 hmargin += XFASTINT (XCAR (Vtool_bar_button_margin));
11562 11579
11563 if (INTEGERP (XCDR (Vtool_bar_button_margin)) 11580 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin),
11564 && XINT (XCDR (Vtool_bar_button_margin)) > 0) 11581 INT_MAX - vmargin))
11565 vmargin += XFASTINT (XCDR (Vtool_bar_button_margin)); 11582 vmargin += XFASTINT (XCDR (Vtool_bar_button_margin));
11566 } 11583 }
11567 11584
@@ -11907,7 +11924,7 @@ redisplay_tool_bar (struct frame *f)
11907 { 11924 {
11908 int border, rows, height, extra; 11925 int border, rows, height, extra;
11909 11926
11910 if (INTEGERP (Vtool_bar_border)) 11927 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border))
11911 border = XINT (Vtool_bar_border); 11928 border = XINT (Vtool_bar_border);
11912 else if (EQ (Vtool_bar_border, Qinternal_border_width)) 11929 else if (EQ (Vtool_bar_border, Qinternal_border_width))
11913 border = FRAME_INTERNAL_BORDER_WIDTH (f); 11930 border = FRAME_INTERNAL_BORDER_WIDTH (f);
@@ -12095,7 +12112,7 @@ get_tool_bar_item (struct frame *f, int x, int y, struct glyph **glyph,
12095 12112
12096void 12113void
12097handle_tool_bar_click (struct frame *f, int x, int y, int down_p, 12114handle_tool_bar_click (struct frame *f, int x, int y, int down_p,
12098 unsigned int modifiers) 12115 int modifiers)
12099{ 12116{
12100 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 12117 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
12101 struct window *w = XWINDOW (f->tool_bar_window); 12118 struct window *w = XWINDOW (f->tool_bar_window);
@@ -12274,7 +12291,7 @@ hscroll_window_tree (Lisp_Object window)
12274 hscroll_step_abs = 0; 12291 hscroll_step_abs = 0;
12275 } 12292 }
12276 } 12293 }
12277 else if (INTEGERP (Vhscroll_step)) 12294 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step))
12278 { 12295 {
12279 hscroll_step_abs = XINT (Vhscroll_step); 12296 hscroll_step_abs = XINT (Vhscroll_step);
12280 if (hscroll_step_abs < 0) 12297 if (hscroll_step_abs < 0)
@@ -12338,9 +12355,9 @@ hscroll_window_tree (Lisp_Object window)
12338 && (w->cursor.x >= text_area_width - h_margin)))))) 12355 && (w->cursor.x >= text_area_width - h_margin))))))
12339 { 12356 {
12340 struct it it; 12357 struct it it;
12341 int hscroll; 12358 ptrdiff_t hscroll;
12342 struct buffer *saved_current_buffer; 12359 struct buffer *saved_current_buffer;
12343 EMACS_INT pt; 12360 ptrdiff_t pt;
12344 int wanted_x; 12361 int wanted_x;
12345 12362
12346 /* Find point in a display of infinite width. */ 12363 /* Find point in a display of infinite width. */
@@ -12455,12 +12472,12 @@ static int debug_dvpos, debug_dy;
12455 12472
12456/* Delta in characters and bytes for try_window_id. */ 12473/* Delta in characters and bytes for try_window_id. */
12457 12474
12458static EMACS_INT debug_delta, debug_delta_bytes; 12475static ptrdiff_t debug_delta, debug_delta_bytes;
12459 12476
12460/* Values of window_end_pos and window_end_vpos at the end of 12477/* Values of window_end_pos and window_end_vpos at the end of
12461 try_window_id. */ 12478 try_window_id. */
12462 12479
12463static EMACS_INT debug_end_vpos; 12480static ptrdiff_t debug_end_vpos;
12464 12481
12465/* Append a string to W->desired_matrix->method. FMT is a printf 12482/* Append a string to W->desired_matrix->method. FMT is a printf
12466 format string. If trace_redisplay_p is non-zero also printf the 12483 format string. If trace_redisplay_p is non-zero also printf the
@@ -12510,7 +12527,7 @@ debug_method_add (struct window *w, char const *fmt, ...)
12510 12527
12511static inline int 12528static inline int
12512text_outside_line_unchanged_p (struct window *w, 12529text_outside_line_unchanged_p (struct window *w,
12513 EMACS_INT start, EMACS_INT end) 12530 ptrdiff_t start, ptrdiff_t end)
12514{ 12531{
12515 int unchanged_p = 1; 12532 int unchanged_p = 1;
12516 12533
@@ -12733,10 +12750,10 @@ overlay_arrow_at_row (struct it *it, struct glyph_row *row)
12733 position. BUF and PT are the current point buffer and position. */ 12750 position. BUF and PT are the current point buffer and position. */
12734 12751
12735static int 12752static int
12736check_point_in_composition (struct buffer *prev_buf, EMACS_INT prev_pt, 12753check_point_in_composition (struct buffer *prev_buf, ptrdiff_t prev_pt,
12737 struct buffer *buf, EMACS_INT pt) 12754 struct buffer *buf, ptrdiff_t pt)
12738{ 12755{
12739 EMACS_INT start, end; 12756 ptrdiff_t start, end;
12740 Lisp_Object prop; 12757 Lisp_Object prop;
12741 Lisp_Object buffer; 12758 Lisp_Object buffer;
12742 12759
@@ -12787,7 +12804,7 @@ reconsider_clip_changes (struct window *w, struct buffer *b)
12787 if (!b->clip_changed 12804 if (!b->clip_changed
12788 && BUFFERP (w->buffer) && !NILP (w->window_end_valid)) 12805 && BUFFERP (w->buffer) && !NILP (w->window_end_valid))
12789 { 12806 {
12790 EMACS_INT pt; 12807 ptrdiff_t pt;
12791 12808
12792 if (w == XWINDOW (selected_window)) 12809 if (w == XWINDOW (selected_window))
12793 pt = PT; 12810 pt = PT;
@@ -12856,7 +12873,7 @@ redisplay_internal (void)
12856 int must_finish = 0; 12873 int must_finish = 0;
12857 struct text_pos tlbufpos, tlendpos; 12874 struct text_pos tlbufpos, tlendpos;
12858 int number_of_visible_frames; 12875 int number_of_visible_frames;
12859 int count, count1; 12876 ptrdiff_t count, count1;
12860 struct frame *sf; 12877 struct frame *sf;
12861 int polling_stopped_here = 0; 12878 int polling_stopped_here = 0;
12862 Lisp_Object old_frame = selected_frame; 12879 Lisp_Object old_frame = selected_frame;
@@ -13206,7 +13223,7 @@ redisplay_internal (void)
13206 { 13223 {
13207 struct glyph_row *row 13224 struct glyph_row *row
13208 = MATRIX_ROW (w->current_matrix, this_line_vpos + 1); 13225 = MATRIX_ROW (w->current_matrix, this_line_vpos + 1);
13209 EMACS_INT delta, delta_bytes; 13226 ptrdiff_t delta, delta_bytes;
13210 13227
13211 /* We used to distinguish between two cases here, 13228 /* We used to distinguish between two cases here,
13212 conditioned by Z - CHARPOS (tlendpos) == ZV, for 13229 conditioned by Z - CHARPOS (tlendpos) == ZV, for
@@ -13841,18 +13858,18 @@ redisplay_window_1 (Lisp_Object window)
13841static int 13858static int
13842set_cursor_from_row (struct window *w, struct glyph_row *row, 13859set_cursor_from_row (struct window *w, struct glyph_row *row,
13843 struct glyph_matrix *matrix, 13860 struct glyph_matrix *matrix,
13844 EMACS_INT delta, EMACS_INT delta_bytes, 13861 ptrdiff_t delta, ptrdiff_t delta_bytes,
13845 int dy, int dvpos) 13862 int dy, int dvpos)
13846{ 13863{
13847 struct glyph *glyph = row->glyphs[TEXT_AREA]; 13864 struct glyph *glyph = row->glyphs[TEXT_AREA];
13848 struct glyph *end = glyph + row->used[TEXT_AREA]; 13865 struct glyph *end = glyph + row->used[TEXT_AREA];
13849 struct glyph *cursor = NULL; 13866 struct glyph *cursor = NULL;
13850 /* The last known character position in row. */ 13867 /* The last known character position in row. */
13851 EMACS_INT last_pos = MATRIX_ROW_START_CHARPOS (row) + delta; 13868 ptrdiff_t last_pos = MATRIX_ROW_START_CHARPOS (row) + delta;
13852 int x = row->x; 13869 int x = row->x;
13853 EMACS_INT pt_old = PT - delta; 13870 ptrdiff_t pt_old = PT - delta;
13854 EMACS_INT pos_before = MATRIX_ROW_START_CHARPOS (row) + delta; 13871 ptrdiff_t pos_before = MATRIX_ROW_START_CHARPOS (row) + delta;
13855 EMACS_INT pos_after = MATRIX_ROW_END_CHARPOS (row) + delta; 13872 ptrdiff_t pos_after = MATRIX_ROW_END_CHARPOS (row) + delta;
13856 struct glyph *glyph_before = glyph - 1, *glyph_after = end; 13873 struct glyph *glyph_before = glyph - 1, *glyph_after = end;
13857 /* A glyph beyond the edge of TEXT_AREA which we should never 13874 /* A glyph beyond the edge of TEXT_AREA which we should never
13858 touch. */ 13875 touch. */
@@ -13865,11 +13882,11 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13865 int string_seen = 0; 13882 int string_seen = 0;
13866 /* Largest and smallest buffer positions seen so far during scan of 13883 /* Largest and smallest buffer positions seen so far during scan of
13867 glyph row. */ 13884 glyph row. */
13868 EMACS_INT bpos_max = pos_before; 13885 ptrdiff_t bpos_max = pos_before;
13869 EMACS_INT bpos_min = pos_after; 13886 ptrdiff_t bpos_min = pos_after;
13870 /* Last buffer position covered by an overlay string with an integer 13887 /* Last buffer position covered by an overlay string with an integer
13871 `cursor' property. */ 13888 `cursor' property. */
13872 EMACS_INT bpos_covered = 0; 13889 ptrdiff_t bpos_covered = 0;
13873 /* Non-zero means the display string on which to display the cursor 13890 /* Non-zero means the display string on which to display the cursor
13874 comes from a text property, not from an overlay. */ 13891 comes from a text property, not from an overlay. */
13875 int string_from_text_prop = 0; 13892 int string_from_text_prop = 0;
@@ -13962,7 +13979,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13962 { 13979 {
13963 if (BUFFERP (glyph->object)) 13980 if (BUFFERP (glyph->object))
13964 { 13981 {
13965 EMACS_INT dpos = glyph->charpos - pt_old; 13982 ptrdiff_t dpos = glyph->charpos - pt_old;
13966 13983
13967 if (glyph->charpos > bpos_max) 13984 if (glyph->charpos > bpos_max)
13968 bpos_max = glyph->charpos; 13985 bpos_max = glyph->charpos;
@@ -13999,7 +14016,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13999 else if (STRINGP (glyph->object)) 14016 else if (STRINGP (glyph->object))
14000 { 14017 {
14001 Lisp_Object chprop; 14018 Lisp_Object chprop;
14002 EMACS_INT glyph_pos = glyph->charpos; 14019 ptrdiff_t glyph_pos = glyph->charpos;
14003 14020
14004 chprop = Fget_char_property (make_number (glyph_pos), Qcursor, 14021 chprop = Fget_char_property (make_number (glyph_pos), Qcursor,
14005 glyph->object); 14022 glyph->object);
@@ -14015,7 +14032,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14015 text is completely covered by display properties, 14032 text is completely covered by display properties,
14016 so that no glyph with valid buffer positions is 14033 so that no glyph with valid buffer positions is
14017 ever seen in the row. */ 14034 ever seen in the row. */
14018 EMACS_INT prop_pos = 14035 ptrdiff_t prop_pos =
14019 string_buffer_position_lim (glyph->object, pos_before, 14036 string_buffer_position_lim (glyph->object, pos_before,
14020 pos_after, 0); 14037 pos_after, 0);
14021 14038
@@ -14053,7 +14070,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14053 { 14070 {
14054 if (BUFFERP (glyph->object)) 14071 if (BUFFERP (glyph->object))
14055 { 14072 {
14056 EMACS_INT dpos = glyph->charpos - pt_old; 14073 ptrdiff_t dpos = glyph->charpos - pt_old;
14057 14074
14058 if (glyph->charpos > bpos_max) 14075 if (glyph->charpos > bpos_max)
14059 bpos_max = glyph->charpos; 14076 bpos_max = glyph->charpos;
@@ -14083,13 +14100,13 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14083 else if (STRINGP (glyph->object)) 14100 else if (STRINGP (glyph->object))
14084 { 14101 {
14085 Lisp_Object chprop; 14102 Lisp_Object chprop;
14086 EMACS_INT glyph_pos = glyph->charpos; 14103 ptrdiff_t glyph_pos = glyph->charpos;
14087 14104
14088 chprop = Fget_char_property (make_number (glyph_pos), Qcursor, 14105 chprop = Fget_char_property (make_number (glyph_pos), Qcursor,
14089 glyph->object); 14106 glyph->object);
14090 if (!NILP (chprop)) 14107 if (!NILP (chprop))
14091 { 14108 {
14092 EMACS_INT prop_pos = 14109 ptrdiff_t prop_pos =
14093 string_buffer_position_lim (glyph->object, pos_before, 14110 string_buffer_position_lim (glyph->object, pos_before,
14094 pos_after, 0); 14111 pos_after, 0);
14095 14112
@@ -14137,7 +14154,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14137 14154
14138 if (row->ends_in_ellipsis_p && pos_after == last_pos) 14155 if (row->ends_in_ellipsis_p && pos_after == last_pos)
14139 { 14156 {
14140 EMACS_INT ellipsis_pos; 14157 ptrdiff_t ellipsis_pos;
14141 14158
14142 /* Scan back over the ellipsis glyphs. */ 14159 /* Scan back over the ellipsis glyphs. */
14143 if (!row->reversed_p) 14160 if (!row->reversed_p)
@@ -14177,7 +14194,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14177 positioned between POS_BEFORE and POS_AFTER in the 14194 positioned between POS_BEFORE and POS_AFTER in the
14178 buffer. */ 14195 buffer. */
14179 struct glyph *start, *stop; 14196 struct glyph *start, *stop;
14180 EMACS_INT pos = pos_before; 14197 ptrdiff_t pos = pos_before;
14181 14198
14182 x = -1; 14199 x = -1;
14183 14200
@@ -14220,10 +14237,10 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14220 if (STRINGP (glyph->object)) 14237 if (STRINGP (glyph->object))
14221 { 14238 {
14222 Lisp_Object str; 14239 Lisp_Object str;
14223 EMACS_INT tem; 14240 ptrdiff_t tem;
14224 /* If the display property covers the newline, we 14241 /* If the display property covers the newline, we
14225 need to search for it one position farther. */ 14242 need to search for it one position farther. */
14226 EMACS_INT lim = pos_after 14243 ptrdiff_t lim = pos_after
14227 + (pos_after == MATRIX_ROW_END_CHARPOS (row) + delta); 14244 + (pos_after == MATRIX_ROW_END_CHARPOS (row) + delta);
14228 14245
14229 string_from_text_prop = 0; 14246 string_from_text_prop = 0;
@@ -14252,7 +14269,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14252 be a character in the string with the 14269 be a character in the string with the
14253 `cursor' property, which means display 14270 `cursor' property, which means display
14254 cursor on that character's glyph. */ 14271 cursor on that character's glyph. */
14255 EMACS_INT strpos = glyph->charpos; 14272 ptrdiff_t strpos = glyph->charpos;
14256 14273
14257 if (tem) 14274 if (tem)
14258 { 14275 {
@@ -14265,7 +14282,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14265 glyph += incr) 14282 glyph += incr)
14266 { 14283 {
14267 Lisp_Object cprop; 14284 Lisp_Object cprop;
14268 EMACS_INT gpos = glyph->charpos; 14285 ptrdiff_t gpos = glyph->charpos;
14269 14286
14270 cprop = Fget_char_property (make_number (gpos), 14287 cprop = Fget_char_property (make_number (gpos),
14271 Qcursor, 14288 Qcursor,
@@ -14556,7 +14573,7 @@ enum
14556 14573
14557static int 14574static int
14558try_scrolling (Lisp_Object window, int just_this_one_p, 14575try_scrolling (Lisp_Object window, int just_this_one_p,
14559 EMACS_INT arg_scroll_conservatively, EMACS_INT scroll_step, 14576 ptrdiff_t arg_scroll_conservatively, ptrdiff_t scroll_step,
14560 int temp_scroll_step, int last_line_misfit) 14577 int temp_scroll_step, int last_line_misfit)
14561{ 14578{
14562 struct window *w = XWINDOW (window); 14579 struct window *w = XWINDOW (window);
@@ -15196,7 +15213,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
15196 MATRIX_ROW (w->current_matrix, w->cursor.vpos); 15213 MATRIX_ROW (w->current_matrix, w->cursor.vpos);
15197 struct glyph *g = 15214 struct glyph *g =
15198 candidate->glyphs[TEXT_AREA] + w->cursor.hpos; 15215 candidate->glyphs[TEXT_AREA] + w->cursor.hpos;
15199 EMACS_INT endpos = MATRIX_ROW_END_CHARPOS (candidate); 15216 ptrdiff_t endpos = MATRIX_ROW_END_CHARPOS (candidate);
15200 15217
15201 exact_match_p = 15218 exact_match_p =
15202 (BUFFERP (g->object) && g->charpos == PT) 15219 (BUFFERP (g->object) && g->charpos == PT)
@@ -15256,7 +15273,7 @@ static
15256void 15273void
15257set_vertical_scroll_bar (struct window *w) 15274set_vertical_scroll_bar (struct window *w)
15258{ 15275{
15259 EMACS_INT start, end, whole; 15276 ptrdiff_t start, end, whole;
15260 15277
15261 /* Calculate the start and end positions for the current window. 15278 /* Calculate the start and end positions for the current window.
15262 At some point, it would be nice to choose between scrollbars 15279 At some point, it would be nice to choose between scrollbars
@@ -15316,11 +15333,11 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15316 It indicates that the buffer contents and narrowing are unchanged. */ 15333 It indicates that the buffer contents and narrowing are unchanged. */
15317 int buffer_unchanged_p = 0; 15334 int buffer_unchanged_p = 0;
15318 int temp_scroll_step = 0; 15335 int temp_scroll_step = 0;
15319 int count = SPECPDL_INDEX (); 15336 ptrdiff_t count = SPECPDL_INDEX ();
15320 int rc; 15337 int rc;
15321 int centering_position = -1; 15338 int centering_position = -1;
15322 int last_line_misfit = 0; 15339 int last_line_misfit = 0;
15323 EMACS_INT beg_unchanged, end_unchanged; 15340 ptrdiff_t beg_unchanged, end_unchanged;
15324 15341
15325 SET_TEXT_POS (lpoint, PT, PT_BYTE); 15342 SET_TEXT_POS (lpoint, PT, PT_BYTE);
15326 opoint = lpoint; 15343 opoint = lpoint;
@@ -15461,8 +15478,8 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15461 window, set up appropriate value. */ 15478 window, set up appropriate value. */
15462 if (!EQ (window, selected_window)) 15479 if (!EQ (window, selected_window))
15463 { 15480 {
15464 EMACS_INT new_pt = XMARKER (w->pointm)->charpos; 15481 ptrdiff_t new_pt = XMARKER (w->pointm)->charpos;
15465 EMACS_INT new_pt_byte = marker_byte_position (w->pointm); 15482 ptrdiff_t new_pt_byte = marker_byte_position (w->pointm);
15466 if (new_pt < BEGV) 15483 if (new_pt < BEGV)
15467 { 15484 {
15468 new_pt = BEGV; 15485 new_pt = BEGV;
@@ -15834,7 +15851,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15834 scroll_margin > 0 15851 scroll_margin > 0
15835 ? min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4) 15852 ? min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4)
15836 : 0; 15853 : 0;
15837 EMACS_INT margin_pos = CHARPOS (startp); 15854 ptrdiff_t margin_pos = CHARPOS (startp);
15838 Lisp_Object aggressive; 15855 Lisp_Object aggressive;
15839 int scrolling_up; 15856 int scrolling_up;
15840 15857
@@ -16747,7 +16764,7 @@ try_window_reusing_current_matrix (struct window *w)
16747 16764
16748static struct glyph_row *find_last_unchanged_at_beg_row (struct window *); 16765static struct glyph_row *find_last_unchanged_at_beg_row (struct window *);
16749static struct glyph_row *find_first_unchanged_at_end_row (struct window *, 16766static struct glyph_row *find_first_unchanged_at_end_row (struct window *,
16750 EMACS_INT *, EMACS_INT *); 16767 ptrdiff_t *, ptrdiff_t *);
16751static struct glyph_row * 16768static struct glyph_row *
16752find_last_row_displaying_text (struct glyph_matrix *, struct it *, 16769find_last_row_displaying_text (struct glyph_matrix *, struct it *,
16753 struct glyph_row *); 16770 struct glyph_row *);
@@ -16795,7 +16812,7 @@ find_last_row_displaying_text (struct glyph_matrix *matrix, struct it *it,
16795static struct glyph_row * 16812static struct glyph_row *
16796find_last_unchanged_at_beg_row (struct window *w) 16813find_last_unchanged_at_beg_row (struct window *w)
16797{ 16814{
16798 EMACS_INT first_changed_pos = BEG + BEG_UNCHANGED; 16815 ptrdiff_t first_changed_pos = BEG + BEG_UNCHANGED;
16799 struct glyph_row *row; 16816 struct glyph_row *row;
16800 struct glyph_row *row_found = NULL; 16817 struct glyph_row *row_found = NULL;
16801 int yb = window_text_bottom_y (w); 16818 int yb = window_text_bottom_y (w);
@@ -16851,7 +16868,7 @@ find_last_unchanged_at_beg_row (struct window *w)
16851 16868
16852static struct glyph_row * 16869static struct glyph_row *
16853find_first_unchanged_at_end_row (struct window *w, 16870find_first_unchanged_at_end_row (struct window *w,
16854 EMACS_INT *delta, EMACS_INT *delta_bytes) 16871 ptrdiff_t *delta, ptrdiff_t *delta_bytes)
16855{ 16872{
16856 struct glyph_row *row; 16873 struct glyph_row *row;
16857 struct glyph_row *row_found = NULL; 16874 struct glyph_row *row_found = NULL;
@@ -16879,11 +16896,11 @@ find_first_unchanged_at_end_row (struct window *w,
16879 corresponds to window_end_pos. This allows us to translate 16896 corresponds to window_end_pos. This allows us to translate
16880 buffer positions in the current matrix to current buffer 16897 buffer positions in the current matrix to current buffer
16881 positions for characters not in changed text. */ 16898 positions for characters not in changed text. */
16882 EMACS_INT Z_old = 16899 ptrdiff_t Z_old =
16883 MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos); 16900 MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos);
16884 EMACS_INT Z_BYTE_old = 16901 ptrdiff_t Z_BYTE_old =
16885 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos; 16902 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos;
16886 EMACS_INT last_unchanged_pos, last_unchanged_pos_old; 16903 ptrdiff_t last_unchanged_pos, last_unchanged_pos_old;
16887 struct glyph_row *first_text_row 16904 struct glyph_row *first_text_row
16888 = MATRIX_FIRST_TEXT_ROW (w->current_matrix); 16905 = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
16889 16906
@@ -16970,12 +16987,12 @@ sync_frame_with_window_matrix_rows (struct window *w)
16970 containing CHARPOS or null. */ 16987 containing CHARPOS or null. */
16971 16988
16972struct glyph_row * 16989struct glyph_row *
16973row_containing_pos (struct window *w, EMACS_INT charpos, 16990row_containing_pos (struct window *w, ptrdiff_t charpos,
16974 struct glyph_row *start, struct glyph_row *end, int dy) 16991 struct glyph_row *start, struct glyph_row *end, int dy)
16975{ 16992{
16976 struct glyph_row *row = start; 16993 struct glyph_row *row = start;
16977 struct glyph_row *best_row = NULL; 16994 struct glyph_row *best_row = NULL;
16978 EMACS_INT mindif = BUF_ZV (XBUFFER (w->buffer)) + 1; 16995 ptrdiff_t mindif = BUF_ZV (XBUFFER (w->buffer)) + 1;
16979 int last_y; 16996 int last_y;
16980 16997
16981 /* If we happen to start on a header-line, skip that. */ 16998 /* If we happen to start on a header-line, skip that. */
@@ -17089,14 +17106,14 @@ try_window_id (struct window *w)
17089 struct glyph_row *bottom_row; 17106 struct glyph_row *bottom_row;
17090 int bottom_vpos; 17107 int bottom_vpos;
17091 struct it it; 17108 struct it it;
17092 EMACS_INT delta = 0, delta_bytes = 0, stop_pos; 17109 ptrdiff_t delta = 0, delta_bytes = 0, stop_pos;
17093 int dvpos, dy; 17110 int dvpos, dy;
17094 struct text_pos start_pos; 17111 struct text_pos start_pos;
17095 struct run run; 17112 struct run run;
17096 int first_unchanged_at_end_vpos = 0; 17113 int first_unchanged_at_end_vpos = 0;
17097 struct glyph_row *last_text_row, *last_text_row_at_end; 17114 struct glyph_row *last_text_row, *last_text_row_at_end;
17098 struct text_pos start; 17115 struct text_pos start;
17099 EMACS_INT first_changed_charpos, last_changed_charpos; 17116 ptrdiff_t first_changed_charpos, last_changed_charpos;
17100 17117
17101#if GLYPH_DEBUG 17118#if GLYPH_DEBUG
17102 if (inhibit_try_window_id) 17119 if (inhibit_try_window_id)
@@ -17230,7 +17247,7 @@ try_window_id (struct window *w)
17230 || (last_changed_charpos < CHARPOS (start) - 1 17247 || (last_changed_charpos < CHARPOS (start) - 1
17231 && FETCH_BYTE (BYTEPOS (start) - 1) == '\n'))) 17248 && FETCH_BYTE (BYTEPOS (start) - 1) == '\n')))
17232 { 17249 {
17233 EMACS_INT Z_old, Z_delta, Z_BYTE_old, Z_delta_bytes; 17250 ptrdiff_t Z_old, Z_delta, Z_BYTE_old, Z_delta_bytes;
17234 struct glyph_row *r0; 17251 struct glyph_row *r0;
17235 17252
17236 /* Compute how many chars/bytes have been added to or removed 17253 /* Compute how many chars/bytes have been added to or removed
@@ -17997,7 +18014,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
17997 row->visible_height, 18014 row->visible_height,
17998 row->ascent, 18015 row->ascent,
17999 row->phys_ascent); 18016 row->phys_ascent);
18000 fprintf (stderr, "%9d %5d\t%5d\n", row->start.overlay_string_index, 18017 fprintf (stderr, "%9"pD"d %5"pD"d\t%5d\n", row->start.overlay_string_index,
18001 row->end.overlay_string_index, 18018 row->end.overlay_string_index,
18002 row->continuation_lines_width); 18019 row->continuation_lines_width);
18003 fprintf (stderr, "%9"pI"d %5"pI"d\n", 18020 fprintf (stderr, "%9"pI"d %5"pI"d\n",
@@ -18071,7 +18088,7 @@ glyphs in short form, otherwise show glyphs in long form. */)
18071 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); 18088 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos);
18072 fprintf (stderr, "=============================================\n"); 18089 fprintf (stderr, "=============================================\n");
18073 dump_glyph_matrix (w->current_matrix, 18090 dump_glyph_matrix (w->current_matrix,
18074 NILP (glyphs) ? 0 : XINT (glyphs)); 18091 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 0);
18075 return Qnil; 18092 return Qnil;
18076} 18093}
18077 18094
@@ -18094,7 +18111,7 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
18094 (Lisp_Object row, Lisp_Object glyphs) 18111 (Lisp_Object row, Lisp_Object glyphs)
18095{ 18112{
18096 struct glyph_matrix *matrix; 18113 struct glyph_matrix *matrix;
18097 int vpos; 18114 EMACS_INT vpos;
18098 18115
18099 CHECK_NUMBER (row); 18116 CHECK_NUMBER (row);
18100 matrix = XWINDOW (selected_window)->current_matrix; 18117 matrix = XWINDOW (selected_window)->current_matrix;
@@ -18102,7 +18119,7 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
18102 if (vpos >= 0 && vpos < matrix->nrows) 18119 if (vpos >= 0 && vpos < matrix->nrows)
18103 dump_glyph_row (MATRIX_ROW (matrix, vpos), 18120 dump_glyph_row (MATRIX_ROW (matrix, vpos),
18104 vpos, 18121 vpos,
18105 INTEGERP (glyphs) ? XINT (glyphs) : 2); 18122 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 2);
18106 return Qnil; 18123 return Qnil;
18107} 18124}
18108 18125
@@ -18116,13 +18133,13 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
18116{ 18133{
18117 struct frame *sf = SELECTED_FRAME (); 18134 struct frame *sf = SELECTED_FRAME ();
18118 struct glyph_matrix *m = XWINDOW (sf->tool_bar_window)->current_matrix; 18135 struct glyph_matrix *m = XWINDOW (sf->tool_bar_window)->current_matrix;
18119 int vpos; 18136 EMACS_INT vpos;
18120 18137
18121 CHECK_NUMBER (row); 18138 CHECK_NUMBER (row);
18122 vpos = XINT (row); 18139 vpos = XINT (row);
18123 if (vpos >= 0 && vpos < m->nrows) 18140 if (vpos >= 0 && vpos < m->nrows)
18124 dump_glyph_row (MATRIX_ROW (m, vpos), vpos, 18141 dump_glyph_row (MATRIX_ROW (m, vpos), vpos,
18125 INTEGERP (glyphs) ? XINT (glyphs) : 2); 18142 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 2);
18126 return Qnil; 18143 return Qnil;
18127} 18144}
18128 18145
@@ -18647,9 +18664,9 @@ extend_face_to_end_of_line (struct it *it)
18647 trailing whitespace. */ 18664 trailing whitespace. */
18648 18665
18649static int 18666static int
18650trailing_whitespace_p (EMACS_INT charpos) 18667trailing_whitespace_p (ptrdiff_t charpos)
18651{ 18668{
18652 EMACS_INT bytepos = CHAR_TO_BYTE (charpos); 18669 ptrdiff_t bytepos = CHAR_TO_BYTE (charpos);
18653 int c = 0; 18670 int c = 0;
18654 18671
18655 while (bytepos < ZV_BYTE 18672 while (bytepos < ZV_BYTE
@@ -18791,7 +18808,7 @@ cursor_row_p (struct glyph_row *row)
18791 18808
18792 for ( ; glyph >= beg && EQ (glyph->object, s); --glyph) 18809 for ( ; glyph >= beg && EQ (glyph->object, s); --glyph)
18793 { 18810 {
18794 EMACS_INT gpos = glyph->charpos; 18811 ptrdiff_t gpos = glyph->charpos;
18795 18812
18796 if (!NILP (Fget_char_property (make_number (gpos), 18813 if (!NILP (Fget_char_property (make_number (gpos),
18797 Qcursor, s))) 18814 Qcursor, s)))
@@ -18988,8 +19005,8 @@ unproduce_glyphs (struct it *it, int n)
18988 and ROW->maxpos. */ 19005 and ROW->maxpos. */
18989static void 19006static void
18990find_row_edges (struct it *it, struct glyph_row *row, 19007find_row_edges (struct it *it, struct glyph_row *row,
18991 EMACS_INT min_pos, EMACS_INT min_bpos, 19008 ptrdiff_t min_pos, ptrdiff_t min_bpos,
18992 EMACS_INT max_pos, EMACS_INT max_bpos) 19009 ptrdiff_t max_pos, ptrdiff_t max_bpos)
18993{ 19010{
18994 /* FIXME: Revisit this when glyph ``spilling'' in continuation 19011 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18995 lines' rows is implemented for bidi-reordered rows. */ 19012 lines' rows is implemented for bidi-reordered rows. */
@@ -19156,11 +19173,11 @@ display_line (struct it *it)
19156 int wrap_row_ascent IF_LINT (= 0), wrap_row_height IF_LINT (= 0); 19173 int wrap_row_ascent IF_LINT (= 0), wrap_row_height IF_LINT (= 0);
19157 int wrap_row_phys_ascent IF_LINT (= 0), wrap_row_phys_height IF_LINT (= 0); 19174 int wrap_row_phys_ascent IF_LINT (= 0), wrap_row_phys_height IF_LINT (= 0);
19158 int wrap_row_extra_line_spacing IF_LINT (= 0); 19175 int wrap_row_extra_line_spacing IF_LINT (= 0);
19159 EMACS_INT wrap_row_min_pos IF_LINT (= 0), wrap_row_min_bpos IF_LINT (= 0); 19176 ptrdiff_t wrap_row_min_pos IF_LINT (= 0), wrap_row_min_bpos IF_LINT (= 0);
19160 EMACS_INT wrap_row_max_pos IF_LINT (= 0), wrap_row_max_bpos IF_LINT (= 0); 19177 ptrdiff_t wrap_row_max_pos IF_LINT (= 0), wrap_row_max_bpos IF_LINT (= 0);
19161 int cvpos; 19178 int cvpos;
19162 EMACS_INT min_pos = ZV + 1, max_pos = 0; 19179 ptrdiff_t min_pos = ZV + 1, max_pos = 0;
19163 EMACS_INT min_bpos IF_LINT (= 0), max_bpos IF_LINT (= 0); 19180 ptrdiff_t min_bpos IF_LINT (= 0), max_bpos IF_LINT (= 0);
19164 19181
19165 /* We always start displaying at hpos zero even if hscrolled. */ 19182 /* We always start displaying at hpos zero even if hscrolled. */
19166 xassert (it->hpos == 0 && it->current_x == 0); 19183 xassert (it->hpos == 0 && it->current_x == 0);
@@ -19233,10 +19250,10 @@ display_line (struct it *it)
19233 { \ 19250 { \
19234 int composition_p = !STRINGP ((IT)->string) \ 19251 int composition_p = !STRINGP ((IT)->string) \
19235 && ((IT)->what == IT_COMPOSITION); \ 19252 && ((IT)->what == IT_COMPOSITION); \
19236 EMACS_INT current_pos = \ 19253 ptrdiff_t current_pos = \
19237 composition_p ? (IT)->cmp_it.charpos \ 19254 composition_p ? (IT)->cmp_it.charpos \
19238 : IT_CHARPOS (*(IT)); \ 19255 : IT_CHARPOS (*(IT)); \
19239 EMACS_INT current_bpos = \ 19256 ptrdiff_t current_bpos = \
19240 composition_p ? CHAR_TO_BYTE (current_pos) \ 19257 composition_p ? CHAR_TO_BYTE (current_pos) \
19241 : IT_BYTEPOS (*(IT)); \ 19258 : IT_BYTEPOS (*(IT)); \
19242 if (current_pos < min_pos) \ 19259 if (current_pos < min_pos) \
@@ -19884,8 +19901,8 @@ See also `bidi-paragraph-direction'. */)
19884 use current_matrix if it is up to date, but this seems fast 19901 use current_matrix if it is up to date, but this seems fast
19885 enough as it is. */ 19902 enough as it is. */
19886 struct bidi_it itb; 19903 struct bidi_it itb;
19887 EMACS_INT pos = BUF_PT (buf); 19904 ptrdiff_t pos = BUF_PT (buf);
19888 EMACS_INT bytepos = BUF_PT_BYTE (buf); 19905 ptrdiff_t bytepos = BUF_PT_BYTE (buf);
19889 int c; 19906 int c;
19890 void *itb_data = bidi_shelve_cache (); 19907 void *itb_data = bidi_shelve_cache ();
19891 19908
@@ -20173,7 +20190,7 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
20173{ 20190{
20174 struct it it; 20191 struct it it;
20175 struct face *face; 20192 struct face *face;
20176 int count = SPECPDL_INDEX (); 20193 ptrdiff_t count = SPECPDL_INDEX ();
20177 20194
20178 init_iterator (&it, w, -1, -1, NULL, face_id); 20195 init_iterator (&it, w, -1, -1, NULL, face_id);
20179 /* Don't extend on a previously drawn mode-line. 20196 /* Don't extend on a previously drawn mode-line.
@@ -20309,7 +20326,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20309 { 20326 {
20310 /* A string: output it and check for %-constructs within it. */ 20327 /* A string: output it and check for %-constructs within it. */
20311 unsigned char c; 20328 unsigned char c;
20312 EMACS_INT offset = 0; 20329 ptrdiff_t offset = 0;
20313 20330
20314 if (SCHARS (elt) > 0 20331 if (SCHARS (elt) > 0
20315 && (!NILP (props) || risky)) 20332 && (!NILP (props) || risky))
@@ -20406,7 +20423,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20406 && (mode_line_target != MODE_LINE_DISPLAY 20423 && (mode_line_target != MODE_LINE_DISPLAY
20407 || it->current_x < it->last_visible_x)) 20424 || it->current_x < it->last_visible_x))
20408 { 20425 {
20409 EMACS_INT last_offset = offset; 20426 ptrdiff_t last_offset = offset;
20410 20427
20411 /* Advance to end of string or next format specifier. */ 20428 /* Advance to end of string or next format specifier. */
20412 while ((c = SREF (elt, offset++)) != '\0' && c != '%') 20429 while ((c = SREF (elt, offset++)) != '\0' && c != '%')
@@ -20414,7 +20431,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20414 20431
20415 if (offset - 1 != last_offset) 20432 if (offset - 1 != last_offset)
20416 { 20433 {
20417 EMACS_INT nchars, nbytes; 20434 ptrdiff_t nchars, nbytes;
20418 20435
20419 /* Output to end of string or up to '%'. Field width 20436 /* Output to end of string or up to '%'. Field width
20420 is length of string. Don't output more than 20437 is length of string. Don't output more than
@@ -20433,9 +20450,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20433 break; 20450 break;
20434 case MODE_LINE_STRING: 20451 case MODE_LINE_STRING:
20435 { 20452 {
20436 EMACS_INT bytepos = last_offset; 20453 ptrdiff_t bytepos = last_offset;
20437 EMACS_INT charpos = string_byte_to_char (elt, bytepos); 20454 ptrdiff_t charpos = string_byte_to_char (elt, bytepos);
20438 EMACS_INT endpos = (precision <= 0 20455 ptrdiff_t endpos = (precision <= 0
20439 ? string_byte_to_char (elt, offset) 20456 ? string_byte_to_char (elt, offset)
20440 : charpos + nchars); 20457 : charpos + nchars);
20441 20458
@@ -20447,8 +20464,8 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20447 break; 20464 break;
20448 case MODE_LINE_DISPLAY: 20465 case MODE_LINE_DISPLAY:
20449 { 20466 {
20450 EMACS_INT bytepos = last_offset; 20467 ptrdiff_t bytepos = last_offset;
20451 EMACS_INT charpos = string_byte_to_char (elt, bytepos); 20468 ptrdiff_t charpos = string_byte_to_char (elt, bytepos);
20452 20469
20453 if (precision <= 0) 20470 if (precision <= 0)
20454 nchars = string_byte_to_char (elt, offset) - charpos; 20471 nchars = string_byte_to_char (elt, offset) - charpos;
@@ -20461,7 +20478,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20461 } 20478 }
20462 else /* c == '%' */ 20479 else /* c == '%' */
20463 { 20480 {
20464 EMACS_INT percent_position = offset; 20481 ptrdiff_t percent_position = offset;
20465 20482
20466 /* Get the specified minimum width. Zero means 20483 /* Get the specified minimum width. Zero means
20467 don't pad. */ 20484 don't pad. */
@@ -20483,7 +20500,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20483 else if (c != 0) 20500 else if (c != 0)
20484 { 20501 {
20485 int multibyte; 20502 int multibyte;
20486 EMACS_INT bytepos, charpos; 20503 ptrdiff_t bytepos, charpos;
20487 const char *spec; 20504 const char *spec;
20488 Lisp_Object string; 20505 Lisp_Object string;
20489 20506
@@ -20756,7 +20773,7 @@ static int
20756store_mode_line_string (const char *string, Lisp_Object lisp_string, int copy_string, 20773store_mode_line_string (const char *string, Lisp_Object lisp_string, int copy_string,
20757 int field_width, int precision, Lisp_Object props) 20774 int field_width, int precision, Lisp_Object props)
20758{ 20775{
20759 EMACS_INT len; 20776 ptrdiff_t len;
20760 int n = 0; 20777 int n = 0;
20761 20778
20762 if (string != NULL) 20779 if (string != NULL)
@@ -20857,7 +20874,7 @@ are the selected window and the WINDOW's buffer). */)
20857 struct buffer *old_buffer = NULL; 20874 struct buffer *old_buffer = NULL;
20858 int face_id; 20875 int face_id;
20859 int no_props = INTEGERP (face); 20876 int no_props = INTEGERP (face);
20860 int count = SPECPDL_INDEX (); 20877 ptrdiff_t count = SPECPDL_INDEX ();
20861 Lisp_Object str; 20878 Lisp_Object str;
20862 int string_start = 0; 20879 int string_start = 0;
20863 20880
@@ -20943,7 +20960,7 @@ are the selected window and the WINDOW's buffer). */)
20943 the positive integer D to BUF using a minimal field width WIDTH. */ 20960 the positive integer D to BUF using a minimal field width WIDTH. */
20944 20961
20945static void 20962static void
20946pint2str (register char *buf, register int width, register EMACS_INT d) 20963pint2str (register char *buf, register int width, register ptrdiff_t d)
20947{ 20964{
20948 register char *p = buf; 20965 register char *p = buf;
20949 20966
@@ -20987,11 +21004,11 @@ static const char power_letter[] =
20987 }; 21004 };
20988 21005
20989static void 21006static void
20990pint2hrstr (char *buf, int width, EMACS_INT d) 21007pint2hrstr (char *buf, int width, ptrdiff_t d)
20991{ 21008{
20992 /* We aim to represent the nonnegative integer D as 21009 /* We aim to represent the nonnegative integer D as
20993 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */ 21010 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20994 EMACS_INT quotient = d; 21011 ptrdiff_t quotient = d;
20995 int remainder = 0; 21012 int remainder = 0;
20996 /* -1 means: do not use TENTHS. */ 21013 /* -1 means: do not use TENTHS. */
20997 int tenths = -1; 21014 int tenths = -1;
@@ -21271,7 +21288,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21271 return ""; 21288 return "";
21272 else 21289 else
21273 { 21290 {
21274 EMACS_INT col = current_column (); 21291 ptrdiff_t col = current_column ();
21275 w->column_number_displayed = make_number (col); 21292 w->column_number_displayed = make_number (col);
21276 pint2str (decode_mode_spec_buf, field_width, col); 21293 pint2str (decode_mode_spec_buf, field_width, col);
21277 return decode_mode_spec_buf; 21294 return decode_mode_spec_buf;
@@ -21303,23 +21320,23 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21303 21320
21304 case 'i': 21321 case 'i':
21305 { 21322 {
21306 EMACS_INT size = ZV - BEGV; 21323 ptrdiff_t size = ZV - BEGV;
21307 pint2str (decode_mode_spec_buf, field_width, size); 21324 pint2str (decode_mode_spec_buf, field_width, size);
21308 return decode_mode_spec_buf; 21325 return decode_mode_spec_buf;
21309 } 21326 }
21310 21327
21311 case 'I': 21328 case 'I':
21312 { 21329 {
21313 EMACS_INT size = ZV - BEGV; 21330 ptrdiff_t size = ZV - BEGV;
21314 pint2hrstr (decode_mode_spec_buf, field_width, size); 21331 pint2hrstr (decode_mode_spec_buf, field_width, size);
21315 return decode_mode_spec_buf; 21332 return decode_mode_spec_buf;
21316 } 21333 }
21317 21334
21318 case 'l': 21335 case 'l':
21319 { 21336 {
21320 EMACS_INT startpos, startpos_byte, line, linepos, linepos_byte; 21337 ptrdiff_t startpos, startpos_byte, line, linepos, linepos_byte;
21321 EMACS_INT topline, nlines, height; 21338 ptrdiff_t topline, nlines, height;
21322 EMACS_INT junk; 21339 ptrdiff_t junk;
21323 21340
21324 /* %c and %l are ignored in `frame-title-format'. */ 21341 /* %c and %l are ignored in `frame-title-format'. */
21325 if (mode_line_target == MODE_LINE_TITLE) 21342 if (mode_line_target == MODE_LINE_TITLE)
@@ -21380,10 +21397,10 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21380 else if (nlines < height + 25 || nlines > height * 3 + 50 21397 else if (nlines < height + 25 || nlines > height * 3 + 50
21381 || linepos == BUF_BEGV (b)) 21398 || linepos == BUF_BEGV (b))
21382 { 21399 {
21383 EMACS_INT limit = BUF_BEGV (b); 21400 ptrdiff_t limit = BUF_BEGV (b);
21384 EMACS_INT limit_byte = BUF_BEGV_BYTE (b); 21401 ptrdiff_t limit_byte = BUF_BEGV_BYTE (b);
21385 EMACS_INT position; 21402 ptrdiff_t position;
21386 EMACS_INT distance = 21403 ptrdiff_t distance =
21387 (height * 2 + 30) * line_number_display_limit_width; 21404 (height * 2 + 30) * line_number_display_limit_width;
21388 21405
21389 if (startpos - distance > limit) 21406 if (startpos - distance > limit)
@@ -21445,8 +21462,8 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21445 21462
21446 case 'p': 21463 case 'p':
21447 { 21464 {
21448 EMACS_INT pos = marker_position (w->start); 21465 ptrdiff_t pos = marker_position (w->start);
21449 EMACS_INT total = BUF_ZV (b) - BUF_BEGV (b); 21466 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
21450 21467
21451 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b)) 21468 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
21452 { 21469 {
@@ -21468,7 +21485,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21468 so get us a 2-digit number that is close. */ 21485 so get us a 2-digit number that is close. */
21469 if (total == 100) 21486 if (total == 100)
21470 total = 99; 21487 total = 99;
21471 sprintf (decode_mode_spec_buf, "%2"pI"d%%", total); 21488 sprintf (decode_mode_spec_buf, "%2"pD"d%%", total);
21472 return decode_mode_spec_buf; 21489 return decode_mode_spec_buf;
21473 } 21490 }
21474 } 21491 }
@@ -21476,9 +21493,9 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21476 /* Display percentage of size above the bottom of the screen. */ 21493 /* Display percentage of size above the bottom of the screen. */
21477 case 'P': 21494 case 'P':
21478 { 21495 {
21479 EMACS_INT toppos = marker_position (w->start); 21496 ptrdiff_t toppos = marker_position (w->start);
21480 EMACS_INT botpos = BUF_Z (b) - XFASTINT (w->window_end_pos); 21497 ptrdiff_t botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
21481 EMACS_INT total = BUF_ZV (b) - BUF_BEGV (b); 21498 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
21482 21499
21483 if (botpos >= BUF_ZV (b)) 21500 if (botpos >= BUF_ZV (b))
21484 { 21501 {
@@ -21499,9 +21516,9 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21499 if (total == 100) 21516 if (total == 100)
21500 total = 99; 21517 total = 99;
21501 if (toppos <= BUF_BEGV (b)) 21518 if (toppos <= BUF_BEGV (b))
21502 sprintf (decode_mode_spec_buf, "Top%2"pI"d%%", total); 21519 sprintf (decode_mode_spec_buf, "Top%2"pD"d%%", total);
21503 else 21520 else
21504 sprintf (decode_mode_spec_buf, "%2"pI"d%%", total); 21521 sprintf (decode_mode_spec_buf, "%2"pD"d%%", total);
21505 return decode_mode_spec_buf; 21522 return decode_mode_spec_buf;
21506 } 21523 }
21507 } 21524 }
@@ -21518,7 +21535,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21518 21535
21519 case '@': 21536 case '@':
21520 { 21537 {
21521 int count = inhibit_garbage_collection (); 21538 ptrdiff_t count = inhibit_garbage_collection ();
21522 Lisp_Object val = call1 (intern ("file-remote-p"), 21539 Lisp_Object val = call1 (intern ("file-remote-p"),
21523 BVAR (current_buffer, directory)); 21540 BVAR (current_buffer, directory));
21524 unbind_to (count, Qnil); 21541 unbind_to (count, Qnil);
@@ -21587,17 +21604,17 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21587 21604
21588 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */ 21605 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21589 21606
21590static EMACS_INT 21607static ptrdiff_t
21591display_count_lines (EMACS_INT start_byte, 21608display_count_lines (ptrdiff_t start_byte,
21592 EMACS_INT limit_byte, EMACS_INT count, 21609 ptrdiff_t limit_byte, ptrdiff_t count,
21593 EMACS_INT *byte_pos_ptr) 21610 ptrdiff_t *byte_pos_ptr)
21594{ 21611{
21595 register unsigned char *cursor; 21612 register unsigned char *cursor;
21596 unsigned char *base; 21613 unsigned char *base;
21597 21614
21598 register EMACS_INT ceiling; 21615 register ptrdiff_t ceiling;
21599 register unsigned char *ceiling_addr; 21616 register unsigned char *ceiling_addr;
21600 EMACS_INT orig_count = count; 21617 ptrdiff_t orig_count = count;
21601 21618
21602 /* If we are not in selective display mode, 21619 /* If we are not in selective display mode,
21603 check only for newlines. */ 21620 check only for newlines. */
@@ -21731,13 +21748,13 @@ display_count_lines (EMACS_INT start_byte,
21731 21748
21732static int 21749static int
21733display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_string, 21750display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_string,
21734 EMACS_INT face_string_pos, EMACS_INT start, struct it *it, 21751 ptrdiff_t face_string_pos, ptrdiff_t start, struct it *it,
21735 int field_width, int precision, int max_x, int multibyte) 21752 int field_width, int precision, int max_x, int multibyte)
21736{ 21753{
21737 int hpos_at_start = it->hpos; 21754 int hpos_at_start = it->hpos;
21738 int saved_face_id = it->face_id; 21755 int saved_face_id = it->face_id;
21739 struct glyph_row *row = it->glyph_row; 21756 struct glyph_row *row = it->glyph_row;
21740 EMACS_INT it_charpos; 21757 ptrdiff_t it_charpos;
21741 21758
21742 /* Initialize the iterator IT for iteration over STRING beginning 21759 /* Initialize the iterator IT for iteration over STRING beginning
21743 with index START. */ 21760 with index START. */
@@ -21752,7 +21769,7 @@ display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_st
21752 FACE_STRING, if that's given. */ 21769 FACE_STRING, if that's given. */
21753 if (STRINGP (face_string)) 21770 if (STRINGP (face_string))
21754 { 21771 {
21755 EMACS_INT endptr; 21772 ptrdiff_t endptr;
21756 struct face *face; 21773 struct face *face;
21757 21774
21758 it->face_id 21775 it->face_id
@@ -23279,7 +23296,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p)
23279 23296
23280static int 23297static int
23281draw_glyphs (struct window *w, int x, struct glyph_row *row, 23298draw_glyphs (struct window *w, int x, struct glyph_row *row,
23282 enum glyph_row_area area, EMACS_INT start, EMACS_INT end, 23299 enum glyph_row_area area, ptrdiff_t start, ptrdiff_t end,
23283 enum draw_glyphs_face hl, int overlaps) 23300 enum draw_glyphs_face hl, int overlaps)
23284{ 23301{
23285 struct glyph_string *head, *tail; 23302 struct glyph_string *head, *tail;
@@ -24826,7 +24843,7 @@ x_produce_glyphs (struct it *it)
24826 XChar2b char2b; 24843 XChar2b char2b;
24827 struct font_metrics *pcm; 24844 struct font_metrics *pcm;
24828 int font_not_found_p; 24845 int font_not_found_p;
24829 EMACS_INT pos; 24846 ptrdiff_t pos;
24830 24847
24831 for (glyph_len = cmp->glyph_len; glyph_len > 0; glyph_len--) 24848 for (glyph_len = cmp->glyph_len; glyph_len > 0; glyph_len--)
24832 if ((c = COMPOSITION_GLYPH (cmp, glyph_len - 1)) != '\t') 24849 if ((c = COMPOSITION_GLYPH (cmp, glyph_len - 1)) != '\t')
@@ -25237,7 +25254,7 @@ x_insert_glyphs (struct glyph *start, int len)
25237 struct glyph_row *row; 25254 struct glyph_row *row;
25238 struct glyph *glyph; 25255 struct glyph *glyph;
25239 int frame_x, frame_y; 25256 int frame_x, frame_y;
25240 EMACS_INT hpos; 25257 ptrdiff_t hpos;
25241 25258
25242 xassert (updated_window && updated_row); 25259 xassert (updated_window && updated_row);
25243 BLOCK_INPUT; 25260 BLOCK_INPUT;
@@ -25384,8 +25401,7 @@ get_specified_cursor_type (Lisp_Object arg, int *width)
25384 25401
25385 if (CONSP (arg) 25402 if (CONSP (arg)
25386 && EQ (XCAR (arg), Qbar) 25403 && EQ (XCAR (arg), Qbar)
25387 && INTEGERP (XCDR (arg)) 25404 && RANGED_INTEGERP (0, XCDR (arg), INT_MAX))
25388 && XINT (XCDR (arg)) >= 0)
25389 { 25405 {
25390 *width = XINT (XCDR (arg)); 25406 *width = XINT (XCDR (arg));
25391 return BAR_CURSOR; 25407 return BAR_CURSOR;
@@ -25399,8 +25415,7 @@ get_specified_cursor_type (Lisp_Object arg, int *width)
25399 25415
25400 if (CONSP (arg) 25416 if (CONSP (arg)
25401 && EQ (XCAR (arg), Qhbar) 25417 && EQ (XCAR (arg), Qhbar)
25402 && INTEGERP (XCDR (arg)) 25418 && RANGED_INTEGERP (0, XCDR (arg), INT_MAX))
25403 && XINT (XCDR (arg)) >= 0)
25404 { 25419 {
25405 *width = XINT (XCDR (arg)); 25420 *width = XINT (XCDR (arg));
25406 return HBAR_CURSOR; 25421 return HBAR_CURSOR;
@@ -26065,7 +26080,7 @@ draw_row_with_mouse_face (struct window *w, int start_x, struct glyph_row *row,
26065 return; 26080 return;
26066 } 26081 }
26067#endif 26082#endif
26068#if defined (HAVE_GPM) || defined (MSDOS) 26083#if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26069 tty_draw_row_with_mouse_face (w, row, start_hpos, end_hpos, draw); 26084 tty_draw_row_with_mouse_face (w, row, start_hpos, end_hpos, draw);
26070#endif 26085#endif
26071} 26086}
@@ -26304,7 +26319,7 @@ cursor_in_mouse_face_p (struct window *w)
26304 buffer positions change non-linearly with glyph rows. */ 26319 buffer positions change non-linearly with glyph rows. */
26305static void 26320static void
26306rows_from_pos_range (struct window *w, 26321rows_from_pos_range (struct window *w,
26307 EMACS_INT start_charpos, EMACS_INT end_charpos, 26322 ptrdiff_t start_charpos, ptrdiff_t end_charpos,
26308 Lisp_Object disp_string, 26323 Lisp_Object disp_string,
26309 struct glyph_row **start, struct glyph_row **end) 26324 struct glyph_row **start, struct glyph_row **end)
26310{ 26325{
@@ -26380,7 +26395,7 @@ rows_from_pos_range (struct window *w,
26380 for ( ; row->enabled_p && MATRIX_ROW_BOTTOM_Y (row) <= last_y; row++) 26395 for ( ; row->enabled_p && MATRIX_ROW_BOTTOM_Y (row) <= last_y; row++)
26381 { 26396 {
26382 struct glyph_row *next = row + 1; 26397 struct glyph_row *next = row + 1;
26383 EMACS_INT next_start = MATRIX_ROW_START_CHARPOS (next); 26398 ptrdiff_t next_start = MATRIX_ROW_START_CHARPOS (next);
26384 26399
26385 if (!next->enabled_p 26400 if (!next->enabled_p
26386 || next >= MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w) 26401 || next >= MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w)
@@ -26461,9 +26476,9 @@ rows_from_pos_range (struct window *w,
26461static void 26476static void
26462mouse_face_from_buffer_pos (Lisp_Object window, 26477mouse_face_from_buffer_pos (Lisp_Object window,
26463 Mouse_HLInfo *hlinfo, 26478 Mouse_HLInfo *hlinfo,
26464 EMACS_INT mouse_charpos, 26479 ptrdiff_t mouse_charpos,
26465 EMACS_INT start_charpos, 26480 ptrdiff_t start_charpos,
26466 EMACS_INT end_charpos, 26481 ptrdiff_t end_charpos,
26467 Lisp_Object before_string, 26482 Lisp_Object before_string,
26468 Lisp_Object after_string, 26483 Lisp_Object after_string,
26469 Lisp_Object disp_string) 26484 Lisp_Object disp_string)
@@ -26472,7 +26487,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26472 struct glyph_row *first = MATRIX_FIRST_TEXT_ROW (w->current_matrix); 26487 struct glyph_row *first = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
26473 struct glyph_row *r1, *r2; 26488 struct glyph_row *r1, *r2;
26474 struct glyph *glyph, *end; 26489 struct glyph *glyph, *end;
26475 EMACS_INT ignore, pos; 26490 ptrdiff_t ignore, pos;
26476 int x; 26491 int x;
26477 26492
26478 xassert (NILP (disp_string) || STRINGP (disp_string)); 26493 xassert (NILP (disp_string) || STRINGP (disp_string));
@@ -26805,7 +26820,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26805 Value is non-zero if a glyph was found. */ 26820 Value is non-zero if a glyph was found. */
26806 26821
26807static int 26822static int
26808fast_find_string_pos (struct window *w, EMACS_INT pos, Lisp_Object object, 26823fast_find_string_pos (struct window *w, ptrdiff_t pos, Lisp_Object object,
26809 int *hpos, int *vpos, int *x, int *y, int right_p) 26824 int *hpos, int *vpos, int *x, int *y, int right_p)
26810{ 26825{
26811 int yb = window_text_bottom_y (w); 26826 int yb = window_text_bottom_y (w);
@@ -26875,7 +26890,7 @@ fast_find_string_pos (struct window *w, EMACS_INT pos, Lisp_Object object,
26875static void 26890static void
26876mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo, 26891mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
26877 Lisp_Object object, 26892 Lisp_Object object,
26878 EMACS_INT startpos, EMACS_INT endpos) 26893 ptrdiff_t startpos, ptrdiff_t endpos)
26879{ 26894{
26880 int yb = window_text_bottom_y (w); 26895 int yb = window_text_bottom_y (w);
26881 struct glyph_row *r; 26896 struct glyph_row *r;
@@ -27045,8 +27060,8 @@ on_hot_spot_p (Lisp_Object hot_spot, int x, int y)
27045 { 27060 {
27046 struct Lisp_Vector *v = XVECTOR (XCDR (hot_spot)); 27061 struct Lisp_Vector *v = XVECTOR (XCDR (hot_spot));
27047 Lisp_Object *poly = v->contents; 27062 Lisp_Object *poly = v->contents;
27048 int n = v->header.size; 27063 ptrdiff_t n = v->header.size;
27049 int i; 27064 ptrdiff_t i;
27050 int inside = 0; 27065 int inside = 0;
27051 Lisp_Object lx, ly; 27066 Lisp_Object lx, ly;
27052 int x0, y0; 27067 int x0, y0;
@@ -27124,7 +27139,9 @@ Returns the alist element for the first matching AREA in MAP. */)
27124 CHECK_NUMBER (x); 27139 CHECK_NUMBER (x);
27125 CHECK_NUMBER (y); 27140 CHECK_NUMBER (y);
27126 27141
27127 return find_hot_spot (map, XINT (x), XINT (y)); 27142 return find_hot_spot (map,
27143 clip_to_bounds (INT_MIN, XINT (x), INT_MAX),
27144 clip_to_bounds (INT_MIN, XINT (y), INT_MAX));
27128} 27145}
27129 27146
27130 27147
@@ -27183,7 +27200,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27183 Cursor cursor = No_Cursor; 27200 Cursor cursor = No_Cursor;
27184 Lisp_Object pointer = Qnil; 27201 Lisp_Object pointer = Qnil;
27185 int dx, dy, width, height; 27202 int dx, dy, width, height;
27186 EMACS_INT charpos; 27203 ptrdiff_t charpos;
27187 Lisp_Object string, object = Qnil; 27204 Lisp_Object string, object = Qnil;
27188 Lisp_Object pos, help; 27205 Lisp_Object pos, help;
27189 27206
@@ -27323,7 +27340,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27323 int gpos; 27340 int gpos;
27324 int gseq_length; 27341 int gseq_length;
27325 int total_pixel_width; 27342 int total_pixel_width;
27326 EMACS_INT begpos, endpos, ignore; 27343 ptrdiff_t begpos, endpos, ignore;
27327 27344
27328 int vpos, hpos; 27345 int vpos, hpos;
27329 27346
@@ -27553,14 +27570,14 @@ note_mouse_highlight (struct frame *f, int x, int y)
27553 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) 27570 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
27554 { 27571 {
27555 int hpos, vpos, dx, dy, area = LAST_AREA; 27572 int hpos, vpos, dx, dy, area = LAST_AREA;
27556 EMACS_INT pos; 27573 ptrdiff_t pos;
27557 struct glyph *glyph; 27574 struct glyph *glyph;
27558 Lisp_Object object; 27575 Lisp_Object object;
27559 Lisp_Object mouse_face = Qnil, position; 27576 Lisp_Object mouse_face = Qnil, position;
27560 Lisp_Object *overlay_vec = NULL; 27577 Lisp_Object *overlay_vec = NULL;
27561 ptrdiff_t i, noverlays; 27578 ptrdiff_t i, noverlays;
27562 struct buffer *obuf; 27579 struct buffer *obuf;
27563 EMACS_INT obegv, ozv; 27580 ptrdiff_t obegv, ozv;
27564 int same_region; 27581 int same_region;
27565 27582
27566 /* Find the glyph under X/Y. */ 27583 /* Find the glyph under X/Y. */
@@ -27718,7 +27735,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27718 /* The mouse-highlighting comes from a display string 27735 /* The mouse-highlighting comes from a display string
27719 with a mouse-face. */ 27736 with a mouse-face. */
27720 Lisp_Object s, e; 27737 Lisp_Object s, e;
27721 EMACS_INT ignore; 27738 ptrdiff_t ignore;
27722 27739
27723 s = Fprevious_single_property_change 27740 s = Fprevious_single_property_change
27724 (make_number (pos + 1), Qmouse_face, object, Qnil); 27741 (make_number (pos + 1), Qmouse_face, object, Qnil);
@@ -27750,7 +27767,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27750 /* If we are on a display string with no mouse-face, 27767 /* If we are on a display string with no mouse-face,
27751 check if the text under it has one. */ 27768 check if the text under it has one. */
27752 struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos); 27769 struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos);
27753 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27770 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27754 pos = string_buffer_position (object, start); 27771 pos = string_buffer_position (object, start);
27755 if (pos > 0) 27772 if (pos > 0)
27756 { 27773 {
@@ -27849,7 +27866,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27849 else 27866 else
27850 { 27867 {
27851 Lisp_Object obj = glyph->object; 27868 Lisp_Object obj = glyph->object;
27852 EMACS_INT charpos = glyph->charpos; 27869 ptrdiff_t charpos = glyph->charpos;
27853 27870
27854 /* Try text properties. */ 27871 /* Try text properties. */
27855 if (STRINGP (obj) 27872 if (STRINGP (obj)
@@ -27864,8 +27881,8 @@ note_mouse_highlight (struct frame *f, int x, int y)
27864 see if the buffer text ``under'' it does. */ 27881 see if the buffer text ``under'' it does. */
27865 struct glyph_row *r 27882 struct glyph_row *r
27866 = MATRIX_ROW (w->current_matrix, vpos); 27883 = MATRIX_ROW (w->current_matrix, vpos);
27867 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27884 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27868 EMACS_INT p = string_buffer_position (obj, start); 27885 ptrdiff_t p = string_buffer_position (obj, start);
27869 if (p > 0) 27886 if (p > 0)
27870 { 27887 {
27871 help = Fget_char_property (make_number (p), 27888 help = Fget_char_property (make_number (p),
@@ -27905,7 +27922,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27905 if (NILP (pointer)) 27922 if (NILP (pointer))
27906 { 27923 {
27907 Lisp_Object obj = glyph->object; 27924 Lisp_Object obj = glyph->object;
27908 EMACS_INT charpos = glyph->charpos; 27925 ptrdiff_t charpos = glyph->charpos;
27909 27926
27910 /* Try text properties. */ 27927 /* Try text properties. */
27911 if (STRINGP (obj) 27928 if (STRINGP (obj)
@@ -27920,8 +27937,8 @@ note_mouse_highlight (struct frame *f, int x, int y)
27920 see if the buffer text ``under'' it does. */ 27937 see if the buffer text ``under'' it does. */
27921 struct glyph_row *r 27938 struct glyph_row *r
27922 = MATRIX_ROW (w->current_matrix, vpos); 27939 = MATRIX_ROW (w->current_matrix, vpos);
27923 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27940 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27924 EMACS_INT p = string_buffer_position (obj, start); 27941 ptrdiff_t p = string_buffer_position (obj, start);
27925 if (p > 0) 27942 if (p > 0)
27926 pointer = Fget_char_property (make_number (p), 27943 pointer = Fget_char_property (make_number (p),
27927 Qpointer, w->buffer); 27944 Qpointer, w->buffer);
@@ -29210,23 +29227,16 @@ start_hourglass (void)
29210{ 29227{
29211#if defined (HAVE_WINDOW_SYSTEM) 29228#if defined (HAVE_WINDOW_SYSTEM)
29212 EMACS_TIME delay; 29229 EMACS_TIME delay;
29213 int secs, usecs = 0; 29230 int secs = DEFAULT_HOURGLASS_DELAY, usecs = 0;
29214 29231
29215 cancel_hourglass (); 29232 cancel_hourglass ();
29216 29233
29217 if (INTEGERP (Vhourglass_delay) 29234 if (NUMBERP (Vhourglass_delay))
29218 && XINT (Vhourglass_delay) > 0)
29219 secs = XFASTINT (Vhourglass_delay);
29220 else if (FLOATP (Vhourglass_delay)
29221 && XFLOAT_DATA (Vhourglass_delay) > 0)
29222 { 29235 {
29223 Lisp_Object tem; 29236 double duration = extract_float (Vhourglass_delay);
29224 tem = Ftruncate (Vhourglass_delay, Qnil); 29237 if (0 < duration)
29225 secs = XFASTINT (tem); 29238 duration_to_sec_usec (duration, &secs, &usecs);
29226 usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000;
29227 } 29239 }
29228 else
29229 secs = DEFAULT_HOURGLASS_DELAY;
29230 29240
29231 EMACS_SET_SECS_USECS (delay, secs, usecs); 29241 EMACS_SET_SECS_USECS (delay, secs, usecs);
29232 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, 29242 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay,
diff --git a/src/xfaces.c b/src/xfaces.c
index 972de234510..84a47cf6ccf 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -922,7 +922,7 @@ the pixmap. Bits are stored row by row, each row occupies
922 else if (CONSP (object)) 922 else if (CONSP (object))
923 { 923 {
924 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and 924 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
925 HEIGHT must be integers > 0, and DATA must be string large 925 HEIGHT must be ints > 0, and DATA must be string large
926 enough to hold a bitmap of the specified size. */ 926 enough to hold a bitmap of the specified size. */
927 Lisp_Object width, height, data; 927 Lisp_Object width, height, data;
928 928
@@ -942,11 +942,11 @@ the pixmap. Bits are stored row by row, each row occupies
942 } 942 }
943 943
944 if (STRINGP (data) 944 if (STRINGP (data)
945 && INTEGERP (width) && 0 < XINT (width) 945 && RANGED_INTEGERP (1, width, INT_MAX)
946 && INTEGERP (height) && 0 < XINT (height)) 946 && RANGED_INTEGERP (1, height, INT_MAX))
947 { 947 {
948 EMACS_INT bytes_per_row = ((XINT (width) + BITS_PER_CHAR - 1) 948 int bytes_per_row = ((XINT (width) + BITS_PER_CHAR - 1)
949 / BITS_PER_CHAR); 949 / BITS_PER_CHAR);
950 if (XINT (height) <= SBYTES (data) / bytes_per_row) 950 if (XINT (height) <= SBYTES (data) / bytes_per_row)
951 pixmap_p = 1; 951 pixmap_p = 1;
952 } 952 }
@@ -1604,7 +1604,9 @@ compare_fonts_by_sort_order (const void *v1, const void *v2)
1604 else 1604 else
1605 { 1605 {
1606 if (INTEGERP (val1)) 1606 if (INTEGERP (val1))
1607 result = INTEGERP (val2) ? XINT (val1) - XINT (val2) : -1; 1607 result = (INTEGERP (val2) && XINT (val1) >= XINT (val2)
1608 ? XINT (val1) > XINT (val2)
1609 : -1);
1608 else 1610 else
1609 result = INTEGERP (val2) ? 1 : 0; 1611 result = INTEGERP (val2) ? 1 : 0;
1610 } 1612 }
@@ -1633,8 +1635,10 @@ the face font sort order. */)
1633 (Lisp_Object family, Lisp_Object frame) 1635 (Lisp_Object family, Lisp_Object frame)
1634{ 1636{
1635 Lisp_Object font_spec, list, *drivers, vec; 1637 Lisp_Object font_spec, list, *drivers, vec;
1636 int i, nfonts, ndrivers; 1638 ptrdiff_t i, nfonts;
1639 EMACS_INT ndrivers;
1637 Lisp_Object result; 1640 Lisp_Object result;
1641 USE_SAFE_ALLOCA;
1638 1642
1639 if (NILP (frame)) 1643 if (NILP (frame))
1640 frame = selected_frame; 1644 frame = selected_frame;
@@ -1670,7 +1674,7 @@ the face font sort order. */)
1670 font_props_for_sorting[i++] = FONT_REGISTRY_INDEX; 1674 font_props_for_sorting[i++] = FONT_REGISTRY_INDEX;
1671 1675
1672 ndrivers = XINT (Flength (list)); 1676 ndrivers = XINT (Flength (list));
1673 drivers = alloca (sizeof (Lisp_Object) * ndrivers); 1677 SAFE_ALLOCA_LISP (drivers, ndrivers);
1674 for (i = 0; i < ndrivers; i++, list = XCDR (list)) 1678 for (i = 0; i < ndrivers; i++, list = XCDR (list))
1675 drivers[i] = XCAR (list); 1679 drivers[i] = XCAR (list);
1676 vec = Fvconcat (ndrivers, drivers); 1680 vec = Fvconcat (ndrivers, drivers);
@@ -1702,6 +1706,7 @@ the face font sort order. */)
1702 result = Fcons (v, result); 1706 result = Fcons (v, result);
1703 } 1707 }
1704 1708
1709 SAFE_FREE ();
1705 return result; 1710 return result;
1706} 1711}
1707 1712
@@ -2263,7 +2268,7 @@ merge_face_heights (Lisp_Object from, Lisp_Object to, Lisp_Object invalid)
2263 { 2268 {
2264 if (INTEGERP (to)) 2269 if (INTEGERP (to))
2265 /* relative X absolute => absolute */ 2270 /* relative X absolute => absolute */
2266 result = make_number ((EMACS_INT)(XFLOAT_DATA (from) * XINT (to))); 2271 result = make_number (XFLOAT_DATA (from) * XINT (to));
2267 else if (FLOATP (to)) 2272 else if (FLOATP (to))
2268 /* relative X relative => relative */ 2273 /* relative X relative => relative */
2269 result = make_float (XFLOAT_DATA (from) * XFLOAT_DATA (to)); 2274 result = make_float (XFLOAT_DATA (from) * XFLOAT_DATA (to));
@@ -2683,8 +2688,7 @@ Value is a vector of face attributes. */)
2683 property `face' of the Lisp face name. */ 2688 property `face' of the Lisp face name. */
2684 if (next_lface_id == lface_id_to_name_size) 2689 if (next_lface_id == lface_id_to_name_size)
2685 lface_id_to_name = 2690 lface_id_to_name =
2686 xpalloc (lface_id_to_name, &lface_id_to_name_size, 1, 2691 xpalloc (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
2687 min (INT_MAX, MOST_POSITIVE_FIXNUM),
2688 sizeof *lface_id_to_name); 2692 sizeof *lface_id_to_name);
2689 2693
2690 lface_id_to_name[next_lface_id] = face; 2694 lface_id_to_name[next_lface_id] = face;
@@ -5277,7 +5281,7 @@ static int
5277realize_basic_faces (struct frame *f) 5281realize_basic_faces (struct frame *f)
5278{ 5282{
5279 int success_p = 0; 5283 int success_p = 0;
5280 int count = SPECPDL_INDEX (); 5284 ptrdiff_t count = SPECPDL_INDEX ();
5281 5285
5282 /* Block input here so that we won't be surprised by an X expose 5286 /* Block input here so that we won't be surprised by an X expose
5283 event, for instance, without having the faces set up. */ 5287 event, for instance, without having the faces set up. */
@@ -5960,9 +5964,9 @@ compute_char_face (struct frame *f, int ch, Lisp_Object prop)
5960 The face returned is suitable for displaying ASCII characters. */ 5964 The face returned is suitable for displaying ASCII characters. */
5961 5965
5962int 5966int
5963face_at_buffer_position (struct window *w, EMACS_INT pos, 5967face_at_buffer_position (struct window *w, ptrdiff_t pos,
5964 EMACS_INT region_beg, EMACS_INT region_end, 5968 ptrdiff_t region_beg, ptrdiff_t region_end,
5965 EMACS_INT *endptr, EMACS_INT limit, 5969 ptrdiff_t *endptr, ptrdiff_t limit,
5966 int mouse, int base_face_id) 5970 int mouse, int base_face_id)
5967{ 5971{
5968 struct frame *f = XFRAME (w->frame); 5972 struct frame *f = XFRAME (w->frame);
@@ -5971,7 +5975,7 @@ face_at_buffer_position (struct window *w, EMACS_INT pos,
5971 ptrdiff_t i, noverlays; 5975 ptrdiff_t i, noverlays;
5972 Lisp_Object *overlay_vec; 5976 Lisp_Object *overlay_vec;
5973 Lisp_Object frame; 5977 Lisp_Object frame;
5974 EMACS_INT endpos; 5978 ptrdiff_t endpos;
5975 Lisp_Object propname = mouse ? Qmouse_face : Qface; 5979 Lisp_Object propname = mouse ? Qmouse_face : Qface;
5976 Lisp_Object limit1, end; 5980 Lisp_Object limit1, end;
5977 struct face *default_face; 5981 struct face *default_face;
@@ -5997,7 +6001,7 @@ face_at_buffer_position (struct window *w, EMACS_INT pos,
5997 6001
5998 /* Look at properties from overlays. */ 6002 /* Look at properties from overlays. */
5999 { 6003 {
6000 EMACS_INT next_overlay; 6004 ptrdiff_t next_overlay;
6001 6005
6002 GET_OVERLAYS_AT (pos, overlay_vec, noverlays, &next_overlay, 0); 6006 GET_OVERLAYS_AT (pos, overlay_vec, noverlays, &next_overlay, 0);
6003 if (next_overlay < endpos) 6007 if (next_overlay < endpos)
@@ -6072,9 +6076,9 @@ face_at_buffer_position (struct window *w, EMACS_INT pos,
6072 simply disregards the `face' properties of all overlays. */ 6076 simply disregards the `face' properties of all overlays. */
6073 6077
6074int 6078int
6075face_for_overlay_string (struct window *w, EMACS_INT pos, 6079face_for_overlay_string (struct window *w, ptrdiff_t pos,
6076 EMACS_INT region_beg, EMACS_INT region_end, 6080 ptrdiff_t region_beg, ptrdiff_t region_end,
6077 EMACS_INT *endptr, EMACS_INT limit, 6081 ptrdiff_t *endptr, ptrdiff_t limit,
6078 int mouse, Lisp_Object overlay) 6082 int mouse, Lisp_Object overlay)
6079{ 6083{
6080 struct frame *f = XFRAME (w->frame); 6084 struct frame *f = XFRAME (w->frame);
@@ -6161,9 +6165,9 @@ face_for_overlay_string (struct window *w, EMACS_INT pos,
6161 6165
6162int 6166int
6163face_at_string_position (struct window *w, Lisp_Object string, 6167face_at_string_position (struct window *w, Lisp_Object string,
6164 EMACS_INT pos, EMACS_INT bufpos, 6168 ptrdiff_t pos, ptrdiff_t bufpos,
6165 EMACS_INT region_beg, EMACS_INT region_end, 6169 ptrdiff_t region_beg, ptrdiff_t region_end,
6166 EMACS_INT *endptr, enum face_id base_face_id, 6170 ptrdiff_t *endptr, enum face_id base_face_id,
6167 int mouse_p) 6171 int mouse_p)
6168{ 6172{
6169 Lisp_Object prop, position, end, limit; 6173 Lisp_Object prop, position, end, limit;
@@ -6246,7 +6250,7 @@ face_at_string_position (struct window *w, Lisp_Object string,
6246*/ 6250*/
6247 6251
6248int 6252int
6249merge_faces (struct frame *f, Lisp_Object face_name, EMACS_INT face_id, 6253merge_faces (struct frame *f, Lisp_Object face_name, int face_id,
6250 int base_face_id) 6254 int base_face_id)
6251{ 6255{
6252 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 6256 Lisp_Object attrs[LFACE_VECTOR_SIZE];
diff --git a/src/xfns.c b/src/xfns.c
index 717378f1cd1..767507805fb 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1200,7 +1200,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1200 if (FRAME_MINIBUF_ONLY_P (f)) 1200 if (FRAME_MINIBUF_ONLY_P (f))
1201 return; 1201 return;
1202 1202
1203 if (INTEGERP (value)) 1203 if (TYPE_RANGED_INTEGERP (int, value))
1204 nlines = XINT (value); 1204 nlines = XINT (value);
1205 else 1205 else
1206 nlines = 0; 1206 nlines = 0;
@@ -1286,8 +1286,8 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1286 if (FRAME_MINIBUF_ONLY_P (f)) 1286 if (FRAME_MINIBUF_ONLY_P (f))
1287 return; 1287 return;
1288 1288
1289 /* Use VALUE only if an integer >= 0. */ 1289 /* Use VALUE only if an int >= 0. */
1290 if (INTEGERP (value) && XINT (value) >= 0) 1290 if (RANGED_INTEGERP (0, value, INT_MAX))
1291 nlines = XFASTINT (value); 1291 nlines = XFASTINT (value);
1292 else 1292 else
1293 nlines = 0; 1293 nlines = 0;
@@ -2784,8 +2784,8 @@ x_icon (struct frame *f, Lisp_Object parms)
2784 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); 2784 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2785 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) 2785 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2786 { 2786 {
2787 CHECK_NUMBER (icon_x); 2787 CHECK_TYPE_RANGED_INTEGER (int, icon_x);
2788 CHECK_NUMBER (icon_y); 2788 CHECK_TYPE_RANGED_INTEGER (int, icon_y);
2789 } 2789 }
2790 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) 2790 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2791 error ("Both left and top icon corners of icon must be specified"); 2791 error ("Both left and top icon corners of icon must be specified");
@@ -3076,7 +3076,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3076 int minibuffer_only = 0; 3076 int minibuffer_only = 0;
3077 long window_prompting = 0; 3077 long window_prompting = 0;
3078 int width, height; 3078 int width, height;
3079 int count = SPECPDL_INDEX (); 3079 ptrdiff_t count = SPECPDL_INDEX ();
3080 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3080 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3081 Lisp_Object display; 3081 Lisp_Object display;
3082 struct x_display_info *dpyinfo = NULL; 3082 struct x_display_info *dpyinfo = NULL;
@@ -3333,7 +3333,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3333 could get an infloop in next_frame since the frame is not yet in 3333 could get an infloop in next_frame since the frame is not yet in
3334 Vframe_list. */ 3334 Vframe_list. */
3335 { 3335 {
3336 int count2 = SPECPDL_INDEX (); 3336 ptrdiff_t count2 = SPECPDL_INDEX ();
3337 record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code); 3337 record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code);
3338 inhibit_lisp_code = Qt; 3338 inhibit_lisp_code = Qt;
3339 3339
@@ -4221,11 +4221,11 @@ FRAME. Default is to change on the edit X window. */)
4221 if (! NILP (format)) 4221 if (! NILP (format))
4222 { 4222 {
4223 CHECK_NUMBER (format); 4223 CHECK_NUMBER (format);
4224 element_format = XFASTINT (format);
4225 4224
4226 if (element_format != 8 && element_format != 16 4225 if (XINT (format) != 8 && XINT (format) != 16
4227 && element_format != 32) 4226 && XINT (format) != 32)
4228 error ("FORMAT must be one of 8, 16 or 32"); 4227 error ("FORMAT must be one of 8, 16 or 32");
4228 element_format = XINT (format);
4229 } 4229 }
4230 4230
4231 if (CONSP (value)) 4231 if (CONSP (value))
@@ -4583,7 +4583,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4583 Lisp_Object frame; 4583 Lisp_Object frame;
4584 Lisp_Object name; 4584 Lisp_Object name;
4585 int width, height; 4585 int width, height;
4586 int count = SPECPDL_INDEX (); 4586 ptrdiff_t count = SPECPDL_INDEX ();
4587 struct gcpro gcpro1, gcpro2, gcpro3; 4587 struct gcpro gcpro1, gcpro2, gcpro3;
4588 int face_change_count_before = face_change_count; 4588 int face_change_count_before = face_change_count;
4589 Lisp_Object buffer; 4589 Lisp_Object buffer;
@@ -4980,7 +4980,7 @@ Text larger than the specified size is clipped. */)
4980 int i, width, height, seen_reversed_p; 4980 int i, width, height, seen_reversed_p;
4981 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4981 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4982 int old_windows_or_buffers_changed = windows_or_buffers_changed; 4982 int old_windows_or_buffers_changed = windows_or_buffers_changed;
4983 int count = SPECPDL_INDEX (); 4983 ptrdiff_t count = SPECPDL_INDEX ();
4984 4984
4985 specbind (Qinhibit_redisplay, Qt); 4985 specbind (Qinhibit_redisplay, Qt);
4986 4986
@@ -5090,10 +5090,8 @@ Text larger than the specified size is clipped. */)
5090 w->left_col = w->top_line = make_number (0); 5090 w->left_col = w->top_line = make_number (0);
5091 5091
5092 if (CONSP (Vx_max_tooltip_size) 5092 if (CONSP (Vx_max_tooltip_size)
5093 && INTEGERP (XCAR (Vx_max_tooltip_size)) 5093 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
5094 && XINT (XCAR (Vx_max_tooltip_size)) > 0 5094 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX))
5095 && INTEGERP (XCDR (Vx_max_tooltip_size))
5096 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
5097 { 5095 {
5098 w->total_cols = XCAR (Vx_max_tooltip_size); 5096 w->total_cols = XCAR (Vx_max_tooltip_size);
5099 w->total_lines = XCDR (Vx_max_tooltip_size); 5097 w->total_lines = XCDR (Vx_max_tooltip_size);
@@ -5239,7 +5237,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
5239Value is t if tooltip was open, nil otherwise. */) 5237Value is t if tooltip was open, nil otherwise. */)
5240 (void) 5238 (void)
5241{ 5239{
5242 int count; 5240 ptrdiff_t count;
5243 Lisp_Object deleted, frame, timer; 5241 Lisp_Object deleted, frame, timer;
5244 struct gcpro gcpro1, gcpro2; 5242 struct gcpro gcpro1, gcpro2;
5245 5243
@@ -5381,7 +5379,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5381 Arg al[10]; 5379 Arg al[10];
5382 int ac = 0; 5380 int ac = 0;
5383 XmString dir_xmstring, pattern_xmstring; 5381 XmString dir_xmstring, pattern_xmstring;
5384 int count = SPECPDL_INDEX (); 5382 ptrdiff_t count = SPECPDL_INDEX ();
5385 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5383 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5386 5384
5387 check_x (); 5385 check_x ();
@@ -5550,7 +5548,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5550 char *fn; 5548 char *fn;
5551 Lisp_Object file = Qnil; 5549 Lisp_Object file = Qnil;
5552 Lisp_Object decoded_file; 5550 Lisp_Object decoded_file;
5553 int count = SPECPDL_INDEX (); 5551 ptrdiff_t count = SPECPDL_INDEX ();
5554 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5552 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5555 char *cdef_file; 5553 char *cdef_file;
5556 5554
@@ -5613,7 +5611,7 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
5613 Lisp_Object font_param; 5611 Lisp_Object font_param;
5614 char *default_name = NULL; 5612 char *default_name = NULL;
5615 struct gcpro gcpro1, gcpro2; 5613 struct gcpro gcpro1, gcpro2;
5616 int count = SPECPDL_INDEX (); 5614 ptrdiff_t count = SPECPDL_INDEX ();
5617 5615
5618 check_x (); 5616 check_x ();
5619 5617
diff --git a/src/xfont.c b/src/xfont.c
index 25bb8a94fd9..bde76c0ba3c 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -248,7 +248,7 @@ xfont_chars_supported (Lisp_Object chars, XFontStruct *xfont,
248 } 248 }
249 else if (VECTORP (chars)) 249 else if (VECTORP (chars))
250 { 250 {
251 int i; 251 ptrdiff_t i;
252 252
253 for (i = ASIZE (chars) - 1; i >= 0; i--) 253 for (i = ASIZE (chars) - 1; i >= 0; i--)
254 { 254 {
diff --git a/src/xmenu.c b/src/xmenu.c
index 5f0a273948a..79ead5f598c 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -318,7 +318,7 @@ for instance using the window manager, then this produces a quit and
318 Lisp_Object title; 318 Lisp_Object title;
319 const char *error_name; 319 const char *error_name;
320 Lisp_Object selection; 320 Lisp_Object selection;
321 int specpdl_count = SPECPDL_INDEX (); 321 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
322 322
323 /* Decode the dialog items from what was specified. */ 323 /* Decode the dialog items from what was specified. */
324 title = Fcar (contents); 324 title = Fcar (contents);
@@ -979,7 +979,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
979 979
980 struct buffer *prev = current_buffer; 980 struct buffer *prev = current_buffer;
981 Lisp_Object buffer; 981 Lisp_Object buffer;
982 int specpdl_count = SPECPDL_INDEX (); 982 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
983 int previous_menu_items_used = f->menu_bar_items_used; 983 int previous_menu_items_used = f->menu_bar_items_used;
984 Lisp_Object *previous_items 984 Lisp_Object *previous_items
985 = (Lisp_Object *) alloca (previous_menu_items_used 985 = (Lisp_Object *) alloca (previous_menu_items_used
@@ -1445,7 +1445,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
1445 GtkWidget *menu; 1445 GtkWidget *menu;
1446 GtkMenuPositionFunc pos_func = 0; /* Pop up at pointer. */ 1446 GtkMenuPositionFunc pos_func = 0; /* Pop up at pointer. */
1447 struct next_popup_x_y popup_x_y; 1447 struct next_popup_x_y popup_x_y;
1448 int specpdl_count = SPECPDL_INDEX (); 1448 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1449 int use_pos_func = ! for_click; 1449 int use_pos_func = ! for_click;
1450 1450
1451#ifdef HAVE_GTK3 1451#ifdef HAVE_GTK3
@@ -1609,7 +1609,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
1609 1609
1610 { 1610 {
1611 int fact = 4 * sizeof (LWLIB_ID); 1611 int fact = 4 * sizeof (LWLIB_ID);
1612 int specpdl_count = SPECPDL_INDEX (); 1612 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1613 record_unwind_protect (pop_down_menu, 1613 record_unwind_protect (pop_down_menu,
1614 Fcons (make_number (menu_id >> (fact)), 1614 Fcons (make_number (menu_id >> (fact)),
1615 make_number (menu_id & ~(-1 << (fact))))); 1615 make_number (menu_id & ~(-1 << (fact)))));
@@ -1648,7 +1648,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
1648 1648
1649 int first_pane; 1649 int first_pane;
1650 1650
1651 int specpdl_count = SPECPDL_INDEX (); 1651 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1652 1652
1653 if (! FRAME_X_P (f)) 1653 if (! FRAME_X_P (f))
1654 abort (); 1654 abort ();
@@ -1945,7 +1945,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
1945 1945
1946 if (menu) 1946 if (menu)
1947 { 1947 {
1948 int specpdl_count = SPECPDL_INDEX (); 1948 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1949 record_unwind_protect (pop_down_menu, make_save_value (menu, 0)); 1949 record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
1950 1950
1951 /* Display the menu. */ 1951 /* Display the menu. */
@@ -2001,7 +2001,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
2001 /* Process events that apply to the dialog box. 2001 /* Process events that apply to the dialog box.
2002 Also handle timers. */ 2002 Also handle timers. */
2003 { 2003 {
2004 int count = SPECPDL_INDEX (); 2004 ptrdiff_t count = SPECPDL_INDEX ();
2005 int fact = 4 * sizeof (LWLIB_ID); 2005 int fact = 4 * sizeof (LWLIB_ID);
2006 2006
2007 /* xdialog_show_unwind is responsible for popping the dialog box down. */ 2007 /* xdialog_show_unwind is responsible for popping the dialog box down. */
@@ -2039,7 +2039,7 @@ xdialog_show (FRAME_PTR f,
2039 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ 2039 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2040 int boundary_seen = 0; 2040 int boundary_seen = 0;
2041 2041
2042 int specpdl_count = SPECPDL_INDEX (); 2042 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
2043 2043
2044 if (! FRAME_X_P (f)) 2044 if (! FRAME_X_P (f))
2045 abort (); 2045 abort ();
@@ -2304,7 +2304,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
2304 int maxwidth; 2304 int maxwidth;
2305 int dummy_int; 2305 int dummy_int;
2306 unsigned int dummy_uint; 2306 unsigned int dummy_uint;
2307 int specpdl_count = SPECPDL_INDEX (); 2307 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
2308 2308
2309 if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f)) 2309 if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
2310 abort (); 2310 abort ();
diff --git a/src/xml.c b/src/xml.c
index 786f0cd8818..e462a1adf57 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -180,8 +180,8 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
180 xmlDoc *doc; 180 xmlDoc *doc;
181 Lisp_Object result = Qnil; 181 Lisp_Object result = Qnil;
182 const char *burl = ""; 182 const char *burl = "";
183 EMACS_INT bytes; 183 ptrdiff_t bytes;
184 EMACS_INT istart, iend; 184 ptrdiff_t istart, iend;
185 185
186 fn_xmlCheckVersion (LIBXML_VERSION); 186 fn_xmlCheckVersion (LIBXML_VERSION);
187 187
diff --git a/src/xrdb.c b/src/xrdb.c
index 5998e49b07e..58ca682c757 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -126,7 +126,7 @@ x_get_customization_string (XrmDatabase db, const char *name,
126 Return NULL otherwise. */ 126 Return NULL otherwise. */
127 127
128static char * 128static char *
129magic_file_p (const char *string, EMACS_INT string_len, const char *class, 129magic_file_p (const char *string, ptrdiff_t string_len, const char *class,
130 const char *escaped_suffix) 130 const char *escaped_suffix)
131{ 131{
132 char *lang = getenv ("LANG"); 132 char *lang = getenv ("LANG");
diff --git a/src/xselect.c b/src/xselect.c
index 15ce8d487fa..48baeb32581 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -81,13 +81,13 @@ static Lisp_Object clean_local_selection_data (Lisp_Object);
81 81
82#ifdef TRACE_SELECTION 82#ifdef TRACE_SELECTION
83#define TRACE0(fmt) \ 83#define TRACE0(fmt) \
84 fprintf (stderr, "%d: " fmt "\n", getpid ()) 84 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid ())
85#define TRACE1(fmt, a0) \ 85#define TRACE1(fmt, a0) \
86 fprintf (stderr, "%d: " fmt "\n", getpid (), a0) 86 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0)
87#define TRACE2(fmt, a0, a1) \ 87#define TRACE2(fmt, a0, a1) \
88 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1) 88 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1)
89#define TRACE3(fmt, a0, a1, a2) \ 89#define TRACE3(fmt, a0, a1, a2) \
90 fprintf (stderr, "%d: " fmt "\n", getpid (), a0, a1, a2) 90 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1, a2)
91#else 91#else
92#define TRACE0(fmt) (void) 0 92#define TRACE0(fmt) (void) 0
93#define TRACE1(fmt, a0) (void) 0 93#define TRACE1(fmt, a0) (void) 0
@@ -392,7 +392,6 @@ x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
392{ 392{
393 Lisp_Object local_value; 393 Lisp_Object local_value;
394 Lisp_Object handler_fn, value, check; 394 Lisp_Object handler_fn, value, check;
395 int count;
396 395
397 local_value = LOCAL_SELECTION (selection_symbol, dpyinfo); 396 local_value = LOCAL_SELECTION (selection_symbol, dpyinfo);
398 397
@@ -409,7 +408,7 @@ x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
409 /* Don't allow a quit within the converter. 408 /* Don't allow a quit within the converter.
410 When the user types C-g, he would be surprised 409 When the user types C-g, he would be surprised
411 if by luck it came during a converter. */ 410 if by luck it came during a converter. */
412 count = SPECPDL_INDEX (); 411 ptrdiff_t count = SPECPDL_INDEX ();
413 specbind (Qinhibit_quit, Qt); 412 specbind (Qinhibit_quit, Qt);
414 413
415 CHECK_SYMBOL (target_type); 414 CHECK_SYMBOL (target_type);
@@ -603,7 +602,7 @@ x_reply_selection_request (struct input_event *event,
603 Window window = SELECTION_EVENT_REQUESTOR (event); 602 Window window = SELECTION_EVENT_REQUESTOR (event);
604 ptrdiff_t bytes_remaining; 603 ptrdiff_t bytes_remaining;
605 int max_bytes = selection_quantum (display); 604 int max_bytes = selection_quantum (display);
606 int count = SPECPDL_INDEX (); 605 ptrdiff_t count = SPECPDL_INDEX ();
607 struct selection_data *cs; 606 struct selection_data *cs;
608 607
609 reply->type = SelectionNotify; 608 reply->type = SelectionNotify;
@@ -792,7 +791,7 @@ x_handle_selection_request (struct input_event *event)
792 Atom property = SELECTION_EVENT_PROPERTY (event); 791 Atom property = SELECTION_EVENT_PROPERTY (event);
793 Lisp_Object local_selection_data; 792 Lisp_Object local_selection_data;
794 int success = 0; 793 int success = 0;
795 int count = SPECPDL_INDEX (); 794 ptrdiff_t count = SPECPDL_INDEX ();
796 GCPRO2 (local_selection_data, target_symbol); 795 GCPRO2 (local_selection_data, target_symbol);
797 796
798 if (!dpyinfo) goto DONE; 797 if (!dpyinfo) goto DONE;
@@ -1141,7 +1140,7 @@ static void
1141wait_for_property_change (struct prop_location *location) 1140wait_for_property_change (struct prop_location *location)
1142{ 1141{
1143 int secs, usecs; 1142 int secs, usecs;
1144 int count = SPECPDL_INDEX (); 1143 ptrdiff_t count = SPECPDL_INDEX ();
1145 1144
1146 if (property_change_reply_object) 1145 if (property_change_reply_object)
1147 abort (); 1146 abort ();
@@ -1702,7 +1701,7 @@ selection_data_to_lisp_data (Display *display, const unsigned char *data,
1702 v = Fmake_vector (make_number (size / 2), make_number (0)); 1701 v = Fmake_vector (make_number (size / 2), make_number (0));
1703 for (i = 0; i < size / 2; i++) 1702 for (i = 0; i < size / 2; i++)
1704 { 1703 {
1705 EMACS_INT j = ((short *) data) [i]; 1704 short j = ((short *) data) [i];
1706 Faset (v, make_number (i), make_number (j)); 1705 Faset (v, make_number (i), make_number (j));
1707 } 1706 }
1708 return v; 1707 return v;
@@ -2623,13 +2622,12 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2623 if (x_check_property_data (values) == -1) 2622 if (x_check_property_data (values) == -1)
2624 error ("Bad data in VALUES, must be number, cons or string"); 2623 error ("Bad data in VALUES, must be number, cons or string");
2625 2624
2626 event.xclient.type = ClientMessage; 2625 if (XINT (format) != 8 && XINT (format) != 16 && XINT (format) != 32)
2627 event.xclient.format = XFASTINT (format);
2628
2629 if (event.xclient.format != 8 && event.xclient.format != 16
2630 && event.xclient.format != 32)
2631 error ("FORMAT must be one of 8, 16 or 32"); 2626 error ("FORMAT must be one of 8, 16 or 32");
2632 2627
2628 event.xclient.type = ClientMessage;
2629 event.xclient.format = XINT (format);
2630
2633 if (FRAMEP (dest) || NILP (dest)) 2631 if (FRAMEP (dest) || NILP (dest))
2634 { 2632 {
2635 struct frame *fdest = check_x_frame (dest); 2633 struct frame *fdest = check_x_frame (dest);
diff --git a/src/xterm.c b/src/xterm.c
index cc8987a4055..b05544a6fca 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3705,24 +3705,23 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
3705/* Convert between the modifier bits X uses and the modifier bits 3705/* Convert between the modifier bits X uses and the modifier bits
3706 Emacs uses. */ 3706 Emacs uses. */
3707 3707
3708EMACS_INT 3708int
3709x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state) 3709x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state)
3710{ 3710{
3711 EMACS_INT mod_meta = meta_modifier; 3711 int mod_meta = meta_modifier;
3712 EMACS_INT mod_alt = alt_modifier; 3712 int mod_alt = alt_modifier;
3713 EMACS_INT mod_hyper = hyper_modifier; 3713 int mod_hyper = hyper_modifier;
3714 EMACS_INT mod_super = super_modifier; 3714 int mod_super = super_modifier;
3715 Lisp_Object tem; 3715 Lisp_Object tem;
3716 3716
3717 tem = Fget (Vx_alt_keysym, Qmodifier_value); 3717 tem = Fget (Vx_alt_keysym, Qmodifier_value);
3718 if (INTEGERP (tem)) mod_alt = XINT (tem); 3718 if (INTEGERP (tem)) mod_alt = XINT (tem) & INT_MAX;
3719 tem = Fget (Vx_meta_keysym, Qmodifier_value); 3719 tem = Fget (Vx_meta_keysym, Qmodifier_value);
3720 if (INTEGERP (tem)) mod_meta = XINT (tem); 3720 if (INTEGERP (tem)) mod_meta = XINT (tem) & INT_MAX;
3721 tem = Fget (Vx_hyper_keysym, Qmodifier_value); 3721 tem = Fget (Vx_hyper_keysym, Qmodifier_value);
3722 if (INTEGERP (tem)) mod_hyper = XINT (tem); 3722 if (INTEGERP (tem)) mod_hyper = XINT (tem) & INT_MAX;
3723 tem = Fget (Vx_super_keysym, Qmodifier_value); 3723 tem = Fget (Vx_super_keysym, Qmodifier_value);
3724 if (INTEGERP (tem)) mod_super = XINT (tem); 3724 if (INTEGERP (tem)) mod_super = XINT (tem) & INT_MAX;
3725
3726 3725
3727 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0) 3726 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0)
3728 | ((state & ControlMask) ? ctrl_modifier : 0) 3727 | ((state & ControlMask) ? ctrl_modifier : 0)
@@ -3735,10 +3734,10 @@ x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state)
3735static int 3734static int
3736x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, EMACS_INT state) 3735x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, EMACS_INT state)
3737{ 3736{
3738 int mod_meta = meta_modifier; 3737 EMACS_INT mod_meta = meta_modifier;
3739 int mod_alt = alt_modifier; 3738 EMACS_INT mod_alt = alt_modifier;
3740 int mod_hyper = hyper_modifier; 3739 EMACS_INT mod_hyper = hyper_modifier;
3741 int mod_super = super_modifier; 3740 EMACS_INT mod_super = super_modifier;
3742 3741
3743 Lisp_Object tem; 3742 Lisp_Object tem;
3744 3743
@@ -6497,9 +6496,10 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6497 6496
6498 /* Now non-ASCII. */ 6497 /* Now non-ASCII. */
6499 if (HASH_TABLE_P (Vx_keysym_table) 6498 if (HASH_TABLE_P (Vx_keysym_table)
6500 && (NATNUMP (c = Fgethash (make_number (keysym), 6499 && (c = Fgethash (make_number (keysym),
6501 Vx_keysym_table, 6500 Vx_keysym_table,
6502 Qnil)))) 6501 Qnil),
6502 NATNUMP (c)))
6503 { 6503 {
6504 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) 6504 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c))
6505 ? ASCII_KEYSTROKE_EVENT 6505 ? ASCII_KEYSTROKE_EVENT
@@ -7782,7 +7782,7 @@ x_connection_closed (Display *dpy, const char *error_message)
7782{ 7782{
7783 struct x_display_info *dpyinfo = x_display_info_for_display (dpy); 7783 struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
7784 Lisp_Object frame, tail; 7784 Lisp_Object frame, tail;
7785 int idx = SPECPDL_INDEX (); 7785 ptrdiff_t idx = SPECPDL_INDEX ();
7786 7786
7787 error_msg = (char *) alloca (strlen (error_message) + 1); 7787 error_msg = (char *) alloca (strlen (error_message) + 1);
7788 strcpy (error_msg, error_message); 7788 strcpy (error_msg, error_message);
diff --git a/src/xterm.h b/src/xterm.h
index 89eb493a43c..8919b648371 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -779,8 +779,7 @@ enum
779struct scroll_bar 779struct scroll_bar
780{ 780{
781 /* These fields are shared by all vectors. */ 781 /* These fields are shared by all vectors. */
782 EMACS_INT size_from_Lisp_Vector_struct; 782 struct vectorlike_header header;
783 struct Lisp_Vector *next_from_Lisp_Vector_struct;
784 783
785 /* The window we're a scroll bar for. */ 784 /* The window we're a scroll bar for. */
786 Lisp_Object window; 785 Lisp_Object window;
@@ -821,12 +820,6 @@ struct scroll_bar
821 unsigned int fringe_extended_p : 1; 820 unsigned int fringe_extended_p : 1;
822}; 821};
823 822
824/* The number of elements a vector holding a struct scroll_bar needs. */
825#define SCROLL_BAR_VEC_SIZE \
826 ((sizeof (struct scroll_bar) \
827 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
828 / sizeof (Lisp_Object))
829
830/* Turning a lisp vector value into a pointer to a struct scroll_bar. */ 823/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
831#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) 824#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
832 825
@@ -996,7 +989,7 @@ extern void x_mouse_leave (struct x_display_info *);
996#ifdef USE_X_TOOLKIT 989#ifdef USE_X_TOOLKIT
997extern int x_dispatch_event (XEvent *, Display *); 990extern int x_dispatch_event (XEvent *, Display *);
998#endif 991#endif
999extern EMACS_INT x_x_to_emacs_modifiers (struct x_display_info *, int); 992extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1000extern int x_display_pixel_height (struct x_display_info *); 993extern int x_display_pixel_height (struct x_display_info *);
1001extern int x_display_pixel_width (struct x_display_info *); 994extern int x_display_pixel_width (struct x_display_info *);
1002 995