aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog278
-rw-r--r--src/alloc.c119
-rw-r--r--src/blockinput.h2
-rw-r--r--src/bytecode.c4
-rw-r--r--src/callproc.c8
-rw-r--r--src/ccl.c6
-rw-r--r--src/character.c6
-rw-r--r--src/charset.c2
-rw-r--r--src/cm.c4
-rw-r--r--src/coding.c4
-rw-r--r--src/data.c4
-rw-r--r--src/dired.c13
-rw-r--r--src/dispextern.h14
-rw-r--r--src/dispnew.c46
-rw-r--r--src/doc.c2
-rw-r--r--src/doprnt.c2
-rw-r--r--src/editfns.c15
-rw-r--r--src/emacs.c7
-rw-r--r--src/emacsgtkfixed.c2
-rw-r--r--src/fileio.c7
-rw-r--r--src/floatfns.c4
-rw-r--r--src/fns.c12
-rw-r--r--src/font.c17
-rw-r--r--src/frame.c27
-rw-r--r--src/frame.h58
-rw-r--r--src/ftfont.c6
-rw-r--r--src/gtkutil.c2
-rw-r--r--src/image.c20
-rw-r--r--src/indent.c2
-rw-r--r--src/intervals.c54
-rw-r--r--src/keyboard.c7
-rw-r--r--src/keymap.c5
-rw-r--r--src/lisp.h160
-rw-r--r--src/lread.c20
-rw-r--r--src/menu.c2
-rw-r--r--src/minibuf.c2
-rw-r--r--src/nsfns.m69
-rw-r--r--src/nsterm.h4
-rw-r--r--src/nsterm.m19
-rw-r--r--src/print.c90
-rw-r--r--src/process.c33
-rw-r--r--src/profiler.c4
-rw-r--r--src/regex.c6
-rw-r--r--src/regex.h2
-rw-r--r--src/search.c6
-rw-r--r--src/sysdep.c6
-rw-r--r--src/systime.h2
-rw-r--r--src/term.c2
-rw-r--r--src/unexcw.c17
-rw-r--r--src/w32.c9
-rw-r--r--src/w32fns.c23
-rw-r--r--src/w32font.c2
-rw-r--r--src/w32term.c60
-rw-r--r--src/w32term.h13
-rw-r--r--src/window.c228
-rw-r--r--src/window.h70
-rw-r--r--src/xdisp.c105
-rw-r--r--src/xfaces.c23
-rw-r--r--src/xfns.c24
-rw-r--r--src/xmenu.c4
-rw-r--r--src/xselect.c6
-rw-r--r--src/xsettings.c9
-rw-r--r--src/xsmfns.c2
-rw-r--r--src/xterm.c10
64 files changed, 1123 insertions, 668 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 288996fffb2..ce0455a4981 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,273 @@
12013-03-26 Eli Zaretskii <eliz@gnu.org>
2
3 * w32.c (_PROCESS_MEMORY_COUNTERS_EX) [_WIN32_WINNT < 0x0500]:
4 Define only for _WIN32_WINNT less than 0x0500.
5 (_ANONYMOUS_UNION, _ANONYMOUS_STRUCT) [!_W64]: Don't define for
6 MinGW64.
7 Move inclusion of time.h before sys/time.h, so that MinGW64 could
8 see its own definitions of 'struct timeval' and 'struct timezone'.
9
10 Fix incompatibilities between MinGW.org and MinGW64 headers.
11 * w32term.c (WCRANGE, GLYPHSET): Don't define if _W64 is defined.
12
13 * w32.c (REPARSE_DATA_BUFFER): Guard with
14 MAXIMUM_REPARSE_DATA_BUFFER_SIZE being defined.
15
162013-03-25 Jan Djärv <jan.h.d@swipnet.se>
17
18 * xterm.c: Include X11/XKBlib.h
19 (XTring_bell): Use XkbBell if HAVE_XKB (Bug#14041).
20
212013-03-24 Andreas Schwab <schwab@linux-m68k.org>
22
23 * alloc.c (xpalloc, Fgarbage_collect): Reorder conditions that are
24 written backwards.
25 * blockinput.h (input_blocked_p): Likewise.
26 * bytecode.c (exec_byte_code): Likewise.
27 * callproc.c (call_process_kill, call_process_cleanup)
28 (Fcall_process): Likewise.
29 * ccl.c (ccl_driver, resolve_symbol_ccl_program)
30 (Fccl_execute_on_string): Likewise.
31 * character.c (string_escape_byte8): Likewise.
32 * charset.c (read_hex): Likewise.
33 * cm.c (calccost): Likewise.
34 * data.c (cons_to_unsigned): Likewise.
35 * dired.c (directory_files_internal, file_name_completion):
36 Likewise.
37 * dispnew.c (scrolling_window, update_frame_1, Fsleep_for)
38 (sit_for): Likewise.
39 * doc.c (Fsubstitute_command_keys): Likewise.
40 * doprnt.c (doprnt): Likewise.
41 * editfns.c (hi_time, decode_time_components, Fformat): Likewise.
42 * emacsgtkfixed.c: Likewise.
43 * fileio.c (file_offset, Fwrite_region): Likewise.
44 * floatfns.c (Fexpt, fmod_float): Likewise.
45 * fns.c (larger_vector, make_hash_table, Fmake_hash_table):
46 Likewise.
47 * font.c (font_intern_prop): Likewise.
48 * frame.c (x_set_alpha): Likewise.
49 * gtkutil.c (get_utf8_string): Likewise.
50 * indent.c (check_display_width): Likewise.
51 * intervals.c (create_root_interval, rotate_right, rotate_left)
52 (split_interval_right, split_interval_left)
53 (adjust_intervals_for_insertion, delete_node)
54 (interval_deletion_adjustment, adjust_intervals_for_deletion)
55 (merge_interval_right, merge_interval_left, copy_intervals)
56 (set_intervals_multibyte_1): Likewise.
57 * keyboard.c (gobble_input, append_tool_bar_item): Likewise.
58 * keymap.c (Fkey_description): Likewise.
59 * lisp.h (FIXNUM_OVERFLOW_P, vcopy): Likewise.
60 * lread.c (openp, read_integer, read1, string_to_number):
61 Likewise.
62 * menu.c (ensure_menu_items): Likewise.
63 * minibuf.c (read_minibuf_noninteractive): Likewise.
64 * print.c (printchar, strout): Likewise.
65 * process.c (create_process, Faccept_process_output)
66 (wait_reading_process_output, read_process_output, send_process)
67 (wait_reading_process_output): Likewise.
68 * profiler.c (make_log, handle_profiler_signal): Likewise.
69 * regex.c (re_exec): Likewise.
70 * regex.h: Likewise.
71 * search.c (looking_at_1, Freplace_match): Likewise.
72 * sysdep.c (get_child_status, procfs_ttyname)
73 (procfs_get_total_memory): Likewise.
74 * systime.h (EMACS_TIME_VALID_P): Likewise.
75 * term.c (dissociate_if_controlling_tty): Likewise.
76 * window.c (get_phys_cursor_glyph): Likewise.
77 * xdisp.c (init_iterator, redisplay_internal, redisplay_window)
78 (try_window_reusing_current_matrix, try_window_id, pint2hrstr):
79 Likewise.
80 * xfns.c (Fx_window_property): Likewise.
81 * xmenu.c (set_frame_menubar): Likewise.
82 * xselect.c (x_get_window_property, x_handle_dnd_message):
83 Likewise.
84 * xsmfns.c (smc_save_yourself_CB): Likewise.
85 * xterm.c (x_scroll_bar_set_handle): Likewise.
86
872013-03-24 Dmitry Antipov <dmantipov@yandex.ru>
88
89 * xfaces.c (Finternal_face_x_get_resource): Allow 3rd (frame) argument
90 to be optional or nil. Adjust comment and convert it to docstring.
91 * xselect.c (Fx_send_client_event): Rename to Fx_send_client_message.
92 * frame.c (display_x_get_resource, Fx_get_resource): Break long line.
93
942013-03-24 Paul Eggert <eggert@cs.ucla.edu>
95
96 Static checking by GCC 4.8-20130319.
97 * image.c (gif_load): Assume pass < 3 to pacify GCC.
98 * process.c (Fset_process_datagram_address)
99 (Fmake_network_process): Check get_lisp_to_sockaddr_size return value.
100 * xdisp.c (get_char_face_and_encoding):
101 (get_glyph_face_and_encoding): Ensure that *CHAR2B is initialized.
102 (get_glyph_face_and_encoding): Prepare face before possibly using it.
103 (get_per_char_metric): Don't use CHAR2B if it might not be initialized.
104
1052013-03-24 Ken Brown <kbrown@cornell.edu>
106
107 * w32fns.c (emacs_abort) [CYGWIN]: Define `_open' as a macro to
108 fix compilation on 64-bit Cygwin, where underscores are not
109 automatically prepended.
110
111 * w32term.c (w32_initialize): Silence compiler warning.
112
1132013-03-23 Eli Zaretskii <eliz@gnu.org>
114
115 * w32term.c (w32fullscreen_hook): Use FRAME_NORMAL_WIDTH,
116 FRAME_NORMAL_HEIGHT, and FRAME_PREV_FSMODE, instead of static
117 variables, to save and restore frame dimensions. Use
118 FRAME_NORMAL_LEFT and FRAME_NORMAL_TOP to restore frame position
119 after returning from a 'fullscreen' configuration. use
120 SendMessage instead of PostMessage to send the SC_RESTORE message,
121 to avoid races between the main thread and the input thread.
122
123 * w32term.h (struct w32_output): New members normal_width,
124 normal_height, normal_top, normal_left, and prev_fsmode.
125 (FRAME_NORMAL_WIDTH, FRAME_NORMAL_HEIGHT, FRAME_NORMAL_TOP)
126 (FRAME_NORMAL_LEFT, FRAME_PREV_FSMODE): New macros to access these
127 members of a frame.
128
129 * w32term.c (w32fullscreen_hook): Record last value of the frame's
130 'fullscreen' parameter. Always record previous width and height
131 of the frame, except when switching out of maximized modes, so
132 that they could be restored correctly, instead of resetting to the
133 default frame dimensions. Send SC_RESTORE command to the frame,
134 unless we are going to send SC_MAXIMIZE, to restore the frame
135 resize hints in the mouse pointer shown by the window manager.
136 (Bug#14032)
137
138 * frame.c (get_frame_param): Now extern for WINDOWSNT as well.
139
140 * lisp.h (get_frame_param): Adjust conditions for prototype
141 declaration.
142
1432013-03-22 Ken Brown <kbrown@cornell.edu>
144
145 * unexcw.c: Drop unneeded inclusion of w32common.h.
146 (report_sheap_usage): Declare.
147 (read_exe_header): Add magic numbers for x86_64.
148 (fixup_executable): Fix printf format specifier for unsigned long
149 argument.
150
1512013-03-22 Dmitry Antipov <dmantipov@yandex.ru>
152
153 * frame.h (struct frame): Put menu_bar_window under #ifdef
154 because this member is not needed when X toolkit is in use.
155 (fset_menu_bar_window):
156 * dispnew.c (clear_current_matrices, clear_desired_matrices)
157 (free_glyphs, update_frame):
158 * xdisp.c (expose_frame): Likewise.
159 (display_menu_bar): Likewise. Remove redundant eassert.
160 * window.h (WINDOW_MENU_BAR_P): Always define to 0 if X
161 toolkit is in use.
162
1632013-03-21 Paul Eggert <eggert@cs.ucla.edu>
164
165 Use functions and constants to manipulate Lisp_Save_Value objects.
166 This replaces code that used macros and strings and token-pasting.
167 The change makes the C source a bit easier to follow,
168 and shrinks the Emacs executable a bit.
169 * alloc.c: Verify some properties of Lisp_Save_Value's representation.
170 (make_save_value): Change 1st arg from string to enum. All callers
171 changed.
172 (INTX): Remove.
173 (mark_object): Use if, not #if, for GC_MARK_STACK.
174 * lisp.h (SAVE_VALUEP, XSAVE_VALUE, XSAVE_POINTER, XSAVE_INTEGER)
175 (XSAVE_OBJECT): Now functions, not macros.
176 (STRING_BYTES_BOUND): Now just a macro, not a constant too;
177 the constant was never used.
178 (SAVE_SLOT_BITS, SAVE_VALUE_SLOTS, SAVE_TYPE_BITS, SAVE_TYPE_INT_INT)
179 (SAVE_TYPE_INT_INT_INT, SAVE_TYPE_OBJ_OBJ, SAVE_TYPE_OBJ_OBJ_OBJ)
180 (SAVE_TYPE_OBJ_OBJ_OBJ_OBJ, SAVE_TYPE_PTR_INT, SAVE_TYPE_PTR_OBJ)
181 (SAVE_TYPE_PTR_PTR, SAVE_TYPE_PTR_PTR_OBJ, SAVE_TYPE_MEMORY):
182 New constants.
183 (struct Lisp_Save_Value): Replace members area, type0, type1, type2,
184 type3 with a single member save_type. All uses changed.
185 (save_type, set_save_pointer, set_save_integer): New functions.
186 * print.c (PRINTX): Remove.
187
188 * alloc.c: Remove redundant static declarations.
189
1902013-03-20 Dmitry Antipov <dmantipov@yandex.ru>
191
192 * window.h (struct window): Convert left_col, top_line, total_lines
193 and total_cols from Lisp_Objects to integers. Adjust comments.
194 (wset_left_col, wset_top_line, wset_total_cols, wset_total_lines):
195 Remove.
196 (WINDOW_TOTAL_COLS, WINDOW_TOTAL_LINES, WINDOW_LEFT_EDGE_COL)
197 (WINDOW_TOP_EDGE_LINE): Drop Lisp_Object to integer conversion.
198 * dispnew.c, frame.c, w32fns.c, window.c, xdisp.c, xfns.c:
199 Adjust users where appropriate.
200
2012013-03-20 Dmitry Antipov <dmantipov@yandex.ru>
202
203 * frame.h (struct frame): Drop resx and resy because the same data is
204 available from window system-specific output context. Adjust users.
205 (default_pixels_per_inch_x, default_pixels_per_inch_y): New
206 functions to provide defaults when no window system available.
207 (FRAME_RES_X, FRAME_RES_Y): New macros.
208 (NUMVAL): Moved from xdisp.c.
209 * font.c (font_pixel_size, font_find_for_lface, font_open_for_lface)
210 (Ffont_face_attributes, Fopen_font):
211 * image.c (gs_load):
212 * w32font.c (fill_in_logfont):
213 * xdisp.c (calc_pixel_width_or_height):
214 * xfaces.c (Fx_family_fonts, set_lface_from_font): Use them.
215 * xsettings.c (apply_xft_settings): Drop frame loop and adjust comment.
216
2172013-03-20 Kenichi Handa <handa@gnu.org>
218
219 * coding.c (syms_of_coding): Initialize disable_ascii_optimization
220 to 1 (temporary workaround until a bug related to ASCII
221 optimization is fixed).
222
2232013-03-19 Dmitry Antipov <dmantipov@yandex.ru>
224
225 * window.c (Fwindow_combination_limit, Fset_window_combination_limit):
226 Signal error if window is not internal. Adjust docstring.
227 (delete_all_child_windows): Use combination_limit to save the buffer.
228 (Fset_window_configuration): Adjust accordingly.
229 * print.c (syms_of_print): Initialize debugging output not here...
230 (init_print_once): ...but in a new function here.
231 * lisp.h (init_print_once): Add prototype.
232 * emacs.c (main): Add call to init_print_once. Adjust comments.
233
2342013-03-18 Dmitry Antipov <dmantipov@yandex.ru>
235
236 * window.c (window_resize_check, window_resize_apply)
237 (window_from_coordinates, recombine_windows, set_window_buffer)
238 (make_parent_window, Fwindow_resize_apply, resize_frame_windows)
239 (Fsplit_window_internal, Fdelete_window_internal)
240 (freeze_window_starts): Use bool for booleans.
241 * window.h (window_frame_coordinates, resize_frame_windows)
242 (freeze_window_starts, set_window_buffer): Adjust prototypes.
243
2442013-03-17 Stefan Monnier <monnier@iro.umontreal.ca>
245
246 * dispnew.c (bitch_at_user): Use `user-error'.
247
2482013-03-17 Ken Brown <kbrown@cornell.edu>
249
250 * dispextern.h (RGB_PIXEL_COLOR): Move here from image.c. Use it
251 as return type of image_background. (Bug#13981)
252 * image.c (RGB_PIXEL_COLOR): Move to dispextern.h.
253
2542013-03-16 Jan Djärv <jan.h.d@swipnet.se>
255
256 * nsterm.m (updateFrameSize:): Change resize increments if needed.
257 (ns_select): Don't return with result uninitialized.
258
259 * nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename
260 and getDirectory.
261
262 * nsfns.m (ns_filename_from_panel, ns_directory_from_panel):
263 New functions.
264 (Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose
265 directories. If filename is nil, get directory name (Bug#13932).
266 Use getFilename and getDirectory.
267 (getFilename, getDirectory): New methods for EmacsSavePanel and
268 EmacsOpenPanel.
269 (ok:): In EmacsOpenPanel, if we can't choose directories, just return.
270
12013-03-15 Paul Eggert <eggert@cs.ucla.edu> 2712013-03-15 Paul Eggert <eggert@cs.ucla.edu>
2 272
3 * coding.c (decode_coding_gap): Fix typo caught by static checking. 273 * coding.c (decode_coding_gap): Fix typo caught by static checking.
@@ -23,10 +293,6 @@
23 (syms_of_coding): Declare disable-ascii-optimization as a Lisp 293 (syms_of_coding): Declare disable-ascii-optimization as a Lisp
24 variable. 294 variable.
25 295
26 * global.h (struct emacs_globals): New member
27 f_disable_ascii_optimization.
28 (disable_ascii_optimization): New macro.
29
30 * lisp.h (adjust_after_replace): Cancel externing it. 296 * lisp.h (adjust_after_replace): Cancel externing it.
31 (insert_from_gap): Adjust prototype. 297 (insert_from_gap): Adjust prototype.
32 298
@@ -5093,8 +5359,8 @@
5093 a public macro and no need to inline by hand. 5359 a public macro and no need to inline by hand.
5094 5360
50952012-09-26 Tomohiro Matsuyama <tomo@cx4a.org> 53612012-09-26 Tomohiro Matsuyama <tomo@cx4a.org>
5096 Stefan Monnier <monnier@iro.umontreal.ca> 5362 Stefan Monnier <monnier@iro.umontreal.ca>
5097 Juanma Barranquero <lekktu@gmail.com> 5363 Juanma Barranquero <lekktu@gmail.com>
5098 5364
5099 * profiler.c: New file. 5365 * profiler.c: New file.
5100 * Makefile.in (base_obj): Add profiler.o. 5366 * Makefile.in (base_obj): Add profiler.o.
diff --git a/src/alloc.c b/src/alloc.c
index b2703c5f961..ea833c62b94 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -323,20 +323,7 @@ static void *min_heap_address, *max_heap_address;
323static struct mem_node mem_z; 323static struct mem_node mem_z;
324#define MEM_NIL &mem_z 324#define MEM_NIL &mem_z
325 325
326static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t);
327static void lisp_free (void *);
328static void mark_stack (void);
329static bool live_vector_p (struct mem_node *, void *);
330static bool live_buffer_p (struct mem_node *, void *);
331static bool live_string_p (struct mem_node *, void *);
332static bool live_cons_p (struct mem_node *, void *);
333static bool live_symbol_p (struct mem_node *, void *);
334static bool live_float_p (struct mem_node *, void *);
335static bool live_misc_p (struct mem_node *, void *);
336static void mark_maybe_object (Lisp_Object);
337static void mark_memory (void *, void *);
338#if GC_MARK_STACK || defined GC_MALLOC_CHECK 326#if GC_MARK_STACK || defined GC_MALLOC_CHECK
339static void mem_init (void);
340static struct mem_node *mem_insert (void *, void *, enum mem_type); 327static struct mem_node *mem_insert (void *, void *, enum mem_type);
341static void mem_insert_fixup (struct mem_node *); 328static void mem_insert_fixup (struct mem_node *);
342static void mem_rotate_left (struct mem_node *); 329static void mem_rotate_left (struct mem_node *);
@@ -346,11 +333,6 @@ static void mem_delete_fixup (struct mem_node *);
346static struct mem_node *mem_find (void *); 333static struct mem_node *mem_find (void *);
347#endif 334#endif
348 335
349
350#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS
351static void check_gcpros (void);
352#endif
353
354#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ 336#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */
355 337
356#ifndef DEADP 338#ifndef DEADP
@@ -797,7 +779,7 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
797 ptrdiff_t nitems_incr_max = n_max - n; 779 ptrdiff_t nitems_incr_max = n_max - n;
798 ptrdiff_t incr = max (nitems_incr_min, min (incr_estimate, nitems_incr_max)); 780 ptrdiff_t incr = max (nitems_incr_min, min (incr_estimate, nitems_incr_max));
799 781
800 eassert (0 < item_size && 0 < nitems_incr_min && 0 <= n && -1 <= nitems_max); 782 eassert (item_size > 0 && nitems_incr_min > 0 && n >= 0 && nitems_max >= -1);
801 if (! pa) 783 if (! pa)
802 *nitems = 0; 784 *nitems = 0;
803 if (nitems_incr_max < incr) 785 if (nitems_incr_max < incr)
@@ -1162,7 +1144,7 @@ lisp_align_free (void *block)
1162#define INTERVAL_BLOCK_SIZE \ 1144#define INTERVAL_BLOCK_SIZE \
1163 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval)) 1145 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval))
1164 1146
1165/* Intervals are allocated in chunks in form of an interval_block 1147/* Intervals are allocated in chunks in the form of an interval_block
1166 structure. */ 1148 structure. */
1167 1149
1168struct interval_block 1150struct interval_block
@@ -3344,56 +3326,50 @@ free_misc (Lisp_Object misc)
3344 total_free_markers++; 3326 total_free_markers++;
3345} 3327}
3346 3328
3329/* Verify properties of Lisp_Save_Value's representation
3330 that are assumed here and elsewhere. */
3331
3332verify (SAVE_UNUSED == 0);
3333verify ((SAVE_INTEGER | SAVE_POINTER | SAVE_OBJECT) >> SAVE_SLOT_BITS == 0);
3334
3347/* Return a Lisp_Save_Value object with the data saved according to 3335/* Return a Lisp_Save_Value object with the data saved according to
3348 FMT. Format specifiers are `i' for an integer, `p' for a pointer 3336 DATA_TYPE. DATA_TYPE should be one of SAVE_TYPE_INT_INT, etc. */
3349 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3350 3337
3351Lisp_Object 3338Lisp_Object
3352make_save_value (const char *fmt, ...) 3339make_save_value (enum Lisp_Save_Type save_type, ...)
3353{ 3340{
3354 va_list ap; 3341 va_list ap;
3355 int len = strlen (fmt); 3342 int i;
3356 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3343 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3357 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3344 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3358 3345
3359 eassert (0 < len && len < 5); 3346 eassert (0 < save_type
3360 va_start (ap, fmt); 3347 && (save_type < 1 << (SAVE_TYPE_BITS - 1)
3361 3348 || save_type == SAVE_TYPE_MEMORY));
3362#define INITX(index) \ 3349 p->save_type = save_type;
3363 do { \ 3350 va_start (ap, save_type);
3364 if (len <= index) \ 3351 save_type &= ~ (1 << (SAVE_TYPE_BITS - 1));
3365 p->type ## index = SAVE_UNUSED; \ 3352
3366 else \ 3353 for (i = 0; save_type; i++, save_type >>= SAVE_SLOT_BITS)
3367 { \ 3354 switch (save_type & ((1 << SAVE_SLOT_BITS) - 1))
3368 if (fmt[index] == 'i') \ 3355 {
3369 { \ 3356 case SAVE_POINTER:
3370 p->type ## index = SAVE_INTEGER; \ 3357 p->data[i].pointer = va_arg (ap, void *);
3371 p->data[index].integer = va_arg (ap, ptrdiff_t); \ 3358 break;
3372 } \
3373 else if (fmt[index] == 'p') \
3374 { \
3375 p->type ## index = SAVE_POINTER; \
3376 p->data[index].pointer = va_arg (ap, void *); \
3377 } \
3378 else if (fmt[index] == 'o') \
3379 { \
3380 p->type ## index = SAVE_OBJECT; \
3381 p->data[index].object = va_arg (ap, Lisp_Object); \
3382 } \
3383 else \
3384 emacs_abort (); \
3385 } \
3386 } while (0)
3387 3359
3388 INITX (0); 3360 case SAVE_INTEGER:
3389 INITX (1); 3361 p->data[i].integer = va_arg (ap, ptrdiff_t);
3390 INITX (2); 3362 break;
3391 INITX (3);
3392 3363
3393#undef INITX 3364 case SAVE_OBJECT:
3365 p->data[i].object = va_arg (ap, Lisp_Object);
3366 break;
3367
3368 default:
3369 emacs_abort ();
3370 }
3394 3371
3395 va_end (ap); 3372 va_end (ap);
3396 p->area = 0;
3397 return val; 3373 return val;
3398} 3374}
3399 3375
@@ -3404,11 +3380,8 @@ make_save_pointer (void *pointer)
3404{ 3380{
3405 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3381 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3406 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3382 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3407 3383 p->save_type = SAVE_POINTER;
3408 p->area = 0;
3409 p->type0 = SAVE_POINTER;
3410 p->data[0].pointer = pointer; 3384 p->data[0].pointer = pointer;
3411 p->type1 = p->type2 = p->type3 = SAVE_UNUSED;
3412 return val; 3385 return val;
3413} 3386}
3414 3387
@@ -5403,7 +5376,7 @@ See Info node `(elisp)Garbage Collection'. */)
5403 double tot = total_bytes_of_live_objects (); 5376 double tot = total_bytes_of_live_objects ();
5404 5377
5405 tot *= XFLOAT_DATA (Vgc_cons_percentage); 5378 tot *= XFLOAT_DATA (Vgc_cons_percentage);
5406 if (0 < tot) 5379 if (tot > 0)
5407 { 5380 {
5408 if (tot < TYPE_MAXIMUM (EMACS_INT)) 5381 if (tot < TYPE_MAXIMUM (EMACS_INT))
5409 gc_relative_threshold = tot; 5382 gc_relative_threshold = tot;
@@ -5976,12 +5949,11 @@ mark_object (Lisp_Object arg)
5976 case Lisp_Misc_Save_Value: 5949 case Lisp_Misc_Save_Value:
5977 XMISCANY (obj)->gcmarkbit = 1; 5950 XMISCANY (obj)->gcmarkbit = 1;
5978 { 5951 {
5979 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); 5952 struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj);
5980 /* If `area' is nonzero, `data[0].pointer' is the address 5953 /* If `save_type' is zero, `data[0].pointer' is the address
5981 of a memory area containing `data[1].integer' potential 5954 of a memory area containing `data[1].integer' potential
5982 Lisp_Objects. */ 5955 Lisp_Objects. */
5983#if GC_MARK_STACK 5956 if (GC_MARK_STACK && ptr->save_type == SAVE_TYPE_MEMORY)
5984 if (ptr->area)
5985 { 5957 {
5986 Lisp_Object *p = ptr->data[0].pointer; 5958 Lisp_Object *p = ptr->data[0].pointer;
5987 ptrdiff_t nelt; 5959 ptrdiff_t nelt;
@@ -5989,17 +5961,12 @@ mark_object (Lisp_Object arg)
5989 mark_maybe_object (*p); 5961 mark_maybe_object (*p);
5990 } 5962 }
5991 else 5963 else
5992#endif /* GC_MARK_STACK */
5993 { 5964 {
5994 /* Find Lisp_Objects in `data[N]' slots and mark them. */ 5965 /* Find Lisp_Objects in `data[N]' slots and mark them. */
5995 if (ptr->type0 == SAVE_OBJECT) 5966 int i;
5996 mark_object (ptr->data[0].object); 5967 for (i = 0; i < SAVE_VALUE_SLOTS; i++)
5997 if (ptr->type1 == SAVE_OBJECT) 5968 if (save_type (ptr, i) == SAVE_OBJECT)
5998 mark_object (ptr->data[1].object); 5969 mark_object (ptr->data[i].object);
5999 if (ptr->type2 == SAVE_OBJECT)
6000 mark_object (ptr->data[2].object);
6001 if (ptr->type3 == SAVE_OBJECT)
6002 mark_object (ptr->data[3].object);
6003 } 5970 }
6004 } 5971 }
6005 break; 5972 break;
diff --git a/src/blockinput.h b/src/blockinput.h
index 192c813073d..6dc22c6f5dd 100644
--- a/src/blockinput.h
+++ b/src/blockinput.h
@@ -67,7 +67,7 @@ extern void unblock_input_to (int);
67BLOCKINPUT_INLINE bool 67BLOCKINPUT_INLINE bool
68input_blocked_p (void) 68input_blocked_p (void)
69{ 69{
70 return 0 < interrupt_input_blocked; 70 return interrupt_input_blocked > 0;
71} 71}
72 72
73INLINE_HEADER_END 73INLINE_HEADER_END
diff --git a/src/bytecode.c b/src/bytecode.c
index acb96c1e61b..7676c8550a4 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -660,7 +660,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
660 the table clearer. */ 660 the table clearer. */
661#define LABEL(OP) [OP] = &&insn_ ## OP 661#define LABEL(OP) [OP] = &&insn_ ## OP
662 662
663#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 663#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
664# pragma GCC diagnostic push 664# pragma GCC diagnostic push
665# pragma GCC diagnostic ignored "-Woverride-init" 665# pragma GCC diagnostic ignored "-Woverride-init"
666#endif 666#endif
@@ -676,7 +676,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
676#undef DEFINE 676#undef DEFINE
677 }; 677 };
678 678
679#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 679#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
680# pragma GCC diagnostic pop 680# pragma GCC diagnostic pop
681#endif 681#endif
682 682
diff --git a/src/callproc.c b/src/callproc.c
index 9132c0dd976..46a37701a40 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1,5 +1,5 @@
1/* Synchronous subprocess invocation for GNU Emacs. 1/* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985-1988, 1993-1995, 1999-2012 2 Copyright (C) 1985-1988, 1993-1995, 1999-2013
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -125,7 +125,7 @@ record_kill_process (struct Lisp_Process *p)
125static Lisp_Object 125static Lisp_Object
126call_process_kill (Lisp_Object ignored) 126call_process_kill (Lisp_Object ignored)
127{ 127{
128 if (0 <= synch_process_fd) 128 if (synch_process_fd >= 0)
129 emacs_close (synch_process_fd); 129 emacs_close (synch_process_fd);
130 130
131 if (synch_process_pid) 131 if (synch_process_pid)
@@ -173,7 +173,7 @@ call_process_cleanup (Lisp_Object arg)
173 } 173 }
174#endif 174#endif
175 175
176 if (0 <= synch_process_fd) 176 if (synch_process_fd >= 0)
177 emacs_close (synch_process_fd); 177 emacs_close (synch_process_fd);
178 178
179#ifdef MSDOS 179#ifdef MSDOS
@@ -682,7 +682,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
682 682
683 child_errno = errno; 683 child_errno = errno;
684 684
685 if (0 < pid) 685 if (pid > 0)
686 { 686 {
687 if (INTEGERP (buffer)) 687 if (INTEGERP (buffer))
688 record_deleted_pid (pid); 688 record_deleted_pid (pid);
diff --git a/src/ccl.c b/src/ccl.c
index 7f77e1d22fa..c3b3f5486c4 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1668,7 +1668,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1668 } 1668 }
1669 map = XCDR (map); 1669 map = XCDR (map);
1670 if (! (VECTORP (map) 1670 if (! (VECTORP (map)
1671 && 0 < ASIZE (map) 1671 && ASIZE (map) > 0
1672 && INTEGERP (AREF (map, 0)) 1672 && INTEGERP (AREF (map, 0))
1673 && XINT (AREF (map, 0)) <= op 1673 && XINT (AREF (map, 0)) <= op
1674 && op - XINT (AREF (map, 0)) + 1 < ASIZE (map))) 1674 && op - XINT (AREF (map, 0)) + 1 < ASIZE (map)))
@@ -1867,7 +1867,7 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
1867 return Qnil; 1867 return Qnil;
1868 } 1868 }
1869 1869
1870 if (! (0 <= XINT (AREF (result, CCL_HEADER_BUF_MAG)) 1870 if (! (XINT (AREF (result, CCL_HEADER_BUF_MAG)) >= 0
1871 && ASCENDING_ORDER (0, XINT (AREF (result, CCL_HEADER_EOF)), 1871 && ASCENDING_ORDER (0, XINT (AREF (result, CCL_HEADER_EOF)),
1872 ASIZE (ccl)))) 1872 ASIZE (ccl))))
1873 return Qnil; 1873 return Qnil;
@@ -2130,7 +2130,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2130 produced_chars += ccl.produced; 2130 produced_chars += ccl.produced;
2131 offset = outp - outbuf; 2131 offset = outp - outbuf;
2132 shortfall = ccl.produced * max_expansion - (outbufsize - offset); 2132 shortfall = ccl.produced * max_expansion - (outbufsize - offset);
2133 if (0 < shortfall) 2133 if (shortfall > 0)
2134 { 2134 {
2135 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1); 2135 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2136 outp = outbuf + offset; 2136 outp = outbuf + offset;
diff --git a/src/character.c b/src/character.c
index b2caaa290af..5a06c7f4d6c 100644
--- a/src/character.c
+++ b/src/character.c
@@ -833,8 +833,8 @@ string_escape_byte8 (Lisp_Object string)
833 833
834 if (multibyte) 834 if (multibyte)
835 { 835 {
836 if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count 836 if (byte8_count > (MOST_POSITIVE_FIXNUM - nchars) / 3
837 || (STRING_BYTES_BOUND - nbytes) / 2 < byte8_count) 837 || byte8_count > (STRING_BYTES_BOUND - nbytes) / 2)
838 string_overflow (); 838 string_overflow ();
839 839
840 /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ 840 /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */
@@ -843,7 +843,7 @@ string_escape_byte8 (Lisp_Object string)
843 } 843 }
844 else 844 else
845 { 845 {
846 if ((STRING_BYTES_BOUND - nbytes) / 3 < byte8_count) 846 if (byte8_count > (STRING_BYTES_BOUND - nbytes) / 3)
847 string_overflow (); 847 string_overflow ();
848 848
849 /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ 849 /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */
diff --git a/src/charset.c b/src/charset.c
index fdb8eebde8b..3d43d81877f 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -447,7 +447,7 @@ read_hex (FILE *fp, bool *eof, bool *overflow)
447 n = 0; 447 n = 0;
448 while (c_isxdigit (c = getc (fp))) 448 while (c_isxdigit (c = getc (fp)))
449 { 449 {
450 if (UINT_MAX >> 4 < n) 450 if (n > UINT_MAX >> 4)
451 *overflow = 1; 451 *overflow = 1;
452 n = ((n << 4) 452 n = ((n << 4)
453 | (c - ('0' <= c && c <= '9' ? '0' 453 | (c - ('0' <= c && c <= '9' ? '0'
diff --git a/src/cm.c b/src/cm.c
index 3a5f927eda3..481ac15e435 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -214,7 +214,7 @@ calccost (struct tty_display_info *tty,
214 if (doit) 214 if (doit)
215 do 215 do
216 emacs_tputs (tty, p, 1, cmputc); 216 emacs_tputs (tty, p, 1, cmputc);
217 while (0 < --deltay); 217 while (--deltay > 0);
218x: 218x:
219 if ((deltax = dstx - srcx) == 0) 219 if ((deltax = dstx - srcx) == 0)
220 goto done; 220 goto done;
@@ -297,7 +297,7 @@ fail:
297 if (doit) 297 if (doit)
298 do 298 do
299 emacs_tputs (tty, p, 1, cmputc); 299 emacs_tputs (tty, p, 1, cmputc);
300 while (0 < --deltax); 300 while (--deltax > 0);
301done: 301done:
302 return totalcost; 302 return totalcost;
303} 303}
diff --git a/src/coding.c b/src/coding.c
index 6cfcec905a1..cb81375a043 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6075,7 +6075,7 @@ complement_process_encoding_system (Lisp_Object coding_system)
6075static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); 6075static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen);
6076 6076
6077 6077
6078/* Return 1 if all the source bytes are ASCII, and return 0 otherwize. 6078/* Return true iff all the source bytes are ASCII.
6079 By side effects, set coding->head_ascii and coding->eol_seen. The 6079 By side effects, set coding->head_ascii and coding->eol_seen. The
6080 value of coding->eol_seen is "logical or" of EOL_SEEN_LF, 6080 value of coding->eol_seen is "logical or" of EOL_SEEN_LF,
6081 EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when 6081 EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when
@@ -10877,7 +10877,7 @@ decode text as usual. */);
10877 DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization, 10877 DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization,
10878 doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files. 10878 doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files.
10879Internal use only. Removed after the experimental optimizer gets stable. */); 10879Internal use only. Removed after the experimental optimizer gets stable. */);
10880 disable_ascii_optimization = 0; 10880 disable_ascii_optimization = 1;
10881 10881
10882 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, 10882 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input,
10883 doc: /* Char table for translating self-inserting characters. 10883 doc: /* Char table for translating self-inserting characters.
diff --git a/src/data.c b/src/data.c
index 6622088b648..b20d1b4c8af 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2337,13 +2337,13 @@ cons_to_unsigned (Lisp_Object c, uintmax_t max)
2337 uintmax_t val IF_LINT (= 0); 2337 uintmax_t val IF_LINT (= 0);
2338 if (INTEGERP (c)) 2338 if (INTEGERP (c))
2339 { 2339 {
2340 valid = 0 <= XINT (c); 2340 valid = XINT (c) >= 0;
2341 val = XINT (c); 2341 val = XINT (c);
2342 } 2342 }
2343 else if (FLOATP (c)) 2343 else if (FLOATP (c))
2344 { 2344 {
2345 double d = XFLOAT_DATA (c); 2345 double d = XFLOAT_DATA (c);
2346 if (0 <= d 2346 if (d >= 0
2347 && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1)) 2347 && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
2348 { 2348 {
2349 val = d; 2349 val = d;
diff --git a/src/dired.c b/src/dired.c
index 0e37568f211..ab48488966b 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -258,7 +258,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
258 QUIT; 258 QUIT;
259 259
260 if (NILP (match) 260 if (NILP (match)
261 || (0 <= re_search (bufp, SSDATA (name), len, 0, len, 0))) 261 || re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0)
262 wanted = 1; 262 wanted = 1;
263 263
264 immediate_quit = 0; 264 immediate_quit = 0;
@@ -517,8 +517,8 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
517 517
518 QUIT; 518 QUIT;
519 if (len < SCHARS (encoded_file) 519 if (len < SCHARS (encoded_file)
520 || 0 <= scmp (dp->d_name, SSDATA (encoded_file), 520 || scmp (dp->d_name, SSDATA (encoded_file),
521 SCHARS (encoded_file))) 521 SCHARS (encoded_file)) >= 0)
522 continue; 522 continue;
523 523
524 if (file_name_completion_stat (fd, dp, &st) < 0) 524 if (file_name_completion_stat (fd, dp, &st) < 0)
@@ -580,7 +580,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
580 if (skip < 0) 580 if (skip < 0)
581 continue; 581 continue;
582 582
583 if (0 <= scmp (dp->d_name + skip, p1, elt_len)) 583 if (scmp (dp->d_name + skip, p1, elt_len) >= 0)
584 continue; 584 continue;
585 break; 585 break;
586 } 586 }
@@ -602,9 +602,8 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
602 skip = len - SCHARS (elt); 602 skip = len - SCHARS (elt);
603 if (skip < 0) continue; 603 if (skip < 0) continue;
604 604
605 if (0 <= scmp (dp->d_name + skip, 605 if (scmp (dp->d_name + skip, SSDATA (elt), SCHARS (elt))
606 SSDATA (elt), 606 >= 0)
607 SCHARS (elt)))
608 continue; 607 continue;
609 break; 608 break;
610 } 609 }
diff --git a/src/dispextern.h b/src/dispextern.h
index 58338587cac..9a03abf6766 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -609,8 +609,8 @@ struct glyph_pool
609 609
610 2. Window glyph matrices on frames having frame glyph matrices. 610 2. Window glyph matrices on frames having frame glyph matrices.
611 Such matrices are sub-matrices of their corresponding frame matrix, 611 Such matrices are sub-matrices of their corresponding frame matrix,
612 i.e. frame glyph matrices and window glyph matrices share the same 612 i.e., frame glyph matrices and window glyph matrices share the same
613 glyph memory which is allocated in form of a glyph_pool structure. 613 glyph memory, which is allocated in the form of a glyph_pool structure.
614 Glyph rows in such a window matrix are slices of frame matrix rows. 614 Glyph rows in such a window matrix are slices of frame matrix rows.
615 615
616 2. Free-standing window glyph matrices managing their own glyph 616 2. Free-standing window glyph matrices managing their own glyph
@@ -3214,7 +3214,15 @@ bool valid_image_p (Lisp_Object);
3214void prepare_image_for_display (struct frame *, struct image *); 3214void prepare_image_for_display (struct frame *, struct image *);
3215ptrdiff_t lookup_image (struct frame *, Lisp_Object); 3215ptrdiff_t lookup_image (struct frame *, Lisp_Object);
3216 3216
3217unsigned long image_background (struct image *, struct frame *, 3217#if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3218#define RGB_PIXEL_COLOR unsigned long
3219#endif
3220
3221#ifdef HAVE_NTGUI
3222#define RGB_PIXEL_COLOR COLORREF
3223#endif
3224
3225RGB_PIXEL_COLOR image_background (struct image *, struct frame *,
3218 XImagePtr_or_DC ximg); 3226 XImagePtr_or_DC ximg);
3219int image_background_transparent (struct image *, struct frame *, 3227int image_background_transparent (struct image *, struct frame *,
3220 XImagePtr_or_DC mask); 3228 XImagePtr_or_DC mask);
diff --git a/src/dispnew.c b/src/dispnew.c
index 763a01ab934..de1ca47ef60 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -365,7 +365,7 @@ margin_glyphs_to_reserve (struct window *w, int total_glyphs, Lisp_Object margin
365 365
366 if (NUMBERP (margin)) 366 if (NUMBERP (margin))
367 { 367 {
368 int width = XFASTINT (w->total_cols); 368 int width = w->total_cols;
369 double d = max (0, XFLOATINT (margin)); 369 double d = max (0, XFLOATINT (margin));
370 d = min (width / 2 - 1, d); 370 d = min (width / 2 - 1, d);
371 n = (int) ((double) total_glyphs / width * d); 371 n = (int) ((double) total_glyphs / width * d);
@@ -796,11 +796,13 @@ clear_current_matrices (register struct frame *f)
796 if (f->current_matrix) 796 if (f->current_matrix)
797 clear_glyph_matrix (f->current_matrix); 797 clear_glyph_matrix (f->current_matrix);
798 798
799#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
799 /* Clear the matrix of the menu bar window, if such a window exists. 800 /* Clear the matrix of the menu bar window, if such a window exists.
800 The menu bar window is currently used to display menus on X when 801 The menu bar window is currently used to display menus on X when
801 no toolkit support is compiled in. */ 802 no toolkit support is compiled in. */
802 if (WINDOWP (f->menu_bar_window)) 803 if (WINDOWP (f->menu_bar_window))
803 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix); 804 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
805#endif
804 806
805 /* Clear the matrix of the tool-bar window, if any. */ 807 /* Clear the matrix of the tool-bar window, if any. */
806 if (WINDOWP (f->tool_bar_window)) 808 if (WINDOWP (f->tool_bar_window))
@@ -820,8 +822,10 @@ clear_desired_matrices (register struct frame *f)
820 if (f->desired_matrix) 822 if (f->desired_matrix)
821 clear_glyph_matrix (f->desired_matrix); 823 clear_glyph_matrix (f->desired_matrix);
822 824
825#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
823 if (WINDOWP (f->menu_bar_window)) 826 if (WINDOWP (f->menu_bar_window))
824 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->desired_matrix); 827 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->desired_matrix);
828#endif
825 829
826 if (WINDOWP (f->tool_bar_window)) 830 if (WINDOWP (f->tool_bar_window))
827 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->desired_matrix); 831 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->desired_matrix);
@@ -1778,7 +1782,7 @@ required_matrix_width (struct window *w)
1778 } 1782 }
1779#endif /* HAVE_WINDOW_SYSTEM */ 1783#endif /* HAVE_WINDOW_SYSTEM */
1780 1784
1781 return XINT (w->total_cols); 1785 return w->total_cols;
1782} 1786}
1783 1787
1784 1788
@@ -2116,10 +2120,10 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f)
2116 2120
2117 /* Set window dimensions to frame dimensions and allocate or 2121 /* Set window dimensions to frame dimensions and allocate or
2118 adjust glyph matrices of W. */ 2122 adjust glyph matrices of W. */
2119 wset_top_line (w, make_number (0)); 2123 w->top_line = 0;
2120 wset_left_col (w, make_number (0)); 2124 w->left_col = 0;
2121 wset_total_lines (w, make_number (FRAME_MENU_BAR_LINES (f))); 2125 w->total_lines = FRAME_MENU_BAR_LINES (f);
2122 wset_total_cols (w, make_number (FRAME_TOTAL_COLS (f))); 2126 w->total_cols = FRAME_TOTAL_COLS (f);
2123 allocate_matrices_for_window_redisplay (w); 2127 allocate_matrices_for_window_redisplay (w);
2124 } 2128 }
2125#endif /* not USE_X_TOOLKIT && not USE_GTK */ 2129#endif /* not USE_X_TOOLKIT && not USE_GTK */
@@ -2142,10 +2146,10 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f)
2142 else 2146 else
2143 w = XWINDOW (f->tool_bar_window); 2147 w = XWINDOW (f->tool_bar_window);
2144 2148
2145 wset_top_line (w, make_number (FRAME_MENU_BAR_LINES (f))); 2149 w->top_line = FRAME_MENU_BAR_LINES (f);
2146 wset_left_col (w, make_number (0)); 2150 w->left_col = 0;
2147 wset_total_lines (w, make_number (FRAME_TOOL_BAR_LINES (f))); 2151 w->total_lines = FRAME_TOOL_BAR_LINES (f);
2148 wset_total_cols (w, make_number (FRAME_TOTAL_COLS (f))); 2152 w->total_cols = FRAME_TOTAL_COLS (f);
2149 allocate_matrices_for_window_redisplay (w); 2153 allocate_matrices_for_window_redisplay (w);
2150 } 2154 }
2151#endif 2155#endif
@@ -2186,6 +2190,7 @@ free_glyphs (struct frame *f)
2186 if (!NILP (f->root_window)) 2190 if (!NILP (f->root_window))
2187 free_window_matrices (XWINDOW (f->root_window)); 2191 free_window_matrices (XWINDOW (f->root_window));
2188 2192
2193#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
2189 /* Free the dummy window for menu bars without X toolkit and its 2194 /* Free the dummy window for menu bars without X toolkit and its
2190 glyph matrices. */ 2195 glyph matrices. */
2191 if (!NILP (f->menu_bar_window)) 2196 if (!NILP (f->menu_bar_window))
@@ -2196,6 +2201,7 @@ free_glyphs (struct frame *f)
2196 w->desired_matrix = w->current_matrix = NULL; 2201 w->desired_matrix = w->current_matrix = NULL;
2197 fset_menu_bar_window (f, Qnil); 2202 fset_menu_bar_window (f, Qnil);
2198 } 2203 }
2204#endif
2199 2205
2200 /* Free the tool bar window and its glyph matrices. */ 2206 /* Free the tool bar window and its glyph matrices. */
2201 if (!NILP (f->tool_bar_window)) 2207 if (!NILP (f->tool_bar_window))
@@ -3094,10 +3100,12 @@ update_frame (struct frame *f, bool force_p, bool inhibit_hairy_id_p)
3094 when pending input is detected. */ 3100 when pending input is detected. */
3095 update_begin (f); 3101 update_begin (f);
3096 3102
3103#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
3097 /* Update the menu bar on X frames that don't have toolkit 3104 /* Update the menu bar on X frames that don't have toolkit
3098 support. */ 3105 support. */
3099 if (WINDOWP (f->menu_bar_window)) 3106 if (WINDOWP (f->menu_bar_window))
3100 update_window (XWINDOW (f->menu_bar_window), 1); 3107 update_window (XWINDOW (f->menu_bar_window), 1);
3108#endif
3101 3109
3102 /* Update the tool-bar window, if present. */ 3110 /* Update the tool-bar window, if present. */
3103 if (WINDOWP (f->tool_bar_window)) 3111 if (WINDOWP (f->tool_bar_window))
@@ -4462,7 +4470,7 @@ scrolling_window (struct window *w, bool header_line_p)
4462 row_table[row_entry_pool[i].bucket] = NULL; 4470 row_table[row_entry_pool[i].bucket] = NULL;
4463 4471
4464 /* Value is 1 to indicate that we scrolled the display. */ 4472 /* Value is 1 to indicate that we scrolled the display. */
4465 return 0 < nruns; 4473 return nruns > 0;
4466} 4474}
4467 4475
4468 4476
@@ -4548,7 +4556,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p)
4548 } 4556 }
4549 } 4557 }
4550 4558
4551 lint_assume (0 <= FRAME_LINES (f)); 4559 lint_assume (FRAME_LINES (f) >= 0);
4552 pause_p = 0 < i && i < FRAME_LINES (f) - 1; 4560 pause_p = 0 < i && i < FRAME_LINES (f) - 1;
4553 4561
4554 /* Now just clean up termcap drivers and set cursor, etc. */ 4562 /* Now just clean up termcap drivers and set cursor, etc. */
@@ -5594,7 +5602,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth,
5594 FrameCols (FRAME_TTY (f)) = newwidth; 5602 FrameCols (FRAME_TTY (f)) = newwidth;
5595 5603
5596 if (WINDOWP (f->tool_bar_window)) 5604 if (WINDOWP (f->tool_bar_window))
5597 wset_total_cols (XWINDOW (f->tool_bar_window), make_number (newwidth)); 5605 XWINDOW (f->tool_bar_window)->total_cols = newwidth;
5598 } 5606 }
5599 5607
5600 FRAME_LINES (f) = newheight; 5608 FRAME_LINES (f) = newheight;
@@ -5736,7 +5744,11 @@ bitch_at_user (void)
5736 if (noninteractive) 5744 if (noninteractive)
5737 putchar (07); 5745 putchar (07);
5738 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */ 5746 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */
5739 error ("Keyboard macro terminated by a command ringing the bell"); 5747 {
5748 const char *msg
5749 = "Keyboard macro terminated by a command ringing the bell";
5750 Fsignal (Quser_error, Fcons (build_string (msg), Qnil));
5751 }
5740 else 5752 else
5741 ring_bell (XFRAME (selected_frame)); 5753 ring_bell (XFRAME (selected_frame));
5742} 5754}
@@ -5763,7 +5775,7 @@ additional wait period, in milliseconds; this is for backwards compatibility.
5763 duration += XINT (milliseconds) / 1000.0; 5775 duration += XINT (milliseconds) / 1000.0;
5764 } 5776 }
5765 5777
5766 if (0 < duration) 5778 if (duration > 0)
5767 { 5779 {
5768 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (duration); 5780 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (duration);
5769 wait_reading_process_output (min (EMACS_SECS (t), WAIT_READING_MAX), 5781 wait_reading_process_output (min (EMACS_SECS (t), WAIT_READING_MAX),
@@ -5803,14 +5815,14 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
5803 if (INTEGERP (timeout)) 5815 if (INTEGERP (timeout))
5804 { 5816 {
5805 sec = XINT (timeout); 5817 sec = XINT (timeout);
5806 if (! (0 < sec)) 5818 if (sec <= 0)
5807 return Qt; 5819 return Qt;
5808 nsec = 0; 5820 nsec = 0;
5809 } 5821 }
5810 else if (FLOATP (timeout)) 5822 else if (FLOATP (timeout))
5811 { 5823 {
5812 double seconds = XFLOAT_DATA (timeout); 5824 double seconds = XFLOAT_DATA (timeout);
5813 if (! (0 < seconds)) 5825 if (seconds <= 0)
5814 return Qt; 5826 return Qt;
5815 else 5827 else
5816 { 5828 {
diff --git a/src/doc.c b/src/doc.c
index 7234fb38bf9..1ddaa117bba 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -826,7 +826,7 @@ Otherwise, return a new string, without any text properties. */)
826 if (NILP (tem)) /* but not on any keys */ 826 if (NILP (tem)) /* but not on any keys */
827 { 827 {
828 ptrdiff_t offset = bufp - buf; 828 ptrdiff_t offset = bufp - buf;
829 if (STRING_BYTES_BOUND - 4 < bsize) 829 if (bsize > STRING_BYTES_BOUND - 4)
830 string_overflow (); 830 string_overflow ();
831 buf = xrealloc (buf, bsize += 4); 831 buf = xrealloc (buf, bsize += 4);
832 bufp = buf + offset; 832 bufp = buf + offset;
diff --git a/src/doprnt.c b/src/doprnt.c
index 471e35c7b43..087256ced2a 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -361,7 +361,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
361 361
362 /* Copy string into final output, truncating if no room. */ 362 /* Copy string into final output, truncating if no room. */
363 doit: 363 doit:
364 eassert (0 <= tem); 364 eassert (tem >= 0);
365 /* Coming here means STRING contains ASCII only. */ 365 /* Coming here means STRING contains ASCII only. */
366 if (STRING_BYTES_BOUND < tem) 366 if (STRING_BYTES_BOUND < tem)
367 error ("Format width or precision too large"); 367 error ("Format width or precision too large");
diff --git a/src/editfns.c b/src/editfns.c
index f34c574cae3..2d87b8e0064 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -839,7 +839,7 @@ Lisp_Object
839save_excursion_save (void) 839save_excursion_save (void)
840{ 840{
841 return make_save_value 841 return make_save_value
842 ("oooo", 842 (SAVE_TYPE_OBJ_OBJ_OBJ_OBJ,
843 Fpoint_marker (), 843 Fpoint_marker (),
844 /* Do not copy the mark if it points to nowhere. */ 844 /* Do not copy the mark if it points to nowhere. */
845 (XMARKER (BVAR (current_buffer, mark))->buffer 845 (XMARKER (BVAR (current_buffer, mark))->buffer
@@ -1398,8 +1398,8 @@ hi_time (time_t t)
1398 no runtime check is needed, and taking care not to convert 1398 no runtime check is needed, and taking care not to convert
1399 negative numbers to unsigned before comparing them. */ 1399 negative numbers to unsigned before comparing them. */
1400 if (! ((! TYPE_SIGNED (time_t) 1400 if (! ((! TYPE_SIGNED (time_t)
1401 || MOST_NEGATIVE_FIXNUM <= TIME_T_MIN >> 16 1401 || TIME_T_MIN >> 16 >= MOST_NEGATIVE_FIXNUM
1402 || MOST_NEGATIVE_FIXNUM <= hi) 1402 || hi >= MOST_NEGATIVE_FIXNUM)
1403 && (TIME_T_MAX >> 16 <= MOST_POSITIVE_FIXNUM 1403 && (TIME_T_MAX >> 16 <= MOST_POSITIVE_FIXNUM
1404 || hi <= MOST_POSITIVE_FIXNUM))) 1404 || hi <= MOST_POSITIVE_FIXNUM)))
1405 time_overflow (); 1405 time_overflow ();
@@ -1561,7 +1561,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1561 1561
1562 if (result) 1562 if (result)
1563 { 1563 {
1564 if ((TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 <= hi : 0 <= hi) 1564 if (hi >= (TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 : 0)
1565 && hi <= TIME_T_MAX >> 16) 1565 && hi <= TIME_T_MAX >> 16)
1566 { 1566 {
1567 /* Return the greatest representable time that is not greater 1567 /* Return the greatest representable time that is not greater
@@ -3958,7 +3958,7 @@ usage: (format STRING &rest OBJECTS) */)
3958 trailing "d"). */ 3958 trailing "d"). */
3959 pMlen = sizeof pMd - 2 3959 pMlen = sizeof pMd - 2
3960 }; 3960 };
3961 verify (0 < USEFUL_PRECISION_MAX); 3961 verify (USEFUL_PRECISION_MAX > 0);
3962 3962
3963 int prec; 3963 int prec;
3964 ptrdiff_t padding, sprintf_bytes; 3964 ptrdiff_t padding, sprintf_bytes;
@@ -4241,7 +4241,10 @@ usage: (format STRING &rest OBJECTS) */)
4241 memcpy (buf, initial_buffer, used); 4241 memcpy (buf, initial_buffer, used);
4242 } 4242 }
4243 else 4243 else
4244 XSAVE_POINTER (buf_save_value, 0) = buf = xrealloc (buf, bufsize); 4244 {
4245 buf = xrealloc (buf, bufsize);
4246 set_save_pointer (buf_save_value, 0, buf);
4247 }
4245 4248
4246 p = buf + used; 4249 p = buf + used;
4247 } 4250 }
diff --git a/src/emacs.c b/src/emacs.c
index 31191dceb3e..e2889f1adf5 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1083,7 +1083,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1083 1083
1084 noninteractive1 = noninteractive; 1084 noninteractive1 = noninteractive;
1085 1085
1086/* Perform basic initializations (not merely interning symbols). */ 1086 /* Perform basic initializations (not merely interning symbols). */
1087 1087
1088 if (!initialized) 1088 if (!initialized)
1089 { 1089 {
@@ -1094,8 +1094,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1094 init_coding_once (); 1094 init_coding_once ();
1095 init_syntax_once (); /* Create standard syntax table. */ 1095 init_syntax_once (); /* Create standard syntax table. */
1096 init_category_once (); /* Create standard category table. */ 1096 init_category_once (); /* Create standard category table. */
1097 /* Must be done before init_buffer. */ 1097 init_casetab_once (); /* Must be done before init_buffer_once. */
1098 init_casetab_once ();
1099 init_buffer_once (); /* Create buffer table and some buffers. */ 1098 init_buffer_once (); /* Create buffer table and some buffers. */
1100 init_minibuf_once (); /* Create list of minibuffers. */ 1099 init_minibuf_once (); /* Create list of minibuffers. */
1101 /* Must precede init_window_once. */ 1100 /* Must precede init_window_once. */
@@ -1120,6 +1119,8 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1120 syms_of_fileio (); 1119 syms_of_fileio ();
1121 /* Before syms_of_coding to initialize Vgc_cons_threshold. */ 1120 /* Before syms_of_coding to initialize Vgc_cons_threshold. */
1122 syms_of_alloc (); 1121 syms_of_alloc ();
1122 /* May call Ffuncall and so GC, thus the latter should be initialized. */
1123 init_print_once ();
1123 /* Before syms_of_coding because it initializes Qcharsetp. */ 1124 /* Before syms_of_coding because it initializes Qcharsetp. */
1124 syms_of_charset (); 1125 syms_of_charset ();
1125 /* Before init_window_once, because it sets up the 1126 /* Before init_window_once, because it sets up the
diff --git a/src/emacsgtkfixed.c b/src/emacsgtkfixed.c
index 9eedb57c81c..6df0b2422b1 100644
--- a/src/emacsgtkfixed.c
+++ b/src/emacsgtkfixed.c
@@ -30,7 +30,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#include "xwidget.h" 30#include "xwidget.h"
31#endif 31#endif
32/* Silence a bogus diagnostic; see GNOME bug 683906. */ 32/* Silence a bogus diagnostic; see GNOME bug 683906. */
33#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 33#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
34# pragma GCC diagnostic push 34# pragma GCC diagnostic push
35# pragma GCC diagnostic ignored "-Wunused-local-typedefs" 35# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
36#endif 36#endif
diff --git a/src/fileio.c b/src/fileio.c
index 724250c8aaa..1919768d98a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3449,7 +3449,7 @@ file_offset (Lisp_Object val)
3449 if (FLOATP (val)) 3449 if (FLOATP (val))
3450 { 3450 {
3451 double v = XFLOAT_DATA (val); 3451 double v = XFLOAT_DATA (val);
3452 if (0 <= v 3452 if (v >= 0
3453 && (sizeof (off_t) < sizeof v 3453 && (sizeof (off_t) < sizeof v
3454 ? v <= TYPE_MAXIMUM (off_t) 3454 ? v <= TYPE_MAXIMUM (off_t)
3455 : v < TYPE_MAXIMUM (off_t))) 3455 : v < TYPE_MAXIMUM (off_t)))
@@ -4218,7 +4218,8 @@ by calling `format-decode', which see. */)
4218 to be signaled after decoding the text we read. */ 4218 to be signaled after decoding the text we read. */
4219 nbytes = internal_condition_case_1 4219 nbytes = internal_condition_case_1
4220 (read_non_regular, 4220 (read_non_regular,
4221 make_save_value ("iii", (ptrdiff_t) fd, inserted, trytry), 4221 make_save_value (SAVE_TYPE_INT_INT_INT, (ptrdiff_t) fd,
4222 inserted, trytry),
4222 Qerror, read_non_regular_quit); 4223 Qerror, read_non_regular_quit);
4223 4224
4224 if (NILP (nbytes)) 4225 if (NILP (nbytes))
@@ -5012,7 +5013,7 @@ This calls `write-region-annotate-functions' at the start, and
5012 && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system)) 5013 && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system))
5013 { 5014 {
5014 int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0); 5015 int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0);
5015 if (0 <= desc1) 5016 if (desc1 >= 0)
5016 { 5017 {
5017 struct stat st1; 5018 struct stat st1;
5018 if (fstat (desc1, &st1) == 0 5019 if (fstat (desc1, &st1) == 0
diff --git a/src/floatfns.c b/src/floatfns.c
index 43576a16248..6113758f964 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -193,7 +193,7 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
193 CHECK_NUMBER_OR_FLOAT (arg2); 193 CHECK_NUMBER_OR_FLOAT (arg2);
194 if (INTEGERP (arg1) /* common lisp spec */ 194 if (INTEGERP (arg1) /* common lisp spec */
195 && INTEGERP (arg2) /* don't promote, if both are ints, and */ 195 && INTEGERP (arg2) /* don't promote, if both are ints, and */
196 && 0 <= XINT (arg2)) /* we are sure the result is not fractional */ 196 && XINT (arg2) >= 0) /* we are sure the result is not fractional */
197 { /* this can be improved by pre-calculating */ 197 { /* this can be improved by pre-calculating */
198 EMACS_INT y; /* some binary powers of x then accumulating */ 198 EMACS_INT y; /* some binary powers of x then accumulating */
199 EMACS_UINT acc, x; /* Unsigned so that overflow is well defined. */ 199 EMACS_UINT acc, x; /* Unsigned so that overflow is well defined. */
@@ -475,7 +475,7 @@ fmod_float (Lisp_Object x, Lisp_Object y)
475 f1 = fmod (f1, f2); 475 f1 = fmod (f1, f2);
476 476
477 /* If the "remainder" comes out with the wrong sign, fix it. */ 477 /* If the "remainder" comes out with the wrong sign, fix it. */
478 if (f2 < 0 ? 0 < f1 : f1 < 0) 478 if (f2 < 0 ? f1 > 0 : f1 < 0)
479 f1 += f2; 479 f1 += f2;
480 480
481 return make_float (f1); 481 return make_float (f1);
diff --git a/src/fns.c b/src/fns.c
index b3a1dc2317a..82ce933b25d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3409,7 +3409,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
3409 ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max 3409 ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max
3410 ? nitems_max : C_language_max); 3410 ? nitems_max : C_language_max);
3411 eassert (VECTORP (vec)); 3411 eassert (VECTORP (vec));
3412 eassert (0 < incr_min && -1 <= nitems_max); 3412 eassert (incr_min > 0 && nitems_max >= -1);
3413 old_size = ASIZE (vec); 3413 old_size = ASIZE (vec);
3414 incr_max = n_max - old_size; 3414 incr_max = n_max - old_size;
3415 incr = max (incr_min, min (old_size >> 1, incr_max)); 3415 incr = max (incr_min, min (old_size >> 1, incr_max));
@@ -3574,9 +3574,9 @@ make_hash_table (struct hash_table_test test,
3574 eassert (SYMBOLP (test.name)); 3574 eassert (SYMBOLP (test.name));
3575 eassert (INTEGERP (size) && XINT (size) >= 0); 3575 eassert (INTEGERP (size) && XINT (size) >= 0);
3576 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0) 3576 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
3577 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size))); 3577 || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1));
3578 eassert (FLOATP (rehash_threshold) 3578 eassert (FLOATP (rehash_threshold)
3579 && 0 < XFLOAT_DATA (rehash_threshold) 3579 && XFLOAT_DATA (rehash_threshold) > 0
3580 && XFLOAT_DATA (rehash_threshold) <= 1.0); 3580 && XFLOAT_DATA (rehash_threshold) <= 1.0);
3581 3581
3582 if (XFASTINT (size) == 0) 3582 if (XFASTINT (size) == 0)
@@ -4312,15 +4312,15 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
4312 /* Look for `:rehash-size SIZE'. */ 4312 /* Look for `:rehash-size SIZE'. */
4313 i = get_key_arg (QCrehash_size, nargs, args, used); 4313 i = get_key_arg (QCrehash_size, nargs, args, used);
4314 rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE); 4314 rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE);
4315 if (! ((INTEGERP (rehash_size) && 0 < XINT (rehash_size)) 4315 if (! ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
4316 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size)))) 4316 || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1)))
4317 signal_error ("Invalid hash table rehash size", rehash_size); 4317 signal_error ("Invalid hash table rehash size", rehash_size);
4318 4318
4319 /* Look for `:rehash-threshold THRESHOLD'. */ 4319 /* Look for `:rehash-threshold THRESHOLD'. */
4320 i = get_key_arg (QCrehash_threshold, nargs, args, used); 4320 i = get_key_arg (QCrehash_threshold, nargs, args, used);
4321 rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD); 4321 rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD);
4322 if (! (FLOATP (rehash_threshold) 4322 if (! (FLOATP (rehash_threshold)
4323 && 0 < XFLOAT_DATA (rehash_threshold) 4323 && XFLOAT_DATA (rehash_threshold) > 0
4324 && XFLOAT_DATA (rehash_threshold) <= 1)) 4324 && XFLOAT_DATA (rehash_threshold) <= 1))
4325 signal_error ("Invalid hash table rehash threshold", rehash_threshold); 4325 signal_error ("Invalid hash table rehash threshold", rehash_threshold);
4326 4326
diff --git a/src/font.c b/src/font.c
index db7bf352c94..357f8483b14 100644
--- a/src/font.c
+++ b/src/font.c
@@ -229,7 +229,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
229 229
230 if (len == 1 && *str == '*') 230 if (len == 1 && *str == '*')
231 return Qnil; 231 return Qnil;
232 if (!force_symbol && 0 < len && '0' <= *str && *str <= '9') 232 if (!force_symbol && len > 0 && '0' <= *str && *str <= '9')
233 { 233 {
234 for (i = 1; i < len; i++) 234 for (i = 1; i < len; i++)
235 if (! ('0' <= str[i] && str[i] <= '9')) 235 if (! ('0' <= str[i] && str[i] <= '9'))
@@ -243,7 +243,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
243 { 243 {
244 if (i == len) 244 if (i == len)
245 return make_number (n); 245 return make_number (n);
246 if (MOST_POSITIVE_FIXNUM / 10 < n) 246 if (n > MOST_POSITIVE_FIXNUM / 10)
247 break; 247 break;
248 } 248 }
249 249
@@ -287,7 +287,7 @@ font_pixel_size (FRAME_PTR f, Lisp_Object spec)
287 if (INTEGERP (val)) 287 if (INTEGERP (val))
288 dpi = XINT (val); 288 dpi = XINT (val);
289 else 289 else
290 dpi = f->resy; 290 dpi = FRAME_RES_Y (f);
291 pixel_size = POINT_TO_PIXEL (point_size, dpi); 291 pixel_size = POINT_TO_PIXEL (point_size, dpi);
292 return pixel_size; 292 return pixel_size;
293#else 293#else
@@ -3117,7 +3117,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3117 { 3117 {
3118 double pt = XINT (attrs[LFACE_HEIGHT_INDEX]); 3118 double pt = XINT (attrs[LFACE_HEIGHT_INDEX]);
3119 3119
3120 pixel_size = POINT_TO_PIXEL (pt / 10, f->resy); 3120 pixel_size = POINT_TO_PIXEL (pt / 10, FRAME_RES_Y (f));
3121 } 3121 }
3122 ASET (work, FONT_SIZE_INDEX, Qnil); 3122 ASET (work, FONT_SIZE_INDEX, Qnil);
3123 foundry[0] = AREF (work, FONT_FOUNDRY_INDEX); 3123 foundry[0] = AREF (work, FONT_FOUNDRY_INDEX);
@@ -3247,12 +3247,13 @@ font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_O
3247 } 3247 }
3248 3248
3249 pt /= 10; 3249 pt /= 10;
3250 size = POINT_TO_PIXEL (pt, f->resy); 3250 size = POINT_TO_PIXEL (pt, FRAME_RES_Y (f));
3251#ifdef HAVE_NS 3251#ifdef HAVE_NS
3252 if (size == 0) 3252 if (size == 0)
3253 { 3253 {
3254 Lisp_Object ffsize = get_frame_param (f, Qfontsize); 3254 Lisp_Object ffsize = get_frame_param (f, Qfontsize);
3255 size = NUMBERP (ffsize) ? POINT_TO_PIXEL (XINT (ffsize), f->resy) : 0; 3255 size = (NUMBERP (ffsize)
3256 ? POINT_TO_PIXEL (XINT (ffsize), FRAME_RES_Y (f)) : 0);
3256 } 3257 }
3257#endif 3258#endif
3258 } 3259 }
@@ -4021,7 +4022,7 @@ are to be displayed on. If omitted, the selected frame is used. */)
4021 if (INTEGERP (val)) 4022 if (INTEGERP (val))
4022 { 4023 {
4023 Lisp_Object font_dpi = AREF (font, FONT_DPI_INDEX); 4024 Lisp_Object font_dpi = AREF (font, FONT_DPI_INDEX);
4024 int dpi = INTEGERP (font_dpi) ? XINT (font_dpi) : f->resy; 4025 int dpi = INTEGERP (font_dpi) ? XINT (font_dpi) : FRAME_RES_Y (f);
4025 plist[n++] = QCheight; 4026 plist[n++] = QCheight;
4026 plist[n++] = make_number (PIXEL_TO_POINT (XINT (val) * 10, dpi)); 4027 plist[n++] = make_number (PIXEL_TO_POINT (XINT (val) * 10, dpi));
4027 } 4028 }
@@ -4532,7 +4533,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4532 { 4533 {
4533 CHECK_NUMBER_OR_FLOAT (size); 4534 CHECK_NUMBER_OR_FLOAT (size);
4534 if (FLOATP (size)) 4535 if (FLOATP (size))
4535 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), f->resy); 4536 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f));
4536 else 4537 else
4537 isize = XINT (size); 4538 isize = XINT (size);
4538 if (! (INT_MIN <= isize && isize <= INT_MAX)) 4539 if (! (INT_MIN <= isize && isize <= INT_MAX))
diff --git a/src/frame.c b/src/frame.c
index 0fa821682f3..cea39144cef 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -155,8 +155,8 @@ set_menu_bar_lines_1 (Lisp_Object window, int n)
155 struct window *w = XWINDOW (window); 155 struct window *w = XWINDOW (window);
156 156
157 w->last_modified = 0; 157 w->last_modified = 0;
158 wset_top_line (w, make_number (XFASTINT (w->top_line) + n)); 158 w->top_line += n;
159 wset_total_lines (w, make_number (XFASTINT (w->total_lines) - n)); 159 w->total_lines -= n;
160 160
161 /* Handle just the top child in a vertical split. */ 161 /* Handle just the top child in a vertical split. */
162 if (!NILP (w->vchild)) 162 if (!NILP (w->vchild))
@@ -332,14 +332,14 @@ make_frame (int mini_p)
332 SET_FRAME_COLS (f, 10); 332 SET_FRAME_COLS (f, 10);
333 FRAME_LINES (f) = 10; 333 FRAME_LINES (f) = 10;
334 334
335 wset_total_cols (XWINDOW (root_window), make_number (10)); 335 XWINDOW (root_window)->total_cols = 10;
336 wset_total_lines (XWINDOW (root_window), make_number (mini_p ? 9 : 10)); 336 XWINDOW (root_window)->total_lines = mini_p ? 9 : 10;
337 337
338 if (mini_p) 338 if (mini_p)
339 { 339 {
340 wset_total_cols (XWINDOW (mini_window), make_number (10)); 340 XWINDOW (mini_window)->total_cols = 10;
341 wset_top_line (XWINDOW (mini_window), make_number (9)); 341 XWINDOW (mini_window)->top_line = 9;
342 wset_total_lines (XWINDOW (mini_window), make_number (1)); 342 XWINDOW (mini_window)->total_lines = 1;
343 } 343 }
344 344
345 /* Choose a buffer for the frame's root window. */ 345 /* Choose a buffer for the frame's root window. */
@@ -1819,7 +1819,7 @@ See `redirect-frame-focus'. */)
1819/* Return the value of frame parameter PROP in frame FRAME. */ 1819/* Return the value of frame parameter PROP in frame FRAME. */
1820 1820
1821#ifdef HAVE_WINDOW_SYSTEM 1821#ifdef HAVE_WINDOW_SYSTEM
1822#if !HAVE_NS 1822#if !HAVE_NS && !defined(WINDOWSNT)
1823static 1823static
1824#endif 1824#endif
1825Lisp_Object 1825Lisp_Object
@@ -3315,13 +3315,13 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3315 else if (FLOATP (item)) 3315 else if (FLOATP (item))
3316 { 3316 {
3317 alpha = XFLOAT_DATA (item); 3317 alpha = XFLOAT_DATA (item);
3318 if (alpha < 0.0 || 1.0 < alpha) 3318 if (alpha < 0.0 || alpha > 1.0)
3319 args_out_of_range (make_float (0.0), make_float (1.0)); 3319 args_out_of_range (make_float (0.0), make_float (1.0));
3320 } 3320 }
3321 else if (INTEGERP (item)) 3321 else if (INTEGERP (item))
3322 { 3322 {
3323 EMACS_INT ialpha = XINT (item); 3323 EMACS_INT ialpha = XINT (item);
3324 if (ialpha < 0 || 100 < ialpha) 3324 if (ialpha < 0 || ialpha > 100)
3325 args_out_of_range (make_number (0), make_number (100)); 3325 args_out_of_range (make_number (0), make_number (100));
3326 else 3326 else
3327 alpha = ialpha / 100.0; 3327 alpha = ialpha / 100.0;
@@ -3495,7 +3495,8 @@ The optional arguments COMPONENT and SUBCLASS add to the key and the
3495class, respectively. You must specify both of them or neither. 3495class, respectively. You must specify both of them or neither.
3496If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE' 3496If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3497and the class is `Emacs.CLASS.SUBCLASS'. */) 3497and the class is `Emacs.CLASS.SUBCLASS'. */)
3498 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass) 3498 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3499 Lisp_Object subclass)
3499{ 3500{
3500#ifdef HAVE_X_WINDOWS 3501#ifdef HAVE_X_WINDOWS
3501 check_x (); 3502 check_x ();
@@ -3508,7 +3509,9 @@ and the class is `Emacs.CLASS.SUBCLASS'. */)
3508/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */ 3509/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3509 3510
3510Lisp_Object 3511Lisp_Object
3511display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass) 3512display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
3513 Lisp_Object class, Lisp_Object component,
3514 Lisp_Object subclass)
3512{ 3515{
3513 return xrdb_get_resource (dpyinfo->xrdb, 3516 return xrdb_get_resource (dpyinfo->xrdb,
3514 attribute, class, component, subclass); 3517 attribute, class, component, subclass);
diff --git a/src/frame.h b/src/frame.h
index c18b7662079..32a6954024e 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -170,9 +170,11 @@ struct frame
170 most recently buried buffer is first. For last-buffer. */ 170 most recently buried buffer is first. For last-buffer. */
171 Lisp_Object buried_buffer_list; 171 Lisp_Object buried_buffer_list;
172 172
173#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
173 /* A dummy window used to display menu bars under X when no X 174 /* A dummy window used to display menu bars under X when no X
174 toolkit support is available. */ 175 toolkit support is available. */
175 Lisp_Object menu_bar_window; 176 Lisp_Object menu_bar_window;
177#endif
176 178
177 /* A window used to display the tool-bar of a frame. */ 179 /* A window used to display the tool-bar of a frame. */
178 Lisp_Object tool_bar_window; 180 Lisp_Object tool_bar_window;
@@ -276,9 +278,6 @@ struct frame
276 /* Size of the frame window in pixels. */ 278 /* Size of the frame window in pixels. */
277 int pixel_height, pixel_width; 279 int pixel_height, pixel_width;
278 280
279 /* Dots per inch of the screen the frame is on. */
280 double resx, resy;
281
282 /* These many pixels are the difference between the outer window (i.e. the 281 /* These many pixels are the difference between the outer window (i.e. the
283 left and top of the window manager decoration) and FRAME_X_WINDOW. */ 282 left and top of the window manager decoration) and FRAME_X_WINDOW. */
284 int x_pixels_diff, y_pixels_diff; 283 int x_pixels_diff, y_pixels_diff;
@@ -518,11 +517,13 @@ fset_menu_bar_vector (struct frame *f, Lisp_Object val)
518{ 517{
519 f->menu_bar_vector = val; 518 f->menu_bar_vector = val;
520} 519}
520#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
521FRAME_INLINE void 521FRAME_INLINE void
522fset_menu_bar_window (struct frame *f, Lisp_Object val) 522fset_menu_bar_window (struct frame *f, Lisp_Object val)
523{ 523{
524 f->menu_bar_window = val; 524 f->menu_bar_window = val;
525} 525}
526#endif
526FRAME_INLINE void 527FRAME_INLINE void
527fset_name (struct frame *f, Lisp_Object val) 528fset_name (struct frame *f, Lisp_Object val)
528{ 529{
@@ -569,6 +570,26 @@ fset_tool_bar_window (struct frame *f, Lisp_Object val)
569 f->tool_bar_window = val; 570 f->tool_bar_window = val;
570} 571}
571 572
573#define NUMVAL(X) ((INTEGERP (X) || FLOATP (X)) ? XFLOATINT (X) : -1)
574
575FRAME_INLINE double
576default_pixels_per_inch_x (void)
577{
578 Lisp_Object v = (CONSP (Vdisplay_pixels_per_inch)
579 ? XCAR (Vdisplay_pixels_per_inch)
580 : Vdisplay_pixels_per_inch);
581 return NUMVAL (v) > 0 ? NUMVAL (v) : 72.0;
582}
583
584FRAME_INLINE double
585default_pixels_per_inch_y (void)
586{
587 Lisp_Object v = (CONSP (Vdisplay_pixels_per_inch)
588 ? XCDR (Vdisplay_pixels_per_inch)
589 : Vdisplay_pixels_per_inch);
590 return NUMVAL (v) > 0 ? NUMVAL (v) : 72.0;
591}
592
572#define FRAME_KBOARD(f) ((f)->terminal->kboard) 593#define FRAME_KBOARD(f) ((f)->terminal->kboard)
573 594
574/* Return a pointer to the image cache of frame F. */ 595/* Return a pointer to the image cache of frame F. */
@@ -602,6 +623,37 @@ typedef struct frame *FRAME_PTR;
602#else 623#else
603#define FRAME_NS_P(f) ((f)->output_method == output_ns) 624#define FRAME_NS_P(f) ((f)->output_method == output_ns)
604#endif 625#endif
626
627/* Dots per inch of the screen the frame F is on. */
628
629#ifdef HAVE_X_WINDOWS
630#define FRAME_RES_X(f) \
631 (eassert (FRAME_X_P (f)), FRAME_X_DISPLAY_INFO (f)->resx)
632#define FRAME_RES_Y(f) \
633 (eassert (FRAME_X_P (f)), FRAME_X_DISPLAY_INFO (f)->resy)
634#endif
635
636#ifdef HAVE_NTGUI
637#define FRAME_RES_X(f) \
638 (eassert (FRAME_W32_P (f)), FRAME_W32_DISPLAY_INFO (f)->resx)
639#define FRAME_RES_Y(f) \
640 (eassert (FRAME_W32_P (f)), FRAME_W32_DISPLAY_INFO (f)->resy)
641#endif
642
643#ifdef HAVE_NS
644#define FRAME_RES_X(f) \
645 (eassert (FRAME_NS_P (f)), FRAME_NS_DISPLAY_INFO (f)->resx)
646#define FRAME_RES_Y(f) \
647 (eassert (FRAME_NS_P (f)), FRAME_NS_DISPLAY_INFO (f)->resy)
648#endif
649
650/* Defaults when no window system available. */
651
652#ifndef FRAME_RES_X
653#define FRAME_RES_X(f) default_pixels_per_inch_x ()
654#define FRAME_RES_Y(f) default_pixels_per_inch_y ()
655#endif
656
605/* FRAME_WINDOW_P tests whether the frame is a window, and is 657/* FRAME_WINDOW_P tests whether the frame is a window, and is
606 defined to be the predicate for the window system being used. */ 658 defined to be the predicate for the window system being used. */
607 659
diff --git a/src/ftfont.c b/src/ftfont.c
index 867e25a7a25..0ad173af98a 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -393,7 +393,7 @@ ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for)
393 cache_data = xmalloc (sizeof *cache_data); 393 cache_data = xmalloc (sizeof *cache_data);
394 cache_data->ft_face = NULL; 394 cache_data->ft_face = NULL;
395 cache_data->fc_charset = NULL; 395 cache_data->fc_charset = NULL;
396 val = make_save_value ("pi", cache_data, 0); 396 val = make_save_value (SAVE_TYPE_PTR_INT, cache_data, 0);
397 cache = Fcons (Qnil, val); 397 cache = Fcons (Qnil, val);
398 Fputhash (key, cache, ft_face_cache); 398 Fputhash (key, cache, ft_face_cache);
399 } 399 }
@@ -1211,7 +1211,7 @@ ftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
1211 return Qnil; 1211 return Qnil;
1212 } 1212 }
1213 } 1213 }
1214 XSAVE_INTEGER (val, 1)++; 1214 set_save_integer (val, 1, XSAVE_INTEGER (val, 1) + 1);
1215 size = XINT (AREF (entity, FONT_SIZE_INDEX)); 1215 size = XINT (AREF (entity, FONT_SIZE_INDEX));
1216 if (size == 0) 1216 if (size == 0)
1217 size = pixel_size; 1217 size = pixel_size;
@@ -1326,7 +1326,7 @@ ftfont_close (FRAME_PTR f, struct font *font)
1326 cache = ftfont_lookup_cache (val, FTFONT_CACHE_FOR_FACE); 1326 cache = ftfont_lookup_cache (val, FTFONT_CACHE_FOR_FACE);
1327 eassert (CONSP (cache)); 1327 eassert (CONSP (cache));
1328 val = XCDR (cache); 1328 val = XCDR (cache);
1329 XSAVE_INTEGER (val, 1)--; 1329 set_save_integer (val, 1, XSAVE_INTEGER (val, 1) - 1);
1330 if (XSAVE_INTEGER (val, 1) == 0) 1330 if (XSAVE_INTEGER (val, 1) == 0)
1331 { 1331 {
1332 struct ftfont_cache_data *cache_data = XSAVE_POINTER (val, 0); 1332 struct ftfont_cache_data *cache_data = XSAVE_POINTER (val, 0);
diff --git a/src/gtkutil.c b/src/gtkutil.c
index d6e4dcebcd3..2bb4305e1d2 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -543,7 +543,7 @@ get_utf8_string (const char *str)
543 if (cp) g_free (cp); 543 if (cp) g_free (cp);
544 544
545 len = strlen (str); 545 len = strlen (str);
546 if ((min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4 < nr_bad) 546 if (nr_bad > (min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4)
547 memory_full (SIZE_MAX); 547 memory_full (SIZE_MAX);
548 up = utf8_str = xmalloc (len + nr_bad * 4 + 1); 548 up = utf8_str = xmalloc (len + nr_bad * 4 + 1);
549 p = (unsigned char *)str; 549 p = (unsigned char *)str;
diff --git a/src/image.c b/src/image.c
index 2d4e7e731ad..21f486176df 100644
--- a/src/image.c
+++ b/src/image.c
@@ -68,8 +68,6 @@ typedef struct x_bitmap_record Bitmap_Record;
68#define GET_PIXEL(ximg, x, y) XGetPixel (ximg, x, y) 68#define GET_PIXEL(ximg, x, y) XGetPixel (ximg, x, y)
69#define NO_PIXMAP None 69#define NO_PIXMAP None
70 70
71#define RGB_PIXEL_COLOR unsigned long
72
73#define PIX_MASK_RETAIN 0 71#define PIX_MASK_RETAIN 0
74#define PIX_MASK_DRAW 1 72#define PIX_MASK_DRAW 1
75#endif /* HAVE_X_WINDOWS */ 73#endif /* HAVE_X_WINDOWS */
@@ -88,8 +86,6 @@ typedef struct w32_bitmap_record Bitmap_Record;
88#define GET_PIXEL(ximg, x, y) GetPixel (ximg, x, y) 86#define GET_PIXEL(ximg, x, y) GetPixel (ximg, x, y)
89#define NO_PIXMAP 0 87#define NO_PIXMAP 0
90 88
91#define RGB_PIXEL_COLOR COLORREF
92
93#define PIX_MASK_RETAIN 0 89#define PIX_MASK_RETAIN 0
94#define PIX_MASK_DRAW 1 90#define PIX_MASK_DRAW 1
95 91
@@ -110,7 +106,6 @@ typedef struct ns_bitmap_record Bitmap_Record;
110#define GET_PIXEL(ximg, x, y) XGetPixel (ximg, x, y) 106#define GET_PIXEL(ximg, x, y) XGetPixel (ximg, x, y)
111#define NO_PIXMAP 0 107#define NO_PIXMAP 0
112 108
113#define RGB_PIXEL_COLOR unsigned long
114#define ZPixmap 0 109#define ZPixmap 0
115 110
116#define PIX_MASK_RETAIN 0 111#define PIX_MASK_RETAIN 0
@@ -159,15 +154,15 @@ XGetImage (Display *display, Pixmap pixmap, int x, int y,
159 return pixmap; 154 return pixmap;
160} 155}
161 156
162/* use with imgs created by ns_image_for_XPM */ 157/* Use with images created by ns_image_for_XPM. */
163unsigned long 158unsigned long
164XGetPixel (XImagePtr ximage, int x, int y) 159XGetPixel (XImagePtr ximage, int x, int y)
165{ 160{
166 return ns_get_pixel (ximage, x, y); 161 return ns_get_pixel (ximage, x, y);
167} 162}
168 163
169/* use with imgs created by ns_image_for_XPM; alpha set to 1; 164/* Use with images created by ns_image_for_XPM; alpha set to 1;
170 pixel is assumed to be in form RGB */ 165 pixel is assumed to be in RGB form. */
171void 166void
172XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel) 167XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel)
173{ 168{
@@ -7378,11 +7373,10 @@ gif_load (struct frame *f, struct image *img)
7378 y < subimg_height; 7373 y < subimg_height;
7379 y++, row += interlace_increment[pass]) 7374 y++, row += interlace_increment[pass])
7380 { 7375 {
7381 if (row >= subimg_height) 7376 while (subimg_height <= row)
7382 { 7377 {
7378 lint_assume (pass < 3);
7383 row = interlace_start[++pass]; 7379 row = interlace_start[++pass];
7384 while (row >= subimg_height)
7385 row = interlace_start[++pass];
7386 } 7380 }
7387 7381
7388 for (x = 0; x < subimg_width; x++) 7382 for (x = 0; x < subimg_width; x++)
@@ -8559,10 +8553,10 @@ gs_load (struct frame *f, struct image *img)
8559 info. */ 8553 info. */
8560 pt_width = image_spec_value (img->spec, QCpt_width, NULL); 8554 pt_width = image_spec_value (img->spec, QCpt_width, NULL);
8561 in_width = INTEGERP (pt_width) ? XFASTINT (pt_width) / 72.0 : 0; 8555 in_width = INTEGERP (pt_width) ? XFASTINT (pt_width) / 72.0 : 0;
8562 in_width *= FRAME_X_DISPLAY_INFO (f)->resx; 8556 in_width *= FRAME_RES_X (f);
8563 pt_height = image_spec_value (img->spec, QCpt_height, NULL); 8557 pt_height = image_spec_value (img->spec, QCpt_height, NULL);
8564 in_height = INTEGERP (pt_height) ? XFASTINT (pt_height) / 72.0 : 0; 8558 in_height = INTEGERP (pt_height) ? XFASTINT (pt_height) / 72.0 : 0;
8565 in_height *= FRAME_X_DISPLAY_INFO (f)->resy; 8559 in_height *= FRAME_RES_Y (f);
8566 8560
8567 if (! (in_width <= INT_MAX && in_height <= INT_MAX 8561 if (! (in_width <= INT_MAX && in_height <= INT_MAX
8568 && check_image_size (f, in_width, in_height))) 8562 && check_image_size (f, in_width, in_height)))
diff --git a/src/indent.c b/src/indent.c
index d1f95da6bcf..ac448532dd4 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -476,7 +476,7 @@ check_display_width (ptrdiff_t pos, ptrdiff_t col, ptrdiff_t *endpos)
476 if ((prop = Fplist_get (plist, QCwidth), 476 if ((prop = Fplist_get (plist, QCwidth),
477 RANGED_INTEGERP (0, prop, INT_MAX))) 477 RANGED_INTEGERP (0, prop, INT_MAX)))
478 width = XINT (prop); 478 width = XINT (prop);
479 else if (FLOATP (prop) && 0 <= XFLOAT_DATA (prop) 479 else if (FLOATP (prop) && XFLOAT_DATA (prop) >= 0
480 && XFLOAT_DATA (prop) <= INT_MAX) 480 && XFLOAT_DATA (prop) <= INT_MAX)
481 width = (int)(XFLOAT_DATA (prop) + 0.5); 481 width = (int)(XFLOAT_DATA (prop) + 0.5);
482 else if ((prop = Fplist_get (plist, QCalign_to), 482 else if ((prop = Fplist_get (plist, QCalign_to),
diff --git a/src/intervals.c b/src/intervals.c
index db38c86c00b..f65ce0ecc77 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -110,14 +110,14 @@ create_root_interval (Lisp_Object parent)
110 { 110 {
111 new->total_length = (BUF_Z (XBUFFER (parent)) 111 new->total_length = (BUF_Z (XBUFFER (parent))
112 - BUF_BEG (XBUFFER (parent))); 112 - BUF_BEG (XBUFFER (parent)));
113 eassert (0 <= TOTAL_LENGTH (new)); 113 eassert (TOTAL_LENGTH (new) >= 0);
114 set_buffer_intervals (XBUFFER (parent), new); 114 set_buffer_intervals (XBUFFER (parent), new);
115 new->position = BEG; 115 new->position = BEG;
116 } 116 }
117 else if (STRINGP (parent)) 117 else if (STRINGP (parent))
118 { 118 {
119 new->total_length = SCHARS (parent); 119 new->total_length = SCHARS (parent);
120 eassert (0 <= TOTAL_LENGTH (new)); 120 eassert (TOTAL_LENGTH (new) >= 0);
121 set_string_intervals (parent, new); 121 set_string_intervals (parent, new);
122 new->position = 0; 122 new->position = 0;
123 } 123 }
@@ -371,11 +371,11 @@ rotate_right (INTERVAL interval)
371 371
372 /* A's total length is decreased by the length of B and its left child. */ 372 /* A's total length is decreased by the length of B and its left child. */
373 interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); 373 interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);
374 eassert (0 <= TOTAL_LENGTH (interval)); 374 eassert (TOTAL_LENGTH (interval) >= 0);
375 375
376 /* B must have the same total length of A. */ 376 /* B must have the same total length of A. */
377 B->total_length = old_total; 377 B->total_length = old_total;
378 eassert (0 <= TOTAL_LENGTH (B)); 378 eassert (TOTAL_LENGTH (B) >= 0);
379 379
380 return B; 380 return B;
381} 381}
@@ -418,11 +418,11 @@ rotate_left (INTERVAL interval)
418 418
419 /* A's total length is decreased by the length of B and its right child. */ 419 /* A's total length is decreased by the length of B and its right child. */
420 interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); 420 interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval);
421 eassert (0 <= TOTAL_LENGTH (interval)); 421 eassert (TOTAL_LENGTH (interval) >= 0);
422 422
423 /* B must have the same total length of A. */ 423 /* B must have the same total length of A. */
424 B->total_length = old_total; 424 B->total_length = old_total;
425 eassert (0 <= TOTAL_LENGTH (B)); 425 eassert (TOTAL_LENGTH (B) >= 0);
426 426
427 return B; 427 return B;
428} 428}
@@ -556,7 +556,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset)
556 { 556 {
557 set_interval_right (interval, new); 557 set_interval_right (interval, new);
558 new->total_length = new_length; 558 new->total_length = new_length;
559 eassert (0 <= TOTAL_LENGTH (new)); 559 eassert (TOTAL_LENGTH (new) >= 0);
560 } 560 }
561 else 561 else
562 { 562 {
@@ -565,7 +565,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset)
565 set_interval_parent (interval->right, new); 565 set_interval_parent (interval->right, new);
566 set_interval_right (interval, new); 566 set_interval_right (interval, new);
567 new->total_length = new_length + new->right->total_length; 567 new->total_length = new_length + new->right->total_length;
568 eassert (0 <= TOTAL_LENGTH (new)); 568 eassert (TOTAL_LENGTH (new) >= 0);
569 balance_an_interval (new); 569 balance_an_interval (new);
570 } 570 }
571 571
@@ -601,7 +601,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset)
601 { 601 {
602 set_interval_left (interval, new); 602 set_interval_left (interval, new);
603 new->total_length = new_length; 603 new->total_length = new_length;
604 eassert (0 <= TOTAL_LENGTH (new)); 604 eassert (TOTAL_LENGTH (new) >= 0);
605 } 605 }
606 else 606 else
607 { 607 {
@@ -610,7 +610,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset)
610 set_interval_parent (new->left, new); 610 set_interval_parent (new->left, new);
611 set_interval_left (interval, new); 611 set_interval_left (interval, new);
612 new->total_length = new_length + new->left->total_length; 612 new->total_length = new_length + new->left->total_length;
613 eassert (0 <= TOTAL_LENGTH (new)); 613 eassert (TOTAL_LENGTH (new) >= 0);
614 balance_an_interval (new); 614 balance_an_interval (new);
615 } 615 }
616 616
@@ -960,7 +960,7 @@ adjust_intervals_for_insertion (INTERVAL tree,
960 for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) 960 for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
961 { 961 {
962 temp->total_length += length; 962 temp->total_length += length;
963 eassert (0 <= TOTAL_LENGTH (temp)); 963 eassert (TOTAL_LENGTH (temp) >= 0);
964 temp = balance_possible_root_interval (temp); 964 temp = balance_possible_root_interval (temp);
965 } 965 }
966 966
@@ -1016,7 +1016,7 @@ adjust_intervals_for_insertion (INTERVAL tree,
1016 for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) 1016 for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp))
1017 { 1017 {
1018 temp->total_length += length; 1018 temp->total_length += length;
1019 eassert (0 <= TOTAL_LENGTH (temp)); 1019 eassert (TOTAL_LENGTH (temp) >= 0);
1020 temp = balance_possible_root_interval (temp); 1020 temp = balance_possible_root_interval (temp);
1021 } 1021 }
1022 } 1022 }
@@ -1218,7 +1218,7 @@ delete_node (register INTERVAL i)
1218 this = this->left; 1218 this = this->left;
1219 this->total_length += migrate_amt; 1219 this->total_length += migrate_amt;
1220 } 1220 }
1221 eassert (0 <= TOTAL_LENGTH (this)); 1221 eassert (TOTAL_LENGTH (this) >= 0);
1222 set_interval_left (this, migrate); 1222 set_interval_left (this, migrate);
1223 set_interval_parent (migrate, this); 1223 set_interval_parent (migrate, this);
1224 1224
@@ -1300,7 +1300,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from,
1300 relative_position, 1300 relative_position,
1301 amount); 1301 amount);
1302 tree->total_length -= subtract; 1302 tree->total_length -= subtract;
1303 eassert (0 <= TOTAL_LENGTH (tree)); 1303 eassert (TOTAL_LENGTH (tree) >= 0);
1304 return subtract; 1304 return subtract;
1305 } 1305 }
1306 /* Right branch. */ 1306 /* Right branch. */
@@ -1315,7 +1315,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from,
1315 relative_position, 1315 relative_position,
1316 amount); 1316 amount);
1317 tree->total_length -= subtract; 1317 tree->total_length -= subtract;
1318 eassert (0 <= TOTAL_LENGTH (tree)); 1318 eassert (TOTAL_LENGTH (tree) >= 0);
1319 return subtract; 1319 return subtract;
1320 } 1320 }
1321 /* Here -- this node. */ 1321 /* Here -- this node. */
@@ -1330,7 +1330,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from,
1330 amount = my_amount; 1330 amount = my_amount;
1331 1331
1332 tree->total_length -= amount; 1332 tree->total_length -= amount;
1333 eassert (0 <= TOTAL_LENGTH (tree)); 1333 eassert (TOTAL_LENGTH (tree) >= 0);
1334 if (LENGTH (tree) == 0) 1334 if (LENGTH (tree) == 0)
1335 delete_interval (tree); 1335 delete_interval (tree);
1336 1336
@@ -1372,7 +1372,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1372 if (ONLY_INTERVAL_P (tree)) 1372 if (ONLY_INTERVAL_P (tree))
1373 { 1373 {
1374 tree->total_length -= length; 1374 tree->total_length -= length;
1375 eassert (0 <= TOTAL_LENGTH (tree)); 1375 eassert (TOTAL_LENGTH (tree) >= 0);
1376 return; 1376 return;
1377 } 1377 }
1378 1378
@@ -1435,19 +1435,19 @@ merge_interval_right (register INTERVAL i)
1435 while (! NULL_LEFT_CHILD (successor)) 1435 while (! NULL_LEFT_CHILD (successor))
1436 { 1436 {
1437 successor->total_length += absorb; 1437 successor->total_length += absorb;
1438 eassert (0 <= TOTAL_LENGTH (successor)); 1438 eassert (TOTAL_LENGTH (successor) >= 0);
1439 successor = successor->left; 1439 successor = successor->left;
1440 } 1440 }
1441 1441
1442 successor->total_length += absorb; 1442 successor->total_length += absorb;
1443 eassert (0 <= TOTAL_LENGTH (successor)); 1443 eassert (TOTAL_LENGTH (successor) >= 0);
1444 delete_interval (i); 1444 delete_interval (i);
1445 return successor; 1445 return successor;
1446 } 1446 }
1447 1447
1448 /* Zero out this interval. */ 1448 /* Zero out this interval. */
1449 i->total_length -= absorb; 1449 i->total_length -= absorb;
1450 eassert (0 <= TOTAL_LENGTH (i)); 1450 eassert (TOTAL_LENGTH (i) >= 0);
1451 1451
1452 successor = i; 1452 successor = i;
1453 while (! NULL_PARENT (successor)) /* It's above us. Subtract as 1453 while (! NULL_PARENT (successor)) /* It's above us. Subtract as
@@ -1462,7 +1462,7 @@ merge_interval_right (register INTERVAL i)
1462 1462
1463 successor = INTERVAL_PARENT (successor); 1463 successor = INTERVAL_PARENT (successor);
1464 successor->total_length -= absorb; 1464 successor->total_length -= absorb;
1465 eassert (0 <= TOTAL_LENGTH (successor)); 1465 eassert (TOTAL_LENGTH (successor) >= 0);
1466 } 1466 }
1467 1467
1468 /* This must be the rightmost or last interval and cannot 1468 /* This must be the rightmost or last interval and cannot
@@ -1491,19 +1491,19 @@ merge_interval_left (register INTERVAL i)
1491 while (! NULL_RIGHT_CHILD (predecessor)) 1491 while (! NULL_RIGHT_CHILD (predecessor))
1492 { 1492 {
1493 predecessor->total_length += absorb; 1493 predecessor->total_length += absorb;
1494 eassert (0 <= TOTAL_LENGTH (predecessor)); 1494 eassert (TOTAL_LENGTH (predecessor) >= 0);
1495 predecessor = predecessor->right; 1495 predecessor = predecessor->right;
1496 } 1496 }
1497 1497
1498 predecessor->total_length += absorb; 1498 predecessor->total_length += absorb;
1499 eassert (0 <= TOTAL_LENGTH (predecessor)); 1499 eassert (TOTAL_LENGTH (predecessor) >= 0);
1500 delete_interval (i); 1500 delete_interval (i);
1501 return predecessor; 1501 return predecessor;
1502 } 1502 }
1503 1503
1504 /* Zero out this interval. */ 1504 /* Zero out this interval. */
1505 i->total_length -= absorb; 1505 i->total_length -= absorb;
1506 eassert (0 <= TOTAL_LENGTH (i)); 1506 eassert (TOTAL_LENGTH (i) >= 0);
1507 1507
1508 predecessor = i; 1508 predecessor = i;
1509 while (! NULL_PARENT (predecessor)) /* It's above us. Go up, 1509 while (! NULL_PARENT (predecessor)) /* It's above us. Go up,
@@ -1518,7 +1518,7 @@ merge_interval_left (register INTERVAL i)
1518 1518
1519 predecessor = INTERVAL_PARENT (predecessor); 1519 predecessor = INTERVAL_PARENT (predecessor);
1520 predecessor->total_length -= absorb; 1520 predecessor->total_length -= absorb;
1521 eassert (0 <= TOTAL_LENGTH (predecessor)); 1521 eassert (TOTAL_LENGTH (predecessor) >= 0);
1522 } 1522 }
1523 1523
1524 /* This must be the leftmost or first interval and cannot 1524 /* This must be the leftmost or first interval and cannot
@@ -2272,7 +2272,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length)
2272 new->position = 0; 2272 new->position = 0;
2273 got = (LENGTH (i) - (start - i->position)); 2273 got = (LENGTH (i) - (start - i->position));
2274 new->total_length = length; 2274 new->total_length = length;
2275 eassert (0 <= TOTAL_LENGTH (new)); 2275 eassert (TOTAL_LENGTH (new) >= 0);
2276 copy_properties (i, new); 2276 copy_properties (i, new);
2277 2277
2278 t = new; 2278 t = new;
@@ -2355,7 +2355,7 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
2355 i->total_length = end - start; 2355 i->total_length = end - start;
2356 else 2356 else
2357 i->total_length = end_byte - start_byte; 2357 i->total_length = end_byte - start_byte;
2358 eassert (0 <= TOTAL_LENGTH (i)); 2358 eassert (TOTAL_LENGTH (i) >= 0);
2359 2359
2360 if (TOTAL_LENGTH (i) == 0) 2360 if (TOTAL_LENGTH (i) == 0)
2361 { 2361 {
diff --git a/src/keyboard.c b/src/keyboard.c
index cf05d2f3855..d373935f3e4 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6785,7 +6785,7 @@ gobble_input (void)
6785 hold_quit.kind = NO_EVENT; 6785 hold_quit.kind = NO_EVENT;
6786 6786
6787 /* No need for FIONREAD or fcntl; just say don't wait. */ 6787 /* No need for FIONREAD or fcntl; just say don't wait. */
6788 while (0 < (nr = (*t->read_socket_hook) (t, &hold_quit))) 6788 while ((nr = (*t->read_socket_hook) (t, &hold_quit)) > 0)
6789 nread += nr; 6789 nread += nr;
6790 6790
6791 if (nr == -1) /* Not OK to read input now. */ 6791 if (nr == -1) /* Not OK to read input now. */
@@ -8259,9 +8259,8 @@ append_tool_bar_item (void)
8259 - (ASIZE (tool_bar_items_vector) - TOOL_BAR_ITEM_NSLOTS)); 8259 - (ASIZE (tool_bar_items_vector) - TOOL_BAR_ITEM_NSLOTS));
8260 8260
8261 /* Enlarge tool_bar_items_vector if necessary. */ 8261 /* Enlarge tool_bar_items_vector if necessary. */
8262 if (0 < incr) 8262 if (incr > 0)
8263 tool_bar_items_vector 8263 tool_bar_items_vector = larger_vector (tool_bar_items_vector, incr, -1);
8264 = larger_vector (tool_bar_items_vector, incr, -1);
8265 8264
8266 /* Append entries from tool_bar_item_properties to the end of 8265 /* Append entries from tool_bar_item_properties to the end of
8267 tool_bar_items_vector. */ 8266 tool_bar_items_vector. */
diff --git a/src/keymap.c b/src/keymap.c
index 00eefb375ef..110c8f43729 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -611,7 +611,8 @@ map_keymap_internal (Lisp_Object map,
611 } 611 }
612 else if (CHAR_TABLE_P (binding)) 612 else if (CHAR_TABLE_P (binding))
613 map_char_table (map_keymap_char_table_item, Qnil, binding, 613 map_char_table (map_keymap_char_table_item, Qnil, binding,
614 make_save_value ("ppo", fun, data, args)); 614 make_save_value (SAVE_TYPE_PTR_PTR_OBJ,
615 fun, data, args));
615 } 616 }
616 UNGCPRO; 617 UNGCPRO;
617 return tail; 618 return tail;
@@ -2062,7 +2063,7 @@ For an approximate inverse of this, see `kbd'. */)
2062 size += XINT (Flength (prefix)); 2063 size += XINT (Flength (prefix));
2063 2064
2064 /* This has one extra element at the end that we don't pass to Fconcat. */ 2065 /* This has one extra element at the end that we don't pass to Fconcat. */
2065 if (min (PTRDIFF_MAX, SIZE_MAX) / word_size / 4 < size) 2066 if (size > min (PTRDIFF_MAX, SIZE_MAX) / word_size / 4)
2066 memory_full (SIZE_MAX); 2067 memory_full (SIZE_MAX);
2067 SAFE_ALLOCA_LISP (args, size * 4); 2068 SAFE_ALLOCA_LISP (args, size * 4);
2068 2069
diff --git a/src/lisp.h b/src/lisp.h
index b209a7b1351..8187f7da993 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -548,7 +548,7 @@ static EMACS_INT const VALMASK
548 type or if I is a NaN. */ 548 type or if I is a NaN. */
549 549
550#define FIXNUM_OVERFLOW_P(i) \ 550#define FIXNUM_OVERFLOW_P(i) \
551 (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM)) 551 (! (((i) >= 0 || (i) >= MOST_NEGATIVE_FIXNUM) && (i) <= MOST_POSITIVE_FIXNUM))
552 552
553LISP_INLINE ptrdiff_t 553LISP_INLINE ptrdiff_t
554clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper) 554clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
@@ -556,6 +556,12 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
556 return num < lower ? lower : num <= upper ? num : upper; 556 return num < lower ? lower : num <= upper ? num : upper;
557} 557}
558 558
559
560/* Forward declarations. */
561
562LISP_INLINE bool SAVE_VALUEP (Lisp_Object);
563LISP_INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object);
564
559/* Extract a value or address from a Lisp_Object. */ 565/* Extract a value or address from a Lisp_Object. */
560 566
561#define XCONS(a) (eassert (CONSP (a)), \ 567#define XCONS(a) (eassert (CONSP (a)), \
@@ -576,7 +582,6 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
576#define XMISCTYPE(a) (XMISCANY (a)->type) 582#define XMISCTYPE(a) (XMISCANY (a)->type)
577#define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker)) 583#define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker))
578#define XOVERLAY(a) (eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay)) 584#define XOVERLAY(a) (eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay))
579#define XSAVE_VALUE(a) (eassert (SAVE_VALUEP (a)), &(XMISC (a)->u_save_value))
580 585
581/* Forwarding object types. */ 586/* Forwarding object types. */
582 587
@@ -786,13 +791,10 @@ extern ptrdiff_t string_bytes (struct Lisp_String *);
786 would expose alloc.c internal details that we'd rather keep 791 would expose alloc.c internal details that we'd rather keep
787 private. 792 private.
788 793
789 This is a macro for use in static initializers, and a constant for 794 This is a macro for use in static initializers. The cast to
790 visibility to GDB. The cast to ptrdiff_t ensures that 795 ptrdiff_t ensures that the macro is signed. */
791 the macro is signed. */
792static ptrdiff_t const STRING_BYTES_BOUND =
793#define STRING_BYTES_BOUND \ 796#define STRING_BYTES_BOUND \
794 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1)) 797 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
795 STRING_BYTES_BOUND;
796 798
797/* Mark STR as a unibyte string. */ 799/* Mark STR as a unibyte string. */
798#define STRING_SET_UNIBYTE(STR) \ 800#define STRING_SET_UNIBYTE(STR) \
@@ -1397,6 +1399,35 @@ enum
1397 SAVE_OBJECT 1399 SAVE_OBJECT
1398 }; 1400 };
1399 1401
1402/* Number of bits needed to store one of the above values. */
1403enum { SAVE_SLOT_BITS = 2 };
1404
1405/* Number of slots in a save value where save_type is nonzero. */
1406enum { SAVE_VALUE_SLOTS = 4 };
1407
1408/* Bit-width and values for struct Lisp_Save_Value's save_type member. */
1409
1410enum { SAVE_TYPE_BITS = SAVE_VALUE_SLOTS * SAVE_SLOT_BITS + 1 };
1411
1412enum Lisp_Save_Type
1413 {
1414 SAVE_TYPE_INT_INT = SAVE_INTEGER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1415 SAVE_TYPE_INT_INT_INT
1416 = (SAVE_INTEGER + (SAVE_TYPE_INT_INT << SAVE_SLOT_BITS)),
1417 SAVE_TYPE_OBJ_OBJ = SAVE_OBJECT + (SAVE_OBJECT << SAVE_SLOT_BITS),
1418 SAVE_TYPE_OBJ_OBJ_OBJ = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ << SAVE_SLOT_BITS),
1419 SAVE_TYPE_OBJ_OBJ_OBJ_OBJ
1420 = SAVE_OBJECT + (SAVE_TYPE_OBJ_OBJ_OBJ << SAVE_SLOT_BITS),
1421 SAVE_TYPE_PTR_INT = SAVE_POINTER + (SAVE_INTEGER << SAVE_SLOT_BITS),
1422 SAVE_TYPE_PTR_OBJ = SAVE_POINTER + (SAVE_OBJECT << SAVE_SLOT_BITS),
1423 SAVE_TYPE_PTR_PTR = SAVE_POINTER + (SAVE_POINTER << SAVE_SLOT_BITS),
1424 SAVE_TYPE_PTR_PTR_OBJ
1425 = SAVE_POINTER + (SAVE_TYPE_PTR_OBJ << SAVE_SLOT_BITS),
1426
1427 /* This has an extra bit indicating it's raw memory. */
1428 SAVE_TYPE_MEMORY = SAVE_TYPE_PTR_INT + (1 << (SAVE_TYPE_BITS - 1))
1429 };
1430
1400/* Special object used to hold a different values for later use. 1431/* Special object used to hold a different values for later use.
1401 1432
1402 This is mostly used to package C integers and pointers to call 1433 This is mostly used to package C integers and pointers to call
@@ -1417,73 +1448,96 @@ enum
1417 1448
1418 If yon need to pass more than just one C pointer, you should 1449 If yon need to pass more than just one C pointer, you should
1419 use make_save_value. This function allows you to pack up to 1450 use make_save_value. This function allows you to pack up to
1420 4 integers, pointers or Lisp_Objects and conveniently get them 1451 SAVE_VALUE_SLOTS integers, pointers or Lisp_Objects and
1421 back with XSAVE_POINTER, XSAVE_INTEGER and XSAVE_OBJECT macros: 1452 conveniently get them back with XSAVE_POINTER, XSAVE_INTEGER and
1453 XSAVE_OBJECT macros:
1422 1454
1423 ... 1455 ...
1424 struct my_data *md = get_my_data (); 1456 struct my_data *md = get_my_data ();
1425 ptrdiff_t my_offset = get_my_offset ();
1426 Lisp_Object my_object = get_my_object (); 1457 Lisp_Object my_object = get_my_object ();
1427 record_unwind_protect 1458 record_unwind_protect
1428 (my_unwind, make_save_value ("pio", md, my_offset, my_object)); 1459 (my_unwind, make_save_value (SAVE_TYPE_PTR_OBJ, md, my_object));
1429 ... 1460 ...
1430 1461
1431 Lisp_Object my_unwind (Lisp_Object arg) 1462 Lisp_Object my_unwind (Lisp_Object arg)
1432 { 1463 {
1433 struct my_data *md = XSAVE_POINTER (arg, 0); 1464 struct my_data *md = XSAVE_POINTER (arg, 0);
1434 ptrdiff_t my_offset = XSAVE_INTEGER (arg, 1); 1465 Lisp_Object my_object = XSAVE_OBJECT (arg, 1);
1435 Lisp_Object my_object = XSAVE_OBJECT (arg, 2);
1436 ... 1466 ...
1437 } 1467 }
1438 1468
1439 If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the 1469 If ENABLE_CHECKING is in effect, XSAVE_xxx macros do type checking of the
1440 saved objects and raise eassert if type of the saved object doesn't match 1470 saved objects and raise eassert if type of the saved object doesn't match
1441 the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2) 1471 the type which is extracted. In the example above, XSAVE_INTEGER (arg, 2)
1442 or XSAVE_OBJECT (arg, 1) are wrong because integer was saved in slot 1 and 1472 or XSAVE_OBJECT (arg, 0) are wrong because nothing was saved in slot 2 and
1443 Lisp_Object was saved in slot 2 of ARG. */ 1473 Lisp_Object was saved in slot 1 of ARG. */
1444 1474
1445struct Lisp_Save_Value 1475struct Lisp_Save_Value
1446 { 1476 {
1447 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */ 1477 ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
1448 unsigned gcmarkbit : 1; 1478 unsigned gcmarkbit : 1;
1449 int spacer : 6; 1479 int spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
1450 /* If `area' is nonzero, `data[0].pointer' is the address of a memory area 1480
1451 containing `data[1].integer' potential Lisp_Objects. The rest of `data' 1481 /* DATA[N] may hold up to SAVE_VALUE_SLOTS entries. The type of
1452 fields are unused. */ 1482 V's Ith entry is given by save_type (V, I). E.g., if save_type
1453 unsigned area : 1; 1483 (V, 3) == SAVE_INTEGER, V->data[3].integer is in use.
1454 /* If `area' is zero, `data[N]' may hold different objects which type is 1484
1455 encoded in `typeN' fields as described by the anonymous enum above. 1485 If SAVE_TYPE == SAVE_TYPE_MEMORY, DATA[0].pointer is the address of
1456 E.g. if `type0' is SAVE_INTEGER, `data[0].integer' is in use. */ 1486 a memory area containing DATA[1].integer potential Lisp_Objects. */
1457 unsigned type0 : 2; 1487 ENUM_BF (Lisp_Save_Type) save_type : SAVE_TYPE_BITS;
1458 unsigned type1 : 2;
1459 unsigned type2 : 2;
1460 unsigned type3 : 2;
1461 union { 1488 union {
1462 void *pointer; 1489 void *pointer;
1463 ptrdiff_t integer; 1490 ptrdiff_t integer;
1464 Lisp_Object object; 1491 Lisp_Object object;
1465 } data[4]; 1492 } data[SAVE_VALUE_SLOTS];
1466 }; 1493 };
1467 1494
1468/* Macro to set and extract Nth saved pointer. Type 1495/* Return the type of V's Nth saved value. */
1469 checking is ugly because it's used as an lvalue. */ 1496LISP_INLINE int
1497save_type (struct Lisp_Save_Value *v, int n)
1498{
1499 eassert (0 <= n && n < SAVE_VALUE_SLOTS);
1500 return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
1501}
1502
1503/* Get and set the Nth saved pointer. */
1470 1504
1471#define XSAVE_POINTER(obj, n) \ 1505LISP_INLINE void *
1472 XSAVE_VALUE (obj)->data[(eassert (XSAVE_VALUE (obj)->type \ 1506XSAVE_POINTER (Lisp_Object obj, int n)
1473 ## n == SAVE_POINTER), n)].pointer 1507{
1508 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1509 return XSAVE_VALUE (obj)->data[n].pointer;;
1510}
1511LISP_INLINE void
1512set_save_pointer (Lisp_Object obj, int n, void *val)
1513{
1514 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
1515 XSAVE_VALUE (obj)->data[n].pointer = val;
1516}
1474 1517
1475/* Likewise for the saved integer. */ 1518/* Likewise for the saved integer. */
1476 1519
1477#define XSAVE_INTEGER(obj, n) \ 1520LISP_INLINE ptrdiff_t
1478 XSAVE_VALUE (obj)->data[(eassert (XSAVE_VALUE (obj)->type \ 1521XSAVE_INTEGER (Lisp_Object obj, int n)
1479 ## n == SAVE_INTEGER), n)].integer 1522{
1523 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1524 return XSAVE_VALUE (obj)->data[n].integer;
1525}
1526LISP_INLINE void
1527set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
1528{
1529 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
1530 XSAVE_VALUE (obj)->data[n].integer = val;
1531}
1480 1532
1481/* Macro to extract Nth saved object. This is never used as 1533/* Extract Nth saved object. */
1482 an lvalue, so we can do more convenient type checking. */
1483 1534
1484#define XSAVE_OBJECT(obj, n) \ 1535LISP_INLINE Lisp_Object
1485 (eassert (XSAVE_VALUE (obj)->type ## n == SAVE_OBJECT), \ 1536XSAVE_OBJECT (Lisp_Object obj, int n)
1486 XSAVE_VALUE (obj)->data[n].object) 1537{
1538 eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
1539 return XSAVE_VALUE (obj)->data[n].object;
1540}
1487 1541
1488/* A miscellaneous object, when it's on the free list. */ 1542/* A miscellaneous object, when it's on the free list. */
1489struct Lisp_Free 1543struct Lisp_Free
@@ -1506,6 +1560,13 @@ union Lisp_Misc
1506 struct Lisp_Save_Value u_save_value; 1560 struct Lisp_Save_Value u_save_value;
1507 }; 1561 };
1508 1562
1563LISP_INLINE struct Lisp_Save_Value *
1564XSAVE_VALUE (Lisp_Object a)
1565{
1566 eassert (SAVE_VALUEP (a));
1567 return & XMISC (a)->u_save_value;
1568}
1569
1509/* Forwarding pointer to an int variable. 1570/* Forwarding pointer to an int variable.
1510 This is allowed only in the value cell of a symbol, 1571 This is allowed only in the value cell of a symbol,
1511 and it means that the symbol's value really lives in the 1572 and it means that the symbol's value really lives in the
@@ -1791,7 +1852,12 @@ typedef struct {
1791#define VECTORP(x) (VECTORLIKEP (x) && !(ASIZE (x) & PSEUDOVECTOR_FLAG)) 1852#define VECTORP(x) (VECTORLIKEP (x) && !(ASIZE (x) & PSEUDOVECTOR_FLAG))
1792#define OVERLAYP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay) 1853#define OVERLAYP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay)
1793#define MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker) 1854#define MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
1794#define SAVE_VALUEP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value) 1855
1856LISP_INLINE bool
1857SAVE_VALUEP (Lisp_Object x)
1858{
1859 return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
1860}
1795 1861
1796#define AUTOLOADP(x) (CONSP (x) && EQ (Qautoload, XCAR (x))) 1862#define AUTOLOADP(x) (CONSP (x) && EQ (Qautoload, XCAR (x)))
1797 1863
@@ -2504,7 +2570,7 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
2504LISP_INLINE void 2570LISP_INLINE void
2505vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count) 2571vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
2506{ 2572{
2507 eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v)); 2573 eassert (offset >= 0 && count >= 0 && offset + count <= ASIZE (v));
2508 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args); 2574 memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
2509} 2575}
2510 2576
@@ -3110,7 +3176,7 @@ extern bool abort_on_gc;
3110extern Lisp_Object make_float (double); 3176extern Lisp_Object make_float (double);
3111extern void display_malloc_warning (void); 3177extern void display_malloc_warning (void);
3112extern ptrdiff_t inhibit_garbage_collection (void); 3178extern ptrdiff_t inhibit_garbage_collection (void);
3113extern Lisp_Object make_save_value (const char *, ...); 3179extern Lisp_Object make_save_value (enum Lisp_Save_Type, ...);
3114extern Lisp_Object make_save_pointer (void *); 3180extern Lisp_Object make_save_pointer (void *);
3115extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object); 3181extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object);
3116extern void free_marker (Lisp_Object); 3182extern void free_marker (Lisp_Object);
@@ -3168,6 +3234,7 @@ extern Lisp_Object internal_with_output_to_temp_buffer
3168 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object); 3234 (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
3169enum FLOAT_TO_STRING_BUFSIZE { FLOAT_TO_STRING_BUFSIZE = 350 }; 3235enum FLOAT_TO_STRING_BUFSIZE { FLOAT_TO_STRING_BUFSIZE = 350 };
3170extern int float_to_string (char *, double); 3236extern int float_to_string (char *, double);
3237extern void init_print_once (void);
3171extern void syms_of_print (void); 3238extern void syms_of_print (void);
3172 3239
3173/* Defined in doprnt.c. */ 3240/* Defined in doprnt.c. */
@@ -3449,7 +3516,7 @@ extern Lisp_Object Qvisible;
3449extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object); 3516extern void store_frame_param (struct frame *, Lisp_Object, Lisp_Object);
3450extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object); 3517extern void store_in_alist (Lisp_Object *, Lisp_Object, Lisp_Object);
3451extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object); 3518extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3452#if HAVE_NS 3519#if HAVE_NS || defined(WINDOWSNT)
3453extern Lisp_Object get_frame_param (struct frame *, Lisp_Object); 3520extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3454#endif 3521#endif
3455extern void frames_discard_buffer (Lisp_Object); 3522extern void frames_discard_buffer (Lisp_Object);
@@ -3826,8 +3893,7 @@ extern void *record_xmalloc (size_t);
3826 { \ 3893 { \
3827 Lisp_Object arg_; \ 3894 Lisp_Object arg_; \
3828 buf = xmalloc ((nelt) * word_size); \ 3895 buf = xmalloc ((nelt) * word_size); \
3829 arg_ = make_save_value ("pi", buf, nelt); \ 3896 arg_ = make_save_value (SAVE_TYPE_MEMORY, buf, nelt); \
3830 XSAVE_VALUE (arg_)->area = 1; \
3831 sa_must_free = 1; \ 3897 sa_must_free = 1; \
3832 record_unwind_protect (safe_alloca_unwind, arg_); \ 3898 record_unwind_protect (safe_alloca_unwind, arg_); \
3833 } \ 3899 } \
diff --git a/src/lread.c b/src/lread.c
index f8ab03af218..d7a16f813c8 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1571,7 +1571,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1571 { 1571 {
1572 struct stat st; 1572 struct stat st;
1573 fd = emacs_open (pfn, O_RDONLY, 0); 1573 fd = emacs_open (pfn, O_RDONLY, 0);
1574 if (0 <= fd 1574 if (fd >= 0
1575 && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode))) 1575 && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode)))
1576 { 1576 {
1577 emacs_close (fd); 1577 emacs_close (fd);
@@ -2359,7 +2359,7 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix)
2359 while (c == '0'); 2359 while (c == '0');
2360 } 2360 }
2361 2361
2362 while (-1 <= (digit = digit_to_number (c, radix))) 2362 while ((digit = digit_to_number (c, radix)) >= -1)
2363 { 2363 {
2364 if (digit == -1) 2364 if (digit == -1)
2365 valid = 0; 2365 valid = 0;
@@ -2731,8 +2731,8 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
2731 /* Read a non-negative integer. */ 2731 /* Read a non-negative integer. */
2732 while (c >= '0' && c <= '9') 2732 while (c >= '0' && c <= '9')
2733 { 2733 {
2734 if (MOST_POSITIVE_FIXNUM / 10 < n 2734 if (n > MOST_POSITIVE_FIXNUM / 10
2735 || MOST_POSITIVE_FIXNUM < n * 10 + c - '0') 2735 || n * 10 + c - '0' > MOST_POSITIVE_FIXNUM)
2736 n = MOST_POSITIVE_FIXNUM + 1; 2736 n = MOST_POSITIVE_FIXNUM + 1;
2737 else 2737 else
2738 n = n * 10 + c - '0'; 2738 n = n * 10 + c - '0';
@@ -2930,7 +2930,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
2930 if (end - p < MAX_MULTIBYTE_LENGTH) 2930 if (end - p < MAX_MULTIBYTE_LENGTH)
2931 { 2931 {
2932 ptrdiff_t offset = p - read_buffer; 2932 ptrdiff_t offset = p - read_buffer;
2933 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 2933 if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
2934 memory_full (SIZE_MAX); 2934 memory_full (SIZE_MAX);
2935 read_buffer = xrealloc (read_buffer, read_buffer_size * 2); 2935 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
2936 read_buffer_size *= 2; 2936 read_buffer_size *= 2;
@@ -3064,7 +3064,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3064 if (end - p < MAX_MULTIBYTE_LENGTH) 3064 if (end - p < MAX_MULTIBYTE_LENGTH)
3065 { 3065 {
3066 ptrdiff_t offset = p - read_buffer; 3066 ptrdiff_t offset = p - read_buffer;
3067 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3067 if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
3068 memory_full (SIZE_MAX); 3068 memory_full (SIZE_MAX);
3069 read_buffer = xrealloc (read_buffer, read_buffer_size * 2); 3069 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3070 read_buffer_size *= 2; 3070 read_buffer_size *= 2;
@@ -3094,7 +3094,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3094 if (p == end) 3094 if (p == end)
3095 { 3095 {
3096 ptrdiff_t offset = p - read_buffer; 3096 ptrdiff_t offset = p - read_buffer;
3097 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3097 if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
3098 memory_full (SIZE_MAX); 3098 memory_full (SIZE_MAX);
3099 read_buffer = xrealloc (read_buffer, read_buffer_size * 2); 3099 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3100 read_buffer_size *= 2; 3100 read_buffer_size *= 2;
@@ -3298,12 +3298,12 @@ string_to_number (char const *string, int base, bool ignore_trailing)
3298 state = 0; 3298 state = 0;
3299 3299
3300 leading_digit = digit_to_number (*cp, base); 3300 leading_digit = digit_to_number (*cp, base);
3301 if (0 <= leading_digit) 3301 if (leading_digit >= 0)
3302 { 3302 {
3303 state |= LEAD_INT; 3303 state |= LEAD_INT;
3304 do 3304 do
3305 ++cp; 3305 ++cp;
3306 while (0 <= digit_to_number (*cp, base)); 3306 while (digit_to_number (*cp, base) >= 0);
3307 } 3307 }
3308 if (*cp == '.') 3308 if (*cp == '.')
3309 { 3309 {
@@ -3380,7 +3380,7 @@ string_to_number (char const *string, int base, bool ignore_trailing)
3380 3380
3381 /* If the number uses integer and not float syntax, and is in C-language 3381 /* If the number uses integer and not float syntax, and is in C-language
3382 range, use its value, preferably as a fixnum. */ 3382 range, use its value, preferably as a fixnum. */
3383 if (0 <= leading_digit && ! float_syntax) 3383 if (leading_digit >= 0 && ! float_syntax)
3384 { 3384 {
3385 uintmax_t n; 3385 uintmax_t n;
3386 3386
diff --git a/src/menu.c b/src/menu.c
index fdef54dd657..ffb5c3bc936 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -173,7 +173,7 @@ static void
173ensure_menu_items (int items) 173ensure_menu_items (int items)
174{ 174{
175 int incr = items - (menu_items_allocated - menu_items_used); 175 int incr = items - (menu_items_allocated - menu_items_used);
176 if (0 < incr) 176 if (incr > 0)
177 { 177 {
178 menu_items = larger_vector (menu_items, incr, INT_MAX); 178 menu_items = larger_vector (menu_items, incr, INT_MAX);
179 menu_items_allocated = ASIZE (menu_items); 179 menu_items_allocated = ASIZE (menu_items);
diff --git a/src/minibuf.c b/src/minibuf.c
index 25425cb97dc..56459353714 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -251,7 +251,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
251 { 251 {
252 if (len == size) 252 if (len == size)
253 { 253 {
254 if (STRING_BYTES_BOUND / 2 < size) 254 if (size > STRING_BYTES_BOUND / 2)
255 memory_full (SIZE_MAX); 255 memory_full (SIZE_MAX);
256 size *= 2; 256 size *= 2;
257 line = xrealloc (line, size); 257 line = xrealloc (line, size);
diff --git a/src/nsfns.m b/src/nsfns.m
index e4dde5fb894..9c3051a8c6a 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -261,6 +261,29 @@ ns_display_info_for_name (Lisp_Object name)
261 return dpyinfo; 261 return dpyinfo;
262} 262}
263 263
264static NSString *
265ns_filename_from_panel (NSSavePanel *panel)
266{
267#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
268 NSURL *url = [panel URL];
269 NSString *str = [url path];
270 return str;
271#else
272 return [panel filename];
273#endif
274}
275
276static NSString *
277ns_directory_from_panel (NSSavePanel *panel)
278{
279#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
280 NSURL *url = [panel directoryURL];
281 NSString *str = [url path];
282 return str;
283#else
284 return [panel directory];
285#endif
286}
264 287
265static Lisp_Object 288static Lisp_Object
266interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) 289interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old)
@@ -1220,9 +1243,6 @@ This function is an internal primitive--use `make-frame' instead. */)
1220 specbind (Qx_resource_name, name); 1243 specbind (Qx_resource_name, name);
1221 } 1244 }
1222 1245
1223 f->resx = dpyinfo->resx;
1224 f->resy = dpyinfo->resy;
1225
1226 block_input (); 1246 block_input ();
1227 register_font_driver (&nsfont_driver, f); 1247 register_font_driver (&nsfont_driver, f);
1228 x_default_parameter (f, parms, Qfont_backend, Qnil, 1248 x_default_parameter (f, parms, Qfont_backend, Qnil,
@@ -1471,7 +1491,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1471 Lisp_Object init, Lisp_Object dir_only_p) 1491 Lisp_Object init, Lisp_Object dir_only_p)
1472{ 1492{
1473 static id fileDelegate = nil; 1493 static id fileDelegate = nil;
1474 int ret; 1494 BOOL ret;
1475 id panel; 1495 id panel;
1476 Lisp_Object fname; 1496 Lisp_Object fname;
1477 1497
@@ -1508,6 +1528,13 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1508 [panel setCanChooseDirectories: YES]; 1528 [panel setCanChooseDirectories: YES];
1509 [panel setCanChooseFiles: NO]; 1529 [panel setCanChooseFiles: NO];
1510 } 1530 }
1531 else
1532 {
1533 /* This is not quite what the documentation says, but it is compatible
1534 with the Gtk+ code. Also, the menu entry says "Open File...". */
1535 [panel setCanChooseDirectories: NO];
1536 [panel setCanChooseFiles: YES];
1537 }
1511 1538
1512 block_input (); 1539 block_input ();
1513#if defined (NS_IMPL_COCOA) && \ 1540#if defined (NS_IMPL_COCOA) && \
@@ -1528,15 +1555,19 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1528 } 1555 }
1529 else 1556 else
1530 { 1557 {
1531 [panel setCanChooseDirectories: YES];
1532 ret = [panel runModalForDirectory: dirS file: initS types: nil]; 1558 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1533 } 1559 }
1534#endif 1560#endif
1535 1561
1536 ret = (ret == NSOKButton) || panelOK; 1562 ret = (ret == NSOKButton) || panelOK;
1537 1563
1538 if (ret) 1564 if (ret)
1539 fname = build_string ([[panel filename] UTF8String]); 1565 {
1566 NSString *str = [panel getFilename];
1567 if (! str) str = [panel getDirectory];
1568 if (! str) ret = NO;
1569 else fname = build_string ([str UTF8String]);
1570 }
1540 1571
1541 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1572 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
1542 unblock_input (); 1573 unblock_input ();
@@ -2603,6 +2634,14 @@ Value is t if tooltip was open, nil otherwise. */)
2603 [NSApp stop: self]; 2634 [NSApp stop: self];
2604} 2635}
2605#endif 2636#endif
2637- (NSString *) getFilename
2638{
2639 return ns_filename_from_panel (self);
2640}
2641- (NSString *) getDirectory
2642{
2643 return ns_directory_from_panel (self);
2644}
2606@end 2645@end
2607 2646
2608 2647
@@ -2616,6 +2655,12 @@ Value is t if tooltip was open, nil otherwise. */)
2616- (void) ok: (id)sender 2655- (void) ok: (id)sender
2617{ 2656{
2618 [super ok: sender]; 2657 [super ok: sender];
2658
2659 // If not choosing directories, and Open is pressed on a directory, return.
2660 if (! [self canChooseDirectories] && [self getDirectory] &&
2661 ! [self getFilename])
2662 return;
2663
2619 panelOK = 1; 2664 panelOK = 1;
2620 [NSApp stop: self]; 2665 [NSApp stop: self];
2621} 2666}
@@ -2624,7 +2669,17 @@ Value is t if tooltip was open, nil otherwise. */)
2624 [super cancel: sender]; 2669 [super cancel: sender];
2625 [NSApp stop: self]; 2670 [NSApp stop: self];
2626} 2671}
2672
2627#endif 2673#endif
2674- (NSString *) getFilename
2675{
2676 return ns_filename_from_panel (self);
2677}
2678- (NSString *) getDirectory
2679{
2680 return ns_directory_from_panel (self);
2681}
2682
2628@end 2683@end
2629 2684
2630 2685
diff --git a/src/nsterm.h b/src/nsterm.h
index 41dbaf3c0f7..6bd04b96684 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
267@interface EmacsSavePanel : NSSavePanel 267@interface EmacsSavePanel : NSSavePanel
268{ 268{
269} 269}
270- (NSString *) getFilename;
271- (NSString *) getDirectory;
270@end 272@end
271@interface EmacsOpenPanel : NSOpenPanel 273@interface EmacsOpenPanel : NSOpenPanel
272{ 274{
273} 275}
276- (NSString *) getFilename;
277- (NSString *) getDirectory;
274@end 278@end
275 279
276@interface EmacsFileDelegate : NSObject 280@interface EmacsFileDelegate : NSObject
diff --git a/src/nsterm.m b/src/nsterm.m
index 1f09e031592..40e506eab27 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3601,6 +3601,11 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3601 result = t; 3601 result = t;
3602 } 3602 }
3603 } 3603 }
3604 else
3605 {
3606 errno = EINTR;
3607 result = -1;
3608 }
3604 3609
3605 return result; 3610 return result;
3606} 3611}
@@ -5448,12 +5453,26 @@ not_in_argv (NSString *arg)
5448 5453
5449 if (oldr != rows || oldc != cols || neww != oldw || newh != oldh) 5454 if (oldr != rows || oldc != cols || neww != oldw || newh != oldh)
5450 { 5455 {
5456 struct frame *f = emacsframe;
5451 NSView *view = FRAME_NS_VIEW (emacsframe); 5457 NSView *view = FRAME_NS_VIEW (emacsframe);
5458 NSWindow *win = [view window];
5459 NSSize sz = [win resizeIncrements];
5460
5452 FRAME_PIXEL_WIDTH (emacsframe) = neww; 5461 FRAME_PIXEL_WIDTH (emacsframe) = neww;
5453 FRAME_PIXEL_HEIGHT (emacsframe) = newh; 5462 FRAME_PIXEL_HEIGHT (emacsframe) = newh;
5454 change_frame_size (emacsframe, rows, cols, 0, delay, 0); 5463 change_frame_size (emacsframe, rows, cols, 0, delay, 0);
5455 SET_FRAME_GARBAGED (emacsframe); 5464 SET_FRAME_GARBAGED (emacsframe);
5456 cancel_mouse_face (emacsframe); 5465 cancel_mouse_face (emacsframe);
5466
5467 // Did resize increments change because of a font change?
5468 if (sz.width != FRAME_COLUMN_WIDTH (emacsframe) ||
5469 sz.height != FRAME_LINE_HEIGHT (emacsframe))
5470 {
5471 sz.width = FRAME_COLUMN_WIDTH (emacsframe);
5472 sz.height = FRAME_LINE_HEIGHT (emacsframe);
5473 [win setResizeIncrements: sz];
5474 }
5475
5457 [view setFrame: NSMakeRect (0, 0, neww, newh)]; 5476 [view setFrame: NSMakeRect (0, 0, neww, newh)];
5458 [self windowDidMove:nil]; // Update top/left. 5477 [self windowDidMove:nil]; // Update top/left.
5459 } 5478 }
diff --git a/src/print.c b/src/print.c
index cc451d2e395..8498a758a21 100644
--- a/src/print.c
+++ b/src/print.c
@@ -229,9 +229,9 @@ printchar (unsigned int ch, Lisp_Object fun)
229 if (NILP (fun)) 229 if (NILP (fun))
230 { 230 {
231 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte); 231 ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
232 if (0 < incr) 232 if (incr > 0)
233 print_buffer = 233 print_buffer = xpalloc (print_buffer, &print_buffer_size,
234 xpalloc (print_buffer, &print_buffer_size, incr, -1, 1); 234 incr, -1, 1);
235 memcpy (print_buffer + print_buffer_pos_byte, str, len); 235 memcpy (print_buffer + print_buffer_pos_byte, str, len);
236 print_buffer_pos += 1; 236 print_buffer_pos += 1;
237 print_buffer_pos_byte += len; 237 print_buffer_pos_byte += len;
@@ -275,7 +275,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
275 if (NILP (printcharfun)) 275 if (NILP (printcharfun))
276 { 276 {
277 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte); 277 ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
278 if (0 < incr) 278 if (incr > 0)
279 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1); 279 print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
280 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte); 280 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
281 print_buffer_pos += size; 281 print_buffer_pos += size;
@@ -2051,17 +2051,15 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2051 2051
2052 strout ("#<save-value ", -1, -1, printcharfun); 2052 strout ("#<save-value ", -1, -1, printcharfun);
2053 2053
2054 if (v->area) 2054 if (v->save_type == SAVE_TYPE_MEMORY)
2055 { 2055 {
2056 ptrdiff_t amount = v->data[1].integer; 2056 ptrdiff_t amount = v->data[1].integer;
2057 2057
2058#if GC_MARK_STACK 2058#if GC_MARK_STACK
2059 2059
2060 /* If GC_MARK_STACK, valid_lisp_object_p is quite reliable, 2060 /* valid_lisp_object_p is reliable, so try to print up
2061 and so we try to print up to 8 objects we have saved. 2061 to 8 saved objects. This code is rarely used, so
2062 Although valid_lisp_object_p is slow, this shouldn't be 2062 it's OK that valid_lisp_object_p is slow. */
2063 a real bottleneck because we do not use this code under
2064 normal circumstances. */
2065 2063
2066 int limit = min (amount, 8); 2064 int limit = min (amount, 8);
2067 Lisp_Object *area = v->data[0].pointer; 2065 Lisp_Object *area = v->data[0].pointer;
@@ -2086,9 +2084,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2086 2084
2087#else /* not GC_MARK_STACK */ 2085#else /* not GC_MARK_STACK */
2088 2086
2089 /* If !GC_MARK_STACK, we have no reliable way to find 2087 /* There is no reliable way to determine whether the objects
2090 whether Lisp_Object pointers points to an initialized 2088 are initialized, so do not try to print them. */
2091 objects, and so we do not ever trying to print them. */
2092 2089
2093 i = sprintf (buf, "with %"pD"d objects", amount); 2090 i = sprintf (buf, "with %"pD"d objects", amount);
2094 strout (buf, i, i, printcharfun); 2091 strout (buf, i, i, printcharfun);
@@ -2097,33 +2094,37 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2097 } 2094 }
2098 else 2095 else
2099 { 2096 {
2100 /* Print each `data[N]' slot according to its type. */ 2097 /* Print each slot according to its type. */
2101 2098 int index;
2102#define PRINTX(index) \ 2099 for (index = 0; index < SAVE_VALUE_SLOTS; index++)
2103 do { \ 2100 {
2104 i = 0; \ 2101 if (index)
2105 if (v->type ## index == SAVE_UNUSED) \ 2102 PRINTCHAR (' ');
2106 i = sprintf (buf, "<unused>"); \
2107 else if (v->type ## index == SAVE_INTEGER) \
2108 i = sprintf (buf, "<integer %"pD"d>", v->data[index].integer); \
2109 else if (v->type ## index == SAVE_POINTER) \
2110 i = sprintf (buf, "<pointer %p>", v->data[index].pointer); \
2111 else /* SAVE_OBJECT */ \
2112 print_object (v->data[index].object, printcharfun, escapeflag); \
2113 if (i) \
2114 strout (buf, i, i, printcharfun); \
2115 } while (0)
2116
2117 PRINTX (0);
2118 PRINTCHAR (' ');
2119 PRINTX (1);
2120 PRINTCHAR (' ');
2121 PRINTX (2);
2122 PRINTCHAR (' ');
2123 PRINTX (3);
2124 2103
2125#undef PRINTX 2104 switch (save_type (v, index))
2105 {
2106 case SAVE_UNUSED:
2107 i = sprintf (buf, "<unused>");
2108 break;
2109
2110 case SAVE_POINTER:
2111 i = sprintf (buf, "<pointer %p>",
2112 v->data[index].pointer);
2113 break;
2114
2115 case SAVE_INTEGER:
2116 i = sprintf (buf, "<integer %"pD"d>",
2117 v->data[index].integer);
2118 break;
2119
2120 case SAVE_OBJECT:
2121 print_object (v->data[index].object, printcharfun,
2122 escapeflag);
2123 continue;
2124 }
2126 2125
2126 strout (buf, i, i, printcharfun);
2127 }
2127 } 2128 }
2128 PRINTCHAR ('>'); 2129 PRINTCHAR ('>');
2129 } 2130 }
@@ -2174,7 +2175,16 @@ print_interval (INTERVAL interval, Lisp_Object printcharfun)
2174 print_object (interval->plist, printcharfun, 1); 2175 print_object (interval->plist, printcharfun, 1);
2175} 2176}
2176 2177
2177 2178/* Initialize debug_print stuff early to have it working from the very
2179 beginning. */
2180
2181void
2182init_print_once (void)
2183{
2184 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2185 defsubr (&Sexternal_debugging_output);
2186}
2187
2178void 2188void
2179syms_of_print (void) 2189syms_of_print (void)
2180{ 2190{
@@ -2306,12 +2316,10 @@ priorities. */);
2306 defsubr (&Sprint); 2316 defsubr (&Sprint);
2307 defsubr (&Sterpri); 2317 defsubr (&Sterpri);
2308 defsubr (&Swrite_char); 2318 defsubr (&Swrite_char);
2309 defsubr (&Sexternal_debugging_output);
2310#ifdef WITH_REDIRECT_DEBUGGING_OUTPUT 2319#ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
2311 defsubr (&Sredirect_debugging_output); 2320 defsubr (&Sredirect_debugging_output);
2312#endif 2321#endif
2313 2322
2314 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2315 DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); 2323 DEFSYM (Qprint_escape_newlines, "print-escape-newlines");
2316 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte"); 2324 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte");
2317 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii"); 2325 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii");
diff --git a/src/process.c b/src/process.c
index bafdca9bd63..6a14a536707 100644
--- a/src/process.c
+++ b/src/process.c
@@ -136,7 +136,7 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *,
136/* Work around GCC 4.7.0 bug with strict overflow checking; see 136/* Work around GCC 4.7.0 bug with strict overflow checking; see
137 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. 137 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>.
138 These lines can be removed once the GCC bug is fixed. */ 138 These lines can be removed once the GCC bug is fixed. */
139#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ 139#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
140# pragma GCC diagnostic ignored "-Wstrict-overflow" 140# pragma GCC diagnostic ignored "-Wstrict-overflow"
141#endif 141#endif
142 142
@@ -1804,7 +1804,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1804 /* Back in the parent process. */ 1804 /* Back in the parent process. */
1805 1805
1806 XPROCESS (process)->pid = pid; 1806 XPROCESS (process)->pid = pid;
1807 if (0 <= pid) 1807 if (pid >= 0)
1808 XPROCESS (process)->alive = 1; 1808 XPROCESS (process)->alive = 1;
1809 1809
1810 /* Stop blocking signals in the parent. */ 1810 /* Stop blocking signals in the parent. */
@@ -2155,7 +2155,7 @@ Returns nil upon error setting address, ADDRESS otherwise. */)
2155 channel = XPROCESS (process)->infd; 2155 channel = XPROCESS (process)->infd;
2156 2156
2157 len = get_lisp_to_sockaddr_size (address, &family); 2157 len = get_lisp_to_sockaddr_size (address, &family);
2158 if (datagram_address[channel].len != len) 2158 if (len == 0 || datagram_address[channel].len != len)
2159 return Qnil; 2159 return Qnil;
2160 conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len); 2160 conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len);
2161 return address; 2161 return address;
@@ -3269,7 +3269,8 @@ usage: (make-network-process &rest ARGS) */)
3269 { 3269 {
3270 int rfamily, rlen; 3270 int rfamily, rlen;
3271 rlen = get_lisp_to_sockaddr_size (remote, &rfamily); 3271 rlen = get_lisp_to_sockaddr_size (remote, &rfamily);
3272 if (rfamily == lres->ai_family && rlen == lres->ai_addrlen) 3272 if (rlen != 0 && rfamily == lres->ai_family
3273 && rlen == lres->ai_addrlen)
3273 conv_lisp_to_sockaddr (rfamily, remote, 3274 conv_lisp_to_sockaddr (rfamily, remote,
3274 datagram_address[s].sa, rlen); 3275 datagram_address[s].sa, rlen);
3275 } 3276 }
@@ -3900,7 +3901,7 @@ Return non-nil if we received any output before the timeout expired. */)
3900 { 3901 {
3901 if (INTEGERP (seconds)) 3902 if (INTEGERP (seconds))
3902 { 3903 {
3903 if (0 < XINT (seconds)) 3904 if (XINT (seconds) > 0)
3904 { 3905 {
3905 secs = XINT (seconds); 3906 secs = XINT (seconds);
3906 nsecs = 0; 3907 nsecs = 0;
@@ -3908,7 +3909,7 @@ Return non-nil if we received any output before the timeout expired. */)
3908 } 3909 }
3909 else if (FLOATP (seconds)) 3910 else if (FLOATP (seconds))
3910 { 3911 {
3911 if (0 < XFLOAT_DATA (seconds)) 3912 if (XFLOAT_DATA (seconds) > 0)
3912 { 3913 {
3913 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); 3914 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds));
3914 secs = min (EMACS_SECS (t), WAIT_READING_MAX); 3915 secs = min (EMACS_SECS (t), WAIT_READING_MAX);
@@ -4235,12 +4236,12 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4235 time_limit = 0; 4236 time_limit = 0;
4236 nsecs = -1; 4237 nsecs = -1;
4237 } 4238 }
4238 else if (TYPE_MAXIMUM (time_t) < time_limit) 4239 else if (time_limit > TYPE_MAXIMUM (time_t))
4239 time_limit = TYPE_MAXIMUM (time_t); 4240 time_limit = TYPE_MAXIMUM (time_t);
4240 4241
4241 /* Since we may need to wait several times, 4242 /* Since we may need to wait several times,
4242 compute the absolute time to return at. */ 4243 compute the absolute time to return at. */
4243 if (time_limit || 0 < nsecs) 4244 if (time_limit || nsecs > 0)
4244 { 4245 {
4245 timeout = make_emacs_time (time_limit, nsecs); 4246 timeout = make_emacs_time (time_limit, nsecs);
4246 end_time = add_emacs_time (current_emacs_time (), timeout); 4247 end_time = add_emacs_time (current_emacs_time (), timeout);
@@ -4272,7 +4273,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4272 4273
4273 timeout = make_emacs_time (0, 0); 4274 timeout = make_emacs_time (0, 0);
4274 } 4275 }
4275 else if (time_limit || 0 < nsecs) 4276 else if (time_limit || nsecs > 0)
4276 { 4277 {
4277 EMACS_TIME now = current_emacs_time (); 4278 EMACS_TIME now = current_emacs_time ();
4278 if (EMACS_TIME_LE (end_time, now)) 4279 if (EMACS_TIME_LE (end_time, now))
@@ -4324,7 +4325,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4324 break; 4325 break;
4325 4326
4326 /* A negative timeout means do not wait at all. */ 4327 /* A negative timeout means do not wait at all. */
4327 if (0 <= nsecs) 4328 if (nsecs >= 0)
4328 { 4329 {
4329 if (EMACS_TIME_VALID_P (timer_delay)) 4330 if (EMACS_TIME_VALID_P (timer_delay))
4330 { 4331 {
@@ -4406,7 +4407,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4406 if (nread == 0) 4407 if (nread == 0)
4407 break; 4408 break;
4408 4409
4409 if (0 < nread) 4410 if (nread > 0)
4410 { 4411 {
4411 total_nread += nread; 4412 total_nread += nread;
4412 got_some_input = 1; 4413 got_some_input = 1;
@@ -4947,7 +4948,7 @@ read_process_output (Lisp_Object proc, register int channel)
4947 else 4948 else
4948#endif 4949#endif
4949 { 4950 {
4950 bool buffered = 0 <= proc_buffered_char[channel]; 4951 bool buffered = proc_buffered_char[channel] >= 0;
4951 if (buffered) 4952 if (buffered)
4952 { 4953 {
4953 chars[carryover] = proc_buffered_char[channel]; 4954 chars[carryover] = proc_buffered_char[channel];
@@ -5454,7 +5455,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5454 rv = sendto (outfd, cur_buf, cur_len, 5455 rv = sendto (outfd, cur_buf, cur_len,
5455 0, datagram_address[outfd].sa, 5456 0, datagram_address[outfd].sa,
5456 datagram_address[outfd].len); 5457 datagram_address[outfd].len);
5457 if (0 <= rv) 5458 if (rv >= 0)
5458 written = rv; 5459 written = rv;
5459 else if (errno == EMSGSIZE) 5460 else if (errno == EMSGSIZE)
5460 report_file_error ("sending datagram", Fcons (proc, Qnil)); 5461 report_file_error ("sending datagram", Fcons (proc, Qnil));
@@ -6577,7 +6578,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6577 time_limit = TYPE_MAXIMUM (time_t); 6578 time_limit = TYPE_MAXIMUM (time_t);
6578 6579
6579 /* What does time_limit really mean? */ 6580 /* What does time_limit really mean? */
6580 if (time_limit || 0 < nsecs) 6581 if (time_limit || nsecs > 0)
6581 { 6582 {
6582 timeout = make_emacs_time (time_limit, nsecs); 6583 timeout = make_emacs_time (time_limit, nsecs);
6583 end_time = add_emacs_time (current_emacs_time (), timeout); 6584 end_time = add_emacs_time (current_emacs_time (), timeout);
@@ -6615,7 +6616,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6615 6616
6616 timeout = make_emacs_time (0, 0); 6617 timeout = make_emacs_time (0, 0);
6617 } 6618 }
6618 else if (time_limit || 0 < nsecs) 6619 else if (time_limit || nsecs > 0)
6619 { 6620 {
6620 EMACS_TIME now = current_emacs_time (); 6621 EMACS_TIME now = current_emacs_time ();
6621 if (EMACS_TIME_LE (end_time, now)) 6622 if (EMACS_TIME_LE (end_time, now))
@@ -6653,7 +6654,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6653 && requeued_events_pending_p ()) 6654 && requeued_events_pending_p ())
6654 break; 6655 break;
6655 6656
6656 if (EMACS_TIME_VALID_P (timer_delay) && 0 <= nsecs) 6657 if (EMACS_TIME_VALID_P (timer_delay) && nsecs >= 0)
6657 { 6658 {
6658 if (EMACS_TIME_LT (timer_delay, timeout)) 6659 if (EMACS_TIME_LT (timer_delay, timeout))
6659 { 6660 {
diff --git a/src/profiler.c b/src/profiler.c
index 85d9c1ca88a..0a0a4d0bc57 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -55,7 +55,7 @@ make_log (int heap_size, int max_stack_depth)
55 /* What is special about our hash-tables is that the keys are pre-filled 55 /* What is special about our hash-tables is that the keys are pre-filled
56 with the vectors we'll put in them. */ 56 with the vectors we'll put in them. */
57 int i = ASIZE (h->key_and_value) / 2; 57 int i = ASIZE (h->key_and_value) / 2;
58 while (0 < i) 58 while (i > 0)
59 set_hash_key_slot (h, --i, 59 set_hash_key_slot (h, --i,
60 Fmake_vector (make_number (max_stack_depth), Qnil)); 60 Fmake_vector (make_number (max_stack_depth), Qnil));
61 return log; 61 return log;
@@ -247,7 +247,7 @@ handle_profiler_signal (int signal)
247 if (profiler_timer_ok) 247 if (profiler_timer_ok)
248 { 248 {
249 int overruns = timer_getoverrun (profiler_timer); 249 int overruns = timer_getoverrun (profiler_timer);
250 eassert (0 <= overruns); 250 eassert (overruns >= 0);
251 count += overruns; 251 count += overruns;
252 } 252 }
253#endif 253#endif
diff --git a/src/regex.c b/src/regex.c
index 051a4fdc26b..648f2529649 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -33,7 +33,7 @@
33 33
34/* Ignore some GCC warnings for now. This section should go away 34/* Ignore some GCC warnings for now. This section should go away
35 once the Emacs and Gnulib regex code is merged. */ 35 once the Emacs and Gnulib regex code is merged. */
36#if (__GNUC__ == 4 && 5 <= __GNUC_MINOR__) || 4 < __GNUC__ 36#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
37# pragma GCC diagnostic ignored "-Wstrict-overflow" 37# pragma GCC diagnostic ignored "-Wstrict-overflow"
38# ifndef emacs 38# ifndef emacs
39# pragma GCC diagnostic ignored "-Wunused-but-set-variable" 39# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
@@ -6404,8 +6404,8 @@ weak_function
6404re_exec (const char *s) 6404re_exec (const char *s)
6405{ 6405{
6406 const size_t len = strlen (s); 6406 const size_t len = strlen (s);
6407 return 6407 return (re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0)
6408 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); 6408 >= 0);
6409} 6409}
6410#endif /* _REGEX_RE_COMP */ 6410#endif /* _REGEX_RE_COMP */
6411 6411
diff --git a/src/regex.h b/src/regex.h
index f1fd837bd6f..8fe7ba16adc 100644
--- a/src/regex.h
+++ b/src/regex.h
@@ -530,7 +530,7 @@ extern int re_exec (const char *);
530/* GCC 2.95 and later have "__restrict"; C99 compilers have 530/* GCC 2.95 and later have "__restrict"; C99 compilers have
531 "restrict", and "configure" may have defined "restrict". */ 531 "restrict", and "configure" may have defined "restrict". */
532#ifndef __restrict 532#ifndef __restrict
533# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) 533# if ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
534# if defined restrict || 199901L <= __STDC_VERSION__ 534# if defined restrict || 199901L <= __STDC_VERSION__
535# define __restrict restrict 535# define __restrict restrict
536# else 536# else
diff --git a/src/search.c b/src/search.c
index c5ac7d494dc..ece346ecd06 100644
--- a/src/search.c
+++ b/src/search.c
@@ -326,7 +326,7 @@ looking_at_1 (Lisp_Object string, bool posix)
326 if (i == -2) 326 if (i == -2)
327 matcher_overflow (); 327 matcher_overflow ();
328 328
329 val = (0 <= i ? Qt : Qnil); 329 val = (i >= 0 ? Qt : Qnil);
330 if (NILP (Vinhibit_changing_match_data) && i >= 0) 330 if (NILP (Vinhibit_changing_match_data) && i >= 0)
331 for (i = 0; i < search_regs.num_regs; i++) 331 for (i = 0; i < search_regs.num_regs; i++)
332 if (search_regs.start[i] >= 0) 332 if (search_regs.start[i] >= 0)
@@ -2450,7 +2450,7 @@ since only regular expressions have distinguished subexpressions. */)
2450 else if (c >= '1' && c <= '9') 2450 else if (c >= '1' && c <= '9')
2451 { 2451 {
2452 if (c - '0' < search_regs.num_regs 2452 if (c - '0' < search_regs.num_regs
2453 && 0 <= search_regs.start[c - '0']) 2453 && search_regs.start[c - '0'] >= 0)
2454 { 2454 {
2455 substart = search_regs.start[c - '0']; 2455 substart = search_regs.start[c - '0'];
2456 subend = search_regs.end[c - '0']; 2456 subend = search_regs.end[c - '0'];
@@ -2533,7 +2533,7 @@ since only regular expressions have distinguished subexpressions. */)
2533 bool str_multibyte = STRING_MULTIBYTE (newtext); 2533 bool str_multibyte = STRING_MULTIBYTE (newtext);
2534 bool really_changed = 0; 2534 bool really_changed = 0;
2535 2535
2536 substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length 2536 substed_alloc_size = (length > (STRING_BYTES_BOUND - 100) / 2
2537 ? STRING_BYTES_BOUND 2537 ? STRING_BYTES_BOUND
2538 : length * 2 + 100); 2538 : length * 2 + 100);
2539 substed = xmalloc (substed_alloc_size); 2539 substed = xmalloc (substed_alloc_size);
diff --git a/src/sysdep.c b/src/sysdep.c
index bff11fc9f75..1d3e646d359 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -282,7 +282,7 @@ get_child_status (pid_t child, int *status, int options, bool interruptible)
282 reap an unwanted process by mistake. For example, invoking 282 reap an unwanted process by mistake. For example, invoking
283 waitpid (-1, ...) can mess up glib by reaping glib's subprocesses, 283 waitpid (-1, ...) can mess up glib by reaping glib's subprocesses,
284 so that another thread running glib won't find them. */ 284 so that another thread running glib won't find them. */
285 eassert (0 < child); 285 eassert (child > 0);
286 286
287 while ((pid = waitpid (child, status, options)) < 0) 287 while ((pid = waitpid (child, status, options)) < 0)
288 { 288 {
@@ -2691,7 +2691,7 @@ procfs_ttyname (int rdev)
2691 2691
2692 while (!feof (fdev) && !ferror (fdev)) 2692 while (!feof (fdev) && !ferror (fdev))
2693 { 2693 {
2694 if (3 <= fscanf (fdev, "%*s %s %u %s %*s\n", name, &major, minor) 2694 if (fscanf (fdev, "%*s %s %u %s %*s\n", name, &major, minor) >= 3
2695 && major == MAJOR (rdev)) 2695 && major == MAJOR (rdev))
2696 { 2696 {
2697 minor_beg = strtoul (minor, &endp, 0); 2697 minor_beg = strtoul (minor, &endp, 0);
@@ -2731,7 +2731,7 @@ procfs_get_total_memory (void)
2731 2731
2732 while (!feof (fmem) && !ferror (fmem)) 2732 while (!feof (fmem) && !ferror (fmem))
2733 { 2733 {
2734 if (2 <= fscanf (fmem, "%s %lu kB\n", entry_name, &entry_value) 2734 if (fscanf (fmem, "%s %lu kB\n", entry_name, &entry_value) >= 2
2735 && strcmp (entry_name, "MemTotal:") == 0) 2735 && strcmp (entry_name, "MemTotal:") == 0)
2736 { 2736 {
2737 retval = entry_value; 2737 retval = entry_value;
diff --git a/src/systime.h b/src/systime.h
index fa5e7270cb5..da495b9064b 100644
--- a/src/systime.h
+++ b/src/systime.h
@@ -121,7 +121,7 @@ EMACS_TIME_SIGN (EMACS_TIME t)
121SYSTIME_INLINE int 121SYSTIME_INLINE int
122EMACS_TIME_VALID_P (EMACS_TIME t) 122EMACS_TIME_VALID_P (EMACS_TIME t)
123{ 123{
124 return 0 <= t.tv_nsec; 124 return t.tv_nsec >= 0;
125} 125}
126 126
127/* Convert the double D to the greatest EMACS_TIME not greater than D. 127/* Convert the double D to the greatest EMACS_TIME not greater than D.
diff --git a/src/term.c b/src/term.c
index 38706602a02..28b944c6436 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2909,7 +2909,7 @@ dissociate_if_controlling_tty (int fd)
2909{ 2909{
2910 /* If tcgetpgrp succeeds, fd is the controlling terminal, 2910 /* If tcgetpgrp succeeds, fd is the controlling terminal,
2911 so dissociate it by invoking setsid. */ 2911 so dissociate it by invoking setsid. */
2912 if (0 <= tcgetpgrp (fd) && setsid () < 0) 2912 if (tcgetpgrp (fd) >= 0 && setsid () < 0)
2913 { 2913 {
2914#ifdef TIOCNOTTY 2914#ifdef TIOCNOTTY
2915 /* setsid failed, presumably because Emacs is already a process 2915 /* setsid failed, presumably because Emacs is already a process
diff --git a/src/unexcw.c b/src/unexcw.c
index af93e158e14..1290c28d245 100644
--- a/src/unexcw.c
+++ b/src/unexcw.c
@@ -20,7 +20,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#include <config.h> 21#include <config.h>
22#include "unexec.h" 22#include "unexec.h"
23#include "w32common.h"
24 23
25#include <lisp.h> 24#include <lisp.h>
26#include <stdio.h> 25#include <stdio.h>
@@ -31,6 +30,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31 30
32#define DOTEXE ".exe" 31#define DOTEXE ".exe"
33 32
33extern void report_sheap_usage (int);
34
34extern int bss_sbrk_did_unexec; 35extern int bss_sbrk_did_unexec;
35 36
36extern int __malloc_initialized; 37extern int __malloc_initialized;
@@ -73,7 +74,11 @@ read_exe_header (int fd, exe_header_t * exe_header_buffer)
73 74
74 assert (exe_header_buffer->file_header.e_magic == 0x5a4d); 75 assert (exe_header_buffer->file_header.e_magic == 0x5a4d);
75 assert (exe_header_buffer->file_header.nt_signature == 0x4550); 76 assert (exe_header_buffer->file_header.nt_signature == 0x4550);
77#ifdef __x86_64__
78 assert (exe_header_buffer->file_header.f_magic == 0x8664);
79#else
76 assert (exe_header_buffer->file_header.f_magic == 0x014c); 80 assert (exe_header_buffer->file_header.f_magic == 0x014c);
81#endif
77 assert (exe_header_buffer->file_header.f_nscns > 0); 82 assert (exe_header_buffer->file_header.f_nscns > 0);
78 assert (exe_header_buffer->file_header.f_nscns <= 83 assert (exe_header_buffer->file_header.f_nscns <=
79 sizeof (exe_header_buffer->section_header) / 84 sizeof (exe_header_buffer->section_header) /
@@ -85,7 +90,11 @@ read_exe_header (int fd, exe_header_t * exe_header_buffer)
85 sizeof (exe_header_buffer->file_optional_header)); 90 sizeof (exe_header_buffer->file_optional_header));
86 assert (ret == sizeof (exe_header_buffer->file_optional_header)); 91 assert (ret == sizeof (exe_header_buffer->file_optional_header));
87 92
93#ifdef __x86_64__
94 assert (exe_header_buffer->file_optional_header.magic == 0x020b);
95#else
88 assert (exe_header_buffer->file_optional_header.magic == 0x010b); 96 assert (exe_header_buffer->file_optional_header.magic == 0x010b);
97#endif
89 98
90 for (i = 0; i < exe_header_buffer->file_header.f_nscns; ++i) 99 for (i = 0; i < exe_header_buffer->file_header.f_nscns; ++i)
91 { 100 {
@@ -132,7 +141,7 @@ fixup_executable (int fd)
132 exe_header->file_optional_header.ImageBase + 141 exe_header->file_optional_header.ImageBase +
133 exe_header->section_header[i].s_paddr; 142 exe_header->section_header[i].s_paddr;
134 if (debug_unexcw) 143 if (debug_unexcw)
135 printf ("%8s start 0x%08x end 0x%08x\n", 144 printf ("%8s start %#lx end %#lx\n",
136 exe_header->section_header[i].s_name, 145 exe_header->section_header[i].s_name,
137 start_address, end_address); 146 start_address, end_address);
138 if (my_edata >= (char *) start_address 147 if (my_edata >= (char *) start_address
@@ -149,7 +158,7 @@ fixup_executable (int fd)
149 assert (ret == my_edata - (char *) start_address); 158 assert (ret == my_edata - (char *) start_address);
150 ++found_data; 159 ++found_data;
151 if (debug_unexcw) 160 if (debug_unexcw)
152 printf (" .data, mem start 0x%08x mem length %d\n", 161 printf (" .data, mem start %#lx mem length %d\n",
153 start_address, my_edata - (char *) start_address); 162 start_address, my_edata - (char *) start_address);
154 if (debug_unexcw) 163 if (debug_unexcw)
155 printf (" .data, file start %d file length %d\n", 164 printf (" .data, file start %d file length %d\n",
@@ -233,7 +242,7 @@ fixup_executable (int fd)
233 __malloc_initialized = 1; 242 __malloc_initialized = 1;
234 assert (ret == (my_endbss - (char *) start_address)); 243 assert (ret == (my_endbss - (char *) start_address));
235 if (debug_unexcw) 244 if (debug_unexcw)
236 printf (" .bss, mem start 0x%08x mem length %d\n", 245 printf (" .bss, mem start %#lx mem length %d\n",
237 start_address, my_endbss - (char *) start_address); 246 start_address, my_endbss - (char *) start_address);
238 if (debug_unexcw) 247 if (debug_unexcw)
239 printf (" .bss, file start %d file length %d\n", 248 printf (" .bss, file start %d file length %d\n",
diff --git a/src/w32.c b/src/w32.c
index 647faf94ef1..f3c98bf9596 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -29,10 +29,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
29#include <ctype.h> 29#include <ctype.h>
30#include <signal.h> 30#include <signal.h>
31#include <sys/file.h> 31#include <sys/file.h>
32#include <time.h> /* must be before nt/inc/sys/time.h, for MinGW64 */
32#include <sys/time.h> 33#include <sys/time.h>
33#include <sys/utime.h> 34#include <sys/utime.h>
34#include <math.h> 35#include <math.h>
35#include <time.h>
36 36
37/* must include CRT headers *before* config.h */ 37/* must include CRT headers *before* config.h */
38 38
@@ -69,7 +69,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
69#include <pwd.h> 69#include <pwd.h>
70#include <grp.h> 70#include <grp.h>
71 71
72#ifdef __GNUC__ 72/* MinGW64 (_W64) defines these in its _mingw.h. */
73#if defined(__GNUC__) && !defined(_W64)
73#define _ANONYMOUS_UNION 74#define _ANONYMOUS_UNION
74#define _ANONYMOUS_STRUCT 75#define _ANONYMOUS_STRUCT
75#endif 76#endif
@@ -96,6 +97,7 @@ typedef struct _MEMORY_STATUS_EX {
96#ifndef _MSC_VER 97#ifndef _MSC_VER
97#include <w32api.h> 98#include <w32api.h>
98#endif 99#endif
100#if _WIN32_WINNT < 0x0500
99#if !defined (__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15) 101#if !defined (__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15)
100/* This either is not in psapi.h or guarded by higher value of 102/* This either is not in psapi.h or guarded by higher value of
101 _WIN32_WINNT than what we use. w32api supplied with MinGW 3.15 103 _WIN32_WINNT than what we use. w32api supplied with MinGW 3.15
@@ -114,6 +116,7 @@ typedef struct _PROCESS_MEMORY_COUNTERS_EX {
114 SIZE_T PrivateUsage; 116 SIZE_T PrivateUsage;
115} PROCESS_MEMORY_COUNTERS_EX,*PPROCESS_MEMORY_COUNTERS_EX; 117} PROCESS_MEMORY_COUNTERS_EX,*PPROCESS_MEMORY_COUNTERS_EX;
116#endif 118#endif
119#endif
117 120
118#include <winioctl.h> 121#include <winioctl.h>
119#include <aclapi.h> 122#include <aclapi.h>
@@ -127,7 +130,7 @@ typedef struct _PROCESS_MEMORY_COUNTERS_EX {
127#define SDDL_REVISION_1 1 130#define SDDL_REVISION_1 1
128#endif /* SDDL_REVISION_1 */ 131#endif /* SDDL_REVISION_1 */
129 132
130#ifdef _MSC_VER 133#ifndef MAXIMUM_REPARSE_DATA_BUFFER_SIZE
131/* MSVC doesn't provide the definition of REPARSE_DATA_BUFFER and the 134/* MSVC doesn't provide the definition of REPARSE_DATA_BUFFER and the
132 associated macros, except on ntifs.h, which cannot be included 135 associated macros, except on ntifs.h, which cannot be included
133 because it triggers conflicts with other Windows API headers. So 136 because it triggers conflicts with other Windows API headers. So
diff --git a/src/w32fns.c b/src/w32fns.c
index cef2009d7a1..88141893445 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -4353,9 +4353,6 @@ This function is an internal primitive--use `make-frame' instead. */)
4353 specbind (Qx_resource_name, name); 4353 specbind (Qx_resource_name, name);
4354 } 4354 }
4355 4355
4356 f->resx = dpyinfo->resx;
4357 f->resy = dpyinfo->resy;
4358
4359 if (uniscribe_available) 4356 if (uniscribe_available)
4360 register_font_driver (&uniscribe_font_driver, f); 4357 register_font_driver (&uniscribe_font_driver, f);
4361 register_font_driver (&w32font_driver, f); 4358 register_font_driver (&w32font_driver, f);
@@ -5420,9 +5417,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5420 specbind (Qx_resource_name, name); 5417 specbind (Qx_resource_name, name);
5421 } 5418 }
5422 5419
5423 f->resx = dpyinfo->resx;
5424 f->resy = dpyinfo->resy;
5425
5426 if (uniscribe_available) 5420 if (uniscribe_available)
5427 register_font_driver (&uniscribe_font_driver, f); 5421 register_font_driver (&uniscribe_font_driver, f);
5428 register_font_driver (&w32font_driver, f); 5422 register_font_driver (&w32font_driver, f);
@@ -5780,8 +5774,8 @@ Text larger than the specified size is clipped. */)
5780 5774
5781 /* Set up the frame's root window. */ 5775 /* Set up the frame's root window. */
5782 w = XWINDOW (FRAME_ROOT_WINDOW (f)); 5776 w = XWINDOW (FRAME_ROOT_WINDOW (f));
5783 wset_left_col (w, make_number (0)); 5777 w->left_col = 0;
5784 wset_top_line (w, make_number (0)); 5778 w->top_line = 0;
5785 5779
5786 if (CONSP (Vx_max_tooltip_size) 5780 if (CONSP (Vx_max_tooltip_size)
5787 && INTEGERP (XCAR (Vx_max_tooltip_size)) 5781 && INTEGERP (XCAR (Vx_max_tooltip_size))
@@ -5789,13 +5783,13 @@ Text larger than the specified size is clipped. */)
5789 && INTEGERP (XCDR (Vx_max_tooltip_size)) 5783 && INTEGERP (XCDR (Vx_max_tooltip_size))
5790 && XINT (XCDR (Vx_max_tooltip_size)) > 0) 5784 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
5791 { 5785 {
5792 wset_total_cols (w, XCAR (Vx_max_tooltip_size)); 5786 w->total_cols = XFASTINT (XCAR (Vx_max_tooltip_size));
5793 wset_total_lines (w, XCDR (Vx_max_tooltip_size)); 5787 w->total_lines = XFASTINT (XCDR (Vx_max_tooltip_size));
5794 } 5788 }
5795 else 5789 else
5796 { 5790 {
5797 wset_total_cols (w, make_number (80)); 5791 w->total_cols = 80;
5798 wset_total_lines (w, make_number (40)); 5792 w->total_lines = 40;
5799 } 5793 }
5800 5794
5801 FRAME_TOTAL_COLS (f) = XINT (w->total_cols); 5795 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
@@ -5866,7 +5860,7 @@ Text larger than the specified size is clipped. */)
5866 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns, 5860 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5867 not in pixels. */ 5861 not in pixels. */
5868 width /= WINDOW_FRAME_COLUMN_WIDTH (w); 5862 width /= WINDOW_FRAME_COLUMN_WIDTH (w);
5869 wset_total_cols (w, make_number (width)); 5863 w->total_cols = width;
5870 FRAME_TOTAL_COLS (f) = width; 5864 FRAME_TOTAL_COLS (f) = width;
5871 adjust_glyphs (f); 5865 adjust_glyphs (f);
5872 w->pseudo_window_p = 1; 5866 w->pseudo_window_p = 1;
@@ -7765,6 +7759,9 @@ emacs_abort (void)
7765#endif 7759#endif
7766 if (stderr_fd >= 0) 7760 if (stderr_fd >= 0)
7767 write (stderr_fd, "\r\nBacktrace:\r\n", 14); 7761 write (stderr_fd, "\r\nBacktrace:\r\n", 14);
7762#ifdef CYGWIN
7763#define _open open
7764#endif
7768 errfile_fd = _open ("emacs_backtrace.txt", O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE); 7765 errfile_fd = _open ("emacs_backtrace.txt", O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
7769 if (errfile_fd >= 0) 7766 if (errfile_fd >= 0)
7770 { 7767 {
diff --git a/src/w32font.c b/src/w32font.c
index 5c5a15cc340..fb52376b9e1 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -1967,7 +1967,7 @@ static void
1967fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec) 1967fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec)
1968{ 1968{
1969 Lisp_Object tmp, extra; 1969 Lisp_Object tmp, extra;
1970 int dpi = FRAME_W32_DISPLAY_INFO (f)->resy; 1970 int dpi = FRAME_RES_Y (f);
1971 1971
1972 tmp = AREF (font_spec, FONT_DPI_INDEX); 1972 tmp = AREF (font_spec, FONT_DPI_INDEX);
1973 if (INTEGERP (tmp)) 1973 if (INTEGERP (tmp))
diff --git a/src/w32term.c b/src/w32term.c
index 989ceb0f847..5f7952c2ec2 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -109,9 +109,10 @@ struct w32_display_info *x_display_list;
109Lisp_Object w32_display_name_list; 109Lisp_Object w32_display_name_list;
110 110
111 111
112#if _WIN32_WINNT < 0x0500 112#if _WIN32_WINNT < 0x0500 && !defined(_W64)
113/* Pre Windows 2000, this was not available, but define it here so 113/* Pre Windows 2000, this was not available, but define it here so
114 that Emacs compiled on such a platform will run on newer versions. */ 114 that Emacs compiled on such a platform will run on newer versions.
115 MinGW64 (_W64) defines these unconditionally, so avoid redefining. */
115 116
116typedef struct tagWCRANGE 117typedef struct tagWCRANGE
117{ 118{
@@ -5660,8 +5661,6 @@ x_check_fullscreen (struct frame *f)
5660static void 5661static void
5661w32fullscreen_hook (FRAME_PTR f) 5662w32fullscreen_hook (FRAME_PTR f)
5662{ 5663{
5663 static int normal_width, normal_height;
5664
5665 if (FRAME_VISIBLE_P (f)) 5664 if (FRAME_VISIBLE_P (f))
5666 { 5665 {
5667 int width, height, top_pos, left_pos, pixel_height, pixel_width; 5666 int width, height, top_pos, left_pos, pixel_height, pixel_width;
@@ -5669,17 +5668,38 @@ w32fullscreen_hook (FRAME_PTR f)
5669 RECT workarea_rect; 5668 RECT workarea_rect;
5670 5669
5671 block_input (); 5670 block_input ();
5672 if (normal_height <= 0) 5671 /* Record current "normal" dimensions for restoring later. */
5673 normal_height = cur_h; 5672 if (!( FRAME_PREV_FSMODE (f) == FULLSCREEN_BOTH
5674 if (normal_width <= 0) 5673 || FRAME_PREV_FSMODE (f) == FULLSCREEN_MAXIMIZED))
5675 normal_width = cur_w; 5674 {
5675 if (FRAME_PREV_FSMODE (f) != FULLSCREEN_HEIGHT)
5676 {
5677 FRAME_NORMAL_HEIGHT (f) = cur_h;
5678 FRAME_NORMAL_TOP (f) = f->top_pos;
5679 }
5680 if (FRAME_PREV_FSMODE (f) != FULLSCREEN_WIDTH)
5681 {
5682 FRAME_NORMAL_WIDTH (f) = cur_w;
5683 FRAME_NORMAL_LEFT (f) = f->left_pos;
5684 }
5685 }
5686 eassert (FRAME_NORMAL_HEIGHT (f) > 0);
5687 eassert (FRAME_NORMAL_WIDTH (f) > 0);
5676 x_real_positions (f, &f->left_pos, &f->top_pos); 5688 x_real_positions (f, &f->left_pos, &f->top_pos);
5677 x_fullscreen_adjust (f, &width, &height, &top_pos, &left_pos); 5689 x_fullscreen_adjust (f, &width, &height, &top_pos, &left_pos);
5678 5690
5679 SystemParametersInfo (SPI_GETWORKAREA, 0, &workarea_rect, 0); 5691 SystemParametersInfo (SPI_GETWORKAREA, 0, &workarea_rect, 0);
5680 pixel_height = workarea_rect.bottom - workarea_rect.top; 5692 pixel_height = workarea_rect.bottom - workarea_rect.top;
5681 pixel_width = workarea_rect.right - workarea_rect.left; 5693 pixel_width = workarea_rect.right - workarea_rect.left;
5682 5694 /* Need to send SC_RESTORE to the window, in case we are
5695 resizing from FULLSCREEN_MAXIMIZED. Otherwise, the mouse
5696 resize hints will not be shown by the window manager when the
5697 mouse pointer hovers over the window edges, becaise the WM
5698 will still think the window is maximized. */
5699 if (f->want_fullscreen != FULLSCREEN_BOTH)
5700 SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_RESTORE, 0);
5701
5702 FRAME_PREV_FSMODE (f) = f->want_fullscreen;
5683 switch (f->want_fullscreen) 5703 switch (f->want_fullscreen)
5684 { 5704 {
5685 case FULLSCREEN_BOTH: 5705 case FULLSCREEN_BOTH:
@@ -5700,8 +5720,7 @@ w32fullscreen_hook (FRAME_PTR f)
5700 width = 5720 width =
5701 FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pixel_width) 5721 FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pixel_width)
5702 - FRAME_SCROLL_BAR_COLS (f); 5722 - FRAME_SCROLL_BAR_COLS (f);
5703 if (normal_height > 0) 5723 height = FRAME_NORMAL_HEIGHT (f);
5704 height = normal_height;
5705 left_pos = workarea_rect.left; 5724 left_pos = workarea_rect.left;
5706 break; 5725 break;
5707 case FULLSCREEN_HEIGHT: 5726 case FULLSCREEN_HEIGHT:
@@ -5709,21 +5728,14 @@ w32fullscreen_hook (FRAME_PTR f)
5709 FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixel_height) 5728 FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixel_height)
5710 - XINT (Ftool_bar_lines_needed (selected_frame)) 5729 - XINT (Ftool_bar_lines_needed (selected_frame))
5711 + (NILP (Vmenu_bar_mode) ? 1 : 0); 5730 + (NILP (Vmenu_bar_mode) ? 1 : 0);
5712 if (normal_width > 0) 5731 width = FRAME_NORMAL_WIDTH (f);
5713 width = normal_width;
5714 top_pos = workarea_rect.top; 5732 top_pos = workarea_rect.top;
5715 break; 5733 break;
5716 case FULLSCREEN_NONE: 5734 case FULLSCREEN_NONE:
5717 if (normal_height > 0) 5735 height = FRAME_NORMAL_HEIGHT (f);
5718 height = normal_height; 5736 width = FRAME_NORMAL_WIDTH (f);
5719 else 5737 left_pos = FRAME_NORMAL_LEFT (f);
5720 normal_height = height; 5738 top_pos = FRAME_NORMAL_TOP (f);
5721 if (normal_width > 0)
5722 width = normal_width;
5723 else
5724 normal_width = width;
5725 /* FIXME: Should restore the original position of the frame. */
5726 top_pos = left_pos = 0;
5727 break; 5739 break;
5728 } 5740 }
5729 5741
@@ -6651,7 +6663,7 @@ w32_initialize (void)
6651 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil); 6663 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
6652 6664
6653 { 6665 {
6654 DWORD input_locale_id = (DWORD) GetKeyboardLayout (0); 6666 DWORD input_locale_id = ((DWORD_PTR) GetKeyboardLayout (0) & 0xffffffff);
6655 w32_keyboard_codepage = 6667 w32_keyboard_codepage =
6656 codepage_for_locale ((LCID) (input_locale_id & 0xffff)); 6668 codepage_for_locale ((LCID) (input_locale_id & 0xffff));
6657 } 6669 }
diff --git a/src/w32term.h b/src/w32term.h
index a31c5de193d..b319f0ca592 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -359,6 +359,12 @@ struct w32_output
359 /* The background for which the above relief GCs were set up. 359 /* The background for which the above relief GCs were set up.
360 They are changed only when a different background is involved. */ 360 They are changed only when a different background is involved. */
361 unsigned long relief_background; 361 unsigned long relief_background;
362
363 /* Frame geometry and full-screen mode before it was resized by
364 specifying the 'fullscreen' frame parameter. Used to restore the
365 geometry when 'fullscreen' is reset to nil. */
366 int normal_width, normal_height, normal_top, normal_left;
367 int prev_fsmode;
362}; 368};
363 369
364extern struct w32_output w32term_display; 370extern struct w32_output w32term_display;
@@ -390,6 +396,13 @@ extern struct w32_output w32term_display;
390 396
391#define FRAME_SMALLEST_FONT_HEIGHT(F) \ 397#define FRAME_SMALLEST_FONT_HEIGHT(F) \
392 FRAME_W32_DISPLAY_INFO(F)->smallest_font_height 398 FRAME_W32_DISPLAY_INFO(F)->smallest_font_height
399
400#define FRAME_NORMAL_WIDTH(F) ((F)->output_data.w32->normal_width)
401#define FRAME_NORMAL_HEIGHT(F) ((F)->output_data.w32->normal_height)
402#define FRAME_NORMAL_TOP(F) ((F)->output_data.w32->normal_top)
403#define FRAME_NORMAL_LEFT(F) ((F)->output_data.w32->normal_left)
404#define FRAME_PREV_FSMODE(F) ((F)->output_data.w32->prev_fsmode)
405
393 406
394/* W32-specific scroll bar stuff. */ 407/* W32-specific scroll bar stuff. */
395 408
diff --git a/src/window.c b/src/window.c
index c987d08534e..a2e6a5a0602 100644
--- a/src/window.c
+++ b/src/window.c
@@ -85,8 +85,8 @@ static int foreach_window_1 (struct window *,
85 int (* fn) (struct window *, void *), 85 int (* fn) (struct window *, void *),
86 void *); 86 void *);
87static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object); 87static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object);
88static int window_resize_check (struct window *, int); 88static int window_resize_check (struct window *, bool);
89static void window_resize_apply (struct window *, int); 89static void window_resize_apply (struct window *, bool);
90static Lisp_Object select_window (Lisp_Object, Lisp_Object, int); 90static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
91static void select_window_1 (Lisp_Object, bool); 91static void select_window_1 (Lisp_Object, bool);
92 92
@@ -636,30 +636,37 @@ Return nil if WINDOW has no previous sibling. */)
636 636
637DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0, 637DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0,
638 doc: /* Return combination limit of window WINDOW. 638 doc: /* Return combination limit of window WINDOW.
639WINDOW must be a valid window used in horizontal or vertical combination.
639If the return value is nil, child windows of WINDOW can be recombined with 640If the return value is nil, child windows of WINDOW can be recombined with
640WINDOW's siblings. A return value of t means that child windows of 641WINDOW's siblings. A return value of t means that child windows of
641WINDOW are never \(re-)combined with WINDOW's siblings. 642WINDOW are never \(re-)combined with WINDOW's siblings. */)
642
643WINDOW must be a valid window. The return value is meaningful for
644internal windows only. */)
645 (Lisp_Object window) 643 (Lisp_Object window)
646{ 644{
645 struct window *w;
646
647 CHECK_VALID_WINDOW (window); 647 CHECK_VALID_WINDOW (window);
648 w = XWINDOW (window);
649 if (!NILP (w->buffer))
650 error ("Combination limit is meaningful for internal windows only");
648 return XWINDOW (window)->combination_limit; 651 return XWINDOW (window)->combination_limit;
649} 652}
650 653
651DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0, 654DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
652 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT. 655 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
656WINDOW must be a valid window used in horizontal or vertical combination.
653If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's 657If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
654siblings. LIMIT t means that child windows of WINDOW are never 658siblings. LIMIT t means that child windows of WINDOW are never
655\(re-)combined with WINDOW's siblings. Other values are reserved for 659\(re-)combined with WINDOW's siblings. Other values are reserved for
656future use. 660future use. */)
657
658WINDOW must be a valid window. Setting the combination limit is
659meaningful for internal windows only. */)
660 (Lisp_Object window, Lisp_Object limit) 661 (Lisp_Object window, Lisp_Object limit)
661{ 662{
662 wset_combination_limit (decode_valid_window (window), limit); 663 struct window *w;
664
665 CHECK_VALID_WINDOW (window);
666 w = XWINDOW (window);
667 if (!NILP (w->buffer))
668 error ("Combination limit is meaningful for internal windows only");
669 wset_combination_limit (w, limit);
663 return limit; 670 return limit;
664} 671}
665 672
@@ -686,7 +693,7 @@ On a graphical display, this total height is reported as an
686integer multiple of the default character height. */) 693integer multiple of the default character height. */)
687 (Lisp_Object window) 694 (Lisp_Object window)
688{ 695{
689 return decode_valid_window (window)->total_lines; 696 return make_number (decode_valid_window (window)->total_lines);
690} 697}
691 698
692DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0, 699DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0,
@@ -701,7 +708,7 @@ On a graphical display, this total width is reported as an
701integer multiple of the default character width. */) 708integer multiple of the default character width. */)
702 (Lisp_Object window) 709 (Lisp_Object window)
703{ 710{
704 return decode_valid_window (window)->total_cols; 711 return make_number (decode_valid_window (window)->total_cols);
705} 712}
706 713
707DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0, 714DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
@@ -740,7 +747,7 @@ value is 0 if there is no window to the left of WINDOW.
740WINDOW must be a valid window and defaults to the selected one. */) 747WINDOW must be a valid window and defaults to the selected one. */)
741 (Lisp_Object window) 748 (Lisp_Object window)
742{ 749{
743 return decode_valid_window (window)->left_col; 750 return make_number (decode_valid_window (window)->left_col);
744} 751}
745 752
746DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0, 753DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
@@ -752,7 +759,7 @@ there is no window above WINDOW.
752WINDOW must be a valid window and defaults to the selected one. */) 759WINDOW must be a valid window and defaults to the selected one. */)
753 (Lisp_Object window) 760 (Lisp_Object window)
754{ 761{
755 return decode_valid_window (window)->top_line; 762 return make_number (decode_valid_window (window)->top_line);
756} 763}
757 764
758/* Return the number of lines of W's body. Don't count any mode or 765/* Return the number of lines of W's body. Don't count any mode or
@@ -761,7 +768,7 @@ WINDOW must be a valid window and defaults to the selected one. */)
761static int 768static int
762window_body_lines (struct window *w) 769window_body_lines (struct window *w)
763{ 770{
764 int height = XFASTINT (w->total_lines); 771 int height = w->total_lines;
765 772
766 if (!MINI_WINDOW_P (w)) 773 if (!MINI_WINDOW_P (w))
767 { 774 {
@@ -783,7 +790,7 @@ int
783window_body_cols (struct window *w) 790window_body_cols (struct window *w)
784{ 791{
785 struct frame *f = XFRAME (WINDOW_FRAME (w)); 792 struct frame *f = XFRAME (WINDOW_FRAME (w));
786 int width = XINT (w->total_cols); 793 int width = w->total_cols;
787 794
788 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w)) 795 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
789 /* Scroll bars occupy a few columns. */ 796 /* Scroll bars occupy a few columns. */
@@ -1369,7 +1376,7 @@ check_window_containing (struct window *w, void *user_data)
1369 1376
1370Lisp_Object 1377Lisp_Object
1371window_from_coordinates (struct frame *f, int x, int y, 1378window_from_coordinates (struct frame *f, int x, int y,
1372 enum window_part *part, int tool_bar_p) 1379 enum window_part *part, bool tool_bar_p)
1373{ 1380{
1374 Lisp_Object window; 1381 Lisp_Object window;
1375 struct check_window_data cw; 1382 struct check_window_data cw;
@@ -2001,12 +2008,12 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
2001 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) 2008 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
2002 fset_root_window (XFRAME (o->frame), new); 2009 fset_root_window (XFRAME (o->frame), new);
2003 2010
2004 if (setflag) 2011 if (setflag)
2005 { 2012 {
2006 wset_left_col (n, o->left_col); 2013 n->left_col = o->left_col;
2007 wset_top_line (n, o->top_line); 2014 n->top_line = o->top_line;
2008 wset_total_cols (n, o->total_cols); 2015 n->total_cols = o->total_cols;
2009 wset_total_lines (n, o->total_lines); 2016 n->total_lines = o->total_lines;
2010 wset_normal_cols (n, o->normal_cols); 2017 wset_normal_cols (n, o->normal_cols);
2011 wset_normal_cols (o, make_float (1.0)); 2018 wset_normal_cols (o, make_float (1.0));
2012 wset_normal_lines (n, o->normal_lines); 2019 wset_normal_lines (n, o->normal_lines);
@@ -2056,7 +2063,7 @@ recombine_windows (Lisp_Object window)
2056{ 2063{
2057 struct window *w, *p, *c; 2064 struct window *w, *p, *c;
2058 Lisp_Object parent, child; 2065 Lisp_Object parent, child;
2059 int horflag; 2066 bool horflag;
2060 2067
2061 w = XWINDOW (window); 2068 w = XWINDOW (window);
2062 parent = w->parent; 2069 parent = w->parent;
@@ -2091,12 +2098,12 @@ recombine_windows (Lisp_Object window)
2091 2098
2092 if (horflag) 2099 if (horflag)
2093 wset_normal_cols (c, 2100 wset_normal_cols (c,
2094 make_float (XFLOATINT (c->total_cols) 2101 make_float ((double) c->total_cols
2095 / XFLOATINT (p->total_cols))); 2102 / (double) p->total_cols));
2096 else 2103 else
2097 wset_normal_lines (c, 2104 wset_normal_lines (c,
2098 make_float (XFLOATINT (c->total_lines) 2105 make_float ((double) c->total_lines
2099 / XFLOATINT (p->total_lines))); 2106 / (double) p->total_lines));
2100 2107
2101 if (NILP (c->next)) 2108 if (NILP (c->next))
2102 { 2109 {
@@ -2855,9 +2862,8 @@ window-start value is reasonable when this function is called. */)
2855 if (NILP (w->buffer)) 2862 if (NILP (w->buffer))
2856 { 2863 {
2857 /* Resize child windows vertically. */ 2864 /* Resize child windows vertically. */
2858 XSETINT (delta, XINT (r->total_lines) 2865 XSETINT (delta, r->total_lines - w->total_lines);
2859 - XINT (w->total_lines)); 2866 w->top_line = r->top_line;
2860 wset_top_line (w, r->top_line);
2861 resize_root_window (window, delta, Qnil, Qnil); 2867 resize_root_window (window, delta, Qnil, Qnil);
2862 if (window_resize_check (w, 0)) 2868 if (window_resize_check (w, 0))
2863 window_resize_apply (w, 0); 2869 window_resize_apply (w, 0);
@@ -2873,10 +2879,8 @@ window-start value is reasonable when this function is called. */)
2873 /* Resize child windows horizontally. */ 2879 /* Resize child windows horizontally. */
2874 if (!resize_failed) 2880 if (!resize_failed)
2875 { 2881 {
2876 wset_left_col (w, r->left_col); 2882 w->left_col = r->left_col;
2877 XSETINT (delta, 2883 XSETINT (delta, r->total_cols - w->total_cols);
2878 XINT (r->total_cols) - XINT (w->total_cols));
2879 wset_left_col (w, r->left_col);
2880 resize_root_window (window, delta, Qt, Qnil); 2884 resize_root_window (window, delta, Qt, Qnil);
2881 if (window_resize_check (w, 1)) 2885 if (window_resize_check (w, 1))
2882 window_resize_apply (w, 1); 2886 window_resize_apply (w, 1);
@@ -3149,7 +3153,8 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
3149 reset from the buffer's local settings. */ 3153 reset from the buffer's local settings. */
3150 3154
3151void 3155void
3152set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int keep_margins_p) 3156set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3157 bool run_hooks_p, bool keep_margins_p)
3153{ 3158{
3154 struct window *w = XWINDOW (window); 3159 struct window *w = XWINDOW (window);
3155 struct buffer *b = XBUFFER (buffer); 3160 struct buffer *b = XBUFFER (buffer);
@@ -3407,7 +3412,7 @@ temp_output_buffer_show (register Lisp_Object buf)
3407 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only 3412 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3408 horizontal child). */ 3413 horizontal child). */
3409static void 3414static void
3410make_parent_window (Lisp_Object window, int horflag) 3415make_parent_window (Lisp_Object window, bool horflag)
3411{ 3416{
3412 Lisp_Object parent; 3417 Lisp_Object parent;
3413 register struct window *o, *p; 3418 register struct window *o, *p;
@@ -3446,10 +3451,6 @@ make_window (void)
3446 w = allocate_window (); 3451 w = allocate_window ();
3447 /* Initialize Lisp data. Note that allocate_window initializes all 3452 /* Initialize Lisp data. Note that allocate_window initializes all
3448 Lisp data to nil, so do it only for slots which should not be nil. */ 3453 Lisp data to nil, so do it only for slots which should not be nil. */
3449 wset_left_col (w, make_number (0));
3450 wset_top_line (w, make_number (0));
3451 wset_total_lines (w, make_number (0));
3452 wset_total_cols (w, make_number (0));
3453 wset_normal_lines (w, make_float (1.0)); 3454 wset_normal_lines (w, make_float (1.0));
3454 wset_normal_cols (w, make_float (1.0)); 3455 wset_normal_cols (w, make_float (1.0));
3455 wset_new_total (w, make_number (0)); 3456 wset_new_total (w, make_number (0));
@@ -3520,7 +3521,7 @@ Note: This function does not operate on any child windows of WINDOW. */)
3520 `window-min-height' or `window-min-width'. It does check that window 3521 `window-min-height' or `window-min-width'. It does check that window
3521 sizes do not drop below one line (two columns). */ 3522 sizes do not drop below one line (two columns). */
3522static int 3523static int
3523window_resize_check (struct window *w, int horflag) 3524window_resize_check (struct window *w, bool horflag)
3524{ 3525{
3525 struct window *c; 3526 struct window *c;
3526 3527
@@ -3601,7 +3602,7 @@ window_resize_check (struct window *w, int horflag)
3601 This function does not perform any error checks. Make sure you have 3602 This function does not perform any error checks. Make sure you have
3602 run window_resize_check on W before applying this function. */ 3603 run window_resize_check on W before applying this function. */
3603static void 3604static void
3604window_resize_apply (struct window *w, int horflag) 3605window_resize_apply (struct window *w, bool horflag)
3605{ 3606{
3606 struct window *c; 3607 struct window *c;
3607 int pos; 3608 int pos;
@@ -3610,19 +3611,19 @@ window_resize_apply (struct window *w, int horflag)
3610 parent window has been set *before*. */ 3611 parent window has been set *before*. */
3611 if (horflag) 3612 if (horflag)
3612 { 3613 {
3613 wset_total_cols (w, w->new_total); 3614 w->total_cols = XFASTINT (w->new_total);
3614 if (NUMBERP (w->new_normal)) 3615 if (NUMBERP (w->new_normal))
3615 wset_normal_cols (w, w->new_normal); 3616 wset_normal_cols (w, w->new_normal);
3616 3617
3617 pos = XINT (w->left_col); 3618 pos = w->left_col;
3618 } 3619 }
3619 else 3620 else
3620 { 3621 {
3621 wset_total_lines (w, w->new_total); 3622 w->total_lines = XFASTINT (w->new_total);
3622 if (NUMBERP (w->new_normal)) 3623 if (NUMBERP (w->new_normal))
3623 wset_normal_lines (w, w->new_normal); 3624 wset_normal_lines (w, w->new_normal);
3624 3625
3625 pos = XINT (w->top_line); 3626 pos = w->top_line;
3626 } 3627 }
3627 3628
3628 if (!NILP (w->vchild)) 3629 if (!NILP (w->vchild))
@@ -3632,12 +3633,12 @@ window_resize_apply (struct window *w, int horflag)
3632 while (c) 3633 while (c)
3633 { 3634 {
3634 if (horflag) 3635 if (horflag)
3635 wset_left_col (c, make_number (pos)); 3636 c->left_col = pos;
3636 else 3637 else
3637 wset_top_line (c, make_number (pos)); 3638 c->top_line = pos;
3638 window_resize_apply (c, horflag); 3639 window_resize_apply (c, horflag);
3639 if (!horflag) 3640 if (!horflag)
3640 pos = pos + XINT (c->total_lines); 3641 pos = pos + c->total_lines;
3641 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3642 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3642 } 3643 }
3643 } 3644 }
@@ -3648,12 +3649,12 @@ window_resize_apply (struct window *w, int horflag)
3648 while (c) 3649 while (c)
3649 { 3650 {
3650 if (horflag) 3651 if (horflag)
3651 wset_left_col (c, make_number (pos)); 3652 c->left_col = pos;
3652 else 3653 else
3653 wset_top_line (c, make_number (pos)); 3654 c->top_line = pos;
3654 window_resize_apply (c, horflag); 3655 window_resize_apply (c, horflag);
3655 if (horflag) 3656 if (horflag)
3656 pos = pos + XINT (c->total_cols); 3657 pos = pos + c->total_cols;
3657 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3658 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3658 } 3659 }
3659 } 3660 }
@@ -3682,11 +3683,11 @@ be applied on the Elisp level. */)
3682{ 3683{
3683 struct frame *f = decode_live_frame (frame); 3684 struct frame *f = decode_live_frame (frame);
3684 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f)); 3685 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
3685 int horflag = !NILP (horizontal); 3686 bool horflag = !NILP (horizontal);
3686 3687
3687 if (!window_resize_check (r, horflag) 3688 if (!window_resize_check (r, horflag)
3688 || ! EQ (r->new_total, 3689 || (XINT (r->new_total)
3689 (horflag ? r->total_cols : r->total_lines))) 3690 != (horflag ? r->total_cols : r->total_lines)))
3690 return Qnil; 3691 return Qnil;
3691 3692
3692 block_input (); 3693 block_input ();
@@ -3712,7 +3713,7 @@ be applied on the Elisp level. */)
3712 satisfy the request. The result will be meaningful if and only if 3713 satisfy the request. The result will be meaningful if and only if
3713 F's windows have meaningful sizes when you call this. */ 3714 F's windows have meaningful sizes when you call this. */
3714void 3715void
3715resize_frame_windows (struct frame *f, int size, int horflag) 3716resize_frame_windows (struct frame *f, int size, bool horflag)
3716{ 3717{
3717 Lisp_Object root = f->root_window; 3718 Lisp_Object root = f->root_window;
3718 struct window *r = XWINDOW (root); 3719 struct window *r = XWINDOW (root);
@@ -3726,18 +3727,17 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3726 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f)) 3727 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3727 ? 1 : 0))); 3728 ? 1 : 0)));
3728 3729
3729 wset_top_line (r, make_number (FRAME_TOP_MARGIN (f))); 3730 r->top_line = FRAME_TOP_MARGIN (f);
3730 if (NILP (r->vchild) && NILP (r->hchild)) 3731 if (NILP (r->vchild) && NILP (r->hchild))
3731 /* For a leaf root window just set the size. */ 3732 /* For a leaf root window just set the size. */
3732 if (horflag) 3733 if (horflag)
3733 wset_total_cols (r, make_number (new_size)); 3734 r->total_cols = new_size;
3734 else 3735 else
3735 wset_total_lines (r, make_number (new_size)); 3736 r->total_lines = new_size;
3736 else 3737 else
3737 { 3738 {
3738 /* old_size is the old size of the frame's root window. */ 3739 /* old_size is the old size of the frame's root window. */
3739 int old_size = XFASTINT (horflag ? r->total_cols 3740 int old_size = horflag ? r->total_cols : r->total_lines;
3740 : r->total_lines);
3741 Lisp_Object delta; 3741 Lisp_Object delta;
3742 3742
3743 XSETINT (delta, new_size - old_size); 3743 XSETINT (delta, new_size - old_size);
@@ -3767,9 +3767,9 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3767 root = f->selected_window; 3767 root = f->selected_window;
3768 Fdelete_other_windows_internal (root, Qnil); 3768 Fdelete_other_windows_internal (root, Qnil);
3769 if (horflag) 3769 if (horflag)
3770 wset_total_cols (XWINDOW (root), make_number (new_size)); 3770 XWINDOW (root)->total_cols = new_size;
3771 else 3771 else
3772 wset_total_lines (XWINDOW (root), make_number (new_size)); 3772 XWINDOW (root)->total_lines = new_size;
3773 } 3773 }
3774 } 3774 }
3775 } 3775 }
@@ -3779,13 +3779,12 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3779 { 3779 {
3780 m = XWINDOW (mini); 3780 m = XWINDOW (mini);
3781 if (horflag) 3781 if (horflag)
3782 wset_total_cols (m, make_number (size)); 3782 m->total_cols = size;
3783 else 3783 else
3784 { 3784 {
3785 /* Are we sure we always want 1 line here? */ 3785 /* Are we sure we always want 1 line here? */
3786 wset_total_lines (m, make_number (1)); 3786 m->total_lines = 1;
3787 wset_top_line 3787 m->top_line = r->top_line + r->total_lines;
3788 (m, make_number (XINT (r->top_line) + XINT (r->total_lines)));
3789 } 3788 }
3790 } 3789 }
3791 3790
@@ -3826,7 +3825,7 @@ set correctly. See the code of `split-window' for how this is done. */)
3826 register Lisp_Object new, frame, reference; 3825 register Lisp_Object new, frame, reference;
3827 register struct window *o, *p, *n, *r; 3826 register struct window *o, *p, *n, *r;
3828 struct frame *f; 3827 struct frame *f;
3829 int horflag 3828 bool horflag
3830 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */ 3829 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3831 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright); 3830 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright);
3832 int combination_limit = 0; 3831 int combination_limit = 0;
@@ -3869,20 +3868,21 @@ set correctly. See the code of `split-window' for how this is done. */)
3869 p = XWINDOW (o->parent); 3868 p = XWINDOW (o->parent);
3870 /* Temporarily pretend we split the parent window. */ 3869 /* Temporarily pretend we split the parent window. */
3871 wset_new_total 3870 wset_new_total
3872 (p, make_number (XINT (horflag ? p->total_cols : p->total_lines) 3871 (p, make_number ((horflag ? p->total_cols : p->total_lines)
3873 - XINT (total_size))); 3872 - XINT (total_size)));
3874 if (!window_resize_check (p, horflag)) 3873 if (!window_resize_check (p, horflag))
3875 error ("Window sizes don't fit"); 3874 error ("Window sizes don't fit");
3876 else 3875 else
3877 /* Undo the temporary pretension. */ 3876 /* Undo the temporary pretension. */
3878 wset_new_total (p, horflag ? p->total_cols : p->total_lines); 3877 wset_new_total (p, make_number
3878 (horflag ? p->total_cols : p->total_lines));
3879 } 3879 }
3880 else 3880 else
3881 { 3881 {
3882 if (!window_resize_check (o, horflag)) 3882 if (!window_resize_check (o, horflag))
3883 error ("Resizing old window failed"); 3883 error ("Resizing old window failed");
3884 else if (XINT (total_size) + XINT (o->new_total) 3884 else if (XINT (total_size) + XINT (o->new_total)
3885 != XINT (horflag ? o->total_cols : o->total_lines)) 3885 != (horflag ? o->total_cols : o->total_lines))
3886 error ("Sum of sizes of old and new window don't fit"); 3886 error ("Sum of sizes of old and new window don't fit");
3887 } 3887 }
3888 3888
@@ -3902,7 +3902,8 @@ set correctly. See the code of `split-window' for how this is done. */)
3902 that its children get merged into another window. */ 3902 that its children get merged into another window. */
3903 wset_combination_limit (p, Qt); 3903 wset_combination_limit (p, Qt);
3904 /* These get applied below. */ 3904 /* These get applied below. */
3905 wset_new_total (p, horflag ? o->total_cols : o->total_lines); 3905 wset_new_total (p, make_number
3906 (horflag ? o->total_cols : o->total_lines));
3906 wset_new_normal (p, new_normal); 3907 wset_new_normal (p, new_normal);
3907 } 3908 }
3908 else 3909 else
@@ -3954,13 +3955,13 @@ set correctly. See the code of `split-window' for how this is done. */)
3954 /* Directly assign orthogonal coordinates and sizes. */ 3955 /* Directly assign orthogonal coordinates and sizes. */
3955 if (horflag) 3956 if (horflag)
3956 { 3957 {
3957 wset_top_line (n, o->top_line); 3958 n->top_line = o->top_line;
3958 wset_total_lines (n, o->total_lines); 3959 n->total_lines = o->total_lines;
3959 } 3960 }
3960 else 3961 else
3961 { 3962 {
3962 wset_left_col (n, o->left_col); 3963 n->left_col = o->left_col;
3963 wset_total_cols (n, o->total_cols); 3964 n->total_cols = o->total_cols;
3964 } 3965 }
3965 3966
3966 /* Iso-coordinates and sizes are assigned by window_resize_apply, 3967 /* Iso-coordinates and sizes are assigned by window_resize_apply,
@@ -3995,7 +3996,7 @@ Signal an error when WINDOW is the only window on its frame. */)
3995 register Lisp_Object parent, sibling, frame, root; 3996 register Lisp_Object parent, sibling, frame, root;
3996 struct window *w, *p, *s, *r; 3997 struct window *w, *p, *s, *r;
3997 struct frame *f; 3998 struct frame *f;
3998 int horflag; 3999 bool horflag;
3999 int before_sibling = 0; 4000 int before_sibling = 0;
4000 4001
4001 w = decode_any_window (window); 4002 w = decode_any_window (window);
@@ -4049,8 +4050,8 @@ Signal an error when WINDOW is the only window on its frame. */)
4049 } 4050 }
4050 4051
4051 if (window_resize_check (r, horflag) 4052 if (window_resize_check (r, horflag)
4052 && EQ (r->new_total, 4053 && (XINT (r->new_total)
4053 (horflag ? r->total_cols : r->total_lines))) 4054 == (horflag ? r->total_cols : r->total_lines)))
4054 /* We can delete WINDOW now. */ 4055 /* We can delete WINDOW now. */
4055 { 4056 {
4056 4057
@@ -4199,10 +4200,8 @@ grow_mini_window (struct window *w, int delta)
4199 window_resize_apply (r, 0); 4200 window_resize_apply (r, 0);
4200 4201
4201 /* Grow the mini-window. */ 4202 /* Grow the mini-window. */
4202 wset_top_line 4203 w->top_line = r->top_line + r->total_lines;
4203 (w, make_number (XFASTINT (r->top_line) + XFASTINT (r->total_lines))); 4204 w->total_lines -= XINT (value);
4204 wset_total_lines
4205 (w, make_number (XFASTINT (w->total_lines) - XINT (value)));
4206 w->last_modified = 0; 4205 w->last_modified = 0;
4207 w->last_overlay_modified = 0; 4206 w->last_overlay_modified = 0;
4208 4207
@@ -4224,7 +4223,7 @@ shrink_mini_window (struct window *w)
4224 4223
4225 eassert (MINI_WINDOW_P (w)); 4224 eassert (MINI_WINDOW_P (w));
4226 4225
4227 size = XINT (w->total_lines); 4226 size = w->total_lines;
4228 if (size > 1) 4227 if (size > 1)
4229 { 4228 {
4230 root = FRAME_ROOT_WINDOW (f); 4229 root = FRAME_ROOT_WINDOW (f);
@@ -4237,9 +4236,8 @@ shrink_mini_window (struct window *w)
4237 window_resize_apply (r, 0); 4236 window_resize_apply (r, 0);
4238 4237
4239 /* Shrink the mini-window. */ 4238 /* Shrink the mini-window. */
4240 wset_top_line (w, make_number (XFASTINT (r->top_line) 4239 w->top_line = r->top_line + r->total_lines;
4241 + XFASTINT (r->total_lines))); 4240 w->total_lines = 1;
4242 wset_total_lines (w, make_number (1));
4243 4241
4244 w->last_modified = 0; 4242 w->last_modified = 0;
4245 w->last_overlay_modified = 0; 4243 w->last_overlay_modified = 0;
@@ -4273,7 +4271,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4273 error ("Cannot resize a minibuffer-only frame"); 4271 error ("Cannot resize a minibuffer-only frame");
4274 4272
4275 r = XWINDOW (FRAME_ROOT_WINDOW (f)); 4273 r = XWINDOW (FRAME_ROOT_WINDOW (f));
4276 height = XINT (r->total_lines) + XINT (w->total_lines); 4274 height = r->total_lines + w->total_lines;
4277 if (window_resize_check (r, 0) 4275 if (window_resize_check (r, 0)
4278 && XINT (w->new_total) > 0 4276 && XINT (w->new_total) > 0
4279 && height == XINT (r->new_total) + XINT (w->new_total)) 4277 && height == XINT (r->new_total) + XINT (w->new_total))
@@ -4281,9 +4279,8 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4281 block_input (); 4279 block_input ();
4282 window_resize_apply (r, 0); 4280 window_resize_apply (r, 0);
4283 4281
4284 wset_total_lines (w, w->new_total); 4282 w->total_lines = XFASTINT (w->new_total);
4285 wset_top_line (w, make_number (XINT (r->top_line) 4283 w->top_line = r->top_line + r->total_lines;
4286 + XINT (r->total_lines)));
4287 4284
4288 windows_or_buffers_changed++; 4285 windows_or_buffers_changed++;
4289 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4286 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
@@ -4323,7 +4320,7 @@ mark_window_cursors_off (struct window *w)
4323int 4320int
4324window_internal_height (struct window *w) 4321window_internal_height (struct window *w)
4325{ 4322{
4326 int ht = XFASTINT (w->total_lines); 4323 int ht = w->total_lines;
4327 4324
4328 if (!MINI_WINDOW_P (w)) 4325 if (!MINI_WINDOW_P (w))
4329 { 4326 {
@@ -4633,7 +4630,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4633 even if there is a header line. */ 4630 even if there is a header line. */
4634 this_scroll_margin = max (0, scroll_margin); 4631 this_scroll_margin = max (0, scroll_margin);
4635 this_scroll_margin 4632 this_scroll_margin
4636 = min (this_scroll_margin, XFASTINT (w->total_lines) / 4); 4633 = min (this_scroll_margin, w->total_lines / 4);
4637 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f); 4634 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4638 4635
4639 if (n > 0) 4636 if (n > 0)
@@ -4810,7 +4807,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4810 { 4807 {
4811 /* Don't use a scroll margin that is negative or too large. */ 4808 /* Don't use a scroll margin that is negative or too large. */
4812 int this_scroll_margin = 4809 int this_scroll_margin =
4813 max (0, min (scroll_margin, XINT (w->total_lines) / 4)); 4810 max (0, min (scroll_margin, w->total_lines / 4));
4814 4811
4815 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); 4812 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4816 w->start_at_line_beg = !NILP (bolp); 4813 w->start_at_line_beg = !NILP (bolp);
@@ -5227,7 +5224,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5227 /* Do this after making BUF current 5224 /* Do this after making BUF current
5228 in case scroll_margin is buffer-local. */ 5225 in case scroll_margin is buffer-local. */
5229 this_scroll_margin = 5226 this_scroll_margin =
5230 max (0, min (scroll_margin, XFASTINT (w->total_lines) / 4)); 5227 max (0, min (scroll_margin, w->total_lines / 4));
5231 5228
5232 /* Handle centering on a graphical frame specially. Such frames can 5229 /* Handle centering on a graphical frame specially. Such frames can
5233 have variable-height lines and centering point on the basis of 5230 have variable-height lines and centering point on the basis of
@@ -5701,7 +5698,7 @@ the return value is nil. Otherwise the value is t. */)
5701 wset_prev (w, Qnil); 5698 wset_prev (w, Qnil);
5702 if (!NILP (w->parent)) 5699 if (!NILP (w->parent))
5703 { 5700 {
5704 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols)) 5701 if (XINT (p->total_cols) == XWINDOW (w->parent)->total_cols)
5705 { 5702 {
5706 wset_vchild (XWINDOW (w->parent), p->window); 5703 wset_vchild (XWINDOW (w->parent), p->window);
5707 wset_hchild (XWINDOW (w->parent), Qnil); 5704 wset_hchild (XWINDOW (w->parent), Qnil);
@@ -5714,14 +5711,13 @@ the return value is nil. Otherwise the value is t. */)
5714 } 5711 }
5715 } 5712 }
5716 5713
5717 /* If we squirreled away the buffer in the window's height, 5714 /* If we squirreled away the buffer, restore it now. */
5718 restore it now. */ 5715 if (BUFFERP (w->combination_limit))
5719 if (BUFFERP (w->total_lines)) 5716 wset_buffer (w, w->combination_limit);
5720 wset_buffer (w, w->total_lines); 5717 w->left_col = XFASTINT (p->left_col);
5721 wset_left_col (w, p->left_col); 5718 w->top_line = XFASTINT (p->top_line);
5722 wset_top_line (w, p->top_line); 5719 w->total_cols = XFASTINT (p->total_cols);
5723 wset_total_cols (w, p->total_cols); 5720 w->total_lines = XFASTINT (p->total_lines);
5724 wset_total_lines (w, p->total_lines);
5725 wset_normal_cols (w, p->normal_cols); 5721 wset_normal_cols (w, p->normal_cols);
5726 wset_normal_lines (w, p->normal_lines); 5722 wset_normal_lines (w, p->normal_lines);
5727 w->hscroll = XFASTINT (p->hscroll); 5723 w->hscroll = XFASTINT (p->hscroll);
@@ -5921,9 +5917,6 @@ delete_all_child_windows (Lisp_Object window)
5921 /* Delete WINDOW's siblings (we traverse postorderly). */ 5917 /* Delete WINDOW's siblings (we traverse postorderly). */
5922 delete_all_child_windows (w->next); 5918 delete_all_child_windows (w->next);
5923 5919
5924 /* See Fset_window_configuration for excuse. */
5925 wset_total_lines (w, w->buffer);
5926
5927 if (!NILP (w->vchild)) 5920 if (!NILP (w->vchild))
5928 { 5921 {
5929 delete_all_child_windows (w->vchild); 5922 delete_all_child_windows (w->vchild);
@@ -5939,6 +5932,10 @@ delete_all_child_windows (Lisp_Object window)
5939 unshow_buffer (w); 5932 unshow_buffer (w);
5940 unchain_marker (XMARKER (w->pointm)); 5933 unchain_marker (XMARKER (w->pointm));
5941 unchain_marker (XMARKER (w->start)); 5934 unchain_marker (XMARKER (w->start));
5935 /* Since combination limit makes sense for an internal windows
5936 only, we use this slot to save the buffer for the sake of
5937 possible resurrection in Fset_window_configuration. */
5938 wset_combination_limit (w, w->buffer);
5942 wset_buffer (w, Qnil); 5939 wset_buffer (w, Qnil);
5943 } 5940 }
5944 5941
@@ -6009,8 +6006,7 @@ get_phys_cursor_glyph (struct window *w)
6009 hpos = row->used[TEXT_AREA] - 1; 6006 hpos = row->used[TEXT_AREA] - 1;
6010 } 6007 }
6011 6008
6012 if (row->used[TEXT_AREA] > hpos 6009 if (hpos >= 0 && hpos < row->used[TEXT_AREA])
6013 && 0 <= hpos)
6014 glyph = row->glyphs[TEXT_AREA] + hpos; 6010 glyph = row->glyphs[TEXT_AREA] + hpos;
6015 else 6011 else
6016 glyph = NULL; 6012 glyph = NULL;
@@ -6034,10 +6030,10 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
6034 wset_temslot (w, make_number (i)); i++; 6030 wset_temslot (w, make_number (i)); i++;
6035 p->window = window; 6031 p->window = window;
6036 p->buffer = w->buffer; 6032 p->buffer = w->buffer;
6037 p->left_col = w->left_col; 6033 p->left_col = make_number (w->left_col);
6038 p->top_line = w->top_line; 6034 p->top_line = make_number (w->top_line);
6039 p->total_cols = w->total_cols; 6035 p->total_cols = make_number (w->total_cols);
6040 p->total_lines = w->total_lines; 6036 p->total_lines = make_number (w->total_lines);
6041 p->normal_cols = w->normal_cols; 6037 p->normal_cols = w->normal_cols;
6042 p->normal_lines = w->normal_lines; 6038 p->normal_lines = w->normal_lines;
6043 XSETFASTINT (p->hscroll, w->hscroll); 6039 XSETFASTINT (p->hscroll, w->hscroll);
@@ -6531,7 +6527,7 @@ freeze_window_start (struct window *w, void *freeze_p)
6531 means freeze the window start. */ 6527 means freeze the window start. */
6532 6528
6533void 6529void
6534freeze_window_starts (struct frame *f, int freeze_p) 6530freeze_window_starts (struct frame *f, bool freeze_p)
6535{ 6531{
6536 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0)); 6532 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6537} 6533}
diff --git a/src/window.h b/src/window.h
index dcef37abb4c..71c438ff7f2 100644
--- a/src/window.h
+++ b/src/window.h
@@ -112,20 +112,14 @@ struct window
112 /* The window this one is a child of. */ 112 /* The window this one is a child of. */
113 Lisp_Object parent; 113 Lisp_Object parent;
114 114
115 /* The upper left corner coordinates of this window, as integers 115 /* The normal size of the window. These are fractions, but we do
116 relative to upper left corner of frame = 0, 0. */ 116 not use C doubles to avoid creating new Lisp_Float objects while
117 Lisp_Object left_col; 117 interfacing Lisp in Fwindow_normal_size. */
118 Lisp_Object top_line;
119
120 /* The size of the window. */
121 Lisp_Object total_lines;
122 Lisp_Object total_cols;
123
124 /* The normal size of the window. */
125 Lisp_Object normal_lines; 118 Lisp_Object normal_lines;
126 Lisp_Object normal_cols; 119 Lisp_Object normal_cols;
127 120
128 /* New sizes of the window. */ 121 /* New sizes of the window. Note that Lisp code may set new_normal
122 to something beyond an integer, so C int can't be used here. */
129 Lisp_Object new_total; 123 Lisp_Object new_total;
130 Lisp_Object new_normal; 124 Lisp_Object new_normal;
131 125
@@ -221,6 +215,15 @@ struct window
221 /* Number saying how recently window was selected. */ 215 /* Number saying how recently window was selected. */
222 int use_time; 216 int use_time;
223 217
218 /* The upper left corner coordinates of this window,
219 relative to upper left corner of frame = 0, 0. */
220 int left_col;
221 int top_line;
222
223 /* The size of the window. */
224 int total_lines;
225 int total_cols;
226
224 /* Number of columns display within the window is scrolled to the left. */ 227 /* Number of columns display within the window is scrolled to the left. */
225 ptrdiff_t hscroll; 228 ptrdiff_t hscroll;
226 229
@@ -354,11 +357,6 @@ wset_frame (struct window *w, Lisp_Object val)
354 w->frame = val; 357 w->frame = val;
355} 358}
356WINDOW_INLINE void 359WINDOW_INLINE void
357wset_left_col (struct window *w, Lisp_Object val)
358{
359 w->left_col = val;
360}
361WINDOW_INLINE void
362wset_next (struct window *w, Lisp_Object val) 360wset_next (struct window *w, Lisp_Object val)
363{ 361{
364 w->next = val; 362 w->next = val;
@@ -374,21 +372,6 @@ wset_redisplay_end_trigger (struct window *w, Lisp_Object val)
374 w->redisplay_end_trigger = val; 372 w->redisplay_end_trigger = val;
375} 373}
376WINDOW_INLINE void 374WINDOW_INLINE void
377wset_top_line (struct window *w, Lisp_Object val)
378{
379 w->top_line = val;
380}
381WINDOW_INLINE void
382wset_total_cols (struct window *w, Lisp_Object val)
383{
384 w->total_cols = val;
385}
386WINDOW_INLINE void
387wset_total_lines (struct window *w, Lisp_Object val)
388{
389 w->total_lines = val;
390}
391WINDOW_INLINE void
392wset_vertical_scroll_bar (struct window *w, Lisp_Object val) 375wset_vertical_scroll_bar (struct window *w, Lisp_Object val)
393{ 376{
394 w->vertical_scroll_bar = val; 377 w->vertical_scroll_bar = val;
@@ -461,14 +444,12 @@ wset_next_buffers (struct window *w, Lisp_Object val)
461/* Return the width of window W in canonical column units. 444/* Return the width of window W in canonical column units.
462 This includes scroll bars and fringes. */ 445 This includes scroll bars and fringes. */
463 446
464#define WINDOW_TOTAL_COLS(W) \ 447#define WINDOW_TOTAL_COLS(W) (W)->total_cols
465 (XFASTINT (W->total_cols))
466 448
467/* Return the height of window W in canonical line units. 449/* Return the height of window W in canonical line units.
468 This includes header and mode lines, if any. */ 450 This includes header and mode lines, if any. */
469 451
470#define WINDOW_TOTAL_LINES(W) \ 452#define WINDOW_TOTAL_LINES(W) (W)->total_lines
471 (XFASTINT (W->total_lines))
472 453
473/* Return the total pixel width of window W. */ 454/* Return the total pixel width of window W. */
474 455
@@ -495,8 +476,7 @@ wset_next_buffers (struct window *w, Lisp_Object val)
495/* Return the canonical frame column at which window W starts. 476/* Return the canonical frame column at which window W starts.
496 This includes a left-hand scroll bar, if any. */ 477 This includes a left-hand scroll bar, if any. */
497 478
498#define WINDOW_LEFT_EDGE_COL(W) \ 479#define WINDOW_LEFT_EDGE_COL(W) (W)->left_col
499 (XFASTINT (W->left_col))
500 480
501/* Return the canonical frame column before which window W ends. 481/* Return the canonical frame column before which window W ends.
502 This includes a right-hand scroll bar, if any. */ 482 This includes a right-hand scroll bar, if any. */
@@ -507,8 +487,7 @@ wset_next_buffers (struct window *w, Lisp_Object val)
507/* Return the canonical frame line at which window W starts. 487/* Return the canonical frame line at which window W starts.
508 This includes a header line, if any. */ 488 This includes a header line, if any. */
509 489
510#define WINDOW_TOP_EDGE_LINE(W) \ 490#define WINDOW_TOP_EDGE_LINE(W) (W)->top_line
511 (XFASTINT (W->top_line))
512 491
513/* Return the canonical frame line before which window W ends. 492/* Return the canonical frame line before which window W ends.
514 This includes a mode line, if any. */ 493 This includes a mode line, if any. */
@@ -533,9 +512,14 @@ wset_next_buffers (struct window *w, Lisp_Object val)
533 512
534/* 1 if W is a menu bar window. */ 513/* 1 if W is a menu bar window. */
535 514
515#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
536#define WINDOW_MENU_BAR_P(W) \ 516#define WINDOW_MENU_BAR_P(W) \
537 (WINDOWP (WINDOW_XFRAME (W)->menu_bar_window) \ 517 (WINDOWP (WINDOW_XFRAME (W)->menu_bar_window) \
538 && (W) == XWINDOW (WINDOW_XFRAME (W)->menu_bar_window)) 518 && (W) == XWINDOW (WINDOW_XFRAME (W)->menu_bar_window))
519#else
520/* No menu bar windows if X toolkit is in use. */
521#define WINDOW_MENU_BAR_P(W) (0)
522#endif
539 523
540/* 1 if W is a tool bar window. */ 524/* 1 if W is a tool bar window. */
541 525
@@ -891,10 +875,10 @@ extern Lisp_Object Vmouse_event;
891 875
892extern Lisp_Object make_window (void); 876extern Lisp_Object make_window (void);
893extern Lisp_Object window_from_coordinates (struct frame *, int, int, 877extern Lisp_Object window_from_coordinates (struct frame *, int, int,
894 enum window_part *, int); 878 enum window_part *, bool);
895extern void resize_frame_windows (struct frame *, int, int); 879extern void resize_frame_windows (struct frame *, int, bool);
896extern void delete_all_child_windows (Lisp_Object); 880extern void delete_all_child_windows (Lisp_Object);
897extern void freeze_window_starts (struct frame *, int); 881extern void freeze_window_starts (struct frame *, bool);
898extern void grow_mini_window (struct window *, int); 882extern void grow_mini_window (struct window *, int);
899extern void shrink_mini_window (struct window *); 883extern void shrink_mini_window (struct window *);
900extern int window_relative_x_coord (struct window *, enum window_part, int); 884extern int window_relative_x_coord (struct window *, enum window_part, int);
@@ -906,7 +890,7 @@ void run_window_configuration_change_hook (struct frame *f);
906 it's not allowed. */ 890 it's not allowed. */
907 891
908void set_window_buffer (Lisp_Object window, Lisp_Object buffer, 892void set_window_buffer (Lisp_Object window, Lisp_Object buffer,
909 int run_hooks_p, int keep_margins_p); 893 bool run_hooks_p, bool keep_margins_p);
910 894
911/* This is the window where the echo area message was displayed. It 895/* This is the window where the echo area message was displayed. It
912 is always a minibuffer window, but it may not be the same window 896 is always a minibuffer window, but it may not be the same window
diff --git a/src/xdisp.c b/src/xdisp.c
index b60b393e614..bd68b286f4e 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -984,7 +984,7 @@ window_text_bottom_y (struct window *w)
984int 984int
985window_box_width (struct window *w, int area) 985window_box_width (struct window *w, int area)
986{ 986{
987 int cols = XFASTINT (w->total_cols); 987 int cols = w->total_cols;
988 int pixels = 0; 988 int pixels = 0;
989 989
990 if (!w->pseudo_window_p) 990 if (!w->pseudo_window_p)
@@ -2682,7 +2682,7 @@ init_iterator (struct it *it, struct window *w,
2682 and IT->region_end_charpos to the start and end of a visible region 2682 and IT->region_end_charpos to the start and end of a visible region
2683 in window IT->w. Set both to -1 to indicate no region. */ 2683 in window IT->w. Set both to -1 to indicate no region. */
2684 markpos = markpos_of_region (); 2684 markpos = markpos_of_region ();
2685 if (0 <= markpos 2685 if (markpos >= 0
2686 /* Maybe highlight only in selected window. */ 2686 /* Maybe highlight only in selected window. */
2687 && (/* Either show region everywhere. */ 2687 && (/* Either show region everywhere. */
2688 highlight_nonselected_windows 2688 highlight_nonselected_windows
@@ -13231,8 +13231,8 @@ redisplay_internal (void)
13231 PT == w->last_point 13231 PT == w->last_point
13232 /* Make sure the cursor was last displayed 13232 /* Make sure the cursor was last displayed
13233 in this window. Otherwise we have to reposition it. */ 13233 in this window. Otherwise we have to reposition it. */
13234 && 0 <= w->cursor.vpos 13234 && w->cursor.vpos >= 0
13235 && WINDOW_TOTAL_LINES (w) > w->cursor.vpos) 13235 && w->cursor.vpos < WINDOW_TOTAL_LINES (w))
13236 { 13236 {
13237 if (!must_finish) 13237 if (!must_finish)
13238 { 13238 {
@@ -15581,7 +15581,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15581 15581
15582 /* If we are highlighting the region, then we just changed 15582 /* If we are highlighting the region, then we just changed
15583 the region, so redisplay to show it. */ 15583 the region, so redisplay to show it. */
15584 if (0 <= markpos_of_region ()) 15584 if (markpos_of_region () >= 0)
15585 { 15585 {
15586 clear_glyph_matrix (w->desired_matrix); 15586 clear_glyph_matrix (w->desired_matrix);
15587 if (!try_window (window, startp, 0)) 15587 if (!try_window (window, startp, 0))
@@ -16296,7 +16296,7 @@ try_window_reusing_current_matrix (struct window *w)
16296 return 0; 16296 return 0;
16297 16297
16298 /* Can't do this if region may have changed. */ 16298 /* Can't do this if region may have changed. */
16299 if (0 <= markpos_of_region () 16299 if (markpos_of_region () >= 0
16300 || w->region_showing 16300 || w->region_showing
16301 || !NILP (Vshow_trailing_whitespace)) 16301 || !NILP (Vshow_trailing_whitespace))
16302 return 0; 16302 return 0;
@@ -17135,7 +17135,7 @@ try_window_id (struct window *w)
17135 17135
17136 /* Can't use this if highlighting a region because a cursor movement 17136 /* Can't use this if highlighting a region because a cursor movement
17137 will do more than just set the cursor. */ 17137 will do more than just set the cursor. */
17138 if (0 <= markpos_of_region ()) 17138 if (markpos_of_region () >= 0)
17139 GIVE_UP (9); 17139 GIVE_UP (9);
17140 17140
17141 /* Likewise if highlighting trailing whitespace. */ 17141 /* Likewise if highlighting trailing whitespace. */
@@ -20093,18 +20093,17 @@ display_menu_bar (struct window *w)
20093 return; 20093 return;
20094#endif /* HAVE_NS */ 20094#endif /* HAVE_NS */
20095 20095
20096#ifdef USE_X_TOOLKIT 20096#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20097 eassert (!FRAME_WINDOW_P (f)); 20097 eassert (!FRAME_WINDOW_P (f));
20098 init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MENU_FACE_ID); 20098 init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MENU_FACE_ID);
20099 it.first_visible_x = 0; 20099 it.first_visible_x = 0;
20100 it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f); 20100 it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f);
20101#else /* not USE_X_TOOLKIT */ 20101#elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20102 if (FRAME_WINDOW_P (f)) 20102 if (FRAME_WINDOW_P (f))
20103 { 20103 {
20104 /* Menu bar lines are displayed in the desired matrix of the 20104 /* Menu bar lines are displayed in the desired matrix of the
20105 dummy window menu_bar_window. */ 20105 dummy window menu_bar_window. */
20106 struct window *menu_w; 20106 struct window *menu_w;
20107 eassert (WINDOWP (f->menu_bar_window));
20108 menu_w = XWINDOW (f->menu_bar_window); 20107 menu_w = XWINDOW (f->menu_bar_window);
20109 init_iterator (&it, menu_w, -1, -1, menu_w->desired_matrix->rows, 20108 init_iterator (&it, menu_w, -1, -1, menu_w->desired_matrix->rows,
20110 MENU_FACE_ID); 20109 MENU_FACE_ID);
@@ -20112,6 +20111,7 @@ display_menu_bar (struct window *w)
20112 it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f); 20111 it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f);
20113 } 20112 }
20114 else 20113 else
20114#endif /* not USE_X_TOOLKIT and not USE_GTK */
20115 { 20115 {
20116 /* This is a TTY frame, i.e. character hpos/vpos are used as 20116 /* This is a TTY frame, i.e. character hpos/vpos are used as
20117 pixel x/y. */ 20117 pixel x/y. */
@@ -20120,7 +20120,6 @@ display_menu_bar (struct window *w)
20120 it.first_visible_x = 0; 20120 it.first_visible_x = 0;
20121 it.last_visible_x = FRAME_COLS (f); 20121 it.last_visible_x = FRAME_COLS (f);
20122 } 20122 }
20123#endif /* not USE_X_TOOLKIT */
20124 20123
20125 /* FIXME: This should be controlled by a user option. See the 20124 /* FIXME: This should be controlled by a user option. See the
20126 comments in redisplay_tool_bar and display_mode_line about 20125 comments in redisplay_tool_bar and display_mode_line about
@@ -21114,7 +21113,7 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
21114 char * psuffix; 21113 char * psuffix;
21115 char * p; 21114 char * p;
21116 21115
21117 if (1000 <= quotient) 21116 if (quotient >= 1000)
21118 { 21117 {
21119 /* Scale to the appropriate EXPONENT. */ 21118 /* Scale to the appropriate EXPONENT. */
21120 do 21119 do
@@ -21123,13 +21122,13 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
21123 quotient /= 1000; 21122 quotient /= 1000;
21124 exponent++; 21123 exponent++;
21125 } 21124 }
21126 while (1000 <= quotient); 21125 while (quotient >= 1000);
21127 21126
21128 /* Round to nearest and decide whether to use TENTHS or not. */ 21127 /* Round to nearest and decide whether to use TENTHS or not. */
21129 if (quotient <= 9) 21128 if (quotient <= 9)
21130 { 21129 {
21131 tenths = remainder / 100; 21130 tenths = remainder / 100;
21132 if (50 <= remainder % 100) 21131 if (remainder % 100 >= 50)
21133 { 21132 {
21134 if (tenths < 9) 21133 if (tenths < 9)
21135 tenths++; 21134 tenths++;
@@ -21144,7 +21143,7 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
21144 } 21143 }
21145 } 21144 }
21146 else 21145 else
21147 if (500 <= remainder) 21146 if (remainder >= 500)
21148 { 21147 {
21149 if (quotient < 999) 21148 if (quotient < 999)
21150 quotient++; 21149 quotient++;
@@ -22187,11 +22186,6 @@ else if the text is replaced by an ellipsis. */)
22187 22186
22188*/ 22187*/
22189 22188
22190#define NUMVAL(X) \
22191 ((INTEGERP (X) || FLOATP (X)) \
22192 ? XFLOATINT (X) \
22193 : - 1)
22194
22195static int 22189static int
22196calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop, 22190calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
22197 struct font *font, int width_p, int *align_to) 22191 struct font *font, int width_p, int *align_to)
@@ -22222,24 +22216,11 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
22222 pixels = 0; 22216 pixels = 0;
22223 if (pixels > 0) 22217 if (pixels > 0)
22224 { 22218 {
22225 double ppi; 22219 double ppi = (width_p ? FRAME_RES_X (it->f)
22226#ifdef HAVE_WINDOW_SYSTEM 22220 : FRAME_RES_Y (it->f));
22227 if (FRAME_WINDOW_P (it->f)
22228 && (ppi = (width_p
22229 ? FRAME_X_DISPLAY_INFO (it->f)->resx
22230 : FRAME_X_DISPLAY_INFO (it->f)->resy),
22231 ppi > 0))
22232 return OK_PIXELS (ppi / pixels);
22233#endif
22234 22221
22235 if ((ppi = NUMVAL (Vdisplay_pixels_per_inch), ppi > 0) 22222 if (ppi > 0)
22236 || (CONSP (Vdisplay_pixels_per_inch)
22237 && (ppi = (width_p
22238 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch))
22239 : NUMVAL (XCDR (Vdisplay_pixels_per_inch))),
22240 ppi > 0)))
22241 return OK_PIXELS (ppi / pixels); 22223 return OK_PIXELS (ppi / pixels);
22242
22243 return 0; 22224 return 0;
22244 } 22225 }
22245 } 22226 }
@@ -22522,16 +22503,16 @@ get_char_face_and_encoding (struct frame *f, int c, int face_id,
22522 XChar2b *char2b, int display_p) 22503 XChar2b *char2b, int display_p)
22523{ 22504{
22524 struct face *face = FACE_FROM_ID (f, face_id); 22505 struct face *face = FACE_FROM_ID (f, face_id);
22506 unsigned code = 0;
22525 22507
22526 if (face->font) 22508 if (face->font)
22527 { 22509 {
22528 unsigned code = face->font->driver->encode_char (face->font, c); 22510 code = face->font->driver->encode_char (face->font, c);
22529 22511
22530 if (code != FONT_INVALID_CODE) 22512 if (code == FONT_INVALID_CODE)
22531 STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF)); 22513 code = 0;
22532 else
22533 STORE_XCHAR2B (char2b, 0, 0);
22534 } 22514 }
22515 STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
22535 22516
22536 /* Make sure X resources of the face are allocated. */ 22517 /* Make sure X resources of the face are allocated. */
22537#ifdef HAVE_X_WINDOWS 22518#ifdef HAVE_X_WINDOWS
@@ -22555,31 +22536,30 @@ get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
22555 XChar2b *char2b, int *two_byte_p) 22536 XChar2b *char2b, int *two_byte_p)
22556{ 22537{
22557 struct face *face; 22538 struct face *face;
22539 unsigned code = 0;
22558 22540
22559 eassert (glyph->type == CHAR_GLYPH); 22541 eassert (glyph->type == CHAR_GLYPH);
22560 face = FACE_FROM_ID (f, glyph->face_id); 22542 face = FACE_FROM_ID (f, glyph->face_id);
22561 22543
22544 /* Make sure X resources of the face are allocated. */
22545 eassert (face != NULL);
22546 PREPARE_FACE_FOR_DISPLAY (f, face);
22547
22562 if (two_byte_p) 22548 if (two_byte_p)
22563 *two_byte_p = 0; 22549 *two_byte_p = 0;
22564 22550
22565 if (face->font) 22551 if (face->font)
22566 { 22552 {
22567 unsigned code;
22568
22569 if (CHAR_BYTE8_P (glyph->u.ch)) 22553 if (CHAR_BYTE8_P (glyph->u.ch))
22570 code = CHAR_TO_BYTE8 (glyph->u.ch); 22554 code = CHAR_TO_BYTE8 (glyph->u.ch);
22571 else 22555 else
22572 code = face->font->driver->encode_char (face->font, glyph->u.ch); 22556 code = face->font->driver->encode_char (face->font, glyph->u.ch);
22573 22557
22574 if (code != FONT_INVALID_CODE) 22558 if (code == FONT_INVALID_CODE)
22575 STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF)); 22559 code = 0;
22576 else
22577 STORE_XCHAR2B (char2b, 0, 0);
22578 } 22560 }
22579 22561
22580 /* Make sure X resources of the face are allocated. */ 22562 STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
22581 eassert (face != NULL);
22582 PREPARE_FACE_FOR_DISPLAY (f, face);
22583 return face; 22563 return face;
22584} 22564}
22585 22565
@@ -22902,9 +22882,12 @@ static struct font_metrics *
22902get_per_char_metric (struct font *font, XChar2b *char2b) 22882get_per_char_metric (struct font *font, XChar2b *char2b)
22903{ 22883{
22904 static struct font_metrics metrics; 22884 static struct font_metrics metrics;
22905 unsigned code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b); 22885 unsigned code;
22906 22886
22907 if (! font || code == FONT_INVALID_CODE) 22887 if (! font)
22888 return NULL;
22889 code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b);
22890 if (code == FONT_INVALID_CODE)
22908 return NULL; 22891 return NULL;
22909 font->driver->text_extents (font, &code, 1, &metrics); 22892 font->driver->text_extents (font, &code, 1, &metrics);
22910 return &metrics; 22893 return &metrics;
@@ -28750,11 +28733,11 @@ expose_frame (struct frame *f, int x, int y, int w, int h)
28750 28733
28751#ifdef HAVE_X_WINDOWS 28734#ifdef HAVE_X_WINDOWS
28752#ifndef MSDOS 28735#ifndef MSDOS
28753#ifndef USE_X_TOOLKIT 28736#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
28754 if (WINDOWP (f->menu_bar_window)) 28737 if (WINDOWP (f->menu_bar_window))
28755 mouse_face_overwritten_p 28738 mouse_face_overwritten_p
28756 |= expose_window (XWINDOW (f->menu_bar_window), &r); 28739 |= expose_window (XWINDOW (f->menu_bar_window), &r);
28757#endif /* not USE_X_TOOLKIT */ 28740#endif /* not USE_X_TOOLKIT and not USE_GTK */
28758#endif 28741#endif
28759#endif 28742#endif
28760 28743
@@ -29488,13 +29471,13 @@ init_xdisp (void)
29488 29471
29489 echo_area_window = minibuf_window; 29472 echo_area_window = minibuf_window;
29490 29473
29491 wset_top_line (r, make_number (FRAME_TOP_MARGIN (f))); 29474 r->top_line = FRAME_TOP_MARGIN (f);
29492 wset_total_lines 29475 r->total_lines = FRAME_LINES (f) - 1 - FRAME_TOP_MARGIN (f);
29493 (r, make_number (FRAME_LINES (f) - 1 - FRAME_TOP_MARGIN (f))); 29476 r->total_cols = FRAME_COLS (f);
29494 wset_total_cols (r, make_number (FRAME_COLS (f))); 29477
29495 wset_top_line (m, make_number (FRAME_LINES (f) - 1)); 29478 m->top_line = FRAME_LINES (f) - 1;
29496 wset_total_lines (m, make_number (1)); 29479 m->total_lines = 1;
29497 wset_total_cols (m, make_number (FRAME_COLS (f))); 29480 m->total_cols = FRAME_COLS (f);
29498 29481
29499 scratch_glyph_row.glyphs[TEXT_AREA] = scratch_glyphs; 29482 scratch_glyph_row.glyphs[TEXT_AREA] = scratch_glyphs;
29500 scratch_glyph_row.glyphs[TEXT_AREA + 1] 29483 scratch_glyph_row.glyphs[TEXT_AREA + 1]
diff --git a/src/xfaces.c b/src/xfaces.c
index 71709446c1d..6db6ac7683f 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -112,7 +112,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
112 merging faces of that character, that face is `realized'. The 112 merging faces of that character, that face is `realized'. The
113 realization process maps face attributes to what is physically 113 realization process maps face attributes to what is physically
114 available on the system where Emacs runs. The result is a 114 available on the system where Emacs runs. The result is a
115 `realized face' in form of a struct face which is stored in the 115 `realized face' in the form of a struct face which is stored in the
116 face cache of the frame on which it was realized. 116 face cache of the frame on which it was realized.
117 117
118 Face realization is done in the context of the character to display 118 Face realization is done in the context of the character to display
@@ -1592,7 +1592,7 @@ the face font sort order. */)
1592 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX)); 1592 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX));
1593 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font)); 1593 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font));
1594 point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10, 1594 point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10,
1595 XFRAME (frame)->resy); 1595 FRAME_RES_Y (XFRAME (frame)));
1596 ASET (v, 2, make_number (point)); 1596 ASET (v, 2, make_number (point));
1597 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font)); 1597 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font));
1598 ASET (v, 4, FONT_SLANT_SYMBOLIC (font)); 1598 ASET (v, 4, FONT_SLANT_SYMBOLIC (font));
@@ -2118,7 +2118,7 @@ set_lface_from_font (struct frame *f, Lisp_Object lface,
2118 2118
2119 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface))) 2119 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface)))
2120 { 2120 {
2121 int pt = PIXEL_TO_POINT (font->pixel_size * 10, f->resy); 2121 int pt = PIXEL_TO_POINT (font->pixel_size * 10, FRAME_RES_Y (f));
2122 2122
2123 eassert (pt > 0); 2123 eassert (pt > 0);
2124 ASET (lface, LFACE_HEIGHT_INDEX, make_number (pt)); 2124 ASET (lface, LFACE_HEIGHT_INDEX, make_number (pt));
@@ -3395,21 +3395,22 @@ set_font_frame_param (Lisp_Object frame, Lisp_Object lface)
3395 } 3395 }
3396} 3396}
3397 3397
3398
3399/* Get the value of X resource RESOURCE, class CLASS for the display
3400 of frame FRAME. This is here because ordinary `x-get-resource'
3401 doesn't take a frame argument. */
3402
3403DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource, 3398DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource,
3404 Sinternal_face_x_get_resource, 3, 3, 0, doc: /* */) 3399 Sinternal_face_x_get_resource, 2, 3, 0,
3400 doc: /* Get the value of X resource RESOURCE, class CLASS.
3401Returned value is for the display of frame FRAME. If FRAME is not
3402specified or nil, use selected frame. This function exists because
3403ordinary `x-get-resource' doesn't take a frame argument. */)
3405 (Lisp_Object resource, Lisp_Object class, Lisp_Object frame) 3404 (Lisp_Object resource, Lisp_Object class, Lisp_Object frame)
3406{ 3405{
3407 Lisp_Object value = Qnil; 3406 Lisp_Object value = Qnil;
3407 struct frame *f;
3408
3408 CHECK_STRING (resource); 3409 CHECK_STRING (resource);
3409 CHECK_STRING (class); 3410 CHECK_STRING (class);
3410 CHECK_LIVE_FRAME (frame); 3411 f = decode_live_frame (frame);
3411 block_input (); 3412 block_input ();
3412 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)), 3413 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (f),
3413 resource, class, Qnil, Qnil); 3414 resource, class, Qnil, Qnil);
3414 unblock_input (); 3415 unblock_input ();
3415 return value; 3416 return value;
diff --git a/src/xfns.c b/src/xfns.c
index 100fd81a155..a6a179be97d 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3182,9 +3182,6 @@ This function is an internal primitive--use `make-frame' instead. */)
3182 specbind (Qx_resource_name, name); 3182 specbind (Qx_resource_name, name);
3183 } 3183 }
3184 3184
3185 f->resx = dpyinfo->resx;
3186 f->resy = dpyinfo->resy;
3187
3188#ifdef HAVE_FREETYPE 3185#ifdef HAVE_FREETYPE
3189#ifdef HAVE_XFT 3186#ifdef HAVE_XFT
3190 register_font_driver (&xftfont_driver, f); 3187 register_font_driver (&xftfont_driver, f);
@@ -4325,7 +4322,7 @@ no value of TYPE (always string in the MS Windows case). */)
4325 property and those are indeed in 32 bit quantities if format is 4322 property and those are indeed in 32 bit quantities if format is
4326 32. */ 4323 32. */
4327 4324
4328 if (32 < BITS_PER_LONG && actual_format == 32) 4325 if (BITS_PER_LONG > 32 && actual_format == 32)
4329 { 4326 {
4330 unsigned long i; 4327 unsigned long i;
4331 int *idata = (int *) tmp_data; 4328 int *idata = (int *) tmp_data;
@@ -4631,9 +4628,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4631 specbind (Qx_resource_name, name); 4628 specbind (Qx_resource_name, name);
4632 } 4629 }
4633 4630
4634 f->resx = dpyinfo->resx;
4635 f->resy = dpyinfo->resy;
4636
4637 register_font_driver (&xfont_driver, f); 4631 register_font_driver (&xfont_driver, f);
4638#ifdef HAVE_FREETYPE 4632#ifdef HAVE_FREETYPE
4639#ifdef HAVE_XFT 4633#ifdef HAVE_XFT
@@ -5027,23 +5021,23 @@ Text larger than the specified size is clipped. */)
5027 5021
5028 /* Set up the frame's root window. */ 5022 /* Set up the frame's root window. */
5029 w = XWINDOW (FRAME_ROOT_WINDOW (f)); 5023 w = XWINDOW (FRAME_ROOT_WINDOW (f));
5030 wset_left_col (w, make_number (0)); 5024 w->left_col = 0;
5031 wset_top_line (w, make_number (0)); 5025 w->top_line = 0;
5032 5026
5033 if (CONSP (Vx_max_tooltip_size) 5027 if (CONSP (Vx_max_tooltip_size)
5034 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX) 5028 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
5035 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX)) 5029 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX))
5036 { 5030 {
5037 wset_total_cols (w, XCAR (Vx_max_tooltip_size)); 5031 w->total_cols = XFASTINT (XCAR (Vx_max_tooltip_size));
5038 wset_total_lines (w, XCDR (Vx_max_tooltip_size)); 5032 w->total_lines = XFASTINT (XCDR (Vx_max_tooltip_size));
5039 } 5033 }
5040 else 5034 else
5041 { 5035 {
5042 wset_total_cols (w, make_number (80)); 5036 w->total_cols = 80;
5043 wset_total_lines (w, make_number (40)); 5037 w->total_lines = 40;
5044 } 5038 }
5045 5039
5046 FRAME_TOTAL_COLS (f) = XINT (w->total_cols); 5040 FRAME_TOTAL_COLS (f) = w->total_cols;
5047 adjust_glyphs (f); 5041 adjust_glyphs (f);
5048 w->pseudo_window_p = 1; 5042 w->pseudo_window_p = 1;
5049 5043
@@ -5110,7 +5104,7 @@ Text larger than the specified size is clipped. */)
5110 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns, 5104 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5111 not in pixels. */ 5105 not in pixels. */
5112 width /= WINDOW_FRAME_COLUMN_WIDTH (w); 5106 width /= WINDOW_FRAME_COLUMN_WIDTH (w);
5113 wset_total_cols (w, make_number (width)); 5107 w->total_cols = width;
5114 FRAME_TOTAL_COLS (f) = width; 5108 FRAME_TOTAL_COLS (f) = width;
5115 adjust_glyphs (f); 5109 adjust_glyphs (f);
5116 clear_glyph_matrix (w->desired_matrix); 5110 clear_glyph_matrix (w->desired_matrix);
diff --git a/src/xmenu.c b/src/xmenu.c
index 958cd220393..af08eeb657c 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1055,7 +1055,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
1055 wv->help = Qnil; 1055 wv->help = Qnil;
1056 first_wv = wv; 1056 first_wv = wv;
1057 1057
1058 for (i = 0; 0 <= submenu_start[i]; i++) 1058 for (i = 0; submenu_start[i] >= 0; i++)
1059 { 1059 {
1060 menu_items_n_panes = submenu_n_panes[i]; 1060 menu_items_n_panes = submenu_n_panes[i];
1061 wv = digest_single_submenu (submenu_start[i], submenu_end[i], 1061 wv = digest_single_submenu (submenu_start[i], submenu_end[i],
@@ -2479,7 +2479,7 @@ xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
2479#endif 2479#endif
2480 2480
2481 record_unwind_protect (pop_down_menu, 2481 record_unwind_protect (pop_down_menu,
2482 make_save_value ("pp", f, menu)); 2482 make_save_value (SAVE_TYPE_PTR_PTR, f, menu));
2483 2483
2484 /* Help display under X won't work because XMenuActivate contains 2484 /* Help display under X won't work because XMenuActivate contains
2485 a loop that doesn't give Emacs a chance to process it. */ 2485 a loop that doesn't give Emacs a chance to process it. */
diff --git a/src/xselect.c b/src/xselect.c
index 5b90d7def22..cca1a47212b 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -1388,7 +1388,7 @@ x_get_window_property (Display *display, Window window, Atom property,
1388 data = data1; 1388 data = data1;
1389 } 1389 }
1390 1390
1391 if (32 < BITS_PER_LONG && *actual_format_ret == 32) 1391 if (BITS_PER_LONG > 32 && *actual_format_ret == 32)
1392 { 1392 {
1393 unsigned long i; 1393 unsigned long i;
1394 int *idata = (int *) (data + offset); 1394 int *idata = (int *) (data + offset);
@@ -2541,7 +2541,7 @@ x_handle_dnd_message (struct frame *f, XClientMessageEvent *event,
2541 function expects them to be of size int (i.e. 32). So to be able to 2541 function expects them to be of size int (i.e. 32). So to be able to
2542 use that function, put the data in the form it expects if format is 32. */ 2542 use that function, put the data in the form it expects if format is 32. */
2543 2543
2544 if (32 < BITS_PER_LONG && event->format == 32) 2544 if (BITS_PER_LONG > 32 && event->format == 32)
2545 { 2545 {
2546 for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */ 2546 for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */
2547 idata[i] = event->data.l[i]; 2547 idata[i] = event->data.l[i];
@@ -2571,7 +2571,7 @@ x_handle_dnd_message (struct frame *f, XClientMessageEvent *event,
2571 return 1; 2571 return 1;
2572} 2572}
2573 2573
2574DEFUN ("x-send-client-message", Fx_send_client_event, 2574DEFUN ("x-send-client-message", Fx_send_client_message,
2575 Sx_send_client_message, 6, 6, 0, 2575 Sx_send_client_message, 6, 6, 0,
2576 doc: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY. 2576 doc: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
2577 2577
diff --git a/src/xsettings.c b/src/xsettings.c
index 576a5032eac..f48c49dbafe 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -673,19 +673,14 @@ apply_xft_settings (struct x_display_info *dpyinfo,
673 if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi 673 if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi
674 && settings->dpi > 0) 674 && settings->dpi > 0)
675 { 675 {
676 Lisp_Object frame, tail;
677
678 FcPatternDel (pat, FC_DPI); 676 FcPatternDel (pat, FC_DPI);
679 FcPatternAddDouble (pat, FC_DPI, settings->dpi); 677 FcPatternAddDouble (pat, FC_DPI, settings->dpi);
680 ++changed; 678 ++changed;
681 oldsettings.dpi = settings->dpi; 679 oldsettings.dpi = settings->dpi;
682 680
683 /* Change the DPI on this display and all frames on the display. */ 681 /* Changing the DPI on this display affects all frames on it.
682 Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */
684 dpyinfo->resy = dpyinfo->resx = settings->dpi; 683 dpyinfo->resy = dpyinfo->resx = settings->dpi;
685 FOR_EACH_FRAME (tail, frame)
686 if (FRAME_X_P (XFRAME (frame))
687 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
688 XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi;
689 } 684 }
690 685
691 if (changed) 686 if (changed)
diff --git a/src/xsmfns.c b/src/xsmfns.c
index cb7122202df..0af196d2160 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -221,7 +221,7 @@ smc_save_yourself_CB (SmcConn smcConn,
221 props[props_idx]->name = xstrdup (SmRestartCommand); 221 props[props_idx]->name = xstrdup (SmRestartCommand);
222 props[props_idx]->type = xstrdup (SmLISTofARRAY8); 222 props[props_idx]->type = xstrdup (SmLISTofARRAY8);
223 /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir ... */ 223 /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir ... */
224 if (INT_MAX - 3 < initial_argc) 224 if (initial_argc > INT_MAX - 3)
225 memory_full (SIZE_MAX); 225 memory_full (SIZE_MAX);
226 i = 3 + initial_argc; 226 i = 3 + initial_argc;
227 props[props_idx]->num_vals = i; 227 props[props_idx]->num_vals = i;
diff --git a/src/xterm.c b/src/xterm.c
index 73e9ad8374d..bd66d5c0def 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -133,6 +133,10 @@ extern void _XEditResCheckMessages (Widget, XtPointer, XEvent *, Boolean *);
133 133
134#include "bitmaps/gray.xbm" 134#include "bitmaps/gray.xbm"
135 135
136#ifdef HAVE_XKB
137#include <X11/XKBlib.h>
138#endif
139
136/* Default to using XIM if available. */ 140/* Default to using XIM if available. */
137#ifdef USE_XIM 141#ifdef USE_XIM
138int use_xim = 1; 142int use_xim = 1;
@@ -3227,7 +3231,11 @@ XTring_bell (struct frame *f)
3227 else 3231 else
3228 { 3232 {
3229 block_input (); 3233 block_input ();
3234#ifdef HAVE_XKB
3235 XkbBell (FRAME_X_DISPLAY (f), None, 0, None);
3236#else
3230 XBell (FRAME_X_DISPLAY (f), 0); 3237 XBell (FRAME_X_DISPLAY (f), 0);
3238#endif
3231 XFlush (FRAME_X_DISPLAY (f)); 3239 XFlush (FRAME_X_DISPLAY (f));
3232 unblock_input (); 3240 unblock_input ();
3233 } 3241 }
@@ -5085,7 +5093,7 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5085 5093
5086 /* Draw the empty space above the handle. Note that we can't clear 5094 /* Draw the empty space above the handle. Note that we can't clear
5087 zero-height areas; that means "clear to end of window." */ 5095 zero-height areas; that means "clear to end of window." */
5088 if (0 < start) 5096 if (start > 0)
5089 x_clear_area (FRAME_X_DISPLAY (f), w, 5097 x_clear_area (FRAME_X_DISPLAY (f), w,
5090 /* x, y, width, height, and exposures. */ 5098 /* x, y, width, height, and exposures. */
5091 VERTICAL_SCROLL_BAR_LEFT_BORDER, 5099 VERTICAL_SCROLL_BAR_LEFT_BORDER,