aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog1188
-rw-r--r--src/Makefile.in17
-rw-r--r--src/alloc.c166
-rw-r--r--src/bidi.c88
-rw-r--r--src/buffer.c384
-rw-r--r--src/buffer.h69
-rw-r--r--src/bytecode.c25
-rw-r--r--src/callint.c23
-rw-r--r--src/callproc.c71
-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.c113
-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.c119
-rw-r--r--src/doc.c45
-rw-r--r--src/doprnt.c2
-rw-r--r--src/editfns.c223
-rw-r--r--src/emacs.c57
-rw-r--r--src/eval.c222
-rw-r--r--src/fileio.c199
-rw-r--r--src/floatfns.c26
-rw-r--r--src/fns.c332
-rw-r--r--src/font.c65
-rw-r--r--src/font.h2
-rw-r--r--src/fontset.c18
-rw-r--r--src/frame.c65
-rw-r--r--src/frame.h2
-rw-r--r--src/fringe.c12
-rw-r--r--src/ftfont.c10
-rw-r--r--src/gmalloc.c8
-rw-r--r--src/gnutls.c19
-rw-r--r--src/gnutls.h8
-rw-r--r--src/gtkutil.c12
-rw-r--r--src/image.c13
-rw-r--r--src/indent.c206
-rw-r--r--src/indent.h44
-rw-r--r--src/insdel.c258
-rw-r--r--src/intervals.c134
-rw-r--r--src/intervals.h34
-rw-r--r--src/keyboard.c187
-rw-r--r--src/keyboard.h4
-rw-r--r--src/keymap.c76
-rw-r--r--src/keymap.h2
-rw-r--r--src/lisp.h347
-rw-r--r--src/lisp.mk43
-rw-r--r--src/lread.c241
-rw-r--r--src/m/README7
-rw-r--r--src/m/alpha.h53
-rw-r--r--src/m/amdx86-64.h35
-rw-r--r--src/m/ia64.h32
-rw-r--r--src/m/ibmrs6000.h46
-rw-r--r--src/m/ibms390x.h32
-rw-r--r--src/m/intel386.h29
-rw-r--r--src/m/m68k.h32
-rw-r--r--src/m/macppc.h24
-rw-r--r--src/m/sparc.h30
-rw-r--r--src/m/template.h34
-rw-r--r--src/macros.c23
-rw-r--r--src/makefile.w32-in12
-rw-r--r--src/marker.c95
-rw-r--r--src/mem-limits.h2
-rw-r--r--src/menu.c71
-rw-r--r--src/minibuf.c54
-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.h6
-rw-r--r--src/ralloc.c19
-rw-r--r--src/regex.c83
-rw-r--r--src/regex.h91
-rw-r--r--src/s/aix4-2.h11
-rw-r--r--src/s/gnu-linux.h6
-rw-r--r--src/s/gnu.h2
-rw-r--r--src/s/hpux10-20.h6
-rw-r--r--src/s/irix6-5.h4
-rw-r--r--src/s/ms-w32.h3
-rw-r--r--src/scroll.c8
-rw-r--r--src/search.c223
-rw-r--r--src/sound.c26
-rw-r--r--src/syntax.c188
-rw-r--r--src/syntax.h16
-rw-r--r--src/sysdep.c64
-rw-r--r--src/term.c8
-rw-r--r--src/termcap.c8
-rw-r--r--src/termhooks.h2
-rw-r--r--src/textprop.c53
-rw-r--r--src/tparam.c4
-rw-r--r--src/undo.c22
-rw-r--r--src/unexelf.c6
-rw-r--r--src/unexmacosx.c19
-rw-r--r--src/vm-limit.c2
-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.c134
-rw-r--r--src/window.h62
-rw-r--r--src/xdisp.c881
-rw-r--r--src/xfaces.c52
-rw-r--r--src/xfns.c52
-rw-r--r--src/xfont.c2
-rw-r--r--src/xgselect.c11
-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.c49
-rw-r--r--src/xterm.h14
132 files changed, 5399 insertions, 4465 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4e648223497..7a9ab1757eb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,1187 @@
12012-06-04 Paul Eggert <eggert@cs.ucla.edu>
2
3 * xdisp.c (note_mode_line_or_margin_highlight): Pacify gcc -Wall.
4
52012-06-03 Glenn Morris <rgm@gnu.org>
6
7 * xdisp.c (tool-bar-style): Doc fix.
8
92012-06-03 Ulrich Müller <ulm@gentoo.org>
10
11 * Makefile.in (PAXCTL): Define.
12 (temacs$(EXEEXT)): Disable memory randomization for the temacs
13 binary via PaX flags if the paxctl utility is available.
14 (emacs$(EXEEXT), bootstrap-emacs$(EXEEXT)):
15 Restore PaX flags to their default. (Bug#11398)
16
172012-06-03 Chong Yidong <cyd@gnu.org>
18
19 * xdisp.c (decode_mode_spec_coding): Display a space for a unibyte
20 buffer (Bug#11226).
21
222012-06-03 Chong Yidong <cyd@gnu.org>
23
24 * xdisp.c (calc_pixel_width_or_height): Use Fbuffer_local_value.
25 (note_mode_line_or_margin_highlight): If there is no help echo,
26 use mode-line-default-help-echo. Handle the case where the mouse
27 position is past the end of the mode line string.
28
29 * buffer.c (buffer_local_value_1): New function, split from
30 Fbuffer_local_value; can return Qunbound.
31 (Fbuffer_local_value): Use it.
32 (Vmode_line_format): Docstring tweaks.
33
342012-06-02 Paul Eggert <eggert@cs.ucla.edu>
35
36 * sysdep.c (system_process_attributes): Improve comment.
37
382012-06-02 Stefan Monnier <monnier@iro.umontreal.ca>
39
40 * keyboard.c: Export real-this-command to Elisp.
41 (syms_of_keyboard): Rename real_this_command to Vreal_this_command
42 and DEFVAR it. Update all users.
43
442012-06-02 Paul Eggert <eggert@cs.ucla.edu>
45
46 * minibuf.c (Fassoc_string): Remove duplicate declaration.
47
48 * sysdep.c (system_process_attributes) [SOLARIS2 && HAVE_PROCFS]:
49 Convert pctcpu and pctmem to Lisp float properly.
50 Let the compiler fold better, as 100.0/0x8000 is exact.
51
522012-06-02 Andreas Schwab <schwab@linux-m68k.org>
53
54 * alloc.c (CONS_BLOCK_SIZE): Account for padding at the end of
55 cons_block.
56
572012-06-01 Paul Eggert <eggert@cs.ucla.edu>
58
59 * xfns.c (x_set_tool_bar_lines) [USE_GTK]: Adjust to bitfield change.
60
612012-06-01 Dmitry Antipov <dmantipov@yandex.ru>
62
63 For a 'struct window', replace some Lisp_Object fields to
64 bitfields where appropriate, remove unused fields.
65 * window.h (struct window): Remove unused 'last_mark_x' and
66 'last_mark_y' fields. Rename 'mini_p' field to 'mini',
67 change it's type from Lisp_Object to bitfield.
68 Change type of 'force_start', 'optional_new_start',
69 'last_had_star', 'update_mode_line' and 'start_at_line_beg'
70 fields from Lisp_Object to bitfield. Adjust users accordingly.
71
722012-05-31 Paul Eggert <eggert@cs.ucla.edu>
73
74 Pacify gcc -Wdouble-precision when using Xaw.
75 * xterm.c (xaw_jump_callback, x_set_toolkit_scroll_bar_thumb)
76 [HAVE_X_WINDOWS && USE_TOOLKIT_SCROLL_BARS && !USE_MOTIF && !USE_GTK]:
77 Use 'float' consistently, rather than 'float' in most places
78 and 'double' in a couple of places.
79
802012-05-31 Eli Zaretskii <eliz@gnu.org>
81
82 * xdisp.c (handle_stop): Detect whether we have overlay strings
83 loaded by testing it->current.overlay_string_index to be
84 non-negative, instead of checking whether n_overlay_strings is
85 positive. (Bug#11587)
86
872012-05-31 Chong Yidong <cyd@gnu.org>
88
89 * keymap.c (describe_map_tree): Revert 2011-07-07 change (Bug#1169).
90
91 * doc.c (Fsubstitute_command_keys): Doc fix.
92
932012-05-31 Eli Zaretskii <eliz@gnu.org>
94
95 * search.c (search_buffer): Remove calls to
96 r_alloc_inhibit_buffer_relocation, as it is now called by
97 maybe_unify_char, which was the cause of relocation of buffer text
98 in bug#11519.
99
1002012-05-31 Eli Zaretskii <eliz@gnu.org>
101
102 * charset.c (maybe_unify_char): Inhibit relocation of buffer text
103 for the duration of call to load_charset, to avoid problems with
104 callers of maybe_unify_char that access buffer text through C
105 pointers.
106
107 * ralloc.c (r_alloc_inhibit_buffer_relocation): Increment and
108 decrement the inhibition flag, instead of just setting or
109 resetting it.
110
1112012-05-31 Paul Eggert <eggert@cs.ucla.edu>
112
113 Remove obsolete '#define static' cruft.
114 * s/hpux10-20.h (_FILE_OFFSET_BITS): Don't #undef.
115 This #undef was "temporary" in 2000; it is no longer needed
116 now that '#define static' has gone away.
117 * xfns.c, xterm.h (gray_bitmap_width, gray_bitmap_height)
118 (gray_bitmap_bits): Remove; no longer needed.
119 All uses replaced with definiens.
120 * xterm.c: Include "bitmaps/gray.xbm".
121
1222012-05-30 Paul Eggert <eggert@cs.ucla.edu>
123
124 Clean up __executable_start, monstartup when --enable-profiling.
125 The following changes affect the code only when profiling.
126 * dispnew.c (__executable_start): Rename from safe_bcopy.
127 Define only on platforms that need it.
128 * emacs.c: Include <sys/gmon.h> when profiling.
129 (_mcleanup): Remove decl, since <sys/gmon.h> does it now.
130 (__executable_start): Remove decl, since lisp.h does it now.
131 (safe_bcopy): Remove decl; no longer has that name.
132 (main): Coalesce #if into single bit of code, for simplicity.
133 Cast pointers to uintptr_t, since standard libraries want integers
134 and not pointers.
135 * lisp.h (__executable_start): New decl.
136
1372012-05-31 Glenn Morris <rgm@gnu.org>
138
139 * image.c (Fimagemagick_types): Doc fix.
140
1412012-05-30 Jim Meyering <meyering@redhat.com>
142
143 * callproc.c (Fcall_process_region): Include directory component
144 in mkstemp error message (Bug#11586).
145
1462012-05-30 Paul Eggert <eggert@cs.ucla.edu>
147
148 * alloc.c, lisp.h (make_pure_vector): Now static.
149
1502012-05-30 Stefan Monnier <monnier@iro.umontreal.ca>
151
152 * eval.c (Fdefun, Fdefmacro, Vmacro_declaration_function):
153 Move to byte-run.el.
154 (Fautoload): Do the hash-doc more carefully.
155 * data.c (Fdefalias): Purify definition, except for keymaps.
156 (Qdefun): Move from eval.c.
157 * lisp.h (Qdefun): Remove.
158 * lread.c (read1): Tiny simplification.
159
1602012-05-29 Troels Nielsen <bn.troels@gmail.com>
161
162 Do not create empty overlays with the evaporate property (Bug#9642).
163 * buffer.c (Fmove_overlay): Reinstate the earlier fix for
164 Bug#9642, but explicitly check that the buffer the overlay would
165 be moved to is live and rearrange lines to make sure that errors
166 will not put the overlay in an inconsistent state.
167 (Fdelete_overlay): Cosmetics.
168
1692012-05-28 Eli Zaretskii <eliz@gnu.org>
170
171 * w32term.c (my_bring_window_to_top): New function.
172 (x_raise_frame): Use handle returned by DeferWindowPos, which
173 could be different from the original one.
174 Call my_bring_window_to_top instead of my_set_foreground_window.
175 (Bug#11513)
176
177 * w32fns.c (w32_wnd_proc): Accept and process WM_EMACS_BRINGTOTOP
178 by calling BringWindowToTop.
179
180 * w32term.h (WM_EMACS_BRINGTOTOP): New message.
181 (WM_EMACS_END): Increase by one.
182
1832012-05-28 Paul Eggert <eggert@cs.ucla.edu>
184
185 * bidi.c (bidi_mirror_char): Put eassert before conversion to int.
186 This avoids undefined behavior that might cause the eassert
187 to not catch an out-of-range value.
188
1892012-05-28 Juanma Barranquero <lekktu@gmail.com>
190
191 * makefile.w32-in ($(BLD)/w32inevt.$(O), $(BLD)/w32console.$(O)):
192 Update dependencies.
193
1942012-05-27 Eli Zaretskii <eliz@gnu.org>
195
196 * bidi.c (bidi_mirror_char): Fix last change.
197
1982012-05-27 Andreas Schwab <schwab@linux-m68k.org>
199
200 * unexmacosx.c (copy_data_segment): Truncate after 16 characters
201 when referring to sectname field in printf format.
202
2032012-05-27 Paul Eggert <eggert@cs.ucla.edu>
204
205 * lisp.h [REL_ALLOC]: Omit duplicate prototypes.
206 Only r_alloc_inhibit_buffer_relocation needed to be added;
207 the others were already declared.
208
209 * bidi.c (bidi_mirror_char): Don't possibly truncate the integer
210 before checking whether it's out of range. Put the check inside
211 eassert. See
212 <http://lists.gnu.org/archive/html/emacs-devel/2012-05/msg00485.html>.
213
2142012-05-27 Ken Brown <kbrown@cornell.edu>
215
216 * callproc.c (Fcall_process): Restore a line that was accidentally
217 commented out in the 2011-02-13 change (bug#11547).
218
2192012-05-27 Eli Zaretskii <eliz@gnu.org>
220
221 * lisp.h [REL_ALLOC]: Add prototypes for external functions
222 defined on ralloc.c.
223
224 * buffer.c [REL_ALLOC]: Remove prototypes of
225 r_alloc_reset_variable, r_alloc, r_re_alloc, and r_alloc_free,
226 they are now on lisp.h.
227
228 * ralloc.c (r_alloc_inhibit_buffer_relocation): New function.
229
230 * search.c (search_buffer): Use it to inhibit relocation of buffer
231 text while re_search_2 is doing its job, because re_search_2 is
232 passed C pointers to buffer text. (Bug#11519)
233
234 * msdos.c (internal_terminal_init) <Vwindow_system_version>:
235 Update value to 24.
236
237 * xdisp.c (move_it_to): Under MOVE_TO_Y, when restoring iterator
238 state after an additional call to move_it_in_display_line_to, keep
239 the values of it->max_ascent and it->max_descent found for the
240 entire line.
241 (pos_visible_p): Revert the comparison against bottom_y to what it
242 was in revid eliz@gnu.org-20120513182235-4p6386j761ld0nwb.
243 (Bug#11464)
244
2452012-05-26 Paul Eggert <eggert@cs.ucla.edu>
246
247 Fix coding-related core dumps with gcc -ftrapv.
248 The code was computing A - B, where A and B are pointers, and B is
249 random garbage. This can lead to core dumps on platforms that
250 have special pointer registers, and it also leads to core dumps on
251 x86-64 when compiled with gcc -ftrapv. The fix is to compute
252 A - B only when B is initialized properly.
253 * coding.c (coding_set_source, coding_set_destination): Return void.
254 (coding_change_source, coding_change_destinations): New functions,
255 with the old behaviors of coding_set_source and coding_set_destination.
256 All callers that need an offset changed to use these new functions.
257
2582012-05-26 Glenn Morris <rgm@gnu.org>
259
260 * nsterm.m (ns_init_paths): Don't mess with INFOPATH. (Bug#2791)
261
2622012-05-26 Eli Zaretskii <eliz@gnu.org>
263
264 Extend mouse support on W32 text-mode console.
265 * xdisp.c (draw_row_with_mouse_face):
266 Call tty_draw_row_with_mouse_face for WINDOWSNT as well.
267
268 * w32console.c: Include window.h.
269 (w32con_write_glyphs_with_face, tty_draw_row_with_mouse_face):
270 New functions.
271 (initialize_w32_display): Initialize mouse-highlight data.
272
273 * w32inevt.c: Include termchar.h and window.h.
274 (do_mouse_event): Support mouse-autoselect-window. When the mouse
275 moves, call note_mouse_highlight. If help_echo changed, call
276 gen_help_event to produce help-echo message in the echo area.
277 Call clear_mouse_face if mouse_face_hidden is set in the mouse
278 highlight info.
279
2802012-05-26 Paul Eggert <eggert@cs.ucla.edu>
281
282 * lread.c (read1): Simplify slightly to avoid an overflow warning
283 with GCC 4.7.0 on x86-64.
284
2852012-05-26 Eli Zaretskii <eliz@gnu.org>
286
287 * bidi.c (bidi_mirror_char): Revert last change: an int is
288 definitely wide enough here.
289
2902012-05-25 Paul Eggert <eggert@cs.ucla.edu>
291
292 Fix integer width and related bugs (Bug#9874).
293 * alloc.c (pure_bytes_used_lisp, pure_bytes_used_non_lisp):
294 (allocate_vectorlike, buffer_memory_full, struct sdata, SDATA_SIZE)
295 (string_bytes, check_sblock, allocate_string_data):
296 (compact_small_strings, Fmake_bool_vector, make_string)
297 (make_unibyte_string, make_multibyte_string)
298 (make_string_from_bytes, make_specified_string)
299 (allocate_vectorlike, Fmake_vector, find_string_data_in_pure)
300 (make_pure_string, make_pure_c_string, make_pure_vector, Fpurecopy)
301 (mark_vectorlike):
302 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
303 (allocate_pseudovector):
304 Use int, not EMACS_INT, where int is wide enough.
305 (inhibit_garbage_collection, Fgarbage_collect):
306 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
307 * bidi.c (bidi_mirror_char): Use EMACS_INT, not int, where
308 int might not be wide enough.
309 (bidi_cache_search, bidi_cache_find, bidi_init_it)
310 (bidi_count_bytes, bidi_char_at_pos, bidi_fetch_char)
311 (bidi_at_paragraph_end, bidi_find_paragraph_start)
312 (bidi_paragraph_init, bidi_resolve_explicit, bidi_resolve_weak)
313 (bidi_level_of_next_char, bidi_move_to_visually_next):
314 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
315 * buffer.c (copy_overlays, Fgenerate_new_buffer_name)
316 (Fkill_buffer, Fset_buffer_major_mode)
317 (advance_to_char_boundary, Fbuffer_swap_text)
318 (Fset_buffer_multibyte, overlays_at, overlays_in)
319 (overlay_touches_p, struct sortvec, record_overlay_string)
320 (overlay_strings, recenter_overlay_lists)
321 (adjust_overlays_for_insert, adjust_overlays_for_delete)
322 (fix_start_end_in_overlays, fix_overlays_before, modify_overlay)
323 (Fmove_overlay, Fnext_overlay_change, Fprevious_overlay_change)
324 (Foverlay_recenter, last_overlay_modification_hooks_used)
325 (report_overlay_modification, evaporate_overlays, enlarge_buffer_text):
326 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
327 (validate_region): Omit unnecessary test for b <= e,
328 since that's guaranteed by the previous test.
329 (adjust_overlays_for_delete): Avoid pos + length overflow.
330 (Fmove_overlay, Fdelete_overlay, add_overlay_mod_hooklist)
331 (report_overlay_modification):
332 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
333 (Foverlays_at, Fnext_overlay_change, Fprevious_overlay_change):
334 Omit pointer cast, which isn't needed anyway, and doesn't work
335 after the EMACS_INT -> ptrdiff_t change.
336 (Fmove_overlay): Clip BEG and END to ptrdiff_t to avoid overflow.
337 * buffer.h: Adjust decls to match defn changes elsewhere.
338 (struct buffer_text, struct buffer):
339 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
340 Use EMACS_INT, not int, where int might not be wide enough.
341 * bytecode.c (unmark_byte_stack, exec_byte_code): Use ptrdiff_t,
342 not int, to avoid needless 32-bit limit on 64-bit hosts.
343 (exec_byte_code): Use tighter memory-full test, one that checks
344 for alloca overflow. Don't compute the address of the object just
345 before an array, as that's not portable. Use EMACS_INT, not
346 ptrdiff_t or int, where ptrdiff_t or int might not be wide enough.
347 * callint.c (Fcall_interactively):
348 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
349 * callproc.c (call_process_kill, Fcall_process):
350 Don't assume pid_t fits into an Emacs fixnum.
351 (call_process_cleanup, Fcall_process, child_setup):
352 Don't assume pid_t fits into int.
353 (call_process_cleanup, Fcall_process, delete_temp_file)
354 (Fcall_process_region):
355 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
356 (Fcall_process): Simplify handling of volatile integers.
357 Use int, not EMACS_INT, where int will do.
358 * casefiddle.c (casify_object, casify_region, operate_on_word)
359 (Fupcase_word, Fdowncase_word, Fcapitalize_word):
360 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
361 (casify_object): Avoid integer overflow when overallocating buffer.
362 * casetab.c (set_identity, shuffle): Prefer int to unsigned when
363 either works. Use lint_assume to convince GCC 4.6.1 that it's OK.
364 * category.c (Fchar_category_set): Don't assume fixnum fits in int.
365 * category.h (CATEGORYP): Don't assume arg is nonnegative.
366 * ccl.c (GET_CCL_INT): Remove; no longer needed, since the
367 integers are now checked earlier. All uses replaced with XINT.
368 (ccl_driver):
369 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
370 For CCL_MapSingle, check that content and value are in int range.
371 (ccl_driver, Fregister_code_conversion_map):
372 Check that Vcode_version_map_vector is a vector.
373 (resolve_symbol_ccl_program): Check that vector header is in range.
374 Always copy the vector, so that we can check its contents reliably
375 now rather than having to recheck each instruction as it's being
376 executed. Check that vector words fit in 'int'.
377 (ccl_get_compiled_code, Fregister_ccl_program)
378 (Fregister_code_conversion_map): Use ptrdiff_t, not int, for
379 program indexes, to avoid needless 32-bit limit on 64-bit hosts.
380 (Fccl_execute, Fccl_execute_on_string): Check that initial reg
381 contents are in range.
382 (Fccl_execute_on_string): Check that status is in range.
383 * ccl.h (struct ccl_program.idx): Now ptrdiff_t, not int.
384 * character.c (char_resolve_modifier_mask, Fchar_resolve_modifiers):
385 Accept and return EMACS_INT, not int, because callers can pass values
386 out of 'int' range.
387 (c_string_width, strwidth, lisp_string_width, chars_in_text)
388 (multibyte_chars_in_text, parse_str_as_multibyte)
389 (str_as_multibyte, count_size_as_multibyte, str_to_multibyte)
390 (str_as_unibyte, str_to_unibyte, string_count_byte8)
391 (string_escape_byte8, Fget_byte):
392 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
393 (Funibyte_string): Use CHECK_RANGED_INTEGER, not CHECK_NATNUM, to
394 avoid mishandling large integers.
395 * character.h: Adjust decls to match defn changes elsewhere.
396 * charset.c (load_charset_map_from_file, find_charsets_in_text)
397 (Ffind_charset_region):
398 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
399 (load_charset_map_from_file): Redo idx calculation to avoid overflow.
400 (load_charset_map_from_vector, Fdefine_charset_internal):
401 Don't assume fixnum fits in int.
402 (load_charset_map_from_vector, Fmap_charset_chars):
403 Remove now-unnecessary CHECK_NATNUMs.
404 (Fdefine_charset_internal): Check ranges here, more carefully.
405 Don't rely on undefined behavior with signed left shift overflow.
406 Don't assume unsigned int fits into fixnum, or that fixnum fits
407 into unsigned int. Don't require max_code to be a valid fixnum;
408 that's not true for gb10830 4-byte on a 32-bit host. Allow
409 invalid_code to be a cons, for the same reason. Require code_offset
410 to be a character. Avoid int overflow if max_char is close
411 to INT_MAX.
412 (CODE_POINT_TO_INDEX): On 32-bit hosts, return int, not unsigned;
413 this is intended anyway and avoids some undefined behavior.
414 (load_charset_map): Pass unsigned, not int, as 2nd arg of
415 INDEX_TO_CODE_POINT, as that's what it expects.
416 (Funify_charset, encode_char): Don't stuff unsigned vals into int vars.
417 * charset.h (DECODE_CHAR): Return int, not unsigned;
418 this is what was intended anyway, and it avoids undefined behavior.
419 (CHARSET_OFFSET): Remove unused macro, instead of fixing its
420 integer-overflow issues.
421 (ENCODE_CHAR): Return unsigned on all hosts, not just on 32-bit hosts.
422 Formerly, it returned EMACS_INT on 64-bit hosts in the common case
423 where the argument is EMACS_INT, and this behavior is not intended.
424 * chartab.c (Fmake_char_table, Fset_char_table_range)
425 (uniprop_get_decoder, uniprop_get_encoder):
426 Don't assume fixnum fits in int.
427 * cmds.c (move_point): New function, that does the gist of
428 Fforward_char and Fbackward_char, but does so while checking
429 for integer overflow more accurately.
430 (Fforward_char, Fbackward_char): Use it.
431 (Fforward_line, Fend_of_line, internal_self_insert)
432 (internal_self_insert):
433 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
434 Fix a FIXME, by checking for integer overflow when calculating
435 target_clm and actual_clm.
436 * coding.c (detect_coding_XXX, encode_coding_XXX, CODING_DECODE_CHAR)
437 (CODING_ENCODE_CHAR, CODING_CHAR_CHARSET, CODING_CHAR_CHARSET_P)
438 (ASSURE_DESTINATION, coding_alloc_by_realloc)
439 (coding_alloc_by_making_gap, alloc_destination)
440 (detect_coding_utf_8, encode_coding_utf_8, decode_coding_utf_16)
441 (encode_coding_utf_16, detect_coding_emacs_mule)
442 (decode_coding_emacs_mule, encode_coding_emacs_mule)
443 (detect_coding_iso_2022, decode_coding_iso_2022)
444 (encode_invocation_designation, encode_designation_at_bol)
445 (encode_coding_iso_2022, detect_coding_sjis, detect_coding_big5)
446 (decode_coding_sjis, decode_coding_big5, encode_coding_sjis)
447 (encode_coding_big5, detect_coding_ccl, decode_coding_ccl)
448 (encode_coding_ccl, encode_coding_raw_text)
449 (detect_coding_charset, decode_coding_charset)
450 (encode_coding_charset, detect_eol, decode_eol, produce_chars)
451 (produce_composition, produce_charset, produce_annotation)
452 (decode_coding, handle_composition_annotation)
453 (handle_charset_annotation, consume_chars, decode_coding_gap)
454 (decode_coding_object, encode_coding_object, detect_coding_system)
455 (Ffind_coding_systems_region_internal, Fcheck_coding_systems_region)
456 (code_convert_region, code_convert_string)
457 (Fdefine_coding_system_internal)
458 (coding_set_source, coding_set_destination):
459 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
460 (setup_iso_safe_charsets, consume_chars, Funencodable_char_position)
461 (Fdefine_coding_system_internal):
462 Don't assume fixnums fit in int.
463 (decode_coding_gap, decode_coding_object, encode_coding_object)
464 (Fread_coding_system, Fdetect_coding_region)
465 (Funencodable_char_position, Fcheck_coding_systems_region)
466 (get_translation, handle_composition_annotation, consume_chars):
467 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
468 (consume_chars): Rewrite to not calculate an address outside buffer.
469 (Ffind_operation_coding_system): NATNUMP can eval its arg twice.
470 Don't access memory outside of the args array.
471 (Fdefine_coding_system_internal): Check for charset-id overflow.
472 (ENCODE_ISO_CHARACTER): Use unsigned, not int, to store the unsigned
473 result of ENCODE_CHAR.
474 * coding.h: Adjust decls to match defn changes elsewhere.
475 (struct coding_system):
476 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
477 * composite.c (get_composition_id, find_composition)
478 (run_composition_function, update_compositions)
479 (compose_text, composition_gstring_put_cache)
480 (composition_gstring_p, composition_gstring_width)
481 (fill_gstring_header, fill_gstring_body, autocmp_chars)
482 (composition_compute_stop_pos, composition_reseat_it)
483 (composition_update_it, struct position_record)
484 (find_automatic_composition, composition_adjust_point)
485 (Fcomposition_get_gstring, Ffind_composition_internal):
486 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
487 (update_compositions):
488 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
489 * composite.h: Adjust decls to match defn changes elsewhere.
490 (struct composition):
491 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
492 * data.c (let_shadows_buffer_binding_p, let_shadows_global_binding_p):
493 Do not attempt to compute the address of the object just before a
494 buffer; this is not portable.
495 (Faref, Faset):
496 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
497 (Faset): Use int, not EMACS_INT, where int is wide enough.
498 (Fstring_to_number): Don't assume fixnums fit in int.
499 (Frem): Don't assume arg is nonnegative.
500 * dbusbind.c (xd_append_arg): Check for integers out of range.
501 (Fdbus_call_method): Don't overflow the timeout int.
502 (extract_signed, extract_unsigned): New functions.
503 (XD_CHECK_DBUS_SERIAL): Remove; superseded by extract_unsigned.
504 (xd_get_connection_references): Return ptrdiff_t, not int.
505 All uses changed.
506 (xd_signature, xd_append_arg, xd_retrieve_arg, Fdbus_message_internal)
507 (xd_read_message_1):
508 Use int, not unsigned, where the dbus API uses int.
509 (Fdbus_message_internal): Don't overflow mtype.
510 (syms_of_dbusbind): Allocate right-sized buffer for integers.
511 * dired.c (directory_files_internal, file_name_completion, scmp)
512 (file_name_completion_stat):
513 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
514 (file_name_completion): Don't overflow matchcount.
515 (file_name_completion_stat): Use SAFE_ALLOCA, not alloca.
516 * dispextern.h: Adjust decls to match defn changes elsewhere.
517 (struct text_pos, struct glyph, struct bidi_saved_info)
518 (struct bidi_string_data, struct bidi_it, struct composition_it)
519 (struct it):
520 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
521 (struct display_pos, struct composition_it, struct it):
522 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
523 * dispnew.c (increment_matrix_positions)
524 (increment_row_positions, mode_line_string)
525 (marginal_area_string):
526 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
527 (change_frame_size_1, Fredisplay, Fframe_or_buffer_changed_p):
528 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
529 (duration_to_sec_usec): New function, to check for overflow better.
530 (Fsleep_for, sit_for): Use it.
531 * doc.c (get_doc_string, store_function_docstring):
532 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
533 (get_doc_string, Fsnarf_documentation):
534 Use int, not EMACS_INT, where int is wide enough.
535 (get_doc_string):
536 Use SAFE_ALLOCA, not alloca.
537 Check for overflow when converting EMACS_INT to off_t.
538 * doprnt.c (doprnt):
539 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
540 * editfns.c (init_editfns, Fuser_uid, Fuser_real_uid):
541 Don't assume uid_t fits into fixnum.
542 (buildmark, Fgoto_char, overlays_around, find_field, Fdelete_field)
543 (Ffield_string, Ffield_string_no_properties, Ffield_beginning)
544 (Ffield_end, Fconstrain_to_field, Fline_beginning_position)
545 (Fline_end_position, Fprevious_char, Fchar_after, Fchar_before)
546 (general_insert_function)
547 (Finsert_char, make_buffer_string, make_buffer_string_both)
548 (update_buffer_properties, Fbuffer_substring)
549 (Fbuffer_substring_no_properties, Fcompare_buffer_substrings)
550 (Fsubst_char_in_region, check_translation)
551 (Ftranslate_region_internal, save_restriction_restore, Fformat)
552 (transpose_markers, Ftranspose_regions):
553 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
554 (clip_to_bounds): Move to lisp.h as an inline function).
555 (Fconstrain_to_field): Don't assume integers are nonnegative.
556 (Fline_beginning_position, Fsave_excursion, Fsave_current_buffer):
557 (Fsubst_char_in_region, Fsave_restriction):
558 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
559 (Femacs_pid): Don't assume pid_t fits into fixnum.
560 (lo_time): Use int, not EMACS_INT, when int suffices.
561 (lisp_time_argument): Check for usec out of range.
562 (Fencode_time): Don't assume fixnum fits in int.
563 (Fuser_login_name, Fuser_full_name): Signal an error
564 if a uid argument is out of range, rather than relying on
565 undefined behavior.
566 (Fformat_time_string): Remove now-unnecessary check.
567 lisp_time_argument checks for out-of-range usec now.
568 Use ptrdiff_t, not size_t, where ptrdiff_t will do.
569 * emacs.c (gdb_valbits, gdb_gctypebits): Now int, not EMACS_INT.
570 (gdb_data_seg_bits): Now uintptr_t, not EMACS_INT.
571 (PVEC_FLAG, gdb_array_mark_flag): Now ptrdiff_t, not EMACS_INT.
572 (init_cmdargs, Fdump_emacs):
573 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
574 (Fkill_emacs): Don't assume fixnum fits in int; instead, take just
575 the bottom (typically) 32 bits of the fixnum.
576 * eval.c (specpdl_size, call_debugger):
577 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
578 (when_entered_debugger, Fbacktrace_debug):
579 Don't assume fixnum can fit in int.
580 (Fdefvaralias, Fdefvar): Do not attempt to compute the address of
581 the object just before a buffer; this is not portable.
582 (FletX, Flet, Funwind_protect, do_autoload, Feval, funcall_lambda)
583 (grow_specpdl, unbind_to):
584 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
585 (Fapply, apply_lambda): Don't assume ptrdiff_t can hold fixnum.
586 (grow_specpdl): Simplify allocation by using xpalloc.
587 (Fprog1, Fprog2): Don't assume list length fits in int. Simplify.
588 * fileio.c (Ffind_file_name_handler, Fcopy_file, Frename_file)
589 (Finsert_file_contents, Fwrite_region, Fdo_auto_save):
590 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
591 (Ffind_file_name_handler, non_regular_inserted, Finsert_file_contents)
592 (a_write, e_write):
593 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
594 (Fcopy_file, non_regular_nbytes, read_non_regular)
595 (Finsert_file_contents):
596 Use int, not EMACS_INT, where int is wide enough.
597 (READ_BUF_SIZE): Verify that it fits in int.
598 (Finsert_file_contents): Check that counts are in proper range,
599 rather than assuming fixnums fit into ptrdiff_t etc.
600 Don't assume fixnums fit into int.
601 * floatfns.c (Fexpt): Avoid undefined signed * signed overflow.
602 * fns.c (Fcompare_strings, Fstring_lessp, struct textprop_rec, concat)
603 (string_char_byte_cache_charpos, string_char_byte_cache_bytepos)
604 (string_char_to_byte, string_byte_to_char)
605 (string_make_multibyte, string_to_multibyte)
606 (string_make_unibyte, Fstring_as_unibyte, Fstring_as_multibyte)
607 (Fstring_to_unibyte, Fsubstring, Fsubstring_no_properties)
608 (substring_both, Fdelete, internal_equal, Ffillarray)
609 (Fclear_string, mapcar1)
610 (Fbase64_encode_region, Fbase64_encode_string, base64_encode_1)
611 (Fbase64_decode_region, Fbase64_decode_string, base64_decode_1)
612 (larger_vector, make_hash_table, maybe_resize_hash_table)
613 (hash_lookup, hash_remove_from_table, hash_clear, sweep_weak_table)
614 (Fmaphash, secure_hash):
615 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
616 (concat): Check for string index and length overflow.
617 (Fmapconcat): Don't assume fixnums fit into ptrdiff_t.
618 (Frequire):
619 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
620 (larger_vector): New API (vec, incr_min, size_max) replaces old
621 one (vec, new_size, init). This catches size overflow.
622 INIT was removed because it was always Qnil.
623 All callers changed.
624 (INDEX_SIZE_BOUND): New macro, which calculates more precisely
625 the upper bound on a hash table index size.
626 (make_hash_table, maybe_resize_hash_table): Use it.
627 (secure_hash): Computer start_byte and end_byte only after
628 they're known to be in ptrdiff_t range.
629 * font.c (font_intern_prop, font_at, font_range, Ffont_shape_gstring)
630 (Ffont_get_glyphs, Ffont_at):
631 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
632 (font_style_to_value, font_prop_validate_style, font_expand_wildcards)
633 (Flist_fonts, Fopen_font):
634 Don't assume fixnum can fit in int.
635 (check_gstring): Don't assume index can fit in int.
636 (font_match_p): Check that fixnum is a character, not a nonnegative
637 fixnum, since the later code needs to stuff it into an int.
638 (font_find_for_lface): Use SAFE_ALLOCA_LISP, not alloca.
639 (font_fill_lglyph_metrics): Use unsigned, not EMACS_INT, to avoid
640 conversion overflow issues.
641 (Fopen_font): Check for integer out of range.
642 (Ffont_get_glyphs): Don't assume index can fit in int.
643 * font.h: Adjust decls to match defn changes elsewhere.
644 * fontset.c (reorder_font_vector): Redo score calculation to avoid
645 integer overflow.
646 (num_auto_fontsets, fontset_from_font): Use ptrdiff_t, not
647 printmax_t, where ptrdiff_t is wide enough.
648 (Finternal_char_font):
649 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
650 * frame.c (Fset_mouse_position, Fset_mouse_pixel_position)
651 (Fset_frame_height, Fset_frame_width, Fset_frame_size)
652 (Fset_frame_position, x_set_frame_parameters)
653 (x_set_line_spacing, x_set_border_width)
654 (x_set_internal_border_width, x_set_alpha, x_figure_window_size):
655 Check that fixnums are in proper range for system types.
656 (frame_name_fnn_p, Fframe_parameter, Fmodify_frame_parameters):
657 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
658 (Fmodify_frame_parameters): Don't assume fixnum fits in int.
659 Use SAFE_ALLOCA_LISP, not alloca.
660 * frame.h (struct frame): Use intptr_t, not EMACS_INT, where
661 intptr_t is wide enough.
662 * fringe.c (lookup_fringe_bitmap, get_logical_fringe_bitmap)
663 (Fdefine_fringe_bitmap): Don't assume fixnum fits in int.
664 (Ffringe_bitmaps_at_pos): Don't assume index fits in int.
665 Check for fixnum out of range.
666 * ftfont.c (ftfont_list): Don't assume index fits in int.
667 Check that fixnums are in proper range for system types.
668 (ftfont_shape_by_flt):
669 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
670 * gnutls.c (emacs_gnutls_write, emacs_gnutls_read):
671 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
672 (Fgnutls_error_fatalp, Fgnutls_error_string, Fgnutls_boot):
673 Check that fixnums are in proper range for system types.
674 * gnutls.h: Adjust decls to match defn changes elsewhere.
675 * gtkutil.c (xg_dialog_run):
676 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
677 (update_frame_tool_bar):
678 Check that fixnums are in proper range for system types.
679 * image.c (parse_image_spec): Redo count calculation to avoid overflow.
680 (lookup_image): Check that fixnums are in range for system types.
681 * indent.c (last_known_column, last_known_column_point):
682 (current_column_bol_cache):
683 (skip_invisible, current_column, check_display_width):
684 (check_display_width, scan_for_column, current_column_1)
685 (Findent_to, Fcurrent_indentation, position_indentation)
686 (indented_beyond_p, Fmove_to_column, compute_motion):
687 (Fcompute_motion, Fvertical_motion):
688 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
689 (last_known_column_modified): Use EMACS_INT, not int.
690 (check_display_width):
691 (Fcompute_motion):
692 Check that fixnums and floats are in proper range for system types.
693 (compute_motion): Don't assume index or fixnum fits in int.
694 (compute_motion, Fcompute_motion):
695 Use int, not EMACS_INT, when it is wide enough.
696 (vmotion): Omit local var start_hpos that is always 0; that way
697 we don't need to worry about overflow in expressions involving it.
698 * indent.h: Adjust decls to match defn changes elsewhere.
699 (struct position):
700 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
701 Use int, not EMACS_INT, where int is wide enough.
702 Remove unused members ovstring_chars_done and tab_offset;
703 all uses removed.
704 * insdel.c (move_gap, move_gap_both, gap_left, gap_right)
705 (adjust_markers_for_delete, adjust_markers_for_insert, adjust_point)
706 (adjust_markers_for_replace, make_gap_larger, make_gap_smaller)
707 (make_gap, copy_text, insert, insert_and_inherit)
708 (insert_before_markers, insert_before_markers_and_inherit)
709 (insert_1, count_combining_before, count_combining_after)
710 (insert_1_both, insert_from_string)
711 (insert_from_string_before_markers, insert_from_string_1)
712 (insert_from_gap, insert_from_buffer, insert_from_buffer_1)
713 (adjust_after_replace, adjust_after_insert, replace_range)
714 (replace_range_2, del_range, del_range_1, del_range_byte)
715 (del_range_both, del_range_2, modify_region)
716 (prepare_to_modify_buffer, signal_before_change)
717 (signal_after_change, Fcombine_after_change_execute):
718 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
719 * intervals.c (traverse_intervals, rotate_right, rotate_left)
720 (balance_an_interval, split_interval_right, split_interval_left)
721 (find_interval, next_interval, update_interval)
722 (adjust_intervals_for_insertion, delete_node, delete_interval)
723 (interval_deletion_adjustment, adjust_intervals_for_deletion)
724 (static_offset_intervals, offset_intervals)
725 (merge_interval_right, merge_interval_left, make_new_interval)
726 (graft_intervals_into_buffer, temp_set_point_both)
727 (temp_set_point, set_point, adjust_for_invis_intang)
728 (set_point_both, move_if_not_intangible, get_property_and_range)
729 (get_local_map, copy_intervals, copy_intervals_to_string)
730 (compare_string_intervals, set_intervals_multibyte_1):
731 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
732 * intervals.h: Adjust decls to match defn changes elsewhere.
733 (struct interval):
734 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
735 * keyboard.c (this_command_key_count, this_single_command_key_start)
736 (before_command_key_count, before_command_echo_length, echo_now)
737 (echo_length, recursive_edit_1, Frecursive_edit, Ftrack_mouse)
738 (command_loop_1, safe_run_hooks, read_char, timer_check_2)
739 (menu_item_eval_property, read_key_sequence, Fread_key_sequence)
740 (Fread_key_sequence_vector, Fexecute_extended_command, Fsuspend_emacs):
741 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
742 (last_non_minibuf_size, last_point_position, echo_truncate)
743 (command_loop_1, adjust_point_for_property, read_char, gen_help_event)
744 (make_lispy_position, make_lispy_event, parse_modifiers_uncached)
745 (parse_modifiers, modify_event_symbol, Fexecute_extended_command)
746 (stuff_buffered_input):
747 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
748 (last_auto_save, command_loop_1, read_char):
749 Use EMACS_INT, not int, to avoid integer overflow.
750 (record_char): Avoid overflow in total_keys computation.
751 (parse_modifiers_uncached): Redo index calculation to avoid overflow.
752 * keyboard.h: Adjust decls to match defn changes elsewhere.
753 * keymap.c (Fdefine_key, Fcurrent_active_maps, accessible_keymaps_1)
754 (Fkey_description, Fdescribe_vector, Flookup_key):
755 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
756 (click_position): New function, to check that positions are in range.
757 (Fcurrent_active_maps):
758 (describe_command):
759 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
760 (Faccessible_keymaps, Fkey_description):
761 (preferred_sequence_p):
762 Don't assume fixnum can fit into int.
763 (Fkey_description): Use SAFE_ALLOCA_LISP, not alloca.
764 Check for integer overflow in size calculations.
765 (Ftext_char_description): Use CHECK_CHARACTER, not CHECK_NUMBER, to
766 avoid mishandling large integers.
767 * lisp.h: Adjust decls to match defn changes elsewhere.
768 (ARRAY_MARK_FLAG, PSEUDOVECTOR_FLAG, struct Lisp_String)
769 (struct vectorlike_header, struct Lisp_Subr, struct Lisp_Hash_Table)
770 (struct Lisp_Marker):
771 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
772 (clip_to_bounds): Now an inline function, moved here from editfns.c.
773 (GLYPH_CODE_P): Check for overflow in system types, subsuming the
774 need for GLYPH_CODE_CHAR_VALID_P and doing proper checking ourselves.
775 All callers changed.
776 (GLYPH_CODE_CHAR, GLYPH_CODE_FACE):
777 Assume the arg has valid form, since it always does.
778 (TYPE_RANGED_INTEGERP): Avoid bug when checking against a wide
779 unsigned integer system type.
780 (CHECK_RANGED_INTEGER, CHECK_TYPE_RANGED_INTEGER): New macros.
781 (struct catchtag, specpdl_size, SPECPDL_INDEX, USE_SAFE_ALLOCA):
782 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
783 (struct catchtag): Use EMACS_INT, not int, since it may be a fixnum.
784 (duration_to_sec_usec): New decl.
785 * lread.c (read_from_string_index, read_from_string_index_byte)
786 (read_from_string_limit, readchar, unreadchar, openp)
787 (read_internal_start, read1, oblookup):
788 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
789 (Fload, readevalloop, Feval_buffer, Feval_region):
790 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
791 (openp): Check for out-of-range argument to 'access'.
792 (read1): Use int, not EMACS_INT, where int is wide enough.
793 Don't assume fixnum fits into int.
794 Fix off-by-one error that can read outside a buffer.
795 (read_filtered_event): Use duration_to_sec_usec
796 to do proper overflow checking on durations.
797 * macros.c (Fstart_kbd_macro): Use xpalloc to check for overflow
798 in size calculation.
799 (Fexecute_kbd_macro):
800 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
801 * marker.c (cached_charpos, cached_bytepos, CONSIDER)
802 (byte_char_debug_check, buf_charpos_to_bytepos, verify_bytepos)
803 (buf_bytepos_to_charpos, Fset_marker, set_marker_restricted)
804 (set_marker_both, set_marker_restricted_both, marker_position)
805 (marker_byte_position, Fbuffer_has_markers_at):
806 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
807 (Fset_marker, set_marker_restricted): Don't assume fixnum fits in int.
808 * menu.c (ensure_menu_items): Rename from grow_menu_items.
809 It now merely ensures that the menu is large enough, without
810 necessarily growing it, as this avoids some integer overflow issues.
811 All callers changed.
812 (keymap_panes, parse_single_submenu, Fx_popup_menu):
813 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
814 (parse_single_submenu, Fx_popup_menu): Don't assume fixnum fits in int.
815 Use SAFE_ALLOCA_LISP, not alloca.
816 (find_and_return_menu_selection): Avoid unnecessary casts of pointers
817 to EMACS_INT. Check that fixnums are in proper range for system types.
818 * minibuf.c (minibuf_prompt_width, string_to_object)
819 (Fminibuffer_contents, Fminibuffer_contents_no_properties)
820 (Fminibuffer_completion_contents, Ftry_completion, Fall_completions):
821 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
822 (get_minibuffer, read_minibuf_unwind):
823 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
824 (read_minibuf): Omit unnecessary arg BACKUP_N, which is always nil;
825 this simplifies overflow checking. All callers changed.
826 (read_minibuf, Fread_buffer, Ftry_completion, Fall_completions)
827 (Ftest_completion):
828 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
829 * nsfns.m (check_ns_display_info): Don't assume fixnum fits in long.
830 (x_set_menu_bar_lines, x_set_tool_bar_lines, Fx_create_frame):
831 Check that fixnums are in proper range for system types.
832 (Fx_create_frame, Fx_show_tip):
833 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
834 * nsfont.m (ns_findfonts, nsfont_list_family):
835 Don't assume fixnum fits in long.
836 * nsmenu.m (ns_update_menubar, ns_menu_show, ns_popup_dialog):
837 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
838 (ns_update_menubar): Use intptr_t, not EMACS_INT, when intptr_t is
839 wide enough.
840 * nsselect.m (ns_get_local_selection, clean_local_selection_data):
841 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
842 * print.c (print_buffer_size, print_buffer_pos, print_buffer_pos_byte)
843 (PRINTDECLARE, PRINTPREPARE):
844 (strout, print_string):
845 (print, print_preprocess, print_check_string_charset_prop)
846 (print_object):
847 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
848 (PRINTDECLARE):
849 (temp_output_buffer_setup, Fprin1_to_string, print_object):
850 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
851 (PRINTPREPARE): Use int, not ptrdiff_t, where int is wide enough.
852 (printchar, strout): Use xpalloc to catch size calculation overflow.
853 (Fexternal_debugging_output): Don't overflow EMACS_INT->int conversion.
854 (print_error_message): Use SAFE_ALLOCA, not alloca.
855 (print_object): Use int, not EMACS_INT, where int is wide enough.
856 (print_depth, new_backquote_output, print_number_index):
857 Use ptrdiff_t, not int, where int might not be wide enough.
858 * process.c (Fdelete_process): Don't assume pid fits into EMACS_INT.
859 (Fset_process_window_size, Fformat_network_address)
860 (get_lisp_to_sockaddr_size, set_socket_option, Fmake_network_process)
861 (sigchld_handler):
862 Check that fixnums are in proper range for system types.
863 (Fsignal_process): Simplify by avoiding a goto.
864 Check for process-ids out of pid_t range rather than relying on
865 undefined behavior.
866 (process_tick, update_tick): Use EMACS_INT, not int.
867 (Fformat_network_address, read_process_output, send_process)
868 (Fprocess_send_region, status_notify):
869 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
870 (Fformat_network_address, Fmake_serial_process, Fmake_network_process)
871 (wait_reading_process_output, read_process_output, exec_sentinel):
872 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
873 (conv_lisp_to_sockaddr): Don't assume fixnums fit into int.
874 (Faccept_process_output): Use duration_to_sec_usec to do proper
875 overflow checking on durations.
876 (emacs_get_tty_pgrp, Fprocess_running_child_p, process_send_signal):
877 Don't assume pid_t fits in int.
878 * process.h (struct Lisp_Process): Members tick and update_tick
879 are now of type EMACS_INT, not int.
880 * puresize.h (PURESIZE_RATIO): Shrink this to 8/6 on 32-bit hosts
881 configured --with-wide-int.
882 * scroll.c (calculate_scrolling, calculate_direct_scrolling)
883 (line_ins_del): Use int, not EMACS_INT, where int is wide enough.
884 * search.c (looking_at_1, string_match_1):
885 (fast_string_match, fast_c_string_match_ignore_case)
886 (fast_string_match_ignore_case, fast_looking_at, scan_buffer)
887 (scan_newline, find_before_next_newline, search_command)
888 (trivial_regexp_p, search_buffer, simple_search, boyer_moore)
889 (set_search_regs, wordify):
890 (Freplace_match):
891 (Fmatch_data):
892 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
893 (string_match_1, search_buffer, set_search_regs):
894 (Fmatch_data):
895 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
896 (wordify): Check for overflow in size calculation.
897 (Freplace_match): Avoid potential buffer overflow in search_regs.start.
898 (Fset_match_data): Don't assume fixnum fits in ptrdiff_t.
899 Check that fixnums are in proper range for system types.
900 * sound.c (struct sound_device)
901 (wav_play, au_play, vox_write, alsa_period_size, alsa_write):
902 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
903 (Fplay_sound_internal):
904 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
905 * syntax.c (struct lisp_parse_state, find_start_modiff)
906 (Finternal_describe_syntax_value, scan_lists, scan_sexps_forward):
907 (Fparse_partial_sexp):
908 Don't assume fixnums can fit in int.
909 (struct lisp_parse_state, find_start_pos, find_start_value)
910 (find_start_value_byte, find_start_begv)
911 (update_syntax_table, char_quoted, dec_bytepos)
912 (find_defun_start, prev_char_comend_first, back_comment):
913 (scan_words, skip_chars, skip_syntaxes, forw_comment, Fforward_comment)
914 (scan_lists, Fbackward_prefix_chars, scan_sexps_forward):
915 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
916 (Finternal_describe_syntax_value): Check that match_lisp is a
917 character, not an integer, since the code stuffs it into int.
918 (scan_words, scan_sexps_forward):
919 Check that fixnums are in proper range for system types.
920 (Fforward_word):
921 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
922 (scan_sexps_forward):
923 Use CHARACTERP, not INTEGERP, since the value must fit into int.
924 (Fparse_partial_sexp): Fix doc; element 8 is not ignored.
925 * syntax.h: Adjust decls to match defn changes elsewhere.
926 (struct gl_state_s):
927 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
928 (SETUP_SYNTAX_TABLE_FOR_OBJECT): Use PTRDIFF_MAX, not
929 MOST_POSITIVE_FIXNUM.
930 * sysdep.c (wait_for_termination_1, wait_for_termination)
931 (interruptible_wait_for_termination, mkdir):
932 Don't assume pid_t fits in int; on 64-bit AIX pid_t is 64-bit.
933 (emacs_read, emacs_write):
934 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
935 (system_process_attributes): Don't assume uid_t, gid_t, EMACS_INT,
936 and double all fit in int.
937 * term.c (set_tty_color_mode):
938 Check that fixnums are in proper range for system types.
939 * termhooks.h (struct input_event):
940 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
941 * textprop.c (validate_interval_range, interval_of)
942 (Fadd_text_properties, set_text_properties_1)
943 (Fremove_text_properties, Fremove_list_of_text_properties)
944 (Ftext_property_any, Ftext_property_not_all)
945 (copy_text_properties, text_property_list, extend_property_ranges)
946 (verify_interval_modification):
947 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
948 (Fnext_single_char_property_change)
949 (Fprevious_single_char_property_change):
950 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
951 (copy_text_properties):
952 Check for integer overflow in index calculation.
953 * undo.c (last_boundary_position, record_point, record_insert)
954 (record_delete, record_marker_adjustment, record_change)
955 (record_property_change):
956 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
957 (truncate_undo_list, Fprimitive_undo): Don't assume fixnum fits in int.
958 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
959 * w32fns.c (Fx_create_frame, x_create_tip_frame, Fx_show_tip)
960 (Fx_hide_tip, Fx_file_dialog):
961 * w32menu.c (set_frame_menubar):
962 Use ptrdiff_t, not int, for consistency with rest of code.
963 * window.c (window_scroll_preserve_hpos, window_scroll_preserve_vpos)
964 (select_window, Fdelete_other_windows_internal)
965 (window_scroll_pixel_based, window_scroll_line_based)
966 (Frecenter, Fset_window_configuration):
967 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
968 (Fset_window_hscroll, run_window_configuration_change_hook)
969 (set_window_buffer, temp_output_buffer_show, scroll_command)
970 (Fscroll_other_window, Frecenter):
971 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
972 (Fwindow_line_height, window_scroll, Fscroll_left, Fscroll_right):
973 Don't assume fixnum fits in int.
974 (Fset_window_scroll_bars):
975 Check that fixnums are in proper range for system types.
976 * xdisp.c (help_echo_pos, pos_visible_p, string_pos_nchars_ahead)
977 (string_pos, c_string_pos, number_of_chars, init_iterator)
978 (in_ellipses_for_invisible_text_p, init_from_display_pos)
979 (compute_stop_pos, next_overlay_change, compute_display_string_pos)
980 (compute_display_string_end, handle_face_prop)
981 (face_before_or_after_it_pos, handle_invisible_prop)
982 (handle_display_prop, handle_display_spec, handle_single_display_spec)
983 (display_prop_intangible_p, string_buffer_position_lim)
984 (string_buffer_position, handle_composition_prop, load_overlay_strings)
985 (get_overlay_strings_1, get_overlay_strings)
986 (iterate_out_of_display_property, forward_to_next_line_start)
987 (back_to_previous_visible_line_start, reseat, reseat_to_string)
988 (get_next_display_element, set_iterator_to_next)
989 (get_visually_first_element, compute_stop_pos_backwards)
990 (handle_stop_backwards, next_element_from_buffer)
991 (move_it_in_display_line_to, move_it_in_display_line)
992 (move_it_to, move_it_vertically_backward, move_it_by_lines)
993 (add_to_log, message_dolog, message_log_check_duplicate)
994 (message2, message2_nolog, message3, message3_nolog
995 (with_echo_area_buffer, display_echo_area_1, resize_mini_window_1)
996 (current_message_1, truncate_echo_area, truncate_message_1)
997 (set_message, set_message_1, store_mode_line_noprop)
998 (hscroll_window_tree, debug_delta, debug_delta_bytes, debug_end_vpos)
999 (text_outside_line_unchanged_p, check_point_in_composition)
1000 (reconsider_clip_changes)
1001 (redisplay_internal, set_cursor_from_row, try_scrolling)
1002 (try_cursor_movement, set_vertical_scroll_bar, redisplay_window)
1003 (redisplay_window, find_last_unchanged_at_beg_row)
1004 (find_first_unchanged_at_end_row, row_containing_pos, try_window_id)
1005 (trailing_whitespace_p, find_row_edges, display_line)
1006 (RECORD_MAX_MIN_POS, Fcurrent_bidi_paragraph_direction)
1007 (display_mode_element, store_mode_line_string)
1008 (pint2str, pint2hrstr, decode_mode_spec)
1009 (display_count_lines, display_string, draw_glyphs)
1010 (x_produce_glyphs, x_insert_glyphs)
1011 (rows_from_pos_range, mouse_face_from_buffer_pos)
1012 (fast_find_string_pos, mouse_face_from_string_pos)
1013 (note_mode_line_or_margin_highlight, note_mouse_highlight):
1014 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
1015 (safe_call, init_from_display_pos, handle_fontified_prop)
1016 (handle_single_display_spec, load_overlay_strings)
1017 (with_echo_area_buffer, setup_echo_area_for_printing)
1018 (display_echo_area, echo_area_display)
1019 (x_consider_frame_title, prepare_menu_bars, update_menu_bar)
1020 (update_tool_bar, hscroll_window_tree, redisplay_internal)
1021 (redisplay_window, dump_glyph_row, display_mode_line)
1022 (Fformat_mode_line, decode_mode_spec, on_hot_spot_p):
1023 (handle_display_spec, display_prop_string_p):
1024 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1025 (handle_single_display_spec, build_desired_tool_bar_string)
1026 (redisplay_tool_bar, scroll_window_tree, Fdump_glyph_matrix)
1027 (get_specified_cursor_type):
1028 Check that fixnums are in proper range for system types.
1029 (struct overlay_entry, resize_mini_window, Fdump_glyph_row)
1030 (Flookup_image_map):
1031 Don't assume fixnums fit in int.
1032 (compare_overlay_entries):
1033 Avoid mishandling comparisons due to subtraction overflow.
1034 (load_overlay_strings): Use SAFE_NALLOCA, not alloca.
1035 (last_escape_glyph_face_id, last_glyphless_glyph_face_id):
1036 (handle_tool_bar_click):
1037 Use int, not unsigned, since we prefer signed and the signedness
1038 doesn't matter here.
1039 (get_next_display_element, next_element_from_display_vector):
1040 Use int, not EMACS_INT, when int is wide enough.
1041 (start_hourglass): Use duration_to_sec_usec to do proper
1042 overflow checking on durations.
1043 * xfaces.c (Fbitmap_spec_p):
1044 Check that fixnums are in proper range for system types.
1045 (compare_fonts_by_sort_order):
1046 Avoid mishandling comparisons due to subtraction overflow.
1047 (Fx_family_fonts, realize_basic_faces):
1048 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1049 (Fx_family_fonts):
1050 Don't assume fixnum fits in int.
1051 Use SAFE_ALLOCA_LISP, not alloca.
1052 (merge_face_heights): Remove unnecessary cast to EMACS_INT.
1053 (Finternal_make_lisp_face): Don't allocate more than MAX_FACE_ID.
1054 (face_at_buffer_position, face_for_overlay_string)
1055 (face_at_string_position):
1056 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
1057 (merge_faces): Use int, not EMACS_INT, where int is wide enough.
1058 * xfns.c (x_set_menu_bar_lines, x_set_tool_bar_lines, x_icon_verify)
1059 (Fx_show_tip):
1060 Check that fixnums are in proper range for system types.
1061 (Fx_create_frame, x_create_tip_frame, Fx_show_tip)
1062 (Fx_hide_tip, Fx_file_dialog, Fx_select_font):
1063 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1064 (Fx_change_window_property): Don't assume fixnums fit in int.
1065 * xfont.c (xfont_chars_supported):
1066 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1067 * xmenu.c (Fx_popup_dialog, set_frame_menubar)
1068 (create_and_show_popup_menu, create_and_show_dialog, xmenu_show):
1069 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1070 * xml.c (parse_region):
1071 * xrdb.c (magic_file_p):
1072 Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough.
1073 * xselect.c (TRACE1): Don't assume pid_t promotes to int.
1074 (x_get_local_selection, x_reply_selection_request)
1075 (x_handle_selection_request, wait_for_property_change):
1076 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1077 (selection_data_to_lisp_data): Use short, not EMACS_INT, where
1078 short is wide enough.
1079 (x_send_client_event): Don't assume fixnum fits in int.
1080 * xterm.c (x_x_to_emacs_modifiers):
1081 Don't assume EMACS_INT overflows nicely into int.
1082 (x_emacs_to_x_modifiers): Use EMACS_INT, not int, because values
1083 may come from Lisp.
1084 (handle_one_xevent): NATNUMP can eval its arg twice.
1085 (x_connection_closed):
1086 Use ptrdiff_t, not int, to avoid needless 32-bit limit on 64-bit hosts.
1087 * xterm.h: Adjust decls to match defn changes elsewhere.
1088 (struct scroll_bar): Use struct vectorlike_header
1089 rather than rolling our own approximation.
1090 (SCROLL_BAR_VEC_SIZE): Remove; not used.
1091
10922012-05-25 Glenn Morris <rgm@gnu.org>
1093
1094 * lisp.mk (lisp): Update for more files being compiled now.
1095
10962012-05-25 Stefan Monnier <monnier@iro.umontreal.ca>
1097
1098 * lread.c: Remove `read_pure' which makes no difference.
1099 (read_pure): Remove var.
1100 (unreadpure): Remove function.
1101 (readevalloop): Don't call read_list with -1 flag.
1102 (read1, read_vector): Don't test read_pure any more.
1103 (read_list): Simplify.
1104
1105 * fileio.c, character.h: Minor style tweaks.
1106
11072012-05-24 Dmitry Antipov <dmantipov@yandex.ru>
1108
1109 * window.h (clip_changed): Remove useless declaration.
1110
11112012-05-22 Juanma Barranquero <lekktu@gmail.com>
1112
1113 * makefile.w32-in: Follow-up to 2012-05-22T16:20:27Z!eggert@cs.ucla.edu.
1114 (TAGS, TAGS-gmake, CONFIG_H): Remove further references to m/intel386.h.
1115
11162012-05-22 Paul Eggert <eggert@cs.ucla.edu>
1117
1118 Remove src/m/*.
1119 This directory predates autoconf and is no longer needed nowadays.
1120 Move its few remaining bits of functionality to where they're needed.
1121 * m/README, m/alpha.h, m/amdx86-64.h, m/ia64.h, m/ibmrs6000.h:
1122 * m/ibms390x.h, m/intel386.h, m/m68k.h, m/macppc.h, m/sparc.h:
1123 * m/template.h: Remove.
1124 * Makefile.in (M_FILE): Remove. All uses removed.
1125 * alloc.c (POINTERS_MIGHT_HIDE_IN_OBJECTS):
1126 * lisp.h (USE_LSB_TAG):
1127 * mem-limits.h (EXCEEDS_LISP_PTR):
1128 Use VAL_MAX, not VALBITS, in #if.
1129 * lisp.h (EMACS_INT_MAX): New macro, useful in #if.
1130 (EMACS_UINT): Define unconditionally now.
1131 (BITS_PER_CHAR, BITS_PER_SHORT, BITS_PER_INT, BITS_PER_LONG)
1132 (BITS_PER_EMACS_INT): New constants, replacing
1133 what used to be in config.h, but not useful in #if.
1134 (GCTYPEBITS, VALBITS): Define unconditionally, since m/* files don't
1135 define them any more.
1136 (VAL_MAX): New macro.
1137 (VALMASK): Use it.
1138 * puresize.h (PURESIZE_RATIO): Use EMACS_INT_MAX, not
1139 BITS_PER_EMACS_INT, in #if.
1140 * s/aix4-2.h (BROKEN_FIONREAD, BROKEN_SIGAIO, BROKEN_SIGPTY)
1141 (BROKEN_SIGPOLL): Move here from m/ibmrs6000.h, which was removed.
1142 * s/gnu-linux.h (ULIMIT_BREAK_VALUE) [__i386__]:
1143 * s/ms-w32.h (DATA_START):
1144 Move here from removed file m/intel386.h.
1145 * s/gnu.h (NLIST_STRUCT): Remove undef; 'configure' does this.
1146 * s/irix6-5.h (_LP64): Remove; lisp.h no longer needs this.
1147
11482012-05-21 Paul Eggert <eggert@cs.ucla.edu>
1149
1150 Assume C89 or later.
1151 * alloc.c, buffer.c, lisp.h: Replace POINTER_TYPE with void.
1152 * alloc.c (overrun_check_malloc, overrun_check_realloc, xmalloc)
1153 (xrealloc):
1154 * buffer.c (mmap_free_1, mmap_enlarge): Omit needless casts.
1155 * editfns.c, fns.c, gmalloc.c, insdel.c, sysdep.c, termcap.c (NULL):
1156 * textprop.c, tparam.c (NULL): Remove.
1157 * ralloc.c, vm-limit.c (POINTER): Assume void * works.
1158 * regex.c (SIGN_EXTEND_CHAR): Assume signed char works.
1159 * regex.h (_RE_ARGS): Remove. All uses rewritten to use prototypes.
1160 * unexelf.c (ElfBitsW): Assume c89 preprocessor or better.
1161 * xterm.c (input_signal_count): Assume volatile works.
1162
11632012-05-21 Ken Brown <kbrown@cornell.edu>
1164
1165 * xgselect.c (xg_select): Fix first argument in call to 'select'
1166 (bug#11508).
1167
11682012-05-20 Ken Brown <kbrown@cornell.edu>
1169
1170 * gmalloc.c (_free_internal_nolock, _realloc_internal_nolock)
1171 [CYGWIN]: Cast ptr to (char *) before comparing to _heapbase.
1172
11732012-05-19 Ken Brown <kbrown@cornell.edu>
1174
1175 * xfns.c (x_in_use): Remove `static' qualifier.
1176 * xterm.h (x_in_use): Declare.
1177 * xgselect.c: Include xterm.h.
1178 (xg_select): Test `x_in_use' instead of `inhibit_window_system'
1179 and `display_arg' (bug#9754).
1180
12012-05-19 Paul Eggert <eggert@cs.ucla.edu> 11812012-05-19 Paul Eggert <eggert@cs.ucla.edu>
2 1182
1183 * s/ms-w32.h (HAVE_GETDOMAINNAME): Remove; not needed.
1184
3 * m/vax.h: Remove; no longer needed since HAVE_FTIME is being removed. 1185 * m/vax.h: Remove; no longer needed since HAVE_FTIME is being removed.
4 * s/ms-w32.h (HAVE_FTIME): Remove; not needed. 1186 * s/ms-w32.h (HAVE_FTIME): Remove; not needed.
5 1187
@@ -68,8 +1250,8 @@
68 1250
69 * xdisp.c (handle_single_display_spec): Return 1 for left-margin 1251 * xdisp.c (handle_single_display_spec): Return 1 for left-margin
70 and right-margin display specs even if the spec is invalid or we 1252 and right-margin display specs even if the spec is invalid or we
71 are on a TTY, and thus unable to display on the fringes. That's 1253 are on a TTY, and thus unable to display on the fringes.
72 because the text with the property will not be displayed anyway, 1254 That's because the text with the property will not be displayed anyway,
73 so we need to signal to the caller that this is a "replacing" 1255 so we need to signal to the caller that this is a "replacing"
74 display spec. This fixes display when the spec is invalid or we 1256 display spec. This fixes display when the spec is invalid or we
75 are on a TTY. 1257 are on a TTY.
@@ -363,7 +1545,7 @@
3632012-04-22 Paul Eggert <eggert@cs.ucla.edu> 15452012-04-22 Paul Eggert <eggert@cs.ucla.edu>
364 1546
365 Modernize and clean up gmalloc.c to assume C89 (Bug#9119). 1547 Modernize and clean up gmalloc.c to assume C89 (Bug#9119).
366 * gmalloc.c: (_MALLOC_INTERNAL, _MALLOC_H, _PP, __ptr_t) 1548 * gmalloc.c (_MALLOC_INTERNAL, _MALLOC_H, _PP, __ptr_t)
367 (__malloc_size_t, __malloc_ptrdiff_t): 1549 (__malloc_size_t, __malloc_ptrdiff_t):
368 Remove. All uses removed, replaced by the definiens if needed, 1550 Remove. All uses removed, replaced by the definiens if needed,
369 since we can assume C89 or better now. 1551 since we can assume C89 or better now.
diff --git a/src/Makefile.in b/src/Makefile.in
index dd667ea60a3..47c7d5cfbc2 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -56,9 +56,8 @@ lwlibdir = ../lwlib
56lispdir = ../lisp 56lispdir = ../lisp
57 57
58# Configuration files for .o files to depend on. 58# Configuration files for .o files to depend on.
59M_FILE = @M_FILE@
60S_FILE = @S_FILE@ 59S_FILE = @S_FILE@
61config_h = config.h $(M_FILE) $(S_FILE) 60config_h = config.h $(S_FILE)
62 61
63bootstrap_exe = $(abs_builddir)/bootstrap-emacs$(EXEEXT) 62bootstrap_exe = $(abs_builddir)/bootstrap-emacs$(EXEEXT)
64 63
@@ -114,6 +113,12 @@ TEMACS_LDFLAGS = $(LD_SWITCH_SYSTEM) $(LD_SWITCH_SYSTEM_TEMACS)
114## $LDFLAGS or empty if NS_IMPL_GNUSTEP (for some reason). 113## $LDFLAGS or empty if NS_IMPL_GNUSTEP (for some reason).
115TEMACS_LDFLAGS2 = @TEMACS_LDFLAGS2@ 114TEMACS_LDFLAGS2 = @TEMACS_LDFLAGS2@
116 115
116## If available, the full path to the paxctl program.
117## On grsecurity/PaX systems, unexec will fail due to a gap between
118## the bss section and the heap. This can be prevented by disabling
119## memory randomization in temacs with "paxctl -r". See bug#11398.
120PAXCTL = @PAXCTL@
121
117## Some systems define this to request special libraries. 122## Some systems define this to request special libraries.
118LIBS_SYSTEM=@LIBS_SYSTEM@ 123LIBS_SYSTEM=@LIBS_SYSTEM@
119 124
@@ -404,6 +409,7 @@ emacs$(EXEEXT): temacs$(EXEEXT) $(etc)/DOC $(lisp) $(leimdir)/leim-list.el
404 -f list-load-path-shadows || true; \ 409 -f list-load-path-shadows || true; \
405 else \ 410 else \
406 LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump || exit 1; \ 411 LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump || exit 1; \
412 test "X$(PAXCTL)" = X || $(PAXCTL) -zex emacs$(EXEEXT); \
407 ln -f emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \ 413 ln -f emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \
408 ./emacs -batch -f list-load-path-shadows || true; \ 414 ./emacs -batch -f list-load-path-shadows || true; \
409 fi 415 fi
@@ -451,6 +457,8 @@ $(lib)/libgnu.a: $(config_h)
451temacs$(EXEEXT): $(START_FILES) stamp-oldxmenu $(obj) $(otherobj) $(lib)/libgnu.a 457temacs$(EXEEXT): $(START_FILES) stamp-oldxmenu $(obj) $(otherobj) $(lib)/libgnu.a
452 $(CC) $(LD_FIRSTFLAG) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(TEMACS_LDFLAGS2) \ 458 $(CC) $(LD_FIRSTFLAG) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(TEMACS_LDFLAGS2) \
453 -o temacs $(START_FILES) $(obj) $(otherobj) $(lib)/libgnu.a $(LIBES) 459 -o temacs $(START_FILES) $(obj) $(otherobj) $(lib)/libgnu.a $(LIBES)
460 test "$(CANNOT_DUMP)" = "yes" || \
461 test "X$(PAXCTL)" = X || $(PAXCTL) -r temacs$(EXEEXT)
454 462
455## The following oldxmenu-related rules are only (possibly) used if 463## The following oldxmenu-related rules are only (possibly) used if
456## HAVE_X11 && !USE_GTK, but there is no harm in always defining them 464## HAVE_X11 && !USE_GTK, but there is no harm in always defining them
@@ -534,10 +542,10 @@ extraclean: distclean
534ctagsfiles1 = [xyzXYZ]*.[hcm] 542ctagsfiles1 = [xyzXYZ]*.[hcm]
535ctagsfiles2 = [a-wA-W]*.[hcm] 543ctagsfiles2 = [a-wA-W]*.[hcm]
536 544
537TAGS: $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) $(M_FILE) $(S_FILE) 545TAGS: $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) $(S_FILE)
538 ../lib-src/etags --include=TAGS-LISP --include=$(lwlibdir)/TAGS \ 546 ../lib-src/etags --include=TAGS-LISP --include=$(lwlibdir)/TAGS \
539 --regex='/[ ]*DEFVAR_[A-Z_ (]+"\([^"]+\)"/' \ 547 --regex='/[ ]*DEFVAR_[A-Z_ (]+"\([^"]+\)"/' \
540 $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) $(M_FILE) $(S_FILE) 548 $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) $(S_FILE)
541frc: 549frc:
542TAGS-LISP: frc 550TAGS-LISP: frc
543 $(MAKE) -f $(lispdir)/Makefile TAGS-LISP ETAGS=../lib-src/etags 551 $(MAKE) -f $(lispdir)/Makefile TAGS-LISP ETAGS=../lib-src/etags
@@ -598,6 +606,7 @@ bootstrap-emacs$(EXEEXT): temacs$(EXEEXT)
598 ln -f temacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \ 606 ln -f temacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \
599 else \ 607 else \
600 $(RUN_TEMACS) --batch --load loadup bootstrap || exit 1; \ 608 $(RUN_TEMACS) --batch --load loadup bootstrap || exit 1; \
609 test "X$(PAXCTL)" = X || $(PAXCTL) -zex emacs$(EXEEXT); \
601 mv -f emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \ 610 mv -f emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \
602 fi 611 fi
603 @: Compile some files earlier to speed up further compilation. 612 @: Compile some files earlier to speed up further compilation.
diff --git a/src/alloc.c b/src/alloc.c
index a120ce9b61f..7c461c5a6af 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -66,7 +66,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
66 66
67#include <unistd.h> 67#include <unistd.h>
68#ifndef HAVE_UNISTD_H 68#ifndef HAVE_UNISTD_H
69extern POINTER_TYPE *sbrk (); 69extern void *sbrk ();
70#endif 70#endif
71 71
72#include <fcntl.h> 72#include <fcntl.h>
@@ -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
@@ -306,7 +307,7 @@ enum mem_type
306 MEM_TYPE_VECTORLIKE 307 MEM_TYPE_VECTORLIKE
307}; 308};
308 309
309static POINTER_TYPE *lisp_malloc (size_t, enum mem_type); 310static void *lisp_malloc (size_t, enum mem_type);
310 311
311 312
312#if GC_MARK_STACK || defined GC_MALLOC_CHECK 313#if GC_MARK_STACK || defined GC_MALLOC_CHECK
@@ -387,8 +388,8 @@ 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 (POINTER_TYPE *); 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 *);
394static int live_buffer_p (struct mem_node *, void *); 395static int live_buffer_p (struct mem_node *, void *);
@@ -435,15 +436,15 @@ static Lisp_Object *staticvec[NSTATICS] = {&Vpurify_flag};
435 436
436static int staticidx = 0; 437static int staticidx = 0;
437 438
438static POINTER_TYPE *pure_alloc (size_t, int); 439static void *pure_alloc (size_t, int);
439 440
440 441
441/* Value is SZ rounded up to the next multiple of ALIGNMENT. 442/* Value is SZ rounded up to the next multiple of ALIGNMENT.
442 ALIGNMENT must be a power of 2. */ 443 ALIGNMENT must be a power of 2. */
443 444
444#define ALIGN(ptr, ALIGNMENT) \ 445#define ALIGN(ptr, ALIGNMENT) \
445 ((POINTER_TYPE *) ((((uintptr_t) (ptr)) + (ALIGNMENT) - 1) \ 446 ((void *) (((uintptr_t) (ptr) + (ALIGNMENT) - 1) \
446 & ~((ALIGNMENT) - 1))) 447 & ~ ((ALIGNMENT) - 1)))
447 448
448 449
449 450
@@ -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
@@ -604,7 +605,7 @@ static ptrdiff_t check_depth;
604 605
605/* Like malloc, but wraps allocated block with header and trailer. */ 606/* Like malloc, but wraps allocated block with header and trailer. */
606 607
607static POINTER_TYPE * 608static void *
608overrun_check_malloc (size_t size) 609overrun_check_malloc (size_t size)
609{ 610{
610 register unsigned char *val; 611 register unsigned char *val;
@@ -622,15 +623,15 @@ overrun_check_malloc (size_t size)
622 XMALLOC_OVERRUN_CHECK_SIZE); 623 XMALLOC_OVERRUN_CHECK_SIZE);
623 } 624 }
624 --check_depth; 625 --check_depth;
625 return (POINTER_TYPE *)val; 626 return val;
626} 627}
627 628
628 629
629/* Like realloc, but checks old block for overrun, and wraps new block 630/* Like realloc, but checks old block for overrun, and wraps new block
630 with header and trailer. */ 631 with header and trailer. */
631 632
632static POINTER_TYPE * 633static void *
633overrun_check_realloc (POINTER_TYPE *block, size_t size) 634overrun_check_realloc (void *block, size_t size)
634{ 635{
635 register unsigned char *val = (unsigned char *) block; 636 register unsigned char *val = (unsigned char *) block;
636 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; 637 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0;
@@ -652,7 +653,7 @@ overrun_check_realloc (POINTER_TYPE *block, size_t size)
652 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE); 653 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE);
653 } 654 }
654 655
655 val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); 656 val = realloc (val, size + overhead);
656 657
657 if (val && check_depth == 1) 658 if (val && check_depth == 1)
658 { 659 {
@@ -663,13 +664,13 @@ overrun_check_realloc (POINTER_TYPE *block, size_t size)
663 XMALLOC_OVERRUN_CHECK_SIZE); 664 XMALLOC_OVERRUN_CHECK_SIZE);
664 } 665 }
665 --check_depth; 666 --check_depth;
666 return (POINTER_TYPE *)val; 667 return val;
667} 668}
668 669
669/* Like free, but checks block for overrun. */ 670/* Like free, but checks block for overrun. */
670 671
671static void 672static void
672overrun_check_free (POINTER_TYPE *block) 673overrun_check_free (void *block)
673{ 674{
674 unsigned char *val = (unsigned char *) block; 675 unsigned char *val = (unsigned char *) block;
675 676
@@ -718,13 +719,13 @@ overrun_check_free (POINTER_TYPE *block)
718 719
719/* Like malloc but check for no memory and block interrupt input.. */ 720/* Like malloc but check for no memory and block interrupt input.. */
720 721
721POINTER_TYPE * 722void *
722xmalloc (size_t size) 723xmalloc (size_t size)
723{ 724{
724 register POINTER_TYPE *val; 725 void *val;
725 726
726 MALLOC_BLOCK_INPUT; 727 MALLOC_BLOCK_INPUT;
727 val = (POINTER_TYPE *) malloc (size); 728 val = malloc (size);
728 MALLOC_UNBLOCK_INPUT; 729 MALLOC_UNBLOCK_INPUT;
729 730
730 if (!val && size) 731 if (!val && size)
@@ -735,18 +736,18 @@ xmalloc (size_t size)
735 736
736/* Like realloc but check for no memory and block interrupt input.. */ 737/* Like realloc but check for no memory and block interrupt input.. */
737 738
738POINTER_TYPE * 739void *
739xrealloc (POINTER_TYPE *block, size_t size) 740xrealloc (void *block, size_t size)
740{ 741{
741 register POINTER_TYPE *val; 742 void *val;
742 743
743 MALLOC_BLOCK_INPUT; 744 MALLOC_BLOCK_INPUT;
744 /* We must call malloc explicitly when BLOCK is 0, since some 745 /* We must call malloc explicitly when BLOCK is 0, since some
745 reallocs don't do this. */ 746 reallocs don't do this. */
746 if (! block) 747 if (! block)
747 val = (POINTER_TYPE *) malloc (size); 748 val = malloc (size);
748 else 749 else
749 val = (POINTER_TYPE *) realloc (block, size); 750 val = realloc (block, size);
750 MALLOC_UNBLOCK_INPUT; 751 MALLOC_UNBLOCK_INPUT;
751 752
752 if (!val && size) 753 if (!val && size)
@@ -758,7 +759,7 @@ xrealloc (POINTER_TYPE *block, size_t size)
758/* Like free but block interrupt input. */ 759/* Like free but block interrupt input. */
759 760
760void 761void
761xfree (POINTER_TYPE *block) 762xfree (void *block)
762{ 763{
763 if (!block) 764 if (!block)
764 return; 765 return;
@@ -893,7 +894,7 @@ safe_alloca_unwind (Lisp_Object arg)
893static void *lisp_malloc_loser; 894static void *lisp_malloc_loser;
894#endif 895#endif
895 896
896static POINTER_TYPE * 897static void *
897lisp_malloc (size_t nbytes, enum mem_type type) 898lisp_malloc (size_t nbytes, enum mem_type type)
898{ 899{
899 register void *val; 900 register void *val;
@@ -938,7 +939,7 @@ lisp_malloc (size_t nbytes, enum mem_type type)
938 call to lisp_malloc. */ 939 call to lisp_malloc. */
939 940
940static void 941static void
941lisp_free (POINTER_TYPE *block) 942lisp_free (void *block)
942{ 943{
943 MALLOC_BLOCK_INPUT; 944 MALLOC_BLOCK_INPUT;
944 free (block); 945 free (block);
@@ -1034,7 +1035,7 @@ static struct ablock *free_ablock;
1034/* Allocate an aligned block of nbytes. 1035/* Allocate an aligned block of nbytes.
1035 Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be 1036 Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be
1036 smaller or equal to BLOCK_BYTES. */ 1037 smaller or equal to BLOCK_BYTES. */
1037static POINTER_TYPE * 1038static void *
1038lisp_align_malloc (size_t nbytes, enum mem_type type) 1039lisp_align_malloc (size_t nbytes, enum mem_type type)
1039{ 1040{
1040 void *base, *val; 1041 void *base, *val;
@@ -1141,7 +1142,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
1141} 1142}
1142 1143
1143static void 1144static void
1144lisp_align_free (POINTER_TYPE *block) 1145lisp_align_free (void *block)
1145{ 1146{
1146 struct ablock *ablock = block; 1147 struct ablock *ablock = block;
1147 struct ablocks *abase = ABLOCK_ABASE (ablock); 1148 struct ablocks *abase = ABLOCK_ABASE (ablock);
@@ -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
@@ -2699,8 +2701,10 @@ make_float (double float_value)
2699 GC are put on a free list to be reallocated before allocating 2701 GC are put on a free list to be reallocated before allocating
2700 any new cons cells from the latest cons_block. */ 2702 any new cons cells from the latest cons_block. */
2701 2703
2702#define CONS_BLOCK_SIZE \ 2704#define CONS_BLOCK_SIZE \
2703 (((BLOCK_BYTES - sizeof (struct cons_block *)) * CHAR_BIT) \ 2705 (((BLOCK_BYTES - sizeof (struct cons_block *) \
2706 /* The compiler might add padding at the end. */ \
2707 - (sizeof (struct Lisp_Cons) - sizeof (int))) * CHAR_BIT) \
2704 / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1)) 2708 / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1))
2705 2709
2706#define CONS_BLOCK(fptr) \ 2710#define CONS_BLOCK(fptr) \
@@ -2939,7 +2943,7 @@ enum
2939 with room for LEN Lisp_Objects. */ 2943 with room for LEN Lisp_Objects. */
2940 2944
2941static struct Lisp_Vector * 2945static struct Lisp_Vector *
2942allocate_vectorlike (EMACS_INT len) 2946allocate_vectorlike (ptrdiff_t len)
2943{ 2947{
2944 struct Lisp_Vector *p; 2948 struct Lisp_Vector *p;
2945 size_t nbytes; 2949 size_t nbytes;
@@ -2995,7 +2999,7 @@ allocate_vector (EMACS_INT len)
2995/* Allocate other vector-like structures. */ 2999/* Allocate other vector-like structures. */
2996 3000
2997struct Lisp_Vector * 3001struct Lisp_Vector *
2998allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag) 3002allocate_pseudovector (int memlen, int lisplen, int tag)
2999{ 3003{
3000 struct Lisp_Vector *v = allocate_vectorlike (memlen); 3004 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3001 int i; 3005 int i;
@@ -3059,14 +3063,14 @@ See also the function `vector'. */)
3059 (register Lisp_Object length, Lisp_Object init) 3063 (register Lisp_Object length, Lisp_Object init)
3060{ 3064{
3061 Lisp_Object vector; 3065 Lisp_Object vector;
3062 register EMACS_INT sizei; 3066 register ptrdiff_t sizei;
3063 register EMACS_INT i; 3067 register ptrdiff_t i;
3064 register struct Lisp_Vector *p; 3068 register struct Lisp_Vector *p;
3065 3069
3066 CHECK_NATNUM (length); 3070 CHECK_NATNUM (length);
3067 sizei = XFASTINT (length);
3068 3071
3069 p = allocate_vector (sizei); 3072 p = allocate_vector (XFASTINT (length));
3073 sizei = XFASTINT (length);
3070 for (i = 0; i < sizei; i++) 3074 for (i = 0; i < sizei; i++)
3071 p->contents[i] = init; 3075 p->contents[i] = init;
3072 3076
@@ -4297,8 +4301,8 @@ mark_maybe_pointer (void *p)
4297 wider than a pointer might allocate a Lisp_Object in non-adjacent halves. 4301 wider than a pointer might allocate a Lisp_Object in non-adjacent halves.
4298 If USE_LSB_TAG, the bottom half is not a valid pointer, but it should 4302 If USE_LSB_TAG, the bottom half is not a valid pointer, but it should
4299 suffice to widen it to to a Lisp_Object and check it that way. */ 4303 suffice to widen it to to a Lisp_Object and check it that way. */
4300#if defined USE_LSB_TAG || UINTPTR_MAX >> VALBITS != 0 4304#if defined USE_LSB_TAG || VAL_MAX < UINTPTR_MAX
4301# if !defined USE_LSB_TAG && UINTPTR_MAX >> VALBITS >> GCTYPEBITS != 0 4305# if !defined USE_LSB_TAG && VAL_MAX < UINTPTR_MAX >> GCTYPEBITS
4302 /* If tag bits straddle pointer-word boundaries, neither mark_maybe_pointer 4306 /* If tag bits straddle pointer-word boundaries, neither mark_maybe_pointer
4303 nor mark_maybe_object can follow the pointers. This should not occur on 4307 nor mark_maybe_object can follow the pointers. This should not occur on
4304 any practical porting target. */ 4308 any practical porting target. */
@@ -4722,10 +4726,10 @@ valid_lisp_object_p (Lisp_Object obj)
4722 pointer to it. TYPE is the Lisp type for which the memory is 4726 pointer to it. TYPE is the Lisp type for which the memory is
4723 allocated. TYPE < 0 means it's not used for a Lisp object. */ 4727 allocated. TYPE < 0 means it's not used for a Lisp object. */
4724 4728
4725static POINTER_TYPE * 4729static void *
4726pure_alloc (size_t size, int type) 4730pure_alloc (size_t size, int type)
4727{ 4731{
4728 POINTER_TYPE *result; 4732 void *result;
4729#ifdef USE_LSB_TAG 4733#ifdef USE_LSB_TAG
4730 size_t alignment = (1 << GCTYPEBITS); 4734 size_t alignment = (1 << GCTYPEBITS);
4731#else 4735#else
@@ -4791,14 +4795,14 @@ check_pure_size (void)
4791 address. Return NULL if not found. */ 4795 address. Return NULL if not found. */
4792 4796
4793static char * 4797static char *
4794find_string_data_in_pure (const char *data, EMACS_INT nbytes) 4798find_string_data_in_pure (const char *data, ptrdiff_t nbytes)
4795{ 4799{
4796 int i; 4800 int i;
4797 EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4801 ptrdiff_t skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4798 const unsigned char *p; 4802 const unsigned char *p;
4799 char *non_lisp_beg; 4803 char *non_lisp_beg;
4800 4804
4801 if (pure_bytes_used_non_lisp < nbytes + 1) 4805 if (pure_bytes_used_non_lisp <= nbytes)
4802 return NULL; 4806 return NULL;
4803 4807
4804 /* Set up the Boyer-Moore table. */ 4808 /* Set up the Boyer-Moore table. */
@@ -4862,7 +4866,7 @@ find_string_data_in_pure (const char *data, EMACS_INT nbytes)
4862 4866
4863Lisp_Object 4867Lisp_Object
4864make_pure_string (const char *data, 4868make_pure_string (const char *data,
4865 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 4869 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
4866{ 4870{
4867 Lisp_Object string; 4871 Lisp_Object string;
4868 struct Lisp_String *s; 4872 struct Lisp_String *s;
@@ -4890,7 +4894,7 @@ make_pure_c_string (const char *data)
4890{ 4894{
4891 Lisp_Object string; 4895 Lisp_Object string;
4892 struct Lisp_String *s; 4896 struct Lisp_String *s;
4893 EMACS_INT nchars = strlen (data); 4897 ptrdiff_t nchars = strlen (data);
4894 4898
4895 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4899 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4896 s->size = nchars; 4900 s->size = nchars;
@@ -4936,8 +4940,8 @@ make_pure_float (double num)
4936/* Return a vector with room for LEN Lisp_Objects allocated from 4940/* Return a vector with room for LEN Lisp_Objects allocated from
4937 pure space. */ 4941 pure space. */
4938 4942
4939Lisp_Object 4943static Lisp_Object
4940make_pure_vector (EMACS_INT len) 4944make_pure_vector (ptrdiff_t len)
4941{ 4945{
4942 Lisp_Object new; 4946 Lisp_Object new;
4943 struct Lisp_Vector *p; 4947 struct Lisp_Vector *p;
@@ -4981,8 +4985,8 @@ Does not copy symbols. Copies strings without text properties. */)
4981 else if (COMPILEDP (obj) || VECTORP (obj)) 4985 else if (COMPILEDP (obj) || VECTORP (obj))
4982 { 4986 {
4983 register struct Lisp_Vector *vec; 4987 register struct Lisp_Vector *vec;
4984 register EMACS_INT i; 4988 register ptrdiff_t i;
4985 EMACS_INT size; 4989 ptrdiff_t size;
4986 4990
4987 size = ASIZE (obj); 4991 size = ASIZE (obj);
4988 if (size & PSEUDOVECTOR_FLAG) 4992 if (size & PSEUDOVECTOR_FLAG)
@@ -5034,10 +5038,10 @@ staticpro (Lisp_Object *varaddress)
5034 5038
5035/* Temporarily prevent garbage collection. */ 5039/* Temporarily prevent garbage collection. */
5036 5040
5037int 5041ptrdiff_t
5038inhibit_garbage_collection (void) 5042inhibit_garbage_collection (void)
5039{ 5043{
5040 int count = SPECPDL_INDEX (); 5044 ptrdiff_t count = SPECPDL_INDEX ();
5041 5045
5042 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM)); 5046 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM));
5043 return count; 5047 return count;
@@ -5063,7 +5067,7 @@ See Info node `(elisp)Garbage Collection'. */)
5063 ptrdiff_t i; 5067 ptrdiff_t i;
5064 int message_p; 5068 int message_p;
5065 Lisp_Object total[8]; 5069 Lisp_Object total[8];
5066 int count = SPECPDL_INDEX (); 5070 ptrdiff_t count = SPECPDL_INDEX ();
5067 EMACS_TIME t1, t2, t3; 5071 EMACS_TIME t1, t2, t3;
5068 5072
5069 if (abort_on_gc) 5073 if (abort_on_gc)
@@ -5358,7 +5362,7 @@ See Info node `(elisp)Garbage Collection'. */)
5358 5362
5359 if (!NILP (Vpost_gc_hook)) 5363 if (!NILP (Vpost_gc_hook))
5360 { 5364 {
5361 int gc_count = inhibit_garbage_collection (); 5365 ptrdiff_t gc_count = inhibit_garbage_collection ();
5362 safe_run_hooks (Qpost_gc_hook); 5366 safe_run_hooks (Qpost_gc_hook);
5363 unbind_to (gc_count, Qnil); 5367 unbind_to (gc_count, Qnil);
5364 } 5368 }
@@ -5443,8 +5447,8 @@ ptrdiff_t mark_object_loop_halt EXTERNALLY_VISIBLE;
5443static void 5447static void
5444mark_vectorlike (struct Lisp_Vector *ptr) 5448mark_vectorlike (struct Lisp_Vector *ptr)
5445{ 5449{
5446 EMACS_INT size = ptr->header.size; 5450 ptrdiff_t size = ptr->header.size;
5447 EMACS_INT i; 5451 ptrdiff_t i;
5448 5452
5449 eassert (!VECTOR_MARKED_P (ptr)); 5453 eassert (!VECTOR_MARKED_P (ptr));
5450 VECTOR_MARK (ptr); /* Else mark it */ 5454 VECTOR_MARK (ptr); /* Else mark it */
@@ -6325,7 +6329,7 @@ Lisp_Object
6325which_symbols (Lisp_Object obj, EMACS_INT find_max) 6329which_symbols (Lisp_Object obj, EMACS_INT find_max)
6326{ 6330{
6327 struct symbol_block *sblk; 6331 struct symbol_block *sblk;
6328 int gc_count = inhibit_garbage_collection (); 6332 ptrdiff_t gc_count = inhibit_garbage_collection ();
6329 Lisp_Object found = Qnil; 6333 Lisp_Object found = Qnil;
6330 6334
6331 if (! DEADP (obj)) 6335 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 2ddbc699481..386d9a78153 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))
@@ -933,6 +933,21 @@ If VARIABLE does not have a buffer-local binding in BUFFER, the value
933is the default binding of the variable. */) 933is the default binding of the variable. */)
934 (register Lisp_Object variable, register Lisp_Object buffer) 934 (register Lisp_Object variable, register Lisp_Object buffer)
935{ 935{
936 register Lisp_Object result = buffer_local_value_1 (variable, buffer);
937
938 if (EQ (result, Qunbound))
939 xsignal1 (Qvoid_variable, variable);
940
941 return result;
942}
943
944
945/* Like Fbuffer_local_value, but return Qunbound if the variable is
946 locally unbound. */
947
948Lisp_Object
949buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer)
950{
936 register struct buffer *buf; 951 register struct buffer *buf;
937 register Lisp_Object result; 952 register Lisp_Object result;
938 struct Lisp_Symbol *sym; 953 struct Lisp_Symbol *sym;
@@ -985,10 +1000,7 @@ is the default binding of the variable. */)
985 default: abort (); 1000 default: abort ();
986 } 1001 }
987 1002
988 if (!EQ (result, Qunbound)) 1003 return result;
989 return result;
990
991 xsignal1 (Qvoid_variable, variable);
992} 1004}
993 1005
994/* Return an alist of the Lisp-level buffer-local bindings of 1006/* Return an alist of the Lisp-level buffer-local bindings of
@@ -1475,7 +1487,7 @@ with SIGHUP. */)
1475 1487
1476 /* Run hooks with the buffer to be killed the current buffer. */ 1488 /* Run hooks with the buffer to be killed the current buffer. */
1477 { 1489 {
1478 int count = SPECPDL_INDEX (); 1490 ptrdiff_t count = SPECPDL_INDEX ();
1479 Lisp_Object arglist[1]; 1491 Lisp_Object arglist[1];
1480 1492
1481 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1493 record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -1751,7 +1763,7 @@ Use this function before selecting the buffer, since it may need to inspect
1751the current buffer's major mode. */) 1763the current buffer's major mode. */)
1752 (Lisp_Object buffer) 1764 (Lisp_Object buffer)
1753{ 1765{
1754 int count; 1766 ptrdiff_t count;
1755 Lisp_Object function; 1767 Lisp_Object function;
1756 1768
1757 CHECK_BUFFER (buffer); 1769 CHECK_BUFFER (buffer);
@@ -1963,16 +1975,15 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1963 tem = *b; *b = *e; *e = tem; 1975 tem = *b; *b = *e; *e = tem;
1964 } 1976 }
1965 1977
1966 if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e) 1978 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
1967 && XINT (*e) <= ZV))
1968 args_out_of_range (*b, *e); 1979 args_out_of_range (*b, *e);
1969} 1980}
1970 1981
1971/* Advance BYTE_POS up to a character boundary 1982/* Advance BYTE_POS up to a character boundary
1972 and return the adjusted position. */ 1983 and return the adjusted position. */
1973 1984
1974static EMACS_INT 1985static ptrdiff_t
1975advance_to_char_boundary (EMACS_INT byte_pos) 1986advance_to_char_boundary (ptrdiff_t byte_pos)
1976{ 1987{
1977 int c; 1988 int c;
1978 1989
@@ -1985,7 +1996,7 @@ advance_to_char_boundary (EMACS_INT byte_pos)
1985 { 1996 {
1986 /* We should advance BYTE_POS only when C is a constituent of a 1997 /* We should advance BYTE_POS only when C is a constituent of a
1987 multibyte sequence. */ 1998 multibyte sequence. */
1988 EMACS_INT orig_byte_pos = byte_pos; 1999 ptrdiff_t orig_byte_pos = byte_pos;
1989 2000
1990 do 2001 do
1991 { 2002 {
@@ -2051,18 +2062,18 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2051 eassert (current_buffer->text == &current_buffer->own_text); 2062 eassert (current_buffer->text == &current_buffer->own_text);
2052 eassert (other_buffer->text == &other_buffer->own_text); 2063 eassert (other_buffer->text == &other_buffer->own_text);
2053#ifdef REL_ALLOC 2064#ifdef REL_ALLOC
2054 r_alloc_reset_variable ((POINTER_TYPE **) &current_buffer->own_text.beg, 2065 r_alloc_reset_variable ((void **) &current_buffer->own_text.beg,
2055 (POINTER_TYPE **) &other_buffer->own_text.beg); 2066 (void **) &other_buffer->own_text.beg);
2056 r_alloc_reset_variable ((POINTER_TYPE **) &other_buffer->own_text.beg, 2067 r_alloc_reset_variable ((void **) &other_buffer->own_text.beg,
2057 (POINTER_TYPE **) &current_buffer->own_text.beg); 2068 (void **) &current_buffer->own_text.beg);
2058#endif /* REL_ALLOC */ 2069#endif /* REL_ALLOC */
2059 2070
2060 swapfield (pt, EMACS_INT); 2071 swapfield (pt, ptrdiff_t);
2061 swapfield (pt_byte, EMACS_INT); 2072 swapfield (pt_byte, ptrdiff_t);
2062 swapfield (begv, EMACS_INT); 2073 swapfield (begv, ptrdiff_t);
2063 swapfield (begv_byte, EMACS_INT); 2074 swapfield (begv_byte, ptrdiff_t);
2064 swapfield (zv, EMACS_INT); 2075 swapfield (zv, ptrdiff_t);
2065 swapfield (zv_byte, EMACS_INT); 2076 swapfield (zv_byte, ptrdiff_t);
2066 eassert (!current_buffer->base_buffer); 2077 eassert (!current_buffer->base_buffer);
2067 eassert (!other_buffer->base_buffer); 2078 eassert (!other_buffer->base_buffer);
2068 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2079 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
@@ -2072,7 +2083,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2072 other_buffer->prevent_redisplay_optimizations_p = 1; 2083 other_buffer->prevent_redisplay_optimizations_p = 1;
2073 swapfield (overlays_before, struct Lisp_Overlay *); 2084 swapfield (overlays_before, struct Lisp_Overlay *);
2074 swapfield (overlays_after, struct Lisp_Overlay *); 2085 swapfield (overlays_after, struct Lisp_Overlay *);
2075 swapfield (overlay_center, EMACS_INT); 2086 swapfield (overlay_center, ptrdiff_t);
2076 swapfield_ (undo_list, Lisp_Object); 2087 swapfield_ (undo_list, Lisp_Object);
2077 swapfield_ (mark, Lisp_Object); 2088 swapfield_ (mark, Lisp_Object);
2078 swapfield_ (enable_multibyte_characters, Lisp_Object); 2089 swapfield_ (enable_multibyte_characters, Lisp_Object);
@@ -2155,7 +2166,7 @@ current buffer is cleared. */)
2155{ 2166{
2156 struct Lisp_Marker *tail, *markers; 2167 struct Lisp_Marker *tail, *markers;
2157 struct buffer *other; 2168 struct buffer *other;
2158 EMACS_INT begv, zv; 2169 ptrdiff_t begv, zv;
2159 int narrowed = (BEG != BEGV || Z != ZV); 2170 int narrowed = (BEG != BEGV || Z != ZV);
2160 int modified_p = !NILP (Fbuffer_modified_p (Qnil)); 2171 int modified_p = !NILP (Fbuffer_modified_p (Qnil));
2161 Lisp_Object old_undo = BVAR (current_buffer, undo_list); 2172 Lisp_Object old_undo = BVAR (current_buffer, undo_list);
@@ -2187,7 +2198,7 @@ current buffer is cleared. */)
2187 2198
2188 if (NILP (flag)) 2199 if (NILP (flag))
2189 { 2200 {
2190 EMACS_INT pos, stop; 2201 ptrdiff_t pos, stop;
2191 unsigned char *p; 2202 unsigned char *p;
2192 2203
2193 /* Do this first, so it can use CHAR_TO_BYTE 2204 /* Do this first, so it can use CHAR_TO_BYTE
@@ -2251,8 +2262,8 @@ current buffer is cleared. */)
2251 } 2262 }
2252 else 2263 else
2253 { 2264 {
2254 EMACS_INT pt = PT; 2265 ptrdiff_t pt = PT;
2255 EMACS_INT pos, stop; 2266 ptrdiff_t pos, stop;
2256 unsigned char *p, *pend; 2267 unsigned char *p, *pend;
2257 2268
2258 /* Be sure not to have a multibyte sequence striding over the GAP. 2269 /* Be sure not to have a multibyte sequence striding over the GAP.
@@ -2268,7 +2279,7 @@ current buffer is cleared. */)
2268 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--; 2279 while (! CHAR_HEAD_P (*q) && q > BEG_ADDR) q--;
2269 if (LEADING_CODE_P (*q)) 2280 if (LEADING_CODE_P (*q))
2270 { 2281 {
2271 EMACS_INT new_gpt = GPT_BYTE - (GPT_ADDR - q); 2282 ptrdiff_t new_gpt = GPT_BYTE - (GPT_ADDR - q);
2272 2283
2273 move_gap_both (new_gpt, new_gpt); 2284 move_gap_both (new_gpt, new_gpt);
2274 } 2285 }
@@ -2352,8 +2363,8 @@ current buffer is cleared. */)
2352 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 2363 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
2353 2364
2354 { 2365 {
2355 EMACS_INT byte = advance_to_char_boundary (PT_BYTE); 2366 ptrdiff_t byte = advance_to_char_boundary (PT_BYTE);
2356 EMACS_INT position; 2367 ptrdiff_t position;
2357 2368
2358 if (byte > GPT_BYTE) 2369 if (byte > GPT_BYTE)
2359 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT; 2370 position = chars_in_text (GAP_END_ADDR, byte - GPT_BYTE) + GPT;
@@ -2517,20 +2528,20 @@ swap_out_buffer_local_variables (struct buffer *b)
2517ptrdiff_t 2528ptrdiff_t
2518overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 2529overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2519 ptrdiff_t *len_ptr, 2530 ptrdiff_t *len_ptr,
2520 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2531 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, int change_req)
2521{ 2532{
2522 Lisp_Object overlay, start, end; 2533 Lisp_Object overlay, start, end;
2523 struct Lisp_Overlay *tail; 2534 struct Lisp_Overlay *tail;
2524 ptrdiff_t idx = 0; 2535 ptrdiff_t idx = 0;
2525 ptrdiff_t len = *len_ptr; 2536 ptrdiff_t len = *len_ptr;
2526 Lisp_Object *vec = *vec_ptr; 2537 Lisp_Object *vec = *vec_ptr;
2527 EMACS_INT next = ZV; 2538 ptrdiff_t next = ZV;
2528 EMACS_INT prev = BEGV; 2539 ptrdiff_t prev = BEGV;
2529 int inhibit_storing = 0; 2540 int inhibit_storing = 0;
2530 2541
2531 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2542 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2532 { 2543 {
2533 EMACS_INT startpos, endpos; 2544 ptrdiff_t startpos, endpos;
2534 2545
2535 XSETMISC (overlay, tail); 2546 XSETMISC (overlay, tail);
2536 2547
@@ -2578,7 +2589,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2578 2589
2579 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2590 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2580 { 2591 {
2581 EMACS_INT startpos, endpos; 2592 ptrdiff_t startpos, endpos;
2582 2593
2583 XSETMISC (overlay, tail); 2594 XSETMISC (overlay, tail);
2584 2595
@@ -2651,21 +2662,21 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2651static ptrdiff_t 2662static ptrdiff_t
2652overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2663overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2653 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, 2664 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2654 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2665 ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr)
2655{ 2666{
2656 Lisp_Object overlay, ostart, oend; 2667 Lisp_Object overlay, ostart, oend;
2657 struct Lisp_Overlay *tail; 2668 struct Lisp_Overlay *tail;
2658 ptrdiff_t idx = 0; 2669 ptrdiff_t idx = 0;
2659 ptrdiff_t len = *len_ptr; 2670 ptrdiff_t len = *len_ptr;
2660 Lisp_Object *vec = *vec_ptr; 2671 Lisp_Object *vec = *vec_ptr;
2661 EMACS_INT next = ZV; 2672 ptrdiff_t next = ZV;
2662 EMACS_INT prev = BEGV; 2673 ptrdiff_t prev = BEGV;
2663 int inhibit_storing = 0; 2674 int inhibit_storing = 0;
2664 int end_is_Z = end == Z; 2675 int end_is_Z = end == Z;
2665 2676
2666 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2677 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2667 { 2678 {
2668 EMACS_INT startpos, endpos; 2679 ptrdiff_t startpos, endpos;
2669 2680
2670 XSETMISC (overlay, tail); 2681 XSETMISC (overlay, tail);
2671 2682
@@ -2712,7 +2723,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2712 2723
2713 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2724 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2714 { 2725 {
2715 EMACS_INT startpos, endpos; 2726 ptrdiff_t startpos, endpos;
2716 2727
2717 XSETMISC (overlay, tail); 2728 XSETMISC (overlay, tail);
2718 2729
@@ -2768,8 +2779,8 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2768int 2779int
2769mouse_face_overlay_overlaps (Lisp_Object overlay) 2780mouse_face_overlay_overlaps (Lisp_Object overlay)
2770{ 2781{
2771 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 2782 ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay));
2772 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 2783 ptrdiff_t end = OVERLAY_POSITION (OVERLAY_END (overlay));
2773 ptrdiff_t n, i, size; 2784 ptrdiff_t n, i, size;
2774 Lisp_Object *v, tem; 2785 Lisp_Object *v, tem;
2775 2786
@@ -2795,14 +2806,14 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2795 2806
2796/* Fast function to just test if we're at an overlay boundary. */ 2807/* Fast function to just test if we're at an overlay boundary. */
2797int 2808int
2798overlay_touches_p (EMACS_INT pos) 2809overlay_touches_p (ptrdiff_t pos)
2799{ 2810{
2800 Lisp_Object overlay; 2811 Lisp_Object overlay;
2801 struct Lisp_Overlay *tail; 2812 struct Lisp_Overlay *tail;
2802 2813
2803 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2814 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2804 { 2815 {
2805 EMACS_INT endpos; 2816 ptrdiff_t endpos;
2806 2817
2807 XSETMISC (overlay ,tail); 2818 XSETMISC (overlay ,tail);
2808 if (!OVERLAYP (overlay)) 2819 if (!OVERLAYP (overlay))
@@ -2817,7 +2828,7 @@ overlay_touches_p (EMACS_INT pos)
2817 2828
2818 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 2829 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
2819 { 2830 {
2820 EMACS_INT startpos; 2831 ptrdiff_t startpos;
2821 2832
2822 XSETMISC (overlay, tail); 2833 XSETMISC (overlay, tail);
2823 if (!OVERLAYP (overlay)) 2834 if (!OVERLAYP (overlay))
@@ -2835,7 +2846,7 @@ overlay_touches_p (EMACS_INT pos)
2835struct sortvec 2846struct sortvec
2836{ 2847{
2837 Lisp_Object overlay; 2848 Lisp_Object overlay;
2838 EMACS_INT beg, end; 2849 ptrdiff_t beg, end;
2839 EMACS_INT priority; 2850 EMACS_INT priority;
2840}; 2851};
2841 2852
@@ -2958,7 +2969,7 @@ static void
2958record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, 2969record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2959 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size) 2970 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2960{ 2971{
2961 EMACS_INT nbytes; 2972 ptrdiff_t nbytes;
2962 2973
2963 if (ssl->used == ssl->size) 2974 if (ssl->used == ssl->size)
2964 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); 2975 ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf);
@@ -3008,12 +3019,12 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3008 PSTR, if that variable is non-null. The string may be overwritten by 3019 PSTR, if that variable is non-null. The string may be overwritten by
3009 subsequent calls. */ 3020 subsequent calls. */
3010 3021
3011EMACS_INT 3022ptrdiff_t
3012overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3023overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr)
3013{ 3024{
3014 Lisp_Object overlay, window, str; 3025 Lisp_Object overlay, window, str;
3015 struct Lisp_Overlay *ov; 3026 struct Lisp_Overlay *ov;
3016 EMACS_INT startpos, endpos; 3027 ptrdiff_t startpos, endpos;
3017 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3028 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
3018 3029
3019 overlay_heads.used = overlay_heads.bytes = 0; 3030 overlay_heads.used = overlay_heads.bytes = 0;
@@ -3083,7 +3094,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3083 if (overlay_heads.bytes || overlay_tails.bytes) 3094 if (overlay_heads.bytes || overlay_tails.bytes)
3084 { 3095 {
3085 Lisp_Object tem; 3096 Lisp_Object tem;
3086 EMACS_INT i; 3097 ptrdiff_t i;
3087 unsigned char *p; 3098 unsigned char *p;
3088 ptrdiff_t total; 3099 ptrdiff_t total;
3089 3100
@@ -3097,7 +3108,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3097 p = overlay_str_buf; 3108 p = overlay_str_buf;
3098 for (i = overlay_tails.used; --i >= 0;) 3109 for (i = overlay_tails.used; --i >= 0;)
3099 { 3110 {
3100 EMACS_INT nbytes; 3111 ptrdiff_t nbytes;
3101 tem = overlay_tails.buf[i].string; 3112 tem = overlay_tails.buf[i].string;
3102 nbytes = copy_text (SDATA (tem), p, 3113 nbytes = copy_text (SDATA (tem), p,
3103 SBYTES (tem), 3114 SBYTES (tem),
@@ -3106,7 +3117,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3106 } 3117 }
3107 for (i = 0; i < overlay_heads.used; ++i) 3118 for (i = 0; i < overlay_heads.used; ++i)
3108 { 3119 {
3109 EMACS_INT nbytes; 3120 ptrdiff_t nbytes;
3110 tem = overlay_heads.buf[i].string; 3121 tem = overlay_heads.buf[i].string;
3111 nbytes = copy_text (SDATA (tem), p, 3122 nbytes = copy_text (SDATA (tem), p,
3112 SBYTES (tem), 3123 SBYTES (tem),
@@ -3133,7 +3144,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. */ 3144/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3134 3145
3135void 3146void
3136recenter_overlay_lists (struct buffer *buf, EMACS_INT pos) 3147recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos)
3137{ 3148{
3138 Lisp_Object overlay, beg, end; 3149 Lisp_Object overlay, beg, end;
3139 struct Lisp_Overlay *prev, *tail, *next; 3150 struct Lisp_Overlay *prev, *tail, *next;
@@ -3171,7 +3182,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3171 if (OVERLAY_POSITION (end) > pos) 3182 if (OVERLAY_POSITION (end) > pos)
3172 { 3183 {
3173 /* OVERLAY needs to be moved. */ 3184 /* OVERLAY needs to be moved. */
3174 EMACS_INT where = OVERLAY_POSITION (beg); 3185 ptrdiff_t where = OVERLAY_POSITION (beg);
3175 struct Lisp_Overlay *other, *other_prev; 3186 struct Lisp_Overlay *other, *other_prev;
3176 3187
3177 /* Splice the cons cell TAIL out of overlays_before. */ 3188 /* Splice the cons cell TAIL out of overlays_before. */
@@ -3244,7 +3255,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3244 if (OVERLAY_POSITION (end) <= pos) 3255 if (OVERLAY_POSITION (end) <= pos)
3245 { 3256 {
3246 /* OVERLAY needs to be moved. */ 3257 /* OVERLAY needs to be moved. */
3247 EMACS_INT where = OVERLAY_POSITION (end); 3258 ptrdiff_t where = OVERLAY_POSITION (end);
3248 struct Lisp_Overlay *other, *other_prev; 3259 struct Lisp_Overlay *other, *other_prev;
3249 3260
3250 /* Splice the cons cell TAIL out of overlays_after. */ 3261 /* Splice the cons cell TAIL out of overlays_after. */
@@ -3282,7 +3293,7 @@ recenter_overlay_lists (struct buffer *buf, EMACS_INT pos)
3282} 3293}
3283 3294
3284void 3295void
3285adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length) 3296adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
3286{ 3297{
3287 /* After an insertion, the lists are still sorted properly, 3298 /* After an insertion, the lists are still sorted properly,
3288 but we may need to update the value of the overlay center. */ 3299 but we may need to update the value of the overlay center. */
@@ -3291,13 +3302,13 @@ adjust_overlays_for_insert (EMACS_INT pos, EMACS_INT length)
3291} 3302}
3292 3303
3293void 3304void
3294adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length) 3305adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
3295{ 3306{
3296 if (current_buffer->overlay_center < pos) 3307 if (current_buffer->overlay_center < pos)
3297 /* The deletion was to our right. No change needed; the before- and 3308 /* The deletion was to our right. No change needed; the before- and
3298 after-lists are still consistent. */ 3309 after-lists are still consistent. */
3299 ; 3310 ;
3300 else if (current_buffer->overlay_center > pos + length) 3311 else if (current_buffer->overlay_center - pos > length)
3301 /* The deletion was to our left. We need to adjust the center value 3312 /* 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 3313 to account for the change in position, but the lists are consistent
3303 given the new value. */ 3314 given the new value. */
@@ -3316,7 +3327,7 @@ adjust_overlays_for_delete (EMACS_INT pos, EMACS_INT length)
3316 Such an overlay might even have negative size at this point. 3327 Such an overlay might even have negative size at this point.
3317 If so, we'll make the overlay empty. */ 3328 If so, we'll make the overlay empty. */
3318void 3329void
3319fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end) 3330fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3320{ 3331{
3321 Lisp_Object overlay; 3332 Lisp_Object overlay;
3322 struct Lisp_Overlay *before_list IF_LINT (= NULL); 3333 struct Lisp_Overlay *before_list IF_LINT (= NULL);
@@ -3329,7 +3340,7 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3329 current_buffer->overlays_before or overlays_after, depending 3340 current_buffer->overlays_before or overlays_after, depending
3330 which loop we're in. */ 3341 which loop we're in. */
3331 struct Lisp_Overlay *tail, *parent; 3342 struct Lisp_Overlay *tail, *parent;
3332 EMACS_INT startpos, endpos; 3343 ptrdiff_t startpos, endpos;
3333 3344
3334 /* This algorithm shifts links around instead of consing and GCing. 3345 /* This algorithm shifts links around instead of consing and GCing.
3335 The loop invariant is that before_list (resp. after_list) is a 3346 The loop invariant is that before_list (resp. after_list) is a
@@ -3463,12 +3474,12 @@ fix_start_end_in_overlays (register EMACS_INT start, register EMACS_INT end)
3463 was at PREV, and now is at POS. */ 3474 was at PREV, and now is at POS. */
3464 3475
3465void 3476void
3466fix_overlays_before (struct buffer *bp, EMACS_INT prev, EMACS_INT pos) 3477fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos)
3467{ 3478{
3468 /* If parent is nil, replace overlays_before; otherwise, parent->next. */ 3479 /* If parent is nil, replace overlays_before; otherwise, parent->next. */
3469 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair; 3480 struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3470 Lisp_Object tem; 3481 Lisp_Object tem;
3471 EMACS_INT end IF_LINT (= 0); 3482 ptrdiff_t end IF_LINT (= 0);
3472 3483
3473 /* After the insertion, the several overlays may be in incorrect 3484 /* After the insertion, the several overlays may be in incorrect
3474 order. The possibility is that, in the list `overlays_before', 3485 order. The possibility is that, in the list `overlays_before',
@@ -3626,11 +3637,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. */ 3637/* Mark a section of BUF as needing redisplay because of overlays changes. */
3627 3638
3628static void 3639static void
3629modify_overlay (struct buffer *buf, EMACS_INT start, EMACS_INT end) 3640modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3630{ 3641{
3631 if (start > end) 3642 if (start > end)
3632 { 3643 {
3633 EMACS_INT temp = start; 3644 ptrdiff_t temp = start;
3634 start = end; 3645 start = end;
3635 end = temp; 3646 end = temp;
3636 } 3647 }
@@ -3677,9 +3688,10 @@ If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
3677buffer. */) 3688buffer. */)
3678 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer) 3689 (Lisp_Object overlay, Lisp_Object beg, Lisp_Object end, Lisp_Object buffer)
3679{ 3690{
3680 struct buffer *b, *ob; 3691 struct buffer *b, *ob = 0;
3681 Lisp_Object obuffer; 3692 Lisp_Object obuffer;
3682 int count = SPECPDL_INDEX (); 3693 ptrdiff_t count = SPECPDL_INDEX ();
3694 ptrdiff_t n_beg, n_end, o_beg IF_LINT (= 0), o_end IF_LINT (= 0);
3683 3695
3684 CHECK_OVERLAY (overlay); 3696 CHECK_OVERLAY (overlay);
3685 if (NILP (buffer)) 3697 if (NILP (buffer))
@@ -3688,6 +3700,9 @@ buffer. */)
3688 XSETBUFFER (buffer, current_buffer); 3700 XSETBUFFER (buffer, current_buffer);
3689 CHECK_BUFFER (buffer); 3701 CHECK_BUFFER (buffer);
3690 3702
3703 if (NILP (Fbuffer_live_p (buffer)))
3704 error ("Attempt to move overlay to a dead buffer");
3705
3691 if (MARKERP (beg) 3706 if (MARKERP (beg)
3692 && ! EQ (Fmarker_buffer (beg), buffer)) 3707 && ! EQ (Fmarker_buffer (beg), buffer))
3693 error ("Marker points into wrong buffer"); 3708 error ("Marker points into wrong buffer");
@@ -3698,9 +3713,6 @@ buffer. */)
3698 CHECK_NUMBER_COERCE_MARKER (beg); 3713 CHECK_NUMBER_COERCE_MARKER (beg);
3699 CHECK_NUMBER_COERCE_MARKER (end); 3714 CHECK_NUMBER_COERCE_MARKER (end);
3700 3715
3701 if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
3702 return Fdelete_overlay (overlay);
3703
3704 if (XINT (beg) > XINT (end)) 3716 if (XINT (beg) > XINT (end))
3705 { 3717 {
3706 Lisp_Object temp; 3718 Lisp_Object temp;
@@ -3711,61 +3723,57 @@ buffer. */)
3711 3723
3712 obuffer = Fmarker_buffer (OVERLAY_START (overlay)); 3724 obuffer = Fmarker_buffer (OVERLAY_START (overlay));
3713 b = XBUFFER (buffer); 3725 b = XBUFFER (buffer);
3714 ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; 3726
3727 if (!NILP (obuffer))
3728 {
3729 ob = XBUFFER (obuffer);
3730
3731 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
3732 o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
3733
3734 ob->overlays_before =
3735 unchain_overlay (ob->overlays_before, XOVERLAY (overlay));
3736 ob->overlays_after =
3737 unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3738 eassert (XOVERLAY (overlay)->next == NULL);
3739 }
3740
3741 /* Set the overlay boundaries, which may clip them. */
3742 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3743 Fset_marker (OVERLAY_END (overlay), end, buffer);
3744
3745 n_beg = marker_position (OVERLAY_START (overlay));
3746 n_end = marker_position (OVERLAY_END (overlay));
3715 3747
3716 /* If the overlay has changed buffers, do a thorough redisplay. */ 3748 /* If the overlay has changed buffers, do a thorough redisplay. */
3717 if (!EQ (buffer, obuffer)) 3749 if (!EQ (buffer, obuffer))
3718 { 3750 {
3719 /* Redisplay where the overlay was. */ 3751 /* Redisplay where the overlay was. */
3720 if (!NILP (obuffer)) 3752 if (ob)
3721 { 3753 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 3754
3731 /* Redisplay where the overlay is going to be. */ 3755 /* Redisplay where the overlay is going to be. */
3732 modify_overlay (b, XINT (beg), XINT (end)); 3756 modify_overlay (b, n_beg, n_end);
3733 } 3757 }
3734 else 3758 else
3735 /* Redisplay the area the overlay has just left, or just enclosed. */ 3759 /* Redisplay the area the overlay has just left, or just enclosed. */
3736 { 3760 {
3737 EMACS_INT o_beg, o_end; 3761 if (o_beg == n_beg)
3738 3762 modify_overlay (b, o_end, n_end);
3739 o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); 3763 else if (o_end == n_end)
3740 o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); 3764 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 3765 else
3747 { 3766 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 } 3767 }
3753 3768
3754 if (!NILP (obuffer)) 3769 /* Delete the overlay if it is empty after clipping and has the
3755 { 3770 evaporate property. */
3756 ob->overlays_before 3771 if (n_beg == n_end && !NILP (Foverlay_get (overlay, Qevaporate)))
3757 = unchain_overlay (ob->overlays_before, XOVERLAY (overlay)); 3772 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 3773
3766 /* Put the overlay on the wrong list. */ 3774 /* Put the overlay into the new buffer's overlay lists, first on the
3767 end = OVERLAY_END (overlay); 3775 wrong list. */
3768 if (OVERLAY_POSITION (end) < b->overlay_center) 3776 if (n_end < b->overlay_center)
3769 { 3777 {
3770 XOVERLAY (overlay)->next = b->overlays_after; 3778 XOVERLAY (overlay)->next = b->overlays_after;
3771 b->overlays_after = XOVERLAY (overlay); 3779 b->overlays_after = XOVERLAY (overlay);
@@ -3788,7 +3796,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3788{ 3796{
3789 Lisp_Object buffer; 3797 Lisp_Object buffer;
3790 struct buffer *b; 3798 struct buffer *b;
3791 int count = SPECPDL_INDEX (); 3799 ptrdiff_t count = SPECPDL_INDEX ();
3792 3800
3793 CHECK_OVERLAY (overlay); 3801 CHECK_OVERLAY (overlay);
3794 3802
@@ -3799,9 +3807,12 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3799 b = XBUFFER (buffer); 3807 b = XBUFFER (buffer);
3800 specbind (Qinhibit_quit, Qt); 3808 specbind (Qinhibit_quit, Qt);
3801 3809
3802 b->overlays_before = unchain_overlay (b->overlays_before,XOVERLAY (overlay)); 3810 b->overlays_before
3803 b->overlays_after = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); 3811 = unchain_overlay (b->overlays_before, XOVERLAY (overlay));
3812 b->overlays_after
3813 = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3804 eassert (XOVERLAY (overlay)->next == NULL); 3814 eassert (XOVERLAY (overlay)->next == NULL);
3815
3805 modify_overlay (b, 3816 modify_overlay (b,
3806 marker_position (OVERLAY_START (overlay)), 3817 marker_position (OVERLAY_START (overlay)),
3807 marker_position (OVERLAY_END (overlay))); 3818 marker_position (OVERLAY_END (overlay)));
@@ -3879,7 +3890,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3879 /* Put all the overlays we want in a vector in overlay_vec. 3890 /* Put all the overlays we want in a vector in overlay_vec.
3880 Store the length in len. */ 3891 Store the length in len. */
3881 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3892 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3882 (EMACS_INT *) 0, (EMACS_INT *) 0, 0); 3893 0, 0, 0);
3883 3894
3884 /* Make a list of them all. */ 3895 /* Make a list of them all. */
3885 result = Flist (noverlays, overlay_vec); 3896 result = Flist (noverlays, overlay_vec);
@@ -3927,7 +3938,7 @@ the value is (point-max). */)
3927 (Lisp_Object pos) 3938 (Lisp_Object pos)
3928{ 3939{
3929 ptrdiff_t i, len, noverlays; 3940 ptrdiff_t i, len, noverlays;
3930 EMACS_INT endpos; 3941 ptrdiff_t endpos;
3931 Lisp_Object *overlay_vec; 3942 Lisp_Object *overlay_vec;
3932 3943
3933 CHECK_NUMBER_COERCE_MARKER (pos); 3944 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3939,14 +3950,14 @@ the value is (point-max). */)
3939 Store the length in len. 3950 Store the length in len.
3940 endpos gets the position where the next overlay starts. */ 3951 endpos gets the position where the next overlay starts. */
3941 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 3952 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
3942 &endpos, (EMACS_INT *) 0, 1); 3953 &endpos, 0, 1);
3943 3954
3944 /* If any of these overlays ends before endpos, 3955 /* If any of these overlays ends before endpos,
3945 use its ending point instead. */ 3956 use its ending point instead. */
3946 for (i = 0; i < noverlays; i++) 3957 for (i = 0; i < noverlays; i++)
3947 { 3958 {
3948 Lisp_Object oend; 3959 Lisp_Object oend;
3949 EMACS_INT oendpos; 3960 ptrdiff_t oendpos;
3950 3961
3951 oend = OVERLAY_END (overlay_vec[i]); 3962 oend = OVERLAY_END (overlay_vec[i]);
3952 oendpos = OVERLAY_POSITION (oend); 3963 oendpos = OVERLAY_POSITION (oend);
@@ -3965,7 +3976,7 @@ If there are no overlay boundaries from (point-min) to POS,
3965the value is (point-min). */) 3976the value is (point-min). */)
3966 (Lisp_Object pos) 3977 (Lisp_Object pos)
3967{ 3978{
3968 EMACS_INT prevpos; 3979 ptrdiff_t prevpos;
3969 Lisp_Object *overlay_vec; 3980 Lisp_Object *overlay_vec;
3970 ptrdiff_t len; 3981 ptrdiff_t len;
3971 3982
@@ -3983,7 +3994,7 @@ the value is (point-min). */)
3983 Store the length in len. 3994 Store the length in len.
3984 prevpos gets the position of the previous change. */ 3995 prevpos gets the position of the previous change. */
3985 overlays_at (XINT (pos), 1, &overlay_vec, &len, 3996 overlays_at (XINT (pos), 1, &overlay_vec, &len,
3986 (EMACS_INT *) 0, &prevpos, 1); 3997 0, &prevpos, 1);
3987 3998
3988 xfree (overlay_vec); 3999 xfree (overlay_vec);
3989 return make_number (prevpos); 4000 return make_number (prevpos);
@@ -4021,9 +4032,11 @@ That makes overlay lookup faster for positions near POS (but perhaps slower
4021for positions far away from POS). */) 4032for positions far away from POS). */)
4022 (Lisp_Object pos) 4033 (Lisp_Object pos)
4023{ 4034{
4035 ptrdiff_t p;
4024 CHECK_NUMBER_COERCE_MARKER (pos); 4036 CHECK_NUMBER_COERCE_MARKER (pos);
4025 4037
4026 recenter_overlay_lists (current_buffer, XINT (pos)); 4038 p = clip_to_bounds (PTRDIFF_MIN, XINT (pos), PTRDIFF_MAX);
4039 recenter_overlay_lists (current_buffer, p);
4027 return Qnil; 4040 return Qnil;
4028} 4041}
4029 4042
@@ -4090,7 +4103,7 @@ VALUE will be returned.*/)
4090static Lisp_Object last_overlay_modification_hooks; 4103static Lisp_Object last_overlay_modification_hooks;
4091 4104
4092/* Number of elements actually used in last_overlay_modification_hooks. */ 4105/* Number of elements actually used in last_overlay_modification_hooks. */
4093static int last_overlay_modification_hooks_used; 4106static ptrdiff_t last_overlay_modification_hooks_used;
4094 4107
4095/* Add one functionlist/overlay pair 4108/* Add one functionlist/overlay pair
4096 to the end of last_overlay_modification_hooks. */ 4109 to the end of last_overlay_modification_hooks. */
@@ -4098,11 +4111,11 @@ static int last_overlay_modification_hooks_used;
4098static void 4111static void
4099add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) 4112add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay)
4100{ 4113{
4101 int oldsize = ASIZE (last_overlay_modification_hooks); 4114 ptrdiff_t oldsize = ASIZE (last_overlay_modification_hooks);
4102 4115
4103 if (last_overlay_modification_hooks_used == oldsize) 4116 if (oldsize - 1 <= last_overlay_modification_hooks_used)
4104 last_overlay_modification_hooks = larger_vector 4117 last_overlay_modification_hooks =
4105 (last_overlay_modification_hooks, oldsize * 2, Qnil); 4118 larger_vector (last_overlay_modification_hooks, 2, -1);
4106 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4119 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
4107 functionlist); last_overlay_modification_hooks_used++; 4120 functionlist); last_overlay_modification_hooks_used++;
4108 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used, 4121 ASET (last_overlay_modification_hooks, last_overlay_modification_hooks_used,
@@ -4151,7 +4164,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4151 last_overlay_modification_hooks_used = 0; 4164 last_overlay_modification_hooks_used = 0;
4152 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4165 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4153 { 4166 {
4154 EMACS_INT startpos, endpos; 4167 ptrdiff_t startpos, endpos;
4155 Lisp_Object ostart, oend; 4168 Lisp_Object ostart, oend;
4156 4169
4157 XSETMISC (overlay, tail); 4170 XSETMISC (overlay, tail);
@@ -4188,7 +4201,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4188 4201
4189 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4202 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4190 { 4203 {
4191 EMACS_INT startpos, endpos; 4204 ptrdiff_t startpos, endpos;
4192 Lisp_Object ostart, oend; 4205 Lisp_Object ostart, oend;
4193 4206
4194 XSETMISC (overlay, tail); 4207 XSETMISC (overlay, tail);
@@ -4229,9 +4242,9 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4229 /* Call the functions recorded in last_overlay_modification_hooks. 4242 /* Call the functions recorded in last_overlay_modification_hooks.
4230 First copy the vector contents, in case some of these hooks 4243 First copy the vector contents, in case some of these hooks
4231 do subsequent modification of the buffer. */ 4244 do subsequent modification of the buffer. */
4232 int size = last_overlay_modification_hooks_used; 4245 ptrdiff_t size = last_overlay_modification_hooks_used;
4233 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4246 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
4234 int i; 4247 ptrdiff_t i;
4235 4248
4236 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4249 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
4237 size * sizeof (Lisp_Object)); 4250 size * sizeof (Lisp_Object));
@@ -4271,7 +4284,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' 4284/* Delete any zero-sized overlays at position POS, if the `evaporate'
4272 property is set. */ 4285 property is set. */
4273void 4286void
4274evaporate_overlays (EMACS_INT pos) 4287evaporate_overlays (ptrdiff_t pos)
4275{ 4288{
4276 Lisp_Object overlay, hit_list; 4289 Lisp_Object overlay, hit_list;
4277 struct Lisp_Overlay *tail; 4290 struct Lisp_Overlay *tail;
@@ -4280,7 +4293,7 @@ evaporate_overlays (EMACS_INT pos)
4280 if (pos <= current_buffer->overlay_center) 4293 if (pos <= current_buffer->overlay_center)
4281 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 4294 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
4282 { 4295 {
4283 EMACS_INT endpos; 4296 ptrdiff_t endpos;
4284 XSETMISC (overlay, tail); 4297 XSETMISC (overlay, tail);
4285 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 4298 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4286 if (endpos < pos) 4299 if (endpos < pos)
@@ -4292,7 +4305,7 @@ evaporate_overlays (EMACS_INT pos)
4292 else 4305 else
4293 for (tail = current_buffer->overlays_after; tail; tail = tail->next) 4306 for (tail = current_buffer->overlays_after; tail; tail = tail->next)
4294 { 4307 {
4295 EMACS_INT startpos; 4308 ptrdiff_t startpos;
4296 XSETMISC (overlay, tail); 4309 XSETMISC (overlay, tail);
4297 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 4310 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4298 if (startpos > pos) 4311 if (startpos > pos)
@@ -4383,7 +4396,7 @@ struct mmap_region
4383 /* Pointer to the location holding the address of the memory 4396 /* Pointer to the location holding the address of the memory
4384 allocated with the mmap'd block. The variable actually points 4397 allocated with the mmap'd block. The variable actually points
4385 after this structure. */ 4398 after this structure. */
4386 POINTER_TYPE **var; 4399 void **var;
4387 4400
4388 /* Next and previous in list of all mmap'd regions. */ 4401 /* Next and previous in list of all mmap'd regions. */
4389 struct mmap_region *next, *prev; 4402 struct mmap_region *next, *prev;
@@ -4430,7 +4443,7 @@ static int mmap_initialized_p;
4430 to the start of the user-visible part of the region. */ 4443 to the start of the user-visible part of the region. */
4431 4444
4432#define MMAP_USER_AREA(P) \ 4445#define MMAP_USER_AREA(P) \
4433 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE)) 4446 ((void *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE))
4434 4447
4435#define MEM_ALIGN sizeof (double) 4448#define MEM_ALIGN sizeof (double)
4436 4449
@@ -4479,7 +4492,7 @@ mmap_init (void)
4479 is at END - 1. */ 4492 is at END - 1. */
4480 4493
4481static struct mmap_region * 4494static struct mmap_region *
4482mmap_find (POINTER_TYPE *start, POINTER_TYPE *end) 4495mmap_find (void *start, void *end)
4483{ 4496{
4484 struct mmap_region *r; 4497 struct mmap_region *r;
4485 char *s = (char *) start, *e = (char *) end; 4498 char *s = (char *) start, *e = (char *) end;
@@ -4517,7 +4530,7 @@ mmap_free_1 (struct mmap_region *r)
4517 else 4530 else
4518 mmap_regions = r->next; 4531 mmap_regions = r->next;
4519 4532
4520 if (munmap ((POINTER_TYPE *) r, r->nbytes_mapped) == -1) 4533 if (munmap (r, r->nbytes_mapped) == -1)
4521 { 4534 {
4522 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); 4535 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
4523 return 0; 4536 return 0;
@@ -4559,13 +4572,13 @@ mmap_enlarge (struct mmap_region *r, int npages)
4559 I'm not sure this is worth doing, let's see. */ 4572 I'm not sure this is worth doing, let's see. */
4560 if (!MMAP_ALLOCATED_P (region_end, region_end + nbytes)) 4573 if (!MMAP_ALLOCATED_P (region_end, region_end + nbytes))
4561 { 4574 {
4562 POINTER_TYPE *p; 4575 void *p;
4563 4576
4564 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, 4577 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
4565 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0); 4578 MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0);
4566 if (p == MAP_FAILED) 4579 if (p == MAP_FAILED)
4567 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */ 4580 ; /* fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); */
4568 else if (p != (POINTER_TYPE *) region_end) 4581 else if (p != region_end)
4569 { 4582 {
4570 /* Kernels are free to choose a different address. In 4583 /* Kernels are free to choose a different address. In
4571 that case, unmap what we've mapped above; we have 4584 that case, unmap what we've mapped above; we have
@@ -4627,8 +4640,8 @@ mmap_set_vars (int restore_p)
4627 If we can't allocate the necessary memory, set *VAR to null, and 4640 If we can't allocate the necessary memory, set *VAR to null, and
4628 return null. */ 4641 return null. */
4629 4642
4630static POINTER_TYPE * 4643static void *
4631mmap_alloc (POINTER_TYPE **var, size_t nbytes) 4644mmap_alloc (void **var, size_t nbytes)
4632{ 4645{
4633 void *p; 4646 void *p;
4634 size_t map; 4647 size_t map;
@@ -4669,7 +4682,7 @@ mmap_alloc (POINTER_TYPE **var, size_t nbytes)
4669 PTR. Store 0 in *PTR to show there's no block allocated. */ 4682 PTR. Store 0 in *PTR to show there's no block allocated. */
4670 4683
4671static void 4684static void
4672mmap_free (POINTER_TYPE **var) 4685mmap_free (void **var)
4673{ 4686{
4674 mmap_init (); 4687 mmap_init ();
4675 4688
@@ -4686,10 +4699,10 @@ mmap_free (POINTER_TYPE **var)
4686 and return this value. If more memory cannot be allocated, then 4699 and return this value. If more memory cannot be allocated, then
4687 leave *VAR unchanged, and return null. */ 4700 leave *VAR unchanged, and return null. */
4688 4701
4689static POINTER_TYPE * 4702static void *
4690mmap_realloc (POINTER_TYPE **var, size_t nbytes) 4703mmap_realloc (void **var, size_t nbytes)
4691{ 4704{
4692 POINTER_TYPE *result; 4705 void *result;
4693 4706
4694 mmap_init (); 4707 mmap_init ();
4695 4708
@@ -4708,7 +4721,7 @@ mmap_realloc (POINTER_TYPE **var, size_t nbytes)
4708 if (room < nbytes) 4721 if (room < nbytes)
4709 { 4722 {
4710 /* Must enlarge. */ 4723 /* Must enlarge. */
4711 POINTER_TYPE *old_ptr = *var; 4724 void *old_ptr = *var;
4712 4725
4713 /* Try to map additional pages at the end of the region. 4726 /* Try to map additional pages at the end of the region.
4714 If that fails, allocate a new region, copy data 4727 If that fails, allocate a new region, copy data
@@ -4770,13 +4783,13 @@ mmap_realloc (POINTER_TYPE **var, size_t nbytes)
4770static void 4783static void
4771alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) 4784alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4772{ 4785{
4773 POINTER_TYPE *p; 4786 void *p;
4774 4787
4775 BLOCK_INPUT; 4788 BLOCK_INPUT;
4776#if defined USE_MMAP_FOR_BUFFERS 4789#if defined USE_MMAP_FOR_BUFFERS
4777 p = mmap_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 4790 p = mmap_alloc ((void **) &b->text->beg, nbytes);
4778#elif defined REL_ALLOC 4791#elif defined REL_ALLOC
4779 p = r_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 4792 p = r_alloc ((void **) &b->text->beg, nbytes);
4780#else 4793#else
4781 p = xmalloc (nbytes); 4794 p = xmalloc (nbytes);
4782#endif 4795#endif
@@ -4795,16 +4808,16 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
4795 shrink it. */ 4808 shrink it. */
4796 4809
4797void 4810void
4798enlarge_buffer_text (struct buffer *b, EMACS_INT delta) 4811enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
4799{ 4812{
4800 POINTER_TYPE *p; 4813 void *p;
4801 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 4814 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
4802 + delta); 4815 + delta);
4803 BLOCK_INPUT; 4816 BLOCK_INPUT;
4804#if defined USE_MMAP_FOR_BUFFERS 4817#if defined USE_MMAP_FOR_BUFFERS
4805 p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); 4818 p = mmap_realloc ((void **) &b->text->beg, nbytes);
4806#elif defined REL_ALLOC 4819#elif defined REL_ALLOC
4807 p = r_re_alloc ((POINTER_TYPE **) &b->text->beg, nbytes); 4820 p = r_re_alloc ((void **) &b->text->beg, nbytes);
4808#else 4821#else
4809 p = xrealloc (b->text->beg, nbytes); 4822 p = xrealloc (b->text->beg, nbytes);
4810#endif 4823#endif
@@ -4828,9 +4841,9 @@ free_buffer_text (struct buffer *b)
4828 BLOCK_INPUT; 4841 BLOCK_INPUT;
4829 4842
4830#if defined USE_MMAP_FOR_BUFFERS 4843#if defined USE_MMAP_FOR_BUFFERS
4831 mmap_free ((POINTER_TYPE **) &b->text->beg); 4844 mmap_free ((void **) &b->text->beg);
4832#elif defined REL_ALLOC 4845#elif defined REL_ALLOC
4833 r_alloc_free ((POINTER_TYPE **) &b->text->beg); 4846 r_alloc_free ((void **) &b->text->beg);
4834#else 4847#else
4835 xfree (b->text->beg); 4848 xfree (b->text->beg);
4836#endif 4849#endif
@@ -5328,31 +5341,40 @@ the mode line appears at the bottom. */);
5328 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), 5341 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format),
5329 Qnil, 5342 Qnil,
5330 doc: /* Template for displaying mode line for current buffer. 5343 doc: /* Template for displaying mode line for current buffer.
5331Each buffer has its own value of this variable. 5344
5332Value may be nil, a string, a symbol or a list or cons cell. 5345The value may be nil, a string, a symbol or a list.
5346
5333A value of nil means don't display a mode line. 5347A value of nil means don't display a mode line.
5334For a symbol, its value is used (but it is ignored if t or nil). 5348
5335 A string appearing directly as the value of a symbol is processed verbatim 5349For any symbol other than t or nil, the symbol's value is processed as
5336 in that the %-constructs below are not recognized. 5350 a mode line construct. As a special exception, if that value is a
5337 Note that unless the symbol is marked as a `risky-local-variable', all 5351 string, the string is processed verbatim, without handling any
5338 properties in any strings, as well as all :eval and :propertize forms 5352 %-constructs (see below). Also, unless the symbol has a non-nil
5339 in the value of that symbol will be ignored. 5353 `risky-local-variable' property, all properties in any strings, as
5340For a list of the form `(:eval FORM)', FORM is evaluated and the result 5354 well as all :eval and :propertize forms in the value, are ignored.
5341 is used as a mode line element. Be careful--FORM should not load any files, 5355
5342 because that can cause an infinite recursion. 5356A list whose car is a string or list is processed by processing each
5343For a list of the form `(:propertize ELT PROPS...)', ELT is displayed 5357 of the list elements recursively, as separate mode line constructs,
5344 with the specified properties PROPS applied. 5358 and concatenating the results.
5345For a list whose car is a symbol, the symbol's value is taken, 5359
5346 and if that is non-nil, the cadr of the list is processed recursively. 5360A list of the form `(:eval FORM)' is processed by evaluating FORM and
5347 Otherwise, the caddr of the list (if there is one) is processed. 5361 using the result as a mode line construct. Be careful--FORM should
5348For a list whose car is a string or list, each element is processed 5362 not load any files, because that can cause an infinite recursion.
5349 recursively and the results are effectively concatenated. 5363
5350For a list whose car is an integer, the cdr of the list is processed 5364A list of the form `(:propertize ELT PROPS...)' is processed by
5351 and padded (if the number is positive) or truncated (if negative) 5365 processing ELT as the mode line construct, and adding the text
5352 to the width specified by that number. 5366 properties PROPS to the result.
5367
5368A list whose car is a symbol is processed by examining the symbol's
5369 value, and, if that value is non-nil, processing the cadr of the list
5370 recursively; and if that value is nil, processing the caddr of the
5371 list recursively.
5372
5373A list whose car is an integer is processed by processing the cadr of
5374 the list, and padding (if the number is positive) or truncating (if
5375 negative) to the width specified by that number.
5376
5353A string is printed verbatim in the mode line except for %-constructs: 5377A string is printed verbatim in the mode line except for %-constructs:
5354 (%-constructs are allowed when the string is the entire mode-line-format
5355 or when it is found in a cons-cell or a list)
5356 %b -- print buffer name. %f -- print visited file name. 5378 %b -- print buffer name. %f -- print visited file name.
5357 %F -- print frame name. 5379 %F -- print frame name.
5358 %* -- print %, * or hyphen. %+ -- print *, % or hyphen. 5380 %* -- print %, * or hyphen. %+ -- print *, % or hyphen.
diff --git a/src/buffer.h b/src/buffer.h
index 1635a847839..3aa4b11c450 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,21 @@ 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 Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object);
915extern void record_buffer (Lisp_Object); 916extern void record_buffer (Lisp_Object);
916extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN; 917extern void buffer_slot_type_mismatch (Lisp_Object, int) NO_RETURN;
917extern void fix_overlays_before (struct buffer *, EMACS_INT, EMACS_INT); 918extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
918extern void mmap_set_vars (int); 919extern void mmap_set_vars (int);
919 920
920/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements. 921/* 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..bfa981ec65a 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;
@@ -284,7 +284,7 @@ invoke it. If KEYS is omitted or nil, the return value of
284 284
285 save_this_command = Vthis_command; 285 save_this_command = Vthis_command;
286 save_this_original_command = Vthis_original_command; 286 save_this_original_command = Vthis_original_command;
287 save_real_this_command = real_this_command; 287 save_real_this_command = Vreal_this_command;
288 save_last_command = KVAR (current_kboard, Vlast_command); 288 save_last_command = KVAR (current_kboard, Vlast_command);
289 289
290 if (NILP (keys)) 290 if (NILP (keys))
@@ -295,7 +295,7 @@ invoke it. If KEYS is omitted or nil, the return value of
295 key_count = ASIZE (keys); 295 key_count = ASIZE (keys);
296 } 296 }
297 297
298 /* Save this now, since use of minibuffer will clobber it. */ 298 /* Save this now, since use of minibuffer will clobber it. */
299 prefix_arg = Vcurrent_prefix_arg; 299 prefix_arg = Vcurrent_prefix_arg;
300 300
301 if (SYMBOLP (function)) 301 if (SYMBOLP (function))
@@ -310,7 +310,8 @@ invoke it. If KEYS is omitted or nil, the return value of
310 The feature is not fully implemented. */ 310 The feature is not fully implemented. */
311 filter_specs = Qnil; 311 filter_specs = Qnil;
312 312
313 /* If k or K discard an up-event, save it here so it can be retrieved with U */ 313 /* If k or K discard an up-event, save it here so it can be retrieved with
314 U. */
314 up_event = Qnil; 315 up_event = Qnil;
315 316
316 /* Set SPECS to the interactive form, or barf if not interactive. */ 317 /* Set SPECS to the interactive form, or barf if not interactive. */
@@ -370,14 +371,14 @@ invoke it. If KEYS is omitted or nil, the return value of
370 371
371 Vthis_command = save_this_command; 372 Vthis_command = save_this_command;
372 Vthis_original_command = save_this_original_command; 373 Vthis_original_command = save_this_original_command;
373 real_this_command= save_real_this_command; 374 Vreal_this_command = save_real_this_command;
374 KVAR (current_kboard, Vlast_command) = save_last_command; 375 KVAR (current_kboard, Vlast_command) = save_last_command;
375 376
376 temporarily_switch_to_single_kboard (NULL); 377 temporarily_switch_to_single_kboard (NULL);
377 return unbind_to (speccount, apply1 (function, specs)); 378 return unbind_to (speccount, apply1 (function, specs));
378 } 379 }
379 380
380 /* Here if function specifies a string to control parsing the defaults */ 381 /* Here if function specifies a string to control parsing the defaults. */
381 382
382 /* Set next_event to point to the first event with parameters. */ 383 /* Set next_event to point to the first event with parameters. */
383 for (next_event = 0; next_event < key_count; next_event++) 384 for (next_event = 0; next_event < key_count; next_event++)
@@ -577,7 +578,7 @@ invoke it. If KEYS is omitted or nil, the return value of
577 578
578 case 'k': /* Key sequence. */ 579 case 'k': /* Key sequence. */
579 { 580 {
580 int speccount1 = SPECPDL_INDEX (); 581 ptrdiff_t speccount1 = SPECPDL_INDEX ();
581 specbind (Qcursor_in_echo_area, Qt); 582 specbind (Qcursor_in_echo_area, Qt);
582 /* Prompt in `minibuffer-prompt' face. */ 583 /* Prompt in `minibuffer-prompt' face. */
583 Fput_text_property (make_number (0), 584 Fput_text_property (make_number (0),
@@ -609,7 +610,7 @@ invoke it. If KEYS is omitted or nil, the return value of
609 610
610 case 'K': /* Key sequence to be defined. */ 611 case 'K': /* Key sequence to be defined. */
611 { 612 {
612 int speccount1 = SPECPDL_INDEX (); 613 ptrdiff_t speccount1 = SPECPDL_INDEX ();
613 specbind (Qcursor_in_echo_area, Qt); 614 specbind (Qcursor_in_echo_area, Qt);
614 /* Prompt in `minibuffer-prompt' face. */ 615 /* Prompt in `minibuffer-prompt' face. */
615 Fput_text_property (make_number (0), 616 Fput_text_property (make_number (0),
@@ -841,7 +842,7 @@ invoke it. If KEYS is omitted or nil, the return value of
841 842
842 Vthis_command = save_this_command; 843 Vthis_command = save_this_command;
843 Vthis_original_command = save_this_original_command; 844 Vthis_original_command = save_this_original_command;
844 real_this_command= save_real_this_command; 845 Vreal_this_command = save_real_this_command;
845 KVAR (current_kboard, Vlast_command) = save_last_command; 846 KVAR (current_kboard, Vlast_command) = save_last_command;
846 847
847 { 848 {
diff --git a/src/callproc.c b/src/callproc.c
index 9528c9644d8..976d3061c8b 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;
@@ -1006,7 +1015,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1006 UNBLOCK_INPUT; 1015 UNBLOCK_INPUT;
1007 if (fd == -1) 1016 if (fd == -1)
1008 report_file_error ("Failed to open temporary file", 1017 report_file_error ("Failed to open temporary file",
1009 Fcons (Vtemp_file_name_pattern, Qnil)); 1018 Fcons (build_string (tempfile), Qnil));
1010 else 1019 else
1011 close (fd); 1020 close (fd);
1012 } 1021 }
@@ -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..8ce972ebf37 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));
@@ -1641,6 +1633,12 @@ maybe_unify_char (int c, Lisp_Object val)
1641 return c; 1633 return c;
1642 1634
1643 CHECK_CHARSET_GET_CHARSET (val, charset); 1635 CHECK_CHARSET_GET_CHARSET (val, charset);
1636#ifdef REL_ALLOC
1637 /* The call to load_charset below can allocate memory, which screws
1638 callers of this function through STRING_CHAR_* macros that hold C
1639 pointers to buffer text, if REL_ALLOC is used. */
1640 r_alloc_inhibit_buffer_relocation (1);
1641#endif
1644 load_charset (charset, 1); 1642 load_charset (charset, 1);
1645 if (! inhibit_load_charset_map) 1643 if (! inhibit_load_charset_map)
1646 { 1644 {
@@ -1656,6 +1654,9 @@ maybe_unify_char (int c, Lisp_Object val)
1656 if (unified > 0) 1654 if (unified > 0)
1657 c = unified; 1655 c = unified;
1658 } 1656 }
1657#ifdef REL_ALLOC
1658 r_alloc_inhibit_buffer_relocation (0);
1659#endif
1659 return c; 1660 return c;
1660} 1661}
1661 1662
@@ -1840,7 +1841,7 @@ encode_char (struct charset *charset, int c)
1840 } 1841 }
1841 else /* method == CHARSET_METHOD_OFFSET */ 1842 else /* method == CHARSET_METHOD_OFFSET */
1842 { 1843 {
1843 int code_index = c - CHARSET_CODE_OFFSET (charset); 1844 unsigned code_index = c - CHARSET_CODE_OFFSET (charset);
1844 1845
1845 code = INDEX_TO_CODE_POINT (charset, code_index); 1846 code = INDEX_TO_CODE_POINT (charset, code_index);
1846 } 1847 }
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 c7652504de2..979ade70bfc 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. */
@@ -320,7 +320,7 @@ struct glyph
320 buffer, this is a position in that buffer. A value of -1 320 buffer, this is a position in that buffer. A value of -1
321 together with a null object means glyph is a truncation glyph at 321 together with a null object means glyph is a truncation glyph at
322 the start of a row. */ 322 the start of a row. */
323 EMACS_INT charpos; 323 ptrdiff_t charpos;
324 324
325 /* Lisp object source of this glyph. Currently either a buffer or 325 /* Lisp object source of this glyph. Currently either a buffer or
326 a string, if the glyph was produced from characters which came from 326 a string, if the glyph was produced from characters which came from
@@ -1808,7 +1808,7 @@ typedef enum { NEUTRAL_DIR, L2R, R2L } bidi_dir_t;
1808/* Data type for storing information about characters we need to 1808/* Data type for storing information about characters we need to
1809 remember. */ 1809 remember. */
1810struct bidi_saved_info { 1810struct bidi_saved_info {
1811 EMACS_INT bytepos, charpos; /* character's buffer position */ 1811 ptrdiff_t bytepos, charpos; /* character's buffer position */
1812 bidi_type_t type; /* character's resolved bidi type */ 1812 bidi_type_t type; /* character's resolved bidi type */
1813 bidi_type_t type_after_w1; /* original type of the character, after W1 */ 1813 bidi_type_t type_after_w1; /* original type of the character, after W1 */
1814 bidi_type_t orig_type; /* type as we found it in the buffer */ 1814 bidi_type_t orig_type; /* type as we found it in the buffer */
@@ -1825,9 +1825,9 @@ struct bidi_stack {
1825struct bidi_string_data { 1825struct bidi_string_data {
1826 Lisp_Object lstring; /* Lisp string to reorder, or nil */ 1826 Lisp_Object lstring; /* Lisp string to reorder, or nil */
1827 const unsigned char *s; /* string data, or NULL if reordering buffer */ 1827 const unsigned char *s; /* string data, or NULL if reordering buffer */
1828 EMACS_INT schars; /* the number of characters in the string, 1828 ptrdiff_t schars; /* the number of characters in the string,
1829 excluding the terminating null */ 1829 excluding the terminating null */
1830 EMACS_INT bufpos; /* buffer position of lstring, or 0 if N/A */ 1830 ptrdiff_t bufpos; /* buffer position of lstring, or 0 if N/A */
1831 unsigned from_disp_str : 1; /* 1 means the string comes from a 1831 unsigned from_disp_str : 1; /* 1 means the string comes from a
1832 display property */ 1832 display property */
1833 unsigned unibyte : 1; /* 1 means the string is unibyte */ 1833 unsigned unibyte : 1; /* 1 means the string is unibyte */
@@ -1835,14 +1835,14 @@ struct bidi_string_data {
1835 1835
1836/* Data type for reordering bidirectional text. */ 1836/* Data type for reordering bidirectional text. */
1837struct bidi_it { 1837struct bidi_it {
1838 EMACS_INT bytepos; /* iterator's position in buffer/string */ 1838 ptrdiff_t bytepos; /* iterator's position in buffer/string */
1839 EMACS_INT charpos; 1839 ptrdiff_t charpos;
1840 int ch; /* character at that position, or u+FFFC 1840 int ch; /* character at that position, or u+FFFC
1841 ("object replacement character") for a run 1841 ("object replacement character") for a run
1842 of characters covered by a display string */ 1842 of characters covered by a display string */
1843 EMACS_INT nchars; /* its "length", usually 1; it's > 1 for a run 1843 ptrdiff_t nchars; /* its "length", usually 1; it's > 1 for a run
1844 of characters covered by a display string */ 1844 of characters covered by a display string */
1845 EMACS_INT ch_len; /* its length in bytes */ 1845 ptrdiff_t ch_len; /* its length in bytes */
1846 bidi_type_t type; /* bidi type of this character, after 1846 bidi_type_t type; /* bidi type of this character, after
1847 resolving weak and neutral types */ 1847 resolving weak and neutral types */
1848 bidi_type_t type_after_w1; /* original type, after overrides and W1 */ 1848 bidi_type_t type_after_w1; /* original type, after overrides and W1 */
@@ -1856,12 +1856,12 @@ struct bidi_it {
1856 struct bidi_saved_info next_for_neutral; /* surrounding characters for... */ 1856 struct bidi_saved_info next_for_neutral; /* surrounding characters for... */
1857 struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */ 1857 struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */
1858 struct bidi_saved_info next_for_ws; /* character after sequence of ws */ 1858 struct bidi_saved_info next_for_ws; /* character after sequence of ws */
1859 EMACS_INT next_en_pos; /* pos. of next char for determining ET type */ 1859 ptrdiff_t next_en_pos; /* pos. of next char for determining ET type */
1860 bidi_type_t next_en_type; /* type of char at next_en_pos */ 1860 bidi_type_t next_en_type; /* type of char at next_en_pos */
1861 EMACS_INT ignore_bn_limit; /* position until which to ignore BNs */ 1861 ptrdiff_t ignore_bn_limit; /* position until which to ignore BNs */
1862 bidi_dir_t sor; /* direction of start-of-run in effect */ 1862 bidi_dir_t sor; /* direction of start-of-run in effect */
1863 int scan_dir; /* direction of text scan, 1: forw, -1: back */ 1863 int scan_dir; /* direction of text scan, 1: forw, -1: back */
1864 EMACS_INT disp_pos; /* position of display string after ch */ 1864 ptrdiff_t disp_pos; /* position of display string after ch */
1865 int disp_prop; /* if non-zero, there really is a 1865 int disp_prop; /* if non-zero, there really is a
1866 `display' property/string at disp_pos; 1866 `display' property/string at disp_pos;
1867 if 2, the property is a `space' spec */ 1867 if 2, the property is a `space' spec */
@@ -1872,7 +1872,7 @@ struct bidi_it {
1872 struct bidi_stack level_stack[BIDI_MAXLEVEL]; /* stack of embedding levels */ 1872 struct bidi_stack level_stack[BIDI_MAXLEVEL]; /* stack of embedding levels */
1873 struct bidi_string_data string; /* string to reorder */ 1873 struct bidi_string_data string; /* string to reorder */
1874 bidi_dir_t paragraph_dir; /* current paragraph direction */ 1874 bidi_dir_t paragraph_dir; /* current paragraph direction */
1875 EMACS_INT separator_limit; /* where paragraph separator should end */ 1875 ptrdiff_t separator_limit; /* where paragraph separator should end */
1876 unsigned first_elt : 1; /* if non-zero, examine current char first */ 1876 unsigned first_elt : 1; /* if non-zero, examine current char first */
1877 unsigned new_paragraph : 1; /* if non-zero, we expect a new paragraph */ 1877 unsigned new_paragraph : 1; /* if non-zero, we expect a new paragraph */
1878 unsigned frame_window_p : 1; /* non-zero if displaying on a GUI frame */ 1878 unsigned frame_window_p : 1; /* non-zero if displaying on a GUI frame */
@@ -2058,7 +2058,7 @@ enum it_method {
2058struct composition_it 2058struct composition_it
2059{ 2059{
2060 /* Next position at which to check the composition. */ 2060 /* Next position at which to check the composition. */
2061 EMACS_INT stop_pos; 2061 ptrdiff_t stop_pos;
2062 /* ID number of the composition or glyph-string. If negative, we 2062 /* ID number of the composition or glyph-string. If negative, we
2063 are not iterating over a composition now. */ 2063 are not iterating over a composition now. */
2064 ptrdiff_t id; 2064 ptrdiff_t id;
@@ -2076,7 +2076,7 @@ struct composition_it
2076 /* If this is an automatic composition, how many characters to look 2076 /* If this is an automatic composition, how many characters to look
2077 back from the position where a character triggering the 2077 back from the position where a character triggering the
2078 composition exists. */ 2078 composition exists. */
2079 int lookback; 2079 ptrdiff_t lookback;
2080 /* If non-negative, number of glyphs of the glyph-string. */ 2080 /* If non-negative, number of glyphs of the glyph-string. */
2081 int nglyphs; 2081 int nglyphs;
2082 /* Nonzero iff the composition is created while buffer is scanned in 2082 /* Nonzero iff the composition is created while buffer is scanned in
@@ -2087,7 +2087,7 @@ struct composition_it
2087 /** The following members contain information about the current 2087 /** The following members contain information about the current
2088 grapheme cluster. */ 2088 grapheme cluster. */
2089 /* Position of the first character of the current grapheme cluster. */ 2089 /* Position of the first character of the current grapheme cluster. */
2090 EMACS_INT charpos; 2090 ptrdiff_t charpos;
2091 /* Number of characters and bytes of the current grapheme cluster. */ 2091 /* Number of characters and bytes of the current grapheme cluster. */
2092 int nchars, nbytes; 2092 int nchars, nbytes;
2093 /* Indices of the glyphs for the current grapheme cluster. */ 2093 /* Indices of the glyphs for the current grapheme cluster. */
@@ -2112,19 +2112,19 @@ struct it
2112 2112
2113 /* The next position at which to check for face changes, invisible 2113 /* The next position at which to check for face changes, invisible
2114 text, overlay strings, end of text etc., which see. */ 2114 text, overlay strings, end of text etc., which see. */
2115 EMACS_INT stop_charpos; 2115 ptrdiff_t stop_charpos;
2116 2116
2117 /* Previous stop position, i.e. the last one before the current 2117 /* Previous stop position, i.e. the last one before the current
2118 iterator position in `current'. */ 2118 iterator position in `current'. */
2119 EMACS_INT prev_stop; 2119 ptrdiff_t prev_stop;
2120 2120
2121 /* Last stop position iterated across whose bidi embedding level is 2121 /* Last stop position iterated across whose bidi embedding level is
2122 equal to the current paragraph's base embedding level. */ 2122 equal to the current paragraph's base embedding level. */
2123 EMACS_INT base_level_stop; 2123 ptrdiff_t base_level_stop;
2124 2124
2125 /* Maximum string or buffer position + 1. ZV when iterating over 2125 /* Maximum string or buffer position + 1. ZV when iterating over
2126 current_buffer. */ 2126 current_buffer. */
2127 EMACS_INT end_charpos; 2127 ptrdiff_t end_charpos;
2128 2128
2129 /* C string to iterate over. Non-null means get characters from 2129 /* C string to iterate over. Non-null means get characters from
2130 this string, otherwise characters are read from current_buffer 2130 this string, otherwise characters are read from current_buffer
@@ -2133,14 +2133,14 @@ struct it
2133 2133
2134 /* Number of characters in the string (s, or it->string) we iterate 2134 /* Number of characters in the string (s, or it->string) we iterate
2135 over. */ 2135 over. */
2136 EMACS_INT string_nchars; 2136 ptrdiff_t string_nchars;
2137 2137
2138 /* Start and end of a visible region; -1 if the region is not 2138 /* Start and end of a visible region; -1 if the region is not
2139 visible in the window. */ 2139 visible in the window. */
2140 EMACS_INT region_beg_charpos, region_end_charpos; 2140 ptrdiff_t region_beg_charpos, region_end_charpos;
2141 2141
2142 /* Position at which redisplay end trigger functions should be run. */ 2142 /* Position at which redisplay end trigger functions should be run. */
2143 EMACS_INT redisplay_end_trigger_charpos; 2143 ptrdiff_t redisplay_end_trigger_charpos;
2144 2144
2145 /* 1 means multibyte characters are enabled. */ 2145 /* 1 means multibyte characters are enabled. */
2146 unsigned multibyte_p : 1; 2146 unsigned multibyte_p : 1;
@@ -2209,13 +2209,13 @@ struct it
2209 2209
2210 /* Total number of overlay strings to process. This can be > 2210 /* Total number of overlay strings to process. This can be >
2211 OVERLAY_STRING_CHUNK_SIZE. */ 2211 OVERLAY_STRING_CHUNK_SIZE. */
2212 int n_overlay_strings; 2212 ptrdiff_t n_overlay_strings;
2213 2213
2214 /* The charpos where n_overlay_strings was calculated. This should 2214 /* The charpos where n_overlay_strings was calculated. This should
2215 be set at the same time as n_overlay_strings. It is needed 2215 be set at the same time as n_overlay_strings. It is needed
2216 because we show before-strings at the start of invisible text; 2216 because we show before-strings at the start of invisible text;
2217 see handle_invisible_prop in xdisp.c. */ 2217 see handle_invisible_prop in xdisp.c. */
2218 EMACS_INT overlay_strings_charpos; 2218 ptrdiff_t overlay_strings_charpos;
2219 2219
2220 /* Vector of overlays to process. Overlay strings are processed 2220 /* Vector of overlays to process. Overlay strings are processed
2221 OVERLAY_STRING_CHUNK_SIZE at a time. */ 2221 OVERLAY_STRING_CHUNK_SIZE at a time. */
@@ -2242,10 +2242,10 @@ struct it
2242 { 2242 {
2243 Lisp_Object string; 2243 Lisp_Object string;
2244 int string_nchars; 2244 int string_nchars;
2245 EMACS_INT end_charpos; 2245 ptrdiff_t end_charpos;
2246 EMACS_INT stop_charpos; 2246 ptrdiff_t stop_charpos;
2247 EMACS_INT prev_stop; 2247 ptrdiff_t prev_stop;
2248 EMACS_INT base_level_stop; 2248 ptrdiff_t base_level_stop;
2249 struct composition_it cmp_it; 2249 struct composition_it cmp_it;
2250 int face_id; 2250 int face_id;
2251 2251
@@ -2295,7 +2295,7 @@ struct it
2295 2295
2296 /* -1 means selective display hides everything between a \r and the 2296 /* -1 means selective display hides everything between a \r and the
2297 next newline; > 0 means hide lines indented more than that value. */ 2297 next newline; > 0 means hide lines indented more than that value. */
2298 EMACS_INT selective; 2298 ptrdiff_t selective;
2299 2299
2300 /* An enumeration describing what the next display element is 2300 /* An enumeration describing what the next display element is
2301 after a call to get_next_display_element. */ 2301 after a call to get_next_display_element. */
@@ -2989,7 +2989,7 @@ enum tool_bar_item_image
2989 2989
2990/* Defined in bidi.c */ 2990/* Defined in bidi.c */
2991 2991
2992extern void bidi_init_it (EMACS_INT, EMACS_INT, int, struct bidi_it *); 2992extern void bidi_init_it (ptrdiff_t, ptrdiff_t, int, struct bidi_it *);
2993extern void bidi_move_to_visually_next (struct bidi_it *); 2993extern void bidi_move_to_visually_next (struct bidi_it *);
2994extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, int); 2994extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, int);
2995extern int bidi_mirror_char (int); 2995extern int bidi_mirror_char (int);
@@ -3000,11 +3000,11 @@ extern void bidi_unshelve_cache (void *, int);
3000 3000
3001/* Defined in xdisp.c */ 3001/* Defined in xdisp.c */
3002 3002
3003struct glyph_row *row_containing_pos (struct window *, EMACS_INT, 3003struct glyph_row *row_containing_pos (struct window *, ptrdiff_t,
3004 struct glyph_row *, 3004 struct glyph_row *,
3005 struct glyph_row *, int); 3005 struct glyph_row *, int);
3006int line_bottom_y (struct it *); 3006int line_bottom_y (struct it *);
3007int display_prop_intangible_p (Lisp_Object, Lisp_Object, EMACS_INT, EMACS_INT); 3007int display_prop_intangible_p (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3008void resize_echo_area_exactly (void); 3008void resize_echo_area_exactly (void);
3009int resize_mini_window (struct window *, int); 3009int resize_mini_window (struct window *, int);
3010#if defined USE_TOOLKIT_SCROLL_BARS && !defined USE_GTK 3010#if defined USE_TOOLKIT_SCROLL_BARS && !defined USE_GTK
@@ -3026,18 +3026,18 @@ void remember_mouse_glyph (struct frame *, int, int, NativeRectangle *);
3026 3026
3027void mark_window_display_accurate (Lisp_Object, int); 3027void mark_window_display_accurate (Lisp_Object, int);
3028void redisplay_preserve_echo_area (int); 3028void redisplay_preserve_echo_area (int);
3029void init_iterator (struct it *, struct window *, EMACS_INT, 3029void init_iterator (struct it *, struct window *, ptrdiff_t,
3030 EMACS_INT, struct glyph_row *, enum face_id); 3030 ptrdiff_t, struct glyph_row *, enum face_id);
3031void init_iterator_to_row_start (struct it *, struct window *, 3031void init_iterator_to_row_start (struct it *, struct window *,
3032 struct glyph_row *); 3032 struct glyph_row *);
3033void start_display (struct it *, struct window *, struct text_pos); 3033void start_display (struct it *, struct window *, struct text_pos);
3034void move_it_to (struct it *, EMACS_INT, int, int, int, int); 3034void move_it_to (struct it *, ptrdiff_t, int, int, int, int);
3035void move_it_vertically (struct it *, int); 3035void move_it_vertically (struct it *, int);
3036void move_it_vertically_backward (struct it *, int); 3036void move_it_vertically_backward (struct it *, int);
3037void move_it_by_lines (struct it *, int); 3037void move_it_by_lines (struct it *, ptrdiff_t);
3038void move_it_past_eol (struct it *); 3038void move_it_past_eol (struct it *);
3039void move_it_in_display_line (struct it *it, 3039void move_it_in_display_line (struct it *it,
3040 EMACS_INT to_charpos, int to_x, 3040 ptrdiff_t to_charpos, int to_x,
3041 enum move_operation_enum op); 3041 enum move_operation_enum op);
3042int in_display_vector_p (struct it *); 3042int in_display_vector_p (struct it *);
3043int frame_mode_line_height (struct frame *); 3043int frame_mode_line_height (struct frame *);
@@ -3047,15 +3047,15 @@ extern int help_echo_showing_p;
3047extern int current_mode_line_height, current_header_line_height; 3047extern int current_mode_line_height, current_header_line_height;
3048extern Lisp_Object help_echo_string, help_echo_window; 3048extern Lisp_Object help_echo_string, help_echo_window;
3049extern Lisp_Object help_echo_object, previous_help_echo_string; 3049extern Lisp_Object help_echo_object, previous_help_echo_string;
3050extern EMACS_INT help_echo_pos; 3050extern ptrdiff_t help_echo_pos;
3051extern struct frame *last_mouse_frame; 3051extern struct frame *last_mouse_frame;
3052extern int last_tool_bar_item; 3052extern int last_tool_bar_item;
3053extern void reseat_at_previous_visible_line_start (struct it *); 3053extern void reseat_at_previous_visible_line_start (struct it *);
3054extern Lisp_Object lookup_glyphless_char_display (int, struct it *); 3054extern Lisp_Object lookup_glyphless_char_display (int, struct it *);
3055extern EMACS_INT compute_display_string_pos (struct text_pos *, 3055extern ptrdiff_t compute_display_string_pos (struct text_pos *,
3056 struct bidi_string_data *, 3056 struct bidi_string_data *,
3057 int, int *); 3057 int, int *);
3058extern EMACS_INT compute_display_string_end (EMACS_INT, 3058extern ptrdiff_t compute_display_string_end (ptrdiff_t,
3059 struct bidi_string_data *); 3059 struct bidi_string_data *);
3060extern void produce_stretch_glyph (struct it *); 3060extern void produce_stretch_glyph (struct it *);
3061 3061
@@ -3101,7 +3101,7 @@ extern void get_glyph_string_clip_rect (struct glyph_string *,
3101extern Lisp_Object find_hot_spot (Lisp_Object, int, int); 3101extern Lisp_Object find_hot_spot (Lisp_Object, int, int);
3102 3102
3103extern void handle_tool_bar_click (struct frame *, 3103extern void handle_tool_bar_click (struct frame *,
3104 int, int, int, unsigned int); 3104 int, int, int, int);
3105 3105
3106extern void expose_frame (struct frame *, int, int, int, int); 3106extern void expose_frame (struct frame *, int, int, int, int);
3107extern int x_intersect_rectangles (XRectangle *, XRectangle *, 3107extern int x_intersect_rectangles (XRectangle *, XRectangle *,
@@ -3207,19 +3207,19 @@ int lookup_derived_face (struct frame *, Lisp_Object, int, int);
3207void init_frame_faces (struct frame *); 3207void init_frame_faces (struct frame *);
3208void free_frame_faces (struct frame *); 3208void free_frame_faces (struct frame *);
3209void recompute_basic_faces (struct frame *); 3209void recompute_basic_faces (struct frame *);
3210int face_at_buffer_position (struct window *w, EMACS_INT pos, 3210int face_at_buffer_position (struct window *w, ptrdiff_t pos,
3211 EMACS_INT region_beg, EMACS_INT region_end, 3211 ptrdiff_t region_beg, ptrdiff_t region_end,
3212 EMACS_INT *endptr, EMACS_INT limit, 3212 ptrdiff_t *endptr, ptrdiff_t limit,
3213 int mouse, int base_face_id); 3213 int mouse, int base_face_id);
3214int face_for_overlay_string (struct window *w, EMACS_INT pos, 3214int face_for_overlay_string (struct window *w, ptrdiff_t pos,
3215 EMACS_INT region_beg, EMACS_INT region_end, 3215 ptrdiff_t region_beg, ptrdiff_t region_end,
3216 EMACS_INT *endptr, EMACS_INT limit, 3216 ptrdiff_t *endptr, ptrdiff_t limit,
3217 int mouse, Lisp_Object overlay); 3217 int mouse, Lisp_Object overlay);
3218int face_at_string_position (struct window *w, Lisp_Object string, 3218int face_at_string_position (struct window *w, Lisp_Object string,
3219 EMACS_INT pos, EMACS_INT bufpos, 3219 ptrdiff_t pos, ptrdiff_t bufpos,
3220 EMACS_INT region_beg, EMACS_INT region_end, 3220 ptrdiff_t region_beg, ptrdiff_t region_end,
3221 EMACS_INT *endptr, enum face_id, int mouse); 3221 ptrdiff_t *endptr, enum face_id, int mouse);
3222int merge_faces (struct frame *, Lisp_Object, EMACS_INT, int); 3222int merge_faces (struct frame *, Lisp_Object, int, int);
3223int compute_char_face (struct frame *, int, Lisp_Object); 3223int compute_char_face (struct frame *, int, Lisp_Object);
3224void free_all_realized_faces (Lisp_Object); 3224void free_all_realized_faces (Lisp_Object);
3225extern Lisp_Object Qforeground_color, Qbackground_color; 3225extern Lisp_Object Qforeground_color, Qbackground_color;
@@ -3284,11 +3284,11 @@ extern Lisp_Object buffer_posn_from_coords (struct window *,
3284 Lisp_Object *, 3284 Lisp_Object *,
3285 int *, int *, int *, int *); 3285 int *, int *, int *, int *);
3286extern Lisp_Object mode_line_string (struct window *, enum window_part, 3286extern Lisp_Object mode_line_string (struct window *, enum window_part,
3287 int *, int *, EMACS_INT *, 3287 int *, int *, ptrdiff_t *,
3288 Lisp_Object *, 3288 Lisp_Object *,
3289 int *, int *, int *, int *); 3289 int *, int *, int *, int *);
3290extern Lisp_Object marginal_area_string (struct window *, enum window_part, 3290extern Lisp_Object marginal_area_string (struct window *, enum window_part,
3291 int *, int *, EMACS_INT *, 3291 int *, int *, ptrdiff_t *,
3292 Lisp_Object *, 3292 Lisp_Object *,
3293 int *, int *, int *, int *); 3293 int *, int *, int *, int *);
3294extern void redraw_frame (struct frame *); 3294extern void redraw_frame (struct frame *);
@@ -3308,7 +3308,7 @@ void shift_glyph_matrix (struct window *, struct glyph_matrix *,
3308 int, int, int); 3308 int, int, int);
3309void rotate_matrix (struct glyph_matrix *, int, int, int); 3309void rotate_matrix (struct glyph_matrix *, int, int, int);
3310void increment_matrix_positions (struct glyph_matrix *, 3310void increment_matrix_positions (struct glyph_matrix *,
3311 int, int, EMACS_INT, EMACS_INT); 3311 int, int, ptrdiff_t, ptrdiff_t);
3312void blank_row (struct window *, struct glyph_row *, int); 3312void blank_row (struct window *, struct glyph_row *, int);
3313void enable_glyph_matrix_rows (struct glyph_matrix *, int, int, int); 3313void enable_glyph_matrix_rows (struct glyph_matrix *, int, int, int);
3314void clear_glyph_row (struct glyph_row *); 3314void clear_glyph_row (struct glyph_row *);
diff --git a/src/dispnew.c b/src/dispnew.c
index a50877a6a90..a23f2b9a959 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -109,7 +109,7 @@ static int required_matrix_height (struct window *);
109static int required_matrix_width (struct window *); 109static int required_matrix_width (struct window *);
110static void adjust_frame_glyphs (struct frame *); 110static void adjust_frame_glyphs (struct frame *);
111static void change_frame_size_1 (struct frame *, int, int, int, int, int); 111static void change_frame_size_1 (struct frame *, int, int, int, int, int);
112static void increment_row_positions (struct glyph_row *, EMACS_INT, EMACS_INT); 112static void increment_row_positions (struct glyph_row *, ptrdiff_t, ptrdiff_t);
113static void fill_up_frame_row_with_spaces (struct glyph_row *, int); 113static void fill_up_frame_row_with_spaces (struct glyph_row *, int);
114static void build_frame_matrix_from_window_tree (struct glyph_matrix *, 114static void build_frame_matrix_from_window_tree (struct glyph_matrix *,
115 struct window *); 115 struct window *);
@@ -332,11 +332,13 @@ DEFUN ("dump-redisplay-history", Fdump_redisplay_history,
332#endif /* GLYPH_DEBUG == 0 */ 332#endif /* GLYPH_DEBUG == 0 */
333 333
334 334
335#if defined PROFILING && !HAVE___EXECUTABLE_START 335#if (defined PROFILING \
336/* FIXME: only used to find text start for profiling. */ 336 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__) \
337 337 && !HAVE___EXECUTABLE_START)
338/* This function comes first in the Emacs executable and is used only
339 to estimate the text start for profiling. */
338void 340void
339safe_bcopy (const char *from, char *to, int size) 341__executable_start (void)
340{ 342{
341 abort (); 343 abort ();
342} 344}
@@ -759,7 +761,7 @@ rotate_matrix (struct glyph_matrix *matrix, int first, int last, int by)
759 761
760void 762void
761increment_matrix_positions (struct glyph_matrix *matrix, int start, int end, 763increment_matrix_positions (struct glyph_matrix *matrix, int start, int end,
762 EMACS_INT delta, EMACS_INT delta_bytes) 764 ptrdiff_t delta, ptrdiff_t delta_bytes)
763{ 765{
764 /* Check that START and END are reasonable values. */ 766 /* Check that START and END are reasonable values. */
765 xassert (start >= 0 && start <= matrix->nrows); 767 xassert (start >= 0 && start <= matrix->nrows);
@@ -1001,7 +1003,7 @@ blank_row (struct window *w, struct glyph_row *row, int y)
1001 1003
1002static void 1004static void
1003increment_row_positions (struct glyph_row *row, 1005increment_row_positions (struct glyph_row *row,
1004 EMACS_INT delta, EMACS_INT delta_bytes) 1006 ptrdiff_t delta, ptrdiff_t delta_bytes)
1005{ 1007{
1006 int area, i; 1008 int area, i;
1007 1009
@@ -2547,8 +2549,7 @@ build_frame_matrix_from_leaf_window (struct glyph_matrix *frame_matrix, struct w
2547 2549
2548 SET_GLYPH_FROM_CHAR (right_border_glyph, '|'); 2550 SET_GLYPH_FROM_CHAR (right_border_glyph, '|');
2549 if (dp 2551 if (dp
2550 && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc)) 2552 && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc)))
2551 && GLYPH_CODE_CHAR_VALID_P (gc))
2552 { 2553 {
2553 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc); 2554 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc);
2554 spec_glyph_lookup_face (w, &right_border_glyph); 2555 spec_glyph_lookup_face (w, &right_border_glyph);
@@ -5479,7 +5480,7 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p
5479 5480
5480Lisp_Object 5481Lisp_Object
5481mode_line_string (struct window *w, enum window_part part, 5482mode_line_string (struct window *w, enum window_part part,
5482 int *x, int *y, EMACS_INT *charpos, Lisp_Object *object, 5483 int *x, int *y, ptrdiff_t *charpos, Lisp_Object *object,
5483 int *dx, int *dy, int *width, int *height) 5484 int *dx, int *dy, int *width, int *height)
5484{ 5485{
5485 struct glyph_row *row; 5486 struct glyph_row *row;
@@ -5548,7 +5549,7 @@ mode_line_string (struct window *w, enum window_part part,
5548 5549
5549Lisp_Object 5550Lisp_Object
5550marginal_area_string (struct window *w, enum window_part part, 5551marginal_area_string (struct window *w, enum window_part part,
5551 int *x, int *y, EMACS_INT *charpos, Lisp_Object *object, 5552 int *x, int *y, ptrdiff_t *charpos, Lisp_Object *object,
5552 int *dx, int *dy, int *width, int *height) 5553 int *dx, int *dy, int *width, int *height)
5553{ 5554{
5554 struct glyph_row *row = w->current_matrix->rows; 5555 struct glyph_row *row = w->current_matrix->rows;
@@ -5745,7 +5746,7 @@ static void
5745change_frame_size_1 (register struct frame *f, int newheight, int newwidth, int pretend, int delay, int safe) 5746change_frame_size_1 (register struct frame *f, int newheight, int newwidth, int pretend, int delay, int safe)
5746{ 5747{
5747 int new_frame_total_cols; 5748 int new_frame_total_cols;
5748 int count = SPECPDL_INDEX (); 5749 ptrdiff_t count = SPECPDL_INDEX ();
5749 5750
5750 /* If we can't deal with the change now, queue it for later. */ 5751 /* If we can't deal with the change now, queue it for later. */
5751 if (delay || (redisplaying_p && !safe)) 5752 if (delay || (redisplaying_p && !safe))
@@ -5966,6 +5967,38 @@ bitch_at_user (void)
5966 Sleeping, Waiting 5967 Sleeping, Waiting
5967 ***********************************************************************/ 5968 ***********************************************************************/
5968 5969
5970/* Convert a positive value DURATION to a seconds count *PSEC plus a
5971 microseconds count *PUSEC, rounding up. On overflow return the
5972 maximal value. */
5973void
5974duration_to_sec_usec (double duration, int *psec, int *pusec)
5975{
5976 int MILLION = 1000000;
5977 int sec = INT_MAX, usec = MILLION - 1;
5978
5979 if (duration < INT_MAX + 1.0)
5980 {
5981 int s = duration;
5982 double usdouble = (duration - s) * MILLION;
5983 int usfloor = usdouble;
5984 int usceil = usfloor + (usfloor < usdouble);
5985
5986 if (usceil < MILLION)
5987 {
5988 sec = s;
5989 usec = usceil;
5990 }
5991 else if (sec < INT_MAX)
5992 {
5993 sec = s + 1;
5994 usec = 0;
5995 }
5996 }
5997
5998 *psec = sec;
5999 *pusec = usec;
6000}
6001
5969DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0, 6002DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
5970 doc: /* Pause, without updating display, for SECONDS seconds. 6003 doc: /* Pause, without updating display, for SECONDS seconds.
5971SECONDS may be a floating-point value, meaning that you can wait for a 6004SECONDS may be a floating-point value, meaning that you can wait for a
@@ -5976,39 +6009,24 @@ Emacs was built without floating point support.
5976 (Lisp_Object seconds, Lisp_Object milliseconds) 6009 (Lisp_Object seconds, Lisp_Object milliseconds)
5977{ 6010{
5978 int sec, usec; 6011 int sec, usec;
6012 double duration = extract_float (seconds);
5979 6013
5980 if (NILP (milliseconds)) 6014 if (!NILP (milliseconds))
5981 XSETINT (milliseconds, 0); 6015 {
5982 else 6016 CHECK_NUMBER (milliseconds);
5983 CHECK_NUMBER (milliseconds); 6017 duration += XINT (milliseconds) / 1000.0;
5984 usec = XINT (milliseconds) * 1000; 6018 }
5985 6019
5986 { 6020 if (! (0 < duration))
5987 double duration = extract_float (seconds); 6021 return Qnil;
5988 sec = (int) duration; 6022
5989 usec += (duration - sec) * 1000000; 6023 duration_to_sec_usec (duration, &sec, &usec);
5990 }
5991 6024
5992#ifndef EMACS_HAS_USECS 6025#ifndef EMACS_HAS_USECS
5993 if (sec == 0 && usec != 0) 6026 if (sec == 0 && usec != 0)
5994 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE); 6027 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE);
5995#endif 6028#endif
5996 6029
5997 /* Assure that 0 <= usec < 1000000. */
5998 if (usec < 0)
5999 {
6000 /* We can't rely on the rounding being correct if usec is negative. */
6001 if (-1000000 < usec)
6002 sec--, usec += 1000000;
6003 else
6004 sec -= -usec / 1000000, usec = 1000000 - (-usec % 1000000);
6005 }
6006 else
6007 sec += usec / 1000000, usec %= 1000000;
6008
6009 if (sec < 0 || (sec == 0 && usec == 0))
6010 return Qnil;
6011
6012 wait_reading_process_output (sec, usec, 0, 0, Qnil, NULL, 0); 6030 wait_reading_process_output (sec, usec, 0, 0, Qnil, NULL, 0);
6013 6031
6014 return Qnil; 6032 return Qnil;
@@ -6039,27 +6057,20 @@ sit_for (Lisp_Object timeout, int reading, int do_display)
6039 if (do_display >= 2) 6057 if (do_display >= 2)
6040 redisplay_preserve_echo_area (2); 6058 redisplay_preserve_echo_area (2);
6041 6059
6042 if (INTEGERP (timeout)) 6060 if (EQ (timeout, Qt))
6043 {
6044 sec = XINT (timeout);
6045 usec = 0;
6046 }
6047 else if (FLOATP (timeout))
6048 {
6049 double seconds = XFLOAT_DATA (timeout);
6050 sec = (int) seconds;
6051 usec = (int) ((seconds - sec) * 1000000);
6052 }
6053 else if (EQ (timeout, Qt))
6054 { 6061 {
6055 sec = 0; 6062 sec = 0;
6056 usec = 0; 6063 usec = 0;
6057 } 6064 }
6058 else 6065 else
6059 wrong_type_argument (Qnumberp, timeout); 6066 {
6067 double duration = extract_float (timeout);
6060 6068
6061 if (sec == 0 && usec == 0 && !EQ (timeout, Qt)) 6069 if (! (0 < duration))
6062 return Qt; 6070 return Qt;
6071
6072 duration_to_sec_usec (duration, &sec, &usec);
6073 }
6063 6074
6064#ifdef SIGIO 6075#ifdef SIGIO
6065 gobble_input (0); 6076 gobble_input (0);
@@ -6083,7 +6094,7 @@ Return t if redisplay was performed, nil if redisplay was preempted
6083immediately by pending input. */) 6094immediately by pending input. */)
6084 (Lisp_Object force) 6095 (Lisp_Object force)
6085{ 6096{
6086 int count; 6097 ptrdiff_t count;
6087 6098
6088 swallow_events (1); 6099 swallow_events (1);
6089 if ((detect_input_pending_run_timers (1) 6100 if ((detect_input_pending_run_timers (1)
@@ -6129,7 +6140,7 @@ pass nil for VARIABLE. */)
6129{ 6140{
6130 Lisp_Object state, tail, frame, buf; 6141 Lisp_Object state, tail, frame, buf;
6131 Lisp_Object *vecp, *end; 6142 Lisp_Object *vecp, *end;
6132 int n; 6143 ptrdiff_t n;
6133 6144
6134 if (! NILP (variable)) 6145 if (! NILP (variable))
6135 { 6146 {
diff --git a/src/doc.c b/src/doc.c
index 9e48a4d49f3..cd23d9266a2 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;
@@ -701,18 +705,23 @@ the same file name is found in the `doc-directory'. */)
701DEFUN ("substitute-command-keys", Fsubstitute_command_keys, 705DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
702 Ssubstitute_command_keys, 1, 1, 0, 706 Ssubstitute_command_keys, 1, 1, 0,
703 doc: /* Substitute key descriptions for command names in STRING. 707 doc: /* Substitute key descriptions for command names in STRING.
704Substrings of the form \\=\\[COMMAND] replaced by either: a keystroke 708Each substring of the form \\=\\[COMMAND] is replaced by either a
705sequence that will invoke COMMAND, or "M-x COMMAND" if COMMAND is not 709keystroke sequence that invokes COMMAND, or "M-x COMMAND" if COMMAND
706on any keys. 710is not on any keys.
707Substrings of the form \\=\\{MAPVAR} are replaced by summaries 711
708\(made by `describe-bindings') of the value of MAPVAR, taken as a keymap. 712Each substring of the form \\=\\{MAPVAR} is replaced by a summary of
709Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR 713the value of MAPVAR as a keymap. This summary is similar to the one
714produced by `describe-bindings'. The summary ends in two newlines
715\(used by the helper function `help-make-xrefs' to find the end of the
716summary).
717
718Each substring of the form \\=\\<MAPVAR> specifies the use of MAPVAR
710as the keymap for future \\=\\[COMMAND] substrings. 719as the keymap for future \\=\\[COMMAND] substrings.
711\\=\\= quotes the following character and is discarded; 720\\=\\= quotes the following character and is discarded;
712thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output. 721thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.
713 722
714Returns original STRING if no substitutions were made. Otherwise, 723Return the original STRING if no substitutions are made.
715a new string, without any text properties, is returned. */) 724Otherwise, return a new string, without any text properties. */)
716 (Lisp_Object string) 725 (Lisp_Object string)
717{ 726{
718 char *buf; 727 char *buf;
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 d266ca9951d..8f7b2aee76c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -59,10 +59,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
59#include "window.h" 59#include "window.h"
60#include "blockinput.h" 60#include "blockinput.h"
61 61
62#ifndef NULL
63#define NULL 0
64#endif
65
66#ifndef USER_FULL_NAME 62#ifndef USER_FULL_NAME
67#define USER_FULL_NAME pw->pw_gecos 63#define USER_FULL_NAME pw->pw_gecos
68#endif 64#endif
@@ -81,7 +77,7 @@ static void time_overflow (void) NO_RETURN;
81static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object, 77static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object,
82 int, time_t *, struct tm *); 78 int, time_t *, struct tm *);
83static int tm_diff (struct tm *, struct tm *); 79static int tm_diff (struct tm *, struct tm *);
84static void update_buffer_properties (EMACS_INT, EMACS_INT); 80static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
85 81
86static Lisp_Object Qbuffer_access_fontify_functions; 82static Lisp_Object Qbuffer_access_fontify_functions;
87static Lisp_Object Fuser_full_name (Lisp_Object); 83static Lisp_Object Fuser_full_name (Lisp_Object);
@@ -141,8 +137,14 @@ init_editfns (void)
141 /* If the user name claimed in the environment vars differs from 137 /* If the user name claimed in the environment vars differs from
142 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. */
143 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); 139 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
144 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid ()) 140 if (! NILP (tem))
145 : 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);
146 148
147 p = getenv ("NAME"); 149 p = getenv ("NAME");
148 if (p) 150 if (p)
@@ -207,7 +209,7 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
207} 209}
208 210
209static Lisp_Object 211static Lisp_Object
210buildmark (EMACS_INT charpos, EMACS_INT bytepos) 212buildmark (ptrdiff_t charpos, ptrdiff_t bytepos)
211{ 213{
212 register Lisp_Object mark; 214 register Lisp_Object mark;
213 mark = Fmake_marker (); 215 mark = Fmake_marker ();
@@ -232,17 +234,6 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
232 return buildmark (PT, PT_BYTE); 234 return buildmark (PT, PT_BYTE);
233} 235}
234 236
235EMACS_INT
236clip_to_bounds (EMACS_INT lower, EMACS_INT num, EMACS_INT upper)
237{
238 if (num < lower)
239 return lower;
240 else if (num > upper)
241 return upper;
242 else
243 return num;
244}
245
246DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", 237DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
247 doc: /* Set point to POSITION, a number or marker. 238 doc: /* Set point to POSITION, a number or marker.
248Beginning of buffer is position (point-min), end is (point-max). 239Beginning of buffer is position (point-min), end is (point-max).
@@ -250,7 +241,7 @@ Beginning of buffer is position (point-min), end is (point-max).
250The return value is POSITION. */) 241The return value is POSITION. */)
251 (register Lisp_Object position) 242 (register Lisp_Object position)
252{ 243{
253 EMACS_INT pos; 244 ptrdiff_t pos;
254 245
255 if (MARKERP (position) 246 if (MARKERP (position)
256 && current_buffer == XMARKER (position)->buffer) 247 && current_buffer == XMARKER (position)->buffer)
@@ -330,7 +321,7 @@ overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
330{ 321{
331 Lisp_Object overlay, start, end; 322 Lisp_Object overlay, start, end;
332 struct Lisp_Overlay *tail; 323 struct Lisp_Overlay *tail;
333 EMACS_INT startpos, endpos; 324 ptrdiff_t startpos, endpos;
334 ptrdiff_t idx = 0; 325 ptrdiff_t idx = 0;
335 326
336 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 327 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
@@ -479,7 +470,7 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
479static void 470static void
480find_field (Lisp_Object pos, Lisp_Object merge_at_boundary, 471find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
481 Lisp_Object beg_limit, 472 Lisp_Object beg_limit,
482 EMACS_INT *beg, Lisp_Object end_limit, EMACS_INT *end) 473 ptrdiff_t *beg, Lisp_Object end_limit, ptrdiff_t *end)
483{ 474{
484 /* Fields right before and after the point. */ 475 /* Fields right before and after the point. */
485 Lisp_Object before_field, after_field; 476 Lisp_Object before_field, after_field;
@@ -595,7 +586,7 @@ A field is a region of text with the same `field' property.
595If POS is nil, the value of point is used for POS. */) 586If POS is nil, the value of point is used for POS. */)
596 (Lisp_Object pos) 587 (Lisp_Object pos)
597{ 588{
598 EMACS_INT beg, end; 589 ptrdiff_t beg, end;
599 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 590 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
600 if (beg != end) 591 if (beg != end)
601 del_range (beg, end); 592 del_range (beg, end);
@@ -608,7 +599,7 @@ A field is a region of text with the same `field' property.
608If POS is nil, the value of point is used for POS. */) 599If POS is nil, the value of point is used for POS. */)
609 (Lisp_Object pos) 600 (Lisp_Object pos)
610{ 601{
611 EMACS_INT beg, end; 602 ptrdiff_t beg, end;
612 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 603 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
613 return make_buffer_string (beg, end, 1); 604 return make_buffer_string (beg, end, 1);
614} 605}
@@ -619,7 +610,7 @@ A field is a region of text with the same `field' property.
619If POS is nil, the value of point is used for POS. */) 610If POS is nil, the value of point is used for POS. */)
620 (Lisp_Object pos) 611 (Lisp_Object pos)
621{ 612{
622 EMACS_INT beg, end; 613 ptrdiff_t beg, end;
623 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 614 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
624 return make_buffer_string (beg, end, 0); 615 return make_buffer_string (beg, end, 0);
625} 616}
@@ -634,7 +625,7 @@ If LIMIT is non-nil, it is a buffer position; if the beginning of the field
634is before LIMIT, then LIMIT will be returned instead. */) 625is before LIMIT, then LIMIT will be returned instead. */)
635 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 626 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
636{ 627{
637 EMACS_INT beg; 628 ptrdiff_t beg;
638 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0); 629 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0);
639 return make_number (beg); 630 return make_number (beg);
640} 631}
@@ -649,7 +640,7 @@ If LIMIT is non-nil, it is a buffer position; if the end of the field
649is after LIMIT, then LIMIT will be returned instead. */) 640is after LIMIT, then LIMIT will be returned instead. */)
650 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 641 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
651{ 642{
652 EMACS_INT end; 643 ptrdiff_t end;
653 find_field (pos, escape_from_edge, Qnil, 0, limit, &end); 644 find_field (pos, escape_from_edge, Qnil, 0, limit, &end);
654 return make_number (end); 645 return make_number (end);
655} 646}
@@ -685,7 +676,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
685 (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)
686{ 677{
687 /* If non-zero, then the original point, before re-positioning. */ 678 /* If non-zero, then the original point, before re-positioning. */
688 EMACS_INT orig_point = 0; 679 ptrdiff_t orig_point = 0;
689 int fwd; 680 int fwd;
690 Lisp_Object prev_old, prev_new; 681 Lisp_Object prev_old, prev_new;
691 682
@@ -699,10 +690,10 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
699 CHECK_NUMBER_COERCE_MARKER (new_pos); 690 CHECK_NUMBER_COERCE_MARKER (new_pos);
700 CHECK_NUMBER_COERCE_MARKER (old_pos); 691 CHECK_NUMBER_COERCE_MARKER (old_pos);
701 692
702 fwd = (XFASTINT (new_pos) > XFASTINT (old_pos)); 693 fwd = (XINT (new_pos) > XINT (old_pos));
703 694
704 prev_old = make_number (XFASTINT (old_pos) - 1); 695 prev_old = make_number (XINT (old_pos) - 1);
705 prev_new = make_number (XFASTINT (new_pos) - 1); 696 prev_new = make_number (XINT (new_pos) - 1);
706 697
707 if (NILP (Vinhibit_field_text_motion) 698 if (NILP (Vinhibit_field_text_motion)
708 && !EQ (new_pos, old_pos) 699 && !EQ (new_pos, old_pos)
@@ -727,7 +718,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
727 /* 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
728 OLD_POS; try to move NEW_POS so that it is. */ 719 OLD_POS; try to move NEW_POS so that it is. */
729 { 720 {
730 EMACS_INT shortage; 721 ptrdiff_t shortage;
731 Lisp_Object field_bound; 722 Lisp_Object field_bound;
732 723
733 if (fwd) 724 if (fwd)
@@ -782,8 +773,8 @@ boundaries bind `inhibit-field-text-motion' to t.
782This function does not move point. */) 773This function does not move point. */)
783 (Lisp_Object n) 774 (Lisp_Object n)
784{ 775{
785 EMACS_INT orig, orig_byte, end; 776 ptrdiff_t orig, orig_byte, end;
786 int count = SPECPDL_INDEX (); 777 ptrdiff_t count = SPECPDL_INDEX ();
787 specbind (Qinhibit_point_motion_hooks, Qt); 778 specbind (Qinhibit_point_motion_hooks, Qt);
788 779
789 if (NILP (n)) 780 if (NILP (n))
@@ -823,15 +814,17 @@ boundaries bind `inhibit-field-text-motion' to t.
823This function does not move point. */) 814This function does not move point. */)
824 (Lisp_Object n) 815 (Lisp_Object n)
825{ 816{
826 EMACS_INT end_pos; 817 ptrdiff_t clipped_n;
827 EMACS_INT orig = PT; 818 ptrdiff_t end_pos;
819 ptrdiff_t orig = PT;
828 820
829 if (NILP (n)) 821 if (NILP (n))
830 XSETFASTINT (n, 1); 822 XSETFASTINT (n, 1);
831 else 823 else
832 CHECK_NUMBER (n); 824 CHECK_NUMBER (n);
833 825
834 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));
835 828
836 /* Return END_POS constrained to the current input field. */ 829 /* Return END_POS constrained to the current input field. */
837 return Fconstrain_to_field (make_number (end_pos), make_number (orig), 830 return Fconstrain_to_field (make_number (end_pos), make_number (orig),
@@ -958,7 +951,7 @@ usage: (save-excursion &rest BODY) */)
958 (Lisp_Object args) 951 (Lisp_Object args)
959{ 952{
960 register Lisp_Object val; 953 register Lisp_Object val;
961 int count = SPECPDL_INDEX (); 954 ptrdiff_t count = SPECPDL_INDEX ();
962 955
963 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 956 record_unwind_protect (save_excursion_restore, save_excursion_save ());
964 957
@@ -973,7 +966,7 @@ usage: (save-current-buffer &rest BODY) */)
973 (Lisp_Object args) 966 (Lisp_Object args)
974{ 967{
975 Lisp_Object val; 968 Lisp_Object val;
976 int count = SPECPDL_INDEX (); 969 ptrdiff_t count = SPECPDL_INDEX ();
977 970
978 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); 971 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
979 972
@@ -1099,7 +1092,7 @@ At the beginning of the buffer or accessible region, return 0. */)
1099 XSETFASTINT (temp, 0); 1092 XSETFASTINT (temp, 0);
1100 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 1093 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1101 { 1094 {
1102 EMACS_INT pos = PT_BYTE; 1095 ptrdiff_t pos = PT_BYTE;
1103 DEC_POS (pos); 1096 DEC_POS (pos);
1104 XSETFASTINT (temp, FETCH_CHAR (pos)); 1097 XSETFASTINT (temp, FETCH_CHAR (pos));
1105 } 1098 }
@@ -1153,7 +1146,7 @@ POS is an integer or a marker and defaults to point.
1153If POS is out of range, the value is nil. */) 1146If POS is out of range, the value is nil. */)
1154 (Lisp_Object pos) 1147 (Lisp_Object pos)
1155{ 1148{
1156 register EMACS_INT pos_byte; 1149 register ptrdiff_t pos_byte;
1157 1150
1158 if (NILP (pos)) 1151 if (NILP (pos))
1159 { 1152 {
@@ -1186,7 +1179,7 @@ If POS is out of range, the value is nil. */)
1186 (Lisp_Object pos) 1179 (Lisp_Object pos)
1187{ 1180{
1188 register Lisp_Object val; 1181 register Lisp_Object val;
1189 register EMACS_INT pos_byte; 1182 register ptrdiff_t pos_byte;
1190 1183
1191 if (NILP (pos)) 1184 if (NILP (pos))
1192 { 1185 {
@@ -1246,7 +1239,7 @@ of the user with that uid, or nil if there is no such user. */)
1246 if (NILP (uid)) 1239 if (NILP (uid))
1247 return Vuser_login_name; 1240 return Vuser_login_name;
1248 1241
1249 id = XFLOATINT (uid); 1242 CONS_TO_INTEGER (uid, uid_t, id);
1250 BLOCK_INPUT; 1243 BLOCK_INPUT;
1251 pw = getpwuid (id); 1244 pw = getpwuid (id);
1252 UNBLOCK_INPUT; 1245 UNBLOCK_INPUT;
@@ -1273,14 +1266,7 @@ DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
1273Value is an integer or a float, depending on the value. */) 1266Value is an integer or a float, depending on the value. */)
1274 (void) 1267 (void)
1275{ 1268{
1276 /* Assignment to EMACS_INT stops GCC whining about limited range of 1269 uid_t euid = geteuid ();
1277 data type. */
1278 EMACS_INT euid = geteuid ();
1279
1280 /* Make sure we don't produce a negative UID due to signed integer
1281 overflow. */
1282 if (euid < 0)
1283 return make_float (geteuid ());
1284 return make_fixnum_or_float (euid); 1270 return make_fixnum_or_float (euid);
1285} 1271}
1286 1272
@@ -1289,14 +1275,7 @@ DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
1289Value is an integer or a float, depending on the value. */) 1275Value is an integer or a float, depending on the value. */)
1290 (void) 1276 (void)
1291{ 1277{
1292 /* Assignment to EMACS_INT stops GCC whining about limited range of 1278 uid_t uid = getuid ();
1293 data type. */
1294 EMACS_INT uid = getuid ();
1295
1296 /* Make sure we don't produce a negative UID due to signed integer
1297 overflow. */
1298 if (uid < 0)
1299 return make_float (getuid ());
1300 return make_fixnum_or_float (uid); 1279 return make_fixnum_or_float (uid);
1301} 1280}
1302 1281
@@ -1319,7 +1298,8 @@ name, or nil if there is no such user. */)
1319 return Vuser_full_name; 1298 return Vuser_full_name;
1320 else if (NUMBERP (uid)) 1299 else if (NUMBERP (uid))
1321 { 1300 {
1322 uid_t u = XFLOATINT (uid); 1301 uid_t u;
1302 CONS_TO_INTEGER (uid, uid_t, u);
1323 BLOCK_INPUT; 1303 BLOCK_INPUT;
1324 pw = getpwuid (u); 1304 pw = getpwuid (u);
1325 UNBLOCK_INPUT; 1305 UNBLOCK_INPUT;
@@ -1381,10 +1361,11 @@ get_system_name (void)
1381} 1361}
1382 1362
1383DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0, 1363DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
1384 doc: /* Return the process ID of Emacs, as an integer. */) 1364 doc: /* Return the process ID of Emacs, as a number. */)
1385 (void) 1365 (void)
1386{ 1366{
1387 return make_number (getpid ()); 1367 pid_t pid = getpid ();
1368 return make_fixnum_or_float (pid);
1388} 1369}
1389 1370
1390 1371
@@ -1424,7 +1405,7 @@ hi_time (time_t t)
1424} 1405}
1425 1406
1426/* Return the bottom 16 bits of the time T. */ 1407/* Return the bottom 16 bits of the time T. */
1427static EMACS_INT 1408static int
1428lo_time (time_t t) 1409lo_time (time_t t)
1429{ 1410{
1430 return t & ((1 << 16) - 1); 1411 return t & ((1 << 16) - 1);
@@ -1542,6 +1523,8 @@ lisp_time_argument (Lisp_Object specified_time, time_t *result, int *usec)
1542 else 1523 else
1543 { 1524 {
1544 CHECK_NUMBER (usec_l); 1525 CHECK_NUMBER (usec_l);
1526 if (! (0 <= XINT (usec_l) && XINT (usec_l) < 1000000))
1527 return 0;
1545 *usec = XINT (usec_l); 1528 *usec = XINT (usec_l);
1546 } 1529 }
1547 } 1530 }
@@ -1712,7 +1695,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1712{ 1695{
1713 char buffer[4000]; 1696 char buffer[4000];
1714 char *buf = buffer; 1697 char *buf = buffer;
1715 size_t size = sizeof buffer; 1698 ptrdiff_t size = sizeof buffer;
1716 size_t len; 1699 size_t len;
1717 Lisp_Object bufstring; 1700 Lisp_Object bufstring;
1718 int usec; 1701 int usec;
@@ -1720,8 +1703,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1720 struct tm *tm; 1703 struct tm *tm;
1721 USE_SAFE_ALLOCA; 1704 USE_SAFE_ALLOCA;
1722 1705
1723 if (! (lisp_time_argument (timeval, tval, &usec) 1706 if (! lisp_time_argument (timeval, tval, &usec))
1724 && 0 <= usec && usec < 1000000))
1725 error ("Invalid time specification"); 1707 error ("Invalid time specification");
1726 ns = usec * 1000; 1708 ns = usec * 1000;
1727 1709
@@ -1885,9 +1867,12 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1885 tzstring = SSDATA (zone); 1867 tzstring = SSDATA (zone);
1886 else if (INTEGERP (zone)) 1868 else if (INTEGERP (zone))
1887 { 1869 {
1888 int abszone = eabs (XINT (zone)); 1870 EMACS_INT abszone = eabs (XINT (zone));
1889 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0), 1871 EMACS_INT zone_hr = abszone / (60*60);
1890 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);
1891 tzstring = tzbuf; 1876 tzstring = tzbuf;
1892 } 1877 }
1893 else 1878 else
@@ -2193,10 +2178,10 @@ set_time_zone_rule (const char *tzstring)
2193 2178
2194static void 2179static void
2195general_insert_function (void (*insert_func) 2180general_insert_function (void (*insert_func)
2196 (const char *, EMACS_INT), 2181 (const char *, ptrdiff_t),
2197 void (*insert_from_string_func) 2182 void (*insert_from_string_func)
2198 (Lisp_Object, EMACS_INT, EMACS_INT, 2183 (Lisp_Object, ptrdiff_t, ptrdiff_t,
2199 EMACS_INT, EMACS_INT, int), 2184 ptrdiff_t, ptrdiff_t, int),
2200 int inherit, ptrdiff_t nargs, Lisp_Object *args) 2185 int inherit, ptrdiff_t nargs, Lisp_Object *args)
2201{ 2186{
2202 ptrdiff_t argnum; 2187 ptrdiff_t argnum;
@@ -2332,7 +2317,7 @@ from adjoining text, if those properties are sticky. */)
2332 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit) 2317 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
2333{ 2318{
2334 int i, stringlen; 2319 int i, stringlen;
2335 register EMACS_INT n; 2320 register ptrdiff_t n;
2336 int c, len; 2321 int c, len;
2337 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2322 unsigned char str[MAX_MULTIBYTE_LENGTH];
2338 char string[4000]; 2323 char string[4000];
@@ -2408,10 +2393,10 @@ from adjoining text, if those properties are sticky. */)
2408 buffer substrings. */ 2393 buffer substrings. */
2409 2394
2410Lisp_Object 2395Lisp_Object
2411make_buffer_string (EMACS_INT start, EMACS_INT end, int props) 2396make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
2412{ 2397{
2413 EMACS_INT start_byte = CHAR_TO_BYTE (start); 2398 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
2414 EMACS_INT end_byte = CHAR_TO_BYTE (end); 2399 ptrdiff_t end_byte = CHAR_TO_BYTE (end);
2415 2400
2416 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);
2417} 2402}
@@ -2432,8 +2417,8 @@ make_buffer_string (EMACS_INT start, EMACS_INT end, int props)
2432 buffer substrings. */ 2417 buffer substrings. */
2433 2418
2434Lisp_Object 2419Lisp_Object
2435make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte, 2420make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
2436 EMACS_INT end, EMACS_INT end_byte, int props) 2421 ptrdiff_t end, ptrdiff_t end_byte, int props)
2437{ 2422{
2438 Lisp_Object result, tem, tem1; 2423 Lisp_Object result, tem, tem1;
2439 2424
@@ -2466,7 +2451,7 @@ make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte,
2466 in the current buffer, if necessary. */ 2451 in the current buffer, if necessary. */
2467 2452
2468static void 2453static void
2469update_buffer_properties (EMACS_INT start, EMACS_INT end) 2454update_buffer_properties (ptrdiff_t start, ptrdiff_t end)
2470{ 2455{
2471 /* If this buffer has some access functions, 2456 /* If this buffer has some access functions,
2472 call them, specifying the range of the buffer being accessed. */ 2457 call them, specifying the range of the buffer being accessed. */
@@ -2505,7 +2490,7 @@ into the result string; if you don't want the text properties,
2505use `buffer-substring-no-properties' instead. */) 2490use `buffer-substring-no-properties' instead. */)
2506 (Lisp_Object start, Lisp_Object end) 2491 (Lisp_Object start, Lisp_Object end)
2507{ 2492{
2508 register EMACS_INT b, e; 2493 register ptrdiff_t b, e;
2509 2494
2510 validate_region (&start, &end); 2495 validate_region (&start, &end);
2511 b = XINT (start); 2496 b = XINT (start);
@@ -2521,7 +2506,7 @@ The two arguments START and END are character positions;
2521they can be in either order. */) 2506they can be in either order. */)
2522 (Lisp_Object start, Lisp_Object end) 2507 (Lisp_Object start, Lisp_Object end)
2523{ 2508{
2524 register EMACS_INT b, e; 2509 register ptrdiff_t b, e;
2525 2510
2526 validate_region (&start, &end); 2511 validate_region (&start, &end);
2527 b = XINT (start); 2512 b = XINT (start);
@@ -2605,8 +2590,8 @@ determines whether case is significant or ignored. */)
2605 register Lisp_Object trt 2590 register Lisp_Object trt
2606 = (!NILP (BVAR (current_buffer, case_fold_search)) 2591 = (!NILP (BVAR (current_buffer, case_fold_search))
2607 ? BVAR (current_buffer, case_canon_table) : Qnil); 2592 ? BVAR (current_buffer, case_canon_table) : Qnil);
2608 EMACS_INT chars = 0; 2593 ptrdiff_t chars = 0;
2609 EMACS_INT i1, i2, i1_byte, i2_byte; 2594 ptrdiff_t i1, i2, i1_byte, i2_byte;
2610 2595
2611 /* Find the first buffer and its substring. */ 2596 /* Find the first buffer and its substring. */
2612 2597
@@ -2767,21 +2752,21 @@ and don't mark the buffer as really changed.
2767Both characters must have the same length of multi-byte form. */) 2752Both characters must have the same length of multi-byte form. */)
2768 (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)
2769{ 2754{
2770 register EMACS_INT pos, pos_byte, stop, i, len, end_byte; 2755 register ptrdiff_t pos, pos_byte, stop, i, len, end_byte;
2771 /* Keep track of the first change in the buffer: 2756 /* Keep track of the first change in the buffer:
2772 if 0 we haven't found it yet. 2757 if 0 we haven't found it yet.
2773 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.
2774 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. */
2775 EMACS_INT changed = 0; 2760 ptrdiff_t changed = 0;
2776 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH]; 2761 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH];
2777 unsigned char *p; 2762 unsigned char *p;
2778 int count = SPECPDL_INDEX (); 2763 ptrdiff_t count = SPECPDL_INDEX ();
2779#define COMBINING_NO 0 2764#define COMBINING_NO 0
2780#define COMBINING_BEFORE 1 2765#define COMBINING_BEFORE 1
2781#define COMBINING_AFTER 2 2766#define COMBINING_AFTER 2
2782#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) 2767#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
2783 int maybe_byte_combining = COMBINING_NO; 2768 int maybe_byte_combining = COMBINING_NO;
2784 EMACS_INT last_changed = 0; 2769 ptrdiff_t last_changed = 0;
2785 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2770 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2786 int fromc, toc; 2771 int fromc, toc;
2787 2772
@@ -2841,7 +2826,7 @@ Both characters must have the same length of multi-byte form. */)
2841 stop = min (stop, GPT_BYTE); 2826 stop = min (stop, GPT_BYTE);
2842 while (1) 2827 while (1)
2843 { 2828 {
2844 EMACS_INT pos_byte_next = pos_byte; 2829 ptrdiff_t pos_byte_next = pos_byte;
2845 2830
2846 if (pos_byte >= stop) 2831 if (pos_byte >= stop)
2847 { 2832 {
@@ -2944,7 +2929,7 @@ Both characters must have the same length of multi-byte form. */)
2944} 2929}
2945 2930
2946 2931
2947static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT, 2932static Lisp_Object check_translation (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2948 Lisp_Object); 2933 Lisp_Object);
2949 2934
2950/* Helper function for Ftranslate_region_internal. 2935/* Helper function for Ftranslate_region_internal.
@@ -2954,7 +2939,7 @@ static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT,
2954 element is found, return it. Otherwise return Qnil. */ 2939 element is found, return it. Otherwise return Qnil. */
2955 2940
2956static Lisp_Object 2941static Lisp_Object
2957check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end, 2942check_translation (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t end,
2958 Lisp_Object val) 2943 Lisp_Object val)
2959{ 2944{
2960 int buf_size = 16, buf_used = 0; 2945 int buf_size = 16, buf_used = 0;
@@ -2963,7 +2948,7 @@ check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end,
2963 for (; CONSP (val); val = XCDR (val)) 2948 for (; CONSP (val); val = XCDR (val))
2964 { 2949 {
2965 Lisp_Object elt; 2950 Lisp_Object elt;
2966 EMACS_INT len, i; 2951 ptrdiff_t len, i;
2967 2952
2968 elt = XCAR (val); 2953 elt = XCAR (val);
2969 if (! CONSP (elt)) 2954 if (! CONSP (elt))
@@ -3016,8 +3001,8 @@ It returns the number of characters changed. */)
3016 register unsigned char *tt; /* Trans table. */ 3001 register unsigned char *tt; /* Trans table. */
3017 register int nc; /* New character. */ 3002 register int nc; /* New character. */
3018 int cnt; /* Number of changes made. */ 3003 int cnt; /* Number of changes made. */
3019 EMACS_INT size; /* Size of translate table. */ 3004 ptrdiff_t size; /* Size of translate table. */
3020 EMACS_INT pos, pos_byte, end_pos; 3005 ptrdiff_t pos, pos_byte, end_pos;
3021 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3006 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3022 int string_multibyte IF_LINT (= 0); 3007 int string_multibyte IF_LINT (= 0);
3023 3008
@@ -3295,7 +3280,7 @@ save_restriction_restore (Lisp_Object data)
3295 /* The restriction has changed from the saved one, so restore 3280 /* The restriction has changed from the saved one, so restore
3296 the saved restriction. */ 3281 the saved restriction. */
3297 { 3282 {
3298 EMACS_INT pt = BUF_PT (buf); 3283 ptrdiff_t pt = BUF_PT (buf);
3299 3284
3300 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos); 3285 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
3301 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos); 3286 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
@@ -3353,7 +3338,7 @@ usage: (save-restriction &rest BODY) */)
3353 (Lisp_Object body) 3338 (Lisp_Object body)
3354{ 3339{
3355 register Lisp_Object val; 3340 register Lisp_Object val;
3356 int count = SPECPDL_INDEX (); 3341 ptrdiff_t count = SPECPDL_INDEX ();
3357 3342
3358 record_unwind_protect (save_restriction_restore, save_restriction_save ()); 3343 record_unwind_protect (save_restriction_restore, save_restriction_save ());
3359 val = Fprogn (body); 3344 val = Fprogn (body);
@@ -3571,12 +3556,12 @@ usage: (format STRING &rest OBJECTS) */)
3571 ptrdiff_t n; /* The number of the next arg to substitute */ 3556 ptrdiff_t n; /* The number of the next arg to substitute */
3572 char initial_buffer[4000]; 3557 char initial_buffer[4000];
3573 char *buf = initial_buffer; 3558 char *buf = initial_buffer;
3574 EMACS_INT bufsize = sizeof initial_buffer; 3559 ptrdiff_t bufsize = sizeof initial_buffer;
3575 EMACS_INT max_bufsize = STRING_BYTES_BOUND + 1; 3560 ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1;
3576 char *p; 3561 char *p;
3577 Lisp_Object buf_save_value IF_LINT (= {0}); 3562 Lisp_Object buf_save_value IF_LINT (= {0});
3578 register char *format, *end, *format_start; 3563 register char *format, *end, *format_start;
3579 EMACS_INT formatlen, nchars; 3564 ptrdiff_t formatlen, nchars;
3580 /* Nonzero if the format is multibyte. */ 3565 /* Nonzero if the format is multibyte. */
3581 int multibyte_format = 0; 3566 int multibyte_format = 0;
3582 /* Nonzero if the output should be a multibyte string, 3567 /* Nonzero if the output should be a multibyte string,
@@ -3603,7 +3588,7 @@ usage: (format STRING &rest OBJECTS) */)
3603 info[0] is unused. Unused elements have -1 for start. */ 3588 info[0] is unused. Unused elements have -1 for start. */
3604 struct info 3589 struct info
3605 { 3590 {
3606 EMACS_INT start, end; 3591 ptrdiff_t start, end;
3607 int converted_to_string; 3592 int converted_to_string;
3608 int intervals; 3593 int intervals;
3609 } *info = 0; 3594 } *info = 0;
@@ -3660,7 +3645,7 @@ usage: (format STRING &rest OBJECTS) */)
3660 char *format0 = format; 3645 char *format0 = format;
3661 3646
3662 /* Bytes needed to represent the output of this conversion. */ 3647 /* Bytes needed to represent the output of this conversion. */
3663 EMACS_INT convbytes; 3648 ptrdiff_t convbytes;
3664 3649
3665 if (*format == '%') 3650 if (*format == '%')
3666 { 3651 {
@@ -3687,7 +3672,7 @@ usage: (format STRING &rest OBJECTS) */)
3687 int space_flag = 0; 3672 int space_flag = 0;
3688 int sharp_flag = 0; 3673 int sharp_flag = 0;
3689 int zero_flag = 0; 3674 int zero_flag = 0;
3690 EMACS_INT field_width; 3675 ptrdiff_t field_width;
3691 int precision_given; 3676 int precision_given;
3692 uintmax_t precision = UINTMAX_MAX; 3677 uintmax_t precision = UINTMAX_MAX;
3693 char *num_end; 3678 char *num_end;
@@ -3794,11 +3779,11 @@ usage: (format STRING &rest OBJECTS) */)
3794 { 3779 {
3795 /* handle case (precision[n] >= 0) */ 3780 /* handle case (precision[n] >= 0) */
3796 3781
3797 EMACS_INT width, padding, nbytes; 3782 ptrdiff_t width, padding, nbytes;
3798 EMACS_INT nchars_string; 3783 ptrdiff_t nchars_string;
3799 3784
3800 EMACS_INT prec = -1; 3785 ptrdiff_t prec = -1;
3801 if (precision_given && precision <= TYPE_MAXIMUM (EMACS_INT)) 3786 if (precision_given && precision <= TYPE_MAXIMUM (ptrdiff_t))
3802 prec = precision; 3787 prec = precision;
3803 3788
3804 /* lisp_string_width ignores a precision of 0, but GNU 3789 /* lisp_string_width ignores a precision of 0, but GNU
@@ -3811,7 +3796,7 @@ usage: (format STRING &rest OBJECTS) */)
3811 width = nchars_string = nbytes = 0; 3796 width = nchars_string = nbytes = 0;
3812 else 3797 else
3813 { 3798 {
3814 EMACS_INT nch, nby; 3799 ptrdiff_t nch, nby;
3815 width = lisp_string_width (args[n], prec, &nch, &nby); 3800 width = lisp_string_width (args[n], prec, &nch, &nby);
3816 if (prec < 0) 3801 if (prec < 0)
3817 { 3802 {
@@ -3908,7 +3893,7 @@ usage: (format STRING &rest OBJECTS) */)
3908 verify (0 < USEFUL_PRECISION_MAX); 3893 verify (0 < USEFUL_PRECISION_MAX);
3909 3894
3910 int prec; 3895 int prec;
3911 EMACS_INT padding, sprintf_bytes; 3896 ptrdiff_t padding, sprintf_bytes;
3912 uintmax_t excess_precision, numwidth; 3897 uintmax_t excess_precision, numwidth;
3913 uintmax_t leading_zeros = 0, trailing_zeros = 0; 3898 uintmax_t leading_zeros = 0, trailing_zeros = 0;
3914 3899
@@ -4223,8 +4208,8 @@ usage: (format STRING &rest OBJECTS) */)
4223 4208
4224 if (CONSP (props)) 4209 if (CONSP (props))
4225 { 4210 {
4226 EMACS_INT bytepos = 0, position = 0, translated = 0; 4211 ptrdiff_t bytepos = 0, position = 0, translated = 0;
4227 EMACS_INT argn = 1; 4212 ptrdiff_t argn = 1;
4228 Lisp_Object list; 4213 Lisp_Object list;
4229 4214
4230 /* Adjust the bounds of each text property 4215 /* Adjust the bounds of each text property
@@ -4242,7 +4227,7 @@ usage: (format STRING &rest OBJECTS) */)
4242 for (list = props; CONSP (list); list = XCDR (list)) 4227 for (list = props; CONSP (list); list = XCDR (list))
4243 { 4228 {
4244 Lisp_Object item; 4229 Lisp_Object item;
4245 EMACS_INT pos; 4230 ptrdiff_t pos;
4246 4231
4247 item = XCAR (list); 4232 item = XCAR (list);
4248 4233
@@ -4373,12 +4358,12 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer. */)
4373 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. */
4374 4359
4375static void 4360static void
4376transpose_markers (EMACS_INT start1, EMACS_INT end1, 4361transpose_markers (ptrdiff_t start1, ptrdiff_t end1,
4377 EMACS_INT start2, EMACS_INT end2, 4362 ptrdiff_t start2, ptrdiff_t end2,
4378 EMACS_INT start1_byte, EMACS_INT end1_byte, 4363 ptrdiff_t start1_byte, ptrdiff_t end1_byte,
4379 EMACS_INT start2_byte, EMACS_INT end2_byte) 4364 ptrdiff_t start2_byte, ptrdiff_t end2_byte)
4380{ 4365{
4381 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;
4382 register struct Lisp_Marker *marker; 4367 register struct Lisp_Marker *marker;
4383 4368
4384 /* Update point as if it were a marker. */ 4369 /* Update point as if it were a marker. */
@@ -4452,9 +4437,9 @@ any markers that happen to be located in the regions.
4452Transposing beyond buffer boundaries is an error. */) 4437Transposing beyond buffer boundaries is an error. */)
4453 (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)
4454{ 4439{
4455 register EMACS_INT start1, end1, start2, end2; 4440 register ptrdiff_t start1, end1, start2, end2;
4456 EMACS_INT start1_byte, start2_byte, len1_byte, len2_byte; 4441 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte;
4457 EMACS_INT gap, len1, len_mid, len2; 4442 ptrdiff_t gap, len1, len_mid, len2;
4458 unsigned char *start1_addr, *start2_addr, *temp; 4443 unsigned char *start1_addr, *start2_addr, *temp;
4459 4444
4460 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;
@@ -4475,7 +4460,7 @@ Transposing beyond buffer boundaries is an error. */)
4475 /* Swap the regions if they're reversed. */ 4460 /* Swap the regions if they're reversed. */
4476 if (start2 < end1) 4461 if (start2 < end1)
4477 { 4462 {
4478 register EMACS_INT glumph = start1; 4463 register ptrdiff_t glumph = start1;
4479 start1 = start2; 4464 start1 = start2;
4480 start2 = glumph; 4465 start2 = glumph;
4481 glumph = end1; 4466 glumph = end1;
diff --git a/src/emacs.c b/src/emacs.c
index c36c7df7e45..8ffacdab1c6 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -65,6 +65,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
65#include "nsterm.h" 65#include "nsterm.h"
66#endif 66#endif
67 67
68#if (defined PROFILING \
69 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
70# include <sys/gmon.h>
71extern void moncontrol (int mode);
72#endif
73
68#ifdef HAVE_X_WINDOWS 74#ifdef HAVE_X_WINDOWS
69#include "xterm.h" 75#include "xterm.h"
70#endif 76#endif
@@ -108,15 +114,15 @@ int gdb_use_union EXTERNALLY_VISIBLE = 0;
108#else 114#else
109int gdb_use_union EXTERNALLY_VISIBLE = 1; 115int gdb_use_union EXTERNALLY_VISIBLE = 1;
110#endif 116#endif
111EMACS_INT gdb_valbits EXTERNALLY_VISIBLE = VALBITS; 117int gdb_valbits EXTERNALLY_VISIBLE = VALBITS;
112EMACS_INT gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS; 118int gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS;
113#if defined (DATA_SEG_BITS) && ! defined (USE_LSB_TAG) 119#if defined (DATA_SEG_BITS) && ! defined (USE_LSB_TAG)
114EMACS_INT gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS; 120uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS;
115#else 121#else
116EMACS_INT gdb_data_seg_bits EXTERNALLY_VISIBLE = 0; 122uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = 0;
117#endif 123#endif
118EMACS_INT PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG; 124ptrdiff_t PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG;
119EMACS_INT gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG; 125ptrdiff_t gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG;
120/* GDB might say "No enum type named pvec_type" if we don't have at 126/* GDB might say "No enum type named pvec_type" if we don't have at
121 least one symbol with that type, and then xbacktrace could fail. */ 127 least one symbol with that type, and then xbacktrace could fail. */
122enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK; 128enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK;
@@ -320,9 +326,9 @@ pthread_t main_thread;
320#ifdef HAVE_NS 326#ifdef HAVE_NS
321/* NS autrelease pool, for memory management. */ 327/* NS autrelease pool, for memory management. */
322static void *ns_pool; 328static void *ns_pool;
323#endif 329#endif
330
324 331
325
326 332
327/* Handle bus errors, invalid instruction, etc. */ 333/* Handle bus errors, invalid instruction, etc. */
328#ifndef FLOAT_CATCH_SIGILL 334#ifndef FLOAT_CATCH_SIGILL
@@ -401,7 +407,7 @@ init_cmdargs (int argc, char **argv, int skip_args)
401{ 407{
402 register int i; 408 register int i;
403 Lisp_Object name, dir, handler; 409 Lisp_Object name, dir, handler;
404 int count = SPECPDL_INDEX (); 410 ptrdiff_t count = SPECPDL_INDEX ();
405 Lisp_Object raw_name; 411 Lisp_Object raw_name;
406 412
407 initial_argv = argv; 413 initial_argv = argv;
@@ -1664,32 +1670,14 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1664#ifdef PROFILING 1670#ifdef PROFILING
1665 if (initialized) 1671 if (initialized)
1666 { 1672 {
1667 extern void _mcleanup ();
1668#ifdef __MINGW32__ 1673#ifdef __MINGW32__
1669 extern unsigned char etext asm ("etext"); 1674 extern unsigned char etext asm ("etext");
1670#else 1675#else
1671 extern char etext; 1676 extern char etext;
1672#endif 1677#endif
1673#ifdef HAVE___EXECUTABLE_START
1674 /* This symbol is defined by GNU ld to the start of the text
1675 segment. */
1676 extern char __executable_start[];
1677#else
1678 extern void safe_bcopy ();
1679#endif
1680 1678
1681 atexit (_mcleanup); 1679 atexit (_mcleanup);
1682#ifdef HAVE___EXECUTABLE_START 1680 monstartup ((uintptr_t) __executable_start, (uintptr_t) &etext);
1683 monstartup (__executable_start, &etext);
1684#else
1685 /* This uses safe_bcopy because that function comes first in the
1686 Emacs executable. It might be better to use something that
1687 gives the start of the text segment, but start_of_text is not
1688 defined on all systems now. */
1689 /* FIXME: Does not work on architectures with function
1690 descriptors. */
1691 monstartup (safe_bcopy, &etext);
1692#endif
1693 } 1681 }
1694 else 1682 else
1695 moncontrol (0); 1683 moncontrol (0);
@@ -2027,10 +2015,15 @@ all of which are called before Emacs is actually killed. */)
2027 if (STRINGP (Vauto_save_list_file_name)) 2015 if (STRINGP (Vauto_save_list_file_name))
2028 unlink (SSDATA (Vauto_save_list_file_name)); 2016 unlink (SSDATA (Vauto_save_list_file_name));
2029 2017
2030 exit_code = EXIT_SUCCESS; 2018 if (INTEGERP (arg))
2031 if (noninteractive && (fflush (stdout) || ferror (stdout))) 2019 exit_code = (XINT (arg) < 0
2020 ? XINT (arg) | INT_MIN
2021 : XINT (arg) & INT_MAX);
2022 else if (noninteractive && (fflush (stdout) || ferror (stdout)))
2032 exit_code = EXIT_FAILURE; 2023 exit_code = EXIT_FAILURE;
2033 exit (INTEGERP (arg) ? XINT (arg) : exit_code); 2024 else
2025 exit_code = EXIT_SUCCESS;
2026 exit (exit_code);
2034} 2027}
2035 2028
2036 2029
@@ -2140,7 +2133,7 @@ You must run Emacs in batch mode in order to dump it. */)
2140{ 2133{
2141 Lisp_Object tem; 2134 Lisp_Object tem;
2142 Lisp_Object symbol; 2135 Lisp_Object symbol;
2143 int count = SPECPDL_INDEX (); 2136 ptrdiff_t count = SPECPDL_INDEX ();
2144 2137
2145 check_pure_size (); 2138 check_pure_size ();
2146 2139
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..496f9d7efa4 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
@@ -3732,7 +3735,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3732 /* If display currently starts at beginning of line, 3735 /* If display currently starts at beginning of line,
3733 keep it that way. */ 3736 keep it that way. */
3734 if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer) 3737 if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer)
3735 XWINDOW (selected_window)->start_at_line_beg = Fbolp (); 3738 XWINDOW (selected_window)->start_at_line_beg = !NILP (Fbolp ());
3736 3739
3737 replace_handled = 1; 3740 replace_handled = 1;
3738 } 3741 }
@@ -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;
@@ -3890,7 +3892,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3890 /* If display currently starts at beginning of line, 3892 /* If display currently starts at beginning of line,
3891 keep it that way. */ 3893 keep it that way. */
3892 if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer) 3894 if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer)
3893 XWINDOW (selected_window)->start_at_line_beg = Fbolp (); 3895 XWINDOW (selected_window)->start_at_line_beg = !NILP (Fbolp ());
3894 3896
3895 /* Replace the chars that we need to replace, 3897 /* Replace the chars that we need to replace,
3896 and update INSERTED to equal the number of bytes 3898 and update INSERTED to equal the number of bytes
@@ -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 a92a1c882fd..676e53ccbd8 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -42,10 +42,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
42#endif 42#endif
43#endif /* HAVE_MENUS */ 43#endif /* HAVE_MENUS */
44 44
45#ifndef NULL
46#define NULL ((POINTER_TYPE *)0)
47#endif
48
49Lisp_Object Qstring_lessp; 45Lisp_Object Qstring_lessp;
50static Lisp_Object Qprovide, Qrequire; 46static Lisp_Object Qprovide, Qrequire;
51static Lisp_Object Qyes_or_no_p_history; 47static Lisp_Object Qyes_or_no_p_history;
@@ -250,8 +246,8 @@ If string STR1 is greater, the value is a positive number N;
250 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. */)
251 (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)
252{ 248{
253 register EMACS_INT end1_char, end2_char; 249 register ptrdiff_t end1_char, end2_char;
254 register EMACS_INT i1, i1_byte, i2, i2_byte; 250 register ptrdiff_t i1, i1_byte, i2, i2_byte;
255 251
256 CHECK_STRING (str1); 252 CHECK_STRING (str1);
257 CHECK_STRING (str2); 253 CHECK_STRING (str2);
@@ -266,19 +262,23 @@ If string STR1 is greater, the value is a positive number N;
266 if (! NILP (end2)) 262 if (! NILP (end2))
267 CHECK_NATNUM (end2); 263 CHECK_NATNUM (end2);
268 264
269 i1 = XINT (start1);
270 i2 = XINT (start2);
271
272 i1_byte = string_char_to_byte (str1, i1);
273 i2_byte = string_char_to_byte (str2, i2);
274
275 end1_char = SCHARS (str1); 265 end1_char = SCHARS (str1);
276 if (! NILP (end1) && end1_char > XINT (end1)) 266 if (! NILP (end1) && end1_char > XINT (end1))
277 end1_char = XINT (end1); 267 end1_char = XINT (end1);
268 if (end1_char < XINT (start1))
269 args_out_of_range (str1, start1);
278 270
279 end2_char = SCHARS (str2); 271 end2_char = SCHARS (str2);
280 if (! NILP (end2) && end2_char > XINT (end2)) 272 if (! NILP (end2) && end2_char > XINT (end2))
281 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);
282 282
283 while (i1 < end1_char && i2 < end2_char) 283 while (i1 < end1_char && i2 < end2_char)
284 { 284 {
@@ -341,8 +341,8 @@ Case is significant.
341Symbols are also allowed; their print names are used instead. */) 341Symbols are also allowed; their print names are used instead. */)
342 (register Lisp_Object s1, Lisp_Object s2) 342 (register Lisp_Object s1, Lisp_Object s2)
343{ 343{
344 register EMACS_INT end; 344 register ptrdiff_t end;
345 register EMACS_INT i1, i1_byte, i2, i2_byte; 345 register ptrdiff_t i1, i1_byte, i2, i2_byte;
346 346
347 if (SYMBOLP (s1)) 347 if (SYMBOLP (s1))
348 s1 = SYMBOL_NAME (s1); 348 s1 = SYMBOL_NAME (s1);
@@ -465,8 +465,8 @@ with the original. */)
465struct textprop_rec 465struct textprop_rec
466{ 466{
467 ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */ 467 ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */
468 EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ 468 ptrdiff_t from; /* refer to ARGS[argnum] (argument string) */
469 EMACS_INT to; /* refer to VAL (the target string) */ 469 ptrdiff_t to; /* refer to VAL (the target string) */
470}; 470};
471 471
472static Lisp_Object 472static Lisp_Object
@@ -476,8 +476,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
476 Lisp_Object val; 476 Lisp_Object val;
477 register Lisp_Object tail; 477 register Lisp_Object tail;
478 register Lisp_Object this; 478 register Lisp_Object this;
479 EMACS_INT toindex; 479 ptrdiff_t toindex;
480 EMACS_INT toindex_byte = 0; 480 ptrdiff_t toindex_byte = 0;
481 register EMACS_INT result_len; 481 register EMACS_INT result_len;
482 register EMACS_INT result_len_byte; 482 register EMACS_INT result_len_byte;
483 ptrdiff_t argnum; 483 ptrdiff_t argnum;
@@ -530,10 +530,10 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
530 { 530 {
531 /* We must count the number of bytes needed in the string 531 /* We must count the number of bytes needed in the string
532 as well as the number of characters. */ 532 as well as the number of characters. */
533 EMACS_INT i; 533 ptrdiff_t i;
534 Lisp_Object ch; 534 Lisp_Object ch;
535 int c; 535 int c;
536 EMACS_INT this_len_byte; 536 ptrdiff_t this_len_byte;
537 537
538 if (VECTORP (this) || COMPILEDP (this)) 538 if (VECTORP (this) || COMPILEDP (this))
539 for (i = 0; i < len; i++) 539 for (i = 0; i < len; i++)
@@ -542,6 +542,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
542 CHECK_CHARACTER (ch); 542 CHECK_CHARACTER (ch);
543 c = XFASTINT (ch); 543 c = XFASTINT (ch);
544 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 ();
545 result_len_byte += this_len_byte; 547 result_len_byte += this_len_byte;
546 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) 548 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
547 some_multibyte = 1; 549 some_multibyte = 1;
@@ -555,6 +557,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
555 CHECK_CHARACTER (ch); 557 CHECK_CHARACTER (ch);
556 c = XFASTINT (ch); 558 c = XFASTINT (ch);
557 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 ();
558 result_len_byte += this_len_byte; 562 result_len_byte += this_len_byte;
559 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) 563 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
560 some_multibyte = 1; 564 some_multibyte = 1;
@@ -564,17 +568,20 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
564 if (STRING_MULTIBYTE (this)) 568 if (STRING_MULTIBYTE (this))
565 { 569 {
566 some_multibyte = 1; 570 some_multibyte = 1;
567 result_len_byte += SBYTES (this); 571 this_len_byte = SBYTES (this);
568 } 572 }
569 else 573 else
570 result_len_byte += count_size_as_multibyte (SDATA (this), 574 this_len_byte = count_size_as_multibyte (SDATA (this),
571 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;
572 } 579 }
573 } 580 }
574 581
575 result_len += len; 582 result_len += len;
576 if (STRING_BYTES_BOUND < result_len) 583 if (MOST_POSITIVE_FIXNUM < result_len)
577 string_overflow (); 584 memory_full (SIZE_MAX);
578 } 585 }
579 586
580 if (! some_multibyte) 587 if (! some_multibyte)
@@ -607,9 +614,9 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
607 for (argnum = 0; argnum < nargs; argnum++) 614 for (argnum = 0; argnum < nargs; argnum++)
608 { 615 {
609 Lisp_Object thislen; 616 Lisp_Object thislen;
610 EMACS_INT thisleni = 0; 617 ptrdiff_t thisleni = 0;
611 register EMACS_INT thisindex = 0; 618 register ptrdiff_t thisindex = 0;
612 register EMACS_INT thisindex_byte = 0; 619 register ptrdiff_t thisindex_byte = 0;
613 620
614 this = args[argnum]; 621 this = args[argnum];
615 if (!CONSP (this)) 622 if (!CONSP (this))
@@ -619,7 +626,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
619 if (STRINGP (this) && STRINGP (val) 626 if (STRINGP (this) && STRINGP (val)
620 && STRING_MULTIBYTE (this) == some_multibyte) 627 && STRING_MULTIBYTE (this) == some_multibyte)
621 { 628 {
622 EMACS_INT thislen_byte = SBYTES (this); 629 ptrdiff_t thislen_byte = SBYTES (this);
623 630
624 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this)); 631 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
625 if (! NULL_INTERVAL_P (STRING_INTERVALS (this))) 632 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
@@ -720,7 +727,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
720 if (num_textprops > 0) 727 if (num_textprops > 0)
721 { 728 {
722 Lisp_Object props; 729 Lisp_Object props;
723 EMACS_INT last_to_end = -1; 730 ptrdiff_t last_to_end = -1;
724 731
725 for (argnum = 0; argnum < num_textprops; argnum++) 732 for (argnum = 0; argnum < num_textprops; argnum++)
726 { 733 {
@@ -744,8 +751,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
744} 751}
745 752
746static Lisp_Object string_char_byte_cache_string; 753static Lisp_Object string_char_byte_cache_string;
747static EMACS_INT string_char_byte_cache_charpos; 754static ptrdiff_t string_char_byte_cache_charpos;
748static EMACS_INT string_char_byte_cache_bytepos; 755static ptrdiff_t string_char_byte_cache_bytepos;
749 756
750void 757void
751clear_string_char_byte_cache (void) 758clear_string_char_byte_cache (void)
@@ -755,12 +762,12 @@ clear_string_char_byte_cache (void)
755 762
756/* Return the byte index corresponding to CHAR_INDEX in STRING. */ 763/* Return the byte index corresponding to CHAR_INDEX in STRING. */
757 764
758EMACS_INT 765ptrdiff_t
759string_char_to_byte (Lisp_Object string, EMACS_INT char_index) 766string_char_to_byte (Lisp_Object string, ptrdiff_t char_index)
760{ 767{
761 EMACS_INT i_byte; 768 ptrdiff_t i_byte;
762 EMACS_INT best_below, best_below_byte; 769 ptrdiff_t best_below, best_below_byte;
763 EMACS_INT best_above, best_above_byte; 770 ptrdiff_t best_above, best_above_byte;
764 771
765 best_below = best_below_byte = 0; 772 best_below = best_below_byte = 0;
766 best_above = SCHARS (string); 773 best_above = SCHARS (string);
@@ -815,12 +822,12 @@ string_char_to_byte (Lisp_Object string, EMACS_INT char_index)
815 822
816/* Return the character index corresponding to BYTE_INDEX in STRING. */ 823/* Return the character index corresponding to BYTE_INDEX in STRING. */
817 824
818EMACS_INT 825ptrdiff_t
819string_byte_to_char (Lisp_Object string, EMACS_INT byte_index) 826string_byte_to_char (Lisp_Object string, ptrdiff_t byte_index)
820{ 827{
821 EMACS_INT i, i_byte; 828 ptrdiff_t i, i_byte;
822 EMACS_INT best_below, best_below_byte; 829 ptrdiff_t best_below, best_below_byte;
823 EMACS_INT best_above, best_above_byte; 830 ptrdiff_t best_above, best_above_byte;
824 831
825 best_below = best_below_byte = 0; 832 best_below = best_below_byte = 0;
826 best_above = SCHARS (string); 833 best_above = SCHARS (string);
@@ -883,7 +890,7 @@ static Lisp_Object
883string_make_multibyte (Lisp_Object string) 890string_make_multibyte (Lisp_Object string)
884{ 891{
885 unsigned char *buf; 892 unsigned char *buf;
886 EMACS_INT nbytes; 893 ptrdiff_t nbytes;
887 Lisp_Object ret; 894 Lisp_Object ret;
888 USE_SAFE_ALLOCA; 895 USE_SAFE_ALLOCA;
889 896
@@ -916,7 +923,7 @@ Lisp_Object
916string_to_multibyte (Lisp_Object string) 923string_to_multibyte (Lisp_Object string)
917{ 924{
918 unsigned char *buf; 925 unsigned char *buf;
919 EMACS_INT nbytes; 926 ptrdiff_t nbytes;
920 Lisp_Object ret; 927 Lisp_Object ret;
921 USE_SAFE_ALLOCA; 928 USE_SAFE_ALLOCA;
922 929
@@ -945,7 +952,7 @@ string_to_multibyte (Lisp_Object string)
945Lisp_Object 952Lisp_Object
946string_make_unibyte (Lisp_Object string) 953string_make_unibyte (Lisp_Object string)
947{ 954{
948 EMACS_INT nchars; 955 ptrdiff_t nchars;
949 unsigned char *buf; 956 unsigned char *buf;
950 Lisp_Object ret; 957 Lisp_Object ret;
951 USE_SAFE_ALLOCA; 958 USE_SAFE_ALLOCA;
@@ -1010,7 +1017,7 @@ If STRING is multibyte and contains a character of charset
1010 1017
1011 if (STRING_MULTIBYTE (string)) 1018 if (STRING_MULTIBYTE (string))
1012 { 1019 {
1013 EMACS_INT bytes = SBYTES (string); 1020 ptrdiff_t bytes = SBYTES (string);
1014 unsigned char *str = (unsigned char *) xmalloc (bytes); 1021 unsigned char *str = (unsigned char *) xmalloc (bytes);
1015 1022
1016 memcpy (str, SDATA (string), bytes); 1023 memcpy (str, SDATA (string), bytes);
@@ -1043,7 +1050,7 @@ If you're not sure, whether to use `string-as-multibyte' or
1043 if (! STRING_MULTIBYTE (string)) 1050 if (! STRING_MULTIBYTE (string))
1044 { 1051 {
1045 Lisp_Object new_string; 1052 Lisp_Object new_string;
1046 EMACS_INT nchars, nbytes; 1053 ptrdiff_t nchars, nbytes;
1047 1054
1048 parse_str_as_multibyte (SDATA (string), 1055 parse_str_as_multibyte (SDATA (string),
1049 SBYTES (string), 1056 SBYTES (string),
@@ -1092,12 +1099,12 @@ an error is signaled. */)
1092 1099
1093 if (STRING_MULTIBYTE (string)) 1100 if (STRING_MULTIBYTE (string))
1094 { 1101 {
1095 EMACS_INT chars = SCHARS (string); 1102 ptrdiff_t chars = SCHARS (string);
1096 unsigned char *str = (unsigned char *) xmalloc (chars); 1103 unsigned char *str = (unsigned char *) xmalloc (chars);
1097 EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0); 1104 ptrdiff_t converted = str_to_unibyte (SDATA (string), str, chars, 0);
1098 1105
1099 if (converted < chars) 1106 if (converted < chars)
1100 error ("Can't convert the %"pI"dth character to unibyte", converted); 1107 error ("Can't convert the %"pD"dth character to unibyte", converted);
1101 string = make_unibyte_string ((char *) str, chars); 1108 string = make_unibyte_string ((char *) str, chars);
1102 xfree (str); 1109 xfree (str);
1103 } 1110 }
@@ -1145,27 +1152,19 @@ value is a new vector that contains the elements between index FROM
1145 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1152 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1146{ 1153{
1147 Lisp_Object res; 1154 Lisp_Object res;
1148 EMACS_INT size; 1155 ptrdiff_t size;
1149 EMACS_INT size_byte = 0;
1150 EMACS_INT from_char, to_char; 1156 EMACS_INT from_char, to_char;
1151 EMACS_INT from_byte = 0, to_byte = 0;
1152 1157
1153 CHECK_VECTOR_OR_STRING (string); 1158 CHECK_VECTOR_OR_STRING (string);
1154 CHECK_NUMBER (from); 1159 CHECK_NUMBER (from);
1155 1160
1156 if (STRINGP (string)) 1161 if (STRINGP (string))
1157 { 1162 size = SCHARS (string);
1158 size = SCHARS (string);
1159 size_byte = SBYTES (string);
1160 }
1161 else 1163 else
1162 size = ASIZE (string); 1164 size = ASIZE (string);
1163 1165
1164 if (NILP (to)) 1166 if (NILP (to))
1165 { 1167 to_char = size;
1166 to_char = size;
1167 to_byte = size_byte;
1168 }
1169 else 1168 else
1170 { 1169 {
1171 CHECK_NUMBER (to); 1170 CHECK_NUMBER (to);
@@ -1173,23 +1172,20 @@ value is a new vector that contains the elements between index FROM
1173 to_char = XINT (to); 1172 to_char = XINT (to);
1174 if (to_char < 0) 1173 if (to_char < 0)
1175 to_char += size; 1174 to_char += size;
1176
1177 if (STRINGP (string))
1178 to_byte = string_char_to_byte (string, to_char);
1179 } 1175 }
1180 1176
1181 from_char = XINT (from); 1177 from_char = XINT (from);
1182 if (from_char < 0) 1178 if (from_char < 0)
1183 from_char += size; 1179 from_char += size;
1184 if (STRINGP (string))
1185 from_byte = string_char_to_byte (string, from_char);
1186
1187 if (!(0 <= from_char && from_char <= to_char && to_char <= size)) 1180 if (!(0 <= from_char && from_char <= to_char && to_char <= size))
1188 args_out_of_range_3 (string, make_number (from_char), 1181 args_out_of_range_3 (string, make_number (from_char),
1189 make_number (to_char)); 1182 make_number (to_char));
1190 1183
1191 if (STRINGP (string)) 1184 if (STRINGP (string))
1192 { 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);
1193 res = make_specified_string (SSDATA (string) + from_byte, 1189 res = make_specified_string (SSDATA (string) + from_byte,
1194 to_char - from_char, to_byte - from_byte, 1190 to_char - from_char, to_byte - from_byte,
1195 STRING_MULTIBYTE (string)); 1191 STRING_MULTIBYTE (string));
@@ -1213,47 +1209,41 @@ If FROM or TO is negative, it counts from the end.
1213With one argument, just copy STRING without its properties. */) 1209With one argument, just copy STRING without its properties. */)
1214 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1210 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1215{ 1211{
1216 EMACS_INT size, size_byte; 1212 ptrdiff_t size;
1217 EMACS_INT from_char, to_char; 1213 EMACS_INT from_char, to_char;
1218 EMACS_INT from_byte, to_byte; 1214 ptrdiff_t from_byte, to_byte;
1219 1215
1220 CHECK_STRING (string); 1216 CHECK_STRING (string);
1221 1217
1222 size = SCHARS (string); 1218 size = SCHARS (string);
1223 size_byte = SBYTES (string);
1224 1219
1225 if (NILP (from)) 1220 if (NILP (from))
1226 from_char = from_byte = 0; 1221 from_char = 0;
1227 else 1222 else
1228 { 1223 {
1229 CHECK_NUMBER (from); 1224 CHECK_NUMBER (from);
1230 from_char = XINT (from); 1225 from_char = XINT (from);
1231 if (from_char < 0) 1226 if (from_char < 0)
1232 from_char += size; 1227 from_char += size;
1233
1234 from_byte = string_char_to_byte (string, from_char);
1235 } 1228 }
1236 1229
1237 if (NILP (to)) 1230 if (NILP (to))
1238 { 1231 to_char = size;
1239 to_char = size;
1240 to_byte = size_byte;
1241 }
1242 else 1232 else
1243 { 1233 {
1244 CHECK_NUMBER (to); 1234 CHECK_NUMBER (to);
1245
1246 to_char = XINT (to); 1235 to_char = XINT (to);
1247 if (to_char < 0) 1236 if (to_char < 0)
1248 to_char += size; 1237 to_char += size;
1249
1250 to_byte = string_char_to_byte (string, to_char);
1251 } 1238 }
1252 1239
1253 if (!(0 <= from_char && from_char <= to_char && to_char <= size)) 1240 if (!(0 <= from_char && from_char <= to_char && to_char <= size))
1254 args_out_of_range_3 (string, make_number (from_char), 1241 args_out_of_range_3 (string, make_number (from_char),
1255 make_number (to_char)); 1242 make_number (to_char));
1256 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);
1257 return make_specified_string (SSDATA (string) + from_byte, 1247 return make_specified_string (SSDATA (string) + from_byte,
1258 to_char - from_char, to_byte - from_byte, 1248 to_char - from_char, to_byte - from_byte,
1259 STRING_MULTIBYTE (string)); 1249 STRING_MULTIBYTE (string));
@@ -1263,11 +1253,11 @@ With one argument, just copy STRING without its properties. */)
1263 both in characters and in bytes. */ 1253 both in characters and in bytes. */
1264 1254
1265Lisp_Object 1255Lisp_Object
1266substring_both (Lisp_Object string, EMACS_INT from, EMACS_INT from_byte, 1256substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte,
1267 EMACS_INT to, EMACS_INT to_byte) 1257 ptrdiff_t to, ptrdiff_t to_byte)
1268{ 1258{
1269 Lisp_Object res; 1259 Lisp_Object res;
1270 EMACS_INT size; 1260 ptrdiff_t size;
1271 1261
1272 CHECK_VECTOR_OR_STRING (string); 1262 CHECK_VECTOR_OR_STRING (string);
1273 1263
@@ -1601,7 +1591,7 @@ to be sure of changing the value of `foo'. */)
1601{ 1591{
1602 if (VECTORP (seq)) 1592 if (VECTORP (seq))
1603 { 1593 {
1604 EMACS_INT i, n; 1594 ptrdiff_t i, n;
1605 1595
1606 for (i = n = 0; i < ASIZE (seq); ++i) 1596 for (i = n = 0; i < ASIZE (seq); ++i)
1607 if (NILP (Fequal (AREF (seq, i), elt))) 1597 if (NILP (Fequal (AREF (seq, i), elt)))
@@ -1620,7 +1610,7 @@ to be sure of changing the value of `foo'. */)
1620 } 1610 }
1621 else if (STRINGP (seq)) 1611 else if (STRINGP (seq))
1622 { 1612 {
1623 EMACS_INT i, ibyte, nchars, nbytes, cbytes; 1613 ptrdiff_t i, ibyte, nchars, nbytes, cbytes;
1624 int c; 1614 int c;
1625 1615
1626 for (i = nchars = nbytes = ibyte = 0; 1616 for (i = nchars = nbytes = ibyte = 0;
@@ -1672,7 +1662,7 @@ to be sure of changing the value of `foo'. */)
1672 { 1662 {
1673 unsigned char *from = SDATA (seq) + ibyte; 1663 unsigned char *from = SDATA (seq) + ibyte;
1674 unsigned char *to = SDATA (tem) + nbytes; 1664 unsigned char *to = SDATA (tem) + nbytes;
1675 EMACS_INT n; 1665 ptrdiff_t n;
1676 1666
1677 ++nchars; 1667 ++nchars;
1678 nbytes += cbytes; 1668 nbytes += cbytes;
@@ -2079,7 +2069,7 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int
2079 case Lisp_Vectorlike: 2069 case Lisp_Vectorlike:
2080 { 2070 {
2081 register int i; 2071 register int i;
2082 EMACS_INT size = ASIZE (o1); 2072 ptrdiff_t size = ASIZE (o1);
2083 /* 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
2084 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
2085 same size. */ 2075 same size. */
@@ -2146,7 +2136,7 @@ DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
2146ARRAY is a vector, string, char-table, or bool-vector. */) 2136ARRAY is a vector, string, char-table, or bool-vector. */)
2147 (Lisp_Object array, Lisp_Object item) 2137 (Lisp_Object array, Lisp_Object item)
2148{ 2138{
2149 register EMACS_INT size, idx; 2139 register ptrdiff_t size, idx;
2150 2140
2151 if (VECTORP (array)) 2141 if (VECTORP (array))
2152 { 2142 {
@@ -2174,7 +2164,7 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2174 { 2164 {
2175 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2165 unsigned char str[MAX_MULTIBYTE_LENGTH];
2176 int len = CHAR_STRING (charval, str); 2166 int len = CHAR_STRING (charval, str);
2177 EMACS_INT size_byte = SBYTES (array); 2167 ptrdiff_t size_byte = SBYTES (array);
2178 2168
2179 if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len) 2169 if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len)
2180 || SCHARS (array) * len != size_byte) 2170 || SCHARS (array) * len != size_byte)
@@ -2189,18 +2179,16 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2189 else if (BOOL_VECTOR_P (array)) 2179 else if (BOOL_VECTOR_P (array))
2190 { 2180 {
2191 register unsigned char *p = XBOOL_VECTOR (array)->data; 2181 register unsigned char *p = XBOOL_VECTOR (array)->data;
2192 EMACS_INT size_in_chars; 2182 size =
2193 size = XBOOL_VECTOR (array)->size; 2183 ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
2194 size_in_chars 2184 / BOOL_VECTOR_BITS_PER_CHAR);
2195 = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1)
2196 / BOOL_VECTOR_BITS_PER_CHAR);
2197 2185
2198 if (size_in_chars) 2186 if (size)
2199 { 2187 {
2200 memset (p, ! NILP (item) ? -1 : 0, size_in_chars); 2188 memset (p, ! NILP (item) ? -1 : 0, size);
2201 2189
2202 /* Clear any extraneous bits in the last byte. */ 2190 /* Clear any extraneous bits in the last byte. */
2203 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;
2204 } 2192 }
2205 } 2193 }
2206 else 2194 else
@@ -2214,7 +2202,7 @@ DEFUN ("clear-string", Fclear_string, Sclear_string,
2214This makes STRING unibyte and may change its length. */) 2202This makes STRING unibyte and may change its length. */)
2215 (Lisp_Object string) 2203 (Lisp_Object string)
2216{ 2204{
2217 EMACS_INT len; 2205 ptrdiff_t len;
2218 CHECK_STRING (string); 2206 CHECK_STRING (string);
2219 len = SBYTES (string); 2207 len = SBYTES (string);
2220 memset (SDATA (string), 0, len); 2208 memset (SDATA (string), 0, len);
@@ -2324,12 +2312,12 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
2324 } 2312 }
2325 else if (STRINGP (seq)) 2313 else if (STRINGP (seq))
2326 { 2314 {
2327 EMACS_INT i_byte; 2315 ptrdiff_t i_byte;
2328 2316
2329 for (i = 0, i_byte = 0; i < leni;) 2317 for (i = 0, i_byte = 0; i < leni;)
2330 { 2318 {
2331 int c; 2319 int c;
2332 EMACS_INT i_before = i; 2320 ptrdiff_t i_before = i;
2333 2321
2334 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte); 2322 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte);
2335 XSETFASTINT (dummy, c); 2323 XSETFASTINT (dummy, c);
@@ -2362,7 +2350,8 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2362{ 2350{
2363 Lisp_Object len; 2351 Lisp_Object len;
2364 register EMACS_INT leni; 2352 register EMACS_INT leni;
2365 ptrdiff_t i, nargs; 2353 EMACS_INT nargs;
2354 ptrdiff_t i;
2366 register Lisp_Object *args; 2355 register Lisp_Object *args;
2367 struct gcpro gcpro1; 2356 struct gcpro gcpro1;
2368 Lisp_Object ret; 2357 Lisp_Object ret;
@@ -2649,7 +2638,7 @@ The normal messages at start and end of loading FILENAME are suppressed. */)
2649 2638
2650 if (NILP (tem)) 2639 if (NILP (tem))
2651 { 2640 {
2652 int count = SPECPDL_INDEX (); 2641 ptrdiff_t count = SPECPDL_INDEX ();
2653 int nesting = 0; 2642 int nesting = 0;
2654 2643
2655 /* 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
@@ -2952,9 +2941,9 @@ static const short base64_char_to_value[128] =
2952 base64 characters. */ 2941 base64 characters. */
2953 2942
2954 2943
2955static 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);
2956static EMACS_INT base64_decode_1 (const char *, char *, EMACS_INT, int, 2945static ptrdiff_t base64_decode_1 (const char *, char *, ptrdiff_t, int,
2957 EMACS_INT *); 2946 ptrdiff_t *);
2958 2947
2959DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region, 2948DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region,
2960 2, 3, "r", 2949 2, 3, "r",
@@ -2965,9 +2954,9 @@ into shorter lines. */)
2965 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break) 2954 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break)
2966{ 2955{
2967 char *encoded; 2956 char *encoded;
2968 EMACS_INT allength, length; 2957 ptrdiff_t allength, length;
2969 EMACS_INT ibeg, iend, encoded_length; 2958 ptrdiff_t ibeg, iend, encoded_length;
2970 EMACS_INT old_pos = PT; 2959 ptrdiff_t old_pos = PT;
2971 USE_SAFE_ALLOCA; 2960 USE_SAFE_ALLOCA;
2972 2961
2973 validate_region (&beg, &end); 2962 validate_region (&beg, &end);
@@ -3023,7 +3012,7 @@ Optional second argument NO-LINE-BREAK means do not break long lines
3023into shorter lines. */) 3012into shorter lines. */)
3024 (Lisp_Object string, Lisp_Object no_line_break) 3013 (Lisp_Object string, Lisp_Object no_line_break)
3025{ 3014{
3026 EMACS_INT allength, length, encoded_length; 3015 ptrdiff_t allength, length, encoded_length;
3027 char *encoded; 3016 char *encoded;
3028 Lisp_Object encoded_string; 3017 Lisp_Object encoded_string;
3029 USE_SAFE_ALLOCA; 3018 USE_SAFE_ALLOCA;
@@ -3059,12 +3048,12 @@ into shorter lines. */)
3059 return encoded_string; 3048 return encoded_string;
3060} 3049}
3061 3050
3062static EMACS_INT 3051static ptrdiff_t
3063base64_encode_1 (const char *from, char *to, EMACS_INT length, 3052base64_encode_1 (const char *from, char *to, ptrdiff_t length,
3064 int line_break, int multibyte) 3053 int line_break, int multibyte)
3065{ 3054{
3066 int counter = 0; 3055 int counter = 0;
3067 EMACS_INT i = 0; 3056 ptrdiff_t i = 0;
3068 char *e = to; 3057 char *e = to;
3069 int c; 3058 int c;
3070 unsigned int value; 3059 unsigned int value;
@@ -3163,11 +3152,11 @@ Return the length of the decoded text.
3163If 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. */)
3164 (Lisp_Object beg, Lisp_Object end) 3153 (Lisp_Object beg, Lisp_Object end)
3165{ 3154{
3166 EMACS_INT ibeg, iend, length, allength; 3155 ptrdiff_t ibeg, iend, length, allength;
3167 char *decoded; 3156 char *decoded;
3168 EMACS_INT old_pos = PT; 3157 ptrdiff_t old_pos = PT;
3169 EMACS_INT decoded_length; 3158 ptrdiff_t decoded_length;
3170 EMACS_INT inserted_chars; 3159 ptrdiff_t inserted_chars;
3171 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3160 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3172 USE_SAFE_ALLOCA; 3161 USE_SAFE_ALLOCA;
3173 3162
@@ -3225,7 +3214,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3225 (Lisp_Object string) 3214 (Lisp_Object string)
3226{ 3215{
3227 char *decoded; 3216 char *decoded;
3228 EMACS_INT length, decoded_length; 3217 ptrdiff_t length, decoded_length;
3229 Lisp_Object decoded_string; 3218 Lisp_Object decoded_string;
3230 USE_SAFE_ALLOCA; 3219 USE_SAFE_ALLOCA;
3231 3220
@@ -3257,15 +3246,15 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3257 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
3258 characters in *NCHARS_RETURN. */ 3247 characters in *NCHARS_RETURN. */
3259 3248
3260static EMACS_INT 3249static ptrdiff_t
3261base64_decode_1 (const char *from, char *to, EMACS_INT length, 3250base64_decode_1 (const char *from, char *to, ptrdiff_t length,
3262 int multibyte, EMACS_INT *nchars_return) 3251 int multibyte, ptrdiff_t *nchars_return)
3263{ 3252{
3264 EMACS_INT i = 0; /* Used inside READ_QUADRUPLET_BYTE */ 3253 ptrdiff_t i = 0; /* Used inside READ_QUADRUPLET_BYTE */
3265 char *e = to; 3254 char *e = to;
3266 unsigned char c; 3255 unsigned char c;
3267 unsigned long value; 3256 unsigned long value;
3268 EMACS_INT nchars = 0; 3257 ptrdiff_t nchars = 0;
3269 3258
3270 while (1) 3259 while (1)
3271 { 3260 {
@@ -3432,23 +3421,31 @@ get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used)
3432 3421
3433 3422
3434/* 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
3435 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting 3424 at least INCR_MIN more entries, where INCR_MIN is positive.
3436 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. */
3437 3428
3438Lisp_Object 3429Lisp_Object
3439larger_vector (Lisp_Object vec, EMACS_INT new_size, Lisp_Object init) 3430larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
3440{ 3431{
3441 struct Lisp_Vector *v; 3432 struct Lisp_Vector *v;
3442 EMACS_INT i, old_size; 3433 ptrdiff_t i, incr, incr_max, old_size, new_size;
3443 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);
3444 xassert (VECTORP (vec)); 3437 xassert (VECTORP (vec));
3438 xassert (0 < incr_min && -1 <= nitems_max);
3445 old_size = ASIZE (vec); 3439 old_size = ASIZE (vec);
3446 xassert (new_size >= old_size); 3440 incr_max = n_max - old_size;
3447 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;
3448 v = allocate_vector (new_size); 3445 v = allocate_vector (new_size);
3449 memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); 3446 memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents);
3450 for (i = old_size; i < new_size; ++i) 3447 for (i = old_size; i < new_size; ++i)
3451 v->contents[i] = init; 3448 v->contents[i] = Qnil;
3452 XSETVECTOR (vec, v); 3449 XSETVECTOR (vec, v);
3453 return vec; 3450 return vec;
3454} 3451}
@@ -3569,6 +3566,10 @@ hashfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key)
3569 return XUINT (hash); 3566 return XUINT (hash);
3570} 3567}
3571 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)))
3572 3573
3573/* Create and initialize a new hash table. 3574/* Create and initialize a new hash table.
3574 3575
@@ -3599,7 +3600,8 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size,
3599{ 3600{
3600 struct Lisp_Hash_Table *h; 3601 struct Lisp_Hash_Table *h;
3601 Lisp_Object table; 3602 Lisp_Object table;
3602 EMACS_INT index_size, i, sz; 3603 EMACS_INT index_size, sz;
3604 ptrdiff_t i;
3603 double index_float; 3605 double index_float;
3604 3606
3605 /* Preconditions. */ 3607 /* Preconditions. */
@@ -3616,10 +3618,10 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size,
3616 3618
3617 sz = XFASTINT (size); 3619 sz = XFASTINT (size);
3618 index_float = sz / XFLOAT_DATA (rehash_threshold); 3620 index_float = sz / XFLOAT_DATA (rehash_threshold);
3619 index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 3621 index_size = (index_float < INDEX_SIZE_BOUND + 1
3620 ? next_almost_prime (index_float) 3622 ? next_almost_prime (index_float)
3621 : MOST_POSITIVE_FIXNUM + 1); 3623 : INDEX_SIZE_BOUND + 1);
3622 if (MOST_POSITIVE_FIXNUM < max (index_size, 2 * sz)) 3624 if (INDEX_SIZE_BOUND < max (index_size, 2 * sz))
3623 error ("Hash table too large"); 3625 error ("Hash table too large");
3624 3626
3625 /* Allocate a table and initialize it. */ 3627 /* Allocate a table and initialize it. */
@@ -3720,9 +3722,9 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3720{ 3722{
3721 if (NILP (h->next_free)) 3723 if (NILP (h->next_free))
3722 { 3724 {
3723 EMACS_INT old_size = HASH_TABLE_SIZE (h); 3725 ptrdiff_t old_size = HASH_TABLE_SIZE (h);
3724 EMACS_INT i, new_size, index_size; 3726 EMACS_INT new_size, index_size, nsize;
3725 EMACS_INT nsize; 3727 ptrdiff_t i;
3726 double index_float; 3728 double index_float;
3727 3729
3728 if (INTEGERP (h->rehash_size)) 3730 if (INTEGERP (h->rehash_size))
@@ -3730,26 +3732,27 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3730 else 3732 else
3731 { 3733 {
3732 double float_new_size = old_size * XFLOAT_DATA (h->rehash_size); 3734 double float_new_size = old_size * XFLOAT_DATA (h->rehash_size);
3733 if (float_new_size < MOST_POSITIVE_FIXNUM + 1) 3735 if (float_new_size < INDEX_SIZE_BOUND + 1)
3734 { 3736 {
3735 new_size = float_new_size; 3737 new_size = float_new_size;
3736 if (new_size <= old_size) 3738 if (new_size <= old_size)
3737 new_size = old_size + 1; 3739 new_size = old_size + 1;
3738 } 3740 }
3739 else 3741 else
3740 new_size = MOST_POSITIVE_FIXNUM + 1; 3742 new_size = INDEX_SIZE_BOUND + 1;
3741 } 3743 }
3742 index_float = new_size / XFLOAT_DATA (h->rehash_threshold); 3744 index_float = new_size / XFLOAT_DATA (h->rehash_threshold);
3743 index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 3745 index_size = (index_float < INDEX_SIZE_BOUND + 1
3744 ? next_almost_prime (index_float) 3746 ? next_almost_prime (index_float)
3745 : MOST_POSITIVE_FIXNUM + 1); 3747 : INDEX_SIZE_BOUND + 1);
3746 nsize = max (index_size, 2 * new_size); 3748 nsize = max (index_size, 2 * new_size);
3747 if (nsize > MOST_POSITIVE_FIXNUM) 3749 if (INDEX_SIZE_BOUND < nsize)
3748 error ("Hash table too large to resize"); 3750 error ("Hash table too large to resize");
3749 3751
3750 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,
3751 h->next = larger_vector (h->next, new_size, Qnil); 3753 2 * (new_size - old_size), -1);
3752 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);
3753 h->index = Fmake_vector (make_number (index_size), Qnil); 3756 h->index = Fmake_vector (make_number (index_size), Qnil);
3754 3757
3755 /* 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
@@ -3777,7 +3780,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3777 if (!NILP (HASH_HASH (h, i))) 3780 if (!NILP (HASH_HASH (h, i)))
3778 { 3781 {
3779 EMACS_UINT hash_code = XUINT (HASH_HASH (h, i)); 3782 EMACS_UINT hash_code = XUINT (HASH_HASH (h, i));
3780 EMACS_INT start_of_bucket = hash_code % ASIZE (h->index); 3783 ptrdiff_t start_of_bucket = hash_code % ASIZE (h->index);
3781 HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket); 3784 HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket);
3782 HASH_INDEX (h, start_of_bucket) = make_number (i); 3785 HASH_INDEX (h, start_of_bucket) = make_number (i);
3783 } 3786 }
@@ -3806,7 +3809,7 @@ hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
3806 /* 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. */
3807 while (!NILP (idx)) 3810 while (!NILP (idx))
3808 { 3811 {
3809 EMACS_INT i = XFASTINT (idx); 3812 ptrdiff_t i = XFASTINT (idx);
3810 if (EQ (key, HASH_KEY (h, i)) 3813 if (EQ (key, HASH_KEY (h, i))
3811 || (h->cmpfn 3814 || (h->cmpfn
3812 && h->cmpfn (h, key, hash_code, 3815 && h->cmpfn (h, key, hash_code,
@@ -3858,7 +3861,7 @@ static void
3858hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) 3861hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
3859{ 3862{
3860 EMACS_UINT hash_code; 3863 EMACS_UINT hash_code;
3861 EMACS_INT start_of_bucket; 3864 ptrdiff_t start_of_bucket;
3862 Lisp_Object idx, prev; 3865 Lisp_Object idx, prev;
3863 3866
3864 hash_code = h->hashfn (h, key); 3867 hash_code = h->hashfn (h, key);
@@ -3869,7 +3872,7 @@ hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
3869 /* 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. */
3870 while (!NILP (idx)) 3873 while (!NILP (idx))
3871 { 3874 {
3872 EMACS_INT i = XFASTINT (idx); 3875 ptrdiff_t i = XFASTINT (idx);
3873 3876
3874 if (EQ (key, HASH_KEY (h, i)) 3877 if (EQ (key, HASH_KEY (h, i))
3875 || (h->cmpfn 3878 || (h->cmpfn
@@ -3907,7 +3910,7 @@ hash_clear (struct Lisp_Hash_Table *h)
3907{ 3910{
3908 if (h->count > 0) 3911 if (h->count > 0)
3909 { 3912 {
3910 EMACS_INT i, size = HASH_TABLE_SIZE (h); 3913 ptrdiff_t i, size = HASH_TABLE_SIZE (h);
3911 3914
3912 for (i = 0; i < size; ++i) 3915 for (i = 0; i < size; ++i)
3913 { 3916 {
@@ -3945,7 +3948,7 @@ init_weak_hash_tables (void)
3945static int 3948static int
3946sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p) 3949sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
3947{ 3950{
3948 EMACS_INT bucket, n; 3951 ptrdiff_t bucket, n;
3949 int marked; 3952 int marked;
3950 3953
3951 n = ASIZE (h->index) & ~ARRAY_MARK_FLAG; 3954 n = ASIZE (h->index) & ~ARRAY_MARK_FLAG;
@@ -3960,7 +3963,7 @@ sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
3960 prev = Qnil; 3963 prev = Qnil;
3961 for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next) 3964 for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next)
3962 { 3965 {
3963 EMACS_INT i = XFASTINT (idx); 3966 ptrdiff_t i = XFASTINT (idx);
3964 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));
3965 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));
3966 int remove_p; 3969 int remove_p;
@@ -4526,7 +4529,7 @@ FUNCTION is called with two arguments, KEY and VALUE. */)
4526{ 4529{
4527 struct Lisp_Hash_Table *h = check_hash_table (table); 4530 struct Lisp_Hash_Table *h = check_hash_table (table);
4528 Lisp_Object args[3]; 4531 Lisp_Object args[3];
4529 EMACS_INT i; 4532 ptrdiff_t i;
4530 4533
4531 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) 4534 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
4532 if (!NILP (HASH_HASH (h, i))) 4535 if (!NILP (HASH_HASH (h, i)))
@@ -4575,10 +4578,9 @@ static Lisp_Object
4575secure_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)
4576{ 4579{
4577 int i; 4580 int i;
4578 EMACS_INT size; 4581 ptrdiff_t size;
4579 EMACS_INT size_byte = 0;
4580 EMACS_INT start_char = 0, end_char = 0; 4582 EMACS_INT start_char = 0, end_char = 0;
4581 EMACS_INT start_byte = 0, end_byte = 0; 4583 ptrdiff_t start_byte, end_byte;
4582 register EMACS_INT b, e; 4584 register EMACS_INT b, e;
4583 register struct buffer *bp; 4585 register struct buffer *bp;
4584 EMACS_INT temp; 4586 EMACS_INT temp;
@@ -4615,7 +4617,6 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4615 object = code_convert_string (object, coding_system, Qnil, 1, 0, 1); 4617 object = code_convert_string (object, coding_system, Qnil, 1, 0, 1);
4616 4618
4617 size = SCHARS (object); 4619 size = SCHARS (object);
4618 size_byte = SBYTES (object);
4619 4620
4620 if (!NILP (start)) 4621 if (!NILP (start))
4621 { 4622 {
@@ -4625,15 +4626,10 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4625 4626
4626 if (start_char < 0) 4627 if (start_char < 0)
4627 start_char += size; 4628 start_char += size;
4628
4629 start_byte = string_char_to_byte (object, start_char);
4630 } 4629 }
4631 4630
4632 if (NILP (end)) 4631 if (NILP (end))
4633 { 4632 end_char = size;
4634 end_char = size;
4635 end_byte = size_byte;
4636 }
4637 else 4633 else
4638 { 4634 {
4639 CHECK_NUMBER (end); 4635 CHECK_NUMBER (end);
@@ -4642,13 +4638,15 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4642 4638
4643 if (end_char < 0) 4639 if (end_char < 0)
4644 end_char += size; 4640 end_char += size;
4645
4646 end_byte = string_char_to_byte (object, end_char);
4647 } 4641 }
4648 4642
4649 if (!(0 <= start_char && start_char <= end_char && end_char <= size)) 4643 if (!(0 <= start_char && start_char <= end_char && end_char <= size))
4650 args_out_of_range_3 (object, make_number (start_char), 4644 args_out_of_range_3 (object, make_number (start_char),
4651 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);
4652 } 4650 }
4653 else 4651 else
4654 { 4652 {
@@ -4755,6 +4753,8 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4755 4753
4756 if (STRING_MULTIBYTE (object)) 4754 if (STRING_MULTIBYTE (object))
4757 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);
4758 } 4758 }
4759 4759
4760 if (EQ (algorithm, Qmd5)) 4760 if (EQ (algorithm, Qmd5))
@@ -4795,7 +4795,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4795 digest = make_uninit_string (digest_size * 2); 4795 digest = make_uninit_string (digest_size * 2);
4796 4796
4797 hash_func (SSDATA (object) + start_byte, 4797 hash_func (SSDATA (object) + start_byte,
4798 SBYTES (object) - (size_byte - end_byte), 4798 end_byte - start_byte,
4799 SSDATA (digest)); 4799 SSDATA (digest));
4800 4800
4801 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..744485d4615 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -331,7 +331,7 @@ make_frame (int mini_p)
331 mini_window = make_window (); 331 mini_window = make_window ();
332 XWINDOW (root_window)->next = mini_window; 332 XWINDOW (root_window)->next = mini_window;
333 XWINDOW (mini_window)->prev = root_window; 333 XWINDOW (mini_window)->prev = root_window;
334 XWINDOW (mini_window)->mini_p = Qt; 334 XWINDOW (mini_window)->mini = 1;
335 XWINDOW (mini_window)->frame = frame; 335 XWINDOW (mini_window)->frame = frame;
336 f->minibuffer_window = mini_window; 336 f->minibuffer_window = mini_window;
337 } 337 }
@@ -480,7 +480,7 @@ make_minibuffer_frame (void)
480 as nil. */ 480 as nil. */
481 481
482 mini_window = f->minibuffer_window = f->root_window; 482 mini_window = f->minibuffer_window = f->root_window;
483 XWINDOW (mini_window)->mini_p = Qt; 483 XWINDOW (mini_window)->mini = 1;
484 XWINDOW (mini_window)->next = Qnil; 484 XWINDOW (mini_window)->next = Qnil;
485 XWINDOW (mini_window)->prev = Qnil; 485 XWINDOW (mini_window)->prev = Qnil;
486 XWINDOW (mini_window)->frame = frame; 486 XWINDOW (mini_window)->frame = frame;
@@ -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/gmalloc.c b/src/gmalloc.c
index 38406fd029a..0df050e127a 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -1004,7 +1004,7 @@ _free_internal_nolock (void *ptr)
1004 return; 1004 return;
1005 1005
1006#ifdef CYGWIN 1006#ifdef CYGWIN
1007 if (ptr < _heapbase) 1007 if ((char *) ptr < _heapbase)
1008 /* We're being asked to free something in the static heap. */ 1008 /* We're being asked to free something in the static heap. */
1009 return; 1009 return;
1010#endif 1010#endif
@@ -1341,7 +1341,7 @@ _realloc_internal_nolock (void *ptr, size_t size)
1341 return _malloc_internal_nolock (size); 1341 return _malloc_internal_nolock (size);
1342 1342
1343#ifdef CYGWIN 1343#ifdef CYGWIN
1344 if (ptr < _heapbase) 1344 if ((char *) ptr < _heapbase)
1345 /* ptr points into the static heap */ 1345 /* ptr points into the static heap */
1346 return special_realloc (ptr, size); 1346 return special_realloc (ptr, size);
1347#endif 1347#endif
@@ -1531,10 +1531,6 @@ MA 02110-1301, USA. */
1531extern void *__sbrk (ptrdiff_t increment); 1531extern void *__sbrk (ptrdiff_t increment);
1532#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ 1532#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */
1533 1533
1534#ifndef NULL
1535#define NULL 0
1536#endif
1537
1538/* Allocate INCREMENT more bytes of data space, 1534/* Allocate INCREMENT more bytes of data space,
1539 and return the start of data space, or NULL on errors. 1535 and return the start of data space, or NULL on errors.
1540 If INCREMENT is negative, shrink data space. */ 1536 If INCREMENT is negative, shrink data space. */
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..b6cdb6c8290 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1,5 +1,6 @@
1/* Functions for image support on window system. 1/* Functions for image support on window system.
2 Copyright (C) 1989, 1992-2012 Free Software Foundation, Inc. 2
3Copyright (C) 1989, 1992-2012 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
@@ -771,10 +772,9 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
771 /* Record that we recognized the keyword. If a keywords 772 /* Record that we recognized the keyword. If a keywords
772 was found more than once, it's an error. */ 773 was found more than once, it's an error. */
773 keywords[i].value = value; 774 keywords[i].value = value;
774 ++keywords[i].count;
775
776 if (keywords[i].count > 1) 775 if (keywords[i].count > 1)
777 return 0; 776 return 0;
777 ++keywords[i].count;
778 778
779 /* Check type of value against allowed type. */ 779 /* Check type of value against allowed type. */
780 switch (keywords[i].type) 780 switch (keywords[i].type)
@@ -1754,6 +1754,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1754 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF', 1754 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
1755 `:background COLOR'. */ 1755 `:background COLOR'. */
1756 Lisp_Object ascent, margin, relief, bg; 1756 Lisp_Object ascent, margin, relief, bg;
1757 int relief_bound;
1757 1758
1758 ascent = image_spec_value (spec, QCascent, NULL); 1759 ascent = image_spec_value (spec, QCascent, NULL);
1759 if (INTEGERP (ascent)) 1760 if (INTEGERP (ascent))
@@ -1771,7 +1772,8 @@ lookup_image (struct frame *f, Lisp_Object spec)
1771 } 1772 }
1772 1773
1773 relief = image_spec_value (spec, QCrelief, NULL); 1774 relief = image_spec_value (spec, QCrelief, NULL);
1774 if (INTEGERP (relief)) 1775 relief_bound = INT_MAX - max (img->hmargin, img->vmargin);
1776 if (RANGED_INTEGERP (- relief_bound, relief, relief_bound))
1775 { 1777 {
1776 img->relief = XINT (relief); 1778 img->relief = XINT (relief);
1777 img->hmargin += eabs (img->relief); 1779 img->hmargin += eabs (img->relief);
@@ -7986,7 +7988,8 @@ their descriptions (http://www.imagemagick.org/script/formats.php).
7986You can also try the shell command: `identify -list format'. 7988You can also try the shell command: `identify -list format'.
7987 7989
7988Note that ImageMagick recognizes many file-types that Emacs does not 7990Note that ImageMagick recognizes many file-types that Emacs does not
7989recognize as images, such as C. See `imagemagick-types-inhibit'. */) 7991recognize as images, such as C. See `imagemagick-types-enable'
7992and `imagemagick-types-inhibit'. */)
7990 (void) 7993 (void)
7991{ 7994{
7992 Lisp_Object typelist = Qnil; 7995 Lisp_Object typelist = Qnil;
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 34d82fa017d..148ba221940 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -31,19 +31,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include "blockinput.h" 31#include "blockinput.h"
32#include "region-cache.h" 32#include "region-cache.h"
33 33
34#ifndef NULL
35#define NULL 0
36#endif
37
38static void insert_from_string_1 (Lisp_Object string, 34static void insert_from_string_1 (Lisp_Object string,
39 EMACS_INT pos, EMACS_INT pos_byte, 35 ptrdiff_t pos, ptrdiff_t pos_byte,
40 EMACS_INT nchars, EMACS_INT nbytes, 36 ptrdiff_t nchars, ptrdiff_t nbytes,
41 int inherit, int before_markers); 37 int inherit, int before_markers);
42static void insert_from_buffer_1 (struct buffer *buf, 38static void insert_from_buffer_1 (struct buffer *buf,
43 EMACS_INT from, EMACS_INT nchars, 39 ptrdiff_t from, ptrdiff_t nchars,
44 int inherit); 40 int inherit);
45static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap); 41static void gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap);
46static void gap_right (EMACS_INT charpos, EMACS_INT bytepos); 42static void gap_right (ptrdiff_t charpos, ptrdiff_t bytepos);
47 43
48static Lisp_Object Fcombine_after_change_execute (void); 44static Lisp_Object Fcombine_after_change_execute (void);
49 45
@@ -64,7 +60,7 @@ static Lisp_Object combine_after_change_buffer;
64 60
65Lisp_Object Qinhibit_modification_hooks; 61Lisp_Object Qinhibit_modification_hooks;
66 62
67static void signal_before_change (EMACS_INT, EMACS_INT, EMACS_INT *); 63static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
68 64
69#define CHECK_MARKERS() \ 65#define CHECK_MARKERS() \
70 do \ 66 do \
@@ -97,7 +93,7 @@ check_markers (void)
97 Note that this can quit! */ 93 Note that this can quit! */
98 94
99void 95void
100move_gap (EMACS_INT charpos) 96move_gap (ptrdiff_t charpos)
101{ 97{
102 move_gap_both (charpos, charpos_to_bytepos (charpos)); 98 move_gap_both (charpos, charpos_to_bytepos (charpos));
103} 99}
@@ -106,7 +102,7 @@ move_gap (EMACS_INT charpos)
106 Note that this can quit! */ 102 Note that this can quit! */
107 103
108void 104void
109move_gap_both (EMACS_INT charpos, EMACS_INT bytepos) 105move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos)
110{ 106{
111 if (bytepos < GPT_BYTE) 107 if (bytepos < GPT_BYTE)
112 gap_left (charpos, bytepos, 0); 108 gap_left (charpos, bytepos, 0);
@@ -120,11 +116,11 @@ move_gap_both (EMACS_INT charpos, EMACS_INT bytepos)
120 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. */
121 117
122static void 118static void
123gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap) 119gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap)
124{ 120{
125 register unsigned char *to, *from; 121 register unsigned char *to, *from;
126 register EMACS_INT i; 122 register ptrdiff_t i;
127 EMACS_INT new_s1; 123 ptrdiff_t new_s1;
128 124
129 if (!newgap) 125 if (!newgap)
130 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT); 126 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT);
@@ -175,11 +171,11 @@ gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap)
175 and CHARPOS is the corresponding char position. */ 171 and CHARPOS is the corresponding char position. */
176 172
177static void 173static void
178gap_right (EMACS_INT charpos, EMACS_INT bytepos) 174gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
179{ 175{
180 register unsigned char *to, *from; 176 register unsigned char *to, *from;
181 register EMACS_INT i; 177 register ptrdiff_t i;
182 EMACS_INT new_s1; 178 ptrdiff_t new_s1;
183 179
184 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT); 180 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT);
185 181
@@ -229,12 +225,12 @@ gap_right (EMACS_INT charpos, EMACS_INT bytepos)
229 or inside of the range being deleted. */ 225 or inside of the range being deleted. */
230 226
231void 227void
232adjust_markers_for_delete (EMACS_INT from, EMACS_INT from_byte, 228adjust_markers_for_delete (ptrdiff_t from, ptrdiff_t from_byte,
233 EMACS_INT to, EMACS_INT to_byte) 229 ptrdiff_t to, ptrdiff_t to_byte)
234{ 230{
235 Lisp_Object marker; 231 Lisp_Object marker;
236 register struct Lisp_Marker *m; 232 register struct Lisp_Marker *m;
237 register EMACS_INT charpos; 233 register ptrdiff_t charpos;
238 234
239 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 235 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
240 { 236 {
@@ -294,13 +290,13 @@ adjust_markers_for_delete (EMACS_INT from, EMACS_INT from_byte,
294 or BEFORE_MARKERS is true. */ 290 or BEFORE_MARKERS is true. */
295 291
296static void 292static void
297adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte, 293adjust_markers_for_insert (ptrdiff_t from, ptrdiff_t from_byte,
298 EMACS_INT to, EMACS_INT to_byte, int before_markers) 294 ptrdiff_t to, ptrdiff_t to_byte, int before_markers)
299{ 295{
300 struct Lisp_Marker *m; 296 struct Lisp_Marker *m;
301 int adjusted = 0; 297 int adjusted = 0;
302 EMACS_INT nchars = to - from; 298 ptrdiff_t nchars = to - from;
303 EMACS_INT nbytes = to_byte - from_byte; 299 ptrdiff_t nbytes = to_byte - from_byte;
304 300
305 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 301 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
306 { 302 {
@@ -345,7 +341,7 @@ adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte,
345 intervals. */ 341 intervals. */
346 342
347static void 343static void
348adjust_point (EMACS_INT nchars, EMACS_INT nbytes) 344adjust_point (ptrdiff_t nchars, ptrdiff_t nbytes)
349{ 345{
350 SET_BUF_PT_BOTH (current_buffer, PT + nchars, PT_BYTE + nbytes); 346 SET_BUF_PT_BOTH (current_buffer, PT + nchars, PT_BYTE + nbytes);
351 /* In a single-byte buffer, the two positions must be equal. */ 347 /* In a single-byte buffer, the two positions must be equal. */
@@ -358,14 +354,14 @@ adjust_point (EMACS_INT nchars, EMACS_INT nbytes)
358 an insertion. */ 354 an insertion. */
359 355
360static void 356static void
361adjust_markers_for_replace (EMACS_INT from, EMACS_INT from_byte, 357adjust_markers_for_replace (ptrdiff_t from, ptrdiff_t from_byte,
362 EMACS_INT old_chars, EMACS_INT old_bytes, 358 ptrdiff_t old_chars, ptrdiff_t old_bytes,
363 EMACS_INT new_chars, EMACS_INT new_bytes) 359 ptrdiff_t new_chars, ptrdiff_t new_bytes)
364{ 360{
365 register struct Lisp_Marker *m; 361 register struct Lisp_Marker *m;
366 EMACS_INT prev_to_byte = from_byte + old_bytes; 362 ptrdiff_t prev_to_byte = from_byte + old_bytes;
367 EMACS_INT diff_chars = new_chars - old_chars; 363 ptrdiff_t diff_chars = new_chars - old_chars;
368 EMACS_INT diff_bytes = new_bytes - old_bytes; 364 ptrdiff_t diff_bytes = new_bytes - old_bytes;
369 365
370 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 366 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
371 { 367 {
@@ -394,13 +390,13 @@ buffer_overflow (void)
394/* Make the gap NBYTES_ADDED bytes longer. */ 390/* Make the gap NBYTES_ADDED bytes longer. */
395 391
396static void 392static void
397make_gap_larger (EMACS_INT nbytes_added) 393make_gap_larger (ptrdiff_t nbytes_added)
398{ 394{
399 Lisp_Object tem; 395 Lisp_Object tem;
400 EMACS_INT real_gap_loc; 396 ptrdiff_t real_gap_loc;
401 EMACS_INT real_gap_loc_byte; 397 ptrdiff_t real_gap_loc_byte;
402 EMACS_INT old_gap_size; 398 ptrdiff_t old_gap_size;
403 EMACS_INT current_size = Z_BYTE - BEG_BYTE + GAP_SIZE; 399 ptrdiff_t current_size = Z_BYTE - BEG_BYTE + GAP_SIZE;
404 enum { enough_for_a_while = 2000 }; 400 enum { enough_for_a_while = 2000 };
405 401
406 if (BUF_BYTES_MAX - current_size < nbytes_added) 402 if (BUF_BYTES_MAX - current_size < nbytes_added)
@@ -446,15 +442,15 @@ make_gap_larger (EMACS_INT nbytes_added)
446/* Make the gap NBYTES_REMOVED bytes shorter. */ 442/* Make the gap NBYTES_REMOVED bytes shorter. */
447 443
448static void 444static void
449make_gap_smaller (EMACS_INT nbytes_removed) 445make_gap_smaller (ptrdiff_t nbytes_removed)
450{ 446{
451 Lisp_Object tem; 447 Lisp_Object tem;
452 EMACS_INT real_gap_loc; 448 ptrdiff_t real_gap_loc;
453 EMACS_INT real_gap_loc_byte; 449 ptrdiff_t real_gap_loc_byte;
454 EMACS_INT real_Z; 450 ptrdiff_t real_Z;
455 EMACS_INT real_Z_byte; 451 ptrdiff_t real_Z_byte;
456 EMACS_INT real_beg_unchanged; 452 ptrdiff_t real_beg_unchanged;
457 EMACS_INT new_gap_size; 453 ptrdiff_t new_gap_size;
458 454
459 /* Make sure the gap is at least 20 bytes. */ 455 /* Make sure the gap is at least 20 bytes. */
460 if (GAP_SIZE - nbytes_removed < 20) 456 if (GAP_SIZE - nbytes_removed < 20)
@@ -504,7 +500,7 @@ make_gap_smaller (EMACS_INT nbytes_removed)
504#endif /* USE_MMAP_FOR_BUFFERS || REL_ALLOC || DOUG_LEA_MALLOC */ 500#endif /* USE_MMAP_FOR_BUFFERS || REL_ALLOC || DOUG_LEA_MALLOC */
505 501
506void 502void
507make_gap (EMACS_INT nbytes_added) 503make_gap (ptrdiff_t nbytes_added)
508{ 504{
509 if (nbytes_added >= 0) 505 if (nbytes_added >= 0)
510 make_gap_larger (nbytes_added); 506 make_gap_larger (nbytes_added);
@@ -521,9 +517,9 @@ make_gap (EMACS_INT nbytes_added)
521 517
522 Return the number of bytes stored at TO_ADDR. */ 518 Return the number of bytes stored at TO_ADDR. */
523 519
524EMACS_INT 520ptrdiff_t
525copy_text (const unsigned char *from_addr, unsigned char *to_addr, 521copy_text (const unsigned char *from_addr, unsigned char *to_addr,
526 EMACS_INT nbytes, int from_multibyte, int to_multibyte) 522 ptrdiff_t nbytes, int from_multibyte, int to_multibyte)
527{ 523{
528 if (from_multibyte == to_multibyte) 524 if (from_multibyte == to_multibyte)
529 { 525 {
@@ -532,8 +528,8 @@ copy_text (const unsigned char *from_addr, unsigned char *to_addr,
532 } 528 }
533 else if (from_multibyte) 529 else if (from_multibyte)
534 { 530 {
535 EMACS_INT nchars = 0; 531 ptrdiff_t nchars = 0;
536 EMACS_INT bytes_left = nbytes; 532 ptrdiff_t bytes_left = nbytes;
537 533
538 while (bytes_left > 0) 534 while (bytes_left > 0)
539 { 535 {
@@ -580,11 +576,11 @@ copy_text (const unsigned char *from_addr, unsigned char *to_addr,
580 prepare_to_modify_buffer could relocate the text. */ 576 prepare_to_modify_buffer could relocate the text. */
581 577
582void 578void
583insert (const char *string, EMACS_INT nbytes) 579insert (const char *string, ptrdiff_t nbytes)
584{ 580{
585 if (nbytes > 0) 581 if (nbytes > 0)
586 { 582 {
587 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 583 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
588 insert_1_both (string, len, nbytes, 0, 1, 0); 584 insert_1_both (string, len, nbytes, 0, 1, 0);
589 opoint = PT - len; 585 opoint = PT - len;
590 signal_after_change (opoint, 0, len); 586 signal_after_change (opoint, 0, len);
@@ -595,11 +591,11 @@ insert (const char *string, EMACS_INT nbytes)
595/* Likewise, but inherit text properties from neighboring characters. */ 591/* Likewise, but inherit text properties from neighboring characters. */
596 592
597void 593void
598insert_and_inherit (const char *string, EMACS_INT nbytes) 594insert_and_inherit (const char *string, ptrdiff_t nbytes)
599{ 595{
600 if (nbytes > 0) 596 if (nbytes > 0)
601 { 597 {
602 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 598 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
603 insert_1_both (string, len, nbytes, 1, 1, 0); 599 insert_1_both (string, len, nbytes, 1, 1, 0);
604 opoint = PT - len; 600 opoint = PT - len;
605 signal_after_change (opoint, 0, len); 601 signal_after_change (opoint, 0, len);
@@ -640,11 +636,11 @@ insert_string (const char *s)
640 since gc could happen and relocate it. */ 636 since gc could happen and relocate it. */
641 637
642void 638void
643insert_before_markers (const char *string, EMACS_INT nbytes) 639insert_before_markers (const char *string, ptrdiff_t nbytes)
644{ 640{
645 if (nbytes > 0) 641 if (nbytes > 0)
646 { 642 {
647 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 643 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
648 insert_1_both (string, len, nbytes, 0, 1, 1); 644 insert_1_both (string, len, nbytes, 0, 1, 1);
649 opoint = PT - len; 645 opoint = PT - len;
650 signal_after_change (opoint, 0, len); 646 signal_after_change (opoint, 0, len);
@@ -656,11 +652,11 @@ insert_before_markers (const char *string, EMACS_INT nbytes)
656 652
657void 653void
658insert_before_markers_and_inherit (const char *string, 654insert_before_markers_and_inherit (const char *string,
659 EMACS_INT nbytes) 655 ptrdiff_t nbytes)
660{ 656{
661 if (nbytes > 0) 657 if (nbytes > 0)
662 { 658 {
663 EMACS_INT len = chars_in_text ((unsigned char *) string, nbytes), opoint; 659 ptrdiff_t len = chars_in_text ((unsigned char *) string, nbytes), opoint;
664 insert_1_both (string, len, nbytes, 1, 1, 1); 660 insert_1_both (string, len, nbytes, 1, 1, 1);
665 opoint = PT - len; 661 opoint = PT - len;
666 signal_after_change (opoint, 0, len); 662 signal_after_change (opoint, 0, len);
@@ -671,7 +667,7 @@ insert_before_markers_and_inherit (const char *string,
671/* Subroutine used by the insert functions above. */ 667/* Subroutine used by the insert functions above. */
672 668
673void 669void
674insert_1 (const char *string, EMACS_INT nbytes, 670insert_1 (const char *string, ptrdiff_t nbytes,
675 int inherit, int prepare, int before_markers) 671 int inherit, int prepare, int before_markers)
676{ 672{
677 insert_1_both (string, chars_in_text ((unsigned char *) string, nbytes), 673 insert_1_both (string, chars_in_text ((unsigned char *) string, nbytes),
@@ -687,8 +683,8 @@ insert_1 (const char *string, EMACS_INT nbytes,
687 which combine in this way. Otherwise, return 0. */ 683 which combine in this way. Otherwise, return 0. */
688 684
689int 685int
690count_combining_before (const unsigned char *string, EMACS_INT length, 686count_combining_before (const unsigned char *string, ptrdiff_t length,
691 EMACS_INT pos, EMACS_INT pos_byte) 687 ptrdiff_t pos, ptrdiff_t pos_byte)
692{ 688{
693 int len, combining_bytes; 689 int len, combining_bytes;
694 const unsigned char *p; 690 const unsigned char *p;
@@ -733,11 +729,11 @@ count_combining_before (const unsigned char *string, EMACS_INT length,
733 729
734int 730int
735count_combining_after (const unsigned char *string, 731count_combining_after (const unsigned char *string,
736 EMACS_INT length, EMACS_INT pos, EMACS_INT pos_byte) 732 ptrdiff_t length, ptrdiff_t pos, ptrdiff_t pos_byte)
737{ 733{
738 EMACS_INT opos_byte = pos_byte; 734 ptrdiff_t opos_byte = pos_byte;
739 EMACS_INT i; 735 ptrdiff_t i;
740 EMACS_INT bytes; 736 ptrdiff_t bytes;
741 unsigned char *bufp; 737 unsigned char *bufp;
742 738
743 if (NILP (current_buffer->enable_multibyte_characters)) 739 if (NILP (current_buffer->enable_multibyte_characters))
@@ -797,7 +793,7 @@ count_combining_after (const unsigned char *string,
797 793
798void 794void
799insert_1_both (const char *string, 795insert_1_both (const char *string,
800 EMACS_INT nchars, EMACS_INT nbytes, 796 ptrdiff_t nchars, ptrdiff_t nbytes,
801 int inherit, int prepare, int before_markers) 797 int inherit, int prepare, int before_markers)
802{ 798{
803 if (nchars == 0) 799 if (nchars == 0)
@@ -875,10 +871,10 @@ insert_1_both (const char *string,
875 without insert noticing. */ 871 without insert noticing. */
876 872
877void 873void
878insert_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,
879 EMACS_INT length, EMACS_INT length_byte, int inherit) 875 ptrdiff_t length, ptrdiff_t length_byte, int inherit)
880{ 876{
881 EMACS_INT opoint = PT; 877 ptrdiff_t opoint = PT;
882 878
883 if (SCHARS (string) == 0) 879 if (SCHARS (string) == 0)
884 return; 880 return;
@@ -894,11 +890,11 @@ insert_from_string (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
894 890
895void 891void
896insert_from_string_before_markers (Lisp_Object string, 892insert_from_string_before_markers (Lisp_Object string,
897 EMACS_INT pos, EMACS_INT pos_byte, 893 ptrdiff_t pos, ptrdiff_t pos_byte,
898 EMACS_INT length, EMACS_INT length_byte, 894 ptrdiff_t length, ptrdiff_t length_byte,
899 int inherit) 895 int inherit)
900{ 896{
901 EMACS_INT opoint = PT; 897 ptrdiff_t opoint = PT;
902 898
903 if (SCHARS (string) == 0) 899 if (SCHARS (string) == 0)
904 return; 900 return;
@@ -912,12 +908,12 @@ insert_from_string_before_markers (Lisp_Object string,
912/* Subroutine of the insertion functions above. */ 908/* Subroutine of the insertion functions above. */
913 909
914static void 910static void
915insert_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,
916 EMACS_INT nchars, EMACS_INT nbytes, 912 ptrdiff_t nchars, ptrdiff_t nbytes,
917 int inherit, int before_markers) 913 int inherit, int before_markers)
918{ 914{
919 struct gcpro gcpro1; 915 struct gcpro gcpro1;
920 EMACS_INT outgoing_nbytes = nbytes; 916 ptrdiff_t outgoing_nbytes = nbytes;
921 INTERVAL intervals; 917 INTERVAL intervals;
922 918
923 /* Make OUTGOING_NBYTES describe the text 919 /* Make OUTGOING_NBYTES describe the text
@@ -1004,7 +1000,7 @@ insert_from_string_1 (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1004 starting at GPT_ADDR. */ 1000 starting at GPT_ADDR. */
1005 1001
1006void 1002void
1007insert_from_gap (EMACS_INT nchars, EMACS_INT nbytes) 1003insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
1008{ 1004{
1009 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 1005 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1010 nchars = nbytes; 1006 nchars = nbytes;
@@ -1050,9 +1046,9 @@ insert_from_gap (EMACS_INT nchars, EMACS_INT nbytes)
1050 1046
1051void 1047void
1052insert_from_buffer (struct buffer *buf, 1048insert_from_buffer (struct buffer *buf,
1053 EMACS_INT charpos, EMACS_INT nchars, int inherit) 1049 ptrdiff_t charpos, ptrdiff_t nchars, int inherit)
1054{ 1050{
1055 EMACS_INT opoint = PT; 1051 ptrdiff_t opoint = PT;
1056 1052
1057 insert_from_buffer_1 (buf, charpos, nchars, inherit); 1053 insert_from_buffer_1 (buf, charpos, nchars, inherit);
1058 signal_after_change (opoint, 0, PT - opoint); 1054 signal_after_change (opoint, 0, PT - opoint);
@@ -1061,13 +1057,13 @@ insert_from_buffer (struct buffer *buf,
1061 1057
1062static void 1058static void
1063insert_from_buffer_1 (struct buffer *buf, 1059insert_from_buffer_1 (struct buffer *buf,
1064 EMACS_INT from, EMACS_INT nchars, int inherit) 1060 ptrdiff_t from, ptrdiff_t nchars, int inherit)
1065{ 1061{
1066 EMACS_INT chunk, chunk_expanded; 1062 ptrdiff_t chunk, chunk_expanded;
1067 EMACS_INT from_byte = buf_charpos_to_bytepos (buf, from); 1063 ptrdiff_t from_byte = buf_charpos_to_bytepos (buf, from);
1068 EMACS_INT to_byte = buf_charpos_to_bytepos (buf, from + nchars); 1064 ptrdiff_t to_byte = buf_charpos_to_bytepos (buf, from + nchars);
1069 EMACS_INT incoming_nbytes = to_byte - from_byte; 1065 ptrdiff_t incoming_nbytes = to_byte - from_byte;
1070 EMACS_INT outgoing_nbytes = incoming_nbytes; 1066 ptrdiff_t outgoing_nbytes = incoming_nbytes;
1071 INTERVAL intervals; 1067 INTERVAL intervals;
1072 1068
1073 /* Make OUTGOING_NBYTES describe the text 1069 /* Make OUTGOING_NBYTES describe the text
@@ -1077,8 +1073,8 @@ insert_from_buffer_1 (struct buffer *buf,
1077 outgoing_nbytes = nchars; 1073 outgoing_nbytes = nchars;
1078 else if (NILP (BVAR (buf, enable_multibyte_characters))) 1074 else if (NILP (BVAR (buf, enable_multibyte_characters)))
1079 { 1075 {
1080 EMACS_INT outgoing_before_gap = 0; 1076 ptrdiff_t outgoing_before_gap = 0;
1081 EMACS_INT outgoing_after_gap = 0; 1077 ptrdiff_t outgoing_after_gap = 0;
1082 1078
1083 if (from < BUF_GPT (buf)) 1079 if (from < BUF_GPT (buf))
1084 { 1080 {
@@ -1195,10 +1191,10 @@ insert_from_buffer_1 (struct buffer *buf,
1195 PREV_TEXT nil means the new text was just inserted. */ 1191 PREV_TEXT nil means the new text was just inserted. */
1196 1192
1197static void 1193static void
1198adjust_after_replace (EMACS_INT from, EMACS_INT from_byte, 1194adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
1199 Lisp_Object prev_text, EMACS_INT len, EMACS_INT len_byte) 1195 Lisp_Object prev_text, ptrdiff_t len, ptrdiff_t len_byte)
1200{ 1196{
1201 EMACS_INT nchars_del = 0, nbytes_del = 0; 1197 ptrdiff_t nchars_del = 0, nbytes_del = 0;
1202 1198
1203#ifdef BYTE_COMBINING_DEBUG 1199#ifdef BYTE_COMBINING_DEBUG
1204 if (count_combining_before (GPT_ADDR, len_byte, from, from_byte) 1200 if (count_combining_before (GPT_ADDR, len_byte, from, from_byte)
@@ -1263,10 +1259,10 @@ adjust_after_replace (EMACS_INT from, EMACS_INT from_byte,
1263 - FROM) may be incorrect, the correct length is NEWLEN. */ 1259 - FROM) may be incorrect, the correct length is NEWLEN. */
1264 1260
1265void 1261void
1266adjust_after_insert (EMACS_INT from, EMACS_INT from_byte, 1262adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
1267 EMACS_INT to, EMACS_INT to_byte, EMACS_INT newlen) 1263 ptrdiff_t to, ptrdiff_t to_byte, ptrdiff_t newlen)
1268{ 1264{
1269 EMACS_INT len = to - from, len_byte = to_byte - from_byte; 1265 ptrdiff_t len = to - from, len_byte = to_byte - from_byte;
1270 1266
1271 if (GPT != to) 1267 if (GPT != to)
1272 move_gap_both (to, to_byte); 1268 move_gap_both (to, to_byte);
@@ -1290,16 +1286,16 @@ adjust_after_insert (EMACS_INT from, EMACS_INT from_byte,
1290 But if MARKERS is 0, don't relocate markers. */ 1286 But if MARKERS is 0, don't relocate markers. */
1291 1287
1292void 1288void
1293replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new, 1289replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1294 int prepare, int inherit, int markers) 1290 int prepare, int inherit, int markers)
1295{ 1291{
1296 EMACS_INT inschars = SCHARS (new); 1292 ptrdiff_t inschars = SCHARS (new);
1297 EMACS_INT insbytes = SBYTES (new); 1293 ptrdiff_t insbytes = SBYTES (new);
1298 EMACS_INT from_byte, to_byte; 1294 ptrdiff_t from_byte, to_byte;
1299 EMACS_INT nbytes_del, nchars_del; 1295 ptrdiff_t nbytes_del, nchars_del;
1300 struct gcpro gcpro1; 1296 struct gcpro gcpro1;
1301 INTERVAL intervals; 1297 INTERVAL intervals;
1302 EMACS_INT outgoing_insbytes = insbytes; 1298 ptrdiff_t outgoing_insbytes = insbytes;
1303 Lisp_Object deletion; 1299 Lisp_Object deletion;
1304 1300
1305 CHECK_MARKERS (); 1301 CHECK_MARKERS ();
@@ -1309,7 +1305,7 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new,
1309 1305
1310 if (prepare) 1306 if (prepare)
1311 { 1307 {
1312 EMACS_INT range_length = to - from; 1308 ptrdiff_t range_length = to - from;
1313 prepare_to_modify_buffer (from, to, &from); 1309 prepare_to_modify_buffer (from, to, &from);
1314 to = from + range_length; 1310 to = from + range_length;
1315 } 1311 }
@@ -1464,12 +1460,12 @@ replace_range (EMACS_INT from, EMACS_INT to, Lisp_Object new,
1464 prepare_to_modify_buffer and never call signal_after_change. */ 1460 prepare_to_modify_buffer and never call signal_after_change. */
1465 1461
1466void 1462void
1467replace_range_2 (EMACS_INT from, EMACS_INT from_byte, 1463replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1468 EMACS_INT to, EMACS_INT to_byte, 1464 ptrdiff_t to, ptrdiff_t to_byte,
1469 const char *ins, EMACS_INT inschars, EMACS_INT insbytes, 1465 const char *ins, ptrdiff_t inschars, ptrdiff_t insbytes,
1470 int markers) 1466 int markers)
1471{ 1467{
1472 EMACS_INT nbytes_del, nchars_del; 1468 ptrdiff_t nbytes_del, nchars_del;
1473 1469
1474 CHECK_MARKERS (); 1470 CHECK_MARKERS ();
1475 1471
@@ -1571,7 +1567,7 @@ replace_range_2 (EMACS_INT from, EMACS_INT from_byte,
1571 If TO comes before FROM, we delete nothing. */ 1567 If TO comes before FROM, we delete nothing. */
1572 1568
1573void 1569void
1574del_range (EMACS_INT from, EMACS_INT to) 1570del_range (ptrdiff_t from, ptrdiff_t to)
1575{ 1571{
1576 del_range_1 (from, to, 1, 0); 1572 del_range_1 (from, to, 1, 0);
1577} 1573}
@@ -1580,9 +1576,9 @@ del_range (EMACS_INT from, EMACS_INT to)
1580 RET_STRING says to return the deleted text. */ 1576 RET_STRING says to return the deleted text. */
1581 1577
1582Lisp_Object 1578Lisp_Object
1583del_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)
1584{ 1580{
1585 EMACS_INT from_byte, to_byte; 1581 ptrdiff_t from_byte, to_byte;
1586 Lisp_Object deletion; 1582 Lisp_Object deletion;
1587 struct gcpro gcpro1; 1583 struct gcpro gcpro1;
1588 1584
@@ -1597,7 +1593,7 @@ del_range_1 (EMACS_INT from, EMACS_INT to, int prepare, int ret_string)
1597 1593
1598 if (prepare) 1594 if (prepare)
1599 { 1595 {
1600 EMACS_INT range_length = to - from; 1596 ptrdiff_t range_length = to - from;
1601 prepare_to_modify_buffer (from, to, &from); 1597 prepare_to_modify_buffer (from, to, &from);
1602 to = min (ZV, from + range_length); 1598 to = min (ZV, from + range_length);
1603 } 1599 }
@@ -1616,9 +1612,9 @@ del_range_1 (EMACS_INT from, EMACS_INT to, int prepare, int ret_string)
1616/* 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. */
1617 1613
1618void 1614void
1619del_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)
1620{ 1616{
1621 EMACS_INT from, to; 1617 ptrdiff_t from, to;
1622 1618
1623 /* Make args be valid */ 1619 /* Make args be valid */
1624 if (from_byte < BEGV_BYTE) 1620 if (from_byte < BEGV_BYTE)
@@ -1634,8 +1630,8 @@ del_range_byte (EMACS_INT from_byte, EMACS_INT to_byte, int prepare)
1634 1630
1635 if (prepare) 1631 if (prepare)
1636 { 1632 {
1637 EMACS_INT old_from = from, old_to = Z - to; 1633 ptrdiff_t old_from = from, old_to = Z - to;
1638 EMACS_INT range_length = to - from; 1634 ptrdiff_t range_length = to - from;
1639 prepare_to_modify_buffer (from, to, &from); 1635 prepare_to_modify_buffer (from, to, &from);
1640 to = from + range_length; 1636 to = from + range_length;
1641 1637
@@ -1659,8 +1655,8 @@ del_range_byte (EMACS_INT from_byte, EMACS_INT to_byte, int prepare)
1659 and bytepos. */ 1655 and bytepos. */
1660 1656
1661void 1657void
1662del_range_both (EMACS_INT from, EMACS_INT from_byte, 1658del_range_both (ptrdiff_t from, ptrdiff_t from_byte,
1663 EMACS_INT to, EMACS_INT to_byte, int prepare) 1659 ptrdiff_t to, ptrdiff_t to_byte, int prepare)
1664{ 1660{
1665 /* Make args be valid */ 1661 /* Make args be valid */
1666 if (from_byte < BEGV_BYTE) 1662 if (from_byte < BEGV_BYTE)
@@ -1678,8 +1674,8 @@ del_range_both (EMACS_INT from, EMACS_INT from_byte,
1678 1674
1679 if (prepare) 1675 if (prepare)
1680 { 1676 {
1681 EMACS_INT old_from = from, old_to = Z - to; 1677 ptrdiff_t old_from = from, old_to = Z - to;
1682 EMACS_INT range_length = to - from; 1678 ptrdiff_t range_length = to - from;
1683 prepare_to_modify_buffer (from, to, &from); 1679 prepare_to_modify_buffer (from, to, &from);
1684 to = from + range_length; 1680 to = from + range_length;
1685 1681
@@ -1705,10 +1701,10 @@ del_range_both (EMACS_INT from, EMACS_INT from_byte,
1705 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. */
1706 1702
1707Lisp_Object 1703Lisp_Object
1708del_range_2 (EMACS_INT from, EMACS_INT from_byte, 1704del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1709 EMACS_INT to, EMACS_INT to_byte, int ret_string) 1705 ptrdiff_t to, ptrdiff_t to_byte, int ret_string)
1710{ 1706{
1711 register EMACS_INT nbytes_del, nchars_del; 1707 register ptrdiff_t nbytes_del, nchars_del;
1712 Lisp_Object deletion; 1708 Lisp_Object deletion;
1713 1709
1714 CHECK_MARKERS (); 1710 CHECK_MARKERS ();
@@ -1792,7 +1788,7 @@ del_range_2 (EMACS_INT from, EMACS_INT from_byte,
1792 Otherwise set CHARS_MODIFF to the new value of MODIFF. */ 1788 Otherwise set CHARS_MODIFF to the new value of MODIFF. */
1793 1789
1794void 1790void
1795modify_region (struct buffer *buffer, EMACS_INT start, EMACS_INT end, 1791modify_region (struct buffer *buffer, ptrdiff_t start, ptrdiff_t end,
1796 int preserve_chars_modiff) 1792 int preserve_chars_modiff)
1797{ 1793{
1798 struct buffer *old_buffer = current_buffer; 1794 struct buffer *old_buffer = current_buffer;
@@ -1827,8 +1823,8 @@ modify_region (struct buffer *buffer, EMACS_INT start, EMACS_INT end,
1827 by holding its value temporarily in a marker. */ 1823 by holding its value temporarily in a marker. */
1828 1824
1829void 1825void
1830prepare_to_modify_buffer (EMACS_INT start, EMACS_INT end, 1826prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
1831 EMACS_INT *preserve_ptr) 1827 ptrdiff_t *preserve_ptr)
1832{ 1828{
1833 struct buffer *base_buffer; 1829 struct buffer *base_buffer;
1834 1830
@@ -1889,8 +1885,8 @@ prepare_to_modify_buffer (EMACS_INT start, EMACS_INT end,
1889 : (!NILP (Vselect_active_regions) 1885 : (!NILP (Vselect_active_regions)
1890 && !NILP (Vtransient_mark_mode)))) 1886 && !NILP (Vtransient_mark_mode))))
1891 { 1887 {
1892 EMACS_INT b = XMARKER (BVAR (current_buffer, mark))->charpos; 1888 ptrdiff_t b = XMARKER (BVAR (current_buffer, mark))->charpos;
1893 EMACS_INT e = PT; 1889 ptrdiff_t e = PT;
1894 if (b < e) 1890 if (b < e)
1895 Vsaved_region_selection = make_buffer_string (b, e, 0); 1891 Vsaved_region_selection = make_buffer_string (b, e, 0);
1896 else if (b > e) 1892 else if (b > e)
@@ -1958,14 +1954,14 @@ reset_var_on_error (Lisp_Object val)
1958 by holding its value temporarily in a marker. */ 1954 by holding its value temporarily in a marker. */
1959 1955
1960static void 1956static void
1961signal_before_change (EMACS_INT start_int, EMACS_INT end_int, 1957signal_before_change (ptrdiff_t start_int, ptrdiff_t end_int,
1962 EMACS_INT *preserve_ptr) 1958 ptrdiff_t *preserve_ptr)
1963{ 1959{
1964 Lisp_Object start, end; 1960 Lisp_Object start, end;
1965 Lisp_Object start_marker, end_marker; 1961 Lisp_Object start_marker, end_marker;
1966 Lisp_Object preserve_marker; 1962 Lisp_Object preserve_marker;
1967 struct gcpro gcpro1, gcpro2, gcpro3; 1963 struct gcpro gcpro1, gcpro2, gcpro3;
1968 int count = SPECPDL_INDEX (); 1964 ptrdiff_t count = SPECPDL_INDEX ();
1969 1965
1970 if (inhibit_modification_hooks) 1966 if (inhibit_modification_hooks)
1971 return; 1967 return;
@@ -2036,9 +2032,9 @@ signal_before_change (EMACS_INT start_int, EMACS_INT end_int,
2036 after the change. */ 2032 after the change. */
2037 2033
2038void 2034void
2039signal_after_change (EMACS_INT charpos, EMACS_INT lendel, EMACS_INT lenins) 2035signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins)
2040{ 2036{
2041 int count = SPECPDL_INDEX (); 2037 ptrdiff_t count = SPECPDL_INDEX ();
2042 if (inhibit_modification_hooks) 2038 if (inhibit_modification_hooks)
2043 return; 2039 return;
2044 2040
@@ -2119,9 +2115,9 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
2119 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'. */)
2120 (void) 2116 (void)
2121{ 2117{
2122 int count = SPECPDL_INDEX (); 2118 ptrdiff_t count = SPECPDL_INDEX ();
2123 EMACS_INT beg, end, change; 2119 ptrdiff_t beg, end, change;
2124 EMACS_INT begpos, endpos; 2120 ptrdiff_t begpos, endpos;
2125 Lisp_Object tail; 2121 Lisp_Object tail;
2126 2122
2127 if (NILP (combine_after_change_list)) 2123 if (NILP (combine_after_change_list))
@@ -2155,7 +2151,7 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
2155 tail = XCDR (tail)) 2151 tail = XCDR (tail))
2156 { 2152 {
2157 Lisp_Object elt; 2153 Lisp_Object elt;
2158 EMACS_INT thisbeg, thisend, thischange; 2154 ptrdiff_t thisbeg, thisend, thischange;
2159 2155
2160 /* Extract the info from the next element. */ 2156 /* Extract the info from the next element. */
2161 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 56858acd6aa..093e33ec67c 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,17 @@ 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
220/* This is like Vthis_command, except that commands never set it. */
221Lisp_Object real_this_command;
222 219
223/* The value of point when the last command was started. */ 220/* The value of point when the last command was started. */
224static EMACS_INT last_point_position; 221static ptrdiff_t last_point_position;
225 222
226/* The buffer that was current when the last command was started. */ 223/* The buffer that was current when the last command was started. */
227static Lisp_Object last_point_position_buffer; 224static Lisp_Object last_point_position_buffer;
@@ -377,7 +374,7 @@ EMACS_TIME timer_check (void);
377 374
378static void record_menu_key (Lisp_Object c); 375static void record_menu_key (Lisp_Object c);
379static void echo_now (void); 376static void echo_now (void);
380static int echo_length (void); 377static ptrdiff_t echo_length (void);
381 378
382static Lisp_Object Qpolling_period; 379static Lisp_Object Qpolling_period;
383 380
@@ -448,9 +445,9 @@ static Lisp_Object make_lispy_movement (struct frame *, Lisp_Object,
448 Lisp_Object, Lisp_Object, 445 Lisp_Object, Lisp_Object,
449 Time); 446 Time);
450#endif 447#endif
451static Lisp_Object modify_event_symbol (EMACS_INT, unsigned, Lisp_Object, 448static Lisp_Object modify_event_symbol (ptrdiff_t, int, Lisp_Object,
452 Lisp_Object, const char *const *, 449 Lisp_Object, const char *const *,
453 Lisp_Object *, EMACS_INT); 450 Lisp_Object *, ptrdiff_t);
454static Lisp_Object make_lispy_switch_frame (Lisp_Object); 451static Lisp_Object make_lispy_switch_frame (Lisp_Object);
455static int help_char_p (Lisp_Object); 452static int help_char_p (Lisp_Object);
456static void save_getcjmp (jmp_buf); 453static void save_getcjmp (jmp_buf);
@@ -615,7 +612,7 @@ echo_now (void)
615{ 612{
616 if (!current_kboard->immediate_echo) 613 if (!current_kboard->immediate_echo)
617 { 614 {
618 int i; 615 ptrdiff_t i;
619 current_kboard->immediate_echo = 1; 616 current_kboard->immediate_echo = 1;
620 617
621 for (i = 0; i < this_command_key_count; i++) 618 for (i = 0; i < this_command_key_count; i++)
@@ -673,7 +670,7 @@ cancel_echoing (void)
673 670
674/* Return the length of the current echo string. */ 671/* Return the length of the current echo string. */
675 672
676static int 673static ptrdiff_t
677echo_length (void) 674echo_length (void)
678{ 675{
679 return (STRINGP (KVAR (current_kboard, echo_string)) 676 return (STRINGP (KVAR (current_kboard, echo_string))
@@ -686,7 +683,7 @@ echo_length (void)
686 switches frames while entering a key sequence. */ 683 switches frames while entering a key sequence. */
687 684
688static void 685static void
689echo_truncate (EMACS_INT nchars) 686echo_truncate (ptrdiff_t nchars)
690{ 687{
691 if (STRINGP (KVAR (current_kboard, echo_string))) 688 if (STRINGP (KVAR (current_kboard, echo_string)))
692 KVAR (current_kboard, echo_string) 689 KVAR (current_kboard, echo_string)
@@ -715,9 +712,7 @@ add_command_key (Lisp_Object key)
715#endif 712#endif
716 713
717 if (this_command_key_count >= ASIZE (this_command_keys)) 714 if (this_command_key_count >= ASIZE (this_command_keys))
718 this_command_keys = larger_vector (this_command_keys, 715 this_command_keys = larger_vector (this_command_keys, 1, -1);
719 2 * ASIZE (this_command_keys),
720 Qnil);
721 716
722 ASET (this_command_keys, this_command_key_count, key); 717 ASET (this_command_keys, this_command_key_count, key);
723 ++this_command_key_count; 718 ++this_command_key_count;
@@ -727,7 +722,7 @@ add_command_key (Lisp_Object key)
727Lisp_Object 722Lisp_Object
728recursive_edit_1 (void) 723recursive_edit_1 (void)
729{ 724{
730 int count = SPECPDL_INDEX (); 725 ptrdiff_t count = SPECPDL_INDEX ();
731 Lisp_Object val; 726 Lisp_Object val;
732 727
733 if (command_loop_level > 0) 728 if (command_loop_level > 0)
@@ -795,7 +790,7 @@ Alternatively, `(throw 'exit t)' makes this function signal an error.
795This function is called by the editor initialization to begin editing. */) 790This function is called by the editor initialization to begin editing. */)
796 (void) 791 (void)
797{ 792{
798 int count = SPECPDL_INDEX (); 793 ptrdiff_t count = SPECPDL_INDEX ();
799 Lisp_Object buffer; 794 Lisp_Object buffer;
800 795
801 /* If we enter while input is blocked, don't lock up here. 796 /* If we enter while input is blocked, don't lock up here.
@@ -1262,7 +1257,7 @@ Normally, mouse motion is ignored.
1262usage: (track-mouse BODY...) */) 1257usage: (track-mouse BODY...) */)
1263 (Lisp_Object args) 1258 (Lisp_Object args)
1264{ 1259{
1265 int count = SPECPDL_INDEX (); 1260 ptrdiff_t count = SPECPDL_INDEX ();
1266 Lisp_Object val; 1261 Lisp_Object val;
1267 1262
1268 record_unwind_protect (tracking_off, do_mouse_tracking); 1263 record_unwind_protect (tracking_off, do_mouse_tracking);
@@ -1313,7 +1308,7 @@ some_mouse_moved (void)
1313static int read_key_sequence (Lisp_Object *, int, Lisp_Object, 1308static int read_key_sequence (Lisp_Object *, int, Lisp_Object,
1314 int, int, int); 1309 int, int, int);
1315void safe_run_hooks (Lisp_Object); 1310void safe_run_hooks (Lisp_Object);
1316static void adjust_point_for_property (EMACS_INT, int); 1311static void adjust_point_for_property (ptrdiff_t, int);
1317 1312
1318/* Cancel hourglass from protect_unwind. 1313/* Cancel hourglass from protect_unwind.
1319 ARG is not used. */ 1314 ARG is not used. */
@@ -1337,7 +1332,7 @@ command_loop_1 (void)
1337 Lisp_Object cmd; 1332 Lisp_Object cmd;
1338 Lisp_Object keybuf[30]; 1333 Lisp_Object keybuf[30];
1339 int i; 1334 int i;
1340 int prev_modiff = 0; 1335 EMACS_INT prev_modiff = 0;
1341 struct buffer *prev_buffer = NULL; 1336 struct buffer *prev_buffer = NULL;
1342#if 0 /* This shouldn't be necessary anymore. --lorentey */ 1337#if 0 /* This shouldn't be necessary anymore. --lorentey */
1343 int was_locked = single_kboard; 1338 int was_locked = single_kboard;
@@ -1378,9 +1373,9 @@ command_loop_1 (void)
1378 1373
1379 /* Do this after running Vpost_command_hook, for consistency. */ 1374 /* Do this after running Vpost_command_hook, for consistency. */
1380 KVAR (current_kboard, Vlast_command) = Vthis_command; 1375 KVAR (current_kboard, Vlast_command) = Vthis_command;
1381 KVAR (current_kboard, Vreal_last_command) = real_this_command; 1376 KVAR (current_kboard, Vreal_last_command) = Vreal_this_command;
1382 if (!CONSP (last_command_event)) 1377 if (!CONSP (last_command_event))
1383 KVAR (current_kboard, Vlast_repeatable_command) = real_this_command; 1378 KVAR (current_kboard, Vlast_repeatable_command) = Vreal_this_command;
1384 1379
1385 while (1) 1380 while (1)
1386 { 1381 {
@@ -1409,7 +1404,7 @@ command_loop_1 (void)
1409 { 1404 {
1410 /* Bind inhibit-quit to t so that C-g gets read in 1405 /* Bind inhibit-quit to t so that C-g gets read in
1411 rather than quitting back to the minibuffer. */ 1406 rather than quitting back to the minibuffer. */
1412 int count = SPECPDL_INDEX (); 1407 ptrdiff_t count = SPECPDL_INDEX ();
1413 specbind (Qinhibit_quit, Qt); 1408 specbind (Qinhibit_quit, Qt);
1414 1409
1415 sit_for (Vminibuffer_message_timeout, 0, 2); 1410 sit_for (Vminibuffer_message_timeout, 0, 2);
@@ -1447,7 +1442,7 @@ command_loop_1 (void)
1447 before_command_echo_length = echo_length (); 1442 before_command_echo_length = echo_length ();
1448 1443
1449 Vthis_command = Qnil; 1444 Vthis_command = Qnil;
1450 real_this_command = Qnil; 1445 Vreal_this_command = Qnil;
1451 Vthis_original_command = Qnil; 1446 Vthis_original_command = Qnil;
1452 Vthis_command_keys_shift_translated = Qnil; 1447 Vthis_command_keys_shift_translated = Qnil;
1453 1448
@@ -1486,10 +1481,10 @@ command_loop_1 (void)
1486 from that position. But also throw away beg_unchanged and 1481 from that position. But also throw away beg_unchanged and
1487 end_unchanged information in that case, so that redisplay will 1482 end_unchanged information in that case, so that redisplay will
1488 update the whole window properly. */ 1483 update the whole window properly. */
1489 if (!NILP (XWINDOW (selected_window)->force_start)) 1484 if (XWINDOW (selected_window)->force_start)
1490 { 1485 {
1491 struct buffer *b; 1486 struct buffer *b;
1492 XWINDOW (selected_window)->force_start = Qnil; 1487 XWINDOW (selected_window)->force_start = 0;
1493 b = XBUFFER (XWINDOW (selected_window)->buffer); 1488 b = XBUFFER (XWINDOW (selected_window)->buffer);
1494 BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0; 1489 BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0;
1495 } 1490 }
@@ -1531,7 +1526,7 @@ command_loop_1 (void)
1531 /* Execute the command. */ 1526 /* Execute the command. */
1532 1527
1533 Vthis_command = cmd; 1528 Vthis_command = cmd;
1534 real_this_command = cmd; 1529 Vreal_this_command = cmd;
1535 safe_run_hooks (Qpre_command_hook); 1530 safe_run_hooks (Qpre_command_hook);
1536 1531
1537 already_adjusted = 0; 1532 already_adjusted = 0;
@@ -1563,7 +1558,7 @@ command_loop_1 (void)
1563 /* Here for a command that isn't executed directly. */ 1558 /* Here for a command that isn't executed directly. */
1564 1559
1565#ifdef HAVE_WINDOW_SYSTEM 1560#ifdef HAVE_WINDOW_SYSTEM
1566 int scount = SPECPDL_INDEX (); 1561 ptrdiff_t scount = SPECPDL_INDEX ();
1567 1562
1568 if (display_hourglass_p 1563 if (display_hourglass_p
1569 && NILP (Vexecuting_kbd_macro)) 1564 && NILP (Vexecuting_kbd_macro))
@@ -1615,12 +1610,14 @@ command_loop_1 (void)
1615 If the command didn't actually create a prefix arg, 1610 If the command didn't actually create a prefix arg,
1616 but is merely a frame event that is transparent to prefix args, 1611 but is merely a frame event that is transparent to prefix args,
1617 then the above doesn't apply. */ 1612 then the above doesn't apply. */
1618 if (NILP (KVAR (current_kboard, Vprefix_arg)) || CONSP (last_command_event)) 1613 if (NILP (KVAR (current_kboard, Vprefix_arg))
1614 || CONSP (last_command_event))
1619 { 1615 {
1620 KVAR (current_kboard, Vlast_command) = Vthis_command; 1616 KVAR (current_kboard, Vlast_command) = Vthis_command;
1621 KVAR (current_kboard, Vreal_last_command) = real_this_command; 1617 KVAR (current_kboard, Vreal_last_command) = Vreal_this_command;
1622 if (!CONSP (last_command_event)) 1618 if (!CONSP (last_command_event))
1623 KVAR (current_kboard, Vlast_repeatable_command) = real_this_command; 1619 KVAR (current_kboard, Vlast_repeatable_command)
1620 = Vreal_this_command;
1624 cancel_echoing (); 1621 cancel_echoing ();
1625 this_command_key_count = 0; 1622 this_command_key_count = 0;
1626 this_command_key_count_reset = 0; 1623 this_command_key_count_reset = 0;
@@ -1657,9 +1654,9 @@ command_loop_1 (void)
1657 && NILP (Fmemq (Vthis_command, 1654 && NILP (Fmemq (Vthis_command,
1658 Vselection_inhibit_update_commands))) 1655 Vselection_inhibit_update_commands)))
1659 { 1656 {
1660 EMACS_INT beg = 1657 ptrdiff_t beg =
1661 XINT (Fmarker_position (BVAR (current_buffer, mark))); 1658 XINT (Fmarker_position (BVAR (current_buffer, mark)));
1662 EMACS_INT end = PT; 1659 ptrdiff_t end = PT;
1663 if (beg < end) 1660 if (beg < end)
1664 call2 (Qx_set_selection, QPRIMARY, 1661 call2 (Qx_set_selection, QPRIMARY,
1665 make_buffer_string (beg, end, 0)); 1662 make_buffer_string (beg, end, 0));
@@ -1719,16 +1716,16 @@ command_loop_1 (void)
1719 LAST_PT is the last position of point. */ 1716 LAST_PT is the last position of point. */
1720 1717
1721static void 1718static void
1722adjust_point_for_property (EMACS_INT last_pt, int modified) 1719adjust_point_for_property (ptrdiff_t last_pt, int modified)
1723{ 1720{
1724 EMACS_INT beg, end; 1721 ptrdiff_t beg, end;
1725 Lisp_Object val, overlay, tmp; 1722 Lisp_Object val, overlay, tmp;
1726 /* When called after buffer modification, we should temporarily 1723 /* When called after buffer modification, we should temporarily
1727 suppress the point adjustment for automatic composition so that a 1724 suppress the point adjustment for automatic composition so that a
1728 user can keep inserting another character at point or keep 1725 user can keep inserting another character at point or keep
1729 deleting characters around point. */ 1726 deleting characters around point. */
1730 int check_composition = ! modified, check_display = 1, check_invisible = 1; 1727 int check_composition = ! modified, check_display = 1, check_invisible = 1;
1731 EMACS_INT orig_pt = PT; 1728 ptrdiff_t orig_pt = PT;
1732 1729
1733 /* FIXME: cycling is probably not necessary because these properties 1730 /* FIXME: cycling is probably not necessary because these properties
1734 can't be usefully combined anyway. */ 1731 can't be usefully combined anyway. */
@@ -1943,7 +1940,7 @@ safe_run_hooks (Lisp_Object hook)
1943 /* FIXME: our `internal_condition_case' does not provide any way to pass data 1940 /* FIXME: our `internal_condition_case' does not provide any way to pass data
1944 to its body or to its handlers other than via globals such as 1941 to its body or to its handlers other than via globals such as
1945 dynamically-bound variables ;-) */ 1942 dynamically-bound variables ;-) */
1946 int count = SPECPDL_INDEX (); 1943 ptrdiff_t count = SPECPDL_INDEX ();
1947 specbind (Qinhibit_quit, hook); 1944 specbind (Qinhibit_quit, hook);
1948 1945
1949 run_hook_with_args (1, &hook, safe_run_hook_funcall); 1946 run_hook_with_args (1, &hook, safe_run_hook_funcall);
@@ -2281,7 +2278,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2281 int *used_mouse_menu, struct timeval *end_time) 2278 int *used_mouse_menu, struct timeval *end_time)
2282{ 2279{
2283 volatile Lisp_Object c; 2280 volatile Lisp_Object c;
2284 int jmpcount; 2281 ptrdiff_t jmpcount;
2285 jmp_buf local_getcjmp; 2282 jmp_buf local_getcjmp;
2286 jmp_buf save_jump; 2283 jmp_buf save_jump;
2287 volatile int key_already_recorded = 0; 2284 volatile int key_already_recorded = 0;
@@ -2670,7 +2667,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2670 if (INTERACTIVE && NILP (c)) 2667 if (INTERACTIVE && NILP (c))
2671 { 2668 {
2672 int delay_level; 2669 int delay_level;
2673 EMACS_INT buffer_size; 2670 ptrdiff_t buffer_size;
2674 2671
2675 /* Slow down auto saves logarithmically in size of current buffer, 2672 /* Slow down auto saves logarithmically in size of current buffer,
2676 and garbage collect while we're at it. */ 2673 and garbage collect while we're at it. */
@@ -2691,8 +2688,9 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2691 && XINT (Vauto_save_timeout) > 0) 2688 && XINT (Vauto_save_timeout) > 0)
2692 { 2689 {
2693 Lisp_Object tem0; 2690 Lisp_Object tem0;
2694 int timeout = delay_level * XFASTINT (Vauto_save_timeout) / 4; 2691 EMACS_INT timeout = (delay_level
2695 2692 * min (XFASTINT (Vauto_save_timeout) / 4,
2693 MOST_POSITIVE_FIXNUM / delay_level));
2696 save_getcjmp (save_jump); 2694 save_getcjmp (save_jump);
2697 restore_getcjmp (local_getcjmp); 2695 restore_getcjmp (local_getcjmp);
2698 tem0 = sit_for (make_number (timeout), 1, 1); 2696 tem0 = sit_for (make_number (timeout), 1, 1);
@@ -2886,7 +2884,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2886 struct buffer *prev_buffer = current_buffer; 2884 struct buffer *prev_buffer = current_buffer;
2887#if 0 /* This shouldn't be necessary anymore. --lorentey */ 2885#if 0 /* This shouldn't be necessary anymore. --lorentey */
2888 int was_locked = single_kboard; 2886 int was_locked = single_kboard;
2889 int count = SPECPDL_INDEX (); 2887 ptrdiff_t count = SPECPDL_INDEX ();
2890 record_single_kboard_state (); 2888 record_single_kboard_state ();
2891#endif 2889#endif
2892 2890
@@ -3013,9 +3011,10 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
3013 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127) 3011 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127)
3014 { 3012 {
3015 Lisp_Object keys; 3013 Lisp_Object keys;
3016 int key_count, key_count_reset; 3014 ptrdiff_t key_count;
3015 int key_count_reset;
3017 struct gcpro gcpro1; 3016 struct gcpro gcpro1;
3018 int count = SPECPDL_INDEX (); 3017 ptrdiff_t count = SPECPDL_INDEX ();
3019 3018
3020 /* Save the echo status. */ 3019 /* Save the echo status. */
3021 int saved_immediate_echo = current_kboard->immediate_echo; 3020 int saved_immediate_echo = current_kboard->immediate_echo;
@@ -3152,7 +3151,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
3152 /* Process the help character specially if enabled */ 3151 /* Process the help character specially if enabled */
3153 if (!NILP (Vhelp_form) && help_char_p (c)) 3152 if (!NILP (Vhelp_form) && help_char_p (c))
3154 { 3153 {
3155 int count = SPECPDL_INDEX (); 3154 ptrdiff_t count = SPECPDL_INDEX ();
3156 3155
3157 help_form_saved_window_configs 3156 help_form_saved_window_configs
3158 = Fcons (Fcurrent_window_configuration (Qnil), 3157 = Fcons (Fcurrent_window_configuration (Qnil),
@@ -3312,7 +3311,7 @@ record_char (Lisp_Object c)
3312 3311
3313 if (!recorded) 3312 if (!recorded)
3314 { 3313 {
3315 total_keys++; 3314 total_keys += total_keys < NUM_RECENT_KEYS;
3316 ASET (recent_keys, recent_keys_index, c); 3315 ASET (recent_keys, recent_keys_index, c);
3317 if (++recent_keys_index >= NUM_RECENT_KEYS) 3316 if (++recent_keys_index >= NUM_RECENT_KEYS)
3318 recent_keys_index = 0; 3317 recent_keys_index = 0;
@@ -3681,7 +3680,7 @@ kbd_buffer_unget_event (register struct input_event *event)
3681 3680
3682void 3681void
3683gen_help_event (Lisp_Object help, Lisp_Object frame, Lisp_Object window, 3682gen_help_event (Lisp_Object help, Lisp_Object frame, Lisp_Object window,
3684 Lisp_Object object, EMACS_INT pos) 3683 Lisp_Object object, ptrdiff_t pos)
3685{ 3684{
3686 struct input_event event; 3685 struct input_event event;
3687 3686
@@ -4465,7 +4464,7 @@ timer_check_2 (void)
4465 { 4464 {
4466 if (NILP (vector[0])) 4465 if (NILP (vector[0]))
4467 { 4466 {
4468 int count = SPECPDL_INDEX (); 4467 ptrdiff_t count = SPECPDL_INDEX ();
4469 Lisp_Object old_deactivate_mark = Vdeactivate_mark; 4468 Lisp_Object old_deactivate_mark = Vdeactivate_mark;
4470 4469
4471 /* Mark the timer as triggered to prevent problems if the lisp 4470 /* Mark the timer as triggered to prevent problems if the lisp
@@ -5176,7 +5175,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5176 /* It's a click in window WINDOW at frame coordinates (X,Y) */ 5175 /* It's a click in window WINDOW at frame coordinates (X,Y) */
5177 struct window *w = XWINDOW (window); 5176 struct window *w = XWINDOW (window);
5178 Lisp_Object string_info = Qnil; 5177 Lisp_Object string_info = Qnil;
5179 EMACS_INT textpos = -1; 5178 ptrdiff_t textpos = -1;
5180 int col = -1, row = -1; 5179 int col = -1, row = -1;
5181 int dx = -1, dy = -1; 5180 int dx = -1, dy = -1;
5182 int width = -1, height = -1; 5181 int width = -1, height = -1;
@@ -5200,7 +5199,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5200 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE) 5199 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE)
5201 { 5200 {
5202 Lisp_Object string; 5201 Lisp_Object string;
5203 EMACS_INT charpos; 5202 ptrdiff_t charpos;
5204 5203
5205 posn = (part == ON_MODE_LINE) ? Qmode_line : Qheader_line; 5204 posn = (part == ON_MODE_LINE) ? Qmode_line : Qheader_line;
5206 /* Note that mode_line_string takes COL, ROW as pixels and 5205 /* Note that mode_line_string takes COL, ROW as pixels and
@@ -5223,7 +5222,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5223 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN) 5222 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN)
5224 { 5223 {
5225 Lisp_Object string; 5224 Lisp_Object string;
5226 EMACS_INT charpos; 5225 ptrdiff_t charpos;
5227 5226
5228 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin; 5227 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin;
5229 col = wx; 5228 col = wx;
@@ -5451,7 +5450,7 @@ make_lispy_event (struct input_event *event)
5451 Qfunction_key, 5450 Qfunction_key,
5452 KVAR (current_kboard, Vsystem_key_alist), 5451 KVAR (current_kboard, Vsystem_key_alist),
5453 0, &KVAR (current_kboard, system_key_syms), 5452 0, &KVAR (current_kboard, system_key_syms),
5454 TYPE_MAXIMUM (EMACS_INT)); 5453 PTRDIFF_MAX);
5455 } 5454 }
5456 5455
5457 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, 5456 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET,
@@ -5583,9 +5582,10 @@ make_lispy_event (struct input_event *event)
5583 5582
5584 if (button >= ASIZE (button_down_location)) 5583 if (button >= ASIZE (button_down_location))
5585 { 5584 {
5585 ptrdiff_t incr = button - ASIZE (button_down_location) + 1;
5586 button_down_location = larger_vector (button_down_location, 5586 button_down_location = larger_vector (button_down_location,
5587 button + 1, Qnil); 5587 incr, -1);
5588 mouse_syms = larger_vector (mouse_syms, button + 1, Qnil); 5588 mouse_syms = larger_vector (mouse_syms, incr, -1);
5589 } 5589 }
5590 5590
5591 start_pos_ptr = &AREF (button_down_location, button); 5591 start_pos_ptr = &AREF (button_down_location, button);
@@ -5885,7 +5885,9 @@ make_lispy_event (struct input_event *event)
5885 event->modifiers &= ~up_modifier; 5885 event->modifiers &= ~up_modifier;
5886 5886
5887 if (event->code >= ASIZE (mouse_syms)) 5887 if (event->code >= ASIZE (mouse_syms))
5888 mouse_syms = larger_vector (mouse_syms, event->code + 1, Qnil); 5888 mouse_syms = larger_vector (mouse_syms,
5889 event->code - ASIZE (mouse_syms) + 1,
5890 -1);
5889 5891
5890 /* Get the symbol we should use for the mouse click. */ 5892 /* Get the symbol we should use for the mouse click. */
5891 head = modify_event_symbol (event->code, 5893 head = modify_event_symbol (event->code,
@@ -5988,9 +5990,10 @@ make_lispy_event (struct input_event *event)
5988 5990
5989 if (button >= ASIZE (button_down_location)) 5991 if (button >= ASIZE (button_down_location))
5990 { 5992 {
5993 ptrdiff_t incr = button - ASIZE (button_down_location) + 1;
5991 button_down_location = larger_vector (button_down_location, 5994 button_down_location = larger_vector (button_down_location,
5992 button + 1, Qnil); 5995 incr, -1);
5993 mouse_syms = larger_vector (mouse_syms, button + 1, Qnil); 5996 mouse_syms = larger_vector (mouse_syms, incr, -1);
5994 } 5997 }
5995 5998
5996 start_pos_ptr = &AREF (button_down_location, button); 5999 start_pos_ptr = &AREF (button_down_location, button);
@@ -6092,10 +6095,10 @@ make_lispy_switch_frame (Lisp_Object frame)
6092 This doesn't use any caches. */ 6095 This doesn't use any caches. */
6093 6096
6094static int 6097static int
6095parse_modifiers_uncached (Lisp_Object symbol, EMACS_INT *modifier_end) 6098parse_modifiers_uncached (Lisp_Object symbol, ptrdiff_t *modifier_end)
6096{ 6099{
6097 Lisp_Object name; 6100 Lisp_Object name;
6098 EMACS_INT i; 6101 ptrdiff_t i;
6099 int modifiers; 6102 int modifiers;
6100 6103
6101 CHECK_SYMBOL (symbol); 6104 CHECK_SYMBOL (symbol);
@@ -6103,9 +6106,9 @@ parse_modifiers_uncached (Lisp_Object symbol, EMACS_INT *modifier_end)
6103 modifiers = 0; 6106 modifiers = 0;
6104 name = SYMBOL_NAME (symbol); 6107 name = SYMBOL_NAME (symbol);
6105 6108
6106 for (i = 0; i+2 <= SBYTES (name); ) 6109 for (i = 0; i < SBYTES (name) - 1; )
6107 { 6110 {
6108 EMACS_INT this_mod_end = 0; 6111 ptrdiff_t this_mod_end = 0;
6109 int this_mod = 0; 6112 int this_mod = 0;
6110 6113
6111 /* See if the name continues with a modifier word. 6114 /* See if the name continues with a modifier word.
@@ -6302,7 +6305,7 @@ parse_modifiers (Lisp_Object symbol)
6302 return elements; 6305 return elements;
6303 else 6306 else
6304 { 6307 {
6305 EMACS_INT end; 6308 ptrdiff_t end;
6306 int modifiers = parse_modifiers_uncached (symbol, &end); 6309 int modifiers = parse_modifiers_uncached (symbol, &end);
6307 Lisp_Object unmodified; 6310 Lisp_Object unmodified;
6308 Lisp_Object mask; 6311 Lisp_Object mask;
@@ -6468,9 +6471,9 @@ reorder_modifiers (Lisp_Object symbol)
6468 in the symbol's name. */ 6471 in the symbol's name. */
6469 6472
6470static Lisp_Object 6473static Lisp_Object
6471modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object symbol_kind, 6474modify_event_symbol (ptrdiff_t symbol_num, int modifiers, Lisp_Object symbol_kind,
6472 Lisp_Object name_alist_or_stem, const char *const *name_table, 6475 Lisp_Object name_alist_or_stem, const char *const *name_table,
6473 Lisp_Object *symbol_table, EMACS_INT table_size) 6476 Lisp_Object *symbol_table, ptrdiff_t table_size)
6474{ 6477{
6475 Lisp_Object value; 6478 Lisp_Object value;
6476 Lisp_Object symbol_int; 6479 Lisp_Object symbol_int;
@@ -6536,7 +6539,7 @@ modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object s
6536 if (NILP (value)) 6539 if (NILP (value))
6537 { 6540 {
6538 char buf[sizeof "key-" + INT_STRLEN_BOUND (EMACS_INT)]; 6541 char buf[sizeof "key-" + INT_STRLEN_BOUND (EMACS_INT)];
6539 sprintf (buf, "key-%"pI"d", symbol_num); 6542 sprintf (buf, "key-%"pD"d", symbol_num);
6540 value = intern (buf); 6543 value = intern (buf);
6541 } 6544 }
6542 6545
@@ -7576,7 +7579,7 @@ menu_bar_items (Lisp_Object old)
7576 int i = menu_bar_items_index; 7579 int i = menu_bar_items_index;
7577 if (i + 4 > ASIZE (menu_bar_items_vector)) 7580 if (i + 4 > ASIZE (menu_bar_items_vector))
7578 menu_bar_items_vector = 7581 menu_bar_items_vector =
7579 larger_vector (menu_bar_items_vector, 2 * i, Qnil); 7582 larger_vector (menu_bar_items_vector, 4, -1);
7580 /* Add this item. */ 7583 /* Add this item. */
7581 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; 7584 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
7582 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; 7585 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
@@ -7647,7 +7650,7 @@ menu_bar_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy1, void *dumm
7647 { 7650 {
7648 /* If vector is too small, get a bigger one. */ 7651 /* If vector is too small, get a bigger one. */
7649 if (i + 4 > ASIZE (menu_bar_items_vector)) 7652 if (i + 4 > ASIZE (menu_bar_items_vector))
7650 menu_bar_items_vector = larger_vector (menu_bar_items_vector, 2 * i, Qnil); 7653 menu_bar_items_vector = larger_vector (menu_bar_items_vector, 4, -1);
7651 /* Add this item. */ 7654 /* Add this item. */
7652 XVECTOR (menu_bar_items_vector)->contents[i++] = key; 7655 XVECTOR (menu_bar_items_vector)->contents[i++] = key;
7653 XVECTOR (menu_bar_items_vector)->contents[i++] 7656 XVECTOR (menu_bar_items_vector)->contents[i++]
@@ -7691,7 +7694,7 @@ eval_dyn (Lisp_Object form)
7691Lisp_Object 7694Lisp_Object
7692menu_item_eval_property (Lisp_Object sexpr) 7695menu_item_eval_property (Lisp_Object sexpr)
7693{ 7696{
7694 int count = SPECPDL_INDEX (); 7697 ptrdiff_t count = SPECPDL_INDEX ();
7695 Lisp_Object val; 7698 Lisp_Object val;
7696 specbind (Qinhibit_redisplay, Qt); 7699 specbind (Qinhibit_redisplay, Qt);
7697 val = internal_condition_case_1 (eval_dyn, sexpr, Qerror, 7700 val = internal_condition_case_1 (eval_dyn, sexpr, Qerror,
@@ -8416,13 +8419,14 @@ static void
8416append_tool_bar_item (void) 8419append_tool_bar_item (void)
8417{ 8420{
8418 Lisp_Object *to, *from; 8421 Lisp_Object *to, *from;
8422 ptrdiff_t incr =
8423 (ntool_bar_items
8424 - (ASIZE (tool_bar_items_vector) - TOOL_BAR_ITEM_NSLOTS));
8419 8425
8420 /* Enlarge tool_bar_items_vector if necessary. */ 8426 /* Enlarge tool_bar_items_vector if necessary. */
8421 if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS 8427 if (0 < incr)
8422 >= ASIZE (tool_bar_items_vector))
8423 tool_bar_items_vector 8428 tool_bar_items_vector
8424 = larger_vector (tool_bar_items_vector, 8429 = larger_vector (tool_bar_items_vector, incr, -1);
8425 2 * ASIZE (tool_bar_items_vector), Qnil);
8426 8430
8427 /* Append entries from tool_bar_item_properties to the end of 8431 /* Append entries from tool_bar_item_properties to the end of
8428 tool_bar_items_vector. */ 8432 tool_bar_items_vector. */
@@ -9007,15 +9011,15 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9007 int fix_current_buffer) 9011 int fix_current_buffer)
9008{ 9012{
9009 Lisp_Object from_string; 9013 Lisp_Object from_string;
9010 int count = SPECPDL_INDEX (); 9014 ptrdiff_t count = SPECPDL_INDEX ();
9011 9015
9012 /* How many keys there are in the current key sequence. */ 9016 /* How many keys there are in the current key sequence. */
9013 int t; 9017 int t;
9014 9018
9015 /* The length of the echo buffer when we started reading, and 9019 /* The length of the echo buffer when we started reading, and
9016 the length of this_command_keys when we started reading. */ 9020 the length of this_command_keys when we started reading. */
9017 int echo_start IF_LINT (= 0); 9021 ptrdiff_t echo_start IF_LINT (= 0);
9018 int keys_start; 9022 ptrdiff_t keys_start;
9019 9023
9020 /* The number of keymaps we're scanning right now, and the number of 9024 /* The number of keymaps we're scanning right now, and the number of
9021 keymaps we have allocated space for. */ 9025 keymaps we have allocated space for. */
@@ -9271,7 +9275,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9271 while those allow us to restart the entire key sequence, 9275 while those allow us to restart the entire key sequence,
9272 echo_local_start and keys_local_start allow us to throw away 9276 echo_local_start and keys_local_start allow us to throw away
9273 just one key. */ 9277 just one key. */
9274 int echo_local_start IF_LINT (= 0); 9278 ptrdiff_t echo_local_start IF_LINT (= 0);
9275 int keys_local_start; 9279 int keys_local_start;
9276 ptrdiff_t local_first_binding; 9280 ptrdiff_t local_first_binding;
9277 9281
@@ -10159,7 +10163,7 @@ will read just one key sequence. */)
10159 Lisp_Object keybuf[30]; 10163 Lisp_Object keybuf[30];
10160 register int i; 10164 register int i;
10161 struct gcpro gcpro1; 10165 struct gcpro gcpro1;
10162 int count = SPECPDL_INDEX (); 10166 ptrdiff_t count = SPECPDL_INDEX ();
10163 10167
10164 if (!NILP (prompt)) 10168 if (!NILP (prompt))
10165 CHECK_STRING (prompt); 10169 CHECK_STRING (prompt);
@@ -10216,7 +10220,7 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
10216 Lisp_Object keybuf[30]; 10220 Lisp_Object keybuf[30];
10217 register int i; 10221 register int i;
10218 struct gcpro gcpro1; 10222 struct gcpro gcpro1;
10219 int count = SPECPDL_INDEX (); 10223 ptrdiff_t count = SPECPDL_INDEX ();
10220 10224
10221 if (!NILP (prompt)) 10225 if (!NILP (prompt))
10222 CHECK_STRING (prompt); 10226 CHECK_STRING (prompt);
@@ -10644,7 +10648,7 @@ Some operating systems cannot stop the Emacs process and resume it later.
10644On such systems, Emacs starts a subshell instead of suspending. */) 10648On such systems, Emacs starts a subshell instead of suspending. */)
10645 (Lisp_Object stuffstring) 10649 (Lisp_Object stuffstring)
10646{ 10650{
10647 int count = SPECPDL_INDEX (); 10651 ptrdiff_t count = SPECPDL_INDEX ();
10648 int old_height, old_width; 10652 int old_height, old_width;
10649 int width, height; 10653 int width, height;
10650 struct gcpro gcpro1; 10654 struct gcpro gcpro1;
@@ -10700,7 +10704,7 @@ stuff_buffered_input (Lisp_Object stuffstring)
10700 10704
10701 if (STRINGP (stuffstring)) 10705 if (STRINGP (stuffstring))
10702 { 10706 {
10703 register EMACS_INT count; 10707 register ptrdiff_t count;
10704 10708
10705 p = SDATA (stuffstring); 10709 p = SDATA (stuffstring);
10706 count = SBYTES (stuffstring); 10710 count = SBYTES (stuffstring);
@@ -11467,9 +11471,6 @@ syms_of_keyboard (void)
11467 staticpro (&tool_bar_items_vector); 11471 staticpro (&tool_bar_items_vector);
11468 tool_bar_items_vector = Qnil; 11472 tool_bar_items_vector = Qnil;
11469 11473
11470 staticpro (&real_this_command);
11471 real_this_command = Qnil;
11472
11473 DEFSYM (Qtimer_event_handler, "timer-event-handler"); 11474 DEFSYM (Qtimer_event_handler, "timer-event-handler");
11474 DEFSYM (Qdisabled_command_function, "disabled-command-function"); 11475 DEFSYM (Qdisabled_command_function, "disabled-command-function");
11475 DEFSYM (Qself_insert_command, "self-insert-command"); 11476 DEFSYM (Qself_insert_command, "self-insert-command");
@@ -11723,12 +11724,14 @@ was a kill command.
11723See Info node `(elisp)Multiple Terminals'. */); 11724See Info node `(elisp)Multiple Terminals'. */);
11724 11725
11725 DEFVAR_KBOARD ("real-last-command", Vreal_last_command, 11726 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
11726 doc: /* Same as `last-command', but never altered by Lisp code. */); 11727 doc: /* Same as `last-command', but never altered by Lisp code.
11728Taken from the previous value of `real-this-command'. */);
11727 11729
11728 DEFVAR_KBOARD ("last-repeatable-command", Vlast_repeatable_command, 11730 DEFVAR_KBOARD ("last-repeatable-command", Vlast_repeatable_command,
11729 doc: /* Last command that may be repeated. 11731 doc: /* Last command that may be repeated.
11730The last command executed that was not bound to an input event. 11732The last command executed that was not bound to an input event.
11731This is the command `repeat' will try to repeat. */); 11733This is the command `repeat' will try to repeat.
11734Taken from a previous value of `real-this-command'. */);
11732 11735
11733 DEFVAR_LISP ("this-command", Vthis_command, 11736 DEFVAR_LISP ("this-command", Vthis_command,
11734 doc: /* The command now being executed. 11737 doc: /* The command now being executed.
@@ -11736,6 +11739,10 @@ The command can set this variable; whatever is put here
11736will be in `last-command' during the following command. */); 11739will be in `last-command' during the following command. */);
11737 Vthis_command = Qnil; 11740 Vthis_command = Qnil;
11738 11741
11742 DEFVAR_LISP ("real-this-command", Vreal_this_command,
11743 doc: /* This is like `this-command', except that commands should never modify it. */);
11744 Vreal_this_command = Qnil;
11745
11739 DEFVAR_LISP ("this-command-keys-shift-translated", 11746 DEFVAR_LISP ("this-command-keys-shift-translated",
11740 Vthis_command_keys_shift_translated, 11747 Vthis_command_keys_shift_translated,
11741 doc: /* Non-nil if the key sequence activating this command was shift-translated. 11748 doc: /* Non-nil if the key sequence activating this command was shift-translated.
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..2f5558c171f 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++)
@@ -2978,9 +2996,9 @@ You type Translation\n\
2978 If MENTION_SHADOW is nonzero, then when something is shadowed by SHADOW, 2996 If MENTION_SHADOW is nonzero, then when something is shadowed by SHADOW,
2979 don't omit it; instead, mention it but say it is shadowed. 2997 don't omit it; instead, mention it but say it is shadowed.
2980 2998
2981 Return whether something was inserted or not. */ 2999 Any inserted text ends in two newlines (used by `help-make-xrefs'). */
2982 3000
2983int 3001void
2984describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow, 3002describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
2985 Lisp_Object prefix, const char *title, int nomenu, int transl, 3003 Lisp_Object prefix, const char *title, int nomenu, int transl,
2986 int always_title, int mention_shadow) 3004 int always_title, int mention_shadow)
@@ -3090,8 +3108,10 @@ key binding\n\
3090 skip: ; 3108 skip: ;
3091 } 3109 }
3092 3110
3111 if (something)
3112 insert_string ("\n");
3113
3093 UNGCPRO; 3114 UNGCPRO;
3094 return something;
3095} 3115}
3096 3116
3097static int previous_description_column; 3117static int previous_description_column;
@@ -3100,7 +3120,7 @@ static void
3100describe_command (Lisp_Object definition, Lisp_Object args) 3120describe_command (Lisp_Object definition, Lisp_Object args)
3101{ 3121{
3102 register Lisp_Object tem1; 3122 register Lisp_Object tem1;
3103 EMACS_INT column = current_column (); 3123 ptrdiff_t column = current_column ();
3104 int description_column; 3124 int description_column;
3105 3125
3106 /* If column 16 is no good, go to col 32; 3126 /* If column 16 is no good, go to col 32;
@@ -3383,7 +3403,7 @@ This is text showing the elements of vector matched against indices.
3383DESCRIBER is the output function used; nil means use `princ'. */) 3403DESCRIBER is the output function used; nil means use `princ'. */)
3384 (Lisp_Object vector, Lisp_Object describer) 3404 (Lisp_Object vector, Lisp_Object describer)
3385{ 3405{
3386 int count = SPECPDL_INDEX (); 3406 ptrdiff_t count = SPECPDL_INDEX ();
3387 if (NILP (describer)) 3407 if (NILP (describer))
3388 describer = intern ("princ"); 3408 describer = intern ("princ");
3389 specbind (Qstandard_output, Fcurrent_buffer ()); 3409 specbind (Qstandard_output, Fcurrent_buffer ());
diff --git a/src/keymap.h b/src/keymap.h
index 234ffce471d..d9334cda0f4 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -47,7 +47,7 @@ EXFUN (Fcurrent_active_maps, 2);
47extern Lisp_Object access_keymap (Lisp_Object, Lisp_Object, int, int, int); 47extern Lisp_Object access_keymap (Lisp_Object, Lisp_Object, int, int, int);
48extern Lisp_Object get_keymap (Lisp_Object, int, int); 48extern Lisp_Object get_keymap (Lisp_Object, int, int);
49EXFUN (Fset_keymap_parent, 2); 49EXFUN (Fset_keymap_parent, 2);
50extern int describe_map_tree (Lisp_Object, int, Lisp_Object, Lisp_Object, 50extern void describe_map_tree (Lisp_Object, int, Lisp_Object, Lisp_Object,
51 const char *, int, int, int, int); 51 const char *, int, int, int, int);
52extern ptrdiff_t current_minor_maps (Lisp_Object **, Lisp_Object **); 52extern ptrdiff_t current_minor_maps (Lisp_Object **, Lisp_Object **);
53extern void initial_define_key (Lisp_Object, int, const char *); 53extern void initial_define_key (Lisp_Object, int, const char *);
diff --git a/src/lisp.h b/src/lisp.h
index 6376862949a..de627b9f4ad 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -41,25 +41,36 @@ extern void check_cons_list (void);
41 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */ 41 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
42/* #undef WIDE_EMACS_INT */ 42/* #undef WIDE_EMACS_INT */
43 43
44/* These are default choices for the types to use. */ 44/* EMACS_INT - signed integer wide enough to hold an Emacs value
45 EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
46 pI - printf length modifier for EMACS_INT
47 EMACS_UINT - unsigned variant of EMACS_INT */
45#ifndef EMACS_INT 48#ifndef EMACS_INT
46# if BITS_PER_LONG < BITS_PER_LONG_LONG && defined WIDE_EMACS_INT 49# if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
47# define EMACS_INT long long 50# define EMACS_INT long long
48# define BITS_PER_EMACS_INT BITS_PER_LONG_LONG 51# define EMACS_INT_MAX LLONG_MAX
49# define pI "ll" 52# define pI "ll"
50# elif BITS_PER_INT < BITS_PER_LONG 53# elif INT_MAX < LONG_MAX
51# define EMACS_INT long 54# define EMACS_INT long
52# define BITS_PER_EMACS_INT BITS_PER_LONG 55# define EMACS_INT_MAX LONG_MAX
53# define pI "l" 56# define pI "l"
54# else 57# else
55# define EMACS_INT int 58# define EMACS_INT int
56# define BITS_PER_EMACS_INT BITS_PER_INT 59# define EMACS_INT_MAX INT_MAX
57# define pI "" 60# define pI ""
58# endif 61# endif
59#endif 62#endif
60#ifndef EMACS_UINT 63#define EMACS_UINT unsigned EMACS_INT
61# define EMACS_UINT unsigned EMACS_INT 64
62#endif 65/* Number of bits in some machine integer types. */
66enum
67 {
68 BITS_PER_CHAR = CHAR_BIT,
69 BITS_PER_SHORT = CHAR_BIT * sizeof (short),
70 BITS_PER_INT = CHAR_BIT * sizeof (int),
71 BITS_PER_LONG = CHAR_BIT * sizeof (long int),
72 BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
73 };
63 74
64/* printmax_t and uprintmax_t are types for printing large integers. 75/* printmax_t and uprintmax_t are types for printing large integers.
65 These are the widest integers that are supported for printing. 76 These are the widest integers that are supported for printing.
@@ -164,13 +175,13 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
164 variable VAR of type TYPE with the added requirement that it be 175 variable VAR of type TYPE with the added requirement that it be
165 TYPEBITS-aligned. */ 176 TYPEBITS-aligned. */
166 177
167#ifndef GCTYPEBITS
168#define GCTYPEBITS 3 178#define GCTYPEBITS 3
169#endif
170
171#ifndef VALBITS
172#define VALBITS (BITS_PER_EMACS_INT - GCTYPEBITS) 179#define VALBITS (BITS_PER_EMACS_INT - GCTYPEBITS)
173#endif 180
181/* The maximum value that can be stored in a EMACS_INT, assuming all
182 bits other than the type bits contribute to a nonnegative signed value.
183 This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */
184#define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1))
174 185
175#ifndef NO_DECL_ALIGN 186#ifndef NO_DECL_ALIGN
176# ifndef DECL_ALIGN 187# ifndef DECL_ALIGN
@@ -195,12 +206,12 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
195 || defined DARWIN_OS || defined __sun) 206 || defined DARWIN_OS || defined __sun)
196/* We also need to be able to specify mult-of-8 alignment on static vars. */ 207/* We also need to be able to specify mult-of-8 alignment on static vars. */
197# if defined DECL_ALIGN 208# if defined DECL_ALIGN
198/* On hosts where VALBITS is greater than the pointer width in bits, 209/* On hosts where pointers-as-ints do not exceed VAL_MAX,
199 USE_LSB_TAG is: 210 USE_LSB_TAG is:
200 a. unnecessary, because the top bits of an EMACS_INT are unused, and 211 a. unnecessary, because the top bits of an EMACS_INT are unused, and
201 b. slower, because it typically requires extra masking. 212 b. slower, because it typically requires extra masking.
202 So, define USE_LSB_TAG only on hosts where it might be useful. */ 213 So, define USE_LSB_TAG only on hosts where it might be useful. */
203# if UINTPTR_MAX >> VALBITS != 0 214# if VAL_MAX < UINTPTR_MAX
204# define USE_LSB_TAG 215# define USE_LSB_TAG
205# endif 216# endif
206# endif 217# endif
@@ -395,14 +406,13 @@ typedef EMACS_INT Lisp_Object;
395#define LISP_MAKE_RVALUE(o) (0+(o)) 406#define LISP_MAKE_RVALUE(o) (0+(o))
396#endif /* USE_LISP_UNION_TYPE */ 407#endif /* USE_LISP_UNION_TYPE */
397 408
398/* 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. */
399 (Shift -1 left, not 1, to avoid provoking overflow diagnostics.) */
400 410
401#define ARRAY_MARK_FLAG ((EMACS_INT) -1 << (BITS_PER_EMACS_INT - 1)) 411#define ARRAY_MARK_FLAG PTRDIFF_MIN
402 412
403/* 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
404 some other vector-like object. */ 414 some other vector-like object. */
405#define PSEUDOVECTOR_FLAG ((EMACS_INT) 1 << (BITS_PER_EMACS_INT - 2)) 415#define PSEUDOVECTOR_FLAG (PTRDIFF_MAX - PTRDIFF_MAX / 2)
406 416
407/* 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
408 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
@@ -479,7 +489,7 @@ enum pvec_type
479 489
480#else /* not USE_LSB_TAG */ 490#else /* not USE_LSB_TAG */
481 491
482#define VALMASK ((((EMACS_INT) 1) << VALBITS) - 1) 492#define VALMASK VAL_MAX
483 493
484/* One need to override this if there must be high bits set in data space 494/* One need to override this if there must be high bits set in data space
485 (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work 495 (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work
@@ -613,6 +623,12 @@ extern Lisp_Object make_number (EMACS_INT);
613#define FIXNUM_OVERFLOW_P(i) \ 623#define FIXNUM_OVERFLOW_P(i) \
614 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM)) 624 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
615 625
626static inline ptrdiff_t
627clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
628{
629 return num < lower ? lower : num <= upper ? num : upper;
630}
631
616/* Extract a value or address from a Lisp_Object. */ 632/* Extract a value or address from a Lisp_Object. */
617 633
618#define XCONS(a) (eassert (CONSP (a)), \ 634#define XCONS(a) (eassert (CONSP (a)), \
@@ -836,7 +852,7 @@ struct Lisp_Cons
836#ifdef GC_CHECK_STRING_BYTES 852#ifdef GC_CHECK_STRING_BYTES
837 853
838struct Lisp_String; 854struct Lisp_String;
839extern EMACS_INT string_bytes (struct Lisp_String *); 855extern ptrdiff_t string_bytes (struct Lisp_String *);
840#define STRING_BYTES(S) string_bytes ((S)) 856#define STRING_BYTES(S) string_bytes ((S))
841 857
842#else /* not GC_CHECK_STRING_BYTES */ 858#else /* not GC_CHECK_STRING_BYTES */
@@ -883,8 +899,8 @@ extern EMACS_INT string_bytes (struct Lisp_String *);
883 899
884struct Lisp_String 900struct Lisp_String
885 { 901 {
886 EMACS_INT size; 902 ptrdiff_t size;
887 EMACS_INT size_byte; 903 ptrdiff_t size_byte;
888 INTERVAL intervals; /* text properties in this string */ 904 INTERVAL intervals; /* text properties in this string */
889 unsigned char *data; 905 unsigned char *data;
890 }; 906 };
@@ -898,7 +914,7 @@ struct Lisp_String
898 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */ 914 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */
899struct vectorlike_header 915struct vectorlike_header
900 { 916 {
901 EMACS_INT size; 917 ptrdiff_t size;
902 918
903 /* Pointer to the next vector-like object. It is generally a buffer or a 919 /* Pointer to the next vector-like object. It is generally a buffer or a
904 Lisp_Vector alias, so for convenience it is a union instead of a 920 Lisp_Vector alias, so for convenience it is a union instead of a
@@ -1093,7 +1109,7 @@ struct Lisp_Bool_Vector
1093 1109
1094struct Lisp_Subr 1110struct Lisp_Subr
1095 { 1111 {
1096 EMACS_INT size; 1112 ptrdiff_t size;
1097 union { 1113 union {
1098 Lisp_Object (*a0) (void); 1114 Lisp_Object (*a0) (void);
1099 Lisp_Object (*a1) (Lisp_Object); 1115 Lisp_Object (*a1) (Lisp_Object);
@@ -1280,7 +1296,7 @@ struct Lisp_Hash_Table
1280 a special way (e.g. because of weakness). */ 1296 a special way (e.g. because of weakness). */
1281 1297
1282 /* Number of key/value entries in the table. */ 1298 /* Number of key/value entries in the table. */
1283 EMACS_INT count; 1299 ptrdiff_t count;
1284 1300
1285 /* Vector of keys and values. The key of item I is found at index 1301 /* Vector of keys and values. The key of item I is found at index
1286 2 * I, the value is found at index 2 * I + 1. 1302 2 * I, the value is found at index 2 * I + 1.
@@ -1395,12 +1411,12 @@ struct Lisp_Marker
1395 That would also allow to preserve it ordered. */ 1411 That would also allow to preserve it ordered. */
1396 struct Lisp_Marker *next; 1412 struct Lisp_Marker *next;
1397 /* This is the char position where the marker points. */ 1413 /* This is the char position where the marker points. */
1398 EMACS_INT charpos; 1414 ptrdiff_t charpos;
1399 /* This is the byte position. 1415 /* This is the byte position.
1400 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly 1416 It's mostly used as a charpos<->bytepos cache (i.e. it's not directly
1401 used to implement the functionality of markers, but rather to (ab)use 1417 used to implement the functionality of markers, but rather to (ab)use
1402 markers as a cache for char<->byte mappings). */ 1418 markers as a cache for char<->byte mappings). */
1403 EMACS_INT bytepos; 1419 ptrdiff_t bytepos;
1404}; 1420};
1405 1421
1406/* Forwarding pointer to an int variable. 1422/* Forwarding pointer to an int variable.
@@ -1659,18 +1675,24 @@ typedef struct {
1659 encodes a char code in the lower CHARACTERBITS bits and a (very small) 1675 encodes a char code in the lower CHARACTERBITS bits and a (very small)
1660 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */ 1676 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */
1661 1677
1662#define GLYPH_CODE_CHAR(gc) \ 1678#define GLYPH_CODE_P(gc) \
1663 (CONSP (gc) ? XINT (XCAR (gc)) : INTEGERP (gc) ? (XINT (gc) & ((1 << CHARACTERBITS)-1)) : 0) 1679 (CONSP (gc) \
1680 ? (CHARACTERP (XCAR (gc)) \
1681 && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID)) \
1682 : (RANGED_INTEGERP \
1683 (0, gc, \
1684 (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS \
1685 ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR \
1686 : TYPE_MAXIMUM (EMACS_INT)))))
1664 1687
1665#define GLYPH_CODE_FACE(gc) \ 1688/* The following are valid only if GLYPH_CODE_P (gc). */
1666 (CONSP (gc) ? XINT (XCDR (gc)) : INTEGERP (gc) ? (XINT (gc) >> CHARACTERBITS) : DEFAULT_FACE_ID)
1667 1689
1668/* Return 1 if glyph code from display vector contains valid character code. */ 1690#define GLYPH_CODE_CHAR(gc) \
1669#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc)) 1691 (CONSP (gc) ? XINT (XCAR (gc)) : XINT (gc) & ((1 << CHARACTERBITS) - 1))
1670 1692
1671#define GLYPH_CODE_P(gc) ((CONSP (gc) && INTEGERP (XCAR (gc)) && INTEGERP (XCDR (gc))) || INTEGERP (gc)) 1693#define GLYPH_CODE_FACE(gc) \
1694 (CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS)
1672 1695
1673/* Only called when GLYPH_CODE_P (gc) is true. */
1674#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \ 1696#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \
1675 do \ 1697 do \
1676 { \ 1698 { \
@@ -1730,7 +1752,9 @@ typedef struct {
1730#define RANGED_INTEGERP(lo, x, hi) \ 1752#define RANGED_INTEGERP(lo, x, hi) \
1731 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi)) 1753 (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
1732#define TYPE_RANGED_INTEGERP(type, x) \ 1754#define TYPE_RANGED_INTEGERP(type, x) \
1733 RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) 1755 (TYPE_SIGNED (type) \
1756 ? RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)) \
1757 : RANGED_INTEGERP (0, x, TYPE_MAXIMUM (type)))
1734 1758
1735#define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x)))) 1759#define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
1736#define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol) 1760#define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
@@ -1853,6 +1877,25 @@ typedef struct {
1853#define CHECK_NATNUM(x) \ 1877#define CHECK_NATNUM(x) \
1854 CHECK_TYPE (NATNUMP (x), Qwholenump, x) 1878 CHECK_TYPE (NATNUMP (x), Qwholenump, x)
1855 1879
1880#define CHECK_RANGED_INTEGER(lo, x, hi) \
1881 do { \
1882 CHECK_NUMBER (x); \
1883 if (! ((lo) <= XINT (x) && XINT (x) <= (hi))) \
1884 args_out_of_range_3 \
1885 (x, \
1886 make_number ((lo) < 0 && (lo) < MOST_NEGATIVE_FIXNUM \
1887 ? MOST_NEGATIVE_FIXNUM \
1888 : (lo)), \
1889 make_number (min (hi, MOST_POSITIVE_FIXNUM))); \
1890 } while (0)
1891#define CHECK_TYPE_RANGED_INTEGER(type, x) \
1892 do { \
1893 if (TYPE_SIGNED (type)) \
1894 CHECK_RANGED_INTEGER (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type)); \
1895 else \
1896 CHECK_RANGED_INTEGER (0, x, TYPE_MAXIMUM (type)); \
1897 } while (0)
1898
1856#define CHECK_MARKER(x) \ 1899#define CHECK_MARKER(x) \
1857 CHECK_TYPE (MARKERP (x), Qmarkerp, x) 1900 CHECK_TYPE (MARKERP (x), Qmarkerp, x)
1858 1901
@@ -2071,9 +2114,9 @@ struct specbinding
2071 2114
2072extern struct specbinding *specpdl; 2115extern struct specbinding *specpdl;
2073extern struct specbinding *specpdl_ptr; 2116extern struct specbinding *specpdl_ptr;
2074extern EMACS_INT specpdl_size; 2117extern ptrdiff_t specpdl_size;
2075 2118
2076#define SPECPDL_INDEX() ((int) (specpdl_ptr - specpdl)) 2119#define SPECPDL_INDEX() (specpdl_ptr - specpdl)
2077 2120
2078/* Everything needed to describe an active condition case. */ 2121/* Everything needed to describe an active condition case. */
2079struct handler 2122struct handler
@@ -2126,8 +2169,8 @@ struct catchtag
2126 jmp_buf jmp; 2169 jmp_buf jmp;
2127 struct backtrace *backlist; 2170 struct backtrace *backlist;
2128 struct handler *handlerlist; 2171 struct handler *handlerlist;
2129 int lisp_eval_depth; 2172 EMACS_INT lisp_eval_depth;
2130 int pdlcount; 2173 ptrdiff_t pdlcount;
2131 int poll_suppress_count; 2174 int poll_suppress_count;
2132 int interrupt_input_blocked; 2175 int interrupt_input_blocked;
2133 struct byte_stack *byte_stack; 2176 struct byte_stack *byte_stack;
@@ -2533,8 +2576,8 @@ EXFUN (Fread_coding_system, 2);
2533EXFUN (Fread_non_nil_coding_system, 1); 2576EXFUN (Fread_non_nil_coding_system, 1);
2534EXFUN (Ffind_operation_coding_system, MANY); 2577EXFUN (Ffind_operation_coding_system, MANY);
2535EXFUN (Fdecode_coding_string, 4); 2578EXFUN (Fdecode_coding_string, 4);
2536extern Lisp_Object detect_coding_system (const unsigned char *, EMACS_INT, 2579extern Lisp_Object detect_coding_system (const unsigned char *, ptrdiff_t,
2537 EMACS_INT, int, int, Lisp_Object); 2580 ptrdiff_t, int, int, Lisp_Object);
2538extern void init_coding (void); 2581extern void init_coding (void);
2539extern void init_coding_once (void); 2582extern void init_coding_once (void);
2540extern void syms_of_coding (void); 2583extern void syms_of_coding (void);
@@ -2542,8 +2585,8 @@ extern void syms_of_coding (void);
2542/* Defined in character.c */ 2585/* Defined in character.c */
2543EXFUN (Fchar_width, 1); 2586EXFUN (Fchar_width, 1);
2544EXFUN (Fstring, MANY); 2587EXFUN (Fstring, MANY);
2545extern EMACS_INT chars_in_text (const unsigned char *, EMACS_INT); 2588extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
2546extern EMACS_INT multibyte_chars_in_text (const unsigned char *, EMACS_INT); 2589extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
2547extern int multibyte_char_to_unibyte (int); 2590extern int multibyte_char_to_unibyte (int);
2548extern int multibyte_char_to_unibyte_safe (int); 2591extern int multibyte_char_to_unibyte_safe (int);
2549extern void init_character_once (void); 2592extern void init_character_once (void);
@@ -2570,7 +2613,7 @@ extern void syms_of_syntax (void);
2570extern Lisp_Object QCrehash_size, QCrehash_threshold; 2613extern Lisp_Object QCrehash_size, QCrehash_threshold;
2571enum { NEXT_ALMOST_PRIME_LIMIT = 11 }; 2614enum { NEXT_ALMOST_PRIME_LIMIT = 11 };
2572extern EMACS_INT next_almost_prime (EMACS_INT); 2615extern EMACS_INT next_almost_prime (EMACS_INT);
2573extern Lisp_Object larger_vector (Lisp_Object, EMACS_INT, Lisp_Object); 2616extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
2574extern void sweep_weak_hash_tables (void); 2617extern void sweep_weak_hash_tables (void);
2575extern Lisp_Object Qcursor_in_echo_area; 2618extern Lisp_Object Qcursor_in_echo_area;
2576extern Lisp_Object Qstring_lessp; 2619extern Lisp_Object Qstring_lessp;
@@ -2602,8 +2645,8 @@ EXFUN (Fstring_as_multibyte, 1);
2602EXFUN (Fstring_as_unibyte, 1); 2645EXFUN (Fstring_as_unibyte, 1);
2603EXFUN (Fstring_to_multibyte, 1); 2646EXFUN (Fstring_to_multibyte, 1);
2604EXFUN (Fsubstring, 3); 2647EXFUN (Fsubstring, 3);
2605extern Lisp_Object substring_both (Lisp_Object, EMACS_INT, EMACS_INT, 2648extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
2606 EMACS_INT, EMACS_INT); 2649 ptrdiff_t, ptrdiff_t);
2607EXFUN (Fnth, 2); 2650EXFUN (Fnth, 2);
2608EXFUN (Fnthcdr, 2); 2651EXFUN (Fnthcdr, 2);
2609EXFUN (Fmemq, 2); 2652EXFUN (Fmemq, 2);
@@ -2631,8 +2674,8 @@ extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
2631extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object); 2674extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
2632extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object); 2675extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);
2633extern void clear_string_char_byte_cache (void); 2676extern void clear_string_char_byte_cache (void);
2634extern EMACS_INT string_char_to_byte (Lisp_Object, EMACS_INT); 2677extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t);
2635extern EMACS_INT string_byte_to_char (Lisp_Object, EMACS_INT); 2678extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t);
2636extern Lisp_Object string_to_multibyte (Lisp_Object); 2679extern Lisp_Object string_to_multibyte (Lisp_Object);
2637extern Lisp_Object string_make_unibyte (Lisp_Object); 2680extern Lisp_Object string_make_unibyte (Lisp_Object);
2638EXFUN (Fcopy_alist, 1); 2681EXFUN (Fcopy_alist, 1);
@@ -2670,55 +2713,60 @@ extern void init_image (void);
2670 2713
2671/* Defined in insdel.c */ 2714/* Defined in insdel.c */
2672extern Lisp_Object Qinhibit_modification_hooks; 2715extern Lisp_Object Qinhibit_modification_hooks;
2673extern void move_gap (EMACS_INT); 2716extern void move_gap (ptrdiff_t);
2674extern void move_gap_both (EMACS_INT, EMACS_INT); 2717extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2675extern void buffer_overflow (void) NO_RETURN; 2718extern void buffer_overflow (void) NO_RETURN;
2676extern void make_gap (EMACS_INT); 2719extern void make_gap (ptrdiff_t);
2677extern EMACS_INT copy_text (const unsigned char *, unsigned char *, 2720extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
2678 EMACS_INT, int, int); 2721 ptrdiff_t, int, int);
2679extern int count_combining_before (const unsigned char *, 2722extern int count_combining_before (const unsigned char *,
2680 EMACS_INT, EMACS_INT, EMACS_INT); 2723 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2681extern int count_combining_after (const unsigned char *, 2724extern int count_combining_after (const unsigned char *,
2682 EMACS_INT, EMACS_INT, EMACS_INT); 2725 ptrdiff_t, ptrdiff_t, ptrdiff_t);
2683extern void insert (const char *, EMACS_INT); 2726extern void insert (const char *, ptrdiff_t);
2684extern void insert_and_inherit (const char *, EMACS_INT); 2727extern void insert_and_inherit (const char *, ptrdiff_t);
2685extern void insert_1 (const char *, EMACS_INT, int, int, int); 2728extern void insert_1 (const char *, ptrdiff_t, int, int, int);
2686extern void insert_1_both (const char *, EMACS_INT, EMACS_INT, 2729extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
2687 int, int, int); 2730 int, int, int);
2688extern void insert_from_gap (EMACS_INT, EMACS_INT); 2731extern void insert_from_gap (ptrdiff_t, ptrdiff_t);
2689extern void insert_from_string (Lisp_Object, EMACS_INT, EMACS_INT, 2732extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
2690 EMACS_INT, EMACS_INT, int); 2733 ptrdiff_t, ptrdiff_t, int);
2691extern void insert_from_buffer (struct buffer *, EMACS_INT, EMACS_INT, int); 2734extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2692extern void insert_char (int); 2735extern void insert_char (int);
2693extern void insert_string (const char *); 2736extern void insert_string (const char *);
2694extern void insert_before_markers (const char *, EMACS_INT); 2737extern void insert_before_markers (const char *, ptrdiff_t);
2695extern void insert_before_markers_and_inherit (const char *, EMACS_INT); 2738extern void insert_before_markers_and_inherit (const char *, ptrdiff_t);
2696extern void insert_from_string_before_markers (Lisp_Object, EMACS_INT, 2739extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
2697 EMACS_INT, EMACS_INT, 2740 ptrdiff_t, ptrdiff_t,
2698 EMACS_INT, int); 2741 ptrdiff_t, int);
2699extern void del_range (EMACS_INT, EMACS_INT); 2742extern void del_range (ptrdiff_t, ptrdiff_t);
2700extern Lisp_Object del_range_1 (EMACS_INT, EMACS_INT, int, int); 2743extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, int, int);
2701extern void del_range_byte (EMACS_INT, EMACS_INT, int); 2744extern void del_range_byte (ptrdiff_t, ptrdiff_t, int);
2702extern void del_range_both (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, int); 2745extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, int);
2703extern Lisp_Object del_range_2 (EMACS_INT, EMACS_INT, 2746extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
2704 EMACS_INT, EMACS_INT, int); 2747 ptrdiff_t, ptrdiff_t, int);
2705extern void modify_region (struct buffer *, EMACS_INT, EMACS_INT, int); 2748extern void modify_region (struct buffer *, ptrdiff_t, ptrdiff_t, int);
2706extern void prepare_to_modify_buffer (EMACS_INT, EMACS_INT, EMACS_INT *); 2749extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
2707extern void signal_after_change (EMACS_INT, EMACS_INT, EMACS_INT); 2750extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
2708extern void adjust_after_insert (EMACS_INT, EMACS_INT, EMACS_INT, 2751extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2709 EMACS_INT, EMACS_INT); 2752 ptrdiff_t, ptrdiff_t);
2710extern void adjust_markers_for_delete (EMACS_INT, EMACS_INT, 2753extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
2711 EMACS_INT, EMACS_INT); 2754 ptrdiff_t, ptrdiff_t);
2712extern void replace_range (EMACS_INT, EMACS_INT, Lisp_Object, int, int, int); 2755extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, int, int, int);
2713extern void replace_range_2 (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, 2756extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
2714 const char *, EMACS_INT, EMACS_INT, int); 2757 const char *, ptrdiff_t, ptrdiff_t, int);
2715extern void syms_of_insdel (void); 2758extern void syms_of_insdel (void);
2716 2759
2717/* Defined in dispnew.c */ 2760/* Defined in dispnew.c */
2761#if (defined PROFILING \
2762 && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__))
2763void __executable_start (void) NO_RETURN;
2764#endif
2718extern Lisp_Object selected_frame; 2765extern Lisp_Object selected_frame;
2719extern Lisp_Object Vwindow_system; 2766extern Lisp_Object Vwindow_system;
2720EXFUN (Fding, 1); 2767EXFUN (Fding, 1);
2721EXFUN (Fredraw_frame, 1); 2768EXFUN (Fredraw_frame, 1);
2769void duration_to_sec_usec (double, int *, int *);
2722EXFUN (Fsleep_for, 2); 2770EXFUN (Fsleep_for, 2);
2723EXFUN (Fredisplay, 1); 2771EXFUN (Fredisplay, 1);
2724extern Lisp_Object sit_for (Lisp_Object, int, int); 2772extern Lisp_Object sit_for (Lisp_Object, int, int);
@@ -2740,7 +2788,7 @@ extern Lisp_Object QCdata, QCfile;
2740extern Lisp_Object QCmap; 2788extern Lisp_Object QCmap;
2741extern Lisp_Object Qrisky_local_variable; 2789extern Lisp_Object Qrisky_local_variable;
2742extern struct frame *last_glyphless_glyph_frame; 2790extern struct frame *last_glyphless_glyph_frame;
2743extern unsigned last_glyphless_glyph_face_id; 2791extern int last_glyphless_glyph_face_id;
2744extern int last_glyphless_glyph_merged_face_id; 2792extern int last_glyphless_glyph_merged_face_id;
2745extern int noninteractive_need_newline; 2793extern int noninteractive_need_newline;
2746extern Lisp_Object echo_area_buffer[2]; 2794extern Lisp_Object echo_area_buffer[2];
@@ -2756,15 +2804,15 @@ extern void clear_message (int, int);
2756extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); 2804extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
2757extern void message1 (const char *); 2805extern void message1 (const char *);
2758extern void message1_nolog (const char *); 2806extern void message1_nolog (const char *);
2759extern void message2 (const char *, EMACS_INT, int); 2807extern void message2 (const char *, ptrdiff_t, int);
2760extern void message2_nolog (const char *, EMACS_INT, int); 2808extern void message2_nolog (const char *, ptrdiff_t, int);
2761extern void message3 (Lisp_Object, EMACS_INT, int); 2809extern void message3 (Lisp_Object, ptrdiff_t, int);
2762extern void message3_nolog (Lisp_Object, EMACS_INT, int); 2810extern void message3_nolog (Lisp_Object, ptrdiff_t, int);
2763extern void message_dolog (const char *, EMACS_INT, int, int); 2811extern void message_dolog (const char *, ptrdiff_t, int, int);
2764extern void message_with_string (const char *, Lisp_Object, int); 2812extern void message_with_string (const char *, Lisp_Object, int);
2765extern void message_log_maybe_newline (void); 2813extern void message_log_maybe_newline (void);
2766extern void update_echo_area (void); 2814extern void update_echo_area (void);
2767extern void truncate_echo_area (EMACS_INT); 2815extern void truncate_echo_area (ptrdiff_t);
2768extern void redisplay (void); 2816extern void redisplay (void);
2769extern void redisplay_preserve_echo_area (int); 2817extern void redisplay_preserve_echo_area (int);
2770extern void prepare_menu_bars (void); 2818extern void prepare_menu_bars (void);
@@ -2773,14 +2821,14 @@ void set_frame_cursor_types (struct frame *, Lisp_Object);
2773extern void syms_of_xdisp (void); 2821extern void syms_of_xdisp (void);
2774extern void init_xdisp (void); 2822extern void init_xdisp (void);
2775extern Lisp_Object safe_eval (Lisp_Object); 2823extern Lisp_Object safe_eval (Lisp_Object);
2776extern int pos_visible_p (struct window *, EMACS_INT, int *, 2824extern int pos_visible_p (struct window *, ptrdiff_t, int *,
2777 int *, int *, int *, int *, int *); 2825 int *, int *, int *, int *, int *);
2778 2826
2779/* Defined in xsettings.c */ 2827/* Defined in xsettings.c */
2780extern void syms_of_xsettings (void); 2828extern void syms_of_xsettings (void);
2781 2829
2782/* Defined in vm-limit.c. */ 2830/* Defined in vm-limit.c. */
2783extern void memory_warnings (POINTER_TYPE *, void (*warnfun) (const char *)); 2831extern void memory_warnings (void *, void (*warnfun) (const char *));
2784 2832
2785/* Defined in alloc.c */ 2833/* Defined in alloc.c */
2786extern void check_pure_size (void); 2834extern void check_pure_size (void);
@@ -2789,7 +2837,7 @@ extern void reset_malloc_hooks (void);
2789extern void uninterrupt_malloc (void); 2837extern void uninterrupt_malloc (void);
2790extern void malloc_warning (const char *); 2838extern void malloc_warning (const char *);
2791extern void memory_full (size_t) NO_RETURN; 2839extern void memory_full (size_t) NO_RETURN;
2792extern void buffer_memory_full (EMACS_INT) NO_RETURN; 2840extern void buffer_memory_full (ptrdiff_t) NO_RETURN;
2793extern int survives_gc_p (Lisp_Object); 2841extern int survives_gc_p (Lisp_Object);
2794extern void mark_object (Lisp_Object); 2842extern void mark_object (Lisp_Object);
2795#if defined REL_ALLOC && !defined SYSTEM_MALLOC 2843#if defined REL_ALLOC && !defined SYSTEM_MALLOC
@@ -2814,26 +2862,25 @@ EXFUN (Fmake_marker, 0);
2814extern void string_overflow (void) NO_RETURN; 2862extern void string_overflow (void) NO_RETURN;
2815EXFUN (Fmake_string, 2); 2863EXFUN (Fmake_string, 2);
2816extern Lisp_Object build_string (const char *); 2864extern Lisp_Object build_string (const char *);
2817extern Lisp_Object make_string (const char *, EMACS_INT); 2865extern Lisp_Object make_string (const char *, ptrdiff_t);
2818extern Lisp_Object make_unibyte_string (const char *, EMACS_INT); 2866extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
2819extern Lisp_Object make_multibyte_string (const char *, EMACS_INT, EMACS_INT); 2867extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
2820extern Lisp_Object make_event_array (int, Lisp_Object *); 2868extern Lisp_Object make_event_array (int, Lisp_Object *);
2821extern Lisp_Object make_uninit_string (EMACS_INT); 2869extern Lisp_Object make_uninit_string (EMACS_INT);
2822extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT); 2870extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
2823extern 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);
2824extern Lisp_Object make_specified_string (const char *, 2872extern Lisp_Object make_specified_string (const char *,
2825 EMACS_INT, EMACS_INT, int); 2873 ptrdiff_t, ptrdiff_t, int);
2826EXFUN (Fpurecopy, 1); 2874EXFUN (Fpurecopy, 1);
2827extern 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);
2828extern Lisp_Object make_pure_c_string (const char *data); 2876extern Lisp_Object make_pure_c_string (const char *data);
2829extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); 2877extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
2830extern Lisp_Object make_pure_vector (EMACS_INT);
2831EXFUN (Fgarbage_collect, 0); 2878EXFUN (Fgarbage_collect, 0);
2832EXFUN (Fmake_byte_code, MANY); 2879EXFUN (Fmake_byte_code, MANY);
2833EXFUN (Fmake_bool_vector, 2); 2880EXFUN (Fmake_bool_vector, 2);
2834extern Lisp_Object Qchar_table_extra_slots; 2881extern Lisp_Object Qchar_table_extra_slots;
2835extern struct Lisp_Vector *allocate_vector (EMACS_INT); 2882extern struct Lisp_Vector *allocate_vector (EMACS_INT);
2836extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag); 2883extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag);
2837#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \ 2884#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
2838 ((typ*) \ 2885 ((typ*) \
2839 allocate_pseudovector \ 2886 allocate_pseudovector \
@@ -2847,7 +2894,7 @@ extern int gc_in_progress;
2847extern int abort_on_gc; 2894extern int abort_on_gc;
2848extern Lisp_Object make_float (double); 2895extern Lisp_Object make_float (double);
2849extern void display_malloc_warning (void); 2896extern void display_malloc_warning (void);
2850extern int inhibit_garbage_collection (void); 2897extern ptrdiff_t inhibit_garbage_collection (void);
2851extern Lisp_Object make_save_value (void *, ptrdiff_t); 2898extern Lisp_Object make_save_value (void *, ptrdiff_t);
2852extern void free_marker (Lisp_Object); 2899extern void free_marker (Lisp_Object);
2853extern void free_cons (struct Lisp_Cons *); 2900extern void free_cons (struct Lisp_Cons *);
@@ -2863,6 +2910,7 @@ extern void *r_alloc (void **, size_t);
2863extern void r_alloc_free (void **); 2910extern void r_alloc_free (void **);
2864extern void *r_re_alloc (void **, size_t); 2911extern void *r_re_alloc (void **, size_t);
2865extern void r_alloc_reset_variable (void **, void **); 2912extern void r_alloc_reset_variable (void **, void **);
2913extern void r_alloc_inhibit_buffer_relocation (int);
2866#endif 2914#endif
2867 2915
2868/* Defined in chartab.c */ 2916/* Defined in chartab.c */
@@ -2939,7 +2987,7 @@ EXFUN (Fread_event, 3);
2939extern Lisp_Object check_obarray (Lisp_Object); 2987extern Lisp_Object check_obarray (Lisp_Object);
2940extern Lisp_Object intern (const char *); 2988extern Lisp_Object intern (const char *);
2941extern Lisp_Object intern_c_string (const char *); 2989extern Lisp_Object intern_c_string (const char *);
2942extern Lisp_Object oblookup (Lisp_Object, const char *, EMACS_INT, EMACS_INT); 2990extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
2943#define LOADHIST_ATTACH(x) \ 2991#define LOADHIST_ATTACH(x) \
2944 do { \ 2992 do { \
2945 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \ 2993 if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
@@ -2956,7 +3004,7 @@ extern void init_lread (void);
2956extern void syms_of_lread (void); 3004extern void syms_of_lread (void);
2957 3005
2958/* Defined in eval.c. */ 3006/* Defined in eval.c. */
2959extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qdefun, Qmacro; 3007extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qmacro;
2960extern Lisp_Object Qinhibit_quit, Qclosure; 3008extern Lisp_Object Qinhibit_quit, Qclosure;
2961extern Lisp_Object Qand_rest; 3009extern Lisp_Object Qand_rest;
2962extern Lisp_Object Vautoload_queue; 3010extern Lisp_Object Vautoload_queue;
@@ -3016,7 +3064,7 @@ extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp
3016extern 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));
3017extern void specbind (Lisp_Object, Lisp_Object); 3065extern void specbind (Lisp_Object, Lisp_Object);
3018extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); 3066extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
3019extern Lisp_Object unbind_to (int, Lisp_Object); 3067extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3020extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2); 3068extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2);
3021extern void verror (const char *, va_list) 3069extern void verror (const char *, va_list)
3022 NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0); 3070 NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0);
@@ -3068,10 +3116,9 @@ EXFUN (Fuser_login_name, 1);
3068EXFUN (Fsystem_name, 0); 3116EXFUN (Fsystem_name, 0);
3069EXFUN (Fcurrent_time, 0); 3117EXFUN (Fcurrent_time, 0);
3070EXFUN (Fget_internal_run_time, 0); 3118EXFUN (Fget_internal_run_time, 0);
3071extern EMACS_INT clip_to_bounds (EMACS_INT, EMACS_INT, EMACS_INT); 3119extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, int);
3072extern Lisp_Object make_buffer_string (EMACS_INT, EMACS_INT, int); 3120extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3073extern Lisp_Object make_buffer_string_both (EMACS_INT, EMACS_INT, EMACS_INT, 3121 ptrdiff_t, int);
3074 EMACS_INT, int);
3075extern void init_editfns (void); 3122extern void init_editfns (void);
3076const char *get_system_name (void); 3123const char *get_system_name (void);
3077extern void syms_of_editfns (void); 3124extern void syms_of_editfns (void);
@@ -3085,12 +3132,12 @@ extern void nsberror (Lisp_Object) NO_RETURN;
3085EXFUN (Fset_buffer_multibyte, 1); 3132EXFUN (Fset_buffer_multibyte, 1);
3086EXFUN (Foverlay_start, 1); 3133EXFUN (Foverlay_start, 1);
3087EXFUN (Foverlay_end, 1); 3134EXFUN (Foverlay_end, 1);
3088extern void adjust_overlays_for_insert (EMACS_INT, EMACS_INT); 3135extern void adjust_overlays_for_insert (ptrdiff_t, ptrdiff_t);
3089extern void adjust_overlays_for_delete (EMACS_INT, EMACS_INT); 3136extern void adjust_overlays_for_delete (ptrdiff_t, ptrdiff_t);
3090extern void fix_start_end_in_overlays (EMACS_INT, EMACS_INT); 3137extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3091extern void report_overlay_modification (Lisp_Object, Lisp_Object, int, 3138extern void report_overlay_modification (Lisp_Object, Lisp_Object, int,
3092 Lisp_Object, Lisp_Object, Lisp_Object); 3139 Lisp_Object, Lisp_Object, Lisp_Object);
3093extern int overlay_touches_p (EMACS_INT); 3140extern int overlay_touches_p (ptrdiff_t);
3094extern Lisp_Object Vbuffer_alist; 3141extern Lisp_Object Vbuffer_alist;
3095EXFUN (Fget_buffer, 1); 3142EXFUN (Fget_buffer, 1);
3096EXFUN (Fget_buffer_create, 1); 3143EXFUN (Fget_buffer_create, 1);
@@ -3124,17 +3171,17 @@ EXFUN (Fmarker_position, 1);
3124EXFUN (Fmarker_buffer, 1); 3171EXFUN (Fmarker_buffer, 1);
3125EXFUN (Fcopy_marker, 2); 3172EXFUN (Fcopy_marker, 2);
3126EXFUN (Fset_marker, 3); 3173EXFUN (Fset_marker, 3);
3127extern EMACS_INT marker_position (Lisp_Object); 3174extern ptrdiff_t marker_position (Lisp_Object);
3128extern EMACS_INT marker_byte_position (Lisp_Object); 3175extern ptrdiff_t marker_byte_position (Lisp_Object);
3129extern void clear_charpos_cache (struct buffer *); 3176extern void clear_charpos_cache (struct buffer *);
3130extern EMACS_INT charpos_to_bytepos (EMACS_INT); 3177extern ptrdiff_t charpos_to_bytepos (ptrdiff_t);
3131extern EMACS_INT buf_charpos_to_bytepos (struct buffer *, EMACS_INT); 3178extern ptrdiff_t buf_charpos_to_bytepos (struct buffer *, ptrdiff_t);
3132extern EMACS_INT buf_bytepos_to_charpos (struct buffer *, EMACS_INT); 3179extern ptrdiff_t buf_bytepos_to_charpos (struct buffer *, ptrdiff_t);
3133extern void unchain_marker (struct Lisp_Marker *marker); 3180extern void unchain_marker (struct Lisp_Marker *marker);
3134extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object); 3181extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object);
3135extern 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);
3136extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object, 3183extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
3137 EMACS_INT, EMACS_INT); 3184 ptrdiff_t, ptrdiff_t);
3138extern void syms_of_marker (void); 3185extern void syms_of_marker (void);
3139 3186
3140/* Defined in fileio.c */ 3187/* Defined in fileio.c */
@@ -3183,18 +3230,18 @@ struct re_registers;
3183extern struct re_pattern_buffer *compile_pattern (Lisp_Object, 3230extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3184 struct re_registers *, 3231 struct re_registers *,
3185 Lisp_Object, int, int); 3232 Lisp_Object, int, int);
3186extern EMACS_INT fast_string_match (Lisp_Object, Lisp_Object); 3233extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3187extern 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 *);
3188extern EMACS_INT fast_string_match_ignore_case (Lisp_Object, Lisp_Object); 3235extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3189extern EMACS_INT fast_looking_at (Lisp_Object, EMACS_INT, EMACS_INT, 3236extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3190 EMACS_INT, EMACS_INT, Lisp_Object); 3237 ptrdiff_t, ptrdiff_t, Lisp_Object);
3191extern EMACS_INT scan_buffer (int, EMACS_INT, EMACS_INT, EMACS_INT, 3238extern ptrdiff_t scan_buffer (int, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3192 EMACS_INT *, int); 3239 ptrdiff_t *, int);
3193extern 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,
3194 EMACS_INT, int); 3241 EMACS_INT, int);
3195extern EMACS_INT find_next_newline (EMACS_INT, int); 3242extern ptrdiff_t find_next_newline (ptrdiff_t, int);
3196extern EMACS_INT find_next_newline_no_quit (EMACS_INT, EMACS_INT); 3243extern ptrdiff_t find_next_newline_no_quit (ptrdiff_t, ptrdiff_t);
3197extern 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);
3198extern void syms_of_search (void); 3245extern void syms_of_search (void);
3199extern void clear_regexp_cache (void); 3246extern void clear_regexp_cache (void);
3200 3247
@@ -3280,9 +3327,9 @@ extern void keys_of_keyboard (void);
3280EXFUN (Fvertical_motion, 2); 3327EXFUN (Fvertical_motion, 2);
3281EXFUN (Findent_to, 2); 3328EXFUN (Findent_to, 2);
3282EXFUN (Fmove_to_column, 2); 3329EXFUN (Fmove_to_column, 2);
3283extern EMACS_INT current_column (void); 3330extern ptrdiff_t current_column (void);
3284extern void invalidate_current_column (void); 3331extern void invalidate_current_column (void);
3285extern int indented_beyond_p (EMACS_INT, EMACS_INT, EMACS_INT); 3332extern int indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3286extern void syms_of_indent (void); 3333extern void syms_of_indent (void);
3287 3334
3288/* Defined in frame.c */ 3335/* Defined in frame.c */
@@ -3414,12 +3461,12 @@ extern Lisp_Object Qapply;
3414extern Lisp_Object Qinhibit_read_only; 3461extern Lisp_Object Qinhibit_read_only;
3415EXFUN (Fundo_boundary, 0); 3462EXFUN (Fundo_boundary, 0);
3416extern void truncate_undo_list (struct buffer *); 3463extern void truncate_undo_list (struct buffer *);
3417extern void record_marker_adjustment (Lisp_Object, EMACS_INT); 3464extern void record_marker_adjustment (Lisp_Object, ptrdiff_t);
3418extern void record_insert (EMACS_INT, EMACS_INT); 3465extern void record_insert (ptrdiff_t, ptrdiff_t);
3419extern void record_delete (EMACS_INT, Lisp_Object); 3466extern void record_delete (ptrdiff_t, Lisp_Object);
3420extern void record_first_change (void); 3467extern void record_first_change (void);
3421extern void record_change (EMACS_INT, EMACS_INT); 3468extern void record_change (ptrdiff_t, ptrdiff_t);
3422extern void record_property_change (EMACS_INT, EMACS_INT, 3469extern void record_property_change (ptrdiff_t, ptrdiff_t,
3423 Lisp_Object, Lisp_Object, 3470 Lisp_Object, Lisp_Object,
3424 Lisp_Object); 3471 Lisp_Object);
3425extern void syms_of_undo (void); 3472extern void syms_of_undo (void);
@@ -3465,8 +3512,8 @@ extern void init_sys_modes (struct tty_display_info *);
3465extern void reset_sys_modes (struct tty_display_info *); 3512extern void reset_sys_modes (struct tty_display_info *);
3466extern void init_all_sys_modes (void); 3513extern void init_all_sys_modes (void);
3467extern void reset_all_sys_modes (void); 3514extern void reset_all_sys_modes (void);
3468extern void wait_for_termination (int); 3515extern void wait_for_termination (pid_t);
3469extern void interruptible_wait_for_termination (int); 3516extern void interruptible_wait_for_termination (pid_t);
3470extern void flush_pending_output (int); 3517extern void flush_pending_output (int);
3471extern void child_setup_tty (int); 3518extern void child_setup_tty (int);
3472extern void setup_pty (int); 3519extern void setup_pty (int);
@@ -3475,8 +3522,8 @@ extern EMACS_INT get_random (void);
3475extern void seed_random (long); 3522extern void seed_random (long);
3476extern int emacs_open (const char *, int, int); 3523extern int emacs_open (const char *, int, int);
3477extern int emacs_close (int); 3524extern int emacs_close (int);
3478extern EMACS_INT emacs_read (int, char *, EMACS_INT); 3525extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
3479extern EMACS_INT emacs_write (int, const char *, EMACS_INT); 3526extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
3480enum { READLINK_BUFSIZE = 1024 }; 3527enum { READLINK_BUFSIZE = 1024 };
3481extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); 3528extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]);
3482 3529
@@ -3597,9 +3644,9 @@ extern int initialized;
3597 3644
3598extern int immediate_quit; /* Nonzero means ^G can quit instantly */ 3645extern int immediate_quit; /* Nonzero means ^G can quit instantly */
3599 3646
3600extern POINTER_TYPE *xmalloc (size_t); 3647extern void *xmalloc (size_t);
3601extern POINTER_TYPE *xrealloc (POINTER_TYPE *, size_t); 3648extern void *xrealloc (void *, size_t);
3602extern void xfree (POINTER_TYPE *); 3649extern void xfree (void *);
3603extern void *xnmalloc (ptrdiff_t, ptrdiff_t); 3650extern void *xnmalloc (ptrdiff_t, ptrdiff_t);
3604extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t); 3651extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
3605extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t); 3652extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
@@ -3703,7 +3750,7 @@ extern void init_system_name (void);
3703extern Lisp_Object safe_alloca_unwind (Lisp_Object); 3750extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3704 3751
3705#define USE_SAFE_ALLOCA \ 3752#define USE_SAFE_ALLOCA \
3706 int sa_count = (int) SPECPDL_INDEX (), sa_must_free = 0 3753 ptrdiff_t sa_count = SPECPDL_INDEX (); int sa_must_free = 0
3707 3754
3708/* SAFE_ALLOCA allocates a simple buffer. */ 3755/* SAFE_ALLOCA allocates a simple buffer. */
3709 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/m/README b/src/m/README
deleted file mode 100644
index ad91167648e..00000000000
--- a/src/m/README
+++ /dev/null
@@ -1,7 +0,0 @@
1This directory contains C header files containing machine-specific
2definitions. Each file describes a particular machine. The emacs
3configuration script edits ../config.h to include the appropriate one of
4these files, and then each emacs source file includes config.h.
5
6template.h is a generic template for machine descriptions; it
7describes the parameters a machine file can specify.
diff --git a/src/m/alpha.h b/src/m/alpha.h
deleted file mode 100644
index 2a97a3d5b0c..00000000000
--- a/src/m/alpha.h
+++ /dev/null
@@ -1,53 +0,0 @@
1/* Machine description file for the alpha chip.
2
3Copyright (C) 1994, 1997, 1999, 2001-2012 Free Software Foundation, Inc.
4
5Author: Rainer Schoepf
6(according to authors.el)
7
8This file is part of GNU Emacs.
9
10GNU Emacs is free software: you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation, either version 3 of the License, or
13(at your option) any later version.
14
15GNU Emacs is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22
23#ifndef _LP64
24#define _LP64 /* This doesn't appear to be necessary on OSF 4/5 -- fx. */
25#endif
26
27/* Now define a symbol for the cpu type, if your compiler
28 does not define it automatically. */
29/* __alpha defined automatically */
30
31
32#ifdef __ELF__
33
34#if !defined (GNU_LINUX) && !defined (__NetBSD__)
35#define DATA_START 0x140000000
36#endif
37
38#else /* not __ELF__ */
39
40/* Describe layout of the address space in an executing process. */
41#define DATA_START 0x140000000
42
43#endif /* __ELF__ */
44
45/* On the Alpha it's best to avoid including TERMIO since struct
46 termio and struct termios are mutually incompatible. */
47#define NO_TERMIO
48
49/* Many Alpha implementations (e.g. gas 2.8) can't handle DBL_MIN:
50 they generate code that uses a signaling NaN instead of DBL_MIN.
51 Define DBL_MIN_REPLACEMENT to be the next value larger than DBL_MIN:
52 this avoids the assembler bug. */
53#define DBL_MIN_REPLACEMENT 2.2250738585072019e-308
diff --git a/src/m/amdx86-64.h b/src/m/amdx86-64.h
deleted file mode 100644
index f0482c733f9..00000000000
--- a/src/m/amdx86-64.h
+++ /dev/null
@@ -1,35 +0,0 @@
1/* machine description file for AMD x86-64.
2
3Copyright (C) 2002-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#define BITS_PER_LONG 64
21#define BITS_PER_EMACS_INT 64
22
23/* Now define a symbol for the cpu type, if your compiler
24 does not define it automatically:
25 Ones defined so far include vax, m68000, ns16000, pyramid,
26 orion, tahoe, APOLLO and many others */
27/* __x86_64 defined automatically. */
28
29/* Define the type to use. */
30#define EMACS_INT long
31#define pI "l"
32#define EMACS_UINT unsigned long
33
34/* Define XPNTR to avoid or'ing with DATA_SEG_BITS */
35#undef DATA_SEG_BITS
diff --git a/src/m/ia64.h b/src/m/ia64.h
deleted file mode 100644
index 47df94cedd0..00000000000
--- a/src/m/ia64.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* machine description file for the IA-64 architecture.
2
3Copyright (C) 2000-2012 Free Software Foundation, Inc.
4
5 Contributed by David Mosberger <davidm@hpl.hp.com>
6
7This file is part of GNU Emacs.
8
9GNU Emacs is free software: you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation, either version 3 of the License, or
12(at your option) any later version.
13
14GNU Emacs is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21
22#define BITS_PER_LONG 64
23#define BITS_PER_EMACS_INT 64
24
25/* Now define a symbol for the cpu type, if your compiler
26 does not define it automatically. */
27/* __ia64__ defined automatically */
28
29/* Define the type to use. */
30#define EMACS_INT long
31#define pI "l"
32#define EMACS_UINT unsigned long
diff --git a/src/m/ibmrs6000.h b/src/m/ibmrs6000.h
deleted file mode 100644
index 9798ad2d3d7..00000000000
--- a/src/m/ibmrs6000.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/* R2 AIX machine/system dependent defines
2
3Copyright (C) 1988, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20
21/* The data segment in this machine always starts at address 0x20000000.
22 An address of data cannot be stored correctly in a Lisp object;
23 we always lose the high bits. We must tell XPNTR to add them back. */
24#define DATA_START 0x20000000
25#define DATA_SEG_BITS 0x20000000
26
27#ifndef NLIST_STRUCT
28/* AIX supposedly doesn't use this interface, but on the RS/6000
29 it apparently does. */
30#define NLIST_STRUCT
31#endif
32
33#undef ADDR_CORRECT
34#define ADDR_CORRECT(x) ((int)(x))
35
36/*** BUILD 9008 - FIONREAD problem still exists in X-Windows. ***/
37#define BROKEN_FIONREAD
38/* As we define BROKEN_FIONREAD, SIGIO will be undefined in systty.h.
39 But, on AIX, SIGAIO, SIGPTY, and SIGPOLL are defined as SIGIO,
40 which causes compilation error at init_signals in sysdep.c. So, we
41 define these macros so that syssignal.h detects them and undefine
42 SIGAIO, SIGPTY and SIGPOLL. */
43#define BROKEN_SIGAIO
44#define BROKEN_SIGPTY
45#define BROKEN_SIGPOLL
46
diff --git a/src/m/ibms390x.h b/src/m/ibms390x.h
deleted file mode 100644
index aa652a8206a..00000000000
--- a/src/m/ibms390x.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* Machine description file for IBM S390 in 64-bit mode
2
3Copyright (C) 2002-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#define BITS_PER_LONG 64
21#define BITS_PER_EMACS_INT 64
22
23/* Define the type to use. */
24#define EMACS_INT long
25#define pI "l"
26#define EMACS_UINT unsigned long
27
28/* On the 64 bit architecture, we can use 60 bits for addresses */
29#define VALBITS 60
30
31/* Define XPNTR to avoid or'ing with DATA_SEG_BITS */
32#define XPNTR(a) XUINT (a)
diff --git a/src/m/intel386.h b/src/m/intel386.h
deleted file mode 100644
index 78a43e92c21..00000000000
--- a/src/m/intel386.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/* Machine description file for intel 386.
2
3Copyright (C) 1987, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20
21#ifdef WINDOWSNT
22#define DATA_START get_data_start ()
23#endif
24
25#ifdef GNU_LINUX
26/* libc-linux/sysdeps/linux/i386/ulimit.c says that due to shared library, */
27/* we cannot get the maximum address for brk */
28#define ULIMIT_BREAK_VALUE (32*1024*1024)
29#endif
diff --git a/src/m/m68k.h b/src/m/m68k.h
deleted file mode 100644
index 120a2bad293..00000000000
--- a/src/m/m68k.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* Machine description file for generic Motorola 68k.
2
3Copyright (C) 1985, 1995, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20/* Now define a symbol for the cpu type, if your compiler
21 does not define it automatically. */
22#ifndef m68k
23#define m68k
24#endif
25
26#ifdef GNU_LINUX
27#ifdef __ELF__
28#define DATA_SEG_BITS 0x80000000
29#endif
30
31#endif
32
diff --git a/src/m/macppc.h b/src/m/macppc.h
deleted file mode 100644
index 0303ead25d6..00000000000
--- a/src/m/macppc.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* machine description file For the powerpc Macintosh.
2
3Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#ifdef _ARCH_PPC64
21#ifndef _LP64
22#define _LP64
23#endif
24#endif
diff --git a/src/m/sparc.h b/src/m/sparc.h
deleted file mode 100644
index 27b6070ba87..00000000000
--- a/src/m/sparc.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/* machine description file for Sun 4 SPARC.
2
3Copyright (C) 1987, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20/* __sparc__ is defined by the compiler by default. */
21
22#ifdef __arch64__ /* GCC, 64-bit ABI. */
23
24#define BITS_PER_LONG 64
25
26#ifndef _LP64
27#define _LP64 /* Done on Alpha -- not sure if it should be here. -- fx */
28#endif
29
30#endif /* __arch64__ */
diff --git a/src/m/template.h b/src/m/template.h
deleted file mode 100644
index 5f1a46c86e1..00000000000
--- a/src/m/template.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/* machine description file template.
2
3Copyright (C) 1985-1986, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20/* Now define a symbol for the cpu type, if your compiler
21 does not define it automatically.
22 Ones defined so far include m68k and many others */
23
24/* After adding support for a new machine, modify the large case
25 statement in configure.in to recognize reasonable
26 configuration names, and add a description of the system to
27 `etc/MACHINES'.
28
29 Check for any tests of $machine in configure.in, and add an entry
30 for the new machine if needed.
31
32 If you've just fixed a problem in an existing configuration file,
33 you should also check `etc/MACHINES' to make sure its descriptions
34 of known problems in that configuration should be updated. */
diff --git a/src/macros.c b/src/macros.c
index d43e37513f5..0db7e63d622 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. */
@@ -258,7 +259,7 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
258 from before this macro started. */ 259 from before this macro started. */
259 Vthis_command = KVAR (current_kboard, Vlast_command); 260 Vthis_command = KVAR (current_kboard, Vlast_command);
260 /* C-x z after the macro should repeat the macro. */ 261 /* C-x z after the macro should repeat the macro. */
261 real_this_command = KVAR (current_kboard, Vlast_kbd_macro); 262 Vreal_this_command = KVAR (current_kboard, Vlast_kbd_macro);
262 263
263 if (! NILP (KVAR (current_kboard, defining_kbd_macro))) 264 if (! NILP (KVAR (current_kboard, defining_kbd_macro)))
264 error ("Can't execute anonymous macro while defining one"); 265 error ("Can't execute anonymous macro while defining one");
@@ -285,7 +286,7 @@ pop_kbd_macro (Lisp_Object info)
285 Vexecuting_kbd_macro = XCAR (info); 286 Vexecuting_kbd_macro = XCAR (info);
286 tem = XCDR (info); 287 tem = XCDR (info);
287 executing_kbd_macro_index = XINT (XCAR (tem)); 288 executing_kbd_macro_index = XINT (XCAR (tem));
288 real_this_command = XCDR (tem); 289 Vreal_this_command = XCDR (tem);
289 Frun_hooks (1, &Qkbd_macro_termination_hook); 290 Frun_hooks (1, &Qkbd_macro_termination_hook);
290 return Qnil; 291 return Qnil;
291} 292}
@@ -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;
@@ -320,7 +321,7 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
320 321
321 tem = Fcons (Vexecuting_kbd_macro, 322 tem = Fcons (Vexecuting_kbd_macro,
322 Fcons (make_number (executing_kbd_macro_index), 323 Fcons (make_number (executing_kbd_macro_index),
323 real_this_command)); 324 Vreal_this_command));
324 record_unwind_protect (pop_kbd_macro, tem); 325 record_unwind_protect (pop_kbd_macro, tem);
325 326
326 GCPRO2 (final, loopfunc); 327 GCPRO2 (final, loopfunc);
@@ -351,7 +352,7 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
351 352
352 executing_kbd_macro = Qnil; 353 executing_kbd_macro = Qnil;
353 354
354 real_this_command = Vexecuting_kbd_macro; 355 Vreal_this_command = Vexecuting_kbd_macro;
355 356
356 UNGCPRO; 357 UNGCPRO;
357 return unbind_to (pdlcount, Qnil); 358 return unbind_to (pdlcount, Qnil);
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index f62c501e1fa..0b88f7cd06b 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -343,7 +343,7 @@ cleanall: clean
343## 343##
344## This works only with GNU Make. 344## This works only with GNU Make.
345 345
346TAGS: $(OBJ0) $(OBJ1) $(OBJ2) $(CURDIR)/m/intel386.h $(CURDIR)/s/ms-w32.h 346TAGS: $(OBJ0) $(OBJ1) $(OBJ2) $(CURDIR)/s/ms-w32.h
347 $(MAKE) $(MFLAGS) TAGS-$(MAKETYPE) 347 $(MAKE) $(MFLAGS) TAGS-$(MAKETYPE)
348 348
349TAGS-LISP: $(OBJ0) $(OBJ1) $(OBJ2) 349TAGS-LISP: $(OBJ0) $(OBJ1) $(OBJ2)
@@ -357,7 +357,7 @@ TAGS-gmake:
357 $(OBJ1_c) 357 $(OBJ1_c)
358 ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \ 358 ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
359 $(OBJ2_c) \ 359 $(OBJ2_c) \
360 $(CURDIR)/*.h $(CURDIR)/m/intel386.h $(CURDIR)/s/ms-w32.h 360 $(CURDIR)/*.h $(CURDIR)/s/ms-w32.h
361 361
362TAGS-nmake: 362TAGS-nmake:
363 echo This target is not supported with NMake 363 echo This target is not supported with NMake
@@ -407,7 +407,6 @@ CODING_H = $(SRC)/coding.h \
407MS_W32_H = $(SRC)/s/ms-w32.h \ 407MS_W32_H = $(SRC)/s/ms-w32.h \
408 $(NT_INC)/sys/stat.h 408 $(NT_INC)/sys/stat.h
409CONFIG_H = $(SRC)/config.h \ 409CONFIG_H = $(SRC)/config.h \
410 $(SRC)/m/intel386.h \
411 $(MS_W32_H) 410 $(MS_W32_H)
412DIR_H = $(NT_INC)/sys/dir.h \ 411DIR_H = $(NT_INC)/sys/dir.h \
413 $(SRC)/ndir.h 412 $(SRC)/ndir.h
@@ -1150,6 +1149,7 @@ $(BLD)/w32heap.$(O) : \
1150 1149
1151$(BLD)/w32inevt.$(O) : \ 1150$(BLD)/w32inevt.$(O) : \
1152 $(SRC)/w32inevt.c \ 1151 $(SRC)/w32inevt.c \
1152 $(SRC)/termchar.h \
1153 $(SRC)/w32heap.h \ 1153 $(SRC)/w32heap.h \
1154 $(BLOCKINPUT_H) \ 1154 $(BLOCKINPUT_H) \
1155 $(CONFIG_H) \ 1155 $(CONFIG_H) \
@@ -1158,7 +1158,8 @@ $(BLD)/w32inevt.$(O) : \
1158 $(KEYBOARD_H) \ 1158 $(KEYBOARD_H) \
1159 $(LISP_H) \ 1159 $(LISP_H) \
1160 $(TERMHOOKS_H) \ 1160 $(TERMHOOKS_H) \
1161 $(W32TERM_H) 1161 $(W32TERM_H) \
1162 $(WINDOW_H)
1162 1163
1163$(BLD)/w32proc.$(O) : \ 1164$(BLD)/w32proc.$(O) : \
1164 $(SRC)/w32proc.c \ 1165 $(SRC)/w32proc.c \
@@ -1188,7 +1189,8 @@ $(BLD)/w32console.$(O) : \
1188 $(DISPEXTERN_H) \ 1189 $(DISPEXTERN_H) \
1189 $(FRAME_H) \ 1190 $(FRAME_H) \
1190 $(LISP_H) \ 1191 $(LISP_H) \
1191 $(TERMHOOKS_H) 1192 $(TERMHOOKS_H) \
1193 $(WINDOW_H)
1192 1194
1193$(BLD)/print.$(O) : \ 1195$(BLD)/print.$(O) : \
1194 $(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/mem-limits.h b/src/mem-limits.h
index 244592a9768..1fd53b472f3 100644
--- a/src/mem-limits.h
+++ b/src/mem-limits.h
@@ -34,7 +34,7 @@ extern int etext;
34#endif 34#endif
35 35
36extern char *start_of_data (void); 36extern char *start_of_data (void);
37#if defined USE_LSB_TAG || UINTPTR_MAX >> VALBITS == 0 37#if defined USE_LSB_TAG || UINTPTR_MAX <= VAL_MAX
38#define EXCEEDS_LISP_PTR(ptr) 0 38#define EXCEEDS_LISP_PTR(ptr) 0
39#elif defined DATA_SEG_BITS 39#elif defined DATA_SEG_BITS
40#define EXCEEDS_LISP_PTR(ptr) \ 40#define EXCEEDS_LISP_PTR(ptr) \
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..d921e80be48 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
@@ -1726,8 +1726,6 @@ See also `completing-read-function'. */)
1726 return Ffuncall (9, args); 1726 return Ffuncall (9, args);
1727} 1727}
1728 1728
1729Lisp_Object Fassoc_string (register Lisp_Object key, Lisp_Object list, Lisp_Object case_fold);
1730
1731/* Test whether TXT is an exact completion. */ 1729/* Test whether TXT is an exact completion. */
1732DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0, 1730DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0,
1733 doc: /* Return non-nil if STRING is a valid completion. 1731 doc: /* Return non-nil if STRING is a valid completion.
@@ -1821,7 +1819,7 @@ the values STRING, PREDICATE and `lambda'. */)
1821 /* Reject this element if it fails to match all the regexps. */ 1819 /* Reject this element if it fails to match all the regexps. */
1822 if (CONSP (Vcompletion_regexp_list)) 1820 if (CONSP (Vcompletion_regexp_list))
1823 { 1821 {
1824 int count = SPECPDL_INDEX (); 1822 ptrdiff_t count = SPECPDL_INDEX ();
1825 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil); 1823 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1826 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1824 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1827 regexps = XCDR (regexps)) 1825 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 c2edde590fe..2158d06dbca 100644
--- a/src/print.c
+++ b/src/print.c
@@ -55,10 +55,10 @@ static Lisp_Object Qfloat_output_format;
55#endif 55#endif
56 56
57/* Avoid actual stack overflow in print. */ 57/* Avoid actual stack overflow in print. */
58static int print_depth; 58static ptrdiff_t print_depth;
59 59
60/* Level of nesting inside outputting backquote in new style. */ 60/* Level of nesting inside outputting backquote in new style. */
61static int new_backquote_output; 61static ptrdiff_t new_backquote_output;
62 62
63/* Detect most circularities to print finite output. */ 63/* Detect most circularities to print finite output. */
64#define PRINT_CIRCLE 200 64#define PRINT_CIRCLE 200
@@ -69,11 +69,11 @@ static Lisp_Object being_printed[PRINT_CIRCLE];
69static char *print_buffer; 69static char *print_buffer;
70 70
71/* Size allocated in print_buffer. */ 71/* Size allocated in print_buffer. */
72static EMACS_INT print_buffer_size; 72static ptrdiff_t print_buffer_size;
73/* Chars stored in print_buffer. */ 73/* Chars stored in print_buffer. */
74static EMACS_INT print_buffer_pos; 74static ptrdiff_t print_buffer_pos;
75/* Bytes stored in print_buffer. */ 75/* Bytes stored in print_buffer. */
76static EMACS_INT print_buffer_pos_byte; 76static ptrdiff_t print_buffer_pos_byte;
77 77
78Lisp_Object Qprint_escape_newlines; 78Lisp_Object Qprint_escape_newlines;
79static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii; 79static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
@@ -86,7 +86,7 @@ static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
86 N the object has been printed so we can refer to it as #N#. 86 N the object has been printed so we can refer to it as #N#.
87 print_number_index holds the largest N already used. 87 print_number_index holds the largest N already used.
88 N has to be striclty larger than 0 since we need to distinguish -N. */ 88 N has to be striclty larger than 0 since we need to distinguish -N. */
89static int print_number_index; 89static ptrdiff_t print_number_index;
90static void print_interval (INTERVAL interval, Lisp_Object printcharfun); 90static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
91 91
92/* GDB resets this to zero on W32 to disable OutputDebugString calls. */ 92/* GDB resets this to zero on W32 to disable OutputDebugString calls. */
@@ -104,9 +104,9 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
104 104
105#define PRINTDECLARE \ 105#define PRINTDECLARE \
106 struct buffer *old = current_buffer; \ 106 struct buffer *old = current_buffer; \
107 EMACS_INT old_point = -1, start_point = -1; \ 107 ptrdiff_t old_point = -1, start_point = -1; \
108 EMACS_INT old_point_byte = -1, start_point_byte = -1; \ 108 ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
109 int specpdl_count = SPECPDL_INDEX (); \ 109 ptrdiff_t specpdl_count = SPECPDL_INDEX (); \
110 int free_print_buffer = 0; \ 110 int free_print_buffer = 0; \
111 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \ 111 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
112 Lisp_Object original 112 Lisp_Object original
@@ -122,7 +122,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
122 } \ 122 } \
123 if (MARKERP (printcharfun)) \ 123 if (MARKERP (printcharfun)) \
124 { \ 124 { \
125 EMACS_INT marker_pos; \ 125 ptrdiff_t marker_pos; \
126 if (! XMARKER (printcharfun)->buffer) \ 126 if (! XMARKER (printcharfun)->buffer) \
127 error ("Marker does not point anywhere"); \ 127 error ("Marker does not point anywhere"); \
128 if (XMARKER (printcharfun)->buffer != current_buffer) \ 128 if (XMARKER (printcharfun)->buffer != current_buffer) \
@@ -156,7 +156,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
156 } \ 156 } \
157 else \ 157 else \
158 { \ 158 { \
159 ptrdiff_t new_size = 1000; \ 159 int new_size = 1000; \
160 print_buffer = (char *) xmalloc (new_size); \ 160 print_buffer = (char *) xmalloc (new_size); \
161 print_buffer_size = new_size; \ 161 print_buffer_size = new_size; \
162 free_print_buffer = 1; \ 162 free_print_buffer = 1; \
@@ -233,15 +233,10 @@ printchar (unsigned int ch, Lisp_Object fun)
233 233
234 if (NILP (fun)) 234 if (NILP (fun))
235 { 235 {
236 if (print_buffer_size - len <= print_buffer_pos_byte) 236 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
237 { 237 if (0 < incr)
238 ptrdiff_t new_size; 238 print_buffer =
239 if (STRING_BYTES_BOUND / 2 < print_buffer_size) 239 xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
240 string_overflow ();
241 new_size = print_buffer_size * 2;
242 print_buffer = (char *) xrealloc (print_buffer, new_size);
243 print_buffer_size = new_size;
244 }
245 memcpy (print_buffer + print_buffer_pos_byte, str, len); 240 memcpy (print_buffer + print_buffer_pos_byte, str, len);
246 print_buffer_pos += 1; 241 print_buffer_pos += 1;
247 print_buffer_pos_byte += len; 242 print_buffer_pos_byte += len;
@@ -276,7 +271,7 @@ printchar (unsigned int ch, Lisp_Object fun)
276 to data in a Lisp string. Otherwise that is not safe. */ 271 to data in a Lisp string. Otherwise that is not safe. */
277 272
278static void 273static void
279strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte, 274strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
280 Lisp_Object printcharfun) 275 Lisp_Object printcharfun)
281{ 276{
282 if (size < 0) 277 if (size < 0)
@@ -284,15 +279,9 @@ strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
284 279
285 if (NILP (printcharfun)) 280 if (NILP (printcharfun))
286 { 281 {
287 if (print_buffer_size - size_byte < print_buffer_pos_byte) 282 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
288 { 283 if (0 < incr)
289 ptrdiff_t new_size; 284 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
290 if (STRING_BYTES_BOUND / 2 - size_byte < print_buffer_size)
291 string_overflow ();
292 new_size = print_buffer_size * 2 + size_byte;
293 print_buffer = (char *) xrealloc (print_buffer, new_size);
294 print_buffer_size = new_size;
295 }
296 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte); 285 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
297 print_buffer_pos += size; 286 print_buffer_pos += size;
298 print_buffer_pos_byte += size_byte; 287 print_buffer_pos_byte += size_byte;
@@ -333,7 +322,7 @@ strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
333 else 322 else
334 { 323 {
335 /* PRINTCHARFUN is a Lisp function. */ 324 /* PRINTCHARFUN is a Lisp function. */
336 EMACS_INT i = 0; 325 ptrdiff_t i = 0;
337 326
338 if (size == size_byte) 327 if (size == size_byte)
339 { 328 {
@@ -369,7 +358,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
369{ 358{
370 if (EQ (printcharfun, Qt) || NILP (printcharfun)) 359 if (EQ (printcharfun, Qt) || NILP (printcharfun))
371 { 360 {
372 EMACS_INT chars; 361 ptrdiff_t chars;
373 362
374 if (print_escape_nonascii) 363 if (print_escape_nonascii)
375 string = string_escape_byte8 (string); 364 string = string_escape_byte8 (string);
@@ -385,7 +374,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
385 convert STRING to a multibyte string containing the same 374 convert STRING to a multibyte string containing the same
386 character codes. */ 375 character codes. */
387 Lisp_Object newstr; 376 Lisp_Object newstr;
388 EMACS_INT bytes; 377 ptrdiff_t bytes;
389 378
390 chars = SBYTES (string); 379 chars = SBYTES (string);
391 bytes = count_size_as_multibyte (SDATA (string), chars); 380 bytes = count_size_as_multibyte (SDATA (string), chars);
@@ -403,7 +392,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
403 if (EQ (printcharfun, Qt)) 392 if (EQ (printcharfun, Qt))
404 { 393 {
405 /* Output to echo area. */ 394 /* Output to echo area. */
406 EMACS_INT nbytes = SBYTES (string); 395 ptrdiff_t nbytes = SBYTES (string);
407 char *buffer; 396 char *buffer;
408 397
409 /* Copy the string contents so that relocation of STRING by 398 /* Copy the string contents so that relocation of STRING by
@@ -425,9 +414,9 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
425 { 414 {
426 /* Otherwise, string may be relocated by printing one char. 415 /* Otherwise, string may be relocated by printing one char.
427 So re-fetch the string address for each character. */ 416 So re-fetch the string address for each character. */
428 EMACS_INT i; 417 ptrdiff_t i;
429 EMACS_INT size = SCHARS (string); 418 ptrdiff_t size = SCHARS (string);
430 EMACS_INT size_byte = SBYTES (string); 419 ptrdiff_t size_byte = SBYTES (string);
431 struct gcpro gcpro1; 420 struct gcpro gcpro1;
432 GCPRO1 (string); 421 GCPRO1 (string);
433 if (size == size_byte) 422 if (size == size_byte)
@@ -498,7 +487,7 @@ write_string_1 (const char *data, int size, Lisp_Object printcharfun)
498void 487void
499temp_output_buffer_setup (const char *bufname) 488temp_output_buffer_setup (const char *bufname)
500{ 489{
501 int count = SPECPDL_INDEX (); 490 ptrdiff_t count = SPECPDL_INDEX ();
502 register struct buffer *old = current_buffer; 491 register struct buffer *old = current_buffer;
503 register Lisp_Object buf; 492 register Lisp_Object buf;
504 493
@@ -602,7 +591,7 @@ A printed representation of an object is text which describes that object. */)
602 Lisp_Object printcharfun; 591 Lisp_Object printcharfun;
603 /* struct gcpro gcpro1, gcpro2; */ 592 /* struct gcpro gcpro1, gcpro2; */
604 Lisp_Object save_deactivate_mark; 593 Lisp_Object save_deactivate_mark;
605 int count = SPECPDL_INDEX (); 594 ptrdiff_t count = SPECPDL_INDEX ();
606 struct buffer *previous; 595 struct buffer *previous;
607 596
608 specbind (Qinhibit_modification_hooks, Qt); 597 specbind (Qinhibit_modification_hooks, Qt);
@@ -728,7 +717,7 @@ to make it write to the debugging output. */)
728 (Lisp_Object character) 717 (Lisp_Object character)
729{ 718{
730 CHECK_NUMBER (character); 719 CHECK_NUMBER (character);
731 putc ((int) XINT (character), stderr); 720 putc (XINT (character) & 0xFF, stderr);
732 721
733#ifdef WINDOWSNT 722#ifdef WINDOWSNT
734 /* Send the output to a debugger (nothing happens if there isn't one). */ 723 /* Send the output to a debugger (nothing happens if there isn't one). */
@@ -874,10 +863,13 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
874 if (!NILP (caller) && SYMBOLP (caller)) 863 if (!NILP (caller) && SYMBOLP (caller))
875 { 864 {
876 Lisp_Object cname = SYMBOL_NAME (caller); 865 Lisp_Object cname = SYMBOL_NAME (caller);
877 char *name = alloca (SBYTES (cname)); 866 char *name;
867 USE_SAFE_ALLOCA;
868 SAFE_ALLOCA (name, char *, SBYTES (cname));
878 memcpy (name, SDATA (cname), SBYTES (cname)); 869 memcpy (name, SDATA (cname), SBYTES (cname));
879 message_dolog (name, SBYTES (cname), 0, 0); 870 message_dolog (name, SBYTES (cname), 0, 0);
880 message_dolog (": ", 2, 0, 0); 871 message_dolog (": ", 2, 0, 0);
872 SAFE_FREE ();
881 } 873 }
882 874
883 errname = Fcar (data); 875 errname = Fcar (data);
@@ -1094,11 +1086,9 @@ print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1094 1086
1095 if (HASH_TABLE_P (Vprint_number_table)) 1087 if (HASH_TABLE_P (Vprint_number_table))
1096 { /* Remove unnecessary objects, which appear only once in OBJ; 1088 { /* Remove unnecessary objects, which appear only once in OBJ;
1097 that is, whose status is Qt. 1089 that is, whose status is Qt. */
1098 Maybe a better way to do that is to copy elements to
1099 a new hash table. */
1100 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table); 1090 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
1101 EMACS_INT i; 1091 ptrdiff_t i;
1102 1092
1103 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) 1093 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1104 if (!NILP (HASH_HASH (h, i)) 1094 if (!NILP (HASH_HASH (h, i))
@@ -1132,7 +1122,7 @@ static void
1132print_preprocess (Lisp_Object obj) 1122print_preprocess (Lisp_Object obj)
1133{ 1123{
1134 int i; 1124 int i;
1135 EMACS_INT size; 1125 ptrdiff_t size;
1136 int loop_count = 0; 1126 int loop_count = 0;
1137 Lisp_Object halftail; 1127 Lisp_Object halftail;
1138 1128
@@ -1275,8 +1265,8 @@ print_check_string_charset_prop (INTERVAL interval, Lisp_Object string)
1275 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) 1265 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1276 { 1266 {
1277 int i, c; 1267 int i, c;
1278 EMACS_INT charpos = interval->position; 1268 ptrdiff_t charpos = interval->position;
1279 EMACS_INT bytepos = string_char_to_byte (string, charpos); 1269 ptrdiff_t bytepos = string_char_to_byte (string, charpos);
1280 Lisp_Object charset; 1270 Lisp_Object charset;
1281 1271
1282 charset = XCAR (XCDR (val)); 1272 charset = XCAR (XCDR (val));
@@ -1396,10 +1386,10 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1396 print_string (obj, printcharfun); 1386 print_string (obj, printcharfun);
1397 else 1387 else
1398 { 1388 {
1399 register EMACS_INT i_byte; 1389 register ptrdiff_t i_byte;
1400 struct gcpro gcpro1; 1390 struct gcpro gcpro1;
1401 unsigned char *str; 1391 unsigned char *str;
1402 EMACS_INT size_byte; 1392 ptrdiff_t size_byte;
1403 /* 1 means we must ensure that the next character we output 1393 /* 1 means we must ensure that the next character we output
1404 cannot be taken as part of a hex character escape. */ 1394 cannot be taken as part of a hex character escape. */
1405 int need_nonhex = 0; 1395 int need_nonhex = 0;
@@ -1517,8 +1507,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1517 register unsigned char *p = SDATA (SYMBOL_NAME (obj)); 1507 register unsigned char *p = SDATA (SYMBOL_NAME (obj));
1518 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj)); 1508 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
1519 register int c; 1509 register int c;
1520 int i, i_byte; 1510 ptrdiff_t i, i_byte;
1521 EMACS_INT size_byte; 1511 ptrdiff_t size_byte;
1522 Lisp_Object name; 1512 Lisp_Object name;
1523 1513
1524 name = SYMBOL_NAME (obj); 1514 name = SYMBOL_NAME (obj);
@@ -1709,7 +1699,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1709 ptrdiff_t i; 1699 ptrdiff_t i;
1710 register unsigned char c; 1700 register unsigned char c;
1711 struct gcpro gcpro1; 1701 struct gcpro gcpro1;
1712 EMACS_INT size_in_chars 1702 ptrdiff_t size_in_chars
1713 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) 1703 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
1714 / BOOL_VECTOR_BITS_PER_CHAR); 1704 / BOOL_VECTOR_BITS_PER_CHAR);
1715 1705
@@ -1795,8 +1785,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1795 else if (HASH_TABLE_P (obj)) 1785 else if (HASH_TABLE_P (obj))
1796 { 1786 {
1797 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); 1787 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1798 int i; 1788 ptrdiff_t i;
1799 EMACS_INT real_size, size; 1789 ptrdiff_t real_size, size;
1800#if 0 1790#if 0
1801 strout ("#<hash-table", -1, -1, printcharfun); 1791 strout ("#<hash-table", -1, -1, printcharfun);
1802 if (SYMBOLP (h->test)) 1792 if (SYMBOLP (h->test))
@@ -1807,7 +1797,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1807 PRINTCHAR (' '); 1797 PRINTCHAR (' ');
1808 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun); 1798 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1809 PRINTCHAR (' '); 1799 PRINTCHAR (' ');
1810 sprintf (buf, "%"pI"d/%"pI"d", h->count, ASIZE (h->next)); 1800 sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
1811 strout (buf, -1, -1, printcharfun); 1801 strout (buf, -1, -1, printcharfun);
1812 } 1802 }
1813 sprintf (buf, " %p", h); 1803 sprintf (buf, " %p", h);
@@ -1817,7 +1807,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1817 /* Implement a readable output, e.g.: 1807 /* Implement a readable output, e.g.:
1818 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ 1808 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1819 /* Always print the size. */ 1809 /* Always print the size. */
1820 sprintf (buf, "#s(hash-table size %"pI"d", ASIZE (h->next)); 1810 sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next));
1821 strout (buf, -1, -1, printcharfun); 1811 strout (buf, -1, -1, printcharfun);
1822 1812
1823 if (!NILP (h->test)) 1813 if (!NILP (h->test))
@@ -1901,7 +1891,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1901 } 1891 }
1902 else if (FONTP (obj)) 1892 else if (FONTP (obj))
1903 { 1893 {
1904 EMACS_INT i; 1894 int i;
1905 1895
1906 if (! FONT_OBJECT_P (obj)) 1896 if (! FONT_OBJECT_P (obj))
1907 { 1897 {
@@ -1929,7 +1919,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1929 } 1919 }
1930 else 1920 else
1931 { 1921 {
1932 EMACS_INT size = ASIZE (obj); 1922 ptrdiff_t size = ASIZE (obj);
1933 if (COMPILEDP (obj)) 1923 if (COMPILEDP (obj))
1934 { 1924 {
1935 PRINTCHAR ('#'); 1925 PRINTCHAR ('#');
@@ -1960,7 +1950,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1960 { 1950 {
1961 register int i; 1951 register int i;
1962 register Lisp_Object tem; 1952 register Lisp_Object tem;
1963 EMACS_INT real_size = size; 1953 ptrdiff_t real_size = size;
1964 1954
1965 /* Don't print more elements than the specified maximum. */ 1955 /* Don't print more elements than the specified maximum. */
1966 if (NATNUMP (Vprint_length) 1956 if (NATNUMP (Vprint_length)
@@ -1992,7 +1982,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1992 strout ("in no buffer", -1, -1, printcharfun); 1982 strout ("in no buffer", -1, -1, printcharfun);
1993 else 1983 else
1994 { 1984 {
1995 sprintf (buf, "at %"pI"d", marker_position (obj)); 1985 sprintf (buf, "at %"pD"d", marker_position (obj));
1996 strout (buf, -1, -1, printcharfun); 1986 strout (buf, -1, -1, printcharfun);
1997 strout (" in ", -1, -1, printcharfun); 1987 strout (" in ", -1, -1, printcharfun);
1998 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun); 1988 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
@@ -2006,7 +1996,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2006 strout ("in no buffer", -1, -1, printcharfun); 1996 strout ("in no buffer", -1, -1, printcharfun);
2007 else 1997 else
2008 { 1998 {
2009 sprintf (buf, "from %"pI"d to %"pI"d in ", 1999 sprintf (buf, "from %"pD"d to %"pD"d in ",
2010 marker_position (OVERLAY_START (obj)), 2000 marker_position (OVERLAY_START (obj)),
2011 marker_position (OVERLAY_END (obj))); 2001 marker_position (OVERLAY_END (obj)));
2012 strout (buf, -1, -1, printcharfun); 2002 strout (buf, -1, -1, printcharfun);
@@ -2045,7 +2035,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2045 if (MISCP (obj)) 2035 if (MISCP (obj))
2046 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2036 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2047 else if (VECTORLIKEP (obj)) 2037 else if (VECTORLIKEP (obj))
2048 sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj)); 2038 sprintf (buf, "(PVEC 0x%08"pD"x)", ASIZE (obj));
2049 else 2039 else
2050 sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2040 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2051 strout (buf, -1, -1, printcharfun); 2041 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 e854dc585e8..bee82d1e783 100644
--- a/src/puresize.h
+++ b/src/puresize.h
@@ -45,9 +45,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
45 45
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 BITS_PER_EMACS_INT > 32 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 4bb2f240438..19d15664eec 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -31,9 +31,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31 31
32#include <unistd.h> 32#include <unistd.h>
33 33
34typedef POINTER_TYPE *POINTER;
35typedef size_t SIZE;
36
37#ifdef DOUG_LEA_MALLOC 34#ifdef DOUG_LEA_MALLOC
38#define M_TOP_PAD -2 35#define M_TOP_PAD -2
39extern int mallopt (int, int); 36extern int mallopt (int, int);
@@ -47,9 +44,6 @@ extern size_t __malloc_extra_blocks;
47 44
48#include <stddef.h> 45#include <stddef.h>
49 46
50typedef size_t SIZE;
51typedef void *POINTER;
52
53#include <unistd.h> 47#include <unistd.h>
54#include <malloc.h> 48#include <malloc.h>
55 49
@@ -58,6 +52,8 @@ typedef void *POINTER;
58 52
59#include "getpagesize.h" 53#include "getpagesize.h"
60 54
55typedef size_t SIZE;
56typedef void *POINTER;
61#define NIL ((POINTER) 0) 57#define NIL ((POINTER) 0)
62 58
63/* A flag to indicate whether we have initialized ralloc yet. For 59/* A flag to indicate whether we have initialized ralloc yet. For
@@ -1143,6 +1139,17 @@ r_alloc_reset_variable (POINTER *old, POINTER *new)
1143 bloc->variable = new; 1139 bloc->variable = new;
1144} 1140}
1145 1141
1142void
1143r_alloc_inhibit_buffer_relocation (int inhibit)
1144{
1145 if (use_relocatable_buffers < 0)
1146 use_relocatable_buffers = 0;
1147 if (inhibit)
1148 use_relocatable_buffers++;
1149 else if (use_relocatable_buffers > 0)
1150 use_relocatable_buffers--;
1151}
1152
1146 1153
1147/*********************************************************************** 1154/***********************************************************************
1148 Initialization 1155 Initialization
diff --git a/src/regex.c b/src/regex.c
index d16a5148054..f9a12a3c2dc 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -434,17 +434,7 @@ init_syntax_once (void)
434 434
435#endif /* not emacs */ 435#endif /* not emacs */
436 436
437/* We remove any previous definition of `SIGN_EXTEND_CHAR', 437#define SIGN_EXTEND_CHAR(c) ((signed char) (c))
438 since ours (we hope) works properly with all combinations of
439 machines, compilers, `char' and `unsigned char' argument types.
440 (Per Bothner suggested the basic approach.) */
441#undef SIGN_EXTEND_CHAR
442#if __STDC__
443# define SIGN_EXTEND_CHAR(c) ((signed char) (c))
444#else /* not __STDC__ */
445/* As in Harbison and Steele. */
446# define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
447#endif
448 438
449/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we 439/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
450 use `alloca' instead of `malloc'. This is because using malloc in 440 use `alloca' instead of `malloc'. This is because using malloc in
@@ -553,12 +543,12 @@ typedef char boolean;
553#define false 0 543#define false 0
554#define true 1 544#define true 1
555 545
556static regoff_t re_match_2_internal _RE_ARGS ((struct re_pattern_buffer *bufp, 546static regoff_t re_match_2_internal (struct re_pattern_buffer *bufp,
557 re_char *string1, size_t size1, 547 re_char *string1, size_t size1,
558 re_char *string2, size_t size2, 548 re_char *string2, size_t size2,
559 ssize_t pos, 549 ssize_t pos,
560 struct re_registers *regs, 550 struct re_registers *regs,
561 ssize_t stop)); 551 ssize_t stop);
562 552
563/* These are the command codes that appear in compiled regular 553/* These are the command codes that appear in compiled regular
564 expressions. Some opcodes are followed by argument bytes. A 554 expressions. Some opcodes are followed by argument bytes. A
@@ -735,11 +725,8 @@ typedef enum
735 } while (0) 725 } while (0)
736 726
737#ifdef DEBUG 727#ifdef DEBUG
738static void extract_number _RE_ARGS ((int *dest, re_char *source));
739static void 728static void
740extract_number (dest, source) 729extract_number (int *dest, re_char *source)
741 int *dest;
742 re_char *source;
743{ 730{
744 int temp = SIGN_EXTEND_CHAR (*(source + 1)); 731 int temp = SIGN_EXTEND_CHAR (*(source + 1));
745 *dest = *source & 0377; 732 *dest = *source & 0377;
@@ -763,12 +750,8 @@ extract_number (dest, source)
763 } while (0) 750 } while (0)
764 751
765#ifdef DEBUG 752#ifdef DEBUG
766static void extract_number_and_incr _RE_ARGS ((int *destination,
767 re_char **source));
768static void 753static void
769extract_number_and_incr (destination, source) 754extract_number_and_incr (int *destination, re_char **source)
770 int *destination;
771 re_char **source;
772{ 755{
773 extract_number (destination, *source); 756 extract_number (destination, *source);
774 *source += 2; 757 *source += 2;
@@ -1672,25 +1655,22 @@ do { \
1672 1655
1673/* Subroutine declarations and macros for regex_compile. */ 1656/* Subroutine declarations and macros for regex_compile. */
1674 1657
1675static reg_errcode_t regex_compile _RE_ARGS ((re_char *pattern, size_t size, 1658static reg_errcode_t regex_compile (re_char *pattern, size_t size,
1676 reg_syntax_t syntax, 1659 reg_syntax_t syntax,
1677 struct re_pattern_buffer *bufp)); 1660 struct re_pattern_buffer *bufp);
1678static void store_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, int arg)); 1661static void store_op1 (re_opcode_t op, unsigned char *loc, int arg);
1679static void store_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, 1662static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2);
1680 int arg1, int arg2)); 1663static void insert_op1 (re_opcode_t op, unsigned char *loc,
1681static void insert_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, 1664 int arg, unsigned char *end);
1682 int arg, unsigned char *end)); 1665static void insert_op2 (re_opcode_t op, unsigned char *loc,
1683static void insert_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, 1666 int arg1, int arg2, unsigned char *end);
1684 int arg1, int arg2, unsigned char *end)); 1667static boolean at_begline_loc_p (re_char *pattern, re_char *p,
1685static boolean at_begline_loc_p _RE_ARGS ((re_char *pattern, 1668 reg_syntax_t syntax);
1686 re_char *p, 1669static boolean at_endline_loc_p (re_char *p, re_char *pend,
1687 reg_syntax_t syntax)); 1670 reg_syntax_t syntax);
1688static boolean at_endline_loc_p _RE_ARGS ((re_char *p, 1671static re_char *skip_one_char (re_char *p);
1689 re_char *pend, 1672static int analyse_first (re_char *p, re_char *pend,
1690 reg_syntax_t syntax)); 1673 char *fastmap, const int multibyte);
1691static re_char *skip_one_char _RE_ARGS ((re_char *p));
1692static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,
1693 char *fastmap, const int multibyte));
1694 1674
1695/* Fetch the next character in the uncompiled pattern, with no 1675/* Fetch the next character in the uncompiled pattern, with no
1696 translation. */ 1676 translation. */
@@ -2442,9 +2422,8 @@ regex_grow_registers (int num_regs)
2442 2422
2443#endif /* not MATCH_MAY_ALLOCATE */ 2423#endif /* not MATCH_MAY_ALLOCATE */
2444 2424
2445static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type 2425static boolean group_in_compile_stack (compile_stack_type compile_stack,
2446 compile_stack, 2426 regnum_t regnum);
2447 regnum_t regnum));
2448 2427
2449/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. 2428/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
2450 Returns one of error codes defined in `regex.h', or zero for success. 2429 Returns one of error codes defined in `regex.h', or zero for success.
@@ -4554,10 +4533,10 @@ WEAK_ALIAS (__re_search_2, re_search_2)
4554 4533
4555/* Declarations and macros for re_match_2. */ 4534/* Declarations and macros for re_match_2. */
4556 4535
4557static int bcmp_translate _RE_ARGS ((re_char *s1, re_char *s2, 4536static int bcmp_translate (re_char *s1, re_char *s2,
4558 register ssize_t len, 4537 register ssize_t len,
4559 RE_TRANSLATE_TYPE translate, 4538 RE_TRANSLATE_TYPE translate,
4560 const int multibyte)); 4539 const int multibyte);
4561 4540
4562/* This converts PTR, a pointer into one of the search strings `string1' 4541/* This converts PTR, a pointer into one of the search strings `string1'
4563 and `string2' into an offset from the beginning of that string. */ 4542 and `string2' into an offset from the beginning of that string. */
diff --git a/src/regex.h b/src/regex.h
index 643d0b7b5ab..e0ede012b20 100644
--- a/src/regex.h
+++ b/src/regex.h
@@ -451,38 +451,21 @@ typedef struct
451 451
452/* Declarations for routines. */ 452/* Declarations for routines. */
453 453
454/* To avoid duplicating every routine declaration -- once with a
455 prototype (if we are ANSI), and once without (if we aren't) -- we
456 use the following macro to declare argument types. This
457 unfortunately clutters up the declarations a bit, but I think it's
458 worth it. */
459
460#if defined __STDC__ || defined PROTOTYPES
461
462# define _RE_ARGS(args) args
463
464#else /* not __STDC__ || PROTOTYPES */
465
466# define _RE_ARGS(args) ()
467
468#endif /* not __STDC__ || PROTOTYPES */
469
470/* Sets the current default syntax to SYNTAX, and return the old syntax. 454/* Sets the current default syntax to SYNTAX, and return the old syntax.
471 You can also simply assign to the `re_syntax_options' variable. */ 455 You can also simply assign to the `re_syntax_options' variable. */
472extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); 456extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
473 457
474/* Compile the regular expression PATTERN, with length LENGTH 458/* Compile the regular expression PATTERN, with length LENGTH
475 and syntax given by the global `re_syntax_options', into the buffer 459 and syntax given by the global `re_syntax_options', into the buffer
476 BUFFER. Return NULL if successful, and an error string if not. */ 460 BUFFER. Return NULL if successful, and an error string if not. */
477extern const char *re_compile_pattern 461extern const char *re_compile_pattern (const char *__pattern, size_t __length,
478 _RE_ARGS ((const char *pattern, size_t length, 462 struct re_pattern_buffer *__buffer);
479 struct re_pattern_buffer *buffer));
480 463
481 464
482/* Compile a fastmap for the compiled pattern in BUFFER; used to 465/* Compile a fastmap for the compiled pattern in BUFFER; used to
483 accelerate searches. Return 0 if successful and -2 if was an 466 accelerate searches. Return 0 if successful and -2 if was an
484 internal error. */ 467 internal error. */
485extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); 468extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
486 469
487 470
488/* Search in the string STRING (with length LENGTH) for the pattern 471/* Search in the string STRING (with length LENGTH) for the pattern
@@ -490,33 +473,35 @@ extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
490 characters. Return the starting position of the match, -1 for no 473 characters. Return the starting position of the match, -1 for no
491 match, or -2 for an internal error. Also return register 474 match, or -2 for an internal error. Also return register
492 information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 475 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
493extern regoff_t re_search 476extern regoff_t re_search (struct re_pattern_buffer *__buffer,
494 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, 477 const char *__string, size_t __length,
495 size_t length, ssize_t start, ssize_t range, 478 ssize_t __start, ssize_t __range,
496 struct re_registers *regs)); 479 struct re_registers *__regs);
497 480
498 481
499/* Like `re_search', but search in the concatenation of STRING1 and 482/* Like `re_search', but search in the concatenation of STRING1 and
500 STRING2. Also, stop searching at index START + STOP. */ 483 STRING2. Also, stop searching at index START + STOP. */
501extern regoff_t re_search_2 484extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
502 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, 485 const char *__string1, size_t __length1,
503 size_t length1, const char *string2, size_t length2, 486 const char *__string2, size_t __length2,
504 ssize_t start, ssize_t range, struct re_registers *regs, 487 ssize_t __start, ssize_t __range,
505 ssize_t stop)); 488 struct re_registers *__regs,
489 ssize_t __stop);
506 490
507 491
508/* Like `re_search', but return how many characters in STRING the regexp 492/* Like `re_search', but return how many characters in STRING the regexp
509 in BUFFER matched, starting at position START. */ 493 in BUFFER matched, starting at position START. */
510extern regoff_t re_match 494extern regoff_t re_match (struct re_pattern_buffer *__buffer,
511 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, 495 const char *__string, size_t __length,
512 size_t length, ssize_t start, struct re_registers *regs)); 496 ssize_t __start, struct re_registers *__regs);
513 497
514 498
515/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 499/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
516extern regoff_t re_match_2 500extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
517 _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, 501 const char *__string1, size_t __length1,
518 size_t length1, const char *string2, size_t length2, 502 const char *__string2, size_t __length2,
519 ssize_t start, struct re_registers *regs, ssize_t stop)); 503 ssize_t __start, struct re_registers *__regs,
504 ssize_t __stop);
520 505
521 506
522/* Set REGS to hold NUM_REGS registers, storing them in STARTS and 507/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
@@ -531,15 +516,16 @@ extern regoff_t re_match_2
531 Unless this function is called, the first search or match using 516 Unless this function is called, the first search or match using
532 PATTERN_BUFFER will allocate its own register data, without 517 PATTERN_BUFFER will allocate its own register data, without
533 freeing the old data. */ 518 freeing the old data. */
534extern void re_set_registers 519extern void re_set_registers (struct re_pattern_buffer *__buffer,
535 _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, 520 struct re_registers *__regs,
536 unsigned num_regs, regoff_t *starts, regoff_t *ends)); 521 unsigned __num_regs,
522 regoff_t *__starts, regoff_t *__ends);
537 523
538#if defined _REGEX_RE_COMP || defined _LIBC 524#if defined _REGEX_RE_COMP || defined _LIBC
539# ifndef _CRAY 525# ifndef _CRAY
540/* 4.2 bsd compatibility. */ 526/* 4.2 bsd compatibility. */
541extern char *re_comp _RE_ARGS ((const char *)); 527extern char *re_comp (const char *);
542extern int re_exec _RE_ARGS ((const char *)); 528extern int re_exec (const char *);
543# endif 529# endif
544#endif 530#endif
545 531
@@ -562,20 +548,19 @@ extern int re_exec _RE_ARGS ((const char *));
562#endif 548#endif
563 549
564/* POSIX compatibility. */ 550/* POSIX compatibility. */
565extern reg_errcode_t regcomp _RE_ARGS ((regex_t *__restrict __preg, 551extern reg_errcode_t regcomp (regex_t *__restrict __preg,
566 const char *__restrict __pattern, 552 const char *__restrict __pattern,
567 int __cflags)); 553 int __cflags);
568 554
569extern reg_errcode_t regexec _RE_ARGS ((const regex_t *__restrict __preg, 555extern reg_errcode_t regexec (const regex_t *__restrict __preg,
570 const char *__restrict __string, 556 const char *__restrict __string, size_t __nmatch,
571 size_t __nmatch, 557 regmatch_t __pmatch[__restrict_arr],
572 regmatch_t __pmatch[__restrict_arr], 558 int __eflags);
573 int __eflags));
574 559
575extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg, 560extern size_t regerror (int __errcode, const regex_t * __preg,
576 char *__errbuf, size_t __errbuf_size)); 561 char *__errbuf, size_t __errbuf_size);
577 562
578extern void regfree _RE_ARGS ((regex_t *__preg)); 563extern void regfree (regex_t *__preg);
579 564
580 565
581#ifdef __cplusplus 566#ifdef __cplusplus
diff --git a/src/s/aix4-2.h b/src/s/aix4-2.h
index 354ffda0988..cacfdc7ed63 100644
--- a/src/s/aix4-2.h
+++ b/src/s/aix4-2.h
@@ -76,6 +76,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
76 to avoid a crash just use the Emacs implementation for that function. */ 76 to avoid a crash just use the Emacs implementation for that function. */
77#define BROKEN_GET_CURRENT_DIR_NAME 1 77#define BROKEN_GET_CURRENT_DIR_NAME 1
78 78
79/*** BUILD 9008 - FIONREAD problem still exists in X-Windows. ***/
80#define BROKEN_FIONREAD
81/* As we define BROKEN_FIONREAD, SIGIO will be undefined in systty.h.
82 But, on AIX, SIGAIO, SIGPTY, and SIGPOLL are defined as SIGIO,
83 which causes compilation error at init_signals in sysdep.c. So, we
84 define these macros so that syssignal.h detects them and undefine
85 SIGAIO, SIGPTY and SIGPOLL. */
86#define BROKEN_SIGAIO
87#define BROKEN_SIGPTY
88#define BROKEN_SIGPOLL
89
79/* Conservative garbage collection has not been tested, so for now 90/* Conservative garbage collection has not been tested, so for now
80 play it safe and stick with the old-fashioned way of marking. */ 91 play it safe and stick with the old-fashioned way of marking. */
81#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE 92#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE
diff --git a/src/s/gnu-linux.h b/src/s/gnu-linux.h
index d04ea33068a..409d0205520 100644
--- a/src/s/gnu-linux.h
+++ b/src/s/gnu-linux.h
@@ -157,3 +157,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
157#else 157#else
158#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE 158#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE
159#endif 159#endif
160
161#ifdef __i386__
162/* libc-linux/sysdeps/linux/i386/ulimit.c says that due to shared library, */
163/* we cannot get the maximum address for brk */
164# define ULIMIT_BREAK_VALUE (32*1024*1024)
165#endif
diff --git a/src/s/gnu.h b/src/s/gnu.h
index a09e0e824c9..cd72164a520 100644
--- a/src/s/gnu.h
+++ b/src/s/gnu.h
@@ -24,8 +24,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24#undef SYSTEM_TYPE 24#undef SYSTEM_TYPE
25#define SYSTEM_TYPE "gnu" 25#define SYSTEM_TYPE "gnu"
26 26
27#undef NLIST_STRUCT
28
29#define SIGNALS_VIA_CHARACTERS 27#define SIGNALS_VIA_CHARACTERS
30 28
31/* libc defines data_start. */ 29/* libc defines data_start. */
diff --git a/src/s/hpux10-20.h b/src/s/hpux10-20.h
index 3e25b1bd0d9..f1ae50c533a 100644
--- a/src/s/hpux10-20.h
+++ b/src/s/hpux10-20.h
@@ -95,12 +95,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
95#define HAVE_XRMSETDATABASE 95#define HAVE_XRMSETDATABASE
96#endif 96#endif
97 97
98/* 2000-11-21: Temporarily disable Unix 98 large file support found by
99 configure. It fails on HPUX 11, at least, because it enables
100 header sections which lose when `static' is defined away, as it is
101 on HP-UX. (You get duplicate symbol errors on linking). */
102#undef _FILE_OFFSET_BITS
103
104/* Conservative garbage collection has not been tested, so for now 98/* Conservative garbage collection has not been tested, so for now
105 play it safe and stick with the old-fashioned way of marking. */ 99 play it safe and stick with the old-fashioned way of marking. */
106#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE 100#define GC_MARK_STACK GC_USE_GCPROS_AS_BEFORE
diff --git a/src/s/irix6-5.h b/src/s/irix6-5.h
index e5d90c1bd5d..e5479c3b8d3 100644
--- a/src/s/irix6-5.h
+++ b/src/s/irix6-5.h
@@ -85,10 +85,6 @@ char *_getpty();
85 85
86#define NARROWPROTO 1 86#define NARROWPROTO 1
87 87
88#if _MIPS_SZLONG == 64 /* -mabi=64 (gcc) or -64 (MIPSpro) */
89#define _LP64 /* lisp.h takes care of the rest */
90#endif /* _MIPS_SZLONG */
91
92#undef SA_RESTART 88#undef SA_RESTART
93 89
94#undef TIOCSIGSEND /* defined in usg5-4-common.h */ 90#undef TIOCSIGSEND /* defined in usg5-4-common.h */
diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h
index 815ab9101f4..f88128b27aa 100644
--- a/src/s/ms-w32.h
+++ b/src/s/ms-w32.h
@@ -122,7 +122,6 @@ struct sigaction {
122 122
123#define HAVE_GETTIMEOFDAY 1 123#define HAVE_GETTIMEOFDAY 1
124#define HAVE_GETHOSTNAME 1 124#define HAVE_GETHOSTNAME 1
125#undef HAVE_GETDOMAINNAME
126#define HAVE_DUP2 1 125#define HAVE_DUP2 1
127#define HAVE_RENAME 1 126#define HAVE_RENAME 1
128#define HAVE_CLOSEDIR 1 127#define HAVE_CLOSEDIR 1
@@ -382,6 +381,8 @@ extern int getloadavg (double *, int);
382/* We need a little extra space, see ../../lisp/loadup.el. */ 381/* We need a little extra space, see ../../lisp/loadup.el. */
383#define SYSTEM_PURESIZE_EXTRA 50000 382#define SYSTEM_PURESIZE_EXTRA 50000
384 383
384#define DATA_START get_data_start ()
385
385/* For unexec to work on Alpha systems, we need to put Emacs' 386/* For unexec to work on Alpha systems, we need to put Emacs'
386 initialized data into a separate section from the CRT initialized 387 initialized data into a separate section from the CRT initialized
387 data (because the Alpha linker freely reorders data variables, even 388 data (because the Alpha linker freely reorders data variables, even
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..99519b839ef 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,7 +1158,8 @@ 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
1161 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, 1163 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
1162 pos_byte - BEGV_BYTE, lim_byte - pos_byte, 1164 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
1163 (NILP (Vinhibit_changing_match_data) 1165 (NILP (Vinhibit_changing_match_data)
@@ -1201,7 +1203,8 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1201 } 1203 }
1202 while (n > 0) 1204 while (n > 0)
1203 { 1205 {
1204 EMACS_INT val; 1206 ptrdiff_t val;
1207
1205 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, 1208 val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
1206 pos_byte - BEGV_BYTE, lim_byte - pos_byte, 1209 pos_byte - BEGV_BYTE, lim_byte - pos_byte,
1207 (NILP (Vinhibit_changing_match_data) 1210 (NILP (Vinhibit_changing_match_data)
@@ -1246,8 +1249,8 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1246 else /* non-RE case */ 1249 else /* non-RE case */
1247 { 1250 {
1248 unsigned char *raw_pattern, *pat; 1251 unsigned char *raw_pattern, *pat;
1249 EMACS_INT raw_pattern_size; 1252 ptrdiff_t raw_pattern_size;
1250 EMACS_INT raw_pattern_size_byte; 1253 ptrdiff_t raw_pattern_size_byte;
1251 unsigned char *patbuf; 1254 unsigned char *patbuf;
1252 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 1255 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
1253 unsigned char *base_pat; 1256 unsigned char *base_pat;
@@ -1441,15 +1444,15 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
1441 1444
1442static EMACS_INT 1445static EMACS_INT
1443simple_search (EMACS_INT n, unsigned char *pat, 1446simple_search (EMACS_INT n, unsigned char *pat,
1444 EMACS_INT len, EMACS_INT len_byte, Lisp_Object trt, 1447 ptrdiff_t len, ptrdiff_t len_byte, Lisp_Object trt,
1445 EMACS_INT pos, EMACS_INT pos_byte, 1448 ptrdiff_t pos, ptrdiff_t pos_byte,
1446 EMACS_INT lim, EMACS_INT lim_byte) 1449 ptrdiff_t lim, ptrdiff_t lim_byte)
1447{ 1450{
1448 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 1451 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
1449 int forward = n > 0; 1452 int forward = n > 0;
1450 /* Number of buffer bytes matched. Note that this may be different 1453 /* Number of buffer bytes matched. Note that this may be different
1451 from len_byte in a multibyte buffer. */ 1454 from len_byte in a multibyte buffer. */
1452 EMACS_INT match_byte; 1455 ptrdiff_t match_byte;
1453 1456
1454 if (lim > pos && multibyte) 1457 if (lim > pos && multibyte)
1455 while (n > 0) 1458 while (n > 0)
@@ -1457,9 +1460,9 @@ simple_search (EMACS_INT n, unsigned char *pat,
1457 while (1) 1460 while (1)
1458 { 1461 {
1459 /* Try matching at position POS. */ 1462 /* Try matching at position POS. */
1460 EMACS_INT this_pos = pos; 1463 ptrdiff_t this_pos = pos;
1461 EMACS_INT this_pos_byte = pos_byte; 1464 ptrdiff_t this_pos_byte = pos_byte;
1462 EMACS_INT this_len = len; 1465 ptrdiff_t this_len = len;
1463 unsigned char *p = pat; 1466 unsigned char *p = pat;
1464 if (pos + len > lim || pos_byte + len_byte > lim_byte) 1467 if (pos + len > lim || pos_byte + len_byte > lim_byte)
1465 goto stop; 1468 goto stop;
@@ -1503,8 +1506,8 @@ simple_search (EMACS_INT n, unsigned char *pat,
1503 while (1) 1506 while (1)
1504 { 1507 {
1505 /* Try matching at position POS. */ 1508 /* Try matching at position POS. */
1506 EMACS_INT this_pos = pos; 1509 ptrdiff_t this_pos = pos;
1507 EMACS_INT this_len = len; 1510 ptrdiff_t this_len = len;
1508 unsigned char *p = pat; 1511 unsigned char *p = pat;
1509 1512
1510 if (pos + len > lim) 1513 if (pos + len > lim)
@@ -1542,9 +1545,9 @@ simple_search (EMACS_INT n, unsigned char *pat,
1542 while (1) 1545 while (1)
1543 { 1546 {
1544 /* Try matching at position POS. */ 1547 /* Try matching at position POS. */
1545 EMACS_INT this_pos = pos; 1548 ptrdiff_t this_pos = pos;
1546 EMACS_INT this_pos_byte = pos_byte; 1549 ptrdiff_t this_pos_byte = pos_byte;
1547 EMACS_INT this_len = len; 1550 ptrdiff_t this_len = len;
1548 const unsigned char *p = pat + len_byte; 1551 const unsigned char *p = pat + len_byte;
1549 1552
1550 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte) 1553 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte)
@@ -1585,8 +1588,8 @@ simple_search (EMACS_INT n, unsigned char *pat,
1585 while (1) 1588 while (1)
1586 { 1589 {
1587 /* Try matching at position POS. */ 1590 /* Try matching at position POS. */
1588 EMACS_INT this_pos = pos - len; 1591 ptrdiff_t this_pos = pos - len;
1589 EMACS_INT this_len = len; 1592 ptrdiff_t this_len = len;
1590 unsigned char *p = pat; 1593 unsigned char *p = pat;
1591 1594
1592 if (this_pos < lim) 1595 if (this_pos < lim)
@@ -1650,18 +1653,18 @@ simple_search (EMACS_INT n, unsigned char *pat,
1650 1653
1651static EMACS_INT 1654static EMACS_INT
1652boyer_moore (EMACS_INT n, unsigned char *base_pat, 1655boyer_moore (EMACS_INT n, unsigned char *base_pat,
1653 EMACS_INT len_byte, 1656 ptrdiff_t len_byte,
1654 Lisp_Object trt, Lisp_Object inverse_trt, 1657 Lisp_Object trt, Lisp_Object inverse_trt,
1655 EMACS_INT pos_byte, EMACS_INT lim_byte, 1658 ptrdiff_t pos_byte, ptrdiff_t lim_byte,
1656 int char_base) 1659 int char_base)
1657{ 1660{
1658 int direction = ((n > 0) ? 1 : -1); 1661 int direction = ((n > 0) ? 1 : -1);
1659 register EMACS_INT dirlen; 1662 register ptrdiff_t dirlen;
1660 EMACS_INT limit; 1663 ptrdiff_t limit;
1661 int stride_for_teases = 0; 1664 int stride_for_teases = 0;
1662 int BM_tab[0400]; 1665 int BM_tab[0400];
1663 register unsigned char *cursor, *p_limit; 1666 register unsigned char *cursor, *p_limit;
1664 register EMACS_INT i; 1667 register ptrdiff_t i;
1665 register int j; 1668 register int j;
1666 unsigned char *pat, *pat_end; 1669 unsigned char *pat, *pat_end;
1667 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 1670 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -1813,7 +1816,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
1813 char if reverse) of pattern would align in a possible match. */ 1816 char if reverse) of pattern would align in a possible match. */
1814 while (n != 0) 1817 while (n != 0)
1815 { 1818 {
1816 EMACS_INT tail_end; 1819 ptrdiff_t tail_end;
1817 unsigned char *tail_end_ptr; 1820 unsigned char *tail_end_ptr;
1818 1821
1819 /* It's been reported that some (broken) compiler thinks that 1822 /* It's been reported that some (broken) compiler thinks that
@@ -1917,7 +1920,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
1917 cursor += dirlen - i - direction; /* fix cursor */ 1920 cursor += dirlen - i - direction; /* fix cursor */
1918 if (i + direction == 0) 1921 if (i + direction == 0)
1919 { 1922 {
1920 EMACS_INT position, start, end; 1923 ptrdiff_t position, start, end;
1921 1924
1922 cursor -= direction; 1925 cursor -= direction;
1923 1926
@@ -2009,7 +2012,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
2009 pos_byte += dirlen - i - direction; 2012 pos_byte += dirlen - i - direction;
2010 if (i + direction == 0) 2013 if (i + direction == 0)
2011 { 2014 {
2012 EMACS_INT position, start, end; 2015 ptrdiff_t position, start, end;
2013 pos_byte -= direction; 2016 pos_byte -= direction;
2014 2017
2015 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); 2018 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0);
@@ -2050,9 +2053,9 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
2050 Also clear out the match data for registers 1 and up. */ 2053 Also clear out the match data for registers 1 and up. */
2051 2054
2052static void 2055static void
2053set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes) 2056set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes)
2054{ 2057{
2055 int i; 2058 ptrdiff_t i;
2056 2059
2057 if (!NILP (Vinhibit_changing_match_data)) 2060 if (!NILP (Vinhibit_changing_match_data))
2058 return; 2061 return;
@@ -2245,14 +2248,14 @@ since only regular expressions have distinguished subexpressions. */)
2245 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp) 2248 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp)
2246{ 2249{
2247 enum { nochange, all_caps, cap_initial } case_action; 2250 enum { nochange, all_caps, cap_initial } case_action;
2248 register EMACS_INT pos, pos_byte; 2251 register ptrdiff_t pos, pos_byte;
2249 int some_multiletter_word; 2252 int some_multiletter_word;
2250 int some_lowercase; 2253 int some_lowercase;
2251 int some_uppercase; 2254 int some_uppercase;
2252 int some_nonuppercase_initial; 2255 int some_nonuppercase_initial;
2253 register int c, prevc; 2256 register int c, prevc;
2254 ptrdiff_t sub; 2257 ptrdiff_t sub;
2255 EMACS_INT opoint, newpoint; 2258 ptrdiff_t opoint, newpoint;
2256 2259
2257 CHECK_STRING (newtext); 2260 CHECK_STRING (newtext);
2258 2261
@@ -2295,7 +2298,7 @@ since only regular expressions have distinguished subexpressions. */)
2295 if (NILP (fixedcase)) 2298 if (NILP (fixedcase))
2296 { 2299 {
2297 /* Decide how to casify by examining the matched text. */ 2300 /* Decide how to casify by examining the matched text. */
2298 EMACS_INT last; 2301 ptrdiff_t last;
2299 2302
2300 pos = search_regs.start[sub]; 2303 pos = search_regs.start[sub];
2301 last = search_regs.end[sub]; 2304 last = search_regs.end[sub];
@@ -2382,19 +2385,19 @@ since only regular expressions have distinguished subexpressions. */)
2382 if desired. */ 2385 if desired. */
2383 if (NILP (literal)) 2386 if (NILP (literal))
2384 { 2387 {
2385 EMACS_INT lastpos = 0; 2388 ptrdiff_t lastpos = 0;
2386 EMACS_INT lastpos_byte = 0; 2389 ptrdiff_t lastpos_byte = 0;
2387 /* We build up the substituted string in ACCUM. */ 2390 /* We build up the substituted string in ACCUM. */
2388 Lisp_Object accum; 2391 Lisp_Object accum;
2389 Lisp_Object middle; 2392 Lisp_Object middle;
2390 EMACS_INT length = SBYTES (newtext); 2393 ptrdiff_t length = SBYTES (newtext);
2391 2394
2392 accum = Qnil; 2395 accum = Qnil;
2393 2396
2394 for (pos_byte = 0, pos = 0; pos_byte < length;) 2397 for (pos_byte = 0, pos = 0; pos_byte < length;)
2395 { 2398 {
2396 EMACS_INT substart = -1; 2399 ptrdiff_t substart = -1;
2397 EMACS_INT subend = 0; 2400 ptrdiff_t subend = 0;
2398 int delbackslash = 0; 2401 int delbackslash = 0;
2399 2402
2400 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); 2403 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
@@ -2410,8 +2413,8 @@ since only regular expressions have distinguished subexpressions. */)
2410 } 2413 }
2411 else if (c >= '1' && c <= '9') 2414 else if (c >= '1' && c <= '9')
2412 { 2415 {
2413 if (search_regs.start[c - '0'] >= 0 2416 if (c - '0' < search_regs.num_regs
2414 && c <= search_regs.num_regs + '0') 2417 && 0 <= search_regs.start[c - '0'])
2415 { 2418 {
2416 substart = search_regs.start[c - '0']; 2419 substart = search_regs.start[c - '0'];
2417 subend = search_regs.end[c - '0']; 2420 subend = search_regs.end[c - '0'];
@@ -2549,7 +2552,7 @@ since only regular expressions have distinguished subexpressions. */)
2549 2552
2550 if (c == '&') 2553 if (c == '&')
2551 idx = sub; 2554 idx = sub;
2552 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') 2555 else if (c >= '1' && c <= '9' && c - '0' < search_regs.num_regs)
2553 { 2556 {
2554 if (search_regs.start[c - '0'] >= 1) 2557 if (search_regs.start[c - '0'] >= 1)
2555 idx = c - '0'; 2558 idx = c - '0';
@@ -2601,7 +2604,7 @@ since only regular expressions have distinguished subexpressions. */)
2601 { 2604 {
2602 if (buf_multibyte) 2605 if (buf_multibyte)
2603 { 2606 {
2604 EMACS_INT nchars = 2607 ptrdiff_t nchars =
2605 multibyte_chars_in_text (substed, substed_len); 2608 multibyte_chars_in_text (substed, substed_len);
2606 2609
2607 newtext = make_multibyte_string ((char *) substed, nchars, 2610 newtext = make_multibyte_string ((char *) substed, nchars,
@@ -2627,10 +2630,10 @@ since only regular expressions have distinguished subexpressions. */)
2627 2630
2628 /* Adjust search data for this change. */ 2631 /* Adjust search data for this change. */
2629 { 2632 {
2630 EMACS_INT oldend = search_regs.end[sub]; 2633 ptrdiff_t oldend = search_regs.end[sub];
2631 EMACS_INT oldstart = search_regs.start[sub]; 2634 ptrdiff_t oldstart = search_regs.start[sub];
2632 EMACS_INT change = newpoint - search_regs.end[sub]; 2635 ptrdiff_t change = newpoint - search_regs.end[sub];
2633 int i; 2636 ptrdiff_t i;
2634 2637
2635 for (i = 0; i < search_regs.num_regs; i++) 2638 for (i = 0; i < search_regs.num_regs; i++)
2636 { 2639 {
@@ -2723,7 +2726,7 @@ Return value is undefined if the last search failed. */)
2723{ 2726{
2724 Lisp_Object tail, prev; 2727 Lisp_Object tail, prev;
2725 Lisp_Object *data; 2728 Lisp_Object *data;
2726 int i, len; 2729 ptrdiff_t i, len;
2727 2730
2728 if (!NILP (reseat)) 2731 if (!NILP (reseat))
2729 for (tail = reuse; CONSP (tail); tail = XCDR (tail)) 2732 for (tail = reuse; CONSP (tail); tail = XCDR (tail))
@@ -2744,7 +2747,7 @@ Return value is undefined if the last search failed. */)
2744 len = 0; 2747 len = 0;
2745 for (i = 0; i < search_regs.num_regs; i++) 2748 for (i = 0; i < search_regs.num_regs; i++)
2746 { 2749 {
2747 EMACS_INT start = search_regs.start[i]; 2750 ptrdiff_t start = search_regs.start[i];
2748 if (start >= 0) 2751 if (start >= 0)
2749 { 2752 {
2750 if (EQ (last_thing_searched, Qt) 2753 if (EQ (last_thing_searched, Qt)
@@ -2835,11 +2838,13 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2835 2838
2836 /* Allocate registers if they don't already exist. */ 2839 /* Allocate registers if they don't already exist. */
2837 { 2840 {
2838 ptrdiff_t length = XFASTINT (Flength (list)) / 2; 2841 EMACS_INT length = XFASTINT (Flength (list)) / 2;
2839 2842
2840 if (length > search_regs.num_regs) 2843 if (length > search_regs.num_regs)
2841 { 2844 {
2842 ptrdiff_t num_regs = search_regs.num_regs; 2845 ptrdiff_t num_regs = search_regs.num_regs;
2846 if (PTRDIFF_MAX < length)
2847 memory_full (SIZE_MAX);
2843 search_regs.start = 2848 search_regs.start =
2844 xpalloc (search_regs.start, &num_regs, length - num_regs, 2849 xpalloc (search_regs.start, &num_regs, length - num_regs,
2845 min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); 2850 min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t));
@@ -2869,7 +2874,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2869 } 2874 }
2870 else 2875 else
2871 { 2876 {
2872 EMACS_INT from; 2877 Lisp_Object from;
2873 Lisp_Object m; 2878 Lisp_Object m;
2874 2879
2875 m = marker; 2880 m = marker;
@@ -2882,7 +2887,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2882 } 2887 }
2883 2888
2884 CHECK_NUMBER_COERCE_MARKER (marker); 2889 CHECK_NUMBER_COERCE_MARKER (marker);
2885 from = XINT (marker); 2890 from = marker;
2886 2891
2887 if (!NILP (reseat) && MARKERP (m)) 2892 if (!NILP (reseat) && MARKERP (m))
2888 { 2893 {
@@ -2899,8 +2904,20 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2899 XSETFASTINT (marker, 0); 2904 XSETFASTINT (marker, 0);
2900 2905
2901 CHECK_NUMBER_COERCE_MARKER (marker); 2906 CHECK_NUMBER_COERCE_MARKER (marker);
2902 search_regs.start[i] = from; 2907 if ((XINT (from) < 0
2903 search_regs.end[i] = XINT (marker); 2908 ? TYPE_MINIMUM (regoff_t) <= XINT (from)
2909 : XINT (from) <= TYPE_MAXIMUM (regoff_t))
2910 && (XINT (marker) < 0
2911 ? TYPE_MINIMUM (regoff_t) <= XINT (marker)
2912 : XINT (marker) <= TYPE_MAXIMUM (regoff_t)))
2913 {
2914 search_regs.start[i] = XINT (from);
2915 search_regs.end[i] = XINT (marker);
2916 }
2917 else
2918 {
2919 search_regs.start[i] = -1;
2920 }
2904 2921
2905 if (!NILP (reseat) && MARKERP (m)) 2922 if (!NILP (reseat) && MARKERP (m))
2906 { 2923 {
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 81529fc7d9b..3356582de0c 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -52,9 +52,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
52#define read sys_read 52#define read sys_read
53#define write sys_write 53#define write sys_write
54#include <windows.h> 54#include <windows.h>
55#ifndef NULL
56#define NULL 0
57#endif
58#endif /* not WINDOWSNT */ 55#endif /* not WINDOWSNT */
59 56
60#include <sys/types.h> 57#include <sys/types.h>
@@ -307,7 +304,7 @@ int wait_debugging EXTERNALLY_VISIBLE;
307#ifndef MSDOS 304#ifndef MSDOS
308 305
309static void 306static void
310wait_for_termination_1 (int pid, int interruptible) 307wait_for_termination_1 (pid_t pid, int interruptible)
311{ 308{
312 while (1) 309 while (1)
313 { 310 {
@@ -355,14 +352,14 @@ wait_for_termination_1 (int pid, int interruptible)
355 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) */
356 353
357void 354void
358wait_for_termination (int pid) 355wait_for_termination (pid_t pid)
359{ 356{
360 wait_for_termination_1 (pid, 0); 357 wait_for_termination_1 (pid, 0);
361} 358}
362 359
363/* Like the above, but allow keyboard interruption. */ 360/* Like the above, but allow keyboard interruption. */
364void 361void
365interruptible_wait_for_termination (int pid) 362interruptible_wait_for_termination (pid_t pid)
366{ 363{
367 wait_for_termination_1 (pid, 1); 364 wait_for_termination_1 (pid, 1);
368} 365}
@@ -1913,8 +1910,8 @@ emacs_close (int fd)
1913/* 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.
1914 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.
1915 On error, set errno and return -1. */ 1912 On error, set errno and return -1. */
1916EMACS_INT 1913ptrdiff_t
1917emacs_read (int fildes, char *buf, EMACS_INT nbyte) 1914emacs_read (int fildes, char *buf, ptrdiff_t nbyte)
1918{ 1915{
1919 register ssize_t rtnval; 1916 register ssize_t rtnval;
1920 1917
@@ -1930,11 +1927,11 @@ emacs_read (int fildes, char *buf, EMACS_INT nbyte)
1930/* 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
1931 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
1932 errno if this is less than NBYTE. */ 1929 errno if this is less than NBYTE. */
1933EMACS_INT 1930ptrdiff_t
1934emacs_write (int fildes, const char *buf, EMACS_INT nbyte) 1931emacs_write (int fildes, const char *buf, ptrdiff_t nbyte)
1935{ 1932{
1936 ssize_t rtnval; 1933 ssize_t rtnval;
1937 EMACS_INT bytes_written; 1934 ptrdiff_t bytes_written;
1938 1935
1939 bytes_written = 0; 1936 bytes_written = 0;
1940 1937
@@ -2169,7 +2166,8 @@ set_file_times (const char *filename, EMACS_TIME atime, EMACS_TIME mtime)
2169int 2166int
2170mkdir (char *dpath, int dmode) 2167mkdir (char *dpath, int dmode)
2171{ 2168{
2172 int cpid, status, fd; 2169 pid_t cpid;
2170 int status, fd;
2173 struct stat statbuf; 2171 struct stat statbuf;
2174 2172
2175 if (stat (dpath, &statbuf) == 0) 2173 if (stat (dpath, &statbuf) == 0)
@@ -2743,7 +2741,10 @@ system_process_attributes (Lisp_Object pid)
2743 char *cmdline = NULL; 2741 char *cmdline = NULL;
2744 ptrdiff_t cmdsize = 0, cmdline_size; 2742 ptrdiff_t cmdsize = 0, cmdline_size;
2745 unsigned char c; 2743 unsigned char c;
2746 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;
2747 unsigned long long u_time, s_time, cutime, cstime, start; 2748 unsigned long long u_time, s_time, cutime, cstime, start;
2748 long priority, niceness, rss; 2749 long priority, niceness, rss;
2749 unsigned long minflt, majflt, cminflt, cmajflt, vsize; 2750 unsigned long minflt, majflt, cminflt, cmajflt, vsize;
@@ -2754,11 +2755,10 @@ system_process_attributes (Lisp_Object pid)
2754 Lisp_Object attrs = Qnil; 2755 Lisp_Object attrs = Qnil;
2755 Lisp_Object cmd_str, decoded_cmd, tem; 2756 Lisp_Object cmd_str, decoded_cmd, tem;
2756 struct gcpro gcpro1, gcpro2; 2757 struct gcpro gcpro1, gcpro2;
2757 EMACS_INT uid_eint, gid_eint;
2758 2758
2759 CHECK_NUMBER_OR_FLOAT (pid); 2759 CHECK_NUMBER_OR_FLOAT (pid);
2760 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 2760 CONS_TO_INTEGER (pid, pid_t, proc_id);
2761 sprintf (procfn, "/proc/%u", proc_id); 2761 sprintf (procfn, "/proc/%"pMd, proc_id);
2762 if (stat (procfn, &st) < 0) 2762 if (stat (procfn, &st) < 0)
2763 return attrs; 2763 return attrs;
2764 2764
@@ -2766,9 +2766,7 @@ system_process_attributes (Lisp_Object pid)
2766 2766
2767 /* euid egid */ 2767 /* euid egid */
2768 uid = st.st_uid; 2768 uid = st.st_uid;
2769 /* Use of EMACS_INT stops GCC whining about limited range of data type. */ 2769 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
2770 uid_eint = uid;
2771 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
2772 BLOCK_INPUT; 2770 BLOCK_INPUT;
2773 pw = getpwuid (uid); 2771 pw = getpwuid (uid);
2774 UNBLOCK_INPUT; 2772 UNBLOCK_INPUT;
@@ -2776,8 +2774,7 @@ system_process_attributes (Lisp_Object pid)
2776 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 2774 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
2777 2775
2778 gid = st.st_gid; 2776 gid = st.st_gid;
2779 gid_eint = gid; 2777 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
2780 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
2781 BLOCK_INPUT; 2778 BLOCK_INPUT;
2782 gr = getgrgid (gid); 2779 gr = getgrgid (gid);
2783 UNBLOCK_INPUT; 2780 UNBLOCK_INPUT;
@@ -3017,15 +3014,16 @@ system_process_attributes (Lisp_Object pid)
3017 struct psinfo pinfo; 3014 struct psinfo pinfo;
3018 int fd; 3015 int fd;
3019 ssize_t nread; 3016 ssize_t nread;
3020 int proc_id, uid, gid; 3017 printmax_t proc_id;
3018 uid_t uid;
3019 gid_t gid;
3021 Lisp_Object attrs = Qnil; 3020 Lisp_Object attrs = Qnil;
3022 Lisp_Object decoded_cmd, tem; 3021 Lisp_Object decoded_cmd, tem;
3023 struct gcpro gcpro1, gcpro2; 3022 struct gcpro gcpro1, gcpro2;
3024 EMACS_INT uid_eint, gid_eint;
3025 3023
3026 CHECK_NUMBER_OR_FLOAT (pid); 3024 CHECK_NUMBER_OR_FLOAT (pid);
3027 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 3025 CONS_TO_INTEGER (pid, pid_t, proc_id);
3028 sprintf (procfn, "/proc/%u", proc_id); 3026 sprintf (procfn, "/proc/%"pMd, proc_id);
3029 if (stat (procfn, &st) < 0) 3027 if (stat (procfn, &st) < 0)
3030 return attrs; 3028 return attrs;
3031 3029
@@ -3033,9 +3031,7 @@ system_process_attributes (Lisp_Object pid)
3033 3031
3034 /* euid egid */ 3032 /* euid egid */
3035 uid = st.st_uid; 3033 uid = st.st_uid;
3036 /* Use of EMACS_INT stops GCC whining about limited range of data type. */ 3034 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
3037 uid_eint = uid;
3038 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
3039 BLOCK_INPUT; 3035 BLOCK_INPUT;
3040 pw = getpwuid (uid); 3036 pw = getpwuid (uid);
3041 UNBLOCK_INPUT; 3037 UNBLOCK_INPUT;
@@ -3043,8 +3039,7 @@ system_process_attributes (Lisp_Object pid)
3043 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 3039 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
3044 3040
3045 gid = st.st_gid; 3041 gid = st.st_gid;
3046 gid_eint = gid; 3042 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
3047 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
3048 BLOCK_INPUT; 3043 BLOCK_INPUT;
3049 gr = getgrgid (gid); 3044 gr = getgrgid (gid);
3050 UNBLOCK_INPUT; 3045 UNBLOCK_INPUT;
@@ -3111,9 +3106,10 @@ system_process_attributes (Lisp_Object pid)
3111 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (pinfo.pr_size)), attrs); 3106 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (pinfo.pr_size)), attrs);
3112 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (pinfo.pr_rssize)), attrs); 3107 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (pinfo.pr_rssize)), attrs);
3113 3108
3114 /* pr_pctcpu and pr_pctmem are encoded as a fixed point 16 bit number in [0 ... 1]. */ 3109 /* pr_pctcpu and pr_pctmem are unsigned integers in the
3115 attrs = Fcons (Fcons (Qpcpu, (pinfo.pr_pctcpu * 100.0) / (double)0x8000), attrs); 3110 range 0 .. 2**15, representing 0.0 .. 1.0. */
3116 attrs = Fcons (Fcons (Qpmem, (pinfo.pr_pctmem * 100.0) / (double)0x8000), attrs); 3111 attrs = Fcons (Fcons (Qpcpu, make_float (100.0 / 0x8000 * pinfo.pr_pctcpu)), attrs);
3112 attrs = Fcons (Fcons (Qpmem, make_float (100.0 / 0x8000 * pinfo.pr_pctmem)), attrs);
3117 3113
3118 decoded_cmd 3114 decoded_cmd
3119 = code_convert_string_norecord (make_unibyte_string (pinfo.pr_fname, 3115 = code_convert_string_norecord (make_unibyte_string (pinfo.pr_fname,
@@ -3159,7 +3155,7 @@ system_process_attributes (Lisp_Object pid)
3159 Lisp_Object decoded_comm; 3155 Lisp_Object decoded_comm;
3160 3156
3161 CHECK_NUMBER_OR_FLOAT (pid); 3157 CHECK_NUMBER_OR_FLOAT (pid);
3162 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); 3158 CONS_TO_INTEGER (pid, int, proc_id);
3163 mib[3] = proc_id; 3159 mib[3] = proc_id;
3164 3160
3165 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0) 3161 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/termcap.c b/src/termcap.c
index 10c195eebe2..61f9d9a31ea 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -30,10 +30,6 @@ Boston, MA 02110-1301, USA. */
30#include "msdos.h" 30#include "msdos.h"
31#endif 31#endif
32 32
33#ifndef NULL
34#define NULL (char *) 0
35#endif
36
37/* BUFSIZE is the initial size allocated for the buffer 33/* BUFSIZE is the initial size allocated for the buffer
38 for reading the termcap file. 34 for reading the termcap file.
39 It is not a limit. 35 It is not a limit.
@@ -661,10 +657,6 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
661 657
662#ifdef TEST 658#ifdef TEST
663 659
664#ifdef NULL
665#undef NULL
666#endif
667
668#include <stdio.h> 660#include <stdio.h>
669 661
670static void 662static void
diff --git a/src/termhooks.h b/src/termhooks.h
index bc61a986cce..4cad4825cdd 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -229,7 +229,7 @@ struct input_event
229 For a HELP_EVENT, this is the position within the object 229 For a HELP_EVENT, this is the position within the object
230 (stored in ARG below) where the help was found. */ 230 (stored in ARG below) where the help was found. */
231 /* In WindowsNT, for a mouse wheel event, this is the delta. */ 231 /* In WindowsNT, for a mouse wheel event, this is the delta. */
232 EMACS_INT code; 232 ptrdiff_t code;
233 enum scroll_bar_part part; 233 enum scroll_bar_part part;
234 234
235 int modifiers; /* See enum below for interpretation. */ 235 int modifiers; /* See enum below for interpretation. */
diff --git a/src/textprop.c b/src/textprop.c
index 688b32eb4ec..83d07c56f28 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -23,10 +23,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include "buffer.h" 23#include "buffer.h"
24#include "window.h" 24#include "window.h"
25 25
26#ifndef NULL
27#define NULL (void *)0
28#endif
29
30/* Test for membership, allowing for t (actually any non-cons) to mean the 26/* Test for membership, allowing for t (actually any non-cons) to mean the
31 universal set. */ 27 universal set. */
32 28
@@ -124,7 +120,7 @@ INTERVAL
124validate_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)
125{ 121{
126 register INTERVAL i; 122 register INTERVAL i;
127 EMACS_INT searchpos; 123 ptrdiff_t searchpos;
128 124
129 CHECK_STRING_OR_BUFFER (object); 125 CHECK_STRING_OR_BUFFER (object);
130 CHECK_NUMBER_COERCE_MARKER (*begin); 126 CHECK_NUMBER_COERCE_MARKER (*begin);
@@ -160,7 +156,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *en
160 } 156 }
161 else 157 else
162 { 158 {
163 EMACS_INT len = SCHARS (object); 159 ptrdiff_t len = SCHARS (object);
164 160
165 if (! (0 <= XINT (*begin) && XINT (*begin) <= XINT (*end) 161 if (! (0 <= XINT (*begin) && XINT (*begin) <= XINT (*end)
166 && XINT (*end) <= len)) 162 && XINT (*end) <= len))
@@ -514,10 +510,10 @@ erase_properties (INTERVAL i)
514 POSITION is BEG-based. */ 510 POSITION is BEG-based. */
515 511
516INTERVAL 512INTERVAL
517interval_of (EMACS_INT position, Lisp_Object object) 513interval_of (ptrdiff_t position, Lisp_Object object)
518{ 514{
519 register INTERVAL i; 515 register INTERVAL i;
520 EMACS_INT beg, end; 516 ptrdiff_t beg, end;
521 517
522 if (NILP (object)) 518 if (NILP (object))
523 XSETBUFFER (object, current_buffer); 519 XSETBUFFER (object, current_buffer);
@@ -775,7 +771,7 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */)
775 else 771 else
776 { 772 {
777 Lisp_Object initial_value, value; 773 Lisp_Object initial_value, value;
778 int count = SPECPDL_INDEX (); 774 ptrdiff_t count = SPECPDL_INDEX ();
779 775
780 if (! NILP (object)) 776 if (! NILP (object))
781 CHECK_BUFFER (object); 777 CHECK_BUFFER (object);
@@ -858,7 +854,7 @@ position LIMIT; return LIMIT if nothing is found before reaching LIMIT. */)
858 } 854 }
859 else 855 else
860 { 856 {
861 int count = SPECPDL_INDEX (); 857 ptrdiff_t count = SPECPDL_INDEX ();
862 858
863 if (! NILP (object)) 859 if (! NILP (object))
864 CHECK_BUFFER (object); 860 CHECK_BUFFER (object);
@@ -1140,7 +1136,7 @@ Return t if any property value actually changed, nil otherwise. */)
1140 (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)
1141{ 1137{
1142 register INTERVAL i, unchanged; 1138 register INTERVAL i, unchanged;
1143 register EMACS_INT s, len; 1139 register ptrdiff_t s, len;
1144 register int modified = 0; 1140 register int modified = 0;
1145 struct gcpro gcpro1; 1141 struct gcpro gcpro1;
1146 1142
@@ -1170,7 +1166,7 @@ Return t if any property value actually changed, nil otherwise. */)
1170 skip it. */ 1166 skip it. */
1171 if (interval_has_all_properties (properties, i)) 1167 if (interval_has_all_properties (properties, i))
1172 { 1168 {
1173 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1169 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1174 if (got >= len) 1170 if (got >= len)
1175 RETURN_UNGCPRO (Qnil); 1171 RETURN_UNGCPRO (Qnil);
1176 len -= got; 1172 len -= got;
@@ -1345,7 +1341,7 @@ void
1345set_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)
1346{ 1342{
1347 register INTERVAL prev_changed = NULL_INTERVAL; 1343 register INTERVAL prev_changed = NULL_INTERVAL;
1348 register EMACS_INT s, len; 1344 register ptrdiff_t s, len;
1349 INTERVAL unchanged; 1345 INTERVAL unchanged;
1350 1346
1351 if (XINT (start) < XINT (end)) 1347 if (XINT (start) < XINT (end))
@@ -1438,7 +1434,7 @@ Use `set-text-properties' if you want to remove all text properties. */)
1438 (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)
1439{ 1435{
1440 register INTERVAL i, unchanged; 1436 register INTERVAL i, unchanged;
1441 register EMACS_INT s, len; 1437 register ptrdiff_t s, len;
1442 register int modified = 0; 1438 register int modified = 0;
1443 1439
1444 if (NILP (object)) 1440 if (NILP (object))
@@ -1457,7 +1453,7 @@ Use `set-text-properties' if you want to remove all text properties. */)
1457 it covers the entire region. */ 1453 it covers the entire region. */
1458 if (! interval_has_some_properties (properties, i)) 1454 if (! interval_has_some_properties (properties, i))
1459 { 1455 {
1460 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1456 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1461 if (got >= len) 1457 if (got >= len)
1462 return Qnil; 1458 return Qnil;
1463 len -= got; 1459 len -= got;
@@ -1524,7 +1520,7 @@ Return t if any property was actually removed, nil otherwise. */)
1524 (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)
1525{ 1521{
1526 register INTERVAL i, unchanged; 1522 register INTERVAL i, unchanged;
1527 register EMACS_INT s, len; 1523 register ptrdiff_t s, len;
1528 register int modified = 0; 1524 register int modified = 0;
1529 Lisp_Object properties; 1525 Lisp_Object properties;
1530 properties = list_of_properties; 1526 properties = list_of_properties;
@@ -1545,7 +1541,7 @@ Return t if any property was actually removed, nil otherwise. */)
1545 it covers the entire region. */ 1541 it covers the entire region. */
1546 if (! interval_has_some_properties_list (properties, i)) 1542 if (! interval_has_some_properties_list (properties, i))
1547 { 1543 {
1548 EMACS_INT got = (LENGTH (i) - (s - i->position)); 1544 ptrdiff_t got = (LENGTH (i) - (s - i->position));
1549 if (got >= len) 1545 if (got >= len)
1550 return Qnil; 1546 return Qnil;
1551 len -= got; 1547 len -= got;
@@ -1634,7 +1630,7 @@ markers). If OBJECT is a string, START and END are 0-based indices into it. */
1634 (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)
1635{ 1631{
1636 register INTERVAL i; 1632 register INTERVAL i;
1637 register EMACS_INT e, pos; 1633 register ptrdiff_t e, pos;
1638 1634
1639 if (NILP (object)) 1635 if (NILP (object))
1640 XSETBUFFER (object, current_buffer); 1636 XSETBUFFER (object, current_buffer);
@@ -1670,7 +1666,7 @@ markers). If OBJECT is a string, START and END are 0-based indices into it. */
1670 (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)
1671{ 1667{
1672 register INTERVAL i; 1668 register INTERVAL i;
1673 register EMACS_INT s, e; 1669 register ptrdiff_t s, e;
1674 1670
1675 if (NILP (object)) 1671 if (NILP (object))
1676 XSETBUFFER (object, current_buffer); 1672 XSETBUFFER (object, current_buffer);
@@ -1780,7 +1776,7 @@ copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src, Lisp_
1780 Lisp_Object res; 1776 Lisp_Object res;
1781 Lisp_Object stuff; 1777 Lisp_Object stuff;
1782 Lisp_Object plist; 1778 Lisp_Object plist;
1783 EMACS_INT s, e, e2, p, len; 1779 ptrdiff_t s, e, e2, p, len;
1784 int modified = 0; 1780 int modified = 0;
1785 struct gcpro gcpro1, gcpro2; 1781 struct gcpro gcpro1, gcpro2;
1786 1782
@@ -1792,8 +1788,11 @@ copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src, Lisp_
1792 { 1788 {
1793 Lisp_Object dest_start, dest_end; 1789 Lisp_Object dest_start, dest_end;
1794 1790
1791 e = XINT (pos) + (XINT (end) - XINT (start));
1792 if (MOST_POSITIVE_FIXNUM < e)
1793 args_out_of_range (pos, end);
1795 dest_start = pos; 1794 dest_start = pos;
1796 XSETFASTINT (dest_end, XINT (dest_start) + (XINT (end) - XINT (start))); 1795 XSETFASTINT (dest_end, e);
1797 /* 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,
1798 which we don't want. */ 1797 which we don't want. */
1799 validate_interval_range (dest, &dest_start, &dest_end, soft); 1798 validate_interval_range (dest, &dest_start, &dest_end, soft);
@@ -1877,12 +1876,12 @@ text_property_list (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp
1877 i = validate_interval_range (object, &start, &end, soft); 1876 i = validate_interval_range (object, &start, &end, soft);
1878 if (!NULL_INTERVAL_P (i)) 1877 if (!NULL_INTERVAL_P (i))
1879 { 1878 {
1880 EMACS_INT s = XINT (start); 1879 ptrdiff_t s = XINT (start);
1881 EMACS_INT e = XINT (end); 1880 ptrdiff_t e = XINT (end);
1882 1881
1883 while (s < e) 1882 while (s < e)
1884 { 1883 {
1885 EMACS_INT interval_end, len; 1884 ptrdiff_t interval_end, len;
1886 Lisp_Object plist; 1885 Lisp_Object plist;
1887 1886
1888 interval_end = i->position + LENGTH (i); 1887 interval_end = i->position + LENGTH (i);
@@ -1960,7 +1959,7 @@ Lisp_Object
1960extend_property_ranges (Lisp_Object list, Lisp_Object new_end) 1959extend_property_ranges (Lisp_Object list, Lisp_Object new_end)
1961{ 1960{
1962 Lisp_Object prev = Qnil, head = list; 1961 Lisp_Object prev = Qnil, head = list;
1963 EMACS_INT max = XINT (new_end); 1962 ptrdiff_t max = XINT (new_end);
1964 1963
1965 for (; CONSP (list); prev = list, list = XCDR (list)) 1964 for (; CONSP (list); prev = list, list = XCDR (list))
1966 { 1965 {
@@ -2014,7 +2013,7 @@ call_mod_hooks (Lisp_Object list, Lisp_Object start, Lisp_Object end)
2014 2013
2015void 2014void
2016verify_interval_modification (struct buffer *buf, 2015verify_interval_modification (struct buffer *buf,
2017 EMACS_INT start, EMACS_INT end) 2016 ptrdiff_t start, ptrdiff_t end)
2018{ 2017{
2019 register INTERVAL intervals = BUF_INTERVALS (buf); 2018 register INTERVAL intervals = BUF_INTERVALS (buf);
2020 register INTERVAL i; 2019 register INTERVAL i;
@@ -2035,7 +2034,7 @@ verify_interval_modification (struct buffer *buf,
2035 2034
2036 if (start > end) 2035 if (start > end)
2037 { 2036 {
2038 EMACS_INT temp = start; 2037 ptrdiff_t temp = start;
2039 start = end; 2038 start = end;
2040 end = temp; 2039 end = temp;
2041 } 2040 }
diff --git a/src/tparam.c b/src/tparam.c
index ac21667d65b..4d26ef524fb 100644
--- a/src/tparam.c
+++ b/src/tparam.c
@@ -22,10 +22,6 @@ Boston, MA 02110-1301, USA. */
22#include <setjmp.h> 22#include <setjmp.h>
23#include "lisp.h" /* for xmalloc */ 23#include "lisp.h" /* for xmalloc */
24#include "tparam.h" 24#include "tparam.h"
25
26#ifndef NULL
27#define NULL (char *) 0
28#endif
29 25
30/* Assuming STRING is the value of a termcap string entry 26/* Assuming STRING is the value of a termcap string entry
31 containing `%' constructs to expand parameters, 27 containing `%' constructs to expand parameters,
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/unexelf.c b/src/unexelf.c
index ac9c9e75764..f35b53aeab3 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -506,11 +506,7 @@ typedef struct {
506#endif 506#endif
507 507
508#ifndef ElfW 508#ifndef ElfW
509# ifdef __STDC__ 509# define ElfBitsW(bits, type) Elf##bits##_##type
510# define ElfBitsW(bits, type) Elf##bits##_##type
511# else
512# define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type
513# endif
514# ifdef _LP64 510# ifdef _LP64
515# define ELFSIZE 64 511# define ELFSIZE 64
516# else 512# else
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/vm-limit.c b/src/vm-limit.c
index 94725044048..c313a900f2c 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -31,7 +31,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31enum warnlevel { not_warned, warned_75, warned_85, warned_95 }; 31enum warnlevel { not_warned, warned_75, warned_85, warned_95 };
32static enum warnlevel warnlevel; 32static enum warnlevel warnlevel;
33 33
34typedef POINTER_TYPE *POINTER; 34typedef void *POINTER;
35 35
36/* Function to call to issue a warning; 36/* Function to call to issue a warning;
37 0 means don't issue them. */ 37 0 means don't issue them. */
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 048779d6830..54ad0af4c3f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -63,7 +63,7 @@ static int displayed_window_lines (struct window *);
63static struct window *decode_window (Lisp_Object); 63static struct window *decode_window (Lisp_Object);
64static int count_windows (struct window *); 64static int count_windows (struct window *);
65static int get_leaf_windows (struct window *, struct window **, int); 65static int get_leaf_windows (struct window *, struct window **, int);
66static void window_scroll (Lisp_Object, int, int, int); 66static void window_scroll (Lisp_Object, EMACS_INT, int, int);
67static void window_scroll_pixel_based (Lisp_Object, int, int, int); 67static void window_scroll_pixel_based (Lisp_Object, int, int, int);
68static void window_scroll_line_based (Lisp_Object, int, int, int); 68static void window_scroll_line_based (Lisp_Object, int, int, int);
69static int freeze_window_start (struct window *, void *); 69static int freeze_window_start (struct window *, void *);
@@ -127,8 +127,8 @@ static int window_scroll_pixel_based_preserve_x;
127static int window_scroll_pixel_based_preserve_y; 127static int window_scroll_pixel_based_preserve_y;
128 128
129/* Same for window_scroll_line_based. */ 129/* Same for window_scroll_line_based. */
130static int window_scroll_preserve_hpos; 130static EMACS_INT window_scroll_preserve_hpos;
131static int window_scroll_preserve_vpos; 131static EMACS_INT window_scroll_preserve_vpos;
132 132
133static struct window * 133static struct window *
134decode_window (register Lisp_Object window) 134decode_window (register Lisp_Object window)
@@ -378,7 +378,7 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
378 redisplay_window has altered point after scrolling, 378 redisplay_window has altered point after scrolling,
379 because it makes the change only in the window. */ 379 because it makes the change only in the window. */
380 { 380 {
381 register EMACS_INT new_point = marker_position (w->pointm); 381 register ptrdiff_t new_point = marker_position (w->pointm);
382 if (new_point < BEGV) 382 if (new_point < BEGV)
383 SET_PT (BEGV); 383 SET_PT (BEGV);
384 else if (new_point > ZV) 384 else if (new_point > ZV)
@@ -680,10 +680,10 @@ window so that the location of point moves off-window. */)
680 (Lisp_Object window, Lisp_Object ncol) 680 (Lisp_Object window, Lisp_Object ncol)
681{ 681{
682 struct window *w = decode_window (window); 682 struct window *w = decode_window (window);
683 int hscroll; 683 ptrdiff_t hscroll;
684 684
685 CHECK_NUMBER (ncol); 685 CHECK_NUMBER (ncol);
686 hscroll = max (0, XINT (ncol)); 686 hscroll = clip_to_bounds (0, XINT (ncol), PTRDIFF_MAX);
687 687
688 /* Prevent redisplay shortcuts when changing the hscroll. */ 688 /* Prevent redisplay shortcuts when changing the hscroll. */
689 if (XINT (w->hscroll) != hscroll) 689 if (XINT (w->hscroll) != hscroll)
@@ -1393,10 +1393,10 @@ overriding motion of point in order to display at this exact start. */)
1393 CHECK_NUMBER_COERCE_MARKER (pos); 1393 CHECK_NUMBER_COERCE_MARKER (pos);
1394 set_marker_restricted (w->start, pos, w->buffer); 1394 set_marker_restricted (w->start, pos, w->buffer);
1395 /* this is not right, but much easier than doing what is right. */ 1395 /* this is not right, but much easier than doing what is right. */
1396 w->start_at_line_beg = Qnil; 1396 w->start_at_line_beg = 0;
1397 if (NILP (noforce)) 1397 if (NILP (noforce))
1398 w->force_start = Qt; 1398 w->force_start = 1;
1399 w->update_mode_line = Qt; 1399 w->update_mode_line = 1;
1400 XSETFASTINT (w->last_modified, 0); 1400 XSETFASTINT (w->last_modified, 0);
1401 XSETFASTINT (w->last_overlay_modified, 0); 1401 XSETFASTINT (w->last_overlay_modified, 0);
1402 if (!EQ (window, selected_window)) 1402 if (!EQ (window, selected_window))
@@ -1495,7 +1495,8 @@ Return nil if window display is not up-to-date. In that case, use
1495 register struct window *w; 1495 register struct window *w;
1496 register struct buffer *b; 1496 register struct buffer *b;
1497 struct glyph_row *row, *end_row; 1497 struct glyph_row *row, *end_row;
1498 int max_y, crop, i, n; 1498 int max_y, crop, i;
1499 EMACS_INT n;
1499 1500
1500 w = decode_window (window); 1501 w = decode_window (window);
1501 1502
@@ -2471,7 +2472,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2471 if (EQ (w->buffer, obj)) 2472 if (EQ (w->buffer, obj))
2472 { 2473 {
2473 mark_window_display_accurate (window, 0); 2474 mark_window_display_accurate (window, 0);
2474 w->update_mode_line = Qt; 2475 w->update_mode_line = 1;
2475 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1; 2476 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2476 ++update_mode_lines; 2477 ++update_mode_lines;
2477 best_window = window; 2478 best_window = window;
@@ -2563,7 +2564,7 @@ window-start value is reasonable when this function is called. */)
2563 struct window *w, *r, *s; 2564 struct window *w, *r, *s;
2564 struct frame *f; 2565 struct frame *f;
2565 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta; 2566 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2566 EMACS_INT startpos IF_LINT (= 0); 2567 ptrdiff_t startpos IF_LINT (= 0);
2567 int top IF_LINT (= 0), new_top, resize_failed; 2568 int top IF_LINT (= 0), new_top, resize_failed;
2568 Mouse_HLInfo *hlinfo; 2569 Mouse_HLInfo *hlinfo;
2569 2570
@@ -2770,12 +2771,11 @@ window-start value is reasonable when this function is called. */)
2770 2771
2771 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); 2772 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2772 w->window_end_valid = Qnil; 2773 w->window_end_valid = Qnil;
2773 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE 2774 w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
2774 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt 2775 || FETCH_BYTE (pos.bytepos - 1) == '\n');
2775 : Qnil);
2776 /* We need to do this, so that the window-scroll-functions 2776 /* We need to do this, so that the window-scroll-functions
2777 get called. */ 2777 get called. */
2778 w->optional_new_start = Qt; 2778 w->optional_new_start = 1;
2779 2779
2780 set_buffer_internal (obuf); 2780 set_buffer_internal (obuf);
2781 } 2781 }
@@ -2904,7 +2904,7 @@ select_frame_norecord (Lisp_Object frame)
2904void 2904void
2905run_window_configuration_change_hook (struct frame *f) 2905run_window_configuration_change_hook (struct frame *f)
2906{ 2906{
2907 int count = SPECPDL_INDEX (); 2907 ptrdiff_t count = SPECPDL_INDEX ();
2908 Lisp_Object frame, global_wcch 2908 Lisp_Object frame, global_wcch
2909 = Fdefault_value (Qwindow_configuration_change_hook); 2909 = Fdefault_value (Qwindow_configuration_change_hook);
2910 XSETFRAME (frame, f); 2910 XSETFRAME (frame, f);
@@ -2935,7 +2935,7 @@ run_window_configuration_change_hook (struct frame *f)
2935 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook, 2935 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
2936 buffer))) 2936 buffer)))
2937 { 2937 {
2938 int inner_count = SPECPDL_INDEX (); 2938 ptrdiff_t inner_count = SPECPDL_INDEX ();
2939 record_unwind_protect (select_window_norecord, Fselected_window ()); 2939 record_unwind_protect (select_window_norecord, Fselected_window ());
2940 select_window_norecord (window); 2940 select_window_norecord (window);
2941 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, 2941 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
@@ -2970,7 +2970,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
2970{ 2970{
2971 struct window *w = XWINDOW (window); 2971 struct window *w = XWINDOW (window);
2972 struct buffer *b = XBUFFER (buffer); 2972 struct buffer *b = XBUFFER (buffer);
2973 int count = SPECPDL_INDEX (); 2973 ptrdiff_t count = SPECPDL_INDEX ();
2974 int samebuf = EQ (buffer, w->buffer); 2974 int samebuf = EQ (buffer, w->buffer);
2975 2975
2976 w->buffer = buffer; 2976 w->buffer = buffer;
@@ -3005,8 +3005,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3005 set_marker_restricted (w->start, 3005 set_marker_restricted (w->start,
3006 make_number (b->last_window_start), 3006 make_number (b->last_window_start),
3007 buffer); 3007 buffer);
3008 w->start_at_line_beg = Qnil; 3008 w->start_at_line_beg = 0;
3009 w->force_start = Qnil; 3009 w->force_start = 0;
3010 XSETFASTINT (w->last_modified, 0); 3010 XSETFASTINT (w->last_modified, 0);
3011 XSETFASTINT (w->last_overlay_modified, 0); 3011 XSETFASTINT (w->last_overlay_modified, 0);
3012 } 3012 }
@@ -3142,7 +3142,7 @@ displaying that buffer. */)
3142 { 3142 {
3143 struct window *w = XWINDOW (object); 3143 struct window *w = XWINDOW (object);
3144 mark_window_display_accurate (object, 0); 3144 mark_window_display_accurate (object, 0);
3145 w->update_mode_line = Qt; 3145 w->update_mode_line = 1;
3146 if (BUFFERP (w->buffer)) 3146 if (BUFFERP (w->buffer))
3147 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; 3147 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3148 ++update_mode_lines; 3148 ++update_mode_lines;
@@ -3201,7 +3201,7 @@ temp_output_buffer_show (register Lisp_Object buf)
3201 /* Run temp-buffer-show-hook, with the chosen window selected 3201 /* Run temp-buffer-show-hook, with the chosen window selected
3202 and its buffer current. */ 3202 and its buffer current. */
3203 { 3203 {
3204 int count = SPECPDL_INDEX (); 3204 ptrdiff_t count = SPECPDL_INDEX ();
3205 Lisp_Object prev_window, prev_buffer; 3205 Lisp_Object prev_window, prev_buffer;
3206 prev_window = selected_window; 3206 prev_window = selected_window;
3207 XSETBUFFER (prev_buffer, old); 3207 XSETBUFFER (prev_buffer, old);
@@ -3274,7 +3274,8 @@ make_window (void)
3274 3274
3275 w = allocate_window (); 3275 w = allocate_window ();
3276 /* Initialize all Lisp data. */ 3276 /* Initialize all Lisp data. */
3277 w->frame = w->mini_p = Qnil; 3277 w->frame = Qnil;
3278 w->mini = 0;
3278 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil; 3279 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
3279 XSETFASTINT (w->left_col, 0); 3280 XSETFASTINT (w->left_col, 0);
3280 XSETFASTINT (w->top_line, 0); 3281 XSETFASTINT (w->top_line, 0);
@@ -3287,7 +3288,7 @@ make_window (void)
3287 w->buffer = Qnil; 3288 w->buffer = Qnil;
3288 w->start = Fmake_marker (); 3289 w->start = Fmake_marker ();
3289 w->pointm = Fmake_marker (); 3290 w->pointm = Fmake_marker ();
3290 w->force_start = w->optional_new_start = Qnil; 3291 w->force_start = w->optional_new_start = 0;
3291 XSETFASTINT (w->hscroll, 0); 3292 XSETFASTINT (w->hscroll, 0);
3292 XSETFASTINT (w->min_hscroll, 0); 3293 XSETFASTINT (w->min_hscroll, 0);
3293 XSETFASTINT (w->use_time, 0); 3294 XSETFASTINT (w->use_time, 0);
@@ -3295,17 +3296,18 @@ make_window (void)
3295 XSETFASTINT (w->sequence_number, sequence_number); 3296 XSETFASTINT (w->sequence_number, sequence_number);
3296 w->temslot = w->last_modified = w->last_overlay_modified = Qnil; 3297 w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
3297 XSETFASTINT (w->last_point, 0); 3298 XSETFASTINT (w->last_point, 0);
3298 w->last_had_star = w->vertical_scroll_bar = Qnil; 3299 w->last_had_star = 0;
3300 w->vertical_scroll_bar = Qnil;
3299 w->left_margin_cols = w->right_margin_cols = Qnil; 3301 w->left_margin_cols = w->right_margin_cols = Qnil;
3300 w->left_fringe_width = w->right_fringe_width = Qnil; 3302 w->left_fringe_width = w->right_fringe_width = Qnil;
3301 w->fringes_outside_margins = Qnil; 3303 w->fringes_outside_margins = Qnil;
3302 w->scroll_bar_width = Qnil; 3304 w->scroll_bar_width = Qnil;
3303 w->vertical_scroll_bar_type = Qt; 3305 w->vertical_scroll_bar_type = Qt;
3304 w->last_mark_x = w->last_mark_y = Qnil;
3305 XSETFASTINT (w->window_end_pos, 0); 3306 XSETFASTINT (w->window_end_pos, 0);
3306 XSETFASTINT (w->window_end_vpos, 0); 3307 XSETFASTINT (w->window_end_vpos, 0);
3307 w->window_end_valid = w->update_mode_line = Qnil; 3308 w->window_end_valid = w->display_table = Qnil;
3308 w->start_at_line_beg = w->display_table = w->dedicated = Qnil; 3309 w->update_mode_line = w->start_at_line_beg = 0;
3310 w->dedicated = Qnil;
3309 w->base_line_number = w->base_line_pos = w->region_showing = Qnil; 3311 w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
3310 w->column_number_displayed = w->redisplay_end_trigger = Qnil; 3312 w->column_number_displayed = w->redisplay_end_trigger = Qnil;
3311 w->combination_limit = w->window_parameters = Qnil; 3313 w->combination_limit = w->window_parameters = Qnil;
@@ -4189,9 +4191,10 @@ window_internal_height (struct window *w)
4189 respectively. */ 4191 respectively. */
4190 4192
4191static void 4193static void
4192window_scroll (Lisp_Object window, int n, int whole, int noerror) 4194window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4193{ 4195{
4194 immediate_quit = 1; 4196 immediate_quit = 1;
4197 n = clip_to_bounds (INT_MIN, n, INT_MAX);
4195 4198
4196 /* If we must, use the pixel-based version which is much slower than 4199 /* If we must, use the pixel-based version which is much slower than
4197 the line-based one but can handle varying line heights. */ 4200 the line-based one but can handle varying line heights. */
@@ -4292,7 +4295,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4292 /* Maybe modify window start instead of scrolling. */ 4295 /* Maybe modify window start instead of scrolling. */
4293 if (rbot > 0 || w->vscroll < 0) 4296 if (rbot > 0 || w->vscroll < 0)
4294 { 4297 {
4295 EMACS_INT spos; 4298 ptrdiff_t spos;
4296 4299
4297 Fset_window_vscroll (window, make_number (0), Qt); 4300 Fset_window_vscroll (window, make_number (0), Qt);
4298 /* If there are other text lines above the current row, 4301 /* If there are other text lines above the current row,
@@ -4303,13 +4306,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4303 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV); 4306 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4304 set_marker_restricted (w->start, make_number (spos), 4307 set_marker_restricted (w->start, make_number (spos),
4305 w->buffer); 4308 w->buffer);
4306 w->start_at_line_beg = Qt; 4309 w->start_at_line_beg = 1;
4307 w->update_mode_line = Qt; 4310 w->update_mode_line = 1;
4308 XSETFASTINT (w->last_modified, 0); 4311 XSETFASTINT (w->last_modified, 0);
4309 XSETFASTINT (w->last_overlay_modified, 0); 4312 XSETFASTINT (w->last_overlay_modified, 0);
4310 /* Set force_start so that redisplay_window will run the 4313 /* Set force_start so that redisplay_window will run the
4311 window-scroll-functions. */ 4314 window-scroll-functions. */
4312 w->force_start = Qt; 4315 w->force_start = 1;
4313 return; 4316 return;
4314 } 4317 }
4315 } 4318 }
@@ -4347,7 +4350,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4347 start_display (&it, w, start); 4350 start_display (&it, w, start);
4348 if (whole) 4351 if (whole)
4349 { 4352 {
4350 EMACS_INT start_pos = IT_CHARPOS (it); 4353 ptrdiff_t start_pos = IT_CHARPOS (it);
4351 int dy = WINDOW_FRAME_LINE_HEIGHT (w); 4354 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4352 dy = max ((window_box_height (w) 4355 dy = max ((window_box_height (w)
4353 - next_screen_context_lines * dy), 4356 - next_screen_context_lines * dy),
@@ -4434,8 +4437,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4434 4437
4435 if (! vscrolled) 4438 if (! vscrolled)
4436 { 4439 {
4437 EMACS_INT pos = IT_CHARPOS (it); 4440 ptrdiff_t pos = IT_CHARPOS (it);
4438 EMACS_INT bytepos; 4441 ptrdiff_t bytepos;
4439 4442
4440 /* If in the middle of a multi-glyph character move forward to 4443 /* If in the middle of a multi-glyph character move forward to
4441 the next character. */ 4444 the next character. */
@@ -4449,14 +4452,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4449 set_marker_restricted (w->start, make_number (pos), 4452 set_marker_restricted (w->start, make_number (pos),
4450 w->buffer); 4453 w->buffer);
4451 bytepos = XMARKER (w->start)->bytepos; 4454 bytepos = XMARKER (w->start)->bytepos;
4452 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n') 4455 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
4453 ? Qt : Qnil); 4456 w->update_mode_line = 1;
4454 w->update_mode_line = Qt;
4455 XSETFASTINT (w->last_modified, 0); 4457 XSETFASTINT (w->last_modified, 0);
4456 XSETFASTINT (w->last_overlay_modified, 0); 4458 XSETFASTINT (w->last_overlay_modified, 0);
4457 /* Set force_start so that redisplay_window will run the 4459 /* Set force_start so that redisplay_window will run the
4458 window-scroll-functions. */ 4460 window-scroll-functions. */
4459 w->force_start = Qt; 4461 w->force_start = 1;
4460 } 4462 }
4461 4463
4462 /* The rest of this function uses current_y in a nonstandard way, 4464 /* The rest of this function uses current_y in a nonstandard way,
@@ -4505,7 +4507,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4505 } 4507 }
4506 else if (n < 0) 4508 else if (n < 0)
4507 { 4509 {
4508 EMACS_INT charpos, bytepos; 4510 ptrdiff_t charpos, bytepos;
4509 int partial_p; 4511 int partial_p;
4510 4512
4511 /* Save our position, for the 4513 /* Save our position, for the
@@ -4582,12 +4584,12 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4582 in `grep-mode-font-lock-keywords'). So we use a marker to record 4584 in `grep-mode-font-lock-keywords'). So we use a marker to record
4583 the old point position, to prevent crashes in SET_PT_BOTH. */ 4585 the old point position, to prevent crashes in SET_PT_BOTH. */
4584 Lisp_Object opoint_marker = Fpoint_marker (); 4586 Lisp_Object opoint_marker = Fpoint_marker ();
4585 register EMACS_INT pos, pos_byte; 4587 register ptrdiff_t pos, pos_byte;
4586 register int ht = window_internal_height (w); 4588 register int ht = window_internal_height (w);
4587 register Lisp_Object tem; 4589 register Lisp_Object tem;
4588 int lose; 4590 int lose;
4589 Lisp_Object bolp; 4591 Lisp_Object bolp;
4590 EMACS_INT startpos; 4592 ptrdiff_t startpos;
4591 Lisp_Object original_pos = Qnil; 4593 Lisp_Object original_pos = Qnil;
4592 4594
4593 /* If scrolling screen-fulls, compute the number of lines to 4595 /* If scrolling screen-fulls, compute the number of lines to
@@ -4649,13 +4651,13 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4649 max (0, min (scroll_margin, XINT (w->total_lines) / 4)); 4651 max (0, min (scroll_margin, XINT (w->total_lines) / 4));
4650 4652
4651 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); 4653 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4652 w->start_at_line_beg = bolp; 4654 w->start_at_line_beg = !NILP (bolp);
4653 w->update_mode_line = Qt; 4655 w->update_mode_line = 1;
4654 XSETFASTINT (w->last_modified, 0); 4656 XSETFASTINT (w->last_modified, 0);
4655 XSETFASTINT (w->last_overlay_modified, 0); 4657 XSETFASTINT (w->last_overlay_modified, 0);
4656 /* Set force_start so that redisplay_window will run 4658 /* Set force_start so that redisplay_window will run
4657 the window-scroll-functions. */ 4659 the window-scroll-functions. */
4658 w->force_start = Qt; 4660 w->force_start = 1;
4659 4661
4660 if (!NILP (Vscroll_preserve_screen_position) 4662 if (!NILP (Vscroll_preserve_screen_position)
4661 && (whole || !EQ (Vscroll_preserve_screen_position, Qt))) 4663 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
@@ -4736,7 +4738,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4736static void 4738static void
4737scroll_command (Lisp_Object n, int direction) 4739scroll_command (Lisp_Object n, int direction)
4738{ 4740{
4739 int count = SPECPDL_INDEX (); 4741 ptrdiff_t count = SPECPDL_INDEX ();
4740 4742
4741 xassert (eabs (direction) == 1); 4743 xassert (eabs (direction) == 1);
4742 4744
@@ -4851,7 +4853,7 @@ specifies the window to scroll. This takes precedence over
4851{ 4853{
4852 Lisp_Object window; 4854 Lisp_Object window;
4853 struct window *w; 4855 struct window *w;
4854 int count = SPECPDL_INDEX (); 4856 ptrdiff_t count = SPECPDL_INDEX ();
4855 4857
4856 window = Fother_window_for_scrolling (); 4858 window = Fother_window_for_scrolling ();
4857 w = XWINDOW (window); 4859 w = XWINDOW (window);
@@ -4893,7 +4895,7 @@ by this function. This happens in an interactive call. */)
4893 (register Lisp_Object arg, Lisp_Object set_minimum) 4895 (register Lisp_Object arg, Lisp_Object set_minimum)
4894{ 4896{
4895 Lisp_Object result; 4897 Lisp_Object result;
4896 int hscroll; 4898 EMACS_INT hscroll;
4897 struct window *w = XWINDOW (selected_window); 4899 struct window *w = XWINDOW (selected_window);
4898 4900
4899 if (NILP (arg)) 4901 if (NILP (arg))
@@ -4922,7 +4924,7 @@ by this function. This happens in an interactive call. */)
4922 (register Lisp_Object arg, Lisp_Object set_minimum) 4924 (register Lisp_Object arg, Lisp_Object set_minimum)
4923{ 4925{
4924 Lisp_Object result; 4926 Lisp_Object result;
4925 int hscroll; 4927 EMACS_INT hscroll;
4926 struct window *w = XWINDOW (selected_window); 4928 struct window *w = XWINDOW (selected_window);
4927 4929
4928 if (NILP (arg)) 4930 if (NILP (arg))
@@ -5033,7 +5035,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5033 struct buffer *buf = XBUFFER (w->buffer); 5035 struct buffer *buf = XBUFFER (w->buffer);
5034 struct buffer *obuf = current_buffer; 5036 struct buffer *obuf = current_buffer;
5035 int center_p = 0; 5037 int center_p = 0;
5036 EMACS_INT charpos, bytepos; 5038 ptrdiff_t charpos, bytepos;
5037 EMACS_INT iarg IF_LINT (= 0); 5039 EMACS_INT iarg IF_LINT (= 0);
5038 int this_scroll_margin; 5040 int this_scroll_margin;
5039 5041
@@ -5098,7 +5100,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5098 { 5100 {
5099 struct it it; 5101 struct it it;
5100 struct text_pos pt; 5102 struct text_pos pt;
5101 int nlines = min (INT_MAX, -iarg); 5103 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
5102 int extra_line_spacing; 5104 int extra_line_spacing;
5103 int h = window_box_height (w); 5105 int h = window_box_height (w);
5104 void *itdata = bidi_shelve_cache (); 5106 void *itdata = bidi_shelve_cache ();
@@ -5199,12 +5201,10 @@ and redisplay normally--don't erase and redraw the frame. */)
5199 set_marker_both (w->start, w->buffer, charpos, bytepos); 5201 set_marker_both (w->start, w->buffer, charpos, bytepos);
5200 w->window_end_valid = Qnil; 5202 w->window_end_valid = Qnil;
5201 5203
5202 w->optional_new_start = Qt; 5204 w->optional_new_start = 1;
5203 5205
5204 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n') 5206 w->start_at_line_beg = (bytepos == BEGV_BYTE ||
5205 w->start_at_line_beg = Qt; 5207 FETCH_BYTE (bytepos - 1) == '\n');
5206 else
5207 w->start_at_line_beg = Qnil;
5208 5208
5209 set_buffer_internal (obuf); 5209 set_buffer_internal (obuf);
5210 return Qnil; 5210 return Qnil;
@@ -5255,8 +5255,8 @@ zero means top of window, negative means relative to bottom of window. */)
5255 int height = window_internal_height (w); 5255 int height = window_internal_height (w);
5256 Fvertical_motion (make_number (- (height / 2)), window); 5256 Fvertical_motion (make_number (- (height / 2)), window);
5257 set_marker_both (w->start, w->buffer, PT, PT_BYTE); 5257 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5258 w->start_at_line_beg = Fbolp (); 5258 w->start_at_line_beg = !NILP (Fbolp ());
5259 w->force_start = Qt; 5259 w->force_start = 1;
5260 } 5260 }
5261 else 5261 else
5262 Fgoto_char (w->start); 5262 Fgoto_char (w->start);
@@ -5382,7 +5382,7 @@ the return value is nil. Otherwise the value is t. */)
5382 Lisp_Object frame; 5382 Lisp_Object frame;
5383 Lisp_Object auto_buffer_name; 5383 Lisp_Object auto_buffer_name;
5384 FRAME_PTR f; 5384 FRAME_PTR f;
5385 EMACS_INT old_point = -1; 5385 ptrdiff_t old_point = -1;
5386 5386
5387 CHECK_WINDOW_CONFIGURATION (configuration); 5387 CHECK_WINDOW_CONFIGURATION (configuration);
5388 5388
@@ -5605,7 +5605,7 @@ the return value is nil. Otherwise the value is t. */)
5605 /* If saved buffer is alive, install it. */ 5605 /* If saved buffer is alive, install it. */
5606 { 5606 {
5607 w->buffer = p->buffer; 5607 w->buffer = p->buffer;
5608 w->start_at_line_beg = p->start_at_line_beg; 5608 w->start_at_line_beg = !NILP (p->start_at_line_beg);
5609 set_marker_restricted (w->start, p->start, w->buffer); 5609 set_marker_restricted (w->start, p->start, w->buffer);
5610 set_marker_restricted (w->pointm, p->pointm, w->buffer); 5610 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5611 Fset_marker (BVAR (XBUFFER (w->buffer), mark), 5611 Fset_marker (BVAR (XBUFFER (w->buffer), mark),
@@ -5630,7 +5630,7 @@ the return value is nil. Otherwise the value is t. */)
5630 set_marker_restricted_both (w->pointm, w->buffer, 5630 set_marker_restricted_both (w->pointm, w->buffer,
5631 BUF_PT (XBUFFER (w->buffer)), 5631 BUF_PT (XBUFFER (w->buffer)),
5632 BUF_PT_BYTE (XBUFFER (w->buffer))); 5632 BUF_PT_BYTE (XBUFFER (w->buffer)));
5633 w->start_at_line_beg = Qt; 5633 w->start_at_line_beg = 1;
5634 } 5634 }
5635 else if (STRINGP (auto_buffer_name = 5635 else if (STRINGP (auto_buffer_name =
5636 Fwindow_parameter (window, Qauto_buffer_name)) 5636 Fwindow_parameter (window, Qauto_buffer_name))
@@ -5639,7 +5639,7 @@ the return value is nil. Otherwise the value is t. */)
5639 { 5639 {
5640 set_marker_restricted (w->start, make_number (0), w->buffer); 5640 set_marker_restricted (w->start, make_number (0), w->buffer);
5641 set_marker_restricted (w->pointm, make_number (0), w->buffer); 5641 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5642 w->start_at_line_beg = Qt; 5642 w->start_at_line_beg = 1;
5643 } 5643 }
5644 else 5644 else
5645 /* Window has no live buffer, get one. */ 5645 /* Window has no live buffer, get one. */
@@ -5653,7 +5653,7 @@ the return value is nil. Otherwise the value is t. */)
5653 range. */ 5653 range. */
5654 set_marker_restricted (w->start, make_number (0), w->buffer); 5654 set_marker_restricted (w->start, make_number (0), w->buffer);
5655 set_marker_restricted (w->pointm, make_number (0), w->buffer); 5655 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5656 w->start_at_line_beg = Qt; 5656 w->start_at_line_beg = 1;
5657 if (!NILP (w->dedicated)) 5657 if (!NILP (w->dedicated))
5658 /* Record this window as dead. */ 5658 /* Record this window as dead. */
5659 dead_windows = Fcons (window, dead_windows); 5659 dead_windows = Fcons (window, dead_windows);
@@ -5954,7 +5954,7 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5954 = !NILP (Vwindow_point_insertion_type); 5954 = !NILP (Vwindow_point_insertion_type);
5955 5955
5956 p->start = Fcopy_marker (w->start, Qnil); 5956 p->start = Fcopy_marker (w->start, Qnil);
5957 p->start_at_line_beg = w->start_at_line_beg; 5957 p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil;
5958 5958
5959 tem = BVAR (XBUFFER (w->buffer), mark); 5959 tem = BVAR (XBUFFER (w->buffer), mark);
5960 p->mark = Fcopy_marker (tem, Qnil); 5960 p->mark = Fcopy_marker (tem, Qnil);
@@ -6187,7 +6187,7 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6187 6187
6188 if (!NILP (width)) 6188 if (!NILP (width))
6189 { 6189 {
6190 CHECK_NATNUM (width); 6190 CHECK_RANGED_INTEGER (0, width, INT_MAX);
6191 6191
6192 if (XINT (width) == 0) 6192 if (XINT (width) == 0)
6193 vertical_type = Qnil; 6193 vertical_type = Qnil;
diff --git a/src/window.h b/src/window.h
index ea127ca95a8..0d3910c8cb0 100644
--- a/src/window.h
+++ b/src/window.h
@@ -94,9 +94,6 @@ struct window
94 /* The frame this window is on. */ 94 /* The frame this window is on. */
95 Lisp_Object frame; 95 Lisp_Object frame;
96 96
97 /* t if this window is a minibuffer window. */
98 Lisp_Object mini_p;
99
100 /* Following (to right or down) and preceding (to left or up) child 97 /* Following (to right or down) and preceding (to left or up) child
101 at same level of tree. */ 98 at same level of tree. */
102 Lisp_Object next, prev; 99 Lisp_Object next, prev;
@@ -144,15 +141,6 @@ struct window
144 each one can have its own value of point. */ 141 each one can have its own value of point. */
145 Lisp_Object pointm; 142 Lisp_Object pointm;
146 143
147 /* Non-nil means next redisplay must use the value of start
148 set up for it in advance. Set by scrolling commands. */
149 Lisp_Object force_start;
150 /* Non-nil means we have explicitly changed the value of start,
151 but that the next redisplay is not obliged to use the new value.
152 This is used in Fdelete_other_windows to force a call to
153 Vwindow_scroll_functions; also by Frecenter with argument. */
154 Lisp_Object optional_new_start;
155
156 /* Number of columns display within the window is scrolled to the left. */ 144 /* Number of columns display within the window is scrolled to the left. */
157 Lisp_Object hscroll; 145 Lisp_Object hscroll;
158 /* Minimum hscroll for automatic hscrolling. This is the value 146 /* Minimum hscroll for automatic hscrolling. This is the value
@@ -176,9 +164,6 @@ struct window
176 Lisp_Object last_overlay_modified; 164 Lisp_Object last_overlay_modified;
177 /* Value of point at that time. */ 165 /* Value of point at that time. */
178 Lisp_Object last_point; 166 Lisp_Object last_point;
179 /* Non-nil if the buffer was "modified" when the window
180 was last updated. */
181 Lisp_Object last_had_star;
182 167
183 /* This window's vertical scroll bar. This field is only for use 168 /* This window's vertical scroll bar. This field is only for use
184 by the window-system-dependent code which implements the 169 by the window-system-dependent code which implements the
@@ -206,11 +191,6 @@ struct window
206 no scroll bar. A value of t means use frame value. */ 191 no scroll bar. A value of t means use frame value. */
207 Lisp_Object vertical_scroll_bar_type; 192 Lisp_Object vertical_scroll_bar_type;
208 193
209 /* Frame coords of mark as of last time display completed */
210 /* May be nil if mark does not exist or was not on frame */
211 Lisp_Object last_mark_x;
212 Lisp_Object last_mark_y;
213
214 /* Z - the buffer position of the last glyph in the current matrix 194 /* Z - the buffer position of the last glyph in the current matrix
215 of W. Only valid if WINDOW_END_VALID is not nil. */ 195 of W. Only valid if WINDOW_END_VALID is not nil. */
216 Lisp_Object window_end_pos; 196 Lisp_Object window_end_pos;
@@ -223,18 +203,13 @@ struct window
223 did not get onto the frame. */ 203 did not get onto the frame. */
224 Lisp_Object window_end_valid; 204 Lisp_Object window_end_valid;
225 205
226 /* Non-nil means must regenerate mode line of this window */
227 Lisp_Object update_mode_line;
228
229 /* Non-nil means current value of `start'
230 was the beginning of a line when it was chosen. */
231 Lisp_Object start_at_line_beg;
232
233 /* Display-table to use for displaying chars in this window. 206 /* Display-table to use for displaying chars in this window.
234 Nil means use the buffer's own display-table. */ 207 Nil means use the buffer's own display-table. */
235 Lisp_Object display_table; 208 Lisp_Object display_table;
236 209
237 /* Non-nil means window is marked as dedicated. */ 210 /* Non-nil usually means window is marked as dedicated.
211 Note Lisp code may set this to something beyond Qnil
212 and Qt, so bitfield can't be used here. */
238 Lisp_Object dedicated; 213 Lisp_Object dedicated;
239 214
240 /* Line number and position of a line somewhere above the top of the 215 /* Line number and position of a line somewhere above the top of the
@@ -302,6 +277,30 @@ struct window
302 /* This is handy for undrawing the cursor. */ 277 /* This is handy for undrawing the cursor. */
303 int phys_cursor_ascent, phys_cursor_height; 278 int phys_cursor_ascent, phys_cursor_height;
304 279
280 /* Non-zero if this window is a minibuffer window. */
281 unsigned mini : 1;
282
283 /* Non-zero means must regenerate mode line of this window */
284 unsigned update_mode_line : 1;
285
286 /* Non-nil if the buffer was "modified" when the window
287 was last updated. */
288 unsigned last_had_star : 1;
289
290 /* Non-zero means current value of `start'
291 was the beginning of a line when it was chosen. */
292 unsigned start_at_line_beg : 1;
293
294 /* Non-zero means next redisplay must use the value of start
295 set up for it in advance. Set by scrolling commands. */
296 unsigned force_start : 1;
297
298 /* Non-zero means we have explicitly changed the value of start,
299 but that the next redisplay is not obliged to use the new value.
300 This is used in Fdelete_other_windows to force a call to
301 Vwindow_scroll_functions; also by Frecenter with argument. */
302 unsigned optional_new_start : 1;
303
305 /* Non-zero means the cursor is currently displayed. This can be 304 /* Non-zero means the cursor is currently displayed. This can be
306 set to zero by functions overpainting the cursor image. */ 305 set to zero by functions overpainting the cursor image. */
307 unsigned phys_cursor_on_p : 1; 306 unsigned phys_cursor_on_p : 1;
@@ -337,7 +336,7 @@ struct window
337 336
338/* 1 if W is a minibuffer window. */ 337/* 1 if W is a minibuffer window. */
339 338
340#define MINI_WINDOW_P(W) (!NILP ((W)->mini_p)) 339#define MINI_WINDOW_P(W) ((W)->mini)
341 340
342/* General window layout: 341/* General window layout:
343 342
@@ -852,11 +851,6 @@ extern EMACS_INT minibuf_level;
852 851
853extern int update_mode_lines; 852extern int update_mode_lines;
854 853
855/* Nonzero if BEGV - BEG or Z - ZV of current buffer has changed since
856 last redisplay that finished. */
857
858extern int clip_changed;
859
860/* Nonzero if window sizes or contents have changed since last 854/* Nonzero if window sizes or contents have changed since last
861 redisplay that finished */ 855 redisplay that finished */
862 856
diff --git a/src/xdisp.c b/src/xdisp.c
index e7ecd2c1d91..5bb1b6deb9f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1,6 +1,6 @@
1/* Display generation from window structure and buffer text. 1/* Display generation from window structure and buffer text.
2 2
3Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc. 3Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -751,6 +751,7 @@ static struct glyph_slice null_glyph_slice = { 0, 0, 0, 0 };
751int redisplaying_p; 751int redisplaying_p;
752 752
753static Lisp_Object Qinhibit_free_realized_faces; 753static Lisp_Object Qinhibit_free_realized_faces;
754static Lisp_Object Qmode_line_default_help_echo;
754 755
755/* If a string, XTread_socket generates an event to display that string. 756/* If a string, XTread_socket generates an event to display that string.
756 (The display is done in read_char.) */ 757 (The display is done in read_char.) */
@@ -758,7 +759,7 @@ static Lisp_Object Qinhibit_free_realized_faces;
758Lisp_Object help_echo_string; 759Lisp_Object help_echo_string;
759Lisp_Object help_echo_window; 760Lisp_Object help_echo_window;
760Lisp_Object help_echo_object; 761Lisp_Object help_echo_object;
761EMACS_INT help_echo_pos; 762ptrdiff_t help_echo_pos;
762 763
763/* Temporary variable for XTread_socket. */ 764/* Temporary variable for XTread_socket. */
764 765
@@ -805,33 +806,33 @@ static Lisp_Object get_it_property (struct it *it, Lisp_Object prop);
805 806
806static void handle_line_prefix (struct it *); 807static void handle_line_prefix (struct it *);
807 808
808static void pint2str (char *, int, EMACS_INT); 809static void pint2str (char *, int, ptrdiff_t);
809static void pint2hrstr (char *, int, EMACS_INT); 810static void pint2hrstr (char *, int, ptrdiff_t);
810static struct text_pos run_window_scroll_functions (Lisp_Object, 811static struct text_pos run_window_scroll_functions (Lisp_Object,
811 struct text_pos); 812 struct text_pos);
812static void reconsider_clip_changes (struct window *, struct buffer *); 813static void reconsider_clip_changes (struct window *, struct buffer *);
813static int text_outside_line_unchanged_p (struct window *, 814static int text_outside_line_unchanged_p (struct window *,
814 EMACS_INT, EMACS_INT); 815 ptrdiff_t, ptrdiff_t);
815static void store_mode_line_noprop_char (char); 816static void store_mode_line_noprop_char (char);
816static int store_mode_line_noprop (const char *, int, int); 817static int store_mode_line_noprop (const char *, int, int);
817static void handle_stop (struct it *); 818static void handle_stop (struct it *);
818static void handle_stop_backwards (struct it *, EMACS_INT); 819static void handle_stop_backwards (struct it *, ptrdiff_t);
819static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0); 820static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
820static void ensure_echo_area_buffers (void); 821static void ensure_echo_area_buffers (void);
821static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object); 822static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object);
822static Lisp_Object with_echo_area_buffer_unwind_data (struct window *); 823static Lisp_Object with_echo_area_buffer_unwind_data (struct window *);
823static int with_echo_area_buffer (struct window *, int, 824static int with_echo_area_buffer (struct window *, int,
824 int (*) (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT), 825 int (*) (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t),
825 EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 826 ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
826static void clear_garbaged_frames (void); 827static void clear_garbaged_frames (void);
827static int current_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 828static int current_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
828static void pop_message (void); 829static void pop_message (void);
829static int truncate_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 830static int truncate_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
830static void set_message (const char *, Lisp_Object, EMACS_INT, int); 831static void set_message (const char *, Lisp_Object, ptrdiff_t, int);
831static int set_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 832static int set_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
832static int display_echo_area (struct window *); 833static int display_echo_area (struct window *);
833static int display_echo_area_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 834static int display_echo_area_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
834static int resize_mini_window_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT); 835static int resize_mini_window_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
835static Lisp_Object unwind_redisplay (Lisp_Object); 836static Lisp_Object unwind_redisplay (Lisp_Object);
836static int string_char_and_length (const unsigned char *, int *); 837static int string_char_and_length (const unsigned char *, int *);
837static struct text_pos display_prop_end (struct it *, Lisp_Object, 838static struct text_pos display_prop_end (struct it *, Lisp_Object,
@@ -844,10 +845,10 @@ static struct glyph_row *get_overlay_arrow_glyph_row (struct window *,
844static void extend_face_to_end_of_line (struct it *); 845static void extend_face_to_end_of_line (struct it *);
845static int append_space_for_newline (struct it *, int); 846static int append_space_for_newline (struct it *, int);
846static int cursor_row_fully_visible_p (struct window *, int, int); 847static int cursor_row_fully_visible_p (struct window *, int, int);
847static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); 848static int try_scrolling (Lisp_Object, int, ptrdiff_t, ptrdiff_t, int, int);
848static int try_cursor_movement (Lisp_Object, struct text_pos, int *); 849static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
849static int trailing_whitespace_p (EMACS_INT); 850static int trailing_whitespace_p (ptrdiff_t);
850static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT); 851static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
851static void push_it (struct it *, struct text_pos *); 852static void push_it (struct it *, struct text_pos *);
852static void iterate_out_of_display_property (struct it *); 853static void iterate_out_of_display_property (struct it *);
853static void pop_it (struct it *); 854static void pop_it (struct it *);
@@ -861,7 +862,7 @@ static Lisp_Object redisplay_window_error (Lisp_Object);
861static Lisp_Object redisplay_window_0 (Lisp_Object); 862static Lisp_Object redisplay_window_0 (Lisp_Object);
862static Lisp_Object redisplay_window_1 (Lisp_Object); 863static Lisp_Object redisplay_window_1 (Lisp_Object);
863static int set_cursor_from_row (struct window *, struct glyph_row *, 864static int set_cursor_from_row (struct window *, struct glyph_row *,
864 struct glyph_matrix *, EMACS_INT, EMACS_INT, 865 struct glyph_matrix *, ptrdiff_t, ptrdiff_t,
865 int, int); 866 int, int);
866static int update_menu_bar (struct frame *, int, int); 867static int update_menu_bar (struct frame *, int, int);
867static int try_window_reusing_current_matrix (struct window *); 868static int try_window_reusing_current_matrix (struct window *);
@@ -873,14 +874,14 @@ static int display_mode_element (struct it *, int, int, int, Lisp_Object, Lisp_O
873static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object); 874static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object);
874static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *); 875static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *);
875static void display_menu_bar (struct window *); 876static void display_menu_bar (struct window *);
876static EMACS_INT display_count_lines (EMACS_INT, EMACS_INT, EMACS_INT, 877static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
877 EMACS_INT *); 878 ptrdiff_t *);
878static int display_string (const char *, Lisp_Object, Lisp_Object, 879static int display_string (const char *, Lisp_Object, Lisp_Object,
879 EMACS_INT, EMACS_INT, struct it *, int, int, int, int); 880 ptrdiff_t, ptrdiff_t, struct it *, int, int, int, int);
880static void compute_line_metrics (struct it *); 881static void compute_line_metrics (struct it *);
881static void run_redisplay_end_trigger_hook (struct it *); 882static void run_redisplay_end_trigger_hook (struct it *);
882static int get_overlay_strings (struct it *, EMACS_INT); 883static int get_overlay_strings (struct it *, ptrdiff_t);
883static int get_overlay_strings_1 (struct it *, EMACS_INT, int); 884static int get_overlay_strings_1 (struct it *, ptrdiff_t, int);
884static void next_overlay_string (struct it *); 885static void next_overlay_string (struct it *);
885static void reseat (struct it *, struct text_pos, int); 886static void reseat (struct it *, struct text_pos, int);
886static void reseat_1 (struct it *, struct text_pos, int); 887static void reseat_1 (struct it *, struct text_pos, int);
@@ -895,14 +896,14 @@ static int next_element_from_buffer (struct it *);
895static int next_element_from_composition (struct it *); 896static int next_element_from_composition (struct it *);
896static int next_element_from_image (struct it *); 897static int next_element_from_image (struct it *);
897static int next_element_from_stretch (struct it *); 898static int next_element_from_stretch (struct it *);
898static void load_overlay_strings (struct it *, EMACS_INT); 899static void load_overlay_strings (struct it *, ptrdiff_t);
899static int init_from_display_pos (struct it *, struct window *, 900static int init_from_display_pos (struct it *, struct window *,
900 struct display_pos *); 901 struct display_pos *);
901static void reseat_to_string (struct it *, const char *, 902static void reseat_to_string (struct it *, const char *,
902 Lisp_Object, EMACS_INT, EMACS_INT, int, int); 903 Lisp_Object, ptrdiff_t, ptrdiff_t, int, int);
903static int get_next_display_element (struct it *); 904static int get_next_display_element (struct it *);
904static enum move_it_result 905static enum move_it_result
905 move_it_in_display_line_to (struct it *, EMACS_INT, int, 906 move_it_in_display_line_to (struct it *, ptrdiff_t, int,
906 enum move_operation_enum); 907 enum move_operation_enum);
907void move_it_vertically_backward (struct it *, int); 908void move_it_vertically_backward (struct it *, int);
908static void init_to_row_start (struct it *, struct window *, 909static void init_to_row_start (struct it *, struct window *,
@@ -912,20 +913,20 @@ static int init_to_row_end (struct it *, struct window *,
912static void back_to_previous_line_start (struct it *); 913static void back_to_previous_line_start (struct it *);
913static int forward_to_next_line_start (struct it *, int *, struct bidi_it *); 914static int forward_to_next_line_start (struct it *, int *, struct bidi_it *);
914static struct text_pos string_pos_nchars_ahead (struct text_pos, 915static struct text_pos string_pos_nchars_ahead (struct text_pos,
915 Lisp_Object, EMACS_INT); 916 Lisp_Object, ptrdiff_t);
916static struct text_pos string_pos (EMACS_INT, Lisp_Object); 917static struct text_pos string_pos (ptrdiff_t, Lisp_Object);
917static struct text_pos c_string_pos (EMACS_INT, const char *, int); 918static struct text_pos c_string_pos (ptrdiff_t, const char *, int);
918static EMACS_INT number_of_chars (const char *, int); 919static ptrdiff_t number_of_chars (const char *, int);
919static void compute_stop_pos (struct it *); 920static void compute_stop_pos (struct it *);
920static void compute_string_pos (struct text_pos *, struct text_pos, 921static void compute_string_pos (struct text_pos *, struct text_pos,
921 Lisp_Object); 922 Lisp_Object);
922static int face_before_or_after_it_pos (struct it *, int); 923static int face_before_or_after_it_pos (struct it *, int);
923static EMACS_INT next_overlay_change (EMACS_INT); 924static ptrdiff_t next_overlay_change (ptrdiff_t);
924static int handle_display_spec (struct it *, Lisp_Object, Lisp_Object, 925static int handle_display_spec (struct it *, Lisp_Object, Lisp_Object,
925 Lisp_Object, struct text_pos *, EMACS_INT, int); 926 Lisp_Object, struct text_pos *, ptrdiff_t, int);
926static int handle_single_display_spec (struct it *, Lisp_Object, 927static int handle_single_display_spec (struct it *, Lisp_Object,
927 Lisp_Object, Lisp_Object, 928 Lisp_Object, Lisp_Object,
928 struct text_pos *, EMACS_INT, int, int); 929 struct text_pos *, ptrdiff_t, int, int);
929static int underlying_face_id (struct it *); 930static int underlying_face_id (struct it *);
930static int in_ellipses_for_invisible_text_p (struct display_pos *, 931static int in_ellipses_for_invisible_text_p (struct display_pos *,
931 struct window *); 932 struct window *);
@@ -1257,7 +1258,7 @@ string_from_display_spec (Lisp_Object spec)
1257 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */ 1258 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1258 1259
1259int 1260int
1260pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y, 1261pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y,
1261 int *rtop, int *rbot, int *rowh, int *vpos) 1262 int *rtop, int *rbot, int *rowh, int *vpos)
1262{ 1263{
1263 struct it it; 1264 struct it it;
@@ -1603,7 +1604,7 @@ string_char_and_length (const unsigned char *str, int *len)
1603 in STRING, return the position NCHARS ahead (NCHARS >= 0). */ 1604 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1604 1605
1605static struct text_pos 1606static struct text_pos
1606string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, EMACS_INT nchars) 1607string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, ptrdiff_t nchars)
1607{ 1608{
1608 xassert (STRINGP (string) && nchars >= 0); 1609 xassert (STRINGP (string) && nchars >= 0);
1609 1610
@@ -1631,7 +1632,7 @@ string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, EMACS_INT ncha
1631 for character position CHARPOS in STRING. */ 1632 for character position CHARPOS in STRING. */
1632 1633
1633static inline struct text_pos 1634static inline struct text_pos
1634string_pos (EMACS_INT charpos, Lisp_Object string) 1635string_pos (ptrdiff_t charpos, Lisp_Object string)
1635{ 1636{
1636 struct text_pos pos; 1637 struct text_pos pos;
1637 xassert (STRINGP (string)); 1638 xassert (STRINGP (string));
@@ -1646,7 +1647,7 @@ string_pos (EMACS_INT charpos, Lisp_Object string)
1646 means recognize multibyte characters. */ 1647 means recognize multibyte characters. */
1647 1648
1648static struct text_pos 1649static struct text_pos
1649c_string_pos (EMACS_INT charpos, const char *s, int multibyte_p) 1650c_string_pos (ptrdiff_t charpos, const char *s, int multibyte_p)
1650{ 1651{
1651 struct text_pos pos; 1652 struct text_pos pos;
1652 1653
@@ -1676,14 +1677,14 @@ c_string_pos (EMACS_INT charpos, const char *s, int multibyte_p)
1676/* Value is the number of characters in C string S. MULTIBYTE_P 1677/* Value is the number of characters in C string S. MULTIBYTE_P
1677 non-zero means recognize multibyte characters. */ 1678 non-zero means recognize multibyte characters. */
1678 1679
1679static EMACS_INT 1680static ptrdiff_t
1680number_of_chars (const char *s, int multibyte_p) 1681number_of_chars (const char *s, int multibyte_p)
1681{ 1682{
1682 EMACS_INT nchars; 1683 ptrdiff_t nchars;
1683 1684
1684 if (multibyte_p) 1685 if (multibyte_p)
1685 { 1686 {
1686 EMACS_INT rest = strlen (s); 1687 ptrdiff_t rest = strlen (s);
1687 int len; 1688 int len;
1688 const unsigned char *p = (const unsigned char *) s; 1689 const unsigned char *p = (const unsigned char *) s;
1689 1690
@@ -2399,7 +2400,7 @@ safe_call (ptrdiff_t nargs, Lisp_Object *args)
2399 val = Qnil; 2400 val = Qnil;
2400 else 2401 else
2401 { 2402 {
2402 int count = SPECPDL_INDEX (); 2403 ptrdiff_t count = SPECPDL_INDEX ();
2403 struct gcpro gcpro1; 2404 struct gcpro gcpro1;
2404 2405
2405 GCPRO1 (args[0]); 2406 GCPRO1 (args[0]);
@@ -2549,7 +2550,7 @@ check_window_end (struct window *w)
2549 2550
2550void 2551void
2551init_iterator (struct it *it, struct window *w, 2552init_iterator (struct it *it, struct window *w,
2552 EMACS_INT charpos, EMACS_INT bytepos, 2553 ptrdiff_t charpos, ptrdiff_t bytepos,
2553 struct glyph_row *row, enum face_id base_face_id) 2554 struct glyph_row *row, enum face_id base_face_id)
2554{ 2555{
2555 int highlight_region_p; 2556 int highlight_region_p;
@@ -2640,7 +2641,9 @@ init_iterator (struct it *it, struct window *w,
2640 is invisible. >0 means lines indented more than this value are 2641 is invisible. >0 means lines indented more than this value are
2641 invisible. */ 2642 invisible. */
2642 it->selective = (INTEGERP (BVAR (current_buffer, selective_display)) 2643 it->selective = (INTEGERP (BVAR (current_buffer, selective_display))
2643 ? XINT (BVAR (current_buffer, selective_display)) 2644 ? clip_to_bounds (-1, XINT (BVAR (current_buffer,
2645 selective_display)),
2646 PTRDIFF_MAX)
2644 : (!NILP (BVAR (current_buffer, selective_display)) 2647 : (!NILP (BVAR (current_buffer, selective_display))
2645 ? -1 : 0)); 2648 ? -1 : 0));
2646 it->selective_display_ellipsis_p 2649 it->selective_display_ellipsis_p
@@ -2673,7 +2676,7 @@ init_iterator (struct it *it, struct window *w,
2673 && WINDOWP (minibuf_selected_window) 2676 && WINDOWP (minibuf_selected_window)
2674 && w == XWINDOW (minibuf_selected_window)))) 2677 && w == XWINDOW (minibuf_selected_window))))
2675 { 2678 {
2676 EMACS_INT markpos = marker_position (BVAR (current_buffer, mark)); 2679 ptrdiff_t markpos = marker_position (BVAR (current_buffer, mark));
2677 it->region_beg_charpos = min (PT, markpos); 2680 it->region_beg_charpos = min (PT, markpos);
2678 it->region_end_charpos = max (PT, markpos); 2681 it->region_end_charpos = max (PT, markpos);
2679 } 2682 }
@@ -2687,7 +2690,8 @@ init_iterator (struct it *it, struct window *w,
2687 it->redisplay_end_trigger_charpos 2690 it->redisplay_end_trigger_charpos
2688 = marker_position (w->redisplay_end_trigger); 2691 = marker_position (w->redisplay_end_trigger);
2689 else if (INTEGERP (w->redisplay_end_trigger)) 2692 else if (INTEGERP (w->redisplay_end_trigger))
2690 it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); 2693 it->redisplay_end_trigger_charpos =
2694 clip_to_bounds (PTRDIFF_MIN, XINT (w->redisplay_end_trigger), PTRDIFF_MAX);
2691 2695
2692 it->tab_width = SANE_TAB_WIDTH (current_buffer); 2696 it->tab_width = SANE_TAB_WIDTH (current_buffer);
2693 2697
@@ -2947,7 +2951,7 @@ in_ellipses_for_invisible_text_p (struct display_pos *pos, struct window *w)
2947{ 2951{
2948 Lisp_Object prop, window; 2952 Lisp_Object prop, window;
2949 int ellipses_p = 0; 2953 int ellipses_p = 0;
2950 EMACS_INT charpos = CHARPOS (pos->pos); 2954 ptrdiff_t charpos = CHARPOS (pos->pos);
2951 2955
2952 /* If POS specifies a position in a display vector, this might 2956 /* If POS specifies a position in a display vector, this might
2953 be for an ellipsis displayed for invisible text. We won't 2957 be for an ellipsis displayed for invisible text. We won't
@@ -2979,7 +2983,7 @@ in_ellipses_for_invisible_text_p (struct display_pos *pos, struct window *w)
2979static int 2983static int
2980init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos) 2984init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
2981{ 2985{
2982 EMACS_INT charpos = CHARPOS (pos->pos), bytepos = BYTEPOS (pos->pos); 2986 ptrdiff_t charpos = CHARPOS (pos->pos), bytepos = BYTEPOS (pos->pos);
2983 int i, overlay_strings_with_newlines = 0; 2987 int i, overlay_strings_with_newlines = 0;
2984 2988
2985 /* If POS specifies a position in a display vector, this might 2989 /* If POS specifies a position in a display vector, this might
@@ -3039,7 +3043,7 @@ init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
3039 pos->overlay_string_index is in IT->overlay_strings. */ 3043 pos->overlay_string_index is in IT->overlay_strings. */
3040 if (pos->overlay_string_index >= OVERLAY_STRING_CHUNK_SIZE) 3044 if (pos->overlay_string_index >= OVERLAY_STRING_CHUNK_SIZE)
3041 { 3045 {
3042 int n = pos->overlay_string_index / OVERLAY_STRING_CHUNK_SIZE; 3046 ptrdiff_t n = pos->overlay_string_index / OVERLAY_STRING_CHUNK_SIZE;
3043 it->current.overlay_string_index = 0; 3047 it->current.overlay_string_index = 0;
3044 while (n--) 3048 while (n--)
3045 { 3049 {
@@ -3167,7 +3171,7 @@ handle_stop (struct it *it)
3167 onto the stack one more time, which is not 3171 onto the stack one more time, which is not
3168 expected by the rest of the code that processes 3172 expected by the rest of the code that processes
3169 overlay strings. */ 3173 overlay strings. */
3170 || (it->n_overlay_strings <= 0 3174 || (it->current.overlay_string_index < 0
3171 ? !get_overlay_strings_1 (it, 0, 0) 3175 ? !get_overlay_strings_1 (it, 0, 0)
3172 : 0)) 3176 : 0))
3173 { 3177 {
@@ -3234,7 +3238,7 @@ compute_stop_pos (struct it *it)
3234{ 3238{
3235 register INTERVAL iv, next_iv; 3239 register INTERVAL iv, next_iv;
3236 Lisp_Object object, limit, position; 3240 Lisp_Object object, limit, position;
3237 EMACS_INT charpos, bytepos; 3241 ptrdiff_t charpos, bytepos;
3238 3242
3239 if (STRINGP (it->string)) 3243 if (STRINGP (it->string))
3240 { 3244 {
@@ -3248,7 +3252,7 @@ compute_stop_pos (struct it *it)
3248 } 3252 }
3249 else 3253 else
3250 { 3254 {
3251 EMACS_INT pos; 3255 ptrdiff_t pos;
3252 3256
3253 /* If end_charpos is out of range for some reason, such as a 3257 /* If end_charpos is out of range for some reason, such as a
3254 misbehaving display function, rationalize it (Bug#5984). */ 3258 misbehaving display function, rationalize it (Bug#5984). */
@@ -3330,7 +3334,7 @@ compute_stop_pos (struct it *it)
3330 3334
3331 if (it->cmp_it.id < 0) 3335 if (it->cmp_it.id < 0)
3332 { 3336 {
3333 EMACS_INT stoppos = it->end_charpos; 3337 ptrdiff_t stoppos = it->end_charpos;
3334 3338
3335 if (it->bidi_p && it->bidi_it.scan_dir < 0) 3339 if (it->bidi_p && it->bidi_it.scan_dir < 0)
3336 stoppos = -1; 3340 stoppos = -1;
@@ -3349,11 +3353,11 @@ compute_stop_pos (struct it *it)
3349 follows. This is like `next-overlay-change' but doesn't use 3353 follows. This is like `next-overlay-change' but doesn't use
3350 xmalloc. */ 3354 xmalloc. */
3351 3355
3352static EMACS_INT 3356static ptrdiff_t
3353next_overlay_change (EMACS_INT pos) 3357next_overlay_change (ptrdiff_t pos)
3354{ 3358{
3355 ptrdiff_t i, noverlays; 3359 ptrdiff_t i, noverlays;
3356 EMACS_INT endpos; 3360 ptrdiff_t endpos;
3357 Lisp_Object *overlays; 3361 Lisp_Object *overlays;
3358 3362
3359 /* Get all overlays at the given position. */ 3363 /* Get all overlays at the given position. */
@@ -3364,7 +3368,7 @@ next_overlay_change (EMACS_INT pos)
3364 for (i = 0; i < noverlays; ++i) 3368 for (i = 0; i < noverlays; ++i)
3365 { 3369 {
3366 Lisp_Object oend; 3370 Lisp_Object oend;
3367 EMACS_INT oendpos; 3371 ptrdiff_t oendpos;
3368 3372
3369 oend = OVERLAY_END (overlays[i]); 3373 oend = OVERLAY_END (overlays[i]);
3370 oendpos = OVERLAY_POSITION (oend); 3374 oendpos = OVERLAY_POSITION (oend);
@@ -3391,7 +3395,7 @@ next_overlay_change (EMACS_INT pos)
3391 strings, non-zero otherwise. It is set to 2 if the display string 3395 strings, non-zero otherwise. It is set to 2 if the display string
3392 uses any kind of `(space ...)' spec that will produce a stretch of 3396 uses any kind of `(space ...)' spec that will produce a stretch of
3393 white space in the text area. */ 3397 white space in the text area. */
3394EMACS_INT 3398ptrdiff_t
3395compute_display_string_pos (struct text_pos *position, 3399compute_display_string_pos (struct text_pos *position,
3396 struct bidi_string_data *string, 3400 struct bidi_string_data *string,
3397 int frame_window_p, int *disp_prop) 3401 int frame_window_p, int *disp_prop)
@@ -3401,10 +3405,10 @@ compute_display_string_pos (struct text_pos *position,
3401 (string && STRINGP (string->lstring)) ? string->lstring : Qnil; 3405 (string && STRINGP (string->lstring)) ? string->lstring : Qnil;
3402 Lisp_Object pos, spec, limpos; 3406 Lisp_Object pos, spec, limpos;
3403 int string_p = (string && (STRINGP (string->lstring) || string->s)); 3407 int string_p = (string && (STRINGP (string->lstring) || string->s));
3404 EMACS_INT eob = string_p ? string->schars : ZV; 3408 ptrdiff_t eob = string_p ? string->schars : ZV;
3405 EMACS_INT begb = string_p ? 0 : BEGV; 3409 ptrdiff_t begb = string_p ? 0 : BEGV;
3406 EMACS_INT bufpos, charpos = CHARPOS (*position); 3410 ptrdiff_t bufpos, charpos = CHARPOS (*position);
3407 EMACS_INT lim = 3411 ptrdiff_t lim =
3408 (charpos < eob - MAX_DISP_SCAN) ? charpos + MAX_DISP_SCAN : eob; 3412 (charpos < eob - MAX_DISP_SCAN) ? charpos + MAX_DISP_SCAN : eob;
3409 struct text_pos tpos; 3413 struct text_pos tpos;
3410 int rv = 0; 3414 int rv = 0;
@@ -3475,14 +3479,14 @@ compute_display_string_pos (struct text_pos *position,
3475 return -1. A display string is either an overlay with `display' 3479 return -1. A display string is either an overlay with `display'
3476 property whose value is a string or a `display' text property whose 3480 property whose value is a string or a `display' text property whose
3477 value is a string. */ 3481 value is a string. */
3478EMACS_INT 3482ptrdiff_t
3479compute_display_string_end (EMACS_INT charpos, struct bidi_string_data *string) 3483compute_display_string_end (ptrdiff_t charpos, struct bidi_string_data *string)
3480{ 3484{
3481 /* OBJECT = nil means current buffer. */ 3485 /* OBJECT = nil means current buffer. */
3482 Lisp_Object object = 3486 Lisp_Object object =
3483 (string && STRINGP (string->lstring)) ? string->lstring : Qnil; 3487 (string && STRINGP (string->lstring)) ? string->lstring : Qnil;
3484 Lisp_Object pos = make_number (charpos); 3488 Lisp_Object pos = make_number (charpos);
3485 EMACS_INT eob = 3489 ptrdiff_t eob =
3486 (STRINGP (object) || (string && string->s)) ? string->schars : ZV; 3490 (STRINGP (object) || (string && string->s)) ? string->schars : ZV;
3487 3491
3488 if (charpos >= eob || (string->s && !STRINGP (object))) 3492 if (charpos >= eob || (string->s && !STRINGP (object)))
@@ -3545,7 +3549,7 @@ handle_fontified_prop (struct it *it)
3545 no amount of fontifying will be able to change it. */ 3549 no amount of fontifying will be able to change it. */
3546 NILP (prop) && IT_CHARPOS (*it) < Z)) 3550 NILP (prop) && IT_CHARPOS (*it) < Z))
3547 { 3551 {
3548 int count = SPECPDL_INDEX (); 3552 ptrdiff_t count = SPECPDL_INDEX ();
3549 Lisp_Object val; 3553 Lisp_Object val;
3550 struct buffer *obuf = current_buffer; 3554 struct buffer *obuf = current_buffer;
3551 int begv = BEGV, zv = ZV; 3555 int begv = BEGV, zv = ZV;
@@ -3642,7 +3646,7 @@ static enum prop_handled
3642handle_face_prop (struct it *it) 3646handle_face_prop (struct it *it)
3643{ 3647{
3644 int new_face_id; 3648 int new_face_id;
3645 EMACS_INT next_stop; 3649 ptrdiff_t next_stop;
3646 3650
3647 if (!STRINGP (it->string)) 3651 if (!STRINGP (it->string))
3648 { 3652 {
@@ -3683,7 +3687,7 @@ handle_face_prop (struct it *it)
3683 else 3687 else
3684 { 3688 {
3685 int base_face_id; 3689 int base_face_id;
3686 EMACS_INT bufpos; 3690 ptrdiff_t bufpos;
3687 int i; 3691 int i;
3688 Lisp_Object from_overlay 3692 Lisp_Object from_overlay
3689 = (it->current.overlay_string_index >= 0 3693 = (it->current.overlay_string_index >= 0
@@ -3803,7 +3807,7 @@ static int
3803face_before_or_after_it_pos (struct it *it, int before_p) 3807face_before_or_after_it_pos (struct it *it, int before_p)
3804{ 3808{
3805 int face_id, limit; 3809 int face_id, limit;
3806 EMACS_INT next_check_charpos; 3810 ptrdiff_t next_check_charpos;
3807 struct it it_copy; 3811 struct it it_copy;
3808 void *it_copy_data = NULL; 3812 void *it_copy_data = NULL;
3809 3813
@@ -3811,7 +3815,7 @@ face_before_or_after_it_pos (struct it *it, int before_p)
3811 3815
3812 if (STRINGP (it->string)) 3816 if (STRINGP (it->string))
3813 { 3817 {
3814 EMACS_INT bufpos, charpos; 3818 ptrdiff_t bufpos, charpos;
3815 int base_face_id; 3819 int base_face_id;
3816 3820
3817 /* No face change past the end of the string (for the case 3821 /* No face change past the end of the string (for the case
@@ -4024,7 +4028,7 @@ handle_invisible_prop (struct it *it)
4024 if (!NILP (prop) 4028 if (!NILP (prop)
4025 && IT_STRING_CHARPOS (*it) < it->end_charpos) 4029 && IT_STRING_CHARPOS (*it) < it->end_charpos)
4026 { 4030 {
4027 EMACS_INT endpos; 4031 ptrdiff_t endpos;
4028 4032
4029 handled = HANDLED_RECOMPUTE_PROPS; 4033 handled = HANDLED_RECOMPUTE_PROPS;
4030 4034
@@ -4043,7 +4047,7 @@ handle_invisible_prop (struct it *it)
4043 && (endpos = XFASTINT (end_charpos)) < XFASTINT (limit)) 4047 && (endpos = XFASTINT (end_charpos)) < XFASTINT (limit))
4044 { 4048 {
4045 struct text_pos old; 4049 struct text_pos old;
4046 EMACS_INT oldpos; 4050 ptrdiff_t oldpos;
4047 4051
4048 old = it->current.string_pos; 4052 old = it->current.string_pos;
4049 oldpos = CHARPOS (old); 4053 oldpos = CHARPOS (old);
@@ -4095,7 +4099,7 @@ handle_invisible_prop (struct it *it)
4095 else 4099 else
4096 { 4100 {
4097 int invis_p; 4101 int invis_p;
4098 EMACS_INT newpos, next_stop, start_charpos, tem; 4102 ptrdiff_t newpos, next_stop, start_charpos, tem;
4099 Lisp_Object pos, prop, overlay; 4103 Lisp_Object pos, prop, overlay;
4100 4104
4101 /* First of all, is there invisible text at this position? */ 4105 /* First of all, is there invisible text at this position? */
@@ -4158,7 +4162,7 @@ handle_invisible_prop (struct it *it)
4158 /* The position newpos is now either ZV or on visible text. */ 4162 /* The position newpos is now either ZV or on visible text. */
4159 if (it->bidi_p) 4163 if (it->bidi_p)
4160 { 4164 {
4161 EMACS_INT bpos = CHAR_TO_BYTE (newpos); 4165 ptrdiff_t bpos = CHAR_TO_BYTE (newpos);
4162 int on_newline = 4166 int on_newline =
4163 bpos == ZV_BYTE || FETCH_BYTE (bpos) == '\n'; 4167 bpos == ZV_BYTE || FETCH_BYTE (bpos) == '\n';
4164 int after_newline = 4168 int after_newline =
@@ -4334,7 +4338,7 @@ handle_display_prop (struct it *it)
4334{ 4338{
4335 Lisp_Object propval, object, overlay; 4339 Lisp_Object propval, object, overlay;
4336 struct text_pos *position; 4340 struct text_pos *position;
4337 EMACS_INT bufpos; 4341 ptrdiff_t bufpos;
4338 /* Nonzero if some property replaces the display of the text itself. */ 4342 /* Nonzero if some property replaces the display of the text itself. */
4339 int display_replaced_p = 0; 4343 int display_replaced_p = 0;
4340 4344
@@ -4399,7 +4403,7 @@ handle_display_prop (struct it *it)
4399static int 4403static int
4400handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object, 4404handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4401 Lisp_Object overlay, struct text_pos *position, 4405 Lisp_Object overlay, struct text_pos *position,
4402 EMACS_INT bufpos, int frame_window_p) 4406 ptrdiff_t bufpos, int frame_window_p)
4403{ 4407{
4404 int replacing_p = 0; 4408 int replacing_p = 0;
4405 int rv; 4409 int rv;
@@ -4435,7 +4439,7 @@ handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4435 } 4439 }
4436 else if (VECTORP (spec)) 4440 else if (VECTORP (spec))
4437 { 4441 {
4438 int i; 4442 ptrdiff_t i;
4439 for (i = 0; i < ASIZE (spec); ++i) 4443 for (i = 0; i < ASIZE (spec); ++i)
4440 if ((rv = handle_single_display_spec (it, AREF (spec, i), object, 4444 if ((rv = handle_single_display_spec (it, AREF (spec, i), object,
4441 overlay, position, bufpos, 4445 overlay, position, bufpos,
@@ -4506,7 +4510,7 @@ display_prop_end (struct it *it, Lisp_Object object, struct text_pos start_pos)
4506static int 4510static int
4507handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object, 4511handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4508 Lisp_Object overlay, struct text_pos *position, 4512 Lisp_Object overlay, struct text_pos *position,
4509 EMACS_INT bufpos, int display_replaced_p, 4513 ptrdiff_t bufpos, int display_replaced_p,
4510 int frame_window_p) 4514 int frame_window_p)
4511{ 4515{
4512 Lisp_Object form; 4516 Lisp_Object form;
@@ -4528,7 +4532,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4528 4532
4529 if (!NILP (form) && !EQ (form, Qt)) 4533 if (!NILP (form) && !EQ (form, Qt))
4530 { 4534 {
4531 int count = SPECPDL_INDEX (); 4535 ptrdiff_t count = SPECPDL_INDEX ();
4532 struct gcpro gcpro1; 4536 struct gcpro gcpro1;
4533 4537
4534 /* Bind `object' to the object having the `display' property, a 4538 /* Bind `object' to the object having the `display' property, a
@@ -4570,7 +4574,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4570 && (EQ (XCAR (it->font_height), Qplus) 4574 && (EQ (XCAR (it->font_height), Qplus)
4571 || EQ (XCAR (it->font_height), Qminus)) 4575 || EQ (XCAR (it->font_height), Qminus))
4572 && CONSP (XCDR (it->font_height)) 4576 && CONSP (XCDR (it->font_height))
4573 && INTEGERP (XCAR (XCDR (it->font_height)))) 4577 && RANGED_INTEGERP (0, XCAR (XCDR (it->font_height)), INT_MAX))
4574 { 4578 {
4575 /* `(+ N)' or `(- N)' where N is an integer. */ 4579 /* `(+ N)' or `(- N)' where N is an integer. */
4576 int steps = XINT (XCAR (XCDR (it->font_height))); 4580 int steps = XINT (XCAR (XCDR (it->font_height)));
@@ -4602,7 +4606,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4602 { 4606 {
4603 /* Evaluate IT->font_height with `height' bound to the 4607 /* Evaluate IT->font_height with `height' bound to the
4604 current specified height to get the new height. */ 4608 current specified height to get the new height. */
4605 int count = SPECPDL_INDEX (); 4609 ptrdiff_t count = SPECPDL_INDEX ();
4606 4610
4607 specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]); 4611 specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]);
4608 value = safe_eval (it->font_height); 4612 value = safe_eval (it->font_height);
@@ -4951,7 +4955,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4951 4955
4952int 4956int
4953display_prop_intangible_p (Lisp_Object prop, Lisp_Object overlay, 4957display_prop_intangible_p (Lisp_Object prop, Lisp_Object overlay,
4954 EMACS_INT charpos, EMACS_INT bytepos) 4958 ptrdiff_t charpos, ptrdiff_t bytepos)
4955{ 4959{
4956 int frame_window_p = FRAME_WINDOW_P (XFRAME (selected_frame)); 4960 int frame_window_p = FRAME_WINDOW_P (XFRAME (selected_frame));
4957 struct text_pos position; 4961 struct text_pos position;
@@ -5032,7 +5036,7 @@ display_prop_string_p (Lisp_Object prop, Lisp_Object string)
5032 else if (VECTORP (prop)) 5036 else if (VECTORP (prop))
5033 { 5037 {
5034 /* A vector of sub-properties. */ 5038 /* A vector of sub-properties. */
5035 int i; 5039 ptrdiff_t i;
5036 for (i = 0; i < ASIZE (prop); ++i) 5040 for (i = 0; i < ASIZE (prop); ++i)
5037 if (single_display_spec_string_p (AREF (prop, i), string)) 5041 if (single_display_spec_string_p (AREF (prop, i), string))
5038 return 1; 5042 return 1;
@@ -5053,9 +5057,9 @@ display_prop_string_p (Lisp_Object prop, Lisp_Object string)
5053 This function may only use code that doesn't eval because it is 5057 This function may only use code that doesn't eval because it is
5054 called asynchronously from note_mouse_highlight. */ 5058 called asynchronously from note_mouse_highlight. */
5055 5059
5056static EMACS_INT 5060static ptrdiff_t
5057string_buffer_position_lim (Lisp_Object string, 5061string_buffer_position_lim (Lisp_Object string,
5058 EMACS_INT from, EMACS_INT to, int back_p) 5062 ptrdiff_t from, ptrdiff_t to, int back_p)
5059{ 5063{
5060 Lisp_Object limit, prop, pos; 5064 Lisp_Object limit, prop, pos;
5061 int found = 0; 5065 int found = 0;
@@ -5101,11 +5105,11 @@ string_buffer_position_lim (Lisp_Object string,
5101 This function may only use code that doesn't eval because it is 5105 This function may only use code that doesn't eval because it is
5102 called asynchronously from note_mouse_highlight. */ 5106 called asynchronously from note_mouse_highlight. */
5103 5107
5104static EMACS_INT 5108static ptrdiff_t
5105string_buffer_position (Lisp_Object string, EMACS_INT around_charpos) 5109string_buffer_position (Lisp_Object string, ptrdiff_t around_charpos)
5106{ 5110{
5107 const int MAX_DISTANCE = 1000; 5111 const int MAX_DISTANCE = 1000;
5108 EMACS_INT found = string_buffer_position_lim (string, around_charpos, 5112 ptrdiff_t found = string_buffer_position_lim (string, around_charpos,
5109 around_charpos + MAX_DISTANCE, 5113 around_charpos + MAX_DISTANCE,
5110 0); 5114 0);
5111 5115
@@ -5128,7 +5132,7 @@ static enum prop_handled
5128handle_composition_prop (struct it *it) 5132handle_composition_prop (struct it *it)
5129{ 5133{
5130 Lisp_Object prop, string; 5134 Lisp_Object prop, string;
5131 EMACS_INT pos, pos_byte, start, end; 5135 ptrdiff_t pos, pos_byte, start, end;
5132 5136
5133 if (STRINGP (it->string)) 5137 if (STRINGP (it->string))
5134 { 5138 {
@@ -5194,7 +5198,7 @@ struct overlay_entry
5194{ 5198{
5195 Lisp_Object overlay; 5199 Lisp_Object overlay;
5196 Lisp_Object string; 5200 Lisp_Object string;
5197 int priority; 5201 EMACS_INT priority;
5198 int after_string_p; 5202 int after_string_p;
5199}; 5203};
5200 5204
@@ -5326,12 +5330,17 @@ compare_overlay_entries (const void *e1, const void *e2)
5326 else 5330 else
5327 result = entry1->after_string_p ? -1 : 1; 5331 result = entry1->after_string_p ? -1 : 1;
5328 } 5332 }
5329 else if (entry1->after_string_p) 5333 else if (entry1->priority != entry2->priority)
5330 /* After-strings sorted in order of decreasing priority. */ 5334 {
5331 result = entry2->priority - entry1->priority; 5335 if (entry1->after_string_p)
5336 /* After-strings sorted in order of decreasing priority. */
5337 result = entry2->priority < entry1->priority ? -1 : 1;
5338 else
5339 /* Before-strings sorted in order of increasing priority. */
5340 result = entry1->priority < entry2->priority ? -1 : 1;
5341 }
5332 else 5342 else
5333 /* Before-strings sorted in order of increasing priority. */ 5343 result = 0;
5334 result = entry1->priority - entry2->priority;
5335 5344
5336 return result; 5345 return result;
5337} 5346}
@@ -5362,15 +5371,17 @@ compare_overlay_entries (const void *e1, const void *e2)
5362 compare_overlay_entries. */ 5371 compare_overlay_entries. */
5363 5372
5364static void 5373static void
5365load_overlay_strings (struct it *it, EMACS_INT charpos) 5374load_overlay_strings (struct it *it, ptrdiff_t charpos)
5366{ 5375{
5367 Lisp_Object overlay, window, str, invisible; 5376 Lisp_Object overlay, window, str, invisible;
5368 struct Lisp_Overlay *ov; 5377 struct Lisp_Overlay *ov;
5369 EMACS_INT start, end; 5378 ptrdiff_t start, end;
5370 int size = 20; 5379 ptrdiff_t size = 20;
5371 int n = 0, i, j, invis_p; 5380 ptrdiff_t n = 0, i, j;
5381 int invis_p;
5372 struct overlay_entry *entries 5382 struct overlay_entry *entries
5373 = (struct overlay_entry *) alloca (size * sizeof *entries); 5383 = (struct overlay_entry *) alloca (size * sizeof *entries);
5384 USE_SAFE_ALLOCA;
5374 5385
5375 if (charpos <= 0) 5386 if (charpos <= 0)
5376 charpos = IT_CHARPOS (*it); 5387 charpos = IT_CHARPOS (*it);
@@ -5386,13 +5397,10 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5386 \ 5397 \
5387 if (n == size) \ 5398 if (n == size) \
5388 { \ 5399 { \
5389 int new_size = 2 * size; \
5390 struct overlay_entry *old = entries; \ 5400 struct overlay_entry *old = entries; \
5391 entries = \ 5401 SAFE_NALLOCA (entries, 2, size); \
5392 (struct overlay_entry *) alloca (new_size \
5393 * sizeof *entries); \
5394 memcpy (entries, old, size * sizeof *entries); \ 5402 memcpy (entries, old, size * sizeof *entries); \
5395 size = new_size; \ 5403 size *= 2; \
5396 } \ 5404 } \
5397 \ 5405 \
5398 entries[n].string = (STRING); \ 5406 entries[n].string = (STRING); \
@@ -5505,6 +5513,7 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5505 } 5513 }
5506 5514
5507 CHECK_IT (it); 5515 CHECK_IT (it);
5516 SAFE_FREE ();
5508} 5517}
5509 5518
5510 5519
@@ -5513,7 +5522,7 @@ load_overlay_strings (struct it *it, EMACS_INT charpos)
5513 least one overlay string was found. */ 5522 least one overlay string was found. */
5514 5523
5515static int 5524static int
5516get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p) 5525get_overlay_strings_1 (struct it *it, ptrdiff_t charpos, int compute_stop_p)
5517{ 5526{
5518 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to 5527 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5519 process. This fills IT->overlay_strings with strings, and sets 5528 process. This fills IT->overlay_strings with strings, and sets
@@ -5577,7 +5586,7 @@ get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p)
5577 /* Set up the bidi iterator for this overlay string. */ 5586 /* Set up the bidi iterator for this overlay string. */
5578 if (it->bidi_p) 5587 if (it->bidi_p)
5579 { 5588 {
5580 EMACS_INT pos = (charpos > 0 ? charpos : IT_CHARPOS (*it)); 5589 ptrdiff_t pos = (charpos > 0 ? charpos : IT_CHARPOS (*it));
5581 5590
5582 it->bidi_it.string.lstring = it->string; 5591 it->bidi_it.string.lstring = it->string;
5583 it->bidi_it.string.s = NULL; 5592 it->bidi_it.string.s = NULL;
@@ -5595,7 +5604,7 @@ get_overlay_strings_1 (struct it *it, EMACS_INT charpos, int compute_stop_p)
5595} 5604}
5596 5605
5597static int 5606static int
5598get_overlay_strings (struct it *it, EMACS_INT charpos) 5607get_overlay_strings (struct it *it, ptrdiff_t charpos)
5599{ 5608{
5600 it->string = Qnil; 5609 it->string = Qnil;
5601 it->method = GET_FROM_BUFFER; 5610 it->method = GET_FROM_BUFFER;
@@ -5676,8 +5685,8 @@ static void
5676iterate_out_of_display_property (struct it *it) 5685iterate_out_of_display_property (struct it *it)
5677{ 5686{
5678 int buffer_p = !STRINGP (it->string); 5687 int buffer_p = !STRINGP (it->string);
5679 EMACS_INT eob = (buffer_p ? ZV : it->end_charpos); 5688 ptrdiff_t eob = (buffer_p ? ZV : it->end_charpos);
5680 EMACS_INT bob = (buffer_p ? BEGV : 0); 5689 ptrdiff_t bob = (buffer_p ? BEGV : 0);
5681 5690
5682 xassert (eob >= CHARPOS (it->position) && CHARPOS (it->position) >= bob); 5691 xassert (eob >= CHARPOS (it->position) && CHARPOS (it->position) >= bob);
5683 5692
@@ -5839,7 +5848,7 @@ static int
5839forward_to_next_line_start (struct it *it, int *skipped_p, 5848forward_to_next_line_start (struct it *it, int *skipped_p,
5840 struct bidi_it *bidi_it_prev) 5849 struct bidi_it *bidi_it_prev)
5841{ 5850{
5842 EMACS_INT old_selective; 5851 ptrdiff_t old_selective;
5843 int newline_found_p, n; 5852 int newline_found_p, n;
5844 const int MAX_NEWLINE_DISTANCE = 500; 5853 const int MAX_NEWLINE_DISTANCE = 500;
5845 5854
@@ -5881,8 +5890,8 @@ forward_to_next_line_start (struct it *it, int *skipped_p,
5881 short-cut. */ 5890 short-cut. */
5882 if (!newline_found_p) 5891 if (!newline_found_p)
5883 { 5892 {
5884 EMACS_INT start = IT_CHARPOS (*it); 5893 ptrdiff_t start = IT_CHARPOS (*it);
5885 EMACS_INT limit = find_next_newline_no_quit (start, 1); 5894 ptrdiff_t limit = find_next_newline_no_quit (start, 1);
5886 Lisp_Object pos; 5895 Lisp_Object pos;
5887 5896
5888 xassert (!STRINGP (it->string)); 5897 xassert (!STRINGP (it->string));
@@ -5980,8 +5989,8 @@ back_to_previous_visible_line_start (struct it *it)
5980 { 5989 {
5981 struct it it2; 5990 struct it it2;
5982 void *it2data = NULL; 5991 void *it2data = NULL;
5983 EMACS_INT pos; 5992 ptrdiff_t pos;
5984 EMACS_INT beg, end; 5993 ptrdiff_t beg, end;
5985 Lisp_Object val, overlay; 5994 Lisp_Object val, overlay;
5986 5995
5987 SAVE_IT (it2, *it, it2data); 5996 SAVE_IT (it2, *it, it2data);
@@ -6134,7 +6143,7 @@ reseat_at_next_visible_line_start (struct it *it, int on_newline_p)
6134static void 6143static void
6135reseat (struct it *it, struct text_pos pos, int force_p) 6144reseat (struct it *it, struct text_pos pos, int force_p)
6136{ 6145{
6137 EMACS_INT original_pos = IT_CHARPOS (*it); 6146 ptrdiff_t original_pos = IT_CHARPOS (*it);
6138 6147
6139 reseat_1 (it, pos, 0); 6148 reseat_1 (it, pos, 0);
6140 6149
@@ -6244,7 +6253,7 @@ reseat_1 (struct it *it, struct text_pos pos, int set_stop_p)
6244 6253
6245static void 6254static void
6246reseat_to_string (struct it *it, const char *s, Lisp_Object string, 6255reseat_to_string (struct it *it, const char *s, Lisp_Object string,
6247 EMACS_INT charpos, EMACS_INT precision, int field_width, 6256 ptrdiff_t charpos, ptrdiff_t precision, int field_width,
6248 int multibyte) 6257 int multibyte)
6249{ 6258{
6250 /* No region in strings. */ 6259 /* No region in strings. */
@@ -6362,7 +6371,7 @@ reseat_to_string (struct it *it, const char *s, Lisp_Object string,
6362 } 6371 }
6363 if (s == NULL && it->multibyte_p) 6372 if (s == NULL && it->multibyte_p)
6364 { 6373 {
6365 EMACS_INT endpos = SCHARS (it->string); 6374 ptrdiff_t endpos = SCHARS (it->string);
6366 if (endpos > it->end_charpos) 6375 if (endpos > it->end_charpos)
6367 endpos = it->end_charpos; 6376 endpos = it->end_charpos;
6368 composition_compute_stop_pos (&it->cmp_it, charpos, -1, endpos, 6377 composition_compute_stop_pos (&it->cmp_it, charpos, -1, endpos,
@@ -6470,11 +6479,11 @@ lookup_glyphless_char_display (int c, struct it *it)
6470 end of buffer (or C string) is reached. */ 6479 end of buffer (or C string) is reached. */
6471 6480
6472static struct frame *last_escape_glyph_frame = NULL; 6481static struct frame *last_escape_glyph_frame = NULL;
6473static unsigned last_escape_glyph_face_id = (1 << FACE_ID_BITS); 6482static int last_escape_glyph_face_id = (1 << FACE_ID_BITS);
6474static int last_escape_glyph_merged_face_id = 0; 6483static int last_escape_glyph_merged_face_id = 0;
6475 6484
6476struct frame *last_glyphless_glyph_frame = NULL; 6485struct frame *last_glyphless_glyph_frame = NULL;
6477unsigned last_glyphless_glyph_face_id = (1 << FACE_ID_BITS); 6486int last_glyphless_glyph_face_id = (1 << FACE_ID_BITS);
6478int last_glyphless_glyph_merged_face_id = 0; 6487int last_glyphless_glyph_merged_face_id = 0;
6479 6488
6480static int 6489static int
@@ -6606,7 +6615,7 @@ get_next_display_element (struct it *it)
6606 Lisp_Object gc; 6615 Lisp_Object gc;
6607 int ctl_len; 6616 int ctl_len;
6608 int face_id; 6617 int face_id;
6609 EMACS_INT lface_id = 0; 6618 int lface_id = 0;
6610 int escape_glyph; 6619 int escape_glyph;
6611 6620
6612 /* Handle control characters with ^. */ 6621 /* Handle control characters with ^. */
@@ -6618,8 +6627,7 @@ get_next_display_element (struct it *it)
6618 g = '^'; /* default glyph for Control */ 6627 g = '^'; /* default glyph for Control */
6619 /* Set IT->ctl_chars[0] to the glyph for `^'. */ 6628 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6620 if (it->dp 6629 if (it->dp
6621 && (gc = DISP_CTRL_GLYPH (it->dp), GLYPH_CODE_P (gc)) 6630 && (gc = DISP_CTRL_GLYPH (it->dp), GLYPH_CODE_P (gc)))
6622 && GLYPH_CODE_CHAR_VALID_P (gc))
6623 { 6631 {
6624 g = GLYPH_CODE_CHAR (gc); 6632 g = GLYPH_CODE_CHAR (gc);
6625 lface_id = GLYPH_CODE_FACE (gc); 6633 lface_id = GLYPH_CODE_FACE (gc);
@@ -6668,8 +6676,7 @@ get_next_display_element (struct it *it)
6668 escape_glyph = '\\'; 6676 escape_glyph = '\\';
6669 6677
6670 if (it->dp 6678 if (it->dp
6671 && (gc = DISP_ESCAPE_GLYPH (it->dp), GLYPH_CODE_P (gc)) 6679 && (gc = DISP_ESCAPE_GLYPH (it->dp), GLYPH_CODE_P (gc)))
6672 && GLYPH_CODE_CHAR_VALID_P (gc))
6673 { 6680 {
6674 escape_glyph = GLYPH_CODE_CHAR (gc); 6681 escape_glyph = GLYPH_CODE_CHAR (gc);
6675 lface_id = GLYPH_CODE_FACE (gc); 6682 lface_id = GLYPH_CODE_FACE (gc);
@@ -6768,7 +6775,7 @@ get_next_display_element (struct it *it)
6768 } 6775 }
6769 else 6776 else
6770 { 6777 {
6771 EMACS_INT pos = (it->s ? -1 6778 ptrdiff_t pos = (it->s ? -1
6772 : STRINGP (it->string) ? IT_STRING_CHARPOS (*it) 6779 : STRINGP (it->string) ? IT_STRING_CHARPOS (*it)
6773 : IT_CHARPOS (*it)); 6780 : IT_CHARPOS (*it));
6774 int c; 6781 int c;
@@ -6820,7 +6827,7 @@ get_next_display_element (struct it *it)
6820 && (it->current.overlay_string_index 6827 && (it->current.overlay_string_index
6821 == it->n_overlay_strings - 1)) 6828 == it->n_overlay_strings - 1))
6822 { 6829 {
6823 EMACS_INT ignore; 6830 ptrdiff_t ignore;
6824 int next_face_id; 6831 int next_face_id;
6825 struct text_pos pos = it->current.pos; 6832 struct text_pos pos = it->current.pos;
6826 INC_TEXT_POS (pos, it->multibyte_p); 6833 INC_TEXT_POS (pos, it->multibyte_p);
@@ -6932,7 +6939,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6932 { 6939 {
6933 /* No more grapheme clusters in this composition. 6940 /* No more grapheme clusters in this composition.
6934 Find the next stop position. */ 6941 Find the next stop position. */
6935 EMACS_INT stop = it->end_charpos; 6942 ptrdiff_t stop = it->end_charpos;
6936 if (it->bidi_it.scan_dir < 0) 6943 if (it->bidi_it.scan_dir < 0)
6937 /* Now we are scanning backward and don't know 6944 /* Now we are scanning backward and don't know
6938 where to stop. */ 6945 where to stop. */
@@ -6960,7 +6967,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6960 { 6967 {
6961 /* No more grapheme clusters in this composition. 6968 /* No more grapheme clusters in this composition.
6962 Find the next stop position. */ 6969 Find the next stop position. */
6963 EMACS_INT stop = it->end_charpos; 6970 ptrdiff_t stop = it->end_charpos;
6964 if (it->bidi_it.scan_dir < 0) 6971 if (it->bidi_it.scan_dir < 0)
6965 /* Now we are scanning backward and don't know 6972 /* Now we are scanning backward and don't know
6966 where to stop. */ 6973 where to stop. */
@@ -6993,7 +7000,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6993 { 7000 {
6994 /* As the scan direction was changed, we must 7001 /* As the scan direction was changed, we must
6995 re-compute the stop position for composition. */ 7002 re-compute the stop position for composition. */
6996 EMACS_INT stop = it->end_charpos; 7003 ptrdiff_t stop = it->end_charpos;
6997 if (it->bidi_it.scan_dir < 0) 7004 if (it->bidi_it.scan_dir < 0)
6998 stop = -1; 7005 stop = -1;
6999 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it), 7006 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
@@ -7123,7 +7130,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7123 it->cmp_it.from = it->cmp_it.to; 7130 it->cmp_it.from = it->cmp_it.to;
7124 else 7131 else
7125 { 7132 {
7126 EMACS_INT stop = it->end_charpos; 7133 ptrdiff_t stop = it->end_charpos;
7127 if (it->bidi_it.scan_dir < 0) 7134 if (it->bidi_it.scan_dir < 0)
7128 stop = -1; 7135 stop = -1;
7129 composition_compute_stop_pos (&it->cmp_it, 7136 composition_compute_stop_pos (&it->cmp_it,
@@ -7142,7 +7149,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7142 it->cmp_it.to = it->cmp_it.from; 7149 it->cmp_it.to = it->cmp_it.from;
7143 else 7150 else
7144 { 7151 {
7145 EMACS_INT stop = it->end_charpos; 7152 ptrdiff_t stop = it->end_charpos;
7146 if (it->bidi_it.scan_dir < 0) 7153 if (it->bidi_it.scan_dir < 0)
7147 stop = -1; 7154 stop = -1;
7148 composition_compute_stop_pos (&it->cmp_it, 7155 composition_compute_stop_pos (&it->cmp_it,
@@ -7174,7 +7181,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
7174 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos; 7181 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos;
7175 if (prev_scan_dir != it->bidi_it.scan_dir) 7182 if (prev_scan_dir != it->bidi_it.scan_dir)
7176 { 7183 {
7177 EMACS_INT stop = it->end_charpos; 7184 ptrdiff_t stop = it->end_charpos;
7178 7185
7179 if (it->bidi_it.scan_dir < 0) 7186 if (it->bidi_it.scan_dir < 0)
7180 stop = -1; 7187 stop = -1;
@@ -7260,7 +7267,7 @@ next_element_from_display_vector (struct it *it)
7260 That seemed totally bogus - so I changed it... */ 7267 That seemed totally bogus - so I changed it... */
7261 gc = it->dpvec[it->current.dpvec_index]; 7268 gc = it->dpvec[it->current.dpvec_index];
7262 7269
7263 if (GLYPH_CODE_P (gc) && GLYPH_CODE_CHAR_VALID_P (gc)) 7270 if (GLYPH_CODE_P (gc))
7264 { 7271 {
7265 it->c = GLYPH_CODE_CHAR (gc); 7272 it->c = GLYPH_CODE_CHAR (gc);
7266 it->len = CHAR_BYTES (it->c); 7273 it->len = CHAR_BYTES (it->c);
@@ -7272,7 +7279,7 @@ next_element_from_display_vector (struct it *it)
7272 it->face_id = it->dpvec_face_id; 7279 it->face_id = it->dpvec_face_id;
7273 else 7280 else
7274 { 7281 {
7275 EMACS_INT lface_id = GLYPH_CODE_FACE (gc); 7282 int lface_id = GLYPH_CODE_FACE (gc);
7276 if (lface_id > 0) 7283 if (lface_id > 0)
7277 it->face_id = merge_faces (it->f, Qt, lface_id, 7284 it->face_id = merge_faces (it->f, Qt, lface_id,
7278 it->saved_face_id); 7285 it->saved_face_id);
@@ -7295,8 +7302,8 @@ static void
7295get_visually_first_element (struct it *it) 7302get_visually_first_element (struct it *it)
7296{ 7303{
7297 int string_p = STRINGP (it->string) || it->s; 7304 int string_p = STRINGP (it->string) || it->s;
7298 EMACS_INT eob = (string_p ? it->bidi_it.string.schars : ZV); 7305 ptrdiff_t eob = (string_p ? it->bidi_it.string.schars : ZV);
7299 EMACS_INT bob = (string_p ? 0 : BEGV); 7306 ptrdiff_t bob = (string_p ? 0 : BEGV);
7300 7307
7301 if (STRINGP (it->string)) 7308 if (STRINGP (it->string))
7302 { 7309 {
@@ -7328,7 +7335,7 @@ get_visually_first_element (struct it *it)
7328 } 7335 }
7329 else 7336 else
7330 { 7337 {
7331 EMACS_INT orig_bytepos = it->bidi_it.bytepos; 7338 ptrdiff_t orig_bytepos = it->bidi_it.bytepos;
7332 7339
7333 /* We need to prime the bidi iterator starting at the line's or 7340 /* We need to prime the bidi iterator starting at the line's or
7334 string's beginning, before we will be able to produce the 7341 string's beginning, before we will be able to produce the
@@ -7366,7 +7373,7 @@ get_visually_first_element (struct it *it)
7366 7373
7367 if (STRINGP (it->string) || !it->s) 7374 if (STRINGP (it->string) || !it->s)
7368 { 7375 {
7369 EMACS_INT stop, charpos, bytepos; 7376 ptrdiff_t stop, charpos, bytepos;
7370 7377
7371 if (STRINGP (it->string)) 7378 if (STRINGP (it->string))
7372 { 7379 {
@@ -7667,10 +7674,10 @@ compute_stop_pos_backwards (struct it *it)
7667 struct text_pos pos; 7674 struct text_pos pos;
7668 struct display_pos save_current = it->current; 7675 struct display_pos save_current = it->current;
7669 struct text_pos save_position = it->position; 7676 struct text_pos save_position = it->position;
7670 EMACS_INT charpos = IT_CHARPOS (*it); 7677 ptrdiff_t charpos = IT_CHARPOS (*it);
7671 EMACS_INT where_we_are = charpos; 7678 ptrdiff_t where_we_are = charpos;
7672 EMACS_INT save_stop_pos = it->stop_charpos; 7679 ptrdiff_t save_stop_pos = it->stop_charpos;
7673 EMACS_INT save_end_pos = it->end_charpos; 7680 ptrdiff_t save_end_pos = it->end_charpos;
7674 7681
7675 xassert (NILP (it->string) && !it->s); 7682 xassert (NILP (it->string) && !it->s);
7676 xassert (it->bidi_p); 7683 xassert (it->bidi_p);
@@ -7708,14 +7715,14 @@ compute_stop_pos_backwards (struct it *it)
7708 position. */ 7715 position. */
7709 7716
7710static void 7717static void
7711handle_stop_backwards (struct it *it, EMACS_INT charpos) 7718handle_stop_backwards (struct it *it, ptrdiff_t charpos)
7712{ 7719{
7713 int bufp = !STRINGP (it->string); 7720 int bufp = !STRINGP (it->string);
7714 EMACS_INT where_we_are = (bufp ? IT_CHARPOS (*it) : IT_STRING_CHARPOS (*it)); 7721 ptrdiff_t where_we_are = (bufp ? IT_CHARPOS (*it) : IT_STRING_CHARPOS (*it));
7715 struct display_pos save_current = it->current; 7722 struct display_pos save_current = it->current;
7716 struct text_pos save_position = it->position; 7723 struct text_pos save_position = it->position;
7717 struct text_pos pos1; 7724 struct text_pos pos1;
7718 EMACS_INT next_stop; 7725 ptrdiff_t next_stop;
7719 7726
7720 /* Scan in strict logical order. */ 7727 /* Scan in strict logical order. */
7721 xassert (it->bidi_p); 7728 xassert (it->bidi_p);
@@ -7859,7 +7866,7 @@ next_element_from_buffer (struct it *it)
7859 /* No face changes, overlays etc. in sight, so just return a 7866 /* No face changes, overlays etc. in sight, so just return a
7860 character from current_buffer. */ 7867 character from current_buffer. */
7861 unsigned char *p; 7868 unsigned char *p;
7862 EMACS_INT stop; 7869 ptrdiff_t stop;
7863 7870
7864 /* Maybe run the redisplay end trigger hook. Performance note: 7871 /* Maybe run the redisplay end trigger hook. Performance note:
7865 This doesn't seem to cost measurable time. */ 7872 This doesn't seem to cost measurable time. */
@@ -8048,7 +8055,7 @@ next_element_from_composition (struct it *it)
8048 8055
8049static enum move_it_result 8056static enum move_it_result
8050move_it_in_display_line_to (struct it *it, 8057move_it_in_display_line_to (struct it *it,
8051 EMACS_INT to_charpos, int to_x, 8058 ptrdiff_t to_charpos, int to_x,
8052 enum move_operation_enum op) 8059 enum move_operation_enum op)
8053{ 8060{
8054 enum move_it_result result = MOVE_UNDEFINED; 8061 enum move_it_result result = MOVE_UNDEFINED;
@@ -8058,7 +8065,7 @@ move_it_in_display_line_to (struct it *it,
8058 void *ppos_data = NULL; 8065 void *ppos_data = NULL;
8059 int may_wrap = 0; 8066 int may_wrap = 0;
8060 enum it_method prev_method = it->method; 8067 enum it_method prev_method = it->method;
8061 EMACS_INT prev_pos = IT_CHARPOS (*it); 8068 ptrdiff_t prev_pos = IT_CHARPOS (*it);
8062 int saw_smaller_pos = prev_pos < to_charpos; 8069 int saw_smaller_pos = prev_pos < to_charpos;
8063 8070
8064 /* Don't produce glyphs in produce_glyphs. */ 8071 /* Don't produce glyphs in produce_glyphs. */
@@ -8552,7 +8559,7 @@ move_it_in_display_line_to (struct it *it,
8552/* For external use. */ 8559/* For external use. */
8553void 8560void
8554move_it_in_display_line (struct it *it, 8561move_it_in_display_line (struct it *it,
8555 EMACS_INT to_charpos, int to_x, 8562 ptrdiff_t to_charpos, int to_x,
8556 enum move_operation_enum op) 8563 enum move_operation_enum op)
8557{ 8564{
8558 if (it->line_wrap == WORD_WRAP 8565 if (it->line_wrap == WORD_WRAP
@@ -8595,7 +8602,7 @@ move_it_in_display_line (struct it *it,
8595 displayed to the right of TO_CHARPOS on the screen. */ 8602 displayed to the right of TO_CHARPOS on the screen. */
8596 8603
8597void 8604void
8598move_it_to (struct it *it, EMACS_INT to_charpos, int to_x, int to_y, int to_vpos, int op) 8605move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos, int op)
8599{ 8606{
8600 enum move_it_result skip, skip2 = MOVE_X_REACHED; 8607 enum move_it_result skip, skip2 = MOVE_X_REACHED;
8601 int line_height, line_start_x = 0, reached = 0; 8608 int line_height, line_start_x = 0, reached = 0;
@@ -8699,8 +8706,18 @@ move_it_to (struct it *it, EMACS_INT to_charpos, int to_x, int to_y, int to_vpos
8699 { 8706 {
8700 /* If TO_Y is in this line and TO_X was reached 8707 /* If TO_Y is in this line and TO_X was reached
8701 above, we scanned too far. We have to restore 8708 above, we scanned too far. We have to restore
8702 IT's settings to the ones before skipping. */ 8709 IT's settings to the ones before skipping. But
8710 keep the more accurate values of max_ascent and
8711 max_descent we've found while skipping the rest
8712 of the line, for the sake of callers, such as
8713 pos_visible_p, that need to know the line
8714 height. */
8715 int max_ascent = it->max_ascent;
8716 int max_descent = it->max_descent;
8717
8703 RESTORE_IT (it, &it_backup, backup_data); 8718 RESTORE_IT (it, &it_backup, backup_data);
8719 it->max_ascent = max_ascent;
8720 it->max_descent = max_descent;
8704 reached = 6; 8721 reached = 6;
8705 } 8722 }
8706 else 8723 else
@@ -8862,7 +8879,7 @@ move_it_vertically_backward (struct it *it, int dy)
8862 int nlines, h; 8879 int nlines, h;
8863 struct it it2, it3; 8880 struct it it2, it3;
8864 void *it2data = NULL, *it3data = NULL; 8881 void *it2data = NULL, *it3data = NULL;
8865 EMACS_INT start_pos; 8882 ptrdiff_t start_pos;
8866 8883
8867 move_further_back: 8884 move_further_back:
8868 xassert (dy >= 0); 8885 xassert (dy >= 0);
@@ -8944,7 +8961,7 @@ move_it_vertically_backward (struct it *it, int dy)
8944 && IT_CHARPOS (*it) > BEGV 8961 && IT_CHARPOS (*it) > BEGV
8945 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n') 8962 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
8946 { 8963 {
8947 EMACS_INT nl_pos = 8964 ptrdiff_t nl_pos =
8948 find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1); 8965 find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1);
8949 8966
8950 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS); 8967 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS);
@@ -9054,7 +9071,7 @@ move_it_past_eol (struct it *it)
9054 truncate-lines nil. */ 9071 truncate-lines nil. */
9055 9072
9056void 9073void
9057move_it_by_lines (struct it *it, int dvpos) 9074move_it_by_lines (struct it *it, ptrdiff_t dvpos)
9058{ 9075{
9059 9076
9060 /* The commented-out optimization uses vmotion on terminals. This 9077 /* The commented-out optimization uses vmotion on terminals. This
@@ -9103,7 +9120,7 @@ move_it_by_lines (struct it *it, int dvpos)
9103 { 9120 {
9104 struct it it2; 9121 struct it it2;
9105 void *it2data = NULL; 9122 void *it2data = NULL;
9106 EMACS_INT start_charpos, i; 9123 ptrdiff_t start_charpos, i;
9107 9124
9108 /* Start at the beginning of the screen line containing IT's 9125 /* Start at the beginning of the screen line containing IT's
9109 position. This may actually move vertically backwards, 9126 position. This may actually move vertically backwards,
@@ -9189,7 +9206,7 @@ add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
9189 Lisp_Object args[3]; 9206 Lisp_Object args[3];
9190 Lisp_Object msg, fmt; 9207 Lisp_Object msg, fmt;
9191 char *buffer; 9208 char *buffer;
9192 EMACS_INT len; 9209 ptrdiff_t len;
9193 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 9210 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9194 USE_SAFE_ALLOCA; 9211 USE_SAFE_ALLOCA;
9195 9212
@@ -9238,7 +9255,7 @@ message_log_maybe_newline (void)
9238 so the buffer M must NOT point to a Lisp string. */ 9255 so the buffer M must NOT point to a Lisp string. */
9239 9256
9240void 9257void
9241message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) 9258message_dolog (const char *m, ptrdiff_t nbytes, int nlflag, int multibyte)
9242{ 9259{
9243 const unsigned char *msg = (const unsigned char *) m; 9260 const unsigned char *msg = (const unsigned char *) m;
9244 9261
@@ -9250,8 +9267,8 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9250 struct buffer *oldbuf; 9267 struct buffer *oldbuf;
9251 Lisp_Object oldpoint, oldbegv, oldzv; 9268 Lisp_Object oldpoint, oldbegv, oldzv;
9252 int old_windows_or_buffers_changed = windows_or_buffers_changed; 9269 int old_windows_or_buffers_changed = windows_or_buffers_changed;
9253 EMACS_INT point_at_end = 0; 9270 ptrdiff_t point_at_end = 0;
9254 EMACS_INT zv_at_end = 0; 9271 ptrdiff_t zv_at_end = 0;
9255 Lisp_Object old_deactivate_mark, tem; 9272 Lisp_Object old_deactivate_mark, tem;
9256 struct gcpro gcpro1; 9273 struct gcpro gcpro1;
9257 9274
@@ -9284,7 +9301,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9284 if (multibyte 9301 if (multibyte
9285 && NILP (BVAR (current_buffer, enable_multibyte_characters))) 9302 && NILP (BVAR (current_buffer, enable_multibyte_characters)))
9286 { 9303 {
9287 EMACS_INT i; 9304 ptrdiff_t i;
9288 int c, char_bytes; 9305 int c, char_bytes;
9289 char work[1]; 9306 char work[1];
9290 9307
@@ -9302,7 +9319,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9302 else if (! multibyte 9319 else if (! multibyte
9303 && ! NILP (BVAR (current_buffer, enable_multibyte_characters))) 9320 && ! NILP (BVAR (current_buffer, enable_multibyte_characters)))
9304 { 9321 {
9305 EMACS_INT i; 9322 ptrdiff_t i;
9306 int c, char_bytes; 9323 int c, char_bytes;
9307 unsigned char str[MAX_MULTIBYTE_LENGTH]; 9324 unsigned char str[MAX_MULTIBYTE_LENGTH];
9308 /* Convert a single-byte string to multibyte 9325 /* Convert a single-byte string to multibyte
@@ -9320,7 +9337,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9320 9337
9321 if (nlflag) 9338 if (nlflag)
9322 { 9339 {
9323 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; 9340 ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte;
9324 printmax_t dups; 9341 printmax_t dups;
9325 insert_1 ("\n", 1, 1, 0, 0); 9342 insert_1 ("\n", 1, 1, 0, 0);
9326 9343
@@ -9413,10 +9430,10 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
9413 value N > 1 if we should also append " [N times]". */ 9430 value N > 1 if we should also append " [N times]". */
9414 9431
9415static intmax_t 9432static intmax_t
9416message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) 9433message_log_check_duplicate (ptrdiff_t prev_bol_byte, ptrdiff_t this_bol_byte)
9417{ 9434{
9418 EMACS_INT i; 9435 ptrdiff_t i;
9419 EMACS_INT len = Z_BYTE - 1 - this_bol_byte; 9436 ptrdiff_t len = Z_BYTE - 1 - this_bol_byte;
9420 int seen_dots = 0; 9437 int seen_dots = 0;
9421 unsigned char *p1 = BUF_BYTE_ADDRESS (current_buffer, prev_bol_byte); 9438 unsigned char *p1 = BUF_BYTE_ADDRESS (current_buffer, prev_bol_byte);
9422 unsigned char *p2 = BUF_BYTE_ADDRESS (current_buffer, this_bol_byte); 9439 unsigned char *p2 = BUF_BYTE_ADDRESS (current_buffer, this_bol_byte);
@@ -9450,7 +9467,7 @@ message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte)
9450 This may GC, so the buffer M must NOT point to a Lisp string. */ 9467 This may GC, so the buffer M must NOT point to a Lisp string. */
9451 9468
9452void 9469void
9453message2 (const char *m, EMACS_INT nbytes, int multibyte) 9470message2 (const char *m, ptrdiff_t nbytes, int multibyte)
9454{ 9471{
9455 /* First flush out any partial line written with print. */ 9472 /* First flush out any partial line written with print. */
9456 message_log_maybe_newline (); 9473 message_log_maybe_newline ();
@@ -9463,7 +9480,7 @@ message2 (const char *m, EMACS_INT nbytes, int multibyte)
9463/* The non-logging counterpart of message2. */ 9480/* The non-logging counterpart of message2. */
9464 9481
9465void 9482void
9466message2_nolog (const char *m, EMACS_INT nbytes, int multibyte) 9483message2_nolog (const char *m, ptrdiff_t nbytes, int multibyte)
9467{ 9484{
9468 struct frame *sf = SELECTED_FRAME (); 9485 struct frame *sf = SELECTED_FRAME ();
9469 message_enable_multibyte = multibyte; 9486 message_enable_multibyte = multibyte;
@@ -9525,7 +9542,7 @@ message2_nolog (const char *m, EMACS_INT nbytes, int multibyte)
9525 This function cancels echoing. */ 9542 This function cancels echoing. */
9526 9543
9527void 9544void
9528message3 (Lisp_Object m, EMACS_INT nbytes, int multibyte) 9545message3 (Lisp_Object m, ptrdiff_t nbytes, int multibyte)
9529{ 9546{
9530 struct gcpro gcpro1; 9547 struct gcpro gcpro1;
9531 9548
@@ -9557,7 +9574,7 @@ message3 (Lisp_Object m, EMACS_INT nbytes, int multibyte)
9557 and make this cancel echoing. */ 9574 and make this cancel echoing. */
9558 9575
9559void 9576void
9560message3_nolog (Lisp_Object m, EMACS_INT nbytes, int multibyte) 9577message3_nolog (Lisp_Object m, ptrdiff_t nbytes, int multibyte)
9561{ 9578{
9562 struct frame *sf = SELECTED_FRAME (); 9579 struct frame *sf = SELECTED_FRAME ();
9563 message_enable_multibyte = multibyte; 9580 message_enable_multibyte = multibyte;
@@ -9854,12 +9871,12 @@ ensure_echo_area_buffers (void)
9854 9871
9855static int 9872static int
9856with_echo_area_buffer (struct window *w, int which, 9873with_echo_area_buffer (struct window *w, int which,
9857 int (*fn) (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT), 9874 int (*fn) (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t),
9858 EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 9875 ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
9859{ 9876{
9860 Lisp_Object buffer; 9877 Lisp_Object buffer;
9861 int this_one, the_other, clear_buffer_p, rc; 9878 int this_one, the_other, clear_buffer_p, rc;
9862 int count = SPECPDL_INDEX (); 9879 ptrdiff_t count = SPECPDL_INDEX ();
9863 9880
9864 /* If buffers aren't live, make new ones. */ 9881 /* If buffers aren't live, make new ones. */
9865 ensure_echo_area_buffers (); 9882 ensure_echo_area_buffers ();
@@ -10035,7 +10052,7 @@ setup_echo_area_for_printing (int multibyte_p)
10035 10052
10036 if (Z > BEG) 10053 if (Z > BEG)
10037 { 10054 {
10038 int count = SPECPDL_INDEX (); 10055 ptrdiff_t count = SPECPDL_INDEX ();
10039 specbind (Qinhibit_read_only, Qt); 10056 specbind (Qinhibit_read_only, Qt);
10040 /* Note that undo recording is always disabled. */ 10057 /* Note that undo recording is always disabled. */
10041 del_range (BEG, Z); 10058 del_range (BEG, Z);
@@ -10088,14 +10105,14 @@ setup_echo_area_for_printing (int multibyte_p)
10088static int 10105static int
10089display_echo_area (struct window *w) 10106display_echo_area (struct window *w)
10090{ 10107{
10091 int i, no_message_p, window_height_changed_p, count; 10108 int i, no_message_p, window_height_changed_p;
10092 10109
10093 /* Temporarily disable garbage collections while displaying the echo 10110 /* Temporarily disable garbage collections while displaying the echo
10094 area. This is done because a GC can print a message itself. 10111 area. This is done because a GC can print a message itself.
10095 That message would modify the echo area buffer's contents while a 10112 That message would modify the echo area buffer's contents while a
10096 redisplay of the buffer is going on, and seriously confuse 10113 redisplay of the buffer is going on, and seriously confuse
10097 redisplay. */ 10114 redisplay. */
10098 count = inhibit_garbage_collection (); 10115 ptrdiff_t count = inhibit_garbage_collection ();
10099 10116
10100 /* If there is no message, we must call display_echo_area_1 10117 /* If there is no message, we must call display_echo_area_1
10101 nevertheless because it resizes the window. But we will have to 10118 nevertheless because it resizes the window. But we will have to
@@ -10124,7 +10141,7 @@ display_echo_area (struct window *w)
10124 Value is non-zero if height of W was changed. */ 10141 Value is non-zero if height of W was changed. */
10125 10142
10126static int 10143static int
10127display_echo_area_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10144display_echo_area_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10128{ 10145{
10129 intptr_t i1 = a1; 10146 intptr_t i1 = a1;
10130 struct window *w = (struct window *) i1; 10147 struct window *w = (struct window *) i1;
@@ -10188,7 +10205,7 @@ resize_echo_area_exactly (void)
10188 resize_mini_window returns. */ 10205 resize_mini_window returns. */
10189 10206
10190static int 10207static int
10191resize_mini_window_1 (EMACS_INT a1, Lisp_Object exactly, EMACS_INT a3, EMACS_INT a4) 10208resize_mini_window_1 (ptrdiff_t a1, Lisp_Object exactly, ptrdiff_t a3, ptrdiff_t a4)
10192{ 10209{
10193 intptr_t i1 = a1; 10210 intptr_t i1 = a1;
10194 return resize_mini_window ((struct window *) i1, !NILP (exactly)); 10211 return resize_mini_window ((struct window *) i1, !NILP (exactly));
@@ -10238,7 +10255,8 @@ resize_mini_window (struct window *w, int exact_p)
10238 struct it it; 10255 struct it it;
10239 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f)); 10256 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
10240 int total_height = WINDOW_TOTAL_LINES (root) + WINDOW_TOTAL_LINES (w); 10257 int total_height = WINDOW_TOTAL_LINES (root) + WINDOW_TOTAL_LINES (w);
10241 int height, max_height; 10258 int height;
10259 EMACS_INT max_height;
10242 int unit = FRAME_LINE_HEIGHT (f); 10260 int unit = FRAME_LINE_HEIGHT (f);
10243 struct text_pos start; 10261 struct text_pos start;
10244 struct buffer *old_current_buffer = NULL; 10262 struct buffer *old_current_buffer = NULL;
@@ -10367,7 +10385,7 @@ current_message (void)
10367 10385
10368 10386
10369static int 10387static int
10370current_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10388current_message_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10371{ 10389{
10372 intptr_t i1 = a1; 10390 intptr_t i1 = a1;
10373 Lisp_Object *msg = (Lisp_Object *) i1; 10391 Lisp_Object *msg = (Lisp_Object *) i1;
@@ -10446,7 +10464,7 @@ check_message_stack (void)
10446 time we display it---but don't redisplay it now. */ 10464 time we display it---but don't redisplay it now. */
10447 10465
10448void 10466void
10449truncate_echo_area (EMACS_INT nchars) 10467truncate_echo_area (ptrdiff_t nchars)
10450{ 10468{
10451 if (nchars == 0) 10469 if (nchars == 0)
10452 echo_area_buffer[0] = Qnil; 10470 echo_area_buffer[0] = Qnil;
@@ -10468,7 +10486,7 @@ truncate_echo_area (EMACS_INT nchars)
10468 message to at most NCHARS characters. */ 10486 message to at most NCHARS characters. */
10469 10487
10470static int 10488static int
10471truncate_message_1 (EMACS_INT nchars, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 10489truncate_message_1 (ptrdiff_t nchars, Lisp_Object a2, ptrdiff_t a3, ptrdiff_t a4)
10472{ 10490{
10473 if (BEG + nchars < Z) 10491 if (BEG + nchars < Z)
10474 del_range (BEG + nchars, Z); 10492 del_range (BEG + nchars, Z);
@@ -10494,7 +10512,7 @@ truncate_message_1 (EMACS_INT nchars, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4
10494 10512
10495static void 10513static void
10496set_message (const char *s, Lisp_Object string, 10514set_message (const char *s, Lisp_Object string,
10497 EMACS_INT nbytes, int multibyte_p) 10515 ptrdiff_t nbytes, int multibyte_p)
10498{ 10516{
10499 message_enable_multibyte 10517 message_enable_multibyte
10500 = ((s && multibyte_p) 10518 = ((s && multibyte_p)
@@ -10513,7 +10531,7 @@ set_message (const char *s, Lisp_Object string,
10513 current. */ 10531 current. */
10514 10532
10515static int 10533static int
10516set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multibyte_p) 10534set_message_1 (ptrdiff_t a1, Lisp_Object a2, ptrdiff_t nbytes, ptrdiff_t multibyte_p)
10517{ 10535{
10518 intptr_t i1 = a1; 10536 intptr_t i1 = a1;
10519 const char *s = (const char *) i1; 10537 const char *s = (const char *) i1;
@@ -10534,7 +10552,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10534 10552
10535 if (STRINGP (string)) 10553 if (STRINGP (string))
10536 { 10554 {
10537 EMACS_INT nchars; 10555 ptrdiff_t nchars;
10538 10556
10539 if (nbytes == 0) 10557 if (nbytes == 0)
10540 nbytes = SBYTES (string); 10558 nbytes = SBYTES (string);
@@ -10553,7 +10571,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10553 if (multibyte_p && NILP (BVAR (current_buffer, enable_multibyte_characters))) 10571 if (multibyte_p && NILP (BVAR (current_buffer, enable_multibyte_characters)))
10554 { 10572 {
10555 /* Convert from multi-byte to single-byte. */ 10573 /* Convert from multi-byte to single-byte. */
10556 EMACS_INT i; 10574 ptrdiff_t i;
10557 int c, n; 10575 int c, n;
10558 char work[1]; 10576 char work[1];
10559 10577
@@ -10571,7 +10589,7 @@ set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multiby
10571 && !NILP (BVAR (current_buffer, enable_multibyte_characters))) 10589 && !NILP (BVAR (current_buffer, enable_multibyte_characters)))
10572 { 10590 {
10573 /* Convert from single-byte to multi-byte. */ 10591 /* Convert from single-byte to multi-byte. */
10574 EMACS_INT i; 10592 ptrdiff_t i;
10575 int c, n; 10593 int c, n;
10576 unsigned char str[MAX_MULTIBYTE_LENGTH]; 10594 unsigned char str[MAX_MULTIBYTE_LENGTH];
10577 10595
@@ -10716,7 +10734,7 @@ echo_area_display (int update_frame_p)
10716 /* Must update other windows. Likewise as in other 10734 /* Must update other windows. Likewise as in other
10717 cases, don't let this update be interrupted by 10735 cases, don't let this update be interrupted by
10718 pending input. */ 10736 pending input. */
10719 int count = SPECPDL_INDEX (); 10737 ptrdiff_t count = SPECPDL_INDEX ();
10720 specbind (Qredisplay_dont_pause, Qt); 10738 specbind (Qredisplay_dont_pause, Qt);
10721 windows_or_buffers_changed = 1; 10739 windows_or_buffers_changed = 1;
10722 redisplay_internal (); 10740 redisplay_internal ();
@@ -10893,7 +10911,7 @@ store_mode_line_noprop (const char *string, int field_width, int precision)
10893{ 10911{
10894 const unsigned char *str = (const unsigned char *) string; 10912 const unsigned char *str = (const unsigned char *) string;
10895 int n = 0; 10913 int n = 0;
10896 EMACS_INT dummy, nbytes; 10914 ptrdiff_t dummy, nbytes;
10897 10915
10898 /* Copy at most PRECISION chars from STR. */ 10916 /* Copy at most PRECISION chars from STR. */
10899 nbytes = strlen (string); 10917 nbytes = strlen (string);
@@ -10938,7 +10956,7 @@ x_consider_frame_title (Lisp_Object frame)
10938 char *title; 10956 char *title;
10939 ptrdiff_t len; 10957 ptrdiff_t len;
10940 struct it it; 10958 struct it it;
10941 int count = SPECPDL_INDEX (); 10959 ptrdiff_t count = SPECPDL_INDEX ();
10942 10960
10943 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) 10961 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
10944 { 10962 {
@@ -11041,7 +11059,7 @@ prepare_menu_bars (void)
11041 if (all_windows) 11059 if (all_windows)
11042 { 11060 {
11043 Lisp_Object tail, frame; 11061 Lisp_Object tail, frame;
11044 int count = SPECPDL_INDEX (); 11062 ptrdiff_t count = SPECPDL_INDEX ();
11045 /* 1 means that update_menu_bar has run its hooks 11063 /* 1 means that update_menu_bar has run its hooks
11046 so any further calls to update_menu_bar shouldn't do so again. */ 11064 so any further calls to update_menu_bar shouldn't do so again. */
11047 int menu_bar_hooks_run = 0; 11065 int menu_bar_hooks_run = 0;
@@ -11152,13 +11170,13 @@ update_menu_bar (struct frame *f, int save_match_data, int hooks_run)
11152 || update_mode_lines 11170 || update_mode_lines
11153 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer)) 11171 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
11154 < BUF_MODIFF (XBUFFER (w->buffer))) 11172 < BUF_MODIFF (XBUFFER (w->buffer)))
11155 != !NILP (w->last_had_star)) 11173 != w->last_had_star)
11156 || ((!NILP (Vtransient_mark_mode) 11174 || ((!NILP (Vtransient_mark_mode)
11157 && !NILP (BVAR (XBUFFER (w->buffer), mark_active))) 11175 && !NILP (BVAR (XBUFFER (w->buffer), mark_active)))
11158 != !NILP (w->region_showing))) 11176 != !NILP (w->region_showing)))
11159 { 11177 {
11160 struct buffer *prev = current_buffer; 11178 struct buffer *prev = current_buffer;
11161 int count = SPECPDL_INDEX (); 11179 ptrdiff_t count = SPECPDL_INDEX ();
11162 11180
11163 specbind (Qinhibit_menubar_update, Qt); 11181 specbind (Qinhibit_menubar_update, Qt);
11164 11182
@@ -11204,11 +11222,11 @@ update_menu_bar (struct frame *f, int save_match_data, int hooks_run)
11204 else 11222 else
11205 /* On a terminal screen, the menu bar is an ordinary screen 11223 /* On a terminal screen, the menu bar is an ordinary screen
11206 line, and this makes it get updated. */ 11224 line, and this makes it get updated. */
11207 w->update_mode_line = Qt; 11225 w->update_mode_line = 1;
11208#else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */ 11226#else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11209 /* In the non-toolkit version, the menu bar is an ordinary screen 11227 /* In the non-toolkit version, the menu bar is an ordinary screen
11210 line, and this makes it get updated. */ 11228 line, and this makes it get updated. */
11211 w->update_mode_line = Qt; 11229 w->update_mode_line = 1;
11212#endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */ 11230#endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11213 11231
11214 unbind_to (count, Qnil); 11232 unbind_to (count, Qnil);
@@ -11346,17 +11364,17 @@ update_tool_bar (struct frame *f, int save_match_data)
11346 the rest of the redisplay algorithm is about the same as 11364 the rest of the redisplay algorithm is about the same as
11347 windows_or_buffers_changed anyway. */ 11365 windows_or_buffers_changed anyway. */
11348 if (windows_or_buffers_changed 11366 if (windows_or_buffers_changed
11349 || !NILP (w->update_mode_line) 11367 || w->update_mode_line
11350 || update_mode_lines 11368 || update_mode_lines
11351 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer)) 11369 || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer))
11352 < BUF_MODIFF (XBUFFER (w->buffer))) 11370 < BUF_MODIFF (XBUFFER (w->buffer)))
11353 != !NILP (w->last_had_star)) 11371 != w->last_had_star)
11354 || ((!NILP (Vtransient_mark_mode) 11372 || ((!NILP (Vtransient_mark_mode)
11355 && !NILP (BVAR (XBUFFER (w->buffer), mark_active))) 11373 && !NILP (BVAR (XBUFFER (w->buffer), mark_active)))
11356 != !NILP (w->region_showing))) 11374 != !NILP (w->region_showing)))
11357 { 11375 {
11358 struct buffer *prev = current_buffer; 11376 struct buffer *prev = current_buffer;
11359 int count = SPECPDL_INDEX (); 11377 ptrdiff_t count = SPECPDL_INDEX ();
11360 Lisp_Object frame, new_tool_bar; 11378 Lisp_Object frame, new_tool_bar;
11361 int new_n_tool_bar; 11379 int new_n_tool_bar;
11362 struct gcpro gcpro1; 11380 struct gcpro gcpro1;
@@ -11401,7 +11419,7 @@ update_tool_bar (struct frame *f, int save_match_data)
11401 BLOCK_INPUT; 11419 BLOCK_INPUT;
11402 f->tool_bar_items = new_tool_bar; 11420 f->tool_bar_items = new_tool_bar;
11403 f->n_tool_bar_items = new_n_tool_bar; 11421 f->n_tool_bar_items = new_n_tool_bar;
11404 w->update_mode_line = Qt; 11422 w->update_mode_line = 1;
11405 UNBLOCK_INPUT; 11423 UNBLOCK_INPUT;
11406 } 11424 }
11407 11425
@@ -11494,20 +11512,20 @@ build_desired_tool_bar_string (struct frame *f)
11494 : DEFAULT_TOOL_BAR_BUTTON_RELIEF); 11512 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
11495 hmargin = vmargin = relief; 11513 hmargin = vmargin = relief;
11496 11514
11497 if (INTEGERP (Vtool_bar_button_margin) 11515 if (RANGED_INTEGERP (1, Vtool_bar_button_margin,
11498 && XINT (Vtool_bar_button_margin) > 0) 11516 INT_MAX - max (hmargin, vmargin)))
11499 { 11517 {
11500 hmargin += XFASTINT (Vtool_bar_button_margin); 11518 hmargin += XFASTINT (Vtool_bar_button_margin);
11501 vmargin += XFASTINT (Vtool_bar_button_margin); 11519 vmargin += XFASTINT (Vtool_bar_button_margin);
11502 } 11520 }
11503 else if (CONSP (Vtool_bar_button_margin)) 11521 else if (CONSP (Vtool_bar_button_margin))
11504 { 11522 {
11505 if (INTEGERP (XCAR (Vtool_bar_button_margin)) 11523 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin),
11506 && XINT (XCAR (Vtool_bar_button_margin)) > 0) 11524 INT_MAX - hmargin))
11507 hmargin += XFASTINT (XCAR (Vtool_bar_button_margin)); 11525 hmargin += XFASTINT (XCAR (Vtool_bar_button_margin));
11508 11526
11509 if (INTEGERP (XCDR (Vtool_bar_button_margin)) 11527 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin),
11510 && XINT (XCDR (Vtool_bar_button_margin)) > 0) 11528 INT_MAX - vmargin))
11511 vmargin += XFASTINT (XCDR (Vtool_bar_button_margin)); 11529 vmargin += XFASTINT (XCDR (Vtool_bar_button_margin));
11512 } 11530 }
11513 11531
@@ -11853,7 +11871,7 @@ redisplay_tool_bar (struct frame *f)
11853 { 11871 {
11854 int border, rows, height, extra; 11872 int border, rows, height, extra;
11855 11873
11856 if (INTEGERP (Vtool_bar_border)) 11874 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border))
11857 border = XINT (Vtool_bar_border); 11875 border = XINT (Vtool_bar_border);
11858 else if (EQ (Vtool_bar_border, Qinternal_border_width)) 11876 else if (EQ (Vtool_bar_border, Qinternal_border_width))
11859 border = FRAME_INTERNAL_BORDER_WIDTH (f); 11877 border = FRAME_INTERNAL_BORDER_WIDTH (f);
@@ -12041,7 +12059,7 @@ get_tool_bar_item (struct frame *f, int x, int y, struct glyph **glyph,
12041 12059
12042void 12060void
12043handle_tool_bar_click (struct frame *f, int x, int y, int down_p, 12061handle_tool_bar_click (struct frame *f, int x, int y, int down_p,
12044 unsigned int modifiers) 12062 int modifiers)
12045{ 12063{
12046 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 12064 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
12047 struct window *w = XWINDOW (f->tool_bar_window); 12065 struct window *w = XWINDOW (f->tool_bar_window);
@@ -12220,7 +12238,7 @@ hscroll_window_tree (Lisp_Object window)
12220 hscroll_step_abs = 0; 12238 hscroll_step_abs = 0;
12221 } 12239 }
12222 } 12240 }
12223 else if (INTEGERP (Vhscroll_step)) 12241 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step))
12224 { 12242 {
12225 hscroll_step_abs = XINT (Vhscroll_step); 12243 hscroll_step_abs = XINT (Vhscroll_step);
12226 if (hscroll_step_abs < 0) 12244 if (hscroll_step_abs < 0)
@@ -12284,9 +12302,9 @@ hscroll_window_tree (Lisp_Object window)
12284 && (w->cursor.x >= text_area_width - h_margin)))))) 12302 && (w->cursor.x >= text_area_width - h_margin))))))
12285 { 12303 {
12286 struct it it; 12304 struct it it;
12287 int hscroll; 12305 ptrdiff_t hscroll;
12288 struct buffer *saved_current_buffer; 12306 struct buffer *saved_current_buffer;
12289 EMACS_INT pt; 12307 ptrdiff_t pt;
12290 int wanted_x; 12308 int wanted_x;
12291 12309
12292 /* Find point in a display of infinite width. */ 12310 /* Find point in a display of infinite width. */
@@ -12401,12 +12419,12 @@ static int debug_dvpos, debug_dy;
12401 12419
12402/* Delta in characters and bytes for try_window_id. */ 12420/* Delta in characters and bytes for try_window_id. */
12403 12421
12404static EMACS_INT debug_delta, debug_delta_bytes; 12422static ptrdiff_t debug_delta, debug_delta_bytes;
12405 12423
12406/* Values of window_end_pos and window_end_vpos at the end of 12424/* Values of window_end_pos and window_end_vpos at the end of
12407 try_window_id. */ 12425 try_window_id. */
12408 12426
12409static EMACS_INT debug_end_vpos; 12427static ptrdiff_t debug_end_vpos;
12410 12428
12411/* Append a string to W->desired_matrix->method. FMT is a printf 12429/* Append a string to W->desired_matrix->method. FMT is a printf
12412 format string. If trace_redisplay_p is non-zero also printf the 12430 format string. If trace_redisplay_p is non-zero also printf the
@@ -12456,7 +12474,7 @@ debug_method_add (struct window *w, char const *fmt, ...)
12456 12474
12457static inline int 12475static inline int
12458text_outside_line_unchanged_p (struct window *w, 12476text_outside_line_unchanged_p (struct window *w,
12459 EMACS_INT start, EMACS_INT end) 12477 ptrdiff_t start, ptrdiff_t end)
12460{ 12478{
12461 int unchanged_p = 1; 12479 int unchanged_p = 1;
12462 12480
@@ -12679,10 +12697,10 @@ overlay_arrow_at_row (struct it *it, struct glyph_row *row)
12679 position. BUF and PT are the current point buffer and position. */ 12697 position. BUF and PT are the current point buffer and position. */
12680 12698
12681static int 12699static int
12682check_point_in_composition (struct buffer *prev_buf, EMACS_INT prev_pt, 12700check_point_in_composition (struct buffer *prev_buf, ptrdiff_t prev_pt,
12683 struct buffer *buf, EMACS_INT pt) 12701 struct buffer *buf, ptrdiff_t pt)
12684{ 12702{
12685 EMACS_INT start, end; 12703 ptrdiff_t start, end;
12686 Lisp_Object prop; 12704 Lisp_Object prop;
12687 Lisp_Object buffer; 12705 Lisp_Object buffer;
12688 12706
@@ -12733,7 +12751,7 @@ reconsider_clip_changes (struct window *w, struct buffer *b)
12733 if (!b->clip_changed 12751 if (!b->clip_changed
12734 && BUFFERP (w->buffer) && !NILP (w->window_end_valid)) 12752 && BUFFERP (w->buffer) && !NILP (w->window_end_valid))
12735 { 12753 {
12736 EMACS_INT pt; 12754 ptrdiff_t pt;
12737 12755
12738 if (w == XWINDOW (selected_window)) 12756 if (w == XWINDOW (selected_window))
12739 pt = PT; 12757 pt = PT;
@@ -12802,7 +12820,7 @@ redisplay_internal (void)
12802 int must_finish = 0; 12820 int must_finish = 0;
12803 struct text_pos tlbufpos, tlendpos; 12821 struct text_pos tlbufpos, tlendpos;
12804 int number_of_visible_frames; 12822 int number_of_visible_frames;
12805 int count, count1; 12823 ptrdiff_t count, count1;
12806 struct frame *sf; 12824 struct frame *sf;
12807 int polling_stopped_here = 0; 12825 int polling_stopped_here = 0;
12808 Lisp_Object old_frame = selected_frame; 12826 Lisp_Object old_frame = selected_frame;
@@ -12950,9 +12968,9 @@ redisplay_internal (void)
12950 update_mode_lines++; 12968 update_mode_lines++;
12951 12969
12952 /* Detect case that we need to write or remove a star in the mode line. */ 12970 /* Detect case that we need to write or remove a star in the mode line. */
12953 if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star)) 12971 if ((SAVE_MODIFF < MODIFF) != w->last_had_star)
12954 { 12972 {
12955 w->update_mode_line = Qt; 12973 w->update_mode_line = 1;
12956 if (buffer_shared > 1) 12974 if (buffer_shared > 1)
12957 update_mode_lines++; 12975 update_mode_lines++;
12958 } 12976 }
@@ -12969,7 +12987,7 @@ redisplay_internal (void)
12969 && XFASTINT (w->last_modified) >= MODIFF 12987 && XFASTINT (w->last_modified) >= MODIFF
12970 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF) 12988 && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF)
12971 && (XFASTINT (w->column_number_displayed) != current_column ())) 12989 && (XFASTINT (w->column_number_displayed) != current_column ()))
12972 w->update_mode_line = Qt; 12990 w->update_mode_line = 1;
12973 12991
12974 unbind_to (count1, Qnil); 12992 unbind_to (count1, Qnil);
12975 12993
@@ -13072,7 +13090,7 @@ redisplay_internal (void)
13072 tlendpos = this_line_end_pos; 13090 tlendpos = this_line_end_pos;
13073 if (!consider_all_windows_p 13091 if (!consider_all_windows_p
13074 && CHARPOS (tlbufpos) > 0 13092 && CHARPOS (tlbufpos) > 0
13075 && NILP (w->update_mode_line) 13093 && !w->update_mode_line
13076 && !current_buffer->clip_changed 13094 && !current_buffer->clip_changed
13077 && !current_buffer->prevent_redisplay_optimizations_p 13095 && !current_buffer->prevent_redisplay_optimizations_p
13078 && FRAME_VISIBLE_P (XFRAME (w->frame)) 13096 && FRAME_VISIBLE_P (XFRAME (w->frame))
@@ -13080,8 +13098,8 @@ redisplay_internal (void)
13080 /* Make sure recorded data applies to current buffer, etc. */ 13098 /* Make sure recorded data applies to current buffer, etc. */
13081 && this_line_buffer == current_buffer 13099 && this_line_buffer == current_buffer
13082 && current_buffer == XBUFFER (w->buffer) 13100 && current_buffer == XBUFFER (w->buffer)
13083 && NILP (w->force_start) 13101 && !w->force_start
13084 && NILP (w->optional_new_start) 13102 && !w->optional_new_start
13085 /* Point must be on the line that we have info recorded about. */ 13103 /* Point must be on the line that we have info recorded about. */
13086 && PT >= CHARPOS (tlbufpos) 13104 && PT >= CHARPOS (tlbufpos)
13087 && PT <= Z - CHARPOS (tlendpos) 13105 && PT <= Z - CHARPOS (tlendpos)
@@ -13152,7 +13170,7 @@ redisplay_internal (void)
13152 { 13170 {
13153 struct glyph_row *row 13171 struct glyph_row *row
13154 = MATRIX_ROW (w->current_matrix, this_line_vpos + 1); 13172 = MATRIX_ROW (w->current_matrix, this_line_vpos + 1);
13155 EMACS_INT delta, delta_bytes; 13173 ptrdiff_t delta, delta_bytes;
13156 13174
13157 /* We used to distinguish between two cases here, 13175 /* We used to distinguish between two cases here,
13158 conditioned by Z - CHARPOS (tlendpos) == ZV, for 13176 conditioned by Z - CHARPOS (tlendpos) == ZV, for
@@ -13616,7 +13634,7 @@ mark_window_display_accurate_1 (struct window *w, int accurate_p)
13616 w->last_overlay_modified 13634 w->last_overlay_modified
13617 = make_number (accurate_p ? BUF_OVERLAY_MODIFF (b) : 0); 13635 = make_number (accurate_p ? BUF_OVERLAY_MODIFF (b) : 0);
13618 w->last_had_star 13636 w->last_had_star
13619 = BUF_MODIFF (b) > BUF_SAVE_MODIFF (b) ? Qt : Qnil; 13637 = BUF_MODIFF (b) > BUF_SAVE_MODIFF (b);
13620 13638
13621 if (accurate_p) 13639 if (accurate_p)
13622 { 13640 {
@@ -13645,7 +13663,7 @@ mark_window_display_accurate_1 (struct window *w, int accurate_p)
13645 if (accurate_p) 13663 if (accurate_p)
13646 { 13664 {
13647 w->window_end_valid = w->buffer; 13665 w->window_end_valid = w->buffer;
13648 w->update_mode_line = Qnil; 13666 w->update_mode_line = 0;
13649 } 13667 }
13650} 13668}
13651 13669
@@ -13780,18 +13798,18 @@ redisplay_window_1 (Lisp_Object window)
13780static int 13798static int
13781set_cursor_from_row (struct window *w, struct glyph_row *row, 13799set_cursor_from_row (struct window *w, struct glyph_row *row,
13782 struct glyph_matrix *matrix, 13800 struct glyph_matrix *matrix,
13783 EMACS_INT delta, EMACS_INT delta_bytes, 13801 ptrdiff_t delta, ptrdiff_t delta_bytes,
13784 int dy, int dvpos) 13802 int dy, int dvpos)
13785{ 13803{
13786 struct glyph *glyph = row->glyphs[TEXT_AREA]; 13804 struct glyph *glyph = row->glyphs[TEXT_AREA];
13787 struct glyph *end = glyph + row->used[TEXT_AREA]; 13805 struct glyph *end = glyph + row->used[TEXT_AREA];
13788 struct glyph *cursor = NULL; 13806 struct glyph *cursor = NULL;
13789 /* The last known character position in row. */ 13807 /* The last known character position in row. */
13790 EMACS_INT last_pos = MATRIX_ROW_START_CHARPOS (row) + delta; 13808 ptrdiff_t last_pos = MATRIX_ROW_START_CHARPOS (row) + delta;
13791 int x = row->x; 13809 int x = row->x;
13792 EMACS_INT pt_old = PT - delta; 13810 ptrdiff_t pt_old = PT - delta;
13793 EMACS_INT pos_before = MATRIX_ROW_START_CHARPOS (row) + delta; 13811 ptrdiff_t pos_before = MATRIX_ROW_START_CHARPOS (row) + delta;
13794 EMACS_INT pos_after = MATRIX_ROW_END_CHARPOS (row) + delta; 13812 ptrdiff_t pos_after = MATRIX_ROW_END_CHARPOS (row) + delta;
13795 struct glyph *glyph_before = glyph - 1, *glyph_after = end; 13813 struct glyph *glyph_before = glyph - 1, *glyph_after = end;
13796 /* A glyph beyond the edge of TEXT_AREA which we should never 13814 /* A glyph beyond the edge of TEXT_AREA which we should never
13797 touch. */ 13815 touch. */
@@ -13804,11 +13822,11 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13804 int string_seen = 0; 13822 int string_seen = 0;
13805 /* Largest and smallest buffer positions seen so far during scan of 13823 /* Largest and smallest buffer positions seen so far during scan of
13806 glyph row. */ 13824 glyph row. */
13807 EMACS_INT bpos_max = pos_before; 13825 ptrdiff_t bpos_max = pos_before;
13808 EMACS_INT bpos_min = pos_after; 13826 ptrdiff_t bpos_min = pos_after;
13809 /* Last buffer position covered by an overlay string with an integer 13827 /* Last buffer position covered by an overlay string with an integer
13810 `cursor' property. */ 13828 `cursor' property. */
13811 EMACS_INT bpos_covered = 0; 13829 ptrdiff_t bpos_covered = 0;
13812 /* Non-zero means the display string on which to display the cursor 13830 /* Non-zero means the display string on which to display the cursor
13813 comes from a text property, not from an overlay. */ 13831 comes from a text property, not from an overlay. */
13814 int string_from_text_prop = 0; 13832 int string_from_text_prop = 0;
@@ -13901,7 +13919,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13901 { 13919 {
13902 if (BUFFERP (glyph->object)) 13920 if (BUFFERP (glyph->object))
13903 { 13921 {
13904 EMACS_INT dpos = glyph->charpos - pt_old; 13922 ptrdiff_t dpos = glyph->charpos - pt_old;
13905 13923
13906 if (glyph->charpos > bpos_max) 13924 if (glyph->charpos > bpos_max)
13907 bpos_max = glyph->charpos; 13925 bpos_max = glyph->charpos;
@@ -13938,7 +13956,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13938 else if (STRINGP (glyph->object)) 13956 else if (STRINGP (glyph->object))
13939 { 13957 {
13940 Lisp_Object chprop; 13958 Lisp_Object chprop;
13941 EMACS_INT glyph_pos = glyph->charpos; 13959 ptrdiff_t glyph_pos = glyph->charpos;
13942 13960
13943 chprop = Fget_char_property (make_number (glyph_pos), Qcursor, 13961 chprop = Fget_char_property (make_number (glyph_pos), Qcursor,
13944 glyph->object); 13962 glyph->object);
@@ -13954,7 +13972,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13954 text is completely covered by display properties, 13972 text is completely covered by display properties,
13955 so that no glyph with valid buffer positions is 13973 so that no glyph with valid buffer positions is
13956 ever seen in the row. */ 13974 ever seen in the row. */
13957 EMACS_INT prop_pos = 13975 ptrdiff_t prop_pos =
13958 string_buffer_position_lim (glyph->object, pos_before, 13976 string_buffer_position_lim (glyph->object, pos_before,
13959 pos_after, 0); 13977 pos_after, 0);
13960 13978
@@ -13992,7 +14010,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13992 { 14010 {
13993 if (BUFFERP (glyph->object)) 14011 if (BUFFERP (glyph->object))
13994 { 14012 {
13995 EMACS_INT dpos = glyph->charpos - pt_old; 14013 ptrdiff_t dpos = glyph->charpos - pt_old;
13996 14014
13997 if (glyph->charpos > bpos_max) 14015 if (glyph->charpos > bpos_max)
13998 bpos_max = glyph->charpos; 14016 bpos_max = glyph->charpos;
@@ -14022,13 +14040,13 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14022 else if (STRINGP (glyph->object)) 14040 else if (STRINGP (glyph->object))
14023 { 14041 {
14024 Lisp_Object chprop; 14042 Lisp_Object chprop;
14025 EMACS_INT glyph_pos = glyph->charpos; 14043 ptrdiff_t glyph_pos = glyph->charpos;
14026 14044
14027 chprop = Fget_char_property (make_number (glyph_pos), Qcursor, 14045 chprop = Fget_char_property (make_number (glyph_pos), Qcursor,
14028 glyph->object); 14046 glyph->object);
14029 if (!NILP (chprop)) 14047 if (!NILP (chprop))
14030 { 14048 {
14031 EMACS_INT prop_pos = 14049 ptrdiff_t prop_pos =
14032 string_buffer_position_lim (glyph->object, pos_before, 14050 string_buffer_position_lim (glyph->object, pos_before,
14033 pos_after, 0); 14051 pos_after, 0);
14034 14052
@@ -14076,7 +14094,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14076 14094
14077 if (row->ends_in_ellipsis_p && pos_after == last_pos) 14095 if (row->ends_in_ellipsis_p && pos_after == last_pos)
14078 { 14096 {
14079 EMACS_INT ellipsis_pos; 14097 ptrdiff_t ellipsis_pos;
14080 14098
14081 /* Scan back over the ellipsis glyphs. */ 14099 /* Scan back over the ellipsis glyphs. */
14082 if (!row->reversed_p) 14100 if (!row->reversed_p)
@@ -14116,7 +14134,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14116 positioned between POS_BEFORE and POS_AFTER in the 14134 positioned between POS_BEFORE and POS_AFTER in the
14117 buffer. */ 14135 buffer. */
14118 struct glyph *start, *stop; 14136 struct glyph *start, *stop;
14119 EMACS_INT pos = pos_before; 14137 ptrdiff_t pos = pos_before;
14120 14138
14121 x = -1; 14139 x = -1;
14122 14140
@@ -14159,10 +14177,10 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14159 if (STRINGP (glyph->object)) 14177 if (STRINGP (glyph->object))
14160 { 14178 {
14161 Lisp_Object str; 14179 Lisp_Object str;
14162 EMACS_INT tem; 14180 ptrdiff_t tem;
14163 /* If the display property covers the newline, we 14181 /* If the display property covers the newline, we
14164 need to search for it one position farther. */ 14182 need to search for it one position farther. */
14165 EMACS_INT lim = pos_after 14183 ptrdiff_t lim = pos_after
14166 + (pos_after == MATRIX_ROW_END_CHARPOS (row) + delta); 14184 + (pos_after == MATRIX_ROW_END_CHARPOS (row) + delta);
14167 14185
14168 string_from_text_prop = 0; 14186 string_from_text_prop = 0;
@@ -14191,7 +14209,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14191 be a character in the string with the 14209 be a character in the string with the
14192 `cursor' property, which means display 14210 `cursor' property, which means display
14193 cursor on that character's glyph. */ 14211 cursor on that character's glyph. */
14194 EMACS_INT strpos = glyph->charpos; 14212 ptrdiff_t strpos = glyph->charpos;
14195 14213
14196 if (tem) 14214 if (tem)
14197 { 14215 {
@@ -14204,7 +14222,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14204 glyph += incr) 14222 glyph += incr)
14205 { 14223 {
14206 Lisp_Object cprop; 14224 Lisp_Object cprop;
14207 EMACS_INT gpos = glyph->charpos; 14225 ptrdiff_t gpos = glyph->charpos;
14208 14226
14209 cprop = Fget_char_property (make_number (gpos), 14227 cprop = Fget_char_property (make_number (gpos),
14210 Qcursor, 14228 Qcursor,
@@ -14495,7 +14513,7 @@ enum
14495 14513
14496static int 14514static int
14497try_scrolling (Lisp_Object window, int just_this_one_p, 14515try_scrolling (Lisp_Object window, int just_this_one_p,
14498 EMACS_INT arg_scroll_conservatively, EMACS_INT scroll_step, 14516 ptrdiff_t arg_scroll_conservatively, ptrdiff_t scroll_step,
14499 int temp_scroll_step, int last_line_misfit) 14517 int temp_scroll_step, int last_line_misfit)
14500{ 14518{
14501 struct window *w = XWINDOW (window); 14519 struct window *w = XWINDOW (window);
@@ -15135,7 +15153,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
15135 MATRIX_ROW (w->current_matrix, w->cursor.vpos); 15153 MATRIX_ROW (w->current_matrix, w->cursor.vpos);
15136 struct glyph *g = 15154 struct glyph *g =
15137 candidate->glyphs[TEXT_AREA] + w->cursor.hpos; 15155 candidate->glyphs[TEXT_AREA] + w->cursor.hpos;
15138 EMACS_INT endpos = MATRIX_ROW_END_CHARPOS (candidate); 15156 ptrdiff_t endpos = MATRIX_ROW_END_CHARPOS (candidate);
15139 15157
15140 exact_match_p = 15158 exact_match_p =
15141 (BUFFERP (g->object) && g->charpos == PT) 15159 (BUFFERP (g->object) && g->charpos == PT)
@@ -15195,7 +15213,7 @@ static
15195void 15213void
15196set_vertical_scroll_bar (struct window *w) 15214set_vertical_scroll_bar (struct window *w)
15197{ 15215{
15198 EMACS_INT start, end, whole; 15216 ptrdiff_t start, end, whole;
15199 15217
15200 /* Calculate the start and end positions for the current window. 15218 /* Calculate the start and end positions for the current window.
15201 At some point, it would be nice to choose between scrollbars 15219 At some point, it would be nice to choose between scrollbars
@@ -15255,11 +15273,11 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15255 It indicates that the buffer contents and narrowing are unchanged. */ 15273 It indicates that the buffer contents and narrowing are unchanged. */
15256 int buffer_unchanged_p = 0; 15274 int buffer_unchanged_p = 0;
15257 int temp_scroll_step = 0; 15275 int temp_scroll_step = 0;
15258 int count = SPECPDL_INDEX (); 15276 ptrdiff_t count = SPECPDL_INDEX ();
15259 int rc; 15277 int rc;
15260 int centering_position = -1; 15278 int centering_position = -1;
15261 int last_line_misfit = 0; 15279 int last_line_misfit = 0;
15262 EMACS_INT beg_unchanged, end_unchanged; 15280 ptrdiff_t beg_unchanged, end_unchanged;
15263 15281
15264 SET_TEXT_POS (lpoint, PT, PT_BYTE); 15282 SET_TEXT_POS (lpoint, PT, PT_BYTE);
15265 opoint = lpoint; 15283 opoint = lpoint;
@@ -15274,7 +15292,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15274 reconsider_clip_changes (w, buffer); 15292 reconsider_clip_changes (w, buffer);
15275 15293
15276 /* Has the mode line to be updated? */ 15294 /* Has the mode line to be updated? */
15277 update_mode_line = (!NILP (w->update_mode_line) 15295 update_mode_line = (w->update_mode_line
15278 || update_mode_lines 15296 || update_mode_lines
15279 || buffer->clip_changed 15297 || buffer->clip_changed
15280 || buffer->prevent_redisplay_optimizations_p); 15298 || buffer->prevent_redisplay_optimizations_p);
@@ -15400,8 +15418,8 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15400 window, set up appropriate value. */ 15418 window, set up appropriate value. */
15401 if (!EQ (window, selected_window)) 15419 if (!EQ (window, selected_window))
15402 { 15420 {
15403 EMACS_INT new_pt = XMARKER (w->pointm)->charpos; 15421 ptrdiff_t new_pt = XMARKER (w->pointm)->charpos;
15404 EMACS_INT new_pt_byte = marker_byte_position (w->pointm); 15422 ptrdiff_t new_pt_byte = marker_byte_position (w->pointm);
15405 if (new_pt < BEGV) 15423 if (new_pt < BEGV)
15406 { 15424 {
15407 new_pt = BEGV; 15425 new_pt = BEGV;
@@ -15446,32 +15464,31 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15446 15464
15447 /* If someone specified a new starting point but did not insist, 15465 /* If someone specified a new starting point but did not insist,
15448 check whether it can be used. */ 15466 check whether it can be used. */
15449 if (!NILP (w->optional_new_start) 15467 if (w->optional_new_start
15450 && CHARPOS (startp) >= BEGV 15468 && CHARPOS (startp) >= BEGV
15451 && CHARPOS (startp) <= ZV) 15469 && CHARPOS (startp) <= ZV)
15452 { 15470 {
15453 w->optional_new_start = Qnil; 15471 w->optional_new_start = 0;
15454 start_display (&it, w, startp); 15472 start_display (&it, w, startp);
15455 move_it_to (&it, PT, 0, it.last_visible_y, -1, 15473 move_it_to (&it, PT, 0, it.last_visible_y, -1,
15456 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); 15474 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
15457 if (IT_CHARPOS (it) == PT) 15475 if (IT_CHARPOS (it) == PT)
15458 w->force_start = Qt; 15476 w->force_start = 1;
15459 /* IT may overshoot PT if text at PT is invisible. */ 15477 /* IT may overshoot PT if text at PT is invisible. */
15460 else if (IT_CHARPOS (it) > PT && CHARPOS (startp) <= PT) 15478 else if (IT_CHARPOS (it) > PT && CHARPOS (startp) <= PT)
15461 w->force_start = Qt; 15479 w->force_start = 1;
15462 } 15480 }
15463 15481
15464 force_start: 15482 force_start:
15465 15483
15466 /* Handle case where place to start displaying has been specified, 15484 /* Handle case where place to start displaying has been specified,
15467 unless the specified location is outside the accessible range. */ 15485 unless the specified location is outside the accessible range. */
15468 if (!NILP (w->force_start) 15486 if (w->force_start || w->frozen_window_start_p)
15469 || w->frozen_window_start_p)
15470 { 15487 {
15471 /* We set this later on if we have to adjust point. */ 15488 /* We set this later on if we have to adjust point. */
15472 int new_vpos = -1; 15489 int new_vpos = -1;
15473 15490
15474 w->force_start = Qnil; 15491 w->force_start = 0;
15475 w->vscroll = 0; 15492 w->vscroll = 0;
15476 w->window_end_valid = Qnil; 15493 w->window_end_valid = Qnil;
15477 15494
@@ -15490,7 +15507,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15490 || ! NILP (Vwindow_scroll_functions)) 15507 || ! NILP (Vwindow_scroll_functions))
15491 { 15508 {
15492 update_mode_line = 1; 15509 update_mode_line = 1;
15493 w->update_mode_line = Qt; 15510 w->update_mode_line = 1;
15494 startp = run_window_scroll_functions (window, startp); 15511 startp = run_window_scroll_functions (window, startp);
15495 } 15512 }
15496 15513
@@ -15508,7 +15525,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15508 the scroll margin (bug#148) -- cyd */ 15525 the scroll margin (bug#148) -- cyd */
15509 if (!try_window (window, startp, 0)) 15526 if (!try_window (window, startp, 0))
15510 { 15527 {
15511 w->force_start = Qt; 15528 w->force_start = 1;
15512 clear_glyph_matrix (w->desired_matrix); 15529 clear_glyph_matrix (w->desired_matrix);
15513 goto need_larger_matrices; 15530 goto need_larger_matrices;
15514 } 15531 }
@@ -15587,7 +15604,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15587 } 15604 }
15588 /* If current starting point was originally the beginning of a line 15605 /* If current starting point was originally the beginning of a line
15589 but no longer is, find a new starting point. */ 15606 but no longer is, find a new starting point. */
15590 else if (!NILP (w->start_at_line_beg) 15607 else if (w->start_at_line_beg
15591 && !(CHARPOS (startp) <= BEGV 15608 && !(CHARPOS (startp) <= BEGV
15592 || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n')) 15609 || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n'))
15593 { 15610 {
@@ -15634,7 +15651,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15634 new window start, since that would change the position under 15651 new window start, since that would change the position under
15635 the mouse, resulting in an unwanted mouse-movement rather 15652 the mouse, resulting in an unwanted mouse-movement rather
15636 than a simple mouse-click. */ 15653 than a simple mouse-click. */
15637 if (NILP (w->start_at_line_beg) 15654 if (!w->start_at_line_beg
15638 && NILP (do_mouse_tracking) 15655 && NILP (do_mouse_tracking)
15639 && CHARPOS (startp) > BEGV 15656 && CHARPOS (startp) > BEGV
15640 && CHARPOS (startp) > BEG + beg_unchanged 15657 && CHARPOS (startp) > BEG + beg_unchanged
@@ -15654,7 +15671,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15654 See bug#9324. */ 15671 See bug#9324. */
15655 && pos_visible_p (w, PT, &d1, &d2, &d3, &d4, &d5, &d6)) 15672 && pos_visible_p (w, PT, &d1, &d2, &d3, &d4, &d5, &d6))
15656 { 15673 {
15657 w->force_start = Qt; 15674 w->force_start = 1;
15658 SET_TEXT_POS_FROM_MARKER (startp, w->start); 15675 SET_TEXT_POS_FROM_MARKER (startp, w->start);
15659 goto force_start; 15676 goto force_start;
15660 } 15677 }
@@ -15715,7 +15732,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15715 if (!update_mode_line) 15732 if (!update_mode_line)
15716 { 15733 {
15717 update_mode_line = 1; 15734 update_mode_line = 1;
15718 w->update_mode_line = Qt; 15735 w->update_mode_line = 1;
15719 } 15736 }
15720 15737
15721 /* Try to scroll by specified few lines. */ 15738 /* Try to scroll by specified few lines. */
@@ -15773,7 +15790,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15773 scroll_margin > 0 15790 scroll_margin > 0
15774 ? min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4) 15791 ? min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4)
15775 : 0; 15792 : 0;
15776 EMACS_INT margin_pos = CHARPOS (startp); 15793 ptrdiff_t margin_pos = CHARPOS (startp);
15777 Lisp_Object aggressive; 15794 Lisp_Object aggressive;
15778 int scrolling_up; 15795 int scrolling_up;
15779 15796
@@ -15970,9 +15987,8 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15970 done: 15987 done:
15971 15988
15972 SET_TEXT_POS_FROM_MARKER (startp, w->start); 15989 SET_TEXT_POS_FROM_MARKER (startp, w->start);
15973 w->start_at_line_beg = ((CHARPOS (startp) == BEGV 15990 w->start_at_line_beg = (CHARPOS (startp) == BEGV
15974 || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n') 15991 || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n');
15975 ? Qt : Qnil);
15976 15992
15977 /* Display the mode line, if we must. */ 15993 /* Display the mode line, if we must. */
15978 if ((update_mode_line 15994 if ((update_mode_line
@@ -16189,7 +16205,7 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
16189 /* If bottom moved off end of frame, change mode line percentage. */ 16205 /* If bottom moved off end of frame, change mode line percentage. */
16190 if (XFASTINT (w->window_end_pos) <= 0 16206 if (XFASTINT (w->window_end_pos) <= 0
16191 && Z != IT_CHARPOS (it)) 16207 && Z != IT_CHARPOS (it))
16192 w->update_mode_line = Qt; 16208 w->update_mode_line = 1;
16193 16209
16194 /* Set window_end_pos to the offset of the last character displayed 16210 /* Set window_end_pos to the offset of the last character displayed
16195 on the window from the end of current_buffer. Set 16211 on the window from the end of current_buffer. Set
@@ -16672,7 +16688,7 @@ try_window_reusing_current_matrix (struct window *w)
16672 16688
16673static struct glyph_row *find_last_unchanged_at_beg_row (struct window *); 16689static struct glyph_row *find_last_unchanged_at_beg_row (struct window *);
16674static struct glyph_row *find_first_unchanged_at_end_row (struct window *, 16690static struct glyph_row *find_first_unchanged_at_end_row (struct window *,
16675 EMACS_INT *, EMACS_INT *); 16691 ptrdiff_t *, ptrdiff_t *);
16676static struct glyph_row * 16692static struct glyph_row *
16677find_last_row_displaying_text (struct glyph_matrix *, struct it *, 16693find_last_row_displaying_text (struct glyph_matrix *, struct it *,
16678 struct glyph_row *); 16694 struct glyph_row *);
@@ -16720,7 +16736,7 @@ find_last_row_displaying_text (struct glyph_matrix *matrix, struct it *it,
16720static struct glyph_row * 16736static struct glyph_row *
16721find_last_unchanged_at_beg_row (struct window *w) 16737find_last_unchanged_at_beg_row (struct window *w)
16722{ 16738{
16723 EMACS_INT first_changed_pos = BEG + BEG_UNCHANGED; 16739 ptrdiff_t first_changed_pos = BEG + BEG_UNCHANGED;
16724 struct glyph_row *row; 16740 struct glyph_row *row;
16725 struct glyph_row *row_found = NULL; 16741 struct glyph_row *row_found = NULL;
16726 int yb = window_text_bottom_y (w); 16742 int yb = window_text_bottom_y (w);
@@ -16776,7 +16792,7 @@ find_last_unchanged_at_beg_row (struct window *w)
16776 16792
16777static struct glyph_row * 16793static struct glyph_row *
16778find_first_unchanged_at_end_row (struct window *w, 16794find_first_unchanged_at_end_row (struct window *w,
16779 EMACS_INT *delta, EMACS_INT *delta_bytes) 16795 ptrdiff_t *delta, ptrdiff_t *delta_bytes)
16780{ 16796{
16781 struct glyph_row *row; 16797 struct glyph_row *row;
16782 struct glyph_row *row_found = NULL; 16798 struct glyph_row *row_found = NULL;
@@ -16804,11 +16820,11 @@ find_first_unchanged_at_end_row (struct window *w,
16804 corresponds to window_end_pos. This allows us to translate 16820 corresponds to window_end_pos. This allows us to translate
16805 buffer positions in the current matrix to current buffer 16821 buffer positions in the current matrix to current buffer
16806 positions for characters not in changed text. */ 16822 positions for characters not in changed text. */
16807 EMACS_INT Z_old = 16823 ptrdiff_t Z_old =
16808 MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos); 16824 MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos);
16809 EMACS_INT Z_BYTE_old = 16825 ptrdiff_t Z_BYTE_old =
16810 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos; 16826 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos;
16811 EMACS_INT last_unchanged_pos, last_unchanged_pos_old; 16827 ptrdiff_t last_unchanged_pos, last_unchanged_pos_old;
16812 struct glyph_row *first_text_row 16828 struct glyph_row *first_text_row
16813 = MATRIX_FIRST_TEXT_ROW (w->current_matrix); 16829 = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
16814 16830
@@ -16895,12 +16911,12 @@ sync_frame_with_window_matrix_rows (struct window *w)
16895 containing CHARPOS or null. */ 16911 containing CHARPOS or null. */
16896 16912
16897struct glyph_row * 16913struct glyph_row *
16898row_containing_pos (struct window *w, EMACS_INT charpos, 16914row_containing_pos (struct window *w, ptrdiff_t charpos,
16899 struct glyph_row *start, struct glyph_row *end, int dy) 16915 struct glyph_row *start, struct glyph_row *end, int dy)
16900{ 16916{
16901 struct glyph_row *row = start; 16917 struct glyph_row *row = start;
16902 struct glyph_row *best_row = NULL; 16918 struct glyph_row *best_row = NULL;
16903 EMACS_INT mindif = BUF_ZV (XBUFFER (w->buffer)) + 1; 16919 ptrdiff_t mindif = BUF_ZV (XBUFFER (w->buffer)) + 1;
16904 int last_y; 16920 int last_y;
16905 16921
16906 /* If we happen to start on a header-line, skip that. */ 16922 /* If we happen to start on a header-line, skip that. */
@@ -17014,14 +17030,14 @@ try_window_id (struct window *w)
17014 struct glyph_row *bottom_row; 17030 struct glyph_row *bottom_row;
17015 int bottom_vpos; 17031 int bottom_vpos;
17016 struct it it; 17032 struct it it;
17017 EMACS_INT delta = 0, delta_bytes = 0, stop_pos; 17033 ptrdiff_t delta = 0, delta_bytes = 0, stop_pos;
17018 int dvpos, dy; 17034 int dvpos, dy;
17019 struct text_pos start_pos; 17035 struct text_pos start_pos;
17020 struct run run; 17036 struct run run;
17021 int first_unchanged_at_end_vpos = 0; 17037 int first_unchanged_at_end_vpos = 0;
17022 struct glyph_row *last_text_row, *last_text_row_at_end; 17038 struct glyph_row *last_text_row, *last_text_row_at_end;
17023 struct text_pos start; 17039 struct text_pos start;
17024 EMACS_INT first_changed_charpos, last_changed_charpos; 17040 ptrdiff_t first_changed_charpos, last_changed_charpos;
17025 17041
17026#if GLYPH_DEBUG 17042#if GLYPH_DEBUG
17027 if (inhibit_try_window_id) 17043 if (inhibit_try_window_id)
@@ -17148,7 +17164,7 @@ try_window_id (struct window *w)
17148 || (last_changed_charpos < CHARPOS (start) - 1 17164 || (last_changed_charpos < CHARPOS (start) - 1
17149 && FETCH_BYTE (BYTEPOS (start) - 1) == '\n'))) 17165 && FETCH_BYTE (BYTEPOS (start) - 1) == '\n')))
17150 { 17166 {
17151 EMACS_INT Z_old, Z_delta, Z_BYTE_old, Z_delta_bytes; 17167 ptrdiff_t Z_old, Z_delta, Z_BYTE_old, Z_delta_bytes;
17152 struct glyph_row *r0; 17168 struct glyph_row *r0;
17153 17169
17154 /* Compute how many chars/bytes have been added to or removed 17170 /* Compute how many chars/bytes have been added to or removed
@@ -17892,7 +17908,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
17892 row->visible_height, 17908 row->visible_height,
17893 row->ascent, 17909 row->ascent,
17894 row->phys_ascent); 17910 row->phys_ascent);
17895 fprintf (stderr, "%9d %5d\t%5d\n", row->start.overlay_string_index, 17911 fprintf (stderr, "%9"pD"d %5"pD"d\t%5d\n", row->start.overlay_string_index,
17896 row->end.overlay_string_index, 17912 row->end.overlay_string_index,
17897 row->continuation_lines_width); 17913 row->continuation_lines_width);
17898 fprintf (stderr, "%9"pI"d %5"pI"d\n", 17914 fprintf (stderr, "%9"pI"d %5"pI"d\n",
@@ -17966,7 +17982,7 @@ glyphs in short form, otherwise show glyphs in long form. */)
17966 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); 17982 w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos);
17967 fprintf (stderr, "=============================================\n"); 17983 fprintf (stderr, "=============================================\n");
17968 dump_glyph_matrix (w->current_matrix, 17984 dump_glyph_matrix (w->current_matrix,
17969 NILP (glyphs) ? 0 : XINT (glyphs)); 17985 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 0);
17970 return Qnil; 17986 return Qnil;
17971} 17987}
17972 17988
@@ -17989,7 +18005,7 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
17989 (Lisp_Object row, Lisp_Object glyphs) 18005 (Lisp_Object row, Lisp_Object glyphs)
17990{ 18006{
17991 struct glyph_matrix *matrix; 18007 struct glyph_matrix *matrix;
17992 int vpos; 18008 EMACS_INT vpos;
17993 18009
17994 CHECK_NUMBER (row); 18010 CHECK_NUMBER (row);
17995 matrix = XWINDOW (selected_window)->current_matrix; 18011 matrix = XWINDOW (selected_window)->current_matrix;
@@ -17997,7 +18013,7 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
17997 if (vpos >= 0 && vpos < matrix->nrows) 18013 if (vpos >= 0 && vpos < matrix->nrows)
17998 dump_glyph_row (MATRIX_ROW (matrix, vpos), 18014 dump_glyph_row (MATRIX_ROW (matrix, vpos),
17999 vpos, 18015 vpos,
18000 INTEGERP (glyphs) ? XINT (glyphs) : 2); 18016 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 2);
18001 return Qnil; 18017 return Qnil;
18002} 18018}
18003 18019
@@ -18011,13 +18027,13 @@ GLYPH > 1 or omitted means dump glyphs in long form. */)
18011{ 18027{
18012 struct frame *sf = SELECTED_FRAME (); 18028 struct frame *sf = SELECTED_FRAME ();
18013 struct glyph_matrix *m = XWINDOW (sf->tool_bar_window)->current_matrix; 18029 struct glyph_matrix *m = XWINDOW (sf->tool_bar_window)->current_matrix;
18014 int vpos; 18030 EMACS_INT vpos;
18015 18031
18016 CHECK_NUMBER (row); 18032 CHECK_NUMBER (row);
18017 vpos = XINT (row); 18033 vpos = XINT (row);
18018 if (vpos >= 0 && vpos < m->nrows) 18034 if (vpos >= 0 && vpos < m->nrows)
18019 dump_glyph_row (MATRIX_ROW (m, vpos), vpos, 18035 dump_glyph_row (MATRIX_ROW (m, vpos), vpos,
18020 INTEGERP (glyphs) ? XINT (glyphs) : 2); 18036 TYPE_RANGED_INTEGERP (int, glyphs) ? XINT (glyphs) : 2);
18021 return Qnil; 18037 return Qnil;
18022} 18038}
18023 18039
@@ -18542,9 +18558,9 @@ extend_face_to_end_of_line (struct it *it)
18542 trailing whitespace. */ 18558 trailing whitespace. */
18543 18559
18544static int 18560static int
18545trailing_whitespace_p (EMACS_INT charpos) 18561trailing_whitespace_p (ptrdiff_t charpos)
18546{ 18562{
18547 EMACS_INT bytepos = CHAR_TO_BYTE (charpos); 18563 ptrdiff_t bytepos = CHAR_TO_BYTE (charpos);
18548 int c = 0; 18564 int c = 0;
18549 18565
18550 while (bytepos < ZV_BYTE 18566 while (bytepos < ZV_BYTE
@@ -18686,7 +18702,7 @@ cursor_row_p (struct glyph_row *row)
18686 18702
18687 for ( ; glyph >= beg && EQ (glyph->object, s); --glyph) 18703 for ( ; glyph >= beg && EQ (glyph->object, s); --glyph)
18688 { 18704 {
18689 EMACS_INT gpos = glyph->charpos; 18705 ptrdiff_t gpos = glyph->charpos;
18690 18706
18691 if (!NILP (Fget_char_property (make_number (gpos), 18707 if (!NILP (Fget_char_property (make_number (gpos),
18692 Qcursor, s))) 18708 Qcursor, s)))
@@ -18883,8 +18899,8 @@ unproduce_glyphs (struct it *it, int n)
18883 and ROW->maxpos. */ 18899 and ROW->maxpos. */
18884static void 18900static void
18885find_row_edges (struct it *it, struct glyph_row *row, 18901find_row_edges (struct it *it, struct glyph_row *row,
18886 EMACS_INT min_pos, EMACS_INT min_bpos, 18902 ptrdiff_t min_pos, ptrdiff_t min_bpos,
18887 EMACS_INT max_pos, EMACS_INT max_bpos) 18903 ptrdiff_t max_pos, ptrdiff_t max_bpos)
18888{ 18904{
18889 /* FIXME: Revisit this when glyph ``spilling'' in continuation 18905 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18890 lines' rows is implemented for bidi-reordered rows. */ 18906 lines' rows is implemented for bidi-reordered rows. */
@@ -19051,11 +19067,11 @@ display_line (struct it *it)
19051 int wrap_row_ascent IF_LINT (= 0), wrap_row_height IF_LINT (= 0); 19067 int wrap_row_ascent IF_LINT (= 0), wrap_row_height IF_LINT (= 0);
19052 int wrap_row_phys_ascent IF_LINT (= 0), wrap_row_phys_height IF_LINT (= 0); 19068 int wrap_row_phys_ascent IF_LINT (= 0), wrap_row_phys_height IF_LINT (= 0);
19053 int wrap_row_extra_line_spacing IF_LINT (= 0); 19069 int wrap_row_extra_line_spacing IF_LINT (= 0);
19054 EMACS_INT wrap_row_min_pos IF_LINT (= 0), wrap_row_min_bpos IF_LINT (= 0); 19070 ptrdiff_t wrap_row_min_pos IF_LINT (= 0), wrap_row_min_bpos IF_LINT (= 0);
19055 EMACS_INT wrap_row_max_pos IF_LINT (= 0), wrap_row_max_bpos IF_LINT (= 0); 19071 ptrdiff_t wrap_row_max_pos IF_LINT (= 0), wrap_row_max_bpos IF_LINT (= 0);
19056 int cvpos; 19072 int cvpos;
19057 EMACS_INT min_pos = ZV + 1, max_pos = 0; 19073 ptrdiff_t min_pos = ZV + 1, max_pos = 0;
19058 EMACS_INT min_bpos IF_LINT (= 0), max_bpos IF_LINT (= 0); 19074 ptrdiff_t min_bpos IF_LINT (= 0), max_bpos IF_LINT (= 0);
19059 19075
19060 /* We always start displaying at hpos zero even if hscrolled. */ 19076 /* We always start displaying at hpos zero even if hscrolled. */
19061 xassert (it->hpos == 0 && it->current_x == 0); 19077 xassert (it->hpos == 0 && it->current_x == 0);
@@ -19128,10 +19144,10 @@ display_line (struct it *it)
19128 { \ 19144 { \
19129 int composition_p = !STRINGP ((IT)->string) \ 19145 int composition_p = !STRINGP ((IT)->string) \
19130 && ((IT)->what == IT_COMPOSITION); \ 19146 && ((IT)->what == IT_COMPOSITION); \
19131 EMACS_INT current_pos = \ 19147 ptrdiff_t current_pos = \
19132 composition_p ? (IT)->cmp_it.charpos \ 19148 composition_p ? (IT)->cmp_it.charpos \
19133 : IT_CHARPOS (*(IT)); \ 19149 : IT_CHARPOS (*(IT)); \
19134 EMACS_INT current_bpos = \ 19150 ptrdiff_t current_bpos = \
19135 composition_p ? CHAR_TO_BYTE (current_pos) \ 19151 composition_p ? CHAR_TO_BYTE (current_pos) \
19136 : IT_BYTEPOS (*(IT)); \ 19152 : IT_BYTEPOS (*(IT)); \
19137 if (current_pos < min_pos) \ 19153 if (current_pos < min_pos) \
@@ -19779,8 +19795,8 @@ See also `bidi-paragraph-direction'. */)
19779 use current_matrix if it is up to date, but this seems fast 19795 use current_matrix if it is up to date, but this seems fast
19780 enough as it is. */ 19796 enough as it is. */
19781 struct bidi_it itb; 19797 struct bidi_it itb;
19782 EMACS_INT pos = BUF_PT (buf); 19798 ptrdiff_t pos = BUF_PT (buf);
19783 EMACS_INT bytepos = BUF_PT_BYTE (buf); 19799 ptrdiff_t bytepos = BUF_PT_BYTE (buf);
19784 int c; 19800 int c;
19785 void *itb_data = bidi_shelve_cache (); 19801 void *itb_data = bidi_shelve_cache ();
19786 19802
@@ -20068,7 +20084,7 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
20068{ 20084{
20069 struct it it; 20085 struct it it;
20070 struct face *face; 20086 struct face *face;
20071 int count = SPECPDL_INDEX (); 20087 ptrdiff_t count = SPECPDL_INDEX ();
20072 20088
20073 init_iterator (&it, w, -1, -1, NULL, face_id); 20089 init_iterator (&it, w, -1, -1, NULL, face_id);
20074 /* Don't extend on a previously drawn mode-line. 20090 /* Don't extend on a previously drawn mode-line.
@@ -20204,7 +20220,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20204 { 20220 {
20205 /* A string: output it and check for %-constructs within it. */ 20221 /* A string: output it and check for %-constructs within it. */
20206 unsigned char c; 20222 unsigned char c;
20207 EMACS_INT offset = 0; 20223 ptrdiff_t offset = 0;
20208 20224
20209 if (SCHARS (elt) > 0 20225 if (SCHARS (elt) > 0
20210 && (!NILP (props) || risky)) 20226 && (!NILP (props) || risky))
@@ -20301,7 +20317,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20301 && (mode_line_target != MODE_LINE_DISPLAY 20317 && (mode_line_target != MODE_LINE_DISPLAY
20302 || it->current_x < it->last_visible_x)) 20318 || it->current_x < it->last_visible_x))
20303 { 20319 {
20304 EMACS_INT last_offset = offset; 20320 ptrdiff_t last_offset = offset;
20305 20321
20306 /* Advance to end of string or next format specifier. */ 20322 /* Advance to end of string or next format specifier. */
20307 while ((c = SREF (elt, offset++)) != '\0' && c != '%') 20323 while ((c = SREF (elt, offset++)) != '\0' && c != '%')
@@ -20309,7 +20325,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20309 20325
20310 if (offset - 1 != last_offset) 20326 if (offset - 1 != last_offset)
20311 { 20327 {
20312 EMACS_INT nchars, nbytes; 20328 ptrdiff_t nchars, nbytes;
20313 20329
20314 /* Output to end of string or up to '%'. Field width 20330 /* Output to end of string or up to '%'. Field width
20315 is length of string. Don't output more than 20331 is length of string. Don't output more than
@@ -20328,9 +20344,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20328 break; 20344 break;
20329 case MODE_LINE_STRING: 20345 case MODE_LINE_STRING:
20330 { 20346 {
20331 EMACS_INT bytepos = last_offset; 20347 ptrdiff_t bytepos = last_offset;
20332 EMACS_INT charpos = string_byte_to_char (elt, bytepos); 20348 ptrdiff_t charpos = string_byte_to_char (elt, bytepos);
20333 EMACS_INT endpos = (precision <= 0 20349 ptrdiff_t endpos = (precision <= 0
20334 ? string_byte_to_char (elt, offset) 20350 ? string_byte_to_char (elt, offset)
20335 : charpos + nchars); 20351 : charpos + nchars);
20336 20352
@@ -20342,8 +20358,8 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20342 break; 20358 break;
20343 case MODE_LINE_DISPLAY: 20359 case MODE_LINE_DISPLAY:
20344 { 20360 {
20345 EMACS_INT bytepos = last_offset; 20361 ptrdiff_t bytepos = last_offset;
20346 EMACS_INT charpos = string_byte_to_char (elt, bytepos); 20362 ptrdiff_t charpos = string_byte_to_char (elt, bytepos);
20347 20363
20348 if (precision <= 0) 20364 if (precision <= 0)
20349 nchars = string_byte_to_char (elt, offset) - charpos; 20365 nchars = string_byte_to_char (elt, offset) - charpos;
@@ -20356,7 +20372,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20356 } 20372 }
20357 else /* c == '%' */ 20373 else /* c == '%' */
20358 { 20374 {
20359 EMACS_INT percent_position = offset; 20375 ptrdiff_t percent_position = offset;
20360 20376
20361 /* Get the specified minimum width. Zero means 20377 /* Get the specified minimum width. Zero means
20362 don't pad. */ 20378 don't pad. */
@@ -20378,7 +20394,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
20378 else if (c != 0) 20394 else if (c != 0)
20379 { 20395 {
20380 int multibyte; 20396 int multibyte;
20381 EMACS_INT bytepos, charpos; 20397 ptrdiff_t bytepos, charpos;
20382 const char *spec; 20398 const char *spec;
20383 Lisp_Object string; 20399 Lisp_Object string;
20384 20400
@@ -20651,7 +20667,7 @@ static int
20651store_mode_line_string (const char *string, Lisp_Object lisp_string, int copy_string, 20667store_mode_line_string (const char *string, Lisp_Object lisp_string, int copy_string,
20652 int field_width, int precision, Lisp_Object props) 20668 int field_width, int precision, Lisp_Object props)
20653{ 20669{
20654 EMACS_INT len; 20670 ptrdiff_t len;
20655 int n = 0; 20671 int n = 0;
20656 20672
20657 if (string != NULL) 20673 if (string != NULL)
@@ -20752,7 +20768,7 @@ are the selected window and the WINDOW's buffer). */)
20752 struct buffer *old_buffer = NULL; 20768 struct buffer *old_buffer = NULL;
20753 int face_id; 20769 int face_id;
20754 int no_props = INTEGERP (face); 20770 int no_props = INTEGERP (face);
20755 int count = SPECPDL_INDEX (); 20771 ptrdiff_t count = SPECPDL_INDEX ();
20756 Lisp_Object str; 20772 Lisp_Object str;
20757 int string_start = 0; 20773 int string_start = 0;
20758 20774
@@ -20838,7 +20854,7 @@ are the selected window and the WINDOW's buffer). */)
20838 the positive integer D to BUF using a minimal field width WIDTH. */ 20854 the positive integer D to BUF using a minimal field width WIDTH. */
20839 20855
20840static void 20856static void
20841pint2str (register char *buf, register int width, register EMACS_INT d) 20857pint2str (register char *buf, register int width, register ptrdiff_t d)
20842{ 20858{
20843 register char *p = buf; 20859 register char *p = buf;
20844 20860
@@ -20882,11 +20898,11 @@ static const char power_letter[] =
20882 }; 20898 };
20883 20899
20884static void 20900static void
20885pint2hrstr (char *buf, int width, EMACS_INT d) 20901pint2hrstr (char *buf, int width, ptrdiff_t d)
20886{ 20902{
20887 /* We aim to represent the nonnegative integer D as 20903 /* We aim to represent the nonnegative integer D as
20888 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */ 20904 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20889 EMACS_INT quotient = d; 20905 ptrdiff_t quotient = d;
20890 int remainder = 0; 20906 int remainder = 0;
20891 /* -1 means: do not use TENTHS. */ 20907 /* -1 means: do not use TENTHS. */
20892 int tenths = -1; 20908 int tenths = -1;
@@ -20996,8 +21012,7 @@ decode_mode_spec_coding (Lisp_Object coding_system, register char *buf, int eol_
20996 21012
20997 if (!VECTORP (val)) /* Not yet decided. */ 21013 if (!VECTORP (val)) /* Not yet decided. */
20998 { 21014 {
20999 if (multibyte) 21015 *buf++ = multibyte ? '-' : ' ';
21000 *buf++ = '-';
21001 if (eol_flag) 21016 if (eol_flag)
21002 eoltype = eol_mnemonic_undecided; 21017 eoltype = eol_mnemonic_undecided;
21003 /* Don't mention EOL conversion if it isn't decided. */ 21018 /* Don't mention EOL conversion if it isn't decided. */
@@ -21010,8 +21025,9 @@ decode_mode_spec_coding (Lisp_Object coding_system, register char *buf, int eol_
21010 attrs = AREF (val, 0); 21025 attrs = AREF (val, 0);
21011 eolvalue = AREF (val, 2); 21026 eolvalue = AREF (val, 2);
21012 21027
21013 if (multibyte) 21028 *buf++ = multibyte
21014 *buf++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs)); 21029 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs))
21030 : ' ';
21015 21031
21016 if (eol_flag) 21032 if (eol_flag)
21017 { 21033 {
@@ -21166,7 +21182,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21166 return ""; 21182 return "";
21167 else 21183 else
21168 { 21184 {
21169 EMACS_INT col = current_column (); 21185 ptrdiff_t col = current_column ();
21170 w->column_number_displayed = make_number (col); 21186 w->column_number_displayed = make_number (col);
21171 pint2str (decode_mode_spec_buf, field_width, col); 21187 pint2str (decode_mode_spec_buf, field_width, col);
21172 return decode_mode_spec_buf; 21188 return decode_mode_spec_buf;
@@ -21198,23 +21214,23 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21198 21214
21199 case 'i': 21215 case 'i':
21200 { 21216 {
21201 EMACS_INT size = ZV - BEGV; 21217 ptrdiff_t size = ZV - BEGV;
21202 pint2str (decode_mode_spec_buf, field_width, size); 21218 pint2str (decode_mode_spec_buf, field_width, size);
21203 return decode_mode_spec_buf; 21219 return decode_mode_spec_buf;
21204 } 21220 }
21205 21221
21206 case 'I': 21222 case 'I':
21207 { 21223 {
21208 EMACS_INT size = ZV - BEGV; 21224 ptrdiff_t size = ZV - BEGV;
21209 pint2hrstr (decode_mode_spec_buf, field_width, size); 21225 pint2hrstr (decode_mode_spec_buf, field_width, size);
21210 return decode_mode_spec_buf; 21226 return decode_mode_spec_buf;
21211 } 21227 }
21212 21228
21213 case 'l': 21229 case 'l':
21214 { 21230 {
21215 EMACS_INT startpos, startpos_byte, line, linepos, linepos_byte; 21231 ptrdiff_t startpos, startpos_byte, line, linepos, linepos_byte;
21216 EMACS_INT topline, nlines, height; 21232 ptrdiff_t topline, nlines, height;
21217 EMACS_INT junk; 21233 ptrdiff_t junk;
21218 21234
21219 /* %c and %l are ignored in `frame-title-format'. */ 21235 /* %c and %l are ignored in `frame-title-format'. */
21220 if (mode_line_target == MODE_LINE_TITLE) 21236 if (mode_line_target == MODE_LINE_TITLE)
@@ -21275,10 +21291,10 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21275 else if (nlines < height + 25 || nlines > height * 3 + 50 21291 else if (nlines < height + 25 || nlines > height * 3 + 50
21276 || linepos == BUF_BEGV (b)) 21292 || linepos == BUF_BEGV (b))
21277 { 21293 {
21278 EMACS_INT limit = BUF_BEGV (b); 21294 ptrdiff_t limit = BUF_BEGV (b);
21279 EMACS_INT limit_byte = BUF_BEGV_BYTE (b); 21295 ptrdiff_t limit_byte = BUF_BEGV_BYTE (b);
21280 EMACS_INT position; 21296 ptrdiff_t position;
21281 EMACS_INT distance = 21297 ptrdiff_t distance =
21282 (height * 2 + 30) * line_number_display_limit_width; 21298 (height * 2 + 30) * line_number_display_limit_width;
21283 21299
21284 if (startpos - distance > limit) 21300 if (startpos - distance > limit)
@@ -21340,8 +21356,8 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21340 21356
21341 case 'p': 21357 case 'p':
21342 { 21358 {
21343 EMACS_INT pos = marker_position (w->start); 21359 ptrdiff_t pos = marker_position (w->start);
21344 EMACS_INT total = BUF_ZV (b) - BUF_BEGV (b); 21360 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
21345 21361
21346 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b)) 21362 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b))
21347 { 21363 {
@@ -21363,7 +21379,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21363 so get us a 2-digit number that is close. */ 21379 so get us a 2-digit number that is close. */
21364 if (total == 100) 21380 if (total == 100)
21365 total = 99; 21381 total = 99;
21366 sprintf (decode_mode_spec_buf, "%2"pI"d%%", total); 21382 sprintf (decode_mode_spec_buf, "%2"pD"d%%", total);
21367 return decode_mode_spec_buf; 21383 return decode_mode_spec_buf;
21368 } 21384 }
21369 } 21385 }
@@ -21371,9 +21387,9 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21371 /* Display percentage of size above the bottom of the screen. */ 21387 /* Display percentage of size above the bottom of the screen. */
21372 case 'P': 21388 case 'P':
21373 { 21389 {
21374 EMACS_INT toppos = marker_position (w->start); 21390 ptrdiff_t toppos = marker_position (w->start);
21375 EMACS_INT botpos = BUF_Z (b) - XFASTINT (w->window_end_pos); 21391 ptrdiff_t botpos = BUF_Z (b) - XFASTINT (w->window_end_pos);
21376 EMACS_INT total = BUF_ZV (b) - BUF_BEGV (b); 21392 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
21377 21393
21378 if (botpos >= BUF_ZV (b)) 21394 if (botpos >= BUF_ZV (b))
21379 { 21395 {
@@ -21394,9 +21410,9 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21394 if (total == 100) 21410 if (total == 100)
21395 total = 99; 21411 total = 99;
21396 if (toppos <= BUF_BEGV (b)) 21412 if (toppos <= BUF_BEGV (b))
21397 sprintf (decode_mode_spec_buf, "Top%2"pI"d%%", total); 21413 sprintf (decode_mode_spec_buf, "Top%2"pD"d%%", total);
21398 else 21414 else
21399 sprintf (decode_mode_spec_buf, "%2"pI"d%%", total); 21415 sprintf (decode_mode_spec_buf, "%2"pD"d%%", total);
21400 return decode_mode_spec_buf; 21416 return decode_mode_spec_buf;
21401 } 21417 }
21402 } 21418 }
@@ -21413,7 +21429,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21413 21429
21414 case '@': 21430 case '@':
21415 { 21431 {
21416 int count = inhibit_garbage_collection (); 21432 ptrdiff_t count = inhibit_garbage_collection ();
21417 Lisp_Object val = call1 (intern ("file-remote-p"), 21433 Lisp_Object val = call1 (intern ("file-remote-p"),
21418 BVAR (current_buffer, directory)); 21434 BVAR (current_buffer, directory));
21419 unbind_to (count, Qnil); 21435 unbind_to (count, Qnil);
@@ -21482,17 +21498,17 @@ decode_mode_spec (struct window *w, register int c, int field_width,
21482 21498
21483 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */ 21499 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21484 21500
21485static EMACS_INT 21501static ptrdiff_t
21486display_count_lines (EMACS_INT start_byte, 21502display_count_lines (ptrdiff_t start_byte,
21487 EMACS_INT limit_byte, EMACS_INT count, 21503 ptrdiff_t limit_byte, ptrdiff_t count,
21488 EMACS_INT *byte_pos_ptr) 21504 ptrdiff_t *byte_pos_ptr)
21489{ 21505{
21490 register unsigned char *cursor; 21506 register unsigned char *cursor;
21491 unsigned char *base; 21507 unsigned char *base;
21492 21508
21493 register EMACS_INT ceiling; 21509 register ptrdiff_t ceiling;
21494 register unsigned char *ceiling_addr; 21510 register unsigned char *ceiling_addr;
21495 EMACS_INT orig_count = count; 21511 ptrdiff_t orig_count = count;
21496 21512
21497 /* If we are not in selective display mode, 21513 /* If we are not in selective display mode,
21498 check only for newlines. */ 21514 check only for newlines. */
@@ -21626,13 +21642,13 @@ display_count_lines (EMACS_INT start_byte,
21626 21642
21627static int 21643static int
21628display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_string, 21644display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_string,
21629 EMACS_INT face_string_pos, EMACS_INT start, struct it *it, 21645 ptrdiff_t face_string_pos, ptrdiff_t start, struct it *it,
21630 int field_width, int precision, int max_x, int multibyte) 21646 int field_width, int precision, int max_x, int multibyte)
21631{ 21647{
21632 int hpos_at_start = it->hpos; 21648 int hpos_at_start = it->hpos;
21633 int saved_face_id = it->face_id; 21649 int saved_face_id = it->face_id;
21634 struct glyph_row *row = it->glyph_row; 21650 struct glyph_row *row = it->glyph_row;
21635 EMACS_INT it_charpos; 21651 ptrdiff_t it_charpos;
21636 21652
21637 /* Initialize the iterator IT for iteration over STRING beginning 21653 /* Initialize the iterator IT for iteration over STRING beginning
21638 with index START. */ 21654 with index START. */
@@ -21647,7 +21663,7 @@ display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_st
21647 FACE_STRING, if that's given. */ 21663 FACE_STRING, if that's given. */
21648 if (STRINGP (face_string)) 21664 if (STRINGP (face_string))
21649 { 21665 {
21650 EMACS_INT endptr; 21666 ptrdiff_t endptr;
21651 struct face *face; 21667 struct face *face;
21652 21668
21653 it->face_id 21669 it->face_id
@@ -22076,7 +22092,9 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
22076 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it->w)); 22092 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it->w));
22077 } 22093 }
22078 22094
22079 prop = Fbuffer_local_value (prop, it->w->buffer); 22095 prop = buffer_local_value_1 (prop, it->w->buffer);
22096 if (EQ (prop, Qunbound))
22097 prop = Qnil;
22080 } 22098 }
22081 22099
22082 if (INTEGERP (prop) || FLOATP (prop)) 22100 if (INTEGERP (prop) || FLOATP (prop))
@@ -22126,7 +22144,9 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
22126 return OK_PIXELS (pixels); 22144 return OK_PIXELS (pixels);
22127 } 22145 }
22128 22146
22129 car = Fbuffer_local_value (car, it->w->buffer); 22147 car = buffer_local_value_1 (car, it->w->buffer);
22148 if (EQ (car, Qunbound))
22149 car = Qnil;
22130 } 22150 }
22131 22151
22132 if (INTEGERP (car) || FLOATP (car)) 22152 if (INTEGERP (car) || FLOATP (car))
@@ -23134,7 +23154,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p)
23134 23154
23135static int 23155static int
23136draw_glyphs (struct window *w, int x, struct glyph_row *row, 23156draw_glyphs (struct window *w, int x, struct glyph_row *row,
23137 enum glyph_row_area area, EMACS_INT start, EMACS_INT end, 23157 enum glyph_row_area area, ptrdiff_t start, ptrdiff_t end,
23138 enum draw_glyphs_face hl, int overlaps) 23158 enum draw_glyphs_face hl, int overlaps)
23139{ 23159{
23140 struct glyph_string *head, *tail; 23160 struct glyph_string *head, *tail;
@@ -24598,7 +24618,7 @@ x_produce_glyphs (struct it *it)
24598 XChar2b char2b; 24618 XChar2b char2b;
24599 struct font_metrics *pcm; 24619 struct font_metrics *pcm;
24600 int font_not_found_p; 24620 int font_not_found_p;
24601 EMACS_INT pos; 24621 ptrdiff_t pos;
24602 24622
24603 for (glyph_len = cmp->glyph_len; glyph_len > 0; glyph_len--) 24623 for (glyph_len = cmp->glyph_len; glyph_len > 0; glyph_len--)
24604 if ((c = COMPOSITION_GLYPH (cmp, glyph_len - 1)) != '\t') 24624 if ((c = COMPOSITION_GLYPH (cmp, glyph_len - 1)) != '\t')
@@ -25006,7 +25026,7 @@ x_insert_glyphs (struct glyph *start, int len)
25006 struct glyph_row *row; 25026 struct glyph_row *row;
25007 struct glyph *glyph; 25027 struct glyph *glyph;
25008 int frame_x, frame_y; 25028 int frame_x, frame_y;
25009 EMACS_INT hpos; 25029 ptrdiff_t hpos;
25010 25030
25011 xassert (updated_window && updated_row); 25031 xassert (updated_window && updated_row);
25012 BLOCK_INPUT; 25032 BLOCK_INPUT;
@@ -25153,8 +25173,7 @@ get_specified_cursor_type (Lisp_Object arg, int *width)
25153 25173
25154 if (CONSP (arg) 25174 if (CONSP (arg)
25155 && EQ (XCAR (arg), Qbar) 25175 && EQ (XCAR (arg), Qbar)
25156 && INTEGERP (XCDR (arg)) 25176 && RANGED_INTEGERP (0, XCDR (arg), INT_MAX))
25157 && XINT (XCDR (arg)) >= 0)
25158 { 25177 {
25159 *width = XINT (XCDR (arg)); 25178 *width = XINT (XCDR (arg));
25160 return BAR_CURSOR; 25179 return BAR_CURSOR;
@@ -25168,8 +25187,7 @@ get_specified_cursor_type (Lisp_Object arg, int *width)
25168 25187
25169 if (CONSP (arg) 25188 if (CONSP (arg)
25170 && EQ (XCAR (arg), Qhbar) 25189 && EQ (XCAR (arg), Qhbar)
25171 && INTEGERP (XCDR (arg)) 25190 && RANGED_INTEGERP (0, XCDR (arg), INT_MAX))
25172 && XINT (XCDR (arg)) >= 0)
25173 { 25191 {
25174 *width = XINT (XCDR (arg)); 25192 *width = XINT (XCDR (arg));
25175 return HBAR_CURSOR; 25193 return HBAR_CURSOR;
@@ -25827,7 +25845,7 @@ draw_row_with_mouse_face (struct window *w, int start_x, struct glyph_row *row,
25827 return; 25845 return;
25828 } 25846 }
25829#endif 25847#endif
25830#if defined (HAVE_GPM) || defined (MSDOS) 25848#if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
25831 tty_draw_row_with_mouse_face (w, row, start_hpos, end_hpos, draw); 25849 tty_draw_row_with_mouse_face (w, row, start_hpos, end_hpos, draw);
25832#endif 25850#endif
25833} 25851}
@@ -26066,7 +26084,7 @@ cursor_in_mouse_face_p (struct window *w)
26066 buffer positions change non-linearly with glyph rows. */ 26084 buffer positions change non-linearly with glyph rows. */
26067static void 26085static void
26068rows_from_pos_range (struct window *w, 26086rows_from_pos_range (struct window *w,
26069 EMACS_INT start_charpos, EMACS_INT end_charpos, 26087 ptrdiff_t start_charpos, ptrdiff_t end_charpos,
26070 Lisp_Object disp_string, 26088 Lisp_Object disp_string,
26071 struct glyph_row **start, struct glyph_row **end) 26089 struct glyph_row **start, struct glyph_row **end)
26072{ 26090{
@@ -26142,7 +26160,7 @@ rows_from_pos_range (struct window *w,
26142 for ( ; row->enabled_p && MATRIX_ROW_BOTTOM_Y (row) <= last_y; row++) 26160 for ( ; row->enabled_p && MATRIX_ROW_BOTTOM_Y (row) <= last_y; row++)
26143 { 26161 {
26144 struct glyph_row *next = row + 1; 26162 struct glyph_row *next = row + 1;
26145 EMACS_INT next_start = MATRIX_ROW_START_CHARPOS (next); 26163 ptrdiff_t next_start = MATRIX_ROW_START_CHARPOS (next);
26146 26164
26147 if (!next->enabled_p 26165 if (!next->enabled_p
26148 || next >= MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w) 26166 || next >= MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w)
@@ -26223,9 +26241,9 @@ rows_from_pos_range (struct window *w,
26223static void 26241static void
26224mouse_face_from_buffer_pos (Lisp_Object window, 26242mouse_face_from_buffer_pos (Lisp_Object window,
26225 Mouse_HLInfo *hlinfo, 26243 Mouse_HLInfo *hlinfo,
26226 EMACS_INT mouse_charpos, 26244 ptrdiff_t mouse_charpos,
26227 EMACS_INT start_charpos, 26245 ptrdiff_t start_charpos,
26228 EMACS_INT end_charpos, 26246 ptrdiff_t end_charpos,
26229 Lisp_Object before_string, 26247 Lisp_Object before_string,
26230 Lisp_Object after_string, 26248 Lisp_Object after_string,
26231 Lisp_Object disp_string) 26249 Lisp_Object disp_string)
@@ -26234,7 +26252,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26234 struct glyph_row *first = MATRIX_FIRST_TEXT_ROW (w->current_matrix); 26252 struct glyph_row *first = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
26235 struct glyph_row *r1, *r2; 26253 struct glyph_row *r1, *r2;
26236 struct glyph *glyph, *end; 26254 struct glyph *glyph, *end;
26237 EMACS_INT ignore, pos; 26255 ptrdiff_t ignore, pos;
26238 int x; 26256 int x;
26239 26257
26240 xassert (NILP (disp_string) || STRINGP (disp_string)); 26258 xassert (NILP (disp_string) || STRINGP (disp_string));
@@ -26567,7 +26585,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26567 Value is non-zero if a glyph was found. */ 26585 Value is non-zero if a glyph was found. */
26568 26586
26569static int 26587static int
26570fast_find_string_pos (struct window *w, EMACS_INT pos, Lisp_Object object, 26588fast_find_string_pos (struct window *w, ptrdiff_t pos, Lisp_Object object,
26571 int *hpos, int *vpos, int *x, int *y, int right_p) 26589 int *hpos, int *vpos, int *x, int *y, int right_p)
26572{ 26590{
26573 int yb = window_text_bottom_y (w); 26591 int yb = window_text_bottom_y (w);
@@ -26637,7 +26655,7 @@ fast_find_string_pos (struct window *w, EMACS_INT pos, Lisp_Object object,
26637static void 26655static void
26638mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo, 26656mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
26639 Lisp_Object object, 26657 Lisp_Object object,
26640 EMACS_INT startpos, EMACS_INT endpos) 26658 ptrdiff_t startpos, ptrdiff_t endpos)
26641{ 26659{
26642 int yb = window_text_bottom_y (w); 26660 int yb = window_text_bottom_y (w);
26643 struct glyph_row *r; 26661 struct glyph_row *r;
@@ -26807,8 +26825,8 @@ on_hot_spot_p (Lisp_Object hot_spot, int x, int y)
26807 { 26825 {
26808 struct Lisp_Vector *v = XVECTOR (XCDR (hot_spot)); 26826 struct Lisp_Vector *v = XVECTOR (XCDR (hot_spot));
26809 Lisp_Object *poly = v->contents; 26827 Lisp_Object *poly = v->contents;
26810 int n = v->header.size; 26828 ptrdiff_t n = v->header.size;
26811 int i; 26829 ptrdiff_t i;
26812 int inside = 0; 26830 int inside = 0;
26813 Lisp_Object lx, ly; 26831 Lisp_Object lx, ly;
26814 int x0, y0; 26832 int x0, y0;
@@ -26886,7 +26904,9 @@ Returns the alist element for the first matching AREA in MAP. */)
26886 CHECK_NUMBER (x); 26904 CHECK_NUMBER (x);
26887 CHECK_NUMBER (y); 26905 CHECK_NUMBER (y);
26888 26906
26889 return find_hot_spot (map, XINT (x), XINT (y)); 26907 return find_hot_spot (map,
26908 clip_to_bounds (INT_MIN, XINT (x), INT_MAX),
26909 clip_to_bounds (INT_MIN, XINT (y), INT_MAX));
26890} 26910}
26891 26911
26892 26912
@@ -26945,14 +26965,14 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
26945 Cursor cursor = No_Cursor; 26965 Cursor cursor = No_Cursor;
26946 Lisp_Object pointer = Qnil; 26966 Lisp_Object pointer = Qnil;
26947 int dx, dy, width, height; 26967 int dx, dy, width, height;
26948 EMACS_INT charpos; 26968 ptrdiff_t charpos;
26949 Lisp_Object string, object = Qnil; 26969 Lisp_Object string, object = Qnil;
26950 Lisp_Object pos, help; 26970 Lisp_Object pos IF_LINT (= Qnil), help;
26951 26971
26952 Lisp_Object mouse_face; 26972 Lisp_Object mouse_face;
26953 int original_x_pixel = x; 26973 int original_x_pixel = x;
26954 struct glyph * glyph = NULL, * row_start_glyph = NULL; 26974 struct glyph * glyph = NULL, * row_start_glyph = NULL;
26955 struct glyph_row *row; 26975 struct glyph_row *row IF_LINT (= 0);
26956 26976
26957 if (area == ON_MODE_LINE || area == ON_HEADER_LINE) 26977 if (area == ON_MODE_LINE || area == ON_HEADER_LINE)
26958 { 26978 {
@@ -27020,7 +27040,6 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27020 if (!NILP (help)) 27040 if (!NILP (help))
27021 { 27041 {
27022 help_echo_string = help; 27042 help_echo_string = help;
27023 /* Is this correct? ++kfs */
27024 XSETWINDOW (help_echo_window, w); 27043 XSETWINDOW (help_echo_window, w);
27025 help_echo_object = w->buffer; 27044 help_echo_object = w->buffer;
27026 help_echo_pos = charpos; 27045 help_echo_pos = charpos;
@@ -27033,14 +27052,20 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27033#endif /* HAVE_WINDOW_SYSTEM */ 27052#endif /* HAVE_WINDOW_SYSTEM */
27034 27053
27035 if (STRINGP (string)) 27054 if (STRINGP (string))
27055 pos = make_number (charpos);
27056
27057 /* Set the help text and mouse pointer. If the mouse is on a part
27058 of the mode line without any text (e.g. past the right edge of
27059 the mode line text), use the default help text and pointer. */
27060 if (STRINGP (string) || area == ON_MODE_LINE)
27036 { 27061 {
27037 pos = make_number (charpos); 27062 /* Arrange to display the help by setting the global variables
27038 /* If we're on a string with `help-echo' text property, arrange 27063 help_echo_string, help_echo_object, and help_echo_pos. */
27039 for the help to be displayed. This is done by setting the
27040 global variable help_echo_string to the help string. */
27041 if (NILP (help)) 27064 if (NILP (help))
27042 { 27065 {
27043 help = Fget_text_property (pos, Qhelp_echo, string); 27066 if (STRINGP (string))
27067 help = Fget_text_property (pos, Qhelp_echo, string);
27068
27044 if (!NILP (help)) 27069 if (!NILP (help))
27045 { 27070 {
27046 help_echo_string = help; 27071 help_echo_string = help;
@@ -27048,31 +27073,56 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27048 help_echo_object = string; 27073 help_echo_object = string;
27049 help_echo_pos = charpos; 27074 help_echo_pos = charpos;
27050 } 27075 }
27076 else if (area == ON_MODE_LINE)
27077 {
27078 Lisp_Object default_help
27079 = buffer_local_value_1 (Qmode_line_default_help_echo,
27080 w->buffer);
27081
27082 if (STRINGP (default_help))
27083 {
27084 help_echo_string = default_help;
27085 XSETWINDOW (help_echo_window, w);
27086 help_echo_object = Qnil;
27087 help_echo_pos = -1;
27088 }
27089 }
27051 } 27090 }
27052 27091
27053#ifdef HAVE_WINDOW_SYSTEM 27092#ifdef HAVE_WINDOW_SYSTEM
27093 /* Change the mouse pointer according to what is under it. */
27054 if (FRAME_WINDOW_P (f)) 27094 if (FRAME_WINDOW_P (f))
27055 { 27095 {
27056 dpyinfo = FRAME_X_DISPLAY_INFO (f); 27096 dpyinfo = FRAME_X_DISPLAY_INFO (f);
27057 cursor = FRAME_X_OUTPUT (f)->nontext_cursor; 27097 if (STRINGP (string))
27058 if (NILP (pointer))
27059 pointer = Fget_text_property (pos, Qpointer, string);
27060
27061 /* Change the mouse pointer according to what is under X/Y. */
27062 if (NILP (pointer)
27063 && ((area == ON_MODE_LINE) || (area == ON_HEADER_LINE)))
27064 { 27098 {
27065 Lisp_Object map; 27099 cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
27066 map = Fget_text_property (pos, Qlocal_map, string); 27100
27067 if (!KEYMAPP (map)) 27101 if (NILP (pointer))
27068 map = Fget_text_property (pos, Qkeymap, string); 27102 pointer = Fget_text_property (pos, Qpointer, string);
27069 if (!KEYMAPP (map)) 27103
27070 cursor = dpyinfo->vertical_scroll_bar_cursor; 27104 /* Change the mouse pointer according to what is under X/Y. */
27105 if (NILP (pointer)
27106 && ((area == ON_MODE_LINE) || (area == ON_HEADER_LINE)))
27107 {
27108 Lisp_Object map;
27109 map = Fget_text_property (pos, Qlocal_map, string);
27110 if (!KEYMAPP (map))
27111 map = Fget_text_property (pos, Qkeymap, string);
27112 if (!KEYMAPP (map))
27113 cursor = dpyinfo->vertical_scroll_bar_cursor;
27114 }
27071 } 27115 }
27116 else
27117 /* Default mode-line pointer. */
27118 cursor = FRAME_X_DISPLAY_INFO (f)->vertical_scroll_bar_cursor;
27072 } 27119 }
27073#endif 27120#endif
27121 }
27074 27122
27075 /* Change the mouse face according to what is under X/Y. */ 27123 /* Change the mouse face according to what is under X/Y. */
27124 if (STRINGP (string))
27125 {
27076 mouse_face = Fget_text_property (pos, Qmouse_face, string); 27126 mouse_face = Fget_text_property (pos, Qmouse_face, string);
27077 if (!NILP (mouse_face) 27127 if (!NILP (mouse_face)
27078 && ((area == ON_MODE_LINE) || (area == ON_HEADER_LINE)) 27128 && ((area == ON_MODE_LINE) || (area == ON_HEADER_LINE))
@@ -27085,7 +27135,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
27085 int gpos; 27135 int gpos;
27086 int gseq_length; 27136 int gseq_length;
27087 int total_pixel_width; 27137 int total_pixel_width;
27088 EMACS_INT begpos, endpos, ignore; 27138 ptrdiff_t begpos, endpos, ignore;
27089 27139
27090 int vpos, hpos; 27140 int vpos, hpos;
27091 27141
@@ -27315,14 +27365,14 @@ note_mouse_highlight (struct frame *f, int x, int y)
27315 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) 27365 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
27316 { 27366 {
27317 int hpos, vpos, dx, dy, area = LAST_AREA; 27367 int hpos, vpos, dx, dy, area = LAST_AREA;
27318 EMACS_INT pos; 27368 ptrdiff_t pos;
27319 struct glyph *glyph; 27369 struct glyph *glyph;
27320 Lisp_Object object; 27370 Lisp_Object object;
27321 Lisp_Object mouse_face = Qnil, position; 27371 Lisp_Object mouse_face = Qnil, position;
27322 Lisp_Object *overlay_vec = NULL; 27372 Lisp_Object *overlay_vec = NULL;
27323 ptrdiff_t i, noverlays; 27373 ptrdiff_t i, noverlays;
27324 struct buffer *obuf; 27374 struct buffer *obuf;
27325 EMACS_INT obegv, ozv; 27375 ptrdiff_t obegv, ozv;
27326 int same_region; 27376 int same_region;
27327 27377
27328 /* Find the glyph under X/Y. */ 27378 /* Find the glyph under X/Y. */
@@ -27480,7 +27530,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27480 /* The mouse-highlighting comes from a display string 27530 /* The mouse-highlighting comes from a display string
27481 with a mouse-face. */ 27531 with a mouse-face. */
27482 Lisp_Object s, e; 27532 Lisp_Object s, e;
27483 EMACS_INT ignore; 27533 ptrdiff_t ignore;
27484 27534
27485 s = Fprevious_single_property_change 27535 s = Fprevious_single_property_change
27486 (make_number (pos + 1), Qmouse_face, object, Qnil); 27536 (make_number (pos + 1), Qmouse_face, object, Qnil);
@@ -27512,7 +27562,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27512 /* If we are on a display string with no mouse-face, 27562 /* If we are on a display string with no mouse-face,
27513 check if the text under it has one. */ 27563 check if the text under it has one. */
27514 struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos); 27564 struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos);
27515 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27565 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27516 pos = string_buffer_position (object, start); 27566 pos = string_buffer_position (object, start);
27517 if (pos > 0) 27567 if (pos > 0)
27518 { 27568 {
@@ -27611,7 +27661,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27611 else 27661 else
27612 { 27662 {
27613 Lisp_Object obj = glyph->object; 27663 Lisp_Object obj = glyph->object;
27614 EMACS_INT charpos = glyph->charpos; 27664 ptrdiff_t charpos = glyph->charpos;
27615 27665
27616 /* Try text properties. */ 27666 /* Try text properties. */
27617 if (STRINGP (obj) 27667 if (STRINGP (obj)
@@ -27626,8 +27676,8 @@ note_mouse_highlight (struct frame *f, int x, int y)
27626 see if the buffer text ``under'' it does. */ 27676 see if the buffer text ``under'' it does. */
27627 struct glyph_row *r 27677 struct glyph_row *r
27628 = MATRIX_ROW (w->current_matrix, vpos); 27678 = MATRIX_ROW (w->current_matrix, vpos);
27629 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27679 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27630 EMACS_INT p = string_buffer_position (obj, start); 27680 ptrdiff_t p = string_buffer_position (obj, start);
27631 if (p > 0) 27681 if (p > 0)
27632 { 27682 {
27633 help = Fget_char_property (make_number (p), 27683 help = Fget_char_property (make_number (p),
@@ -27667,7 +27717,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27667 if (NILP (pointer)) 27717 if (NILP (pointer))
27668 { 27718 {
27669 Lisp_Object obj = glyph->object; 27719 Lisp_Object obj = glyph->object;
27670 EMACS_INT charpos = glyph->charpos; 27720 ptrdiff_t charpos = glyph->charpos;
27671 27721
27672 /* Try text properties. */ 27722 /* Try text properties. */
27673 if (STRINGP (obj) 27723 if (STRINGP (obj)
@@ -27682,8 +27732,8 @@ note_mouse_highlight (struct frame *f, int x, int y)
27682 see if the buffer text ``under'' it does. */ 27732 see if the buffer text ``under'' it does. */
27683 struct glyph_row *r 27733 struct glyph_row *r
27684 = MATRIX_ROW (w->current_matrix, vpos); 27734 = MATRIX_ROW (w->current_matrix, vpos);
27685 EMACS_INT start = MATRIX_ROW_START_CHARPOS (r); 27735 ptrdiff_t start = MATRIX_ROW_START_CHARPOS (r);
27686 EMACS_INT p = string_buffer_position (obj, start); 27736 ptrdiff_t p = string_buffer_position (obj, start);
27687 if (p > 0) 27737 if (p > 0)
27688 pointer = Fget_char_property (make_number (p), 27738 pointer = Fget_char_property (make_number (p),
27689 Qpointer, w->buffer); 27739 Qpointer, w->buffer);
@@ -28413,6 +28463,8 @@ syms_of_xdisp (void)
28413 Vmode_line_unwind_vector = Qnil; 28463 Vmode_line_unwind_vector = Qnil;
28414 staticpro (&Vmode_line_unwind_vector); 28464 staticpro (&Vmode_line_unwind_vector);
28415 28465
28466 DEFSYM (Qmode_line_default_help_echo, "mode-line-default-help-echo");
28467
28416 help_echo_string = Qnil; 28468 help_echo_string = Qnil;
28417 staticpro (&help_echo_string); 28469 staticpro (&help_echo_string);
28418 help_echo_object = Qnil; 28470 help_echo_object = Qnil;
@@ -28693,7 +28745,9 @@ It can be one of
28693 both - show both, text below image 28745 both - show both, text below image
28694 both-horiz - show text to the right of the image 28746 both-horiz - show text to the right of the image
28695 text-image-horiz - show text to the left of the image 28747 text-image-horiz - show text to the left of the image
28696 any other - use system default or image if no system default. */); 28748 any other - use system default or image if no system default.
28749
28750This variable only affects the GTK+ toolkit version of Emacs. */);
28697 Vtool_bar_style = Qnil; 28751 Vtool_bar_style = Qnil;
28698 28752
28699 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size, 28753 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size,
@@ -28972,23 +29026,16 @@ start_hourglass (void)
28972{ 29026{
28973#if defined (HAVE_WINDOW_SYSTEM) 29027#if defined (HAVE_WINDOW_SYSTEM)
28974 EMACS_TIME delay; 29028 EMACS_TIME delay;
28975 int secs, usecs = 0; 29029 int secs = DEFAULT_HOURGLASS_DELAY, usecs = 0;
28976 29030
28977 cancel_hourglass (); 29031 cancel_hourglass ();
28978 29032
28979 if (INTEGERP (Vhourglass_delay) 29033 if (NUMBERP (Vhourglass_delay))
28980 && XINT (Vhourglass_delay) > 0)
28981 secs = XFASTINT (Vhourglass_delay);
28982 else if (FLOATP (Vhourglass_delay)
28983 && XFLOAT_DATA (Vhourglass_delay) > 0)
28984 { 29034 {
28985 Lisp_Object tem; 29035 double duration = extract_float (Vhourglass_delay);
28986 tem = Ftruncate (Vhourglass_delay, Qnil); 29036 if (0 < duration)
28987 secs = XFASTINT (tem); 29037 duration_to_sec_usec (duration, &secs, &usecs);
28988 usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000;
28989 } 29038 }
28990 else
28991 secs = DEFAULT_HOURGLASS_DELAY;
28992 29039
28993 EMACS_SET_SECS_USECS (delay, secs, usecs); 29040 EMACS_SET_SECS_USECS (delay, secs, usecs);
28994 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, 29041 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 510a66d6349..43ccdfaef1a 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -126,17 +126,9 @@ extern LWLIB_ID widget_id_tick;
126 126
127#define MAXREQUEST(dpy) (XMaxRequestSize (dpy)) 127#define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
128 128
129/* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
130 it, and including `bitmaps/gray' more than once is a problem when
131 config.h defines `static' as an empty replacement string. */
132
133int gray_bitmap_width = gray_width;
134int gray_bitmap_height = gray_height;
135char *gray_bitmap_bits = gray_bits;
136
137/* Nonzero if using X. */ 129/* Nonzero if using X. */
138 130
139static int x_in_use; 131int x_in_use;
140 132
141static Lisp_Object Qnone; 133static Lisp_Object Qnone;
142static Lisp_Object Qsuppress_icon; 134static Lisp_Object Qsuppress_icon;
@@ -1200,7 +1192,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1200 if (FRAME_MINIBUF_ONLY_P (f)) 1192 if (FRAME_MINIBUF_ONLY_P (f))
1201 return; 1193 return;
1202 1194
1203 if (INTEGERP (value)) 1195 if (TYPE_RANGED_INTEGERP (int, value))
1204 nlines = XINT (value); 1196 nlines = XINT (value);
1205 else 1197 else
1206 nlines = 0; 1198 nlines = 0;
@@ -1215,7 +1207,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1215 FRAME_EXTERNAL_MENU_BAR (f) = 1; 1207 FRAME_EXTERNAL_MENU_BAR (f) = 1;
1216 if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0) 1208 if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0)
1217 /* Make sure next redisplay shows the menu bar. */ 1209 /* Make sure next redisplay shows the menu bar. */
1218 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; 1210 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1;
1219 } 1211 }
1220 else 1212 else
1221 { 1213 {
@@ -1286,8 +1278,8 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1286 if (FRAME_MINIBUF_ONLY_P (f)) 1278 if (FRAME_MINIBUF_ONLY_P (f))
1287 return; 1279 return;
1288 1280
1289 /* Use VALUE only if an integer >= 0. */ 1281 /* Use VALUE only if an int >= 0. */
1290 if (INTEGERP (value) && XINT (value) >= 0) 1282 if (RANGED_INTEGERP (0, value, INT_MAX))
1291 nlines = XFASTINT (value); 1283 nlines = XFASTINT (value);
1292 else 1284 else
1293 nlines = 0; 1285 nlines = 0;
@@ -1299,7 +1291,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1299 FRAME_EXTERNAL_TOOL_BAR (f) = 1; 1291 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
1300 if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0) 1292 if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0)
1301 /* Make sure next redisplay shows the tool bar. */ 1293 /* Make sure next redisplay shows the tool bar. */
1302 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; 1294 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1;
1303 update_frame_tool_bar (f); 1295 update_frame_tool_bar (f);
1304 } 1296 }
1305 else 1297 else
@@ -2784,8 +2776,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); 2776 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)) 2777 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2786 { 2778 {
2787 CHECK_NUMBER (icon_x); 2779 CHECK_TYPE_RANGED_INTEGER (int, icon_x);
2788 CHECK_NUMBER (icon_y); 2780 CHECK_TYPE_RANGED_INTEGER (int, icon_y);
2789 } 2781 }
2790 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) 2782 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2791 error ("Both left and top icon corners of icon must be specified"); 2783 error ("Both left and top icon corners of icon must be specified");
@@ -3076,7 +3068,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3076 int minibuffer_only = 0; 3068 int minibuffer_only = 0;
3077 long window_prompting = 0; 3069 long window_prompting = 0;
3078 int width, height; 3070 int width, height;
3079 int count = SPECPDL_INDEX (); 3071 ptrdiff_t count = SPECPDL_INDEX ();
3080 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3072 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3081 Lisp_Object display; 3073 Lisp_Object display;
3082 struct x_display_info *dpyinfo = NULL; 3074 struct x_display_info *dpyinfo = NULL;
@@ -3333,7 +3325,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 3325 could get an infloop in next_frame since the frame is not yet in
3334 Vframe_list. */ 3326 Vframe_list. */
3335 { 3327 {
3336 int count2 = SPECPDL_INDEX (); 3328 ptrdiff_t count2 = SPECPDL_INDEX ();
3337 record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code); 3329 record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code);
3338 inhibit_lisp_code = Qt; 3330 inhibit_lisp_code = Qt;
3339 3331
@@ -4221,11 +4213,11 @@ FRAME. Default is to change on the edit X window. */)
4221 if (! NILP (format)) 4213 if (! NILP (format))
4222 { 4214 {
4223 CHECK_NUMBER (format); 4215 CHECK_NUMBER (format);
4224 element_format = XFASTINT (format);
4225 4216
4226 if (element_format != 8 && element_format != 16 4217 if (XINT (format) != 8 && XINT (format) != 16
4227 && element_format != 32) 4218 && XINT (format) != 32)
4228 error ("FORMAT must be one of 8, 16 or 32"); 4219 error ("FORMAT must be one of 8, 16 or 32");
4220 element_format = XINT (format);
4229 } 4221 }
4230 4222
4231 if (CONSP (value)) 4223 if (CONSP (value))
@@ -4583,7 +4575,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4583 Lisp_Object frame; 4575 Lisp_Object frame;
4584 Lisp_Object name; 4576 Lisp_Object name;
4585 int width, height; 4577 int width, height;
4586 int count = SPECPDL_INDEX (); 4578 ptrdiff_t count = SPECPDL_INDEX ();
4587 struct gcpro gcpro1, gcpro2, gcpro3; 4579 struct gcpro gcpro1, gcpro2, gcpro3;
4588 int face_change_count_before = face_change_count; 4580 int face_change_count_before = face_change_count;
4589 Lisp_Object buffer; 4581 Lisp_Object buffer;
@@ -4980,7 +4972,7 @@ Text larger than the specified size is clipped. */)
4980 int i, width, height, seen_reversed_p; 4972 int i, width, height, seen_reversed_p;
4981 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4973 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4982 int old_windows_or_buffers_changed = windows_or_buffers_changed; 4974 int old_windows_or_buffers_changed = windows_or_buffers_changed;
4983 int count = SPECPDL_INDEX (); 4975 ptrdiff_t count = SPECPDL_INDEX ();
4984 4976
4985 specbind (Qinhibit_redisplay, Qt); 4977 specbind (Qinhibit_redisplay, Qt);
4986 4978
@@ -5090,10 +5082,8 @@ Text larger than the specified size is clipped. */)
5090 w->left_col = w->top_line = make_number (0); 5082 w->left_col = w->top_line = make_number (0);
5091 5083
5092 if (CONSP (Vx_max_tooltip_size) 5084 if (CONSP (Vx_max_tooltip_size)
5093 && INTEGERP (XCAR (Vx_max_tooltip_size)) 5085 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
5094 && XINT (XCAR (Vx_max_tooltip_size)) > 0 5086 && 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 { 5087 {
5098 w->total_cols = XCAR (Vx_max_tooltip_size); 5088 w->total_cols = XCAR (Vx_max_tooltip_size);
5099 w->total_lines = XCDR (Vx_max_tooltip_size); 5089 w->total_lines = XCDR (Vx_max_tooltip_size);
@@ -5239,7 +5229,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
5239Value is t if tooltip was open, nil otherwise. */) 5229Value is t if tooltip was open, nil otherwise. */)
5240 (void) 5230 (void)
5241{ 5231{
5242 int count; 5232 ptrdiff_t count;
5243 Lisp_Object deleted, frame, timer; 5233 Lisp_Object deleted, frame, timer;
5244 struct gcpro gcpro1, gcpro2; 5234 struct gcpro gcpro1, gcpro2;
5245 5235
@@ -5381,7 +5371,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5381 Arg al[10]; 5371 Arg al[10];
5382 int ac = 0; 5372 int ac = 0;
5383 XmString dir_xmstring, pattern_xmstring; 5373 XmString dir_xmstring, pattern_xmstring;
5384 int count = SPECPDL_INDEX (); 5374 ptrdiff_t count = SPECPDL_INDEX ();
5385 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5375 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5386 5376
5387 check_x (); 5377 check_x ();
@@ -5550,7 +5540,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5550 char *fn; 5540 char *fn;
5551 Lisp_Object file = Qnil; 5541 Lisp_Object file = Qnil;
5552 Lisp_Object decoded_file; 5542 Lisp_Object decoded_file;
5553 int count = SPECPDL_INDEX (); 5543 ptrdiff_t count = SPECPDL_INDEX ();
5554 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5544 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5555 char *cdef_file; 5545 char *cdef_file;
5556 5546
@@ -5613,7 +5603,7 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
5613 Lisp_Object font_param; 5603 Lisp_Object font_param;
5614 char *default_name = NULL; 5604 char *default_name = NULL;
5615 struct gcpro gcpro1, gcpro2; 5605 struct gcpro gcpro1, gcpro2;
5616 int count = SPECPDL_INDEX (); 5606 ptrdiff_t count = SPECPDL_INDEX ();
5617 5607
5618 check_x (); 5608 check_x ();
5619 5609
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/xgselect.c b/src/xgselect.c
index 8b5ee68e55b..9d6a3ba774a 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -27,12 +27,13 @@ along with GNU Emacs. If not, see <http§://www.gnu.org/licenses/>. */
27#include <glib.h> 27#include <glib.h>
28#include <errno.h> 28#include <errno.h>
29#include <setjmp.h> 29#include <setjmp.h>
30#include "xterm.h"
30 31
31static GPollFD *gfds; 32static GPollFD *gfds;
32static ptrdiff_t gfds_size; 33static ptrdiff_t gfds_size;
33 34
34int 35int
35xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, 36xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
36 EMACS_TIME *timeout) 37 EMACS_TIME *timeout)
37{ 38{
38 SELECT_TYPE all_rfds, all_wfds; 39 SELECT_TYPE all_rfds, all_wfds;
@@ -40,11 +41,11 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
40 41
41 GMainContext *context; 42 GMainContext *context;
42 int have_wfds = wfds != NULL; 43 int have_wfds = wfds != NULL;
43 int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0; 44 int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
44 int i, nfds, fds_lim, tmo_in_millisec; 45 int i, nfds, tmo_in_millisec;
45 46
46 if (inhibit_window_system || !display_arg) 47 if (!x_in_use)
47 return select (max_fds, rfds, wfds, efds, timeout); 48 return select (fds_lim, rfds, wfds, efds, timeout);
48 49
49 if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds)); 50 if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
50 else FD_ZERO (&all_rfds); 51 else FD_ZERO (&all_rfds);
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 02fa137d6a7..3c7a7efdd71 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -139,6 +139,8 @@ extern void _XEditResCheckMessages (Widget, XtPointer, XEvent *, Boolean *);
139#endif 139#endif
140#endif 140#endif
141 141
142#include "bitmaps/gray.xbm"
143
142/* Default to using XIM if available. */ 144/* Default to using XIM if available. */
143#ifdef USE_XIM 145#ifdef USE_XIM
144int use_xim = 1; 146int use_xim = 1;
@@ -256,11 +258,7 @@ static Time last_user_time;
256/* Incremented by XTread_socket whenever it really tries to read 258/* Incremented by XTread_socket whenever it really tries to read
257 events. */ 259 events. */
258 260
259#ifdef __STDC__
260static int volatile input_signal_count; 261static int volatile input_signal_count;
261#else
262static int input_signal_count;
263#endif
264 262
265/* Used locally within XTread_socket. */ 263/* Used locally within XTread_socket. */
266 264
@@ -3700,24 +3698,23 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
3700/* Convert between the modifier bits X uses and the modifier bits 3698/* Convert between the modifier bits X uses and the modifier bits
3701 Emacs uses. */ 3699 Emacs uses. */
3702 3700
3703EMACS_INT 3701int
3704x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state) 3702x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state)
3705{ 3703{
3706 EMACS_INT mod_meta = meta_modifier; 3704 int mod_meta = meta_modifier;
3707 EMACS_INT mod_alt = alt_modifier; 3705 int mod_alt = alt_modifier;
3708 EMACS_INT mod_hyper = hyper_modifier; 3706 int mod_hyper = hyper_modifier;
3709 EMACS_INT mod_super = super_modifier; 3707 int mod_super = super_modifier;
3710 Lisp_Object tem; 3708 Lisp_Object tem;
3711 3709
3712 tem = Fget (Vx_alt_keysym, Qmodifier_value); 3710 tem = Fget (Vx_alt_keysym, Qmodifier_value);
3713 if (INTEGERP (tem)) mod_alt = XINT (tem); 3711 if (INTEGERP (tem)) mod_alt = XINT (tem) & INT_MAX;
3714 tem = Fget (Vx_meta_keysym, Qmodifier_value); 3712 tem = Fget (Vx_meta_keysym, Qmodifier_value);
3715 if (INTEGERP (tem)) mod_meta = XINT (tem); 3713 if (INTEGERP (tem)) mod_meta = XINT (tem) & INT_MAX;
3716 tem = Fget (Vx_hyper_keysym, Qmodifier_value); 3714 tem = Fget (Vx_hyper_keysym, Qmodifier_value);
3717 if (INTEGERP (tem)) mod_hyper = XINT (tem); 3715 if (INTEGERP (tem)) mod_hyper = XINT (tem) & INT_MAX;
3718 tem = Fget (Vx_super_keysym, Qmodifier_value); 3716 tem = Fget (Vx_super_keysym, Qmodifier_value);
3719 if (INTEGERP (tem)) mod_super = XINT (tem); 3717 if (INTEGERP (tem)) mod_super = XINT (tem) & INT_MAX;
3720
3721 3718
3722 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0) 3719 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0)
3723 | ((state & ControlMask) ? ctrl_modifier : 0) 3720 | ((state & ControlMask) ? ctrl_modifier : 0)
@@ -3730,10 +3727,10 @@ x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state)
3730static int 3727static int
3731x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, EMACS_INT state) 3728x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, EMACS_INT state)
3732{ 3729{
3733 int mod_meta = meta_modifier; 3730 EMACS_INT mod_meta = meta_modifier;
3734 int mod_alt = alt_modifier; 3731 EMACS_INT mod_alt = alt_modifier;
3735 int mod_hyper = hyper_modifier; 3732 EMACS_INT mod_hyper = hyper_modifier;
3736 int mod_super = super_modifier; 3733 EMACS_INT mod_super = super_modifier;
3737 3734
3738 Lisp_Object tem; 3735 Lisp_Object tem;
3739 3736
@@ -4532,7 +4529,7 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4532 whole = 10000000; 4529 whole = 10000000;
4533 portion = shown < 1 ? top * whole : 0; 4530 portion = shown < 1 ? top * whole : 0;
4534 4531
4535 if (shown < 1 && (eabs (top + shown - 1) < 1.0/height)) 4532 if (shown < 1 && (eabs (top + shown - 1) < 1.0f / height))
4536 /* Some derivatives of Xaw refuse to shrink the thumb when you reach 4533 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4537 the bottom, so we force the scrolling whenever we see that we're 4534 the bottom, so we force the scrolling whenever we see that we're
4538 too close to the bottom (in x_set_toolkit_scroll_bar_thumb 4535 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
@@ -4897,7 +4894,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4897 else 4894 else
4898 top = old_top; 4895 top = old_top;
4899 /* Keep two pixels available for moving the thumb down. */ 4896 /* Keep two pixels available for moving the thumb down. */
4900 shown = max (0, min (1 - top - (2.0 / height), shown)); 4897 shown = max (0, min (1 - top - (2.0f / height), shown));
4901 4898
4902 /* If the call to XawScrollbarSetThumb below doesn't seem to work, 4899 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4903 check that your system's configuration file contains a define 4900 check that your system's configuration file contains a define
@@ -6492,9 +6489,10 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6492 6489
6493 /* Now non-ASCII. */ 6490 /* Now non-ASCII. */
6494 if (HASH_TABLE_P (Vx_keysym_table) 6491 if (HASH_TABLE_P (Vx_keysym_table)
6495 && (NATNUMP (c = Fgethash (make_number (keysym), 6492 && (c = Fgethash (make_number (keysym),
6496 Vx_keysym_table, 6493 Vx_keysym_table,
6497 Qnil)))) 6494 Qnil),
6495 NATNUMP (c)))
6498 { 6496 {
6499 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) 6497 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c))
6500 ? ASCII_KEYSTROKE_EVENT 6498 ? ASCII_KEYSTROKE_EVENT
@@ -7772,7 +7770,7 @@ x_connection_closed (Display *dpy, const char *error_message)
7772{ 7770{
7773 struct x_display_info *dpyinfo = x_display_info_for_display (dpy); 7771 struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
7774 Lisp_Object frame, tail; 7772 Lisp_Object frame, tail;
7775 int idx = SPECPDL_INDEX (); 7773 ptrdiff_t idx = SPECPDL_INDEX ();
7776 7774
7777 error_msg = (char *) alloca (strlen (error_message) + 1); 7775 error_msg = (char *) alloca (strlen (error_message) + 1);
7778 strcpy (error_msg, error_message); 7776 strcpy (error_msg, error_message);
@@ -10387,8 +10385,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10387 { 10385 {
10388 dpyinfo->gray 10386 dpyinfo->gray
10389 = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, 10387 = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window,
10390 gray_bitmap_bits, 10388 gray_bits, gray_width, gray_height,
10391 gray_bitmap_width, gray_bitmap_height,
10392 1, 0, 1); 10389 1, 0, 1);
10393 } 10390 }
10394 10391
diff --git a/src/xterm.h b/src/xterm.h
index 86daa7bd27e..68e0372b05a 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
@@ -946,8 +939,6 @@ void x_handle_property_notify (XPropertyEvent *);
946struct frame *check_x_frame (Lisp_Object); 939struct frame *check_x_frame (Lisp_Object);
947EXFUN (Fx_display_grayscale_p, 1); 940EXFUN (Fx_display_grayscale_p, 1);
948extern void x_free_gcs (struct frame *); 941extern void x_free_gcs (struct frame *);
949extern int gray_bitmap_width, gray_bitmap_height;
950extern char *gray_bitmap_bits;
951 942
952/* From xrdb.c. */ 943/* From xrdb.c. */
953 944
@@ -996,7 +987,7 @@ extern void x_mouse_leave (struct x_display_info *);
996#ifdef USE_X_TOOLKIT 987#ifdef USE_X_TOOLKIT
997extern int x_dispatch_event (XEvent *, Display *); 988extern int x_dispatch_event (XEvent *, Display *);
998#endif 989#endif
999extern EMACS_INT x_x_to_emacs_modifiers (struct x_display_info *, int); 990extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1000extern int x_display_pixel_height (struct x_display_info *); 991extern int x_display_pixel_height (struct x_display_info *);
1001extern int x_display_pixel_width (struct x_display_info *); 992extern int x_display_pixel_width (struct x_display_info *);
1002 993
@@ -1038,6 +1029,7 @@ extern void x_clipboard_manager_save_all (void);
1038 1029
1039extern struct x_display_info * check_x_display_info (Lisp_Object); 1030extern struct x_display_info * check_x_display_info (Lisp_Object);
1040extern Lisp_Object x_get_focus_frame (struct frame *); 1031extern Lisp_Object x_get_focus_frame (struct frame *);
1032extern int x_in_use;
1041 1033
1042#ifdef USE_GTK 1034#ifdef USE_GTK
1043extern int xg_set_icon (struct frame *, Lisp_Object); 1035extern int xg_set_icon (struct frame *, Lisp_Object);