aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-15 12:57:25 -0700
committerPaul Eggert2011-06-15 12:57:25 -0700
commita7af7fdede602a111401c2352e81311a9dc38b99 (patch)
treedaebcb8a73345231337d0a461c01ae7804b2b646 /src
parent8c9b210626493dd93f236d7fb312c4f6dba62892 (diff)
parentb1c46f026de9d185ba86ffb1b23c50f2bd095ccf (diff)
downloademacs-a7af7fdede602a111401c2352e81311a9dc38b99.tar.gz
emacs-a7af7fdede602a111401c2352e81311a9dc38b99.zip
Integer overflow and signedness fixes (Bug#8873).
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog250
-rw-r--r--src/alloc.c181
-rw-r--r--src/buffer.c8
-rw-r--r--src/buffer.h4
-rw-r--r--src/bytecode.c16
-rw-r--r--src/callint.c16
-rw-r--r--src/callproc.c12
-rw-r--r--src/casefiddle.c2
-rw-r--r--src/ccl.c8
-rw-r--r--src/character.c14
-rw-r--r--src/character.h23
-rw-r--r--src/charset.c13
-rw-r--r--src/charset.h48
-rw-r--r--src/chartab.c6
-rw-r--r--src/coding.c10
-rw-r--r--src/composite.c5
-rw-r--r--src/composite.h2
-rw-r--r--src/data.c123
-rw-r--r--src/dbusbind.c50
-rw-r--r--src/dired.c13
-rw-r--r--src/dispextern.h4
-rw-r--r--src/doc.c7
-rw-r--r--src/doprnt.c8
-rw-r--r--src/editfns.c79
-rw-r--r--src/eval.c61
-rw-r--r--src/fileio.c33
-rw-r--r--src/floatfns.c2
-rw-r--r--src/fns.c158
-rw-r--r--src/font.c4
-rw-r--r--src/fontset.c2
-rw-r--r--src/frame.c2
-rw-r--r--src/keyboard.c24
-rw-r--r--src/lisp.h83
-rw-r--r--src/lread.c13
-rw-r--r--src/mem-limits.h2
-rw-r--r--src/print.c2
-rw-r--r--src/process.c12
-rw-r--r--src/puresize.h2
-rw-r--r--src/sound.c2
-rw-r--r--src/unexelf.c3
-rw-r--r--src/vm-limit.c5
-rw-r--r--src/widget.c12
-rw-r--r--src/xdisp.c14
-rw-r--r--src/xfaces.c3
-rw-r--r--src/xfns.c3
-rw-r--r--src/xterm.c23
46 files changed, 836 insertions, 531 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 821e4090cfd..59fb2d89b24 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,253 @@
12011-06-15 Paul Eggert <eggert@cs.ucla.edu>
2
3 Integer overflow and signedness fixes (Bug#8873).
4
5 * ccl.c (ASCENDING_ORDER): New macro, to work around GCC bug 43772.
6 (GET_CCL_RANGE, IN_INT_RANGE): Use it.
7
8 * fileio.c: Don't assume EMACS_INT fits in off_t.
9 (emacs_lseek): New static function.
10 (Finsert_file_contents, Fwrite_region): Use it.
11 Use SEEK_SET, SEEK_CUR, SEEK_END as appropriate.
12
13 * fns.c (Fload_average): Don't assume 100 * load average fits in int.
14
15 * fns.c: Don't overflow int when computing a list length.
16 * fns.c (QUIT_COUNT_HEURISTIC): New constant.
17 (Flength, Fsafe_length): Use EMACS_INT, not int, to avoid unwanted
18 truncation on 64-bit hosts. Check for QUIT every
19 QUIT_COUNT_HEURISTIC entries rather than every other entry; that's
20 faster and is responsive enough.
21 (Flength): Report an error instead of overflowing an integer.
22 (Fsafe_length): Return a float if the value is not representable
23 as a fixnum. This shouldn't happen except in contrived situations.
24 (Fnthcdr, Fsort): Don't assume list length fits in int.
25 (Fcopy_sequence): Don't assume vector length fits in int.
26
27 * alloc.c: Check that resized vectors' lengths fit in fixnums.
28 (header_size, word_size): New constants.
29 (allocate_vectorlike): Don't check size overflow here.
30 (allocate_vector): Check it here instead, since this is the only
31 caller of allocate_vectorlike that could cause overflow.
32 Check that the new vector's length is representable as a fixnum.
33
34 * fns.c (next_almost_prime): Don't return a multiple of 3 or 5.
35 The previous code was bogus. For example, next_almost_prime (32)
36 returned 39, which is undesirable as it is a multiple of 3; and
37 next_almost_prime (24) returned 25, which is a multiple of 5 so
38 why was the code bothering to check for multiples of 7?
39
40 * bytecode.c (exec_byte_code): Use ptrdiff_t, not int, for vector length.
41
42 * eval.c, doprnt.c (SIZE_MAX): Remove; inttypes.h defines this now.
43
44 Variadic C functions now count arguments with ptrdiff_t.
45 This partly undoes my 2011-03-30 change, which replaced int with size_t.
46 Back then I didn't know that the Emacs coding style prefers signed int.
47 Also, in the meantime I found a few more instances where arguments
48 were being counted with int, which may truncate counts on 64-bit
49 machines, or EMACS_INT, which may be unnecessarily wide.
50 * lisp.h (struct Lisp_Subr.function.aMANY)
51 (DEFUN_ARGS_MANY, internal_condition_case_n, safe_call):
52 Arg counts are now ptrdiff_t, not size_t.
53 All variadic functions and their callers changed accordingly.
54 (struct gcpro.nvars): Now size_t, not size_t. All uses changed.
55 * bytecode.c (exec_byte_code): Check maxdepth for overflow,
56 to avoid potential buffer overrun. Don't assume arg counts fit in 'int'.
57 * callint.c (Fcall_interactively): Check arg count for overflow,
58 to avoid potential buffer overrun. Use signed char, not 'int',
59 for 'varies' array, so that we needn't bother to check its size
60 calculation for overflow.
61 * editfns.c (Fformat): Use ptrdiff_t, not EMACS_INT, to count args.
62 * eval.c (apply_lambda):
63 * fns.c (Fmapconcat): Use XFASTINT, not XINT, to get args length.
64 (struct textprop_rec.argnum): Now ptrdiff_t, not int. All uses changed.
65 (mapconcat): Use ptrdiff_t, not int and EMACS_INT, to count args.
66
67 * callint.c (Fcall_interactively): Don't use index var as event count.
68
69 * vm-limit.c (check_memory_limits): Fix incorrect extern function decls.
70 * mem-limits.h (SIZE): Remove; no longer used.
71
72 * xterm.c (x_alloc_nearest_color_1): Prefer int to long when int works.
73
74 Remove unnecessary casts.
75 * xterm.c (x_term_init):
76 * xfns.c (x_set_border_pixel):
77 * widget.c (create_frame_gcs): Remove casts to unsigned long etc.
78 These aren't needed now that we assume ANSI C.
79
80 * sound.c (Fplay_sound_internal): Remove cast to unsigned long.
81 It's more likely to cause problems (due to unsigned overflow)
82 than to cure them.
83
84 * dired.c (Ffile_attributes): Don't use 32-bit hack on 64-bit hosts.
85
86 * unexelf.c (unexec): Don't assume BSS addr fits in unsigned.
87
88 * xterm.c (handle_one_xevent): Omit unnecessary casts to unsigned.
89
90 * keyboard.c (modify_event_symbol): Don't limit alist len to UINT_MAX.
91
92 * lisp.h (CHAR_TABLE_SET): Omit now-redundant test.
93
94 * lread.c (Fload): Don't compare a possibly-garbage time_t value.
95
96 GLYPH_CODE_FACE returns EMACS_INT, not int.
97 * dispextern.h (merge_faces):
98 * xfaces.c (merge_faces):
99 * xdisp.c (get_next_display_element, next_element_from_display_vector):
100 Don't assume EMACS_INT fits in int.
101
102 * character.h (CHAR_VALID_P): Remove unused parameter.
103 * fontset.c, lisp.h, xdisp.c: All uses changed.
104
105 * editfns.c (Ftranslate_region_internal): Omit redundant test.
106
107 * fns.c (concat): Minor tuning based on overflow analysis.
108 This doesn't fix any bugs. Use int to hold character, instead
109 of constantly refetching from Emacs object. Use XFASTINT, not
110 XINT, for value known to be a character. Don't bother comparing
111 a single byte to 0400, as it's always less.
112
113 * floatfns.c (Fexpt):
114 * fileio.c (make_temp_name): Omit unnecessary cast to unsigned.
115
116 * editfns.c (Ftranslate_region_internal): Use int, not EMACS_INT
117 for characters.
118
119 * doc.c (get_doc_string): Omit (unsigned)c that mishandled negatives.
120
121 * data.c (Faset): If ARRAY is a string, check that NEWELT is a char.
122 Without this fix, on a 64-bit host (aset S 0 4294967386) would
123 incorrectly succeed when S was a string, because 4294967386 was
124 truncated before it was used.
125
126 * chartab.c (Fchar_table_range): Use CHARACTERP to check range.
127 Otherwise, an out-of-range integer could cause undefined behavior
128 on a 64-bit host.
129
130 * composite.c: Use int, not EMACS_INT, for characters.
131 (fill_gstring_body, composition_compute_stop_pos): Use int, not
132 EMACS_INT, for values that are known to be in character range.
133 This doesn't fix any bugs but is the usual style inside Emacs and
134 may generate better code on 32-bit machines.
135
136 Make sure a 64-bit char is never passed to ENCODE_CHAR.
137 This is for reasons similar to the recent CHAR_STRING fix.
138 * charset.c (Fencode_char): Check that character arg is actually
139 a character. Pass an int to ENCODE_CHAR.
140 * charset.h (ENCODE_CHAR): Verify that the character argument is no
141 wider than 'int', as a compile-time check to prevent future regressions
142 in this area.
143
144 * character.c (char_string): Remove unnecessary casts.
145
146 Make sure a 64-bit char is never passed to CHAR_STRING.
147 Otherwise, CHAR_STRING would do the wrong thing on a 64-bit platform,
148 by silently ignoring the top 32 bits, allowing some values
149 that were far too large to be valid characters.
150 * character.h: Include <verify.h>.
151 (CHAR_STRING, CHAR_STRING_ADVANCE): Verify that the character
152 arguments are no wider than unsigned, as a compile-time check
153 to prevent future regressions in this area.
154 * data.c (Faset):
155 * editfns.c (Fchar_to_string, general_insert_function, Finsert_char)
156 (Fsubst_char_in_region):
157 * fns.c (concat):
158 * xdisp.c (decode_mode_spec_coding):
159 Adjust to CHAR_STRING's new requirement.
160 * editfns.c (Finsert_char, Fsubst_char_in_region):
161 * fns.c (concat): Check that character args are actually
162 characters. Without this test, these functions did the wrong
163 thing with wildly out-of-range values on 64-bit hosts.
164
165 Remove incorrect casts to 'unsigned' that lose info on 64-bit hosts.
166 These casts should not be needed on 32-bit hosts, either.
167 * keyboard.c (read_char):
168 * lread.c (Fload): Remove casts to unsigned.
169
170 * lisp.h (UNSIGNED_CMP): New macro.
171 This fixes comparison bugs on 64-bit hosts.
172 (ASCII_CHAR_P): Use it.
173 * casefiddle.c (casify_object):
174 * character.h (ASCII_BYTE_P, CHAR_VALID_P)
175 (SINGLE_BYTE_CHAR_P, CHAR_STRING):
176 * composite.h (COMPOSITION_ENCODE_RULE_VALID):
177 * dispextern.h (FACE_FROM_ID):
178 * keyboard.c (read_char): Use UNSIGNED_CMP.
179
180 * xmenu.c (dialog_selection_callback) [!USE_GTK]: Cast to intptr_t,
181 not to EMACS_INT, to avoid GCC warning.
182
183 * xfns.c (x_set_scroll_bar_default_width): Remove unused 'int' locals.
184
185 * buffer.h (PTR_BYTE_POS, BUF_PTR_BYTE_POS): Remove harmful cast.
186 The cast incorrectly truncated 64-bit byte offsets to 32 bits, and
187 isn't needed on 32-bit machines.
188
189 * buffer.c (Fgenerate_new_buffer_name):
190 Use EMACS_INT for count, not int.
191 (advance_to_char_boundary): Return EMACS_INT, not int.
192
193 * data.c (Qcompiled_function): Now static.
194
195 * window.c (window_body_lines): Now static.
196
197 * image.c (gif_load): Rename local to avoid shadowing.
198
199 * lisp.h (SAFE_ALLOCA_LISP): Check for integer overflow.
200 (struct Lisp_Save_Value): Use ptrdiff_t, not int, for 'integer' member.
201 * alloc.c (make_save_value): Integer argument is now of type
202 ptrdiff_t, not int.
203 (mark_object): Use ptrdiff_t, not int.
204 * lisp.h (pD): New macro.
205 * print.c (print_object): Use it.
206
207 * alloc.c: Use EMACS_INT, not int, to count objects.
208 (total_conses, total_markers, total_symbols, total_vector_size)
209 (total_free_conses, total_free_markers, total_free_symbols)
210 (total_free_floats, total_floats, total_free_intervals)
211 (total_intervals, total_strings, total_free_strings):
212 Now EMACS_INT, not int. All uses changed.
213 (Fgarbage_collect): Compute overall total using a double, so that
214 integer overflow is less likely to be a problem. Check for overflow
215 when converting back to an integer.
216 (n_interval_blocks, n_string_blocks, n_float_blocks, n_cons_blocks)
217 (n_vectors, n_symbol_blocks, n_marker_blocks): Remove.
218 These were 'int' variables that could overflow on 64-bit hosts;
219 they were never used, so remove them instead of repairing them.
220 (nzombies, ngcs, max_live, max_zombies): Now EMACS_INT, not 'int'.
221 (inhibit_garbage_collection): Set gc_cons_threshold to max value.
222 Previously, this ceilinged at INT_MAX, but that doesn't work on
223 64-bit machines.
224 (allocate_pseudovector): Don't use EMACS_INT when int would do.
225
226 * alloc.c (Fmake_bool_vector): Don't assume vector size fits in int.
227 (allocate_vectorlike): Check for ptrdiff_t overflow.
228 (mark_vectorlike, mark_char_table, mark_object): Avoid EMACS_UINT
229 when a (possibly-narrower) signed value would do just as well.
230 We prefer using signed arithmetic, to avoid comparison confusion.
231
232 * alloc.c: Catch some string size overflows that we were missing.
233 (XMALLOC_OVERRUN_CHECK_SIZE) [!XMALLOC_OVERRUN_CHECK]: Define to 0,
234 for convenience in STRING_BYTES_MAX.
235 (STRING_BYTES_MAX): New macro, superseding the old one in lisp.h.
236 The definition here is exact; the one in lisp.h was approximate.
237 (allocate_string_data): Check for string overflow. This catches
238 some instances we weren't catching before. Also, it catches
239 size_t overflow on (unusual) hosts where SIZE_MAX <= min
240 (PTRDIFF_MAX, MOST_POSITIVE_FIXNUM), e.g., when size_t is 32 bits
241 and ptrdiff_t and EMACS_INT are both 64 bits.
242
243 * character.c, coding.c, doprnt.c, editfns.c, eval.c:
244 All uses of STRING_BYTES_MAX replaced by STRING_BYTES_BOUND.
245 * lisp.h (STRING_BYTES_BOUND): Renamed from STRING_BYTES_MAX.
246
247 * character.c (string_escape_byte8): Fix nbytes/nchars typo.
248
249 * alloc.c (Fmake_string): Check for out-of-range init.
250
12011-06-15 Stefan Monnier <monnier@iro.umontreal.ca> 2512011-06-15 Stefan Monnier <monnier@iro.umontreal.ca>
2 252
3 * eval.c (Fdefvaralias): Also mark the target as variable-special-p. 253 * eval.c (Fdefvaralias): Also mark the target as variable-special-p.
diff --git a/src/alloc.c b/src/alloc.c
index cfbb79b2e61..00d330c1b6a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -180,9 +180,9 @@ int abort_on_gc;
180 180
181/* Number of live and free conses etc. */ 181/* Number of live and free conses etc. */
182 182
183static int total_conses, total_markers, total_symbols, total_vector_size; 183static EMACS_INT total_conses, total_markers, total_symbols, total_vector_size;
184static int total_free_conses, total_free_markers, total_free_symbols; 184static EMACS_INT total_free_conses, total_free_markers, total_free_symbols;
185static int total_free_floats, total_floats; 185static EMACS_INT total_free_floats, total_floats;
186 186
187/* Points to memory space allocated as "spare", to be freed if we run 187/* Points to memory space allocated as "spare", to be freed if we run
188 out of memory. We keep one large block, four cons-blocks, and 188 out of memory. We keep one large block, four cons-blocks, and
@@ -485,7 +485,9 @@ buffer_memory_full (EMACS_INT nbytes)
485} 485}
486 486
487 487
488#ifdef XMALLOC_OVERRUN_CHECK 488#ifndef XMALLOC_OVERRUN_CHECK
489#define XMALLOC_OVERRUN_CHECK_SIZE 0
490#else
489 491
490/* Check for overrun in malloc'ed buffers by wrapping a 16 byte header 492/* Check for overrun in malloc'ed buffers by wrapping a 16 byte header
491 and a 16 byte trailer around each block. 493 and a 16 byte trailer around each block.
@@ -1336,16 +1338,12 @@ static int interval_block_index;
1336 1338
1337/* Number of free and live intervals. */ 1339/* Number of free and live intervals. */
1338 1340
1339static int total_free_intervals, total_intervals; 1341static EMACS_INT total_free_intervals, total_intervals;
1340 1342
1341/* List of free intervals. */ 1343/* List of free intervals. */
1342 1344
1343static INTERVAL interval_free_list; 1345static INTERVAL interval_free_list;
1344 1346
1345/* Total number of interval blocks now in use. */
1346
1347static int n_interval_blocks;
1348
1349 1347
1350/* Initialize interval allocation. */ 1348/* Initialize interval allocation. */
1351 1349
@@ -1355,7 +1353,6 @@ init_intervals (void)
1355 interval_block = NULL; 1353 interval_block = NULL;
1356 interval_block_index = INTERVAL_BLOCK_SIZE; 1354 interval_block_index = INTERVAL_BLOCK_SIZE;
1357 interval_free_list = 0; 1355 interval_free_list = 0;
1358 n_interval_blocks = 0;
1359} 1356}
1360 1357
1361 1358
@@ -1387,7 +1384,6 @@ make_interval (void)
1387 newi->next = interval_block; 1384 newi->next = interval_block;
1388 interval_block = newi; 1385 interval_block = newi;
1389 interval_block_index = 0; 1386 interval_block_index = 0;
1390 n_interval_blocks++;
1391 } 1387 }
1392 val = &interval_block->intervals[interval_block_index++]; 1388 val = &interval_block->intervals[interval_block_index++];
1393 } 1389 }
@@ -1580,10 +1576,9 @@ static struct sblock *oldest_sblock, *current_sblock;
1580 1576
1581static struct sblock *large_sblocks; 1577static struct sblock *large_sblocks;
1582 1578
1583/* List of string_block structures, and how many there are. */ 1579/* List of string_block structures. */
1584 1580
1585static struct string_block *string_blocks; 1581static struct string_block *string_blocks;
1586static int n_string_blocks;
1587 1582
1588/* Free-list of Lisp_Strings. */ 1583/* Free-list of Lisp_Strings. */
1589 1584
@@ -1591,7 +1586,7 @@ static struct Lisp_String *string_free_list;
1591 1586
1592/* Number of live and free Lisp_Strings. */ 1587/* Number of live and free Lisp_Strings. */
1593 1588
1594static int total_strings, total_free_strings; 1589static EMACS_INT total_strings, total_free_strings;
1595 1590
1596/* Number of bytes used by live strings. */ 1591/* Number of bytes used by live strings. */
1597 1592
@@ -1659,6 +1654,18 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
1659 1654
1660#define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE) 1655#define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE)
1661 1656
1657/* Exact bound on the number of bytes in a string, not counting the
1658 terminating null. A string cannot contain more bytes than
1659 STRING_BYTES_BOUND, nor can it be so long that the size_t
1660 arithmetic in allocate_string_data would overflow while it is
1661 calculating a value to be passed to malloc. */
1662#define STRING_BYTES_MAX \
1663 min (STRING_BYTES_BOUND, \
1664 ((SIZE_MAX - XMALLOC_OVERRUN_CHECK_SIZE - GC_STRING_EXTRA \
1665 - offsetof (struct sblock, first_data) \
1666 - SDATA_DATA_OFFSET) \
1667 & ~(sizeof (EMACS_INT) - 1)))
1668
1662/* Initialize string allocation. Called from init_alloc_once. */ 1669/* Initialize string allocation. Called from init_alloc_once. */
1663 1670
1664static void 1671static void
@@ -1667,7 +1674,6 @@ init_strings (void)
1667 total_strings = total_free_strings = total_string_size = 0; 1674 total_strings = total_free_strings = total_string_size = 0;
1668 oldest_sblock = current_sblock = large_sblocks = NULL; 1675 oldest_sblock = current_sblock = large_sblocks = NULL;
1669 string_blocks = NULL; 1676 string_blocks = NULL;
1670 n_string_blocks = 0;
1671 string_free_list = NULL; 1677 string_free_list = NULL;
1672 empty_unibyte_string = make_pure_string ("", 0, 0, 0); 1678 empty_unibyte_string = make_pure_string ("", 0, 0, 0);
1673 empty_multibyte_string = make_pure_string ("", 0, 0, 1); 1679 empty_multibyte_string = make_pure_string ("", 0, 0, 1);
@@ -1799,7 +1805,6 @@ allocate_string (void)
1799 memset (b, 0, sizeof *b); 1805 memset (b, 0, sizeof *b);
1800 b->next = string_blocks; 1806 b->next = string_blocks;
1801 string_blocks = b; 1807 string_blocks = b;
1802 ++n_string_blocks;
1803 1808
1804 for (i = STRING_BLOCK_SIZE - 1; i >= 0; --i) 1809 for (i = STRING_BLOCK_SIZE - 1; i >= 0; --i)
1805 { 1810 {
@@ -1858,6 +1863,9 @@ allocate_string_data (struct Lisp_String *s,
1858 struct sblock *b; 1863 struct sblock *b;
1859 EMACS_INT needed, old_nbytes; 1864 EMACS_INT needed, old_nbytes;
1860 1865
1866 if (STRING_BYTES_MAX < nbytes)
1867 string_overflow ();
1868
1861 /* Determine the number of bytes needed to store NBYTES bytes 1869 /* Determine the number of bytes needed to store NBYTES bytes
1862 of string data. */ 1870 of string data. */
1863 needed = SDATA_SIZE (nbytes); 1871 needed = SDATA_SIZE (nbytes);
@@ -2025,7 +2033,6 @@ sweep_strings (void)
2025 && total_free_strings > STRING_BLOCK_SIZE) 2033 && total_free_strings > STRING_BLOCK_SIZE)
2026 { 2034 {
2027 lisp_free (b); 2035 lisp_free (b);
2028 --n_string_blocks;
2029 string_free_list = free_list_before; 2036 string_free_list = free_list_before;
2030 } 2037 }
2031 else 2038 else
@@ -2186,9 +2193,9 @@ INIT must be an integer that represents a character. */)
2186 EMACS_INT nbytes; 2193 EMACS_INT nbytes;
2187 2194
2188 CHECK_NATNUM (length); 2195 CHECK_NATNUM (length);
2189 CHECK_NUMBER (init); 2196 CHECK_CHARACTER (init);
2190 2197
2191 c = XINT (init); 2198 c = XFASTINT (init);
2192 if (ASCII_CHAR_P (c)) 2199 if (ASCII_CHAR_P (c))
2193 { 2200 {
2194 nbytes = XINT (length); 2201 nbytes = XINT (length);
@@ -2229,7 +2236,6 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2229{ 2236{
2230 register Lisp_Object val; 2237 register Lisp_Object val;
2231 struct Lisp_Bool_Vector *p; 2238 struct Lisp_Bool_Vector *p;
2232 int real_init, i;
2233 EMACS_INT length_in_chars, length_in_elts; 2239 EMACS_INT length_in_chars, length_in_elts;
2234 int bits_per_value; 2240 int bits_per_value;
2235 2241
@@ -2251,9 +2257,7 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2251 p = XBOOL_VECTOR (val); 2257 p = XBOOL_VECTOR (val);
2252 p->size = XFASTINT (length); 2258 p->size = XFASTINT (length);
2253 2259
2254 real_init = (NILP (init) ? 0 : -1); 2260 memset (p->data, NILP (init) ? 0 : -1, length_in_chars);
2255 for (i = 0; i < length_in_chars ; i++)
2256 p->data[i] = real_init;
2257 2261
2258 /* Clear the extraneous bits in the last byte. */ 2262 /* Clear the extraneous bits in the last byte. */
2259 if (XINT (length) != length_in_chars * BOOL_VECTOR_BITS_PER_CHAR) 2263 if (XINT (length) != length_in_chars * BOOL_VECTOR_BITS_PER_CHAR)
@@ -2463,10 +2467,6 @@ static struct float_block *float_block;
2463 2467
2464static int float_block_index; 2468static int float_block_index;
2465 2469
2466/* Total number of float blocks now in use. */
2467
2468static int n_float_blocks;
2469
2470/* Free-list of Lisp_Floats. */ 2470/* Free-list of Lisp_Floats. */
2471 2471
2472static struct Lisp_Float *float_free_list; 2472static struct Lisp_Float *float_free_list;
@@ -2480,7 +2480,6 @@ init_float (void)
2480 float_block = NULL; 2480 float_block = NULL;
2481 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */ 2481 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */
2482 float_free_list = 0; 2482 float_free_list = 0;
2483 n_float_blocks = 0;
2484} 2483}
2485 2484
2486 2485
@@ -2514,7 +2513,6 @@ make_float (double float_value)
2514 memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); 2513 memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
2515 float_block = new; 2514 float_block = new;
2516 float_block_index = 0; 2515 float_block_index = 0;
2517 n_float_blocks++;
2518 } 2516 }
2519 XSETFLOAT (val, &float_block->floats[float_block_index]); 2517 XSETFLOAT (val, &float_block->floats[float_block_index]);
2520 float_block_index++; 2518 float_block_index++;
@@ -2579,10 +2577,6 @@ static int cons_block_index;
2579 2577
2580static struct Lisp_Cons *cons_free_list; 2578static struct Lisp_Cons *cons_free_list;
2581 2579
2582/* Total number of cons blocks now in use. */
2583
2584static int n_cons_blocks;
2585
2586 2580
2587/* Initialize cons allocation. */ 2581/* Initialize cons allocation. */
2588 2582
@@ -2592,7 +2586,6 @@ init_cons (void)
2592 cons_block = NULL; 2586 cons_block = NULL;
2593 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */ 2587 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */
2594 cons_free_list = 0; 2588 cons_free_list = 0;
2595 n_cons_blocks = 0;
2596} 2589}
2597 2590
2598 2591
@@ -2636,7 +2629,6 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2636 new->next = cons_block; 2629 new->next = cons_block;
2637 cons_block = new; 2630 cons_block = new;
2638 cons_block_index = 0; 2631 cons_block_index = 0;
2639 n_cons_blocks++;
2640 } 2632 }
2641 XSETCONS (val, &cons_block->conses[cons_block_index]); 2633 XSETCONS (val, &cons_block->conses[cons_block_index]);
2642 cons_block_index++; 2634 cons_block_index++;
@@ -2705,7 +2697,7 @@ DEFUN ("list", Flist, Slist, 0, MANY, 0,
2705 doc: /* Return a newly created list with specified arguments as elements. 2697 doc: /* Return a newly created list with specified arguments as elements.
2706Any number of arguments, even zero arguments, are allowed. 2698Any number of arguments, even zero arguments, are allowed.
2707usage: (list &rest OBJECTS) */) 2699usage: (list &rest OBJECTS) */)
2708 (size_t nargs, register Lisp_Object *args) 2700 (ptrdiff_t nargs, Lisp_Object *args)
2709{ 2701{
2710 register Lisp_Object val; 2702 register Lisp_Object val;
2711 val = Qnil; 2703 val = Qnil;
@@ -2775,10 +2767,12 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
2775 2767
2776static struct Lisp_Vector *all_vectors; 2768static struct Lisp_Vector *all_vectors;
2777 2769
2778/* Total number of vector-like objects now in use. */ 2770/* Handy constants for vectorlike objects. */
2779 2771enum
2780static int n_vectors; 2772 {
2781 2773 header_size = offsetof (struct Lisp_Vector, contents),
2774 word_size = sizeof (Lisp_Object)
2775 };
2782 2776
2783/* Value is a pointer to a newly allocated Lisp_Vector structure 2777/* Value is a pointer to a newly allocated Lisp_Vector structure
2784 with room for LEN Lisp_Objects. */ 2778 with room for LEN Lisp_Objects. */
@@ -2788,11 +2782,6 @@ allocate_vectorlike (EMACS_INT len)
2788{ 2782{
2789 struct Lisp_Vector *p; 2783 struct Lisp_Vector *p;
2790 size_t nbytes; 2784 size_t nbytes;
2791 int header_size = offsetof (struct Lisp_Vector, contents);
2792 int word_size = sizeof p->contents[0];
2793
2794 if ((SIZE_MAX - header_size) / word_size < len)
2795 memory_full (SIZE_MAX);
2796 2785
2797 MALLOC_BLOCK_INPUT; 2786 MALLOC_BLOCK_INPUT;
2798 2787
@@ -2822,18 +2811,22 @@ allocate_vectorlike (EMACS_INT len)
2822 2811
2823 MALLOC_UNBLOCK_INPUT; 2812 MALLOC_UNBLOCK_INPUT;
2824 2813
2825 ++n_vectors;
2826 return p; 2814 return p;
2827} 2815}
2828 2816
2829 2817
2830/* Allocate a vector with NSLOTS slots. */ 2818/* Allocate a vector with LEN slots. */
2831 2819
2832struct Lisp_Vector * 2820struct Lisp_Vector *
2833allocate_vector (EMACS_INT nslots) 2821allocate_vector (EMACS_INT len)
2834{ 2822{
2835 struct Lisp_Vector *v = allocate_vectorlike (nslots); 2823 struct Lisp_Vector *v;
2836 v->header.size = nslots; 2824 ptrdiff_t nbytes_max = min (PTRDIFF_MAX, SIZE_MAX);
2825
2826 if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len)
2827 memory_full (SIZE_MAX);
2828 v = allocate_vectorlike (len);
2829 v->header.size = len;
2837 return v; 2830 return v;
2838} 2831}
2839 2832
@@ -2844,7 +2837,7 @@ struct Lisp_Vector *
2844allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag) 2837allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag)
2845{ 2838{
2846 struct Lisp_Vector *v = allocate_vectorlike (memlen); 2839 struct Lisp_Vector *v = allocate_vectorlike (memlen);
2847 EMACS_INT i; 2840 int i;
2848 2841
2849 /* Only the first lisplen slots will be traced normally by the GC. */ 2842 /* Only the first lisplen slots will be traced normally by the GC. */
2850 for (i = 0; i < lisplen; ++i) 2843 for (i = 0; i < lisplen; ++i)
@@ -2925,10 +2918,10 @@ DEFUN ("vector", Fvector, Svector, 0, MANY, 0,
2925 doc: /* Return a newly created vector with specified arguments as elements. 2918 doc: /* Return a newly created vector with specified arguments as elements.
2926Any number of arguments, even zero arguments, are allowed. 2919Any number of arguments, even zero arguments, are allowed.
2927usage: (vector &rest OBJECTS) */) 2920usage: (vector &rest OBJECTS) */)
2928 (register size_t nargs, Lisp_Object *args) 2921 (ptrdiff_t nargs, Lisp_Object *args)
2929{ 2922{
2930 register Lisp_Object len, val; 2923 register Lisp_Object len, val;
2931 register size_t i; 2924 ptrdiff_t i;
2932 register struct Lisp_Vector *p; 2925 register struct Lisp_Vector *p;
2933 2926
2934 XSETFASTINT (len, nargs); 2927 XSETFASTINT (len, nargs);
@@ -2956,15 +2949,15 @@ argument to catch the left-over arguments. If such an integer is used, the
2956arguments will not be dynamically bound but will be instead pushed on the 2949arguments will not be dynamically bound but will be instead pushed on the
2957stack before executing the byte-code. 2950stack before executing the byte-code.
2958usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) 2951usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */)
2959 (register size_t nargs, Lisp_Object *args) 2952 (ptrdiff_t nargs, Lisp_Object *args)
2960{ 2953{
2961 register Lisp_Object len, val; 2954 register Lisp_Object len, val;
2962 register size_t i; 2955 ptrdiff_t i;
2963 register struct Lisp_Vector *p; 2956 register struct Lisp_Vector *p;
2964 2957
2965 XSETFASTINT (len, nargs); 2958 XSETFASTINT (len, nargs);
2966 if (!NILP (Vpurify_flag)) 2959 if (!NILP (Vpurify_flag))
2967 val = make_pure_vector ((EMACS_INT) nargs); 2960 val = make_pure_vector (nargs);
2968 else 2961 else
2969 val = Fmake_vector (len, Qnil); 2962 val = Fmake_vector (len, Qnil);
2970 2963
@@ -3018,10 +3011,6 @@ static int symbol_block_index;
3018 3011
3019static struct Lisp_Symbol *symbol_free_list; 3012static struct Lisp_Symbol *symbol_free_list;
3020 3013
3021/* Total number of symbol blocks now in use. */
3022
3023static int n_symbol_blocks;
3024
3025 3014
3026/* Initialize symbol allocation. */ 3015/* Initialize symbol allocation. */
3027 3016
@@ -3031,7 +3020,6 @@ init_symbol (void)
3031 symbol_block = NULL; 3020 symbol_block = NULL;
3032 symbol_block_index = SYMBOL_BLOCK_SIZE; 3021 symbol_block_index = SYMBOL_BLOCK_SIZE;
3033 symbol_free_list = 0; 3022 symbol_free_list = 0;
3034 n_symbol_blocks = 0;
3035} 3023}
3036 3024
3037 3025
@@ -3064,7 +3052,6 @@ Its value and function definition are void, and its property list is nil. */)
3064 new->next = symbol_block; 3052 new->next = symbol_block;
3065 symbol_block = new; 3053 symbol_block = new;
3066 symbol_block_index = 0; 3054 symbol_block_index = 0;
3067 n_symbol_blocks++;
3068 } 3055 }
3069 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index]); 3056 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index]);
3070 symbol_block_index++; 3057 symbol_block_index++;
@@ -3112,17 +3099,12 @@ static int marker_block_index;
3112 3099
3113static union Lisp_Misc *marker_free_list; 3100static union Lisp_Misc *marker_free_list;
3114 3101
3115/* Total number of marker blocks now in use. */
3116
3117static int n_marker_blocks;
3118
3119static void 3102static void
3120init_marker (void) 3103init_marker (void)
3121{ 3104{
3122 marker_block = NULL; 3105 marker_block = NULL;
3123 marker_block_index = MARKER_BLOCK_SIZE; 3106 marker_block_index = MARKER_BLOCK_SIZE;
3124 marker_free_list = 0; 3107 marker_free_list = 0;
3125 n_marker_blocks = 0;
3126} 3108}
3127 3109
3128/* Return a newly allocated Lisp_Misc object, with no substructure. */ 3110/* Return a newly allocated Lisp_Misc object, with no substructure. */
@@ -3151,7 +3133,6 @@ allocate_misc (void)
3151 new->next = marker_block; 3133 new->next = marker_block;
3152 marker_block = new; 3134 marker_block = new;
3153 marker_block_index = 0; 3135 marker_block_index = 0;
3154 n_marker_blocks++;
3155 total_free_markers += MARKER_BLOCK_SIZE; 3136 total_free_markers += MARKER_BLOCK_SIZE;
3156 } 3137 }
3157 XSETMISC (val, &marker_block->markers[marker_block_index]); 3138 XSETMISC (val, &marker_block->markers[marker_block_index]);
@@ -3184,7 +3165,7 @@ free_misc (Lisp_Object misc)
3184 The unwind function can get the C values back using XSAVE_VALUE. */ 3165 The unwind function can get the C values back using XSAVE_VALUE. */
3185 3166
3186Lisp_Object 3167Lisp_Object
3187make_save_value (void *pointer, int integer) 3168make_save_value (void *pointer, ptrdiff_t integer)
3188{ 3169{
3189 register Lisp_Object val; 3170 register Lisp_Object val;
3190 register struct Lisp_Save_Value *p; 3171 register struct Lisp_Save_Value *p;
@@ -3929,11 +3910,11 @@ static Lisp_Object zombies[MAX_ZOMBIES];
3929 3910
3930/* Number of zombie objects. */ 3911/* Number of zombie objects. */
3931 3912
3932static int nzombies; 3913static EMACS_INT nzombies;
3933 3914
3934/* Number of garbage collections. */ 3915/* Number of garbage collections. */
3935 3916
3936static int ngcs; 3917static EMACS_INT ngcs;
3937 3918
3938/* Average percentage of zombies per collection. */ 3919/* Average percentage of zombies per collection. */
3939 3920
@@ -3941,7 +3922,7 @@ static double avg_zombies;
3941 3922
3942/* Max. number of live and zombie objects. */ 3923/* Max. number of live and zombie objects. */
3943 3924
3944static int max_live, max_zombies; 3925static EMACS_INT max_live, max_zombies;
3945 3926
3946/* Average number of live objects per GC. */ 3927/* Average number of live objects per GC. */
3947 3928
@@ -3952,7 +3933,7 @@ DEFUN ("gc-status", Fgc_status, Sgc_status, 0, 0, "",
3952 (void) 3933 (void)
3953{ 3934{
3954 Lisp_Object args[8], zombie_list = Qnil; 3935 Lisp_Object args[8], zombie_list = Qnil;
3955 int i; 3936 EMACS_INT i;
3956 for (i = 0; i < nzombies; i++) 3937 for (i = 0; i < nzombies; i++)
3957 zombie_list = Fcons (zombies[i], zombie_list); 3938 zombie_list = Fcons (zombies[i], zombie_list);
3958 args[0] = build_string ("%d GCs, avg live/zombies = %.2f/%.2f (%f%%), max %d/%d\nzombies: %S"); 3939 args[0] = build_string ("%d GCs, avg live/zombies = %.2f/%.2f (%f%%), max %d/%d\nzombies: %S");
@@ -4262,7 +4243,7 @@ static void
4262check_gcpros (void) 4243check_gcpros (void)
4263{ 4244{
4264 struct gcpro *p; 4245 struct gcpro *p;
4265 size_t i; 4246 ptrdiff_t i;
4266 4247
4267 for (p = gcprolist; p; p = p->next) 4248 for (p = gcprolist; p; p = p->next)
4268 for (i = 0; i < p->nvars; ++i) 4249 for (i = 0; i < p->nvars; ++i)
@@ -4279,7 +4260,7 @@ dump_zombies (void)
4279{ 4260{
4280 int i; 4261 int i;
4281 4262
4282 fprintf (stderr, "\nZombies kept alive = %d:\n", nzombies); 4263 fprintf (stderr, "\nZombies kept alive = %"pI":\n", nzombies);
4283 for (i = 0; i < min (MAX_ZOMBIES, nzombies); ++i) 4264 for (i = 0; i < min (MAX_ZOMBIES, nzombies); ++i)
4284 { 4265 {
4285 fprintf (stderr, " %d = ", i); 4266 fprintf (stderr, " %d = ", i);
@@ -4851,9 +4832,8 @@ int
4851inhibit_garbage_collection (void) 4832inhibit_garbage_collection (void)
4852{ 4833{
4853 int count = SPECPDL_INDEX (); 4834 int count = SPECPDL_INDEX ();
4854 int nbits = min (VALBITS, BITS_PER_INT);
4855 4835
4856 specbind (Qgc_cons_threshold, make_number (((EMACS_INT) 1 << (nbits - 1)) - 1)); 4836 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM));
4857 return count; 4837 return count;
4858} 4838}
4859 4839
@@ -4873,7 +4853,7 @@ returns nil, because real GC can't be done. */)
4873{ 4853{
4874 register struct specbinding *bind; 4854 register struct specbinding *bind;
4875 char stack_top_variable; 4855 char stack_top_variable;
4876 register size_t i; 4856 ptrdiff_t i;
4877 int message_p; 4857 int message_p;
4878 Lisp_Object total[8]; 4858 Lisp_Object total[8];
4879 int count = SPECPDL_INDEX (); 4859 int count = SPECPDL_INDEX ();
@@ -5103,9 +5083,10 @@ returns nil, because real GC can't be done. */)
5103 if (gc_cons_threshold < 10000) 5083 if (gc_cons_threshold < 10000)
5104 gc_cons_threshold = 10000; 5084 gc_cons_threshold = 10000;
5105 5085
5086 gc_relative_threshold = 0;
5106 if (FLOATP (Vgc_cons_percentage)) 5087 if (FLOATP (Vgc_cons_percentage))
5107 { /* Set gc_cons_combined_threshold. */ 5088 { /* Set gc_cons_combined_threshold. */
5108 EMACS_INT tot = 0; 5089 double tot = 0;
5109 5090
5110 tot += total_conses * sizeof (struct Lisp_Cons); 5091 tot += total_conses * sizeof (struct Lisp_Cons);
5111 tot += total_symbols * sizeof (struct Lisp_Symbol); 5092 tot += total_symbols * sizeof (struct Lisp_Symbol);
@@ -5116,10 +5097,15 @@ returns nil, because real GC can't be done. */)
5116 tot += total_intervals * sizeof (struct interval); 5097 tot += total_intervals * sizeof (struct interval);
5117 tot += total_strings * sizeof (struct Lisp_String); 5098 tot += total_strings * sizeof (struct Lisp_String);
5118 5099
5119 gc_relative_threshold = tot * XFLOAT_DATA (Vgc_cons_percentage); 5100 tot *= XFLOAT_DATA (Vgc_cons_percentage);
5101 if (0 < tot)
5102 {
5103 if (tot < TYPE_MAXIMUM (EMACS_INT))
5104 gc_relative_threshold = tot;
5105 else
5106 gc_relative_threshold = TYPE_MAXIMUM (EMACS_INT);
5107 }
5120 } 5108 }
5121 else
5122 gc_relative_threshold = 0;
5123 5109
5124 if (garbage_collection_messages) 5110 if (garbage_collection_messages)
5125 { 5111 {
@@ -5250,8 +5236,8 @@ static size_t mark_object_loop_halt;
5250static void 5236static void
5251mark_vectorlike (struct Lisp_Vector *ptr) 5237mark_vectorlike (struct Lisp_Vector *ptr)
5252{ 5238{
5253 register EMACS_UINT size = ptr->header.size; 5239 EMACS_INT size = ptr->header.size;
5254 register EMACS_UINT i; 5240 EMACS_INT i;
5255 5241
5256 eassert (!VECTOR_MARKED_P (ptr)); 5242 eassert (!VECTOR_MARKED_P (ptr));
5257 VECTOR_MARK (ptr); /* Else mark it */ 5243 VECTOR_MARK (ptr); /* Else mark it */
@@ -5273,8 +5259,8 @@ mark_vectorlike (struct Lisp_Vector *ptr)
5273static void 5259static void
5274mark_char_table (struct Lisp_Vector *ptr) 5260mark_char_table (struct Lisp_Vector *ptr)
5275{ 5261{
5276 register EMACS_UINT size = ptr->header.size & PSEUDOVECTOR_SIZE_MASK; 5262 int size = ptr->header.size & PSEUDOVECTOR_SIZE_MASK;
5277 register EMACS_UINT i; 5263 int i;
5278 5264
5279 eassert (!VECTOR_MARKED_P (ptr)); 5265 eassert (!VECTOR_MARKED_P (ptr));
5280 VECTOR_MARK (ptr); 5266 VECTOR_MARK (ptr);
@@ -5402,12 +5388,11 @@ mark_object (Lisp_Object arg)
5402 recursion there. */ 5388 recursion there. */
5403 { 5389 {
5404 register struct Lisp_Vector *ptr = XVECTOR (obj); 5390 register struct Lisp_Vector *ptr = XVECTOR (obj);
5405 register EMACS_UINT size = ptr->header.size; 5391 int size = ptr->header.size & PSEUDOVECTOR_SIZE_MASK;
5406 register EMACS_UINT i; 5392 int i;
5407 5393
5408 CHECK_LIVE (live_vector_p); 5394 CHECK_LIVE (live_vector_p);
5409 VECTOR_MARK (ptr); /* Else mark it */ 5395 VECTOR_MARK (ptr); /* Else mark it */
5410 size &= PSEUDOVECTOR_SIZE_MASK;
5411 for (i = 0; i < size; i++) /* and then mark its elements */ 5396 for (i = 0; i < size; i++) /* and then mark its elements */
5412 { 5397 {
5413 if (i != COMPILED_CONSTANTS) 5398 if (i != COMPILED_CONSTANTS)
@@ -5534,7 +5519,7 @@ mark_object (Lisp_Object arg)
5534 if (ptr->dogc) 5519 if (ptr->dogc)
5535 { 5520 {
5536 Lisp_Object *p = (Lisp_Object *) ptr->pointer; 5521 Lisp_Object *p = (Lisp_Object *) ptr->pointer;
5537 int nelt; 5522 ptrdiff_t nelt;
5538 for (nelt = ptr->integer; nelt > 0; nelt--, p++) 5523 for (nelt = ptr->integer; nelt > 0; nelt--, p++)
5539 mark_maybe_object (*p); 5524 mark_maybe_object (*p);
5540 } 5525 }
@@ -5734,7 +5719,7 @@ gc_sweep (void)
5734 register struct cons_block *cblk; 5719 register struct cons_block *cblk;
5735 struct cons_block **cprev = &cons_block; 5720 struct cons_block **cprev = &cons_block;
5736 register int lim = cons_block_index; 5721 register int lim = cons_block_index;
5737 register int num_free = 0, num_used = 0; 5722 EMACS_INT num_free = 0, num_used = 0;
5738 5723
5739 cons_free_list = 0; 5724 cons_free_list = 0;
5740 5725
@@ -5795,7 +5780,6 @@ gc_sweep (void)
5795 /* Unhook from the free list. */ 5780 /* Unhook from the free list. */
5796 cons_free_list = cblk->conses[0].u.chain; 5781 cons_free_list = cblk->conses[0].u.chain;
5797 lisp_align_free (cblk); 5782 lisp_align_free (cblk);
5798 n_cons_blocks--;
5799 } 5783 }
5800 else 5784 else
5801 { 5785 {
@@ -5812,7 +5796,7 @@ gc_sweep (void)
5812 register struct float_block *fblk; 5796 register struct float_block *fblk;
5813 struct float_block **fprev = &float_block; 5797 struct float_block **fprev = &float_block;
5814 register int lim = float_block_index; 5798 register int lim = float_block_index;
5815 register int num_free = 0, num_used = 0; 5799 EMACS_INT num_free = 0, num_used = 0;
5816 5800
5817 float_free_list = 0; 5801 float_free_list = 0;
5818 5802
@@ -5842,7 +5826,6 @@ gc_sweep (void)
5842 /* Unhook from the free list. */ 5826 /* Unhook from the free list. */
5843 float_free_list = fblk->floats[0].u.chain; 5827 float_free_list = fblk->floats[0].u.chain;
5844 lisp_align_free (fblk); 5828 lisp_align_free (fblk);
5845 n_float_blocks--;
5846 } 5829 }
5847 else 5830 else
5848 { 5831 {
@@ -5859,7 +5842,7 @@ gc_sweep (void)
5859 register struct interval_block *iblk; 5842 register struct interval_block *iblk;
5860 struct interval_block **iprev = &interval_block; 5843 struct interval_block **iprev = &interval_block;
5861 register int lim = interval_block_index; 5844 register int lim = interval_block_index;
5862 register int num_free = 0, num_used = 0; 5845 EMACS_INT num_free = 0, num_used = 0;
5863 5846
5864 interval_free_list = 0; 5847 interval_free_list = 0;
5865 5848
@@ -5892,7 +5875,6 @@ gc_sweep (void)
5892 /* Unhook from the free list. */ 5875 /* Unhook from the free list. */
5893 interval_free_list = INTERVAL_PARENT (&iblk->intervals[0]); 5876 interval_free_list = INTERVAL_PARENT (&iblk->intervals[0]);
5894 lisp_free (iblk); 5877 lisp_free (iblk);
5895 n_interval_blocks--;
5896 } 5878 }
5897 else 5879 else
5898 { 5880 {
@@ -5909,7 +5891,7 @@ gc_sweep (void)
5909 register struct symbol_block *sblk; 5891 register struct symbol_block *sblk;
5910 struct symbol_block **sprev = &symbol_block; 5892 struct symbol_block **sprev = &symbol_block;
5911 register int lim = symbol_block_index; 5893 register int lim = symbol_block_index;
5912 register int num_free = 0, num_used = 0; 5894 EMACS_INT num_free = 0, num_used = 0;
5913 5895
5914 symbol_free_list = NULL; 5896 symbol_free_list = NULL;
5915 5897
@@ -5956,7 +5938,6 @@ gc_sweep (void)
5956 /* Unhook from the free list. */ 5938 /* Unhook from the free list. */
5957 symbol_free_list = sblk->symbols[0].next; 5939 symbol_free_list = sblk->symbols[0].next;
5958 lisp_free (sblk); 5940 lisp_free (sblk);
5959 n_symbol_blocks--;
5960 } 5941 }
5961 else 5942 else
5962 { 5943 {
@@ -5974,7 +5955,7 @@ gc_sweep (void)
5974 register struct marker_block *mblk; 5955 register struct marker_block *mblk;
5975 struct marker_block **mprev = &marker_block; 5956 struct marker_block **mprev = &marker_block;
5976 register int lim = marker_block_index; 5957 register int lim = marker_block_index;
5977 register int num_free = 0, num_used = 0; 5958 EMACS_INT num_free = 0, num_used = 0;
5978 5959
5979 marker_free_list = 0; 5960 marker_free_list = 0;
5980 5961
@@ -6013,7 +5994,6 @@ gc_sweep (void)
6013 /* Unhook from the free list. */ 5994 /* Unhook from the free list. */
6014 marker_free_list = mblk->markers[0].u_free.chain; 5995 marker_free_list = mblk->markers[0].u_free.chain;
6015 lisp_free (mblk); 5996 lisp_free (mblk);
6016 n_marker_blocks--;
6017 } 5997 }
6018 else 5998 else
6019 { 5999 {
@@ -6063,7 +6043,6 @@ gc_sweep (void)
6063 all_vectors = vector->header.next.vector; 6043 all_vectors = vector->header.next.vector;
6064 next = vector->header.next.vector; 6044 next = vector->header.next.vector;
6065 lisp_free (vector); 6045 lisp_free (vector);
6066 n_vectors--;
6067 vector = next; 6046 vector = next;
6068 6047
6069 } 6048 }
diff --git a/src/buffer.c b/src/buffer.c
index 7030fea1002..d7adf63c98b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -850,8 +850,8 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
850 (register Lisp_Object name, Lisp_Object ignore) 850 (register Lisp_Object name, Lisp_Object ignore)
851{ 851{
852 register Lisp_Object gentemp, tem; 852 register Lisp_Object gentemp, tem;
853 int count; 853 EMACS_INT count;
854 char number[10]; 854 char number[INT_BUFSIZE_BOUND (EMACS_INT) + sizeof "<>"];
855 855
856 CHECK_STRING (name); 856 CHECK_STRING (name);
857 857
@@ -865,7 +865,7 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
865 count = 1; 865 count = 1;
866 while (1) 866 while (1)
867 { 867 {
868 sprintf (number, "<%d>", ++count); 868 sprintf (number, "<%"pI"d>", ++count);
869 gentemp = concat2 (name, build_string (number)); 869 gentemp = concat2 (name, build_string (number));
870 tem = Fstring_equal (gentemp, ignore); 870 tem = Fstring_equal (gentemp, ignore);
871 if (!NILP (tem)) 871 if (!NILP (tem))
@@ -1969,7 +1969,7 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
1969/* Advance BYTE_POS up to a character boundary 1969/* Advance BYTE_POS up to a character boundary
1970 and return the adjusted position. */ 1970 and return the adjusted position. */
1971 1971
1972static int 1972static EMACS_INT
1973advance_to_char_boundary (EMACS_INT byte_pos) 1973advance_to_char_boundary (EMACS_INT byte_pos)
1974{ 1974{
1975 int c; 1975 int c;
diff --git a/src/buffer.h b/src/buffer.h
index 3540bd87cea..dc1d62beb00 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -338,7 +338,7 @@ while (0)
338 338
339#define PTR_BYTE_POS(ptr) \ 339#define PTR_BYTE_POS(ptr) \
340((ptr) - (current_buffer)->text->beg \ 340((ptr) - (current_buffer)->text->beg \
341 - (ptr - (current_buffer)->text->beg <= (unsigned) (GPT_BYTE - BEG_BYTE) ? 0 : GAP_SIZE) \ 341 - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \
342 + BEG_BYTE) 342 + BEG_BYTE)
343 343
344/* Return character at byte position POS. */ 344/* Return character at byte position POS. */
@@ -397,7 +397,7 @@ extern unsigned char *_fetch_multibyte_char_p;
397 397
398#define BUF_PTR_BYTE_POS(buf, ptr) \ 398#define BUF_PTR_BYTE_POS(buf, ptr) \
399((ptr) - (buf)->text->beg \ 399((ptr) - (buf)->text->beg \
400 - (ptr - (buf)->text->beg <= (unsigned) (BUF_GPT_BYTE ((buf)) - BEG_BYTE)\ 400 - (ptr - (buf)->text->beg <= BUF_GPT_BYTE (buf) - BEG_BYTE \
401 ? 0 : BUF_GAP_SIZE ((buf))) \ 401 ? 0 : BUF_GAP_SIZE ((buf))) \
402 + BEG_BYTE) 402 + BEG_BYTE)
403 403
diff --git a/src/bytecode.c b/src/bytecode.c
index 74cf401bf1d..58b26c79b84 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -433,7 +433,7 @@ If the third argument is incorrect, Emacs may crash. */)
433 433
434Lisp_Object 434Lisp_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, int nargs, Lisp_Object *args) 436 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
437{ 437{
438 int count = SPECPDL_INDEX (); 438 int count = SPECPDL_INDEX ();
439#ifdef BYTE_CODE_METER 439#ifdef BYTE_CODE_METER
@@ -444,7 +444,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
444 /* Lisp_Object v1, v2; */ 444 /* Lisp_Object v1, v2; */
445 Lisp_Object *vectorp; 445 Lisp_Object *vectorp;
446#ifdef BYTE_CODE_SAFE 446#ifdef BYTE_CODE_SAFE
447 int const_length; 447 ptrdiff_t const_length;
448 Lisp_Object *stacke; 448 Lisp_Object *stacke;
449 int bytestr_length; 449 int bytestr_length;
450#endif 450#endif
@@ -464,7 +464,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
464 464
465 CHECK_STRING (bytestr); 465 CHECK_STRING (bytestr);
466 CHECK_VECTOR (vector); 466 CHECK_VECTOR (vector);
467 CHECK_NUMBER (maxdepth); 467 CHECK_NATNUM (maxdepth);
468 468
469#ifdef BYTE_CODE_SAFE 469#ifdef BYTE_CODE_SAFE
470 const_length = ASIZE (vector); 470 const_length = ASIZE (vector);
@@ -486,6 +486,8 @@ 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))
490 memory_full (SIZE_MAX);
489 top = (Lisp_Object *) alloca (XFASTINT (maxdepth) 491 top = (Lisp_Object *) alloca (XFASTINT (maxdepth)
490 * sizeof (Lisp_Object)); 492 * sizeof (Lisp_Object));
491#if BYTE_MAINTAIN_TOP 493#if BYTE_MAINTAIN_TOP
@@ -502,14 +504,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
502 504
503 if (INTEGERP (args_template)) 505 if (INTEGERP (args_template))
504 { 506 {
505 int at = XINT (args_template); 507 ptrdiff_t at = XINT (args_template);
506 int rest = at & 128; 508 int rest = at & 128;
507 int mandatory = at & 127; 509 int mandatory = at & 127;
508 int nonrest = at >> 8; 510 ptrdiff_t nonrest = at >> 8;
509 eassert (mandatory <= nonrest); 511 eassert (mandatory <= nonrest);
510 if (nargs <= nonrest) 512 if (nargs <= nonrest)
511 { 513 {
512 int i; 514 ptrdiff_t i;
513 for (i = 0 ; i < nargs; i++, args++) 515 for (i = 0 ; i < nargs; i++, args++)
514 PUSH (*args); 516 PUSH (*args);
515 if (nargs < mandatory) 517 if (nargs < mandatory)
@@ -528,7 +530,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
528 } 530 }
529 else if (rest) 531 else if (rest)
530 { 532 {
531 int i; 533 ptrdiff_t i;
532 for (i = 0 ; i < nonrest; i++, args++) 534 for (i = 0 ; i < nonrest; i++, args++)
533 PUSH (*args); 535 PUSH (*args);
534 PUSH (Flist (nargs - nonrest, args)); 536 PUSH (Flist (nargs - nonrest, args));
diff --git a/src/callint.c b/src/callint.c
index 2cc3a7cb537..dc5e6a4c37a 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -269,10 +269,9 @@ invoke it. If KEYS is omitted or nil, the return value of
269 /* If varies[i] > 0, the i'th argument shouldn't just have its value 269 /* If varies[i] > 0, the i'th argument shouldn't just have its value
270 in this call quoted in the command history. It should be 270 in this call quoted in the command history. It should be
271 recorded as a call to the function named callint_argfuns[varies[i]]. */ 271 recorded as a call to the function named callint_argfuns[varies[i]]. */
272 int *varies; 272 signed char *varies;
273 273
274 register size_t i; 274 ptrdiff_t i, nargs;
275 size_t nargs;
276 int foo; 275 int foo;
277 char prompt1[100]; 276 char prompt1[100];
278 char *tem1; 277 char *tem1;
@@ -339,7 +338,7 @@ invoke it. If KEYS is omitted or nil, the return value of
339 { 338 {
340 Lisp_Object input; 339 Lisp_Object input;
341 Lisp_Object funval = Findirect_function (function, Qt); 340 Lisp_Object funval = Findirect_function (function, Qt);
342 i = num_input_events; 341 size_t events = num_input_events;
343 input = specs; 342 input = specs;
344 /* Compute the arg values using the user's expression. */ 343 /* Compute the arg values using the user's expression. */
345 GCPRO2 (input, filter_specs); 344 GCPRO2 (input, filter_specs);
@@ -347,7 +346,7 @@ invoke it. If KEYS is omitted or nil, the return value of
347 CONSP (funval) && EQ (Qclosure, XCAR (funval)) 346 CONSP (funval) && EQ (Qclosure, XCAR (funval))
348 ? Qt : Qnil); 347 ? Qt : Qnil);
349 UNGCPRO; 348 UNGCPRO;
350 if (i != num_input_events || !NILP (record_flag)) 349 if (events != num_input_events || !NILP (record_flag))
351 { 350 {
352 /* We should record this command on the command history. */ 351 /* We should record this command on the command history. */
353 Lisp_Object values; 352 Lisp_Object values;
@@ -465,9 +464,14 @@ invoke it. If KEYS is omitted or nil, the return value of
465 break; 464 break;
466 } 465 }
467 466
467 if (min (MOST_POSITIVE_FIXNUM,
468 min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object))
469 < nargs)
470 memory_full (SIZE_MAX);
471
468 args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); 472 args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
469 visargs = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); 473 visargs = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
470 varies = (int *) alloca (nargs * sizeof (int)); 474 varies = (signed char *) alloca (nargs);
471 475
472 for (i = 0; i < nargs; i++) 476 for (i = 0; i < nargs; i++)
473 { 477 {
diff --git a/src/callproc.c b/src/callproc.c
index 7bb2ac05933..d6bad2a44e7 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -184,7 +184,7 @@ and returns a numeric exit status or a signal description string.
184If you quit, the process is killed with SIGINT, or SIGKILL if you quit again. 184If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
185 185
186usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) 186usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
187 (size_t nargs, register Lisp_Object *args) 187 (ptrdiff_t nargs, Lisp_Object *args)
188{ 188{
189 Lisp_Object infile, buffer, current_dir, path; 189 Lisp_Object infile, buffer, current_dir, path;
190 volatile int display_p_volatile; 190 volatile int display_p_volatile;
@@ -231,7 +231,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
231 /* Decide the coding-system for giving arguments. */ 231 /* Decide the coding-system for giving arguments. */
232 { 232 {
233 Lisp_Object val, *args2; 233 Lisp_Object val, *args2;
234 size_t i; 234 ptrdiff_t i;
235 235
236 /* If arguments are supplied, we may have to encode them. */ 236 /* If arguments are supplied, we may have to encode them. */
237 if (nargs >= 5) 237 if (nargs >= 5)
@@ -422,7 +422,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
422 (nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv); 422 (nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
423 if (nargs > 4) 423 if (nargs > 4)
424 { 424 {
425 register size_t i; 425 ptrdiff_t i;
426 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 426 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
427 427
428 GCPRO5 (infile, buffer, current_dir, path, error_file); 428 GCPRO5 (infile, buffer, current_dir, path, error_file);
@@ -716,7 +716,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
716 { 716 {
717 if (EQ (coding_systems, Qt)) 717 if (EQ (coding_systems, Qt))
718 { 718 {
719 size_t i; 719 ptrdiff_t i;
720 720
721 SAFE_ALLOCA (args2, Lisp_Object *, (nargs + 1) * sizeof *args2); 721 SAFE_ALLOCA (args2, Lisp_Object *, (nargs + 1) * sizeof *args2);
722 args2[0] = Qcall_process; 722 args2[0] = Qcall_process;
@@ -944,7 +944,7 @@ and returns a numeric exit status or a signal description string.
944If you quit, the process is killed with SIGINT, or SIGKILL if you quit again. 944If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
945 945
946usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */) 946usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
947 (size_t nargs, register Lisp_Object *args) 947 (ptrdiff_t nargs, Lisp_Object *args)
948{ 948{
949 struct gcpro gcpro1; 949 struct gcpro gcpro1;
950 Lisp_Object filename_string; 950 Lisp_Object filename_string;
@@ -953,7 +953,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
953 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 953 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
954 Lisp_Object coding_systems; 954 Lisp_Object coding_systems;
955 Lisp_Object val, *args2; 955 Lisp_Object val, *args2;
956 size_t i; 956 ptrdiff_t i;
957 char *tempfile; 957 char *tempfile;
958 Lisp_Object tmpdir, pattern; 958 Lisp_Object tmpdir, pattern;
959 959
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 9f286d73a5e..1a0a62f273c 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -52,7 +52,7 @@ casify_object (enum case_action flag, Lisp_Object obj)
52 /* If the character has higher bits set 52 /* If the character has higher bits set
53 above the flags, return it unchanged. 53 above the flags, return it unchanged.
54 It is not a real character. */ 54 It is not a real character. */
55 if ((unsigned) XFASTINT (obj) > (unsigned) flagbits) 55 if (UNSIGNED_CMP (XFASTINT (obj), >, flagbits))
56 return obj; 56 return obj;
57 57
58 c1 = XFASTINT (obj) & ~flagbits; 58 c1 = XFASTINT (obj) & ~flagbits;
diff --git a/src/ccl.c b/src/ccl.c
index e2ef4f194f3..30d151f00a0 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -745,11 +745,15 @@ while(0)
745 745
746#endif 746#endif
747 747
748/* Use "&" rather than "&&" to suppress a bogus GCC warning; see
749 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43772>. */
750#define ASCENDING_ORDER(lo, med, hi) (((lo) <= (med)) & ((med) <= (hi)))
751
748#define GET_CCL_RANGE(var, ccl_prog, ic, lo, hi) \ 752#define GET_CCL_RANGE(var, ccl_prog, ic, lo, hi) \
749 do \ 753 do \
750 { \ 754 { \
751 EMACS_INT prog_word = XINT ((ccl_prog)[ic]); \ 755 EMACS_INT prog_word = XINT ((ccl_prog)[ic]); \
752 if (! ((lo) <= prog_word && prog_word <= (hi))) \ 756 if (! ASCENDING_ORDER (lo, prog_word, hi)) \
753 CCL_INVALID_CMD; \ 757 CCL_INVALID_CMD; \
754 (var) = prog_word; \ 758 (var) = prog_word; \
755 } \ 759 } \
@@ -761,7 +765,7 @@ while(0)
761#define GET_CCL_INT(var, ccl_prog, ic) \ 765#define GET_CCL_INT(var, ccl_prog, ic) \
762 GET_CCL_RANGE (var, ccl_prog, ic, INT_MIN, INT_MAX) 766 GET_CCL_RANGE (var, ccl_prog, ic, INT_MIN, INT_MAX)
763 767
764#define IN_INT_RANGE(val) (INT_MIN <= (val) && (val) <= INT_MAX) 768#define IN_INT_RANGE(val) ASCENDING_ORDER (INT_MIN, val, INT_MAX)
765 769
766/* Encode one character CH to multibyte form and write to the current 770/* Encode one character CH to multibyte form and write to the current
767 output buffer. If CH is less than 256, CH is written as is. */ 771 output buffer. If CH is less than 256, CH is written as is. */
diff --git a/src/character.c b/src/character.c
index 170952619e7..7fc5d647ff5 100644
--- a/src/character.c
+++ b/src/character.c
@@ -123,7 +123,7 @@ char_string (unsigned int c, unsigned char *p)
123 123
124 if (c & CHAR_MODIFIER_MASK) 124 if (c & CHAR_MODIFIER_MASK)
125 { 125 {
126 c = (unsigned) char_resolve_modifier_mask ((int) c); 126 c = char_resolve_modifier_mask (c);
127 /* If C still has any modifier bits, just ignore it. */ 127 /* If C still has any modifier bits, just ignore it. */
128 c &= ~CHAR_MODIFIER_MASK; 128 c &= ~CHAR_MODIFIER_MASK;
129 } 129 }
@@ -838,7 +838,7 @@ string_escape_byte8 (Lisp_Object string)
838 if (multibyte) 838 if (multibyte)
839 { 839 {
840 if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count 840 if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
841 || (STRING_BYTES_MAX - nbytes) / 2 < byte8_count) 841 || (STRING_BYTES_BOUND - nbytes) / 2 < byte8_count)
842 string_overflow (); 842 string_overflow ();
843 843
844 /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ 844 /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */
@@ -847,7 +847,7 @@ string_escape_byte8 (Lisp_Object string)
847 } 847 }
848 else 848 else
849 { 849 {
850 if ((STRING_BYTES_MAX - nchars) / 3 < byte8_count) 850 if ((STRING_BYTES_BOUND - nbytes) / 3 < byte8_count)
851 string_overflow (); 851 string_overflow ();
852 852
853 /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ 853 /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */
@@ -893,9 +893,9 @@ DEFUN ("string", Fstring, Sstring, 0, MANY, 0,
893 doc: /* 893 doc: /*
894Concatenate all the argument characters and make the result a string. 894Concatenate all the argument characters and make the result a string.
895usage: (string &rest CHARACTERS) */) 895usage: (string &rest CHARACTERS) */)
896 (size_t n, Lisp_Object *args) 896 (ptrdiff_t n, Lisp_Object *args)
897{ 897{
898 size_t i; 898 ptrdiff_t i;
899 int c; 899 int c;
900 unsigned char *buf, *p; 900 unsigned char *buf, *p;
901 Lisp_Object str; 901 Lisp_Object str;
@@ -919,9 +919,9 @@ usage: (string &rest CHARACTERS) */)
919DEFUN ("unibyte-string", Funibyte_string, Sunibyte_string, 0, MANY, 0, 919DEFUN ("unibyte-string", Funibyte_string, Sunibyte_string, 0, MANY, 0,
920 doc: /* Concatenate all the argument bytes and make the result a unibyte string. 920 doc: /* Concatenate all the argument bytes and make the result a unibyte string.
921usage: (unibyte-string &rest BYTES) */) 921usage: (unibyte-string &rest BYTES) */)
922 (size_t n, Lisp_Object *args) 922 (ptrdiff_t n, Lisp_Object *args)
923{ 923{
924 size_t i; 924 ptrdiff_t i;
925 int c; 925 int c;
926 unsigned char *buf, *p; 926 unsigned char *buf, *p;
927 Lisp_Object str; 927 Lisp_Object str;
diff --git a/src/character.h b/src/character.h
index 884833775de..9a45e7f0033 100644
--- a/src/character.h
+++ b/src/character.h
@@ -23,6 +23,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#ifndef EMACS_CHARACTER_H 23#ifndef EMACS_CHARACTER_H
24#define EMACS_CHARACTER_H 24#define EMACS_CHARACTER_H
25 25
26#include <verify.h>
27
26/* character code 1st byte byte sequence 28/* character code 1st byte byte sequence
27 -------------- -------- ------------- 29 -------------- -------- -------------
28 0-7F 00..7F 0xxxxxxx 30 0-7F 00..7F 0xxxxxxx
@@ -102,13 +104,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
102#define make_char(c) make_number (c) 104#define make_char(c) make_number (c)
103 105
104/* Nonzero iff C is an ASCII byte. */ 106/* Nonzero iff C is an ASCII byte. */
105#define ASCII_BYTE_P(c) ((unsigned) (c) < 0x80) 107#define ASCII_BYTE_P(c) UNSIGNED_CMP (c, <, 0x80)
106 108
107/* Nonzero iff X is a character. */ 109/* Nonzero iff X is a character. */
108#define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR) 110#define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR)
109 111
110/* Nonzero iff C is valid as a character code. GENERICP is not used. */ 112/* Nonzero iff C is valid as a character code. */
111#define CHAR_VALID_P(c, genericp) ((unsigned) (c) <= MAX_CHAR) 113#define CHAR_VALID_P(c) UNSIGNED_CMP (c, <=, MAX_CHAR)
112 114
113/* Check if Lisp object X is a character or not. */ 115/* Check if Lisp object X is a character or not. */
114#define CHECK_CHARACTER(x) \ 116#define CHECK_CHARACTER(x) \
@@ -129,7 +131,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
129 } while (0) 131 } while (0)
130 132
131/* Nonzero iff C is a character of code less than 0x100. */ 133/* Nonzero iff C is a character of code less than 0x100. */
132#define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100) 134#define SINGLE_BYTE_CHAR_P(c) UNSIGNED_CMP (c, <, 0x100)
133 135
134/* Nonzero if character C has a printable glyph. */ 136/* Nonzero if character C has a printable glyph. */
135#define CHAR_PRINTABLE_P(c) \ 137#define CHAR_PRINTABLE_P(c) \
@@ -161,19 +163,19 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
161 Returns the length of the multibyte form. */ 163 Returns the length of the multibyte form. */
162 164
163#define CHAR_STRING(c, p) \ 165#define CHAR_STRING(c, p) \
164 ((unsigned) (c) <= MAX_1_BYTE_CHAR \ 166 (UNSIGNED_CMP (c, <=, MAX_1_BYTE_CHAR) \
165 ? ((p)[0] = (c), \ 167 ? ((p)[0] = (c), \
166 1) \ 168 1) \
167 : (unsigned) (c) <= MAX_2_BYTE_CHAR \ 169 : UNSIGNED_CMP (c, <=, MAX_2_BYTE_CHAR) \
168 ? ((p)[0] = (0xC0 | ((c) >> 6)), \ 170 ? ((p)[0] = (0xC0 | ((c) >> 6)), \
169 (p)[1] = (0x80 | ((c) & 0x3F)), \ 171 (p)[1] = (0x80 | ((c) & 0x3F)), \
170 2) \ 172 2) \
171 : (unsigned) (c) <= MAX_3_BYTE_CHAR \ 173 : UNSIGNED_CMP (c, <=, MAX_3_BYTE_CHAR) \
172 ? ((p)[0] = (0xE0 | ((c) >> 12)), \ 174 ? ((p)[0] = (0xE0 | ((c) >> 12)), \
173 (p)[1] = (0x80 | (((c) >> 6) & 0x3F)), \ 175 (p)[1] = (0x80 | (((c) >> 6) & 0x3F)), \
174 (p)[2] = (0x80 | ((c) & 0x3F)), \ 176 (p)[2] = (0x80 | ((c) & 0x3F)), \
175 3) \ 177 3) \
176 : char_string ((unsigned) c, p)) 178 : verify_expr (sizeof (c) <= sizeof (unsigned), char_string (c, p)))
177 179
178/* Store multibyte form of byte B in P. The caller should allocate at 180/* Store multibyte form of byte B in P. The caller should allocate at
179 least MAX_MULTIBYTE_LENGTH bytes area at P in advance. Returns the 181 least MAX_MULTIBYTE_LENGTH bytes area at P in advance. Returns the
@@ -201,7 +203,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
201 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ 203 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \
202 *(p)++ = (0x80 | ((c) & 0x3F)); \ 204 *(p)++ = (0x80 | ((c) & 0x3F)); \
203 else \ 205 else \
204 (p) += char_string ((c), (p)); \ 206 { \
207 verify (sizeof (c) <= sizeof (unsigned)); \
208 (p) += char_string (c, p); \
209 } \
205 } while (0) 210 } while (0)
206 211
207 212
diff --git a/src/charset.c b/src/charset.c
index 770e98c99e1..55234aa76aa 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -844,7 +844,7 @@ DEFUN ("define-charset-internal", Fdefine_charset_internal,
844 Sdefine_charset_internal, charset_arg_max, MANY, 0, 844 Sdefine_charset_internal, charset_arg_max, MANY, 0,
845 doc: /* For internal use only. 845 doc: /* For internal use only.
846usage: (define-charset-internal ...) */) 846usage: (define-charset-internal ...) */)
847 (size_t nargs, Lisp_Object *args) 847 (ptrdiff_t nargs, Lisp_Object *args)
848{ 848{
849 /* Charset attr vector. */ 849 /* Charset attr vector. */
850 Lisp_Object attrs; 850 Lisp_Object attrs;
@@ -1862,14 +1862,15 @@ Optional argument RESTRICTION specifies a way to map CH to a
1862code-point in CCS. Currently not supported and just ignored. */) 1862code-point in CCS. Currently not supported and just ignored. */)
1863 (Lisp_Object ch, Lisp_Object charset, Lisp_Object restriction) 1863 (Lisp_Object ch, Lisp_Object charset, Lisp_Object restriction)
1864{ 1864{
1865 int id; 1865 int c, id;
1866 unsigned code; 1866 unsigned code;
1867 struct charset *charsetp; 1867 struct charset *charsetp;
1868 1868
1869 CHECK_CHARSET_GET_ID (charset, id); 1869 CHECK_CHARSET_GET_ID (charset, id);
1870 CHECK_NATNUM (ch); 1870 CHECK_CHARACTER (ch);
1871 c = XFASTINT (ch);
1871 charsetp = CHARSET_FROM_ID (id); 1872 charsetp = CHARSET_FROM_ID (id);
1872 code = ENCODE_CHAR (charsetp, XINT (ch)); 1873 code = ENCODE_CHAR (charsetp, c);
1873 if (code == CHARSET_INVALID_CODE (charsetp)) 1874 if (code == CHARSET_INVALID_CODE (charsetp))
1874 return Qnil; 1875 return Qnil;
1875 return INTEGER_TO_CONS (code); 1876 return INTEGER_TO_CONS (code);
@@ -2144,11 +2145,11 @@ DEFUN ("set-charset-priority", Fset_charset_priority, Sset_charset_priority,
2144 1, MANY, 0, 2145 1, MANY, 0,
2145 doc: /* Assign higher priority to the charsets given as arguments. 2146 doc: /* Assign higher priority to the charsets given as arguments.
2146usage: (set-charset-priority &rest charsets) */) 2147usage: (set-charset-priority &rest charsets) */)
2147 (size_t nargs, Lisp_Object *args) 2148 (ptrdiff_t nargs, Lisp_Object *args)
2148{ 2149{
2149 Lisp_Object new_head, old_list, arglist[2]; 2150 Lisp_Object new_head, old_list, arglist[2];
2150 Lisp_Object list_2022, list_emacs_mule; 2151 Lisp_Object list_2022, list_emacs_mule;
2151 size_t i; 2152 ptrdiff_t i;
2152 int id; 2153 int id;
2153 2154
2154 old_list = Fcopy_sequence (Vcharset_ordered_list); 2155 old_list = Fcopy_sequence (Vcharset_ordered_list);
diff --git a/src/charset.h b/src/charset.h
index 16f45ff9865..c2a52a38e7e 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -27,6 +27,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27#ifndef EMACS_CHARSET_H 27#ifndef EMACS_CHARSET_H
28#define EMACS_CHARSET_H 28#define EMACS_CHARSET_H
29 29
30#include <verify.h>
31
30/* Index to arguments of Fdefine_charset_internal. */ 32/* Index to arguments of Fdefine_charset_internal. */
31 33
32enum define_charset_arg_index 34enum define_charset_arg_index
@@ -424,28 +426,30 @@ extern Lisp_Object charset_work;
424/* Return a code point of CHAR in CHARSET. 426/* Return a code point of CHAR in CHARSET.
425 Try some optimization before calling encode_char. */ 427 Try some optimization before calling encode_char. */
426 428
427#define ENCODE_CHAR(charset, c) \ 429#define ENCODE_CHAR(charset, c) \
428 ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p) \ 430 (verify_expr \
429 ? (c) \ 431 (sizeof (c) <= sizeof (int), \
430 : ((charset)->unified_p \ 432 (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p \
431 || (charset)->method == CHARSET_METHOD_SUBSET \ 433 ? (c) \
432 || (charset)->method == CHARSET_METHOD_SUPERSET) \ 434 : ((charset)->unified_p \
433 ? encode_char ((charset), (c)) \ 435 || (charset)->method == CHARSET_METHOD_SUBSET \
434 : ((c) < (charset)->min_char || (c) > (charset)->max_char) \ 436 || (charset)->method == CHARSET_METHOD_SUPERSET) \
435 ? (charset)->invalid_code \ 437 ? encode_char (charset, c) \
436 : (charset)->method == CHARSET_METHOD_OFFSET \ 438 : (c) < (charset)->min_char || (c) > (charset)->max_char \
437 ? ((charset)->code_linear_p \ 439 ? (charset)->invalid_code \
438 ? (c) - (charset)->code_offset + (charset)->min_code \ 440 : (charset)->method == CHARSET_METHOD_OFFSET \
439 : encode_char ((charset), (c))) \ 441 ? ((charset)->code_linear_p \
440 : (charset)->method == CHARSET_METHOD_MAP \ 442 ? (c) - (charset)->code_offset + (charset)->min_code \
441 ? (((charset)->compact_codes_p \ 443 : encode_char (charset, c)) \
442 && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \ 444 : (charset)->method == CHARSET_METHOD_MAP \
443 ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c)), \ 445 ? (((charset)->compact_codes_p \
444 (NILP (charset_work) \ 446 && CHAR_TABLE_P (CHARSET_ENCODER (charset))) \
445 ? (charset)->invalid_code \ 447 ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \
446 : XFASTINT (charset_work))) \ 448 (NILP (charset_work) \
447 : encode_char ((charset), (c))) \ 449 ? (charset)->invalid_code \
448 : encode_char ((charset), (c))) 450 : XFASTINT (charset_work))) \
451 : encode_char (charset, c)) \
452 : encode_char (charset, c))))
449 453
450 454
451/* Set to 1 when a charset map is loaded to warn that a buffer text 455/* Set to 1 when a charset map is loaded to warn that a buffer text
diff --git a/src/chartab.c b/src/chartab.c
index 2f40ceee6ce..ed5b238646e 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -524,15 +524,15 @@ a cons of character codes (for characters in the range), or a character code. *
524 524
525 if (EQ (range, Qnil)) 525 if (EQ (range, Qnil))
526 val = XCHAR_TABLE (char_table)->defalt; 526 val = XCHAR_TABLE (char_table)->defalt;
527 else if (INTEGERP (range)) 527 else if (CHARACTERP (range))
528 val = CHAR_TABLE_REF (char_table, XINT (range)); 528 val = CHAR_TABLE_REF (char_table, XFASTINT (range));
529 else if (CONSP (range)) 529 else if (CONSP (range))
530 { 530 {
531 int from, to; 531 int from, to;
532 532
533 CHECK_CHARACTER_CAR (range); 533 CHECK_CHARACTER_CAR (range);
534 CHECK_CHARACTER_CDR (range); 534 CHECK_CHARACTER_CDR (range);
535 val = char_table_ref_and_range (char_table, XINT (XCAR (range)), 535 val = char_table_ref_and_range (char_table, XFASTINT (XCAR (range)),
536 &from, &to); 536 &from, &to);
537 /* Not yet implemented. */ 537 /* Not yet implemented. */
538 } 538 }
diff --git a/src/coding.c b/src/coding.c
index 64e8e41a5a1..04985ab3c74 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -1071,7 +1071,7 @@ coding_set_destination (struct coding_system *coding)
1071static void 1071static void
1072coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes) 1072coding_alloc_by_realloc (struct coding_system *coding, EMACS_INT bytes)
1073{ 1073{
1074 if (STRING_BYTES_MAX - coding->dst_bytes < bytes) 1074 if (STRING_BYTES_BOUND - coding->dst_bytes < bytes)
1075 string_overflow (); 1075 string_overflow ();
1076 coding->destination = (unsigned char *) xrealloc (coding->destination, 1076 coding->destination = (unsigned char *) xrealloc (coding->destination,
1077 coding->dst_bytes + bytes); 1077 coding->dst_bytes + bytes);
@@ -9278,7 +9278,7 @@ function to call for FILENAME, that function should examine the
9278contents of BUFFER instead of reading the file. 9278contents of BUFFER instead of reading the file.
9279 9279
9280usage: (find-operation-coding-system OPERATION ARGUMENTS...) */) 9280usage: (find-operation-coding-system OPERATION ARGUMENTS...) */)
9281 (size_t nargs, Lisp_Object *args) 9281 (ptrdiff_t nargs, Lisp_Object *args)
9282{ 9282{
9283 Lisp_Object operation, target_idx, target, val; 9283 Lisp_Object operation, target_idx, target, val;
9284 register Lisp_Object chain; 9284 register Lisp_Object chain;
@@ -9355,9 +9355,9 @@ If multiple coding systems belong to the same category,
9355all but the first one are ignored. 9355all but the first one are ignored.
9356 9356
9357usage: (set-coding-system-priority &rest coding-systems) */) 9357usage: (set-coding-system-priority &rest coding-systems) */)
9358 (size_t nargs, Lisp_Object *args) 9358 (ptrdiff_t nargs, Lisp_Object *args)
9359{ 9359{
9360 size_t i, j; 9360 ptrdiff_t i, j;
9361 int changed[coding_category_max]; 9361 int changed[coding_category_max];
9362 enum coding_category priorities[coding_category_max]; 9362 enum coding_category priorities[coding_category_max];
9363 9363
@@ -9461,7 +9461,7 @@ DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal,
9461 Sdefine_coding_system_internal, coding_arg_max, MANY, 0, 9461 Sdefine_coding_system_internal, coding_arg_max, MANY, 0,
9462 doc: /* For internal use only. 9462 doc: /* For internal use only.
9463usage: (define-coding-system-internal ...) */) 9463usage: (define-coding-system-internal ...) */)
9464 (size_t nargs, Lisp_Object *args) 9464 (ptrdiff_t nargs, Lisp_Object *args)
9465{ 9465{
9466 Lisp_Object name; 9466 Lisp_Object name;
9467 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */ 9467 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */
diff --git a/src/composite.c b/src/composite.c
index ab9ec3f5a03..51b7669cb4f 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -858,7 +858,7 @@ fill_gstring_body (Lisp_Object gstring)
858 for (i = 0; i < len; i++) 858 for (i = 0; i < len; i++)
859 { 859 {
860 Lisp_Object g = LGSTRING_GLYPH (gstring, i); 860 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
861 EMACS_INT c = XINT (AREF (header, i + 1)); 861 int c = XFASTINT (AREF (header, i + 1));
862 862
863 if (NILP (g)) 863 if (NILP (g))
864 { 864 {
@@ -995,7 +995,8 @@ static int _work_char;
995void 995void
996composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, Lisp_Object string) 996composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, Lisp_Object string)
997{ 997{
998 EMACS_INT start, end, c; 998 EMACS_INT start, end;
999 int c;
999 Lisp_Object prop, val; 1000 Lisp_Object prop, val;
1000 /* This is from forward_to_next_line_start in xdisp.c. */ 1001 /* This is from forward_to_next_line_start in xdisp.c. */
1001 const int MAX_NEWLINE_DISTANCE = 500; 1002 const int MAX_NEWLINE_DISTANCE = 500;
diff --git a/src/composite.h b/src/composite.h
index 0f81911f0b0..8cedfdbe352 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -151,7 +151,7 @@ extern Lisp_Object composition_temp;
151/* Nonzero if the global reference point GREF and new reference point NREF are 151/* Nonzero if the global reference point GREF and new reference point NREF are
152 valid. */ 152 valid. */
153#define COMPOSITION_ENCODE_RULE_VALID(gref, nref) \ 153#define COMPOSITION_ENCODE_RULE_VALID(gref, nref) \
154 ((unsigned) (gref) < 12 && (unsigned) (nref) < 12) 154 (UNSIGNED_CMP (gref, <, 12) && UNSIGNED_CMP (nref, <, 12))
155 155
156/* Return encoded composition rule for the pair of global reference 156/* Return encoded composition rule for the pair of global reference
157 point GREF and new reference point NREF. Arguments must be valid. */ 157 point GREF and new reference point NREF. Arguments must be valid. */
diff --git a/src/data.c b/src/data.c
index 57d7753e393..cf01d38036d 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2148,61 +2148,62 @@ bool-vector. IDX starts at 0. */)
2148 CHECK_CHARACTER (idx); 2148 CHECK_CHARACTER (idx);
2149 CHAR_TABLE_SET (array, idxval, newelt); 2149 CHAR_TABLE_SET (array, idxval, newelt);
2150 } 2150 }
2151 else if (STRING_MULTIBYTE (array)) 2151 else
2152 { 2152 {
2153 EMACS_INT idxval_byte, prev_bytes, new_bytes, nbytes; 2153 int c;
2154 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2155 2154
2156 if (idxval < 0 || idxval >= SCHARS (array)) 2155 if (idxval < 0 || idxval >= SCHARS (array))
2157 args_out_of_range (array, idx); 2156 args_out_of_range (array, idx);
2158 CHECK_CHARACTER (newelt); 2157 CHECK_CHARACTER (newelt);
2158 c = XFASTINT (newelt);
2159 2159
2160 nbytes = SBYTES (array); 2160 if (STRING_MULTIBYTE (array))
2161
2162 idxval_byte = string_char_to_byte (array, idxval);
2163 p1 = SDATA (array) + idxval_byte;
2164 prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2165 new_bytes = CHAR_STRING (XINT (newelt), p0);
2166 if (prev_bytes != new_bytes)
2167 { 2161 {
2168 /* We must relocate the string data. */ 2162 EMACS_INT idxval_byte, prev_bytes, new_bytes, nbytes;
2169 EMACS_INT nchars = SCHARS (array); 2163 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2170 unsigned char *str; 2164
2171 USE_SAFE_ALLOCA; 2165 nbytes = SBYTES (array);
2172 2166 idxval_byte = string_char_to_byte (array, idxval);
2173 SAFE_ALLOCA (str, unsigned char *, nbytes);
2174 memcpy (str, SDATA (array), nbytes);
2175 allocate_string_data (XSTRING (array), nchars,
2176 nbytes + new_bytes - prev_bytes);
2177 memcpy (SDATA (array), str, idxval_byte);
2178 p1 = SDATA (array) + idxval_byte; 2167 p1 = SDATA (array) + idxval_byte;
2179 memcpy (p1 + new_bytes, str + idxval_byte + prev_bytes, 2168 prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2180 nbytes - (idxval_byte + prev_bytes)); 2169 new_bytes = CHAR_STRING (c, p0);
2181 SAFE_FREE (); 2170 if (prev_bytes != new_bytes)
2182 clear_string_char_byte_cache (); 2171 {
2172 /* We must relocate the string data. */
2173 EMACS_INT nchars = SCHARS (array);
2174 unsigned char *str;
2175 USE_SAFE_ALLOCA;
2176
2177 SAFE_ALLOCA (str, unsigned char *, nbytes);
2178 memcpy (str, SDATA (array), nbytes);
2179 allocate_string_data (XSTRING (array), nchars,
2180 nbytes + new_bytes - prev_bytes);
2181 memcpy (SDATA (array), str, idxval_byte);
2182 p1 = SDATA (array) + idxval_byte;
2183 memcpy (p1 + new_bytes, str + idxval_byte + prev_bytes,
2184 nbytes - (idxval_byte + prev_bytes));
2185 SAFE_FREE ();
2186 clear_string_char_byte_cache ();
2187 }
2188 while (new_bytes--)
2189 *p1++ = *p0++;
2183 } 2190 }
2184 while (new_bytes--) 2191 else
2185 *p1++ = *p0++;
2186 }
2187 else
2188 {
2189 if (idxval < 0 || idxval >= SCHARS (array))
2190 args_out_of_range (array, idx);
2191 CHECK_NUMBER (newelt);
2192
2193 if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
2194 { 2192 {
2195 int i; 2193 if (! SINGLE_BYTE_CHAR_P (c))
2196 2194 {
2197 for (i = SBYTES (array) - 1; i >= 0; i--) 2195 int i;
2198 if (SREF (array, i) >= 0x80) 2196
2199 args_out_of_range (array, newelt); 2197 for (i = SBYTES (array) - 1; i >= 0; i--)
2200 /* ARRAY is an ASCII string. Convert it to a multibyte 2198 if (SREF (array, i) >= 0x80)
2201 string, and try `aset' again. */ 2199 args_out_of_range (array, newelt);
2202 STRING_SET_MULTIBYTE (array); 2200 /* ARRAY is an ASCII string. Convert it to a multibyte
2203 return Faset (array, idx, newelt); 2201 string, and try `aset' again. */
2202 STRING_SET_MULTIBYTE (array);
2203 return Faset (array, idx, newelt);
2204 }
2205 SSET (array, idxval, c);
2204 } 2206 }
2205 SSET (array, idxval, XINT (newelt));
2206 } 2207 }
2207 2208
2208 return newelt; 2209 return newelt;
@@ -2502,18 +2503,18 @@ enum arithop
2502 Amin 2503 Amin
2503 }; 2504 };
2504 2505
2505static Lisp_Object float_arith_driver (double, size_t, enum arithop, 2506static Lisp_Object float_arith_driver (double, ptrdiff_t, enum arithop,
2506 size_t, Lisp_Object *); 2507 ptrdiff_t, Lisp_Object *);
2507static Lisp_Object 2508static Lisp_Object
2508arith_driver (enum arithop code, size_t nargs, register Lisp_Object *args) 2509arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
2509{ 2510{
2510 register Lisp_Object val; 2511 register Lisp_Object val;
2511 register size_t argnum; 2512 ptrdiff_t argnum;
2512 register EMACS_INT accum = 0; 2513 register EMACS_INT accum = 0;
2513 register EMACS_INT next; 2514 register EMACS_INT next;
2514 2515
2515 int overflow = 0; 2516 int overflow = 0;
2516 size_t ok_args; 2517 ptrdiff_t ok_args;
2517 EMACS_INT ok_accum; 2518 EMACS_INT ok_accum;
2518 2519
2519 switch (SWITCH_ENUM_CAST (code)) 2520 switch (SWITCH_ENUM_CAST (code))
@@ -2617,8 +2618,8 @@ arith_driver (enum arithop code, size_t nargs, register Lisp_Object *args)
2617#define isnan(x) ((x) != (x)) 2618#define isnan(x) ((x) != (x))
2618 2619
2619static Lisp_Object 2620static Lisp_Object
2620float_arith_driver (double accum, register size_t argnum, enum arithop code, 2621float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code,
2621 size_t nargs, register Lisp_Object *args) 2622 ptrdiff_t nargs, Lisp_Object *args)
2622{ 2623{
2623 register Lisp_Object val; 2624 register Lisp_Object val;
2624 double next; 2625 double next;
@@ -2680,7 +2681,7 @@ float_arith_driver (double accum, register size_t argnum, enum arithop code,
2680DEFUN ("+", Fplus, Splus, 0, MANY, 0, 2681DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2681 doc: /* Return sum of any number of arguments, which are numbers or markers. 2682 doc: /* Return sum of any number of arguments, which are numbers or markers.
2682usage: (+ &rest NUMBERS-OR-MARKERS) */) 2683usage: (+ &rest NUMBERS-OR-MARKERS) */)
2683 (size_t nargs, Lisp_Object *args) 2684 (ptrdiff_t nargs, Lisp_Object *args)
2684{ 2685{
2685 return arith_driver (Aadd, nargs, args); 2686 return arith_driver (Aadd, nargs, args);
2686} 2687}
@@ -2690,7 +2691,7 @@ DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2690With one arg, negates it. With more than one arg, 2691With one arg, negates it. With more than one arg,
2691subtracts all but the first from the first. 2692subtracts all but the first from the first.
2692usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) 2693usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2693 (size_t nargs, Lisp_Object *args) 2694 (ptrdiff_t nargs, Lisp_Object *args)
2694{ 2695{
2695 return arith_driver (Asub, nargs, args); 2696 return arith_driver (Asub, nargs, args);
2696} 2697}
@@ -2698,7 +2699,7 @@ usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2698DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, 2699DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2699 doc: /* Return product of any number of arguments, which are numbers or markers. 2700 doc: /* Return product of any number of arguments, which are numbers or markers.
2700usage: (* &rest NUMBERS-OR-MARKERS) */) 2701usage: (* &rest NUMBERS-OR-MARKERS) */)
2701 (size_t nargs, Lisp_Object *args) 2702 (ptrdiff_t nargs, Lisp_Object *args)
2702{ 2703{
2703 return arith_driver (Amult, nargs, args); 2704 return arith_driver (Amult, nargs, args);
2704} 2705}
@@ -2707,9 +2708,9 @@ DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2707 doc: /* Return first argument divided by all the remaining arguments. 2708 doc: /* Return first argument divided by all the remaining arguments.
2708The arguments must be numbers or markers. 2709The arguments must be numbers or markers.
2709usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */) 2710usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2710 (size_t nargs, Lisp_Object *args) 2711 (ptrdiff_t nargs, Lisp_Object *args)
2711{ 2712{
2712 size_t argnum; 2713 ptrdiff_t argnum;
2713 for (argnum = 2; argnum < nargs; argnum++) 2714 for (argnum = 2; argnum < nargs; argnum++)
2714 if (FLOATP (args[argnum])) 2715 if (FLOATP (args[argnum]))
2715 return float_arith_driver (0, 0, Adiv, nargs, args); 2716 return float_arith_driver (0, 0, Adiv, nargs, args);
@@ -2791,7 +2792,7 @@ DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2791 doc: /* Return largest of all the arguments (which must be numbers or markers). 2792 doc: /* Return largest of all the arguments (which must be numbers or markers).
2792The value is always a number; markers are converted to numbers. 2793The value is always a number; markers are converted to numbers.
2793usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) 2794usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2794 (size_t nargs, Lisp_Object *args) 2795 (ptrdiff_t nargs, Lisp_Object *args)
2795{ 2796{
2796 return arith_driver (Amax, nargs, args); 2797 return arith_driver (Amax, nargs, args);
2797} 2798}
@@ -2800,7 +2801,7 @@ DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2800 doc: /* Return smallest of all the arguments (which must be numbers or markers). 2801 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2801The value is always a number; markers are converted to numbers. 2802The value is always a number; markers are converted to numbers.
2802usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) 2803usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2803 (size_t nargs, Lisp_Object *args) 2804 (ptrdiff_t nargs, Lisp_Object *args)
2804{ 2805{
2805 return arith_driver (Amin, nargs, args); 2806 return arith_driver (Amin, nargs, args);
2806} 2807}
@@ -2809,7 +2810,7 @@ DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2809 doc: /* Return bitwise-and of all the arguments. 2810 doc: /* Return bitwise-and of all the arguments.
2810Arguments may be integers, or markers converted to integers. 2811Arguments may be integers, or markers converted to integers.
2811usage: (logand &rest INTS-OR-MARKERS) */) 2812usage: (logand &rest INTS-OR-MARKERS) */)
2812 (size_t nargs, Lisp_Object *args) 2813 (ptrdiff_t nargs, Lisp_Object *args)
2813{ 2814{
2814 return arith_driver (Alogand, nargs, args); 2815 return arith_driver (Alogand, nargs, args);
2815} 2816}
@@ -2818,7 +2819,7 @@ DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2818 doc: /* Return bitwise-or of all the arguments. 2819 doc: /* Return bitwise-or of all the arguments.
2819Arguments may be integers, or markers converted to integers. 2820Arguments may be integers, or markers converted to integers.
2820usage: (logior &rest INTS-OR-MARKERS) */) 2821usage: (logior &rest INTS-OR-MARKERS) */)
2821 (size_t nargs, Lisp_Object *args) 2822 (ptrdiff_t nargs, Lisp_Object *args)
2822{ 2823{
2823 return arith_driver (Alogior, nargs, args); 2824 return arith_driver (Alogior, nargs, args);
2824} 2825}
@@ -2827,7 +2828,7 @@ DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2827 doc: /* Return bitwise-exclusive-or of all the arguments. 2828 doc: /* Return bitwise-exclusive-or of all the arguments.
2828Arguments may be integers, or markers converted to integers. 2829Arguments may be integers, or markers converted to integers.
2829usage: (logxor &rest INTS-OR-MARKERS) */) 2830usage: (logxor &rest INTS-OR-MARKERS) */)
2830 (size_t nargs, Lisp_Object *args) 2831 (ptrdiff_t nargs, Lisp_Object *args)
2831{ 2832{
2832 return arith_driver (Alogxor, nargs, args); 2833 return arith_driver (Alogxor, nargs, args);
2833} 2834}
diff --git a/src/dbusbind.c b/src/dbusbind.c
index d8d0c7c2ef0..f662d5b38a2 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -1078,7 +1078,7 @@ object is returned instead of a list containing this single Lisp object.
1078 => "i686" 1078 => "i686"
1079 1079
1080usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TIMEOUT &rest ARGS) */) 1080usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TIMEOUT &rest ARGS) */)
1081 (size_t nargs, register Lisp_Object *args) 1081 (ptrdiff_t nargs, Lisp_Object *args)
1082{ 1082{
1083 Lisp_Object bus, service, path, interface, method; 1083 Lisp_Object bus, service, path, interface, method;
1084 Lisp_Object result; 1084 Lisp_Object result;
@@ -1090,7 +1090,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
1090 DBusError derror; 1090 DBusError derror;
1091 unsigned int dtype; 1091 unsigned int dtype;
1092 int timeout = -1; 1092 int timeout = -1;
1093 size_t i = 5; 1093 ptrdiff_t i = 5;
1094 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1094 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1095 1095
1096 /* Check parameters. */ 1096 /* Check parameters. */
@@ -1143,7 +1143,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
1143 { 1143 {
1144 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1144 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1145 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1145 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1146 XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4), 1146 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
1147 SDATA (format2 ("%s", args[i], Qnil)), 1147 SDATA (format2 ("%s", args[i], Qnil)),
1148 SDATA (format2 ("%s", args[i+1], Qnil))); 1148 SDATA (format2 ("%s", args[i+1], Qnil)));
1149 ++i; 1149 ++i;
@@ -1151,7 +1151,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
1151 else 1151 else
1152 { 1152 {
1153 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1153 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1154 XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-4), 1154 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
1155 SDATA (format2 ("%s", args[i], Qnil))); 1155 SDATA (format2 ("%s", args[i], Qnil)));
1156 } 1156 }
1157 1157
@@ -1260,7 +1260,7 @@ Example:
1260 -| i686 1260 -| i686
1261 1261
1262usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLER &optional :timeout TIMEOUT &rest ARGS) */) 1262usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLER &optional :timeout TIMEOUT &rest ARGS) */)
1263 (size_t nargs, register Lisp_Object *args) 1263 (ptrdiff_t nargs, Lisp_Object *args)
1264{ 1264{
1265 Lisp_Object bus, service, path, interface, method, handler; 1265 Lisp_Object bus, service, path, interface, method, handler;
1266 Lisp_Object result; 1266 Lisp_Object result;
@@ -1271,7 +1271,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1271 unsigned int dtype; 1271 unsigned int dtype;
1272 dbus_uint32_t serial; 1272 dbus_uint32_t serial;
1273 int timeout = -1; 1273 int timeout = -1;
1274 size_t i = 6; 1274 ptrdiff_t i = 6;
1275 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1275 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1276 1276
1277 /* Check parameters. */ 1277 /* Check parameters. */
@@ -1326,7 +1326,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1326 { 1326 {
1327 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1327 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1328 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1328 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1329 XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4), 1329 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
1330 SDATA (format2 ("%s", args[i], Qnil)), 1330 SDATA (format2 ("%s", args[i], Qnil)),
1331 SDATA (format2 ("%s", args[i+1], Qnil))); 1331 SDATA (format2 ("%s", args[i+1], Qnil)));
1332 ++i; 1332 ++i;
@@ -1334,7 +1334,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1334 else 1334 else
1335 { 1335 {
1336 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1336 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1337 XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i - 4), 1337 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
1338 SDATA (format2 ("%s", args[i], Qnil))); 1338 SDATA (format2 ("%s", args[i], Qnil)));
1339 } 1339 }
1340 1340
@@ -1386,7 +1386,7 @@ DEFUN ("dbus-method-return-internal", Fdbus_method_return_internal,
1386This is an internal function, it shall not be used outside dbus.el. 1386This is an internal function, it shall not be used outside dbus.el.
1387 1387
1388usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */) 1388usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1389 (size_t nargs, register Lisp_Object *args) 1389 (ptrdiff_t nargs, Lisp_Object *args)
1390{ 1390{
1391 Lisp_Object bus, service; 1391 Lisp_Object bus, service;
1392 struct gcpro gcpro1, gcpro2; 1392 struct gcpro gcpro1, gcpro2;
@@ -1395,7 +1395,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1395 DBusMessageIter iter; 1395 DBusMessageIter iter;
1396 dbus_uint32_t serial; 1396 dbus_uint32_t serial;
1397 unsigned int ui_serial, dtype; 1397 unsigned int ui_serial, dtype;
1398 size_t i; 1398 ptrdiff_t i;
1399 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1399 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1400 1400
1401 /* Check parameters. */ 1401 /* Check parameters. */
@@ -1435,7 +1435,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1435 { 1435 {
1436 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1436 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1437 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1437 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1438 XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-2), 1438 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
1439 SDATA (format2 ("%s", args[i], Qnil)), 1439 SDATA (format2 ("%s", args[i], Qnil)),
1440 SDATA (format2 ("%s", args[i+1], Qnil))); 1440 SDATA (format2 ("%s", args[i+1], Qnil)));
1441 ++i; 1441 ++i;
@@ -1443,7 +1443,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1443 else 1443 else
1444 { 1444 {
1445 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1445 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1446 XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-2), 1446 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
1447 SDATA (format2 ("%s", args[i], Qnil))); 1447 SDATA (format2 ("%s", args[i], Qnil)));
1448 } 1448 }
1449 1449
@@ -1475,7 +1475,7 @@ DEFUN ("dbus-method-error-internal", Fdbus_method_error_internal,
1475This is an internal function, it shall not be used outside dbus.el. 1475This is an internal function, it shall not be used outside dbus.el.
1476 1476
1477usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) 1477usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1478 (size_t nargs, register Lisp_Object *args) 1478 (ptrdiff_t nargs, Lisp_Object *args)
1479{ 1479{
1480 Lisp_Object bus, service; 1480 Lisp_Object bus, service;
1481 struct gcpro gcpro1, gcpro2; 1481 struct gcpro gcpro1, gcpro2;
@@ -1484,7 +1484,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1484 DBusMessageIter iter; 1484 DBusMessageIter iter;
1485 dbus_uint32_t serial; 1485 dbus_uint32_t serial;
1486 unsigned int ui_serial, dtype; 1486 unsigned int ui_serial, dtype;
1487 size_t i; 1487 ptrdiff_t i;
1488 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1488 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1489 1489
1490 /* Check parameters. */ 1490 /* Check parameters. */
@@ -1525,7 +1525,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1525 { 1525 {
1526 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1526 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1527 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1527 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1528 XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-2), 1528 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
1529 SDATA (format2 ("%s", args[i], Qnil)), 1529 SDATA (format2 ("%s", args[i], Qnil)),
1530 SDATA (format2 ("%s", args[i+1], Qnil))); 1530 SDATA (format2 ("%s", args[i+1], Qnil)));
1531 ++i; 1531 ++i;
@@ -1533,7 +1533,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1533 else 1533 else
1534 { 1534 {
1535 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1535 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1536 XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-2), 1536 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
1537 SDATA (format2 ("%s", args[i], Qnil))); 1537 SDATA (format2 ("%s", args[i], Qnil)));
1538 } 1538 }
1539 1539
@@ -1588,7 +1588,7 @@ Example:
1588 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs") 1588 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
1589 1589
1590usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */) 1590usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1591 (size_t nargs, register Lisp_Object *args) 1591 (ptrdiff_t nargs, Lisp_Object *args)
1592{ 1592{
1593 Lisp_Object bus, service, path, interface, signal; 1593 Lisp_Object bus, service, path, interface, signal;
1594 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 1594 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
@@ -1596,7 +1596,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1596 DBusMessage *dmessage; 1596 DBusMessage *dmessage;
1597 DBusMessageIter iter; 1597 DBusMessageIter iter;
1598 unsigned int dtype; 1598 unsigned int dtype;
1599 size_t i; 1599 ptrdiff_t i;
1600 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1600 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1601 1601
1602 /* Check parameters. */ 1602 /* Check parameters. */
@@ -1640,7 +1640,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1640 { 1640 {
1641 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1641 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1642 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1642 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1643 XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4), 1643 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
1644 SDATA (format2 ("%s", args[i], Qnil)), 1644 SDATA (format2 ("%s", args[i], Qnil)),
1645 SDATA (format2 ("%s", args[i+1], Qnil))); 1645 SDATA (format2 ("%s", args[i+1], Qnil)));
1646 ++i; 1646 ++i;
@@ -1648,7 +1648,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1648 else 1648 else
1649 { 1649 {
1650 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1650 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1651 XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-4), 1651 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
1652 SDATA (format2 ("%s", args[i], Qnil))); 1652 SDATA (format2 ("%s", args[i], Qnil)));
1653 } 1653 }
1654 1654
@@ -1919,11 +1919,11 @@ Example:
1919 => :already-owner. 1919 => :already-owner.
1920 1920
1921usage: (dbus-register-service BUS SERVICE &rest FLAGS) */) 1921usage: (dbus-register-service BUS SERVICE &rest FLAGS) */)
1922 (size_t nargs, register Lisp_Object *args) 1922 (ptrdiff_t nargs, Lisp_Object *args)
1923{ 1923{
1924 Lisp_Object bus, service; 1924 Lisp_Object bus, service;
1925 DBusConnection *connection; 1925 DBusConnection *connection;
1926 size_t i; 1926 ptrdiff_t i;
1927 unsigned int value; 1927 unsigned int value;
1928 unsigned int flags = 0; 1928 unsigned int flags = 0;
1929 int result; 1929 int result;
@@ -2019,13 +2019,13 @@ INTERFACE, SIGNAL and HANDLER must not be nil. Example:
2019`dbus-unregister-object' for removing the registration. 2019`dbus-unregister-object' for removing the registration.
2020 2020
2021usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARGS) */) 2021usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARGS) */)
2022 (size_t nargs, register Lisp_Object *args) 2022 (ptrdiff_t nargs, Lisp_Object *args)
2023{ 2023{
2024 Lisp_Object bus, service, path, interface, signal, handler; 2024 Lisp_Object bus, service, path, interface, signal, handler;
2025 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 2025 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
2026 Lisp_Object uname, key, key1, value; 2026 Lisp_Object uname, key, key1, value;
2027 DBusConnection *connection; 2027 DBusConnection *connection;
2028 size_t i; 2028 ptrdiff_t i;
2029 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2029 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2030 char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2030 char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2031 DBusError derror; 2031 DBusError derror;
@@ -2095,7 +2095,7 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2095 if (!NILP (args[i])) 2095 if (!NILP (args[i]))
2096 { 2096 {
2097 CHECK_STRING (args[i]); 2097 CHECK_STRING (args[i]);
2098 sprintf (x, ",arg%lu='%s'", (unsigned long) (i-6), 2098 sprintf (x, ",arg%"pD"d='%s'", i - 6,
2099 SDATA (args[i])); 2099 SDATA (args[i]));
2100 strcat (rule, x); 2100 strcat (rule, x);
2101 } 2101 }
diff --git a/src/dired.c b/src/dired.c
index a95882060fb..3ab1ba8a900 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -978,11 +978,14 @@ so last access time will always be midnight of that day. */)
978 values[4] = make_time (s.st_atime); 978 values[4] = make_time (s.st_atime);
979 values[5] = make_time (s.st_mtime); 979 values[5] = make_time (s.st_mtime);
980 values[6] = make_time (s.st_ctime); 980 values[6] = make_time (s.st_ctime);
981 values[7] = make_fixnum_or_float (s.st_size); 981
982 /* If the size is negative, and its type is long, convert it back to 982 /* If the file size is a 4-byte type, assume that files of sizes in
983 positive. */ 983 the 2-4 GiB range wrap around to negative values, as this is a
984 if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long)) 984 common bug on older 32-bit platforms. */
985 values[7] = make_float ((double) ((unsigned long) s.st_size)); 985 if (sizeof (s.st_size) == 4)
986 values[7] = make_fixnum_or_float (s.st_size & 0xffffffffu);
987 else
988 values[7] = make_fixnum_or_float (s.st_size);
986 989
987 filemodestring (&s, modes); 990 filemodestring (&s, modes);
988 values[8] = make_string (modes, 10); 991 values[8] = make_string (modes, 10);
diff --git a/src/dispextern.h b/src/dispextern.h
index 211a1b06659..0ededf33ac6 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1729,7 +1729,7 @@ struct face_cache
1729 face doesn't exist. */ 1729 face doesn't exist. */
1730 1730
1731#define FACE_FROM_ID(F, ID) \ 1731#define FACE_FROM_ID(F, ID) \
1732 (((unsigned) (ID) < FRAME_FACE_CACHE (F)->used) \ 1732 (UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used) \
1733 ? FRAME_FACE_CACHE (F)->faces_by_id[ID] \ 1733 ? FRAME_FACE_CACHE (F)->faces_by_id[ID] \
1734 : NULL) 1734 : NULL)
1735 1735
@@ -3163,7 +3163,7 @@ int face_at_string_position (struct window *w, Lisp_Object string,
3163 EMACS_INT pos, EMACS_INT bufpos, 3163 EMACS_INT pos, EMACS_INT bufpos,
3164 EMACS_INT region_beg, EMACS_INT region_end, 3164 EMACS_INT region_beg, EMACS_INT region_end,
3165 EMACS_INT *endptr, enum face_id, int mouse); 3165 EMACS_INT *endptr, enum face_id, int mouse);
3166int merge_faces (struct frame *, Lisp_Object, int, int); 3166int merge_faces (struct frame *, Lisp_Object, EMACS_INT, int);
3167int compute_char_face (struct frame *, int, Lisp_Object); 3167int compute_char_face (struct frame *, int, Lisp_Object);
3168void free_all_realized_faces (Lisp_Object); 3168void free_all_realized_faces (Lisp_Object);
3169extern Lisp_Object Qforeground_color, Qbackground_color; 3169extern Lisp_Object Qforeground_color, Qbackground_color;
diff --git a/src/doc.c b/src/doc.c
index 89a7d322966..48e0936510b 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -253,9 +253,12 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
253 else if (c == '_') 253 else if (c == '_')
254 *to++ = 037; 254 *to++ = 037;
255 else 255 else
256 error ("\ 256 {
257 unsigned char uc = c;
258 error ("\
257Invalid data in documentation file -- %c followed by code %03o", 259Invalid data in documentation file -- %c followed by code %03o",
258 1, (unsigned)c); 260 1, uc);
261 }
259 } 262 }
260 else 263 else
261 *to++ = *from++; 264 *to++ = *from++;
diff --git a/src/doprnt.c b/src/doprnt.c
index 5ca3ea89be6..195598c07ea 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -118,10 +118,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
118 another macro. */ 118 another macro. */
119#include "character.h" 119#include "character.h"
120 120
121#ifndef SIZE_MAX
122# define SIZE_MAX ((size_t) -1)
123#endif
124
125#ifndef DBL_MAX_10_EXP 121#ifndef DBL_MAX_10_EXP
126#define DBL_MAX_10_EXP 308 /* IEEE double */ 122#define DBL_MAX_10_EXP 308 /* IEEE double */
127#endif 123#endif
@@ -329,7 +325,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format,
329 minlen = atoi (&fmtcpy[1]); 325 minlen = atoi (&fmtcpy[1]);
330 string = va_arg (ap, char *); 326 string = va_arg (ap, char *);
331 tem = strlen (string); 327 tem = strlen (string);
332 if (tem > STRING_BYTES_MAX) 328 if (STRING_BYTES_BOUND < tem)
333 error ("String for %%s or %%S format is too long"); 329 error ("String for %%s or %%S format is too long");
334 width = strwidth (string, tem); 330 width = strwidth (string, tem);
335 goto doit1; 331 goto doit1;
@@ -338,7 +334,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format,
338 doit: 334 doit:
339 /* Coming here means STRING contains ASCII only. */ 335 /* Coming here means STRING contains ASCII only. */
340 tem = strlen (string); 336 tem = strlen (string);
341 if (tem > STRING_BYTES_MAX) 337 if (STRING_BYTES_BOUND < tem)
342 error ("Format width or precision too large"); 338 error ("Format width or precision too large");
343 width = tem; 339 width = tem;
344 doit1: 340 doit1:
diff --git a/src/editfns.c b/src/editfns.c
index b4ce9a1c571..9678d4da6a2 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -96,7 +96,7 @@ static void general_insert_function (void (*) (const char *, EMACS_INT),
96 void (*) (Lisp_Object, EMACS_INT, 96 void (*) (Lisp_Object, EMACS_INT,
97 EMACS_INT, EMACS_INT, 97 EMACS_INT, EMACS_INT,
98 EMACS_INT, int), 98 EMACS_INT, int),
99 int, size_t, Lisp_Object *); 99 int, ptrdiff_t, Lisp_Object *);
100static Lisp_Object subst_char_in_region_unwind (Lisp_Object); 100static Lisp_Object subst_char_in_region_unwind (Lisp_Object);
101static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object); 101static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object);
102static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, 102static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT,
@@ -185,12 +185,13 @@ DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
185usage: (char-to-string CHAR) */) 185usage: (char-to-string CHAR) */)
186 (Lisp_Object character) 186 (Lisp_Object character)
187{ 187{
188 int len; 188 int c, len;
189 unsigned char str[MAX_MULTIBYTE_LENGTH]; 189 unsigned char str[MAX_MULTIBYTE_LENGTH];
190 190
191 CHECK_CHARACTER (character); 191 CHECK_CHARACTER (character);
192 c = XFASTINT (character);
192 193
193 len = CHAR_STRING (XFASTINT (character), str); 194 len = CHAR_STRING (c, str);
194 return make_string_from_bytes ((char *) str, 1, len); 195 return make_string_from_bytes ((char *) str, 1, len);
195} 196}
196 197
@@ -1857,7 +1858,7 @@ Years before 1970 are not guaranteed to work. On some systems,
1857year values as low as 1901 do work. 1858year values as low as 1901 do work.
1858 1859
1859usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */) 1860usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1860 (size_t nargs, register Lisp_Object *args) 1861 (ptrdiff_t nargs, Lisp_Object *args)
1861{ 1862{
1862 time_t value; 1863 time_t value;
1863 struct tm tm; 1864 struct tm tm;
@@ -2193,9 +2194,9 @@ general_insert_function (void (*insert_func)
2193 void (*insert_from_string_func) 2194 void (*insert_from_string_func)
2194 (Lisp_Object, EMACS_INT, EMACS_INT, 2195 (Lisp_Object, EMACS_INT, EMACS_INT,
2195 EMACS_INT, EMACS_INT, int), 2196 EMACS_INT, EMACS_INT, int),
2196 int inherit, size_t nargs, Lisp_Object *args) 2197 int inherit, ptrdiff_t nargs, Lisp_Object *args)
2197{ 2198{
2198 register size_t argnum; 2199 ptrdiff_t argnum;
2199 register Lisp_Object val; 2200 register Lisp_Object val;
2200 2201
2201 for (argnum = 0; argnum < nargs; argnum++) 2202 for (argnum = 0; argnum < nargs; argnum++)
@@ -2203,16 +2204,15 @@ general_insert_function (void (*insert_func)
2203 val = args[argnum]; 2204 val = args[argnum];
2204 if (CHARACTERP (val)) 2205 if (CHARACTERP (val))
2205 { 2206 {
2207 int c = XFASTINT (val);
2206 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2208 unsigned char str[MAX_MULTIBYTE_LENGTH];
2207 int len; 2209 int len;
2208 2210
2209 if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 2211 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
2210 len = CHAR_STRING (XFASTINT (val), str); 2212 len = CHAR_STRING (c, str);
2211 else 2213 else
2212 { 2214 {
2213 str[0] = (ASCII_CHAR_P (XINT (val)) 2215 str[0] = ASCII_CHAR_P (c) ? c : multibyte_char_to_unibyte (c);
2214 ? XINT (val)
2215 : multibyte_char_to_unibyte (XINT (val)));
2216 len = 1; 2216 len = 1;
2217 } 2217 }
2218 (*insert_func) ((char *) str, len); 2218 (*insert_func) ((char *) str, len);
@@ -2258,7 +2258,7 @@ buffer; to accomplish this, apply `string-as-multibyte' to the string
2258and insert the result. 2258and insert the result.
2259 2259
2260usage: (insert &rest ARGS) */) 2260usage: (insert &rest ARGS) */)
2261 (size_t nargs, register Lisp_Object *args) 2261 (ptrdiff_t nargs, Lisp_Object *args)
2262{ 2262{
2263 general_insert_function (insert, insert_from_string, 0, nargs, args); 2263 general_insert_function (insert, insert_from_string, 0, nargs, args);
2264 return Qnil; 2264 return Qnil;
@@ -2277,7 +2277,7 @@ If the current buffer is unibyte, multibyte strings are converted
2277to unibyte for insertion. 2277to unibyte for insertion.
2278 2278
2279usage: (insert-and-inherit &rest ARGS) */) 2279usage: (insert-and-inherit &rest ARGS) */)
2280 (size_t nargs, register Lisp_Object *args) 2280 (ptrdiff_t nargs, Lisp_Object *args)
2281{ 2281{
2282 general_insert_function (insert_and_inherit, insert_from_string, 1, 2282 general_insert_function (insert_and_inherit, insert_from_string, 1,
2283 nargs, args); 2283 nargs, args);
@@ -2294,7 +2294,7 @@ If the current buffer is unibyte, multibyte strings are converted
2294to unibyte for insertion. 2294to unibyte for insertion.
2295 2295
2296usage: (insert-before-markers &rest ARGS) */) 2296usage: (insert-before-markers &rest ARGS) */)
2297 (size_t nargs, register Lisp_Object *args) 2297 (ptrdiff_t nargs, Lisp_Object *args)
2298{ 2298{
2299 general_insert_function (insert_before_markers, 2299 general_insert_function (insert_before_markers,
2300 insert_from_string_before_markers, 0, 2300 insert_from_string_before_markers, 0,
@@ -2313,7 +2313,7 @@ If the current buffer is unibyte, multibyte strings are converted
2313to unibyte for insertion. 2313to unibyte for insertion.
2314 2314
2315usage: (insert-before-markers-and-inherit &rest ARGS) */) 2315usage: (insert-before-markers-and-inherit &rest ARGS) */)
2316 (size_t nargs, register Lisp_Object *args) 2316 (ptrdiff_t nargs, Lisp_Object *args)
2317{ 2317{
2318 general_insert_function (insert_before_markers_and_inherit, 2318 general_insert_function (insert_before_markers_and_inherit,
2319 insert_from_string_before_markers, 1, 2319 insert_from_string_before_markers, 1,
@@ -2332,16 +2332,17 @@ from adjoining text, if those properties are sticky. */)
2332 register EMACS_INT stringlen; 2332 register EMACS_INT stringlen;
2333 register int i; 2333 register int i;
2334 register EMACS_INT n; 2334 register EMACS_INT n;
2335 int len; 2335 int c, len;
2336 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2336 unsigned char str[MAX_MULTIBYTE_LENGTH];
2337 2337
2338 CHECK_NUMBER (character); 2338 CHECK_CHARACTER (character);
2339 CHECK_NUMBER (count); 2339 CHECK_NUMBER (count);
2340 c = XFASTINT (character);
2340 2341
2341 if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 2342 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
2342 len = CHAR_STRING (XFASTINT (character), str); 2343 len = CHAR_STRING (c, str);
2343 else 2344 else
2344 str[0] = XFASTINT (character), len = 1; 2345 str[0] = c, len = 1;
2345 if (BUF_BYTES_MAX / len < XINT (count)) 2346 if (BUF_BYTES_MAX / len < XINT (count))
2346 error ("Maximum buffer size would be exceeded"); 2347 error ("Maximum buffer size would be exceeded");
2347 n = XINT (count) * len; 2348 n = XINT (count) * len;
@@ -2784,17 +2785,20 @@ Both characters must have the same length of multi-byte form. */)
2784 int maybe_byte_combining = COMBINING_NO; 2785 int maybe_byte_combining = COMBINING_NO;
2785 EMACS_INT last_changed = 0; 2786 EMACS_INT last_changed = 0;
2786 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2787 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2788 int fromc, toc;
2787 2789
2788 restart: 2790 restart:
2789 2791
2790 validate_region (&start, &end); 2792 validate_region (&start, &end);
2791 CHECK_NUMBER (fromchar); 2793 CHECK_CHARACTER (fromchar);
2792 CHECK_NUMBER (tochar); 2794 CHECK_CHARACTER (tochar);
2795 fromc = XFASTINT (fromchar);
2796 toc = XFASTINT (tochar);
2793 2797
2794 if (multibyte_p) 2798 if (multibyte_p)
2795 { 2799 {
2796 len = CHAR_STRING (XFASTINT (fromchar), fromstr); 2800 len = CHAR_STRING (fromc, fromstr);
2797 if (CHAR_STRING (XFASTINT (tochar), tostr) != len) 2801 if (CHAR_STRING (toc, tostr) != len)
2798 error ("Characters in `subst-char-in-region' have different byte-lengths"); 2802 error ("Characters in `subst-char-in-region' have different byte-lengths");
2799 if (!ASCII_BYTE_P (*tostr)) 2803 if (!ASCII_BYTE_P (*tostr))
2800 { 2804 {
@@ -2811,8 +2815,8 @@ Both characters must have the same length of multi-byte form. */)
2811 else 2815 else
2812 { 2816 {
2813 len = 1; 2817 len = 1;
2814 fromstr[0] = XFASTINT (fromchar); 2818 fromstr[0] = fromc;
2815 tostr[0] = XFASTINT (tochar); 2819 tostr[0] = toc;
2816 } 2820 }
2817 2821
2818 pos = XINT (start); 2822 pos = XINT (start);
@@ -3084,14 +3088,11 @@ It returns the number of characters changed. */)
3084 } 3088 }
3085 else 3089 else
3086 { 3090 {
3087 EMACS_INT c;
3088
3089 nc = oc; 3091 nc = oc;
3090 val = CHAR_TABLE_REF (table, oc); 3092 val = CHAR_TABLE_REF (table, oc);
3091 if (CHARACTERP (val) 3093 if (CHARACTERP (val))
3092 && (c = XINT (val), CHAR_VALID_P (c, 0)))
3093 { 3094 {
3094 nc = c; 3095 nc = XFASTINT (val);
3095 str_len = CHAR_STRING (nc, buf); 3096 str_len = CHAR_STRING (nc, buf);
3096 str = buf; 3097 str = buf;
3097 } 3098 }
@@ -3385,7 +3386,7 @@ any existing message; this lets the minibuffer contents show. See
3385also `current-message'. 3386also `current-message'.
3386 3387
3387usage: (message FORMAT-STRING &rest ARGS) */) 3388usage: (message FORMAT-STRING &rest ARGS) */)
3388 (size_t nargs, Lisp_Object *args) 3389 (ptrdiff_t nargs, Lisp_Object *args)
3389{ 3390{
3390 if (NILP (args[0]) 3391 if (NILP (args[0])
3391 || (STRINGP (args[0]) 3392 || (STRINGP (args[0])
@@ -3413,7 +3414,7 @@ If the first argument is nil or the empty string, clear any existing
3413message; let the minibuffer contents show. 3414message; let the minibuffer contents show.
3414 3415
3415usage: (message-box FORMAT-STRING &rest ARGS) */) 3416usage: (message-box FORMAT-STRING &rest ARGS) */)
3416 (size_t nargs, Lisp_Object *args) 3417 (ptrdiff_t nargs, Lisp_Object *args)
3417{ 3418{
3418 if (NILP (args[0])) 3419 if (NILP (args[0]))
3419 { 3420 {
@@ -3470,7 +3471,7 @@ If the first argument is nil or the empty string, clear any existing
3470message; let the minibuffer contents show. 3471message; let the minibuffer contents show.
3471 3472
3472usage: (message-or-box FORMAT-STRING &rest ARGS) */) 3473usage: (message-or-box FORMAT-STRING &rest ARGS) */)
3473 (size_t nargs, Lisp_Object *args) 3474 (ptrdiff_t nargs, Lisp_Object *args)
3474{ 3475{
3475#ifdef HAVE_MENUS 3476#ifdef HAVE_MENUS
3476 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 3477 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
@@ -3494,11 +3495,11 @@ First argument is the string to copy.
3494Remaining arguments form a sequence of PROPERTY VALUE pairs for text 3495Remaining arguments form a sequence of PROPERTY VALUE pairs for text
3495properties to add to the result. 3496properties to add to the result.
3496usage: (propertize STRING &rest PROPERTIES) */) 3497usage: (propertize STRING &rest PROPERTIES) */)
3497 (size_t nargs, Lisp_Object *args) 3498 (ptrdiff_t nargs, Lisp_Object *args)
3498{ 3499{
3499 Lisp_Object properties, string; 3500 Lisp_Object properties, string;
3500 struct gcpro gcpro1, gcpro2; 3501 struct gcpro gcpro1, gcpro2;
3501 size_t i; 3502 ptrdiff_t i;
3502 3503
3503 /* Number of args must be odd. */ 3504 /* Number of args must be odd. */
3504 if ((nargs & 1) == 0) 3505 if ((nargs & 1) == 0)
@@ -3583,13 +3584,13 @@ decimal point itself is omitted. For %s and %S, the precision
3583specifier truncates the string to the given width. 3584specifier truncates the string to the given width.
3584 3585
3585usage: (format STRING &rest OBJECTS) */) 3586usage: (format STRING &rest OBJECTS) */)
3586 (size_t nargs, register Lisp_Object *args) 3587 (ptrdiff_t nargs, Lisp_Object *args)
3587{ 3588{
3588 EMACS_INT n; /* The number of the next arg to substitute */ 3589 ptrdiff_t n; /* The number of the next arg to substitute */
3589 char initial_buffer[4000]; 3590 char initial_buffer[4000];
3590 char *buf = initial_buffer; 3591 char *buf = initial_buffer;
3591 EMACS_INT bufsize = sizeof initial_buffer; 3592 EMACS_INT bufsize = sizeof initial_buffer;
3592 EMACS_INT max_bufsize = STRING_BYTES_MAX + 1; 3593 EMACS_INT max_bufsize = STRING_BYTES_BOUND + 1;
3593 char *p; 3594 char *p;
3594 Lisp_Object buf_save_value IF_LINT (= {0}); 3595 Lisp_Object buf_save_value IF_LINT (= {0});
3595 register char *format, *end, *format_start; 3596 register char *format, *end, *format_start;
@@ -3634,7 +3635,7 @@ usage: (format STRING &rest OBJECTS) */)
3634 3635
3635 /* Allocate the info and discarded tables. */ 3636 /* Allocate the info and discarded tables. */
3636 { 3637 {
3637 EMACS_INT i; 3638 ptrdiff_t i;
3638 if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs) 3639 if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs)
3639 memory_full (SIZE_MAX); 3640 memory_full (SIZE_MAX);
3640 SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen); 3641 SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen);
@@ -3673,7 +3674,7 @@ usage: (format STRING &rest OBJECTS) */)
3673 while (format != end) 3674 while (format != end)
3674 { 3675 {
3675 /* The values of N and FORMAT when the loop body is entered. */ 3676 /* The values of N and FORMAT when the loop body is entered. */
3676 EMACS_INT n0 = n; 3677 ptrdiff_t n0 = n;
3677 char *format0 = format; 3678 char *format0 = format;
3678 3679
3679 /* Bytes needed to represent the output of this conversion. */ 3680 /* Bytes needed to represent the output of this conversion. */
diff --git a/src/eval.c b/src/eval.c
index d6f9a9ede81..be582775fea 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -32,10 +32,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#include "xterm.h" 32#include "xterm.h"
33#endif 33#endif
34 34
35#ifndef SIZE_MAX
36# define SIZE_MAX ((size_t) -1)
37#endif
38
39/* This definition is duplicated in alloc.c and keyboard.c. */ 35/* This definition is duplicated in alloc.c and keyboard.c. */
40/* Putting it in lisp.h makes cc bomb out! */ 36/* Putting it in lisp.h makes cc bomb out! */
41 37
@@ -139,7 +135,7 @@ Lisp_Object Vsignaling_function;
139 135
140int handling_signal; 136int handling_signal;
141 137
142static Lisp_Object funcall_lambda (Lisp_Object, size_t, Lisp_Object *); 138static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
143static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; 139static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
144static int interactive_p (int); 140static int interactive_p (int);
145static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); 141static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
@@ -1053,7 +1049,7 @@ usage: (let VARLIST BODY...) */)
1053 Lisp_Object *temps, tem, lexenv; 1049 Lisp_Object *temps, tem, lexenv;
1054 register Lisp_Object elt, varlist; 1050 register Lisp_Object elt, varlist;
1055 int count = SPECPDL_INDEX (); 1051 int count = SPECPDL_INDEX ();
1056 register size_t argnum; 1052 ptrdiff_t argnum;
1057 struct gcpro gcpro1, gcpro2; 1053 struct gcpro gcpro1, gcpro2;
1058 USE_SAFE_ALLOCA; 1054 USE_SAFE_ALLOCA;
1059 1055
@@ -1609,8 +1605,8 @@ internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1609 and ARGS as second argument. */ 1605 and ARGS as second argument. */
1610 1606
1611Lisp_Object 1607Lisp_Object
1612internal_condition_case_n (Lisp_Object (*bfun) (size_t, Lisp_Object *), 1608internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1613 size_t nargs, 1609 ptrdiff_t nargs,
1614 Lisp_Object *args, 1610 Lisp_Object *args,
1615 Lisp_Object handlers, 1611 Lisp_Object handlers,
1616 Lisp_Object (*hfun) (Lisp_Object)) 1612 Lisp_Object (*hfun) (Lisp_Object))
@@ -1995,7 +1991,7 @@ verror (const char *m, va_list ap)
1995{ 1991{
1996 char buf[4000]; 1992 char buf[4000];
1997 size_t size = sizeof buf; 1993 size_t size = sizeof buf;
1998 size_t size_max = STRING_BYTES_MAX + 1; 1994 size_t size_max = STRING_BYTES_BOUND + 1;
1999 size_t mlen = strlen (m); 1995 size_t mlen = strlen (m);
2000 char *buffer = buf; 1996 char *buffer = buf;
2001 size_t used; 1997 size_t used;
@@ -2337,7 +2333,7 @@ eval_sub (Lisp_Object form)
2337 { 2333 {
2338 /* Pass a vector of evaluated arguments. */ 2334 /* Pass a vector of evaluated arguments. */
2339 Lisp_Object *vals; 2335 Lisp_Object *vals;
2340 register size_t argnum = 0; 2336 ptrdiff_t argnum = 0;
2341 USE_SAFE_ALLOCA; 2337 USE_SAFE_ALLOCA;
2342 2338
2343 SAFE_ALLOCA_LISP (vals, XINT (numargs)); 2339 SAFE_ALLOCA_LISP (vals, XINT (numargs));
@@ -2467,9 +2463,9 @@ DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2467Then return the value FUNCTION returns. 2463Then return the value FUNCTION returns.
2468Thus, (apply '+ 1 2 '(3 4)) returns 10. 2464Thus, (apply '+ 1 2 '(3 4)) returns 10.
2469usage: (apply FUNCTION &rest ARGUMENTS) */) 2465usage: (apply FUNCTION &rest ARGUMENTS) */)
2470 (size_t nargs, Lisp_Object *args) 2466 (ptrdiff_t nargs, Lisp_Object *args)
2471{ 2467{
2472 register size_t i, numargs; 2468 ptrdiff_t i, numargs;
2473 register Lisp_Object spread_arg; 2469 register Lisp_Object spread_arg;
2474 register Lisp_Object *funcall_args; 2470 register Lisp_Object *funcall_args;
2475 Lisp_Object fun, retval; 2471 Lisp_Object fun, retval;
@@ -2551,7 +2547,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2551/* Run hook variables in various ways. */ 2547/* Run hook variables in various ways. */
2552 2548
2553static Lisp_Object 2549static Lisp_Object
2554funcall_nil (size_t nargs, Lisp_Object *args) 2550funcall_nil (ptrdiff_t nargs, Lisp_Object *args)
2555{ 2551{
2556 Ffuncall (nargs, args); 2552 Ffuncall (nargs, args);
2557 return Qnil; 2553 return Qnil;
@@ -2572,10 +2568,10 @@ hook; they should use `run-mode-hooks' instead.
2572Do not use `make-local-variable' to make a hook variable buffer-local. 2568Do not use `make-local-variable' to make a hook variable buffer-local.
2573Instead, use `add-hook' and specify t for the LOCAL argument. 2569Instead, use `add-hook' and specify t for the LOCAL argument.
2574usage: (run-hooks &rest HOOKS) */) 2570usage: (run-hooks &rest HOOKS) */)
2575 (size_t nargs, Lisp_Object *args) 2571 (ptrdiff_t nargs, Lisp_Object *args)
2576{ 2572{
2577 Lisp_Object hook[1]; 2573 Lisp_Object hook[1];
2578 register size_t i; 2574 ptrdiff_t i;
2579 2575
2580 for (i = 0; i < nargs; i++) 2576 for (i = 0; i < nargs; i++)
2581 { 2577 {
@@ -2601,7 +2597,7 @@ as that may change.
2601Do not use `make-local-variable' to make a hook variable buffer-local. 2597Do not use `make-local-variable' to make a hook variable buffer-local.
2602Instead, use `add-hook' and specify t for the LOCAL argument. 2598Instead, use `add-hook' and specify t for the LOCAL argument.
2603usage: (run-hook-with-args HOOK &rest ARGS) */) 2599usage: (run-hook-with-args HOOK &rest ARGS) */)
2604 (size_t nargs, Lisp_Object *args) 2600 (ptrdiff_t nargs, Lisp_Object *args)
2605{ 2601{
2606 return run_hook_with_args (nargs, args, funcall_nil); 2602 return run_hook_with_args (nargs, args, funcall_nil);
2607} 2603}
@@ -2621,13 +2617,13 @@ However, if they all return nil, we return nil.
2621Do not use `make-local-variable' to make a hook variable buffer-local. 2617Do not use `make-local-variable' to make a hook variable buffer-local.
2622Instead, use `add-hook' and specify t for the LOCAL argument. 2618Instead, use `add-hook' and specify t for the LOCAL argument.
2623usage: (run-hook-with-args-until-success HOOK &rest ARGS) */) 2619usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2624 (size_t nargs, Lisp_Object *args) 2620 (ptrdiff_t nargs, Lisp_Object *args)
2625{ 2621{
2626 return run_hook_with_args (nargs, args, Ffuncall); 2622 return run_hook_with_args (nargs, args, Ffuncall);
2627} 2623}
2628 2624
2629static Lisp_Object 2625static Lisp_Object
2630funcall_not (size_t nargs, Lisp_Object *args) 2626funcall_not (ptrdiff_t nargs, Lisp_Object *args)
2631{ 2627{
2632 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil; 2628 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil;
2633} 2629}
@@ -2646,13 +2642,13 @@ Then we return nil. However, if they all return non-nil, we return non-nil.
2646Do not use `make-local-variable' to make a hook variable buffer-local. 2642Do not use `make-local-variable' to make a hook variable buffer-local.
2647Instead, use `add-hook' and specify t for the LOCAL argument. 2643Instead, use `add-hook' and specify t for the LOCAL argument.
2648usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */) 2644usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2649 (size_t nargs, Lisp_Object *args) 2645 (ptrdiff_t nargs, Lisp_Object *args)
2650{ 2646{
2651 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil; 2647 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil;
2652} 2648}
2653 2649
2654static Lisp_Object 2650static Lisp_Object
2655run_hook_wrapped_funcall (size_t nargs, Lisp_Object *args) 2651run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
2656{ 2652{
2657 Lisp_Object tmp = args[0], ret; 2653 Lisp_Object tmp = args[0], ret;
2658 args[0] = args[1]; 2654 args[0] = args[1];
@@ -2670,7 +2666,7 @@ it calls WRAP-FUNCTION with arguments FUN and ARGS.
2670As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped' 2666As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2671aborts and returns that value. 2667aborts and returns that value.
2672usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */) 2668usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2673 (size_t nargs, Lisp_Object *args) 2669 (ptrdiff_t nargs, Lisp_Object *args)
2674{ 2670{
2675 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall); 2671 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall);
2676} 2672}
@@ -2683,8 +2679,8 @@ usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2683 except that it isn't necessary to gcpro ARGS[0]. */ 2679 except that it isn't necessary to gcpro ARGS[0]. */
2684 2680
2685Lisp_Object 2681Lisp_Object
2686run_hook_with_args (size_t nargs, Lisp_Object *args, 2682run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2687 Lisp_Object (*funcall) (size_t nargs, Lisp_Object *args)) 2683 Lisp_Object (*funcall) (ptrdiff_t nargs, Lisp_Object *args))
2688{ 2684{
2689 Lisp_Object sym, val, ret = Qnil; 2685 Lisp_Object sym, val, ret = Qnil;
2690 struct gcpro gcpro1, gcpro2, gcpro3; 2686 struct gcpro gcpro1, gcpro2, gcpro3;
@@ -2957,16 +2953,16 @@ DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2957Return the value that function returns. 2953Return the value that function returns.
2958Thus, (funcall 'cons 'x 'y) returns (x . y). 2954Thus, (funcall 'cons 'x 'y) returns (x . y).
2959usage: (funcall FUNCTION &rest ARGUMENTS) */) 2955usage: (funcall FUNCTION &rest ARGUMENTS) */)
2960 (size_t nargs, Lisp_Object *args) 2956 (ptrdiff_t nargs, Lisp_Object *args)
2961{ 2957{
2962 Lisp_Object fun, original_fun; 2958 Lisp_Object fun, original_fun;
2963 Lisp_Object funcar; 2959 Lisp_Object funcar;
2964 size_t numargs = nargs - 1; 2960 ptrdiff_t numargs = nargs - 1;
2965 Lisp_Object lisp_numargs; 2961 Lisp_Object lisp_numargs;
2966 Lisp_Object val; 2962 Lisp_Object val;
2967 struct backtrace backtrace; 2963 struct backtrace backtrace;
2968 register Lisp_Object *internal_args; 2964 register Lisp_Object *internal_args;
2969 register size_t i; 2965 ptrdiff_t i;
2970 2966
2971 QUIT; 2967 QUIT;
2972 if ((consing_since_gc > gc_cons_threshold 2968 if ((consing_since_gc > gc_cons_threshold
@@ -3120,14 +3116,13 @@ static Lisp_Object
3120apply_lambda (Lisp_Object fun, Lisp_Object args) 3116apply_lambda (Lisp_Object fun, Lisp_Object args)
3121{ 3117{
3122 Lisp_Object args_left; 3118 Lisp_Object args_left;
3123 size_t numargs; 3119 ptrdiff_t i, numargs;
3124 register Lisp_Object *arg_vector; 3120 register Lisp_Object *arg_vector;
3125 struct gcpro gcpro1, gcpro2, gcpro3; 3121 struct gcpro gcpro1, gcpro2, gcpro3;
3126 register size_t i;
3127 register Lisp_Object tem; 3122 register Lisp_Object tem;
3128 USE_SAFE_ALLOCA; 3123 USE_SAFE_ALLOCA;
3129 3124
3130 numargs = XINT (Flength (args)); 3125 numargs = XFASTINT (Flength (args));
3131 SAFE_ALLOCA_LISP (arg_vector, numargs); 3126 SAFE_ALLOCA_LISP (arg_vector, numargs);
3132 args_left = args; 3127 args_left = args;
3133 3128
@@ -3163,12 +3158,12 @@ apply_lambda (Lisp_Object fun, Lisp_Object args)
3163 FUN must be either a lambda-expression or a compiled-code object. */ 3158 FUN must be either a lambda-expression or a compiled-code object. */
3164 3159
3165static Lisp_Object 3160static Lisp_Object
3166funcall_lambda (Lisp_Object fun, size_t nargs, 3161funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
3167 register Lisp_Object *arg_vector) 3162 register Lisp_Object *arg_vector)
3168{ 3163{
3169 Lisp_Object val, syms_left, next, lexenv; 3164 Lisp_Object val, syms_left, next, lexenv;
3170 int count = SPECPDL_INDEX (); 3165 int count = SPECPDL_INDEX ();
3171 size_t i; 3166 ptrdiff_t i;
3172 int optional, rest; 3167 int optional, rest;
3173 3168
3174 if (CONSP (fun)) 3169 if (CONSP (fun))
@@ -3585,7 +3580,7 @@ Output stream used is value of `standard-output'. */)
3585 } 3580 }
3586 else 3581 else
3587 { 3582 {
3588 size_t i; 3583 ptrdiff_t i;
3589 for (i = 0; i < backlist->nargs; i++) 3584 for (i = 0; i < backlist->nargs; i++)
3590 { 3585 {
3591 if (i) write_string (" ", -1); 3586 if (i) write_string (" ", -1);
@@ -3645,7 +3640,7 @@ void
3645mark_backtrace (void) 3640mark_backtrace (void)
3646{ 3641{
3647 register struct backtrace *backlist; 3642 register struct backtrace *backlist;
3648 register size_t i; 3643 ptrdiff_t i;
3649 3644
3650 for (backlist = backtrace_list; backlist; backlist = backlist->next) 3645 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3651 { 3646 {
diff --git a/src/fileio.c b/src/fileio.c
index d9bc28d8c37..fd5277cbd59 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -643,7 +643,7 @@ make_temp_name (Lisp_Object prefix, int base64_p)
643 643
644 if (!make_temp_name_count_initialized_p) 644 if (!make_temp_name_count_initialized_p)
645 { 645 {
646 make_temp_name_count = (unsigned) time (NULL); 646 make_temp_name_count = time (NULL);
647 make_temp_name_count_initialized_p = 1; 647 make_temp_name_count_initialized_p = 1;
648 } 648 }
649 649
@@ -3109,6 +3109,21 @@ read_non_regular_quit (Lisp_Object ignore)
3109 return Qnil; 3109 return Qnil;
3110} 3110}
3111 3111
3112/* Reposition FD to OFFSET, based on WHENCE. This acts like lseek
3113 except that it also tests for OFFSET being out of lseek's range. */
3114static off_t
3115emacs_lseek (int fd, EMACS_INT offset, int whence)
3116{
3117 /* Use "&" rather than "&&" to suppress a bogus GCC warning; see
3118 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43772>. */
3119 if (! ((TYPE_MINIMUM (off_t) <= offset) & (offset <= TYPE_MAXIMUM (off_t))))
3120 {
3121 errno = EINVAL;
3122 return -1;
3123 }
3124 return lseek (fd, offset, whence);
3125}
3126
3112 3127
3113DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 3128DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
3114 1, 5, 0, 3129 1, 5, 0,
@@ -3317,7 +3332,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3317 nread = emacs_read (fd, read_buf, 1024); 3332 nread = emacs_read (fd, read_buf, 1024);
3318 if (nread >= 0) 3333 if (nread >= 0)
3319 { 3334 {
3320 if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) 3335 if (lseek (fd, st.st_size - (1024 * 3), SEEK_SET) < 0)
3321 report_file_error ("Setting file position", 3336 report_file_error ("Setting file position",
3322 Fcons (orig_filename, Qnil)); 3337 Fcons (orig_filename, Qnil));
3323 nread += emacs_read (fd, read_buf + nread, 1024 * 3); 3338 nread += emacs_read (fd, read_buf + nread, 1024 * 3);
@@ -3361,7 +3376,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3361 specpdl_ptr--; 3376 specpdl_ptr--;
3362 3377
3363 /* Rewind the file for the actual read done later. */ 3378 /* Rewind the file for the actual read done later. */
3364 if (lseek (fd, 0, 0) < 0) 3379 if (lseek (fd, 0, SEEK_SET) < 0)
3365 report_file_error ("Setting file position", 3380 report_file_error ("Setting file position",
3366 Fcons (orig_filename, Qnil)); 3381 Fcons (orig_filename, Qnil));
3367 } 3382 }
@@ -3428,7 +3443,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3428 3443
3429 if (XINT (beg) != 0) 3444 if (XINT (beg) != 0)
3430 { 3445 {
3431 if (lseek (fd, XINT (beg), 0) < 0) 3446 if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0)
3432 report_file_error ("Setting file position", 3447 report_file_error ("Setting file position",
3433 Fcons (orig_filename, Qnil)); 3448 Fcons (orig_filename, Qnil));
3434 } 3449 }
@@ -3500,7 +3515,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3500 break; 3515 break;
3501 /* How much can we scan in the next step? */ 3516 /* How much can we scan in the next step? */
3502 trial = min (curpos, sizeof buffer); 3517 trial = min (curpos, sizeof buffer);
3503 if (lseek (fd, curpos - trial, 0) < 0) 3518 if (emacs_lseek (fd, curpos - trial, SEEK_SET) < 0)
3504 report_file_error ("Setting file position", 3519 report_file_error ("Setting file position",
3505 Fcons (orig_filename, Qnil)); 3520 Fcons (orig_filename, Qnil));
3506 3521
@@ -3618,7 +3633,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3618 /* First read the whole file, performing code conversion into 3633 /* First read the whole file, performing code conversion into
3619 CONVERSION_BUFFER. */ 3634 CONVERSION_BUFFER. */
3620 3635
3621 if (lseek (fd, XINT (beg), 0) < 0) 3636 if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0)
3622 report_file_error ("Setting file position", 3637 report_file_error ("Setting file position",
3623 Fcons (orig_filename, Qnil)); 3638 Fcons (orig_filename, Qnil));
3624 3639
@@ -3817,7 +3832,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3817 3832
3818 if (XINT (beg) != 0 || !NILP (replace)) 3833 if (XINT (beg) != 0 || !NILP (replace))
3819 { 3834 {
3820 if (lseek (fd, XINT (beg), 0) < 0) 3835 if (emacs_lseek (fd, XINT (beg), SEEK_SET) < 0)
3821 report_file_error ("Setting file position", 3836 report_file_error ("Setting file position",
3822 Fcons (orig_filename, Qnil)); 3837 Fcons (orig_filename, Qnil));
3823 } 3838 }
@@ -4549,9 +4564,9 @@ This calls `write-region-annotate-functions' at the start, and
4549 long ret; 4564 long ret;
4550 4565
4551 if (NUMBERP (append)) 4566 if (NUMBERP (append))
4552 ret = lseek (desc, XINT (append), 1); 4567 ret = emacs_lseek (desc, XINT (append), SEEK_CUR);
4553 else 4568 else
4554 ret = lseek (desc, 0, 2); 4569 ret = lseek (desc, 0, SEEK_END);
4555 if (ret < 0) 4570 if (ret < 0)
4556 { 4571 {
4557#ifdef CLASH_DETECTION 4572#ifdef CLASH_DETECTION
diff --git a/src/floatfns.c b/src/floatfns.c
index 1232fc0afa1..b5c8b4af5c3 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -507,7 +507,7 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
507 if (y & 1) 507 if (y & 1)
508 acc *= x; 508 acc *= x;
509 x *= x; 509 x *= x;
510 y = (unsigned)y >> 1; 510 y >>= 1;
511 } 511 }
512 } 512 }
513 XSETINT (val, acc); 513 XSETINT (val, acc);
diff --git a/src/fns.c b/src/fns.c
index 7a2845741f9..a19c886e3e1 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -99,6 +99,10 @@ Other values of LIMIT are ignored. */)
99 return lispy_val; 99 return lispy_val;
100} 100}
101 101
102/* Heuristic on how many iterations of a tight loop can be safely done
103 before it's time to do a QUIT. This must be a power of 2. */
104enum { QUIT_COUNT_HEURISTIC = 1 << 16 };
105
102/* Random data-structure functions */ 106/* Random data-structure functions */
103 107
104DEFUN ("length", Flength, Slength, 1, 1, 0, 108DEFUN ("length", Flength, Slength, 1, 1, 0,
@@ -110,7 +114,6 @@ To get the number of bytes, use `string-bytes'. */)
110 (register Lisp_Object sequence) 114 (register Lisp_Object sequence)
111{ 115{
112 register Lisp_Object val; 116 register Lisp_Object val;
113 register int i;
114 117
115 if (STRINGP (sequence)) 118 if (STRINGP (sequence))
116 XSETFASTINT (val, SCHARS (sequence)); 119 XSETFASTINT (val, SCHARS (sequence));
@@ -124,19 +127,20 @@ To get the number of bytes, use `string-bytes'. */)
124 XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK); 127 XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK);
125 else if (CONSP (sequence)) 128 else if (CONSP (sequence))
126 { 129 {
127 i = 0; 130 EMACS_INT i = 0;
128 while (CONSP (sequence)) 131
132 do
129 { 133 {
130 sequence = XCDR (sequence);
131 ++i; 134 ++i;
132 135 if ((i & (QUIT_COUNT_HEURISTIC - 1)) == 0)
133 if (!CONSP (sequence)) 136 {
134 break; 137 if (MOST_POSITIVE_FIXNUM < i)
135 138 error ("List too long");
139 QUIT;
140 }
136 sequence = XCDR (sequence); 141 sequence = XCDR (sequence);
137 ++i;
138 QUIT;
139 } 142 }
143 while (CONSP (sequence));
140 144
141 CHECK_LIST_END (sequence, sequence); 145 CHECK_LIST_END (sequence, sequence);
142 146
@@ -159,22 +163,38 @@ it returns 0. If LIST is circular, it returns a finite value
159which is at least the number of distinct elements. */) 163which is at least the number of distinct elements. */)
160 (Lisp_Object list) 164 (Lisp_Object list)
161{ 165{
162 Lisp_Object tail, halftail, length; 166 Lisp_Object tail, halftail;
163 int len = 0; 167 double hilen = 0;
168 uintmax_t lolen = 1;
169
170 if (! CONSP (list))
171 return 0;
164 172
165 /* halftail is used to detect circular lists. */ 173 /* halftail is used to detect circular lists. */
166 halftail = list; 174 for (tail = halftail = list; ; )
167 for (tail = list; CONSP (tail); tail = XCDR (tail))
168 { 175 {
169 if (EQ (tail, halftail) && len != 0) 176 tail = XCDR (tail);
177 if (! CONSP (tail))
178 break;
179 if (EQ (tail, halftail))
170 break; 180 break;
171 len++; 181 lolen++;
172 if ((len & 1) == 0) 182 if ((lolen & 1) == 0)
173 halftail = XCDR (halftail); 183 {
184 halftail = XCDR (halftail);
185 if ((lolen & (QUIT_COUNT_HEURISTIC - 1)) == 0)
186 {
187 QUIT;
188 if (lolen == 0)
189 hilen += UINTMAX_MAX + 1.0;
190 }
191 }
174 } 192 }
175 193
176 XSETINT (length, len); 194 /* If the length does not fit into a fixnum, return a float.
177 return length; 195 On all known practical machines this returns an upper bound on
196 the true length. */
197 return hilen ? make_float (hilen + lolen) : make_fixnum_or_float (lolen);
178} 198}
179 199
180DEFUN ("string-bytes", Fstring_bytes, Sstring_bytes, 1, 1, 0, 200DEFUN ("string-bytes", Fstring_bytes, Sstring_bytes, 1, 1, 0,
@@ -344,7 +364,7 @@ Symbols are also allowed; their print names are used instead. */)
344 return i1 < SCHARS (s2) ? Qt : Qnil; 364 return i1 < SCHARS (s2) ? Qt : Qnil;
345} 365}
346 366
347static Lisp_Object concat (size_t nargs, Lisp_Object *args, 367static Lisp_Object concat (ptrdiff_t nargs, Lisp_Object *args,
348 enum Lisp_Type target_type, int last_special); 368 enum Lisp_Type target_type, int last_special);
349 369
350/* ARGSUSED */ 370/* ARGSUSED */
@@ -374,7 +394,7 @@ The result is a list whose elements are the elements of all the arguments.
374Each argument may be a list, vector or string. 394Each argument may be a list, vector or string.
375The last argument is not copied, just used as the tail of the new list. 395The last argument is not copied, just used as the tail of the new list.
376usage: (append &rest SEQUENCES) */) 396usage: (append &rest SEQUENCES) */)
377 (size_t nargs, Lisp_Object *args) 397 (ptrdiff_t nargs, Lisp_Object *args)
378{ 398{
379 return concat (nargs, args, Lisp_Cons, 1); 399 return concat (nargs, args, Lisp_Cons, 1);
380} 400}
@@ -384,7 +404,7 @@ DEFUN ("concat", Fconcat, Sconcat, 0, MANY, 0,
384The result is a string whose elements are the elements of all the arguments. 404The result is a string whose elements are the elements of all the arguments.
385Each argument may be a string or a list or vector of characters (integers). 405Each argument may be a string or a list or vector of characters (integers).
386usage: (concat &rest SEQUENCES) */) 406usage: (concat &rest SEQUENCES) */)
387 (size_t nargs, Lisp_Object *args) 407 (ptrdiff_t nargs, Lisp_Object *args)
388{ 408{
389 return concat (nargs, args, Lisp_String, 0); 409 return concat (nargs, args, Lisp_String, 0);
390} 410}
@@ -394,7 +414,7 @@ DEFUN ("vconcat", Fvconcat, Svconcat, 0, MANY, 0,
394The result is a vector whose elements are the elements of all the arguments. 414The result is a vector whose elements are the elements of all the arguments.
395Each argument may be a list, vector or string. 415Each argument may be a list, vector or string.
396usage: (vconcat &rest SEQUENCES) */) 416usage: (vconcat &rest SEQUENCES) */)
397 (size_t nargs, Lisp_Object *args) 417 (ptrdiff_t nargs, Lisp_Object *args)
398{ 418{
399 return concat (nargs, args, Lisp_Vectorlike, 0); 419 return concat (nargs, args, Lisp_Vectorlike, 0);
400} 420}
@@ -416,7 +436,7 @@ with the original. */)
416 if (BOOL_VECTOR_P (arg)) 436 if (BOOL_VECTOR_P (arg))
417 { 437 {
418 Lisp_Object val; 438 Lisp_Object val;
419 int size_in_chars 439 ptrdiff_t size_in_chars
420 = ((XBOOL_VECTOR (arg)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) 440 = ((XBOOL_VECTOR (arg)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
421 / BOOL_VECTOR_BITS_PER_CHAR); 441 / BOOL_VECTOR_BITS_PER_CHAR);
422 442
@@ -436,13 +456,13 @@ with the original. */)
436 a string and has text properties to be copied. */ 456 a string and has text properties to be copied. */
437struct textprop_rec 457struct textprop_rec
438{ 458{
439 int argnum; /* refer to ARGS (arguments of `concat') */ 459 ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */
440 EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ 460 EMACS_INT from; /* refer to ARGS[argnum] (argument string) */
441 EMACS_INT to; /* refer to VAL (the target string) */ 461 EMACS_INT to; /* refer to VAL (the target string) */
442}; 462};
443 463
444static Lisp_Object 464static Lisp_Object
445concat (size_t nargs, Lisp_Object *args, 465concat (ptrdiff_t nargs, Lisp_Object *args,
446 enum Lisp_Type target_type, int last_special) 466 enum Lisp_Type target_type, int last_special)
447{ 467{
448 Lisp_Object val; 468 Lisp_Object val;
@@ -452,7 +472,7 @@ concat (size_t nargs, Lisp_Object *args,
452 EMACS_INT toindex_byte = 0; 472 EMACS_INT toindex_byte = 0;
453 register EMACS_INT result_len; 473 register EMACS_INT result_len;
454 register EMACS_INT result_len_byte; 474 register EMACS_INT result_len_byte;
455 register size_t argnum; 475 ptrdiff_t argnum;
456 Lisp_Object last_tail; 476 Lisp_Object last_tail;
457 Lisp_Object prev; 477 Lisp_Object prev;
458 int some_multibyte; 478 int some_multibyte;
@@ -463,7 +483,7 @@ concat (size_t nargs, Lisp_Object *args,
463 here, and copy the text properties after the concatenation. */ 483 here, and copy the text properties after the concatenation. */
464 struct textprop_rec *textprops = NULL; 484 struct textprop_rec *textprops = NULL;
465 /* Number of elements in textprops. */ 485 /* Number of elements in textprops. */
466 int num_textprops = 0; 486 ptrdiff_t num_textprops = 0;
467 USE_SAFE_ALLOCA; 487 USE_SAFE_ALLOCA;
468 488
469 tail = Qnil; 489 tail = Qnil;
@@ -504,6 +524,7 @@ concat (size_t nargs, Lisp_Object *args,
504 as well as the number of characters. */ 524 as well as the number of characters. */
505 EMACS_INT i; 525 EMACS_INT i;
506 Lisp_Object ch; 526 Lisp_Object ch;
527 int c;
507 EMACS_INT this_len_byte; 528 EMACS_INT this_len_byte;
508 529
509 if (VECTORP (this) || COMPILEDP (this)) 530 if (VECTORP (this) || COMPILEDP (this))
@@ -511,9 +532,10 @@ concat (size_t nargs, Lisp_Object *args,
511 { 532 {
512 ch = AREF (this, i); 533 ch = AREF (this, i);
513 CHECK_CHARACTER (ch); 534 CHECK_CHARACTER (ch);
514 this_len_byte = CHAR_BYTES (XINT (ch)); 535 c = XFASTINT (ch);
536 this_len_byte = CHAR_BYTES (c);
515 result_len_byte += this_len_byte; 537 result_len_byte += this_len_byte;
516 if (! ASCII_CHAR_P (XINT (ch)) && ! CHAR_BYTE8_P (XINT (ch))) 538 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
517 some_multibyte = 1; 539 some_multibyte = 1;
518 } 540 }
519 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size > 0) 541 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size > 0)
@@ -523,9 +545,10 @@ concat (size_t nargs, Lisp_Object *args,
523 { 545 {
524 ch = XCAR (this); 546 ch = XCAR (this);
525 CHECK_CHARACTER (ch); 547 CHECK_CHARACTER (ch);
526 this_len_byte = CHAR_BYTES (XINT (ch)); 548 c = XFASTINT (ch);
549 this_len_byte = CHAR_BYTES (c);
527 result_len_byte += this_len_byte; 550 result_len_byte += this_len_byte;
528 if (! ASCII_CHAR_P (XINT (ch)) && ! CHAR_BYTE8_P (XINT (ch))) 551 if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c))
529 some_multibyte = 1; 552 some_multibyte = 1;
530 } 553 }
531 else if (STRINGP (this)) 554 else if (STRINGP (this))
@@ -631,23 +654,16 @@ concat (size_t nargs, Lisp_Object *args,
631 { 654 {
632 int c; 655 int c;
633 if (STRING_MULTIBYTE (this)) 656 if (STRING_MULTIBYTE (this))
634 { 657 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, this,
635 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, this, 658 thisindex,
636 thisindex, 659 thisindex_byte);
637 thisindex_byte);
638 XSETFASTINT (elt, c);
639 }
640 else 660 else
641 { 661 {
642 XSETFASTINT (elt, SREF (this, thisindex)); thisindex++; 662 c = SREF (this, thisindex); thisindex++;
643 if (some_multibyte 663 if (some_multibyte && !ASCII_CHAR_P (c))
644 && !ASCII_CHAR_P (XINT (elt)) 664 c = BYTE8_TO_CHAR (c);
645 && XINT (elt) < 0400)
646 {
647 c = BYTE8_TO_CHAR (XINT (elt));
648 XSETINT (elt, c);
649 }
650 } 665 }
666 XSETFASTINT (elt, c);
651 } 667 }
652 else if (BOOL_VECTOR_P (this)) 668 else if (BOOL_VECTOR_P (this))
653 { 669 {
@@ -679,12 +695,13 @@ concat (size_t nargs, Lisp_Object *args,
679 } 695 }
680 else 696 else
681 { 697 {
682 CHECK_NUMBER (elt); 698 int c;
699 CHECK_CHARACTER (elt);
700 c = XFASTINT (elt);
683 if (some_multibyte) 701 if (some_multibyte)
684 toindex_byte += CHAR_STRING (XINT (elt), 702 toindex_byte += CHAR_STRING (c, SDATA (val) + toindex_byte);
685 SDATA (val) + toindex_byte);
686 else 703 else
687 SSET (val, toindex_byte++, XINT (elt)); 704 SSET (val, toindex_byte++, c);
688 toindex++; 705 toindex++;
689 } 706 }
690 } 707 }
@@ -1269,7 +1286,7 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0,
1269 doc: /* Take cdr N times on LIST, return the result. */) 1286 doc: /* Take cdr N times on LIST, return the result. */)
1270 (Lisp_Object n, Lisp_Object list) 1287 (Lisp_Object n, Lisp_Object list)
1271{ 1288{
1272 register int i, num; 1289 EMACS_INT i, num;
1273 CHECK_NUMBER (n); 1290 CHECK_NUMBER (n);
1274 num = XINT (n); 1291 num = XINT (n);
1275 for (i = 0; i < num && !NILP (list); i++) 1292 for (i = 0; i < num && !NILP (list); i++)
@@ -1734,7 +1751,7 @@ if the first element should sort before the second. */)
1734 Lisp_Object front, back; 1751 Lisp_Object front, back;
1735 register Lisp_Object len, tem; 1752 register Lisp_Object len, tem;
1736 struct gcpro gcpro1, gcpro2; 1753 struct gcpro gcpro1, gcpro2;
1737 register int length; 1754 EMACS_INT length;
1738 1755
1739 front = list; 1756 front = list;
1740 len = Flength (list); 1757 len = Flength (list);
@@ -2220,9 +2237,9 @@ DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0,
2220 doc: /* Concatenate any number of lists by altering them. 2237 doc: /* Concatenate any number of lists by altering them.
2221Only the last argument is not altered, and need not be a list. 2238Only the last argument is not altered, and need not be a list.
2222usage: (nconc &rest LISTS) */) 2239usage: (nconc &rest LISTS) */)
2223 (size_t nargs, Lisp_Object *args) 2240 (ptrdiff_t nargs, Lisp_Object *args)
2224{ 2241{
2225 register size_t argnum; 2242 ptrdiff_t argnum;
2226 register Lisp_Object tail, tem, val; 2243 register Lisp_Object tail, tem, val;
2227 2244
2228 val = tail = Qnil; 2245 val = tail = Qnil;
@@ -2345,9 +2362,8 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2345{ 2362{
2346 Lisp_Object len; 2363 Lisp_Object len;
2347 register EMACS_INT leni; 2364 register EMACS_INT leni;
2348 int nargs; 2365 ptrdiff_t i, nargs;
2349 register Lisp_Object *args; 2366 register Lisp_Object *args;
2350 register EMACS_INT i;
2351 struct gcpro gcpro1; 2367 struct gcpro gcpro1;
2352 Lisp_Object ret; 2368 Lisp_Object ret;
2353 USE_SAFE_ALLOCA; 2369 USE_SAFE_ALLOCA;
@@ -2526,8 +2542,8 @@ advisable. */)
2526 2542
2527 while (loads-- > 0) 2543 while (loads-- > 0)
2528 { 2544 {
2529 Lisp_Object load = (NILP (use_floats) ? 2545 Lisp_Object load = (NILP (use_floats)
2530 make_number ((int) (100.0 * load_ave[loads])) 2546 ? make_number (100.0 * load_ave[loads])
2531 : make_float (load_ave[loads])); 2547 : make_float (load_ave[loads]));
2532 ret = Fcons (load, ret); 2548 ret = Fcons (load, ret);
2533 } 2549 }
@@ -2751,7 +2767,7 @@ DEFUN ("widget-apply", Fwidget_apply, Swidget_apply, 2, MANY, 0,
2751 doc: /* Apply the value of WIDGET's PROPERTY to the widget itself. 2767 doc: /* Apply the value of WIDGET's PROPERTY to the widget itself.
2752ARGS are passed as extra arguments to the function. 2768ARGS are passed as extra arguments to the function.
2753usage: (widget-apply WIDGET PROPERTY &rest ARGS) */) 2769usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
2754 (size_t nargs, Lisp_Object *args) 2770 (ptrdiff_t nargs, Lisp_Object *args)
2755{ 2771{
2756 /* This function can GC. */ 2772 /* This function can GC. */
2757 Lisp_Object newargs[3]; 2773 Lisp_Object newargs[3];
@@ -3356,7 +3372,7 @@ static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;
3356/* Function prototypes. */ 3372/* Function prototypes. */
3357 3373
3358static struct Lisp_Hash_Table *check_hash_table (Lisp_Object); 3374static struct Lisp_Hash_Table *check_hash_table (Lisp_Object);
3359static size_t get_key_arg (Lisp_Object, size_t, Lisp_Object *, char *); 3375static ptrdiff_t get_key_arg (Lisp_Object, ptrdiff_t, Lisp_Object *, char *);
3360static void maybe_resize_hash_table (struct Lisp_Hash_Table *); 3376static void maybe_resize_hash_table (struct Lisp_Hash_Table *);
3361static int sweep_weak_table (struct Lisp_Hash_Table *, int); 3377static int sweep_weak_table (struct Lisp_Hash_Table *, int);
3362 3378
@@ -3383,13 +3399,9 @@ check_hash_table (Lisp_Object obj)
3383EMACS_INT 3399EMACS_INT
3384next_almost_prime (EMACS_INT n) 3400next_almost_prime (EMACS_INT n)
3385{ 3401{
3386 if (n % 2 == 0) 3402 for (n |= 1; ; n += 2)
3387 n += 1; 3403 if (n % 3 != 0 && n % 5 != 0 && n % 7 != 0)
3388 if (n % 3 == 0) 3404 return n;
3389 n += 2;
3390 if (n % 7 == 0)
3391 n += 4;
3392 return n;
3393} 3405}
3394 3406
3395 3407
@@ -3399,10 +3411,10 @@ next_almost_prime (EMACS_INT n)
3399 0. This function is used to extract a keyword/argument pair from 3411 0. This function is used to extract a keyword/argument pair from
3400 a DEFUN parameter list. */ 3412 a DEFUN parameter list. */
3401 3413
3402static size_t 3414static ptrdiff_t
3403get_key_arg (Lisp_Object key, size_t nargs, Lisp_Object *args, char *used) 3415get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used)
3404{ 3416{
3405 size_t i; 3417 ptrdiff_t i;
3406 3418
3407 for (i = 1; i < nargs; i++) 3419 for (i = 1; i < nargs; i++)
3408 if (!used[i - 1] && EQ (args[i - 1], key)) 3420 if (!used[i - 1] && EQ (args[i - 1], key))
@@ -4300,12 +4312,12 @@ WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK
4300is nil. 4312is nil.
4301 4313
4302usage: (make-hash-table &rest KEYWORD-ARGS) */) 4314usage: (make-hash-table &rest KEYWORD-ARGS) */)
4303 (size_t nargs, Lisp_Object *args) 4315 (ptrdiff_t nargs, Lisp_Object *args)
4304{ 4316{
4305 Lisp_Object test, size, rehash_size, rehash_threshold, weak; 4317 Lisp_Object test, size, rehash_size, rehash_threshold, weak;
4306 Lisp_Object user_test, user_hash; 4318 Lisp_Object user_test, user_hash;
4307 char *used; 4319 char *used;
4308 size_t i; 4320 ptrdiff_t i;
4309 4321
4310 /* The vector `used' is used to keep track of arguments that 4322 /* The vector `used' is used to keep track of arguments that
4311 have been consumed. */ 4323 have been consumed. */
diff --git a/src/font.c b/src/font.c
index 326c9d80e44..ecb61ab6a53 100644
--- a/src/font.c
+++ b/src/font.c
@@ -3829,10 +3829,10 @@ be an OpenType font whose GPOS table of `thai' script's default
3829language system must contain `mark' feature. 3829language system must contain `mark' feature.
3830 3830
3831usage: (font-spec ARGS...) */) 3831usage: (font-spec ARGS...) */)
3832 (size_t nargs, Lisp_Object *args) 3832 (ptrdiff_t nargs, Lisp_Object *args)
3833{ 3833{
3834 Lisp_Object spec = font_make_spec (); 3834 Lisp_Object spec = font_make_spec ();
3835 size_t i; 3835 ptrdiff_t i;
3836 3836
3837 for (i = 0; i < nargs; i += 2) 3837 for (i = 0; i < nargs; i += 2)
3838 { 3838 {
diff --git a/src/fontset.c b/src/fontset.c
index fec3c56b036..3091f43d6e9 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1851,7 +1851,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1851 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, 1851 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy,
1852 pos + 100, 0, -1); 1852 pos + 100, 0, -1);
1853 } 1853 }
1854 if (! CHAR_VALID_P (c, 0)) 1854 if (! CHAR_VALID_P (c))
1855 return Qnil; 1855 return Qnil;
1856 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil); 1856 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
1857 face = FACE_FROM_ID (f, face_id); 1857 face = FACE_FROM_ID (f, face_id);
diff --git a/src/frame.c b/src/frame.c
index 34474417efa..27a31fac3e7 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2807,7 +2807,7 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2807 /* Record in these vectors all the parms specified. */ 2807 /* Record in these vectors all the parms specified. */
2808 Lisp_Object *parms; 2808 Lisp_Object *parms;
2809 Lisp_Object *values; 2809 Lisp_Object *values;
2810 size_t i, p; 2810 ptrdiff_t i, p;
2811 int left_no_change = 0, top_no_change = 0; 2811 int left_no_change = 0, top_no_change = 0;
2812 int icon_left_no_change = 0, icon_top_no_change = 0; 2812 int icon_left_no_change = 0, icon_top_no_change = 0;
2813 int size_changed = 0; 2813 int size_changed = 0;
diff --git a/src/keyboard.c b/src/keyboard.c
index 89483972a65..e7a0598e839 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -448,7 +448,7 @@ static Lisp_Object make_lispy_movement (struct frame *, Lisp_Object,
448#endif 448#endif
449static Lisp_Object modify_event_symbol (EMACS_INT, unsigned, Lisp_Object, 449static Lisp_Object modify_event_symbol (EMACS_INT, unsigned, Lisp_Object,
450 Lisp_Object, const char *const *, 450 Lisp_Object, const char *const *,
451 Lisp_Object *, unsigned); 451 Lisp_Object *, EMACS_INT);
452static Lisp_Object make_lispy_switch_frame (Lisp_Object); 452static Lisp_Object make_lispy_switch_frame (Lisp_Object);
453static int help_char_p (Lisp_Object); 453static int help_char_p (Lisp_Object);
454static void save_getcjmp (jmp_buf); 454static void save_getcjmp (jmp_buf);
@@ -1901,7 +1901,7 @@ safe_run_hooks_error (Lisp_Object error_data)
1901} 1901}
1902 1902
1903static Lisp_Object 1903static Lisp_Object
1904safe_run_hook_funcall (size_t nargs, Lisp_Object *args) 1904safe_run_hook_funcall (ptrdiff_t nargs, Lisp_Object *args)
1905{ 1905{
1906 eassert (nargs == 1); 1906 eassert (nargs == 1);
1907 if (CONSP (Vinhibit_quit)) 1907 if (CONSP (Vinhibit_quit))
@@ -2906,9 +2906,13 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
2906 goto exit; 2906 goto exit;
2907 2907
2908 if ((STRINGP (KVAR (current_kboard, Vkeyboard_translate_table)) 2908 if ((STRINGP (KVAR (current_kboard, Vkeyboard_translate_table))
2909 && SCHARS (KVAR (current_kboard, Vkeyboard_translate_table)) > (unsigned) XFASTINT (c)) 2909 && UNSIGNED_CMP (XFASTINT (c), <,
2910 SCHARS (KVAR (current_kboard,
2911 Vkeyboard_translate_table))))
2910 || (VECTORP (KVAR (current_kboard, Vkeyboard_translate_table)) 2912 || (VECTORP (KVAR (current_kboard, Vkeyboard_translate_table))
2911 && ASIZE (KVAR (current_kboard, Vkeyboard_translate_table)) > (unsigned) XFASTINT (c)) 2913 && UNSIGNED_CMP (XFASTINT (c), <,
2914 ASIZE (KVAR (current_kboard,
2915 Vkeyboard_translate_table))))
2912 || (CHAR_TABLE_P (KVAR (current_kboard, Vkeyboard_translate_table)) 2916 || (CHAR_TABLE_P (KVAR (current_kboard, Vkeyboard_translate_table))
2913 && CHARACTERP (c))) 2917 && CHARACTERP (c)))
2914 { 2918 {
@@ -2955,9 +2959,7 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
2955 save the echo area contents for it to refer to. */ 2959 save the echo area contents for it to refer to. */
2956 if (INTEGERP (c) 2960 if (INTEGERP (c)
2957 && ! NILP (Vinput_method_function) 2961 && ! NILP (Vinput_method_function)
2958 && (unsigned) XINT (c) >= ' ' 2962 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127)
2959 && (unsigned) XINT (c) != 127
2960 && (unsigned) XINT (c) < 256)
2961 { 2963 {
2962 previous_echo_area_message = Fcurrent_message (); 2964 previous_echo_area_message = Fcurrent_message ();
2963 Vinput_method_previous_message = previous_echo_area_message; 2965 Vinput_method_previous_message = previous_echo_area_message;
@@ -2982,9 +2984,7 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
2982 /* Don't run the input method within a key sequence, 2984 /* Don't run the input method within a key sequence,
2983 after the first event of the key sequence. */ 2985 after the first event of the key sequence. */
2984 && NILP (prev_event) 2986 && NILP (prev_event)
2985 && (unsigned) XINT (c) >= ' ' 2987 && ' ' <= XINT (c) && XINT (c) < 256 && XINT (c) != 127)
2986 && (unsigned) XINT (c) != 127
2987 && (unsigned) XINT (c) < 256)
2988 { 2988 {
2989 Lisp_Object keys; 2989 Lisp_Object keys;
2990 int key_count, key_count_reset; 2990 int key_count, key_count_reset;
@@ -5391,7 +5391,7 @@ make_lispy_event (struct input_event *event)
5391 Qfunction_key, 5391 Qfunction_key,
5392 KVAR (current_kboard, Vsystem_key_alist), 5392 KVAR (current_kboard, Vsystem_key_alist),
5393 0, &KVAR (current_kboard, system_key_syms), 5393 0, &KVAR (current_kboard, system_key_syms),
5394 (unsigned) -1); 5394 TYPE_MAXIMUM (EMACS_INT));
5395 } 5395 }
5396 5396
5397 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, 5397 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET,
@@ -6410,7 +6410,7 @@ reorder_modifiers (Lisp_Object symbol)
6410static Lisp_Object 6410static Lisp_Object
6411modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object symbol_kind, 6411modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object symbol_kind,
6412 Lisp_Object name_alist_or_stem, const char *const *name_table, 6412 Lisp_Object name_alist_or_stem, const char *const *name_table,
6413 Lisp_Object *symbol_table, unsigned int table_size) 6413 Lisp_Object *symbol_table, EMACS_INT table_size)
6414{ 6414{
6415 Lisp_Object value; 6415 Lisp_Object value;
6416 Lisp_Object symbol_int; 6416 Lisp_Object symbol_int;
diff --git a/src/lisp.h b/src/lisp.h
index 8aa36601dd7..83534e55433 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -60,6 +60,21 @@ extern void check_cons_list (void);
60# define EMACS_UINT unsigned EMACS_INT 60# define EMACS_UINT unsigned EMACS_INT
61#endif 61#endif
62 62
63/* Use pD to format ptrdiff_t values, which suffice for indexes into
64 buffers and strings. Emacs never allocates objects larger than
65 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
66 In C99, pD can always be "t"; configure it here for the sake of
67 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
68#if PTRDIFF_MAX == INT_MAX
69# define pD ""
70#elif PTRDIFF_MAX == LONG_MAX
71# define pD "l"
72#elif PTRDIFF_MAX == LLONG_MAX
73# define pD "ll"
74#else
75# define pD "t"
76#endif
77
63/* Extra internal type checking? */ 78/* Extra internal type checking? */
64 79
65#ifdef ENABLE_CHECKING 80#ifdef ENABLE_CHECKING
@@ -765,11 +780,19 @@ extern EMACS_INT string_bytes (struct Lisp_String *);
765 780
766#endif /* not GC_CHECK_STRING_BYTES */ 781#endif /* not GC_CHECK_STRING_BYTES */
767 782
768/* A string cannot contain more bytes than a fixnum can represent, 783/* An upper bound on the number of bytes in a Lisp string, not
769 nor can it be so long that C pointer arithmetic stops working on 784 counting the terminating null. This a tight enough bound to
770 the string plus a terminating null. */ 785 prevent integer overflow errors that would otherwise occur during
771#define STRING_BYTES_MAX \ 786 string size calculations. A string cannot contain more bytes than
772 min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1) 787 a fixnum can represent, nor can it be so long that C pointer
788 arithmetic stops working on the string plus its terminating null.
789 Although the actual size limit (see STRING_BYTES_MAX in alloc.c)
790 may be a bit smaller than STRING_BYTES_BOUND, calculating it here
791 would expose alloc.c internal details that we'd rather keep
792 private. The cast to ptrdiff_t ensures that STRING_BYTES_BOUND is
793 signed. */
794#define STRING_BYTES_BOUND \
795 min (MOST_POSITIVE_FIXNUM, (ptrdiff_t) min (SIZE_MAX, PTRDIFF_MAX) - 1)
773 796
774/* Mark STR as a unibyte string. */ 797/* Mark STR as a unibyte string. */
775#define STRING_SET_UNIBYTE(STR) \ 798#define STRING_SET_UNIBYTE(STR) \
@@ -888,8 +911,18 @@ struct Lisp_Vector
888 911
889#endif /* not __GNUC__ */ 912#endif /* not __GNUC__ */
890 913
914/* Compute A OP B, using the unsigned comparison operator OP. A and B
915 should be integer expressions. This is not the same as
916 mathemeatical comparison; for example, UNSIGNED_CMP (0, <, -1)
917 returns 1. For efficiency, prefer plain unsigned comparison if A
918 and B's sizes both fit (after integer promotion). */
919#define UNSIGNED_CMP(a, op, b) \
920 (max (sizeof ((a) + 0), sizeof ((b) + 0)) <= sizeof (unsigned) \
921 ? ((a) + (unsigned) 0) op ((b) + (unsigned) 0) \
922 : ((a) + (uintmax_t) 0) op ((b) + (uintmax_t) 0))
923
891/* Nonzero iff C is an ASCII character. */ 924/* Nonzero iff C is an ASCII character. */
892#define ASCII_CHAR_P(c) ((unsigned) (c) < 0x80) 925#define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
893 926
894/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII 927/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
895 characters. Do not check validity of CT. */ 928 characters. Do not check validity of CT. */
@@ -908,8 +941,7 @@ struct Lisp_Vector
908/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and 941/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
909 8-bit European characters. Do not check validity of CT. */ 942 8-bit European characters. Do not check validity of CT. */
910#define CHAR_TABLE_SET(CT, IDX, VAL) \ 943#define CHAR_TABLE_SET(CT, IDX, VAL) \
911 (((IDX) >= 0 && ASCII_CHAR_P (IDX) \ 944 (ASCII_CHAR_P (IDX) && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii) \
912 && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii)) \
913 ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] = VAL \ 945 ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] = VAL \
914 : char_table_set (CT, IDX, VAL)) 946 : char_table_set (CT, IDX, VAL))
915 947
@@ -1007,7 +1039,7 @@ struct Lisp_Subr
1007 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); 1039 Lisp_Object (*a7) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1008 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); 1040 Lisp_Object (*a8) (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
1009 Lisp_Object (*aUNEVALLED) (Lisp_Object args); 1041 Lisp_Object (*aUNEVALLED) (Lisp_Object args);
1010 Lisp_Object (*aMANY) (size_t, Lisp_Object *); 1042 Lisp_Object (*aMANY) (ptrdiff_t, Lisp_Object *);
1011 } function; 1043 } function;
1012 short min_args, max_args; 1044 short min_args, max_args;
1013 const char *symbol_name; 1045 const char *symbol_name;
@@ -1447,7 +1479,7 @@ struct Lisp_Save_Value
1447 area containing INTEGER potential Lisp_Objects. */ 1479 area containing INTEGER potential Lisp_Objects. */
1448 unsigned int dogc : 1; 1480 unsigned int dogc : 1;
1449 void *pointer; 1481 void *pointer;
1450 int integer; 1482 ptrdiff_t integer;
1451 }; 1483 };
1452 1484
1453 1485
@@ -1576,7 +1608,7 @@ typedef struct {
1576#define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face)) 1608#define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face))
1577 1609
1578/* Return 1 if GLYPH contains valid character code. */ 1610/* Return 1 if GLYPH contains valid character code. */
1579#define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph), 1) 1611#define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph))
1580 1612
1581 1613
1582/* Glyph Code from a display vector may either be an integer which 1614/* Glyph Code from a display vector may either be an integer which
@@ -1590,7 +1622,7 @@ typedef struct {
1590 (CONSP (gc) ? XINT (XCDR (gc)) : INTEGERP (gc) ? (XINT (gc) >> CHARACTERBITS) : DEFAULT_FACE_ID) 1622 (CONSP (gc) ? XINT (XCDR (gc)) : INTEGERP (gc) ? (XINT (gc) >> CHARACTERBITS) : DEFAULT_FACE_ID)
1591 1623
1592/* Return 1 if glyph code from display vector contains valid character code. */ 1624/* Return 1 if glyph code from display vector contains valid character code. */
1593#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc), 1) 1625#define GLYPH_CODE_CHAR_VALID_P(gc) CHAR_VALID_P (GLYPH_CODE_CHAR (gc))
1594 1626
1595#define GLYPH_CODE_P(gc) ((CONSP (gc) && INTEGERP (XCAR (gc)) && INTEGERP (XCDR (gc))) || INTEGERP (gc)) 1627#define GLYPH_CODE_P(gc) ((CONSP (gc) && INTEGERP (XCAR (gc)) && INTEGERP (XCDR (gc))) || INTEGERP (gc))
1596 1628
@@ -1864,7 +1896,7 @@ typedef struct {
1864 1896
1865/* Note that the weird token-substitution semantics of ANSI C makes 1897/* Note that the weird token-substitution semantics of ANSI C makes
1866 this work for MANY and UNEVALLED. */ 1898 this work for MANY and UNEVALLED. */
1867#define DEFUN_ARGS_MANY (size_t, Lisp_Object *) 1899#define DEFUN_ARGS_MANY (ptrdiff_t, Lisp_Object *)
1868#define DEFUN_ARGS_UNEVALLED (Lisp_Object) 1900#define DEFUN_ARGS_UNEVALLED (Lisp_Object)
1869#define DEFUN_ARGS_0 (void) 1901#define DEFUN_ARGS_0 (void)
1870#define DEFUN_ARGS_1 (Lisp_Object) 1902#define DEFUN_ARGS_1 (Lisp_Object)
@@ -2129,7 +2161,7 @@ struct gcpro
2129 volatile Lisp_Object *var; 2161 volatile Lisp_Object *var;
2130 2162
2131 /* Number of consecutive protected variables. */ 2163 /* Number of consecutive protected variables. */
2132 size_t nvars; 2164 ptrdiff_t nvars;
2133 2165
2134#ifdef DEBUG_GCPRO 2166#ifdef DEBUG_GCPRO
2135 int level; 2167 int level;
@@ -2778,7 +2810,7 @@ extern int abort_on_gc;
2778extern Lisp_Object make_float (double); 2810extern Lisp_Object make_float (double);
2779extern void display_malloc_warning (void); 2811extern void display_malloc_warning (void);
2780extern int inhibit_garbage_collection (void); 2812extern int inhibit_garbage_collection (void);
2781extern Lisp_Object make_save_value (void *, int); 2813extern Lisp_Object make_save_value (void *, ptrdiff_t);
2782extern void free_marker (Lisp_Object); 2814extern void free_marker (Lisp_Object);
2783extern void free_cons (struct Lisp_Cons *); 2815extern void free_cons (struct Lisp_Cons *);
2784extern void init_alloc_once (void); 2816extern void init_alloc_once (void);
@@ -2890,9 +2922,9 @@ EXFUN (Frun_hooks, MANY);
2890EXFUN (Frun_hook_with_args, MANY); 2922EXFUN (Frun_hook_with_args, MANY);
2891EXFUN (Frun_hook_with_args_until_failure, MANY); 2923EXFUN (Frun_hook_with_args_until_failure, MANY);
2892extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object); 2924extern void run_hook_with_args_2 (Lisp_Object, Lisp_Object, Lisp_Object);
2893extern Lisp_Object run_hook_with_args (size_t nargs, Lisp_Object *args, 2925extern Lisp_Object run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2894 Lisp_Object (*funcall) 2926 Lisp_Object (*funcall)
2895 (size_t nargs, Lisp_Object *args)); 2927 (ptrdiff_t nargs, Lisp_Object *args));
2896EXFUN (Fprogn, UNEVALLED); 2928EXFUN (Fprogn, UNEVALLED);
2897EXFUN (Finteractive_p, 0); 2929EXFUN (Finteractive_p, 0);
2898EXFUN (Fthrow, 2) NO_RETURN; 2930EXFUN (Fthrow, 2) NO_RETURN;
@@ -2924,7 +2956,7 @@ extern Lisp_Object internal_lisp_condition_case (Lisp_Object, Lisp_Object, Lisp_
2924extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object)); 2956extern Lisp_Object internal_condition_case (Lisp_Object (*) (void), Lisp_Object, Lisp_Object (*) (Lisp_Object));
2925extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object)); 2957extern Lisp_Object internal_condition_case_1 (Lisp_Object (*) (Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2926extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object)); 2958extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp_Object), Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2927extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (size_t, Lisp_Object *), size_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object)); 2959extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object));
2928extern void specbind (Lisp_Object, Lisp_Object); 2960extern void specbind (Lisp_Object, Lisp_Object);
2929extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); 2961extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
2930extern Lisp_Object unbind_to (int, Lisp_Object); 2962extern Lisp_Object unbind_to (int, Lisp_Object);
@@ -2934,7 +2966,7 @@ extern void verror (const char *, va_list)
2934extern void do_autoload (Lisp_Object, Lisp_Object); 2966extern void do_autoload (Lisp_Object, Lisp_Object);
2935extern Lisp_Object un_autoload (Lisp_Object); 2967extern Lisp_Object un_autoload (Lisp_Object);
2936extern void init_eval_once (void); 2968extern void init_eval_once (void);
2937extern Lisp_Object safe_call (size_t, Lisp_Object *); 2969extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object *);
2938extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object); 2970extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
2939extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object); 2971extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
2940extern void init_eval (void); 2972extern void init_eval (void);
@@ -3316,7 +3348,7 @@ extern void mark_byte_stack (void);
3316#endif 3348#endif
3317extern void unmark_byte_stack (void); 3349extern void unmark_byte_stack (void);
3318extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object, 3350extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
3319 Lisp_Object, int, Lisp_Object *); 3351 Lisp_Object, ptrdiff_t, Lisp_Object *);
3320 3352
3321/* Defined in macros.c */ 3353/* Defined in macros.c */
3322extern Lisp_Object Qexecute_kbd_macro; 3354extern Lisp_Object Qexecute_kbd_macro;
@@ -3671,18 +3703,19 @@ extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3671 3703
3672#define SAFE_ALLOCA_LISP(buf, nelt) \ 3704#define SAFE_ALLOCA_LISP(buf, nelt) \
3673 do { \ 3705 do { \
3674 int size_ = (nelt) * sizeof (Lisp_Object); \ 3706 if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
3675 if (size_ < MAX_ALLOCA) \ 3707 buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object)); \
3676 buf = (Lisp_Object *) alloca (size_); \ 3708 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
3677 else \
3678 { \ 3709 { \
3679 Lisp_Object arg_; \ 3710 Lisp_Object arg_; \
3680 buf = (Lisp_Object *) xmalloc (size_); \ 3711 buf = (Lisp_Object *) xmalloc ((nelt) * sizeof (Lisp_Object)); \
3681 arg_ = make_save_value (buf, nelt); \ 3712 arg_ = make_save_value (buf, nelt); \
3682 XSAVE_VALUE (arg_)->dogc = 1; \ 3713 XSAVE_VALUE (arg_)->dogc = 1; \
3683 sa_must_free = 1; \ 3714 sa_must_free = 1; \
3684 record_unwind_protect (safe_alloca_unwind, arg_); \ 3715 record_unwind_protect (safe_alloca_unwind, arg_); \
3685 } \ 3716 } \
3717 else \
3718 memory_full (SIZE_MAX); \
3686 } while (0) 3719 } while (0)
3687 3720
3688 3721
diff --git a/src/lread.c b/src/lread.c
index b22ca930ee6..b789457b223 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1203,12 +1203,15 @@ Return t if the file exists and loads successfully. */)
1203#ifdef DOS_NT 1203#ifdef DOS_NT
1204 fmode = "rb"; 1204 fmode = "rb";
1205#endif /* DOS_NT */ 1205#endif /* DOS_NT */
1206 stat (SSDATA (efound), &s1); 1206 result = stat (SSDATA (efound), &s1);
1207 SSET (efound, SBYTES (efound) - 1, 0); 1207 if (result == 0)
1208 result = stat (SSDATA (efound), &s2); 1208 {
1209 SSET (efound, SBYTES (efound) - 1, 'c'); 1209 SSET (efound, SBYTES (efound) - 1, 0);
1210 result = stat (SSDATA (efound), &s2);
1211 SSET (efound, SBYTES (efound) - 1, 'c');
1212 }
1210 1213
1211 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) 1214 if (result == 0 && s1.st_mtime < s2.st_mtime)
1212 { 1215 {
1213 /* Make the progress messages mention that source is newer. */ 1216 /* Make the progress messages mention that source is newer. */
1214 newer = 1; 1217 newer = 1;
diff --git a/src/mem-limits.h b/src/mem-limits.h
index aa3a13c1c34..86b2f44846d 100644
--- a/src/mem-limits.h
+++ b/src/mem-limits.h
@@ -33,8 +33,6 @@ extern int etext;
33# endif 33# endif
34#endif 34#endif
35 35
36typedef unsigned long SIZE;
37
38extern char *start_of_data (void); 36extern char *start_of_data (void);
39#if defined USE_LSB_TAG 37#if defined USE_LSB_TAG
40#define EXCEEDS_LISP_PTR(ptr) 0 38#define EXCEEDS_LISP_PTR(ptr) 0
diff --git a/src/print.c b/src/print.c
index 803e3a17214..d07f89702cc 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2004,7 +2004,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2004 2004
2005 case Lisp_Misc_Save_Value: 2005 case Lisp_Misc_Save_Value:
2006 strout ("#<save_value ", -1, -1, printcharfun); 2006 strout ("#<save_value ", -1, -1, printcharfun);
2007 sprintf(buf, "ptr=%p int=%d", 2007 sprintf(buf, "ptr=%p int=%"pD"d",
2008 XSAVE_VALUE (obj)->pointer, 2008 XSAVE_VALUE (obj)->pointer,
2009 XSAVE_VALUE (obj)->integer); 2009 XSAVE_VALUE (obj)->integer);
2010 strout (buf, -1, -1, printcharfun); 2010 strout (buf, -1, -1, printcharfun);
diff --git a/src/process.c b/src/process.c
index 9ff7dd198dd..5a26bf43146 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1272,11 +1272,11 @@ the command through a shell and redirect one of them using the shell
1272syntax. 1272syntax.
1273 1273
1274usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 1274usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1275 (size_t nargs, register Lisp_Object *args) 1275 (ptrdiff_t nargs, Lisp_Object *args)
1276{ 1276{
1277 Lisp_Object buffer, name, program, proc, current_dir, tem; 1277 Lisp_Object buffer, name, program, proc, current_dir, tem;
1278 register unsigned char **new_argv; 1278 register unsigned char **new_argv;
1279 register size_t i; 1279 ptrdiff_t i;
1280 int count = SPECPDL_INDEX (); 1280 int count = SPECPDL_INDEX ();
1281 1281
1282 buffer = args[1]; 1282 buffer = args[1];
@@ -2436,7 +2436,7 @@ Examples:
2436\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7) 2436\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2437 2437
2438usage: (serial-process-configure &rest ARGS) */) 2438usage: (serial-process-configure &rest ARGS) */)
2439 (size_t nargs, Lisp_Object *args) 2439 (ptrdiff_t nargs, Lisp_Object *args)
2440{ 2440{
2441 struct Lisp_Process *p; 2441 struct Lisp_Process *p;
2442 Lisp_Object contact = Qnil; 2442 Lisp_Object contact = Qnil;
@@ -2554,7 +2554,7 @@ Examples:
2554\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) 2554\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2555 2555
2556usage: (make-serial-process &rest ARGS) */) 2556usage: (make-serial-process &rest ARGS) */)
2557 (size_t nargs, Lisp_Object *args) 2557 (ptrdiff_t nargs, Lisp_Object *args)
2558{ 2558{
2559 int fd = -1; 2559 int fd = -1;
2560 Lisp_Object proc, contact, port; 2560 Lisp_Object proc, contact, port;
@@ -2832,7 +2832,7 @@ The original argument list, modified with the actual connection
2832information, is available via the `process-contact' function. 2832information, is available via the `process-contact' function.
2833 2833
2834usage: (make-network-process &rest ARGS) */) 2834usage: (make-network-process &rest ARGS) */)
2835 (size_t nargs, Lisp_Object *args) 2835 (ptrdiff_t nargs, Lisp_Object *args)
2836{ 2836{
2837 Lisp_Object proc; 2837 Lisp_Object proc;
2838 Lisp_Object contact; 2838 Lisp_Object contact;
@@ -3148,7 +3148,7 @@ usage: (make-network-process &rest ARGS) */)
3148 3148
3149 for (lres = res; lres; lres = lres->ai_next) 3149 for (lres = res; lres; lres = lres->ai_next)
3150 { 3150 {
3151 size_t optn; 3151 ptrdiff_t optn;
3152 int optbits; 3152 int optbits;
3153 3153
3154#ifdef WINDOWSNT 3154#ifdef WINDOWSNT
diff --git a/src/puresize.h b/src/puresize.h
index 8024aa95d31..c26c496a757 100644
--- a/src/puresize.h
+++ b/src/puresize.h
@@ -86,7 +86,6 @@ extern EMACS_INT pure[];
86 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure) 86 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure)
87 87
88#else /* not VIRT_ADDR_VARIES */ 88#else /* not VIRT_ADDR_VARIES */
89/* When PNTR_COMPARISON_TYPE is not the default (unsigned int). */
90 89
91extern char my_edata[]; 90extern char my_edata[];
92 91
@@ -94,4 +93,3 @@ extern char my_edata[];
94 ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) my_edata) 93 ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) my_edata)
95 94
96#endif /* VIRT_ADDRESS_VARIES */ 95#endif /* VIRT_ADDRESS_VARIES */
97
diff --git a/src/sound.c b/src/sound.c
index 794c8e64e54..0e71e66352e 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1447,7 +1447,7 @@ Internal use only, use `play-sound' instead. */)
1447 } 1447 }
1448 else if (FLOATP (attrs[SOUND_VOLUME])) 1448 else if (FLOATP (attrs[SOUND_VOLUME]))
1449 { 1449 {
1450 ui_volume_tmp = (unsigned long) XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100; 1450 ui_volume_tmp = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
1451 } 1451 }
1452 /* 1452 /*
1453 Based on some experiments I have conducted, a value of 100 or less 1453 Based on some experiments I have conducted, a value of 100 or less
diff --git a/src/unexelf.c b/src/unexelf.c
index 8b45894f853..951e7c0eea6 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -391,6 +391,7 @@ temacs:
391extern void fatal (const char *msgid, ...); 391extern void fatal (const char *msgid, ...);
392 392
393#include <sys/types.h> 393#include <sys/types.h>
394#include <stdint.h>
394#include <stdio.h> 395#include <stdio.h>
395#include <sys/stat.h> 396#include <sys/stat.h>
396#include <memory.h> 397#include <memory.h>
@@ -784,7 +785,7 @@ unexec (const char *new_name, const char *old_name)
784 fprintf (stderr, "new_data2_incr %x\n", new_data2_incr); 785 fprintf (stderr, "new_data2_incr %x\n", new_data2_incr);
785#endif 786#endif
786 787
787 if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size) 788 if ((uintptr_t) new_bss_addr < (uintptr_t) old_bss_addr + old_bss_size)
788 fatal (".bss shrank when undumping???\n", 0, 0); 789 fatal (".bss shrank when undumping???\n", 0, 0);
789 790
790 /* Set the output file to the right size. Allocate a buffer to hold 791 /* Set the output file to the right size. Allocate a buffer to hold
diff --git a/src/vm-limit.c b/src/vm-limit.c
index 4694608602f..846946b41c1 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -166,9 +166,9 @@ static void
166check_memory_limits (void) 166check_memory_limits (void)
167{ 167{
168#ifdef REL_ALLOC 168#ifdef REL_ALLOC
169 extern POINTER (*real_morecore) (SIZE); 169 extern POINTER (*real_morecore) (long);
170#endif 170#endif
171 extern POINTER (*__morecore) (SIZE); 171 extern POINTER (*__morecore) (long);
172 172
173 register POINTER cp; 173 register POINTER cp;
174 unsigned long five_percent; 174 unsigned long five_percent;
@@ -297,4 +297,3 @@ memory_warnings (POINTER start, void (*warnfun) (const char *))
297 /* Force data limit to be recalculated on each run. */ 297 /* Force data limit to be recalculated on each run. */
298 lim_data = 0; 298 lim_data = 0;
299} 299}
300
diff --git a/src/widget.c b/src/widget.c
index 7d32e30eed7..6d871ad7cb2 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -516,14 +516,11 @@ create_frame_gcs (ew)
516 struct frame *s = ew->emacs_frame.frame; 516 struct frame *s = ew->emacs_frame.frame;
517 517
518 s->output_data.x->normal_gc 518 s->output_data.x->normal_gc
519 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 519 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
520 (unsigned long)0, (XGCValues *)0);
521 s->output_data.x->reverse_gc 520 s->output_data.x->reverse_gc
522 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 521 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
523 (unsigned long)0, (XGCValues *)0);
524 s->output_data.x->cursor_gc 522 s->output_data.x->cursor_gc
525 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 523 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
526 (unsigned long)0, (XGCValues *)0);
527 s->output_data.x->black_relief.gc = 0; 524 s->output_data.x->black_relief.gc = 0;
528 s->output_data.x->white_relief.gc = 0; 525 s->output_data.x->white_relief.gc = 0;
529} 526}
@@ -582,8 +579,7 @@ setup_frame_gcs (EmacsFrame ew)
582 = XCreatePixmapFromBitmapData (XtDisplay(ew), 579 = XCreatePixmapFromBitmapData (XtDisplay(ew),
583 RootWindowOfScreen (XtScreen (ew)), 580 RootWindowOfScreen (XtScreen (ew)),
584 setup_frame_cursor_bits, 2, 2, 581 setup_frame_cursor_bits, 2, 2,
585 (unsigned long)0, (unsigned long)1, 582 0, 1, ew->core.depth);
586 ew->core.depth);
587 583
588 /* Normal video */ 584 /* Normal video */
589 gc_values.foreground = ew->emacs_frame.foreground_pixel; 585 gc_values.foreground = ew->emacs_frame.foreground_pixel;
diff --git a/src/xdisp.c b/src/xdisp.c
index 65f6ddd3889..5a0b0060fa3 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1335,7 +1335,7 @@ string_char_and_length (const unsigned char *str, int *len)
1335 int c; 1335 int c;
1336 1336
1337 c = STRING_CHAR_AND_LENGTH (str, *len); 1337 c = STRING_CHAR_AND_LENGTH (str, *len);
1338 if (!CHAR_VALID_P (c, 1)) 1338 if (!CHAR_VALID_P (c))
1339 /* We may not change the length here because other places in Emacs 1339 /* We may not change the length here because other places in Emacs
1340 don't use this function, i.e. they silently accept invalid 1340 don't use this function, i.e. they silently accept invalid
1341 characters. */ 1341 characters. */
@@ -2138,7 +2138,7 @@ safe_eval_handler (Lisp_Object arg)
2138 redisplay during the evaluation. */ 2138 redisplay during the evaluation. */
2139 2139
2140Lisp_Object 2140Lisp_Object
2141safe_call (size_t nargs, Lisp_Object *args) 2141safe_call (ptrdiff_t nargs, Lisp_Object *args)
2142{ 2142{
2143 Lisp_Object val; 2143 Lisp_Object val;
2144 2144
@@ -5819,7 +5819,8 @@ get_next_display_element (struct it *it)
5819 display. Then, set IT->dpvec to these glyphs. */ 5819 display. Then, set IT->dpvec to these glyphs. */
5820 Lisp_Object gc; 5820 Lisp_Object gc;
5821 int ctl_len; 5821 int ctl_len;
5822 int face_id, lface_id = 0 ; 5822 int face_id;
5823 EMACS_INT lface_id = 0;
5823 int escape_glyph; 5824 int escape_glyph;
5824 5825
5825 /* Handle control characters with ^. */ 5826 /* Handle control characters with ^. */
@@ -6374,7 +6375,7 @@ next_element_from_display_vector (struct it *it)
6374 it->face_id = it->dpvec_face_id; 6375 it->face_id = it->dpvec_face_id;
6375 else 6376 else
6376 { 6377 {
6377 int lface_id = GLYPH_CODE_FACE (gc); 6378 EMACS_INT lface_id = GLYPH_CODE_FACE (gc);
6378 if (lface_id > 0) 6379 if (lface_id > 0)
6379 it->face_id = merge_faces (it->f, Qt, lface_id, 6380 it->face_id = merge_faces (it->f, Qt, lface_id,
6380 it->saved_face_id); 6381 it->saved_face_id);
@@ -16570,7 +16571,7 @@ With ARG, turn tracing on if and only if ARG is positive. */)
16570DEFUN ("trace-to-stderr", Ftrace_to_stderr, Strace_to_stderr, 1, MANY, "", 16571DEFUN ("trace-to-stderr", Ftrace_to_stderr, Strace_to_stderr, 1, MANY, "",
16571 doc: /* Like `format', but print result to stderr. 16572 doc: /* Like `format', but print result to stderr.
16572usage: (trace-to-stderr STRING &rest OBJECTS) */) 16573usage: (trace-to-stderr STRING &rest OBJECTS) */)
16573 (size_t nargs, Lisp_Object *args) 16574 (ptrdiff_t nargs, Lisp_Object *args)
16574{ 16575{
16575 Lisp_Object s = Fformat (nargs, args); 16576 Lisp_Object s = Fformat (nargs, args);
16576 fprintf (stderr, "%s", SDATA (s)); 16577 fprintf (stderr, "%s", SDATA (s));
@@ -19379,7 +19380,8 @@ decode_mode_spec_coding (Lisp_Object coding_system, register char *buf, int eol_
19379 else if (CHARACTERP (eoltype)) 19380 else if (CHARACTERP (eoltype))
19380 { 19381 {
19381 unsigned char *tmp = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH); 19382 unsigned char *tmp = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH);
19382 eol_str_len = CHAR_STRING (XINT (eoltype), tmp); 19383 int c = XFASTINT (eoltype);
19384 eol_str_len = CHAR_STRING (c, tmp);
19383 eol_str = tmp; 19385 eol_str = tmp;
19384 } 19386 }
19385 else 19387 else
diff --git a/src/xfaces.c b/src/xfaces.c
index b14710245b1..a56e54c90cd 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -6223,7 +6223,8 @@ face_at_string_position (struct window *w, Lisp_Object string,
6223*/ 6223*/
6224 6224
6225int 6225int
6226merge_faces (struct frame *f, Lisp_Object face_name, int face_id, int base_face_id) 6226merge_faces (struct frame *f, Lisp_Object face_name, EMACS_INT face_id,
6227 int base_face_id)
6227{ 6228{
6228 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 6229 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6229 struct face *base_face; 6230 struct face *base_face;
diff --git a/src/xfns.c b/src/xfns.c
index 5bc0cef6154..abc273c2bdf 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1074,8 +1074,7 @@ x_set_border_pixel (struct frame *f, int pix)
1074 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0) 1074 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0)
1075 { 1075 {
1076 BLOCK_INPUT; 1076 BLOCK_INPUT;
1077 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 1077 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), pix);
1078 (unsigned long)pix);
1079 UNBLOCK_INPUT; 1078 UNBLOCK_INPUT;
1080 1079
1081 if (FRAME_VISIBLE_P (f)) 1080 if (FRAME_VISIBLE_P (f))
diff --git a/src/xterm.c b/src/xterm.c
index 9673e5e315e..f40d260dabe 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1697,16 +1697,18 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1697 a least-squares matching, which is what X uses for closest 1697 a least-squares matching, which is what X uses for closest
1698 color matching with StaticColor visuals. */ 1698 color matching with StaticColor visuals. */
1699 int nearest, i; 1699 int nearest, i;
1700 unsigned long nearest_delta = ~ (unsigned long) 0; 1700 int max_color_delta = 255;
1701 int max_delta = 3 * max_color_delta;
1702 int nearest_delta = max_delta + 1;
1701 int ncells; 1703 int ncells;
1702 const XColor *cells = x_color_cells (dpy, &ncells); 1704 const XColor *cells = x_color_cells (dpy, &ncells);
1703 1705
1704 for (nearest = i = 0; i < ncells; ++i) 1706 for (nearest = i = 0; i < ncells; ++i)
1705 { 1707 {
1706 long dred = (color->red >> 8) - (cells[i].red >> 8); 1708 int dred = (color->red >> 8) - (cells[i].red >> 8);
1707 long dgreen = (color->green >> 8) - (cells[i].green >> 8); 1709 int dgreen = (color->green >> 8) - (cells[i].green >> 8);
1708 long dblue = (color->blue >> 8) - (cells[i].blue >> 8); 1710 int dblue = (color->blue >> 8) - (cells[i].blue >> 8);
1709 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; 1711 int delta = dred * dred + dgreen * dgreen + dblue * dblue;
1710 1712
1711 if (delta < nearest_delta) 1713 if (delta < nearest_delta)
1712 { 1714 {
@@ -6442,8 +6444,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6442 keys". It seems there's no cleaner way. 6444 keys". It seems there's no cleaner way.
6443 Test IsModifierKey to avoid handling 6445 Test IsModifierKey to avoid handling
6444 mode_switch incorrectly. */ 6446 mode_switch incorrectly. */
6445 || ((unsigned) (keysym) >= XK_Select 6447 || (XK_Select <= keysym && keysym < XK_KP_Space)
6446 && (unsigned)(keysym) < XK_KP_Space)
6447#endif 6448#endif
6448#ifdef XK_dead_circumflex 6449#ifdef XK_dead_circumflex
6449 || orig_keysym == XK_dead_circumflex 6450 || orig_keysym == XK_dead_circumflex
@@ -6496,10 +6497,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6496 should be treated similarly to 6497 should be treated similarly to
6497 Mode_switch by Emacs. */ 6498 Mode_switch by Emacs. */
6498#if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock 6499#if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6499 || ((unsigned)(orig_keysym) 6500 || (XK_ISO_Lock <= orig_keysym
6500 >= XK_ISO_Lock 6501 && orig_keysym <= XK_ISO_Last_Group_Lock)
6501 && (unsigned)(orig_keysym)
6502 <= XK_ISO_Last_Group_Lock)
6503#endif 6502#endif
6504 )) 6503 ))
6505 { 6504 {
@@ -10275,7 +10274,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10275 = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, 10274 = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window,
10276 gray_bitmap_bits, 10275 gray_bitmap_bits,
10277 gray_bitmap_width, gray_bitmap_height, 10276 gray_bitmap_width, gray_bitmap_height,
10278 (unsigned long) 1, (unsigned long) 0, 1); 10277 1, 0, 1);
10279 } 10278 }
10280 10279
10281#ifdef HAVE_X_I18N 10280#ifdef HAVE_X_I18N