aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2012-10-07 14:31:58 -0800
committerDaniel Colascione2012-10-07 14:31:58 -0800
commit36a305a723c63fd345be65c536c52fe9765c14be (patch)
treefb89d9e103552863214c60297a65320917109357 /src
parent2ab329f3b5d52a39f0a45c3d9c129f1c19560142 (diff)
parent795b1482a9e314cda32d62ac2988f573d359366e (diff)
downloademacs-36a305a723c63fd345be65c536c52fe9765c14be.tar.gz
emacs-36a305a723c63fd345be65c536c52fe9765c14be.zip
Merge from trunk
Diffstat (limited to 'src')
-rw-r--r--src/.gdbinit24
-rw-r--r--src/ChangeLog1193
-rw-r--r--src/ChangeLog.112
-rw-r--r--src/ChangeLog.22
-rw-r--r--src/ChangeLog.32
-rw-r--r--src/Makefile.in5
-rw-r--r--src/alloc.c130
-rw-r--r--src/atimer.c86
-rw-r--r--src/bidi.c68
-rw-r--r--src/blockinput.h118
-rw-r--r--src/buffer.c138
-rw-r--r--src/bytecode.c2
-rw-r--r--src/callproc.c12
-rw-r--r--src/category.c2
-rw-r--r--src/character.c4
-rw-r--r--src/character.h17
-rw-r--r--src/charset.c12
-rw-r--r--src/charset.h1
-rw-r--r--src/chartab.c10
-rw-r--r--src/cmds.c2
-rw-r--r--src/coding.c90
-rw-r--r--src/coding.h6
-rw-r--r--src/composite.c51
-rw-r--r--src/data.c37
-rw-r--r--src/dired.c20
-rw-r--r--src/dispextern.h21
-rw-r--r--src/dispnew.c42
-rw-r--r--src/dosfns.c4
-rw-r--r--src/editfns.c66
-rw-r--r--src/emacs.c215
-rw-r--r--src/eval.c108
-rw-r--r--src/fileio.c36
-rw-r--r--src/floatfns.c9
-rw-r--r--src/fns.c22
-rw-r--r--src/font.h1
-rw-r--r--src/fontset.c4
-rw-r--r--src/frame.c119
-rw-r--r--src/frame.h7
-rw-r--r--src/fringe.c2
-rw-r--r--src/ftxfont.c16
-rw-r--r--src/gmalloc.c8
-rw-r--r--src/gnutls.c29
-rw-r--r--src/gtkutil.c245
-rw-r--r--src/gtkutil.h38
-rw-r--r--src/image.c656
-rw-r--r--src/indent.c65
-rw-r--r--src/indent.h6
-rw-r--r--src/intervals.c14
-rw-r--r--src/keyboard.c369
-rw-r--r--src/keyboard.h5
-rw-r--r--src/keymap.c4
-rw-r--r--src/lisp.h47
-rw-r--r--src/lread.c49
-rw-r--r--src/makefile.w32-in123
-rw-r--r--src/marker.c6
-rw-r--r--src/menu.c12
-rw-r--r--src/minibuf.c10
-rw-r--r--src/msdos.c8
-rw-r--r--src/nsfns.m140
-rw-r--r--src/nsfont.m12
-rw-r--r--src/nsimage.m10
-rw-r--r--src/nsmenu.m45
-rw-r--r--src/nsselect.m4
-rw-r--r--src/nsterm.h42
-rw-r--r--src/nsterm.m637
-rw-r--r--src/print.c4
-rw-r--r--src/process.c608
-rw-r--r--src/profiler.c546
-rw-r--r--src/ralloc.c25
-rw-r--r--src/search.c53
-rw-r--r--src/syntax.c4
-rw-r--r--src/sysdep.c459
-rw-r--r--src/syssignal.h22
-rw-r--r--src/syswait.h7
-rw-r--r--src/term.c12
-rw-r--r--src/termhooks.h16
-rw-r--r--src/terminal.c2
-rw-r--r--src/textprop.c4
-rw-r--r--src/unexmacosx.c21
-rw-r--r--src/unexw32.c46
-rw-r--r--src/vm-limit.c12
-rw-r--r--src/w16select.c8
-rw-r--r--src/w32.c129
-rw-r--r--src/w32.h11
-rw-r--r--src/w32fns.c228
-rw-r--r--src/w32gui.h3
-rw-r--r--src/w32heap.c44
-rw-r--r--src/w32heap.h12
-rw-r--r--src/w32inevt.c26
-rw-r--r--src/w32inevt.h2
-rw-r--r--src/w32menu.c26
-rw-r--r--src/w32proc.c590
-rw-r--r--src/w32reg.c4
-rw-r--r--src/w32select.c17
-rw-r--r--src/w32term.c145
-rw-r--r--src/w32term.h18
-rw-r--r--src/w32xfns.c132
-rw-r--r--src/widget.c4
-rw-r--r--src/window.c145
-rw-r--r--src/window.h15
-rw-r--r--src/xdisp.c174
-rw-r--r--src/xfaces.c102
-rw-r--r--src/xfns.c201
-rw-r--r--src/xfont.c40
-rw-r--r--src/xftfont.c34
-rw-r--r--src/xmenu.c65
-rw-r--r--src/xml.c10
-rw-r--r--src/xselect.c100
-rw-r--r--src/xsettings.c4
-rw-r--r--src/xterm.c362
-rw-r--r--src/xterm.h11
111 files changed, 6033 insertions, 3760 deletions
diff --git a/src/.gdbinit b/src/.gdbinit
index 79419f66ac1..952d7392a4c 100644
--- a/src/.gdbinit
+++ b/src/.gdbinit
@@ -1121,15 +1121,15 @@ end
1121define xbacktrace 1121define xbacktrace
1122 set $bt = backtrace_list 1122 set $bt = backtrace_list
1123 while $bt 1123 while $bt
1124 xgettype (*$bt->function) 1124 xgettype ($bt->function)
1125 if $type == Lisp_Symbol 1125 if $type == Lisp_Symbol
1126 xprintsym (*$bt->function) 1126 xprintsym ($bt->function)
1127 printf " (0x%x)\n", $bt->args 1127 printf " (0x%x)\n", $bt->args
1128 else 1128 else
1129 xgetptr *$bt->function 1129 xgetptr $bt->function
1130 printf "0x%x ", $ptr 1130 printf "0x%x ", $ptr
1131 if $type == Lisp_Vectorlike 1131 if $type == Lisp_Vectorlike
1132 xgetptr (*$bt->function) 1132 xgetptr ($bt->function)
1133 set $size = ((struct Lisp_Vector *) $ptr)->header.size 1133 set $size = ((struct Lisp_Vector *) $ptr)->header.size
1134 if ($size & PSEUDOVECTOR_FLAG) 1134 if ($size & PSEUDOVECTOR_FLAG)
1135 output (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_SIZE_BITS) 1135 output (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_SIZE_BITS)
@@ -1213,19 +1213,9 @@ set print sevenbit-strings
1213show environment DISPLAY 1213show environment DISPLAY
1214show environment TERM 1214show environment TERM
1215 1215
1216# People get bothered when they see messages about non-existent functions... 1216# When debugging, it is handy to be able to "return" from
1217xgetptr globals.f_Vsystem_type 1217# terminate_due_to_signal when an assertion failure is non-fatal.
1218# $ptr is NULL in temacs 1218break terminate_due_to_signal
1219if ($ptr != 0)
1220 set $tem = (struct Lisp_Symbol *) $ptr
1221 xgetptr $tem->name
1222 set $tem = (struct Lisp_String *) $ptr
1223 set $tem = (char *) $tem->data
1224
1225 # Don't let emacs_abort actually run, as it will make stdio stop
1226 # working and therefore the 'pr' command above as well.
1227 break emacs_abort
1228end
1229 1219
1230# x_error_quitter is defined only on X. But window-system is set up 1220# x_error_quitter is defined only on X. But window-system is set up
1231# only at run time, during Emacs startup, so we need to defer setting 1221# only at run time, during Emacs startup, so we need to defer setting
diff --git a/src/ChangeLog b/src/ChangeLog
index 36df05c25ae..29e831a2eb8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,1172 @@
12012-10-07 Eli Zaretskii <eliz@gnu.org>
2
3 * ralloc.c (relinquish): If a heap is ready to be relinquished,
4 but it still has blocs in it, don't return it to the system,
5 instead of aborting. (Bug#12402)
6
72012-10-07 Jan Djärv <jan.h.d@swipnet.se>
8
9 * nsterm.m (ns_dumpglyphs_image): Only draw slice of image (Bug#12506).
10
11 * nsterm.m (ns_update_auto_hide_menu_bar): Remove defintion of
12 MAC_OS_X_VERSION_10_6.
13 (syms_of_nsterm): Remove comment about Panther and above for
14 ns-antialias-text.
15 * nsterm.h (MAC_OS_X_VERSION_10_3, onTiger): Remove.
16 (EmacsApp): Remove check for >= MAC_OS_X_VERSION_10_4.
17 (struct nsfont_info): Remove check for >= MAC_OS_X_VERSION_10_3.
18
19 * nsselect.m (ns_string_from_pasteboard): Remove check for >=
20 MAC_OS_X_VERSION_10_4.
21
22 * nsmenu.m (fillWithWidgetValue:): Remove code for <
23 MAC_OS_X_VERSION_10_2.
24
25 * nsimage.m (setPixmapData, getPixelAtX, setAlphaAtX): Remove onTiger.
26
27 * nsfns.m (Fns_list_services): Remove comment and check for OSX < 10.4.
28 (ns_do_applescript): Remove check for >= MAC_OS_X_VERSION_10_4.
29
30 * nsterm.m (ns_in_resize): Remove (Bug#12479).
31 (ns_resize_handle_rect, mouseDown, mouseUp, mouseDragged): Remove.
32 (ns_clear_frame, sendEvent, windowDidResize, drawRect:): Remove
33 ns_in_resize check.
34 (ns_clear_frame_area): Remove resize handle code.
35
36 * nsfns.m (ns_in_resize): Remove.
37 (x_set_icon_name, ns_set_name, ns_set_name_as_filename): Remove
38 ns_in_resize check.
39
402012-10-07 Paul Eggert <eggert@cs.ucla.edu>
41
42 Improve sys_siglist detection.
43 * sysdep.c (sys_siglist, init_signals): Use _sys_siglist if it's
44 defined as a macro, as is done in Solaris.
45 (sys_siglist_entries): New macro.
46 (save_strsignal): Use it.
47 * syssignal.h (safe_strsignal): Now ATTRIBUTE_CONST, to pacify
48 GCC 4.7.2 on Fedora 17 with the fixed sys_siglist detection.
49
502012-10-06 Jan Djärv <jan.h.d@swipnet.se>
51
52 * nsfns.m (Fx_create_frame): Call x_default_parameter with
53 fullscreen/Fullscreen.
54
55 * nsterm.h (EmacsView): Rename tbar_height to tibar_height.
56 tobar_height is new.
57
58 * nsterm.m (x_make_frame_visible): Check for fullscreen.
59 (ns_fullscreen_hook): Activate old style fullscreen with a timer.
60 (ns_term_init): Set activateIgnoringOtherApps if old style fullscreen.
61 (windowDidResize:): Check for correct window if old style fullscreen.
62 Capitalize word in comment. Remove incorrect comment.
63 (initFrameFromEmacs:): tbar_height renamed tibar_height.
64 (windowDidEnterFullScreen:): Toggle toolbar for fullscreen to fix
65 error in drawing background.
66 (toggleFullScreen:): Remove comment. Rearrange calls.
67 Set toolbar values to zero, save old height in tobar_height.
68 Restore tool bar height when leaving fullscreen.
69 (canBecomeMainWindow): New function.
70
712012-10-06 Paul Eggert <eggert@cs.ucla.edu>
72
73 * keyboard.c (read_char): Remove unnecessary 'volatile's and label.
74
752012-10-05 Eli Zaretskii <eliz@gnu.org>
76
77 * w32proc.c (stop_timer_thread): Fix declaration of 'err'.
78
79 * w32.c (utime): Open the file with FILE_FLAG_BACKUP_SEMANTICS, so
80 that time stamps of directories could also be changed. Don't
81 request the too broad GENERIC_WRITE, only the more restrictive
82 FILE_WRITE_ATTRIBUTES access rights.
83
84 * fileio.c (Fset_file_times): Special-case ignoring errors for
85 directories only on MSDOS, not on MS-Windows.
86
872012-10-05 Ikumi Keita <ikumi@ikumi.que.jp> (tiny change)
88
89 * minibuf.c (Fcompleting_read): Doc fix. (Bug#12555)
90
912012-10-04 Eli Zaretskii <eliz@gnu.org>
92
93 * w32.c (utime): Test for INVALID_HANDLE_VALUE, not for NULL, to
94 see whether CreateFile failed.
95
962012-10-04 Paul Eggert <eggert@cs.ucla.edu>
97
98 * profiler.c (handle_profiler_signal): Inhibit pending signals too,
99 to avoid similar races.
100 * keyboard.c (pending_signals): Now bool, not int.
101
102 Port timers to OpenBSD, plus check for timer failures.
103 OpenBSD problem reported by Han Boetes.
104 * profiler.c (setup_cpu_timer): Check for failure of timer_settime
105 and/or setitimer.
106 (Fprofiler_cpu_stop): Don't assume HAVE_SETITIMER.
107 * syssignal.h (HAVE_ITIMERSPEC): New macro. This is for platforms
108 like OpenBSD, which has timer_settime but does not declare it.
109 OpenBSD does not define SIGEV_SIGNAL, so use that when deciding
110 whether to use itimerspec-related primitives. All uses of
111 HAVE_TIMER_SETTIME replaced with HAVE_ITIMERSPEC.
112
1132012-10-02 Paul Eggert <eggert@cs.ucla.edu>
114
115 * profiler.c (handle_profiler_signal): Fix a malloc race
116 that caused Emacs to hang on Fedora 17 when profiling Lisp.
117
1182012-10-02 Jan Djärv <jan.h.d@swipnet.se>
119
120 * nsterm.m (windowDidEnterFullScreen): Remove fprintf.
121
1222012-10-02 Eli Zaretskii <eliz@gnu.org>
123
124 * w32proc.c (sys_wait): Declare 'signame' 'const char *', to be
125 consistent with the change in return value of 'safe_strsignal'.
126
1272012-10-02 Paul Eggert <eggert@cs.ucla.edu>
128
129 Prefer plain 'static' to 'static inline' (Bug#12541).
130 * bidi.c (bidi_get_type, bidi_check_type, bidi_get_category)
131 (bidi_set_sor_type, bidi_push_embedding_level)
132 (bidi_pop_embedding_level, bidi_remember_char, bidi_copy_it)
133 (bidi_cache_reset, bidi_cache_shrink, bidi_cache_fetch_state)
134 (bidi_cache_search, bidi_cache_ensure_space)
135 (bidi_cache_iterator_state, bidi_cache_find)
136 (bidi_peek_at_next_level, bidi_set_paragraph_end)
137 (bidi_count_bytes, bidi_char_at_pos, bidi_fetch_char)
138 (bidi_explicit_dir_char, bidi_resolve_neutral_1):
139 Now 'static', not 'static inline'.
140
141 Count overruns when profiling; change units to ns.
142 * profiler.c (handle_profiler_signal): Count sampling intervals, not ms.
143 Give extra weight to samples after overruns, to attempt to count
144 the time more accurately.
145 (setup_cpu_timer): Change sampling interval units from ms to ns, since
146 the underlying primitives nominally do ns.
147 (Fprofiler_cpu_start): Document the change. Mention that
148 the sampling intervals are only approximate.
149
1502012-10-02 Stefan Monnier <monnier@iro.umontreal.ca>
151
152 * frame.c (Fmake_terminal_frame): Prefer safer CONSP over !NILP.
153
154 * coding.h (ENCODE_FILE, DECODE_FILE, DECODE_SYSTEM): Remove special
155 case for the special 0 coding-system.
156
157 * buffer.c (Fset_buffer_multibyte): Signal an error instead of widening.
158 (Fmake_overlay): Remove redundant tests.
159 (fix_start_end_in_overlays): Remove redundant recentering.
160
1612012-10-02 Juanma Barranquero <lekktu@gmail.com>
162
163 * makefile.w32-in ($(BLD)/alloc.$(O), $(BLD)/gmalloc.$(O)):
164 Update dependencies.
165
1662012-10-01 Paul Eggert <eggert@cs.ucla.edu>
167
168 Fix a malloc race condition involving strsignal.
169 A signal can arrive in the middle of a malloc, and Emacs's signal
170 handler can invoke strsignal, which can invoke malloc, which is
171 not portable. This race condition bug makes Emacs hang on GNU/Linux.
172 Fix it by altering the signal handler so that it does not invoke
173 strsignal.
174 * emacs.c (shut_down_emacs): Use safe_strsignal, not strsignal.
175 * process.c (status_message): Use const pointer, in case strsignal
176 is #defined to safe_strsignal.
177 * sysdep.c (sys_siglist, init_signals): Always define and
178 initialize a substitute sys_siglist if the system does not define
179 one, even if HAVE_STRSIGNAL.
180 (safe_strsignal): Rename from strsignal. Always define,
181 using sys_siglist. Return a const pointer.
182 * syssignal.h (safe_strsignal): New decl.
183 (strsignal) [!HAVE_STRSIGNAL]: Define in terms of safe_strsignal.
184
1852012-10-01 Eli Zaretskii <eliz@gnu.org>
186
187 * w32proc.c (timer_loop): Fix code that waits for timer
188 expiration, to avoid high CPU usage.
189
1902012-10-01 Stefan Monnier <monnier@iro.umontreal.ca>
191
192 * fns.c (check_hash_table, get_key_arg, maybe_resize_hash_table)
193 (sweep_weak_table): Remove redundant prototypes.
194
1952012-10-01 Fabrice Popineau <fabrice.popineau@gmail.com>
196
197 * emacs.c: Move the inclusion of TERM_HEADER after including
198 windows.h on WINDOWSNT. This avoids compilation problems with
199 MSVC.
200
2012012-10-01 Eli Zaretskii <eliz@gnu.org>
202
203 * unexw32.c (OFFSET_TO_RVA, RVA_TO_OFFSET)
204 (RVA_TO_SECTION_OFFSET): Encode all macro arguments in parentheses.
205 (RVA_TO_PTR): Cast the result of RVA_TO_OFFSET to 'unsigned char *',
206 as the previous version used 'void *'.
207
208 * ralloc.c (ROUNDUP): Fix last change.
209 (MEM_ROUNDUP): Don't cast MEM_ALIGN, it is already of type
210 'size_t'.
211
212 * w32proc.c <disable_itimers>: New static flag.
213 (init_timers): Initialize it to zero, after creating the critical
214 sections used by the timer threads.
215 (term_timers): Set to 1 before deleting the critical sections.
216 (getitimer, setitimer): If disable_itimers is non-zero, return an
217 error indication without doing anything. Reported by Fabrice
218 Popineau <fabrice.popineau@supelec.fr> as part of bug#12544.
219 (alarm) [HAVE_SETITIMER]: Be more conformant to the expected
220 return results.
221 [!HAVE_SETITIMER]: Behave as the previous version that didn't
222 support timers.
223
224 * emacs.c (shut_down_emacs) [WINDOWSNT]: Move the call to
225 term_ntproc after all the other bookkeeping, to get timers working
226 as long as possible.
227
2282012-10-01 Paul Eggert <eggert@cs.ucla.edu>
229
230 * xdisp.c (syms_of_xdisp): Default message-log-max to 1000, not 100.
231 Suggested by Juri Linkov in
232 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00821.html>.
233
234 Prefer plain 'static' to 'static inline' (Bug#12541).
235 With static functions, modern compilers inline pretty well by
236 themselves; advice from programmers often hurts as much as it helps.
237 On my host (x86-64, Fedora 17, GCC 4.7.2, default 'configure'),
238 this change shrinks the text size of the Emacs executable by 1.1%
239 without affecting CPU significantly in my benchmark.
240 * alloc.c (mem_find, live_string_p, live_cons_p, live_symbol_p)
241 (live_float_p, live_misc_p, live_vector_p, live_buffer_p)
242 (mark_maybe_object, mark_maybe_pointer, bounded_number):
243 * buffer.c (bset_abbrev_mode, bset_abbrev_table)
244 (bset_auto_fill_function, bset_auto_save_file_format)
245 (bset_auto_save_file_name, bset_backed_up, bset_begv_marker)
246 (bset_bidi_display_reordering, bset_buffer_file_coding_system)
247 (bset_cache_long_line_scans, bset_case_fold_search)
248 (bset_ctl_arrow, bset_cursor_in_non_selected_windows)
249 (bset_cursor_type, bset_display_table, bset_extra_line_spacing)
250 (bset_file_format, bset_file_truename, bset_fringe_cursor_alist)
251 (bset_fringe_indicator_alist, bset_fringes_outside_margins)
252 (bset_header_line_format, bset_indicate_buffer_boundaries)
253 (bset_indicate_empty_lines, bset_invisibility_spec)
254 (bset_left_fringe_width, bset_major_mode, bset_mark)
255 (bset_minor_modes, bset_mode_line_format, bset_mode_name)
256 (bset_name, bset_overwrite_mode, bset_pt_marker)
257 (bset_right_fringe_width, bset_save_length)
258 (bset_scroll_bar_width, bset_scroll_down_aggressively)
259 (bset_scroll_up_aggressively, bset_selective_display)
260 (bset_selective_display_ellipses, bset_vertical_scroll_bar_type)
261 (bset_word_wrap, bset_zv_marker, set_buffer_overlays_before)
262 (set_buffer_overlays_after):
263 * category.c (bset_category_table):
264 * charset.c (read_hex):
265 * coding.c (produce_composition, produce_charset)
266 (handle_composition_annotation, handle_charset_annotation)
267 (char_encodable_p):
268 * dispnew.c (swap_glyph_pointers, copy_row_except_pointers)
269 (assign_row, set_frame_matrix_frame, make_current)
270 (add_row_entry):
271 * eval.c (set_specpdl_symbol, set_specpdl_old_value):
272 * fns.c (maybe_resize_hash_table):
273 * frame.c (fset_buffer_predicate, fset_minibuffer_window):
274 * gmalloc.c (register_heapinfo):
275 * image.c (lookup_image_type):
276 * intervals.c (set_interval_object, set_interval_left)
277 (set_interval_right, copy_interval_parent, rotate_right)
278 (rotate_left, balance_possible_root_interval):
279 * keyboard.c (kset_echo_string, kset_kbd_queue)
280 (kset_keyboard_translate_table, kset_last_prefix_arg)
281 (kset_last_repeatable_command, kset_local_function_key_map)
282 (kset_overriding_terminal_local_map, kset_real_last_command)
283 (kset_system_key_syms, clear_event, set_prop):
284 * lread.c (digit_to_number):
285 * marker.c (attach_marker, live_buffer, set_marker_internal):
286 * nsterm.m (ns_compute_glyph_string_overhangs):
287 * process.c (pset_buffer, pset_command)
288 (pset_decode_coding_system, pset_decoding_buf)
289 (pset_encode_coding_system, pset_encoding_buf, pset_filter)
290 (pset_log, pset_mark, pset_name, pset_plist, pset_sentinel)
291 (pset_status, pset_tty_name, pset_type, pset_write_queue):
292 * syntax.c (bset_syntax_table, dec_bytepos):
293 * terminal.c (tset_param_alist):
294 * textprop.c (interval_has_some_properties)
295 (interval_has_some_properties_list):
296 * window.c (wset_combination_limit, wset_dedicated)
297 (wset_display_table, wset_hchild, wset_left_fringe_width)
298 (wset_left_margin_cols, wset_new_normal, wset_new_total)
299 (wset_normal_cols, wset_normal_lines, wset_parent, wset_pointm)
300 (wset_right_fringe_width, wset_right_margin_cols)
301 (wset_scroll_bar_width, wset_start, wset_temslot, wset_vchild)
302 (wset_vertical_scroll_bar_type, wset_window_parameters):
303 * xdisp.c (wset_base_line_number, wset_base_line_pos)
304 (wset_column_number_displayed, wset_region_showing)
305 (window_box_edges, run_window_scroll_functions)
306 (append_glyph_string_lists, prepend_glyph_string_lists)
307 (append_glyph_string, set_glyph_string_background_width)
308 (append_glyph, append_composite_glyph)
309 (take_vertical_position_into_account):
310 * xfaces.c (x_create_gc, x_free_gc, merge_face_vectors)
311 (face_attr_equal_p, lface_equal_p, hash_string_case_insensitive)
312 (lface_hash, lface_same_font_attributes_p, lookup_face):
313 * xml.c (libxml2_loaded_p):
314 * xterm.c (x_set_mode_line_face_gc, x_set_glyph_string_gc)
315 (x_set_glyph_string_clipping, x_clear_glyph_string_rect):
316 Now 'static', not 'static inline'.
317
318 * bidi.c: Tune.
319 (bidi_copy_it): Do the whole copy with a single memcpy.
320 (bidi_char_at_pos): Merge the two STRING_CHAR calls into one.
321
322 Revert the FOLLOW-SYMLINKS change for file-attributes.
323 Doing it right would require several changes to Tramp, and there's
324 not enough time to get that tested before the freeze today.
325 * dired.c (directory_files_internal, Ffile_attributes):
326 Undo last change.
327
328 * frame.c (x_report_frame_params): Port better to wider ints.
329 Do not assume that EMACS_UINT is the same width as uprintmax_t,
330 or that pointers can be printed in 15 decimal digits.
331 Avoid GCC warnings if EMACS_UINT is wider than a pointer.
332
3332012-09-30 Fabrice Popineau <fabrice.popineau@supelec.fr>
334
335 Support x64 build on MS-Windows.
336 * w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
337 (SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
338 compatibility with x64.
339 (x_get_focus_frame): Add prototype.
340
341 * w32term.c (w32_draw_underwave): Don't use GCC extensions for
342 defining an XRectangle structure.
343
344 * w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
345 arithmetics for compatibility with x64.
346
347 * w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
348 compatibility with x64.
349
350 * w32heap.h: Adjust prototypes and declarations.
351
352 * w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
353 (round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
354 DWORD, long, and unsigned long, for compatibility with x64.
355 (allocate_heap) [_WIN64]: Reserve 32GB of memory.
356 (sbrk): Argument is now of type ptrdiff_t.
357
358 * w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
359 less than 0x0500.
360 (w32_msg_pump): Use WPARAM type for 'result'.
361
362 * w32.c (init_environment, get_emacs_configuration): Support AMD64
363 architecture.
364 (init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
365 compatibility with x64.
366
367 * vm-limit.c (lim_data): Now size_t.
368 (check_memory_limits): Adjust prototypes of real_morecore and
369 __morecore to receive argument of type ptrdiff_t. Use size_t for
370 five_percent and data_size.
371
372 * unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
373 variables, for compatibility with x64.
374 (rva_to_section, offset_to_section, relocate_offset)
375 (OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
376 (PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
377 (copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
378 for compatibility with x64.
379
380 * sysdep.c (STDERR_FILENO): Define if not already defined.
381
382 * ralloc.c (real_morecore): Argument type is now ptrdiff_t.
383 (__morecore): Argument type is now ptrdiff_t.
384 (ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
385 (relinquish): Use ptrdiff_t type for 'excess'.
386 (r_alloc_sbrk): Argument type is now ptrdiff_t.
387
388 * makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
389 (bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
390 instead of a literal number.
391
392 * gmalloc.c [WINDOWSNT]: Include w32heap.h.
393 (min): Define only if not already defined.
394
395 * frame.c (x_report_frame_params): Use EMACS_UINT for the return
396 value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
397 hosts.
398
399 * image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
400 'bitmaps' is a pointer.
401
402 * dispextern.h (x_bitmap_pixmap): Adjust prototype.
403
404 * alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
405
4062012-09-30 Paul Eggert <eggert@cs.ucla.edu>
407
408 file-attributes has a new optional arg FOLLOW-SYMLINKS.
409 * dired.c (directory_files_internal, Ffile_attributes):
410 New arg follow_symlinks. All uses changed.
411
4122012-09-30 Stefan Monnier <monnier@iro.umontreal.ca>
413
414 * .gdbinit (xbacktrace): Adjust to recent "struct backtrace" change.
415
4162012-09-30 Eli Zaretskii <eliz@gnu.org>
417
418 Support atimers and CPU profiler via profile.c on MS-Windows.
419 * w32proc.c (sig_mask, crit_sig): New static variables.
420 (sys_signal): Support SIGALRM and SIGPROF.
421 (sigemptyset, sigaddset, sigfillset, sigprocmask)
422 (pthread_sigmask, setpgrp): Move here from w32.c. sigaddset,
423 sigfillset, and sigprocmask are no longer no-ops.
424 (sigismember): New function.
425 (struct itimer_data): New definition.
426 (ticks_now, real_itimer, prof_itimer, clocks_min, crit_real)
427 (crit_prof): New static variables.
428 (MAX_SINGLE_SLEEP): New definition.
429 (timer_loop, stop_timer_thread, term_timers, init_timers)
430 (start_timer_thread, getitimer, setitimer): New functions.
431 (alarm): No longer a no-op, calls setitimer.
432
433 * w32.c (term_ntproc): Call term_timers.
434 (init_ntproc): Make sure all signals are unblocked at startup, to
435 erase any traces of dumping. Call init_timers.
436
437 * w32fns.c (hourglass_timer, HOURGLASS_ID): Remove.
438 Windows-specific code to display the hourglass mouse pointer is no
439 longer used.
440 (w32_wnd_proc): Remove code that handled the WM_TIMER message due
441 to hourglass timer expiration.
442 (start_hourglass, cancel_hourglass, DEFAULT_HOURGLASS_DELAY):
443 Remove, no longer used.
444 (w32_note_current_window, show_hourglass, hide_hourglass):
445 New functions, in support of hourglass cursor display similar to other
446 window systems.
447 (syms_of_w32fns): Don't initialize hourglass_timer.
448
449 * xdisp.c (start_hourglass, cancel_hourglass): Now used on
450 WINDOWSNT as well.
451 (start_hourglass) [WINDOWSNT]: Call w32_note_current_window.
452
453 * w32.h (init_timers, term_timers): Add prototypes.
454
4552012-09-30 Kenichi Handa <handa@gnu.org>
456
457 * coding.c (decode_coding_ccl, encode_coding_ccl): Pay attention
458 to the buffer relocation which may be caused by ccl_driver.
459
4602012-09-30 Jan Djärv <jan.h.d@swipnet.se>
461
462 * xfns.c (Fx_file_dialog): Update comment.
463
464 * w32fns.c (Fx_file_dialog): Update comment.
465
466 * nsfns.m (Fns_read_file_name): Add argument DIR_ONLY_P.
467 Initialize panel name field if OSX >= 10.6.
468
469 * fileio.c (Fnext_read_file_uses_dialog_p): Add HAVE_NS.
470
471 * nsfns.m (ns_frame_parm_handlers): Add x_set_fullscreen.
472
473 * nsterm.m (NEW_STYLE_FS): New define.
474 (ns_fullscreen_hook, windowWillEnterFullScreen)
475 (windowDidEnterFullScreen, windowWillExitFullScreen)
476 (windowDidExitFullScreen, toggleFullScreen, handleFS)
477 (setFSValue): New functions.
478 (EmacsFSWindow): New implementation.
479 (canBecomeKeyWindow): New function for EmacsFSWindow.
480 (ns_create_terminal): Set fullscreen_hook to ns_fullscreen_hook.
481 (dealloc): Release nonfs_window if in fullscreen.
482 (updateFrameSize:): Call windowDidMove to update top/left.
483 (windowWillResize:toSize:): Check if frame is still maximized.
484 (initFrameFromEmacs:): Initialize fs_state, fs_before_fs,
485 next_maximized, maximized_width, maximized_height and nonfs_window.
486 Call setCollectionBehavior if NEW_STYLE_FS. Initialize bwidth and
487 tbar_height.
488 (windowWillUseStandardFrame:defaultFrame:): Update frame parameter
489 fullscreen. Set maximized_width/height. Act on next_maximized.
490
491 * nsterm.h (MAC_OS_X_VERSION_10_7, MAC_OS_X_VERSION_10_8): New.
492 (EmacsView): Add variables for fullscreen.
493 (handleFS, setFSValue, toggleFullScreen): New in EmacsView.
494 (EmacsFSWindow): New interface for fullscreen.
495
4962012-09-30 Juanma Barranquero <lekktu@gmail.com>
497
498 * makefile.w32-in ($(BLD)/profiler.$(O)): Update dependencies.
499
5002012-09-30 Chong Yidong <cyd@gnu.org>
501
502 * fns.c (Frandom): Doc fix.
503
5042012-09-30 Martin Rudalics <rudalics@gmx.at>
505
506 * window.c (Vwindow_combination_limit): New default value.
507 (Qwindow_size): New symbol replacing Qtemp_buffer_resize.
508
5092012-09-30 Paul Eggert <eggert@cs.ucla.edu>
510
511 * syssignal.h (PROFILER_CPU_SUPPORT): Don't define if PROFILING.
512 Suggested by Eli Zaretskii in
513 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00811.html>.
514
5152012-09-30 Eli Zaretskii <eliz@gnu.org>
516
517 * profiler.c (Fprofiler_cpu_stop): Use timer_settime only if
518 HAVE_TIMER_SETTIME is defined.
519
5202012-09-30 Paul Eggert <eggert@cs.ucla.edu>
521
522 Profiler improvements: more-accurate timers, overflow checks.
523 * profiler.c: Don't include stdio.h, limits.h, sys/time.h,
524 signal.h, setjmp.h. Include systime.h instead.
525 (saturated_add): New function.
526 (record_backtrace, current_sample_interval): Use EMACS_INT, not size_t.
527 (record_backtrace, handle_profiler_signal): Saturate on fixnum overflow.
528 (profiler_timer, profiler_timer_ok) [HAVE_TIMER_SETTIME]:
529 New static vars.
530 (enum profiler_cpu_running): New enum.
531 (profiler_cpu_running): Now of that enum type, not bool.
532 All uses changed to store the new value.
533 (handle_profiler_signal): Rename from sigprof_handler_1,
534 for consistency with other handlers. Do not check whether
535 cpu_log is a hash-table if garbage collecting, since it
536 doesn't matter in that case.
537 (deliver_profiler_signal): Rename from sigprof_handler,
538 for consistency with other handlers.
539 (setup_cpu_timer): New function, with much of what used to be in
540 Fprofiler_cpu_start. Check for out-of-range argument.
541 Prefer timer_settime if available, and prefer
542 thread cputime clocks, then process cputime clocks, then
543 monotonic clocks, to the old realtime clock. Use make_timeval
544 to round more-correctly when falling back to setitimer.
545 (Fprofiler_cpu_start): Use it.
546 (Fprofiler_cpu_stop): Prefer timer_settime if available.
547 Don't assume that passing NULL as the 2nd argument of setitimer
548 is the same as passing a pointer to all-zero storage.
549 Ignore SIGPROF afterwards.
550 (malloc_probe): Saturate at MOST_POSITIVE_FIXNUM.
551 * sysdep.c (emacs_sigaction_init): Also mask out SIGPROF in
552 non-fatal signal handlers. Ignore SIGPROF on startup.
553 * syssignal.h (PROFILER_CPU_SUPPORT): Define this macro here, not
554 in profiler.c, since sysdep.c now uses it.
555
556 * sysdep.c (handle_fatal_signal): Bump backtrace size to 40.
557 Suggested by Eli Zaretskii in
558 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00796.html>.
559
5602012-09-29 Juanma Barranquero <lekktu@gmail.com>
561
562 * makefile.w32-in ($(BLD)/profiler.$(O)): Update dependencies.
563
5642012-09-29 Stefan Monnier <monnier@iro.umontreal.ca>
565
566 * lisp.h (struct backtrace): Remove indirection for `function' field.
567 * xdisp.c (redisplay_internal):
568 * profiler.c (record_backtrace, sigprof_handler_1):
569 * alloc.c (Fgarbage_collect):
570 * eval.c (interactive_p, Fsignal, eval_sub, Ffuncall, Fbacktrace)
571 (Fbacktrace_frame): Adjust accordingly.
572
5732012-09-28 Glenn Morris <rgm@gnu.org>
574
575 * eval.c (Frun_hook_with_args, Frun_hook_with_args_until_success)
576 (Frun_hook_with_args_until_failure): Doc fixes.
577
5782012-09-28 Eli Zaretskii <eliz@gnu.org>
579
580 * xdisp.c (syms_of_xdisp) <Qredisplay_internal>: Rename from
581 Qautomatic_redisplay and change the symbol name. All users changed.
582
5832012-09-28 Tomohiro Matsuyama <tomo@cx4a.org>
584
585 * profiler.c (sigprof_handler): Fix race condition.
586
5872012-09-28 Glenn Morris <rgm@gnu.org>
588
589 * lread.c (lisp_file_lexically_bound_p): Handle #! lines. (Bug#12528)
590
5912012-09-27 Paul Eggert <eggert@cs.ucla.edu>
592
593 Check more robustly for timer_settime.
594 * Makefile.in (LIB_TIMER_TIME): New macro.
595 (LIBES): Add it.
596 * atimer.c (alarm_timer, alarm_timer_ok, set_alarm, init_atimer):
597 Use HAVE_TIMER_SETTIME, not SIGEV_SIGNAL, to decide whether to
598 call timer_settime.
599
6002012-09-26 Tomohiro Matsuyama <tomo@cx4a.org>
601
602 * profiler.c (Fprofiler_cpu_start): Remove unnecessary flag SA_SIGINFO.
603
6042012-09-26 Juanma Barranquero <lekktu@gmail.com>
605
606 * makefile.w32-in ($(BLD)/profiler.$(O)): Update dependencies.
607
6082012-09-26 Paul Eggert <eggert@cs.ucla.edu>
609
610 * character.h (MAYBE_UNIFY_CHAR): Remove.
611 * charset.c, charset.h (maybe_unify_char): Now static.
612 * charset.c (decode_char): Use maybe_unify_char, not MAYBE_UNIFY_CHAR.
613 Since this stuff is now private to charset.c, there's no need for
614 a public macro and no need to inline by hand.
615
6162012-09-26 Tomohiro Matsuyama <tomo@cx4a.org>
617 Stefan Monnier <monnier@iro.umontreal.ca>
618 Juanma Barranquero <lekktu@gmail.com>
619
620 * profiler.c: New file.
621 * Makefile.in (base_obj): Add profiler.o.
622 * makefile.w32-in (OBJ2, GLOBAL_SOURCES): Add profiler.c.
623 ($(BLD)/profiler.$(O)): New target.
624 * emacs.c (main): Call syms_of_profiler.
625 * alloc.c (Qautomatic_gc): New constant.
626 (MALLOC_PROBE): New macro.
627 (xmalloc, xzalloc, xrealloc, lisp_malloc, lisp_align_malloc): Use it.
628 (total_bytes_of_live_objects): New function.
629 (Fgarbage_collect): Use it. Record itself in backtrace_list.
630 Call malloc_probe for the memory profiler.
631 (syms_of_alloc): Define Qautomatic_gc.
632 * eval.c (eval_sub, Ffuncall): Reorder assignments to avoid
633 race condition.
634 (struct backtrace): Move definition...
635 * lisp.h (struct backtrace): ..here.
636 (Qautomatic_gc, profiler_memory_running): Declare vars.
637 (malloc_probe, syms_of_profiler): Declare functions.
638 * xdisp.c (Qautomatic_redisplay): New constant.
639 (redisplay_internal): Record itself in backtrace_list.
640 (syms_of_xdisp): Define Qautomatic_redisplay.
641
6422012-09-25 Eli Zaretskii <eliz@gnu.org>
6432012-09-25 Juanma Barranquero <lekktu@gmail.com>
644
645 * makefile.w32-in ($(BLD)/callproc.$(O)): Update dependencies.
646
6472012-09-25 Paul Eggert <eggert@cs.ucla.edu>
648
649 Prefer POSIX timers if available.
650 They avoid a race if the timer is too close to the current time.
651 * atimer.c (alarm_timer, alarm_timer_ok) [SIGEV_SIGNAL]: New static vars.
652 (set_alarm) [SIGEV_SIGNAL]: Use POSIX timers if available.
653 (init_atimer) [SIGEV_SIGNAL]: Initialize them.
654
6552012-09-25 Eli Zaretskii <eliz@gnu.org>
656
657 * coding.c (CHAR_STRING_ADVANCE_NO_UNIFY): Make it an alias of
658 CHAR_STRING_ADVANCE.
659 (STRING_CHAR_ADVANCE_NO_UNIFY): Make it an alias of
660 STRING_CHAR_ADVANCE.
661
6622012-09-25 Juanma Barranquero <lekktu@gmail.com>
663
664 Move Vlibrary_cache to emacs.c and reset before dumping.
665
666 * lisp.h (reset_image_types): Declare.
667 [WINDOWSNT] (Vlibrary_cache): Declare.
668
669 * image.c (reset_image_types): New function.
670
671 * emacs.c [WINDOWSNT] (Vlibrary_cache): Move from w32.c.
672 (syms_of_emacs) [WINDOWSNT] <Vlibrary_cache>: Initialize and staticpro.
673 (Fdump_emacs): Reset Vlibrary_cache and image_types.
674
675 * w32.c (Vlibrary_cache): Do not define; moved to emacs.c
676 (globals_of_w32) <Vlibrary_cache>: Do not initialize.
677
678 * w32.h (Vlibrary_cache): Do not declare.
679
6802012-09-25 Eli Zaretskii <eliz@gnu.org>
681
682 * w32proc.c (sys_signal): Handle all signals defined by the
683 MS-Windows runtime, not just SIGCHLD. Actually install the signal
684 handlers for signals supported by Windows. Don't override
685 term_ntproc as the handler for SIGABRT.
686 (sigaction): Rewrite to call sys_signal instead of duplicating its
687 code.
688 (sys_kill): Improve commentary.
689
690 * w32.c (term_ntproc): Accept (and ignore) one argument, for
691 consistency with a signature of a signal handler. All callers
692 changed.
693 (init_ntproc): Accept an argument DUMPING. If dumping, don't
694 install term_ntproc as a signal handler for SIGABRT, as that
695 should be done by the dumped Emacs.
696
697 * w32.h (init_ntproc, term_ntproc): Adjust prototypes.
698
699 * w32select.c (term_w32select): Protect against repeated
700 invocation by setting clipboard_owner to NULL after calling
701 DestroyWindow.
702
703 * emacs.c (shut_down_emacs, main): Adapt the calls to init_ntproc
704 and term_ntproc to their modified signatures.
705
706 * character.c (char_string, string_char): Remove calls to
707 MAYBE_UNIFY_CHAR. See the discussion starting at
708 http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00433.html
709 for the details.
710
7112012-09-25 Chong Yidong <cyd@gnu.org>
712
713 * xdisp.c (mode_line_inverse_video): Delete obsolete variable.
714
7152012-09-24 Stefan Monnier <monnier@iro.umontreal.ca>
716
717 * bytecode.c (exec_byte_code): Signal an error instead of aborting,
718 when encountering an unknown bytecode.
719
7202012-09-24 Paul Eggert <eggert@cs.ucla.edu>
721
722 image.c, indent.c: Use bool for booleans.
723 * dispextern.h (struct image_type): Members valid_p, load, init
724 now return bool, not int. All uses changed.
725 * image.c: Omit unnecessary static decls.
726 (x_create_bitmap_mask, x_build_heuristic_mask):
727 Return void, not int, since callers don't care about the return value.
728 (x_create_bitmap_mask, define_image_type, valid_image_p)
729 (struct image_keyword, parse_image_spec, image_spec_value)
730 (check_image_size, image_background)
731 (image_background_transparent, x_clear_image_1)
732 (postprocess_image, lookup_image, x_check_image_size)
733 (x_create_x_image_and_pixmap, xbm_image_p)
734 (Create_Pixmap_From_Bitmap_Data, xbm_read_bitmap_data)
735 (xbm_load_image, xbm_file_p, xbm_load, xpm_lookup_color)
736 (init_xpm_functions, xpm_valid_color_symbols_p, xpm_image_p)
737 (xpm_load, xpm_load_image, lookup_rgb_color, lookup_pixel_color)
738 (x_to_xcolors, x_build_heuristic_mask, pbm_image_p, pbm_load)
739 (png_image_p, init_png_functions, png_load_body, png_load)
740 (jpeg_image_p, init_jpeg_functions, jpeg_load_body, jpeg_load)
741 (tiff_image_p, init_tiff_functions, tiff_load, gif_image_p)
742 (init_gif_functions, gif_load, imagemagick_image_p)
743 (imagemagick_load_image, imagemagick_load, svg_image_p)
744 (init_svg_functions, svg_load, svg_load_image, gs_image_p)
745 (gs_load):
746 * nsimage.m (ns_load_image):
747 * nsterm.m (ns_defined_color):
748 * xfaces.c (tty_lookup_color, tty_defined_color, defined_color):
749 * xfns.c (x_defined_color):
750 * xterm.c (x_alloc_lighter_color_for_widget)
751 (x_alloc_nearest_color_1, x_alloc_nearest_color)
752 (x_alloc_lighter_color):
753 * indent.c (disptab_matches_widthtab, current_column)
754 (scan_for_column, string_display_width, indented_beyond_p)
755 (compute_motion, vmotion, Fvertical_motion):
756 Use bool for booleans.
757
7582012-09-24 Chong Yidong <cyd@gnu.org>
759
760 * chartab.c (Fset_char_table_default): Obsolete function removed.
761
7622012-09-23 Paul Eggert <eggert@cs.ucla.edu>
763
764 Move pid_t related decls out of lisp.h.
765 * lisp.h, syswait.h (record_child_status_change, wait_for_termination)
766 (interruptible_wait_for_termination):
767 Move these decls from lisp.h to syswait.h, since they use pid_t.
768 Needed on FreeBSD; see Herbert J. Skuhra in
769 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00571.html>.
770 * callproc.c: Include syswait.h.
771
772 gnutls.c, gtkutil.c: Use bool for boolean.
773 * gnutls.c (gnutls_global_initialized, init_gnutls_functions)
774 (emacs_gnutls_handle_error):
775 * gtkutil.c (xg_check_special_colors, xg_prepare_tooltip)
776 (xg_hide_tooltip, xg_create_frame_widgets)
777 (create_dialog, xg_uses_old_file_dialog)
778 (xg_get_file_with_chooser, xg_get_file_with_selection)
779 (xg_get_file_name, xg_have_tear_offs, create_menus, xg_create_widget)
780 (xg_item_label_same_p, xg_update_menubar)
781 (xg_modify_menubar_widgets, xg_event_is_for_menubar)
782 (xg_ignore_gtk_scrollbar, xg_set_toolkit_scroll_bar_thumb)
783 (xg_event_is_for_scrollbar, xg_pack_tool_bar, xg_make_tool_item)
784 (is_box_type, xg_tool_item_stale_p, xg_update_tool_bar_sizes)
785 (update_frame_tool_bar, free_frame_tool_bar):
786 * gtkutil.c, w32term.c, xterm.c (x_wm_set_size_hint):
787 * nsmenu.m (ns_update_menubar):
788 * nsmenu.m, w32menu.c, xmenu.c (set_frame_menubar):
789 * xfns.c (Fx_show_tip) [USE_GTK]:
790 Use bool for boolean.
791 * gtkutil.c (xg_update_frame_menubar):
792 * xmenu.c (update_frame_menubar):
793 Return void, not int, since caller ignores return value.
794 * gtkutil.c (xg_change_toolbar_position):
795 Return void, not 1.
796
7972012-09-23 Juanma Barranquero <lekktu@gmail.com>
798
799 * makefile.w32-in (BLOCKINPUT_H): Remove.
800 (SYSSIGNAL_H): New macro.
801 ($(BLD)/alloc.$(O), $(BLD)/atimer.$(O), $(BLD)/buffer.$(O))
802 ($(BLD)/callproc.$(O), $(BLD)/data.$(O), $(BLD)/dired.$(O))
803 ($(BLD)/dispnew.$(O), $(BLD)/editfns.$(O), $(BLD)/emacs.$(O))
804 ($(BLD)/eval.$(O), $(BLD)/fileio.$(O), $(BLD)/floatfns.$(O))
805 ($(BLD)/fns.$(O), $(BLD)/fontset.$(O), $(BLD)/frame.$(O))
806 ($(BLD)/fringe.$(O), $(BLD)/image.$(O), $(BLD)/insdel.$(O))
807 ($(BLD)/keyboard.$(O), $(BLD)/keymap.$(O), $(BLD)/lread.$(O))
808 ($(BLD)/menu.$(O), $(BLD)/w32inevt.$(O), $(BLD)/w32proc.$(O))
809 ($(BLD)/print.$(O), $(BLD)/process.$(O), $(BLD)/ralloc.$(O))
810 ($(BLD)/search.$(O), $(BLD)/sound.$(O), $(BLD)/sysdep.$(O))
811 ($(BLD)/term.$(O), $(BLD)/window.$(O), $(BLD)/xdisp.$(O))
812 ($(BLD)/xfaces.$(O), $(BLD)/w32fns.$(O), $(BLD)/w32menu.$(O))
813 ($(BLD)/w32term.$(O), $(BLD)/w32select.$(O), $(BLD)/w32reg.$(O))
814 ($(BLD)/w32xfns.$(O)): Update dependencies.
815
8162012-09-23 Eli Zaretskii <eliz@gnu.org>
817
818 * .gdbinit: Set breakpoint on terminate_due_to_signal, not on
819 fatal_error_backtrace.
820
821 * w32proc.c (sys_kill): Undo last change: don't do anything when
822 invoked to deliver SIGABRT to our own process. This is now
823 handled by emacs_raise.
824
8252012-09-23 Juanma Barranquero <lekktu@gmail.com>
826
827 * w32term.c (w32_read_socket): Remove leftover reference to
828 interrupt_input_pending.
829
8302012-09-23 Paul Eggert <eggert@cs.ucla.edu>
831
832 Do not use SA_NODEFER.
833 Problem reported by Dani Moncayo in
834 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00557.html>.
835 * alloc.c (die):
836 * sysdep.c (emacs_abort): Do not reset signal handler.
837 * emacs.c (terminate_due_to_signal): Reset signal handler here.
838 * sysdep.c (init_signals): Do not use SA_NODEFER. It wasn't
839 wanted even on POSIXish hosts, and it doesn't work on Windows.
840
8412012-09-23 Jan Djärv <jan.h.d@swipnet.se>
842
843 * xterm.c (x_term_init): Call fixup_locale before and after calling
844 gtk_init (Bug#12392).
845
8462012-09-23 Chong Yidong <cyd@gnu.org>
847
848 * w32.c (w32_delayed_load): Remove LIBRARIES argument; always use
849 Vdynamic_library_alist.
850
851 * gnutls.c (init_gnutls_functions): Caller changed; remove arg.
852 (Fgnutls_available_p): Caller changed.
853
854 * xml.c (init_libxml2_functions, Flibxml_parse_html_region)
855 (Flibxml_parse_xml_region): Likewise.
856
857 * dispextern.h (struct image_type): Remove arg from init function.
858
859 * image.c (Finit_image_library, lookup_image_type)
860 (define_image_type): Remove now-unneeded second arg.
861 (init_xpm_functions, init_png_functions, init_jpeg_functions)
862 (init_tiff_functions, init_gif_functions, init_svg_functions):
863 Arglist and w32_delayed_load calling convention changed.
864 (gs_type): Remove init_gs_functions; there is no such function.
865 (valid_image_p, make_image): Fix caller to lookup_image_type.
866
8672012-09-23 Paul Eggert <eggert@cs.ucla.edu>
868
869 Simplify and avoid signal-handling races (Bug#12471).
870 * alloc.c (die):
871 * sysdep.c (emacs_abort) [HAVE_NTGUI]:
872 Avoid recursive loop if there's a fatal error in the function itself.
873 * atimer.c (pending_atimers):
874 * blockinput.h: Don't include "atimer.h"; no longer needed.
875 (interrupt_input_pending): Remove. All uses removed.
876 pending_signals now counts both atimers and ordinary interrupts.
877 This is less racy than having three separate pending-signal flags.
878 (block_input, unblock_input, totally_unblock_input, unblock_input_to)
879 (input_blocked_p):
880 Rename from their upper-case counterparts BLOCK_INPUT,
881 UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_TO,
882 INPUT_BLOCKED_P, and turn into functions. All uses changed.
883 This makes it easier to access volatile variables more accurately.
884 (BLOCK_INPUT_RESIGNAL): Remove. All uses replaced by unblock_input ().
885 (input_blocked_p): Prefer this to 'interrupt_input_blocked', as
886 that's more reliable if the code is buggy and sets
887 interrupt_input_blocked to a negative value. All uses changed.
888 * atimer.c (deliver_alarm_signal):
889 Remove. No need to deliver this to the parent; any thread can
890 handle this signal now. All uses replaced by underlying handler.
891 * atimer.c (turn_on_atimers):
892 * dispnew.c (handle_window_change_signal):
893 * emacs.c (handle_danger_signal):
894 * keyboard.c (kbd_buffer_get_event):
895 Don't reestablish signal handler; not needed with sigaction.
896 * blockinput.h (UNBLOCK_INPUT_TO, TOTALLY_UNBLOCK_INPUT)
897 (UNBLOCK_INPUT_TO):
898 Rework to avoid unnecessary accesses to volatile variables.
899 (UNBLOCK_INPUT_TO): Now a function.
900 (totally_unblock_input, unblock_input): New decls.
901 * data.c (handle_arith_signal, deliver_arith_signal): Move to sysdep.c
902 (init_data): Remove. Necessary stuff now done in init_signal.
903 * emacs.c, xdisp.c: Include "atimer.h", since we invoke atimer functions.
904 * emacs.c (handle_fatal_signal, deliver_fatal_signal): Move to sysdep.c.
905 (fatal_error_code): Remove; no longer needed.
906 (terminate_due_to_signal): Rename from fatal_error_backtrace, since
907 it doesn't always backtrace. All uses changed. No need to reset
908 signal to default, since sigaction and/or die does that for us now.
909 Use emacs_raise (FOO), not kill (getpid (), FOO).
910 (main): Check more-accurately whether we're dumping.
911 Move fatal-error setup to sysdep.c
912 * floatfns.c: Do not include "syssignal.h"; no longer needed.
913 * gtkutil.c (xg_get_file_name, xg_get_font):
914 Remove no-longer-needed signal-mask manipulation.
915 * keyboard.c, process.c (POLL_FOR_INPUT):
916 Don't depend on USE_ASYNC_EVENTS, a symbol that is never defined.
917 * keyboard.c (read_avail_input): Remove.
918 All uses replaced by gobble_input.
919 (Ftop_level): Use TOTALLY_UNBLOCK_INPUT rather than open code.
920 (kbd_buffer_store_event_hold, gobble_input):
921 (record_asynch_buffer_change) [USABLE_SIGIO]:
922 (store_user_signal_events):
923 No need to mess with signal mask.
924 (gobble_input): If blocking input and there are terminals, simply
925 set pending_signals to 1 and return. All hooks changed to not
926 worry about whether input is blocked.
927 (process_pending_signals): Clear pending_signals before processing
928 them, in case a signal comes in while we're processing.
929 By convention callers now test pending_signals before calling us.
930 (UNBLOCK_INPUT_TO, unblock_input, totally_unblock_input):
931 New functions, to support changes to blockinput.h.
932 (handle_input_available_signal): Now extern.
933 (reinvoke_input_signal): Remove. All uses replaced by
934 handle_async_input.
935 (quit_count): Now volatile, since a signal handler uses it.
936 (handle_interrupt): Now takes bool IN_SIGNAL_HANDLER as arg.
937 All callers changed. Block SIGINT only if not already blocked.
938 Clear sigmask reliably, even if Fsignal returns, which it can.
939 Omit unnecessary accesses to volatile var.
940 (quit_throw_to_read_char): No need to restore sigmask.
941 * keyboard.c (gobble_input, handle_user_signal):
942 * process.c (wait_reading_process_output):
943 Call signal-handling code rather than killing ourselves.
944 * lisp.h: Include <float.h>, for...
945 (IEEE_FLOATING_POINT): New macro, moved here to avoid duplication.
946 (pending_signals): Now volatile.
947 (syms_of_data): Now const if IEEE floating point.
948 (handle_input_available_signal) [USABLE_SIGIO]:
949 (terminate_due_to_signal, record_child_status_change): New decls.
950 * process.c (create_process): Avoid disaster if memory is exhausted
951 while we're processing a vfork, by tightening the critical section
952 around the vfork.
953 (send_process_frame, process_sent_to, handle_pipe_signal)
954 (deliver_pipe_signal): Remove. No longer needed, as Emacs now
955 ignores SIGPIPE.
956 (send_process): No need for setjmp/longjmp any more, since the
957 SIGPIPE stuff is now gone. Instead, report an error if errno
958 is EPIPE.
959 (record_child_status_change): Now extern. PID and W are now args.
960 Return void, not bool. All callers changed.
961 * sysdep.c (wait_debugging) [(BSD_SYSTEM || HPUX) && !defined (__GNU__)]:
962 Remove. All uses removed. This bug should be fixed now in a
963 different way.
964 (wait_for_termination_1): Use waitpid rather than sigsuspend,
965 and record the child status change directly. This avoids the
966 need to futz with the signal mask.
967 (process_fatal_action): Move here from emacs.c.
968 (emacs_sigaction_flags): New function, containing
969 much of what used to be in emacs_sigaction_init.
970 (emacs_sigaction_init): Use it. Block nonfatal system signals that are
971 caught by emacs, to make races less likely.
972 (deliver_process_signal): Rename from handle_on_main_thread.
973 All uses changed.
974 (BACKTRACE_LIMIT_MAX): Now at top level.
975 (thread_backtrace_buffer, threadback_backtrace_pointers):
976 New static vars.
977 (deliver_thread_signal, deliver_fatal_thread_signal):
978 New functions, for more-accurate delivery of thread-specific signals.
979 (handle_fatal_signal, deliver_fatal_signal): Move here from emacs.c.
980 (deliver_arith_signal): Handle in this thread, not
981 in the main thread, since it's triggered by this thread.
982 (maybe_fatal_sig): New function.
983 (init_signals): New arg DUMPING so that we can be more accurate
984 about whether we're dumping. Caller changed.
985 Treat thread-specific signals differently from process-general signals.
986 Block all signals while handling fatal error; that's safer.
987 xsignal from SIGFPE only on non-IEEE hosts, treating it as fatal
988 on IEEE hosts.
989 When batch, ignore SIGHUP, SIGINT, SIGTERM if they were already ignored.
990 Ignore SIGPIPE unless batch.
991 (emacs_backtrace): Output backtrace for the appropriate thread,
992 which is not necessarily the main thread.
993 * syssignal.h: Include <stdbool.h>.
994 (emacs_raise): New macro.
995 * xterm.c (x_connection_signal): Remove; no longer needed
996 now that we use sigaction.
997 (x_connection_closed): No need to mess with sigmask now.
998 (x_initialize): No need to reset SIGPIPE handler here, since
999 init_signals does this for us now.
1000
10012012-09-23 Jan Djärv <jan.h.d@swipnet.se>
1002
1003 * nsterm.m (ns_dumpglyphs_image): dr is a new rect to draw image into,
1004 background rect may be larger (Bug#12245).
1005
10062012-09-23 Chong Yidong <cyd@gnu.org>
1007
1008 * keyboard.c (timer_check): Avoid quitting during Fcopy_sequence.
1009
10102012-09-22 Paul Eggert <eggert@cs.ucla.edu>
1011
1012 * .gdbinit: Just stop at fatal_error_backtrace.
1013 See Stefan Monnier's request in
1014 <http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00549.html>.
1015 Remove no-longer-used query of system type.
1016
10172012-09-22 Chong Yidong <cyd@gnu.org>
1018
1019 * search.c (Freplace_match): Doc fix (Bug#12325).
1020
1021 * minibuf.c (Finternal_complete_buffer): Doc fix (Bug#12391).
1022
1023 * editfns.c (Fline_beginning_position): Doc fix (Bug#12416).
1024 (Fline_end_position): Doc fix.
1025
1026 * cmds.c (Fforward_char, Fbackward_char): Doc fix (Bug#12414).
1027
10282012-09-22 Chong Yidong <cyd@gnu.org>
1029
1030 * dispextern.h (struct image_type): Add new slot, storing a type
1031 initialization function.
1032
1033 * image.c (define_image_type): Call the image initializer function
1034 if it is defined. Arguments and return value changed.
1035 (valid_image_p, make_image): Callers changed.
1036 (xbm_type, xpm_type, pbm_type, png_type, jpeg_type, tiff_type)
1037 (gif_type, imagemagick_type, svg_type, gs_type):
1038 Add initialization functions.
1039 (Finit_image_library): Call lookup_image_type.
1040 (CHECK_LIB_AVAILABLE): Macro deleted.
1041 (lookup_image_type): Call define_image_type here, rather than via
1042 Finit_image_library, and without using CHECK_LIB_AVAILABLE.
1043 (syms_of_image): Move define_image_type calls for xbm_type and
1044 pbm_type to lookup_image_type.
1045
10462012-09-22 Eli Zaretskii <eliz@gnu.org>
1047
1048 * keyboard.c (timer_check_2): Move calculation of 'timers' and
1049 'idle_timers' from here ...
1050 (timer_check): ... to here. Use Fcopy_sequence to copy the timer
1051 lists, to avoid infloops when the timer does something stupid,
1052 like reinvoke itself with the same or smaller time-out.
1053 (Bug#12447)
1054
10552012-09-22 Martin Rudalics <rudalics@gmx.at>
1056
1057 * window.c (Fsplit_window_internal): Handle only Qt value of
1058 Vwindow_combination_limit separately.
1059 (Qtemp_buffer_resize): New symbol.
1060 (Vwindow_combination_limit): New default value.
1061 Rewrite doc-string.
1062
10632012-09-22 Eli Zaretskii <eliz@gnu.org>
1064
1065 * xdisp.c (next_overlay_string): Initialize it->end_charpos for
1066 the new overlay string. (Bug#10159)
1067
10682012-09-22 Paul Eggert <eggert@cs.ucla.edu>
1069
1070 * emacs.c (shut_down_emacs): Don't assume stderr is buffered,
1071 or that fprintf is async-signal-safe. POSIX doesn't require
1072 either assumption.
1073
10742012-09-22 Chong Yidong <cyd@gnu.org>
1075
1076 * buffer.c (Fset_buffer_modified_p): Handle indirect buffers
1077 (Bug#8207).
1078
10792012-09-22 Kenichi Handa <handa@gnu.org>
1080
1081 * composite.c (composition_reseat_it): Handle the case that a
1082 grapheme cluster is not covered by a single font (Bug#12352).
1083
10842012-09-21 Chong Yidong <cyd@gnu.org>
1085
1086 * image.c (define_image_type): Avoid adding duplicate types to
1087 image_types (Bug#12463). Suggested by Jörg Walter.
1088
10892012-09-21 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
1090
1091 * unexmacosx.c: Define LC_DATA_IN_CODE if not defined.
1092 (print_load_command_name): Add case LC_DATA_IN_CODE.
1093 (dump_it) [LC_DATA_IN_CODE]: Call copy_linkedit_data.
1094
10952012-09-21 Glenn Morris <rgm@gnu.org>
1096
1097 * eval.c (Frun_hook_with_args_until_success)
1098 (Frun_hook_with_args_until_failure): Doc fixes. (Bug#12393)
1099
11002012-09-21 Andreas Schwab <schwab@linux-m68k.org>
1101
1102 * fileio.c (Ffile_selinux_context): Only call freecon when
1103 lgetfilecon succeeded.
1104 (Fset_file_selinux_context): Likewise. (Bug#12444)
1105
11062012-09-21 Eli Zaretskii <eliz@gnu.org>
1107
1108 * xdisp.c (try_window_reusing_current_matrix): Under bidi
1109 reordering, locate the cursor by calling set_cursor_from_row; if
1110 that fails, clear the desired glyph matrix before returning a
1111 failure indication to the caller. Fixes leaving garbled display
1112 when fast scrolling with a down-key. (Bug#12403)
1113 (compute_stop_pos_backwards): Fix a typo that caused crashes while
1114 scrolling through multibyte text.
1115
11162012-09-20 Stefan Monnier <monnier@iro.umontreal.ca>
1117
1118 * alloc.c (mark_object) <PVEC_WINDOW>: Mark prev/next_buffers *after*
1119 calling mark_vectorlike since that's the one that marks the window.
1120 (mark_discard_killed_buffers): Mark the final cdr.
1121 * window.h (struct window): Move prev/next_buffers to the
1122 non-standard fields.
1123 * window.c (make_window): Initialize prev/next_buffers manually.
1124
11252012-09-20 Paul Eggert <eggert@cs.ucla.edu>
1126
1127 Omit unused arg EXPECTED from socket hooks.
1128 * keyboard.c (gobble_input, read_avail_input, tty_read_avail_input):
1129 * nsterm.m (ns_term_init):
1130 * termhooks.h (struct terminal.read_socket_hook):
1131 * w32inevt.c (w32_console_read_socket):
1132 * w32term.c (w32_read_socket):
1133 * xterm.c (XTread_socket):
1134 Omit unused arg EXPECTED. All callers changed.
1135 (store_user_signal_events): Return void, not int, since callers no
1136 longer care about the return value. All uses changed.
1137
11382012-09-20 Juanma Barranquero <lekktu@gmail.com>
1139
1140 * w32gui.h (XParseGeometry): Do not declare.
1141
11422012-09-19 Paul Eggert <eggert@cs.ucla.edu>
1143
1144 * w32inevt.c (w32_console_read_socket): Return -1 on failure, not 0.
1145 Ignore 'expected'. See Eli Zaretskii in
1146 <http://bugs.gnu.org/12471#8> (last line).
1147
1148 * frame.c (read_integer): Remove. All uses replaced by strtol/strtoul.
1149 (XParseGeometry): Now static. Substitute extremal values for
1150 values that are out of range.
1151
11522012-09-19 Jan Djärv <jan.h.d@swipnet.se>
1153
1154 * w32xfns.c (read_integer, XParseGeometry): Move to frame.c.
1155
1156 * nsfns.m (XParseGeometry): Remove.
1157 (Fx_create_frame): Call x_set_offset to correctly interpret
1158 top_pos in geometry.
1159
1160 * frame.c (read_integer, XParseGeometry): Move from w32xfns.c.
1161 (Fx_parse_geometry): If there is a space in string, call
1162 Qns_parse_geometry, otherwise do as on other terms (Bug#12368).
1163
12012-09-17 Eli Zaretskii <eliz@gnu.org> 11642012-09-17 Eli Zaretskii <eliz@gnu.org>
2 1165
1166 * search.c (scan_buffer): Use character positions in calls to
1167 region_cache_forward and region_cache_backward, not byte
1168 positions. (Bug#12196)
1169
3 * w32term.c (w32_read_socket): Set pending_signals to 1, like 1170 * w32term.c (w32_read_socket): Set pending_signals to 1, like
4 xterm.c does. Reported by Daniel Colascione <dancol@dancol.org>. 1171 xterm.c does. Reported by Daniel Colascione <dancol@dancol.org>.
5 1172
@@ -79,7 +1246,7 @@
79 (clean): Simplify nextstep entry. 1246 (clean): Simplify nextstep entry.
80 * ns.mk: Remove file. 1247 * ns.mk: Remove file.
81 1248
822012-09-16 Kenichi Handa <handa@gnu.org> 12492012-09-17 Kenichi Handa <handa@gnu.org>
83 1250
84 * font.c (Ffont_shape_gstring): Fix previous change; GLYPHs may 1251 * font.c (Ffont_shape_gstring): Fix previous change; GLYPHs may
85 not covert the last few charactes. 1252 not covert the last few charactes.
@@ -91,8 +1258,8 @@
91 1258
922012-09-16 Martin Rudalics <rudalics@gmx.at> 12592012-09-16 Martin Rudalics <rudalics@gmx.at>
93 1260
94 * window.c (Fwindow_parameter, Fset_window_parameter): Accept 1261 * window.c (Fwindow_parameter, Fset_window_parameter):
95 any window as argument (Bug#12452). 1262 Accept any window as argument (Bug#12452).
96 1263
972012-09-16 Jan Djärv <jan.h.d@swipnet.se> 12642012-09-16 Jan Djärv <jan.h.d@swipnet.se>
98 1265
@@ -167,8 +1334,8 @@
1672012-09-14 Dmitry Antipov <dmantipov@yandex.ru> 13342012-09-14 Dmitry Antipov <dmantipov@yandex.ru>
168 1335
169 Avoid out-of-range marker position (Bug#12426). 1336 Avoid out-of-range marker position (Bug#12426).
170 * insdel.c (replace_range, replace_range_2): Adjust 1337 * insdel.c (replace_range, replace_range_2):
171 markers before overlays, as suggested by comments. 1338 Adjust markers before overlays, as suggested by comments.
172 (insert_1_both, insert_from_buffer_1, adjust_after_replace): 1339 (insert_1_both, insert_from_buffer_1, adjust_after_replace):
173 Remove redundant check before calling offset_intervals. 1340 Remove redundant check before calling offset_intervals.
174 1341
@@ -467,8 +1634,8 @@
467 in the internal border. 1634 in the internal border.
468 (x_set_window_size): Remove static variables and their usage. 1635 (x_set_window_size): Remove static variables and their usage.
469 (ns_redraw_scroll_bars): Fix NSTRACE arg. 1636 (ns_redraw_scroll_bars): Fix NSTRACE arg.
470 (ns_after_update_window_line, ns_draw_fringe_bitmap): Remove 1637 (ns_after_update_window_line, ns_draw_fringe_bitmap):
471 fringe/internal border adjustment (Bug#11052). 1638 Remove fringe/internal border adjustment (Bug#11052).
472 (ns_draw_fringe_bitmap): Make code more like other terms (xterm.c). 1639 (ns_draw_fringe_bitmap): Make code more like other terms (xterm.c).
473 (ns_draw_window_cursor): Remove fringe/internal border adjustment. 1640 (ns_draw_window_cursor): Remove fringe/internal border adjustment.
474 (ns_fix_rect_ibw): Remove. 1641 (ns_fix_rect_ibw): Remove.
@@ -685,8 +1852,8 @@
685 (init_signals) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Initialize it; 1852 (init_signals) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Initialize it;
686 code moved here from emacs.c's main function. 1853 code moved here from emacs.c's main function.
687 * sysdep.c, syssignal.h (handle_on_main_thread): New function, 1854 * sysdep.c, syssignal.h (handle_on_main_thread): New function,
688 replacing the old SIGNAL_THREAD_CHECK. All uses changed. This 1855 replacing the old SIGNAL_THREAD_CHECK. All uses changed.
689 lets callers save and restore errno properly. 1856 This lets callers save and restore errno properly.
690 1857
6912012-09-05 Dmitry Antipov <dmantipov@yandex.ru> 18582012-09-05 Dmitry Antipov <dmantipov@yandex.ru>
692 1859
@@ -995,8 +2162,8 @@
995 * process.c: Include TERM_HEADER instead of listing all possible 2162 * process.c: Include TERM_HEADER instead of listing all possible
996 window-system headers. 2163 window-system headers.
997 2164
998 * nsterm.h: Remove declarations now in frame.h. Define 2165 * nsterm.h: Remove declarations now in frame.h.
999 FRAME_X_SCREEN, FRAME_X_VISUAL. 2166 Define FRAME_X_SCREEN, FRAME_X_VISUAL.
1000 2167
1001 * menu.c: Include TERM_HEADER instead of listing all possible 2168 * menu.c: Include TERM_HEADER instead of listing all possible
1002 window-system headers. 2169 window-system headers.
@@ -1192,8 +2359,8 @@
1192 2359
1193 * nsterm.h (NSPanel): New class variable dialog_return. 2360 * nsterm.h (NSPanel): New class variable dialog_return.
1194 2361
1195 * nsmenu.m (initWithContentRect:styleMask:backing:defer:): Initialize 2362 * nsmenu.m (initWithContentRect:styleMask:backing:defer:):
1196 dialog_return. 2363 Initialize dialog_return.
1197 (windowShouldClose:): Use stop instead of stopModalWithCode. 2364 (windowShouldClose:): Use stop instead of stopModalWithCode.
1198 (clicked:): Ditto, and also set dialog_return (Bug#12258). 2365 (clicked:): Ditto, and also set dialog_return (Bug#12258).
1199 (timeout_handler:): Use stop instead of abortModal. Send a dummy 2366 (timeout_handler:): Use stop instead of abortModal. Send a dummy
diff --git a/src/ChangeLog.11 b/src/ChangeLog.11
index d3b0a8284b5..1f444b9292c 100644
--- a/src/ChangeLog.11
+++ b/src/ChangeLog.11
@@ -5532,7 +5532,7 @@
5532 (update_frame_tool_bar): Remove old_req, new_req. Do not get tool bar 5532 (update_frame_tool_bar): Remove old_req, new_req. Do not get tool bar
5533 height, call xg_update_tool_bar_sizes instead. 5533 height, call xg_update_tool_bar_sizes instead.
5534 (free_frame_tool_bar): Remove from hbox or vbox depending on 5534 (free_frame_tool_bar): Remove from hbox or vbox depending on
5535 toolbar_in_hbox, Set all FRAME_TOOLBAR_*_(WIDTH|HEIGHT) to zero. 5535 toolbar_in_hbox. Set all FRAME_TOOLBAR_*_(WIDTH|HEIGHT) to zero.
5536 (xg_change_toolbar_position): New function. 5536 (xg_change_toolbar_position): New function.
5537 5537
5538 * frame.h (struct frame): Add tool_bar_position. 5538 * frame.h (struct frame): Add tool_bar_position.
diff --git a/src/ChangeLog.2 b/src/ChangeLog.2
index 1a9728f6896..0806106836e 100644
--- a/src/ChangeLog.2
+++ b/src/ChangeLog.2
@@ -2680,7 +2680,7 @@
2680 2680
26811986-12-11 Richard Mlynarik (mly@prep) 26811986-12-11 Richard Mlynarik (mly@prep)
2682 2682
2683 * emacs.c, dispnew.c: 2683 * emacs.c, dispnew.c:
2684 Rename inhibit_x_windows inhibit_window_system. 2684 Rename inhibit_x_windows inhibit_window_system.
2685 Understand "-nw" command-line option. 2685 Understand "-nw" command-line option.
2686 Reorganize init_display a little to make other window-system 2686 Reorganize init_display a little to make other window-system
diff --git a/src/ChangeLog.3 b/src/ChangeLog.3
index 6c580fe4b52..4f6e02ff8d3 100644
--- a/src/ChangeLog.3
+++ b/src/ChangeLog.3
@@ -11154,7 +11154,7 @@
11154 (classify_object): Removed code to look up a function key in the 11154 (classify_object): Removed code to look up a function key in the
11155 global and local function key keymaps, since this will be done 11155 global and local function key keymaps, since this will be done
11156 more generally. 11156 more generally.
11157 (Fexecute_mouse_event): Elided this function with a #if 0; I 11157 (Fexecute_mouse_event): Elided this function with a #if 0; I
11158 think it will go away once the more general keymap stuff is 11158 think it will go away once the more general keymap stuff is
11159 implemented, but I'm not sure. 11159 implemented, but I'm not sure.
11160 (syms_of_keyboard): Removed defsubr for Sexecute_mouse_event. 11160 (syms_of_keyboard): Removed defsubr for Sexecute_mouse_event.
diff --git a/src/Makefile.in b/src/Makefile.in
index a31499e2767..e704f2f5c0c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -150,6 +150,7 @@ M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@
150M17N_FLT_LIBS = @M17N_FLT_LIBS@ 150M17N_FLT_LIBS = @M17N_FLT_LIBS@
151 151
152LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ 152LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@
153LIB_TIMER_TIME=@LIB_TIMER_TIME@
153 154
154DBUS_CFLAGS = @DBUS_CFLAGS@ 155DBUS_CFLAGS = @DBUS_CFLAGS@
155DBUS_LIBS = @DBUS_LIBS@ 156DBUS_LIBS = @DBUS_LIBS@
@@ -343,6 +344,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
343 process.o gnutls.o callproc.o \ 344 process.o gnutls.o callproc.o \
344 region-cache.o sound.o atimer.o \ 345 region-cache.o sound.o atimer.o \
345 doprnt.o intervals.o textprop.o composite.o xml.o \ 346 doprnt.o intervals.o textprop.o composite.o xml.o \
347 profiler.o \
346 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 348 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
347 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) 349 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ)
348obj = $(base_obj) $(NS_OBJC_OBJ) 350obj = $(base_obj) $(NS_OBJC_OBJ)
@@ -389,7 +391,8 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \
389## with GCC, we might need LIB_GCC again after them. 391## with GCC, we might need LIB_GCC again after them.
390LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \ 392LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \
391 $(LIBX_OTHER) $(LIBSOUND) \ 393 $(LIBX_OTHER) $(LIBSOUND) \
392 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) $(DBUS_LIBS) \ 394 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
395 $(LIB_TIMER_TIME) $(DBUS_LIBS) \
393 $(LIB_EXECINFO) \ 396 $(LIB_EXECINFO) \
394 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 397 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
395 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 398 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
diff --git a/src/alloc.c b/src/alloc.c
index fb7d35b5590..3ed8cc2d990 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -74,6 +74,7 @@ extern void *sbrk ();
74#endif 74#endif
75#ifdef WINDOWSNT 75#ifdef WINDOWSNT
76#include "w32.h" 76#include "w32.h"
77#include "w32heap.h" /* for sbrk */
77#endif 78#endif
78 79
79#ifdef DOUG_LEA_MALLOC 80#ifdef DOUG_LEA_MALLOC
@@ -205,6 +206,7 @@ static Lisp_Object Qintervals;
205static Lisp_Object Qbuffers; 206static Lisp_Object Qbuffers;
206static Lisp_Object Qstring_bytes, Qvector_slots, Qheap; 207static Lisp_Object Qstring_bytes, Qvector_slots, Qheap;
207static Lisp_Object Qgc_cons_threshold; 208static Lisp_Object Qgc_cons_threshold;
209Lisp_Object Qautomatic_gc;
208Lisp_Object Qchar_table_extra_slots; 210Lisp_Object Qchar_table_extra_slots;
209 211
210/* Hook run after GC has finished. */ 212/* Hook run after GC has finished. */
@@ -353,7 +355,7 @@ static void mem_rotate_left (struct mem_node *);
353static void mem_rotate_right (struct mem_node *); 355static void mem_rotate_right (struct mem_node *);
354static void mem_delete (struct mem_node *); 356static void mem_delete (struct mem_node *);
355static void mem_delete_fixup (struct mem_node *); 357static void mem_delete_fixup (struct mem_node *);
356static inline struct mem_node *mem_find (void *); 358static struct mem_node *mem_find (void *);
357#endif 359#endif
358 360
359 361
@@ -633,13 +635,13 @@ static void
633malloc_block_input (void) 635malloc_block_input (void)
634{ 636{
635 if (block_input_in_memory_allocators) 637 if (block_input_in_memory_allocators)
636 BLOCK_INPUT; 638 block_input ();
637} 639}
638static void 640static void
639malloc_unblock_input (void) 641malloc_unblock_input (void)
640{ 642{
641 if (block_input_in_memory_allocators) 643 if (block_input_in_memory_allocators)
642 UNBLOCK_INPUT; 644 unblock_input ();
643} 645}
644# define MALLOC_BLOCK_INPUT malloc_block_input () 646# define MALLOC_BLOCK_INPUT malloc_block_input ()
645# define MALLOC_UNBLOCK_INPUT malloc_unblock_input () 647# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
@@ -648,6 +650,13 @@ malloc_unblock_input (void)
648# define MALLOC_UNBLOCK_INPUT ((void) 0) 650# define MALLOC_UNBLOCK_INPUT ((void) 0)
649#endif 651#endif
650 652
653#define MALLOC_PROBE(size) \
654 do { \
655 if (profiler_memory_running) \
656 malloc_probe (size); \
657 } while (0)
658
659
651/* Like malloc but check for no memory and block interrupt input.. */ 660/* Like malloc but check for no memory and block interrupt input.. */
652 661
653void * 662void *
@@ -661,6 +670,7 @@ xmalloc (size_t size)
661 670
662 if (!val && size) 671 if (!val && size)
663 memory_full (size); 672 memory_full (size);
673 MALLOC_PROBE (size);
664 return val; 674 return val;
665} 675}
666 676
@@ -678,6 +688,7 @@ xzalloc (size_t size)
678 if (!val && size) 688 if (!val && size)
679 memory_full (size); 689 memory_full (size);
680 memset (val, 0, size); 690 memset (val, 0, size);
691 MALLOC_PROBE (size);
681 return val; 692 return val;
682} 693}
683 694
@@ -699,6 +710,7 @@ xrealloc (void *block, size_t size)
699 710
700 if (!val && size) 711 if (!val && size)
701 memory_full (size); 712 memory_full (size);
713 MALLOC_PROBE (size);
702 return val; 714 return val;
703} 715}
704 716
@@ -888,6 +900,7 @@ lisp_malloc (size_t nbytes, enum mem_type type)
888 MALLOC_UNBLOCK_INPUT; 900 MALLOC_UNBLOCK_INPUT;
889 if (!val && nbytes) 901 if (!val && nbytes)
890 memory_full (nbytes); 902 memory_full (nbytes);
903 MALLOC_PROBE (nbytes);
891 return val; 904 return val;
892} 905}
893 906
@@ -1093,6 +1106,8 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
1093 1106
1094 MALLOC_UNBLOCK_INPUT; 1107 MALLOC_UNBLOCK_INPUT;
1095 1108
1109 MALLOC_PROBE (nbytes);
1110
1096 eassert (0 == ((uintptr_t) val) % BLOCK_ALIGN); 1111 eassert (0 == ((uintptr_t) val) % BLOCK_ALIGN);
1097 return val; 1112 return val;
1098} 1113}
@@ -3535,7 +3550,7 @@ mem_init (void)
3535/* Value is a pointer to the mem_node containing START. Value is 3550/* Value is a pointer to the mem_node containing START. Value is
3536 MEM_NIL if there is no node in the tree containing START. */ 3551 MEM_NIL if there is no node in the tree containing START. */
3537 3552
3538static inline struct mem_node * 3553static struct mem_node *
3539mem_find (void *start) 3554mem_find (void *start)
3540{ 3555{
3541 struct mem_node *p; 3556 struct mem_node *p;
@@ -3911,7 +3926,7 @@ mem_delete_fixup (struct mem_node *x)
3911/* Value is non-zero if P is a pointer to a live Lisp string on 3926/* Value is non-zero if P is a pointer to a live Lisp string on
3912 the heap. M is a pointer to the mem_block for P. */ 3927 the heap. M is a pointer to the mem_block for P. */
3913 3928
3914static inline bool 3929static bool
3915live_string_p (struct mem_node *m, void *p) 3930live_string_p (struct mem_node *m, void *p)
3916{ 3931{
3917 if (m->type == MEM_TYPE_STRING) 3932 if (m->type == MEM_TYPE_STRING)
@@ -3934,7 +3949,7 @@ live_string_p (struct mem_node *m, void *p)
3934/* Value is non-zero if P is a pointer to a live Lisp cons on 3949/* Value is non-zero if P is a pointer to a live Lisp cons on
3935 the heap. M is a pointer to the mem_block for P. */ 3950 the heap. M is a pointer to the mem_block for P. */
3936 3951
3937static inline bool 3952static bool
3938live_cons_p (struct mem_node *m, void *p) 3953live_cons_p (struct mem_node *m, void *p)
3939{ 3954{
3940 if (m->type == MEM_TYPE_CONS) 3955 if (m->type == MEM_TYPE_CONS)
@@ -3960,7 +3975,7 @@ live_cons_p (struct mem_node *m, void *p)
3960/* Value is non-zero if P is a pointer to a live Lisp symbol on 3975/* Value is non-zero if P is a pointer to a live Lisp symbol on
3961 the heap. M is a pointer to the mem_block for P. */ 3976 the heap. M is a pointer to the mem_block for P. */
3962 3977
3963static inline bool 3978static bool
3964live_symbol_p (struct mem_node *m, void *p) 3979live_symbol_p (struct mem_node *m, void *p)
3965{ 3980{
3966 if (m->type == MEM_TYPE_SYMBOL) 3981 if (m->type == MEM_TYPE_SYMBOL)
@@ -3986,7 +4001,7 @@ live_symbol_p (struct mem_node *m, void *p)
3986/* Value is non-zero if P is a pointer to a live Lisp float on 4001/* Value is non-zero if P is a pointer to a live Lisp float on
3987 the heap. M is a pointer to the mem_block for P. */ 4002 the heap. M is a pointer to the mem_block for P. */
3988 4003
3989static inline bool 4004static bool
3990live_float_p (struct mem_node *m, void *p) 4005live_float_p (struct mem_node *m, void *p)
3991{ 4006{
3992 if (m->type == MEM_TYPE_FLOAT) 4007 if (m->type == MEM_TYPE_FLOAT)
@@ -4010,7 +4025,7 @@ live_float_p (struct mem_node *m, void *p)
4010/* Value is non-zero if P is a pointer to a live Lisp Misc on 4025/* Value is non-zero if P is a pointer to a live Lisp Misc on
4011 the heap. M is a pointer to the mem_block for P. */ 4026 the heap. M is a pointer to the mem_block for P. */
4012 4027
4013static inline bool 4028static bool
4014live_misc_p (struct mem_node *m, void *p) 4029live_misc_p (struct mem_node *m, void *p)
4015{ 4030{
4016 if (m->type == MEM_TYPE_MISC) 4031 if (m->type == MEM_TYPE_MISC)
@@ -4036,7 +4051,7 @@ live_misc_p (struct mem_node *m, void *p)
4036/* Value is non-zero if P is a pointer to a live vector-like object. 4051/* Value is non-zero if P is a pointer to a live vector-like object.
4037 M is a pointer to the mem_block for P. */ 4052 M is a pointer to the mem_block for P. */
4038 4053
4039static inline bool 4054static bool
4040live_vector_p (struct mem_node *m, void *p) 4055live_vector_p (struct mem_node *m, void *p)
4041{ 4056{
4042 if (m->type == MEM_TYPE_VECTOR_BLOCK) 4057 if (m->type == MEM_TYPE_VECTOR_BLOCK)
@@ -4072,7 +4087,7 @@ live_vector_p (struct mem_node *m, void *p)
4072/* Value is non-zero if P is a pointer to a live buffer. M is a 4087/* Value is non-zero if P is a pointer to a live buffer. M is a
4073 pointer to the mem_block for P. */ 4088 pointer to the mem_block for P. */
4074 4089
4075static inline bool 4090static bool
4076live_buffer_p (struct mem_node *m, void *p) 4091live_buffer_p (struct mem_node *m, void *p)
4077{ 4092{
4078 /* P must point to the start of the block, and the buffer 4093 /* P must point to the start of the block, and the buffer
@@ -4138,7 +4153,7 @@ DEFUN ("gc-status", Fgc_status, Sgc_status, 0, 0, "",
4138 4153
4139/* Mark OBJ if we can prove it's a Lisp_Object. */ 4154/* Mark OBJ if we can prove it's a Lisp_Object. */
4140 4155
4141static inline void 4156static void
4142mark_maybe_object (Lisp_Object obj) 4157mark_maybe_object (Lisp_Object obj)
4143{ 4158{
4144 void *po; 4159 void *po;
@@ -4207,7 +4222,7 @@ mark_maybe_object (Lisp_Object obj)
4207/* If P points to Lisp data, mark that as live if it isn't already 4222/* If P points to Lisp data, mark that as live if it isn't already
4208 marked. */ 4223 marked. */
4209 4224
4210static inline void 4225static void
4211mark_maybe_pointer (void *p) 4226mark_maybe_pointer (void *p)
4212{ 4227{
4213 struct mem_node *m; 4228 struct mem_node *m;
@@ -5037,12 +5052,29 @@ inhibit_garbage_collection (void)
5037/* Used to avoid possible overflows when 5052/* Used to avoid possible overflows when
5038 converting from C to Lisp integers. */ 5053 converting from C to Lisp integers. */
5039 5054
5040static inline Lisp_Object 5055static Lisp_Object
5041bounded_number (EMACS_INT number) 5056bounded_number (EMACS_INT number)
5042{ 5057{
5043 return make_number (min (MOST_POSITIVE_FIXNUM, number)); 5058 return make_number (min (MOST_POSITIVE_FIXNUM, number));
5044} 5059}
5045 5060
5061/* Calculate total bytes of live objects. */
5062
5063static size_t
5064total_bytes_of_live_objects (void)
5065{
5066 size_t tot = 0;
5067 tot += total_conses * sizeof (struct Lisp_Cons);
5068 tot += total_symbols * sizeof (struct Lisp_Symbol);
5069 tot += total_markers * sizeof (union Lisp_Misc);
5070 tot += total_string_bytes;
5071 tot += total_vector_slots * word_size;
5072 tot += total_floats * sizeof (struct Lisp_Float);
5073 tot += total_intervals * sizeof (struct interval);
5074 tot += total_strings * sizeof (struct Lisp_String);
5075 return tot;
5076}
5077
5046DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", 5078DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "",
5047 doc: /* Reclaim storage for Lisp objects no longer needed. 5079 doc: /* Reclaim storage for Lisp objects no longer needed.
5048Garbage collection happens automatically if you cons more than 5080Garbage collection happens automatically if you cons more than
@@ -5068,6 +5100,8 @@ See Info node `(elisp)Garbage Collection'. */)
5068 ptrdiff_t count = SPECPDL_INDEX (); 5100 ptrdiff_t count = SPECPDL_INDEX ();
5069 EMACS_TIME start; 5101 EMACS_TIME start;
5070 Lisp_Object retval = Qnil; 5102 Lisp_Object retval = Qnil;
5103 size_t tot_before = 0;
5104 struct backtrace backtrace;
5071 5105
5072 if (abort_on_gc) 5106 if (abort_on_gc)
5073 emacs_abort (); 5107 emacs_abort ();
@@ -5077,6 +5111,14 @@ See Info node `(elisp)Garbage Collection'. */)
5077 if (pure_bytes_used_before_overflow) 5111 if (pure_bytes_used_before_overflow)
5078 return Qnil; 5112 return Qnil;
5079 5113
5114 /* Record this function, so it appears on the profiler's backtraces. */
5115 backtrace.next = backtrace_list;
5116 backtrace.function = Qautomatic_gc;
5117 backtrace.args = &Qnil;
5118 backtrace.nargs = 0;
5119 backtrace.debug_on_exit = 0;
5120 backtrace_list = &backtrace;
5121
5080 check_cons_list (); 5122 check_cons_list ();
5081 5123
5082 /* Don't keep undo information around forever. 5124 /* Don't keep undo information around forever.
@@ -5084,6 +5126,9 @@ See Info node `(elisp)Garbage Collection'. */)
5084 FOR_EACH_BUFFER (nextb) 5126 FOR_EACH_BUFFER (nextb)
5085 compact_buffer (nextb); 5127 compact_buffer (nextb);
5086 5128
5129 if (profiler_memory_running)
5130 tot_before = total_bytes_of_live_objects ();
5131
5087 start = current_emacs_time (); 5132 start = current_emacs_time ();
5088 5133
5089 /* In case user calls debug_print during GC, 5134 /* In case user calls debug_print during GC,
@@ -5125,7 +5170,7 @@ See Info node `(elisp)Garbage Collection'. */)
5125 if (garbage_collection_messages) 5170 if (garbage_collection_messages)
5126 message1_nolog ("Garbage collecting..."); 5171 message1_nolog ("Garbage collecting...");
5127 5172
5128 BLOCK_INPUT; 5173 block_input ();
5129 5174
5130 shrink_regexp_cache (); 5175 shrink_regexp_cache ();
5131 5176
@@ -5242,7 +5287,7 @@ See Info node `(elisp)Garbage Collection'. */)
5242 dump_zombies (); 5287 dump_zombies ();
5243#endif 5288#endif
5244 5289
5245 UNBLOCK_INPUT; 5290 unblock_input ();
5246 5291
5247 check_cons_list (); 5292 check_cons_list ();
5248 5293
@@ -5255,16 +5300,7 @@ See Info node `(elisp)Garbage Collection'. */)
5255 gc_relative_threshold = 0; 5300 gc_relative_threshold = 0;
5256 if (FLOATP (Vgc_cons_percentage)) 5301 if (FLOATP (Vgc_cons_percentage))
5257 { /* Set gc_cons_combined_threshold. */ 5302 { /* Set gc_cons_combined_threshold. */
5258 double tot = 0; 5303 double tot = total_bytes_of_live_objects ();
5259
5260 tot += total_conses * sizeof (struct Lisp_Cons);
5261 tot += total_symbols * sizeof (struct Lisp_Symbol);
5262 tot += total_markers * sizeof (union Lisp_Misc);
5263 tot += total_string_bytes;
5264 tot += total_vector_slots * word_size;
5265 tot += total_floats * sizeof (struct Lisp_Float);
5266 tot += total_intervals * sizeof (struct interval);
5267 tot += total_strings * sizeof (struct Lisp_String);
5268 5304
5269 tot *= XFLOAT_DATA (Vgc_cons_percentage); 5305 tot *= XFLOAT_DATA (Vgc_cons_percentage);
5270 if (0 < tot) 5306 if (0 < tot)
@@ -5367,6 +5403,17 @@ See Info node `(elisp)Garbage Collection'. */)
5367 5403
5368 gcs_done++; 5404 gcs_done++;
5369 5405
5406 /* Collect profiling data. */
5407 if (profiler_memory_running)
5408 {
5409 size_t swept = 0;
5410 size_t tot_after = total_bytes_of_live_objects ();
5411 if (tot_before > tot_after)
5412 swept = tot_before - tot_after;
5413 malloc_probe (swept);
5414 }
5415
5416 backtrace_list = backtrace.next;
5370 return retval; 5417 return retval;
5371} 5418}
5372 5419
@@ -5521,7 +5568,7 @@ mark_buffer (struct buffer *buffer)
5521} 5568}
5522 5569
5523/* Remove killed buffers or items whose car is a killed buffer from 5570/* Remove killed buffers or items whose car is a killed buffer from
5524 LIST, and mark other items. Return changed LIST, which is marked. */ 5571 LIST, and mark other items. Return changed LIST, which is marked. */
5525 5572
5526static Lisp_Object 5573static Lisp_Object
5527mark_discard_killed_buffers (Lisp_Object list) 5574mark_discard_killed_buffers (Lisp_Object list)
@@ -5543,6 +5590,7 @@ mark_discard_killed_buffers (Lisp_Object list)
5543 prev = &XCDR_AS_LVALUE (tail); 5590 prev = &XCDR_AS_LVALUE (tail);
5544 } 5591 }
5545 } 5592 }
5593 mark_object (tail);
5546 return list; 5594 return list;
5547} 5595}
5548 5596
@@ -5691,18 +5739,8 @@ mark_object (Lisp_Object arg)
5691 struct window *w = (struct window *) ptr; 5739 struct window *w = (struct window *) ptr;
5692 bool leaf = NILP (w->hchild) && NILP (w->vchild); 5740 bool leaf = NILP (w->hchild) && NILP (w->vchild);
5693 5741
5694 /* For live windows, Lisp code filters out killed buffers
5695 from both buffer lists. For dead windows, we do it here
5696 in attempt to help GC to reclaim killed buffers faster. */
5697 if (leaf && NILP (w->buffer))
5698 {
5699 wset_prev_buffers
5700 (w, mark_discard_killed_buffers (w->prev_buffers));
5701 wset_next_buffers
5702 (w, mark_discard_killed_buffers (w->next_buffers));
5703 }
5704
5705 mark_vectorlike (ptr); 5742 mark_vectorlike (ptr);
5743
5706 /* Mark glyphs for leaf windows. Marking window 5744 /* Mark glyphs for leaf windows. Marking window
5707 matrices is sufficient because frame matrices 5745 matrices is sufficient because frame matrices
5708 use the same glyph memory. */ 5746 use the same glyph memory. */
@@ -5711,6 +5749,15 @@ mark_object (Lisp_Object arg)
5711 mark_glyph_matrix (w->current_matrix); 5749 mark_glyph_matrix (w->current_matrix);
5712 mark_glyph_matrix (w->desired_matrix); 5750 mark_glyph_matrix (w->desired_matrix);
5713 } 5751 }
5752
5753 /* Filter out killed buffers from both buffer lists
5754 in attempt to help GC to reclaim killed buffers faster.
5755 We can do it elsewhere for live windows, but this is the
5756 best place to do it for dead windows. */
5757 wset_prev_buffers
5758 (w, mark_discard_killed_buffers (w->prev_buffers));
5759 wset_next_buffers
5760 (w, mark_discard_killed_buffers (w->next_buffers));
5714 } 5761 }
5715 break; 5762 break;
5716 5763
@@ -6395,7 +6442,7 @@ die (const char *msg, const char *file, int line)
6395{ 6442{
6396 fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n", 6443 fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n",
6397 file, line, msg); 6444 file, line, msg);
6398 fatal_error_backtrace (SIGABRT, INT_MAX); 6445 terminate_due_to_signal (SIGABRT, INT_MAX);
6399} 6446}
6400#endif 6447#endif
6401 6448
@@ -6527,6 +6574,7 @@ do hash-consing of the objects allocated to pure space. */);
6527 DEFSYM (Qstring_bytes, "string-bytes"); 6574 DEFSYM (Qstring_bytes, "string-bytes");
6528 DEFSYM (Qvector_slots, "vector-slots"); 6575 DEFSYM (Qvector_slots, "vector-slots");
6529 DEFSYM (Qheap, "heap"); 6576 DEFSYM (Qheap, "heap");
6577 DEFSYM (Qautomatic_gc, "Automatic GC");
6530 6578
6531 DEFSYM (Qgc_cons_threshold, "gc-cons-threshold"); 6579 DEFSYM (Qgc_cons_threshold, "gc-cons-threshold");
6532 DEFSYM (Qchar_table_extra_slots, "char-table-extra-slots"); 6580 DEFSYM (Qchar_table_extra_slots, "char-table-extra-slots");
@@ -6560,7 +6608,8 @@ The time is in seconds as a floating point value. */);
6560/* When compiled with GCC, GDB might say "No enum type named 6608/* When compiled with GCC, GDB might say "No enum type named
6561 pvec_type" if we don't have at least one symbol with that type, and 6609 pvec_type" if we don't have at least one symbol with that type, and
6562 then xbacktrace could fail. Similarly for the other enums and 6610 then xbacktrace could fail. Similarly for the other enums and
6563 their values. */ 6611 their values. Some non-GCC compilers don't like these constructs. */
6612#ifdef __GNUC__
6564union 6613union
6565{ 6614{
6566 enum CHARTAB_SIZE_BITS CHARTAB_SIZE_BITS; 6615 enum CHARTAB_SIZE_BITS CHARTAB_SIZE_BITS;
@@ -6580,3 +6629,4 @@ union
6580 enum lsb_bits lsb_bits; 6629 enum lsb_bits lsb_bits;
6581#endif 6630#endif
6582} const EXTERNALLY_VISIBLE gdb_make_enums_visible = {0}; 6631} const EXTERNALLY_VISIBLE gdb_make_enums_visible = {0};
6632#endif /* __GNUC__ */
diff --git a/src/atimer.c b/src/atimer.c
index 5dbd807872a..5752192be76 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -40,13 +40,12 @@ static struct atimer *stopped_atimers;
40 40
41static struct atimer *atimers; 41static struct atimer *atimers;
42 42
43/* Non-zero means alarm signal handler has found ripe timers but 43/* The alarm timer and whether it was properly initialized, if
44 interrupt_input_blocked was non-zero. In this case, timer 44 POSIX timers are available. */
45 functions are not called until the next UNBLOCK_INPUT because timer 45#ifdef HAVE_ITIMERSPEC
46 functions are expected to call X, and X cannot be assumed to be 46static timer_t alarm_timer;
47 reentrant. */ 47static bool alarm_timer_ok;
48 48#endif
49int pending_atimers;
50 49
51/* Block/unblock SIGALRM. */ 50/* Block/unblock SIGALRM. */
52 51
@@ -295,14 +294,25 @@ set_alarm (void)
295#ifdef HAVE_SETITIMER 294#ifdef HAVE_SETITIMER
296 struct itimerval it; 295 struct itimerval it;
297#endif 296#endif
297 EMACS_TIME now, interval;
298 298
299 /* Determine s/us till the next timer is ripe. */ 299#ifdef HAVE_ITIMERSPEC
300 EMACS_TIME now = current_emacs_time (); 300 if (alarm_timer_ok)
301 {
302 struct itimerspec ispec;
303 ispec.it_value = atimers->expiration;
304 ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0;
305 if (timer_settime (alarm_timer, 0, &ispec, 0) == 0)
306 return;
307 }
308#endif
301 309
302 /* Don't set the interval to 0; this disables the timer. */ 310 /* Determine interval till the next timer is ripe.
303 EMACS_TIME interval = (EMACS_TIME_LE (atimers->expiration, now) 311 Don't set the interval to 0; this disables the timer. */
304 ? make_emacs_time (0, 1000 * 1000) 312 now = current_emacs_time ();
305 : sub_emacs_time (atimers->expiration, now)); 313 interval = (EMACS_TIME_LE (atimers->expiration, now)
314 ? make_emacs_time (0, 1000 * 1000)
315 : sub_emacs_time (atimers->expiration, now));
306 316
307#ifdef HAVE_SETITIMER 317#ifdef HAVE_SETITIMER
308 318
@@ -341,16 +351,11 @@ schedule_atimer (struct atimer *t)
341static void 351static void
342run_timers (void) 352run_timers (void)
343{ 353{
344 EMACS_TIME now; 354 EMACS_TIME now = current_emacs_time ();
345 355
346 while (atimers 356 while (atimers && EMACS_TIME_LE (atimers->expiration, now))
347 && (pending_atimers = interrupt_input_blocked) == 0
348 && (now = current_emacs_time (),
349 EMACS_TIME_LE (atimers->expiration, now)))
350 { 357 {
351 struct atimer *t; 358 struct atimer *t = atimers;
352
353 t = atimers;
354 atimers = atimers->next; 359 atimers = atimers->next;
355 t->fn (t); 360 t->fn (t);
356 361
@@ -366,16 +371,7 @@ run_timers (void)
366 } 371 }
367 } 372 }
368 373
369 if (! atimers) 374 set_alarm ();
370 pending_atimers = 0;
371
372 if (pending_atimers)
373 pending_signals = 1;
374 else
375 {
376 pending_signals = interrupt_input_pending;
377 set_alarm ();
378 }
379} 375}
380 376
381 377
@@ -385,23 +381,16 @@ run_timers (void)
385static void 381static void
386handle_alarm_signal (int sig) 382handle_alarm_signal (int sig)
387{ 383{
388 pending_atimers = 1;
389 pending_signals = 1; 384 pending_signals = 1;
390} 385}
391 386
392static void
393deliver_alarm_signal (int sig)
394{
395 handle_on_main_thread (sig, handle_alarm_signal);
396}
397
398 387
399/* Call alarm signal handler for pending timers. */ 388/* Do pending timers. */
400 389
401void 390void
402do_pending_atimers (void) 391do_pending_atimers (void)
403{ 392{
404 if (pending_atimers) 393 if (atimers)
405 { 394 {
406 block_atimers (); 395 block_atimers ();
407 run_timers (); 396 run_timers ();
@@ -417,12 +406,7 @@ void
417turn_on_atimers (bool on) 406turn_on_atimers (bool on)
418{ 407{
419 if (on) 408 if (on)
420 { 409 set_alarm ();
421 struct sigaction action;
422 emacs_sigaction_init (&action, deliver_alarm_signal);
423 sigaction (SIGALRM, &action, 0);
424 set_alarm ();
425 }
426 else 410 else
427 alarm (0); 411 alarm (0);
428} 412}
@@ -432,9 +416,15 @@ void
432init_atimer (void) 416init_atimer (void)
433{ 417{
434 struct sigaction action; 418 struct sigaction action;
419#ifdef HAVE_ITIMERSPEC
420 struct sigevent sigev;
421 sigev.sigev_notify = SIGEV_SIGNAL;
422 sigev.sigev_signo = SIGALRM;
423 sigev.sigev_value.sival_ptr = &alarm_timer;
424 alarm_timer_ok = timer_create (CLOCK_REALTIME, &sigev, &alarm_timer) == 0;
425#endif
435 free_atimers = stopped_atimers = atimers = NULL; 426 free_atimers = stopped_atimers = atimers = NULL;
436 pending_atimers = 0;
437 /* pending_signals is initialized in init_keyboard.*/ 427 /* pending_signals is initialized in init_keyboard.*/
438 emacs_sigaction_init (&action, deliver_alarm_signal); 428 emacs_sigaction_init (&action, handle_alarm_signal);
439 sigaction (SIGALRM, &action, 0); 429 sigaction (SIGALRM, &action, 0);
440} 430}
diff --git a/src/bidi.c b/src/bidi.c
index af0209565e2..6f3d749ef22 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -96,7 +96,7 @@ static Lisp_Object Qparagraph_start, Qparagraph_separate;
96 96
97/* Return the bidi type of a character CH, subject to the current 97/* Return the bidi type of a character CH, subject to the current
98 directional OVERRIDE. */ 98 directional OVERRIDE. */
99static inline bidi_type_t 99static bidi_type_t
100bidi_get_type (int ch, bidi_dir_t override) 100bidi_get_type (int ch, bidi_dir_t override)
101{ 101{
102 bidi_type_t default_type; 102 bidi_type_t default_type;
@@ -145,14 +145,14 @@ bidi_get_type (int ch, bidi_dir_t override)
145 } 145 }
146} 146}
147 147
148static inline void 148static void
149bidi_check_type (bidi_type_t type) 149bidi_check_type (bidi_type_t type)
150{ 150{
151 eassert (UNKNOWN_BT <= type && type <= NEUTRAL_ON); 151 eassert (UNKNOWN_BT <= type && type <= NEUTRAL_ON);
152} 152}
153 153
154/* Given a bidi TYPE of a character, return its category. */ 154/* Given a bidi TYPE of a character, return its category. */
155static inline bidi_category_t 155static bidi_category_t
156bidi_get_category (bidi_type_t type) 156bidi_get_category (bidi_type_t type)
157{ 157{
158 switch (type) 158 switch (type)
@@ -226,7 +226,7 @@ bidi_mirror_char (int c)
226 embedding levels on either side of the run boundary. Also, update 226 embedding levels on either side of the run boundary. Also, update
227 the saved info about previously seen characters, since that info is 227 the saved info about previously seen characters, since that info is
228 generally valid for a single level run. */ 228 generally valid for a single level run. */
229static inline void 229static void
230bidi_set_sor_type (struct bidi_it *bidi_it, int level_before, int level_after) 230bidi_set_sor_type (struct bidi_it *bidi_it, int level_before, int level_after)
231{ 231{
232 int higher_level = (level_before > level_after ? level_before : level_after); 232 int higher_level = (level_before > level_after ? level_before : level_after);
@@ -257,7 +257,7 @@ bidi_set_sor_type (struct bidi_it *bidi_it, int level_before, int level_after)
257 257
258/* Push the current embedding level and override status; reset the 258/* Push the current embedding level and override status; reset the
259 current level to LEVEL and the current override status to OVERRIDE. */ 259 current level to LEVEL and the current override status to OVERRIDE. */
260static inline void 260static void
261bidi_push_embedding_level (struct bidi_it *bidi_it, 261bidi_push_embedding_level (struct bidi_it *bidi_it,
262 int level, bidi_dir_t override) 262 int level, bidi_dir_t override)
263{ 263{
@@ -269,7 +269,7 @@ bidi_push_embedding_level (struct bidi_it *bidi_it,
269 269
270/* Pop the embedding level and directional override status from the 270/* Pop the embedding level and directional override status from the
271 stack, and return the new level. */ 271 stack, and return the new level. */
272static inline int 272static int
273bidi_pop_embedding_level (struct bidi_it *bidi_it) 273bidi_pop_embedding_level (struct bidi_it *bidi_it)
274{ 274{
275 /* UAX#9 says to ignore invalid PDFs. */ 275 /* UAX#9 says to ignore invalid PDFs. */
@@ -279,7 +279,7 @@ bidi_pop_embedding_level (struct bidi_it *bidi_it)
279} 279}
280 280
281/* Record in SAVED_INFO the information about the current character. */ 281/* Record in SAVED_INFO the information about the current character. */
282static inline void 282static void
283bidi_remember_char (struct bidi_saved_info *saved_info, 283bidi_remember_char (struct bidi_saved_info *saved_info,
284 struct bidi_it *bidi_it) 284 struct bidi_it *bidi_it)
285{ 285{
@@ -295,18 +295,14 @@ bidi_remember_char (struct bidi_saved_info *saved_info,
295 295
296/* Copy the bidi iterator from FROM to TO. To save cycles, this only 296/* Copy the bidi iterator from FROM to TO. To save cycles, this only
297 copies the part of the level stack that is actually in use. */ 297 copies the part of the level stack that is actually in use. */
298static inline void 298static void
299bidi_copy_it (struct bidi_it *to, struct bidi_it *from) 299bidi_copy_it (struct bidi_it *to, struct bidi_it *from)
300{ 300{
301 int i; 301 /* Copy everything from the start through the active part of
302 302 the level stack. */
303 /* Copy everything except the level stack and beyond. */ 303 memcpy (to, from,
304 memcpy (to, from, offsetof (struct bidi_it, level_stack[0])); 304 (offsetof (struct bidi_it, level_stack[1])
305 305 + from->stack_idx * sizeof from->level_stack[0]));
306 /* Copy the active part of the level stack. */
307 to->level_stack[0] = from->level_stack[0]; /* level zero is always in use */
308 for (i = 1; i <= from->stack_idx; i++)
309 to->level_stack[i] = from->level_stack[i];
310} 306}
311 307
312 308
@@ -344,7 +340,7 @@ enum
344 intact. This is called when the cached information is no more 340 intact. This is called when the cached information is no more
345 useful for the current iteration, e.g. when we were reseated to a 341 useful for the current iteration, e.g. when we were reseated to a
346 new position on the same object. */ 342 new position on the same object. */
347static inline void 343static void
348bidi_cache_reset (void) 344bidi_cache_reset (void)
349{ 345{
350 bidi_cache_idx = bidi_cache_start; 346 bidi_cache_idx = bidi_cache_start;
@@ -355,7 +351,7 @@ bidi_cache_reset (void)
355 iterator for reordering a buffer or a string that does not come 351 iterator for reordering a buffer or a string that does not come
356 from display properties, because that means all the previously 352 from display properties, because that means all the previously
357 cached info is of no further use. */ 353 cached info is of no further use. */
358static inline void 354static void
359bidi_cache_shrink (void) 355bidi_cache_shrink (void)
360{ 356{
361 if (bidi_cache_size > BIDI_CACHE_CHUNK) 357 if (bidi_cache_size > BIDI_CACHE_CHUNK)
@@ -366,7 +362,7 @@ bidi_cache_shrink (void)
366 bidi_cache_reset (); 362 bidi_cache_reset ();
367} 363}
368 364
369static inline void 365static void
370bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) 366bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it)
371{ 367{
372 int current_scan_dir = bidi_it->scan_dir; 368 int current_scan_dir = bidi_it->scan_dir;
@@ -383,7 +379,7 @@ bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it)
383 level less or equal to LEVEL. if LEVEL is -1, disregard the 379 level less or equal to LEVEL. if LEVEL is -1, disregard the
384 resolved levels in cached states. DIR, if non-zero, means search 380 resolved levels in cached states. DIR, if non-zero, means search
385 in that direction from the last cache hit. */ 381 in that direction from the last cache hit. */
386static inline ptrdiff_t 382static ptrdiff_t
387bidi_cache_search (ptrdiff_t charpos, int level, int dir) 383bidi_cache_search (ptrdiff_t charpos, int level, int dir)
388{ 384{
389 ptrdiff_t i, i_start; 385 ptrdiff_t i, i_start;
@@ -488,7 +484,7 @@ bidi_cache_find_level_change (int level, int dir, bool before)
488 return -1; 484 return -1;
489} 485}
490 486
491static inline void 487static void
492bidi_cache_ensure_space (ptrdiff_t idx) 488bidi_cache_ensure_space (ptrdiff_t idx)
493{ 489{
494 /* Enlarge the cache as needed. */ 490 /* Enlarge the cache as needed. */
@@ -510,7 +506,7 @@ bidi_cache_ensure_space (ptrdiff_t idx)
510 } 506 }
511} 507}
512 508
513static inline void 509static void
514bidi_cache_iterator_state (struct bidi_it *bidi_it, bool resolved) 510bidi_cache_iterator_state (struct bidi_it *bidi_it, bool resolved)
515{ 511{
516 ptrdiff_t idx; 512 ptrdiff_t idx;
@@ -567,7 +563,7 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, bool resolved)
567 bidi_cache_idx = idx + 1; 563 bidi_cache_idx = idx + 1;
568} 564}
569 565
570static inline bidi_type_t 566static bidi_type_t
571bidi_cache_find (ptrdiff_t charpos, int level, struct bidi_it *bidi_it) 567bidi_cache_find (ptrdiff_t charpos, int level, struct bidi_it *bidi_it)
572{ 568{
573 ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir); 569 ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir);
@@ -587,7 +583,7 @@ bidi_cache_find (ptrdiff_t charpos, int level, struct bidi_it *bidi_it)
587 return UNKNOWN_BT; 583 return UNKNOWN_BT;
588} 584}
589 585
590static inline int 586static int
591bidi_peek_at_next_level (struct bidi_it *bidi_it) 587bidi_peek_at_next_level (struct bidi_it *bidi_it)
592{ 588{
593 if (bidi_cache_idx == bidi_cache_start || bidi_cache_last_idx == -1) 589 if (bidi_cache_idx == bidi_cache_start || bidi_cache_last_idx == -1)
@@ -790,7 +786,7 @@ bidi_initialize (void)
790 786
791/* Do whatever UAX#9 clause X8 says should be done at paragraph's 787/* Do whatever UAX#9 clause X8 says should be done at paragraph's
792 end. */ 788 end. */
793static inline void 789static void
794bidi_set_paragraph_end (struct bidi_it *bidi_it) 790bidi_set_paragraph_end (struct bidi_it *bidi_it)
795{ 791{
796 bidi_it->invalid_levels = 0; 792 bidi_it->invalid_levels = 0;
@@ -872,7 +868,7 @@ bidi_line_init (struct bidi_it *bidi_it)
872/* Count bytes in string S between BEG/BEGBYTE and END. BEG and END 868/* Count bytes in string S between BEG/BEGBYTE and END. BEG and END
873 are zero-based character positions in S, BEGBYTE is byte position 869 are zero-based character positions in S, BEGBYTE is byte position
874 corresponding to BEG. UNIBYTE means S is a unibyte string. */ 870 corresponding to BEG. UNIBYTE means S is a unibyte string. */
875static inline ptrdiff_t 871static ptrdiff_t
876bidi_count_bytes (const unsigned char *s, const ptrdiff_t beg, 872bidi_count_bytes (const unsigned char *s, const ptrdiff_t beg,
877 const ptrdiff_t begbyte, const ptrdiff_t end, bool unibyte) 873 const ptrdiff_t begbyte, const ptrdiff_t end, bool unibyte)
878{ 874{
@@ -896,22 +892,22 @@ bidi_count_bytes (const unsigned char *s, const ptrdiff_t beg,
896 return p - start; 892 return p - start;
897} 893}
898 894
899/* Fetch and returns the character at byte position BYTEPOS. If S is 895/* Fetch and return the character at byte position BYTEPOS. If S is
900 non-NULL, fetch the character from string S; otherwise fetch the 896 non-NULL, fetch the character from string S; otherwise fetch the
901 character from the current buffer. UNIBYTE means S is a 897 character from the current buffer. UNIBYTE means S is a
902 unibyte string. */ 898 unibyte string. */
903static inline int 899static int
904bidi_char_at_pos (ptrdiff_t bytepos, const unsigned char *s, bool unibyte) 900bidi_char_at_pos (ptrdiff_t bytepos, const unsigned char *s, bool unibyte)
905{ 901{
906 if (s) 902 if (s)
907 { 903 {
904 s += bytepos;
908 if (unibyte) 905 if (unibyte)
909 return s[bytepos]; 906 return *s;
910 else
911 return STRING_CHAR (s + bytepos);
912 } 907 }
913 else 908 else
914 return FETCH_MULTIBYTE_CHAR (bytepos); 909 s = BYTE_POS_ADDR (bytepos);
910 return STRING_CHAR (s);
915} 911}
916 912
917/* Fetch and return the character at BYTEPOS/CHARPOS. If that 913/* Fetch and return the character at BYTEPOS/CHARPOS. If that
@@ -928,7 +924,7 @@ bidi_char_at_pos (ptrdiff_t bytepos, const unsigned char *s, bool unibyte)
928 u+2029 to handle it as a paragraph separator. STRING->s is the C 924 u+2029 to handle it as a paragraph separator. STRING->s is the C
929 string to iterate, or NULL if iterating over a buffer or a Lisp 925 string to iterate, or NULL if iterating over a buffer or a Lisp
930 string; in the latter case, STRING->lstring is the Lisp string. */ 926 string; in the latter case, STRING->lstring is the Lisp string. */
931static inline int 927static int
932bidi_fetch_char (ptrdiff_t bytepos, ptrdiff_t charpos, ptrdiff_t *disp_pos, 928bidi_fetch_char (ptrdiff_t bytepos, ptrdiff_t charpos, ptrdiff_t *disp_pos,
933 int *disp_prop, struct bidi_string_data *string, 929 int *disp_prop, struct bidi_string_data *string,
934 bool frame_window_p, ptrdiff_t *ch_len, ptrdiff_t *nchars) 930 bool frame_window_p, ptrdiff_t *ch_len, ptrdiff_t *nchars)
@@ -1318,7 +1314,7 @@ bidi_paragraph_init (bidi_dir_t dir, struct bidi_it *bidi_it, bool no_default_p)
1318 The rest of this file constitutes the core of the UBA implementation. 1314 The rest of this file constitutes the core of the UBA implementation.
1319 ***********************************************************************/ 1315 ***********************************************************************/
1320 1316
1321static inline bool 1317static bool
1322bidi_explicit_dir_char (int ch) 1318bidi_explicit_dir_char (int ch)
1323{ 1319{
1324 bidi_type_t ch_type; 1320 bidi_type_t ch_type;
@@ -1841,7 +1837,7 @@ bidi_resolve_weak (struct bidi_it *bidi_it)
1841 1837
1842/* Resolve the type of a neutral character according to the type of 1838/* Resolve the type of a neutral character according to the type of
1843 surrounding strong text and the current embedding level. */ 1839 surrounding strong text and the current embedding level. */
1844static inline bidi_type_t 1840static bidi_type_t
1845bidi_resolve_neutral_1 (bidi_type_t prev_type, bidi_type_t next_type, int lev) 1841bidi_resolve_neutral_1 (bidi_type_t prev_type, bidi_type_t next_type, int lev)
1846{ 1842{
1847 /* N1: European and Arabic numbers are treated as though they were R. */ 1843 /* N1: European and Arabic numbers are treated as though they were R. */
diff --git a/src/blockinput.h b/src/blockinput.h
index 7501bfc91a0..70822e29be7 100644
--- a/src/blockinput.h
+++ b/src/blockinput.h
@@ -19,103 +19,57 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19#ifndef EMACS_BLOCKINPUT_H 19#ifndef EMACS_BLOCKINPUT_H
20#define EMACS_BLOCKINPUT_H 20#define EMACS_BLOCKINPUT_H
21 21
22#include "atimer.h" 22INLINE_HEADER_BEGIN
23#ifndef BLOCKINPUT_INLINE
24# define BLOCKINPUT_INLINE INLINE
25#endif
23 26
24/* When Emacs is using signal-driven input, the processing of those 27/* Emacs should avoid doing anything hairy in a signal handler, because
25 input signals can get pretty hairy. For example, when Emacs is 28 so many system functions are non-reentrant. For example, malloc
26 running under X windows, handling an input signal can entail 29 and the Xlib functions aren't usually re-entrant, so if they were
27 retrieving events from the X event queue, or making other X calls. 30 used by the SIGIO handler, we'd lose.
28
29 If an input signal occurs while Emacs is in the midst of some
30 non-reentrant code, and the signal processing invokes that same
31 code, we lose. For example, malloc and the Xlib functions aren't
32 usually re-entrant, and both are used by the X input signal handler
33 - if we try to process an input signal in the midst of executing
34 any of these functions, we'll lose.
35 31
36 To avoid this, we make the following requirements: 32 To avoid this, we make the following requirements:
37 33
38 * Everyone must evaluate BLOCK_INPUT before entering these functions, 34 * Everyone must evaluate BLOCK_INPUT before performing actions that
39 and then call UNBLOCK_INPUT after performing them. Calls 35 might conflict with a signal handler, and then call UNBLOCK_INPUT
40 BLOCK_INPUT and UNBLOCK_INPUT may be nested. 36 after performing them. Calls BLOCK_INPUT and UNBLOCK_INPUT may be
37 nested.
41 38
42 * Any complicated interrupt handling code should test 39 * Any complicated interrupt handling code should test
43 interrupt_input_blocked, and put off its work until later. 40 INPUT_BLOCKED_P, and put off its work until later.
44 41
45 * If the interrupt handling code wishes, it may set 42 * If the interrupt handling code wishes, it may set
46 interrupt_input_pending to a non-zero value. If that flag is set 43 pending_signals to a non-zero value. If that flag is set
47 when input becomes unblocked, UNBLOCK_INPUT will send a new SIGIO. */ 44 when input becomes unblocked, UNBLOCK_INPUT will then read
48 45 input and process timers.
49extern volatile int interrupt_input_blocked;
50
51/* Nonzero means an input interrupt has arrived
52 during the current critical section. */
53extern int interrupt_input_pending;
54 46
47 Historically, Emacs signal handlers did much more than they do now,
48 and this caused many BLOCK_INPUT calls to be sprinkled around the code.
49 FIXME: Remove calls that aren't needed now. */
55 50
56/* Non-zero means asynchronous timers should be run when input is 51extern volatile int interrupt_input_blocked;
57 unblocked. */
58 52
59extern int pending_atimers; 53/* Begin critical section. */
60 54
55BLOCKINPUT_INLINE void
56block_input (void)
57{
58 interrupt_input_blocked++;
59}
61 60
62/* Begin critical section. */ 61extern void unblock_input (void);
63#define BLOCK_INPUT (interrupt_input_blocked++) 62extern void totally_unblock_input (void);
64 63extern void unblock_input_to (int);
65/* End critical section.
66
67 If doing signal-driven input, and a signal came in when input was
68 blocked, reinvoke the signal handler now to deal with it.
69
70 Always test interrupt_input_pending; that's not too expensive, and
71 it'll never get set if we don't need to resignal. This is simpler
72 than dealing here with every configuration option that might affect
73 whether interrupt_input_pending can be nonzero. */
74
75#define UNBLOCK_INPUT \
76 do \
77 { \
78 --interrupt_input_blocked; \
79 if (interrupt_input_blocked == 0) \
80 { \
81 if (interrupt_input_pending) \
82 reinvoke_input_signal (); \
83 if (pending_atimers) \
84 do_pending_atimers (); \
85 } \
86 else if (interrupt_input_blocked < 0) \
87 emacs_abort (); \
88 } \
89 while (0)
90
91/* Undo any number of BLOCK_INPUT calls,
92 and also reinvoke any pending signal. */
93
94#define TOTALLY_UNBLOCK_INPUT \
95 do if (interrupt_input_blocked != 0) \
96 { \
97 interrupt_input_blocked = 1; \
98 UNBLOCK_INPUT; \
99 } \
100 while (0)
101
102/* Undo any number of BLOCK_INPUT calls down to level LEVEL,
103 and also (if the level is now 0) reinvoke any pending signal. */
104
105#define UNBLOCK_INPUT_TO(LEVEL) \
106 do \
107 { \
108 interrupt_input_blocked = (LEVEL) + 1; \
109 UNBLOCK_INPUT; \
110 } \
111 while (0)
112
113#define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
114 64
115/* In critical section ? */ 65/* In critical section ? */
116#define INPUT_BLOCKED_P (interrupt_input_blocked > 0)
117 66
118/* Defined in keyboard.c */ 67BLOCKINPUT_INLINE bool
119extern void reinvoke_input_signal (void); 68input_blocked_p (void)
69{
70 return 0 < interrupt_input_blocked;
71}
72
73INLINE_HEADER_END
120 74
121#endif /* EMACS_BLOCKINPUT_H */ 75#endif /* EMACS_BLOCKINPUT_H */
diff --git a/src/buffer.c b/src/buffer.c
index b020edb9962..425d05ca790 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -150,222 +150,222 @@ static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t);
150static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool); 150static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool);
151 151
152/* These setters are used only in this file, so they can be private. */ 152/* These setters are used only in this file, so they can be private. */
153static inline void 153static void
154bset_abbrev_mode (struct buffer *b, Lisp_Object val) 154bset_abbrev_mode (struct buffer *b, Lisp_Object val)
155{ 155{
156 b->INTERNAL_FIELD (abbrev_mode) = val; 156 b->INTERNAL_FIELD (abbrev_mode) = val;
157} 157}
158static inline void 158static void
159bset_abbrev_table (struct buffer *b, Lisp_Object val) 159bset_abbrev_table (struct buffer *b, Lisp_Object val)
160{ 160{
161 b->INTERNAL_FIELD (abbrev_table) = val; 161 b->INTERNAL_FIELD (abbrev_table) = val;
162} 162}
163static inline void 163static void
164bset_auto_fill_function (struct buffer *b, Lisp_Object val) 164bset_auto_fill_function (struct buffer *b, Lisp_Object val)
165{ 165{
166 b->INTERNAL_FIELD (auto_fill_function) = val; 166 b->INTERNAL_FIELD (auto_fill_function) = val;
167} 167}
168static inline void 168static void
169bset_auto_save_file_format (struct buffer *b, Lisp_Object val) 169bset_auto_save_file_format (struct buffer *b, Lisp_Object val)
170{ 170{
171 b->INTERNAL_FIELD (auto_save_file_format) = val; 171 b->INTERNAL_FIELD (auto_save_file_format) = val;
172} 172}
173static inline void 173static void
174bset_auto_save_file_name (struct buffer *b, Lisp_Object val) 174bset_auto_save_file_name (struct buffer *b, Lisp_Object val)
175{ 175{
176 b->INTERNAL_FIELD (auto_save_file_name) = val; 176 b->INTERNAL_FIELD (auto_save_file_name) = val;
177} 177}
178static inline void 178static void
179bset_backed_up (struct buffer *b, Lisp_Object val) 179bset_backed_up (struct buffer *b, Lisp_Object val)
180{ 180{
181 b->INTERNAL_FIELD (backed_up) = val; 181 b->INTERNAL_FIELD (backed_up) = val;
182} 182}
183static inline void 183static void
184bset_begv_marker (struct buffer *b, Lisp_Object val) 184bset_begv_marker (struct buffer *b, Lisp_Object val)
185{ 185{
186 b->INTERNAL_FIELD (begv_marker) = val; 186 b->INTERNAL_FIELD (begv_marker) = val;
187} 187}
188static inline void 188static void
189bset_bidi_display_reordering (struct buffer *b, Lisp_Object val) 189bset_bidi_display_reordering (struct buffer *b, Lisp_Object val)
190{ 190{
191 b->INTERNAL_FIELD (bidi_display_reordering) = val; 191 b->INTERNAL_FIELD (bidi_display_reordering) = val;
192} 192}
193static inline void 193static void
194bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val) 194bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
195{ 195{
196 b->INTERNAL_FIELD (buffer_file_coding_system) = val; 196 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
197} 197}
198static inline void 198static void
199bset_cache_long_line_scans (struct buffer *b, Lisp_Object val) 199bset_cache_long_line_scans (struct buffer *b, Lisp_Object val)
200{ 200{
201 b->INTERNAL_FIELD (cache_long_line_scans) = val; 201 b->INTERNAL_FIELD (cache_long_line_scans) = val;
202} 202}
203static inline void 203static void
204bset_case_fold_search (struct buffer *b, Lisp_Object val) 204bset_case_fold_search (struct buffer *b, Lisp_Object val)
205{ 205{
206 b->INTERNAL_FIELD (case_fold_search) = val; 206 b->INTERNAL_FIELD (case_fold_search) = val;
207} 207}
208static inline void 208static void
209bset_ctl_arrow (struct buffer *b, Lisp_Object val) 209bset_ctl_arrow (struct buffer *b, Lisp_Object val)
210{ 210{
211 b->INTERNAL_FIELD (ctl_arrow) = val; 211 b->INTERNAL_FIELD (ctl_arrow) = val;
212} 212}
213static inline void 213static void
214bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val) 214bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val)
215{ 215{
216 b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val; 216 b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val;
217} 217}
218static inline void 218static void
219bset_cursor_type (struct buffer *b, Lisp_Object val) 219bset_cursor_type (struct buffer *b, Lisp_Object val)
220{ 220{
221 b->INTERNAL_FIELD (cursor_type) = val; 221 b->INTERNAL_FIELD (cursor_type) = val;
222} 222}
223static inline void 223static void
224bset_display_table (struct buffer *b, Lisp_Object val) 224bset_display_table (struct buffer *b, Lisp_Object val)
225{ 225{
226 b->INTERNAL_FIELD (display_table) = val; 226 b->INTERNAL_FIELD (display_table) = val;
227} 227}
228static inline void 228static void
229bset_extra_line_spacing (struct buffer *b, Lisp_Object val) 229bset_extra_line_spacing (struct buffer *b, Lisp_Object val)
230{ 230{
231 b->INTERNAL_FIELD (extra_line_spacing) = val; 231 b->INTERNAL_FIELD (extra_line_spacing) = val;
232} 232}
233static inline void 233static void
234bset_file_format (struct buffer *b, Lisp_Object val) 234bset_file_format (struct buffer *b, Lisp_Object val)
235{ 235{
236 b->INTERNAL_FIELD (file_format) = val; 236 b->INTERNAL_FIELD (file_format) = val;
237} 237}
238static inline void 238static void
239bset_file_truename (struct buffer *b, Lisp_Object val) 239bset_file_truename (struct buffer *b, Lisp_Object val)
240{ 240{
241 b->INTERNAL_FIELD (file_truename) = val; 241 b->INTERNAL_FIELD (file_truename) = val;
242} 242}
243static inline void 243static void
244bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val) 244bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val)
245{ 245{
246 b->INTERNAL_FIELD (fringe_cursor_alist) = val; 246 b->INTERNAL_FIELD (fringe_cursor_alist) = val;
247} 247}
248static inline void 248static void
249bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val) 249bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val)
250{ 250{
251 b->INTERNAL_FIELD (fringe_indicator_alist) = val; 251 b->INTERNAL_FIELD (fringe_indicator_alist) = val;
252} 252}
253static inline void 253static void
254bset_fringes_outside_margins (struct buffer *b, Lisp_Object val) 254bset_fringes_outside_margins (struct buffer *b, Lisp_Object val)
255{ 255{
256 b->INTERNAL_FIELD (fringes_outside_margins) = val; 256 b->INTERNAL_FIELD (fringes_outside_margins) = val;
257} 257}
258static inline void 258static void
259bset_header_line_format (struct buffer *b, Lisp_Object val) 259bset_header_line_format (struct buffer *b, Lisp_Object val)
260{ 260{
261 b->INTERNAL_FIELD (header_line_format) = val; 261 b->INTERNAL_FIELD (header_line_format) = val;
262} 262}
263static inline void 263static void
264bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val) 264bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val)
265{ 265{
266 b->INTERNAL_FIELD (indicate_buffer_boundaries) = val; 266 b->INTERNAL_FIELD (indicate_buffer_boundaries) = val;
267} 267}
268static inline void 268static void
269bset_indicate_empty_lines (struct buffer *b, Lisp_Object val) 269bset_indicate_empty_lines (struct buffer *b, Lisp_Object val)
270{ 270{
271 b->INTERNAL_FIELD (indicate_empty_lines) = val; 271 b->INTERNAL_FIELD (indicate_empty_lines) = val;
272} 272}
273static inline void 273static void
274bset_invisibility_spec (struct buffer *b, Lisp_Object val) 274bset_invisibility_spec (struct buffer *b, Lisp_Object val)
275{ 275{
276 b->INTERNAL_FIELD (invisibility_spec) = val; 276 b->INTERNAL_FIELD (invisibility_spec) = val;
277} 277}
278static inline void 278static void
279bset_left_fringe_width (struct buffer *b, Lisp_Object val) 279bset_left_fringe_width (struct buffer *b, Lisp_Object val)
280{ 280{
281 b->INTERNAL_FIELD (left_fringe_width) = val; 281 b->INTERNAL_FIELD (left_fringe_width) = val;
282} 282}
283static inline void 283static void
284bset_major_mode (struct buffer *b, Lisp_Object val) 284bset_major_mode (struct buffer *b, Lisp_Object val)
285{ 285{
286 b->INTERNAL_FIELD (major_mode) = val; 286 b->INTERNAL_FIELD (major_mode) = val;
287} 287}
288static inline void 288static void
289bset_mark (struct buffer *b, Lisp_Object val) 289bset_mark (struct buffer *b, Lisp_Object val)
290{ 290{
291 b->INTERNAL_FIELD (mark) = val; 291 b->INTERNAL_FIELD (mark) = val;
292} 292}
293static inline void 293static void
294bset_minor_modes (struct buffer *b, Lisp_Object val) 294bset_minor_modes (struct buffer *b, Lisp_Object val)
295{ 295{
296 b->INTERNAL_FIELD (minor_modes) = val; 296 b->INTERNAL_FIELD (minor_modes) = val;
297} 297}
298static inline void 298static void
299bset_mode_line_format (struct buffer *b, Lisp_Object val) 299bset_mode_line_format (struct buffer *b, Lisp_Object val)
300{ 300{
301 b->INTERNAL_FIELD (mode_line_format) = val; 301 b->INTERNAL_FIELD (mode_line_format) = val;
302} 302}
303static inline void 303static void
304bset_mode_name (struct buffer *b, Lisp_Object val) 304bset_mode_name (struct buffer *b, Lisp_Object val)
305{ 305{
306 b->INTERNAL_FIELD (mode_name) = val; 306 b->INTERNAL_FIELD (mode_name) = val;
307} 307}
308static inline void 308static void
309bset_name (struct buffer *b, Lisp_Object val) 309bset_name (struct buffer *b, Lisp_Object val)
310{ 310{
311 b->INTERNAL_FIELD (name) = val; 311 b->INTERNAL_FIELD (name) = val;
312} 312}
313static inline void 313static void
314bset_overwrite_mode (struct buffer *b, Lisp_Object val) 314bset_overwrite_mode (struct buffer *b, Lisp_Object val)
315{ 315{
316 b->INTERNAL_FIELD (overwrite_mode) = val; 316 b->INTERNAL_FIELD (overwrite_mode) = val;
317} 317}
318static inline void 318static void
319bset_pt_marker (struct buffer *b, Lisp_Object val) 319bset_pt_marker (struct buffer *b, Lisp_Object val)
320{ 320{
321 b->INTERNAL_FIELD (pt_marker) = val; 321 b->INTERNAL_FIELD (pt_marker) = val;
322} 322}
323static inline void 323static void
324bset_right_fringe_width (struct buffer *b, Lisp_Object val) 324bset_right_fringe_width (struct buffer *b, Lisp_Object val)
325{ 325{
326 b->INTERNAL_FIELD (right_fringe_width) = val; 326 b->INTERNAL_FIELD (right_fringe_width) = val;
327} 327}
328static inline void 328static void
329bset_save_length (struct buffer *b, Lisp_Object val) 329bset_save_length (struct buffer *b, Lisp_Object val)
330{ 330{
331 b->INTERNAL_FIELD (save_length) = val; 331 b->INTERNAL_FIELD (save_length) = val;
332} 332}
333static inline void 333static void
334bset_scroll_bar_width (struct buffer *b, Lisp_Object val) 334bset_scroll_bar_width (struct buffer *b, Lisp_Object val)
335{ 335{
336 b->INTERNAL_FIELD (scroll_bar_width) = val; 336 b->INTERNAL_FIELD (scroll_bar_width) = val;
337} 337}
338static inline void 338static void
339bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val) 339bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val)
340{ 340{
341 b->INTERNAL_FIELD (scroll_down_aggressively) = val; 341 b->INTERNAL_FIELD (scroll_down_aggressively) = val;
342} 342}
343static inline void 343static void
344bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val) 344bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val)
345{ 345{
346 b->INTERNAL_FIELD (scroll_up_aggressively) = val; 346 b->INTERNAL_FIELD (scroll_up_aggressively) = val;
347} 347}
348static inline void 348static void
349bset_selective_display (struct buffer *b, Lisp_Object val) 349bset_selective_display (struct buffer *b, Lisp_Object val)
350{ 350{
351 b->INTERNAL_FIELD (selective_display) = val; 351 b->INTERNAL_FIELD (selective_display) = val;
352} 352}
353static inline void 353static void
354bset_selective_display_ellipses (struct buffer *b, Lisp_Object val) 354bset_selective_display_ellipses (struct buffer *b, Lisp_Object val)
355{ 355{
356 b->INTERNAL_FIELD (selective_display_ellipses) = val; 356 b->INTERNAL_FIELD (selective_display_ellipses) = val;
357} 357}
358static inline void 358static void
359bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val) 359bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val)
360{ 360{
361 b->INTERNAL_FIELD (vertical_scroll_bar_type) = val; 361 b->INTERNAL_FIELD (vertical_scroll_bar_type) = val;
362} 362}
363static inline void 363static void
364bset_word_wrap (struct buffer *b, Lisp_Object val) 364bset_word_wrap (struct buffer *b, Lisp_Object val)
365{ 365{
366 b->INTERNAL_FIELD (word_wrap) = val; 366 b->INTERNAL_FIELD (word_wrap) = val;
367} 367}
368static inline void 368static void
369bset_zv_marker (struct buffer *b, Lisp_Object val) 369bset_zv_marker (struct buffer *b, Lisp_Object val)
370{ 370{
371 b->INTERNAL_FIELD (zv_marker) = val; 371 b->INTERNAL_FIELD (zv_marker) = val;
@@ -550,11 +550,11 @@ even if it is dead. The return value is never nil. */)
550 b->indirections = 0; 550 b->indirections = 0;
551 551
552 BUF_GAP_SIZE (b) = 20; 552 BUF_GAP_SIZE (b) = 20;
553 BLOCK_INPUT; 553 block_input ();
554 /* We allocate extra 1-byte at the tail and keep it always '\0' for 554 /* We allocate extra 1-byte at the tail and keep it always '\0' for
555 anchoring a search. */ 555 anchoring a search. */
556 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); 556 alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1);
557 UNBLOCK_INPUT; 557 unblock_input ();
558 if (! BUF_BEG_ADDR (b)) 558 if (! BUF_BEG_ADDR (b))
559 buffer_memory_full (BUF_GAP_SIZE (b) + 1); 559 buffer_memory_full (BUF_GAP_SIZE (b) + 1);
560 560
@@ -651,13 +651,13 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
651 651
652/* Set an appropriate overlay of B. */ 652/* Set an appropriate overlay of B. */
653 653
654static inline void 654static void
655set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o) 655set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o)
656{ 656{
657 b->overlays_before = o; 657 b->overlays_before = o;
658} 658}
659 659
660static inline void 660static void
661set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o) 661set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o)
662{ 662{
663 b->overlays_after = o; 663 b->overlays_after = o;
@@ -1341,9 +1341,13 @@ A non-nil FLAG means mark the buffer modified. */)
1341 /* If buffer becoming modified, lock the file. 1341 /* If buffer becoming modified, lock the file.
1342 If buffer becoming unmodified, unlock the file. */ 1342 If buffer becoming unmodified, unlock the file. */
1343 1343
1344 fn = BVAR (current_buffer, file_truename); 1344 struct buffer *b = current_buffer->base_buffer
1345 ? current_buffer->base_buffer
1346 : current_buffer;
1347
1348 fn = BVAR (b, file_truename);
1345 /* Test buffer-file-name so that binding it to nil is effective. */ 1349 /* Test buffer-file-name so that binding it to nil is effective. */
1346 if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) 1350 if (!NILP (fn) && ! NILP (BVAR (b, filename)))
1347 { 1351 {
1348 bool already = SAVE_MODIFF < MODIFF; 1352 bool already = SAVE_MODIFF < MODIFF;
1349 if (!already && !NILP (flag)) 1353 if (!already && !NILP (flag))
@@ -1919,7 +1923,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1919 1923
1920 bset_name (b, Qnil); 1924 bset_name (b, Qnil);
1921 1925
1922 BLOCK_INPUT; 1926 block_input ();
1923 if (b->base_buffer) 1927 if (b->base_buffer)
1924 { 1928 {
1925 /* Notify our base buffer that we don't share the text anymore. */ 1929 /* Notify our base buffer that we don't share the text anymore. */
@@ -1942,7 +1946,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1942 b->width_run_cache = 0; 1946 b->width_run_cache = 0;
1943 } 1947 }
1944 bset_width_table (b, Qnil); 1948 bset_width_table (b, Qnil);
1945 UNBLOCK_INPUT; 1949 unblock_input ();
1946 bset_undo_list (b, Qnil); 1950 bset_undo_list (b, Qnil);
1947 1951
1948 /* Run buffer-list-update-hook. */ 1952 /* Run buffer-list-update-hook. */
@@ -2460,7 +2464,7 @@ current buffer is cleared. */)
2460 begv = BEGV, zv = ZV; 2464 begv = BEGV, zv = ZV;
2461 2465
2462 if (narrowed) 2466 if (narrowed)
2463 Fwiden (); 2467 error ("Changing multibyteness in a narrowed buffer");
2464 2468
2465 if (NILP (flag)) 2469 if (NILP (flag))
2466 { 2470 {
@@ -3685,7 +3689,6 @@ fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end)
3685 beforep->next = current_buffer->overlays_before; 3689 beforep->next = current_buffer->overlays_before;
3686 set_buffer_overlays_before (current_buffer, before_list); 3690 set_buffer_overlays_before (current_buffer, before_list);
3687 } 3691 }
3688 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3689 3692
3690 if (afterp) 3693 if (afterp)
3691 { 3694 {
@@ -3843,17 +3846,16 @@ for the rear of the overlay advance when text is inserted there
3843 end = OVERLAY_END (overlay); 3846 end = OVERLAY_END (overlay);
3844 if (OVERLAY_POSITION (end) < b->overlay_center) 3847 if (OVERLAY_POSITION (end) < b->overlay_center)
3845 { 3848 {
3846 if (b->overlays_after) 3849 eassert (b->overlays_after || (XOVERLAY (overlay)->next == NULL));
3847 XOVERLAY (overlay)->next = b->overlays_after; 3850 XOVERLAY (overlay)->next = b->overlays_after;
3848 set_buffer_overlays_after (b, XOVERLAY (overlay)); 3851 set_buffer_overlays_after (b, XOVERLAY (overlay));
3849 } 3852 }
3850 else 3853 else
3851 { 3854 {
3852 if (b->overlays_before) 3855 eassert (b->overlays_before || (XOVERLAY (overlay)->next == NULL));
3853 XOVERLAY (overlay)->next = b->overlays_before; 3856 XOVERLAY (overlay)->next = b->overlays_before;
3854 set_buffer_overlays_before (b, XOVERLAY (overlay)); 3857 set_buffer_overlays_before (b, XOVERLAY (overlay));
3855 } 3858 }
3856
3857 /* This puts it in the right list, and in the right order. */ 3859 /* This puts it in the right list, and in the right order. */
3858 recenter_overlay_lists (b, b->overlay_center); 3860 recenter_overlay_lists (b, b->overlay_center);
3859 3861
@@ -4137,7 +4139,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
4137 /* Put all the overlays we want in a vector in overlay_vec. 4139 /* Put all the overlays we want in a vector in overlay_vec.
4138 Store the length in len. */ 4140 Store the length in len. */
4139 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, 4141 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
4140 0, 0, 0); 4142 NULL, NULL, 0);
4141 4143
4142 /* Make a list of them all. */ 4144 /* Make a list of them all. */
4143 result = Flist (noverlays, overlay_vec); 4145 result = Flist (noverlays, overlay_vec);
@@ -5028,7 +5030,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5028{ 5030{
5029 void *p; 5031 void *p;
5030 5032
5031 BLOCK_INPUT; 5033 block_input ();
5032#if defined USE_MMAP_FOR_BUFFERS 5034#if defined USE_MMAP_FOR_BUFFERS
5033 p = mmap_alloc ((void **) &b->text->beg, nbytes); 5035 p = mmap_alloc ((void **) &b->text->beg, nbytes);
5034#elif defined REL_ALLOC 5036#elif defined REL_ALLOC
@@ -5039,12 +5041,12 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5039 5041
5040 if (p == NULL) 5042 if (p == NULL)
5041 { 5043 {
5042 UNBLOCK_INPUT; 5044 unblock_input ();
5043 memory_full (nbytes); 5045 memory_full (nbytes);
5044 } 5046 }
5045 5047
5046 b->text->beg = (unsigned char *) p; 5048 b->text->beg = (unsigned char *) p;
5047 UNBLOCK_INPUT; 5049 unblock_input ();
5048} 5050}
5049 5051
5050/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means 5052/* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means
@@ -5056,7 +5058,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5056 void *p; 5058 void *p;
5057 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 5059 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
5058 + delta); 5060 + delta);
5059 BLOCK_INPUT; 5061 block_input ();
5060#if defined USE_MMAP_FOR_BUFFERS 5062#if defined USE_MMAP_FOR_BUFFERS
5061 p = mmap_realloc ((void **) &b->text->beg, nbytes); 5063 p = mmap_realloc ((void **) &b->text->beg, nbytes);
5062#elif defined REL_ALLOC 5064#elif defined REL_ALLOC
@@ -5067,12 +5069,12 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5067 5069
5068 if (p == NULL) 5070 if (p == NULL)
5069 { 5071 {
5070 UNBLOCK_INPUT; 5072 unblock_input ();
5071 memory_full (nbytes); 5073 memory_full (nbytes);
5072 } 5074 }
5073 5075
5074 BUF_BEG_ADDR (b) = (unsigned char *) p; 5076 BUF_BEG_ADDR (b) = (unsigned char *) p;
5075 UNBLOCK_INPUT; 5077 unblock_input ();
5076} 5078}
5077 5079
5078 5080
@@ -5081,7 +5083,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5081static void 5083static void
5082free_buffer_text (struct buffer *b) 5084free_buffer_text (struct buffer *b)
5083{ 5085{
5084 BLOCK_INPUT; 5086 block_input ();
5085 5087
5086#if defined USE_MMAP_FOR_BUFFERS 5088#if defined USE_MMAP_FOR_BUFFERS
5087 mmap_free ((void **) &b->text->beg); 5089 mmap_free ((void **) &b->text->beg);
@@ -5092,7 +5094,7 @@ free_buffer_text (struct buffer *b)
5092#endif 5094#endif
5093 5095
5094 BUF_BEG_ADDR (b) = NULL; 5096 BUF_BEG_ADDR (b) = NULL;
5095 UNBLOCK_INPUT; 5097 unblock_input ();
5096} 5098}
5097 5099
5098 5100
diff --git a/src/bytecode.c b/src/bytecode.c
index 5f4fdcc5eff..648813aed86 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1876,7 +1876,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1876 /* Actually this is Bstack_ref with offset 0, but we use Bdup 1876 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1877 for that instead. */ 1877 for that instead. */
1878 /* CASE (Bstack_ref): */ 1878 /* CASE (Bstack_ref): */
1879 emacs_abort (); 1879 error ("Invalid byte opcode");
1880 1880
1881 /* Handy byte-codes for lexical binding. */ 1881 /* Handy byte-codes for lexical binding. */
1882 CASE (Bstack_ref1): 1882 CASE (Bstack_ref1):
diff --git a/src/callproc.c b/src/callproc.c
index 2604d295f3e..b33882e54c2 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -51,6 +51,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#include "process.h" 51#include "process.h"
52#include "syssignal.h" 52#include "syssignal.h"
53#include "systty.h" 53#include "systty.h"
54#include "syswait.h"
54#include "blockinput.h" 55#include "blockinput.h"
55#include "frame.h" 56#include "frame.h"
56#include "termhooks.h" 57#include "termhooks.h"
@@ -582,7 +583,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
582 0, current_dir); 583 0, current_dir);
583#else /* not WINDOWSNT */ 584#else /* not WINDOWSNT */
584 585
585 BLOCK_INPUT; 586 block_input ();
586 587
587 /* vfork, and prevent local vars from being clobbered by the vfork. */ 588 /* vfork, and prevent local vars from being clobbered by the vfork. */
588 { 589 {
@@ -626,15 +627,14 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
626 setpgrp (pid, pid); 627 setpgrp (pid, pid);
627#endif /* USG */ 628#endif /* USG */
628 629
629 /* GConf causes us to ignore SIGPIPE, make sure it is restored 630 /* Emacs ignores SIGPIPE, but the child should not. */
630 in the child. */
631 signal (SIGPIPE, SIG_DFL); 631 signal (SIGPIPE, SIG_DFL);
632 632
633 child_setup (filefd, fd1, fd_error, (char **) new_argv, 633 child_setup (filefd, fd1, fd_error, (char **) new_argv,
634 0, current_dir); 634 0, current_dir);
635 } 635 }
636 636
637 UNBLOCK_INPUT; 637 unblock_input ();
638 638
639#endif /* not WINDOWSNT */ 639#endif /* not WINDOWSNT */
640 640
@@ -976,9 +976,9 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
976 { 976 {
977 int fd; 977 int fd;
978 978
979 BLOCK_INPUT; 979 block_input ();
980 fd = mkstemp (tempfile); 980 fd = mkstemp (tempfile);
981 UNBLOCK_INPUT; 981 unblock_input ();
982 if (fd == -1) 982 if (fd == -1)
983 report_file_error ("Failed to open temporary file", 983 report_file_error ("Failed to open temporary file",
984 Fcons (build_string (tempfile), Qnil)); 984 Fcons (build_string (tempfile), Qnil));
diff --git a/src/category.c b/src/category.c
index 01a6f54ad17..fe02303f679 100644
--- a/src/category.c
+++ b/src/category.c
@@ -40,7 +40,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
40#include "keymap.h" 40#include "keymap.h"
41 41
42/* This setter is used only in this file, so it can be private. */ 42/* This setter is used only in this file, so it can be private. */
43static inline void 43static void
44bset_category_table (struct buffer *b, Lisp_Object val) 44bset_category_table (struct buffer *b, Lisp_Object val)
45{ 45{
46 b->INTERNAL_FIELD (category_table) = val; 46 b->INTERNAL_FIELD (category_table) = val;
diff --git a/src/character.c b/src/character.c
index def1ad090fd..5808d48a235 100644
--- a/src/character.c
+++ b/src/character.c
@@ -126,8 +126,6 @@ char_string (unsigned int c, unsigned char *p)
126 c &= ~CHAR_MODIFIER_MASK; 126 c &= ~CHAR_MODIFIER_MASK;
127 } 127 }
128 128
129 MAYBE_UNIFY_CHAR (c);
130
131 if (c <= MAX_3_BYTE_CHAR) 129 if (c <= MAX_3_BYTE_CHAR)
132 { 130 {
133 bytes = CHAR_STRING (c, p); 131 bytes = CHAR_STRING (c, p);
@@ -195,8 +193,6 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len)
195 p += 5; 193 p += 5;
196 } 194 }
197 195
198 MAYBE_UNIFY_CHAR (c);
199
200 if (len) 196 if (len)
201 *len = p - saved_p; 197 *len = p - saved_p;
202 if (advanced) 198 if (advanced)
diff --git a/src/character.h b/src/character.h
index 70d4e67a978..b2cdcb76699 100644
--- a/src/character.h
+++ b/src/character.h
@@ -554,23 +554,6 @@ INLINE_HEADER_BEGIN
554 } while (0) 554 } while (0)
555 555
556 556
557/* If C is a character to be unified with a Unicode character, return
558 the unified Unicode character. */
559
560#define MAYBE_UNIFY_CHAR(c) \
561 do { \
562 if (c > MAX_UNICODE_CHAR && c <= MAX_5_BYTE_CHAR) \
563 { \
564 Lisp_Object val; \
565 val = CHAR_TABLE_REF (Vchar_unify_table, c); \
566 if (INTEGERP (val)) \
567 c = XFASTINT (val); \
568 else if (! NILP (val)) \
569 c = maybe_unify_char (c, val); \
570 } \
571 } while (0)
572
573
574/* Return a non-outlandish value for the tab width. */ 557/* Return a non-outlandish value for the tab width. */
575 558
576#define SANE_TAB_WIDTH(buf) \ 559#define SANE_TAB_WIDTH(buf) \
diff --git a/src/charset.c b/src/charset.c
index d8c38e5ea3b..6b999824dab 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -421,7 +421,7 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries,
421/* Read a hexadecimal number (preceded by "0x") from the file FP while 421/* Read a hexadecimal number (preceded by "0x") from the file FP while
422 paying attention to comment character '#'. */ 422 paying attention to comment character '#'. */
423 423
424static inline unsigned 424static unsigned
425read_hex (FILE *fp, bool *eof, bool *overflow) 425read_hex (FILE *fp, bool *eof, bool *overflow)
426{ 426{
427 int c; 427 int c;
@@ -1617,7 +1617,7 @@ only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
1617/* Return a unified character code for C (>= 0x110000). VAL is a 1617/* Return a unified character code for C (>= 0x110000). VAL is a
1618 value of Vchar_unify_table for C; i.e. it is nil, an integer, or a 1618 value of Vchar_unify_table for C; i.e. it is nil, an integer, or a
1619 charset symbol. */ 1619 charset symbol. */
1620int 1620static int
1621maybe_unify_char (int c, Lisp_Object val) 1621maybe_unify_char (int c, Lisp_Object val)
1622{ 1622{
1623 struct charset *charset; 1623 struct charset *charset;
@@ -1723,8 +1723,12 @@ decode_char (struct charset *charset, unsigned int code)
1723 { 1723 {
1724 c = char_index + CHARSET_CODE_OFFSET (charset); 1724 c = char_index + CHARSET_CODE_OFFSET (charset);
1725 if (CHARSET_UNIFIED_P (charset) 1725 if (CHARSET_UNIFIED_P (charset)
1726 && c > MAX_UNICODE_CHAR) 1726 && MAX_UNICODE_CHAR < c && c <= MAX_5_BYTE_CHAR)
1727 MAYBE_UNIFY_CHAR (c); 1727 {
1728 /* Unify C with a Unicode character if possible. */
1729 Lisp_Object val = CHAR_TABLE_REF (Vchar_unify_table, c);
1730 c = maybe_unify_char (c, val);
1731 }
1728 } 1732 }
1729 } 1733 }
1730 1734
diff --git a/src/charset.h b/src/charset.h
index 50d230489fe..b5fa36290c8 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -538,7 +538,6 @@ extern int charset_unibyte;
538extern struct charset *char_charset (int, Lisp_Object, unsigned *); 538extern struct charset *char_charset (int, Lisp_Object, unsigned *);
539extern Lisp_Object charset_attributes (int); 539extern Lisp_Object charset_attributes (int);
540 540
541extern int maybe_unify_char (int, Lisp_Object);
542extern int decode_char (struct charset *, unsigned); 541extern int decode_char (struct charset *, unsigned);
543extern unsigned encode_char (struct charset *, int); 542extern unsigned encode_char (struct charset *, int);
544extern int string_xstring_p (Lisp_Object); 543extern int string_xstring_p (Lisp_Object);
diff --git a/src/chartab.c b/src/chartab.c
index e864514e336..7430235b4af 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -655,15 +655,6 @@ or a character code. Return VALUE. */)
655 return value; 655 return value;
656} 656}
657 657
658DEFUN ("set-char-table-default", Fset_char_table_default,
659 Sset_char_table_default, 3, 3, 0,
660 doc: /*
661This function is obsolete and has no effect. */)
662 (Lisp_Object char_table, Lisp_Object ch, Lisp_Object value)
663{
664 return Qnil;
665}
666
667/* Look up the element in TABLE at index CH, and return it as an 658/* Look up the element in TABLE at index CH, and return it as an
668 integer. If the element is not a character, return CH itself. */ 659 integer. If the element is not a character, return CH itself. */
669 660
@@ -1415,7 +1406,6 @@ syms_of_chartab (void)
1415 defsubr (&Sset_char_table_extra_slot); 1406 defsubr (&Sset_char_table_extra_slot);
1416 defsubr (&Schar_table_range); 1407 defsubr (&Schar_table_range);
1417 defsubr (&Sset_char_table_range); 1408 defsubr (&Sset_char_table_range);
1418 defsubr (&Sset_char_table_default);
1419 defsubr (&Soptimize_char_table); 1409 defsubr (&Soptimize_char_table);
1420 defsubr (&Smap_char_table); 1410 defsubr (&Smap_char_table);
1421 defsubr (&Sunicode_property_table_internal); 1411 defsubr (&Sunicode_property_table_internal);
diff --git a/src/cmds.c b/src/cmds.c
index 45f7df948ae..453a4b67e57 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -85,6 +85,7 @@ move_point (Lisp_Object n, bool forward)
85DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p", 85DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
86 doc: /* Move point N characters forward (backward if N is negative). 86 doc: /* Move point N characters forward (backward if N is negative).
87On reaching end or beginning of buffer, stop and signal error. 87On reaching end or beginning of buffer, stop and signal error.
88Interactively, N is the numeric prefix argument.
88 89
89Depending on the bidirectional context, the movement may be to the 90Depending on the bidirectional context, the movement may be to the
90right or to the left on the screen. This is in contrast with 91right or to the left on the screen. This is in contrast with
@@ -97,6 +98,7 @@ right or to the left on the screen. This is in contrast with
97DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p", 98DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
98 doc: /* Move point N characters backward (forward if N is negative). 99 doc: /* Move point N characters backward (forward if N is negative).
99On attempt to pass beginning or end of buffer, stop and signal error. 100On attempt to pass beginning or end of buffer, stop and signal error.
101Interactively, N is the numeric prefix argument.
100 102
101Depending on the bidirectional context, the movement may be to the 103Depending on the bidirectional context, the movement may be to the
102right or to the left on the screen. This is in contrast with 104right or to the left on the screen. This is in contrast with
diff --git a/src/coding.c b/src/coding.c
index 4b3d22f956c..d9606cf5710 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -920,65 +920,18 @@ record_conversion_result (struct coding_system *coding,
920 920
921 921
922/* Store multibyte form of the character C in P, and advance P to the 922/* Store multibyte form of the character C in P, and advance P to the
923 end of the multibyte form. This is like CHAR_STRING_ADVANCE but it 923 end of the multibyte form. This used to be like CHAR_STRING_ADVANCE
924 never calls MAYBE_UNIFY_CHAR. */ 924 without ever calling MAYBE_UNIFY_CHAR, but nowadays we don't call
925 925 MAYBE_UNIFY_CHAR in CHAR_STRING_ADVANCE. */
926#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) \
927 do { \
928 if ((c) <= MAX_1_BYTE_CHAR) \
929 *(p)++ = (c); \
930 else if ((c) <= MAX_2_BYTE_CHAR) \
931 *(p)++ = (0xC0 | ((c) >> 6)), \
932 *(p)++ = (0x80 | ((c) & 0x3F)); \
933 else if ((c) <= MAX_3_BYTE_CHAR) \
934 *(p)++ = (0xE0 | ((c) >> 12)), \
935 *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \
936 *(p)++ = (0x80 | ((c) & 0x3F)); \
937 else if ((c) <= MAX_4_BYTE_CHAR) \
938 *(p)++ = (0xF0 | (c >> 18)), \
939 *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \
940 *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \
941 *(p)++ = (0x80 | (c & 0x3F)); \
942 else if ((c) <= MAX_5_BYTE_CHAR) \
943 *(p)++ = 0xF8, \
944 *(p)++ = (0x80 | ((c >> 18) & 0x0F)), \
945 *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \
946 *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \
947 *(p)++ = (0x80 | (c & 0x3F)); \
948 else \
949 (p) += BYTE8_STRING ((c) - 0x3FFF80, p); \
950 } while (0)
951 926
927#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) CHAR_STRING_ADVANCE(c, p)
952 928
953/* Return the character code of character whose multibyte form is at 929/* Return the character code of character whose multibyte form is at
954 P, and advance P to the end of the multibyte form. This is like 930 P, and advance P to the end of the multibyte form. This used to be
955 STRING_CHAR_ADVANCE, but it never calls MAYBE_UNIFY_CHAR. */ 931 like STRING_CHAR_ADVANCE without ever calling MAYBE_UNIFY_CHAR, but
956 932 nowadays STRING_CHAR_ADVANCE doesn't call MAYBE_UNIFY_CHAR. */
957#define STRING_CHAR_ADVANCE_NO_UNIFY(p) \
958 (!((p)[0] & 0x80) \
959 ? *(p)++ \
960 : ! ((p)[0] & 0x20) \
961 ? ((p) += 2, \
962 ((((p)[-2] & 0x1F) << 6) \
963 | ((p)[-1] & 0x3F) \
964 | ((unsigned char) ((p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \
965 : ! ((p)[0] & 0x10) \
966 ? ((p) += 3, \
967 ((((p)[-3] & 0x0F) << 12) \
968 | (((p)[-2] & 0x3F) << 6) \
969 | ((p)[-1] & 0x3F))) \
970 : ! ((p)[0] & 0x08) \
971 ? ((p) += 4, \
972 ((((p)[-4] & 0xF) << 18) \
973 | (((p)[-3] & 0x3F) << 12) \
974 | (((p)[-2] & 0x3F) << 6) \
975 | ((p)[-1] & 0x3F))) \
976 : ((p) += 5, \
977 ((((p)[-4] & 0x3F) << 18) \
978 | (((p)[-3] & 0x3F) << 12) \
979 | (((p)[-2] & 0x3F) << 6) \
980 | ((p)[-1] & 0x3F))))
981 933
934#define STRING_CHAR_ADVANCE_NO_UNIFY(p) STRING_CHAR_ADVANCE(p)
982 935
983/* Set coding->source from coding->src_object. */ 936/* Set coding->source from coding->src_object. */
984 937
@@ -5106,6 +5059,7 @@ decode_coding_ccl (struct coding_system *coding)
5106 while (1) 5059 while (1)
5107 { 5060 {
5108 const unsigned char *p = src; 5061 const unsigned char *p = src;
5062 ptrdiff_t offset;
5109 int i = 0; 5063 int i = 0;
5110 5064
5111 if (multibytep) 5065 if (multibytep)
@@ -5123,8 +5077,17 @@ decode_coding_ccl (struct coding_system *coding)
5123 5077
5124 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) 5078 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK)
5125 ccl->last_block = 1; 5079 ccl->last_block = 1;
5080 /* As ccl_driver calls DECODE_CHAR, buffer may be relocated. */
5081 charset_map_loaded = 0;
5126 ccl_driver (ccl, source_charbuf, charbuf, i, charbuf_end - charbuf, 5082 ccl_driver (ccl, source_charbuf, charbuf, i, charbuf_end - charbuf,
5127 charset_list); 5083 charset_list);
5084 if (charset_map_loaded
5085 && (offset = coding_change_source (coding)))
5086 {
5087 p += offset;
5088 src += offset;
5089 src_end += offset;
5090 }
5128 charbuf += ccl->produced; 5091 charbuf += ccl->produced;
5129 if (multibytep) 5092 if (multibytep)
5130 src += source_byteidx[ccl->consumed]; 5093 src += source_byteidx[ccl->consumed];
@@ -5177,8 +5140,15 @@ encode_coding_ccl (struct coding_system *coding)
5177 5140
5178 do 5141 do
5179 { 5142 {
5143 ptrdiff_t offset;
5144
5145 /* As ccl_driver calls DECODE_CHAR, buffer may be relocated. */
5146 charset_map_loaded = 0;
5180 ccl_driver (ccl, charbuf, destination_charbuf, 5147 ccl_driver (ccl, charbuf, destination_charbuf,
5181 charbuf_end - charbuf, 1024, charset_list); 5148 charbuf_end - charbuf, 1024, charset_list);
5149 if (charset_map_loaded
5150 && (offset = coding_change_destination (coding)))
5151 dst += offset;
5182 if (multibytep) 5152 if (multibytep)
5183 { 5153 {
5184 ASSURE_DESTINATION (ccl->produced * 2); 5154 ASSURE_DESTINATION (ccl->produced * 2);
@@ -6852,7 +6822,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6852 [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ] 6822 [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ]
6853 */ 6823 */
6854 6824
6855static inline void 6825static void
6856produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos) 6826produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
6857{ 6827{
6858 int len; 6828 int len;
@@ -6896,7 +6866,7 @@ produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
6896 [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ] 6866 [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ]
6897 */ 6867 */
6898 6868
6899static inline void 6869static void
6900produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) 6870produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
6901{ 6871{
6902 ptrdiff_t from = pos - charbuf[2]; 6872 ptrdiff_t from = pos - charbuf[2];
@@ -7131,7 +7101,7 @@ decode_coding (struct coding_system *coding)
7131 position of a composition after POS (if any) or to LIMIT, and 7101 position of a composition after POS (if any) or to LIMIT, and
7132 return BUF. */ 7102 return BUF. */
7133 7103
7134static inline int * 7104static int *
7135handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, 7105handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit,
7136 struct coding_system *coding, int *buf, 7106 struct coding_system *coding, int *buf,
7137 ptrdiff_t *stop) 7107 ptrdiff_t *stop)
@@ -7214,7 +7184,7 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit,
7214 If the property value is nil, set *STOP to the position where the 7184 If the property value is nil, set *STOP to the position where the
7215 property value is non-nil (limiting by LIMIT), and return BUF. */ 7185 property value is non-nil (limiting by LIMIT), and return BUF. */
7216 7186
7217static inline int * 7187static int *
7218handle_charset_annotation (ptrdiff_t pos, ptrdiff_t limit, 7188handle_charset_annotation (ptrdiff_t pos, ptrdiff_t limit,
7219 struct coding_system *coding, int *buf, 7189 struct coding_system *coding, int *buf,
7220 ptrdiff_t *stop) 7190 ptrdiff_t *stop)
@@ -8459,7 +8429,7 @@ highest priority. */)
8459} 8429}
8460 8430
8461 8431
8462static inline bool 8432static bool
8463char_encodable_p (int c, Lisp_Object attrs) 8433char_encodable_p (int c, Lisp_Object attrs)
8464{ 8434{
8465 Lisp_Object tail; 8435 Lisp_Object tail;
diff --git a/src/coding.h b/src/coding.h
index c45d2ef86e2..989552bf667 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -646,10 +646,8 @@ struct coding_system
646 for file names, if any. */ 646 for file names, if any. */
647#define ENCODE_FILE(name) \ 647#define ENCODE_FILE(name) \
648 (! NILP (Vfile_name_coding_system) \ 648 (! NILP (Vfile_name_coding_system) \
649 && !EQ (Vfile_name_coding_system, make_number (0)) \
650 ? code_convert_string_norecord (name, Vfile_name_coding_system, 1) \ 649 ? code_convert_string_norecord (name, Vfile_name_coding_system, 1) \
651 : (! NILP (Vdefault_file_name_coding_system) \ 650 : (! NILP (Vdefault_file_name_coding_system) \
652 && !EQ (Vdefault_file_name_coding_system, make_number (0)) \
653 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \ 651 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 1) \
654 : name)) 652 : name))
655 653
@@ -658,10 +656,8 @@ struct coding_system
658 for file names, if any. */ 656 for file names, if any. */
659#define DECODE_FILE(name) \ 657#define DECODE_FILE(name) \
660 (! NILP (Vfile_name_coding_system) \ 658 (! NILP (Vfile_name_coding_system) \
661 && !EQ (Vfile_name_coding_system, make_number (0)) \
662 ? code_convert_string_norecord (name, Vfile_name_coding_system, 0) \ 659 ? code_convert_string_norecord (name, Vfile_name_coding_system, 0) \
663 : (! NILP (Vdefault_file_name_coding_system) \ 660 : (! NILP (Vdefault_file_name_coding_system) \
664 && !EQ (Vdefault_file_name_coding_system, make_number (0)) \
665 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \ 661 ? code_convert_string_norecord (name, Vdefault_file_name_coding_system, 0) \
666 : name)) 662 : name))
667 663
@@ -670,7 +666,6 @@ struct coding_system
670 for system functions, if any. */ 666 for system functions, if any. */
671#define ENCODE_SYSTEM(str) \ 667#define ENCODE_SYSTEM(str) \
672 (! NILP (Vlocale_coding_system) \ 668 (! NILP (Vlocale_coding_system) \
673 && !EQ (Vlocale_coding_system, make_number (0)) \
674 ? code_convert_string_norecord (str, Vlocale_coding_system, 1) \ 669 ? code_convert_string_norecord (str, Vlocale_coding_system, 1) \
675 : str) 670 : str)
676 671
@@ -678,7 +673,6 @@ struct coding_system
678 for system functions, if any. */ 673 for system functions, if any. */
679#define DECODE_SYSTEM(str) \ 674#define DECODE_SYSTEM(str) \
680 (! NILP (Vlocale_coding_system) \ 675 (! NILP (Vlocale_coding_system) \
681 && !EQ (Vlocale_coding_system, make_number (0)) \
682 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \ 676 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
683 : str) 677 : str)
684 678
diff --git a/src/composite.c b/src/composite.c
index ae46df0a573..6c603fab3fc 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1219,9 +1219,6 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos,
1219 ptrdiff_t bytepos, ptrdiff_t endpos, struct window *w, 1219 ptrdiff_t bytepos, ptrdiff_t endpos, struct window *w,
1220 struct face *face, Lisp_Object string) 1220 struct face *face, Lisp_Object string)
1221{ 1221{
1222 if (endpos < 0)
1223 endpos = NILP (string) ? BEGV : 0;
1224
1225 if (cmp_it->ch == -2) 1222 if (cmp_it->ch == -2)
1226 { 1223 {
1227 composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string); 1224 composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
@@ -1230,6 +1227,9 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos,
1230 return 0; 1227 return 0;
1231 } 1228 }
1232 1229
1230 if (endpos < 0)
1231 endpos = NILP (string) ? BEGV : 0;
1232
1233 if (cmp_it->ch < 0) 1233 if (cmp_it->ch < 0)
1234 { 1234 {
1235 /* We are looking at a static composition. */ 1235 /* We are looking at a static composition. */
@@ -1277,36 +1277,23 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos,
1277 { 1277 {
1278 ptrdiff_t cpos = charpos, bpos = bytepos; 1278 ptrdiff_t cpos = charpos, bpos = bytepos;
1279 1279
1280 while (1) 1280 cmp_it->reversed_p = 1;
1281 elt = XCAR (val);
1282 if (cmp_it->lookback > 0)
1281 { 1283 {
1282 elt = XCAR (val); 1284 cpos = charpos - cmp_it->lookback;
1283 if (cmp_it->lookback > 0) 1285 if (STRINGP (string))
1284 { 1286 bpos = string_char_to_byte (string, cpos);
1285 cpos = charpos - cmp_it->lookback; 1287 else
1286 if (STRINGP (string)) 1288 bpos = CHAR_TO_BYTE (cpos);
1287 bpos = string_char_to_byte (string, cpos);
1288 else
1289 bpos = CHAR_TO_BYTE (cpos);
1290 }
1291 lgstring = autocmp_chars (elt, cpos, bpos, charpos + 1, w, face,
1292 string);
1293 if (composition_gstring_p (lgstring)
1294 && cpos + LGSTRING_CHAR_LEN (lgstring) - 1 == charpos)
1295 break;
1296 /* Composition failed or didn't cover the current
1297 character. */
1298 if (cmp_it->lookback == 0)
1299 goto no_composition;
1300 lgstring = Qnil;
1301 /* Try to find a shorter composition that starts after CPOS. */
1302 composition_compute_stop_pos (cmp_it, charpos, bytepos, cpos,
1303 string);
1304 if (cmp_it->ch == -2 || cmp_it->stop_pos < charpos)
1305 goto no_composition;
1306 val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch);
1307 for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val));
1308 } 1289 }
1309 cmp_it->reversed_p = 1; 1290 lgstring = autocmp_chars (elt, cpos, bpos, charpos + 1, w, face,
1291 string);
1292 if (! composition_gstring_p (lgstring)
1293 || cpos + LGSTRING_CHAR_LEN (lgstring) - 1 != charpos)
1294 /* Composition failed or didn't cover the current
1295 character. */
1296 goto no_composition;
1310 } 1297 }
1311 if (NILP (lgstring)) 1298 if (NILP (lgstring))
1312 goto no_composition; 1299 goto no_composition;
@@ -1341,6 +1328,8 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos,
1341 /* BYTEPOS is calculated in composition_compute_stop_pos */ 1328 /* BYTEPOS is calculated in composition_compute_stop_pos */
1342 bytepos = -1; 1329 bytepos = -1;
1343 } 1330 }
1331 if (cmp_it->reversed_p)
1332 endpos = -1;
1344 composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string); 1333 composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
1345 return 0; 1334 return 0;
1346} 1335}
diff --git a/src/data.c b/src/data.c
index 72d7c8ccf9a..abcdd4dca0d 100644
--- a/src/data.c
+++ b/src/data.c
@@ -34,14 +34,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
34#include "font.h" 34#include "font.h"
35#include "keymap.h" 35#include "keymap.h"
36 36
37#include <float.h>
38#if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
39 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
40#define IEEE_FLOATING_POINT 1
41#else
42#define IEEE_FLOATING_POINT 0
43#endif
44
45Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; 37Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
46static Lisp_Object Qsubr; 38static Lisp_Object Qsubr;
47Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; 39Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
@@ -3179,32 +3171,3 @@ syms_of_data (void)
3179 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM); 3171 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3180 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1; 3172 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3181} 3173}
3182
3183static _Noreturn void
3184handle_arith_signal (int sig)
3185{
3186 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
3187 xsignal0 (Qarith_error);
3188}
3189
3190static void
3191deliver_arith_signal (int sig)
3192{
3193 handle_on_main_thread (sig, handle_arith_signal);
3194}
3195
3196void
3197init_data (void)
3198{
3199 struct sigaction action;
3200 /* Don't do this if just dumping out.
3201 We don't want to call `signal' in this case
3202 so that we don't have trouble with dumping
3203 signal-delivering routines in an inconsistent state. */
3204#ifndef CANNOT_DUMP
3205 if (!initialized)
3206 return;
3207#endif /* CANNOT_DUMP */
3208 emacs_sigaction_init (&action, deliver_arith_signal);
3209 sigaction (SIGFPE, &action, 0);
3210}
diff --git a/src/dired.c b/src/dired.c
index 3aa27ecf920..4986f845101 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -101,9 +101,9 @@ static Lisp_Object
101directory_files_internal_unwind (Lisp_Object dh) 101directory_files_internal_unwind (Lisp_Object dh)
102{ 102{
103 DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer; 103 DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer;
104 BLOCK_INPUT; 104 block_input ();
105 closedir (d); 105 closedir (d);
106 UNBLOCK_INPUT; 106 unblock_input ();
107 return Qnil; 107 return Qnil;
108} 108}
109 109
@@ -164,9 +164,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
164 /* Now *bufp is the compiled form of MATCH; don't call anything 164 /* Now *bufp is the compiled form of MATCH; don't call anything
165 which might compile a new regexp until we're done with the loop! */ 165 which might compile a new regexp until we're done with the loop! */
166 166
167 BLOCK_INPUT; 167 block_input ();
168 d = opendir (SSDATA (dirfilename)); 168 d = opendir (SSDATA (dirfilename));
169 UNBLOCK_INPUT; 169 unblock_input ();
170 if (d == NULL) 170 if (d == NULL)
171 report_file_error ("Opening directory", Fcons (directory, Qnil)); 171 report_file_error ("Opening directory", Fcons (directory, Qnil));
172 172
@@ -310,9 +310,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
310 } 310 }
311 } 311 }
312 312
313 BLOCK_INPUT; 313 block_input ();
314 closedir (d); 314 closedir (d);
315 UNBLOCK_INPUT; 315 unblock_input ();
316#ifdef WINDOWSNT 316#ifdef WINDOWSNT
317 if (attrs) 317 if (attrs)
318 Vw32_get_true_file_attributes = w32_save; 318 Vw32_get_true_file_attributes = w32_save;
@@ -486,9 +486,9 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
486 486
487 encoded_dir = ENCODE_FILE (dirname); 487 encoded_dir = ENCODE_FILE (dirname);
488 488
489 BLOCK_INPUT; 489 block_input ();
490 d = opendir (SSDATA (Fdirectory_file_name (encoded_dir))); 490 d = opendir (SSDATA (Fdirectory_file_name (encoded_dir)));
491 UNBLOCK_INPUT; 491 unblock_input ();
492 if (!d) 492 if (!d)
493 report_file_error ("Opening directory", Fcons (dirname, Qnil)); 493 report_file_error ("Opening directory", Fcons (dirname, Qnil));
494 494
@@ -962,10 +962,10 @@ so last access time will always be midnight of that day. */)
962 962
963 if (!(NILP (id_format) || EQ (id_format, Qinteger))) 963 if (!(NILP (id_format) || EQ (id_format, Qinteger)))
964 { 964 {
965 BLOCK_INPUT; 965 block_input ();
966 uname = stat_uname (&s); 966 uname = stat_uname (&s);
967 gname = stat_gname (&s); 967 gname = stat_gname (&s);
968 UNBLOCK_INPUT; 968 unblock_input ();
969 } 969 }
970 if (uname) 970 if (uname)
971 values[2] = DECODE_SYSTEM (build_string (uname)); 971 values[2] = DECODE_SYSTEM (build_string (uname));
diff --git a/src/dispextern.h b/src/dispextern.h
index 5acfe6b5ca6..c5ebb808b05 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2138,7 +2138,8 @@ struct it
2138 const unsigned char *s; 2138 const unsigned char *s;
2139 2139
2140 /* Number of characters in the string (s, or it->string) we iterate 2140 /* Number of characters in the string (s, or it->string) we iterate
2141 over. */ 2141 over. Used only in display_string and its subroutines; never
2142 used for overlay strings and strings from display properties. */
2142 ptrdiff_t string_nchars; 2143 ptrdiff_t string_nchars;
2143 2144
2144 /* Start and end of a visible region; -1 if the region is not 2145 /* Start and end of a visible region; -1 if the region is not
@@ -2756,16 +2757,20 @@ struct image_type
2756 Lisp_Object *type; 2757 Lisp_Object *type;
2757 2758
2758 /* Check that SPEC is a valid image specification for the given 2759 /* Check that SPEC is a valid image specification for the given
2759 image type. Value is non-zero if SPEC is valid. */ 2760 image type. Value is true if SPEC is valid. */
2760 int (* valid_p) (Lisp_Object spec); 2761 bool (* valid_p) (Lisp_Object spec);
2761 2762
2762 /* Load IMG which is used on frame F from information contained in 2763 /* Load IMG which is used on frame F from information contained in
2763 IMG->spec. Value is non-zero if successful. */ 2764 IMG->spec. Value is true if successful. */
2764 int (* load) (struct frame *f, struct image *img); 2765 bool (* load) (struct frame *f, struct image *img);
2765 2766
2766 /* Free resources of image IMG which is used on frame F. */ 2767 /* Free resources of image IMG which is used on frame F. */
2767 void (* free) (struct frame *f, struct image *img); 2768 void (* free) (struct frame *f, struct image *img);
2768 2769
2770 /* Initialization function (used for dynamic loading of image
2771 libraries on Windows), or NULL if none. */
2772 bool (* init) (void);
2773
2769 /* Next in list of all supported image types. */ 2774 /* Next in list of all supported image types. */
2770 struct image_type *next; 2775 struct image_type *next;
2771}; 2776};
@@ -3152,7 +3157,7 @@ extern unsigned row_hash (struct glyph_row *);
3152 3157
3153extern int x_bitmap_height (struct frame *, ptrdiff_t); 3158extern int x_bitmap_height (struct frame *, ptrdiff_t);
3154extern int x_bitmap_width (struct frame *, ptrdiff_t); 3159extern int x_bitmap_width (struct frame *, ptrdiff_t);
3155extern int x_bitmap_pixmap (struct frame *, ptrdiff_t); 3160extern ptrdiff_t x_bitmap_pixmap (struct frame *, ptrdiff_t);
3156extern void x_reference_bitmap (struct frame *, ptrdiff_t); 3161extern void x_reference_bitmap (struct frame *, ptrdiff_t);
3157extern ptrdiff_t x_create_bitmap_from_data (struct frame *, char *, 3162extern ptrdiff_t x_create_bitmap_from_data (struct frame *, char *,
3158 unsigned int, unsigned int); 3163 unsigned int, unsigned int);
@@ -3164,7 +3169,7 @@ extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
3164extern void x_destroy_bitmap (struct frame *, ptrdiff_t); 3169extern void x_destroy_bitmap (struct frame *, ptrdiff_t);
3165#endif 3170#endif
3166extern void x_destroy_all_bitmaps (Display_Info *); 3171extern void x_destroy_all_bitmaps (Display_Info *);
3167extern int x_create_bitmap_mask (struct frame *, ptrdiff_t); 3172extern void x_create_bitmap_mask (struct frame *, ptrdiff_t);
3168extern Lisp_Object x_find_image_file (Lisp_Object); 3173extern Lisp_Object x_find_image_file (Lisp_Object);
3169 3174
3170void x_kill_gs_process (Pixmap, struct frame *); 3175void x_kill_gs_process (Pixmap, struct frame *);
@@ -3172,7 +3177,7 @@ struct image_cache *make_image_cache (void);
3172void free_image_cache (struct frame *); 3177void free_image_cache (struct frame *);
3173void clear_image_caches (Lisp_Object); 3178void clear_image_caches (Lisp_Object);
3174void mark_image_cache (struct image_cache *); 3179void mark_image_cache (struct image_cache *);
3175int valid_image_p (Lisp_Object); 3180bool valid_image_p (Lisp_Object);
3176void prepare_image_for_display (struct frame *, struct image *); 3181void prepare_image_for_display (struct frame *, struct image *);
3177ptrdiff_t lookup_image (struct frame *, Lisp_Object); 3182ptrdiff_t lookup_image (struct frame *, Lisp_Object);
3178 3183
diff --git a/src/dispnew.c b/src/dispnew.c
index 5827316a7b7..6f8fb10b41d 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -1028,7 +1028,7 @@ swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b)
1028 these should all go together for the row's hash value to be 1028 these should all go together for the row's hash value to be
1029 correct. */ 1029 correct. */
1030 1030
1031static inline void 1031static void
1032swap_glyph_pointers (struct glyph_row *a, struct glyph_row *b) 1032swap_glyph_pointers (struct glyph_row *a, struct glyph_row *b)
1033{ 1033{
1034 int i; 1034 int i;
@@ -1057,7 +1057,7 @@ swap_glyph_pointers (struct glyph_row *a, struct glyph_row *b)
1057 that glyph pointers, the `used' counts, and the hash values in the 1057 that glyph pointers, the `used' counts, and the hash values in the
1058 structures are left unchanged. */ 1058 structures are left unchanged. */
1059 1059
1060static inline void 1060static void
1061copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from) 1061copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from)
1062{ 1062{
1063 struct glyph *pointers[1 + LAST_AREA]; 1063 struct glyph *pointers[1 + LAST_AREA];
@@ -1084,7 +1084,7 @@ copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from)
1084 exchanged between TO and FROM. Pointers must be exchanged to avoid 1084 exchanged between TO and FROM. Pointers must be exchanged to avoid
1085 a memory leak. */ 1085 a memory leak. */
1086 1086
1087static inline void 1087static void
1088assign_row (struct glyph_row *to, struct glyph_row *from) 1088assign_row (struct glyph_row *to, struct glyph_row *from)
1089{ 1089{
1090 swap_glyph_pointers (to, from); 1090 swap_glyph_pointers (to, from);
@@ -1249,7 +1249,7 @@ line_draw_cost (struct glyph_matrix *matrix, int vpos)
1249/* Return true if the glyph rows A and B have equal contents. 1249/* Return true if the glyph rows A and B have equal contents.
1250 MOUSE_FACE_P means compare the mouse_face_p flags of A and B, too. */ 1250 MOUSE_FACE_P means compare the mouse_face_p flags of A and B, too. */
1251 1251
1252static inline bool 1252static bool
1253row_equal_p (struct glyph_row *a, struct glyph_row *b, bool mouse_face_p) 1253row_equal_p (struct glyph_row *a, struct glyph_row *b, bool mouse_face_p)
1254{ 1254{
1255 eassert (verify_row_hash (a)); 1255 eassert (verify_row_hash (a));
@@ -1834,7 +1834,7 @@ adjust_glyphs (struct frame *f)
1834{ 1834{
1835 /* Block input so that expose events and other events that access 1835 /* Block input so that expose events and other events that access
1836 glyph matrices are not processed while we are changing them. */ 1836 glyph matrices are not processed while we are changing them. */
1837 BLOCK_INPUT; 1837 block_input ();
1838 1838
1839 if (f) 1839 if (f)
1840 adjust_frame_glyphs (f); 1840 adjust_frame_glyphs (f);
@@ -1846,7 +1846,7 @@ adjust_glyphs (struct frame *f)
1846 adjust_frame_glyphs (XFRAME (lisp_frame)); 1846 adjust_frame_glyphs (XFRAME (lisp_frame));
1847 } 1847 }
1848 1848
1849 UNBLOCK_INPUT; 1849 unblock_input ();
1850} 1850}
1851 1851
1852 1852
@@ -2242,7 +2242,7 @@ free_glyphs (struct frame *f)
2242 { 2242 {
2243 /* Block interrupt input so that we don't get surprised by an X 2243 /* Block interrupt input so that we don't get surprised by an X
2244 event while we're in an inconsistent state. */ 2244 event while we're in an inconsistent state. */
2245 BLOCK_INPUT; 2245 block_input ();
2246 f->glyphs_initialized_p = 0; 2246 f->glyphs_initialized_p = 0;
2247 2247
2248 /* Release window sub-matrices. */ 2248 /* Release window sub-matrices. */
@@ -2287,7 +2287,7 @@ free_glyphs (struct frame *f)
2287 f->desired_pool = f->current_pool = NULL; 2287 f->desired_pool = f->current_pool = NULL;
2288 } 2288 }
2289 2289
2290 UNBLOCK_INPUT; 2290 unblock_input ();
2291 } 2291 }
2292} 2292}
2293 2293
@@ -2657,7 +2657,7 @@ fill_up_frame_row_with_spaces (struct glyph_row *row, int upto)
2657 function must be called before updates to make explicit that we are 2657 function must be called before updates to make explicit that we are
2658 working on frame matrices or not. */ 2658 working on frame matrices or not. */
2659 2659
2660static inline void 2660static void
2661set_frame_matrix_frame (struct frame *f) 2661set_frame_matrix_frame (struct frame *f)
2662{ 2662{
2663 frame_matrix_frame = f; 2663 frame_matrix_frame = f;
@@ -2672,7 +2672,7 @@ set_frame_matrix_frame (struct frame *f)
2672 done in frame matrices, and that we have to perform analogous 2672 done in frame matrices, and that we have to perform analogous
2673 operations in window matrices of frame_matrix_frame. */ 2673 operations in window matrices of frame_matrix_frame. */
2674 2674
2675static inline void 2675static void
2676make_current (struct glyph_matrix *desired_matrix, struct glyph_matrix *current_matrix, int row) 2676make_current (struct glyph_matrix *desired_matrix, struct glyph_matrix *current_matrix, int row)
2677{ 2677{
2678 struct glyph_row *current_row = MATRIX_ROW (current_matrix, row); 2678 struct glyph_row *current_row = MATRIX_ROW (current_matrix, row);
@@ -4158,7 +4158,7 @@ static struct run **runs;
4158 4158
4159/* Add glyph row ROW to the scrolling hash table. */ 4159/* Add glyph row ROW to the scrolling hash table. */
4160 4160
4161static inline struct row_entry * 4161static struct row_entry *
4162add_row_entry (struct glyph_row *row) 4162add_row_entry (struct glyph_row *row)
4163{ 4163{
4164 struct row_entry *entry; 4164 struct row_entry *entry;
@@ -5563,10 +5563,6 @@ handle_window_change_signal (int sig)
5563 int width, height; 5563 int width, height;
5564 struct tty_display_info *tty; 5564 struct tty_display_info *tty;
5565 5565
5566 struct sigaction action;
5567 emacs_sigaction_init (&action, deliver_window_change_signal);
5568 sigaction (SIGWINCH, &action, 0);
5569
5570 /* The frame size change obviously applies to a single 5566 /* The frame size change obviously applies to a single
5571 termcap-controlled terminal, but we can't decide which. 5567 termcap-controlled terminal, but we can't decide which.
5572 Therefore, we resize the frames corresponding to each tty. 5568 Therefore, we resize the frames corresponding to each tty.
@@ -5599,7 +5595,7 @@ handle_window_change_signal (int sig)
5599static void 5595static void
5600deliver_window_change_signal (int sig) 5596deliver_window_change_signal (int sig)
5601{ 5597{
5602 handle_on_main_thread (sig, handle_window_change_signal); 5598 deliver_process_signal (sig, handle_window_change_signal);
5603} 5599}
5604#endif /* SIGWINCH */ 5600#endif /* SIGWINCH */
5605 5601
@@ -5708,7 +5704,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth,
5708 && new_frame_total_cols == FRAME_TOTAL_COLS (f)) 5704 && new_frame_total_cols == FRAME_TOTAL_COLS (f))
5709 return; 5705 return;
5710 5706
5711 BLOCK_INPUT; 5707 block_input ();
5712 5708
5713#ifdef MSDOS 5709#ifdef MSDOS
5714 /* We only can set screen dimensions to certain values supported 5710 /* We only can set screen dimensions to certain values supported
@@ -5760,7 +5756,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth,
5760 SET_FRAME_GARBAGED (f); 5756 SET_FRAME_GARBAGED (f);
5761 f->resized_p = 1; 5757 f->resized_p = 1;
5762 5758
5763 UNBLOCK_INPUT; 5759 unblock_input ();
5764 5760
5765 record_unwind_current_buffer (); 5761 record_unwind_current_buffer ();
5766 5762
@@ -5791,9 +5787,9 @@ FILE = nil means just close any termscript file currently open. */)
5791 5787
5792 if (tty->termscript != 0) 5788 if (tty->termscript != 0)
5793 { 5789 {
5794 BLOCK_INPUT; 5790 block_input ();
5795 fclose (tty->termscript); 5791 fclose (tty->termscript);
5796 UNBLOCK_INPUT; 5792 unblock_input ();
5797 } 5793 }
5798 tty->termscript = 0; 5794 tty->termscript = 0;
5799 5795
@@ -5824,7 +5820,7 @@ when TERMINAL is nil. */)
5824 5820
5825 /* ??? Perhaps we should do something special for multibyte strings here. */ 5821 /* ??? Perhaps we should do something special for multibyte strings here. */
5826 CHECK_STRING (string); 5822 CHECK_STRING (string);
5827 BLOCK_INPUT; 5823 block_input ();
5828 5824
5829 if (!t) 5825 if (!t)
5830 error ("Unknown terminal device"); 5826 error ("Unknown terminal device");
@@ -5849,7 +5845,7 @@ when TERMINAL is nil. */)
5849 } 5845 }
5850 fwrite (SDATA (string), 1, SBYTES (string), out); 5846 fwrite (SDATA (string), 1, SBYTES (string), out);
5851 fflush (out); 5847 fflush (out);
5852 UNBLOCK_INPUT; 5848 unblock_input ();
5853 return Qnil; 5849 return Qnil;
5854} 5850}
5855 5851
@@ -5971,7 +5967,7 @@ sit_for (Lisp_Object timeout, bool reading, int do_display)
5971 5967
5972 5968
5973#ifdef USABLE_SIGIO 5969#ifdef USABLE_SIGIO
5974 gobble_input (0); 5970 gobble_input ();
5975#endif 5971#endif
5976 5972
5977 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display, 5973 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
diff --git a/src/dosfns.c b/src/dosfns.c
index 3c649f4d534..ce1ec4a4f93 100644
--- a/src/dosfns.c
+++ b/src/dosfns.c
@@ -480,9 +480,9 @@ x_set_title (struct frame *f, Lisp_Object name)
480 480
481 if (FRAME_MSDOS_P (f)) 481 if (FRAME_MSDOS_P (f))
482 { 482 {
483 BLOCK_INPUT; 483 block_input ();
484 w95_set_virtual_machine_title (SDATA (name)); 484 w95_set_virtual_machine_title (SDATA (name));
485 UNBLOCK_INPUT; 485 unblock_input ();
486 } 486 }
487} 487}
488#endif /* !HAVE_X_WINDOWS */ 488#endif /* !HAVE_X_WINDOWS */
diff --git a/src/editfns.c b/src/editfns.c
index c6744648bc5..fc6465a3d46 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -738,17 +738,18 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
738DEFUN ("line-beginning-position", 738DEFUN ("line-beginning-position",
739 Fline_beginning_position, Sline_beginning_position, 0, 1, 0, 739 Fline_beginning_position, Sline_beginning_position, 0, 1, 0,
740 doc: /* Return the character position of the first character on the current line. 740 doc: /* Return the character position of the first character on the current line.
741With argument N not nil or 1, move forward N - 1 lines first. 741With optional argument N, scan forward N - 1 lines first.
742If scan reaches end of buffer, return that position. 742If the scan reaches the end of the buffer, return that position.
743 743
744The returned position is of the first character in the logical order, 744This function ignores text display directionality; it returns the
745i.e. the one that has the smallest character position. 745position of the first character in logical order, i.e. the smallest
746character position on the line.
746 747
747This function constrains the returned position to the current field 748This function constrains the returned position to the current field
748unless that would be on a different line than the original, 749unless that position would be on a different line than the original,
749unconstrained result. If N is nil or 1, and a front-sticky field 750unconstrained result. If N is nil or 1, and a front-sticky field
750starts at point, the scan stops as soon as it starts. To ignore field 751starts at point, the scan stops as soon as it starts. To ignore field
751boundaries bind `inhibit-field-text-motion' to t. 752boundaries, bind `inhibit-field-text-motion' to t.
752 753
753This function does not move point. */) 754This function does not move point. */)
754 (Lisp_Object n) 755 (Lisp_Object n)
@@ -782,8 +783,9 @@ DEFUN ("line-end-position", Fline_end_position, Sline_end_position, 0, 1, 0,
782With argument N not nil or 1, move forward N - 1 lines first. 783With argument N not nil or 1, move forward N - 1 lines first.
783If scan reaches end of buffer, return that position. 784If scan reaches end of buffer, return that position.
784 785
785The returned position is of the last character in the logical order, 786This function ignores text display directionality; it returns the
786i.e. the character whose buffer position is the largest one. 787position of the last character in logical order, i.e. the largest
788character position on the line.
787 789
788This function constrains the returned position to the current field 790This function constrains the returned position to the current field
789unless that would be on a different line than the original, 791unless that would be on a different line than the original,
@@ -1217,9 +1219,9 @@ of the user with that uid, or nil if there is no such user. */)
1217 return Vuser_login_name; 1219 return Vuser_login_name;
1218 1220
1219 CONS_TO_INTEGER (uid, uid_t, id); 1221 CONS_TO_INTEGER (uid, uid_t, id);
1220 BLOCK_INPUT; 1222 block_input ();
1221 pw = getpwuid (id); 1223 pw = getpwuid (id);
1222 UNBLOCK_INPUT; 1224 unblock_input ();
1223 return (pw ? build_string (pw->pw_name) : Qnil); 1225 return (pw ? build_string (pw->pw_name) : Qnil);
1224} 1226}
1225 1227
@@ -1277,15 +1279,15 @@ name, or nil if there is no such user. */)
1277 { 1279 {
1278 uid_t u; 1280 uid_t u;
1279 CONS_TO_INTEGER (uid, uid_t, u); 1281 CONS_TO_INTEGER (uid, uid_t, u);
1280 BLOCK_INPUT; 1282 block_input ();
1281 pw = getpwuid (u); 1283 pw = getpwuid (u);
1282 UNBLOCK_INPUT; 1284 unblock_input ();
1283 } 1285 }
1284 else if (STRINGP (uid)) 1286 else if (STRINGP (uid))
1285 { 1287 {
1286 BLOCK_INPUT; 1288 block_input ();
1287 pw = getpwnam (SSDATA (uid)); 1289 pw = getpwnam (SSDATA (uid));
1288 UNBLOCK_INPUT; 1290 unblock_input ();
1289 } 1291 }
1290 else 1292 else
1291 error ("Invalid UID specification"); 1293 error ("Invalid UID specification");
@@ -1761,14 +1763,14 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1761 while (1) 1763 while (1)
1762 { 1764 {
1763 time_t *taddr = emacs_secs_addr (&t); 1765 time_t *taddr = emacs_secs_addr (&t);
1764 BLOCK_INPUT; 1766 block_input ();
1765 1767
1766 synchronize_system_time_locale (); 1768 synchronize_system_time_locale ();
1767 1769
1768 tm = ut ? gmtime (taddr) : localtime (taddr); 1770 tm = ut ? gmtime (taddr) : localtime (taddr);
1769 if (! tm) 1771 if (! tm)
1770 { 1772 {
1771 UNBLOCK_INPUT; 1773 unblock_input ();
1772 time_overflow (); 1774 time_overflow ();
1773 } 1775 }
1774 *tmp = *tm; 1776 *tmp = *tm;
@@ -1780,14 +1782,14 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1780 1782
1781 /* Buffer was too small, so make it bigger and try again. */ 1783 /* Buffer was too small, so make it bigger and try again. */
1782 len = emacs_nmemftime (NULL, SIZE_MAX, format, formatlen, tm, ut, ns); 1784 len = emacs_nmemftime (NULL, SIZE_MAX, format, formatlen, tm, ut, ns);
1783 UNBLOCK_INPUT; 1785 unblock_input ();
1784 if (STRING_BYTES_BOUND <= len) 1786 if (STRING_BYTES_BOUND <= len)
1785 string_overflow (); 1787 string_overflow ();
1786 size = len + 1; 1788 size = len + 1;
1787 buf = SAFE_ALLOCA (size); 1789 buf = SAFE_ALLOCA (size);
1788 } 1790 }
1789 1791
1790 UNBLOCK_INPUT; 1792 unblock_input ();
1791 bufstring = make_unibyte_string (buf, len); 1793 bufstring = make_unibyte_string (buf, len);
1792 SAFE_FREE (); 1794 SAFE_FREE ();
1793 return code_convert_string_norecord (bufstring, Vlocale_coding_system, 0); 1795 return code_convert_string_norecord (bufstring, Vlocale_coding_system, 0);
@@ -1815,11 +1817,11 @@ DOW and ZONE.) */)
1815 struct tm *decoded_time; 1817 struct tm *decoded_time;
1816 Lisp_Object list_args[9]; 1818 Lisp_Object list_args[9];
1817 1819
1818 BLOCK_INPUT; 1820 block_input ();
1819 decoded_time = localtime (&time_spec); 1821 decoded_time = localtime (&time_spec);
1820 if (decoded_time) 1822 if (decoded_time)
1821 save_tm = *decoded_time; 1823 save_tm = *decoded_time;
1822 UNBLOCK_INPUT; 1824 unblock_input ();
1823 if (! (decoded_time 1825 if (! (decoded_time
1824 && MOST_NEGATIVE_FIXNUM - TM_YEAR_BASE <= save_tm.tm_year 1826 && MOST_NEGATIVE_FIXNUM - TM_YEAR_BASE <= save_tm.tm_year
1825 && save_tm.tm_year <= MOST_POSITIVE_FIXNUM - TM_YEAR_BASE)) 1827 && save_tm.tm_year <= MOST_POSITIVE_FIXNUM - TM_YEAR_BASE))
@@ -1835,13 +1837,13 @@ DOW and ZONE.) */)
1835 XSETFASTINT (list_args[6], save_tm.tm_wday); 1837 XSETFASTINT (list_args[6], save_tm.tm_wday);
1836 list_args[7] = save_tm.tm_isdst ? Qt : Qnil; 1838 list_args[7] = save_tm.tm_isdst ? Qt : Qnil;
1837 1839
1838 BLOCK_INPUT; 1840 block_input ();
1839 decoded_time = gmtime (&time_spec); 1841 decoded_time = gmtime (&time_spec);
1840 if (decoded_time == 0) 1842 if (decoded_time == 0)
1841 list_args[8] = Qnil; 1843 list_args[8] = Qnil;
1842 else 1844 else
1843 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time)); 1845 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time));
1844 UNBLOCK_INPUT; 1846 unblock_input ();
1845 return Flist (9, list_args); 1847 return Flist (9, list_args);
1846} 1848}
1847 1849
@@ -1899,9 +1901,9 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1899 zone = XCAR (zone); 1901 zone = XCAR (zone);
1900 if (NILP (zone)) 1902 if (NILP (zone))
1901 { 1903 {
1902 BLOCK_INPUT; 1904 block_input ();
1903 value = mktime (&tm); 1905 value = mktime (&tm);
1904 UNBLOCK_INPUT; 1906 unblock_input ();
1905 } 1907 }
1906 else 1908 else
1907 { 1909 {
@@ -1926,7 +1928,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1926 else 1928 else
1927 error ("Invalid time zone specification"); 1929 error ("Invalid time zone specification");
1928 1930
1929 BLOCK_INPUT; 1931 block_input ();
1930 1932
1931 /* Set TZ before calling mktime; merely adjusting mktime's returned 1933 /* Set TZ before calling mktime; merely adjusting mktime's returned
1932 value doesn't suffice, since that would mishandle leap seconds. */ 1934 value doesn't suffice, since that would mishandle leap seconds. */
@@ -1940,7 +1942,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1940#ifdef LOCALTIME_CACHE 1942#ifdef LOCALTIME_CACHE
1941 tzset (); 1943 tzset ();
1942#endif 1944#endif
1943 UNBLOCK_INPUT; 1945 unblock_input ();
1944 1946
1945 xfree (newenv); 1947 xfree (newenv);
1946 } 1948 }
@@ -1976,7 +1978,7 @@ but this is considered obsolete. */)
1976 newline, and without the 4-digit year limit. Don't use asctime 1978 newline, and without the 4-digit year limit. Don't use asctime
1977 or ctime, as they might dump core if the year is outside the 1979 or ctime, as they might dump core if the year is outside the
1978 range -999 .. 9999. */ 1980 range -999 .. 9999. */
1979 BLOCK_INPUT; 1981 block_input ();
1980 tm = localtime (&value); 1982 tm = localtime (&value);
1981 if (tm) 1983 if (tm)
1982 { 1984 {
@@ -1992,7 +1994,7 @@ but this is considered obsolete. */)
1992 tm->tm_hour, tm->tm_min, tm->tm_sec, 1994 tm->tm_hour, tm->tm_min, tm->tm_sec,
1993 tm->tm_year + year_base); 1995 tm->tm_year + year_base);
1994 } 1996 }
1995 UNBLOCK_INPUT; 1997 unblock_input ();
1996 if (! tm) 1998 if (! tm)
1997 time_overflow (); 1999 time_overflow ();
1998 2000
@@ -2048,11 +2050,11 @@ the data it can't find. */)
2048 zone_offset = Qnil; 2050 zone_offset = Qnil;
2049 value = make_emacs_time (lisp_seconds_argument (specified_time), 0); 2051 value = make_emacs_time (lisp_seconds_argument (specified_time), 0);
2050 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); 2052 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
2051 BLOCK_INPUT; 2053 block_input ();
2052 t = gmtime (emacs_secs_addr (&value)); 2054 t = gmtime (emacs_secs_addr (&value));
2053 if (t) 2055 if (t)
2054 offset = tm_diff (&localtm, t); 2056 offset = tm_diff (&localtm, t);
2055 UNBLOCK_INPUT; 2057 unblock_input ();
2056 2058
2057 if (t) 2059 if (t)
2058 { 2060 {
@@ -2099,7 +2101,7 @@ only the former. */)
2099 if (! (NILP (tz) || EQ (tz, Qt))) 2101 if (! (NILP (tz) || EQ (tz, Qt)))
2100 CHECK_STRING (tz); 2102 CHECK_STRING (tz);
2101 2103
2102 BLOCK_INPUT; 2104 block_input ();
2103 2105
2104 /* When called for the first time, save the original TZ. */ 2106 /* When called for the first time, save the original TZ. */
2105 old_environbuf = environbuf; 2107 old_environbuf = environbuf;
@@ -2116,7 +2118,7 @@ only the former. */)
2116 set_time_zone_rule (tzstring); 2118 set_time_zone_rule (tzstring);
2117 environbuf = environ; 2119 environbuf = environ;
2118 2120
2119 UNBLOCK_INPUT; 2121 unblock_input ();
2120 2122
2121 xfree (old_environbuf); 2123 xfree (old_environbuf);
2122 return Qnil; 2124 return Qnil;
diff --git a/src/emacs.c b/src/emacs.c
index 80d536a5c14..6cc50a23d66 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -27,11 +27,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27#include <sys/file.h> 27#include <sys/file.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#include "lisp.h" 30#include <ignore-value.h>
31 31
32#ifdef HAVE_WINDOW_SYSTEM 32#include "lisp.h"
33#include TERM_HEADER
34#endif /* HAVE_WINDOW_SYSTEM */
35 33
36#ifdef WINDOWSNT 34#ifdef WINDOWSNT
37#include <fcntl.h> 35#include <fcntl.h>
@@ -51,6 +49,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#include "cygw32.h" 49#include "cygw32.h"
52#endif 50#endif
53 51
52#ifdef HAVE_WINDOW_SYSTEM
53#include TERM_HEADER
54#endif /* HAVE_WINDOW_SYSTEM */
55
54#ifdef NS_IMPL_GNUSTEP 56#ifdef NS_IMPL_GNUSTEP
55/* At least under Debian, GSConfig is in a subdirectory. --Stef */ 57/* At least under Debian, GSConfig is in a subdirectory. --Stef */
56#include <GNUstepBase/GSConfig.h> 58#include <GNUstepBase/GSConfig.h>
@@ -63,6 +65,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
63#include "window.h" 65#include "window.h"
64 66
65#include "systty.h" 67#include "systty.h"
68#include "atimer.h"
66#include "blockinput.h" 69#include "blockinput.h"
67#include "syssignal.h" 70#include "syssignal.h"
68#include "process.h" 71#include "process.h"
@@ -104,6 +107,11 @@ static const char emacs_copyright[] = COPYRIGHT;
104/* Empty lisp strings. To avoid having to build any others. */ 107/* Empty lisp strings. To avoid having to build any others. */
105Lisp_Object empty_unibyte_string, empty_multibyte_string; 108Lisp_Object empty_unibyte_string, empty_multibyte_string;
106 109
110#ifdef WINDOWSNT
111/* Cache for externally loaded libraries. */
112Lisp_Object Vlibrary_cache;
113#endif
114
107/* Set after Emacs has started up the first time. 115/* Set after Emacs has started up the first time.
108 Prevents reinitialization of the Lisp world and keymaps 116 Prevents reinitialization of the Lisp world and keymaps
109 on subsequent starts. */ 117 on subsequent starts. */
@@ -294,9 +302,6 @@ Report bugs to bug-gnu-emacs@gnu.org. First, please see the Bugs\n\
294section of the Emacs manual or the file BUGS.\n" 302section of the Emacs manual or the file BUGS.\n"
295 303
296 304
297/* Signal code for the fatal signal that was received. */
298static int fatal_error_code;
299
300/* True if handling a fatal error already. */ 305/* True if handling a fatal error already. */
301bool fatal_error_in_progress; 306bool fatal_error_in_progress;
302 307
@@ -307,28 +312,13 @@ static void *ns_pool;
307 312
308 313
309 314
310/* Handle bus errors, invalid instruction, etc. */
311static void
312handle_fatal_signal (int sig)
313{
314 fatal_error_backtrace (sig, 10);
315}
316
317static void
318deliver_fatal_signal (int sig)
319{
320 handle_on_main_thread (sig, handle_fatal_signal);
321}
322
323/* Report a fatal error due to signal SIG, output a backtrace of at 315/* Report a fatal error due to signal SIG, output a backtrace of at
324 most BACKTRACE_LIMIT lines, and exit. */ 316 most BACKTRACE_LIMIT lines, and exit. */
325_Noreturn void 317_Noreturn void
326fatal_error_backtrace (int sig, int backtrace_limit) 318terminate_due_to_signal (int sig, int backtrace_limit)
327{ 319{
328 fatal_error_code = sig;
329 signal (sig, SIG_DFL); 320 signal (sig, SIG_DFL);
330 321 totally_unblock_input ();
331 TOTALLY_UNBLOCK_INPUT;
332 322
333 /* If fatal error occurs in code below, avoid infinite recursion. */ 323 /* If fatal error occurs in code below, avoid infinite recursion. */
334 if (! fatal_error_in_progress) 324 if (! fatal_error_in_progress)
@@ -343,19 +333,18 @@ fatal_error_backtrace (int sig, int backtrace_limit)
343 } 333 }
344 334
345 /* Signal the same code; this time it will really be fatal. 335 /* Signal the same code; this time it will really be fatal.
346 Remember that since we're in a signal handler, the signal we're 336 Since we're in a signal handler, the signal is blocked, so we
347 going to send is probably blocked, so we have to unblock it if we 337 have to unblock it if we want to really receive it. */
348 want to really receive it. */
349#ifndef MSDOS 338#ifndef MSDOS
350 { 339 {
351 sigset_t unblocked; 340 sigset_t unblocked;
352 sigemptyset (&unblocked); 341 sigemptyset (&unblocked);
353 sigaddset (&unblocked, fatal_error_code); 342 sigaddset (&unblocked, sig);
354 pthread_sigmask (SIG_UNBLOCK, &unblocked, 0); 343 pthread_sigmask (SIG_UNBLOCK, &unblocked, 0);
355 } 344 }
356#endif 345#endif
357 346
358 kill (getpid (), fatal_error_code); 347 emacs_raise (sig);
359 348
360 /* This shouldn't be executed, but it prevents a warning. */ 349 /* This shouldn't be executed, but it prevents a warning. */
361 exit (1); 350 exit (1);
@@ -364,15 +353,9 @@ fatal_error_backtrace (int sig, int backtrace_limit)
364#ifdef SIGDANGER 353#ifdef SIGDANGER
365 354
366/* Handler for SIGDANGER. */ 355/* Handler for SIGDANGER. */
367static void deliver_danger_signal (int);
368
369static void 356static void
370handle_danger_signal (int sig) 357handle_danger_signal (int sig)
371{ 358{
372 struct sigaction action;
373 emacs_sigaction_init (&action, deliver_danger_signal);
374 sigaction (sig, &action, 0);
375
376 malloc_warning ("Operating system warns that virtual memory is running low.\n"); 359 malloc_warning ("Operating system warns that virtual memory is running low.\n");
377 360
378 /* It might be unsafe to call do_auto_save now. */ 361 /* It might be unsafe to call do_auto_save now. */
@@ -382,7 +365,7 @@ handle_danger_signal (int sig)
382static void 365static void
383deliver_danger_signal (int sig) 366deliver_danger_signal (int sig)
384{ 367{
385 handle_on_main_thread (sig, handle_danger_signal); 368 deliver_process_signal (sig, handle_danger_signal);
386} 369}
387#endif 370#endif
388 371
@@ -705,6 +688,7 @@ main (int argc, char **argv)
705#endif 688#endif
706 char stack_bottom_variable; 689 char stack_bottom_variable;
707 bool do_initial_setlocale; 690 bool do_initial_setlocale;
691 bool dumping;
708 int skip_args = 0; 692 int skip_args = 0;
709#ifdef HAVE_SETRLIMIT 693#ifdef HAVE_SETRLIMIT
710 struct rlimit rlim; 694 struct rlimit rlim;
@@ -716,7 +700,6 @@ main (int argc, char **argv)
716 char dname_arg2[80]; 700 char dname_arg2[80];
717#endif /* DAEMON_MUST_EXEC */ 701#endif /* DAEMON_MUST_EXEC */
718 char *ch_to_dir; 702 char *ch_to_dir;
719 struct sigaction fatal_error_action;
720 703
721#if GC_MARK_STACK 704#if GC_MARK_STACK
722 stack_base = &dummy; 705 stack_base = &dummy;
@@ -802,12 +785,11 @@ main (int argc, char **argv)
802 exit (1); 785 exit (1);
803 } 786 }
804 787
788 dumping = !initialized && (strcmp (argv[argc - 1], "dump") == 0
789 || strcmp (argv[argc - 1], "bootstrap") == 0);
805 790
806#ifdef HAVE_PERSONALITY_LINUX32 791#ifdef HAVE_PERSONALITY_LINUX32
807 if (!initialized 792 if (dumping && ! getenv ("EMACS_HEAP_EXEC"))
808 && (strcmp (argv[argc-1], "dump") == 0
809 || strcmp (argv[argc-1], "bootstrap") == 0)
810 && ! getenv ("EMACS_HEAP_EXEC"))
811 { 793 {
812 static char heapexec[] = "EMACS_HEAP_EXEC=true"; 794 static char heapexec[] = "EMACS_HEAP_EXEC=true";
813 /* Set this so we only do this once. */ 795 /* Set this so we only do this once. */
@@ -1126,119 +1108,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1126#endif 1108#endif
1127 } 1109 }
1128 1110
1129 init_signals (); 1111 init_signals (dumping);
1130 emacs_sigaction_init (&fatal_error_action, deliver_fatal_signal);
1131
1132 /* Don't catch SIGHUP if dumping. */
1133 if (1
1134#ifndef CANNOT_DUMP
1135 && initialized
1136#endif
1137 )
1138 {
1139 /* In --batch mode, don't catch SIGHUP if already ignored.
1140 That makes nohup work. */
1141 bool catch_SIGHUP = !noninteractive;
1142 if (!catch_SIGHUP)
1143 {
1144 struct sigaction old_action;
1145 sigaction (SIGHUP, 0, &old_action);
1146 catch_SIGHUP = old_action.sa_handler != SIG_IGN;
1147 }
1148 if (catch_SIGHUP)
1149 sigaction (SIGHUP, &fatal_error_action, 0);
1150 }
1151
1152 if (
1153#ifndef CANNOT_DUMP
1154 ! noninteractive || initialized
1155#else
1156 1
1157#endif
1158 )
1159 {
1160 /* Don't catch these signals in batch mode if dumping.
1161 On some machines, this sets static data that would make
1162 signal fail to work right when the dumped Emacs is run. */
1163 sigaction (SIGQUIT, &fatal_error_action, 0);
1164 sigaction (SIGILL, &fatal_error_action, 0);
1165 sigaction (SIGTRAP, &fatal_error_action, 0);
1166#ifdef SIGUSR1
1167 add_user_signal (SIGUSR1, "sigusr1");
1168#endif
1169#ifdef SIGUSR2
1170 add_user_signal (SIGUSR2, "sigusr2");
1171#endif
1172#ifdef SIGABRT
1173 sigaction (SIGABRT, &fatal_error_action, 0);
1174#endif
1175#ifdef SIGHWE
1176 sigaction (SIGHWE, &fatal_error_action, 0);
1177#endif
1178#ifdef SIGPRE
1179 sigaction (SIGPRE, &fatal_error_action, 0);
1180#endif
1181#ifdef SIGORE
1182 sigaction (SIGORE, &fatal_error_action, 0);
1183#endif
1184#ifdef SIGUME
1185 sigaction (SIGUME, &fatal_error_action, 0);
1186#endif
1187#ifdef SIGDLK
1188 sigaction (SIGDLK, &fatal_error_action, 0);
1189#endif
1190#ifdef SIGCPULIM
1191 sigaction (SIGCPULIM, &fatal_error_action, 0);
1192#endif
1193#ifdef SIGIOT
1194 /* This is missing on some systems - OS/2, for example. */
1195 sigaction (SIGIOT, &fatal_error_action, 0);
1196#endif
1197#ifdef SIGEMT
1198 sigaction (SIGEMT, &fatal_error_action, 0);
1199#endif
1200 sigaction (SIGFPE, &fatal_error_action, 0);
1201#ifdef SIGBUS
1202 sigaction (SIGBUS, &fatal_error_action, 0);
1203#endif
1204 sigaction (SIGSEGV, &fatal_error_action, 0);
1205#ifdef SIGSYS
1206 sigaction (SIGSYS, &fatal_error_action, 0);
1207#endif
1208 /* May need special treatment on MS-Windows. See
1209 http://lists.gnu.org/archive/html/emacs-devel/2010-09/msg01062.html
1210 Please update the doc of kill-emacs, kill-emacs-hook, and
1211 NEWS if you change this.
1212 */
1213 if (noninteractive)
1214 sigaction (SIGINT, &fatal_error_action, 0);
1215 sigaction (SIGTERM, &fatal_error_action, 0);
1216#ifdef SIGXCPU
1217 sigaction (SIGXCPU, &fatal_error_action, 0);
1218#endif
1219#ifdef SIGXFSZ
1220 sigaction (SIGXFSZ, &fatal_error_action, 0);
1221#endif /* SIGXFSZ */
1222
1223#ifdef SIGDANGER
1224 /* This just means available memory is getting low. */
1225 {
1226 struct sigaction action;
1227 emacs_sigaction_init (&action, deliver_danger_signal);
1228 sigaction (SIGDANGER, &action, 0);
1229 }
1230#endif
1231
1232#ifdef AIX
1233/* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
1234 sigaction (SIGXCPU, &fatal_error_action, 0);
1235 sigaction (SIGIOINT, &fatal_error_action, 0);
1236 sigaction (SIGGRANT, &fatal_error_action, 0);
1237 sigaction (SIGRETRACT, &fatal_error_action, 0);
1238 sigaction (SIGSOUND, &fatal_error_action, 0);
1239 sigaction (SIGMSG, &fatal_error_action, 0);
1240#endif /* AIX */
1241 }
1242 1112
1243 noninteractive1 = noninteractive; 1113 noninteractive1 = noninteractive;
1244 1114
@@ -1300,7 +1170,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1300 } 1170 }
1301 1171
1302 init_eval (); 1172 init_eval ();
1303 init_data ();
1304 init_atimer (); 1173 init_atimer ();
1305 running_asynch_code = 0; 1174 running_asynch_code = 0;
1306 init_random (); 1175 init_random ();
@@ -1415,7 +1284,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1415 globals_of_w32 (); 1284 globals_of_w32 ();
1416 /* Initialize environment from registry settings. */ 1285 /* Initialize environment from registry settings. */
1417 init_environment (argv); 1286 init_environment (argv);
1418 init_ntproc (); /* must precede init_editfns. */ 1287 init_ntproc (dumping); /* must precede init_editfns. */
1419#endif 1288#endif
1420 1289
1421 /* Initialize and GC-protect Vinitial_environment and 1290 /* Initialize and GC-protect Vinitial_environment and
@@ -1426,8 +1295,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1426 /* egetenv is a pretty low-level facility, which may get called in 1295 /* egetenv is a pretty low-level facility, which may get called in
1427 many circumstances; it seems flimsy to put off initializing it 1296 many circumstances; it seems flimsy to put off initializing it
1428 until calling init_callproc. Do not do it when dumping. */ 1297 until calling init_callproc. Do not do it when dumping. */
1429 if (initialized || ((strcmp (argv[argc-1], "dump") != 0 1298 if (! dumping)
1430 && strcmp (argv[argc-1], "bootstrap") != 0)))
1431 set_initial_environment (); 1299 set_initial_environment ();
1432 1300
1433 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4 1301 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
@@ -1578,6 +1446,8 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1578 syms_of_ntterm (); 1446 syms_of_ntterm ();
1579#endif /* WINDOWSNT */ 1447#endif /* WINDOWSNT */
1580 1448
1449 syms_of_profiler ();
1450
1581 keys_of_casefiddle (); 1451 keys_of_casefiddle ();
1582 keys_of_cmds (); 1452 keys_of_cmds ();
1583 keys_of_buffer (); 1453 keys_of_buffer ();
@@ -2042,7 +1912,14 @@ shut_down_emacs (int sig, Lisp_Object stuff)
2042 { 1912 {
2043 reset_all_sys_modes (); 1913 reset_all_sys_modes ();
2044 if (sig && sig != SIGTERM) 1914 if (sig && sig != SIGTERM)
2045 fprintf (stderr, "Fatal error %d: %s", sig, strsignal (sig)); 1915 {
1916 static char const format[] = "Fatal error %d: ";
1917 char buf[sizeof format - 2 + INT_STRLEN_BOUND (int)];
1918 int buflen = sprintf (buf, format, sig);
1919 char const *sig_desc = safe_strsignal (sig);
1920 ignore_value (write (STDERR_FILENO, buf, buflen));
1921 ignore_value (write (STDERR_FILENO, sig_desc, strlen (sig_desc)));
1922 }
2046 } 1923 }
2047 } 1924 }
2048#else 1925#else
@@ -2065,10 +1942,6 @@ shut_down_emacs (int sig, Lisp_Object stuff)
2065 unrequest_sigio (); 1942 unrequest_sigio ();
2066 ignore_sigio (); 1943 ignore_sigio ();
2067 1944
2068#ifdef WINDOWSNT
2069 term_ntproc ();
2070#endif
2071
2072 /* Do this only if terminating normally, we want glyph matrices 1945 /* Do this only if terminating normally, we want glyph matrices
2073 etc. in a core dump. */ 1946 etc. in a core dump. */
2074 if (sig == 0 || sig == SIGTERM) 1947 if (sig == 0 || sig == SIGTERM)
@@ -2088,6 +1961,10 @@ shut_down_emacs (int sig, Lisp_Object stuff)
2088#ifdef HAVE_LIBXML2 1961#ifdef HAVE_LIBXML2
2089 xml_cleanup_parser (); 1962 xml_cleanup_parser ();
2090#endif 1963#endif
1964
1965#ifdef WINDOWSNT
1966 term_ntproc (0);
1967#endif
2091} 1968}
2092 1969
2093 1970
@@ -2185,6 +2062,13 @@ You must run Emacs in batch mode in order to dump it. */)
2185 free (malloc_state_ptr); 2062 free (malloc_state_ptr);
2186#endif 2063#endif
2187 2064
2065#ifdef WINDOWSNT
2066 Vlibrary_cache = Qnil;
2067#endif
2068#ifdef HAVE_WINDOW_SYSTEM
2069 reset_image_types ();
2070#endif
2071
2188 Vpurify_flag = tem; 2072 Vpurify_flag = tem;
2189 2073
2190 return unbind_to (count, Qnil); 2074 return unbind_to (count, Qnil);
@@ -2517,6 +2401,11 @@ libraries; only those already known by Emacs will be loaded. */);
2517 Vdynamic_library_alist = Qnil; 2401 Vdynamic_library_alist = Qnil;
2518 Fput (intern_c_string ("dynamic-library-alist"), Qrisky_local_variable, Qt); 2402 Fput (intern_c_string ("dynamic-library-alist"), Qrisky_local_variable, Qt);
2519 2403
2404#ifdef WINDOWSNT
2405 Vlibrary_cache = Qnil;
2406 staticpro (&Vlibrary_cache);
2407#endif
2408
2520 /* Make sure IS_DAEMON starts up as false. */ 2409 /* Make sure IS_DAEMON starts up as false. */
2521 daemon_pipe[1] = 0; 2410 daemon_pipe[1] = 0;
2522} 2411}
diff --git a/src/eval.c b/src/eval.c
index 1c565e233c6..4d200fbc2bd 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -31,17 +31,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include "xterm.h" 31#include "xterm.h"
32#endif 32#endif
33 33
34struct backtrace 34struct backtrace *backtrace_list;
35{
36 struct backtrace *next;
37 Lisp_Object *function;
38 Lisp_Object *args; /* Points to vector of args. */
39 ptrdiff_t nargs; /* Length of vector. */
40 /* Nonzero means call value of debugger when done with this operation. */
41 unsigned int debug_on_exit : 1;
42};
43
44static struct backtrace *backtrace_list;
45 35
46#if !BYTE_MARK_STACK 36#if !BYTE_MARK_STACK
47static 37static
@@ -129,13 +119,13 @@ static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
129 119
130/* Functions to set Lisp_Object slots of struct specbinding. */ 120/* Functions to set Lisp_Object slots of struct specbinding. */
131 121
132static inline void 122static void
133set_specpdl_symbol (Lisp_Object symbol) 123set_specpdl_symbol (Lisp_Object symbol)
134{ 124{
135 specpdl_ptr->symbol = symbol; 125 specpdl_ptr->symbol = symbol;
136} 126}
137 127
138static inline void 128static void
139set_specpdl_old_value (Lisp_Object oldval) 129set_specpdl_old_value (Lisp_Object oldval)
140{ 130{
141 specpdl_ptr->old_value = oldval; 131 specpdl_ptr->old_value = oldval;
@@ -562,7 +552,7 @@ interactive_p (void)
562 552
563 /* If this isn't a byte-compiled function, there may be a frame at 553 /* If this isn't a byte-compiled function, there may be a frame at
564 the top for Finteractive_p. If so, skip it. */ 554 the top for Finteractive_p. If so, skip it. */
565 fun = Findirect_function (*btp->function, Qnil); 555 fun = Findirect_function (btp->function, Qnil);
566 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p 556 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
567 || XSUBR (fun) == &Scalled_interactively_p)) 557 || XSUBR (fun) == &Scalled_interactively_p))
568 btp = btp->next; 558 btp = btp->next;
@@ -575,7 +565,7 @@ interactive_p (void)
575 If this isn't a byte-compiled function, then we may now be 565 If this isn't a byte-compiled function, then we may now be
576 looking at several frames for special forms. Skip past them. */ 566 looking at several frames for special forms. Skip past them. */
577 while (btp 567 while (btp
578 && (EQ (*btp->function, Qbytecode) 568 && (EQ (btp->function, Qbytecode)
579 || btp->nargs == UNEVALLED)) 569 || btp->nargs == UNEVALLED))
580 btp = btp->next; 570 btp = btp->next;
581 571
@@ -583,13 +573,13 @@ interactive_p (void)
583 a special form, ignoring frames for Finteractive_p and/or 573 a special form, ignoring frames for Finteractive_p and/or
584 Fbytecode at the top. If this frame is for a built-in function 574 Fbytecode at the top. If this frame is for a built-in function
585 (such as load or eval-region) return false. */ 575 (such as load or eval-region) return false. */
586 fun = Findirect_function (*btp->function, Qnil); 576 fun = Findirect_function (btp->function, Qnil);
587 if (SUBRP (fun)) 577 if (SUBRP (fun))
588 return 0; 578 return 0;
589 579
590 /* `btp' points to the frame of a Lisp function that called interactive-p. 580 /* `btp' points to the frame of a Lisp function that called interactive-p.
591 Return t if that function was called interactively. */ 581 Return t if that function was called interactively. */
592 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively)) 582 if (btp && btp->next && EQ (btp->next->function, Qcall_interactively))
593 return 1; 583 return 1;
594 return 0; 584 return 0;
595} 585}
@@ -1076,7 +1066,7 @@ internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object
1076/* Unwind the specbind, catch, and handler stacks back to CATCH, and 1066/* Unwind the specbind, catch, and handler stacks back to CATCH, and
1077 jump to that CATCH, returning VALUE as the value of that catch. 1067 jump to that CATCH, returning VALUE as the value of that catch.
1078 1068
1079 This is the guts Fthrow and Fsignal; they differ only in the way 1069 This is the guts of Fthrow and Fsignal; they differ only in the way
1080 they choose the catch tag to throw to. A catch tag for a 1070 they choose the catch tag to throw to. A catch tag for a
1081 condition-case form has a TAG of Qnil. 1071 condition-case form has a TAG of Qnil.
1082 1072
@@ -1085,7 +1075,7 @@ internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object
1085 the handler stack as we go, so that the proper handlers are in 1075 the handler stack as we go, so that the proper handlers are in
1086 effect for each unwind-protect clause we run. At the end, restore 1076 effect for each unwind-protect clause we run. At the end, restore
1087 some static info saved in CATCH, and longjmp to the location 1077 some static info saved in CATCH, and longjmp to the location
1088 specified in the 1078 specified there.
1089 1079
1090 This is used for correct unwinding in Fthrow and Fsignal. */ 1080 This is used for correct unwinding in Fthrow and Fsignal. */
1091 1081
@@ -1099,7 +1089,7 @@ unwind_to_catch (struct catchtag *catch, Lisp_Object value)
1099 1089
1100 /* Restore certain special C variables. */ 1090 /* Restore certain special C variables. */
1101 set_poll_suppress_count (catch->poll_suppress_count); 1091 set_poll_suppress_count (catch->poll_suppress_count);
1102 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked); 1092 unblock_input_to (catch->interrupt_input_blocked);
1103 immediate_quit = 0; 1093 immediate_quit = 0;
1104 1094
1105 do 1095 do
@@ -1114,16 +1104,6 @@ unwind_to_catch (struct catchtag *catch, Lisp_Object value)
1114 } 1104 }
1115 while (! last_time); 1105 while (! last_time);
1116 1106
1117#if HAVE_X_WINDOWS
1118 /* If x_catch_errors was done, turn it off now.
1119 (First we give unbind_to a chance to do that.) */
1120#if 0 /* This would disable x_catch_errors after x_connection_closed.
1121 The catch must remain in effect during that delicate
1122 state. --lorentey */
1123 x_fully_uncatch_errors ();
1124#endif
1125#endif
1126
1127 byte_stack_list = catch->byte_stack; 1107 byte_stack_list = catch->byte_stack;
1128 gcprolist = catch->gcpro; 1108 gcprolist = catch->gcpro;
1129#ifdef DEBUG_GCPRO 1109#ifdef DEBUG_GCPRO
@@ -1516,10 +1496,10 @@ See also the function `condition-case'. */)
1516 if (backtrace_list && !NILP (error_symbol)) 1496 if (backtrace_list && !NILP (error_symbol))
1517 { 1497 {
1518 bp = backtrace_list->next; 1498 bp = backtrace_list->next;
1519 if (bp && bp->function && EQ (*bp->function, Qerror)) 1499 if (bp && EQ (bp->function, Qerror))
1520 bp = bp->next; 1500 bp = bp->next;
1521 if (bp && bp->function) 1501 if (bp)
1522 Vsignaling_function = *bp->function; 1502 Vsignaling_function = bp->function;
1523 } 1503 }
1524 1504
1525 for (h = handlerlist; h; h = h->next) 1505 for (h = handlerlist; h; h = h->next)
@@ -1530,7 +1510,7 @@ See also the function `condition-case'. */)
1530 } 1510 }
1531 1511
1532 if (/* Don't run the debugger for a memory-full error. 1512 if (/* Don't run the debugger for a memory-full error.
1533 (There is no room in memory to do that!) */ 1513 (There is no room in memory to do that!) */
1534 !NILP (error_symbol) 1514 !NILP (error_symbol)
1535 && (!NILP (Vdebug_on_signal) 1515 && (!NILP (Vdebug_on_signal)
1536 /* If no handler is present now, try to run the debugger. */ 1516 /* If no handler is present now, try to run the debugger. */
@@ -1713,7 +1693,7 @@ maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
1713 if ( 1693 if (
1714 /* Don't try to run the debugger with interrupts blocked. 1694 /* Don't try to run the debugger with interrupts blocked.
1715 The editing loop would return anyway. */ 1695 The editing loop would return anyway. */
1716 ! INPUT_BLOCKED_P 1696 ! input_blocked_p ()
1717 && NILP (Vinhibit_debugger) 1697 && NILP (Vinhibit_debugger)
1718 /* Does user want to enter debugger for this kind of error? */ 1698 /* Does user want to enter debugger for this kind of error? */
1719 && (EQ (sig, Qquit) 1699 && (EQ (sig, Qquit)
@@ -2065,11 +2045,11 @@ eval_sub (Lisp_Object form)
2065 original_args = XCDR (form); 2045 original_args = XCDR (form);
2066 2046
2067 backtrace.next = backtrace_list; 2047 backtrace.next = backtrace_list;
2068 backtrace_list = &backtrace; 2048 backtrace.function = original_fun; /* This also protects them from gc. */
2069 backtrace.function = &original_fun; /* This also protects them from gc. */
2070 backtrace.args = &original_args; 2049 backtrace.args = &original_args;
2071 backtrace.nargs = UNEVALLED; 2050 backtrace.nargs = UNEVALLED;
2072 backtrace.debug_on_exit = 0; 2051 backtrace.debug_on_exit = 0;
2052 backtrace_list = &backtrace;
2073 2053
2074 if (debug_on_next_call) 2054 if (debug_on_next_call)
2075 do_debug_on_call (Qt); 2055 do_debug_on_call (Qt);
@@ -2371,14 +2351,10 @@ usage: (run-hooks &rest HOOKS) */)
2371DEFUN ("run-hook-with-args", Frun_hook_with_args, 2351DEFUN ("run-hook-with-args", Frun_hook_with_args,
2372 Srun_hook_with_args, 1, MANY, 0, 2352 Srun_hook_with_args, 1, MANY, 0,
2373 doc: /* Run HOOK with the specified arguments ARGS. 2353 doc: /* Run HOOK with the specified arguments ARGS.
2374HOOK should be a symbol, a hook variable. If HOOK has a non-nil 2354HOOK should be a symbol, a hook variable. The value of HOOK
2375value, that value may be a function or a list of functions to be 2355may be nil, a function, or a list of functions. Call each
2376called to run the hook. If the value is a function, it is called with 2356function in order with arguments ARGS. The final return value
2377the given arguments and its return value is returned. If it is a list 2357is unspecified.
2378of functions, those functions are called, in order,
2379with the given arguments ARGS.
2380It is best not to depend on the value returned by `run-hook-with-args',
2381as that may change.
2382 2358
2383Do not use `make-local-variable' to make a hook variable buffer-local. 2359Do not use `make-local-variable' to make a hook variable buffer-local.
2384Instead, use `add-hook' and specify t for the LOCAL argument. 2360Instead, use `add-hook' and specify t for the LOCAL argument.
@@ -2388,17 +2364,18 @@ usage: (run-hook-with-args HOOK &rest ARGS) */)
2388 return run_hook_with_args (nargs, args, funcall_nil); 2364 return run_hook_with_args (nargs, args, funcall_nil);
2389} 2365}
2390 2366
2367/* NB this one still documents a specific non-nil return value.
2368 (As did run-hook-with-args and run-hook-with-args-until-failure
2369 until they were changed in 24.1.) */
2391DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 2370DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2392 Srun_hook_with_args_until_success, 1, MANY, 0, 2371 Srun_hook_with_args_until_success, 1, MANY, 0,
2393 doc: /* Run HOOK with the specified arguments ARGS. 2372 doc: /* Run HOOK with the specified arguments ARGS.
2394HOOK should be a symbol, a hook variable. If HOOK has a non-nil 2373HOOK should be a symbol, a hook variable. The value of HOOK
2395value, that value may be a function or a list of functions to be 2374may be nil, a function, or a list of functions. Call each
2396called to run the hook. If the value is a function, it is called with 2375function in order with arguments ARGS, stopping at the first
2397the given arguments and its return value is returned. 2376one that returns non-nil, and return that value. Otherwise (if
2398If it is a list of functions, those functions are called, in order, 2377all functions return nil, or if there are no functions to call),
2399with the given arguments ARGS, until one of them 2378return nil.
2400returns a non-nil value. Then we return that value.
2401However, if they all return nil, we return nil.
2402 2379
2403Do not use `make-local-variable' to make a hook variable buffer-local. 2380Do not use `make-local-variable' to make a hook variable buffer-local.
2404Instead, use `add-hook' and specify t for the LOCAL argument. 2381Instead, use `add-hook' and specify t for the LOCAL argument.
@@ -2417,13 +2394,12 @@ funcall_not (ptrdiff_t nargs, Lisp_Object *args)
2417DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 2394DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2418 Srun_hook_with_args_until_failure, 1, MANY, 0, 2395 Srun_hook_with_args_until_failure, 1, MANY, 0,
2419 doc: /* Run HOOK with the specified arguments ARGS. 2396 doc: /* Run HOOK with the specified arguments ARGS.
2420HOOK should be a symbol, a hook variable. If HOOK has a non-nil 2397HOOK should be a symbol, a hook variable. The value of HOOK
2421value, that value may be a function or a list of functions to be 2398may be nil, a function, or a list of functions. Call each
2422called to run the hook. If the value is a function, it is called with 2399function in order with arguments ARGS, stopping at the first
2423the given arguments and its return value is returned. 2400one that returns nil, and return nil. Otherwise (if all functions
2424If it is a list of functions, those functions are called, in order, 2401return non-nil, or if there are no functions to call), return non-nil
2425with the given arguments ARGS, until one of them returns nil. 2402\(do not rely on the precise return value in this case).
2426Then we return nil. However, if they all return non-nil, we return non-nil.
2427 2403
2428Do not use `make-local-variable' to make a hook variable buffer-local. 2404Do not use `make-local-variable' to make a hook variable buffer-local.
2429Instead, use `add-hook' and specify t for the LOCAL argument. 2405Instead, use `add-hook' and specify t for the LOCAL argument.
@@ -2737,11 +2713,11 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2737 } 2713 }
2738 2714
2739 backtrace.next = backtrace_list; 2715 backtrace.next = backtrace_list;
2740 backtrace_list = &backtrace; 2716 backtrace.function = args[0];
2741 backtrace.function = &args[0];
2742 backtrace.args = &args[1]; /* This also GCPROs them. */ 2717 backtrace.args = &args[1]; /* This also GCPROs them. */
2743 backtrace.nargs = nargs - 1; 2718 backtrace.nargs = nargs - 1;
2744 backtrace.debug_on_exit = 0; 2719 backtrace.debug_on_exit = 0;
2720 backtrace_list = &backtrace;
2745 2721
2746 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */ 2722 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2747 maybe_gc (); 2723 maybe_gc ();
@@ -3313,12 +3289,12 @@ Output stream used is value of `standard-output'. */)
3313 write_string (backlist->debug_on_exit ? "* " : " ", 2); 3289 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3314 if (backlist->nargs == UNEVALLED) 3290 if (backlist->nargs == UNEVALLED)
3315 { 3291 {
3316 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil); 3292 Fprin1 (Fcons (backlist->function, *backlist->args), Qnil);
3317 write_string ("\n", -1); 3293 write_string ("\n", -1);
3318 } 3294 }
3319 else 3295 else
3320 { 3296 {
3321 tem = *backlist->function; 3297 tem = backlist->function;
3322 Fprin1 (tem, Qnil); /* This can QUIT. */ 3298 Fprin1 (tem, Qnil); /* This can QUIT. */
3323 write_string ("(", -1); 3299 write_string ("(", -1);
3324 if (backlist->nargs == MANY) 3300 if (backlist->nargs == MANY)
@@ -3376,7 +3352,7 @@ If NFRAMES is more than the number of frames, the value is nil. */)
3376 if (!backlist) 3352 if (!backlist)
3377 return Qnil; 3353 return Qnil;
3378 if (backlist->nargs == UNEVALLED) 3354 if (backlist->nargs == UNEVALLED)
3379 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args)); 3355 return Fcons (Qnil, Fcons (backlist->function, *backlist->args));
3380 else 3356 else
3381 { 3357 {
3382 if (backlist->nargs == MANY) /* FIXME: Can this happen? */ 3358 if (backlist->nargs == MANY) /* FIXME: Can this happen? */
@@ -3384,7 +3360,7 @@ If NFRAMES is more than the number of frames, the value is nil. */)
3384 else 3360 else
3385 tem = Flist (backlist->nargs, backlist->args); 3361 tem = Flist (backlist->nargs, backlist->args);
3386 3362
3387 return Fcons (Qt, Fcons (*backlist->function, tem)); 3363 return Fcons (Qt, Fcons (backlist->function, tem));
3388 } 3364 }
3389} 3365}
3390 3366
diff --git a/src/fileio.c b/src/fileio.c
index ca71af7ed95..b4eda01afcc 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1025,9 +1025,9 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1025 memcpy (o, nm, p - nm); 1025 memcpy (o, nm, p - nm);
1026 o [p - nm] = 0; 1026 o [p - nm] = 0;
1027 1027
1028 BLOCK_INPUT; 1028 block_input ();
1029 pw = (struct passwd *) getpwnam (o + 1); 1029 pw = (struct passwd *) getpwnam (o + 1);
1030 UNBLOCK_INPUT; 1030 unblock_input ();
1031 if (pw) 1031 if (pw)
1032 { 1032 {
1033 newdir = pw->pw_dir; 1033 newdir = pw->pw_dir;
@@ -1413,9 +1413,9 @@ See also the function `substitute-in-file-name'.")
1413 o[len] = 0; 1413 o[len] = 0;
1414 1414
1415 /* Look up the user name. */ 1415 /* Look up the user name. */
1416 BLOCK_INPUT; 1416 block_input ();
1417 pw = (struct passwd *) getpwnam (o + 1); 1417 pw = (struct passwd *) getpwnam (o + 1);
1418 UNBLOCK_INPUT; 1418 unblock_input ();
1419 if (!pw) 1419 if (!pw)
1420 error ("\"%s\" isn't a registered user", o + 1); 1420 error ("\"%s\" isn't a registered user", o + 1);
1421 1421
@@ -1531,9 +1531,9 @@ search_embedded_absfilename (char *nm, char *endp)
1531 /* If we have ~user and `user' exists, discard 1531 /* If we have ~user and `user' exists, discard
1532 everything up to ~. But if `user' does not exist, leave 1532 everything up to ~. But if `user' does not exist, leave
1533 ~user alone, it might be a literal file name. */ 1533 ~user alone, it might be a literal file name. */
1534 BLOCK_INPUT; 1534 block_input ();
1535 pw = getpwnam (o + 1); 1535 pw = getpwnam (o + 1);
1536 UNBLOCK_INPUT; 1536 unblock_input ();
1537 if (pw) 1537 if (pw)
1538 return p; 1538 return p;
1539 } 1539 }
@@ -2833,9 +2833,8 @@ or if SELinux is disabled, or if Emacs lacks SELinux support. */)
2833 if (context_range_get (context)) 2833 if (context_range_get (context))
2834 values[3] = build_string (context_range_get (context)); 2834 values[3] = build_string (context_range_get (context));
2835 context_free (context); 2835 context_free (context);
2836 freecon (con);
2836 } 2837 }
2837 if (con)
2838 freecon (con);
2839 } 2838 }
2840#endif 2839#endif
2841 2840
@@ -2914,12 +2913,10 @@ compiled with SELinux support. */)
2914 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); 2913 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil));
2915 2914
2916 context_free (parsed_con); 2915 context_free (parsed_con);
2916 freecon (con);
2917 } 2917 }
2918 else 2918 else
2919 report_file_error ("Doing lgetfilecon", Fcons (absname, Qnil)); 2919 report_file_error ("Doing lgetfilecon", Fcons (absname, Qnil));
2920
2921 if (con)
2922 freecon (con);
2923 } 2920 }
2924#endif 2921#endif
2925 2922
@@ -3002,10 +2999,10 @@ The value is an integer. */)
3002 mode_t realmask; 2999 mode_t realmask;
3003 Lisp_Object value; 3000 Lisp_Object value;
3004 3001
3005 BLOCK_INPUT; 3002 block_input ();
3006 realmask = umask (0); 3003 realmask = umask (0);
3007 umask (realmask); 3004 umask (realmask);
3008 UNBLOCK_INPUT; 3005 unblock_input ();
3009 3006
3010 XSETINT (value, (~ realmask) & 0777); 3007 XSETINT (value, (~ realmask) & 0777);
3011 return value; 3008 return value;
@@ -3037,7 +3034,7 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
3037 { 3034 {
3038 if (set_file_times (-1, SSDATA (encoded_absname), t, t)) 3035 if (set_file_times (-1, SSDATA (encoded_absname), t, t))
3039 { 3036 {
3040#ifdef DOS_NT 3037#ifdef MSDOS
3041 struct stat st; 3038 struct stat st;
3042 3039
3043 /* Setting times on a directory always fails. */ 3040 /* Setting times on a directory always fails. */
@@ -5238,9 +5235,9 @@ do_auto_save_unwind (Lisp_Object arg) /* used as unwind-protect function */
5238 auto_saving = 0; 5235 auto_saving = 0;
5239 if (stream != NULL) 5236 if (stream != NULL)
5240 { 5237 {
5241 BLOCK_INPUT; 5238 block_input ();
5242 fclose (stream); 5239 fclose (stream);
5243 UNBLOCK_INPUT; 5240 unblock_input ();
5244 } 5241 }
5245 return Qnil; 5242 return Qnil;
5246} 5243}
@@ -5371,7 +5368,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5371 if (STRINGP (BVAR (b, auto_save_file_name)) 5368 if (STRINGP (BVAR (b, auto_save_file_name))
5372 && stream != NULL && do_handled_files == 0) 5369 && stream != NULL && do_handled_files == 0)
5373 { 5370 {
5374 BLOCK_INPUT; 5371 block_input ();
5375 if (!NILP (BVAR (b, filename))) 5372 if (!NILP (BVAR (b, filename)))
5376 { 5373 {
5377 fwrite (SDATA (BVAR (b, filename)), 1, 5374 fwrite (SDATA (BVAR (b, filename)), 1,
@@ -5381,7 +5378,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5381 fwrite (SDATA (BVAR (b, auto_save_file_name)), 1, 5378 fwrite (SDATA (BVAR (b, auto_save_file_name)), 1,
5382 SBYTES (BVAR (b, auto_save_file_name)), stream); 5379 SBYTES (BVAR (b, auto_save_file_name)), stream);
5383 putc ('\n', stream); 5380 putc ('\n', stream);
5384 UNBLOCK_INPUT; 5381 unblock_input ();
5385 } 5382 }
5386 5383
5387 if (!NILP (current_only) 5384 if (!NILP (current_only)
@@ -5523,7 +5520,8 @@ The return value is only relevant for a call to `read-file-name' that happens
5523before any other event (mouse or keypress) is handled. */) 5520before any other event (mouse or keypress) is handled. */)
5524 (void) 5521 (void)
5525{ 5522{
5526#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) 5523#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) \
5524 || defined (HAVE_NS)
5527 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 5525 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
5528 && use_dialog_box 5526 && use_dialog_box
5529 && use_file_dialog 5527 && use_file_dialog
diff --git a/src/floatfns.c b/src/floatfns.c
index 4fe209fcb61..645a5957609 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -31,15 +31,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include <config.h> 31#include <config.h>
32 32
33#include "lisp.h" 33#include "lisp.h"
34#include "syssignal.h"
35
36#include <float.h>
37#if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
38 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
39#define IEEE_FLOATING_POINT 1
40#else
41#define IEEE_FLOATING_POINT 0
42#endif
43 34
44#include <math.h> 35#include <math.h>
45 36
diff --git a/src/fns.c b/src/fns.c
index 42c4f817f29..c999b5b08b9 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -61,8 +61,9 @@ DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0,
61 61
62DEFUN ("random", Frandom, Srandom, 0, 1, 0, 62DEFUN ("random", Frandom, Srandom, 0, 1, 0,
63 doc: /* Return a pseudo-random number. 63 doc: /* Return a pseudo-random number.
64All integers representable in Lisp are equally likely. 64All integers representable in Lisp, i.e. between `most-negative-fixnum'
65 On most systems, this is 29 bits' worth. 65and `most-positive-fixnum', inclusive, are equally likely.
66
66With positive integer LIMIT, return random number in interval [0,LIMIT). 67With positive integer LIMIT, return random number in interval [0,LIMIT).
67With argument t, set the random number seed from the current time and pid. 68With argument t, set the random number seed from the current time and pid.
68Other values of LIMIT are ignored. */) 69Other values of LIMIT are ignored. */)
@@ -1838,13 +1839,6 @@ properties on the list. This function never signals an error. */)
1838 halftail = XCDR (halftail); 1839 halftail = XCDR (halftail);
1839 if (EQ (tail, halftail)) 1840 if (EQ (tail, halftail))
1840 break; 1841 break;
1841
1842#if 0 /* Unsafe version. */
1843 /* This function can be called asynchronously
1844 (setup_coding_system). Don't QUIT in that case. */
1845 if (!interrupt_input_blocked)
1846 QUIT;
1847#endif
1848 } 1842 }
1849 1843
1850 return Qnil; 1844 return Qnil;
@@ -3343,14 +3337,6 @@ Lisp_Object Qeq, Qeql, Qequal;
3343Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness; 3337Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
3344static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value; 3338static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;
3345 3339
3346/* Function prototypes. */
3347
3348static struct Lisp_Hash_Table *check_hash_table (Lisp_Object);
3349static ptrdiff_t get_key_arg (Lisp_Object, ptrdiff_t, Lisp_Object *, char *);
3350static void maybe_resize_hash_table (struct Lisp_Hash_Table *);
3351static bool sweep_weak_table (struct Lisp_Hash_Table *, bool);
3352
3353
3354 3340
3355/*********************************************************************** 3341/***********************************************************************
3356 Utilities 3342 Utilities
@@ -3701,7 +3687,7 @@ copy_hash_table (struct Lisp_Hash_Table *h1)
3701/* Resize hash table H if it's too full. If H cannot be resized 3687/* Resize hash table H if it's too full. If H cannot be resized
3702 because it's already too large, throw an error. */ 3688 because it's already too large, throw an error. */
3703 3689
3704static inline void 3690static void
3705maybe_resize_hash_table (struct Lisp_Hash_Table *h) 3691maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3706{ 3692{
3707 if (NILP (h->next_free)) 3693 if (NILP (h->next_free))
diff --git a/src/font.h b/src/font.h
index 71cb26ccfdc..3035a909efc 100644
--- a/src/font.h
+++ b/src/font.h
@@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#define EMACS_FONT_H 23#define EMACS_FONT_H
24 24
25#include "ccl.h" 25#include "ccl.h"
26#include "frame.h"
26 27
27/* We have three types of Lisp objects related to font. 28/* We have three types of Lisp objects related to font.
28 29
diff --git a/src/fontset.c b/src/fontset.c
index 7295951bc21..da745b31ca1 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1275,7 +1275,7 @@ free_realized_fontsets (Lisp_Object base)
1275 doesn't remove FACE from a cache. Until we find a solution, we 1275 doesn't remove FACE from a cache. Until we find a solution, we
1276 suppress this code, and simply use Fclear_face_cache even though 1276 suppress this code, and simply use Fclear_face_cache even though
1277 that is not efficient. */ 1277 that is not efficient. */
1278 BLOCK_INPUT; 1278 block_input ();
1279 for (id = 0; id < ASIZE (Vfontset_table); id++) 1279 for (id = 0; id < ASIZE (Vfontset_table); id++)
1280 { 1280 {
1281 Lisp_Object this = AREF (Vfontset_table, id); 1281 Lisp_Object this = AREF (Vfontset_table, id);
@@ -1296,7 +1296,7 @@ free_realized_fontsets (Lisp_Object base)
1296 } 1296 }
1297 } 1297 }
1298 } 1298 }
1299 UNBLOCK_INPUT; 1299 unblock_input ();
1300#else /* not 0 */ 1300#else /* not 0 */
1301 /* But, we don't have to call Fclear_face_cache if no fontset has 1301 /* But, we don't have to call Fclear_face_cache if no fontset has
1302 been realized from BASE. */ 1302 been realized from BASE. */
diff --git a/src/frame.c b/src/frame.c
index 73e46eff00f..599d8879169 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -120,12 +120,12 @@ static void x_report_frame_params (struct frame *, Lisp_Object *);
120#endif 120#endif
121 121
122/* These setters are used only in this file, so they can be private. */ 122/* These setters are used only in this file, so they can be private. */
123static inline void 123static void
124fset_buffer_predicate (struct frame *f, Lisp_Object val) 124fset_buffer_predicate (struct frame *f, Lisp_Object val)
125{ 125{
126 f->buffer_predicate = val; 126 f->buffer_predicate = val;
127} 127}
128static inline void 128static void
129fset_minibuffer_window (struct frame *f, Lisp_Object val) 129fset_minibuffer_window (struct frame *f, Lisp_Object val)
130{ 130{
131 f->minibuffer_window = val; 131 f->minibuffer_window = val;
@@ -632,7 +632,7 @@ affects all frames on the same terminal device. */)
632 Lisp_Object terminal; 632 Lisp_Object terminal;
633 633
634 terminal = Fassq (Qterminal, parms); 634 terminal = Fassq (Qterminal, parms);
635 if (!NILP (terminal)) 635 if (CONSP (terminal))
636 { 636 {
637 terminal = XCDR (terminal); 637 terminal = XCDR (terminal);
638 t = get_terminal (terminal, 1); 638 t = get_terminal (terminal, 1);
@@ -3028,9 +3028,9 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
3028void 3028void
3029x_report_frame_params (struct frame *f, Lisp_Object *alistptr) 3029x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3030{ 3030{
3031 char buf[16];
3032 Lisp_Object tem; 3031 Lisp_Object tem;
3033 unsigned long w; 3032 uprintmax_t w;
3033 char buf[INT_BUFSIZE_BOUND (w)];
3034 3034
3035 /* Represent negative positions (off the top or left screen edge) 3035 /* Represent negative positions (off the top or left screen edge)
3036 in a way that Fmodify_frame_parameters will understand correctly. */ 3036 in a way that Fmodify_frame_parameters will understand correctly. */
@@ -3067,17 +3067,17 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3067 MS-Windows it returns a value whose type is HANDLE, which is 3067 MS-Windows it returns a value whose type is HANDLE, which is
3068 actually a pointer. Explicit casting avoids compiler 3068 actually a pointer. Explicit casting avoids compiler
3069 warnings. */ 3069 warnings. */
3070 w = (unsigned long) FRAME_X_WINDOW (f); 3070 w = (uintptr_t) FRAME_X_WINDOW (f);
3071 store_in_alist (alistptr, Qwindow_id, 3071 store_in_alist (alistptr, Qwindow_id,
3072 make_formatted_string (buf, "%lu", w)); 3072 make_formatted_string (buf, "%"pMu, w));
3073#ifdef HAVE_X_WINDOWS 3073#ifdef HAVE_X_WINDOWS
3074#ifdef USE_X_TOOLKIT 3074#ifdef USE_X_TOOLKIT
3075 /* Tooltip frame may not have this widget. */ 3075 /* Tooltip frame may not have this widget. */
3076 if (FRAME_X_OUTPUT (f)->widget) 3076 if (FRAME_X_OUTPUT (f)->widget)
3077#endif 3077#endif
3078 w = (unsigned long) FRAME_OUTER_WINDOW (f); 3078 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3079 store_in_alist (alistptr, Qouter_window_id, 3079 store_in_alist (alistptr, Qouter_window_id,
3080 make_formatted_string (buf, "%lu", w)); 3080 make_formatted_string (buf, "%"pMu, w));
3081#endif 3081#endif
3082 store_in_alist (alistptr, Qicon_name, f->icon_name); 3082 store_in_alist (alistptr, Qicon_name, f->icon_name);
3083 FRAME_SAMPLE_VISIBILITY (f); 3083 FRAME_SAMPLE_VISIBILITY (f);
@@ -3533,9 +3533,9 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3533 f->alpha[i] = newval[i]; 3533 f->alpha[i] = newval[i];
3534 3534
3535#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) 3535#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3536 BLOCK_INPUT; 3536 block_input ();
3537 x_set_frame_alpha (f); 3537 x_set_frame_alpha (f);
3538 UNBLOCK_INPUT; 3538 unblock_input ();
3539#endif 3539#endif
3540 3540
3541 return; 3541 return;
@@ -3897,6 +3897,95 @@ x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3897} 3897}
3898 3898
3899 3899
3900#if !defined (HAVE_X_WINDOWS) && defined (NoValue)
3901
3902/*
3903 * XParseGeometry parses strings of the form
3904 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
3905 * width, height, xoffset, and yoffset are unsigned integers.
3906 * Example: "=80x24+300-49"
3907 * The equal sign is optional.
3908 * It returns a bitmask that indicates which of the four values
3909 * were actually found in the string. For each value found,
3910 * the corresponding argument is updated; for each value
3911 * not found, the corresponding argument is left unchanged.
3912 */
3913
3914static int
3915XParseGeometry (char *string,
3916 int *x, int *y,
3917 unsigned int *width, unsigned int *height)
3918{
3919 int mask = NoValue;
3920 char *strind;
3921 unsigned long int tempWidth, tempHeight;
3922 long int tempX, tempY;
3923 char *nextCharacter;
3924
3925 if (string == NULL || *string == '\0')
3926 return mask;
3927 if (*string == '=')
3928 string++; /* ignore possible '=' at beg of geometry spec */
3929
3930 strind = string;
3931 if (*strind != '+' && *strind != '-' && *strind != 'x')
3932 {
3933 tempWidth = strtoul (strind, &nextCharacter, 10);
3934 if (strind == nextCharacter)
3935 return 0;
3936 strind = nextCharacter;
3937 mask |= WidthValue;
3938 }
3939
3940 if (*strind == 'x' || *strind == 'X')
3941 {
3942 strind++;
3943 tempHeight = strtoul (strind, &nextCharacter, 10);
3944 if (strind == nextCharacter)
3945 return 0;
3946 strind = nextCharacter;
3947 mask |= HeightValue;
3948 }
3949
3950 if (*strind == '+' || *strind == '-')
3951 {
3952 if (*strind == '-')
3953 mask |= XNegative;
3954 tempX = strtol (strind, &nextCharacter, 10);
3955 if (strind == nextCharacter)
3956 return 0;
3957 strind = nextCharacter;
3958 mask |= XValue;
3959 if (*strind == '+' || *strind == '-')
3960 {
3961 if (*strind == '-')
3962 mask |= YNegative;
3963 tempY = strtol (strind, &nextCharacter, 10);
3964 if (strind == nextCharacter)
3965 return 0;
3966 strind = nextCharacter;
3967 mask |= YValue;
3968 }
3969 }
3970
3971 /* If strind isn't at the end of the string then it's an invalid
3972 geometry specification. */
3973
3974 if (*strind != '\0')
3975 return 0;
3976
3977 if (mask & XValue)
3978 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
3979 if (mask & YValue)
3980 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
3981 if (mask & WidthValue)
3982 *width = min (tempWidth, UINT_MAX);
3983 if (mask & HeightValue)
3984 *height = min (tempHeight, UINT_MAX);
3985 return mask;
3986}
3987
3988#endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
3900 3989
3901 3990
3902/* NS used to define x-parse-geometry in ns-win.el, but that confused 3991/* NS used to define x-parse-geometry in ns-win.el, but that confused
@@ -3917,15 +4006,16 @@ or a list (- N) meaning -N pixels relative to bottom/right corner.
3917On Nextstep, this just calls `ns-parse-geometry'. */) 4006On Nextstep, this just calls `ns-parse-geometry'. */)
3918 (Lisp_Object string) 4007 (Lisp_Object string)
3919{ 4008{
3920#ifdef HAVE_NS
3921 return call1 (Qns_parse_geometry, string);
3922#else
3923 int geometry, x, y; 4009 int geometry, x, y;
3924 unsigned int width, height; 4010 unsigned int width, height;
3925 Lisp_Object result; 4011 Lisp_Object result;
3926 4012
3927 CHECK_STRING (string); 4013 CHECK_STRING (string);
3928 4014
4015#ifdef HAVE_NS
4016 if (strchr (SSDATA (string), ' ') != NULL)
4017 return call1 (Qns_parse_geometry, string);
4018#endif
3929 geometry = XParseGeometry (SSDATA (string), 4019 geometry = XParseGeometry (SSDATA (string),
3930 &x, &y, &width, &height); 4020 &x, &y, &width, &height);
3931 result = Qnil; 4021 result = Qnil;
@@ -3961,7 +4051,6 @@ On Nextstep, this just calls `ns-parse-geometry'. */)
3961 result = Fcons (Fcons (Qheight, make_number (height)), result); 4051 result = Fcons (Fcons (Qheight, make_number (height)), result);
3962 4052
3963 return result; 4053 return result;
3964#endif /* HAVE_NS */
3965} 4054}
3966 4055
3967 4056
diff --git a/src/frame.h b/src/frame.h
index 1184545d2e6..7bf76c21c56 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1203,7 +1203,7 @@ extern Lisp_Object Qrun_hook_with_args;
1203extern void x_set_scroll_bar_default_width (struct frame *); 1203extern void x_set_scroll_bar_default_width (struct frame *);
1204extern void x_set_offset (struct frame *, int, int, int); 1204extern void x_set_offset (struct frame *, int, int, int);
1205extern void x_wm_set_icon_position (struct frame *, int, int); 1205extern void x_wm_set_icon_position (struct frame *, int, int);
1206extern void x_wm_set_size_hint (FRAME_PTR f, long flags, int user_position); 1206extern void x_wm_set_size_hint (FRAME_PTR f, long flags, bool user_position);
1207 1207
1208extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int); 1208extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
1209 1209
@@ -1249,7 +1249,7 @@ extern Lisp_Object display_x_get_resource (Display_Info *,
1249 Lisp_Object component, 1249 Lisp_Object component,
1250 Lisp_Object subclass); 1250 Lisp_Object subclass);
1251 1251
1252extern void set_frame_menubar (struct frame *f, int first_time, int deep_p); 1252extern void set_frame_menubar (struct frame *f, bool first_time, bool deep_p);
1253extern void x_set_window_size (struct frame *f, int change_grav, 1253extern void x_set_window_size (struct frame *f, int change_grav,
1254 int cols, int rows); 1254 int cols, int rows);
1255extern void x_sync (struct frame *); 1255extern void x_sync (struct frame *);
@@ -1284,9 +1284,6 @@ extern char *x_get_resource_string (const char *, const char *);
1284extern void x_query_colors (struct frame *f, XColor *, int); 1284extern void x_query_colors (struct frame *f, XColor *, int);
1285extern void x_query_color (struct frame *f, XColor *); 1285extern void x_query_color (struct frame *f, XColor *);
1286 1286
1287/* In xmenu.c */
1288extern void set_frame_menubar (FRAME_PTR, int, int);
1289
1290#endif /* HAVE_WINDOW_SYSTEM */ 1287#endif /* HAVE_WINDOW_SYSTEM */
1291 1288
1292INLINE_HEADER_END 1289INLINE_HEADER_END
diff --git a/src/fringe.c b/src/fringe.c
index 6e6deeddb08..d788503e91e 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -872,7 +872,7 @@ draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
872void 872void
873draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row) 873draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
874{ 874{
875 eassert (interrupt_input_blocked); 875 eassert (input_blocked_p ());
876 876
877 /* If row is completely invisible, because of vscrolling, we 877 /* If row is completely invisible, because of vscrolling, we
878 don't have to draw anything. */ 878 don't have to draw anything. */
diff --git a/src/ftxfont.c b/src/ftxfont.c
index 466250bd43f..5effe6e9104 100644
--- a/src/ftxfont.c
+++ b/src/ftxfont.c
@@ -98,7 +98,7 @@ ftxfont_get_gcs (FRAME_PTR f, long unsigned int foreground, long unsigned int ba
98 new->colors[0].pixel = background; 98 new->colors[0].pixel = background;
99 new->colors[1].pixel = foreground; 99 new->colors[1].pixel = foreground;
100 100
101 BLOCK_INPUT; 101 block_input ();
102 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), new->colors, 2); 102 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), new->colors, 2);
103 for (i = 1; i < 7; i++) 103 for (i = 1; i < 7; i++)
104 { 104 {
@@ -115,14 +115,14 @@ ftxfont_get_gcs (FRAME_PTR f, long unsigned int foreground, long unsigned int ba
115 new->gcs[i - 1] = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 115 new->gcs[i - 1] = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
116 GCForeground, &xgcv); 116 GCForeground, &xgcv);
117 } 117 }
118 UNBLOCK_INPUT; 118 unblock_input ();
119 119
120 if (i < 7) 120 if (i < 7)
121 { 121 {
122 BLOCK_INPUT; 122 block_input ();
123 for (i--; i >= 0; i--) 123 for (i--; i >= 0; i--)
124 XFreeGC (FRAME_X_DISPLAY (f), new->gcs[i]); 124 XFreeGC (FRAME_X_DISPLAY (f), new->gcs[i]);
125 UNBLOCK_INPUT; 125 unblock_input ();
126 if (prev) 126 if (prev)
127 prev->next = new->next; 127 prev->next = new->next;
128 else if (data) 128 else if (data)
@@ -282,7 +282,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
282 282
283 n[0] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = 0; 283 n[0] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = 0;
284 284
285 BLOCK_INPUT; 285 block_input ();
286 if (with_background) 286 if (with_background)
287 ftxfont_draw_background (f, font, s->gc, x, y, s->width); 287 ftxfont_draw_background (f, font, s->gc, x, y, s->width);
288 code = alloca (sizeof (unsigned) * len); 288 code = alloca (sizeof (unsigned) * len);
@@ -332,7 +332,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
332 } 332 }
333 } 333 }
334 334
335 UNBLOCK_INPUT; 335 unblock_input ();
336 336
337 return len; 337 return len;
338} 338}
@@ -342,7 +342,7 @@ ftxfont_end_for_frame (FRAME_PTR f)
342{ 342{
343 struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver); 343 struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver);
344 344
345 BLOCK_INPUT; 345 block_input ();
346 while (data) 346 while (data)
347 { 347 {
348 struct ftxfont_frame_data *next = data->next; 348 struct ftxfont_frame_data *next = data->next;
@@ -353,7 +353,7 @@ ftxfont_end_for_frame (FRAME_PTR f)
353 free (data); 353 free (data);
354 data = next; 354 data = next;
355 } 355 }
356 UNBLOCK_INPUT; 356 unblock_input ();
357 font_put_frame_data (f, &ftxfont_driver, NULL); 357 font_put_frame_data (f, &ftxfont_driver, NULL);
358 return 0; 358 return 0;
359} 359}
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 78d6934755b..dc584955661 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -36,6 +36,10 @@ Fifth Floor, Boston, MA 02110-1301, USA.
36#include <pthread.h> 36#include <pthread.h>
37#endif 37#endif
38 38
39#ifdef WINDOWSNT
40#include <w32heap.h> /* for sbrk */
41#endif
42
39#ifdef __cplusplus 43#ifdef __cplusplus
40extern "C" 44extern "C"
41{ 45{
@@ -460,7 +464,7 @@ get_contiguous_space (ptrdiff_t size, void *position)
460/* This is called when `_heapinfo' and `heapsize' have just 464/* This is called when `_heapinfo' and `heapsize' have just
461 been set to describe a new info table. Set up the table 465 been set to describe a new info table. Set up the table
462 to describe itself and account for it in the statistics. */ 466 to describe itself and account for it in the statistics. */
463static inline void 467static void
464register_heapinfo (void) 468register_heapinfo (void)
465{ 469{
466 size_t block, blocks; 470 size_t block, blocks;
@@ -1289,7 +1293,9 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1289 The author may be reached (Email) at the address mike@ai.mit.edu, 1293 The author may be reached (Email) at the address mike@ai.mit.edu,
1290 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1294 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1291 1295
1296#ifndef min
1292#define min(A, B) ((A) < (B) ? (A) : (B)) 1297#define min(A, B) ((A) < (B) ? (A) : (B))
1298#endif
1293 1299
1294/* On Cygwin the dumped emacs may try to realloc storage allocated in 1300/* On Cygwin the dumped emacs may try to realloc storage allocated in
1295 the static heap. We just malloc space in the new heap and copy the 1301 the static heap. We just malloc space in the new heap and copy the
diff --git a/src/gnutls.c b/src/gnutls.c
index 1c4693aee32..e3d84a0b61b 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -30,15 +30,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#include "w32.h" 30#include "w32.h"
31#endif 31#endif
32 32
33static int 33static bool emacs_gnutls_handle_error (gnutls_session_t, int);
34emacs_gnutls_handle_error (gnutls_session_t, int err);
35 34
36static Lisp_Object Qgnutls_dll; 35static Lisp_Object Qgnutls_dll;
37static Lisp_Object Qgnutls_code; 36static Lisp_Object Qgnutls_code;
38static Lisp_Object Qgnutls_anon, Qgnutls_x509pki; 37static Lisp_Object Qgnutls_anon, Qgnutls_x509pki;
39static Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again, 38static Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again,
40 Qgnutls_e_invalid_session, Qgnutls_e_not_ready_for_handshake; 39 Qgnutls_e_invalid_session, Qgnutls_e_not_ready_for_handshake;
41static int gnutls_global_initialized; 40static bool gnutls_global_initialized;
42 41
43/* The following are for the property list of `gnutls-boot'. */ 42/* The following are for the property list of `gnutls-boot'. */
44static Lisp_Object QCgnutls_bootprop_priority; 43static Lisp_Object QCgnutls_bootprop_priority;
@@ -141,13 +140,13 @@ DEF_GNUTLS_FN (int, gnutls_x509_crt_import,
141 gnutls_x509_crt_fmt_t)); 140 gnutls_x509_crt_fmt_t));
142DEF_GNUTLS_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *)); 141DEF_GNUTLS_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *));
143 142
144static int 143static bool
145init_gnutls_functions (Lisp_Object libraries) 144init_gnutls_functions (void)
146{ 145{
147 HMODULE library; 146 HMODULE library;
148 int max_log_level = 1; 147 int max_log_level = 1;
149 148
150 if (!(library = w32_delayed_load (libraries, Qgnutls_dll))) 149 if (!(library = w32_delayed_load (Qgnutls_dll)))
151 { 150 {
152 GNUTLS_LOG (1, max_log_level, "GnuTLS library not found"); 151 GNUTLS_LOG (1, max_log_level, "GnuTLS library not found");
153 return 0; 152 return 0;
@@ -438,7 +437,7 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
438 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH) 437 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
439 /* The peer closed the connection. */ 438 /* The peer closed the connection. */
440 return 0; 439 return 0;
441 else if (emacs_gnutls_handle_error (state, rtnval) == 0) 440 else if (emacs_gnutls_handle_error (state, rtnval))
442 /* non-fatal error */ 441 /* non-fatal error */
443 return -1; 442 return -1;
444 else { 443 else {
@@ -447,19 +446,19 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
447 } 446 }
448} 447}
449 448
450/* report a GnuTLS error to the user. 449/* Report a GnuTLS error to the user.
451 Returns zero if the error code was successfully handled. */ 450 Return true if the error code was successfully handled. */
452static int 451static bool
453emacs_gnutls_handle_error (gnutls_session_t session, int err) 452emacs_gnutls_handle_error (gnutls_session_t session, int err)
454{ 453{
455 int max_log_level = 0; 454 int max_log_level = 0;
456 455
457 int ret; 456 bool ret;
458 const char *str; 457 const char *str;
459 458
460 /* TODO: use a Lisp_Object generated by gnutls_make_error? */ 459 /* TODO: use a Lisp_Object generated by gnutls_make_error? */
461 if (err >= 0) 460 if (err >= 0)
462 return 0; 461 return 1;
463 462
464 max_log_level = global_gnutls_log_level; 463 max_log_level = global_gnutls_log_level;
465 464
@@ -471,12 +470,12 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
471 470
472 if (fn_gnutls_error_is_fatal (err)) 471 if (fn_gnutls_error_is_fatal (err))
473 { 472 {
474 ret = err; 473 ret = 0;
475 GNUTLS_LOG2 (0, max_log_level, "fatal error:", str); 474 GNUTLS_LOG2 (0, max_log_level, "fatal error:", str);
476 } 475 }
477 else 476 else
478 { 477 {
479 ret = 0; 478 ret = 1;
480 GNUTLS_LOG2 (1, max_log_level, "non-fatal error:", str); 479 GNUTLS_LOG2 (1, max_log_level, "non-fatal error:", str);
481 /* TODO: EAGAIN AKA Qgnutls_e_again should be level 2. */ 480 /* TODO: EAGAIN AKA Qgnutls_e_again should be level 2. */
482 } 481 }
@@ -656,7 +655,7 @@ DEFUN ("gnutls-available-p", Fgnutls_available_p, Sgnutls_available_p, 0, 0, 0,
656 else 655 else
657 { 656 {
658 Lisp_Object status; 657 Lisp_Object status;
659 status = init_gnutls_functions (Vdynamic_library_alist) ? Qt : Qnil; 658 status = init_gnutls_functions () ? Qt : Qnil;
660 Vlibrary_cache = Fcons (Fcons (Qgnutls_dll, status), Vlibrary_cache); 659 Vlibrary_cache = Fcons (Fcons (Qgnutls_dll, status), Vlibrary_cache);
661 return status; 660 return status;
662 } 661 }
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 1eb4b2cabdf..1bf2b533b41 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -576,21 +576,21 @@ get_utf8_string (const char *str)
576 576
577/* Check for special colors used in face spec for region face. 577/* Check for special colors used in face spec for region face.
578 The colors are fetched from the Gtk+ theme. 578 The colors are fetched from the Gtk+ theme.
579 Return 1 if color was found, 0 if not. */ 579 Return true if color was found, false if not. */
580 580
581int 581bool
582xg_check_special_colors (struct frame *f, 582xg_check_special_colors (struct frame *f,
583 const char *color_name, 583 const char *color_name,
584 XColor *color) 584 XColor *color)
585{ 585{
586 int success_p = 0; 586 bool success_p = 0;
587 int get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0; 587 bool get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0;
588 int get_fg = !get_bg && strcmp ("gtk_selection_fg_color", color_name) == 0; 588 bool get_fg = !get_bg && strcmp ("gtk_selection_fg_color", color_name) == 0;
589 589
590 if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg)) 590 if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg))
591 return success_p; 591 return success_p;
592 592
593 BLOCK_INPUT; 593 block_input ();
594 { 594 {
595#ifdef HAVE_GTK3 595#ifdef HAVE_GTK3
596 GtkStyleContext *gsty 596 GtkStyleContext *gsty
@@ -604,8 +604,9 @@ xg_check_special_colors (struct frame *f,
604 gtk_style_context_get_background_color (gsty, state, &col); 604 gtk_style_context_get_background_color (gsty, state, &col);
605 605
606 sprintf (buf, "rgbi:%lf/%lf/%lf", col.red, col.green, col.blue); 606 sprintf (buf, "rgbi:%lf/%lf/%lf", col.red, col.green, col.blue);
607 success_p = XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), 607 success_p = (XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
608 buf, color); 608 buf, color)
609 != 0);
609#else 610#else
610 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); 611 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
611 GdkColor *grgb = get_bg 612 GdkColor *grgb = get_bg
@@ -620,7 +621,7 @@ xg_check_special_colors (struct frame *f,
620#endif 621#endif
621 622
622 } 623 }
623 UNBLOCK_INPUT; 624 unblock_input ();
624 return success_p; 625 return success_p;
625} 626}
626 627
@@ -703,9 +704,9 @@ qttip_cb (GtkWidget *widget,
703#endif /* USE_GTK_TOOLTIP */ 704#endif /* USE_GTK_TOOLTIP */
704 705
705/* Prepare a tooltip to be shown, i.e. calculate WIDTH and HEIGHT. 706/* Prepare a tooltip to be shown, i.e. calculate WIDTH and HEIGHT.
706 Return zero if no system tooltip available, non-zero otherwise. */ 707 Return true if a system tooltip is available. */
707 708
708int 709bool
709xg_prepare_tooltip (FRAME_PTR f, 710xg_prepare_tooltip (FRAME_PTR f,
710 Lisp_Object string, 711 Lisp_Object string,
711 int *width, 712 int *width,
@@ -725,7 +726,7 @@ xg_prepare_tooltip (FRAME_PTR f,
725 726
726 if (!x->ttip_lbl) return 0; 727 if (!x->ttip_lbl) return 0;
727 728
728 BLOCK_INPUT; 729 block_input ();
729 encoded_string = ENCODE_UTF_8 (string); 730 encoded_string = ENCODE_UTF_8 (string);
730 widget = GTK_WIDGET (x->ttip_lbl); 731 widget = GTK_WIDGET (x->ttip_lbl);
731 gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window)); 732 gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window));
@@ -753,7 +754,7 @@ xg_prepare_tooltip (FRAME_PTR f,
753 if (width) *width = req.width; 754 if (width) *width = req.width;
754 if (height) *height = req.height; 755 if (height) *height = req.height;
755 756
756 UNBLOCK_INPUT; 757 unblock_input ();
757 758
758 return 1; 759 return 1;
759#endif /* USE_GTK_TOOLTIP */ 760#endif /* USE_GTK_TOOLTIP */
@@ -769,27 +770,27 @@ xg_show_tooltip (FRAME_PTR f, int root_x, int root_y)
769 struct x_output *x = f->output_data.x; 770 struct x_output *x = f->output_data.x;
770 if (x->ttip_window) 771 if (x->ttip_window)
771 { 772 {
772 BLOCK_INPUT; 773 block_input ();
773 gtk_window_move (x->ttip_window, root_x, root_y); 774 gtk_window_move (x->ttip_window, root_x, root_y);
774 gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); 775 gtk_widget_show_all (GTK_WIDGET (x->ttip_window));
775 UNBLOCK_INPUT; 776 unblock_input ();
776 } 777 }
777#endif 778#endif
778} 779}
779 780
780/* Hide tooltip if shown. Do nothing if not shown. 781/* Hide tooltip if shown. Do nothing if not shown.
781 Return non-zero if tip was hidden, non-zero if not (i.e. not using 782 Return true if tip was hidden, false if not (i.e. not using
782 system tooltips). */ 783 system tooltips). */
783 784
784int 785bool
785xg_hide_tooltip (FRAME_PTR f) 786xg_hide_tooltip (FRAME_PTR f)
786{ 787{
787 int ret = 0; 788 bool ret = 0;
788#ifdef USE_GTK_TOOLTIP 789#ifdef USE_GTK_TOOLTIP
789 if (f->output_data.x->ttip_window) 790 if (f->output_data.x->ttip_window)
790 { 791 {
791 GtkWindow *win = f->output_data.x->ttip_window; 792 GtkWindow *win = f->output_data.x->ttip_window;
792 BLOCK_INPUT; 793 block_input ();
793 gtk_widget_hide (GTK_WIDGET (win)); 794 gtk_widget_hide (GTK_WIDGET (win));
794 795
795 if (g_object_get_data (G_OBJECT (win), "restore-tt")) 796 if (g_object_get_data (G_OBJECT (win), "restore-tt"))
@@ -799,7 +800,7 @@ xg_hide_tooltip (FRAME_PTR f)
799 GtkSettings *settings = gtk_settings_get_for_screen (screen); 800 GtkSettings *settings = gtk_settings_get_for_screen (screen);
800 g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL); 801 g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL);
801 } 802 }
802 UNBLOCK_INPUT; 803 unblock_input ();
803 804
804 ret = 1; 805 ret = 1;
805 } 806 }
@@ -1007,7 +1008,7 @@ xg_win_to_widget (Display *dpy, Window wdesc)
1007 gpointer gdkwin; 1008 gpointer gdkwin;
1008 GtkWidget *gwdesc = 0; 1009 GtkWidget *gwdesc = 0;
1009 1010
1010 BLOCK_INPUT; 1011 block_input ();
1011 1012
1012 gdkwin = gdk_x11_window_lookup_for_display (gdk_x11_lookup_xdisplay (dpy), 1013 gdkwin = gdk_x11_window_lookup_for_display (gdk_x11_lookup_xdisplay (dpy),
1013 wdesc); 1014 wdesc);
@@ -1019,7 +1020,7 @@ xg_win_to_widget (Display *dpy, Window wdesc)
1019 gwdesc = gtk_get_event_widget (&event); 1020 gwdesc = gtk_get_event_widget (&event);
1020 } 1021 }
1021 1022
1022 UNBLOCK_INPUT; 1023 unblock_input ();
1023 return gwdesc; 1024 return gwdesc;
1024} 1025}
1025 1026
@@ -1110,9 +1111,9 @@ delete_cb (GtkWidget *widget,
1110} 1111}
1111 1112
1112/* Create and set up the GTK widgets for frame F. 1113/* Create and set up the GTK widgets for frame F.
1113 Return 0 if creation failed, non-zero otherwise. */ 1114 Return true if creation succeeded. */
1114 1115
1115int 1116bool
1116xg_create_frame_widgets (FRAME_PTR f) 1117xg_create_frame_widgets (FRAME_PTR f)
1117{ 1118{
1118 GtkWidget *wtop; 1119 GtkWidget *wtop;
@@ -1123,7 +1124,7 @@ xg_create_frame_widgets (FRAME_PTR f)
1123#endif 1124#endif
1124 char *title = 0; 1125 char *title = 0;
1125 1126
1126 BLOCK_INPUT; 1127 block_input ();
1127 1128
1128 if (FRAME_X_EMBEDDED_P (f)) 1129 if (FRAME_X_EMBEDDED_P (f))
1129 { 1130 {
@@ -1161,7 +1162,7 @@ xg_create_frame_widgets (FRAME_PTR f)
1161 if (whbox) gtk_widget_destroy (whbox); 1162 if (whbox) gtk_widget_destroy (whbox);
1162 if (wfixed) gtk_widget_destroy (wfixed); 1163 if (wfixed) gtk_widget_destroy (wfixed);
1163 1164
1164 UNBLOCK_INPUT; 1165 unblock_input ();
1165 return 0; 1166 return 0;
1166 } 1167 }
1167 1168
@@ -1275,7 +1276,7 @@ xg_create_frame_widgets (FRAME_PTR f)
1275 } 1276 }
1276 } 1277 }
1277 1278
1278 UNBLOCK_INPUT; 1279 unblock_input ();
1279 1280
1280 return 1; 1281 return 1;
1281} 1282}
@@ -1309,11 +1310,11 @@ xg_free_frame_widgets (FRAME_PTR f)
1309/* Set the normal size hints for the window manager, for frame F. 1310/* Set the normal size hints for the window manager, for frame F.
1310 FLAGS is the flags word to use--or 0 meaning preserve the flags 1311 FLAGS is the flags word to use--or 0 meaning preserve the flags
1311 that the window now has. 1312 that the window now has.
1312 If USER_POSITION is nonzero, we set the User Position 1313 If USER_POSITION, set the User Position
1313 flag (this is useful when FLAGS is 0). */ 1314 flag (this is useful when FLAGS is 0). */
1314 1315
1315void 1316void
1316x_wm_set_size_hint (FRAME_PTR f, long int flags, int user_position) 1317x_wm_set_size_hint (FRAME_PTR f, long int flags, bool user_position)
1317{ 1318{
1318 /* Must use GTK routines here, otherwise GTK resets the size hints 1319 /* Must use GTK routines here, otherwise GTK resets the size hints
1319 to its own defaults. */ 1320 to its own defaults. */
@@ -1397,12 +1398,12 @@ x_wm_set_size_hint (FRAME_PTR f, long int flags, int user_position)
1397 &f->output_data.x->size_hints, 1398 &f->output_data.x->size_hints,
1398 sizeof (size_hints)) != 0) 1399 sizeof (size_hints)) != 0)
1399 { 1400 {
1400 BLOCK_INPUT; 1401 block_input ();
1401 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 1402 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1402 NULL, &size_hints, hint_flags); 1403 NULL, &size_hints, hint_flags);
1403 f->output_data.x->size_hints = size_hints; 1404 f->output_data.x->size_hints = size_hints;
1404 f->output_data.x->hint_flags = hint_flags; 1405 f->output_data.x->hint_flags = hint_flags;
1405 UNBLOCK_INPUT; 1406 unblock_input ();
1406 } 1407 }
1407} 1408}
1408 1409
@@ -1417,9 +1418,9 @@ xg_set_background_color (FRAME_PTR f, long unsigned int bg)
1417{ 1418{
1418 if (FRAME_GTK_WIDGET (f)) 1419 if (FRAME_GTK_WIDGET (f))
1419 { 1420 {
1420 BLOCK_INPUT; 1421 block_input ();
1421 xg_set_widget_bg (f, FRAME_GTK_WIDGET (f), FRAME_BACKGROUND_PIXEL (f)); 1422 xg_set_widget_bg (f, FRAME_GTK_WIDGET (f), FRAME_BACKGROUND_PIXEL (f));
1422 UNBLOCK_INPUT; 1423 unblock_input ();
1423 } 1424 }
1424} 1425}
1425 1426
@@ -1519,7 +1520,7 @@ create_dialog (widget_value *wv,
1519 1520
1520 /* If the number of buttons is greater than 4, make two rows of buttons 1521 /* If the number of buttons is greater than 4, make two rows of buttons
1521 instead. This looks better. */ 1522 instead. This looks better. */
1522 int make_two_rows = total_buttons > 4; 1523 bool make_two_rows = total_buttons > 4;
1523 1524
1524 if (right_buttons == 0) right_buttons = total_buttons/2; 1525 if (right_buttons == 0) right_buttons = total_buttons/2;
1525 left_buttons = total_buttons - right_buttons; 1526 left_buttons = total_buttons - right_buttons;
@@ -1637,14 +1638,14 @@ pop_down_dialog (Lisp_Object arg)
1637 struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 1638 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
1638 struct xg_dialog_data *dd = (struct xg_dialog_data *) p->pointer; 1639 struct xg_dialog_data *dd = (struct xg_dialog_data *) p->pointer;
1639 1640
1640 BLOCK_INPUT; 1641 block_input ();
1641 if (dd->w) gtk_widget_destroy (dd->w); 1642 if (dd->w) gtk_widget_destroy (dd->w);
1642 if (dd->timerid != 0) g_source_remove (dd->timerid); 1643 if (dd->timerid != 0) g_source_remove (dd->timerid);
1643 1644
1644 g_main_loop_quit (dd->loop); 1645 g_main_loop_quit (dd->loop);
1645 g_main_loop_unref (dd->loop); 1646 g_main_loop_unref (dd->loop);
1646 1647
1647 UNBLOCK_INPUT; 1648 unblock_input ();
1648 1649
1649 return Qnil; 1650 return Qnil;
1650} 1651}
@@ -1716,10 +1717,9 @@ xg_dialog_run (FRAME_PTR f, GtkWidget *w)
1716/*********************************************************************** 1717/***********************************************************************
1717 File dialog functions 1718 File dialog functions
1718 ***********************************************************************/ 1719 ***********************************************************************/
1719/* Return non-zero if the old file selection dialog is being used. 1720/* Return true if the old file selection dialog is being used. */
1720 Return zero if not. */
1721 1721
1722int 1722bool
1723xg_uses_old_file_dialog (void) 1723xg_uses_old_file_dialog (void)
1724{ 1724{
1725#ifdef HAVE_GTK_FILE_SELECTION_NEW 1725#ifdef HAVE_GTK_FILE_SELECTION_NEW
@@ -1790,7 +1790,7 @@ xg_toggle_notify_cb (GObject *gobject, GParamSpec *arg1, gpointer user_data)
1790 F is the current frame. 1790 F is the current frame.
1791 PROMPT is a prompt to show to the user. May not be NULL. 1791 PROMPT is a prompt to show to the user. May not be NULL.
1792 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1792 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1793 If MUSTMATCH_P is non-zero, the returned file name must be an existing 1793 If MUSTMATCH_P, the returned file name must be an existing
1794 file. (Actually, this only has cosmetic effects, the user can 1794 file. (Actually, this only has cosmetic effects, the user can
1795 still enter a non-existing file.) *FUNC is set to a function that 1795 still enter a non-existing file.) *FUNC is set to a function that
1796 can be used to retrieve the selected file name from the returned widget. 1796 can be used to retrieve the selected file name from the returned widget.
@@ -1801,7 +1801,7 @@ static GtkWidget *
1801xg_get_file_with_chooser (FRAME_PTR f, 1801xg_get_file_with_chooser (FRAME_PTR f,
1802 char *prompt, 1802 char *prompt,
1803 char *default_filename, 1803 char *default_filename,
1804 int mustmatch_p, int only_dir_p, 1804 bool mustmatch_p, bool only_dir_p,
1805 xg_get_file_func *func) 1805 xg_get_file_func *func)
1806{ 1806{
1807 char msgbuf[1024]; 1807 char msgbuf[1024];
@@ -1913,7 +1913,7 @@ xg_get_file_name_from_selector (GtkWidget *w)
1913 F is the current frame. 1913 F is the current frame.
1914 PROMPT is a prompt to show to the user. May not be NULL. 1914 PROMPT is a prompt to show to the user. May not be NULL.
1915 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1915 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1916 If MUSTMATCH_P is non-zero, the returned file name must be an existing 1916 If MUSTMATCH_P, the returned file name must be an existing
1917 file. *FUNC is set to a function that can be used to retrieve the 1917 file. *FUNC is set to a function that can be used to retrieve the
1918 selected file name from the returned widget. 1918 selected file name from the returned widget.
1919 1919
@@ -1923,7 +1923,7 @@ static GtkWidget *
1923xg_get_file_with_selection (FRAME_PTR f, 1923xg_get_file_with_selection (FRAME_PTR f,
1924 char *prompt, 1924 char *prompt,
1925 char *default_filename, 1925 char *default_filename,
1926 int mustmatch_p, int only_dir_p, 1926 bool mustmatch_p, bool only_dir_p,
1927 xg_get_file_func *func) 1927 xg_get_file_func *func)
1928{ 1928{
1929 GtkWidget *filewin; 1929 GtkWidget *filewin;
@@ -1955,7 +1955,7 @@ xg_get_file_with_selection (FRAME_PTR f,
1955 F is the current frame. 1955 F is the current frame.
1956 PROMPT is a prompt to show to the user. May not be NULL. 1956 PROMPT is a prompt to show to the user. May not be NULL.
1957 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1957 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1958 If MUSTMATCH_P is non-zero, the returned file name must be an existing 1958 If MUSTMATCH_P, the returned file name must be an existing
1959 file. 1959 file.
1960 1960
1961 Returns a file name or NULL if no file was selected. 1961 Returns a file name or NULL if no file was selected.
@@ -1965,24 +1965,14 @@ char *
1965xg_get_file_name (FRAME_PTR f, 1965xg_get_file_name (FRAME_PTR f,
1966 char *prompt, 1966 char *prompt,
1967 char *default_filename, 1967 char *default_filename,
1968 int mustmatch_p, 1968 bool mustmatch_p,
1969 int only_dir_p) 1969 bool only_dir_p)
1970{ 1970{
1971 GtkWidget *w = 0; 1971 GtkWidget *w = 0;
1972 char *fn = 0; 1972 char *fn = 0;
1973 int filesel_done = 0; 1973 int filesel_done = 0;
1974 xg_get_file_func func; 1974 xg_get_file_func func;
1975 1975
1976#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
1977 /* I really don't know why this is needed, but without this the GLIBC add on
1978 library linuxthreads hangs when the Gnome file chooser backend creates
1979 threads. */
1980 sigset_t blocked;
1981 sigemptyset (&blocked);
1982 sigaddset (&blocked, __SIGRTMIN);
1983 pthread_sigmask (SIG_BLOCK, &blocked, 0);
1984#endif /* HAVE_PTHREAD */
1985
1986#ifdef HAVE_GTK_FILE_SELECTION_NEW 1976#ifdef HAVE_GTK_FILE_SELECTION_NEW
1987 1977
1988 if (xg_uses_old_file_dialog ()) 1978 if (xg_uses_old_file_dialog ())
@@ -2000,11 +1990,6 @@ xg_get_file_name (FRAME_PTR f,
2000 gtk_widget_set_name (w, "emacs-filedialog"); 1990 gtk_widget_set_name (w, "emacs-filedialog");
2001 1991
2002 filesel_done = xg_dialog_run (f, w); 1992 filesel_done = xg_dialog_run (f, w);
2003
2004#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
2005 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
2006#endif
2007
2008 if (filesel_done == GTK_RESPONSE_OK) 1993 if (filesel_done == GTK_RESPONSE_OK)
2009 fn = (*func) (w); 1994 fn = (*func) (w);
2010 1995
@@ -2057,13 +2042,6 @@ xg_get_font (FRAME_PTR f, const char *default_name)
2057 int done = 0; 2042 int done = 0;
2058 Lisp_Object font = Qnil; 2043 Lisp_Object font = Qnil;
2059 2044
2060#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
2061 sigset_t blocked;
2062 sigemptyset (&blocked);
2063 sigaddset (&blocked, __SIGRTMIN);
2064 pthread_sigmask (SIG_BLOCK, &blocked, 0);
2065#endif /* HAVE_PTHREAD */
2066
2067 w = gtk_font_chooser_dialog_new 2045 w = gtk_font_chooser_dialog_new
2068 ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 2046 ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
2069 2047
@@ -2088,11 +2066,6 @@ xg_get_font (FRAME_PTR f, const char *default_name)
2088 2066
2089 gtk_widget_set_name (w, "emacs-fontdialog"); 2067 gtk_widget_set_name (w, "emacs-fontdialog");
2090 done = xg_dialog_run (f, w); 2068 done = xg_dialog_run (f, w);
2091
2092#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
2093 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
2094#endif
2095
2096 if (done == GTK_RESPONSE_OK) 2069 if (done == GTK_RESPONSE_OK)
2097 { 2070 {
2098#if USE_NEW_GTK_FONT_CHOOSER 2071#if USE_NEW_GTK_FONT_CHOOSER
@@ -2430,9 +2403,9 @@ make_menu_item (const char *utf8_label,
2430 2403
2431static int xg_detached_menus; 2404static int xg_detached_menus;
2432 2405
2433/* Returns non-zero if there are detached menus. */ 2406/* Return true if there are detached menus. */
2434 2407
2435int 2408bool
2436xg_have_tear_offs (void) 2409xg_have_tear_offs (void)
2437{ 2410{
2438 return xg_detached_menus > 0; 2411 return xg_detached_menus > 0;
@@ -2536,10 +2509,9 @@ xg_create_one_menuitem (widget_value *item,
2536 SELECT_CB is the callback to use when a menu item is selected. 2509 SELECT_CB is the callback to use when a menu item is selected.
2537 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. 2510 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
2538 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. 2511 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
2539 POP_UP_P is non-zero if we shall create a popup menu. 2512 If POP_UP_P, create a popup menu.
2540 MENU_BAR_P is non-zero if we shall create a menu bar. 2513 If MENU_BAR_P, create a menu bar.
2541 ADD_TEAROFF_P is non-zero if we shall add a tearoff menu item. Ignored 2514 If ADD_TEAROFF_P, add a tearoff menu item. Ignored if MENU_BAR_P.
2542 if MENU_BAR_P is non-zero.
2543 TOPMENU is the topmost GtkWidget that others shall be placed under. 2515 TOPMENU is the topmost GtkWidget that others shall be placed under.
2544 It may be NULL, in that case we create the appropriate widget 2516 It may be NULL, in that case we create the appropriate widget
2545 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P) 2517 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P)
@@ -2559,9 +2531,9 @@ create_menus (widget_value *data,
2559 GCallback select_cb, 2531 GCallback select_cb,
2560 GCallback deactivate_cb, 2532 GCallback deactivate_cb,
2561 GCallback highlight_cb, 2533 GCallback highlight_cb,
2562 int pop_up_p, 2534 bool pop_up_p,
2563 int menu_bar_p, 2535 bool menu_bar_p,
2564 int add_tearoff_p, 2536 bool add_tearoff_p,
2565 GtkWidget *topmenu, 2537 GtkWidget *topmenu,
2566 xg_menu_cb_data *cl_data, 2538 xg_menu_cb_data *cl_data,
2567 const char *name) 2539 const char *name)
@@ -2701,8 +2673,8 @@ xg_create_widget (const char *type, const char *name, FRAME_PTR f, widget_value
2701 GCallback highlight_cb) 2673 GCallback highlight_cb)
2702{ 2674{
2703 GtkWidget *w = 0; 2675 GtkWidget *w = 0;
2704 int menu_bar_p = strcmp (type, "menubar") == 0; 2676 bool menu_bar_p = strcmp (type, "menubar") == 0;
2705 int pop_up_p = strcmp (type, "popup") == 0; 2677 bool pop_up_p = strcmp (type, "popup") == 0;
2706 2678
2707 if (strcmp (type, "dialog") == 0) 2679 if (strcmp (type, "dialog") == 0)
2708 { 2680 {
@@ -2755,12 +2727,12 @@ xg_get_menu_item_label (GtkMenuItem *witem)
2755 return gtk_label_get_label (wlabel); 2727 return gtk_label_get_label (wlabel);
2756} 2728}
2757 2729
2758/* Return non-zero if the menu item WITEM has the text LABEL. */ 2730/* Return true if the menu item WITEM has the text LABEL. */
2759 2731
2760static int 2732static bool
2761xg_item_label_same_p (GtkMenuItem *witem, const char *label) 2733xg_item_label_same_p (GtkMenuItem *witem, const char *label)
2762{ 2734{
2763 int is_same = 0; 2735 bool is_same = 0;
2764 char *utf8_label = get_utf8_string (label); 2736 char *utf8_label = get_utf8_string (label);
2765 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0; 2737 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0;
2766 2738
@@ -2851,8 +2823,8 @@ xg_update_menubar (GtkWidget *menubar,
2851 { 2823 {
2852 GtkMenuItem *witem = GTK_MENU_ITEM (iter->data); 2824 GtkMenuItem *witem = GTK_MENU_ITEM (iter->data);
2853 GtkMenuItem *witem2 = 0; 2825 GtkMenuItem *witem2 = 0;
2854 int val_in_menubar = 0; 2826 bool val_in_menubar = 0;
2855 int iter_in_new_menubar = 0; 2827 bool iter_in_new_menubar = 0;
2856 GList *iter2; 2828 GList *iter2;
2857 widget_value *cur; 2829 widget_value *cur;
2858 2830
@@ -3130,7 +3102,7 @@ xg_update_submenu (GtkWidget *submenu,
3130 GList *list = 0; 3102 GList *list = 0;
3131 GList *iter; 3103 GList *iter;
3132 widget_value *cur; 3104 widget_value *cur;
3133 int has_tearoff_p = 0; 3105 bool has_tearoff_p = 0;
3134 GList *first_radio = 0; 3106 GList *first_radio = 0;
3135 3107
3136 if (submenu) 3108 if (submenu)
@@ -3252,7 +3224,7 @@ xg_update_submenu (GtkWidget *submenu,
3252/* Update the MENUBAR. 3224/* Update the MENUBAR.
3253 F is the frame the menu bar belongs to. 3225 F is the frame the menu bar belongs to.
3254 VAL describes the contents of the menu bar. 3226 VAL describes the contents of the menu bar.
3255 If DEEP_P is non-zero, rebuild all but the top level menu names in 3227 If DEEP_P, rebuild all but the top level menu names in
3256 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar. 3228 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar.
3257 SELECT_CB is the callback to use when a menu item is selected. 3229 SELECT_CB is the callback to use when a menu item is selected.
3258 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. 3230 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
@@ -3260,7 +3232,7 @@ xg_update_submenu (GtkWidget *submenu,
3260 3232
3261void 3233void
3262xg_modify_menubar_widgets (GtkWidget *menubar, FRAME_PTR f, widget_value *val, 3234xg_modify_menubar_widgets (GtkWidget *menubar, FRAME_PTR f, widget_value *val,
3263 int deep_p, 3235 bool deep_p,
3264 GCallback select_cb, GCallback deactivate_cb, 3236 GCallback select_cb, GCallback deactivate_cb,
3265 GCallback highlight_cb) 3237 GCallback highlight_cb)
3266{ 3238{
@@ -3344,21 +3316,21 @@ menubar_map_cb (GtkWidget *w, gpointer user_data)
3344} 3316}
3345 3317
3346/* Recompute all the widgets of frame F, when the menu bar has been 3318/* Recompute all the widgets of frame F, when the menu bar has been
3347 changed. Value is non-zero if widgets were updated. */ 3319 changed. */
3348 3320
3349int 3321void
3350xg_update_frame_menubar (FRAME_PTR f) 3322xg_update_frame_menubar (FRAME_PTR f)
3351{ 3323{
3352 struct x_output *x = f->output_data.x; 3324 struct x_output *x = f->output_data.x;
3353 GtkRequisition req; 3325 GtkRequisition req;
3354 3326
3355 if (!x->menubar_widget || gtk_widget_get_mapped (x->menubar_widget)) 3327 if (!x->menubar_widget || gtk_widget_get_mapped (x->menubar_widget))
3356 return 0; 3328 return;
3357 3329
3358 if (x->menubar_widget && gtk_widget_get_parent (x->menubar_widget)) 3330 if (x->menubar_widget && gtk_widget_get_parent (x->menubar_widget))
3359 return 0; /* Already done this, happens for frames created invisible. */ 3331 return; /* Already done this, happens for frames created invisible. */
3360 3332
3361 BLOCK_INPUT; 3333 block_input ();
3362 3334
3363 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->menubar_widget, 3335 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->menubar_widget,
3364 FALSE, FALSE, 0); 3336 FALSE, FALSE, 0);
@@ -3378,9 +3350,7 @@ xg_update_frame_menubar (FRAME_PTR f)
3378 FRAME_MENUBAR_HEIGHT (f) = req.height; 3350 FRAME_MENUBAR_HEIGHT (f) = req.height;
3379 xg_height_or_width_changed (f); 3351 xg_height_or_width_changed (f);
3380 } 3352 }
3381 UNBLOCK_INPUT; 3353 unblock_input ();
3382
3383 return 1;
3384} 3354}
3385 3355
3386/* Get rid of the menu bar of frame F, and free its storage. 3356/* Get rid of the menu bar of frame F, and free its storage.
@@ -3393,7 +3363,7 @@ free_frame_menubar (FRAME_PTR f)
3393 3363
3394 if (x->menubar_widget) 3364 if (x->menubar_widget)
3395 { 3365 {
3396 BLOCK_INPUT; 3366 block_input ();
3397 3367
3398 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget); 3368 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget);
3399 /* The menubar and its children shall be deleted when removed from 3369 /* The menubar and its children shall be deleted when removed from
@@ -3401,11 +3371,11 @@ free_frame_menubar (FRAME_PTR f)
3401 x->menubar_widget = 0; 3371 x->menubar_widget = 0;
3402 FRAME_MENUBAR_HEIGHT (f) = 0; 3372 FRAME_MENUBAR_HEIGHT (f) = 0;
3403 xg_height_or_width_changed (f); 3373 xg_height_or_width_changed (f);
3404 UNBLOCK_INPUT; 3374 unblock_input ();
3405 } 3375 }
3406} 3376}
3407 3377
3408int 3378bool
3409xg_event_is_for_menubar (FRAME_PTR f, XEvent *event) 3379xg_event_is_for_menubar (FRAME_PTR f, XEvent *event)
3410{ 3380{
3411 struct x_output *x = f->output_data.x; 3381 struct x_output *x = f->output_data.x;
@@ -3452,7 +3422,7 @@ xg_event_is_for_menubar (FRAME_PTR f, XEvent *event)
3452 break; 3422 break;
3453 } 3423 }
3454 g_list_free (list); 3424 g_list_free (list);
3455 return iter == 0 ? 0 : 1; 3425 return iter != 0;
3456} 3426}
3457 3427
3458 3428
@@ -3465,7 +3435,7 @@ xg_event_is_for_menubar (FRAME_PTR f, XEvent *event)
3465/* Setting scroll bar values invokes the callback. Use this variable 3435/* Setting scroll bar values invokes the callback. Use this variable
3466 to indicate that callback should do nothing. */ 3436 to indicate that callback should do nothing. */
3467 3437
3468int xg_ignore_gtk_scrollbar; 3438bool xg_ignore_gtk_scrollbar;
3469 3439
3470/* The width of the scroll bar for the current theme. */ 3440/* The width of the scroll bar for the current theme. */
3471 3441
@@ -3791,7 +3761,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
3791 int size, value; 3761 int size, value;
3792 int old_size; 3762 int old_size;
3793 int new_step; 3763 int new_step;
3794 int changed = 0; 3764 bool changed = 0;
3795 3765
3796 adj = gtk_range_get_adjustment (GTK_RANGE (wscroll)); 3766 adj = gtk_range_get_adjustment (GTK_RANGE (wscroll));
3797 3767
@@ -3838,7 +3808,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
3838 3808
3839 if (changed || int_gtk_range_get_value (GTK_RANGE (wscroll)) != value) 3809 if (changed || int_gtk_range_get_value (GTK_RANGE (wscroll)) != value)
3840 { 3810 {
3841 BLOCK_INPUT; 3811 block_input ();
3842 3812
3843 /* gtk_range_set_value invokes the callback. Set 3813 /* gtk_range_set_value invokes the callback. Set
3844 ignore_gtk_scrollbar to make the callback do nothing */ 3814 ignore_gtk_scrollbar to make the callback do nothing */
@@ -3851,22 +3821,20 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
3851 3821
3852 xg_ignore_gtk_scrollbar = 0; 3822 xg_ignore_gtk_scrollbar = 0;
3853 3823
3854 UNBLOCK_INPUT; 3824 unblock_input ();
3855 } 3825 }
3856 } 3826 }
3857} 3827}
3858 3828
3859/* Return non-zero if EVENT is for a scroll bar in frame F. 3829/* Return true if EVENT is for a scroll bar in frame F.
3860 When the same X window is used for several Gtk+ widgets, we cannot 3830 When the same X window is used for several Gtk+ widgets, we cannot
3861 say for sure based on the X window alone if an event is for the 3831 say for sure based on the X window alone if an event is for the
3862 frame. This function does additional checks. 3832 frame. This function does additional checks. */
3863 3833
3864 Return non-zero if the event is for a scroll bar, zero otherwise. */ 3834bool
3865
3866int
3867xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event) 3835xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event)
3868{ 3836{
3869 int retval = 0; 3837 bool retval = 0;
3870 3838
3871 if (f && event->type == ButtonPress && event->xbutton.button < 4) 3839 if (f && event->type == ButtonPress && event->xbutton.button < 4)
3872 { 3840 {
@@ -4297,7 +4265,7 @@ static void
4297xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos) 4265xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
4298{ 4266{
4299 struct x_output *x = f->output_data.x; 4267 struct x_output *x = f->output_data.x;
4300 int into_hbox = EQ (pos, Qleft) || EQ (pos, Qright); 4268 bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright);
4301 4269
4302 toolbar_set_orientation (x->toolbar_widget, 4270 toolbar_set_orientation (x->toolbar_widget,
4303 into_hbox 4271 into_hbox
@@ -4329,7 +4297,7 @@ xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
4329 } 4297 }
4330 else 4298 else
4331 { 4299 {
4332 int vbox_pos = x->menubar_widget ? 1 : 0; 4300 bool vbox_pos = x->menubar_widget != 0;
4333 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget), 4301 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget),
4334 GTK_POS_LEFT); 4302 GTK_POS_LEFT);
4335 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget, 4303 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget,
@@ -4420,7 +4388,7 @@ xg_make_tool_item (FRAME_PTR f,
4420 GtkWidget *wimage, 4388 GtkWidget *wimage,
4421 GtkWidget **wbutton, 4389 GtkWidget **wbutton,
4422 const char *label, 4390 const char *label,
4423 int i, int horiz, int text_image) 4391 int i, bool horiz, bool text_image)
4424{ 4392{
4425 GtkToolItem *ti = gtk_tool_item_new (); 4393 GtkToolItem *ti = gtk_tool_item_new ();
4426 GtkWidget *vb = gtk_box_new (horiz 4394 GtkWidget *vb = gtk_box_new (horiz
@@ -4515,11 +4483,11 @@ xg_make_tool_item (FRAME_PTR f,
4515 return ti; 4483 return ti;
4516} 4484}
4517 4485
4518static int 4486static bool
4519is_box_type (GtkWidget *vb, int is_horizontal) 4487is_box_type (GtkWidget *vb, bool is_horizontal)
4520{ 4488{
4521#ifdef HAVE_GTK3 4489#ifdef HAVE_GTK3
4522 int ret = 0; 4490 bool ret = 0;
4523 if (GTK_IS_BOX (vb)) 4491 if (GTK_IS_BOX (vb))
4524 { 4492 {
4525 GtkOrientation ori = gtk_orientable_get_orientation (GTK_ORIENTABLE (vb)); 4493 GtkOrientation ori = gtk_orientable_get_orientation (GTK_ORIENTABLE (vb));
@@ -4533,10 +4501,10 @@ is_box_type (GtkWidget *vb, int is_horizontal)
4533} 4501}
4534 4502
4535 4503
4536static int 4504static bool
4537xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name, 4505xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name,
4538 const char *icon_name, const struct image *img, 4506 const char *icon_name, const struct image *img,
4539 const char *label, int horiz) 4507 const char *label, bool horiz)
4540{ 4508{
4541 gpointer old; 4509 gpointer old;
4542 GtkWidget *wimage; 4510 GtkWidget *wimage;
@@ -4578,7 +4546,7 @@ xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name,
4578 return 0; 4546 return 0;
4579} 4547}
4580 4548
4581static int 4549static bool
4582xg_update_tool_bar_sizes (FRAME_PTR f) 4550xg_update_tool_bar_sizes (FRAME_PTR f)
4583{ 4551{
4584 struct x_output *x = f->output_data.x; 4552 struct x_output *x = f->output_data.x;
@@ -4634,15 +4602,15 @@ update_frame_tool_bar (FRAME_PTR f)
4634 GtkToolbar *wtoolbar; 4602 GtkToolbar *wtoolbar;
4635 GtkToolItem *ti; 4603 GtkToolItem *ti;
4636 GtkTextDirection dir; 4604 GtkTextDirection dir;
4637 int pack_tool_bar = x->handlebox_widget == NULL; 4605 bool pack_tool_bar = x->handlebox_widget == NULL;
4638 Lisp_Object style; 4606 Lisp_Object style;
4639 int text_image, horiz; 4607 bool text_image, horiz;
4640 struct xg_frame_tb_info *tbinfo; 4608 struct xg_frame_tb_info *tbinfo;
4641 4609
4642 if (! FRAME_GTK_WIDGET (f)) 4610 if (! FRAME_GTK_WIDGET (f))
4643 return; 4611 return;
4644 4612
4645 BLOCK_INPUT; 4613 block_input ();
4646 4614
4647 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX)) 4615 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4648 { 4616 {
@@ -4684,7 +4652,7 @@ update_frame_tool_bar (FRAME_PTR f)
4684 && ! NILP (Fequal (tbinfo->style, style)) 4652 && ! NILP (Fequal (tbinfo->style, style))
4685 && ! NILP (Fequal (tbinfo->last_tool_bar, f->tool_bar_items))) 4653 && ! NILP (Fequal (tbinfo->last_tool_bar, f->tool_bar_items)))
4686 { 4654 {
4687 UNBLOCK_INPUT; 4655 unblock_input ();
4688 return; 4656 return;
4689 } 4657 }
4690 4658
@@ -4700,8 +4668,8 @@ update_frame_tool_bar (FRAME_PTR f)
4700 4668
4701 for (i = j = 0; i < f->n_tool_bar_items; ++i) 4669 for (i = j = 0; i < f->n_tool_bar_items; ++i)
4702 { 4670 {
4703 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); 4671 bool enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P));
4704 int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); 4672 bool selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P));
4705 int idx; 4673 int idx;
4706 ptrdiff_t img_id; 4674 ptrdiff_t img_id;
4707 int icon_size = 0; 4675 int icon_size = 0;
@@ -4714,7 +4682,7 @@ update_frame_tool_bar (FRAME_PTR f)
4714 Lisp_Object rtl; 4682 Lisp_Object rtl;
4715 GtkWidget *wbutton = NULL; 4683 GtkWidget *wbutton = NULL;
4716 Lisp_Object specified_file; 4684 Lisp_Object specified_file;
4717 int vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY)); 4685 bool vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY));
4718 const char *label 4686 const char *label
4719 = (EQ (style, Qimage) || (vert_only && horiz)) ? NULL 4687 = (EQ (style, Qimage) || (vert_only && horiz)) ? NULL
4720 : STRINGP (PROP (TOOL_BAR_ITEM_LABEL)) 4688 : STRINGP (PROP (TOOL_BAR_ITEM_LABEL))
@@ -4895,7 +4863,7 @@ update_frame_tool_bar (FRAME_PTR f)
4895 xg_height_or_width_changed (f); 4863 xg_height_or_width_changed (f);
4896 } 4864 }
4897 4865
4898 UNBLOCK_INPUT; 4866 unblock_input ();
4899} 4867}
4900 4868
4901/* Deallocate all resources for the tool bar on frame F. 4869/* Deallocate all resources for the tool bar on frame F.
@@ -4909,8 +4877,8 @@ free_frame_tool_bar (FRAME_PTR f)
4909 if (x->toolbar_widget) 4877 if (x->toolbar_widget)
4910 { 4878 {
4911 struct xg_frame_tb_info *tbinfo; 4879 struct xg_frame_tb_info *tbinfo;
4912 int is_packed = x->handlebox_widget != 0; 4880 bool is_packed = x->handlebox_widget != 0;
4913 BLOCK_INPUT; 4881 block_input ();
4914 /* We may have created the toolbar_widget in xg_create_tool_bar, but 4882 /* We may have created the toolbar_widget in xg_create_tool_bar, but
4915 not the x->handlebox_widget which is created in xg_pack_tool_bar. */ 4883 not the x->handlebox_widget which is created in xg_pack_tool_bar. */
4916 if (is_packed) 4884 if (is_packed)
@@ -4942,19 +4910,19 @@ free_frame_tool_bar (FRAME_PTR f)
4942 4910
4943 xg_height_or_width_changed (f); 4911 xg_height_or_width_changed (f);
4944 4912
4945 UNBLOCK_INPUT; 4913 unblock_input ();
4946 } 4914 }
4947} 4915}
4948 4916
4949int 4917void
4950xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos) 4918xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos)
4951{ 4919{
4952 struct x_output *x = f->output_data.x; 4920 struct x_output *x = f->output_data.x;
4953 4921
4954 if (! x->toolbar_widget || ! x->handlebox_widget) 4922 if (! x->toolbar_widget || ! x->handlebox_widget)
4955 return 1; 4923 return;
4956 4924
4957 BLOCK_INPUT; 4925 block_input ();
4958 g_object_ref (x->handlebox_widget); 4926 g_object_ref (x->handlebox_widget);
4959 if (x->toolbar_in_hbox) 4927 if (x->toolbar_in_hbox)
4960 gtk_container_remove (GTK_CONTAINER (x->hbox_widget), 4928 gtk_container_remove (GTK_CONTAINER (x->hbox_widget),
@@ -4967,8 +4935,7 @@ xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos)
4967 if (xg_update_tool_bar_sizes (f)) 4935 if (xg_update_tool_bar_sizes (f))
4968 xg_height_or_width_changed (f); 4936 xg_height_or_width_changed (f);
4969 4937
4970 UNBLOCK_INPUT; 4938 unblock_input ();
4971 return 1;
4972} 4939}
4973 4940
4974 4941
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 926478dd728..43f2b237a68 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -79,13 +79,13 @@ struct _widget_value;
79extern struct _widget_value *malloc_widget_value (void); 79extern struct _widget_value *malloc_widget_value (void);
80extern void free_widget_value (struct _widget_value *); 80extern void free_widget_value (struct _widget_value *);
81 81
82extern int xg_uses_old_file_dialog (void) ATTRIBUTE_CONST; 82extern bool xg_uses_old_file_dialog (void) ATTRIBUTE_CONST;
83 83
84extern char *xg_get_file_name (FRAME_PTR f, 84extern char *xg_get_file_name (FRAME_PTR f,
85 char *prompt, 85 char *prompt,
86 char *default_filename, 86 char *default_filename,
87 int mustmatch_p, 87 bool mustmatch_p,
88 int only_dir_p); 88 bool only_dir_p);
89 89
90extern Lisp_Object xg_get_font (FRAME_PTR f, const char *); 90extern Lisp_Object xg_get_font (FRAME_PTR f, const char *);
91 91
@@ -100,16 +100,16 @@ extern GtkWidget *xg_create_widget (const char *type,
100extern void xg_modify_menubar_widgets (GtkWidget *menubar, 100extern void xg_modify_menubar_widgets (GtkWidget *menubar,
101 FRAME_PTR f, 101 FRAME_PTR f,
102 struct _widget_value *val, 102 struct _widget_value *val,
103 int deep_p, 103 bool deep_p,
104 GCallback select_cb, 104 GCallback select_cb,
105 GCallback deactivate_cb, 105 GCallback deactivate_cb,
106 GCallback highlight_cb); 106 GCallback highlight_cb);
107 107
108extern int xg_update_frame_menubar (FRAME_PTR f); 108extern void xg_update_frame_menubar (FRAME_PTR f);
109 109
110extern int xg_event_is_for_menubar (FRAME_PTR f, XEvent *event); 110extern bool xg_event_is_for_menubar (FRAME_PTR f, XEvent *event);
111 111
112extern int xg_have_tear_offs (void); 112extern bool xg_have_tear_offs (void);
113 113
114extern ptrdiff_t xg_get_scroll_id_for_window (Display *dpy, Window wid); 114extern ptrdiff_t xg_get_scroll_id_for_window (Display *dpy, Window wid);
115 115
@@ -131,12 +131,12 @@ extern void xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
131 int portion, 131 int portion,
132 int position, 132 int position,
133 int whole); 133 int whole);
134extern int xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event); 134extern bool xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event);
135extern int xg_get_default_scrollbar_width (void); 135extern int xg_get_default_scrollbar_width (void);
136 136
137extern void update_frame_tool_bar (FRAME_PTR f); 137extern void update_frame_tool_bar (FRAME_PTR f);
138extern void free_frame_tool_bar (FRAME_PTR f); 138extern void free_frame_tool_bar (FRAME_PTR f);
139extern int xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos); 139extern void xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos);
140 140
141extern void xg_frame_resized (FRAME_PTR f, 141extern void xg_frame_resized (FRAME_PTR f,
142 int pixelwidth, 142 int pixelwidth,
@@ -148,23 +148,23 @@ extern void xg_display_open (char *display_name, Display **dpy);
148extern void xg_display_close (Display *dpy); 148extern void xg_display_close (Display *dpy);
149extern GdkCursor * xg_create_default_cursor (Display *dpy); 149extern GdkCursor * xg_create_default_cursor (Display *dpy);
150 150
151extern int xg_create_frame_widgets (FRAME_PTR f); 151extern bool xg_create_frame_widgets (FRAME_PTR f);
152extern void xg_free_frame_widgets (FRAME_PTR f); 152extern void xg_free_frame_widgets (FRAME_PTR f);
153extern void xg_set_background_color (FRAME_PTR f, unsigned long bg); 153extern void xg_set_background_color (FRAME_PTR f, unsigned long bg);
154extern int xg_check_special_colors (struct frame *f, 154extern bool xg_check_special_colors (struct frame *f,
155 const char *color_name, 155 const char *color_name,
156 XColor *color); 156 XColor *color);
157 157
158extern void xg_set_frame_icon (FRAME_PTR f, 158extern void xg_set_frame_icon (FRAME_PTR f,
159 Pixmap icon_pixmap, 159 Pixmap icon_pixmap,
160 Pixmap icon_mask); 160 Pixmap icon_mask);
161 161
162extern int xg_prepare_tooltip (FRAME_PTR f, 162extern bool xg_prepare_tooltip (FRAME_PTR f,
163 Lisp_Object string, 163 Lisp_Object string,
164 int *width, 164 int *width,
165 int *height); 165 int *height);
166extern void xg_show_tooltip (FRAME_PTR f, int root_x, int root_y); 166extern void xg_show_tooltip (FRAME_PTR f, int root_x, int root_y);
167extern int xg_hide_tooltip (FRAME_PTR f); 167extern bool xg_hide_tooltip (FRAME_PTR f);
168 168
169 169
170/* Mark all callback data that are Lisp_object:s during GC. */ 170/* Mark all callback data that are Lisp_object:s during GC. */
@@ -175,7 +175,7 @@ extern void xg_initialize (void);
175 175
176/* Setting scrollbar values invokes the callback. Use this variable 176/* Setting scrollbar values invokes the callback. Use this variable
177 to indicate that the callback should do nothing. */ 177 to indicate that the callback should do nothing. */
178extern int xg_ignore_gtk_scrollbar; 178extern bool xg_ignore_gtk_scrollbar;
179 179
180#endif /* USE_GTK */ 180#endif /* USE_GTK */
181#endif /* GTKUTIL_H */ 181#endif /* GTKUTIL_H */
diff --git a/src/image.c b/src/image.c
index a562868d94d..6fc459f0bbc 100644
--- a/src/image.c
+++ b/src/image.c
@@ -190,11 +190,11 @@ x_bitmap_width (FRAME_PTR f, ptrdiff_t id)
190} 190}
191 191
192#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) 192#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
193int 193ptrdiff_t
194x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id) 194x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id)
195{ 195{
196 /* HAVE_NTGUI needs the explicit cast here. */ 196 /* HAVE_NTGUI needs the explicit cast here. */
197 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 197 return (ptrdiff_t) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
198} 198}
199#endif 199#endif
200 200
@@ -411,9 +411,9 @@ x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id)
411 411
412 if (--bm->refcount == 0) 412 if (--bm->refcount == 0)
413 { 413 {
414 BLOCK_INPUT; 414 block_input ();
415 free_bitmap_record (dpyinfo, bm); 415 free_bitmap_record (dpyinfo, bm);
416 UNBLOCK_INPUT; 416 unblock_input ();
417 } 417 }
418 } 418 }
419} 419}
@@ -433,6 +433,9 @@ x_destroy_all_bitmaps (Display_Info *dpyinfo)
433 dpyinfo->bitmaps_last = 0; 433 dpyinfo->bitmaps_last = 0;
434} 434}
435 435
436static bool x_create_x_image_and_pixmap (struct frame *, int, int, int,
437 XImagePtr *, Pixmap *);
438static void x_destroy_x_image (XImagePtr ximg);
436 439
437#ifdef HAVE_X_WINDOWS 440#ifdef HAVE_X_WINDOWS
438 441
@@ -444,23 +447,17 @@ static unsigned long four_corners_best (XImagePtr ximg,
444 unsigned long width, 447 unsigned long width,
445 unsigned long height); 448 unsigned long height);
446 449
447static int x_create_x_image_and_pixmap (struct frame *f, int width, int height,
448 int depth, XImagePtr *ximg,
449 Pixmap *pixmap);
450
451static void x_destroy_x_image (XImagePtr ximg);
452
453 450
454/* Create a mask of a bitmap. Note is this not a perfect mask. 451/* Create a mask of a bitmap. Note is this not a perfect mask.
455 It's nicer with some borders in this context */ 452 It's nicer with some borders in this context */
456 453
457int 454void
458x_create_bitmap_mask (struct frame *f, ptrdiff_t id) 455x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
459{ 456{
460 Pixmap pixmap, mask; 457 Pixmap pixmap, mask;
461 XImagePtr ximg, mask_img; 458 XImagePtr ximg, mask_img;
462 unsigned long width, height; 459 unsigned long width, height;
463 int result; 460 bool result;
464 unsigned long bg; 461 unsigned long bg;
465 unsigned long x, y, xp, xm, yp, ym; 462 unsigned long x, y, xp, xm, yp, ym;
466 GC gc; 463 GC gc;
@@ -468,29 +465,29 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
468 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 465 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
469 466
470 if (!(id > 0)) 467 if (!(id > 0))
471 return -1; 468 return;
472 469
473 pixmap = x_bitmap_pixmap (f, id); 470 pixmap = x_bitmap_pixmap (f, id);
474 width = x_bitmap_width (f, id); 471 width = x_bitmap_width (f, id);
475 height = x_bitmap_height (f, id); 472 height = x_bitmap_height (f, id);
476 473
477 BLOCK_INPUT; 474 block_input ();
478 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, 475 ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height,
479 ~0, ZPixmap); 476 ~0, ZPixmap);
480 477
481 if (!ximg) 478 if (!ximg)
482 { 479 {
483 UNBLOCK_INPUT; 480 unblock_input ();
484 return -1; 481 return;
485 } 482 }
486 483
487 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask); 484 result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask);
488 485
489 UNBLOCK_INPUT; 486 unblock_input ();
490 if (!result) 487 if (!result)
491 { 488 {
492 XDestroyImage (ximg); 489 XDestroyImage (ximg);
493 return -1; 490 return;
494 } 491 }
495 492
496 bg = four_corners_best (ximg, NULL, width, height); 493 bg = four_corners_best (ximg, NULL, width, height);
@@ -518,7 +515,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
518 } 515 }
519 } 516 }
520 517
521 eassert (interrupt_input_blocked); 518 eassert (input_blocked_p ());
522 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL); 519 gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL);
523 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0, 520 XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0,
524 width, height); 521 width, height);
@@ -529,8 +526,6 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
529 526
530 XDestroyImage (ximg); 527 XDestroyImage (ximg);
531 x_destroy_x_image (mask_img); 528 x_destroy_x_image (mask_img);
532
533 return 0;
534} 529}
535 530
536#endif /* HAVE_X_WINDOWS */ 531#endif /* HAVE_X_WINDOWS */
@@ -563,15 +558,13 @@ static Lisp_Object QCcrop, QCrotation;
563static Lisp_Object Qcount, Qextension_data, Qdelay; 558static Lisp_Object Qcount, Qextension_data, Qdelay;
564static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic; 559static Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic;
565 560
566/* Function prototypes. */ 561/* Forward function prototypes. */
567 562
568static Lisp_Object define_image_type (struct image_type *type, int loaded); 563static struct image_type *lookup_image_type (Lisp_Object);
569static struct image_type *lookup_image_type (Lisp_Object symbol);
570static void image_error (const char *format, Lisp_Object, Lisp_Object);
571static void x_laplace (struct frame *, struct image *); 564static void x_laplace (struct frame *, struct image *);
572static void x_emboss (struct frame *, struct image *); 565static void x_emboss (struct frame *, struct image *);
573static int x_build_heuristic_mask (struct frame *, struct image *, 566static void x_build_heuristic_mask (struct frame *, struct image *,
574 Lisp_Object); 567 Lisp_Object);
575#ifdef WINDOWSNT 568#ifdef WINDOWSNT
576extern Lisp_Object Vlibrary_cache; 569extern Lisp_Object Vlibrary_cache;
577#define CACHE_IMAGE_TYPE(type, status) \ 570#define CACHE_IMAGE_TYPE(type, status) \
@@ -586,60 +579,61 @@ extern Lisp_Object Vlibrary_cache;
586/* Define a new image type from TYPE. This adds a copy of TYPE to 579/* Define a new image type from TYPE. This adds a copy of TYPE to
587 image_types and caches the loading status of TYPE. */ 580 image_types and caches the loading status of TYPE. */
588 581
589static Lisp_Object 582static struct image_type *
590define_image_type (struct image_type *type, int loaded) 583define_image_type (struct image_type *type)
591{ 584{
592 Lisp_Object success; 585 struct image_type *p = NULL;
586 Lisp_Object target_type = *type->type;
587 bool type_valid = 1;
593 588
594 if (!loaded) 589 block_input ();
595 success = Qnil; 590
596 else 591 for (p = image_types; p; p = p->next)
592 if (EQ (*p->type, target_type))
593 goto done;
594
595 if (type->init)
596 {
597#if defined (HAVE_NTGUI) && defined (WINDOWSNT)
598 /* If we failed to load the library before, don't try again. */
599 Lisp_Object tested = Fassq (target_type, Vlibrary_cache);
600 if (CONSP (tested) && NILP (XCDR (tested)))
601 type_valid = 0;
602 else
603#endif
604 {
605 type_valid = type->init ();
606 CACHE_IMAGE_TYPE (target_type, type_valid ? Qt : Qnil);
607 }
608 }
609
610 if (type_valid)
597 { 611 {
598 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 612 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
599 The initialized data segment is read-only. */ 613 The initialized data segment is read-only. */
600 struct image_type *p = xmalloc (sizeof *p); 614 p = xmalloc (sizeof *p);
601 *p = *type; 615 *p = *type;
602 p->next = image_types; 616 p->next = image_types;
603 image_types = p; 617 image_types = p;
604 success = Qt;
605 } 618 }
606 619
607 CACHE_IMAGE_TYPE (*type->type, success); 620 done:
608 return success; 621 unblock_input ();
609} 622 return p;
610
611
612/* Look up image type SYMBOL, and return a pointer to its image_type
613 structure. Value is null if SYMBOL is not a known image type. */
614
615static inline struct image_type *
616lookup_image_type (Lisp_Object symbol)
617{
618 struct image_type *type;
619
620 /* We must initialize the image-type if it hasn't been already. */
621 if (NILP (Finit_image_library (symbol, Vdynamic_library_alist)))
622 return 0; /* unimplemented */
623
624 for (type = image_types; type; type = type->next)
625 if (EQ (symbol, *type->type))
626 break;
627
628 return type;
629} 623}
630 624
631 625
632/* Value is non-zero if OBJECT is a valid Lisp image specification. A 626/* Value is true if OBJECT is a valid Lisp image specification. A
633 valid image specification is a list whose car is the symbol 627 valid image specification is a list whose car is the symbol
634 `image', and whose rest is a property list. The property list must 628 `image', and whose rest is a property list. The property list must
635 contain a value for key `:type'. That value must be the name of a 629 contain a value for key `:type'. That value must be the name of a
636 supported image type. The rest of the property list depends on the 630 supported image type. The rest of the property list depends on the
637 image type. */ 631 image type. */
638 632
639int 633bool
640valid_image_p (Lisp_Object object) 634valid_image_p (Lisp_Object object)
641{ 635{
642 int valid_p = 0; 636 bool valid_p = 0;
643 637
644 if (IMAGEP (object)) 638 if (IMAGEP (object))
645 { 639 {
@@ -709,8 +703,8 @@ struct image_keyword
709 /* The type of value allowed. */ 703 /* The type of value allowed. */
710 enum image_value_type type; 704 enum image_value_type type;
711 705
712 /* Non-zero means key must be present. */ 706 /* True means key must be present. */
713 int mandatory_p; 707 bool mandatory_p;
714 708
715 /* Used to recognize duplicate keywords in a property list. */ 709 /* Used to recognize duplicate keywords in a property list. */
716 int count; 710 int count;
@@ -720,18 +714,13 @@ struct image_keyword
720}; 714};
721 715
722 716
723static int parse_image_spec (Lisp_Object, struct image_keyword *,
724 int, Lisp_Object);
725static Lisp_Object image_spec_value (Lisp_Object, Lisp_Object, int *);
726
727
728/* Parse image spec SPEC according to KEYWORDS. A valid image spec 717/* Parse image spec SPEC according to KEYWORDS. A valid image spec
729 has the format (image KEYWORD VALUE ...). One of the keyword/ 718 has the format (image KEYWORD VALUE ...). One of the keyword/
730 value pairs must be `:type TYPE'. KEYWORDS is a vector of 719 value pairs must be `:type TYPE'. KEYWORDS is a vector of
731 image_keywords structures of size NKEYWORDS describing other 720 image_keywords structures of size NKEYWORDS describing other
732 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */ 721 allowed keyword/value pairs. Value is true if SPEC is valid. */
733 722
734static int 723static bool
735parse_image_spec (Lisp_Object spec, struct image_keyword *keywords, 724parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
736 int nkeywords, Lisp_Object type) 725 int nkeywords, Lisp_Object type)
737{ 726{
@@ -863,11 +852,11 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
863 852
864 853
865/* Return the value of KEY in image specification SPEC. Value is nil 854/* Return the value of KEY in image specification SPEC. Value is nil
866 if KEY is not present in SPEC. if FOUND is not null, set *FOUND 855 if KEY is not present in SPEC. Set *FOUND depending on whether KEY
867 to 1 if KEY was found in SPEC, set it to 0 otherwise. */ 856 was found in SPEC. */
868 857
869static Lisp_Object 858static Lisp_Object
870image_spec_value (Lisp_Object spec, Lisp_Object key, int *found) 859image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
871{ 860{
872 Lisp_Object tail; 861 Lisp_Object tail;
873 862
@@ -971,8 +960,6 @@ or omitted means use the selected frame. */)
971 Image type independent image structures 960 Image type independent image structures
972 ***********************************************************************/ 961 ***********************************************************************/
973 962
974static void free_image (struct frame *f, struct image *img);
975
976#define MAX_IMAGE_SIZE 10.0 963#define MAX_IMAGE_SIZE 10.0
977/* Allocate and return a new image structure for image specification 964/* Allocate and return a new image structure for image specification
978 SPEC. SPEC has a hash value of HASH. */ 965 SPEC. SPEC has a hash value of HASH. */
@@ -1022,10 +1009,9 @@ free_image (struct frame *f, struct image *img)
1022 } 1009 }
1023} 1010}
1024 1011
1025/* Return 1 if the given widths and heights are valid for display; 1012/* Return true if the given widths and heights are valid for display. */
1026 otherwise, return 0. */
1027 1013
1028static int 1014static bool
1029check_image_size (struct frame *f, int width, int height) 1015check_image_size (struct frame *f, int width, int height)
1030{ 1016{
1031 int w, h; 1017 int w, h;
@@ -1064,7 +1050,7 @@ prepare_image_for_display (struct frame *f, struct image *img)
1064 /* If IMG doesn't have a pixmap yet, load it now, using the image 1050 /* If IMG doesn't have a pixmap yet, load it now, using the image
1065 type dependent loader function. */ 1051 type dependent loader function. */
1066 if (img->pixmap == NO_PIXMAP && !img->load_failed_p) 1052 if (img->pixmap == NO_PIXMAP && !img->load_failed_p)
1067 img->load_failed_p = img->type->load (f, img) == 0; 1053 img->load_failed_p = ! img->type->load (f, img);
1068 1054
1069} 1055}
1070 1056
@@ -1197,7 +1183,7 @@ image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg)
1197 if (! img->background_valid) 1183 if (! img->background_valid)
1198 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1184 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1199 { 1185 {
1200 int free_ximg = !ximg; 1186 bool free_ximg = !ximg;
1201#ifdef HAVE_NTGUI 1187#ifdef HAVE_NTGUI
1202 HGDIOBJ prev; 1188 HGDIOBJ prev;
1203#endif /* HAVE_NTGUI */ 1189#endif /* HAVE_NTGUI */
@@ -1238,7 +1224,7 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1238 { 1224 {
1239 if (img->mask) 1225 if (img->mask)
1240 { 1226 {
1241 int free_mask = !mask; 1227 bool free_mask = !mask;
1242#ifdef HAVE_NTGUI 1228#ifdef HAVE_NTGUI
1243 HGDIOBJ prev; 1229 HGDIOBJ prev;
1244#endif /* HAVE_NTGUI */ 1230#endif /* HAVE_NTGUI */
@@ -1276,23 +1262,13 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
1276 Helper functions for X image types 1262 Helper functions for X image types
1277 ***********************************************************************/ 1263 ***********************************************************************/
1278 1264
1279static void x_clear_image_1 (struct frame *, struct image *, int, 1265/* Clear X resources of image IMG on frame F. PIXMAP_P means free the
1280 int, int); 1266 pixmap if any. MASK_P means clear the mask pixmap if any.
1281static void x_clear_image (struct frame *f, struct image *img); 1267 COLORS_P means free colors allocated for the image, if any. */
1282static unsigned long x_alloc_image_color (struct frame *f,
1283 struct image *img,
1284 Lisp_Object color_name,
1285 unsigned long dflt);
1286
1287
1288/* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
1289 free the pixmap if any. MASK_P non-zero means clear the mask
1290 pixmap if any. COLORS_P non-zero means free colors allocated for
1291 the image, if any. */
1292 1268
1293static void 1269static void
1294x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p, 1270x_clear_image_1 (struct frame *f, struct image *img, bool pixmap_p,
1295 int colors_p) 1271 bool mask_p, bool colors_p)
1296{ 1272{
1297 if (pixmap_p && img->pixmap) 1273 if (pixmap_p && img->pixmap)
1298 { 1274 {
@@ -1327,9 +1303,9 @@ x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p,
1327static void 1303static void
1328x_clear_image (struct frame *f, struct image *img) 1304x_clear_image (struct frame *f, struct image *img)
1329{ 1305{
1330 BLOCK_INPUT; 1306 block_input ();
1331 x_clear_image_1 (f, img, 1, 1, 1); 1307 x_clear_image_1 (f, img, 1, 1, 1);
1332 UNBLOCK_INPUT; 1308 unblock_input ();
1333} 1309}
1334 1310
1335 1311
@@ -1372,7 +1348,6 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
1372 ***********************************************************************/ 1348 ***********************************************************************/
1373 1349
1374static void cache_image (struct frame *f, struct image *img); 1350static void cache_image (struct frame *f, struct image *img);
1375static void postprocess_image (struct frame *, struct image *);
1376 1351
1377/* Return a new, initialized image cache that is allocated from the 1352/* Return a new, initialized image cache that is allocated from the
1378 heap. Call free_image_cache to free an image cache. */ 1353 heap. Call free_image_cache to free an image cache. */
@@ -1484,7 +1459,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1484 1459
1485 /* Block input so that we won't be interrupted by a SIGIO 1460 /* Block input so that we won't be interrupted by a SIGIO
1486 while being in an inconsistent state. */ 1461 while being in an inconsistent state. */
1487 BLOCK_INPUT; 1462 block_input ();
1488 1463
1489 if (!NILP (filter)) 1464 if (!NILP (filter))
1490 { 1465 {
@@ -1550,7 +1525,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1550 ++windows_or_buffers_changed; 1525 ++windows_or_buffers_changed;
1551 } 1526 }
1552 1527
1553 UNBLOCK_INPUT; 1528 unblock_input ();
1554 } 1529 }
1555} 1530}
1556 1531
@@ -1645,7 +1620,7 @@ postprocess_image (struct frame *f, struct image *img)
1645 x_build_heuristic_mask (f, img, mask); 1620 x_build_heuristic_mask (f, img, mask);
1646 else 1621 else
1647 { 1622 {
1648 int found_p; 1623 bool found_p;
1649 1624
1650 mask = image_spec_value (spec, QCmask, &found_p); 1625 mask = image_spec_value (spec, QCmask, &found_p);
1651 1626
@@ -1715,10 +1690,10 @@ lookup_image (struct frame *f, Lisp_Object spec)
1715 /* If not found, create a new image and cache it. */ 1690 /* If not found, create a new image and cache it. */
1716 if (img == NULL) 1691 if (img == NULL)
1717 { 1692 {
1718 BLOCK_INPUT; 1693 block_input ();
1719 img = make_image (spec, hash); 1694 img = make_image (spec, hash);
1720 cache_image (f, img); 1695 cache_image (f, img);
1721 img->load_failed_p = img->type->load (f, img) == 0; 1696 img->load_failed_p = ! img->type->load (f, img);
1722 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f); 1697 img->frame_foreground = FRAME_FOREGROUND_PIXEL (f);
1723 img->frame_background = FRAME_BACKGROUND_PIXEL (f); 1698 img->frame_background = FRAME_BACKGROUND_PIXEL (f);
1724 1699
@@ -1786,7 +1761,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1786 postprocess_image (f, img); 1761 postprocess_image (f, img);
1787 } 1762 }
1788 1763
1789 UNBLOCK_INPUT; 1764 unblock_input ();
1790 } 1765 }
1791 1766
1792 /* We're using IMG, so set its timestamp to `now'. */ 1767 /* We're using IMG, so set its timestamp to `now'. */
@@ -1877,16 +1852,11 @@ mark_image_cache (struct image_cache *c)
1877 1852
1878#endif /* WINDOWSNT */ 1853#endif /* WINDOWSNT */
1879 1854
1880static int x_create_x_image_and_pixmap (struct frame *, int, int, int, 1855/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the
1881 XImagePtr *, Pixmap *);
1882static void x_destroy_x_image (XImagePtr);
1883static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int);
1884
1885/* Return nonzero if XIMG's size WIDTH x HEIGHT doesn't break the
1886 windowing system. 1856 windowing system.
1887 WIDTH and HEIGHT must both be positive. 1857 WIDTH and HEIGHT must both be positive.
1888 If XIMG is null, assume it is a bitmap. */ 1858 If XIMG is null, assume it is a bitmap. */
1889static int 1859static bool
1890x_check_image_size (XImagePtr ximg, int width, int height) 1860x_check_image_size (XImagePtr ximg, int width, int height)
1891{ 1861{
1892#ifdef HAVE_X_WINDOWS 1862#ifdef HAVE_X_WINDOWS
@@ -1925,12 +1895,12 @@ x_check_image_size (XImagePtr ximg, int width, int height)
1925 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. 1895 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
1926 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated 1896 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
1927 via xmalloc. Print error messages via image_error if an error 1897 via xmalloc. Print error messages via image_error if an error
1928 occurs. Value is non-zero if successful. 1898 occurs. Value is true if successful.
1929 1899
1930 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH 1900 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH
1931 should indicate the bit depth of the image. */ 1901 should indicate the bit depth of the image. */
1932 1902
1933static int 1903static bool
1934x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, 1904x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1935 XImagePtr *ximg, Pixmap *pixmap) 1905 XImagePtr *ximg, Pixmap *pixmap)
1936{ 1906{
@@ -1939,7 +1909,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1939 Window window = FRAME_X_WINDOW (f); 1909 Window window = FRAME_X_WINDOW (f);
1940 Screen *screen = FRAME_X_SCREEN (f); 1910 Screen *screen = FRAME_X_SCREEN (f);
1941 1911
1942 eassert (interrupt_input_blocked); 1912 eassert (input_blocked_p ());
1943 1913
1944 if (depth <= 0) 1914 if (depth <= 0)
1945 depth = DefaultDepthOfScreen (screen); 1915 depth = DefaultDepthOfScreen (screen);
@@ -2077,7 +2047,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
2077static void 2047static void
2078x_destroy_x_image (XImagePtr ximg) 2048x_destroy_x_image (XImagePtr ximg)
2079{ 2049{
2080 eassert (interrupt_input_blocked); 2050 eassert (input_blocked_p ());
2081 if (ximg) 2051 if (ximg)
2082 { 2052 {
2083#ifdef HAVE_X_WINDOWS 2053#ifdef HAVE_X_WINDOWS
@@ -2106,7 +2076,7 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he
2106#ifdef HAVE_X_WINDOWS 2076#ifdef HAVE_X_WINDOWS
2107 GC gc; 2077 GC gc;
2108 2078
2109 eassert (interrupt_input_blocked); 2079 eassert (input_blocked_p ());
2110 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); 2080 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL);
2111 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height); 2081 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height);
2112 XFreeGC (FRAME_X_DISPLAY (f), gc); 2082 XFreeGC (FRAME_X_DISPLAY (f), gc);
@@ -2202,15 +2172,9 @@ slurp_file (char *file, ptrdiff_t *size)
2202 XBM images 2172 XBM images
2203 ***********************************************************************/ 2173 ***********************************************************************/
2204 2174
2205static int xbm_scan (unsigned char **, unsigned char *, char *, int *); 2175static bool xbm_load (struct frame *f, struct image *img);
2206static int xbm_load (struct frame *f, struct image *img); 2176static bool xbm_image_p (Lisp_Object object);
2207static int xbm_load_image (struct frame *f, struct image *img, 2177static bool xbm_file_p (Lisp_Object);
2208 unsigned char *, unsigned char *);
2209static int xbm_image_p (Lisp_Object object);
2210static int xbm_read_bitmap_data (struct frame *f,
2211 unsigned char *, unsigned char *,
2212 int *, int *, char **, int);
2213static int xbm_file_p (Lisp_Object);
2214 2178
2215 2179
2216/* Indices of image specification fields in xbm_format, below. */ 2180/* Indices of image specification fields in xbm_format, below. */
@@ -2261,6 +2225,7 @@ static struct image_type xbm_type =
2261 xbm_image_p, 2225 xbm_image_p,
2262 xbm_load, 2226 xbm_load,
2263 x_clear_image, 2227 x_clear_image,
2228 NULL,
2264 NULL 2229 NULL
2265}; 2230};
2266 2231
@@ -2273,10 +2238,10 @@ enum xbm_token
2273}; 2238};
2274 2239
2275 2240
2276/* Return non-zero if OBJECT is a valid XBM-type image specification. 2241/* Return true if OBJECT is a valid XBM-type image specification.
2277 A valid specification is a list starting with the symbol `image' 2242 A valid specification is a list starting with the symbol `image'
2278 The rest of the list is a property list which must contain an 2243 The rest of the list is a property list which must contain an
2279 entry `:type xbm.. 2244 entry `:type xbm'.
2280 2245
2281 If the specification specifies a file to load, it must contain 2246 If the specification specifies a file to load, it must contain
2282 an entry `:file FILENAME' where FILENAME is a string. 2247 an entry `:file FILENAME' where FILENAME is a string.
@@ -2302,7 +2267,7 @@ enum xbm_token
2302 foreground and background of the frame on which the image is 2267 foreground and background of the frame on which the image is
2303 displayed is used. */ 2268 displayed is used. */
2304 2269
2305static int 2270static bool
2306xbm_image_p (Lisp_Object object) 2271xbm_image_p (Lisp_Object object)
2307{ 2272{
2308 struct image_keyword kw[XBM_LAST]; 2273 struct image_keyword kw[XBM_LAST];
@@ -2560,7 +2525,7 @@ convert_mono_to_color_image (struct frame *f, struct image *img,
2560static void 2525static void
2561Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, 2526Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2562 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg, 2527 RGB_PIXEL_COLOR fg, RGB_PIXEL_COLOR bg,
2563 int non_default_colors) 2528 bool non_default_colors)
2564{ 2529{
2565#ifdef HAVE_NTGUI 2530#ifdef HAVE_NTGUI
2566 img->pixmap 2531 img->pixmap
@@ -2592,20 +2557,20 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
2592 X versions. CONTENTS is a pointer to a buffer to parse; END is the 2557 X versions. CONTENTS is a pointer to a buffer to parse; END is the
2593 buffer's end. Set *WIDTH and *HEIGHT to the width and height of 2558 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
2594 the image. Return in *DATA the bitmap data allocated with xmalloc. 2559 the image. Return in *DATA the bitmap data allocated with xmalloc.
2595 Value is non-zero if successful. DATA null means just test if 2560 Value is true if successful. DATA null means just test if
2596 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR 2561 CONTENTS looks like an in-memory XBM file. If INHIBIT_IMAGE_ERROR,
2597 is non-zero, inhibit the call to image_error when the image size is 2562 inhibit the call to image_error when the image size is invalid (the
2598 invalid (the bitmap remains unread). */ 2563 bitmap remains unread). */
2599 2564
2600static int 2565static bool
2601xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end, 2566xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end,
2602 int *width, int *height, char **data, 2567 int *width, int *height, char **data,
2603 int inhibit_image_error) 2568 bool inhibit_image_error)
2604{ 2569{
2605 unsigned char *s = contents; 2570 unsigned char *s = contents;
2606 char buffer[BUFSIZ]; 2571 char buffer[BUFSIZ];
2607 int padding_p = 0; 2572 bool padding_p = 0;
2608 int v10 = 0; 2573 bool v10 = 0;
2609 int bytes_per_line, i, nbytes; 2574 int bytes_per_line, i, nbytes;
2610 char *p; 2575 char *p;
2611 int value; 2576 int value;
@@ -2752,16 +2717,16 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
2752 2717
2753 2718
2754/* Load XBM image IMG which will be displayed on frame F from buffer 2719/* Load XBM image IMG which will be displayed on frame F from buffer
2755 CONTENTS. END is the end of the buffer. Value is non-zero if 2720 CONTENTS. END is the end of the buffer. Value is true if
2756 successful. */ 2721 successful. */
2757 2722
2758static int 2723static bool
2759xbm_load_image (struct frame *f, struct image *img, unsigned char *contents, 2724xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2760 unsigned char *end) 2725 unsigned char *end)
2761{ 2726{
2762 int rc; 2727 bool rc;
2763 char *data; 2728 char *data;
2764 int success_p = 0; 2729 bool success_p = 0;
2765 2730
2766 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height, 2731 rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height,
2767 &data, 0); 2732 &data, 0);
@@ -2769,7 +2734,7 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2769 { 2734 {
2770 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2735 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2771 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2736 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2772 int non_default_colors = 0; 2737 bool non_default_colors = 0;
2773 Lisp_Object value; 2738 Lisp_Object value;
2774 2739
2775 eassert (img->width > 0 && img->height > 0); 2740 eassert (img->width > 0 && img->height > 0);
@@ -2810,9 +2775,9 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
2810} 2775}
2811 2776
2812 2777
2813/* Value is non-zero if DATA looks like an in-memory XBM file. */ 2778/* Value is true if DATA looks like an in-memory XBM file. */
2814 2779
2815static int 2780static bool
2816xbm_file_p (Lisp_Object data) 2781xbm_file_p (Lisp_Object data)
2817{ 2782{
2818 int w, h; 2783 int w, h;
@@ -2824,12 +2789,12 @@ xbm_file_p (Lisp_Object data)
2824 2789
2825 2790
2826/* Fill image IMG which is used on frame F with pixmap data. Value is 2791/* Fill image IMG which is used on frame F with pixmap data. Value is
2827 non-zero if successful. */ 2792 true if successful. */
2828 2793
2829static int 2794static bool
2830xbm_load (struct frame *f, struct image *img) 2795xbm_load (struct frame *f, struct image *img)
2831{ 2796{
2832 int success_p = 0; 2797 bool success_p = 0;
2833 Lisp_Object file_name; 2798 Lisp_Object file_name;
2834 2799
2835 eassert (xbm_image_p (img->spec)); 2800 eassert (xbm_image_p (img->spec));
@@ -2865,10 +2830,10 @@ xbm_load (struct frame *f, struct image *img)
2865 Lisp_Object data; 2830 Lisp_Object data;
2866 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); 2831 unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
2867 unsigned long background = FRAME_BACKGROUND_PIXEL (f); 2832 unsigned long background = FRAME_BACKGROUND_PIXEL (f);
2868 int non_default_colors = 0; 2833 bool non_default_colors = 0;
2869 char *bits; 2834 char *bits;
2870 int parsed_p; 2835 bool parsed_p;
2871 int in_memory_file_p = 0; 2836 bool in_memory_file_p = 0;
2872 2837
2873 /* See if data looks like an in-memory XBM file. */ 2838 /* See if data looks like an in-memory XBM file. */
2874 data = image_spec_value (img->spec, QCdata, NULL); 2839 data = image_spec_value (img->spec, QCdata, NULL);
@@ -2877,7 +2842,6 @@ xbm_load (struct frame *f, struct image *img)
2877 /* Parse the image specification. */ 2842 /* Parse the image specification. */
2878 memcpy (fmt, xbm_format, sizeof fmt); 2843 memcpy (fmt, xbm_format, sizeof fmt);
2879 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm); 2844 parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
2880 (void) parsed_p;
2881 eassert (parsed_p); 2845 eassert (parsed_p);
2882 2846
2883 /* Get specified width, and height. */ 2847 /* Get specified width, and height. */
@@ -2982,9 +2946,8 @@ xbm_load (struct frame *f, struct image *img)
2982 2946
2983#if defined (HAVE_XPM) || defined (HAVE_NS) 2947#if defined (HAVE_XPM) || defined (HAVE_NS)
2984 2948
2985static int xpm_image_p (Lisp_Object object); 2949static bool xpm_image_p (Lisp_Object object);
2986static int xpm_load (struct frame *f, struct image *img); 2950static bool xpm_load (struct frame *f, struct image *img);
2987static int xpm_valid_color_symbols_p (Lisp_Object);
2988 2951
2989#endif /* HAVE_XPM || HAVE_NS */ 2952#endif /* HAVE_XPM || HAVE_NS */
2990 2953
@@ -3050,6 +3013,12 @@ static const struct image_keyword xpm_format[XPM_LAST] =
3050 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 3013 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
3051}; 3014};
3052 3015
3016#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
3017static bool init_xpm_functions (void);
3018#else
3019#define init_xpm_functions NULL
3020#endif
3021
3053/* Structure describing the image type XPM. */ 3022/* Structure describing the image type XPM. */
3054 3023
3055static struct image_type xpm_type = 3024static struct image_type xpm_type =
@@ -3058,6 +3027,7 @@ static struct image_type xpm_type =
3058 xpm_image_p, 3027 xpm_image_p,
3059 xpm_load, 3028 xpm_load,
3060 x_clear_image, 3029 x_clear_image,
3030 init_xpm_functions,
3061 NULL 3031 NULL
3062}; 3032};
3063 3033
@@ -3075,10 +3045,6 @@ static struct image_type xpm_type =
3075 3045
3076#ifdef ALLOC_XPM_COLORS 3046#ifdef ALLOC_XPM_COLORS
3077 3047
3078static void xpm_init_color_cache (struct frame *, XpmAttributes *);
3079static void xpm_free_color_cache (void);
3080static int xpm_lookup_color (struct frame *, char *, XColor *);
3081static int xpm_color_bucket (char *);
3082static struct xpm_cached_color *xpm_cache_color (struct frame *, char *, 3048static struct xpm_cached_color *xpm_cache_color (struct frame *, char *,
3083 XColor *, int); 3049 XColor *, int);
3084 3050
@@ -3185,10 +3151,10 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3185 3151
3186/* Look up color COLOR_NAME for frame F in the color cache. If found, 3152/* Look up color COLOR_NAME for frame F in the color cache. If found,
3187 return the cached definition in *COLOR. Otherwise, make a new 3153 return the cached definition in *COLOR. Otherwise, make a new
3188 entry in the cache and allocate the color. Value is zero if color 3154 entry in the cache and allocate the color. Value is false if color
3189 allocation failed. */ 3155 allocation failed. */
3190 3156
3191static int 3157static bool
3192xpm_lookup_color (struct frame *f, char *color_name, XColor *color) 3158xpm_lookup_color (struct frame *f, char *color_name, XColor *color)
3193{ 3159{
3194 struct xpm_cached_color *p; 3160 struct xpm_cached_color *p;
@@ -3257,12 +3223,12 @@ DEF_IMGLIB_FN (int, XpmReadFileToImage, (Display *, char *, xpm_XImage **,
3257 xpm_XImage **, XpmAttributes *)); 3223 xpm_XImage **, XpmAttributes *));
3258DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *)); 3224DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *));
3259 3225
3260static int 3226static bool
3261init_xpm_functions (Lisp_Object libraries) 3227init_xpm_functions (void)
3262{ 3228{
3263 HMODULE library; 3229 HMODULE library;
3264 3230
3265 if (!(library = w32_delayed_load (libraries, Qxpm))) 3231 if (!(library = w32_delayed_load (Qxpm)))
3266 return 0; 3232 return 0;
3267 3233
3268 LOAD_IMGLIB_FN (library, XpmFreeAttributes); 3234 LOAD_IMGLIB_FN (library, XpmFreeAttributes);
@@ -3282,11 +3248,11 @@ init_xpm_functions (Lisp_Object libraries)
3282#define fn_XpmFreeAttributes XpmFreeAttributes 3248#define fn_XpmFreeAttributes XpmFreeAttributes
3283#endif /* HAVE_NTGUI */ 3249#endif /* HAVE_NTGUI */
3284 3250
3285/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list 3251/* Value is true if COLOR_SYMBOLS is a valid color symbols list
3286 for XPM images. Such a list must consist of conses whose car and 3252 for XPM images. Such a list must consist of conses whose car and
3287 cdr are strings. */ 3253 cdr are strings. */
3288 3254
3289static int 3255static bool
3290xpm_valid_color_symbols_p (Lisp_Object color_symbols) 3256xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3291{ 3257{
3292 while (CONSP (color_symbols)) 3258 while (CONSP (color_symbols))
@@ -3303,9 +3269,9 @@ xpm_valid_color_symbols_p (Lisp_Object color_symbols)
3303} 3269}
3304 3270
3305 3271
3306/* Value is non-zero if OBJECT is a valid XPM image specification. */ 3272/* Value is true if OBJECT is a valid XPM image specification. */
3307 3273
3308static int 3274static bool
3309xpm_image_p (Lisp_Object object) 3275xpm_image_p (Lisp_Object object)
3310{ 3276{
3311 struct image_keyword fmt[XPM_LAST]; 3277 struct image_keyword fmt[XPM_LAST];
@@ -3362,11 +3328,11 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
3362#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */ 3328#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
3363 3329
3364/* Load image IMG which will be displayed on frame F. Value is 3330/* Load image IMG which will be displayed on frame F. Value is
3365 non-zero if successful. */ 3331 true if successful. */
3366 3332
3367#ifdef HAVE_XPM 3333#ifdef HAVE_XPM
3368 3334
3369static int 3335static bool
3370xpm_load (struct frame *f, struct image *img) 3336xpm_load (struct frame *f, struct image *img)
3371{ 3337{
3372 int rc; 3338 int rc;
@@ -3820,7 +3786,7 @@ xpm_str_to_color_key (const char *s)
3820 return -1; 3786 return -1;
3821} 3787}
3822 3788
3823static int 3789static bool
3824xpm_load_image (struct frame *f, 3790xpm_load_image (struct frame *f,
3825 struct image *img, 3791 struct image *img,
3826 const unsigned char *contents, 3792 const unsigned char *contents,
@@ -3835,7 +3801,8 @@ xpm_load_image (struct frame *f,
3835 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3801 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object);
3836 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); 3802 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int);
3837 Lisp_Object frame, color_symbols, color_table; 3803 Lisp_Object frame, color_symbols, color_table;
3838 int best_key, have_mask = 0; 3804 int best_key;
3805 bool have_mask = 0;
3839 XImagePtr ximg = NULL, mask_img = NULL; 3806 XImagePtr ximg = NULL, mask_img = NULL;
3840 3807
3841#define match() \ 3808#define match() \
@@ -4055,11 +4022,11 @@ xpm_load_image (struct frame *f,
4055#undef expect_ident 4022#undef expect_ident
4056} 4023}
4057 4024
4058static int 4025static bool
4059xpm_load (struct frame *f, 4026xpm_load (struct frame *f,
4060 struct image *img) 4027 struct image *img)
4061{ 4028{
4062 int success_p = 0; 4029 bool success_p = 0;
4063 Lisp_Object file_name; 4030 Lisp_Object file_name;
4064 4031
4065 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 4032 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -4230,7 +4197,7 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
4230#ifdef HAVE_X_WINDOWS 4197#ifdef HAVE_X_WINDOWS
4231 XColor color; 4198 XColor color;
4232 Colormap cmap; 4199 Colormap cmap;
4233 int rc; 4200 bool rc;
4234#else 4201#else
4235 COLORREF color; 4202 COLORREF color;
4236#endif 4203#endif
@@ -4298,7 +4265,7 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4298 { 4265 {
4299 XColor color; 4266 XColor color;
4300 Colormap cmap; 4267 Colormap cmap;
4301 int rc; 4268 bool rc;
4302 4269
4303 if (ct_colors_allocated_max <= ct_colors_allocated) 4270 if (ct_colors_allocated_max <= ct_colors_allocated)
4304 return FRAME_FOREGROUND_PIXEL (f); 4271 return FRAME_FOREGROUND_PIXEL (f);
@@ -4309,12 +4276,12 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4309 x_query_color (f, &color); 4276 x_query_color (f, &color);
4310 rc = x_alloc_nearest_color (f, cmap, &color); 4277 rc = x_alloc_nearest_color (f, cmap, &color);
4311#else 4278#else
4312 BLOCK_INPUT; 4279 block_input ();
4313 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 4280 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
4314 color.pixel = pixel; 4281 color.pixel = pixel;
4315 XQueryColor (NULL, cmap, &color); 4282 XQueryColor (NULL, cmap, &color);
4316 rc = x_alloc_nearest_color (f, cmap, &color); 4283 rc = x_alloc_nearest_color (f, cmap, &color);
4317 UNBLOCK_INPUT; 4284 unblock_input ();
4318#endif /* HAVE_X_WINDOWS */ 4285#endif /* HAVE_X_WINDOWS */
4319 4286
4320 if (rc) 4287 if (rc)
@@ -4392,14 +4359,6 @@ init_color_table (void)
4392 Algorithms 4359 Algorithms
4393 ***********************************************************************/ 4360 ***********************************************************************/
4394 4361
4395static XColor *x_to_xcolors (struct frame *, struct image *, int);
4396static void x_from_xcolors (struct frame *, struct image *, XColor *);
4397static void x_detect_edges (struct frame *, struct image *, int[9], int);
4398
4399#ifdef HAVE_NTGUI
4400static void XPutPixel (XImagePtr , int, int, COLORREF);
4401#endif /* HAVE_NTGUI */
4402
4403/* Edge detection matrices for different edge-detection 4362/* Edge detection matrices for different edge-detection
4404 strategies. */ 4363 strategies. */
4405 4364
@@ -4425,12 +4384,12 @@ static int laplace_matrix[9] = {
4425 4384
4426/* On frame F, return an array of XColor structures describing image 4385/* On frame F, return an array of XColor structures describing image
4427 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P 4386 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
4428 non-zero means also fill the red/green/blue members of the XColor 4387 means also fill the red/green/blue members of the XColor
4429 structures. Value is a pointer to the array of XColors structures, 4388 structures. Value is a pointer to the array of XColors structures,
4430 allocated with xmalloc; it must be freed by the caller. */ 4389 allocated with xmalloc; it must be freed by the caller. */
4431 4390
4432static XColor * 4391static XColor *
4433x_to_xcolors (struct frame *f, struct image *img, int rgb_p) 4392x_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
4434{ 4393{
4435 int x, y; 4394 int x, y;
4436 XColor *colors, *p; 4395 XColor *colors, *p;
@@ -4806,9 +4765,9 @@ x_disable_image (struct frame *f, struct image *img)
4806 determine the background color of IMG. If it is a list '(R G B)', 4765 determine the background color of IMG. If it is a list '(R G B)',
4807 with R, G, and B being integers >= 0, take that as the color of the 4766 with R, G, and B being integers >= 0, take that as the color of the
4808 background. Otherwise, determine the background color of IMG 4767 background. Otherwise, determine the background color of IMG
4809 heuristically. Value is non-zero if successful. */ 4768 heuristically. */
4810 4769
4811static int 4770static void
4812x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how) 4771x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4813{ 4772{
4814 XImagePtr_or_DC ximg; 4773 XImagePtr_or_DC ximg;
@@ -4820,7 +4779,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4820 char *mask_img; 4779 char *mask_img;
4821 int row_width; 4780 int row_width;
4822#endif /* HAVE_NTGUI */ 4781#endif /* HAVE_NTGUI */
4823 int x, y, rc, use_img_background; 4782 int x, y;
4783 bool rc, use_img_background;
4824 unsigned long bg = 0; 4784 unsigned long bg = 0;
4825 4785
4826 if (img->mask) 4786 if (img->mask)
@@ -4836,7 +4796,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4836 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, 4796 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1,
4837 &mask_img, &img->mask); 4797 &mask_img, &img->mask);
4838 if (!rc) 4798 if (!rc)
4839 return 0; 4799 return;
4840#endif /* !HAVE_NS */ 4800#endif /* !HAVE_NS */
4841 4801
4842 /* Get the X image of IMG->pixmap. */ 4802 /* Get the X image of IMG->pixmap. */
@@ -4926,8 +4886,6 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4926#endif /* HAVE_NTGUI */ 4886#endif /* HAVE_NTGUI */
4927 4887
4928 Destroy_Image (ximg, prev); 4888 Destroy_Image (ximg, prev);
4929
4930 return 1;
4931} 4889}
4932 4890
4933 4891
@@ -4935,9 +4893,8 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4935 PBM (mono, gray, color) 4893 PBM (mono, gray, color)
4936 ***********************************************************************/ 4894 ***********************************************************************/
4937 4895
4938static int pbm_image_p (Lisp_Object object); 4896static bool pbm_image_p (Lisp_Object object);
4939static int pbm_load (struct frame *f, struct image *img); 4897static bool pbm_load (struct frame *f, struct image *img);
4940static int pbm_scan_number (unsigned char **, unsigned char *);
4941 4898
4942/* The symbol `pbm' identifying images of this type. */ 4899/* The symbol `pbm' identifying images of this type. */
4943 4900
@@ -4987,13 +4944,14 @@ static struct image_type pbm_type =
4987 pbm_image_p, 4944 pbm_image_p,
4988 pbm_load, 4945 pbm_load,
4989 x_clear_image, 4946 x_clear_image,
4947 NULL,
4990 NULL 4948 NULL
4991}; 4949};
4992 4950
4993 4951
4994/* Return non-zero if OBJECT is a valid PBM image specification. */ 4952/* Return true if OBJECT is a valid PBM image specification. */
4995 4953
4996static int 4954static bool
4997pbm_image_p (Lisp_Object object) 4955pbm_image_p (Lisp_Object object)
4998{ 4956{
4999 struct image_keyword fmt[PBM_LAST]; 4957 struct image_keyword fmt[PBM_LAST];
@@ -5086,10 +5044,11 @@ pbm_read_file (Lisp_Object file, int *size)
5086 5044
5087/* Load PBM image IMG for use on frame F. */ 5045/* Load PBM image IMG for use on frame F. */
5088 5046
5089static int 5047static bool
5090pbm_load (struct frame *f, struct image *img) 5048pbm_load (struct frame *f, struct image *img)
5091{ 5049{
5092 int raw_p, x, y; 5050 bool raw_p;
5051 int x, y;
5093 int width, height, max_color_idx = 0; 5052 int width, height, max_color_idx = 0;
5094 XImagePtr ximg; 5053 XImagePtr ximg;
5095 Lisp_Object file, specified_file; 5054 Lisp_Object file, specified_file;
@@ -5352,8 +5311,8 @@ pbm_load (struct frame *f, struct image *img)
5352 5311
5353/* Function prototypes. */ 5312/* Function prototypes. */
5354 5313
5355static int png_image_p (Lisp_Object object); 5314static bool png_image_p (Lisp_Object object);
5356static int png_load (struct frame *f, struct image *img); 5315static bool png_load (struct frame *f, struct image *img);
5357 5316
5358/* The symbol `png' identifying images of this type. */ 5317/* The symbol `png' identifying images of this type. */
5359 5318
@@ -5393,6 +5352,12 @@ static const struct image_keyword png_format[PNG_LAST] =
5393 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 5352 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
5394}; 5353};
5395 5354
5355#if defined(HAVE_NTGUI) && defined (WINDOWSNT)
5356static bool init_png_functions (void);
5357#else
5358#define init_png_functions NULL
5359#endif
5360
5396/* Structure describing the image type `png'. */ 5361/* Structure describing the image type `png'. */
5397 5362
5398static struct image_type png_type = 5363static struct image_type png_type =
@@ -5401,12 +5366,13 @@ static struct image_type png_type =
5401 png_image_p, 5366 png_image_p,
5402 png_load, 5367 png_load,
5403 x_clear_image, 5368 x_clear_image,
5369 init_png_functions,
5404 NULL 5370 NULL
5405}; 5371};
5406 5372
5407/* Return non-zero if OBJECT is a valid PNG image specification. */ 5373/* Return true if OBJECT is a valid PNG image specification. */
5408 5374
5409static int 5375static bool
5410png_image_p (Lisp_Object object) 5376png_image_p (Lisp_Object object)
5411{ 5377{
5412 struct image_keyword fmt[PNG_LAST]; 5378 struct image_keyword fmt[PNG_LAST];
@@ -5458,12 +5424,12 @@ DEF_IMGLIB_FN (void, png_longjmp, (png_structp, int));
5458DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t)); 5424DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t));
5459#endif /* libpng version >= 1.5 */ 5425#endif /* libpng version >= 1.5 */
5460 5426
5461static int 5427static bool
5462init_png_functions (Lisp_Object libraries) 5428init_png_functions (void)
5463{ 5429{
5464 HMODULE library; 5430 HMODULE library;
5465 5431
5466 if (!(library = w32_delayed_load (libraries, Qpng))) 5432 if (!(library = w32_delayed_load (Qpng)))
5467 return 0; 5433 return 0;
5468 5434
5469 LOAD_IMGLIB_FN (library, png_get_io_ptr); 5435 LOAD_IMGLIB_FN (library, png_get_io_ptr);
@@ -5609,7 +5575,7 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5609} 5575}
5610 5576
5611 5577
5612/* Load PNG image IMG for use on frame F. Value is non-zero if 5578/* Load PNG image IMG for use on frame F. Value is true if
5613 successful. */ 5579 successful. */
5614 5580
5615struct png_load_context 5581struct png_load_context
@@ -5623,7 +5589,7 @@ struct png_load_context
5623 png_byte **rows; 5589 png_byte **rows;
5624}; 5590};
5625 5591
5626static int 5592static bool
5627png_load_body (struct frame *f, struct image *img, struct png_load_context *c) 5593png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5628{ 5594{
5629 Lisp_Object file, specified_file; 5595 Lisp_Object file, specified_file;
@@ -5641,7 +5607,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5641 int bit_depth, color_type, interlace_type; 5607 int bit_depth, color_type, interlace_type;
5642 png_byte channels; 5608 png_byte channels;
5643 png_uint_32 row_bytes; 5609 png_uint_32 row_bytes;
5644 int transparent_p; 5610 bool transparent_p;
5645 struct png_memory_storage tbr; /* Data to be read */ 5611 struct png_memory_storage tbr; /* Data to be read */
5646 5612
5647 /* Find out what file to load. */ 5613 /* Find out what file to load. */
@@ -5974,7 +5940,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5974 return 1; 5940 return 1;
5975} 5941}
5976 5942
5977static int 5943static bool
5978png_load (struct frame *f, struct image *img) 5944png_load (struct frame *f, struct image *img)
5979{ 5945{
5980 struct png_load_context c; 5946 struct png_load_context c;
@@ -5984,7 +5950,7 @@ png_load (struct frame *f, struct image *img)
5984#else /* HAVE_PNG */ 5950#else /* HAVE_PNG */
5985 5951
5986#ifdef HAVE_NS 5952#ifdef HAVE_NS
5987static int 5953static bool
5988png_load (struct frame *f, struct image *img) 5954png_load (struct frame *f, struct image *img)
5989{ 5955{
5990 return ns_load_image (f, img, 5956 return ns_load_image (f, img,
@@ -6004,8 +5970,8 @@ png_load (struct frame *f, struct image *img)
6004 5970
6005#if defined (HAVE_JPEG) || defined (HAVE_NS) 5971#if defined (HAVE_JPEG) || defined (HAVE_NS)
6006 5972
6007static int jpeg_image_p (Lisp_Object object); 5973static bool jpeg_image_p (Lisp_Object object);
6008static int jpeg_load (struct frame *f, struct image *img); 5974static bool jpeg_load (struct frame *f, struct image *img);
6009 5975
6010/* The symbol `jpeg' identifying images of this type. */ 5976/* The symbol `jpeg' identifying images of this type. */
6011 5977
@@ -6045,6 +6011,12 @@ static const struct image_keyword jpeg_format[JPEG_LAST] =
6045 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 6011 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
6046}; 6012};
6047 6013
6014#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
6015static bool init_jpeg_functions (void);
6016#else
6017#define init_jpeg_functions NULL
6018#endif
6019
6048/* Structure describing the image type `jpeg'. */ 6020/* Structure describing the image type `jpeg'. */
6049 6021
6050static struct image_type jpeg_type = 6022static struct image_type jpeg_type =
@@ -6053,12 +6025,13 @@ static struct image_type jpeg_type =
6053 jpeg_image_p, 6025 jpeg_image_p,
6054 jpeg_load, 6026 jpeg_load,
6055 x_clear_image, 6027 x_clear_image,
6028 init_jpeg_functions,
6056 NULL 6029 NULL
6057}; 6030};
6058 6031
6059/* Return non-zero if OBJECT is a valid JPEG image specification. */ 6032/* Return true if OBJECT is a valid JPEG image specification. */
6060 6033
6061static int 6034static bool
6062jpeg_image_p (Lisp_Object object) 6035jpeg_image_p (Lisp_Object object)
6063{ 6036{
6064 struct image_keyword fmt[JPEG_LAST]; 6037 struct image_keyword fmt[JPEG_LAST];
@@ -6113,12 +6086,12 @@ DEF_IMGLIB_FN (JDIMENSION, jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, J
6113DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *)); 6086DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *));
6114DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int)); 6087DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int));
6115 6088
6116static int 6089static bool
6117init_jpeg_functions (Lisp_Object libraries) 6090init_jpeg_functions (void)
6118{ 6091{
6119 HMODULE library; 6092 HMODULE library;
6120 6093
6121 if (!(library = w32_delayed_load (libraries, Qjpeg))) 6094 if (!(library = w32_delayed_load (Qjpeg)))
6122 return 0; 6095 return 0;
6123 6096
6124 LOAD_IMGLIB_FN (library, jpeg_finish_decompress); 6097 LOAD_IMGLIB_FN (library, jpeg_finish_decompress);
@@ -6383,7 +6356,7 @@ jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6383/* Load image IMG for use on frame F. Patterned after example.c 6356/* Load image IMG for use on frame F. Patterned after example.c
6384 from the JPEG lib. */ 6357 from the JPEG lib. */
6385 6358
6386static int 6359static bool
6387jpeg_load_body (struct frame *f, struct image *img, 6360jpeg_load_body (struct frame *f, struct image *img,
6388 struct my_jpeg_error_mgr *mgr) 6361 struct my_jpeg_error_mgr *mgr)
6389{ 6362{
@@ -6564,7 +6537,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6564 return 1; 6537 return 1;
6565} 6538}
6566 6539
6567static int 6540static bool
6568jpeg_load (struct frame *f, struct image *img) 6541jpeg_load (struct frame *f, struct image *img)
6569{ 6542{
6570 struct my_jpeg_error_mgr mgr; 6543 struct my_jpeg_error_mgr mgr;
@@ -6574,7 +6547,7 @@ jpeg_load (struct frame *f, struct image *img)
6574#else /* HAVE_JPEG */ 6547#else /* HAVE_JPEG */
6575 6548
6576#ifdef HAVE_NS 6549#ifdef HAVE_NS
6577static int 6550static bool
6578jpeg_load (struct frame *f, struct image *img) 6551jpeg_load (struct frame *f, struct image *img)
6579{ 6552{
6580 return ns_load_image (f, img, 6553 return ns_load_image (f, img,
@@ -6593,8 +6566,8 @@ jpeg_load (struct frame *f, struct image *img)
6593 6566
6594#if defined (HAVE_TIFF) || defined (HAVE_NS) 6567#if defined (HAVE_TIFF) || defined (HAVE_NS)
6595 6568
6596static int tiff_image_p (Lisp_Object object); 6569static bool tiff_image_p (Lisp_Object object);
6597static int tiff_load (struct frame *f, struct image *img); 6570static bool tiff_load (struct frame *f, struct image *img);
6598 6571
6599/* The symbol `tiff' identifying images of this type. */ 6572/* The symbol `tiff' identifying images of this type. */
6600 6573
@@ -6636,6 +6609,12 @@ static const struct image_keyword tiff_format[TIFF_LAST] =
6636 {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0} 6609 {":index", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0}
6637}; 6610};
6638 6611
6612#ifdef HAVE_NTGUI
6613static bool init_tiff_functions (void);
6614#else
6615#define init_tiff_functions NULL
6616#endif
6617
6639/* Structure describing the image type `tiff'. */ 6618/* Structure describing the image type `tiff'. */
6640 6619
6641static struct image_type tiff_type = 6620static struct image_type tiff_type =
@@ -6644,12 +6623,13 @@ static struct image_type tiff_type =
6644 tiff_image_p, 6623 tiff_image_p,
6645 tiff_load, 6624 tiff_load,
6646 x_clear_image, 6625 x_clear_image,
6626 init_tiff_functions,
6647 NULL 6627 NULL
6648}; 6628};
6649 6629
6650/* Return non-zero if OBJECT is a valid TIFF image specification. */ 6630/* Return true if OBJECT is a valid TIFF image specification. */
6651 6631
6652static int 6632static bool
6653tiff_image_p (Lisp_Object object) 6633tiff_image_p (Lisp_Object object)
6654{ 6634{
6655 struct image_keyword fmt[TIFF_LAST]; 6635 struct image_keyword fmt[TIFF_LAST];
@@ -6683,12 +6663,12 @@ DEF_IMGLIB_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
6683DEF_IMGLIB_FN (void, TIFFClose, (TIFF *)); 6663DEF_IMGLIB_FN (void, TIFFClose, (TIFF *));
6684DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t)); 6664DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t));
6685 6665
6686static int 6666static bool
6687init_tiff_functions (Lisp_Object libraries) 6667init_tiff_functions (void)
6688{ 6668{
6689 HMODULE library; 6669 HMODULE library;
6690 6670
6691 if (!(library = w32_delayed_load (libraries, Qtiff))) 6671 if (!(library = w32_delayed_load (Qtiff)))
6692 return 0; 6672 return 0;
6693 6673
6694 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler); 6674 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler);
@@ -6853,10 +6833,10 @@ tiff_warning_handler (const char *title, const char *format, va_list ap)
6853} 6833}
6854 6834
6855 6835
6856/* Load TIFF image IMG for use on frame F. Value is non-zero if 6836/* Load TIFF image IMG for use on frame F. Value is true if
6857 successful. */ 6837 successful. */
6858 6838
6859static int 6839static bool
6860tiff_load (struct frame *f, struct image *img) 6840tiff_load (struct frame *f, struct image *img)
6861{ 6841{
6862 Lisp_Object file, specified_file; 6842 Lisp_Object file, specified_file;
@@ -7021,7 +7001,7 @@ tiff_load (struct frame *f, struct image *img)
7021#else /* HAVE_TIFF */ 7001#else /* HAVE_TIFF */
7022 7002
7023#ifdef HAVE_NS 7003#ifdef HAVE_NS
7024static int 7004static bool
7025tiff_load (struct frame *f, struct image *img) 7005tiff_load (struct frame *f, struct image *img)
7026{ 7006{
7027 return ns_load_image (f, img, 7007 return ns_load_image (f, img,
@@ -7040,8 +7020,8 @@ tiff_load (struct frame *f, struct image *img)
7040 7020
7041#if defined (HAVE_GIF) || defined (HAVE_NS) 7021#if defined (HAVE_GIF) || defined (HAVE_NS)
7042 7022
7043static int gif_image_p (Lisp_Object object); 7023static bool gif_image_p (Lisp_Object object);
7044static int gif_load (struct frame *f, struct image *img); 7024static bool gif_load (struct frame *f, struct image *img);
7045static void gif_clear_image (struct frame *f, struct image *img); 7025static void gif_clear_image (struct frame *f, struct image *img);
7046 7026
7047/* The symbol `gif' identifying images of this type. */ 7027/* The symbol `gif' identifying images of this type. */
@@ -7084,6 +7064,12 @@ static const struct image_keyword gif_format[GIF_LAST] =
7084 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 7064 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
7085}; 7065};
7086 7066
7067#if defined(HAVE_NTGUI) && defined(WINDOWSNT)
7068static bool init_gif_functions (void);
7069#else
7070#define init_gif_functions NULL
7071#endif
7072
7087/* Structure describing the image type `gif'. */ 7073/* Structure describing the image type `gif'. */
7088 7074
7089static struct image_type gif_type = 7075static struct image_type gif_type =
@@ -7092,6 +7078,7 @@ static struct image_type gif_type =
7092 gif_image_p, 7078 gif_image_p,
7093 gif_load, 7079 gif_load,
7094 gif_clear_image, 7080 gif_clear_image,
7081 init_gif_functions,
7095 NULL 7082 NULL
7096}; 7083};
7097 7084
@@ -7104,9 +7091,9 @@ gif_clear_image (struct frame *f, struct image *img)
7104 x_clear_image (f, img); 7091 x_clear_image (f, img);
7105} 7092}
7106 7093
7107/* Return non-zero if OBJECT is a valid GIF image specification. */ 7094/* Return true if OBJECT is a valid GIF image specification. */
7108 7095
7109static int 7096static bool
7110gif_image_p (Lisp_Object object) 7097gif_image_p (Lisp_Object object)
7111{ 7098{
7112 struct image_keyword fmt[GIF_LAST]; 7099 struct image_keyword fmt[GIF_LAST];
@@ -7149,12 +7136,12 @@ DEF_IMGLIB_FN (int, DGifSlurp, (GifFileType *));
7149DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc)); 7136DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc));
7150DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *)); 7137DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *));
7151 7138
7152static int 7139static bool
7153init_gif_functions (Lisp_Object libraries) 7140init_gif_functions (void)
7154{ 7141{
7155 HMODULE library; 7142 HMODULE library;
7156 7143
7157 if (!(library = w32_delayed_load (libraries, Qgif))) 7144 if (!(library = w32_delayed_load (Qgif)))
7158 return 0; 7145 return 0;
7159 7146
7160 LOAD_IMGLIB_FN (library, DGifCloseFile); 7147 LOAD_IMGLIB_FN (library, DGifCloseFile);
@@ -7203,7 +7190,7 @@ gif_read_from_memory (GifFileType *file, GifByteType *buf, int len)
7203} 7190}
7204 7191
7205 7192
7206/* Load GIF image IMG for use on frame F. Value is non-zero if 7193/* Load GIF image IMG for use on frame F. Value is true if
7207 successful. */ 7194 successful. */
7208 7195
7209static const int interlace_start[] = {0, 4, 2, 1}; 7196static const int interlace_start[] = {0, 4, 2, 1};
@@ -7211,7 +7198,7 @@ static const int interlace_increment[] = {8, 8, 4, 2};
7211 7198
7212#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249 7199#define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
7213 7200
7214static int 7201static bool
7215gif_load (struct frame *f, struct image *img) 7202gif_load (struct frame *f, struct image *img)
7216{ 7203{
7217 Lisp_Object file; 7204 Lisp_Object file;
@@ -7509,7 +7496,7 @@ gif_load (struct frame *f, struct image *img)
7509#else /* !HAVE_GIF */ 7496#else /* !HAVE_GIF */
7510 7497
7511#ifdef HAVE_NS 7498#ifdef HAVE_NS
7512static int 7499static bool
7513gif_load (struct frame *f, struct image *img) 7500gif_load (struct frame *f, struct image *img)
7514{ 7501{
7515 return ns_load_image (f, img, 7502 return ns_load_image (f, img,
@@ -7528,8 +7515,8 @@ gif_load (struct frame *f, struct image *img)
7528 7515
7529static Lisp_Object Qimagemagick; 7516static Lisp_Object Qimagemagick;
7530 7517
7531static int imagemagick_image_p (Lisp_Object); 7518static bool imagemagick_image_p (Lisp_Object);
7532static int imagemagick_load (struct frame *, struct image *); 7519static bool imagemagick_load (struct frame *, struct image *);
7533static void imagemagick_clear_image (struct frame *, struct image *); 7520static void imagemagick_clear_image (struct frame *, struct image *);
7534 7521
7535/* Indices of image specification fields in imagemagick_format. */ 7522/* Indices of image specification fields in imagemagick_format. */
@@ -7574,6 +7561,12 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7574 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} 7561 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
7575 }; 7562 };
7576 7563
7564#ifdef HAVE_NTGUI
7565static bool init_imagemagick_functions (void);
7566#else
7567#define init_imagemagick_functions NULL
7568#endif
7569
7577/* Structure describing the image type for any image handled via 7570/* Structure describing the image type for any image handled via
7578 ImageMagick. */ 7571 ImageMagick. */
7579 7572
@@ -7583,6 +7576,7 @@ static struct image_type imagemagick_type =
7583 imagemagick_image_p, 7576 imagemagick_image_p,
7584 imagemagick_load, 7577 imagemagick_load,
7585 imagemagick_clear_image, 7578 imagemagick_clear_image,
7579 init_imagemagick_functions,
7586 NULL 7580 NULL
7587 }; 7581 };
7588 7582
@@ -7595,11 +7589,11 @@ imagemagick_clear_image (struct frame *f,
7595 x_clear_image (f, img); 7589 x_clear_image (f, img);
7596} 7590}
7597 7591
7598/* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do 7592/* Return true if OBJECT is a valid IMAGEMAGICK image specification. Do
7599 this by calling parse_image_spec and supplying the keywords that 7593 this by calling parse_image_spec and supplying the keywords that
7600 identify the IMAGEMAGICK format. */ 7594 identify the IMAGEMAGICK format. */
7601 7595
7602static int 7596static bool
7603imagemagick_image_p (Lisp_Object object) 7597imagemagick_image_p (Lisp_Object object)
7604{ 7598{
7605 struct image_keyword fmt[IMAGEMAGICK_LAST]; 7599 struct image_keyword fmt[IMAGEMAGICK_LAST];
@@ -7651,9 +7645,9 @@ imagemagick_error (MagickWand *wand)
7651 be parsed; SIZE is the number of bytes of data; and FILENAME is 7645 be parsed; SIZE is the number of bytes of data; and FILENAME is
7652 either the file name or the image data. 7646 either the file name or the image data.
7653 7647
7654 Return non-zero if successful. */ 7648 Return true if successful. */
7655 7649
7656static int 7650static bool
7657imagemagick_load_image (struct frame *f, struct image *img, 7651imagemagick_load_image (struct frame *f, struct image *img,
7658 unsigned char *contents, unsigned int size, 7652 unsigned char *contents, unsigned int size,
7659 char *filename) 7653 char *filename)
@@ -7991,14 +7985,14 @@ imagemagick_load_image (struct frame *f, struct image *img,
7991} 7985}
7992 7986
7993 7987
7994/* Load IMAGEMAGICK image IMG for use on frame F. Value is non-zero if 7988/* Load IMAGEMAGICK image IMG for use on frame F. Value is true if
7995 successful. this function will go into the imagemagick_type structure, and 7989 successful. this function will go into the imagemagick_type structure, and
7996 the prototype thus needs to be compatible with that structure. */ 7990 the prototype thus needs to be compatible with that structure. */
7997 7991
7998static int 7992static bool
7999imagemagick_load (struct frame *f, struct image *img) 7993imagemagick_load (struct frame *f, struct image *img)
8000{ 7994{
8001 int success_p = 0; 7995 bool success_p = 0;
8002 Lisp_Object file_name; 7996 Lisp_Object file_name;
8003 7997
8004 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 7998 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8077,11 +8071,11 @@ and `imagemagick-types-inhibit'. */)
8077 8071
8078/* Function prototypes. */ 8072/* Function prototypes. */
8079 8073
8080static int svg_image_p (Lisp_Object object); 8074static bool svg_image_p (Lisp_Object object);
8081static int svg_load (struct frame *f, struct image *img); 8075static bool svg_load (struct frame *f, struct image *img);
8082 8076
8083static int svg_load_image (struct frame *, struct image *, 8077static bool svg_load_image (struct frame *, struct image *,
8084 unsigned char *, ptrdiff_t); 8078 unsigned char *, ptrdiff_t);
8085 8079
8086/* The symbol `svg' identifying images of this type. */ 8080/* The symbol `svg' identifying images of this type. */
8087 8081
@@ -8121,31 +8115,32 @@ static const struct image_keyword svg_format[SVG_LAST] =
8121 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 8115 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
8122}; 8116};
8123 8117
8118#ifdef HAVE_NTGUI
8119static bool init_svg_functions (void);
8120#else
8121#define init_svg_functions NULL
8122#endif
8123
8124/* Structure describing the image type `svg'. Its the same type of 8124/* Structure describing the image type `svg'. Its the same type of
8125 structure defined for all image formats, handled by emacs image 8125 structure defined for all image formats, handled by emacs image
8126 functions. See struct image_type in dispextern.h. */ 8126 functions. See struct image_type in dispextern.h. */
8127 8127
8128static struct image_type svg_type = 8128static struct image_type svg_type =
8129{ 8129{
8130 /* An identifier showing that this is an image structure for the SVG format. */
8131 &Qsvg, 8130 &Qsvg,
8132 /* Handle to a function that can be used to identify a SVG file. */
8133 svg_image_p, 8131 svg_image_p,
8134 /* Handle to function used to load a SVG file. */
8135 svg_load, 8132 svg_load,
8136 /* Handle to function to free sresources for SVG. */
8137 x_clear_image, 8133 x_clear_image,
8138 /* An internal field to link to the next image type in a list of 8134 init_svg_functions,
8139 image types, will be filled in when registering the format. */
8140 NULL 8135 NULL
8141}; 8136};
8142 8137
8143 8138
8144/* Return non-zero if OBJECT is a valid SVG image specification. Do 8139/* Return true if OBJECT is a valid SVG image specification. Do
8145 this by calling parse_image_spec and supplying the keywords that 8140 this by calling parse_image_spec and supplying the keywords that
8146 identify the SVG format. */ 8141 identify the SVG format. */
8147 8142
8148static int 8143static bool
8149svg_image_p (Lisp_Object object) 8144svg_image_p (Lisp_Object object)
8150{ 8145{
8151 struct image_keyword fmt[SVG_LAST]; 8146 struct image_keyword fmt[SVG_LAST];
@@ -8184,15 +8179,15 @@ DEF_IMGLIB_FN (void, g_error_free);
8184 8179
8185Lisp_Object Qgdk_pixbuf, Qglib, Qgobject; 8180Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
8186 8181
8187static int 8182static bool
8188init_svg_functions (Lisp_Object libraries) 8183init_svg_functions (void)
8189{ 8184{
8190 HMODULE library, gdklib, glib, gobject; 8185 HMODULE library, gdklib, glib, gobject;
8191 8186
8192 if (!(glib = w32_delayed_load (libraries, Qglib)) 8187 if (!(glib = w32_delayed_load (Qglib))
8193 || !(gobject = w32_delayed_load (libraries, Qgobject)) 8188 || !(gobject = w32_delayed_load (Qgobject))
8194 || !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf)) 8189 || !(gdklib = w32_delayed_load (Qgdk_pixbuf))
8195 || !(library = w32_delayed_load (libraries, Qsvg))) 8190 || !(library = w32_delayed_load (Qsvg)))
8196 return 0; 8191 return 0;
8197 8192
8198 LOAD_IMGLIB_FN (library, rsvg_handle_new); 8193 LOAD_IMGLIB_FN (library, rsvg_handle_new);
@@ -8240,14 +8235,13 @@ init_svg_functions (Lisp_Object libraries)
8240#define fn_g_error_free g_error_free 8235#define fn_g_error_free g_error_free
8241#endif /* !WINDOWSNT */ 8236#endif /* !WINDOWSNT */
8242 8237
8243/* Load SVG image IMG for use on frame F. Value is non-zero if 8238/* Load SVG image IMG for use on frame F. Value is true if
8244 successful. this function will go into the svg_type structure, and 8239 successful. */
8245 the prototype thus needs to be compatible with that structure. */
8246 8240
8247static int 8241static bool
8248svg_load (struct frame *f, struct image *img) 8242svg_load (struct frame *f, struct image *img)
8249{ 8243{
8250 int success_p = 0; 8244 bool success_p = 0;
8251 Lisp_Object file_name; 8245 Lisp_Object file_name;
8252 8246
8253 /* If IMG->spec specifies a file name, create a non-file spec from it. */ 8247 /* If IMG->spec specifies a file name, create a non-file spec from it. */
@@ -8300,8 +8294,8 @@ svg_load (struct frame *f, struct image *img)
8300 8294
8301 Uses librsvg to do most of the image processing. 8295 Uses librsvg to do most of the image processing.
8302 8296
8303 Returns non-zero when successful. */ 8297 Returns true when successful. */
8304static int 8298static bool
8305svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */ 8299svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */
8306 struct image *img, /* Pointer to emacs image structure. */ 8300 struct image *img, /* Pointer to emacs image structure. */
8307 unsigned char *contents, /* String containing the SVG XML data to be parsed. */ 8301 unsigned char *contents, /* String containing the SVG XML data to be parsed. */
@@ -8468,8 +8462,8 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8468 8462
8469#ifdef HAVE_GHOSTSCRIPT 8463#ifdef HAVE_GHOSTSCRIPT
8470 8464
8471static int gs_image_p (Lisp_Object object); 8465static bool gs_image_p (Lisp_Object object);
8472static int gs_load (struct frame *f, struct image *img); 8466static bool gs_load (struct frame *f, struct image *img);
8473static void gs_clear_image (struct frame *f, struct image *img); 8467static void gs_clear_image (struct frame *f, struct image *img);
8474 8468
8475/* Keyword symbols. */ 8469/* Keyword symbols. */
@@ -8524,6 +8518,7 @@ static struct image_type gs_type =
8524 gs_image_p, 8518 gs_image_p,
8525 gs_load, 8519 gs_load,
8526 gs_clear_image, 8520 gs_clear_image,
8521 NULL,
8527 NULL 8522 NULL
8528}; 8523};
8529 8524
@@ -8537,10 +8532,10 @@ gs_clear_image (struct frame *f, struct image *img)
8537} 8532}
8538 8533
8539 8534
8540/* Return non-zero if OBJECT is a valid Ghostscript image 8535/* Return true if OBJECT is a valid Ghostscript image
8541 specification. */ 8536 specification. */
8542 8537
8543static int 8538static bool
8544gs_image_p (Lisp_Object object) 8539gs_image_p (Lisp_Object object)
8545{ 8540{
8546 struct image_keyword fmt[GS_LAST]; 8541 struct image_keyword fmt[GS_LAST];
@@ -8577,10 +8572,10 @@ gs_image_p (Lisp_Object object)
8577} 8572}
8578 8573
8579 8574
8580/* Load Ghostscript image IMG for use on frame F. Value is non-zero 8575/* Load Ghostscript image IMG for use on frame F. Value is true
8581 if successful. */ 8576 if successful. */
8582 8577
8583static int 8578static bool
8584gs_load (struct frame *f, struct image *img) 8579gs_load (struct frame *f, struct image *img)
8585{ 8580{
8586 uprintmax_t printnum1, printnum2; 8581 uprintmax_t printnum1, printnum2;
@@ -8616,11 +8611,11 @@ gs_load (struct frame *f, struct image *img)
8616 if (x_check_image_size (0, img->width, img->height)) 8611 if (x_check_image_size (0, img->width, img->height))
8617 { 8612 {
8618 /* Only W32 version did BLOCK_INPUT here. ++kfs */ 8613 /* Only W32 version did BLOCK_INPUT here. ++kfs */
8619 BLOCK_INPUT; 8614 block_input ();
8620 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 8615 img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
8621 img->width, img->height, 8616 img->width, img->height,
8622 DefaultDepthOfScreen (FRAME_X_SCREEN (f))); 8617 DefaultDepthOfScreen (FRAME_X_SCREEN (f)));
8623 UNBLOCK_INPUT; 8618 unblock_input ();
8624 } 8619 }
8625 8620
8626 if (!img->pixmap) 8621 if (!img->pixmap)
@@ -8696,7 +8691,7 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8696 { 8691 {
8697 XImagePtr ximg; 8692 XImagePtr ximg;
8698 8693
8699 BLOCK_INPUT; 8694 block_input ();
8700 8695
8701 /* Try to get an XImage for img->pixmep. */ 8696 /* Try to get an XImage for img->pixmep. */
8702 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, 8697 ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap,
@@ -8739,15 +8734,15 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
8739 image_error ("Cannot get X image of `%s'; colors will not be freed", 8734 image_error ("Cannot get X image of `%s'; colors will not be freed",
8740 img->spec, Qnil); 8735 img->spec, Qnil);
8741 8736
8742 UNBLOCK_INPUT; 8737 unblock_input ();
8743 } 8738 }
8744#endif /* HAVE_X_WINDOWS */ 8739#endif /* HAVE_X_WINDOWS */
8745 8740
8746 /* Now that we have the pixmap, compute mask and transform the 8741 /* Now that we have the pixmap, compute mask and transform the
8747 image if requested. */ 8742 image if requested. */
8748 BLOCK_INPUT; 8743 block_input ();
8749 postprocess_image (f, img); 8744 postprocess_image (f, img);
8750 UNBLOCK_INPUT; 8745 unblock_input ();
8751} 8746}
8752 8747
8753#endif /* HAVE_GHOSTSCRIPT */ 8748#endif /* HAVE_GHOSTSCRIPT */
@@ -8796,78 +8791,92 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
8796 define_image_type (image_type, 1) 8791 define_image_type (image_type, 1)
8797#endif /* WINDOWSNT */ 8792#endif /* WINDOWSNT */
8798 8793
8799DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 2, 2, 0, 8794DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 1, 1, 0,
8800 doc: /* Initialize image library implementing image type TYPE. 8795 doc: /* Initialize image library implementing image type TYPE.
8801Return non-nil if TYPE is a supported image type. 8796Return non-nil if TYPE is a supported image type.
8802 8797
8803Image types pbm and xbm are prebuilt; other types are loaded here. 8798If image libraries are loaded dynamically (currently only the case on
8804Libraries to load are specified in alist LIBRARIES (usually, the value 8799MS-Windows), load the library for TYPE if it is not yet loaded, using
8805of `dynamic-library-alist', which see). */) 8800the library file(s) specified by `dynamic-library-alist'. */)
8806 (Lisp_Object type, Lisp_Object libraries) 8801 (Lisp_Object type)
8807{ 8802{
8808#ifdef WINDOWSNT 8803 return lookup_image_type (type) ? Qt : Qnil;
8809 /* Don't try to reload the library. */ 8804}
8810 Lisp_Object tested = Fassq (type, Vlibrary_cache);
8811 if (CONSP (tested))
8812 return XCDR (tested);
8813#endif
8814 8805
8806/* Look up image type TYPE, and return a pointer to its image_type
8807 structure. Return 0 if TYPE is not a known image type. */
8808
8809static struct image_type *
8810lookup_image_type (Lisp_Object type)
8811{
8815 /* Types pbm and xbm are built-in and always available. */ 8812 /* Types pbm and xbm are built-in and always available. */
8816 if (EQ (type, Qpbm) || EQ (type, Qxbm)) 8813 if (EQ (type, Qpbm))
8817 return Qt; 8814 return define_image_type (&pbm_type);
8815
8816 if (EQ (type, Qxbm))
8817 return define_image_type (&xbm_type);
8818 8818
8819#if defined (HAVE_XPM) || defined (HAVE_NS) 8819#if defined (HAVE_XPM) || defined (HAVE_NS)
8820 if (EQ (type, Qxpm)) 8820 if (EQ (type, Qxpm))
8821 return CHECK_LIB_AVAILABLE (&xpm_type, init_xpm_functions, libraries); 8821 return define_image_type (&xpm_type);
8822#endif 8822#endif
8823 8823
8824#if defined (HAVE_JPEG) || defined (HAVE_NS) 8824#if defined (HAVE_JPEG) || defined (HAVE_NS)
8825 if (EQ (type, Qjpeg)) 8825 if (EQ (type, Qjpeg))
8826 return CHECK_LIB_AVAILABLE (&jpeg_type, init_jpeg_functions, libraries); 8826 return define_image_type (&jpeg_type);
8827#endif 8827#endif
8828 8828
8829#if defined (HAVE_TIFF) || defined (HAVE_NS) 8829#if defined (HAVE_TIFF) || defined (HAVE_NS)
8830 if (EQ (type, Qtiff)) 8830 if (EQ (type, Qtiff))
8831 return CHECK_LIB_AVAILABLE (&tiff_type, init_tiff_functions, libraries); 8831 return define_image_type (&tiff_type);
8832#endif 8832#endif
8833 8833
8834#if defined (HAVE_GIF) || defined (HAVE_NS) 8834#if defined (HAVE_GIF) || defined (HAVE_NS)
8835 if (EQ (type, Qgif)) 8835 if (EQ (type, Qgif))
8836 return CHECK_LIB_AVAILABLE (&gif_type, init_gif_functions, libraries); 8836 return define_image_type (&gif_type);
8837#endif 8837#endif
8838 8838
8839#if defined (HAVE_PNG) || defined (HAVE_NS) 8839#if defined (HAVE_PNG) || defined (HAVE_NS)
8840 if (EQ (type, Qpng)) 8840 if (EQ (type, Qpng))
8841 return CHECK_LIB_AVAILABLE (&png_type, init_png_functions, libraries); 8841 return define_image_type (&png_type);
8842#endif 8842#endif
8843 8843
8844#if defined (HAVE_RSVG) 8844#if defined (HAVE_RSVG)
8845 if (EQ (type, Qsvg)) 8845 if (EQ (type, Qsvg))
8846 return CHECK_LIB_AVAILABLE (&svg_type, init_svg_functions, libraries); 8846 return define_image_type (&svg_type);
8847#endif 8847#endif
8848 8848
8849#if defined (HAVE_IMAGEMAGICK) 8849#if defined (HAVE_IMAGEMAGICK)
8850 if (EQ (type, Qimagemagick)) 8850 if (EQ (type, Qimagemagick))
8851 return CHECK_LIB_AVAILABLE (&imagemagick_type, init_imagemagick_functions, 8851 return define_image_type (&imagemagick_type);
8852 libraries);
8853#endif 8852#endif
8854 8853
8855#ifdef HAVE_GHOSTSCRIPT 8854#ifdef HAVE_GHOSTSCRIPT
8856 if (EQ (type, Qpostscript)) 8855 if (EQ (type, Qpostscript))
8857 return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries); 8856 return define_image_type (&gs_type);
8858#endif 8857#endif
8859 8858
8860 /* If the type is not recognized, avoid testing it ever again. */ 8859 return NULL;
8861 CACHE_IMAGE_TYPE (type, Qnil); 8860}
8862 return Qnil; 8861
8862/* Reset image_types before dumping.
8863 Called from Fdump_emacs. */
8864
8865void
8866reset_image_types (void)
8867{
8868 while (image_types)
8869 {
8870 struct image_type *next = image_types->next;
8871 xfree (image_types);
8872 image_types = next;
8873 }
8863} 8874}
8864 8875
8865void 8876void
8866syms_of_image (void) 8877syms_of_image (void)
8867{ 8878{
8868 /* Initialize this only once, since that's what we do with Vimage_types 8879 /* Initialize this only once; it will be reset before dumping. */
8869 and they are supposed to be in sync. Initializing here gives correct
8870 operation on GNU/Linux of calling dump-emacs after loading some images. */
8871 image_types = NULL; 8880 image_types = NULL;
8872 8881
8873 /* Must be defined now because we're going to update it below, while 8882 /* Must be defined now because we're going to update it below, while
@@ -8890,15 +8899,6 @@ as a ratio to the frame height and width. If the value is
8890non-numeric, there is no explicit limit on the size of images. */); 8899non-numeric, there is no explicit limit on the size of images. */);
8891 Vmax_image_size = make_float (MAX_IMAGE_SIZE); 8900 Vmax_image_size = make_float (MAX_IMAGE_SIZE);
8892 8901
8893 DEFSYM (Qpbm, "pbm");
8894 ADD_IMAGE_TYPE (Qpbm);
8895
8896 DEFSYM (Qxbm, "xbm");
8897 ADD_IMAGE_TYPE (Qxbm);
8898
8899 define_image_type (&xbm_type, 1);
8900 define_image_type (&pbm_type, 1);
8901
8902 DEFSYM (Qcount, "count"); 8902 DEFSYM (Qcount, "count");
8903 DEFSYM (Qextension_data, "extension-data"); 8903 DEFSYM (Qextension_data, "extension-data");
8904 DEFSYM (Qdelay, "delay"); 8904 DEFSYM (Qdelay, "delay");
@@ -8942,6 +8942,12 @@ non-numeric, there is no explicit limit on the size of images. */);
8942 ); 8942 );
8943#endif 8943#endif
8944 8944
8945 DEFSYM (Qpbm, "pbm");
8946 ADD_IMAGE_TYPE (Qpbm);
8947
8948 DEFSYM (Qxbm, "xbm");
8949 ADD_IMAGE_TYPE (Qxbm);
8950
8945#if defined (HAVE_XPM) || defined (HAVE_NS) 8951#if defined (HAVE_XPM) || defined (HAVE_NS)
8946 DEFSYM (Qxpm, "xpm"); 8952 DEFSYM (Qxpm, "xpm");
8947 ADD_IMAGE_TYPE (Qxpm); 8953 ADD_IMAGE_TYPE (Qxpm);
diff --git a/src/indent.c b/src/indent.c
index 053643e6319..b368a7aeb09 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -115,7 +115,7 @@ character_width (int c, struct Lisp_Char_Table *dp)
115 for characters as WIDTHTAB. We use this to decide when to 115 for characters as WIDTHTAB. We use this to decide when to
116 invalidate the buffer's width_run_cache. */ 116 invalidate the buffer's width_run_cache. */
117 117
118int 118bool
119disptab_matches_widthtab (struct Lisp_Char_Table *disptab, struct Lisp_Vector *widthtab) 119disptab_matches_widthtab (struct Lisp_Char_Table *disptab, struct Lisp_Vector *widthtab)
120{ 120{
121 int i; 121 int i;
@@ -320,14 +320,14 @@ invalidate_current_column (void)
320ptrdiff_t 320ptrdiff_t
321current_column (void) 321current_column (void)
322{ 322{
323 register ptrdiff_t col; 323 ptrdiff_t col;
324 register unsigned char *ptr, *stop; 324 unsigned char *ptr, *stop;
325 register int tab_seen; 325 bool tab_seen;
326 ptrdiff_t post_tab; 326 ptrdiff_t post_tab;
327 register int c; 327 int c;
328 int tab_width = SANE_TAB_WIDTH (current_buffer); 328 int tab_width = SANE_TAB_WIDTH (current_buffer);
329 int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 329 bool ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
330 register struct Lisp_Char_Table *dp = buffer_display_table (); 330 struct Lisp_Char_Table *dp = buffer_display_table ();
331 331
332 if (PT == last_known_column_point 332 if (PT == last_known_column_point
333 && MODIFF == last_known_column_modified) 333 && MODIFF == last_known_column_modified)
@@ -512,9 +512,9 @@ static void
512scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol) 512scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol)
513{ 513{
514 int tab_width = SANE_TAB_WIDTH (current_buffer); 514 int tab_width = SANE_TAB_WIDTH (current_buffer);
515 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 515 bool ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
516 register struct Lisp_Char_Table *dp = buffer_display_table (); 516 struct Lisp_Char_Table *dp = buffer_display_table ();
517 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 517 bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
518 struct composition_it cmp_it; 518 struct composition_it cmp_it;
519 Lisp_Object window; 519 Lisp_Object window;
520 struct window *w; 520 struct window *w;
@@ -722,14 +722,14 @@ current_column_1 (void)
722static double 722static double
723string_display_width (Lisp_Object string, Lisp_Object beg, Lisp_Object end) 723string_display_width (Lisp_Object string, Lisp_Object beg, Lisp_Object end)
724{ 724{
725 register int col; 725 int col;
726 register unsigned char *ptr, *stop; 726 unsigned char *ptr, *stop;
727 register int tab_seen; 727 bool tab_seen;
728 int post_tab; 728 int post_tab;
729 register int c; 729 int c;
730 int tab_width = SANE_TAB_WIDTH (current_buffer); 730 int tab_width = SANE_TAB_WIDTH (current_buffer);
731 int ctl_arrow = !NILP (current_buffer->ctl_arrow); 731 bool ctl_arrow = !NILP (current_buffer->ctl_arrow);
732 register struct Lisp_Char_Table *dp = buffer_display_table (); 732 struct Lisp_Char_Table *dp = buffer_display_table ();
733 int b, e; 733 int b, e;
734 734
735 if (NILP (end)) 735 if (NILP (end))
@@ -945,7 +945,7 @@ position_indentation (ptrdiff_t pos_byte)
945 Blank lines are treated as if they had the same indentation as the 945 Blank lines are treated as if they had the same indentation as the
946 preceding line. */ 946 preceding line. */
947 947
948int 948bool
949indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column) 949indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column)
950{ 950{
951 ptrdiff_t val; 951 ptrdiff_t val;
@@ -1047,11 +1047,11 @@ static struct position val_compute_motion;
1047 can't hit the requested column exactly (because of a tab or other 1047 can't hit the requested column exactly (because of a tab or other
1048 multi-column character), overshoot. 1048 multi-column character), overshoot.
1049 1049
1050 DID_MOTION is 1 if FROMHPOS has already accounted for overlay strings 1050 DID_MOTION is true if FROMHPOS has already accounted for overlay strings
1051 at FROM. This is the case if FROMVPOS and FROMVPOS came from an 1051 at FROM. This is the case if FROMVPOS and FROMVPOS came from an
1052 earlier call to compute_motion. The other common case is that FROMHPOS 1052 earlier call to compute_motion. The other common case is that FROMHPOS
1053 is zero and FROM is a position that "belongs" at column zero, but might 1053 is zero and FROM is a position that "belongs" at column zero, but might
1054 be shifted by overlay strings; in this case DID_MOTION should be 0. 1054 be shifted by overlay strings; in this case DID_MOTION should be false.
1055 1055
1056 WIDTH is the number of columns available to display text; 1056 WIDTH is the number of columns available to display text;
1057 compute_motion uses this to handle continuation lines and such. 1057 compute_motion uses this to handle continuation lines and such.
@@ -1104,17 +1104,20 @@ static struct position val_compute_motion;
1104 the scroll bars if they are turned on. */ 1104 the scroll bars if they are turned on. */
1105 1105
1106struct position * 1106struct position *
1107compute_motion (ptrdiff_t from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_motion, ptrdiff_t to, EMACS_INT tovpos, EMACS_INT tohpos, EMACS_INT width, ptrdiff_t hscroll, int tab_offset, struct window *win) 1107compute_motion (ptrdiff_t from, EMACS_INT fromvpos, EMACS_INT fromhpos,
1108 bool did_motion, ptrdiff_t to,
1109 EMACS_INT tovpos, EMACS_INT tohpos, EMACS_INT width,
1110 ptrdiff_t hscroll, int tab_offset, struct window *win)
1108{ 1111{
1109 register EMACS_INT hpos = fromhpos; 1112 EMACS_INT hpos = fromhpos;
1110 register EMACS_INT vpos = fromvpos; 1113 EMACS_INT vpos = fromvpos;
1111 1114
1112 register ptrdiff_t pos; 1115 ptrdiff_t pos;
1113 ptrdiff_t pos_byte; 1116 ptrdiff_t pos_byte;
1114 register int c = 0; 1117 int c = 0;
1115 int tab_width = SANE_TAB_WIDTH (current_buffer); 1118 int tab_width = SANE_TAB_WIDTH (current_buffer);
1116 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 1119 bool ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
1117 register struct Lisp_Char_Table *dp = window_display_table (win); 1120 struct Lisp_Char_Table *dp = window_display_table (win);
1118 EMACS_INT selective 1121 EMACS_INT selective
1119 = (INTEGERP (BVAR (current_buffer, selective_display)) 1122 = (INTEGERP (BVAR (current_buffer, selective_display))
1120 ? XINT (BVAR (current_buffer, selective_display)) 1123 ? XINT (BVAR (current_buffer, selective_display))
@@ -1139,7 +1142,7 @@ compute_motion (ptrdiff_t from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1139 ptrdiff_t next_width_run = from; 1142 ptrdiff_t next_width_run = from;
1140 Lisp_Object window; 1143 Lisp_Object window;
1141 1144
1142 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 1145 bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
1143 /* If previous char scanned was a wide character, 1146 /* If previous char scanned was a wide character,
1144 this is the column where it ended. Otherwise, this is 0. */ 1147 this is the column where it ended. Otherwise, this is 0. */
1145 EMACS_INT wide_column_end_hpos = 0; 1148 EMACS_INT wide_column_end_hpos = 0;
@@ -1308,7 +1311,7 @@ compute_motion (ptrdiff_t from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1308 if (hpos > width) 1311 if (hpos > width)
1309 { 1312 {
1310 EMACS_INT total_width = width + continuation_glyph_width; 1313 EMACS_INT total_width = width + continuation_glyph_width;
1311 int truncate = 0; 1314 bool truncate = 0;
1312 1315
1313 if (!NILP (Vtruncate_partial_width_windows) 1316 if (!NILP (Vtruncate_partial_width_windows)
1314 && (total_width < FRAME_COLS (XFRAME (WINDOW_FRAME (win))))) 1317 && (total_width < FRAME_COLS (XFRAME (WINDOW_FRAME (win)))))
@@ -1827,7 +1830,7 @@ vmotion (register ptrdiff_t from, register EMACS_INT vtarget, struct window *w)
1827 PTRDIFF_MAX) 1830 PTRDIFF_MAX)
1828 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0); 1831 : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0);
1829 Lisp_Object window; 1832 Lisp_Object window;
1830 int did_motion; 1833 bool did_motion;
1831 /* This is the object we use for fetching character properties. */ 1834 /* This is the object we use for fetching character properties. */
1832 Lisp_Object text_prop_object; 1835 Lisp_Object text_prop_object;
1833 1836
@@ -2017,8 +2020,8 @@ whether or not it is currently displayed in some window. */)
2017 { 2020 {
2018 ptrdiff_t it_start, it_overshoot_count = 0; 2021 ptrdiff_t it_start, it_overshoot_count = 0;
2019 int first_x; 2022 int first_x;
2020 int overshoot_handled = 0; 2023 bool overshoot_handled = 0;
2021 int disp_string_at_start_p = 0; 2024 bool disp_string_at_start_p = 0;
2022 2025
2023 itdata = bidi_shelve_cache (); 2026 itdata = bidi_shelve_cache ();
2024 SET_TEXT_POS (pt, PT, PT_BYTE); 2027 SET_TEXT_POS (pt, PT, PT_BYTE);
diff --git a/src/indent.h b/src/indent.h
index e198137a756..abcd06036d1 100644
--- a/src/indent.h
+++ b/src/indent.h
@@ -27,7 +27,7 @@ struct position
27 }; 27 };
28 28
29struct position *compute_motion (ptrdiff_t from, EMACS_INT fromvpos, 29struct position *compute_motion (ptrdiff_t from, EMACS_INT fromvpos,
30 EMACS_INT fromhpos, int did_motion, 30 EMACS_INT fromhpos, bool did_motion,
31 ptrdiff_t to, EMACS_INT tovpos, 31 ptrdiff_t to, EMACS_INT tovpos,
32 EMACS_INT tohpos, 32 EMACS_INT tohpos,
33 EMACS_INT width, ptrdiff_t hscroll, 33 EMACS_INT width, ptrdiff_t hscroll,
@@ -45,8 +45,8 @@ extern ptrdiff_t last_known_column_point;
45/* Return true if the display table DISPTAB specifies the same widths 45/* Return true if the display table DISPTAB specifies the same widths
46 for characters as WIDTHTAB. We use this to decide when to 46 for characters as WIDTHTAB. We use this to decide when to
47 invalidate the buffer's column_cache. */ 47 invalidate the buffer's column_cache. */
48int disptab_matches_widthtab (struct Lisp_Char_Table *disptab, 48bool disptab_matches_widthtab (struct Lisp_Char_Table *disptab,
49 struct Lisp_Vector *widthtab); 49 struct Lisp_Vector *widthtab);
50 50
51/* Recompute BUF's width table, using the display table DISPTAB. */ 51/* Recompute BUF's width table, using the display table DISPTAB. */
52void recompute_width_table (struct buffer *buf, 52void recompute_width_table (struct buffer *buf,
diff --git a/src/intervals.c b/src/intervals.c
index 584ee1e923d..1ed93e1302d 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -64,7 +64,7 @@ static INTERVAL reproduce_tree (INTERVAL, INTERVAL);
64/* Use these functions to set Lisp_Object 64/* Use these functions to set Lisp_Object
65 or pointer slots of struct interval. */ 65 or pointer slots of struct interval. */
66 66
67static inline void 67static void
68set_interval_object (INTERVAL i, Lisp_Object obj) 68set_interval_object (INTERVAL i, Lisp_Object obj)
69{ 69{
70 eassert (BUFFERP (obj) || STRINGP (obj)); 70 eassert (BUFFERP (obj) || STRINGP (obj));
@@ -72,13 +72,13 @@ set_interval_object (INTERVAL i, Lisp_Object obj)
72 i->up.obj = obj; 72 i->up.obj = obj;
73} 73}
74 74
75static inline void 75static void
76set_interval_left (INTERVAL i, INTERVAL left) 76set_interval_left (INTERVAL i, INTERVAL left)
77{ 77{
78 i->left = left; 78 i->left = left;
79} 79}
80 80
81static inline void 81static void
82set_interval_right (INTERVAL i, INTERVAL right) 82set_interval_right (INTERVAL i, INTERVAL right)
83{ 83{
84 i->right = right; 84 i->right = right;
@@ -87,7 +87,7 @@ set_interval_right (INTERVAL i, INTERVAL right)
87/* Make the parent of D be whatever the parent of S is, regardless 87/* Make the parent of D be whatever the parent of S is, regardless
88 of the type. This is used when balancing an interval tree. */ 88 of the type. This is used when balancing an interval tree. */
89 89
90static inline void 90static void
91copy_interval_parent (INTERVAL d, INTERVAL s) 91copy_interval_parent (INTERVAL d, INTERVAL s)
92{ 92{
93 d->up = s->up; 93 d->up = s->up;
@@ -341,7 +341,7 @@ root_interval (INTERVAL interval)
341 c c 341 c c
342*/ 342*/
343 343
344static inline INTERVAL 344static INTERVAL
345rotate_right (INTERVAL interval) 345rotate_right (INTERVAL interval)
346{ 346{
347 INTERVAL i; 347 INTERVAL i;
@@ -388,7 +388,7 @@ rotate_right (INTERVAL interval)
388 c c 388 c c
389*/ 389*/
390 390
391static inline INTERVAL 391static INTERVAL
392rotate_left (INTERVAL interval) 392rotate_left (INTERVAL interval)
393{ 393{
394 INTERVAL i; 394 INTERVAL i;
@@ -466,7 +466,7 @@ balance_an_interval (INTERVAL i)
466/* Balance INTERVAL, potentially stuffing it back into its parent 466/* Balance INTERVAL, potentially stuffing it back into its parent
467 Lisp Object. */ 467 Lisp Object. */
468 468
469static inline INTERVAL 469static INTERVAL
470balance_possible_root_interval (INTERVAL interval) 470balance_possible_root_interval (INTERVAL interval)
471{ 471{
472 Lisp_Object parent; 472 Lisp_Object parent;
diff --git a/src/keyboard.c b/src/keyboard.c
index 451ffd9d600..05b9a9dde01 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20#include <config.h> 20#include <config.h>
21 21
22#define BLOCKINPUT_INLINE EXTERN_INLINE
22#define KEYBOARD_INLINE EXTERN_INLINE 23#define KEYBOARD_INLINE EXTERN_INLINE
23 24
24#include <stdio.h> 25#include <stdio.h>
@@ -72,19 +73,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
72 73
73/* Variables for blockinput.h: */ 74/* Variables for blockinput.h: */
74 75
75/* Non-zero if interrupt input is blocked right now. */ 76/* Positive if interrupt input is blocked right now. */
76volatile int interrupt_input_blocked; 77volatile int interrupt_input_blocked;
77 78
78/* Nonzero means an input interrupt has arrived 79/* True means an input interrupt or alarm signal has arrived.
79 during the current critical section. */ 80 The QUIT macro checks this. */
80int interrupt_input_pending; 81volatile bool pending_signals;
81
82/* This var should be (interrupt_input_pending || pending_atimers).
83 The QUIT macro checks this instead of interrupt_input_pending and
84 pending_atimers separately, to reduce code size. So, any code that
85 changes interrupt_input_pending or pending_atimers should update
86 this too. */
87int pending_signals;
88 82
89#define KBD_BUFFER_SIZE 4096 83#define KBD_BUFFER_SIZE 4096
90 84
@@ -225,7 +219,11 @@ static Lisp_Object last_point_position_window;
225 last event came from a macro. We use this to determine when to 219 last event came from a macro. We use this to determine when to
226 generate switch-frame events. This may be cleared by functions 220 generate switch-frame events. This may be cleared by functions
227 like Fselect_frame, to make sure that a switch-frame event is 221 like Fselect_frame, to make sure that a switch-frame event is
228 generated by the next character. */ 222 generated by the next character.
223
224 FIXME: This is modified by a signal handler so it should be volatile.
225 It's exported to Lisp, though, so it can't simply be marked
226 'volatile' here. */
229Lisp_Object internal_last_event_frame; 227Lisp_Object internal_last_event_frame;
230 228
231/* The timestamp of the last input event we received from the X server. 229/* The timestamp of the last input event we received from the X server.
@@ -389,7 +387,7 @@ int interrupts_deferred;
389 387
390/* If we support a window system, turn on the code to poll periodically 388/* If we support a window system, turn on the code to poll periodically
391 to detect C-g. It isn't actually used when doing interrupt input. */ 389 to detect C-g. It isn't actually used when doing interrupt input. */
392#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS) 390#ifdef HAVE_WINDOW_SYSTEM
393#define POLL_FOR_INPUT 391#define POLL_FOR_INPUT
394#endif 392#endif
395 393
@@ -413,7 +411,6 @@ static EMACS_TIME timer_last_idleness_start_time;
413/* Function for init_keyboard to call with no args (if nonzero). */ 411/* Function for init_keyboard to call with no args (if nonzero). */
414static void (*keyboard_init_hook) (void); 412static void (*keyboard_init_hook) (void);
415 413
416static int read_avail_input (int);
417static void get_input_pending (int *, int); 414static void get_input_pending (int *, int);
418static int readable_events (int); 415static int readable_events (int);
419static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *, 416static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *,
@@ -440,7 +437,7 @@ static Lisp_Object restore_kboard_configuration (Lisp_Object);
440#ifdef USABLE_SIGIO 437#ifdef USABLE_SIGIO
441static void deliver_input_available_signal (int signo); 438static void deliver_input_available_signal (int signo);
442#endif 439#endif
443static void handle_interrupt (void); 440static void handle_interrupt (bool);
444static _Noreturn void quit_throw_to_read_char (int); 441static _Noreturn void quit_throw_to_read_char (int);
445static void process_special_events (void); 442static void process_special_events (void);
446static void timer_start_idle (void); 443static void timer_start_idle (void);
@@ -448,50 +445,50 @@ static void timer_stop_idle (void);
448static void timer_resume_idle (void); 445static void timer_resume_idle (void);
449static void deliver_user_signal (int); 446static void deliver_user_signal (int);
450static char *find_user_signal_name (int); 447static char *find_user_signal_name (int);
451static int store_user_signal_events (void); 448static void store_user_signal_events (void);
452 449
453/* These setters are used only in this file, so they can be private. */ 450/* These setters are used only in this file, so they can be private. */
454static inline void 451static void
455kset_echo_string (struct kboard *kb, Lisp_Object val) 452kset_echo_string (struct kboard *kb, Lisp_Object val)
456{ 453{
457 kb->INTERNAL_FIELD (echo_string) = val; 454 kb->INTERNAL_FIELD (echo_string) = val;
458} 455}
459static inline void 456static void
460kset_kbd_queue (struct kboard *kb, Lisp_Object val) 457kset_kbd_queue (struct kboard *kb, Lisp_Object val)
461{ 458{
462 kb->INTERNAL_FIELD (kbd_queue) = val; 459 kb->INTERNAL_FIELD (kbd_queue) = val;
463} 460}
464static inline void 461static void
465kset_keyboard_translate_table (struct kboard *kb, Lisp_Object val) 462kset_keyboard_translate_table (struct kboard *kb, Lisp_Object val)
466{ 463{
467 kb->INTERNAL_FIELD (Vkeyboard_translate_table) = val; 464 kb->INTERNAL_FIELD (Vkeyboard_translate_table) = val;
468} 465}
469static inline void 466static void
470kset_last_prefix_arg (struct kboard *kb, Lisp_Object val) 467kset_last_prefix_arg (struct kboard *kb, Lisp_Object val)
471{ 468{
472 kb->INTERNAL_FIELD (Vlast_prefix_arg) = val; 469 kb->INTERNAL_FIELD (Vlast_prefix_arg) = val;
473} 470}
474static inline void 471static void
475kset_last_repeatable_command (struct kboard *kb, Lisp_Object val) 472kset_last_repeatable_command (struct kboard *kb, Lisp_Object val)
476{ 473{
477 kb->INTERNAL_FIELD (Vlast_repeatable_command) = val; 474 kb->INTERNAL_FIELD (Vlast_repeatable_command) = val;
478} 475}
479static inline void 476static void
480kset_local_function_key_map (struct kboard *kb, Lisp_Object val) 477kset_local_function_key_map (struct kboard *kb, Lisp_Object val)
481{ 478{
482 kb->INTERNAL_FIELD (Vlocal_function_key_map) = val; 479 kb->INTERNAL_FIELD (Vlocal_function_key_map) = val;
483} 480}
484static inline void 481static void
485kset_overriding_terminal_local_map (struct kboard *kb, Lisp_Object val) 482kset_overriding_terminal_local_map (struct kboard *kb, Lisp_Object val)
486{ 483{
487 kb->INTERNAL_FIELD (Voverriding_terminal_local_map) = val; 484 kb->INTERNAL_FIELD (Voverriding_terminal_local_map) = val;
488} 485}
489static inline void 486static void
490kset_real_last_command (struct kboard *kb, Lisp_Object val) 487kset_real_last_command (struct kboard *kb, Lisp_Object val)
491{ 488{
492 kb->INTERNAL_FIELD (Vreal_last_command) = val; 489 kb->INTERNAL_FIELD (Vreal_last_command) = val;
493} 490}
494static inline void 491static void
495kset_system_key_syms (struct kboard *kb, Lisp_Object val) 492kset_system_key_syms (struct kboard *kb, Lisp_Object val)
496{ 493{
497 kb->INTERNAL_FIELD (system_key_syms) = val; 494 kb->INTERNAL_FIELD (system_key_syms) = val;
@@ -823,7 +820,7 @@ This function is called by the editor initialization to begin editing. */)
823 820
824 /* If we enter while input is blocked, don't lock up here. 821 /* If we enter while input is blocked, don't lock up here.
825 This may happen through the debugger during redisplay. */ 822 This may happen through the debugger during redisplay. */
826 if (INPUT_BLOCKED_P) 823 if (input_blocked_p ())
827 return Qnil; 824 return Qnil;
828 825
829 command_loop_level++; 826 command_loop_level++;
@@ -1216,8 +1213,7 @@ This also exits all active minibuffers. */)
1216 1213
1217 /* Unblock input if we enter with input blocked. This may happen if 1214 /* Unblock input if we enter with input blocked. This may happen if
1218 redisplay traps e.g. during tool-bar update with input blocked. */ 1215 redisplay traps e.g. during tool-bar update with input blocked. */
1219 while (INPUT_BLOCKED_P) 1216 totally_unblock_input ();
1220 UNBLOCK_INPUT;
1221 1217
1222 Fthrow (Qtop_level, Qnil); 1218 Fthrow (Qtop_level, Qnil);
1223} 1219}
@@ -1460,15 +1456,6 @@ command_loop_1 (void)
1460 } 1456 }
1461 } 1457 }
1462 1458
1463#if 0
1464 /* Select the frame that the last event came from. Usually,
1465 switch-frame events will take care of this, but if some lisp
1466 code swallows a switch-frame event, we'll fix things up here.
1467 Is this a good idea? */
1468 if (FRAMEP (internal_last_event_frame)
1469 && !EQ (internal_last_event_frame, selected_frame))
1470 Fselect_frame (internal_last_event_frame, Qnil);
1471#endif
1472 /* If it has changed current-menubar from previous value, 1459 /* If it has changed current-menubar from previous value,
1473 really recompute the menubar from the value. */ 1460 really recompute the menubar from the value. */
1474 if (! NILP (Vlucid_menu_bar_dirty_flag) 1461 if (! NILP (Vlucid_menu_bar_dirty_flag)
@@ -2008,9 +1995,9 @@ static struct atimer *poll_timer;
2008void 1995void
2009poll_for_input_1 (void) 1996poll_for_input_1 (void)
2010{ 1997{
2011 if (interrupt_input_blocked == 0 1998 if (! input_blocked_p ()
2012 && !waiting_for_input) 1999 && !waiting_for_input)
2013 read_avail_input (0); 2000 gobble_input ();
2014} 2001}
2015 2002
2016/* Timer callback function for poll_timer. TIMER is equal to 2003/* Timer callback function for poll_timer. TIMER is equal to
@@ -2020,10 +2007,7 @@ static void
2020poll_for_input (struct atimer *timer) 2007poll_for_input (struct atimer *timer)
2021{ 2008{
2022 if (poll_suppress_count == 0) 2009 if (poll_suppress_count == 0)
2023 { 2010 pending_signals = 1;
2024 interrupt_input_pending = 1;
2025 pending_signals = 1;
2026 }
2027} 2011}
2028 2012
2029#endif /* POLL_FOR_INPUT */ 2013#endif /* POLL_FOR_INPUT */
@@ -2299,11 +2283,10 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2299 Lisp_Object prev_event, 2283 Lisp_Object prev_event,
2300 int *used_mouse_menu, EMACS_TIME *end_time) 2284 int *used_mouse_menu, EMACS_TIME *end_time)
2301{ 2285{
2302 volatile Lisp_Object c; 2286 Lisp_Object c;
2303 ptrdiff_t jmpcount; 2287 ptrdiff_t jmpcount;
2304 sys_jmp_buf local_getcjmp; 2288 sys_jmp_buf local_getcjmp;
2305 sys_jmp_buf save_jump; 2289 sys_jmp_buf save_jump;
2306 volatile int key_already_recorded = 0;
2307 Lisp_Object tem, save; 2290 Lisp_Object tem, save;
2308 volatile Lisp_Object previous_echo_area_message; 2291 volatile Lisp_Object previous_echo_area_message;
2309 volatile Lisp_Object also_record; 2292 volatile Lisp_Object also_record;
@@ -2535,10 +2518,7 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2535 return c; /* wrong_kboard_jmpbuf */ 2518 return c; /* wrong_kboard_jmpbuf */
2536 2519
2537 if (! NILP (c)) 2520 if (! NILP (c))
2538 { 2521 goto exit;
2539 key_already_recorded = 1;
2540 goto non_reread_1;
2541 }
2542 } 2522 }
2543 2523
2544 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet. 2524 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
@@ -2866,12 +2846,10 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2866 goto wrong_kboard; 2846 goto wrong_kboard;
2867 } 2847 }
2868 2848
2869 non_reread_1:
2870
2871 /* Buffer switch events are only for internal wakeups 2849 /* Buffer switch events are only for internal wakeups
2872 so don't show them to the user. 2850 so don't show them to the user.
2873 Also, don't record a key if we already did. */ 2851 Also, don't record a key if we already did. */
2874 if (BUFFERP (c) || key_already_recorded) 2852 if (BUFFERP (c))
2875 goto exit; 2853 goto exit;
2876 2854
2877 /* Process special events within read_char 2855 /* Process special events within read_char
@@ -3344,7 +3322,7 @@ record_char (Lisp_Object c)
3344 If you, dear reader, have a better idea, you've got the source. :-) */ 3322 If you, dear reader, have a better idea, you've got the source. :-) */
3345 if (dribble) 3323 if (dribble)
3346 { 3324 {
3347 BLOCK_INPUT; 3325 block_input ();
3348 if (INTEGERP (c)) 3326 if (INTEGERP (c))
3349 { 3327 {
3350 if (XUINT (c) < 0x100) 3328 if (XUINT (c) < 0x100)
@@ -3370,7 +3348,7 @@ record_char (Lisp_Object c)
3370 } 3348 }
3371 3349
3372 fflush (dribble); 3350 fflush (dribble);
3373 UNBLOCK_INPUT; 3351 unblock_input ();
3374 } 3352 }
3375} 3353}
3376 3354
@@ -3514,10 +3492,8 @@ kbd_buffer_store_event (register struct input_event *event)
3514 Else, if EVENT is a quit event, store the quit event 3492 Else, if EVENT is a quit event, store the quit event
3515 in HOLD_QUIT, and return (thus ignoring further events). 3493 in HOLD_QUIT, and return (thus ignoring further events).
3516 3494
3517 This is used in read_avail_input to postpone the processing 3495 This is used to postpone the processing of the quit event until all
3518 of the quit event until all subsequent input events have been 3496 subsequent input events have been parsed (and discarded). */
3519 parsed (and discarded).
3520 */
3521 3497
3522void 3498void
3523kbd_buffer_store_event_hold (register struct input_event *event, 3499kbd_buffer_store_event_hold (register struct input_event *event,
@@ -3587,7 +3563,8 @@ kbd_buffer_store_event_hold (register struct input_event *event,
3587 } 3563 }
3588 3564
3589 last_event_timestamp = event->timestamp; 3565 last_event_timestamp = event->timestamp;
3590 handle_interrupt (); 3566
3567 handle_interrupt (0);
3591 return; 3568 return;
3592 } 3569 }
3593 3570
@@ -3643,7 +3620,6 @@ kbd_buffer_store_event_hold (register struct input_event *event,
3643 if (immediate_quit && NILP (Vinhibit_quit)) 3620 if (immediate_quit && NILP (Vinhibit_quit))
3644 { 3621 {
3645 immediate_quit = 0; 3622 immediate_quit = 0;
3646 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
3647 QUIT; 3623 QUIT;
3648 } 3624 }
3649 } 3625 }
@@ -3767,7 +3743,7 @@ kbd_buffer_events_waiting (int discard)
3767 3743
3768/* Clear input event EVENT. */ 3744/* Clear input event EVENT. */
3769 3745
3770static inline void 3746static void
3771clear_event (struct input_event *event) 3747clear_event (struct input_event *event)
3772{ 3748{
3773 event->kind = NO_EVENT; 3749 event->kind = NO_EVENT;
@@ -3793,14 +3769,6 @@ kbd_buffer_get_event (KBOARD **kbp,
3793 /* Start reading input again because we have processed enough to 3769 /* Start reading input again because we have processed enough to
3794 be able to accept new events again. */ 3770 be able to accept new events again. */
3795 unhold_keyboard_input (); 3771 unhold_keyboard_input ();
3796#ifdef USABLE_SIGIO
3797 if (!noninteractive)
3798 {
3799 struct sigaction action;
3800 emacs_sigaction_init (&action, deliver_input_available_signal);
3801 sigaction (SIGIO, &action, 0);
3802 }
3803#endif
3804 start_polling (); 3772 start_polling ();
3805 } 3773 }
3806#endif /* subprocesses */ 3774#endif /* subprocesses */
@@ -3843,7 +3811,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3843 interrupt handlers have not read it, read it now. */ 3811 interrupt handlers have not read it, read it now. */
3844 3812
3845#ifdef USABLE_SIGIO 3813#ifdef USABLE_SIGIO
3846 gobble_input (0); 3814 gobble_input ();
3847#endif 3815#endif
3848 if (kbd_fetch_ptr != kbd_store_ptr) 3816 if (kbd_fetch_ptr != kbd_store_ptr)
3849 break; 3817 break;
@@ -3869,8 +3837,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3869 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0); 3837 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0);
3870 3838
3871 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) 3839 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr)
3872 /* Pass 1 for EXPECT since we just waited to have input. */ 3840 gobble_input ();
3873 read_avail_input (1);
3874 } 3841 }
3875 3842
3876 if (CONSP (Vunread_command_events)) 3843 if (CONSP (Vunread_command_events))
@@ -4334,25 +4301,18 @@ decode_timer (Lisp_Object timer, EMACS_TIME *result)
4334 should be done. */ 4301 should be done. */
4335 4302
4336static EMACS_TIME 4303static EMACS_TIME
4337timer_check_2 (void) 4304timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4338{ 4305{
4339 EMACS_TIME nexttime; 4306 EMACS_TIME nexttime;
4340 EMACS_TIME now; 4307 EMACS_TIME now;
4341 EMACS_TIME idleness_now; 4308 EMACS_TIME idleness_now;
4342 Lisp_Object timers, idle_timers, chosen_timer; 4309 Lisp_Object chosen_timer;
4343 struct gcpro gcpro1, gcpro2, gcpro3; 4310 struct gcpro gcpro1;
4344 4311
4345 nexttime = invalid_emacs_time (); 4312 nexttime = invalid_emacs_time ();
4346 4313
4347 /* Always consider the ordinary timers. */
4348 timers = Vtimer_list;
4349 /* Consider the idle timers only if Emacs is idle. */
4350 if (EMACS_TIME_VALID_P (timer_idleness_start_time))
4351 idle_timers = Vtimer_idle_list;
4352 else
4353 idle_timers = Qnil;
4354 chosen_timer = Qnil; 4314 chosen_timer = Qnil;
4355 GCPRO3 (timers, idle_timers, chosen_timer); 4315 GCPRO1 (chosen_timer);
4356 4316
4357 /* First run the code that was delayed. */ 4317 /* First run the code that was delayed. */
4358 while (CONSP (pending_funcalls)) 4318 while (CONSP (pending_funcalls))
@@ -4501,13 +4461,35 @@ EMACS_TIME
4501timer_check (void) 4461timer_check (void)
4502{ 4462{
4503 EMACS_TIME nexttime; 4463 EMACS_TIME nexttime;
4464 Lisp_Object timers, idle_timers;
4465 struct gcpro gcpro1, gcpro2;
4466
4467 Lisp_Object tem = Vinhibit_quit;
4468 Vinhibit_quit = Qt;
4469
4470 /* We use copies of the timers' lists to allow a timer to add itself
4471 again, without locking up Emacs if the newly added timer is
4472 already ripe when added. */
4473
4474 /* Always consider the ordinary timers. */
4475 timers = Fcopy_sequence (Vtimer_list);
4476 /* Consider the idle timers only if Emacs is idle. */
4477 if (EMACS_TIME_VALID_P (timer_idleness_start_time))
4478 idle_timers = Fcopy_sequence (Vtimer_idle_list);
4479 else
4480 idle_timers = Qnil;
4481
4482 Vinhibit_quit = tem;
4483
4484 GCPRO2 (timers, idle_timers);
4504 4485
4505 do 4486 do
4506 { 4487 {
4507 nexttime = timer_check_2 (); 4488 nexttime = timer_check_2 (timers, idle_timers);
4508 } 4489 }
4509 while (EMACS_SECS (nexttime) == 0 && EMACS_NSECS (nexttime) == 0); 4490 while (EMACS_SECS (nexttime) == 0 && EMACS_NSECS (nexttime) == 0);
4510 4491
4492 UNGCPRO;
4511 return nexttime; 4493 return nexttime;
4512} 4494}
4513 4495
@@ -6734,45 +6716,10 @@ get_input_pending (int *addr, int flags)
6734 return; 6716 return;
6735 6717
6736 /* Try to read some input and see how much we get. */ 6718 /* Try to read some input and see how much we get. */
6737 gobble_input (0); 6719 gobble_input ();
6738 *addr = (!NILP (Vquit_flag) || readable_events (flags)); 6720 *addr = (!NILP (Vquit_flag) || readable_events (flags));
6739} 6721}
6740 6722
6741/* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6742
6743void
6744gobble_input (int expected)
6745{
6746#ifdef USABLE_SIGIO
6747 if (interrupt_input)
6748 {
6749 sigset_t blocked, procmask;
6750 sigemptyset (&blocked);
6751 sigaddset (&blocked, SIGIO);
6752 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6753 read_avail_input (expected);
6754 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6755 }
6756 else
6757#ifdef POLL_FOR_INPUT
6758 /* XXX This condition was (read_socket_hook && !interrupt_input),
6759 but read_socket_hook is not global anymore. Let's pretend that
6760 it's always set. */
6761 if (!interrupt_input && poll_suppress_count == 0)
6762 {
6763 sigset_t blocked, procmask;
6764 sigemptyset (&blocked);
6765 sigaddset (&blocked, SIGALRM);
6766 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6767 read_avail_input (expected);
6768 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6769 }
6770 else
6771#endif
6772#endif
6773 read_avail_input (expected);
6774}
6775
6776/* Put a BUFFER_SWITCH_EVENT in the buffer 6723/* Put a BUFFER_SWITCH_EVENT in the buffer
6777 so that read_key_sequence will notice the new current buffer. */ 6724 so that read_key_sequence will notice the new current buffer. */
6778 6725
@@ -6800,14 +6747,7 @@ record_asynch_buffer_change (void)
6800 /* Make sure no interrupt happens while storing the event. */ 6747 /* Make sure no interrupt happens while storing the event. */
6801#ifdef USABLE_SIGIO 6748#ifdef USABLE_SIGIO
6802 if (interrupt_input) 6749 if (interrupt_input)
6803 { 6750 kbd_buffer_store_event (&event);
6804 sigset_t blocked, procmask;
6805 sigemptyset (&blocked);
6806 sigaddset (&blocked, SIGIO);
6807 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6808 kbd_buffer_store_event (&event);
6809 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6810 }
6811 else 6751 else
6812#endif 6752#endif
6813 { 6753 {
@@ -6820,21 +6760,18 @@ record_asynch_buffer_change (void)
6820/* Read any terminal input already buffered up by the system 6760/* Read any terminal input already buffered up by the system
6821 into the kbd_buffer, but do not wait. 6761 into the kbd_buffer, but do not wait.
6822 6762
6823 EXPECTED should be nonzero if the caller knows there is some input. 6763 Return the number of keyboard chars read, or -1 meaning
6824
6825 Returns the number of keyboard chars read, or -1 meaning
6826 this is a bad time to try to read input. */ 6764 this is a bad time to try to read input. */
6827 6765
6828static int 6766int
6829read_avail_input (int expected) 6767gobble_input (void)
6830{ 6768{
6831 int nread = 0; 6769 int nread = 0;
6832 int err = 0; 6770 int err = 0;
6833 struct terminal *t; 6771 struct terminal *t;
6834 6772
6835 /* Store pending user signal events, if any. */ 6773 /* Store pending user signal events, if any. */
6836 if (store_user_signal_events ()) 6774 store_user_signal_events ();
6837 expected = 0;
6838 6775
6839 /* Loop through the available terminals, and call their input hooks. */ 6776 /* Loop through the available terminals, and call their input hooks. */
6840 t = terminal_list; 6777 t = terminal_list;
@@ -6847,15 +6784,18 @@ read_avail_input (int expected)
6847 int nr; 6784 int nr;
6848 struct input_event hold_quit; 6785 struct input_event hold_quit;
6849 6786
6787 if (input_blocked_p ())
6788 {
6789 pending_signals = 1;
6790 break;
6791 }
6792
6850 EVENT_INIT (hold_quit); 6793 EVENT_INIT (hold_quit);
6851 hold_quit.kind = NO_EVENT; 6794 hold_quit.kind = NO_EVENT;
6852 6795
6853 /* No need for FIONREAD or fcntl; just say don't wait. */ 6796 /* No need for FIONREAD or fcntl; just say don't wait. */
6854 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0) 6797 while (0 < (nr = (*t->read_socket_hook) (t, &hold_quit)))
6855 { 6798 nread += nr;
6856 nread += nr;
6857 expected = 0;
6858 }
6859 6799
6860 if (nr == -1) /* Not OK to read input now. */ 6800 if (nr == -1) /* Not OK to read input now. */
6861 { 6801 {
@@ -6875,7 +6815,7 @@ read_avail_input (int expected)
6875 this process rather than to the whole process 6815 this process rather than to the whole process
6876 group? Perhaps on systems with FIONREAD Emacs is 6816 group? Perhaps on systems with FIONREAD Emacs is
6877 alone in its group. */ 6817 alone in its group. */
6878 kill (getpid (), SIGHUP); 6818 terminate_due_to_signal (SIGHUP, 10);
6879 6819
6880 /* XXX Is calling delete_terminal safe here? It calls delete_frame. */ 6820 /* XXX Is calling delete_terminal safe here? It calls delete_frame. */
6881 { 6821 {
@@ -6950,7 +6890,6 @@ decode_keyboard_code (struct tty_display_info *tty,
6950 6890
6951int 6891int
6952tty_read_avail_input (struct terminal *terminal, 6892tty_read_avail_input (struct terminal *terminal,
6953 int expected,
6954 struct input_event *hold_quit) 6893 struct input_event *hold_quit)
6955{ 6894{
6956 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 6895 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
@@ -7165,35 +7104,68 @@ tty_read_avail_input (struct terminal *terminal,
7165static void 7104static void
7166handle_async_input (void) 7105handle_async_input (void)
7167{ 7106{
7168 interrupt_input_pending = 0; 7107#ifdef USABLE_SIGIO
7169 pending_signals = pending_atimers;
7170
7171 while (1) 7108 while (1)
7172 { 7109 {
7173 int nread; 7110 int nread = gobble_input ();
7174 nread = read_avail_input (1);
7175 /* -1 means it's not ok to read the input now. 7111 /* -1 means it's not ok to read the input now.
7176 UNBLOCK_INPUT will read it later; now, avoid infinite loop. 7112 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7177 0 means there was no keyboard input available. */ 7113 0 means there was no keyboard input available. */
7178 if (nread <= 0) 7114 if (nread <= 0)
7179 break; 7115 break;
7180 } 7116 }
7117#endif
7181} 7118}
7182 7119
7183void 7120void
7184process_pending_signals (void) 7121process_pending_signals (void)
7185{ 7122{
7186 if (interrupt_input_pending) 7123 pending_signals = 0;
7187 handle_async_input (); 7124 handle_async_input ();
7188 do_pending_atimers (); 7125 do_pending_atimers ();
7189} 7126}
7190 7127
7128/* Undo any number of BLOCK_INPUT calls down to level LEVEL,
7129 and also (if the level is now 0) reinvoke any pending signal. */
7130
7131void
7132unblock_input_to (int level)
7133{
7134 interrupt_input_blocked = level;
7135 if (level == 0)
7136 {
7137 if (pending_signals)
7138 process_pending_signals ();
7139 }
7140 else if (level < 0)
7141 emacs_abort ();
7142}
7143
7144/* End critical section.
7145
7146 If doing signal-driven input, and a signal came in when input was
7147 blocked, reinvoke the signal handler now to deal with it. */
7148
7149void
7150unblock_input (void)
7151{
7152 unblock_input_to (interrupt_input_blocked - 1);
7153}
7154
7155/* Undo any number of BLOCK_INPUT calls,
7156 and also reinvoke any pending signal. */
7157
7158void
7159totally_unblock_input (void)
7160{
7161 unblock_input_to (0);
7162}
7163
7191#ifdef USABLE_SIGIO 7164#ifdef USABLE_SIGIO
7192 7165
7193static void 7166void
7194handle_input_available_signal (int sig) 7167handle_input_available_signal (int sig)
7195{ 7168{
7196 interrupt_input_pending = 1;
7197 pending_signals = 1; 7169 pending_signals = 1;
7198 7170
7199 if (input_available_clear_time) 7171 if (input_available_clear_time)
@@ -7203,25 +7175,10 @@ handle_input_available_signal (int sig)
7203static void 7175static void
7204deliver_input_available_signal (int sig) 7176deliver_input_available_signal (int sig)
7205{ 7177{
7206 handle_on_main_thread (sig, handle_input_available_signal); 7178 deliver_process_signal (sig, handle_input_available_signal);
7207} 7179}
7208#endif /* USABLE_SIGIO */ 7180#endif /* USABLE_SIGIO */
7209 7181
7210/* Send ourselves a SIGIO.
7211
7212 This function exists so that the UNBLOCK_INPUT macro in
7213 blockinput.h can have some way to take care of input we put off
7214 dealing with, without assuming that every file which uses
7215 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7216void
7217reinvoke_input_signal (void)
7218{
7219#ifdef USABLE_SIGIO
7220 handle_async_input ();
7221#endif
7222}
7223
7224
7225 7182
7226/* User signal events. */ 7183/* User signal events. */
7227 7184
@@ -7292,7 +7249,7 @@ handle_user_signal (int sig)
7292 p->npending++; 7249 p->npending++;
7293#ifdef USABLE_SIGIO 7250#ifdef USABLE_SIGIO
7294 if (interrupt_input) 7251 if (interrupt_input)
7295 kill (getpid (), SIGIO); 7252 handle_input_available_signal (sig);
7296 else 7253 else
7297#endif 7254#endif
7298 { 7255 {
@@ -7308,7 +7265,7 @@ handle_user_signal (int sig)
7308static void 7265static void
7309deliver_user_signal (int sig) 7266deliver_user_signal (int sig)
7310{ 7267{
7311 handle_on_main_thread (sig, handle_user_signal); 7268 deliver_process_signal (sig, handle_user_signal);
7312} 7269}
7313 7270
7314static char * 7271static char *
@@ -7323,29 +7280,23 @@ find_user_signal_name (int sig)
7323 return NULL; 7280 return NULL;
7324} 7281}
7325 7282
7326static int 7283static void
7327store_user_signal_events (void) 7284store_user_signal_events (void)
7328{ 7285{
7329 struct user_signal_info *p; 7286 struct user_signal_info *p;
7330 struct input_event buf; 7287 struct input_event buf;
7331 int nstored = 0; 7288 bool buf_initialized = 0;
7332 7289
7333 for (p = user_signals; p; p = p->next) 7290 for (p = user_signals; p; p = p->next)
7334 if (p->npending > 0) 7291 if (p->npending > 0)
7335 { 7292 {
7336 sigset_t blocked, procmask; 7293 if (! buf_initialized)
7337
7338 if (nstored == 0)
7339 { 7294 {
7340 memset (&buf, 0, sizeof buf); 7295 memset (&buf, 0, sizeof buf);
7341 buf.kind = USER_SIGNAL_EVENT; 7296 buf.kind = USER_SIGNAL_EVENT;
7342 buf.frame_or_window = selected_frame; 7297 buf.frame_or_window = selected_frame;
7298 buf_initialized = 1;
7343 } 7299 }
7344 nstored += p->npending;
7345
7346 sigemptyset (&blocked);
7347 sigaddset (&blocked, p->sig);
7348 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
7349 7300
7350 do 7301 do
7351 { 7302 {
@@ -7354,11 +7305,7 @@ store_user_signal_events (void)
7354 p->npending--; 7305 p->npending--;
7355 } 7306 }
7356 while (p->npending > 0); 7307 while (p->npending > 0);
7357
7358 pthread_sigmask (SIG_SETMASK, &procmask, 0);
7359 } 7308 }
7360
7361 return nstored;
7362} 7309}
7363 7310
7364 7311
@@ -8101,7 +8048,7 @@ process_tool_bar_item (Lisp_Object key, Lisp_Object def, Lisp_Object data, void
8101 8048
8102/* Access slot with index IDX of vector tool_bar_item_properties. */ 8049/* Access slot with index IDX of vector tool_bar_item_properties. */
8103#define PROP(IDX) AREF (tool_bar_item_properties, (IDX)) 8050#define PROP(IDX) AREF (tool_bar_item_properties, (IDX))
8104static inline void 8051static void
8105set_prop (ptrdiff_t idx, Lisp_Object val) 8052set_prop (ptrdiff_t idx, Lisp_Object val)
8106{ 8053{
8107 ASET (tool_bar_item_properties, idx, val); 8054 ASET (tool_bar_item_properties, idx, val);
@@ -10562,9 +10509,9 @@ The file will be closed when Emacs exits. */)
10562{ 10509{
10563 if (dribble) 10510 if (dribble)
10564 { 10511 {
10565 BLOCK_INPUT; 10512 block_input ();
10566 fclose (dribble); 10513 fclose (dribble);
10567 UNBLOCK_INPUT; 10514 unblock_input ();
10568 dribble = 0; 10515 dribble = 0;
10569 } 10516 }
10570 if (!NILP (file)) 10517 if (!NILP (file))
@@ -10753,21 +10700,21 @@ handle_interrupt_signal (int sig)
10753 from the controlling tty. */ 10700 from the controlling tty. */
10754 internal_last_event_frame = terminal->display_info.tty->top_frame; 10701 internal_last_event_frame = terminal->display_info.tty->top_frame;
10755 10702
10756 handle_interrupt (); 10703 handle_interrupt (1);
10757 } 10704 }
10758} 10705}
10759 10706
10760static void 10707static void
10761deliver_interrupt_signal (int sig) 10708deliver_interrupt_signal (int sig)
10762{ 10709{
10763 handle_on_main_thread (sig, handle_interrupt_signal); 10710 deliver_process_signal (sig, handle_interrupt_signal);
10764} 10711}
10765 10712
10766 10713
10767/* If Emacs is stuck because `inhibit-quit' is true, then keep track 10714/* If Emacs is stuck because `inhibit-quit' is true, then keep track
10768 of the number of times C-g has been requested. If C-g is pressed 10715 of the number of times C-g has been requested. If C-g is pressed
10769 enough times, then quit anyway. See bug#6585. */ 10716 enough times, then quit anyway. See bug#6585. */
10770static int force_quit_count; 10717static int volatile force_quit_count;
10771 10718
10772/* This routine is called at interrupt level in response to C-g. 10719/* This routine is called at interrupt level in response to C-g.
10773 10720
@@ -10781,7 +10728,7 @@ static int force_quit_count;
10781 non-nil, it stops the job right away. */ 10728 non-nil, it stops the job right away. */
10782 10729
10783static void 10730static void
10784handle_interrupt (void) 10731handle_interrupt (bool in_signal_handler)
10785{ 10732{
10786 char c; 10733 char c;
10787 10734
@@ -10790,13 +10737,16 @@ handle_interrupt (void)
10790 /* XXX This code needs to be revised for multi-tty support. */ 10737 /* XXX This code needs to be revised for multi-tty support. */
10791 if (!NILP (Vquit_flag) && get_named_tty ("/dev/tty")) 10738 if (!NILP (Vquit_flag) && get_named_tty ("/dev/tty"))
10792 { 10739 {
10793 /* If SIGINT isn't blocked, don't let us be interrupted by 10740 if (! in_signal_handler)
10794 another SIGINT, it might be harmful due to non-reentrancy 10741 {
10795 in I/O functions. */ 10742 /* If SIGINT isn't blocked, don't let us be interrupted by
10796 sigset_t blocked; 10743 a SIGINT. It might be harmful due to non-reentrancy
10797 sigemptyset (&blocked); 10744 in I/O functions. */
10798 sigaddset (&blocked, SIGINT); 10745 sigset_t blocked;
10799 pthread_sigmask (SIG_BLOCK, &blocked, 0); 10746 sigemptyset (&blocked);
10747 sigaddset (&blocked, SIGINT);
10748 pthread_sigmask (SIG_BLOCK, &blocked, 0);
10749 }
10800 10750
10801 fflush (stdout); 10751 fflush (stdout);
10802 reset_all_sys_modes (); 10752 reset_all_sys_modes ();
@@ -10867,7 +10817,6 @@ handle_interrupt (void)
10867#endif /* not MSDOS */ 10817#endif /* not MSDOS */
10868 fflush (stdout); 10818 fflush (stdout);
10869 init_all_sys_modes (); 10819 init_all_sys_modes ();
10870 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
10871 } 10820 }
10872 else 10821 else
10873 { 10822 {
@@ -10885,15 +10834,14 @@ handle_interrupt (void)
10885 GCPRO4 (saved.object, saved.global_code, 10834 GCPRO4 (saved.object, saved.global_code,
10886 saved.current_syntax_table, saved.old_prop); 10835 saved.current_syntax_table, saved.old_prop);
10887 Fsignal (Qquit, Qnil); 10836 Fsignal (Qquit, Qnil);
10888 /* FIXME: AFAIK, `quit' can never return, so this code is dead! */
10889 gl_state = saved; 10837 gl_state = saved;
10890 UNGCPRO; 10838 UNGCPRO;
10891 } 10839 }
10892 else 10840 else
10893 { /* Else request quit when it's safe. */ 10841 { /* Else request quit when it's safe. */
10894 if (NILP (Vquit_flag)) 10842 int count = NILP (Vquit_flag) ? 1 : force_quit_count + 1;
10895 force_quit_count = 0; 10843 force_quit_count = count;
10896 if (++force_quit_count == 3) 10844 if (count == 3)
10897 { 10845 {
10898 immediate_quit = 1; 10846 immediate_quit = 1;
10899 Vinhibit_quit = Qnil; 10847 Vinhibit_quit = Qnil;
@@ -10902,6 +10850,8 @@ handle_interrupt (void)
10902 } 10850 }
10903 } 10851 }
10904 10852
10853 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
10854
10905/* TODO: The longjmp in this call throws the NS event loop integration off, 10855/* TODO: The longjmp in this call throws the NS event loop integration off,
10906 and it seems to do fine without this. Probably some attention 10856 and it seems to do fine without this. Probably some attention
10907 needs to be paid to the setting of waiting_for_input in 10857 needs to be paid to the setting of waiting_for_input in
@@ -10911,7 +10861,7 @@ handle_interrupt (void)
10911 separate event loop thread like W32. */ 10861 separate event loop thread like W32. */
10912#ifndef HAVE_NS 10862#ifndef HAVE_NS
10913 if (waiting_for_input && !echoing) 10863 if (waiting_for_input && !echoing)
10914 quit_throw_to_read_char (1); 10864 quit_throw_to_read_char (in_signal_handler);
10915#endif 10865#endif
10916} 10866}
10917 10867
@@ -10925,22 +10875,12 @@ quit_throw_to_read_char (int from_signal)
10925 if (!from_signal && EQ (Vquit_flag, Qkill_emacs)) 10875 if (!from_signal && EQ (Vquit_flag, Qkill_emacs))
10926 Fkill_emacs (Qnil); 10876 Fkill_emacs (Qnil);
10927 10877
10928 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
10929 /* Prevent another signal from doing this before we finish. */ 10878 /* Prevent another signal from doing this before we finish. */
10930 clear_waiting_for_input (); 10879 clear_waiting_for_input ();
10931 input_pending = 0; 10880 input_pending = 0;
10932 10881
10933 Vunread_command_events = Qnil; 10882 Vunread_command_events = Qnil;
10934 10883
10935#if 0 /* Currently, sit_for is called from read_char without turning
10936 off polling. And that can call set_waiting_for_input.
10937 It seems to be harmless. */
10938#ifdef POLL_FOR_INPUT
10939 /* May be > 1 if in recursive minibuffer. */
10940 if (poll_suppress_count == 0)
10941 emacs_abort ();
10942#endif
10943#endif
10944 if (FRAMEP (internal_last_event_frame) 10884 if (FRAMEP (internal_last_event_frame)
10945 && !EQ (internal_last_event_frame, selected_frame)) 10885 && !EQ (internal_last_event_frame, selected_frame))
10946 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), 10886 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
@@ -11331,7 +11271,6 @@ init_keyboard (void)
11331#endif 11271#endif
11332 input_pending = 0; 11272 input_pending = 0;
11333 interrupt_input_blocked = 0; 11273 interrupt_input_blocked = 0;
11334 interrupt_input_pending = 0;
11335 pending_signals = 0; 11274 pending_signals = 0;
11336 11275
11337 /* This means that command_loop_1 won't try to select anything the first 11276 /* This means that command_loop_1 won't try to select anything the first
@@ -11352,7 +11291,7 @@ init_keyboard (void)
11352 /* Before multi-tty support, these handlers used to be installed 11291 /* Before multi-tty support, these handlers used to be installed
11353 only if the current session was a tty session. Now an Emacs 11292 only if the current session was a tty session. Now an Emacs
11354 session may have multiple display types, so we always handle 11293 session may have multiple display types, so we always handle
11355 SIGINT. There is special code in interrupt_signal to exit 11294 SIGINT. There is special code in handle_interrupt_signal to exit
11356 Emacs on SIGINT when there are no termcap frames on the 11295 Emacs on SIGINT when there are no termcap frames on the
11357 controlling terminal. */ 11296 controlling terminal. */
11358 struct sigaction action; 11297 struct sigaction action;
diff --git a/src/keyboard.h b/src/keyboard.h
index 3939747abf4..d78c27fbf9b 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -523,7 +523,7 @@ extern void input_poll_signal (int);
523extern void start_polling (void); 523extern void start_polling (void);
524extern void stop_polling (void); 524extern void stop_polling (void);
525extern void set_poll_suppress_count (int); 525extern void set_poll_suppress_count (int);
526extern void gobble_input (int); 526extern int gobble_input (void);
527extern int input_polling_used (void); 527extern int input_polling_used (void);
528extern void clear_input_pending (void); 528extern void clear_input_pending (void);
529extern int requeued_events_pending_p (void); 529extern int requeued_events_pending_p (void);
@@ -547,8 +547,7 @@ extern Lisp_Object menu_item_eval_property (Lisp_Object);
547extern int kbd_buffer_events_waiting (int); 547extern int kbd_buffer_events_waiting (int);
548extern void add_user_signal (int, const char *); 548extern void add_user_signal (int, const char *);
549 549
550extern int tty_read_avail_input (struct terminal *, int, 550extern int tty_read_avail_input (struct terminal *, struct input_event *);
551 struct input_event *);
552extern EMACS_TIME timer_check (void); 551extern EMACS_TIME timer_check (void);
553extern void mark_kboards (void); 552extern void mark_kboards (void);
554 553
diff --git a/src/keymap.c b/src/keymap.c
index 66fb52061f9..6ea142651bf 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1477,7 +1477,7 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1477 1477
1478 /* Use malloc here. See the comment above this function. 1478 /* Use malloc here. See the comment above this function.
1479 Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */ 1479 Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */
1480 BLOCK_INPUT; 1480 block_input ();
1481 newmodes = malloc (allocsize); 1481 newmodes = malloc (allocsize);
1482 if (newmodes) 1482 if (newmodes)
1483 { 1483 {
@@ -1501,7 +1501,7 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
1501 } 1501 }
1502 cmm_maps = newmaps; 1502 cmm_maps = newmaps;
1503 } 1503 }
1504 UNBLOCK_INPUT; 1504 unblock_input ();
1505 1505
1506 if (newmodes == NULL || newmaps == NULL) 1506 if (newmodes == NULL || newmaps == NULL)
1507 break; 1507 break;
diff --git a/src/lisp.h b/src/lisp.h
index 3a473a60b48..2a647e593a8 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -25,6 +25,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25#include <stdarg.h> 25#include <stdarg.h>
26#include <stdbool.h> 26#include <stdbool.h>
27#include <stddef.h> 27#include <stddef.h>
28#include <float.h>
28#include <inttypes.h> 29#include <inttypes.h>
29#include <limits.h> 30#include <limits.h>
30 31
@@ -1487,6 +1488,16 @@ struct Lisp_Float
1487#define XFLOAT_DATA(f) (0 ? XFLOAT (f)->u.data : XFLOAT (f)->u.data) 1488#define XFLOAT_DATA(f) (0 ? XFLOAT (f)->u.data : XFLOAT (f)->u.data)
1488#define XFLOAT_INIT(f, n) (XFLOAT (f)->u.data = (n)) 1489#define XFLOAT_INIT(f, n) (XFLOAT (f)->u.data = (n))
1489 1490
1491/* Most hosts nowadays use IEEE floating point, so they use IEC 60559
1492 representations, have infinities and NaNs, and do not trap on
1493 exceptions. Define IEEE_FLOATING_POINT if this host is one of the
1494 typical ones. The C11 macro __STDC_IEC_559__ is close to what is
1495 wanted here, but is not quite right because Emacs does not require
1496 all the features of C11 Annex F (and does not require C11 at all,
1497 for that matter). */
1498#define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
1499 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
1500
1490/* A character, declared with the following typedef, is a member 1501/* A character, declared with the following typedef, is a member
1491 of some character set associated with the current buffer. */ 1502 of some character set associated with the current buffer. */
1492#ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */ 1503#ifndef _UCHAR_T /* Protect against something in ctab.h on AIX. */
@@ -2020,6 +2031,18 @@ extern ptrdiff_t specpdl_size;
2020 2031
2021#define SPECPDL_INDEX() (specpdl_ptr - specpdl) 2032#define SPECPDL_INDEX() (specpdl_ptr - specpdl)
2022 2033
2034struct backtrace
2035{
2036 struct backtrace *next;
2037 Lisp_Object function;
2038 Lisp_Object *args; /* Points to vector of args. */
2039 ptrdiff_t nargs; /* Length of vector. */
2040 /* Nonzero means call value of debugger when done with this operation. */
2041 unsigned int debug_on_exit : 1;
2042};
2043
2044extern struct backtrace *backtrace_list;
2045
2023/* Everything needed to describe an active condition case. 2046/* Everything needed to describe an active condition case.
2024 2047
2025 Members are volatile if their values need to survive _longjmp when 2048 Members are volatile if their values need to survive _longjmp when
@@ -2108,7 +2131,7 @@ extern char *stack_bottom;
2108 a request to exit Emacs when it is safe to do. */ 2131 a request to exit Emacs when it is safe to do. */
2109 2132
2110extern void process_pending_signals (void); 2133extern void process_pending_signals (void);
2111extern int pending_signals; 2134extern bool volatile pending_signals;
2112 2135
2113extern void process_quit_flag (void); 2136extern void process_quit_flag (void);
2114#define QUIT \ 2137#define QUIT \
@@ -2633,7 +2656,6 @@ extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
2633extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *); 2656extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *);
2634extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, bool); 2657extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, bool);
2635extern void syms_of_data (void); 2658extern void syms_of_data (void);
2636extern void init_data (void);
2637extern void swap_in_global_binding (struct Lisp_Symbol *); 2659extern void swap_in_global_binding (struct Lisp_Symbol *);
2638 2660
2639/* Defined in cmds.c */ 2661/* Defined in cmds.c */
@@ -2721,6 +2743,7 @@ extern void init_fringe_once (void);
2721extern Lisp_Object QCascent, QCmargin, QCrelief; 2743extern Lisp_Object QCascent, QCmargin, QCrelief;
2722extern Lisp_Object QCconversion; 2744extern Lisp_Object QCconversion;
2723extern int x_bitmap_mask (struct frame *, ptrdiff_t); 2745extern int x_bitmap_mask (struct frame *, ptrdiff_t);
2746extern void reset_image_types (void);
2724extern void syms_of_image (void); 2747extern void syms_of_image (void);
2725 2748
2726/* Defined in insdel.c. */ 2749/* Defined in insdel.c. */
@@ -2905,6 +2928,7 @@ build_string (const char *str)
2905 2928
2906extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); 2929extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
2907extern void make_byte_code (struct Lisp_Vector *); 2930extern void make_byte_code (struct Lisp_Vector *);
2931extern Lisp_Object Qautomatic_gc;
2908extern Lisp_Object Qchar_table_extra_slots; 2932extern Lisp_Object Qchar_table_extra_slots;
2909extern struct Lisp_Vector *allocate_vector (EMACS_INT); 2933extern struct Lisp_Vector *allocate_vector (EMACS_INT);
2910extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag); 2934extern struct Lisp_Vector *allocate_pseudovector (int memlen, int lisplen, int tag);
@@ -3227,6 +3251,9 @@ extern int input_pending;
3227extern Lisp_Object menu_bar_items (Lisp_Object); 3251extern Lisp_Object menu_bar_items (Lisp_Object);
3228extern Lisp_Object tool_bar_items (Lisp_Object, int *); 3252extern Lisp_Object tool_bar_items (Lisp_Object, int *);
3229extern void discard_mouse_events (void); 3253extern void discard_mouse_events (void);
3254#ifdef USABLE_SIGIO
3255void handle_input_available_signal (int);
3256#endif
3230extern Lisp_Object pending_funcalls; 3257extern Lisp_Object pending_funcalls;
3231extern int detect_input_pending (void); 3258extern int detect_input_pending (void);
3232extern int detect_input_pending_ignore_squeezables (void); 3259extern int detect_input_pending_ignore_squeezables (void);
@@ -3244,7 +3271,7 @@ extern void keys_of_keyboard (void);
3244/* Defined in indent.c. */ 3271/* Defined in indent.c. */
3245extern ptrdiff_t current_column (void); 3272extern ptrdiff_t current_column (void);
3246extern void invalidate_current_column (void); 3273extern void invalidate_current_column (void);
3247extern int indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT); 3274extern bool indented_beyond_p (ptrdiff_t, ptrdiff_t, EMACS_INT);
3248extern void syms_of_indent (void); 3275extern void syms_of_indent (void);
3249 3276
3250/* Defined in frame.c. */ 3277/* Defined in frame.c. */
@@ -3269,8 +3296,11 @@ extern bool display_arg;
3269extern Lisp_Object decode_env_path (const char *, const char *); 3296extern Lisp_Object decode_env_path (const char *, const char *);
3270extern Lisp_Object empty_unibyte_string, empty_multibyte_string; 3297extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3271extern Lisp_Object Qfile_name_handler_alist; 3298extern Lisp_Object Qfile_name_handler_alist;
3272extern _Noreturn void fatal_error_backtrace (int, int); 3299extern _Noreturn void terminate_due_to_signal (int, int);
3273extern Lisp_Object Qkill_emacs; 3300extern Lisp_Object Qkill_emacs;
3301#ifdef WINDOWSNT
3302extern Lisp_Object Vlibrary_cache;
3303#endif
3274#if HAVE_SETLOCALE 3304#if HAVE_SETLOCALE
3275void fixup_locale (void); 3305void fixup_locale (void);
3276void synchronize_system_messages_locale (void); 3306void synchronize_system_messages_locale (void);
@@ -3407,8 +3437,6 @@ extern void init_sys_modes (struct tty_display_info *);
3407extern void reset_sys_modes (struct tty_display_info *); 3437extern void reset_sys_modes (struct tty_display_info *);
3408extern void init_all_sys_modes (void); 3438extern void init_all_sys_modes (void);
3409extern void reset_all_sys_modes (void); 3439extern void reset_all_sys_modes (void);
3410extern void wait_for_termination (pid_t);
3411extern void interruptible_wait_for_termination (pid_t);
3412extern void flush_pending_output (int) ATTRIBUTE_CONST; 3440extern void flush_pending_output (int) ATTRIBUTE_CONST;
3413extern void child_setup_tty (int); 3441extern void child_setup_tty (int);
3414extern void setup_pty (int); 3442extern void setup_pty (int);
@@ -3519,6 +3547,13 @@ extern int have_menus_p (void);
3519void syms_of_dbusbind (void); 3547void syms_of_dbusbind (void);
3520#endif 3548#endif
3521 3549
3550
3551/* Defined in profiler.c. */
3552extern bool profiler_memory_running;
3553extern void malloc_probe (size_t);
3554extern void syms_of_profiler (void);
3555
3556
3522#ifdef DOS_NT 3557#ifdef DOS_NT
3523/* Defined in msdos.c, w32.c. */ 3558/* Defined in msdos.c, w32.c. */
3524extern char *emacs_root_dir (void); 3559extern char *emacs_root_dir (void);
diff --git a/src/lread.c b/src/lread.c
index 08d5f97292b..a2b6d1f26d9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -408,9 +408,9 @@ unreadchar (Lisp_Object readcharfun, int c)
408 { 408 {
409 if (load_each_byte) 409 if (load_each_byte)
410 { 410 {
411 BLOCK_INPUT; 411 block_input ();
412 ungetc (c, instream); 412 ungetc (c, instream);
413 UNBLOCK_INPUT; 413 unblock_input ();
414 } 414 }
415 else 415 else
416 unread_char = c; 416 unread_char = c;
@@ -431,28 +431,28 @@ readbyte_from_file (int c, Lisp_Object readcharfun)
431{ 431{
432 if (c >= 0) 432 if (c >= 0)
433 { 433 {
434 BLOCK_INPUT; 434 block_input ();
435 ungetc (c, instream); 435 ungetc (c, instream);
436 UNBLOCK_INPUT; 436 unblock_input ();
437 return 0; 437 return 0;
438 } 438 }
439 439
440 BLOCK_INPUT; 440 block_input ();
441 c = getc (instream); 441 c = getc (instream);
442 442
443#ifdef EINTR 443#ifdef EINTR
444 /* Interrupted reads have been observed while reading over the network. */ 444 /* Interrupted reads have been observed while reading over the network. */
445 while (c == EOF && ferror (instream) && errno == EINTR) 445 while (c == EOF && ferror (instream) && errno == EINTR)
446 { 446 {
447 UNBLOCK_INPUT; 447 unblock_input ();
448 QUIT; 448 QUIT;
449 BLOCK_INPUT; 449 block_input ();
450 clearerr (instream); 450 clearerr (instream);
451 c = getc (instream); 451 c = getc (instream);
452 } 452 }
453#endif 453#endif
454 454
455 UNBLOCK_INPUT; 455 unblock_input ();
456 456
457 return (c == EOF ? -1 : c); 457 return (c == EOF ? -1 : c);
458} 458}
@@ -753,9 +753,9 @@ DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
753 (void) 753 (void)
754{ 754{
755 register Lisp_Object val; 755 register Lisp_Object val;
756 BLOCK_INPUT; 756 block_input ();
757 XSETINT (val, getc (instream)); 757 XSETINT (val, getc (instream));
758 UNBLOCK_INPUT; 758 unblock_input ();
759 return val; 759 return val;
760} 760}
761 761
@@ -764,13 +764,30 @@ DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
764 764
765/* Return true if the lisp code read using READCHARFUN defines a non-nil 765/* Return true if the lisp code read using READCHARFUN defines a non-nil
766 `lexical-binding' file variable. After returning, the stream is 766 `lexical-binding' file variable. After returning, the stream is
767 positioned following the first line, if it is a comment, otherwise 767 positioned following the first line, if it is a comment or #! line,
768 nothing is read. */ 768 otherwise nothing is read. */
769 769
770static int 770static int
771lisp_file_lexically_bound_p (Lisp_Object readcharfun) 771lisp_file_lexically_bound_p (Lisp_Object readcharfun)
772{ 772{
773 int ch = READCHAR; 773 int ch = READCHAR;
774
775 if (ch == '#')
776 {
777 ch = READCHAR;
778 if (ch != '!')
779 {
780 UNREAD (ch);
781 UNREAD ('#');
782 return 0;
783 }
784 while (ch != '\n' && ch != EOF)
785 ch = READCHAR;
786 if (ch == '\n') ch = READCHAR;
787 /* It is OK to leave the position after a #! line, since
788 that is what read1 does. */
789 }
790
774 if (ch != ';') 791 if (ch != ';')
775 /* The first line isn't a comment, just give up. */ 792 /* The first line isn't a comment, just give up. */
776 { 793 {
@@ -1350,9 +1367,9 @@ load_unwind (Lisp_Object arg) /* Used as unwind-protect function in load. */
1350 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; 1367 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer;
1351 if (stream != NULL) 1368 if (stream != NULL)
1352 { 1369 {
1353 BLOCK_INPUT; 1370 block_input ();
1354 fclose (stream); 1371 fclose (stream);
1355 UNBLOCK_INPUT; 1372 unblock_input ();
1356 } 1373 }
1357 return Qnil; 1374 return Qnil;
1358} 1375}
@@ -1683,7 +1700,7 @@ readevalloop (Lisp_Object readcharfun,
1683 if (NILP (Ffboundp (macroexpand)) 1700 if (NILP (Ffboundp (macroexpand))
1684 /* Don't macroexpand in .elc files, since it should have been done 1701 /* Don't macroexpand in .elc files, since it should have been done
1685 already. We actually don't know whether we're in a .elc file or not, 1702 already. We actually don't know whether we're in a .elc file or not,
1686 so we use circumstancial evidence: .el files normally go through 1703 so we use circumstantial evidence: .el files normally go through
1687 Vload_source_file_function -> load-with-code-conversion 1704 Vload_source_file_function -> load-with-code-conversion
1688 -> eval-buffer. */ 1705 -> eval-buffer. */
1689 || EQ (readcharfun, Qget_file_char) 1706 || EQ (readcharfun, Qget_file_char)
@@ -2266,7 +2283,7 @@ read_escape (Lisp_Object readcharfun, int stringp)
2266/* Return the digit that CHARACTER stands for in the given BASE. 2283/* Return the digit that CHARACTER stands for in the given BASE.
2267 Return -1 if CHARACTER is out of range for BASE, 2284 Return -1 if CHARACTER is out of range for BASE,
2268 and -2 if CHARACTER is not valid for any supported BASE. */ 2285 and -2 if CHARACTER is not valid for any supported BASE. */
2269static inline int 2286static int
2270digit_to_number (int character, int base) 2287digit_to_number (int character, int base)
2271{ 2288{
2272 int digit; 2289 int digit;
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 24ecb2676da..c6fbf59fb5a 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -25,7 +25,7 @@ ALL = emacs
25EMACSLOADPATH=$(CURDIR)/../lisp 25EMACSLOADPATH=$(CURDIR)/../lisp
26 26
27# Size in MBs of the static heap in temacs.exe. 27# Size in MBs of the static heap in temacs.exe.
28HEAPSIZE = 27 28HEAPSIZE = $(EMACS_HEAPSIZE)
29 29
30LOCAL_FLAGS = -Demacs=1 -I../lib -I../nt/inc -DHAVE_NTGUI=1 $(EMACS_EXTRA_C_FLAGS) 30LOCAL_FLAGS = -Demacs=1 -I../lib -I../nt/inc -DHAVE_NTGUI=1 $(EMACS_EXTRA_C_FLAGS)
31 31
@@ -125,6 +125,7 @@ OBJ2 = $(BLD)/sysdep.$(O) \
125 $(BLD)/terminal.$(O) \ 125 $(BLD)/terminal.$(O) \
126 $(BLD)/menu.$(O) \ 126 $(BLD)/menu.$(O) \
127 $(BLD)/xml.$(O) \ 127 $(BLD)/xml.$(O) \
128 $(BLD)/profiler.$(O) \
128 $(BLD)/w32term.$(O) \ 129 $(BLD)/w32term.$(O) \
129 $(BLD)/w32xfns.$(O) \ 130 $(BLD)/w32xfns.$(O) \
130 $(BLD)/w32fns.$(O) \ 131 $(BLD)/w32fns.$(O) \
@@ -222,7 +223,7 @@ GLOBAL_SOURCES = dosfns.c msdos.c \
222 process.c callproc.c unexw32.c \ 223 process.c callproc.c unexw32.c \
223 region-cache.c sound.c atimer.c \ 224 region-cache.c sound.c atimer.c \
224 doprnt.c intervals.c textprop.c composite.c \ 225 doprnt.c intervals.c textprop.c composite.c \
225 gnutls.c xml.c 226 gnutls.c xml.c profiler.c
226SOME_MACHINE_OBJECTS = dosfns.o msdos.o \ 227SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
227 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o dbusbind.o 228 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o dbusbind.o
228obj = $(GLOBAL_SOURCES:.c=.o) 229obj = $(GLOBAL_SOURCES:.c=.o)
@@ -246,10 +247,10 @@ bootstrap: bootstrap-emacs
246# WARNING: Do NOT split the part inside $(ARGQUOTE)s into multiple lines as 247# WARNING: Do NOT split the part inside $(ARGQUOTE)s into multiple lines as
247# this can break with GNU Make 3.81 and later if sh.exe is used. 248# this can break with GNU Make 3.81 and later if sh.exe is used.
248bootstrap-temacs-CMD: 249bootstrap-temacs-CMD:
249 $(MAKE) $(MFLAGS) $(XMFLAGS) temacs CFLAGS=$(ARGQUOTE)$(ESC_CFLAGS) -DPURESIZE=5000000$(ARGQUOTE) 250 $(MAKE) $(MFLAGS) $(XMFLAGS) temacs CFLAGS=$(ARGQUOTE)$(ESC_CFLAGS) -DPURESIZE=$(EMACS_PURESIZE)$(ARGQUOTE)
250 251
251bootstrap-temacs-SH: 252bootstrap-temacs-SH:
252 $(MAKE) $(MFLAGS) $(XMFLAGS) temacs CFLAGS=$(ARGQUOTE)$(CFLAGS) -DPURESIZE=5000000$(ARGQUOTE) 253 $(MAKE) $(MFLAGS) $(XMFLAGS) temacs CFLAGS=$(ARGQUOTE)$(CFLAGS) -DPURESIZE=$(EMACS_PURESIZE)$(ARGQUOTE)
253 254
254bootstrap-temacs: 255bootstrap-temacs:
255 $(MAKE) $(MFLAGS) bootstrap-temacs-$(SHELLTYPE) 256 $(MAKE) $(MFLAGS) bootstrap-temacs-$(SHELLTYPE)
@@ -392,8 +393,6 @@ SYSTIME_H = $(SRC)/systime.h \
392ATIMER_H = $(SRC)/atimer.h \ 393ATIMER_H = $(SRC)/atimer.h \
393 $(NT_INC)/stdbool.h \ 394 $(NT_INC)/stdbool.h \
394 $(SYSTIME_H) 395 $(SYSTIME_H)
395BLOCKINPUT_H = $(SRC)/blockinput.h \
396 $(ATIMER_H)
397BUFFER_H = $(SRC)/buffer.h \ 396BUFFER_H = $(SRC)/buffer.h \
398 $(SYSTIME_H) 397 $(SYSTIME_H)
399C_CTYPE_H = $(GNU_LIB)/c-ctype.h \ 398C_CTYPE_H = $(GNU_LIB)/c-ctype.h \
@@ -467,6 +466,8 @@ SOCKET_H = $(NT_INC)/sys/socket.h \
467 $(SRC)/w32.h 466 $(SRC)/w32.h
468STAT_TIME_H = $(GNU_LIB)/stat-time.h \ 467STAT_TIME_H = $(GNU_LIB)/stat-time.h \
469 $(NT_INC)/sys/stat.h 468 $(NT_INC)/sys/stat.h
469SYSSIGNAL_H = $(SRC)/syssignal.h \
470 $(NT_INC)/stdbool.h
470SYSTTY_H = $(SRC)/systty.h \ 471SYSTTY_H = $(SRC)/systty.h \
471 $(NT_INC)/sys/ioctl.h \ 472 $(NT_INC)/sys/ioctl.h \
472 $(NT_INC)/unistd.h 473 $(NT_INC)/unistd.h
@@ -481,11 +482,12 @@ WINDOW_H = $(SRC)/window.h \
481 482
482$(BLD)/alloc.$(O) : \ 483$(BLD)/alloc.$(O) : \
483 $(SRC)/alloc.c \ 484 $(SRC)/alloc.c \
485 $(SRC)/blockinput.h \
484 $(SRC)/puresize.h \ 486 $(SRC)/puresize.h \
485 $(SRC)/w32.h \ 487 $(SRC)/w32.h \
488 $(SRC)/w32heap.h \
486 $(NT_INC)/unistd.h \ 489 $(NT_INC)/unistd.h \
487 $(GNU_LIB)/verify.h \ 490 $(GNU_LIB)/verify.h \
488 $(BLOCKINPUT_H) \
489 $(BUFFER_H) \ 491 $(BUFFER_H) \
490 $(CHARACTER_H) \ 492 $(CHARACTER_H) \
491 $(CONFIG_H) \ 493 $(CONFIG_H) \
@@ -499,12 +501,12 @@ $(BLD)/alloc.$(O) : \
499 501
500$(BLD)/atimer.$(O) : \ 502$(BLD)/atimer.$(O) : \
501 $(SRC)/atimer.c \ 503 $(SRC)/atimer.c \
502 $(SRC)/syssignal.h \ 504 $(SRC)/blockinput.h \
503 $(NT_INC)/unistd.h \ 505 $(NT_INC)/unistd.h \
504 $(ATIMER_H) \ 506 $(ATIMER_H) \
505 $(BLOCKINPUT_H) \
506 $(CONFIG_H) \ 507 $(CONFIG_H) \
507 $(LISP_H) \ 508 $(LISP_H) \
509 $(SYSSIGNAL_H) \
508 $(SYSTIME_H) 510 $(SYSTIME_H)
509 511
510$(BLD)/bidi.$(O) : \ 512$(BLD)/bidi.$(O) : \
@@ -517,6 +519,7 @@ $(BLD)/bidi.$(O) : \
517 519
518$(BLD)/buffer.$(O) : \ 520$(BLD)/buffer.$(O) : \
519 $(SRC)/buffer.c \ 521 $(SRC)/buffer.c \
522 $(SRC)/blockinput.h \
520 $(SRC)/commands.h \ 523 $(SRC)/commands.h \
521 $(SRC)/indent.h \ 524 $(SRC)/indent.h \
522 $(SRC)/keymap.h \ 525 $(SRC)/keymap.h \
@@ -525,7 +528,6 @@ $(BLD)/buffer.$(O) : \
525 $(NT_INC)/sys/stat.h \ 528 $(NT_INC)/sys/stat.h \
526 $(NT_INC)/unistd.h \ 529 $(NT_INC)/unistd.h \
527 $(GNU_LIB)/verify.h \ 530 $(GNU_LIB)/verify.h \
528 $(BLOCKINPUT_H) \
529 $(BUFFER_H) \ 531 $(BUFFER_H) \
530 $(CHARACTER_H) \ 532 $(CHARACTER_H) \
531 $(CONFIG_H) \ 533 $(CONFIG_H) \
@@ -557,14 +559,14 @@ $(BLD)/callint.$(O) : \
557 559
558$(BLD)/callproc.$(O) : \ 560$(BLD)/callproc.$(O) : \
559 $(SRC)/callproc.c \ 561 $(SRC)/callproc.c \
562 $(SRC)/blockinput.h \
560 $(SRC)/commands.h \ 563 $(SRC)/commands.h \
561 $(SRC)/composite.h \ 564 $(SRC)/composite.h \
562 $(SRC)/epaths.h \ 565 $(SRC)/epaths.h \
563 $(SRC)/syssignal.h \ 566 $(SRC)/syswait.h \
564 $(SRC)/w32.h \ 567 $(SRC)/w32.h \
565 $(NT_INC)/sys/file.h \ 568 $(NT_INC)/sys/file.h \
566 $(NT_INC)/unistd.h \ 569 $(NT_INC)/unistd.h \
567 $(BLOCKINPUT_H) \
568 $(BUFFER_H) \ 570 $(BUFFER_H) \
569 $(CCL_H) \ 571 $(CCL_H) \
570 $(CHARACTER_H) \ 572 $(CHARACTER_H) \
@@ -573,6 +575,7 @@ $(BLD)/callproc.$(O) : \
573 $(FRAME_H) \ 575 $(FRAME_H) \
574 $(LISP_H) \ 576 $(LISP_H) \
575 $(PROCESS_H) \ 577 $(PROCESS_H) \
578 $(SYSSIGNAL_H) \
576 $(SYSTTY_H) \ 579 $(SYSTTY_H) \
577 $(TERMHOOKS_H) 580 $(TERMHOOKS_H)
578 581
@@ -690,7 +693,6 @@ $(BLD)/data.$(O) : \
690 $(SRC)/data.c \ 693 $(SRC)/data.c \
691 $(SRC)/keymap.h \ 694 $(SRC)/keymap.h \
692 $(SRC)/puresize.h \ 695 $(SRC)/puresize.h \
693 $(SRC)/syssignal.h \
694 $(GNU_LIB)/intprops.h \ 696 $(GNU_LIB)/intprops.h \
695 $(BUFFER_H) \ 697 $(BUFFER_H) \
696 $(CHARACTER_H) \ 698 $(CHARACTER_H) \
@@ -699,16 +701,17 @@ $(BLD)/data.$(O) : \
699 $(FRAME_H) \ 701 $(FRAME_H) \
700 $(KEYBOARD_H) \ 702 $(KEYBOARD_H) \
701 $(LISP_H) \ 703 $(LISP_H) \
704 $(SYSSIGNAL_H) \
702 $(TERMHOOKS_H) 705 $(TERMHOOKS_H)
703 706
704$(BLD)/dired.$(O) : \ 707$(BLD)/dired.$(O) : \
705 $(SRC)/dired.c \ 708 $(SRC)/dired.c \
709 $(SRC)/blockinput.h \
706 $(SRC)/commands.h \ 710 $(SRC)/commands.h \
707 $(SRC)/regex.h \ 711 $(SRC)/regex.h \
708 $(NT_INC)/pwd.h \ 712 $(NT_INC)/pwd.h \
709 $(NT_INC)/sys/stat.h \ 713 $(NT_INC)/sys/stat.h \
710 $(NT_INC)/unistd.h \ 714 $(NT_INC)/unistd.h \
711 $(BLOCKINPUT_H) \
712 $(BUFFER_H) \ 715 $(BUFFER_H) \
713 $(CHARACTER_H) \ 716 $(CHARACTER_H) \
714 $(CHARSET_H) \ 717 $(CHARSET_H) \
@@ -723,15 +726,14 @@ $(BLD)/dired.$(O) : \
723 726
724$(BLD)/dispnew.$(O) : \ 727$(BLD)/dispnew.$(O) : \
725 $(SRC)/dispnew.c \ 728 $(SRC)/dispnew.c \
729 $(SRC)/blockinput.h \
726 $(SRC)/cm.h \ 730 $(SRC)/cm.h \
727 $(SRC)/commands.h \ 731 $(SRC)/commands.h \
728 $(SRC)/disptab.h \ 732 $(SRC)/disptab.h \
729 $(SRC)/indent.h \ 733 $(SRC)/indent.h \
730 $(SRC)/syssignal.h \
731 $(SRC)/termchar.h \ 734 $(SRC)/termchar.h \
732 $(SRC)/termopts.h \ 735 $(SRC)/termopts.h \
733 $(NT_INC)/unistd.h \ 736 $(NT_INC)/unistd.h \
734 $(BLOCKINPUT_H) \
735 $(BUFFER_H) \ 737 $(BUFFER_H) \
736 $(CHARACTER_H) \ 738 $(CHARACTER_H) \
737 $(CONFIG_H) \ 739 $(CONFIG_H) \
@@ -741,6 +743,7 @@ $(BLD)/dispnew.$(O) : \
741 $(KEYBOARD_H) \ 743 $(KEYBOARD_H) \
742 $(LISP_H) \ 744 $(LISP_H) \
743 $(PROCESS_H) \ 745 $(PROCESS_H) \
746 $(SYSSIGNAL_H) \
744 $(SYSTIME_H) \ 747 $(SYSTIME_H) \
745 $(TERMHOOKS_H) \ 748 $(TERMHOOKS_H) \
746 $(W32TERM_H) \ 749 $(W32TERM_H) \
@@ -768,12 +771,12 @@ $(BLD)/doprnt.$(O) : \
768 771
769$(BLD)/editfns.$(O) : \ 772$(BLD)/editfns.$(O) : \
770 $(SRC)/editfns.c \ 773 $(SRC)/editfns.c \
774 $(SRC)/blockinput.h \
771 $(NT_INC)/pwd.h \ 775 $(NT_INC)/pwd.h \
772 $(NT_INC)/unistd.h \ 776 $(NT_INC)/unistd.h \
773 $(GNU_LIB)/intprops.h \ 777 $(GNU_LIB)/intprops.h \
774 $(GNU_LIB)/strftime.h \ 778 $(GNU_LIB)/strftime.h \
775 $(GNU_LIB)/verify.h \ 779 $(GNU_LIB)/verify.h \
776 $(BLOCKINPUT_H) \
777 $(BUFFER_H) \ 780 $(BUFFER_H) \
778 $(CHARACTER_H) \ 781 $(CHARACTER_H) \
779 $(CODING_H) \ 782 $(CODING_H) \
@@ -786,16 +789,17 @@ $(BLD)/editfns.$(O) : \
786 789
787$(BLD)/emacs.$(O) : \ 790$(BLD)/emacs.$(O) : \
788 $(SRC)/emacs.c \ 791 $(SRC)/emacs.c \
792 $(SRC)/blockinput.h \
789 $(SRC)/commands.h \ 793 $(SRC)/commands.h \
790 $(SRC)/gnutls.h \ 794 $(SRC)/gnutls.h \
791 $(SRC)/keymap.h \ 795 $(SRC)/keymap.h \
792 $(SRC)/syssignal.h \
793 $(SRC)/unexec.h \ 796 $(SRC)/unexec.h \
794 $(SRC)/w32.h \ 797 $(SRC)/w32.h \
795 $(SRC)/w32heap.h \ 798 $(SRC)/w32heap.h \
796 $(NT_INC)/sys/file.h \ 799 $(NT_INC)/sys/file.h \
797 $(NT_INC)/unistd.h \ 800 $(NT_INC)/unistd.h \
798 $(BLOCKINPUT_H) \ 801 $(GNU_LIB)/ignore-value.h \
802 $(ATIMER_H) \
799 $(BUFFER_H) \ 803 $(BUFFER_H) \
800 $(CHARACTER_H) \ 804 $(CHARACTER_H) \
801 $(CONFIG_H) \ 805 $(CONFIG_H) \
@@ -804,6 +808,7 @@ $(BLD)/emacs.$(O) : \
804 $(KEYBOARD_H) \ 808 $(KEYBOARD_H) \
805 $(LISP_H) \ 809 $(LISP_H) \
806 $(PROCESS_H) \ 810 $(PROCESS_H) \
811 $(SYSSIGNAL_H) \
807 $(SYSTTY_H) \ 812 $(SYSTTY_H) \
808 $(TERMHOOKS_H) \ 813 $(TERMHOOKS_H) \
809 $(W32TERM_H) \ 814 $(W32TERM_H) \
@@ -811,8 +816,8 @@ $(BLD)/emacs.$(O) : \
811 816
812$(BLD)/eval.$(O) : \ 817$(BLD)/eval.$(O) : \
813 $(SRC)/eval.c \ 818 $(SRC)/eval.c \
819 $(SRC)/blockinput.h \
814 $(SRC)/commands.h \ 820 $(SRC)/commands.h \
815 $(BLOCKINPUT_H) \
816 $(CONFIG_H) \ 821 $(CONFIG_H) \
817 $(DISPEXTERN_H) \ 822 $(DISPEXTERN_H) \
818 $(FRAME_H) \ 823 $(FRAME_H) \
@@ -821,11 +826,11 @@ $(BLD)/eval.$(O) : \
821 826
822$(BLD)/fileio.$(O) : \ 827$(BLD)/fileio.$(O) : \
823 $(SRC)/fileio.c \ 828 $(SRC)/fileio.c \
829 $(SRC)/blockinput.h \
824 $(SRC)/commands.h \ 830 $(SRC)/commands.h \
825 $(NT_INC)/pwd.h \ 831 $(NT_INC)/pwd.h \
826 $(NT_INC)/sys/stat.h \ 832 $(NT_INC)/sys/stat.h \
827 $(NT_INC)/unistd.h \ 833 $(NT_INC)/unistd.h \
828 $(BLOCKINPUT_H) \
829 $(BUFFER_H) \ 834 $(BUFFER_H) \
830 $(CHARACTER_H) \ 835 $(CHARACTER_H) \
831 $(CODING_H) \ 836 $(CODING_H) \
@@ -858,17 +863,16 @@ $(BLD)/firstfile.$(O) : \
858 863
859$(BLD)/floatfns.$(O) : \ 864$(BLD)/floatfns.$(O) : \
860 $(SRC)/floatfns.c \ 865 $(SRC)/floatfns.c \
861 $(SRC)/syssignal.h \
862 $(CONFIG_H) \ 866 $(CONFIG_H) \
863 $(LISP_H) 867 $(LISP_H)
864 868
865$(BLD)/fns.$(O) : \ 869$(BLD)/fns.$(O) : \
866 $(SRC)/fns.c \ 870 $(SRC)/fns.c \
871 $(SRC)/blockinput.h \
867 $(SRC)/commands.h \ 872 $(SRC)/commands.h \
868 $(SRC)/keymap.h \ 873 $(SRC)/keymap.h \
869 $(NT_INC)/unistd.h \ 874 $(NT_INC)/unistd.h \
870 $(GNU_LIB)/intprops.h \ 875 $(GNU_LIB)/intprops.h \
871 $(BLOCKINPUT_H) \
872 $(BUFFER_H) \ 876 $(BUFFER_H) \
873 $(CHARACTER_H) \ 877 $(CHARACTER_H) \
874 $(CODING_H) \ 878 $(CODING_H) \
@@ -902,8 +906,8 @@ $(BLD)/font.$(O) : \
902 906
903$(BLD)/fontset.$(O) : \ 907$(BLD)/fontset.$(O) : \
904 $(SRC)/fontset.c \ 908 $(SRC)/fontset.c \
909 $(SRC)/blockinput.h \
905 $(SRC)/fontset.h \ 910 $(SRC)/fontset.h \
906 $(BLOCKINPUT_H) \
907 $(BUFFER_H) \ 911 $(BUFFER_H) \
908 $(CCL_H) \ 912 $(CCL_H) \
909 $(CHARACTER_H) \ 913 $(CHARACTER_H) \
@@ -921,10 +925,10 @@ $(BLD)/fontset.$(O) : \
921 925
922$(BLD)/frame.$(O) : \ 926$(BLD)/frame.$(O) : \
923 $(SRC)/frame.c \ 927 $(SRC)/frame.c \
928 $(SRC)/blockinput.h \
924 $(SRC)/commands.h \ 929 $(SRC)/commands.h \
925 $(SRC)/fontset.h \ 930 $(SRC)/fontset.h \
926 $(SRC)/termchar.h \ 931 $(SRC)/termchar.h \
927 $(BLOCKINPUT_H) \
928 $(BUFFER_H) \ 932 $(BUFFER_H) \
929 $(CHARACTER_H) \ 933 $(CHARACTER_H) \
930 $(CONFIG_H) \ 934 $(CONFIG_H) \
@@ -940,7 +944,7 @@ $(BLD)/frame.$(O) : \
940 944
941$(BLD)/fringe.$(O) : \ 945$(BLD)/fringe.$(O) : \
942 $(SRC)/fringe.c \ 946 $(SRC)/fringe.c \
943 $(BLOCKINPUT_H) \ 947 $(SRC)/blockinput.h \
944 $(BUFFER_H) \ 948 $(BUFFER_H) \
945 $(CHARACTER_H) \ 949 $(CHARACTER_H) \
946 $(CONFIG_H) \ 950 $(CONFIG_H) \
@@ -952,6 +956,7 @@ $(BLD)/fringe.$(O) : \
952 956
953$(BLD)/gmalloc.$(O) : \ 957$(BLD)/gmalloc.$(O) : \
954 $(SRC)/gmalloc.c \ 958 $(SRC)/gmalloc.c \
959 $(SRC)/w32heap.h \
955 $(NT_INC)/stdint.h \ 960 $(NT_INC)/stdint.h \
956 $(NT_INC)/unistd.h \ 961 $(NT_INC)/unistd.h \
957 $(CONFIG_H) 962 $(CONFIG_H)
@@ -971,12 +976,19 @@ $(BLD)/xml.$(O) : \
971 $(CONFIG_H) \ 976 $(CONFIG_H) \
972 $(LISP_H) 977 $(LISP_H)
973 978
979$(BLD)/profiler.$(O) : \
980 $(SRC)/profiler.c \
981 $(CONFIG_H) \
982 $(LISP_H) \
983 $(SYSSIGNAL_H) \
984 $(SYSTIME_H)
985
974$(BLD)/image.$(O) : \ 986$(BLD)/image.$(O) : \
975 $(SRC)/image.c \ 987 $(SRC)/image.c \
988 $(SRC)/blockinput.h \
976 $(SRC)/epaths.h \ 989 $(SRC)/epaths.h \
977 $(SRC)/w32.h \ 990 $(SRC)/w32.h \
978 $(NT_INC)/unistd.h \ 991 $(NT_INC)/unistd.h \
979 $(BLOCKINPUT_H) \
980 $(CHARACTER_H) \ 992 $(CHARACTER_H) \
981 $(CODING_H) \ 993 $(CODING_H) \
982 $(CONFIG_H) \ 994 $(CONFIG_H) \
@@ -1011,9 +1023,9 @@ $(BLD)/indent.$(O) : \
1011 1023
1012$(BLD)/insdel.$(O) : \ 1024$(BLD)/insdel.$(O) : \
1013 $(SRC)/insdel.c \ 1025 $(SRC)/insdel.c \
1026 $(SRC)/blockinput.h \
1014 $(SRC)/region-cache.h \ 1027 $(SRC)/region-cache.h \
1015 $(GNU_LIB)/intprops.h \ 1028 $(GNU_LIB)/intprops.h \
1016 $(BLOCKINPUT_H) \
1017 $(BUFFER_H) \ 1029 $(BUFFER_H) \
1018 $(CHARACTER_H) \ 1030 $(CHARACTER_H) \
1019 $(CONFIG_H) \ 1031 $(CONFIG_H) \
@@ -1035,19 +1047,18 @@ $(BLD)/intervals.$(O) : \
1035 1047
1036$(BLD)/keyboard.$(O) : \ 1048$(BLD)/keyboard.$(O) : \
1037 $(SRC)/keyboard.c \ 1049 $(SRC)/keyboard.c \
1050 $(SRC)/blockinput.h \
1038 $(SRC)/commands.h \ 1051 $(SRC)/commands.h \
1039 $(SRC)/disptab.h \ 1052 $(SRC)/disptab.h \
1040 $(SRC)/keymap.h \ 1053 $(SRC)/keymap.h \
1041 $(SRC)/macros.h \ 1054 $(SRC)/macros.h \
1042 $(SRC)/puresize.h \ 1055 $(SRC)/puresize.h \
1043 $(SRC)/syntax.h \ 1056 $(SRC)/syntax.h \
1044 $(SRC)/syssignal.h \
1045 $(SRC)/termchar.h \ 1057 $(SRC)/termchar.h \
1046 $(SRC)/termopts.h \ 1058 $(SRC)/termopts.h \
1047 $(NT_INC)/sys/ioctl.h \ 1059 $(NT_INC)/sys/ioctl.h \
1048 $(NT_INC)/unistd.h \ 1060 $(NT_INC)/unistd.h \
1049 $(ATIMER_H) \ 1061 $(ATIMER_H) \
1050 $(BLOCKINPUT_H) \
1051 $(BUFFER_H) \ 1062 $(BUFFER_H) \
1052 $(CHARACTER_H) \ 1063 $(CHARACTER_H) \
1053 $(CONFIG_H) \ 1064 $(CONFIG_H) \
@@ -1057,6 +1068,7 @@ $(BLD)/keyboard.$(O) : \
1057 $(KEYBOARD_H) \ 1068 $(KEYBOARD_H) \
1058 $(LISP_H) \ 1069 $(LISP_H) \
1059 $(PROCESS_H) \ 1070 $(PROCESS_H) \
1071 $(SYSSIGNAL_H) \
1060 $(SYSTIME_H) \ 1072 $(SYSTIME_H) \
1061 $(TERMHOOKS_H) \ 1073 $(TERMHOOKS_H) \
1062 $(W32TERM_H) \ 1074 $(W32TERM_H) \
@@ -1064,10 +1076,10 @@ $(BLD)/keyboard.$(O) : \
1064 1076
1065$(BLD)/keymap.$(O) : \ 1077$(BLD)/keymap.$(O) : \
1066 $(SRC)/keymap.c \ 1078 $(SRC)/keymap.c \
1079 $(SRC)/blockinput.h \
1067 $(SRC)/commands.h \ 1080 $(SRC)/commands.h \
1068 $(SRC)/keymap.h \ 1081 $(SRC)/keymap.h \
1069 $(SRC)/puresize.h \ 1082 $(SRC)/puresize.h \
1070 $(BLOCKINPUT_H) \
1071 $(BUFFER_H) \ 1083 $(BUFFER_H) \
1072 $(CHARACTER_H) \ 1084 $(CHARACTER_H) \
1073 $(CHARSET_H) \ 1085 $(CHARSET_H) \
@@ -1085,12 +1097,12 @@ $(BLD)/lastfile.$(O) : \
1085 1097
1086$(BLD)/lread.$(O) : \ 1098$(BLD)/lread.$(O) : \
1087 $(SRC)/lread.c \ 1099 $(SRC)/lread.c \
1100 $(SRC)/blockinput.h \
1088 $(SRC)/commands.h \ 1101 $(SRC)/commands.h \
1089 $(SRC)/epaths.h \ 1102 $(SRC)/epaths.h \
1090 $(NT_INC)/sys/file.h \ 1103 $(NT_INC)/sys/file.h \
1091 $(NT_INC)/sys/stat.h \ 1104 $(NT_INC)/sys/stat.h \
1092 $(NT_INC)/unistd.h \ 1105 $(NT_INC)/unistd.h \
1093 $(BLOCKINPUT_H) \
1094 $(BUFFER_H) \ 1106 $(BUFFER_H) \
1095 $(CHARACTER_H) \ 1107 $(CHARACTER_H) \
1096 $(CHARSET_H) \ 1108 $(CHARSET_H) \
@@ -1123,8 +1135,8 @@ $(BLD)/marker.$(O) : \
1123 1135
1124$(BLD)/menu.$(O) : \ 1136$(BLD)/menu.$(O) : \
1125 $(SRC)/menu.c \ 1137 $(SRC)/menu.c \
1138 $(SRC)/blockinput.h \
1126 $(SRC)/keymap.h \ 1139 $(SRC)/keymap.h \
1127 $(BLOCKINPUT_H) \
1128 $(CONFIG_H) \ 1140 $(CONFIG_H) \
1129 $(DISPEXTERN_H) \ 1141 $(DISPEXTERN_H) \
1130 $(FRAME_H) \ 1142 $(FRAME_H) \
@@ -1178,10 +1190,10 @@ $(BLD)/w32heap.$(O) : \
1178 1190
1179$(BLD)/w32inevt.$(O) : \ 1191$(BLD)/w32inevt.$(O) : \
1180 $(SRC)/w32inevt.c \ 1192 $(SRC)/w32inevt.c \
1193 $(SRC)/blockinput.h \
1181 $(SRC)/termchar.h \ 1194 $(SRC)/termchar.h \
1182 $(SRC)/w32heap.h \ 1195 $(SRC)/w32heap.h \
1183 $(SRC)/w32inevt.h \ 1196 $(SRC)/w32inevt.h \
1184 $(BLOCKINPUT_H) \
1185 $(CONFIG_H) \ 1197 $(CONFIG_H) \
1186 $(DISPEXTERN_H) \ 1198 $(DISPEXTERN_H) \
1187 $(FRAME_H) \ 1199 $(FRAME_H) \
@@ -1193,7 +1205,6 @@ $(BLD)/w32inevt.$(O) : \
1193 1205
1194$(BLD)/w32proc.$(O) : \ 1206$(BLD)/w32proc.$(O) : \
1195 $(SRC)/w32proc.c \ 1207 $(SRC)/w32proc.c \
1196 $(SRC)/syssignal.h \
1197 $(SRC)/syswait.h \ 1208 $(SRC)/syswait.h \
1198 $(SRC)/w32.h \ 1209 $(SRC)/w32.h \
1199 $(SRC)/w32heap.h \ 1210 $(SRC)/w32heap.h \
@@ -1205,6 +1216,7 @@ $(BLD)/w32proc.$(O) : \
1205 $(LANGINFO_H) \ 1216 $(LANGINFO_H) \
1206 $(LISP_H) \ 1217 $(LISP_H) \
1207 $(PROCESS_H) \ 1218 $(PROCESS_H) \
1219 $(SYSSIGNAL_H) \
1208 $(SYSTIME_H) \ 1220 $(SYSTIME_H) \
1209 $(W32TERM_H) 1221 $(W32TERM_H)
1210 1222
@@ -1225,8 +1237,8 @@ $(BLD)/w32console.$(O) : \
1225 1237
1226$(BLD)/print.$(O) : \ 1238$(BLD)/print.$(O) : \
1227 $(SRC)/print.c \ 1239 $(SRC)/print.c \
1240 $(SRC)/blockinput.h \
1228 $(SRC)/termchar.h \ 1241 $(SRC)/termchar.h \
1229 $(BLOCKINPUT_H) \
1230 $(BUFFER_H) \ 1242 $(BUFFER_H) \
1231 $(CHARACTER_H) \ 1243 $(CHARACTER_H) \
1232 $(CHARSET_H) \ 1244 $(CHARSET_H) \
@@ -1244,11 +1256,11 @@ $(BLD)/print.$(O) : \
1244 1256
1245$(BLD)/process.$(O) : \ 1257$(BLD)/process.$(O) : \
1246 $(SRC)/process.c \ 1258 $(SRC)/process.c \
1259 $(SRC)/blockinput.h \
1247 $(SRC)/commands.h \ 1260 $(SRC)/commands.h \
1248 $(SRC)/composite.h \ 1261 $(SRC)/composite.h \
1249 $(SRC)/gnutls.h \ 1262 $(SRC)/gnutls.h \
1250 $(SRC)/sysselect.h \ 1263 $(SRC)/sysselect.h \
1251 $(SRC)/syssignal.h \
1252 $(SRC)/syswait.h \ 1264 $(SRC)/syswait.h \
1253 $(SRC)/termopts.h \ 1265 $(SRC)/termopts.h \
1254 $(NT_INC)/arpa/inet.h \ 1266 $(NT_INC)/arpa/inet.h \
@@ -1259,7 +1271,6 @@ $(BLD)/process.$(O) : \
1259 $(NT_INC)/sys/stat.h \ 1271 $(NT_INC)/sys/stat.h \
1260 $(NT_INC)/unistd.h \ 1272 $(NT_INC)/unistd.h \
1261 $(ATIMER_H) \ 1273 $(ATIMER_H) \
1262 $(BLOCKINPUT_H) \
1263 $(BUFFER_H) \ 1274 $(BUFFER_H) \
1264 $(CHARACTER_H) \ 1275 $(CHARACTER_H) \
1265 $(CODING_H) \ 1276 $(CODING_H) \
@@ -1270,6 +1281,7 @@ $(BLD)/process.$(O) : \
1270 $(LISP_H) \ 1281 $(LISP_H) \
1271 $(PROCESS_H) \ 1282 $(PROCESS_H) \
1272 $(SOCKET_H) \ 1283 $(SOCKET_H) \
1284 $(SYSSIGNAL_H) \
1273 $(SYSTIME_H) \ 1285 $(SYSTIME_H) \
1274 $(SYSTTY_H) \ 1286 $(SYSTTY_H) \
1275 $(TERMHOOKS_H) \ 1287 $(TERMHOOKS_H) \
@@ -1278,9 +1290,9 @@ $(BLD)/process.$(O) : \
1278 1290
1279$(BLD)/ralloc.$(O) : \ 1291$(BLD)/ralloc.$(O) : \
1280 $(SRC)/ralloc.c \ 1292 $(SRC)/ralloc.c \
1293 $(SRC)/blockinput.h \
1281 $(SRC)/getpagesize.h \ 1294 $(SRC)/getpagesize.h \
1282 $(NT_INC)/unistd.h \ 1295 $(NT_INC)/unistd.h \
1283 $(BLOCKINPUT_H) \
1284 $(CONFIG_H) \ 1296 $(CONFIG_H) \
1285 $(LISP_H) 1297 $(LISP_H)
1286 1298
@@ -1315,12 +1327,12 @@ $(BLD)/scroll.$(O) : \
1315 1327
1316$(BLD)/search.$(O) : \ 1328$(BLD)/search.$(O) : \
1317 $(SRC)/search.c \ 1329 $(SRC)/search.c \
1330 $(SRC)/blockinput.h \
1318 $(SRC)/category.h \ 1331 $(SRC)/category.h \
1319 $(SRC)/commands.h \ 1332 $(SRC)/commands.h \
1320 $(SRC)/regex.h \ 1333 $(SRC)/regex.h \
1321 $(SRC)/region-cache.h \ 1334 $(SRC)/region-cache.h \
1322 $(SRC)/syntax.h \ 1335 $(SRC)/syntax.h \
1323 $(BLOCKINPUT_H) \
1324 $(BUFFER_H) \ 1336 $(BUFFER_H) \
1325 $(CHARACTER_H) \ 1337 $(CHARACTER_H) \
1326 $(CHARSET_H) \ 1338 $(CHARSET_H) \
@@ -1330,12 +1342,12 @@ $(BLD)/search.$(O) : \
1330 1342
1331$(BLD)/sound.$(O) : \ 1343$(BLD)/sound.$(O) : \
1332 $(SRC)/sound.c \ 1344 $(SRC)/sound.c \
1333 $(SRC)/syssignal.h \
1334 $(NT_INC)/unistd.h \ 1345 $(NT_INC)/unistd.h \
1335 $(ATIMER_H) \ 1346 $(ATIMER_H) \
1336 $(CONFIG_H) \ 1347 $(CONFIG_H) \
1337 $(DISPEXTERN_H) \ 1348 $(DISPEXTERN_H) \
1338 $(LISP_H) 1349 $(LISP_H) \
1350 $(SYSSIGNAL_H)
1339 1351
1340$(BLD)/syntax.$(O) : \ 1352$(BLD)/syntax.$(O) : \
1341 $(SRC)/syntax.c \ 1353 $(SRC)/syntax.c \
@@ -1352,9 +1364,9 @@ $(BLD)/syntax.$(O) : \
1352 1364
1353$(BLD)/sysdep.$(O) : \ 1365$(BLD)/sysdep.$(O) : \
1354 $(SRC)/sysdep.c \ 1366 $(SRC)/sysdep.c \
1367 $(SRC)/blockinput.h \
1355 $(SRC)/cm.h \ 1368 $(SRC)/cm.h \
1356 $(SRC)/sysselect.h \ 1369 $(SRC)/sysselect.h \
1357 $(SRC)/syssignal.h \
1358 $(SRC)/syswait.h \ 1370 $(SRC)/syswait.h \
1359 $(SRC)/termchar.h \ 1371 $(SRC)/termchar.h \
1360 $(SRC)/termopts.h \ 1372 $(SRC)/termopts.h \
@@ -1367,7 +1379,6 @@ $(BLD)/sysdep.$(O) : \
1367 $(GNU_LIB)/execinfo.h \ 1379 $(GNU_LIB)/execinfo.h \
1368 $(GNU_LIB)/ignore-value.h \ 1380 $(GNU_LIB)/ignore-value.h \
1369 $(GNU_LIB)/utimens.h \ 1381 $(GNU_LIB)/utimens.h \
1370 $(BLOCKINPUT_H) \
1371 $(CAREADLINKAT_H) \ 1382 $(CAREADLINKAT_H) \
1372 $(CONFIG_H) \ 1383 $(CONFIG_H) \
1373 $(C_CTYPE_H) \ 1384 $(C_CTYPE_H) \
@@ -1378,6 +1389,7 @@ $(BLD)/sysdep.$(O) : \
1378 $(LISP_H) \ 1389 $(LISP_H) \
1379 $(PROCESS_H) \ 1390 $(PROCESS_H) \
1380 $(SOCKET_H) \ 1391 $(SOCKET_H) \
1392 $(SYSSIGNAL_H) \
1381 $(SYSTIME_H) \ 1393 $(SYSTIME_H) \
1382 $(SYSTTY_H) \ 1394 $(SYSTTY_H) \
1383 $(TERMHOOKS_H) \ 1395 $(TERMHOOKS_H) \
@@ -1385,18 +1397,17 @@ $(BLD)/sysdep.$(O) : \
1385 1397
1386$(BLD)/term.$(O) : \ 1398$(BLD)/term.$(O) : \
1387 $(SRC)/term.c \ 1399 $(SRC)/term.c \
1400 $(SRC)/blockinput.h \
1388 $(SRC)/cm.h \ 1401 $(SRC)/cm.h \
1389 $(SRC)/composite.h \ 1402 $(SRC)/composite.h \
1390 $(SRC)/disptab.h \ 1403 $(SRC)/disptab.h \
1391 $(SRC)/keymap.h \ 1404 $(SRC)/keymap.h \
1392 $(SRC)/syssignal.h \
1393 $(SRC)/termchar.h \ 1405 $(SRC)/termchar.h \
1394 $(SRC)/termopts.h \ 1406 $(SRC)/termopts.h \
1395 $(SRC)/tparam.h \ 1407 $(SRC)/tparam.h \
1396 $(NT_INC)/sys/file.h \ 1408 $(NT_INC)/sys/file.h \
1397 $(NT_INC)/sys/time.h \ 1409 $(NT_INC)/sys/time.h \
1398 $(NT_INC)/unistd.h \ 1410 $(NT_INC)/unistd.h \
1399 $(BLOCKINPUT_H) \
1400 $(BUFFER_H) \ 1411 $(BUFFER_H) \
1401 $(CHARACTER_H) \ 1412 $(CHARACTER_H) \
1402 $(CHARSET_H) \ 1413 $(CHARSET_H) \
@@ -1407,6 +1418,7 @@ $(BLD)/term.$(O) : \
1407 $(INTERVALS_H) \ 1418 $(INTERVALS_H) \
1408 $(KEYBOARD_H) \ 1419 $(KEYBOARD_H) \
1409 $(LISP_H) \ 1420 $(LISP_H) \
1421 $(SYSSIGNAL_H) \
1410 $(SYSTTY_H) \ 1422 $(SYSTTY_H) \
1411 $(TERMHOOKS_H) \ 1423 $(TERMHOOKS_H) \
1412 $(WINDOW_H) 1424 $(WINDOW_H)
@@ -1461,12 +1473,12 @@ $(BLD)/vm-limit.$(O) : \
1461 1473
1462$(BLD)/window.$(O) : \ 1474$(BLD)/window.$(O) : \
1463 $(SRC)/window.c \ 1475 $(SRC)/window.c \
1476 $(SRC)/blockinput.h \
1464 $(SRC)/commands.h \ 1477 $(SRC)/commands.h \
1465 $(SRC)/disptab.h \ 1478 $(SRC)/disptab.h \
1466 $(SRC)/indent.h \ 1479 $(SRC)/indent.h \
1467 $(SRC)/keymap.h \ 1480 $(SRC)/keymap.h \
1468 $(SRC)/termchar.h \ 1481 $(SRC)/termchar.h \
1469 $(BLOCKINPUT_H) \
1470 $(BUFFER_H) \ 1482 $(BUFFER_H) \
1471 $(CHARACTER_H) \ 1483 $(CHARACTER_H) \
1472 $(CONFIG_H) \ 1484 $(CONFIG_H) \
@@ -1481,6 +1493,7 @@ $(BLD)/window.$(O) : \
1481 1493
1482$(BLD)/xdisp.$(O) : \ 1494$(BLD)/xdisp.$(O) : \
1483 $(SRC)/xdisp.c \ 1495 $(SRC)/xdisp.c \
1496 $(SRC)/blockinput.h \
1484 $(SRC)/commands.h \ 1497 $(SRC)/commands.h \
1485 $(SRC)/disptab.h \ 1498 $(SRC)/disptab.h \
1486 $(SRC)/fontset.h \ 1499 $(SRC)/fontset.h \
@@ -1490,7 +1503,7 @@ $(BLD)/xdisp.$(O) : \
1490 $(SRC)/region-cache.h \ 1503 $(SRC)/region-cache.h \
1491 $(SRC)/termchar.h \ 1504 $(SRC)/termchar.h \
1492 $(SRC)/termopts.h \ 1505 $(SRC)/termopts.h \
1493 $(BLOCKINPUT_H) \ 1506 $(ATIMER_H) \
1494 $(BUFFER_H) \ 1507 $(BUFFER_H) \
1495 $(CHARACTER_H) \ 1508 $(CHARACTER_H) \
1496 $(CHARSET_H) \ 1509 $(CHARSET_H) \
@@ -1509,10 +1522,10 @@ $(BLD)/xdisp.$(O) : \
1509 1522
1510$(BLD)/xfaces.$(O) : \ 1523$(BLD)/xfaces.$(O) : \
1511 $(SRC)/xfaces.c \ 1524 $(SRC)/xfaces.c \
1525 $(SRC)/blockinput.h \
1512 $(SRC)/fontset.h \ 1526 $(SRC)/fontset.h \
1513 $(SRC)/termchar.h \ 1527 $(SRC)/termchar.h \
1514 $(NT_INC)/sys/stat.h \ 1528 $(NT_INC)/sys/stat.h \
1515 $(BLOCKINPUT_H) \
1516 $(BUFFER_H) \ 1529 $(BUFFER_H) \
1517 $(CHARACTER_H) \ 1530 $(CHARACTER_H) \
1518 $(CHARSET_H) \ 1531 $(CHARSET_H) \
@@ -1530,11 +1543,11 @@ $(BLD)/xfaces.$(O) : \
1530 1543
1531$(BLD)/w32fns.$(O) : \ 1544$(BLD)/w32fns.$(O) : \
1532 $(SRC)/w32fns.c \ 1545 $(SRC)/w32fns.c \
1546 $(SRC)/blockinput.h \
1533 $(SRC)/epaths.h \ 1547 $(SRC)/epaths.h \
1534 $(SRC)/fontset.h \ 1548 $(SRC)/fontset.h \
1535 $(SRC)/w32.h \ 1549 $(SRC)/w32.h \
1536 $(SRC)/w32heap.h \ 1550 $(SRC)/w32heap.h \
1537 $(BLOCKINPUT_H) \
1538 $(BUFFER_H) \ 1551 $(BUFFER_H) \
1539 $(CCL_H) \ 1552 $(CCL_H) \
1540 $(CHARACTER_H) \ 1553 $(CHARACTER_H) \
@@ -1555,9 +1568,9 @@ $(BLD)/w32fns.$(O) : \
1555 1568
1556$(BLD)/w32menu.$(O) : \ 1569$(BLD)/w32menu.$(O) : \
1557 $(SRC)/w32menu.c \ 1570 $(SRC)/w32menu.c \
1571 $(SRC)/blockinput.h \
1558 $(SRC)/keymap.h \ 1572 $(SRC)/keymap.h \
1559 $(SRC)/w32heap.h \ 1573 $(SRC)/w32heap.h \
1560 $(BLOCKINPUT_H) \
1561 $(BUFFER_H) \ 1574 $(BUFFER_H) \
1562 $(CHARACTER_H) \ 1575 $(CHARACTER_H) \
1563 $(CHARSET_H) \ 1576 $(CHARSET_H) \
@@ -1574,6 +1587,7 @@ $(BLD)/w32menu.$(O) : \
1574 1587
1575$(BLD)/w32term.$(O) : \ 1588$(BLD)/w32term.$(O) : \
1576 $(SRC)/w32term.c \ 1589 $(SRC)/w32term.c \
1590 $(SRC)/blockinput.h \
1577 $(SRC)/disptab.h \ 1591 $(SRC)/disptab.h \
1578 $(SRC)/fontset.h \ 1592 $(SRC)/fontset.h \
1579 $(SRC)/keymap.h \ 1593 $(SRC)/keymap.h \
@@ -1582,7 +1596,6 @@ $(BLD)/w32term.$(O) : \
1582 $(SRC)/w32heap.h \ 1596 $(SRC)/w32heap.h \
1583 $(NT_INC)/sys/stat.h \ 1597 $(NT_INC)/sys/stat.h \
1584 $(ATIMER_H) \ 1598 $(ATIMER_H) \
1585 $(BLOCKINPUT_H) \
1586 $(BUFFER_H) \ 1599 $(BUFFER_H) \
1587 $(CCL_H) \ 1600 $(CCL_H) \
1588 $(CHARACTER_H) \ 1601 $(CHARACTER_H) \
@@ -1605,9 +1618,9 @@ $(BLD)/w32term.$(O) : \
1605 1618
1606$(BLD)/w32select.$(O) : \ 1619$(BLD)/w32select.$(O) : \
1607 $(SRC)/w32select.c \ 1620 $(SRC)/w32select.c \
1621 $(SRC)/blockinput.h \
1608 $(SRC)/composite.h \ 1622 $(SRC)/composite.h \
1609 $(SRC)/w32heap.h \ 1623 $(SRC)/w32heap.h \
1610 $(BLOCKINPUT_H) \
1611 $(CHARSET_H) \ 1624 $(CHARSET_H) \
1612 $(CODING_H) \ 1625 $(CODING_H) \
1613 $(CONFIG_H) \ 1626 $(CONFIG_H) \
@@ -1616,15 +1629,15 @@ $(BLD)/w32select.$(O) : \
1616 1629
1617$(BLD)/w32reg.$(O) : \ 1630$(BLD)/w32reg.$(O) : \
1618 $(SRC)/w32reg.c \ 1631 $(SRC)/w32reg.c \
1619 $(BLOCKINPUT_H) \ 1632 $(SRC)/blockinput.h \
1620 $(CONFIG_H) \ 1633 $(CONFIG_H) \
1621 $(LISP_H) \ 1634 $(LISP_H) \
1622 $(W32TERM_H) 1635 $(W32TERM_H)
1623 1636
1624$(BLD)/w32xfns.$(O) : \ 1637$(BLD)/w32xfns.$(O) : \
1625 $(SRC)/w32xfns.c \ 1638 $(SRC)/w32xfns.c \
1639 $(SRC)/blockinput.h \
1626 $(SRC)/fontset.h \ 1640 $(SRC)/fontset.h \
1627 $(BLOCKINPUT_H) \
1628 $(CHARSET_H) \ 1641 $(CHARSET_H) \
1629 $(CONFIG_H) \ 1642 $(CONFIG_H) \
1630 $(FRAME_H) \ 1643 $(FRAME_H) \
diff --git a/src/marker.c b/src/marker.c
index 0c4e8cb3b55..e01647bdb2a 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -427,7 +427,7 @@ Returns nil if MARKER points nowhere. */)
427 427
428/* Change M so it points to B at CHARPOS and BYTEPOS. */ 428/* Change M so it points to B at CHARPOS and BYTEPOS. */
429 429
430static inline void 430static void
431attach_marker (struct Lisp_Marker *m, struct buffer *b, 431attach_marker (struct Lisp_Marker *m, struct buffer *b,
432 ptrdiff_t charpos, ptrdiff_t bytepos) 432 ptrdiff_t charpos, ptrdiff_t bytepos)
433{ 433{
@@ -454,7 +454,7 @@ attach_marker (struct Lisp_Marker *m, struct buffer *b,
454 whether BUFFER is a buffer object and return buffer pointer 454 whether BUFFER is a buffer object and return buffer pointer
455 corresponding to BUFFER if BUFFER is live, or NULL otherwise. */ 455 corresponding to BUFFER if BUFFER is live, or NULL otherwise. */
456 456
457static inline struct buffer * 457static struct buffer *
458live_buffer (Lisp_Object buffer) 458live_buffer (Lisp_Object buffer)
459{ 459{
460 struct buffer *b; 460 struct buffer *b;
@@ -477,7 +477,7 @@ live_buffer (Lisp_Object buffer)
477/* Internal function to set MARKER in BUFFER at POSITION. Non-zero 477/* Internal function to set MARKER in BUFFER at POSITION. Non-zero
478 RESTRICTED means limit the POSITION by the visible part of BUFFER. */ 478 RESTRICTED means limit the POSITION by the visible part of BUFFER. */
479 479
480static inline Lisp_Object 480static Lisp_Object
481set_marker_internal (Lisp_Object marker, Lisp_Object position, 481set_marker_internal (Lisp_Object marker, Lisp_Object position,
482 Lisp_Object buffer, int restricted) 482 Lisp_Object buffer, int restricted)
483{ 483{
diff --git a/src/menu.c b/src/menu.c
index 31b96cf4405..835267b2f0c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -577,9 +577,9 @@ xmalloc_widget_value (void)
577{ 577{
578 widget_value *value; 578 widget_value *value;
579 579
580 BLOCK_INPUT; 580 block_input ();
581 value = malloc_widget_value (); 581 value = malloc_widget_value ();
582 UNBLOCK_INPUT; 582 unblock_input ();
583 583
584 return value; 584 return value;
585} 585}
@@ -606,9 +606,9 @@ free_menubar_widget_value_tree (widget_value *wv)
606 free_menubar_widget_value_tree (wv->next); 606 free_menubar_widget_value_tree (wv->next);
607 wv->next = (widget_value *) 0xDEADBEEF; 607 wv->next = (widget_value *) 0xDEADBEEF;
608 } 608 }
609 BLOCK_INPUT; 609 block_input ();
610 free_widget_value (wv); 610 free_widget_value (wv);
611 UNBLOCK_INPUT; 611 unblock_input ();
612} 612}
613 613
614/* Create a tree of widget_value objects 614/* Create a tree of widget_value objects
@@ -1317,7 +1317,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1317#endif 1317#endif
1318 1318
1319 /* Display them in a menu. */ 1319 /* Display them in a menu. */
1320 BLOCK_INPUT; 1320 block_input ();
1321 1321
1322 /* FIXME: Use a terminal hook! */ 1322 /* FIXME: Use a terminal hook! */
1323#if defined HAVE_NTGUI 1323#if defined HAVE_NTGUI
@@ -1336,7 +1336,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1336 last_event_timestamp); 1336 last_event_timestamp);
1337#endif 1337#endif
1338 1338
1339 UNBLOCK_INPUT; 1339 unblock_input ();
1340 1340
1341#ifdef HAVE_NS 1341#ifdef HAVE_NS
1342 unbind_to (specpdl_count, Qnil); 1342 unbind_to (specpdl_count, Qnil);
diff --git a/src/minibuf.c b/src/minibuf.c
index 8a1e0ddde86..dd4ca34c3fb 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1703,7 +1703,7 @@ If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
1703 functions, which use one-indexing for POSITION.) This feature is 1703 functions, which use one-indexing for POSITION.) This feature is
1704 deprecated--it is best to pass nil for INITIAL-INPUT and supply the 1704 deprecated--it is best to pass nil for INITIAL-INPUT and supply the
1705 default value DEF instead. The user can yank the default value into 1705 default value DEF instead. The user can yank the default value into
1706 the minibuffer easily using \\[next-history-element]. 1706 the minibuffer easily using \\<minibuffer-local-map>\\[next-history-element].
1707 1707
1708HIST, if non-nil, specifies a history list and optionally the initial 1708HIST, if non-nil, specifies a history list and optionally the initial
1709 position in the list. It can be a symbol, which is the history list 1709 position in the list. It can be a symbol, which is the history list
@@ -1862,11 +1862,11 @@ static Lisp_Object Qmetadata;
1862 1862
1863DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0, 1863DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0,
1864 doc: /* Perform completion on buffer names. 1864 doc: /* Perform completion on buffer names.
1865If the argument FLAG is nil, invoke `try-completion', if it's t, invoke 1865STRING and PREDICATE have the same meanings as in `try-completion',
1866`all-completions', otherwise invoke `test-completion'. 1866`all-completions', and `test-completion'.
1867 1867
1868The arguments STRING and PREDICATE are as in `try-completion', 1868If FLAG is nil, invoke `try-completion'; if it is t, invoke
1869`all-completions', and `test-completion'. */) 1869`all-completions'; otherwise invoke `test-completion'. */)
1870 (Lisp_Object string, Lisp_Object predicate, Lisp_Object flag) 1870 (Lisp_Object string, Lisp_Object predicate, Lisp_Object flag)
1871{ 1871{
1872 if (NILP (flag)) 1872 if (NILP (flag))
diff --git a/src/msdos.c b/src/msdos.c
index ed5d3240aa1..bac6b977fdf 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -1229,7 +1229,7 @@ IT_update_begin (struct frame *f)
1229 if (display_info->termscript) 1229 if (display_info->termscript)
1230 fprintf (display_info->termscript, "\n\n<UPDATE_BEGIN"); 1230 fprintf (display_info->termscript, "\n\n<UPDATE_BEGIN");
1231 1231
1232 BLOCK_INPUT; 1232 block_input ();
1233 1233
1234 if (f && f == mouse_face_frame) 1234 if (f && f == mouse_face_frame)
1235 { 1235 {
@@ -1279,7 +1279,7 @@ IT_update_begin (struct frame *f)
1279 hlinfo->mouse_face_mouse_frame = NULL; 1279 hlinfo->mouse_face_mouse_frame = NULL;
1280 } 1280 }
1281 1281
1282 UNBLOCK_INPUT; 1282 unblock_input ();
1283} 1283}
1284 1284
1285static void 1285static void
@@ -1302,13 +1302,13 @@ IT_frame_up_to_date (struct frame *f)
1302 if (hlinfo->mouse_face_deferred_gc 1302 if (hlinfo->mouse_face_deferred_gc
1303 || (f && f == hlinfo->mouse_face_mouse_frame)) 1303 || (f && f == hlinfo->mouse_face_mouse_frame))
1304 { 1304 {
1305 BLOCK_INPUT; 1305 block_input ();
1306 if (hlinfo->mouse_face_mouse_frame) 1306 if (hlinfo->mouse_face_mouse_frame)
1307 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, 1307 note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
1308 hlinfo->mouse_face_mouse_x, 1308 hlinfo->mouse_face_mouse_x,
1309 hlinfo->mouse_face_mouse_y); 1309 hlinfo->mouse_face_mouse_y);
1310 hlinfo->mouse_face_deferred_gc = 0; 1310 hlinfo->mouse_face_deferred_gc = 0;
1311 UNBLOCK_INPUT; 1311 unblock_input ();
1312 } 1312 }
1313 1313
1314 /* Set the cursor type to whatever they wanted. In a minibuffer 1314 /* Set the cursor type to whatever they wanted. In a minibuffer
diff --git a/src/nsfns.m b/src/nsfns.m
index 072005d2d3d..7a22ac547c3 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -93,8 +93,6 @@ EmacsTooltip *ns_tooltip;
93/* Need forward declaration here to preserve organizational integrity of file */ 93/* Need forward declaration here to preserve organizational integrity of file */
94Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object); 94Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
95 95
96extern BOOL ns_in_resize;
97
98/* Static variables to handle applescript execution. */ 96/* Static variables to handle applescript execution. */
99static Lisp_Object as_script, *as_result; 97static Lisp_Object as_script, *as_result;
100static int as_status; 98static int as_status;
@@ -433,9 +431,6 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
433 NSView *view = FRAME_NS_VIEW (f); 431 NSView *view = FRAME_NS_VIEW (f);
434 NSTRACE (x_set_icon_name); 432 NSTRACE (x_set_icon_name);
435 433
436 if (ns_in_resize)
437 return;
438
439 /* see if it's changed */ 434 /* see if it's changed */
440 if (STRINGP (arg)) 435 if (STRINGP (arg))
441 { 436 {
@@ -511,9 +506,6 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
511{ 506{
512 NSTRACE (ns_set_name); 507 NSTRACE (ns_set_name);
513 508
514 if (ns_in_resize)
515 return;
516
517 /* Make sure that requests from lisp code override requests from 509 /* Make sure that requests from lisp code override requests from
518 Emacs redisplay code. */ 510 Emacs redisplay code. */
519 if (explicit) 511 if (explicit)
@@ -612,10 +604,10 @@ ns_set_name_as_filename (struct frame *f)
612 NSString *str; 604 NSString *str;
613 NSTRACE (ns_set_name_as_filename); 605 NSTRACE (ns_set_name_as_filename);
614 606
615 if (f->explicit_name || ! NILP (f->title) || ns_in_resize) 607 if (f->explicit_name || ! NILP (f->title))
616 return; 608 return;
617 609
618 BLOCK_INPUT; 610 block_input ();
619 pool = [[NSAutoreleasePool alloc] init]; 611 pool = [[NSAutoreleasePool alloc] init];
620 filename = BVAR (XBUFFER (buf), filename); 612 filename = BVAR (XBUFFER (buf), filename);
621 name = BVAR (XBUFFER (buf), name); 613 name = BVAR (XBUFFER (buf), name);
@@ -640,7 +632,7 @@ ns_set_name_as_filename (struct frame *f)
640 if (title && (! strcmp (title, SSDATA (encoded_name)))) 632 if (title && (! strcmp (title, SSDATA (encoded_name))))
641 { 633 {
642 [pool release]; 634 [pool release];
643 UNBLOCK_INPUT; 635 unblock_input ();
644 return; 636 return;
645 } 637 }
646 638
@@ -678,7 +670,7 @@ ns_set_name_as_filename (struct frame *f)
678 } 670 }
679 671
680 [pool release]; 672 [pool release];
681 UNBLOCK_INPUT; 673 unblock_input ();
682} 674}
683 675
684 676
@@ -689,11 +681,11 @@ ns_set_doc_edited (struct frame *f, Lisp_Object arg)
689 NSAutoreleasePool *pool; 681 NSAutoreleasePool *pool;
690 if (!MINI_WINDOW_P (XWINDOW (f->selected_window))) 682 if (!MINI_WINDOW_P (XWINDOW (f->selected_window)))
691 { 683 {
692 BLOCK_INPUT; 684 block_input ();
693 pool = [[NSAutoreleasePool alloc] init]; 685 pool = [[NSAutoreleasePool alloc] init];
694 [[view window] setDocumentEdited: !NILP (arg)]; 686 [[view window] setDocumentEdited: !NILP (arg)];
695 [pool release]; 687 [pool release];
696 UNBLOCK_INPUT; 688 unblock_input ();
697 } 689 }
698} 690}
699 691
@@ -771,14 +763,14 @@ ns_implicitly_set_icon_type (struct frame *f)
771 763
772 NSTRACE (ns_implicitly_set_icon_type); 764 NSTRACE (ns_implicitly_set_icon_type);
773 765
774 BLOCK_INPUT; 766 block_input ();
775 pool = [[NSAutoreleasePool alloc] init]; 767 pool = [[NSAutoreleasePool alloc] init];
776 if (f->output_data.ns->miniimage 768 if (f->output_data.ns->miniimage
777 && [[NSString stringWithUTF8String: SSDATA (f->name)] 769 && [[NSString stringWithUTF8String: SSDATA (f->name)]
778 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]]) 770 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]])
779 { 771 {
780 [pool release]; 772 [pool release];
781 UNBLOCK_INPUT; 773 unblock_input ();
782 return; 774 return;
783 } 775 }
784 776
@@ -786,7 +778,7 @@ ns_implicitly_set_icon_type (struct frame *f)
786 if (CONSP (tem) && ! NILP (XCDR (tem))) 778 if (CONSP (tem) && ! NILP (XCDR (tem)))
787 { 779 {
788 [pool release]; 780 [pool release];
789 UNBLOCK_INPUT; 781 unblock_input ();
790 return; 782 return;
791 } 783 }
792 784
@@ -826,7 +818,7 @@ ns_implicitly_set_icon_type (struct frame *f)
826 f->output_data.ns->miniimage = image; 818 f->output_data.ns->miniimage = image;
827 [view setMiniwindowImage: setMini]; 819 [view setMiniwindowImage: setMini];
828 [pool release]; 820 [pool release];
829 UNBLOCK_INPUT; 821 unblock_input ();
830} 822}
831 823
832 824
@@ -870,16 +862,6 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
870} 862}
871 863
872 864
873/* Xism; we stub out (we do implement this in ns-win.el) */
874int
875XParseGeometry (char *string, int *x, int *y,
876 unsigned int *width, unsigned int *height)
877{
878 message1 ("Warning: XParseGeometry not supported under NS.\n");
879 return 0;
880}
881
882
883/* TODO: move to nsterm? */ 865/* TODO: move to nsterm? */
884int 866int
885ns_lisp_to_cursor_type (Lisp_Object arg) 867ns_lisp_to_cursor_type (Lisp_Object arg)
@@ -1028,7 +1010,7 @@ frame_parm_handler ns_frame_parm_handlers[] =
1028 x_set_fringe_width, /* generic OK */ 1010 x_set_fringe_width, /* generic OK */
1029 x_set_fringe_width, /* generic OK */ 1011 x_set_fringe_width, /* generic OK */
1030 0, /* x_set_wait_for_wm, will ignore */ 1012 0, /* x_set_wait_for_wm, will ignore */
1031 0, /* x_set_fullscreen will ignore */ 1013 x_set_fullscreen, /* generic OK */
1032 x_set_font_backend, /* generic OK */ 1014 x_set_font_backend, /* generic OK */
1033 x_set_alpha, 1015 x_set_alpha,
1034 0, /* x_set_sticky */ 1016 0, /* x_set_sticky */
@@ -1242,7 +1224,7 @@ This function is an internal primitive--use `make-frame' instead. */)
1242 f->resx = dpyinfo->resx; 1224 f->resx = dpyinfo->resx;
1243 f->resy = dpyinfo->resy; 1225 f->resy = dpyinfo->resy;
1244 1226
1245 BLOCK_INPUT; 1227 block_input ();
1246 register_font_driver (&nsfont_driver, f); 1228 register_font_driver (&nsfont_driver, f);
1247 x_default_parameter (f, parms, Qfont_backend, Qnil, 1229 x_default_parameter (f, parms, Qfont_backend, Qnil,
1248 "fontBackend", "FontBackend", RES_TYPE_STRING); 1230 "fontBackend", "FontBackend", RES_TYPE_STRING);
@@ -1257,7 +1239,7 @@ This function is an internal primitive--use `make-frame' instead. */)
1257 build_string ([[font fontName] UTF8String]), 1239 build_string ([[font fontName] UTF8String]),
1258 "font", "Font", RES_TYPE_STRING); 1240 "font", "Font", RES_TYPE_STRING);
1259 } 1241 }
1260 UNBLOCK_INPUT; 1242 unblock_input ();
1261 1243
1262 x_default_parameter (f, parms, Qborder_width, make_number (0), 1244 x_default_parameter (f, parms, Qborder_width, make_number (0),
1263 "borderwidth", "BorderWidth", RES_TYPE_NUMBER); 1245 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
@@ -1356,6 +1338,8 @@ This function is an internal primitive--use `make-frame' instead. */)
1356 RES_TYPE_NUMBER); 1338 RES_TYPE_NUMBER);
1357 x_default_parameter (f, parms, Qalpha, Qnil, 1339 x_default_parameter (f, parms, Qalpha, Qnil,
1358 "alpha", "Alpha", RES_TYPE_NUMBER); 1340 "alpha", "Alpha", RES_TYPE_NUMBER);
1341 x_default_parameter (f, parms, Qfullscreen, Qnil,
1342 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
1359 1343
1360 width = FRAME_COLS (f); 1344 width = FRAME_COLS (f);
1361 height = FRAME_LINES (f); 1345 height = FRAME_LINES (f);
@@ -1399,6 +1383,9 @@ This function is an internal primitive--use `make-frame' instead. */)
1399 1383
1400 UNGCPRO; 1384 UNGCPRO;
1401 1385
1386 if (window_prompting & USPosition)
1387 x_set_offset (f, f->left_pos, f->top_pos, 1);
1388
1402 /* Make sure windows on this frame appear in calls to next-window 1389 /* Make sure windows on this frame appear in calls to next-window
1403 and similar functions. */ 1390 and similar functions. */
1404 Vwindow_list = Qnil; 1391 Vwindow_list = Qnil;
@@ -1418,10 +1405,10 @@ FRAME nil means use the selected frame. */)
1418 if (dpyinfo->x_focus_frame != f) 1405 if (dpyinfo->x_focus_frame != f)
1419 { 1406 {
1420 EmacsView *view = FRAME_NS_VIEW (f); 1407 EmacsView *view = FRAME_NS_VIEW (f);
1421 BLOCK_INPUT; 1408 block_input ();
1422 [NSApp activateIgnoringOtherApps: YES]; 1409 [NSApp activateIgnoringOtherApps: YES];
1423 [[view window] makeKeyAndOrderFront: view]; 1410 [[view window] makeKeyAndOrderFront: view];
1424 UNBLOCK_INPUT; 1411 unblock_input ();
1425 } 1412 }
1426 1413
1427 return Qnil; 1414 return Qnil;
@@ -1474,13 +1461,15 @@ DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
1474} 1461}
1475 1462
1476 1463
1477DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 4, 0, 1464DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
1478 doc: /* Use a graphical panel to read a file name, using prompt PROMPT. 1465 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
1479Optional arg DIR, if non-nil, supplies a default directory. 1466Optional arg DIR, if non-nil, supplies a default directory.
1480Optional arg MUSTMATCH, if non-nil, means the returned file or 1467Optional arg MUSTMATCH, if non-nil, means the returned file or
1481directory must exist. 1468directory must exist.
1482Optional arg INIT, if non-nil, provides a default file name to use. */) 1469Optional arg INIT, if non-nil, provides a default file name to use.
1483 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch, Lisp_Object init) 1470Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1471 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch,
1472 Lisp_Object init, Lisp_Object dir_only_p)
1484{ 1473{
1485 static id fileDelegate = nil; 1474 static id fileDelegate = nil;
1486 int ret; 1475 int ret;
@@ -1505,21 +1494,36 @@ Optional arg INIT, if non-nil, provides a default file name to use. */)
1505 if ([dirS characterAtIndex: 0] == '~') 1494 if ([dirS characterAtIndex: 0] == '~')
1506 dirS = [dirS stringByExpandingTildeInPath]; 1495 dirS = [dirS stringByExpandingTildeInPath];
1507 1496
1508 panel = NILP (mustmatch) ? 1497 panel = NILP (mustmatch) && NILP (dir_only_p) ?
1509 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel]; 1498 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
1510 1499
1511 [panel setTitle: promptS]; 1500 [panel setTitle: promptS];
1512 1501
1513 /* Puma (10.1) does not have */ 1502 [panel setAllowsOtherFileTypes: YES];
1514 if ([panel respondsToSelector: @selector (setAllowsOtherFileTypes:)])
1515 [panel setAllowsOtherFileTypes: YES];
1516
1517 [panel setTreatsFilePackagesAsDirectories: YES]; 1503 [panel setTreatsFilePackagesAsDirectories: YES];
1518 [panel setDelegate: fileDelegate]; 1504 [panel setDelegate: fileDelegate];
1519 1505
1520 panelOK = 0; 1506 panelOK = 0;
1521 BLOCK_INPUT; 1507 if (! NILP (dir_only_p))
1522 if (NILP (mustmatch)) 1508 {
1509 [panel setCanChooseDirectories: YES];
1510 [panel setCanChooseFiles: NO];
1511 }
1512
1513 block_input ();
1514#if defined (NS_IMPL_COCOA) && \
1515 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1516 if (! NILP (mustmatch) || ! NILP (dir_only_p))
1517 [panel setAllowedFileTypes: nil];
1518 if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]];
1519 if (initS && NILP (Ffile_directory_p (init)))
1520 [panel setNameFieldStringValue: [initS lastPathComponent]];
1521 else
1522 [panel setNameFieldStringValue: @""];
1523
1524 ret = [panel runModal];
1525#else
1526 if (NILP (mustmatch) && NILP (dir_only_p))
1523 { 1527 {
1524 ret = [panel runModalForDirectory: dirS file: initS]; 1528 ret = [panel runModalForDirectory: dirS file: initS];
1525 } 1529 }
@@ -1528,6 +1532,7 @@ Optional arg INIT, if non-nil, provides a default file name to use. */)
1528 [panel setCanChooseDirectories: YES]; 1532 [panel setCanChooseDirectories: YES];
1529 ret = [panel runModalForDirectory: dirS file: initS types: nil]; 1533 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1530 } 1534 }
1535#endif
1531 1536
1532 ret = (ret == NSOKButton) || panelOK; 1537 ret = (ret == NSOKButton) || panelOK;
1533 1538
@@ -1535,7 +1540,7 @@ Optional arg INIT, if non-nil, provides a default file name to use. */)
1535 fname = build_string ([[panel filename] UTF8String]); 1540 fname = build_string ([[panel filename] UTF8String]);
1536 1541
1537 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1542 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
1538 UNBLOCK_INPUT; 1543 unblock_input ();
1539 1544
1540 return ret ? fname : Qnil; 1545 return ret ? fname : Qnil;
1541} 1546}
@@ -1906,7 +1911,7 @@ The optional argument FRAME is currently ignored. */)
1906 error ("non-Nextstep frame used in `ns-list-colors'"); 1911 error ("non-Nextstep frame used in `ns-list-colors'");
1907 } 1912 }
1908 1913
1909 BLOCK_INPUT; 1914 block_input ();
1910 1915
1911 colorlists = [[NSColorList availableColorLists] objectEnumerator]; 1916 colorlists = [[NSColorList availableColorLists] objectEnumerator];
1912 while ((clist = [colorlists nextObject])) 1917 while ((clist = [colorlists nextObject]))
@@ -1924,7 +1929,7 @@ The optional argument FRAME is currently ignored. */)
1924 } 1929 }
1925 } 1930 }
1926 1931
1927 UNBLOCK_INPUT; 1932 unblock_input ();
1928 1933
1929 return list; 1934 return list;
1930} 1935}
@@ -1944,32 +1949,29 @@ DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
1944 1949
1945 check_ns (); 1950 check_ns ();
1946 svcs = [[NSMenu alloc] initWithTitle: @"Services"]; 1951 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
1947 [NSApp setServicesMenu: svcs]; /* this and next rebuild on <10.4 */ 1952 [NSApp setServicesMenu: svcs];
1948 [NSApp registerServicesMenuSendTypes: ns_send_types 1953 [NSApp registerServicesMenuSendTypes: ns_send_types
1949 returnTypes: ns_return_types]; 1954 returnTypes: ns_return_types];
1950 1955
1951/* On Tiger, services menu updating was made lazier (waits for user to 1956/* On Tiger, services menu updating was made lazier (waits for user to
1952 actually click on the menu), so we have to force things along: */ 1957 actually click on the menu), so we have to force things along: */
1953#ifdef NS_IMPL_COCOA 1958#ifdef NS_IMPL_COCOA
1954 if (NSAppKitVersionNumber >= 744.0) 1959 delegate = [svcs delegate];
1960 if (delegate != nil)
1955 { 1961 {
1956 delegate = [svcs delegate]; 1962 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)])
1957 if (delegate != nil) 1963 [delegate menuNeedsUpdate: svcs];
1964 if ([delegate respondsToSelector:
1965 @selector (menu:updateItem:atIndex:shouldCancel:)])
1958 { 1966 {
1959 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)]) 1967 int i, len = [delegate numberOfItemsInMenu: svcs];
1960 [delegate menuNeedsUpdate: svcs]; 1968 for (i =0; i<len; i++)
1961 if ([delegate respondsToSelector: 1969 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""];
1962 @selector (menu:updateItem:atIndex:shouldCancel:)]) 1970 for (i =0; i<len; i++)
1963 { 1971 if (![delegate menu: svcs
1964 int i, len = [delegate numberOfItemsInMenu: svcs]; 1972 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1965 for (i =0; i<len; i++) 1973 atIndex: i shouldCancel: NO])
1966 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""]; 1974 break;
1967 for (i =0; i<len; i++)
1968 if (![delegate menu: svcs
1969 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1970 atIndex: i shouldCancel: NO])
1971 break;
1972 }
1973 } 1975 }
1974 } 1976 }
1975#endif 1977#endif
@@ -2070,7 +2072,7 @@ ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2070 *result = Qt; 2072 *result = Qt;
2071 // script returned an AppleScript result 2073 // script returned an AppleScript result
2072 if ((typeUnicodeText == [returnDescriptor descriptorType]) || 2074 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
2073#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 2075#if defined (NS_IMPL_COCOA)
2074 (typeUTF16ExternalRepresentation 2076 (typeUTF16ExternalRepresentation
2075 == [returnDescriptor descriptorType]) || 2077 == [returnDescriptor descriptorType]) ||
2076#endif 2078#endif
@@ -2122,7 +2124,7 @@ In case the execution fails, an error is signaled. */)
2122 CHECK_STRING (script); 2124 CHECK_STRING (script);
2123 check_ns (); 2125 check_ns ();
2124 2126
2125 BLOCK_INPUT; 2127 block_input ();
2126 2128
2127 as_script = script; 2129 as_script = script;
2128 as_result = &result; 2130 as_result = &result;
@@ -2148,7 +2150,7 @@ In case the execution fails, an error is signaled. */)
2148 as_status = 0; 2150 as_status = 0;
2149 as_script = Qnil; 2151 as_script = Qnil;
2150 as_result = 0; 2152 as_result = 0;
2151 UNBLOCK_INPUT; 2153 unblock_input ();
2152 if (status == 0) 2154 if (status == 0)
2153 return result; 2155 return result;
2154 else if (!STRINGP (result)) 2156 else if (!STRINGP (result))
@@ -2555,7 +2557,7 @@ Text larger than the specified size is clipped. */)
2555 else 2557 else
2556 CHECK_NUMBER (dy); 2558 CHECK_NUMBER (dy);
2557 2559
2558 BLOCK_INPUT; 2560 block_input ();
2559 if (ns_tooltip == nil) 2561 if (ns_tooltip == nil)
2560 ns_tooltip = [[EmacsTooltip alloc] init]; 2562 ns_tooltip = [[EmacsTooltip alloc] init];
2561 else 2563 else
@@ -2570,7 +2572,7 @@ Text larger than the specified size is clipped. */)
2570 &root_x, &root_y); 2572 &root_x, &root_y);
2571 2573
2572 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)]; 2574 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)];
2573 UNBLOCK_INPUT; 2575 unblock_input ();
2574 2576
2575 UNGCPRO; 2577 UNGCPRO;
2576 return unbind_to (count, Qnil); 2578 return unbind_to (count, Qnil);
diff --git a/src/nsfont.m b/src/nsfont.m
index eba1eb04765..b13c96aa6ed 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -821,7 +821,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
821 font_info->glyphs = xzalloc (0x100 * sizeof *font_info->glyphs); 821 font_info->glyphs = xzalloc (0x100 * sizeof *font_info->glyphs);
822 font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics); 822 font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics);
823 823
824 BLOCK_INPUT; 824 block_input ();
825 825
826 /* for metrics */ 826 /* for metrics */
827 sfont = [nsfont screenFont]; 827 sfont = [nsfont screenFont];
@@ -932,7 +932,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
932 font->props[FONT_FULLNAME_INDEX] = 932 font->props[FONT_FULLNAME_INDEX] =
933 make_unibyte_string (font_info->name, strlen (font_info->name)); 933 make_unibyte_string (font_info->name, strlen (font_info->name));
934 } 934 }
935 UNBLOCK_INPUT; 935 unblock_input ();
936 936
937 return font_object; 937 return font_object;
938} 938}
@@ -1316,7 +1316,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1316 fprintf (stderr, "%p\tFinding glyphs for glyphs in block %d\n", 1316 fprintf (stderr, "%p\tFinding glyphs for glyphs in block %d\n",
1317 font_info, block); 1317 font_info, block);
1318 1318
1319 BLOCK_INPUT; 1319 block_input ();
1320 1320
1321#ifdef NS_IMPL_COCOA 1321#ifdef NS_IMPL_COCOA
1322 if (firstTime) 1322 if (firstTime)
@@ -1373,7 +1373,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1373#endif 1373#endif
1374 } 1374 }
1375 1375
1376 UNBLOCK_INPUT; 1376 unblock_input ();
1377 xfree (unichars); 1377 xfree (unichars);
1378} 1378}
1379 1379
@@ -1398,7 +1398,7 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
1398 numGlyphs = 0x10000; 1398 numGlyphs = 0x10000;
1399#endif 1399#endif
1400 1400
1401 BLOCK_INPUT; 1401 block_input ();
1402 sfont = [font_info->nsfont screenFont]; 1402 sfont = [font_info->nsfont screenFont];
1403 1403
1404 font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics)); 1404 font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics));
@@ -1427,7 +1427,7 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
1427 metrics->ascent = r.size.height - metrics->descent; 1427 metrics->ascent = r.size.height - metrics->descent;
1428/*-lrint (hshrink* [sfont descender] - expand * hd/2); */ 1428/*-lrint (hshrink* [sfont descender] - expand * hd/2); */
1429 } 1429 }
1430 UNBLOCK_INPUT; 1430 unblock_input ();
1431} 1431}
1432 1432
1433 1433
diff --git a/src/nsimage.m b/src/nsimage.m
index 668664c7a20..884c0763fd4 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -78,7 +78,7 @@ ns_image_from_file (Lisp_Object file)
78 return [EmacsImage allocInitFromFile: file]; 78 return [EmacsImage allocInitFromFile: file];
79} 79}
80 80
81int 81bool
82ns_load_image (struct frame *f, struct image *img, 82ns_load_image (struct frame *f, struct image *img,
83 Lisp_Object spec_file, Lisp_Object spec_data) 83 Lisp_Object spec_file, Lisp_Object spec_data)
84{ 84{
@@ -403,7 +403,6 @@ static EmacsImage *ImageList = nil;
403 if ([rep respondsToSelector: @selector (getBitmapDataPlanes:)]) 403 if ([rep respondsToSelector: @selector (getBitmapDataPlanes:)])
404 { 404 {
405 bmRep = (NSBitmapImageRep *) rep; 405 bmRep = (NSBitmapImageRep *) rep;
406 onTiger = [bmRep respondsToSelector: @selector (colorAtX:y:)];
407 406
408 if ([bmRep numberOfPlanes] >= 3) 407 if ([bmRep numberOfPlanes] >= 3)
409 [bmRep getBitmapDataPlanes: pixmapData]; 408 [bmRep getBitmapDataPlanes: pixmapData];
@@ -435,7 +434,7 @@ static EmacsImage *ImageList = nil;
435 | (pixmapData[0][loc] << 16) | (pixmapData[1][loc] << 8) 434 | (pixmapData[0][loc] << 16) | (pixmapData[1][loc] << 8)
436 | (pixmapData[2][loc]); 435 | (pixmapData[2][loc]);
437 } 436 }
438 else if (onTiger) 437 else
439 { 438 {
440 NSColor *color = [bmRep colorAtX: x y: y]; 439 NSColor *color = [bmRep colorAtX: x y: y];
441 CGFloat r, g, b, a; 440 CGFloat r, g, b, a;
@@ -445,7 +444,6 @@ static EmacsImage *ImageList = nil;
445 | ((int)(b * 255.0)); 444 | ((int)(b * 255.0));
446 445
447 } 446 }
448 return 0;
449} 447}
450 448
451- (void) setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r 449- (void) setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
@@ -463,7 +461,7 @@ static EmacsImage *ImageList = nil;
463 pixmapData[2][loc] = b; 461 pixmapData[2][loc] = b;
464 pixmapData[3][loc] = a; 462 pixmapData[3][loc] = a;
465 } 463 }
466 else if (onTiger) 464 else
467 { 465 {
468 [bmRep setColor: 466 [bmRep setColor:
469 [NSColor colorWithCalibratedRed: (r/255.0) green: (g/255.0) 467 [NSColor colorWithCalibratedRed: (r/255.0) green: (g/255.0)
@@ -483,7 +481,7 @@ static EmacsImage *ImageList = nil;
483 481
484 pixmapData[3][loc] = a; 482 pixmapData[3][loc] = a;
485 } 483 }
486 else if (onTiger) 484 else
487 { 485 {
488 NSColor *color = [bmRep colorAtX: x y: y]; 486 NSColor *color = [bmRep colorAtX: x y: y];
489 color = [color colorWithAlphaComponent: (a / 255.0)]; 487 color = [color colorWithAlphaComponent: (a / 255.0)];
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 907d3eac622..9af732c6c45 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -115,13 +115,13 @@ popup_activated (void)
115 115
116/* -------------------------------------------------------------------------- 116/* --------------------------------------------------------------------------
117 Update menubar. Three cases: 117 Update menubar. Three cases:
118 1) deep_p = 0, submenu = nil: Fresh switch onto a frame -- either set up 118 1) ! deep_p, submenu = nil: Fresh switch onto a frame -- either set up
119 just top-level menu strings (OS X), or goto case (2) (GNUstep). 119 just top-level menu strings (OS X), or goto case (2) (GNUstep).
120 2) deep_p = 1, submenu = nil: Recompute all submenus. 120 2) deep_p, submenu = nil: Recompute all submenus.
121 3) deep_p = 1, submenu = non-nil: Update contents of a single submenu. 121 3) deep_p, submenu = non-nil: Update contents of a single submenu.
122 -------------------------------------------------------------------------- */ 122 -------------------------------------------------------------------------- */
123void 123void
124ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu) 124ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
125{ 125{
126 NSAutoreleasePool *pool; 126 NSAutoreleasePool *pool;
127 id menu = [NSApp mainMenu]; 127 id menu = [NSApp mainMenu];
@@ -146,7 +146,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
146 XSETFRAME (Vmenu_updating_frame, f); 146 XSETFRAME (Vmenu_updating_frame, f);
147/*fprintf (stderr, "ns_update_menubar: frame: %p\tdeep: %d\tsub: %p\n", f, deep_p, submenu); */ 147/*fprintf (stderr, "ns_update_menubar: frame: %p\tdeep: %d\tsub: %p\n", f, deep_p, submenu); */
148 148
149 BLOCK_INPUT; 149 block_input ();
150 pool = [[NSAutoreleasePool alloc] init]; 150 pool = [[NSAutoreleasePool alloc] init];
151 151
152 /* Menu may have been created automatically; if so, discard it. */ 152 /* Menu may have been created automatically; if so, discard it. */
@@ -271,7 +271,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
271 discard_menu_items (); 271 discard_menu_items ();
272 unbind_to (specpdl_count, Qnil); 272 unbind_to (specpdl_count, Qnil);
273 [pool release]; 273 [pool release];
274 UNBLOCK_INPUT; 274 unblock_input ();
275 return; 275 return;
276 } 276 }
277 277
@@ -333,7 +333,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
333 discard_menu_items (); 333 discard_menu_items ();
334 unbind_to (specpdl_count, Qnil); 334 unbind_to (specpdl_count, Qnil);
335 [pool release]; 335 [pool release];
336 UNBLOCK_INPUT; 336 unblock_input ();
337 return; 337 return;
338 } 338 }
339 } 339 }
@@ -404,7 +404,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
404 { 404 {
405 free_menubar_widget_value_tree (first_wv); 405 free_menubar_widget_value_tree (first_wv);
406 [pool release]; 406 [pool release];
407 UNBLOCK_INPUT; 407 unblock_input ();
408 return; 408 return;
409 } 409 }
410 410
@@ -435,7 +435,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
435 { 435 {
436 free_menubar_widget_value_tree (first_wv); 436 free_menubar_widget_value_tree (first_wv);
437 [pool release]; 437 [pool release];
438 UNBLOCK_INPUT; 438 unblock_input ();
439 return; 439 return;
440 } 440 }
441 } 441 }
@@ -498,7 +498,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
498 [NSApp setMainMenu: menu]; 498 [NSApp setMainMenu: menu];
499 499
500 [pool release]; 500 [pool release];
501 UNBLOCK_INPUT; 501 unblock_input ();
502 502
503} 503}
504 504
@@ -507,7 +507,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
507 frame's menus have changed, and the *step representation should be updated 507 frame's menus have changed, and the *step representation should be updated
508 from Lisp. */ 508 from Lisp. */
509void 509void
510set_frame_menubar (struct frame *f, int first_time, int deep_p) 510set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
511{ 511{
512 ns_update_menubar (f, deep_p, nil); 512 ns_update_menubar (f, deep_p, nil);
513} 513}
@@ -722,11 +722,6 @@ extern NSString *NSMenuDidBeginTrackingNotification;
722#ifdef NS_IMPL_GNUSTEP 722#ifdef NS_IMPL_GNUSTEP
723 if ([[self window] isVisible]) 723 if ([[self window] isVisible])
724 [self sizeToFit]; 724 [self sizeToFit];
725#else
726#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_2
727 if ([self supermenu] == nil)
728 [self sizeToFit];
729#endif
730#endif 725#endif
731} 726}
732 727
@@ -1012,10 +1007,10 @@ free_frame_tool_bar (FRAME_PTR f)
1012 Under NS we just hide the toolbar until it might be needed again. 1007 Under NS we just hide the toolbar until it might be needed again.
1013 -------------------------------------------------------------------------- */ 1008 -------------------------------------------------------------------------- */
1014{ 1009{
1015 BLOCK_INPUT; 1010 block_input ();
1016 [[FRAME_NS_VIEW (f) toolbar] setVisible: NO]; 1011 [[FRAME_NS_VIEW (f) toolbar] setVisible: NO];
1017 FRAME_TOOLBAR_HEIGHT (f) = 0; 1012 FRAME_TOOLBAR_HEIGHT (f) = 0;
1018 UNBLOCK_INPUT; 1013 unblock_input ();
1019} 1014}
1020 1015
1021void 1016void
@@ -1029,7 +1024,7 @@ update_frame_tool_bar (FRAME_PTR f)
1029 NSWindow *window = [view window]; 1024 NSWindow *window = [view window];
1030 EmacsToolbar *toolbar = [view toolbar]; 1025 EmacsToolbar *toolbar = [view toolbar];
1031 1026
1032 BLOCK_INPUT; 1027 block_input ();
1033 [toolbar clearActive]; 1028 [toolbar clearActive];
1034 1029
1035 /* update EmacsToolbar as in GtkUtils, build items list */ 1030 /* update EmacsToolbar as in GtkUtils, build items list */
@@ -1115,7 +1110,7 @@ update_frame_tool_bar (FRAME_PTR f)
1115 FRAME_TOOLBAR_HEIGHT (f) = 1110 FRAME_TOOLBAR_HEIGHT (f) =
1116 NSHeight ([window frameRectForContentRect: NSMakeRect (0, 0, 0, 0)]) 1111 NSHeight ([window frameRectForContentRect: NSMakeRect (0, 0, 0, 0)])
1117 - FRAME_NS_TITLEBAR_HEIGHT (f); 1112 - FRAME_NS_TITLEBAR_HEIGHT (f);
1118 UNBLOCK_INPUT; 1113 unblock_input ();
1119} 1114}
1120 1115
1121 1116
@@ -1355,7 +1350,7 @@ pop_down_menu (Lisp_Object arg)
1355 struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 1350 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
1356 struct Popdown_data *unwind_data = (struct Popdown_data *) p->pointer; 1351 struct Popdown_data *unwind_data = (struct Popdown_data *) p->pointer;
1357 1352
1358 BLOCK_INPUT; 1353 block_input ();
1359 if (popup_activated_flag) 1354 if (popup_activated_flag)
1360 { 1355 {
1361 EmacsDialogPanel *panel = unwind_data->dialog; 1356 EmacsDialogPanel *panel = unwind_data->dialog;
@@ -1366,7 +1361,7 @@ pop_down_menu (Lisp_Object arg)
1366 } 1361 }
1367 1362
1368 xfree (unwind_data); 1363 xfree (unwind_data);
1369 UNBLOCK_INPUT; 1364 unblock_input ();
1370 1365
1371 return Qnil; 1366 return Qnil;
1372} 1367}
@@ -1434,7 +1429,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1434 the dialog. */ 1429 the dialog. */
1435 contents = Fcons (title, Fcons (Fcons (build_string ("Ok"), Qt), Qnil)); 1430 contents = Fcons (title, Fcons (Fcons (build_string ("Ok"), Qt), Qnil));
1436 1431
1437 BLOCK_INPUT; 1432 block_input ();
1438 pool = [[NSAutoreleasePool alloc] init]; 1433 pool = [[NSAutoreleasePool alloc] init];
1439 dialog = [[EmacsDialogPanel alloc] initFromContents: contents 1434 dialog = [[EmacsDialogPanel alloc] initFromContents: contents
1440 isQuestion: isQ]; 1435 isQuestion: isQ];
@@ -1452,7 +1447,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1452 unbind_to (specpdl_count, Qnil); /* calls pop_down_menu */ 1447 unbind_to (specpdl_count, Qnil); /* calls pop_down_menu */
1453 } 1448 }
1454 1449
1455 UNBLOCK_INPUT; 1450 unblock_input ();
1456 1451
1457 return tem; 1452 return tem;
1458} 1453}
@@ -1766,7 +1761,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1766} 1761}
1767 1762
1768 1763
1769 1764
1770- (void)timeout_handler: (NSTimer *)timedEntry 1765- (void)timeout_handler: (NSTimer *)timedEntry
1771{ 1766{
1772 NSEvent *nxev = [NSEvent otherEventWithType: NSApplicationDefined 1767 NSEvent *nxev = [NSEvent otherEventWithType: NSApplicationDefined
diff --git a/src/nsselect.m b/src/nsselect.m
index 95bc1a95957..c0c412c6fb2 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -295,7 +295,7 @@ ns_string_from_pasteboard (id pb)
295 utfStr = [mstr UTF8String]; 295 utfStr = [mstr UTF8String];
296 length = [mstr lengthOfBytesUsingEncoding: NSUTF8StringEncoding]; 296 length = [mstr lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
297 297
298#if ! defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4 298#if ! defined (NS_IMPL_COCOA)
299 if (!utfStr) 299 if (!utfStr)
300 { 300 {
301 utfStr = [mstr cString]; 301 utfStr = [mstr cString];
@@ -306,7 +306,7 @@ ns_string_from_pasteboard (id pb)
306 NS_HANDLER 306 NS_HANDLER
307 { 307 {
308 message1 ("ns_string_from_pasteboard: UTF8String failed\n"); 308 message1 ("ns_string_from_pasteboard: UTF8String failed\n");
309#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 309#if defined (NS_IMPL_COCOA)
310 utfStr = "Conversion failed"; 310 utfStr = "Conversion failed";
311#else 311#else
312 utfStr = [str lossyCString]; 312 utfStr = [str lossyCString];
diff --git a/src/nsterm.h b/src/nsterm.h
index f3adab883a1..958d1ce7853 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -26,9 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#ifdef HAVE_NS 26#ifdef HAVE_NS
27 27
28#ifdef NS_IMPL_COCOA 28#ifdef NS_IMPL_COCOA
29#ifndef MAC_OS_X_VERSION_10_3
30#define MAC_OS_X_VERSION_10_3 1030
31#endif
32#ifndef MAC_OS_X_VERSION_10_4 29#ifndef MAC_OS_X_VERSION_10_4
33#define MAC_OS_X_VERSION_10_4 1040 30#define MAC_OS_X_VERSION_10_4 1040
34#endif 31#endif
@@ -38,6 +35,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
38#ifndef MAC_OS_X_VERSION_10_6 35#ifndef MAC_OS_X_VERSION_10_6
39#define MAC_OS_X_VERSION_10_6 1060 36#define MAC_OS_X_VERSION_10_6 1060
40#endif 37#endif
38#ifndef MAC_OS_X_VERSION_10_7
39#define MAC_OS_X_VERSION_10_7 1070
40#endif
41#ifndef MAC_OS_X_VERSION_10_8
42#define MAC_OS_X_VERSION_10_8 1080
43#endif
41#endif /* NS_IMPL_COCOA */ 44#endif /* NS_IMPL_COCOA */
42 45
43#ifdef __OBJC__ 46#ifdef __OBJC__
@@ -80,6 +83,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
80 BOOL windowClosing; 83 BOOL windowClosing;
81 NSString *workingText; 84 NSString *workingText;
82 BOOL processingCompose; 85 BOOL processingCompose;
86 int fs_state, fs_before_fs, next_maximized;
87 int tibar_height, tobar_height, bwidth;
88 int maximized_width, maximized_height;
89 NSWindow *nonfs_window;
83@public 90@public
84 struct frame *emacsframe; 91 struct frame *emacsframe;
85 int rows, cols; 92 int rows, cols;
@@ -104,6 +111,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
104- (EmacsToolbar *) toolbar; 111- (EmacsToolbar *) toolbar;
105- (void) deleteWorkingText; 112- (void) deleteWorkingText;
106- (void) updateFrameSize: (BOOL) delay; 113- (void) updateFrameSize: (BOOL) delay;
114- (void) handleFS;
115- (void) setFSValue: (int)value;
116- (void) toggleFullScreen: (id) sender;
107 117
108#ifdef NS_IMPL_GNUSTEP 118#ifdef NS_IMPL_GNUSTEP
109/* Not declared, but useful. */ 119/* Not declared, but useful. */
@@ -120,6 +130,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
120@end 130@end
121 131
122 132
133/* Fullscreen version of the above. */
134@interface EmacsFSWindow : EmacsWindow
135{
136}
137@end
138
123/* ========================================================================== 139/* ==========================================================================
124 140
125 The main menu implementation 141 The main menu implementation
@@ -267,7 +283,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
267 int refCount; 283 int refCount;
268 NSBitmapImageRep *bmRep; /* used for accessing pixel data */ 284 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
269 unsigned char *pixmapData[5]; /* shortcut to access pixel data */ 285 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
270 BOOL onTiger;
271 NSColor *stippleMask; 286 NSColor *stippleMask;
272} 287}
273+ allocInitFromFile: (Lisp_Object)file; 288+ allocInitFromFile: (Lisp_Object)file;
@@ -336,7 +351,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
336 351
337/* ========================================================================== 352/* ==========================================================================
338 353
339 Rendering on Panther and above 354 Rendering
340 355
341 ========================================================================== */ 356 ========================================================================== */
342 357
@@ -361,7 +376,7 @@ extern NSString *ns_app_name;
361extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu; 376extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
362 377
363/* Apple removed the declaration, but kept the implementation */ 378/* Apple removed the declaration, but kept the implementation */
364#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 379#if defined (NS_IMPL_COCOA)
365@interface NSApplication (EmacsApp) 380@interface NSApplication (EmacsApp)
366- (void)setAppleMenu: (NSMenu *)menu; 381- (void)setAppleMenu: (NSMenu *)menu;
367@end 382@end
@@ -464,10 +479,9 @@ struct nsfont_info
464 float size; 479 float size;
465#ifdef __OBJC__ 480#ifdef __OBJC__
466 NSFont *nsfont; 481 NSFont *nsfont;
467 /* cgfont and synthItal are used only on OS X 10.3+ */ 482#if defined (NS_IMPL_COCOA)
468#if defined (NS_IMPL_COCOA) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
469 CGFontRef cgfont; 483 CGFontRef cgfont;
470#else /* GNUstep or OS X < 10.3 */ 484#else /* GNUstep */
471 void *cgfont; 485 void *cgfont;
472#endif 486#endif
473#else /* ! OBJC */ 487#else /* ! OBJC */
@@ -749,11 +763,11 @@ extern Lisp_Object ns_cursor_type_to_lisp (int arg);
749extern void ns_set_name_as_filename (struct frame *f); 763extern void ns_set_name_as_filename (struct frame *f);
750extern void ns_set_doc_edited (struct frame *f, Lisp_Object arg); 764extern void ns_set_doc_edited (struct frame *f, Lisp_Object arg);
751 765
752extern int 766extern bool
753ns_defined_color (struct frame *f, 767ns_defined_color (struct frame *f,
754 const char *name, 768 const char *name,
755 XColor *color_def, int alloc, 769 XColor *color_def, bool alloc,
756 char makeIndex); 770 bool makeIndex);
757extern void 771extern void
758ns_query_color (void *col, XColor *color_def, int setPixel); 772ns_query_color (void *col, XColor *color_def, int setPixel);
759 773
@@ -799,8 +813,8 @@ struct image;
799extern void *ns_image_from_XBM (unsigned char *bits, int width, int height); 813extern void *ns_image_from_XBM (unsigned char *bits, int width, int height);
800extern void *ns_image_for_XPM (int width, int height, int depth); 814extern void *ns_image_for_XPM (int width, int height, int depth);
801extern void *ns_image_from_file (Lisp_Object file); 815extern void *ns_image_from_file (Lisp_Object file);
802extern int ns_load_image (struct frame *f, struct image *img, 816extern bool ns_load_image (struct frame *f, struct image *img,
803 Lisp_Object spec_file, Lisp_Object spec_data); 817 Lisp_Object spec_file, Lisp_Object spec_data);
804extern int ns_image_width (void *img); 818extern int ns_image_width (void *img);
805extern int ns_image_height (void *img); 819extern int ns_image_height (void *img);
806extern unsigned long ns_get_pixel (void *img, int x, int y); 820extern unsigned long ns_get_pixel (void *img, int x, int y);
diff --git a/src/nsterm.m b/src/nsterm.m
index 0b26508dbd0..6b739befeeb 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -72,6 +72,11 @@ int term_trace_num = 0;
72#define NSTRACE(x) 72#define NSTRACE(x)
73#endif 73#endif
74 74
75#if defined (NS_IMPL_COCOA) && \
76 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
77#define NEW_STYLE_FS
78#endif
79
75extern NSString *NSMenuDidBeginTrackingNotification; 80extern NSString *NSMenuDidBeginTrackingNotification;
76 81
77/* ========================================================================== 82/* ==========================================================================
@@ -178,7 +183,6 @@ static int ns_window_num = 0;
178static NSRect uRect; 183static NSRect uRect;
179#endif 184#endif
180static BOOL gsaved = NO; 185static BOOL gsaved = NO;
181BOOL ns_in_resize = NO;
182static BOOL ns_fake_keydown = NO; 186static BOOL ns_fake_keydown = NO;
183int ns_tmp_flags; /* FIXME */ 187int ns_tmp_flags; /* FIXME */
184struct nsfont_info *ns_tmp_font; /* FIXME */ 188struct nsfont_info *ns_tmp_font; /* FIXME */
@@ -488,17 +492,6 @@ ns_release_autorelease_pool (void *pool)
488 492
489 ========================================================================== */ 493 ========================================================================== */
490 494
491static NSRect
492ns_resize_handle_rect (NSWindow *window)
493{
494 NSRect r = [window frame];
495 r.origin.x = r.size.width - RESIZE_HANDLE_SIZE;
496 r.origin.y = 0;
497 r.size.width = r.size.height = RESIZE_HANDLE_SIZE;
498 return r;
499}
500
501
502// 495//
503// Window constraining 496// Window constraining
504// ------------------- 497// -------------------
@@ -576,12 +569,9 @@ ns_menu_bar_should_be_hidden (void)
576static void 569static void
577ns_update_auto_hide_menu_bar (void) 570ns_update_auto_hide_menu_bar (void)
578{ 571{
579#ifndef MAC_OS_X_VERSION_10_6
580#define MAC_OS_X_VERSION_10_6 1060
581#endif
582#ifdef NS_IMPL_COCOA 572#ifdef NS_IMPL_COCOA
583#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 573#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
584 BLOCK_INPUT; 574 block_input ();
585 575
586 NSTRACE (ns_update_auto_hide_menu_bar); 576 NSTRACE (ns_update_auto_hide_menu_bar);
587 577
@@ -612,7 +602,7 @@ ns_update_auto_hide_menu_bar (void)
612 } 602 }
613 } 603 }
614 604
615 UNBLOCK_INPUT; 605 unblock_input ();
616#endif 606#endif
617#endif 607#endif
618} 608}
@@ -662,7 +652,7 @@ ns_update_window_begin (struct window *w)
662 updated_window = w; 652 updated_window = w;
663 set_output_cursor (&w->cursor); 653 set_output_cursor (&w->cursor);
664 654
665 BLOCK_INPUT; 655 block_input ();
666 656
667 if (f == hlinfo->mouse_face_mouse_frame) 657 if (f == hlinfo->mouse_face_mouse_frame)
668 { 658 {
@@ -677,7 +667,7 @@ ns_update_window_begin (struct window *w)
677 /* (further code for mouse faces ifdef'd out in other terms elided) */ 667 /* (further code for mouse faces ifdef'd out in other terms elided) */
678 } 668 }
679 669
680 UNBLOCK_INPUT; 670 unblock_input ();
681} 671}
682 672
683 673
@@ -694,7 +684,7 @@ ns_update_window_end (struct window *w, int cursor_on_p,
694 /* note: this fn is nearly identical in all terms */ 684 /* note: this fn is nearly identical in all terms */
695 if (!w->pseudo_window_p) 685 if (!w->pseudo_window_p)
696 { 686 {
697 BLOCK_INPUT; 687 block_input ();
698 688
699 if (cursor_on_p) 689 if (cursor_on_p)
700 display_and_set_cursor (w, 1, 690 display_and_set_cursor (w, 1,
@@ -704,7 +694,7 @@ ns_update_window_end (struct window *w, int cursor_on_p,
704 if (draw_window_fringes (w, 1)) 694 if (draw_window_fringes (w, 1))
705 x_draw_vertical_border (w); 695 x_draw_vertical_border (w);
706 696
707 UNBLOCK_INPUT; 697 unblock_input ();
708 } 698 }
709 699
710 /* If a row with mouse-face was overwritten, arrange for 700 /* If a row with mouse-face was overwritten, arrange for
@@ -733,7 +723,7 @@ ns_update_end (struct frame *f)
733/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */ 723/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
734 MOUSE_HL_INFO (f)->mouse_face_defer = 0; 724 MOUSE_HL_INFO (f)->mouse_face_defer = 0;
735 725
736 BLOCK_INPUT; 726 block_input ();
737 727
738#ifdef NS_IMPL_GNUSTEP 728#ifdef NS_IMPL_GNUSTEP
739 /* trigger flush only in the rectangle we tracked as being drawn */ 729 /* trigger flush only in the rectangle we tracked as being drawn */
@@ -745,7 +735,7 @@ ns_update_end (struct frame *f)
745 [view unlockFocus]; 735 [view unlockFocus];
746 [[view window] flushWindow]; 736 [[view window] flushWindow];
747 737
748 UNBLOCK_INPUT; 738 unblock_input ();
749 ns_updating_frame = NULL; 739 ns_updating_frame = NULL;
750 NSTRACE (ns_update_end); 740 NSTRACE (ns_update_end);
751} 741}
@@ -902,7 +892,7 @@ ns_ring_bell (struct frame *f)
902 struct frame *frame = SELECTED_FRAME (); 892 struct frame *frame = SELECTED_FRAME ();
903 NSView *view; 893 NSView *view;
904 894
905 BLOCK_INPUT; 895 block_input ();
906 pool = [[NSAutoreleasePool alloc] init]; 896 pool = [[NSAutoreleasePool alloc] init];
907 897
908 view = FRAME_NS_VIEW (frame); 898 view = FRAME_NS_VIEW (frame);
@@ -929,7 +919,7 @@ ns_ring_bell (struct frame *f)
929 ns_unfocus (frame); 919 ns_unfocus (frame);
930 } 920 }
931 [pool release]; 921 [pool release];
932 UNBLOCK_INPUT; 922 unblock_input ();
933 } 923 }
934 else 924 else
935 { 925 {
@@ -970,13 +960,13 @@ ns_raise_frame (struct frame *f)
970{ 960{
971 NSView *view = FRAME_NS_VIEW (f); 961 NSView *view = FRAME_NS_VIEW (f);
972 check_ns (); 962 check_ns ();
973 BLOCK_INPUT; 963 block_input ();
974 FRAME_SAMPLE_VISIBILITY (f); 964 FRAME_SAMPLE_VISIBILITY (f);
975 if (FRAME_VISIBLE_P (f)) 965 if (FRAME_VISIBLE_P (f))
976 { 966 {
977 [[view window] makeKeyAndOrderFront: NSApp]; 967 [[view window] makeKeyAndOrderFront: NSApp];
978 } 968 }
979 UNBLOCK_INPUT; 969 unblock_input ();
980} 970}
981 971
982 972
@@ -988,9 +978,9 @@ ns_lower_frame (struct frame *f)
988{ 978{
989 NSView *view = FRAME_NS_VIEW (f); 979 NSView *view = FRAME_NS_VIEW (f);
990 check_ns (); 980 check_ns ();
991 BLOCK_INPUT; 981 block_input ();
992 [[view window] orderBack: NSApp]; 982 [[view window] orderBack: NSApp];
993 UNBLOCK_INPUT; 983 unblock_input ();
994} 984}
995 985
996 986
@@ -1063,8 +1053,23 @@ x_make_frame_visible (struct frame *f)
1063 if this ends up the case again, comment this out again. */ 1053 if this ends up the case again, comment this out again. */
1064 if (!FRAME_VISIBLE_P (f)) 1054 if (!FRAME_VISIBLE_P (f))
1065 { 1055 {
1056 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1066 f->async_visible = 1; 1057 f->async_visible = 1;
1067 ns_raise_frame (f); 1058 ns_raise_frame (f);
1059
1060#ifdef NEW_STYLE_FS
1061 /* Making a new frame from a fullscreen frame will make the new frame
1062 fullscreen also. So skip handleFS as this will print an error. */
1063 if (f->want_fullscreen == FULLSCREEN_BOTH
1064 && ([[view window] styleMask] & NSFullScreenWindowMask) != 0)
1065 return;
1066#endif
1067 if (f->want_fullscreen != FULLSCREEN_NONE)
1068 {
1069 block_input ();
1070 [view handleFS];
1071 unblock_input ();
1072 }
1068 } 1073 }
1069} 1074}
1070 1075
@@ -1126,7 +1131,7 @@ x_free_frame_resources (struct frame *f)
1126 1131
1127 [(EmacsView *)view setWindowClosing: YES]; /* may not have been informed */ 1132 [(EmacsView *)view setWindowClosing: YES]; /* may not have been informed */
1128 1133
1129 BLOCK_INPUT; 1134 block_input ();
1130 1135
1131 free_frame_menubar (f); 1136 free_frame_menubar (f);
1132 1137
@@ -1154,7 +1159,7 @@ x_free_frame_resources (struct frame *f)
1154 1159
1155 xfree (f->output_data.ns); 1160 xfree (f->output_data.ns);
1156 1161
1157 UNBLOCK_INPUT; 1162 unblock_input ();
1158} 1163}
1159 1164
1160void 1165void
@@ -1183,7 +1188,7 @@ x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
1183 1188
1184 NSTRACE (x_set_offset); 1189 NSTRACE (x_set_offset);
1185 1190
1186 BLOCK_INPUT; 1191 block_input ();
1187 1192
1188 f->left_pos = xoff; 1193 f->left_pos = xoff;
1189 f->top_pos = yoff; 1194 f->top_pos = yoff;
@@ -1215,7 +1220,7 @@ x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
1215 f->size_hint_flags &= ~(XNegative|YNegative); 1220 f->size_hint_flags &= ~(XNegative|YNegative);
1216 } 1221 }
1217 1222
1218 UNBLOCK_INPUT; 1223 unblock_input ();
1219} 1224}
1220 1225
1221 1226
@@ -1240,7 +1245,7 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
1240 1245
1241/*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */ 1246/*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1242 1247
1243 BLOCK_INPUT; 1248 block_input ();
1244 1249
1245 check_frame_size (f, &rows, &cols); 1250 check_frame_size (f, &rows, &cols);
1246 1251
@@ -1302,10 +1307,33 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
1302 mark_window_cursors_off (XWINDOW (f->root_window)); 1307 mark_window_cursors_off (XWINDOW (f->root_window));
1303 cancel_mouse_face (f); 1308 cancel_mouse_face (f);
1304 1309
1305 UNBLOCK_INPUT; 1310 unblock_input ();
1306} 1311}
1307 1312
1308 1313
1314static void
1315ns_fullscreen_hook (FRAME_PTR f)
1316{
1317 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1318
1319 if (! f->async_visible) return;
1320#ifndef NEW_STYLE_FS
1321 if (f->want_fullscreen == FULLSCREEN_BOTH)
1322 {
1323 /* Old style fs don't initiate correctly if created from
1324 init/default-frame alist, so use a timer (not nice...).
1325 */
1326 [NSTimer scheduledTimerWithTimeInterval: 0.5 target: view
1327 selector: @selector (handleFS)
1328 userInfo: nil repeats: NO];
1329 return;
1330 }
1331#endif
1332
1333 block_input ();
1334 [view handleFS];
1335 unblock_input ();
1336}
1309 1337
1310/* ========================================================================== 1338/* ==========================================================================
1311 1339
@@ -1414,7 +1442,7 @@ ns_get_color (const char *name, NSColor **col)
1414 NSString *nsname = [NSString stringWithUTF8String: name]; 1442 NSString *nsname = [NSString stringWithUTF8String: name];
1415 1443
1416/*fprintf (stderr, "ns_get_color: '%s'\n", name); */ 1444/*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1417 BLOCK_INPUT; 1445 block_input ();
1418 1446
1419 if ([nsname isEqualToString: @"ns_selection_color"]) 1447 if ([nsname isEqualToString: @"ns_selection_color"])
1420 { 1448 {
@@ -1461,7 +1489,7 @@ ns_get_color (const char *name, NSColor **col)
1461 if (r >= 0.0) 1489 if (r >= 0.0)
1462 { 1490 {
1463 *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0]; 1491 *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0];
1464 UNBLOCK_INPUT; 1492 unblock_input ();
1465 return 0; 1493 return 0;
1466 } 1494 }
1467 1495
@@ -1493,7 +1521,7 @@ ns_get_color (const char *name, NSColor **col)
1493 1521
1494 if (new) 1522 if (new)
1495 *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; 1523 *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
1496 UNBLOCK_INPUT; 1524 unblock_input ();
1497 return new ? 0 : 1; 1525 return new ? 0 : 1;
1498} 1526}
1499 1527
@@ -1524,12 +1552,12 @@ ns_color_to_lisp (NSColor *col)
1524 const char *str; 1552 const char *str;
1525 NSTRACE (ns_color_to_lisp); 1553 NSTRACE (ns_color_to_lisp);
1526 1554
1527 BLOCK_INPUT; 1555 block_input ();
1528 if ([[col colorSpaceName] isEqualToString: NSNamedColorSpace]) 1556 if ([[col colorSpaceName] isEqualToString: NSNamedColorSpace])
1529 1557
1530 if ((str =[[col colorNameComponent] UTF8String])) 1558 if ((str =[[col colorNameComponent] UTF8String]))
1531 { 1559 {
1532 UNBLOCK_INPUT; 1560 unblock_input ();
1533 return build_string ((char *)str); 1561 return build_string ((char *)str);
1534 } 1562 }
1535 1563
@@ -1541,14 +1569,14 @@ ns_color_to_lisp (NSColor *col)
1541 getWhite: &gray alpha: &alpha]; 1569 getWhite: &gray alpha: &alpha];
1542 snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx", 1570 snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx",
1543 lrint (gray * 0xff), lrint (gray * 0xff), lrint (gray * 0xff)); 1571 lrint (gray * 0xff), lrint (gray * 0xff), lrint (gray * 0xff));
1544 UNBLOCK_INPUT; 1572 unblock_input ();
1545 return build_string (buf); 1573 return build_string (buf);
1546 } 1574 }
1547 1575
1548 snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx", 1576 snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx",
1549 lrint (red*0xff), lrint (green*0xff), lrint (blue*0xff)); 1577 lrint (red*0xff), lrint (green*0xff), lrint (blue*0xff));
1550 1578
1551 UNBLOCK_INPUT; 1579 unblock_input ();
1552 return build_string (buf); 1580 return build_string (buf);
1553} 1581}
1554 1582
@@ -1575,33 +1603,33 @@ ns_query_color(void *col, XColor *color_def, int setPixel)
1575} 1603}
1576 1604
1577 1605
1578int 1606bool
1579ns_defined_color (struct frame *f, 1607ns_defined_color (struct frame *f,
1580 const char *name, 1608 const char *name,
1581 XColor *color_def, 1609 XColor *color_def,
1582 int alloc, 1610 bool alloc,
1583 char makeIndex) 1611 bool makeIndex)
1584/* -------------------------------------------------------------------------- 1612/* --------------------------------------------------------------------------
1585 Return 1 if named color found, and set color_def rgb accordingly. 1613 Return true if named color found, and set color_def rgb accordingly.
1586 If makeIndex and alloc are nonzero put the color in the color_table, 1614 If makeIndex and alloc are nonzero put the color in the color_table,
1587 and set color_def pixel to the resulting index. 1615 and set color_def pixel to the resulting index.
1588 If makeIndex is zero, set color_def pixel to ARGB. 1616 If makeIndex is zero, set color_def pixel to ARGB.
1589 Return 0 if not found 1617 Return false if not found
1590 -------------------------------------------------------------------------- */ 1618 -------------------------------------------------------------------------- */
1591{ 1619{
1592 NSColor *col; 1620 NSColor *col;
1593 NSTRACE (ns_defined_color); 1621 NSTRACE (ns_defined_color);
1594 1622
1595 BLOCK_INPUT; 1623 block_input ();
1596 if (ns_get_color (name, &col) != 0) /* Color not found */ 1624 if (ns_get_color (name, &col) != 0) /* Color not found */
1597 { 1625 {
1598 UNBLOCK_INPUT; 1626 unblock_input ();
1599 return 0; 1627 return 0;
1600 } 1628 }
1601 if (makeIndex && alloc) 1629 if (makeIndex && alloc)
1602 color_def->pixel = ns_index_color (col, f); 1630 color_def->pixel = ns_index_color (col, f);
1603 ns_query_color (col, color_def, !makeIndex); 1631 ns_query_color (col, color_def, !makeIndex);
1604 UNBLOCK_INPUT; 1632 unblock_input ();
1605 return 1; 1633 return 1;
1606} 1634}
1607 1635
@@ -1767,7 +1795,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
1767 1795
1768 dpyinfo = FRAME_NS_DISPLAY_INFO (*fp); 1796 dpyinfo = FRAME_NS_DISPLAY_INFO (*fp);
1769 1797
1770 BLOCK_INPUT; 1798 block_input ();
1771 1799
1772 if (last_mouse_scroll_bar != nil && insist == 0) 1800 if (last_mouse_scroll_bar != nil && insist == 0)
1773 { 1801 {
@@ -1812,7 +1840,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
1812 } 1840 }
1813 } 1841 }
1814 1842
1815 UNBLOCK_INPUT; 1843 unblock_input ();
1816} 1844}
1817 1845
1818 1846
@@ -1832,7 +1860,7 @@ ns_frame_up_to_date (struct frame *f)
1832 if ((hlinfo->mouse_face_deferred_gc || f ==hlinfo->mouse_face_mouse_frame) 1860 if ((hlinfo->mouse_face_deferred_gc || f ==hlinfo->mouse_face_mouse_frame)
1833 /*&& hlinfo->mouse_face_mouse_frame*/) 1861 /*&& hlinfo->mouse_face_mouse_frame*/)
1834 { 1862 {
1835 BLOCK_INPUT; 1863 block_input ();
1836 ns_update_begin(f); 1864 ns_update_begin(f);
1837 if (hlinfo->mouse_face_mouse_frame) 1865 if (hlinfo->mouse_face_mouse_frame)
1838 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, 1866 note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
@@ -1840,7 +1868,7 @@ ns_frame_up_to_date (struct frame *f)
1840 hlinfo->mouse_face_mouse_y); 1868 hlinfo->mouse_face_mouse_y);
1841 hlinfo->mouse_face_deferred_gc = 0; 1869 hlinfo->mouse_face_deferred_gc = 0;
1842 ns_update_end(f); 1870 ns_update_end(f);
1843 UNBLOCK_INPUT; 1871 unblock_input ();
1844 } 1872 }
1845 } 1873 }
1846} 1874}
@@ -1940,8 +1968,6 @@ ns_clear_frame (struct frame *f)
1940 NSRect r; 1968 NSRect r;
1941 1969
1942 NSTRACE (ns_clear_frame); 1970 NSTRACE (ns_clear_frame);
1943 if (ns_in_resize)
1944 return;
1945 1971
1946 /* comes on initial frame because we have 1972 /* comes on initial frame because we have
1947 after-make-frame-functions = select-frame */ 1973 after-make-frame-functions = select-frame */
@@ -1955,19 +1981,15 @@ ns_clear_frame (struct frame *f)
1955 1981
1956 r = [view bounds]; 1982 r = [view bounds];
1957 1983
1958 BLOCK_INPUT; 1984 block_input ();
1959 ns_focus (f, &r, 1); 1985 ns_focus (f, &r, 1);
1960 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (FRAME_DEFAULT_FACE (f)), f) set]; 1986 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (FRAME_DEFAULT_FACE (f)), f) set];
1961 NSRectFill (r); 1987 NSRectFill (r);
1962 ns_unfocus (f); 1988 ns_unfocus (f);
1963 1989
1964#ifdef NS_IMPL_COCOA
1965 [[view window] display]; /* redraw resize handle */
1966#endif
1967
1968 /* as of 2006/11 or so this is now needed */ 1990 /* as of 2006/11 or so this is now needed */
1969 ns_redraw_scroll_bars (f); 1991 ns_redraw_scroll_bars (f);
1970 UNBLOCK_INPUT; 1992 unblock_input ();
1971} 1993}
1972 1994
1973 1995
@@ -1990,35 +2012,8 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height)
1990 ns_focus (f, &r, 1); 2012 ns_focus (f, &r, 1);
1991 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set]; 2013 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
1992 2014
1993#ifdef NS_IMPL_COCOA
1994 {
1995 /* clip out the resize handle */
1996 NSWindow *window = [FRAME_NS_VIEW (f) window];
1997 NSRect ir
1998 = [view convertRect: ns_resize_handle_rect (window) fromView: nil];
1999
2000 ir = NSIntersectionRect (r, ir);
2001 if (NSIsEmptyRect (ir))
2002 {
2003#endif
2004
2005 NSRectFill (r); 2015 NSRectFill (r);
2006 2016
2007#ifdef NS_IMPL_COCOA
2008 }
2009 else
2010 {
2011 NSRect r1 = r, r2 = r; /* upper and lower non-intersecting */
2012 r1.size.height -= ir.size.height;
2013 r2.origin.y += r1.size.height;
2014 r2.size.width -= ir.size.width;
2015 r2.size.height = ir.size.height;
2016 NSRectFill (r1);
2017 NSRectFill (r2);
2018 }
2019 }
2020#endif
2021
2022 ns_unfocus (f); 2017 ns_unfocus (f);
2023 return; 2018 return;
2024} 2019}
@@ -2068,7 +2063,7 @@ ns_scroll_run (struct window *w, struct run *run)
2068 if (height == 0) 2063 if (height == 0)
2069 return; 2064 return;
2070 2065
2071 BLOCK_INPUT; 2066 block_input ();
2072 2067
2073 updated_window = w; 2068 updated_window = w;
2074 x_clear_cursor (w); 2069 x_clear_cursor (w);
@@ -2083,7 +2078,7 @@ ns_scroll_run (struct window *w, struct run *run)
2083 ns_unfocus (f); 2078 ns_unfocus (f);
2084 } 2079 }
2085 2080
2086 UNBLOCK_INPUT; 2081 unblock_input ();
2087} 2082}
2088 2083
2089 2084
@@ -2117,12 +2112,12 @@ ns_after_update_window_line (struct glyph_row *desired_row)
2117 { 2112 {
2118 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); 2113 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
2119 2114
2120 BLOCK_INPUT; 2115 block_input ();
2121 ns_clear_frame_area (f, 0, y, width, height); 2116 ns_clear_frame_area (f, 0, y, width, height);
2122 ns_clear_frame_area (f, 2117 ns_clear_frame_area (f,
2123 FRAME_PIXEL_WIDTH (f) - width, 2118 FRAME_PIXEL_WIDTH (f) - width,
2124 y, width, height); 2119 y, width, height);
2125 UNBLOCK_INPUT; 2120 unblock_input ();
2126 } 2121 }
2127} 2122}
2128 2123
@@ -2155,7 +2150,7 @@ ns_shift_glyphs_for_insert (struct frame *f,
2155 ========================================================================== */ 2150 ========================================================================== */
2156 2151
2157 2152
2158static inline void 2153static void
2159ns_compute_glyph_string_overhangs (struct glyph_string *s) 2154ns_compute_glyph_string_overhangs (struct glyph_string *s)
2160/* -------------------------------------------------------------------------- 2155/* --------------------------------------------------------------------------
2161 External (RIF); compute left/right overhang of whole string and set in s 2156 External (RIF); compute left/right overhang of whole string and set in s
@@ -2489,12 +2484,12 @@ show_hourglass (struct atimer *timer)
2489 if (hourglass_shown_p) 2484 if (hourglass_shown_p)
2490 return; 2485 return;
2491 2486
2492 BLOCK_INPUT; 2487 block_input ();
2493 2488
2494 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */ 2489 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2495 2490
2496 hourglass_shown_p = 1; 2491 hourglass_shown_p = 1;
2497 UNBLOCK_INPUT; 2492 unblock_input ();
2498} 2493}
2499 2494
2500 2495
@@ -2504,12 +2499,12 @@ hide_hourglass (void)
2504 if (!hourglass_shown_p) 2499 if (!hourglass_shown_p)
2505 return; 2500 return;
2506 2501
2507 BLOCK_INPUT; 2502 block_input ();
2508 2503
2509 /* TODO: remove NSProgressIndicator from all frames */ 2504 /* TODO: remove NSProgressIndicator from all frames */
2510 2505
2511 hourglass_shown_p = 0; 2506 hourglass_shown_p = 0;
2512 UNBLOCK_INPUT; 2507 unblock_input ();
2513} 2508}
2514 2509
2515 2510
@@ -2979,8 +2974,11 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2979 if (img != nil) 2974 if (img != nil)
2980 { 2975 {
2981#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 2976#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2982 [img drawInRect: br 2977 NSRect dr = NSMakeRect (x, y, s->slice.width, s->slice.height);
2983 fromRect: NSZeroRect 2978 NSRect ir = NSMakeRect (s->slice.x, s->slice.y,
2979 s->slice.width, s->slice.height);
2980 [img drawInRect: dr
2981 fromRect: ir
2984 operation: NSCompositeSourceOver 2982 operation: NSCompositeSourceOver
2985 fraction: 1.0 2983 fraction: 1.0
2986 respectFlipped: YES 2984 respectFlipped: YES
@@ -3336,8 +3334,7 @@ ns_send_appdefined (int value)
3336} 3334}
3337 3335
3338static int 3336static int
3339ns_read_socket (struct terminal *terminal, int expected, 3337ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
3340 struct input_event *hold_quit)
3341/* -------------------------------------------------------------------------- 3338/* --------------------------------------------------------------------------
3342 External (hook): Post an event to ourself and keep reading events until 3339 External (hook): Post an event to ourself and keep reading events until
3343 we read it back again. In effect process all events which were waiting. 3340 we read it back again. In effect process all events which were waiting.
@@ -3352,17 +3349,7 @@ ns_read_socket (struct terminal *terminal, int expected,
3352 if ([NSApp modalWindow] != nil) 3349 if ([NSApp modalWindow] != nil)
3353 return -1; 3350 return -1;
3354 3351
3355 if (interrupt_input_blocked) 3352 block_input ();
3356 {
3357 interrupt_input_pending = 1;
3358 pending_signals = 1;
3359 return -1;
3360 }
3361
3362 interrupt_input_pending = 0;
3363 pending_signals = pending_atimers;
3364
3365 BLOCK_INPUT;
3366 n_emacs_events_pending = 0; 3353 n_emacs_events_pending = 0;
3367 EVENT_INIT (ev); 3354 EVENT_INIT (ev);
3368 emacs_event = &ev; 3355 emacs_event = &ev;
@@ -3407,7 +3394,7 @@ ns_read_socket (struct terminal *terminal, int expected,
3407 nevents = n_emacs_events_pending; 3394 nevents = n_emacs_events_pending;
3408 n_emacs_events_pending = 0; 3395 n_emacs_events_pending = 0;
3409 emacs_event = q_event_ptr = NULL; 3396 emacs_event = q_event_ptr = NULL;
3410 UNBLOCK_INPUT; 3397 unblock_input ();
3411 3398
3412 return nevents; 3399 return nevents;
3413} 3400}
@@ -3487,7 +3474,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3487 } 3474 }
3488 3475
3489 EVENT_INIT (event); 3476 EVENT_INIT (event);
3490 BLOCK_INPUT; 3477 block_input ();
3491 emacs_event = &event; 3478 emacs_event = &event;
3492 if (++apploopnr != 1) 3479 if (++apploopnr != 1)
3493 { 3480 {
@@ -3501,7 +3488,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3501 c = 's'; 3488 c = 's';
3502 write (selfds[1], &c, 1); 3489 write (selfds[1], &c, 1);
3503 } 3490 }
3504 UNBLOCK_INPUT; 3491 unblock_input ();
3505 3492
3506 ev = last_appdefined_event; 3493 ev = last_appdefined_event;
3507 3494
@@ -3613,7 +3600,7 @@ ns_set_vertical_scroll_bar (struct window *window,
3613 || WINDOW_RIGHT_MARGIN_COLS (window) == 0)); 3600 || WINDOW_RIGHT_MARGIN_COLS (window) == 0));
3614 3601
3615 XSETWINDOW (win, window); 3602 XSETWINDOW (win, window);
3616 BLOCK_INPUT; 3603 block_input ();
3617 3604
3618 /* we want at least 5 lines to display a scrollbar */ 3605 /* we want at least 5 lines to display a scrollbar */
3619 if (WINDOW_TOTAL_LINES (window) < 5) 3606 if (WINDOW_TOTAL_LINES (window) < 5)
@@ -3625,7 +3612,7 @@ ns_set_vertical_scroll_bar (struct window *window,
3625 wset_vertical_scroll_bar (window, Qnil); 3612 wset_vertical_scroll_bar (window, Qnil);
3626 } 3613 }
3627 ns_clear_frame_area (f, sb_left, top, width, height); 3614 ns_clear_frame_area (f, sb_left, top, width, height);
3628 UNBLOCK_INPUT; 3615 unblock_input ();
3629 return; 3616 return;
3630 } 3617 }
3631 3618
@@ -3657,7 +3644,7 @@ ns_set_vertical_scroll_bar (struct window *window,
3657 } 3644 }
3658 3645
3659 [bar setPosition: position portion: portion whole: whole]; 3646 [bar setPosition: position portion: portion whole: whole];
3660 UNBLOCK_INPUT; 3647 unblock_input ();
3661} 3648}
3662 3649
3663 3650
@@ -3901,11 +3888,11 @@ ns_delete_terminal (struct terminal *terminal)
3901 if (!terminal->name) 3888 if (!terminal->name)
3902 return; 3889 return;
3903 3890
3904 BLOCK_INPUT; 3891 block_input ();
3905 3892
3906 x_destroy_all_bitmaps (dpyinfo); 3893 x_destroy_all_bitmaps (dpyinfo);
3907 ns_delete_display (dpyinfo); 3894 ns_delete_display (dpyinfo);
3908 UNBLOCK_INPUT; 3895 unblock_input ();
3909} 3896}
3910 3897
3911 3898
@@ -3942,7 +3929,7 @@ ns_create_terminal (struct ns_display_info *dpyinfo)
3942 terminal->frame_rehighlight_hook = ns_frame_rehighlight; 3929 terminal->frame_rehighlight_hook = ns_frame_rehighlight;
3943 terminal->frame_raise_lower_hook = ns_frame_raise_lower; 3930 terminal->frame_raise_lower_hook = ns_frame_raise_lower;
3944 3931
3945 terminal->fullscreen_hook = 0; /* see XTfullscreen_hook */ 3932 terminal->fullscreen_hook = ns_fullscreen_hook;
3946 3933
3947 terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar; 3934 terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar;
3948 terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars; 3935 terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars;
@@ -3983,7 +3970,7 @@ ns_term_init (Lisp_Object display_name)
3983 3970
3984 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */ 3971 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3985 /*GSDebugAllocationActive (YES); */ 3972 /*GSDebugAllocationActive (YES); */
3986 BLOCK_INPUT; 3973 block_input ();
3987 3974
3988 baud_rate = 38400; 3975 baud_rate = 38400;
3989 Fset_input_interrupt_mode (Qnil); 3976 Fset_input_interrupt_mode (Qnil);
@@ -4052,7 +4039,7 @@ ns_term_init (Lisp_Object display_name)
4052 4039
4053 terminal->name = xstrdup (SSDATA (display_name)); 4040 terminal->name = xstrdup (SSDATA (display_name));
4054 4041
4055 UNBLOCK_INPUT; 4042 unblock_input ();
4056 4043
4057 if (!inhibit_x_resources) 4044 if (!inhibit_x_resources)
4058 { 4045 {
@@ -4204,7 +4191,12 @@ ns_term_init (Lisp_Object display_name)
4204 NSColorPboardType, 4191 NSColorPboardType,
4205 NSFontPboardType, nil] retain]; 4192 NSFontPboardType, nil] retain];
4206 4193
4207 4194#ifndef NEW_STYLE_FS
4195 /* If fullscreen is in init/default-frame-alist, focus isn't set
4196 right for fullscreen windows, so set this. */
4197 [NSApp activateIgnoringOtherApps:YES];
4198#endif
4199
4208 [NSApp run]; 4200 [NSApp run];
4209 ns_do_open_file = YES; 4201 ns_do_open_file = YES;
4210 return dpyinfo; 4202 return dpyinfo;
@@ -4276,34 +4268,6 @@ ns_term_shutdown (int sig)
4276 return; 4268 return;
4277 } 4269 }
4278 4270
4279#ifdef NS_IMPL_COCOA
4280 /* pass mouse down in resize handle and subsequent drags directly to
4281 EmacsWindow so we can generate continuous redisplays */
4282 if (ns_in_resize)
4283 {
4284 if (type == NSLeftMouseDragged)
4285 {
4286 [window mouseDragged: theEvent];
4287 return;
4288 }
4289 else if (type == NSLeftMouseUp)
4290 {
4291 [window mouseUp: theEvent];
4292 return;
4293 }
4294 }
4295 else if (type == NSLeftMouseDown)
4296 {
4297 NSRect r = ns_resize_handle_rect (window);
4298 if (NSPointInRect ([theEvent locationInWindow], r))
4299 {
4300 ns_in_resize = YES;
4301 [window mouseDown: theEvent];
4302 return;
4303 }
4304 }
4305#endif
4306
4307 if (type == NSApplicationDefined) 4271 if (type == NSApplicationDefined)
4308 { 4272 {
4309 /* Events posted by ns_send_appdefined interrupt the run loop here. 4273 /* Events posted by ns_send_appdefined interrupt the run loop here.
@@ -4697,6 +4661,8 @@ not_in_argv (NSString *arg)
4697{ 4661{
4698 NSTRACE (EmacsView_dealloc); 4662 NSTRACE (EmacsView_dealloc);
4699 [toolbar release]; 4663 [toolbar release];
4664 if (fs_state == FULLSCREEN_BOTH)
4665 [nonfs_window release];
4700 [super dealloc]; 4666 [super dealloc];
4701} 4667}
4702 4668
@@ -5415,6 +5381,7 @@ not_in_argv (NSString *arg)
5415 SET_FRAME_GARBAGED (emacsframe); 5381 SET_FRAME_GARBAGED (emacsframe);
5416 cancel_mouse_face (emacsframe); 5382 cancel_mouse_face (emacsframe);
5417 [view setFrame: NSMakeRect (0, 0, neww, newh)]; 5383 [view setFrame: NSMakeRect (0, 0, neww, newh)];
5384 [self windowDidMove:nil]; // Update top/left.
5418 } 5385 }
5419} 5386}
5420 5387
@@ -5424,6 +5391,19 @@ not_in_argv (NSString *arg)
5424 NSTRACE (windowWillResize); 5391 NSTRACE (windowWillResize);
5425/*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */ 5392/*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5426 5393
5394 if (fs_state == FULLSCREEN_MAXIMIZED
5395 && (maximized_width != (int)frameSize.width
5396 || maximized_height != (int)frameSize.height))
5397 [self setFSValue: FULLSCREEN_NONE];
5398 else if (fs_state == FULLSCREEN_WIDTH
5399 && maximized_width != (int)frameSize.width)
5400 [self setFSValue: FULLSCREEN_NONE];
5401 else if (fs_state == FULLSCREEN_HEIGHT
5402 && maximized_height != (int)frameSize.height)
5403 [self setFSValue: FULLSCREEN_NONE];
5404 if (fs_state == FULLSCREEN_NONE)
5405 maximized_width = maximized_height = -1;
5406
5427 cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (emacsframe, 5407 cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (emacsframe,
5428#ifdef NS_IMPL_GNUSTEP 5408#ifdef NS_IMPL_GNUSTEP
5429 frameSize.width + 3); 5409 frameSize.width + 3);
@@ -5483,10 +5463,17 @@ not_in_argv (NSString *arg)
5483 5463
5484- (void)windowDidResize: (NSNotification *)notification 5464- (void)windowDidResize: (NSNotification *)notification
5485{ 5465{
5466
5467#if !defined (NEW_STYLE_FS) && ! defined (NS_IMPL_GNUSTEP)
5468 NSWindow *theWindow = [notification object];
5469 /* We can get notification on the non-FS window when in fullscreen mode. */
5470 if ([self window] != theWindow) return;
5471#endif
5472
5486#ifdef NS_IMPL_GNUSTEP 5473#ifdef NS_IMPL_GNUSTEP
5487 NSWindow *theWindow = [notification object]; 5474 NSWindow *theWindow = [notification object];
5488 5475
5489 /* in GNUstep, at least currently, it's possible to get a didResize 5476 /* In GNUstep, at least currently, it's possible to get a didResize
5490 without getting a willResize.. therefore we need to act as if we got 5477 without getting a willResize.. therefore we need to act as if we got
5491 the willResize now */ 5478 the willResize now */
5492 NSSize sz = [theWindow frame].size; 5479 NSSize sz = [theWindow frame].size;
@@ -5504,20 +5491,10 @@ not_in_argv (NSString *arg)
5504 } 5491 }
5505#endif /* NS_IMPL_COCOA */ 5492#endif /* NS_IMPL_COCOA */
5506 5493
5507 /* Avoid loop under GNUstep due to call at beginning of this function.
5508 (x_set_window_size causes a resize which causes
5509 a "windowDidResize" which calls x_set_window_size). */
5510#ifndef NS_IMPL_GNUSTEP
5511 if (cols > 0 && rows > 0) 5494 if (cols > 0 && rows > 0)
5512 { 5495 {
5513 if (ns_in_resize) 5496 [self updateFrameSize: YES];
5514 x_set_window_size (emacsframe, 0, cols, rows);
5515 else
5516 {
5517 [self updateFrameSize: YES];
5518 }
5519 } 5497 }
5520#endif
5521 5498
5522 ns_send_appdefined (-1); 5499 ns_send_appdefined (-1);
5523} 5500}
@@ -5605,6 +5582,10 @@ not_in_argv (NSString *arg)
5605 windowClosing = NO; 5582 windowClosing = NO;
5606 processingCompose = NO; 5583 processingCompose = NO;
5607 scrollbarsNeedingUpdate = 0; 5584 scrollbarsNeedingUpdate = 0;
5585 fs_state = FULLSCREEN_NONE;
5586 fs_before_fs = next_maximized = -1;
5587 maximized_width = maximized_height = -1;
5588 nonfs_window = nil;
5608 5589
5609/*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */ 5590/*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5610 5591
@@ -5629,9 +5610,13 @@ not_in_argv (NSString *arg)
5629 backing: NSBackingStoreBuffered 5610 backing: NSBackingStoreBuffered
5630 defer: YES]; 5611 defer: YES];
5631 5612
5613#ifdef NEW_STYLE_FS
5614 [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
5615#endif
5616
5632 wr = [win frame]; 5617 wr = [win frame];
5633 f->border_width = wr.size.width - r.size.width; 5618 bwidth = f->border_width = wr.size.width - r.size.width;
5634 FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height; 5619 tibar_height = FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height;
5635 5620
5636 [win setAcceptsMouseMovedEvents: YES]; 5621 [win setAcceptsMouseMovedEvents: YES];
5637 [win setDelegate: self]; 5622 [win setDelegate: self];
@@ -5737,27 +5722,50 @@ not_in_argv (NSString *arg)
5737 5722
5738 NSTRACE (windowWillUseStandardFrame); 5723 NSTRACE (windowWillUseStandardFrame);
5739 5724
5740 if (abs (defaultFrame.size.height - result.size.height) 5725 if (fs_before_fs != -1) /* Entering fullscreen */
5741 > FRAME_LINE_HEIGHT (emacsframe)) 5726 {
5727 result = defaultFrame;
5728 }
5729 else if (next_maximized == FULLSCREEN_HEIGHT
5730 || (next_maximized == -1
5731 && abs (defaultFrame.size.height - result.size.height)
5732 > FRAME_LINE_HEIGHT (emacsframe)))
5742 { 5733 {
5743 /* first click */ 5734 /* first click */
5744 ns_userRect = result; 5735 ns_userRect = result;
5745 result.size.height = defaultFrame.size.height; 5736 maximized_height = result.size.height = defaultFrame.size.height;
5737 maximized_width = -1;
5746 result.origin.y = defaultFrame.origin.y; 5738 result.origin.y = defaultFrame.origin.y;
5739 [self setFSValue: FULLSCREEN_HEIGHT];
5740 }
5741 else if (next_maximized == FULLSCREEN_WIDTH)
5742 {
5743 ns_userRect = result;
5744 maximized_width = result.size.width = defaultFrame.size.width;
5745 maximized_height = -1;
5746 result.origin.x = defaultFrame.origin.x;
5747 [self setFSValue: FULLSCREEN_WIDTH];
5748 }
5749 else if (next_maximized == FULLSCREEN_MAXIMIZED
5750 || (next_maximized == -1
5751 && abs (defaultFrame.size.width - result.size.width)
5752 > FRAME_COLUMN_WIDTH (emacsframe)))
5753 {
5754 result = defaultFrame; /* second click */
5755 maximized_width = result.size.width;
5756 maximized_height = result.size.height;
5757 [self setFSValue: FULLSCREEN_MAXIMIZED];
5747 } 5758 }
5748 else 5759 else
5749 { 5760 {
5750 if (abs (defaultFrame.size.width - result.size.width) 5761 /* restore */
5751 > FRAME_COLUMN_WIDTH (emacsframe)) 5762 result = ns_userRect.size.height ? ns_userRect : result;
5752 result = defaultFrame; /* second click */ 5763 ns_userRect = NSMakeRect (0, 0, 0, 0);
5753 else 5764 [self setFSValue: FULLSCREEN_NONE];
5754 { 5765 maximized_width = maximized_width = -1;
5755 /* restore */
5756 result = ns_userRect.size.height ? ns_userRect : result;
5757 ns_userRect = NSMakeRect (0, 0, 0, 0);
5758 }
5759 } 5766 }
5760 5767
5768 if (fs_before_fs == -1) next_maximized = -1;
5761 [self windowWillResize: sender toSize: result.size]; 5769 [self windowWillResize: sender toSize: result.size];
5762 return result; 5770 return result;
5763} 5771}
@@ -5809,6 +5817,211 @@ not_in_argv (NSString *arg)
5809 } 5817 }
5810} 5818}
5811 5819
5820- (void)windowWillEnterFullScreen:(NSNotification *)notification
5821{
5822 fs_before_fs = fs_state;
5823}
5824
5825- (void)windowDidEnterFullScreen:(NSNotification *)notification
5826{
5827 [self setFSValue: FULLSCREEN_BOTH];
5828#ifdef NEW_STYLE_FS
5829 // Fix bad background.
5830 if ([toolbar isVisible])
5831 {
5832 [toolbar setVisible:NO];
5833 [toolbar setVisible:YES];
5834 }
5835#else
5836 [self windowDidBecomeKey:notification];
5837 [nonfs_window orderOut:self];
5838#endif
5839}
5840
5841- (void)windowWillExitFullScreen:(NSNotification *)notification
5842{
5843 if (next_maximized != -1)
5844 fs_before_fs = next_maximized;
5845}
5846
5847- (void)windowDidExitFullScreen:(NSNotification *)notification
5848{
5849 [self setFSValue: fs_before_fs];
5850 fs_before_fs = -1;
5851 if (next_maximized != -1)
5852 [[self window] performZoom:self];
5853}
5854
5855- (void)toggleFullScreen: (id)sender
5856{
5857#ifdef NEW_STYLE_FS
5858 [[self window] toggleFullScreen:sender];
5859#else
5860 NSWindow *w = [self window], *fw;
5861 BOOL onFirstScreen = [[w screen]
5862 isEqual:[[NSScreen screens] objectAtIndex:0]];
5863 struct frame *f = emacsframe;
5864 NSSize sz;
5865 NSRect r, wr = [w frame];
5866 NSColor *col = ns_lookup_indexed_color (NS_FACE_BACKGROUND
5867 (FRAME_DEFAULT_FACE (f)),
5868 f);
5869
5870 sz.width = FRAME_COLUMN_WIDTH (f);
5871 sz.height = FRAME_LINE_HEIGHT (f);
5872
5873 if (fs_state != FULLSCREEN_BOTH)
5874 {
5875 /* Hide dock and menubar if we are on the primary screen. */
5876 if (onFirstScreen)
5877 {
5878#if defined (NS_IMPL_COCOA) && \
5879 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
5880 NSApplicationPresentationOptions options
5881 = NSApplicationPresentationAutoHideDock
5882 | NSApplicationPresentationAutoHideMenuBar;
5883
5884 [NSApp setPresentationOptions: options];
5885#else
5886 [NSMenu setMenuBarVisible:NO];
5887#endif
5888 }
5889
5890 fw = [[EmacsFSWindow alloc]
5891 initWithContentRect:[w contentRectForFrameRect:wr]
5892 styleMask:NSBorderlessWindowMask
5893 backing:NSBackingStoreBuffered
5894 defer:YES
5895 screen:[w screen]];
5896
5897 [fw setContentView:[w contentView]];
5898 [fw setTitle:[w title]];
5899 [fw setDelegate:self];
5900 [fw setAcceptsMouseMovedEvents: YES];
5901 [fw useOptimizedDrawing: YES];
5902 [fw setResizeIncrements: sz];
5903 [fw setBackgroundColor: col];
5904 if ([col alphaComponent] != 1.0)
5905 [fw setOpaque: NO];
5906
5907 f->border_width = 0;
5908 FRAME_NS_TITLEBAR_HEIGHT (f) = 0;
5909 tobar_height = FRAME_TOOLBAR_HEIGHT (f);
5910 FRAME_TOOLBAR_HEIGHT (f) = 0;
5911 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
5912
5913 nonfs_window = w;
5914
5915 [self windowWillEnterFullScreen:nil];
5916 [fw makeKeyAndOrderFront:NSApp];
5917 [fw makeFirstResponder:self];
5918 [w orderOut:self];
5919 r = [fw frameRectForContentRect:[[fw screen] frame]];
5920 [fw setFrame: r display:YES animate:YES];
5921 [self windowDidEnterFullScreen:nil];
5922 [fw display];
5923 }
5924 else
5925 {
5926 fw = w;
5927 w = nonfs_window;
5928 nonfs_window = nil;
5929
5930 if (onFirstScreen)
5931 {
5932#if defined (NS_IMPL_COCOA) && \
5933 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
5934 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
5935#else
5936 [NSMenu setMenuBarVisible:YES];
5937#endif
5938 }
5939
5940 [w setContentView:[fw contentView]];
5941 [w setResizeIncrements: sz];
5942 [w setBackgroundColor: col];
5943 if ([col alphaComponent] != 1.0)
5944 [w setOpaque: NO];
5945
5946 f->border_width = bwidth;
5947 FRAME_NS_TITLEBAR_HEIGHT (f) = tibar_height;
5948 FRAME_TOOLBAR_HEIGHT (f) = tobar_height;
5949 if (tobar_height)
5950 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
5951
5952 [self windowWillExitFullScreen:nil];
5953 [fw setFrame: [w frame] display:YES animate:YES];
5954 [fw close];
5955 [w makeKeyAndOrderFront:NSApp];
5956 [self windowDidExitFullScreen:nil];
5957 }
5958#endif
5959}
5960
5961- (void)handleFS
5962{
5963 if (fs_state != emacsframe->want_fullscreen)
5964 {
5965 if (fs_state == FULLSCREEN_BOTH)
5966 {
5967 [self toggleFullScreen:self];
5968 }
5969
5970 switch (emacsframe->want_fullscreen)
5971 {
5972 case FULLSCREEN_BOTH:
5973 [self toggleFullScreen:self];
5974 break;
5975 case FULLSCREEN_WIDTH:
5976 next_maximized = FULLSCREEN_WIDTH;
5977 if (fs_state != FULLSCREEN_BOTH)
5978 [[self window] performZoom:self];
5979 break;
5980 case FULLSCREEN_HEIGHT:
5981 next_maximized = FULLSCREEN_HEIGHT;
5982 if (fs_state != FULLSCREEN_BOTH)
5983 [[self window] performZoom:self];
5984 break;
5985 case FULLSCREEN_MAXIMIZED:
5986 next_maximized = FULLSCREEN_MAXIMIZED;
5987 if (fs_state != FULLSCREEN_BOTH)
5988 [[self window] performZoom:self];
5989 break;
5990 case FULLSCREEN_NONE:
5991 if (fs_state != FULLSCREEN_BOTH)
5992 {
5993 next_maximized = FULLSCREEN_NONE;
5994 [[self window] performZoom:self];
5995 }
5996 break;
5997 }
5998
5999 emacsframe->want_fullscreen = FULLSCREEN_NONE;
6000 }
6001
6002}
6003
6004- (void) setFSValue: (int)value
6005{
6006 Lisp_Object lval = Qnil;
6007 switch (value)
6008 {
6009 case FULLSCREEN_BOTH:
6010 lval = Qfullboth;
6011 break;
6012 case FULLSCREEN_WIDTH:
6013 lval = Qfullwidth;
6014 break;
6015 case FULLSCREEN_HEIGHT:
6016 lval = Qfullheight;
6017 break;
6018 case FULLSCREEN_MAXIMIZED:
6019 lval = Qmaximized;
6020 break;
6021 }
6022 store_frame_param (emacsframe, Qfullscreen, lval);
6023 fs_state = value;
6024}
5812 6025
5813- (void)mouseEntered: (NSEvent *)theEvent 6026- (void)mouseEntered: (NSEvent *)theEvent
5814{ 6027{
@@ -5906,7 +6119,7 @@ not_in_argv (NSString *arg)
5906 6119
5907 NSTRACE (drawRect); 6120 NSTRACE (drawRect);
5908 6121
5909 if (!emacsframe || !emacsframe->output_data.ns || ns_in_resize) 6122 if (!emacsframe || !emacsframe->output_data.ns)
5910 return; 6123 return;
5911 6124
5912 ns_clear_frame_area (emacsframe, x, y, width, height); 6125 ns_clear_frame_area (emacsframe, x, y, width, height);
@@ -6243,62 +6456,22 @@ not_in_argv (NSString *arg)
6243 return [super constrainFrameRect:frameRect toScreen:screen]; 6456 return [super constrainFrameRect:frameRect toScreen:screen];
6244} 6457}
6245 6458
6459@end /* EmacsWindow */
6246 6460
6247/* called only on resize clicks by special case in EmacsApp-sendEvent */
6248- (void)mouseDown: (NSEvent *)theEvent
6249{
6250 if (ns_in_resize)
6251 {
6252 NSSize size = [[theEvent window] frame].size;
6253 grabOffset = [theEvent locationInWindow];
6254 grabOffset.x = size.width - grabOffset.x;
6255 }
6256 else
6257 [super mouseDown: theEvent];
6258}
6259 6461
6462@implementation EmacsFSWindow
6260 6463
6261/* stop resizing */ 6464- (BOOL)canBecomeKeyWindow
6262- (void)mouseUp: (NSEvent *)theEvent
6263{ 6465{
6264 if (ns_in_resize) 6466 return YES;
6265 {
6266 struct frame *f = ((EmacsView *)[self delegate])->emacsframe;
6267 ns_in_resize = NO;
6268 ns_set_name_as_filename (f);
6269 [self display];
6270 ns_send_appdefined (-1);
6271 }
6272 else
6273 [super mouseUp: theEvent];
6274} 6467}
6275 6468
6276 6469- (BOOL)canBecomeMainWindow
6277/* send resize events */
6278- (void)mouseDragged: (NSEvent *)theEvent
6279{ 6470{
6280 if (ns_in_resize) 6471 return YES;
6281 {
6282 NSPoint p = [theEvent locationInWindow];
6283 NSSize size, vettedSize, origSize = [self frame].size;
6284
6285 size.width = p.x + grabOffset.x;
6286 size.height = origSize.height - p.y + grabOffset.y;
6287
6288 if (size.width == origSize.width && size.height == origSize.height)
6289 return;
6290
6291 vettedSize = [[self delegate] windowWillResize: self toSize: size];
6292 [[NSNotificationCenter defaultCenter]
6293 postNotificationName: NSWindowDidResizeNotification
6294 object: self];
6295 }
6296 else
6297 [super mouseDragged: theEvent];
6298} 6472}
6299 6473
6300@end /* EmacsWindow */ 6474@end
6301
6302 6475
6303/* ========================================================================== 6476/* ==========================================================================
6304 6477
@@ -6370,13 +6543,13 @@ not_in_argv (NSString *arg)
6370- (void)setFrame: (NSRect)newRect 6543- (void)setFrame: (NSRect)newRect
6371{ 6544{
6372 NSTRACE (EmacsScroller_setFrame); 6545 NSTRACE (EmacsScroller_setFrame);
6373/* BLOCK_INPUT; */ 6546/* block_input (); */
6374 pixel_height = NSHeight (newRect); 6547 pixel_height = NSHeight (newRect);
6375 if (pixel_height == 0) pixel_height = 1; 6548 if (pixel_height == 0) pixel_height = 1;
6376 min_portion = 20 / pixel_height; 6549 min_portion = 20 / pixel_height;
6377 [super setFrame: newRect]; 6550 [super setFrame: newRect];
6378 [self display]; 6551 [self display];
6379/* UNBLOCK_INPUT; */ 6552/* unblock_input (); */
6380} 6553}
6381 6554
6382 6555
@@ -6411,14 +6584,14 @@ not_in_argv (NSString *arg)
6411 if (condemned) 6584 if (condemned)
6412 { 6585 {
6413 EmacsView *view; 6586 EmacsView *view;
6414 BLOCK_INPUT; 6587 block_input ();
6415 /* ensure other scrollbar updates after deletion */ 6588 /* ensure other scrollbar updates after deletion */
6416 view = (EmacsView *)FRAME_NS_VIEW (frame); 6589 view = (EmacsView *)FRAME_NS_VIEW (frame);
6417 if (view != nil) 6590 if (view != nil)
6418 view->scrollbarsNeedingUpdate++; 6591 view->scrollbarsNeedingUpdate++;
6419 [self removeFromSuperview]; 6592 [self removeFromSuperview];
6420 [self release]; 6593 [self release];
6421 UNBLOCK_INPUT; 6594 unblock_input ();
6422 } 6595 }
6423 return self; 6596 return self;
6424} 6597}
@@ -6913,7 +7086,7 @@ allowing it to be used at a lower level for accented character entry.");
6913 ns_function_modifier = Qnone; 7086 ns_function_modifier = Qnone;
6914 7087
6915 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text, 7088 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6916 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above."); 7089 "Non-nil (the default) means to render text antialiased.");
6917 ns_antialias_text = Qt; 7090 ns_antialias_text = Qt;
6918 7091
6919 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit, 7092 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
diff --git a/src/print.c b/src/print.c
index aae13bb6764..49b491faec8 100644
--- a/src/print.c
+++ b/src/print.c
@@ -753,9 +753,9 @@ append to existing target file. */)
753{ 753{
754 if (initial_stderr_stream != NULL) 754 if (initial_stderr_stream != NULL)
755 { 755 {
756 BLOCK_INPUT; 756 block_input ();
757 fclose (stderr); 757 fclose (stderr);
758 UNBLOCK_INPUT; 758 unblock_input ();
759 } 759 }
760 stderr = initial_stderr_stream; 760 stderr = initial_stderr_stream;
761 initial_stderr_stream = NULL; 761 initial_stderr_stream = NULL;
diff --git a/src/process.c b/src/process.c
index 6f48463b85b..c941a196539 100644
--- a/src/process.c
+++ b/src/process.c
@@ -255,11 +255,12 @@ static int keyboard_bit_set (SELECT_TYPE *);
255static void deactivate_process (Lisp_Object); 255static void deactivate_process (Lisp_Object);
256static void status_notify (struct Lisp_Process *); 256static void status_notify (struct Lisp_Process *);
257static int read_process_output (Lisp_Object, int); 257static int read_process_output (Lisp_Object, int);
258static void handle_child_signal (int);
258static void create_pty (Lisp_Object); 259static void create_pty (Lisp_Object);
259 260
260/* If we support a window system, turn on the code to poll periodically 261/* If we support a window system, turn on the code to poll periodically
261 to detect C-g. It isn't actually used when doing interrupt input. */ 262 to detect C-g. It isn't actually used when doing interrupt input. */
262#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS) 263#ifdef HAVE_WINDOW_SYSTEM
263#define POLL_FOR_INPUT 264#define POLL_FOR_INPUT
264#endif 265#endif
265 266
@@ -334,82 +335,82 @@ static struct sockaddr_and_len {
334static int pty_max_bytes; 335static int pty_max_bytes;
335 336
336/* These setters are used only in this file, so they can be private. */ 337/* These setters are used only in this file, so they can be private. */
337static inline void 338static void
338pset_buffer (struct Lisp_Process *p, Lisp_Object val) 339pset_buffer (struct Lisp_Process *p, Lisp_Object val)
339{ 340{
340 p->buffer = val; 341 p->buffer = val;
341} 342}
342static inline void 343static void
343pset_command (struct Lisp_Process *p, Lisp_Object val) 344pset_command (struct Lisp_Process *p, Lisp_Object val)
344{ 345{
345 p->command = val; 346 p->command = val;
346} 347}
347static inline void 348static void
348pset_decode_coding_system (struct Lisp_Process *p, Lisp_Object val) 349pset_decode_coding_system (struct Lisp_Process *p, Lisp_Object val)
349{ 350{
350 p->decode_coding_system = val; 351 p->decode_coding_system = val;
351} 352}
352static inline void 353static void
353pset_decoding_buf (struct Lisp_Process *p, Lisp_Object val) 354pset_decoding_buf (struct Lisp_Process *p, Lisp_Object val)
354{ 355{
355 p->decoding_buf = val; 356 p->decoding_buf = val;
356} 357}
357static inline void 358static void
358pset_encode_coding_system (struct Lisp_Process *p, Lisp_Object val) 359pset_encode_coding_system (struct Lisp_Process *p, Lisp_Object val)
359{ 360{
360 p->encode_coding_system = val; 361 p->encode_coding_system = val;
361} 362}
362static inline void 363static void
363pset_encoding_buf (struct Lisp_Process *p, Lisp_Object val) 364pset_encoding_buf (struct Lisp_Process *p, Lisp_Object val)
364{ 365{
365 p->encoding_buf = val; 366 p->encoding_buf = val;
366} 367}
367static inline void 368static void
368pset_filter (struct Lisp_Process *p, Lisp_Object val) 369pset_filter (struct Lisp_Process *p, Lisp_Object val)
369{ 370{
370 p->filter = val; 371 p->filter = val;
371} 372}
372static inline void 373static void
373pset_log (struct Lisp_Process *p, Lisp_Object val) 374pset_log (struct Lisp_Process *p, Lisp_Object val)
374{ 375{
375 p->log = val; 376 p->log = val;
376} 377}
377static inline void 378static void
378pset_mark (struct Lisp_Process *p, Lisp_Object val) 379pset_mark (struct Lisp_Process *p, Lisp_Object val)
379{ 380{
380 p->mark = val; 381 p->mark = val;
381} 382}
382static inline void 383static void
383pset_name (struct Lisp_Process *p, Lisp_Object val) 384pset_name (struct Lisp_Process *p, Lisp_Object val)
384{ 385{
385 p->name = val; 386 p->name = val;
386} 387}
387static inline void 388static void
388pset_plist (struct Lisp_Process *p, Lisp_Object val) 389pset_plist (struct Lisp_Process *p, Lisp_Object val)
389{ 390{
390 p->plist = val; 391 p->plist = val;
391} 392}
392static inline void 393static void
393pset_sentinel (struct Lisp_Process *p, Lisp_Object val) 394pset_sentinel (struct Lisp_Process *p, Lisp_Object val)
394{ 395{
395 p->sentinel = val; 396 p->sentinel = val;
396} 397}
397static inline void 398static void
398pset_status (struct Lisp_Process *p, Lisp_Object val) 399pset_status (struct Lisp_Process *p, Lisp_Object val)
399{ 400{
400 p->status = val; 401 p->status = val;
401} 402}
402static inline void 403static void
403pset_tty_name (struct Lisp_Process *p, Lisp_Object val) 404pset_tty_name (struct Lisp_Process *p, Lisp_Object val)
404{ 405{
405 p->tty_name = val; 406 p->tty_name = val;
406} 407}
407static inline void 408static void
408pset_type (struct Lisp_Process *p, Lisp_Object val) 409pset_type (struct Lisp_Process *p, Lisp_Object val)
409{ 410{
410 p->type = val; 411 p->type = val;
411} 412}
412static inline void 413static void
413pset_write_queue (struct Lisp_Process *p, Lisp_Object val) 414pset_write_queue (struct Lisp_Process *p, Lisp_Object val)
414{ 415{
415 p->write_queue = val; 416 p->write_queue = val;
@@ -569,7 +570,7 @@ status_message (struct Lisp_Process *p)
569 570
570 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) 571 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
571 { 572 {
572 char *signame; 573 char const *signame;
573 synchronize_system_messages_locale (); 574 synchronize_system_messages_locale ();
574 signame = strsignal (code); 575 signame = strsignal (code);
575 if (signame == 0) 576 if (signame == 0)
@@ -1610,11 +1611,16 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1610 int wait_child_setup[2]; 1611 int wait_child_setup[2];
1611#endif 1612#endif
1612#ifdef SIGCHLD 1613#ifdef SIGCHLD
1613 sigset_t blocked, procmask; 1614 sigset_t blocked;
1614#endif 1615#endif
1615 /* Use volatile to protect variables from being clobbered by vfork. */ 1616 /* Use volatile to protect variables from being clobbered by vfork. */
1616 volatile int forkin, forkout; 1617 volatile int forkin, forkout;
1617 volatile int pty_flag = 0; 1618 volatile int pty_flag = 0;
1619 volatile Lisp_Object lisp_pty_name = Qnil;
1620 volatile Lisp_Object encoded_current_dir;
1621#if HAVE_WORKING_VFORK
1622 char **volatile save_environ;
1623#endif
1618 1624
1619 inchannel = outchannel = -1; 1625 inchannel = outchannel = -1;
1620 1626
@@ -1640,6 +1646,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1640 forkin = forkout = -1; 1646 forkin = forkout = -1;
1641#endif /* not USG, or USG_SUBTTY_WORKS */ 1647#endif /* not USG, or USG_SUBTTY_WORKS */
1642 pty_flag = 1; 1648 pty_flag = 1;
1649 lisp_pty_name = build_string (pty_name);
1643 } 1650 }
1644 else 1651 else
1645#endif /* HAVE_PTYS */ 1652#endif /* HAVE_PTYS */
@@ -1704,14 +1711,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1704 XPROCESS (process)->pty_flag = pty_flag; 1711 XPROCESS (process)->pty_flag = pty_flag;
1705 pset_status (XPROCESS (process), Qrun); 1712 pset_status (XPROCESS (process), Qrun);
1706 1713
1707#ifdef SIGCHLD
1708 /* Delay interrupts until we have a chance to store
1709 the new fork's pid in its process structure */
1710 sigemptyset (&blocked);
1711 sigaddset (&blocked, SIGCHLD);
1712 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
1713#endif
1714
1715 FD_SET (inchannel, &input_wait_mask); 1714 FD_SET (inchannel, &input_wait_mask);
1716 FD_SET (inchannel, &non_keyboard_wait_mask); 1715 FD_SET (inchannel, &non_keyboard_wait_mask);
1717 if (inchannel > max_process_desc) 1716 if (inchannel > max_process_desc)
@@ -1729,89 +1728,99 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1729 error. */ 1728 error. */
1730 setup_process_coding_systems (process); 1729 setup_process_coding_systems (process);
1731 1730
1732 BLOCK_INPUT; 1731 encoded_current_dir = ENCODE_FILE (current_dir);
1733 1732
1734 { 1733 block_input ();
1735 /* child_setup must clobber environ on systems with true vfork. 1734
1736 Protect it from permanent change. */ 1735#ifdef SIGCHLD
1737 char **save_environ = environ; 1736 /* Block SIGCHLD until we have a chance to store the new fork's
1738 volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir); 1737 pid in its process structure. */
1738 sigemptyset (&blocked);
1739 sigaddset (&blocked, SIGCHLD);
1740 pthread_sigmask (SIG_BLOCK, &blocked, 0);
1741#endif
1742
1743#if HAVE_WORKING_VFORK
1744 /* child_setup must clobber environ on systems with true vfork.
1745 Protect it from permanent change. */
1746 save_environ = environ;
1747#endif
1739 1748
1740#ifndef WINDOWSNT 1749#ifndef WINDOWSNT
1741 pid = vfork (); 1750 pid = vfork ();
1742 if (pid == 0) 1751 if (pid == 0)
1743#endif /* not WINDOWSNT */ 1752#endif /* not WINDOWSNT */
1744 { 1753 {
1745 int xforkin = forkin; 1754 int xforkin = forkin;
1746 int xforkout = forkout; 1755 int xforkout = forkout;
1747 1756
1748 /* Make the pty be the controlling terminal of the process. */ 1757 /* Make the pty be the controlling terminal of the process. */
1749#ifdef HAVE_PTYS 1758#ifdef HAVE_PTYS
1750 /* First, disconnect its current controlling terminal. */ 1759 /* First, disconnect its current controlling terminal. */
1751#ifdef HAVE_SETSID 1760#ifdef HAVE_SETSID
1752 /* We tried doing setsid only if pty_flag, but it caused 1761 /* We tried doing setsid only if pty_flag, but it caused
1753 process_set_signal to fail on SGI when using a pipe. */ 1762 process_set_signal to fail on SGI when using a pipe. */
1754 setsid (); 1763 setsid ();
1755 /* Make the pty's terminal the controlling terminal. */ 1764 /* Make the pty's terminal the controlling terminal. */
1756 if (pty_flag && xforkin >= 0) 1765 if (pty_flag && xforkin >= 0)
1757 { 1766 {
1758#ifdef TIOCSCTTY 1767#ifdef TIOCSCTTY
1759 /* We ignore the return value 1768 /* We ignore the return value
1760 because faith@cs.unc.edu says that is necessary on Linux. */ 1769 because faith@cs.unc.edu says that is necessary on Linux. */
1761 ioctl (xforkin, TIOCSCTTY, 0); 1770 ioctl (xforkin, TIOCSCTTY, 0);
1762#endif 1771#endif
1763 } 1772 }
1764#else /* not HAVE_SETSID */ 1773#else /* not HAVE_SETSID */
1765#ifdef USG 1774#ifdef USG
1766 /* It's very important to call setpgrp here and no time 1775 /* It's very important to call setpgrp here and no time
1767 afterwards. Otherwise, we lose our controlling tty which 1776 afterwards. Otherwise, we lose our controlling tty which
1768 is set when we open the pty. */ 1777 is set when we open the pty. */
1769 setpgrp (); 1778 setpgrp ();
1770#endif /* USG */ 1779#endif /* USG */
1771#endif /* not HAVE_SETSID */ 1780#endif /* not HAVE_SETSID */
1772#if defined (LDISC1) 1781#if defined (LDISC1)
1773 if (pty_flag && xforkin >= 0) 1782 if (pty_flag && xforkin >= 0)
1774 { 1783 {
1775 struct termios t; 1784 struct termios t;
1776 tcgetattr (xforkin, &t); 1785 tcgetattr (xforkin, &t);
1777 t.c_lflag = LDISC1; 1786 t.c_lflag = LDISC1;
1778 if (tcsetattr (xforkin, TCSANOW, &t) < 0) 1787 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
1779 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39); 1788 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
1780 } 1789 }
1781#else 1790#else
1782#if defined (NTTYDISC) && defined (TIOCSETD) 1791#if defined (NTTYDISC) && defined (TIOCSETD)
1783 if (pty_flag && xforkin >= 0) 1792 if (pty_flag && xforkin >= 0)
1784 { 1793 {
1785 /* Use new line discipline. */ 1794 /* Use new line discipline. */
1786 int ldisc = NTTYDISC; 1795 int ldisc = NTTYDISC;
1787 ioctl (xforkin, TIOCSETD, &ldisc); 1796 ioctl (xforkin, TIOCSETD, &ldisc);
1788 } 1797 }
1789#endif 1798#endif
1790#endif 1799#endif
1791#ifdef TIOCNOTTY 1800#ifdef TIOCNOTTY
1792 /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you 1801 /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
1793 can do TIOCSPGRP only to the process's controlling tty. */ 1802 can do TIOCSPGRP only to the process's controlling tty. */
1794 if (pty_flag) 1803 if (pty_flag)
1795 { 1804 {
1796 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 1805 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
1797 I can't test it since I don't have 4.3. */ 1806 I can't test it since I don't have 4.3. */
1798 int j = emacs_open ("/dev/tty", O_RDWR, 0); 1807 int j = emacs_open ("/dev/tty", O_RDWR, 0);
1799 if (j >= 0) 1808 if (j >= 0)
1800 { 1809 {
1801 ioctl (j, TIOCNOTTY, 0); 1810 ioctl (j, TIOCNOTTY, 0);
1802 emacs_close (j); 1811 emacs_close (j);
1803 } 1812 }
1804#ifndef USG 1813#ifndef USG
1805 /* In order to get a controlling terminal on some versions 1814 /* In order to get a controlling terminal on some versions
1806 of BSD, it is necessary to put the process in pgrp 0 1815 of BSD, it is necessary to put the process in pgrp 0
1807 before it opens the terminal. */ 1816 before it opens the terminal. */
1808#ifdef HAVE_SETPGID 1817#ifdef HAVE_SETPGID
1809 setpgid (0, 0); 1818 setpgid (0, 0);
1810#else 1819#else
1811 setpgrp (0, 0); 1820 setpgrp (0, 0);
1812#endif 1821#endif
1813#endif 1822#endif
1814 } 1823 }
1815#endif /* TIOCNOTTY */ 1824#endif /* TIOCNOTTY */
1816 1825
1817#if !defined (DONT_REOPEN_PTY) 1826#if !defined (DONT_REOPEN_PTY)
@@ -1823,70 +1832,79 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1823 both HAVE_SETSID and TIOCSCTTY are defined. */ 1832 both HAVE_SETSID and TIOCSCTTY are defined. */
1824 /* Now close the pty (if we had it open) and reopen it. 1833 /* Now close the pty (if we had it open) and reopen it.
1825 This makes the pty the controlling terminal of the subprocess. */ 1834 This makes the pty the controlling terminal of the subprocess. */
1826 if (pty_flag) 1835 if (pty_flag)
1827 { 1836 {
1828 1837
1829 /* I wonder if emacs_close (emacs_open (pty_name, ...)) 1838 /* I wonder if emacs_close (emacs_open (pty_name, ...))
1830 would work? */ 1839 would work? */
1831 if (xforkin >= 0) 1840 if (xforkin >= 0)
1832 emacs_close (xforkin); 1841 emacs_close (xforkin);
1833 xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0); 1842 xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0);
1834 1843
1835 if (xforkin < 0) 1844 if (xforkin < 0)
1836 { 1845 {
1837 emacs_write (1, "Couldn't open the pty terminal ", 31); 1846 emacs_write (1, "Couldn't open the pty terminal ", 31);
1838 emacs_write (1, pty_name, strlen (pty_name)); 1847 emacs_write (1, pty_name, strlen (pty_name));
1839 emacs_write (1, "\n", 1); 1848 emacs_write (1, "\n", 1);
1840 _exit (1); 1849 _exit (1);
1841 } 1850 }
1842 1851
1843 } 1852 }
1844#endif /* not DONT_REOPEN_PTY */ 1853#endif /* not DONT_REOPEN_PTY */
1845 1854
1846#ifdef SETUP_SLAVE_PTY 1855#ifdef SETUP_SLAVE_PTY
1847 if (pty_flag) 1856 if (pty_flag)
1848 { 1857 {
1849 SETUP_SLAVE_PTY; 1858 SETUP_SLAVE_PTY;
1850 } 1859 }
1851#endif /* SETUP_SLAVE_PTY */ 1860#endif /* SETUP_SLAVE_PTY */
1852#ifdef AIX 1861#ifdef AIX
1853 /* On AIX, we've disabled SIGHUP above once we start a child on a pty. 1862 /* On AIX, we've disabled SIGHUP above once we start a child on a pty.
1854 Now reenable it in the child, so it will die when we want it to. */ 1863 Now reenable it in the child, so it will die when we want it to. */
1855 if (pty_flag) 1864 if (pty_flag)
1856 signal (SIGHUP, SIG_DFL); 1865 signal (SIGHUP, SIG_DFL);
1857#endif 1866#endif
1858#endif /* HAVE_PTYS */ 1867#endif /* HAVE_PTYS */
1859 1868
1860 signal (SIGINT, SIG_DFL); 1869 signal (SIGINT, SIG_DFL);
1861 signal (SIGQUIT, SIG_DFL); 1870 signal (SIGQUIT, SIG_DFL);
1862 /* GConf causes us to ignore SIGPIPE, make sure it is restored 1871
1863 in the child. */ 1872 /* Emacs ignores SIGPIPE, but the child should not. */
1864 signal (SIGPIPE, SIG_DFL); 1873 signal (SIGPIPE, SIG_DFL);
1865 1874
1866#ifdef SIGCHLD 1875#ifdef SIGCHLD
1867 /* Stop blocking signals in the child. */ 1876 /* Stop blocking signals in the child. */
1868 pthread_sigmask (SIG_SETMASK, &procmask, 0); 1877 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
1869#endif 1878#endif
1870 1879
1871 if (pty_flag) 1880 if (pty_flag)
1872 child_setup_tty (xforkout); 1881 child_setup_tty (xforkout);
1873#ifdef WINDOWSNT 1882#ifdef WINDOWSNT
1874 pid = child_setup (xforkin, xforkout, xforkout, 1883 pid = child_setup (xforkin, xforkout, xforkout,
1875 new_argv, 1, encoded_current_dir); 1884 new_argv, 1, encoded_current_dir);
1876#else /* not WINDOWSNT */ 1885#else /* not WINDOWSNT */
1877#ifdef FD_CLOEXEC 1886#ifdef FD_CLOEXEC
1878 emacs_close (wait_child_setup[0]); 1887 emacs_close (wait_child_setup[0]);
1879#endif 1888#endif
1880 child_setup (xforkin, xforkout, xforkout, 1889 child_setup (xforkin, xforkout, xforkout,
1881 new_argv, 1, encoded_current_dir); 1890 new_argv, 1, encoded_current_dir);
1882#endif /* not WINDOWSNT */ 1891#endif /* not WINDOWSNT */
1883 } 1892 }
1884 environ = save_environ;
1885 }
1886 1893
1887 UNBLOCK_INPUT; 1894 /* Back in the parent process. */
1895
1896#if HAVE_WORKING_VFORK
1897 environ = save_environ;
1898#endif
1899
1900 XPROCESS (process)->pid = pid;
1901
1902 /* Stop blocking signals in the parent. */
1903#ifdef SIGCHLD
1904 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
1905#endif
1906 unblock_input ();
1888 1907
1889 /* This runs in the Emacs process. */
1890 if (pid < 0) 1908 if (pid < 0)
1891 { 1909 {
1892 if (forkin >= 0) 1910 if (forkin >= 0)
@@ -1897,7 +1915,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1897 else 1915 else
1898 { 1916 {
1899 /* vfork succeeded. */ 1917 /* vfork succeeded. */
1900 XPROCESS (process)->pid = pid;
1901 1918
1902#ifdef WINDOWSNT 1919#ifdef WINDOWSNT
1903 register_child (pid, inchannel); 1920 register_child (pid, inchannel);
@@ -1923,12 +1940,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1923 if (forkin != forkout && forkout >= 0) 1940 if (forkin != forkout && forkout >= 0)
1924 emacs_close (forkout); 1941 emacs_close (forkout);
1925 1942
1926#ifdef HAVE_PTYS 1943 pset_tty_name (XPROCESS (process), lisp_pty_name);
1927 if (pty_flag)
1928 pset_tty_name (XPROCESS (process), build_string (pty_name));
1929 else
1930#endif
1931 pset_tty_name (XPROCESS (process), Qnil);
1932 1944
1933#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) 1945#if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1934 /* Wait for child_setup to complete in case that vfork is 1946 /* Wait for child_setup to complete in case that vfork is
@@ -1945,11 +1957,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1945#endif 1957#endif
1946 } 1958 }
1947 1959
1948#ifdef SIGCHLD
1949 /* Stop blocking signals in the parent. */
1950 pthread_sigmask (SIG_SETMASK, &procmask, 0);
1951#endif
1952
1953 /* Now generate the error if vfork failed. */ 1960 /* Now generate the error if vfork failed. */
1954 if (pid < 0) 1961 if (pid < 0)
1955 report_file_error ("Doing vfork", Qnil); 1962 report_file_error ("Doing vfork", Qnil);
@@ -3402,9 +3409,9 @@ usage: (make-network-process &rest ARGS) */)
3402#ifdef HAVE_GETADDRINFO 3409#ifdef HAVE_GETADDRINFO
3403 if (res != &ai) 3410 if (res != &ai)
3404 { 3411 {
3405 BLOCK_INPUT; 3412 block_input ();
3406 freeaddrinfo (res); 3413 freeaddrinfo (res);
3407 UNBLOCK_INPUT; 3414 unblock_input ();
3408 } 3415 }
3409#endif 3416#endif
3410 3417
@@ -4372,7 +4379,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4372 Otherwise, do pending quit if requested. */ 4379 Otherwise, do pending quit if requested. */
4373 if (read_kbd >= 0) 4380 if (read_kbd >= 0)
4374 QUIT; 4381 QUIT;
4375 else 4382 else if (pending_signals)
4376 process_pending_signals (); 4383 process_pending_signals ();
4377 4384
4378 /* Exit now if the cell we're waiting for became non-nil. */ 4385 /* Exit now if the cell we're waiting for became non-nil. */
@@ -4740,21 +4747,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4740 check_write = 0; 4747 check_write = 0;
4741 } 4748 }
4742 4749
4743#if 0 /* When polling is used, interrupt_input is 0,
4744 so get_input_pending should read the input.
4745 So this should not be needed. */
4746 /* If we are using polling for input,
4747 and we see input available, make it get read now.
4748 Otherwise it might not actually get read for a second.
4749 And on hpux, since we turn off polling in wait_reading_process_output,
4750 it might never get read at all if we don't spend much time
4751 outside of wait_reading_process_output. */
4752 if (read_kbd && interrupt_input
4753 && keyboard_bit_set (&Available)
4754 && input_polling_used ())
4755 kill (getpid (), SIGALRM);
4756#endif
4757
4758 /* Check for keyboard input */ 4750 /* Check for keyboard input */
4759 /* If there is any, return immediately 4751 /* If there is any, return immediately
4760 to give it higher priority than subprocesses */ 4752 to give it higher priority than subprocesses */
@@ -4818,7 +4810,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4818 4810
4819 if (read_kbd && interrupt_input 4811 if (read_kbd && interrupt_input
4820 && keyboard_bit_set (&Available) && ! noninteractive) 4812 && keyboard_bit_set (&Available) && ! noninteractive)
4821 kill (getpid (), SIGIO); 4813 handle_input_available_signal (SIGIO);
4822#endif 4814#endif
4823 4815
4824 if (! wait_proc) 4816 if (! wait_proc)
@@ -4938,7 +4930,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4938 pset_status (p, Qfailed); 4930 pset_status (p, Qfailed);
4939 } 4931 }
4940 else 4932 else
4941 kill (getpid (), SIGCHLD); 4933 handle_child_signal (SIGCHLD);
4942 } 4934 }
4943#endif /* HAVE_PTYS */ 4935#endif /* HAVE_PTYS */
4944 /* If we can detect process termination, don't consider the 4936 /* If we can detect process termination, don't consider the
@@ -5394,25 +5386,6 @@ read_process_output (Lisp_Object proc, register int channel)
5394 5386
5395/* Sending data to subprocess */ 5387/* Sending data to subprocess */
5396 5388
5397static sys_jmp_buf send_process_frame;
5398static Lisp_Object process_sent_to;
5399
5400static _Noreturn void
5401handle_pipe_signal (int sig)
5402{
5403 sigset_t unblocked;
5404 sigemptyset (&unblocked);
5405 sigaddset (&unblocked, SIGPIPE);
5406 pthread_sigmask (SIG_UNBLOCK, &unblocked, 0);
5407 sys_longjmp (send_process_frame, 1);
5408}
5409
5410static void
5411deliver_pipe_signal (int sig)
5412{
5413 handle_on_main_thread (sig, handle_pipe_signal);
5414}
5415
5416/* In send_process, when a write fails temporarily, 5389/* In send_process, when a write fails temporarily,
5417 wait_reading_process_output is called. It may execute user code, 5390 wait_reading_process_output is called. It may execute user code,
5418 e.g. timers, that attempts to write new data to the same process. 5391 e.g. timers, that attempts to write new data to the same process.
@@ -5496,14 +5469,12 @@ write_queue_pop (struct Lisp_Process *p, Lisp_Object *obj,
5496 This function can evaluate Lisp code and can garbage collect. */ 5469 This function can evaluate Lisp code and can garbage collect. */
5497 5470
5498static void 5471static void
5499send_process (volatile Lisp_Object proc, const char *volatile buf, 5472send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5500 volatile ptrdiff_t len, volatile Lisp_Object object) 5473 Lisp_Object object)
5501{ 5474{
5502 /* Use volatile to protect variables from being clobbered by longjmp. */
5503 struct Lisp_Process *p = XPROCESS (proc); 5475 struct Lisp_Process *p = XPROCESS (proc);
5504 ssize_t rv; 5476 ssize_t rv;
5505 struct coding_system *coding; 5477 struct coding_system *coding;
5506 struct sigaction old_sigpipe_action;
5507 5478
5508 if (p->raw_status_new) 5479 if (p->raw_status_new)
5509 update_status (p); 5480 update_status (p);
@@ -5610,145 +5581,126 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5610 pty_max_bytes--; 5581 pty_max_bytes--;
5611 } 5582 }
5612 5583
5613 /* 2000-09-21: Emacs 20.7, sparc-sun-solaris-2.6, GCC 2.95.2, 5584 /* If there is already data in the write_queue, put the new data
5614 CFLAGS="-g -O": The value of the parameter `proc' is clobbered 5585 in the back of queue. Otherwise, ignore it. */
5615 when returning with longjmp despite being declared volatile. */ 5586 if (!NILP (p->write_queue))
5616 if (!sys_setjmp (send_process_frame)) 5587 write_queue_push (p, object, buf, len, 0);
5617 {
5618 p = XPROCESS (proc); /* Repair any setjmp clobbering. */
5619 process_sent_to = proc;
5620 5588
5621 /* If there is already data in the write_queue, put the new data 5589 do /* while !NILP (p->write_queue) */
5622 in the back of queue. Otherwise, ignore it. */ 5590 {
5623 if (!NILP (p->write_queue)) 5591 ptrdiff_t cur_len = -1;
5624 write_queue_push (p, object, buf, len, 0); 5592 const char *cur_buf;
5593 Lisp_Object cur_object;
5625 5594
5626 do /* while !NILP (p->write_queue) */ 5595 /* If write_queue is empty, ignore it. */
5596 if (!write_queue_pop (p, &cur_object, &cur_buf, &cur_len))
5627 { 5597 {
5628 ptrdiff_t cur_len = -1; 5598 cur_len = len;
5629 const char *cur_buf; 5599 cur_buf = buf;
5630 Lisp_Object cur_object; 5600 cur_object = object;
5601 }
5631 5602
5632 /* If write_queue is empty, ignore it. */ 5603 while (cur_len > 0)
5633 if (!write_queue_pop (p, &cur_object, &cur_buf, &cur_len)) 5604 {
5605 /* Send this batch, using one or more write calls. */
5606 ptrdiff_t written = 0;
5607 int outfd = p->outfd;
5608#ifdef DATAGRAM_SOCKETS
5609 if (DATAGRAM_CHAN_P (outfd))
5634 { 5610 {
5635 cur_len = len; 5611 rv = sendto (outfd, cur_buf, cur_len,
5636 cur_buf = buf; 5612 0, datagram_address[outfd].sa,
5637 cur_object = object; 5613 datagram_address[outfd].len);
5614 if (0 <= rv)
5615 written = rv;
5616 else if (errno == EMSGSIZE)
5617 report_file_error ("sending datagram", Fcons (proc, Qnil));
5638 } 5618 }
5639 5619 else
5640 while (cur_len > 0)
5641 {
5642 /* Send this batch, using one or more write calls. */
5643 ptrdiff_t written = 0;
5644 int outfd = p->outfd;
5645 struct sigaction action;
5646 emacs_sigaction_init (&action, deliver_pipe_signal);
5647 sigaction (SIGPIPE, &action, &old_sigpipe_action);
5648#ifdef DATAGRAM_SOCKETS
5649 if (DATAGRAM_CHAN_P (outfd))
5650 {
5651 rv = sendto (outfd, cur_buf, cur_len,
5652 0, datagram_address[outfd].sa,
5653 datagram_address[outfd].len);
5654 if (0 <= rv)
5655 written = rv;
5656 else if (errno == EMSGSIZE)
5657 {
5658 sigaction (SIGPIPE, &old_sigpipe_action, 0);
5659 report_file_error ("sending datagram",
5660 Fcons (proc, Qnil));
5661 }
5662 }
5663 else
5664#endif 5620#endif
5665 { 5621 {
5666#ifdef HAVE_GNUTLS 5622#ifdef HAVE_GNUTLS
5667 if (p->gnutls_p) 5623 if (p->gnutls_p)
5668 written = emacs_gnutls_write (p, cur_buf, cur_len); 5624 written = emacs_gnutls_write (p, cur_buf, cur_len);
5669 else 5625 else
5670#endif 5626#endif
5671 written = emacs_write (outfd, cur_buf, cur_len); 5627 written = emacs_write (outfd, cur_buf, cur_len);
5672 rv = (written ? 0 : -1); 5628 rv = (written ? 0 : -1);
5673#ifdef ADAPTIVE_READ_BUFFERING 5629#ifdef ADAPTIVE_READ_BUFFERING
5674 if (p->read_output_delay > 0 5630 if (p->read_output_delay > 0
5675 && p->adaptive_read_buffering == 1) 5631 && p->adaptive_read_buffering == 1)
5676 { 5632 {
5677 p->read_output_delay = 0; 5633 p->read_output_delay = 0;
5678 process_output_delay_count--; 5634 process_output_delay_count--;
5679 p->read_output_skip = 0; 5635 p->read_output_skip = 0;
5680 }
5681#endif
5682 } 5636 }
5683 sigaction (SIGPIPE, &old_sigpipe_action, 0); 5637#endif
5638 }
5684 5639
5685 if (rv < 0) 5640 if (rv < 0)
5686 { 5641 {
5687 if (0 5642 if (0
5688#ifdef EWOULDBLOCK 5643#ifdef EWOULDBLOCK
5689 || errno == EWOULDBLOCK 5644 || errno == EWOULDBLOCK
5690#endif 5645#endif
5691#ifdef EAGAIN 5646#ifdef EAGAIN
5692 || errno == EAGAIN 5647 || errno == EAGAIN
5693#endif 5648#endif
5694 ) 5649 )
5695 /* Buffer is full. Wait, accepting input; 5650 /* Buffer is full. Wait, accepting input;
5696 that may allow the program 5651 that may allow the program
5697 to finish doing output and read more. */ 5652 to finish doing output and read more. */
5698 { 5653 {
5699#ifdef BROKEN_PTY_READ_AFTER_EAGAIN 5654#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5700 /* A gross hack to work around a bug in FreeBSD. 5655 /* A gross hack to work around a bug in FreeBSD.
5701 In the following sequence, read(2) returns 5656 In the following sequence, read(2) returns
5702 bogus data: 5657 bogus data:
5703 5658
5704 write(2) 1022 bytes 5659 write(2) 1022 bytes
5705 write(2) 954 bytes, get EAGAIN 5660 write(2) 954 bytes, get EAGAIN
5706 read(2) 1024 bytes in process_read_output 5661 read(2) 1024 bytes in process_read_output
5707 read(2) 11 bytes in process_read_output 5662 read(2) 11 bytes in process_read_output
5708 5663
5709 That is, read(2) returns more bytes than have 5664 That is, read(2) returns more bytes than have
5710 ever been written successfully. The 1033 bytes 5665 ever been written successfully. The 1033 bytes
5711 read are the 1022 bytes written successfully 5666 read are the 1022 bytes written successfully
5712 after processing (for example with CRs added if 5667 after processing (for example with CRs added if
5713 the terminal is set up that way which it is 5668 the terminal is set up that way which it is
5714 here). The same bytes will be seen again in a 5669 here). The same bytes will be seen again in a
5715 later read(2), without the CRs. */ 5670 later read(2), without the CRs. */
5716 5671
5717 if (errno == EAGAIN) 5672 if (errno == EAGAIN)
5718 { 5673 {
5719 int flags = FWRITE; 5674 int flags = FWRITE;
5720 ioctl (p->outfd, TIOCFLUSH, &flags); 5675 ioctl (p->outfd, TIOCFLUSH, &flags);
5721 } 5676 }
5722#endif /* BROKEN_PTY_READ_AFTER_EAGAIN */ 5677#endif /* BROKEN_PTY_READ_AFTER_EAGAIN */
5723 5678
5724 /* Put what we should have written in wait_queue. */ 5679 /* Put what we should have written in wait_queue. */
5725 write_queue_push (p, cur_object, cur_buf, cur_len, 1); 5680 write_queue_push (p, cur_object, cur_buf, cur_len, 1);
5726 wait_reading_process_output (0, 20 * 1000 * 1000, 5681 wait_reading_process_output (0, 20 * 1000 * 1000,
5727 0, 0, Qnil, NULL, 0); 5682 0, 0, Qnil, NULL, 0);
5728 /* Reread queue, to see what is left. */ 5683 /* Reread queue, to see what is left. */
5729 break; 5684 break;
5730 }
5731 else
5732 /* This is a real error. */
5733 report_file_error ("writing to process", Fcons (proc, Qnil));
5734 } 5685 }
5735 cur_buf += written; 5686 else if (errno == EPIPE)
5736 cur_len -= written; 5687 {
5688 p->raw_status_new = 0;
5689 pset_status (p, list2 (Qexit, make_number (256)));
5690 p->tick = ++process_tick;
5691 deactivate_process (proc);
5692 error ("process %s no longer connected to pipe; closed it",
5693 SDATA (p->name));
5694 }
5695 else
5696 /* This is a real error. */
5697 report_file_error ("writing to process", Fcons (proc, Qnil));
5737 } 5698 }
5699 cur_buf += written;
5700 cur_len -= written;
5738 } 5701 }
5739 while (!NILP (p->write_queue));
5740 }
5741 else
5742 {
5743 sigaction (SIGPIPE, &old_sigpipe_action, 0);
5744 proc = process_sent_to;
5745 p = XPROCESS (proc);
5746 p->raw_status_new = 0;
5747 pset_status (p, Fcons (Qexit, Fcons (make_number (256), Qnil)));
5748 p->tick = ++process_tick;
5749 deactivate_process (proc);
5750 error ("SIGPIPE raised on process %s; closed it", SDATA (p->name));
5751 } 5702 }
5703 while (!NILP (p->write_queue));
5752} 5704}
5753 5705
5754DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region, 5706DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
@@ -6179,39 +6131,27 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6179#ifdef SIGUSR2 6131#ifdef SIGUSR2
6180 parse_signal ("usr2", SIGUSR2); 6132 parse_signal ("usr2", SIGUSR2);
6181#endif 6133#endif
6182#ifdef SIGTERM
6183 parse_signal ("term", SIGTERM); 6134 parse_signal ("term", SIGTERM);
6184#endif
6185#ifdef SIGHUP 6135#ifdef SIGHUP
6186 parse_signal ("hup", SIGHUP); 6136 parse_signal ("hup", SIGHUP);
6187#endif 6137#endif
6188#ifdef SIGINT
6189 parse_signal ("int", SIGINT); 6138 parse_signal ("int", SIGINT);
6190#endif
6191#ifdef SIGQUIT 6139#ifdef SIGQUIT
6192 parse_signal ("quit", SIGQUIT); 6140 parse_signal ("quit", SIGQUIT);
6193#endif 6141#endif
6194#ifdef SIGILL
6195 parse_signal ("ill", SIGILL); 6142 parse_signal ("ill", SIGILL);
6196#endif
6197#ifdef SIGABRT
6198 parse_signal ("abrt", SIGABRT); 6143 parse_signal ("abrt", SIGABRT);
6199#endif
6200#ifdef SIGEMT 6144#ifdef SIGEMT
6201 parse_signal ("emt", SIGEMT); 6145 parse_signal ("emt", SIGEMT);
6202#endif 6146#endif
6203#ifdef SIGKILL 6147#ifdef SIGKILL
6204 parse_signal ("kill", SIGKILL); 6148 parse_signal ("kill", SIGKILL);
6205#endif 6149#endif
6206#ifdef SIGFPE
6207 parse_signal ("fpe", SIGFPE); 6150 parse_signal ("fpe", SIGFPE);
6208#endif
6209#ifdef SIGBUS 6151#ifdef SIGBUS
6210 parse_signal ("bus", SIGBUS); 6152 parse_signal ("bus", SIGBUS);
6211#endif 6153#endif
6212#ifdef SIGSEGV
6213 parse_signal ("segv", SIGSEGV); 6154 parse_signal ("segv", SIGSEGV);
6214#endif
6215#ifdef SIGSYS 6155#ifdef SIGSYS
6216 parse_signal ("sys", SIGSYS); 6156 parse_signal ("sys", SIGSYS);
6217#endif 6157#endif
@@ -6376,27 +6316,15 @@ process has been transmitted to the serial port. */)
6376 ** Malloc WARNING: This should never call malloc either directly or 6316 ** Malloc WARNING: This should never call malloc either directly or
6377 indirectly; if it does, that is a bug */ 6317 indirectly; if it does, that is a bug */
6378 6318
6379#ifdef SIGCHLD 6319/* Record the changed status of the child process PID with wait status W. */
6380 6320void
6381/* Record one child's changed status. Return true if a child was found. */ 6321record_child_status_change (pid_t pid, int w)
6382static bool
6383record_child_status_change (void)
6384{ 6322{
6323#ifdef SIGCHLD
6385 Lisp_Object proc; 6324 Lisp_Object proc;
6386 struct Lisp_Process *p; 6325 struct Lisp_Process *p;
6387 pid_t pid;
6388 int w;
6389 Lisp_Object tail; 6326 Lisp_Object tail;
6390 6327
6391 do
6392 pid = waitpid (-1, &w, WNOHANG | WUNTRACED);
6393 while (pid < 0 && errno == EINTR);
6394
6395 /* PID == 0 means no processes found, PID == -1 means a real failure.
6396 Either way, we have done all our job. */
6397 if (pid <= 0)
6398 return false;
6399
6400 /* Find the process that signaled us, and record its status. */ 6328 /* Find the process that signaled us, and record its status. */
6401 6329
6402 /* The process can have been deleted by Fdelete_process. */ 6330 /* The process can have been deleted by Fdelete_process. */
@@ -6407,7 +6335,7 @@ record_child_status_change (void)
6407 || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid))) 6335 || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid)))
6408 { 6336 {
6409 XSETCAR (tail, Qnil); 6337 XSETCAR (tail, Qnil);
6410 return true; 6338 return;
6411 } 6339 }
6412 } 6340 }
6413 6341
@@ -6477,10 +6405,11 @@ record_child_status_change (void)
6477 if (input_available_clear_time) 6405 if (input_available_clear_time)
6478 *input_available_clear_time = make_emacs_time (0, 0); 6406 *input_available_clear_time = make_emacs_time (0, 0);
6479 } 6407 }
6480 6408#endif
6481 return true;
6482} 6409}
6483 6410
6411#ifdef SIGCHLD
6412
6484/* On some systems, the SIGCHLD handler must return right away. If 6413/* On some systems, the SIGCHLD handler must return right away. If
6485 any more processes want to signal us, we will get another signal. 6414 any more processes want to signal us, we will get another signal.
6486 Otherwise, loop around to use up all the processes that have 6415 Otherwise, loop around to use up all the processes that have
@@ -6496,14 +6425,29 @@ enum { CAN_HANDLE_MULTIPLE_CHILDREN = 1 };
6496static void 6425static void
6497handle_child_signal (int sig) 6426handle_child_signal (int sig)
6498{ 6427{
6499 while (record_child_status_change () && CAN_HANDLE_MULTIPLE_CHILDREN) 6428 do
6500 continue; 6429 {
6430 pid_t pid;
6431 int status;
6432
6433 do
6434 pid = waitpid (-1, &status, WNOHANG | WUNTRACED);
6435 while (pid < 0 && errno == EINTR);
6436
6437 /* PID == 0 means no processes found, PID == -1 means a real failure.
6438 Either way, we have done all our job. */
6439 if (pid <= 0)
6440 break;
6441
6442 record_child_status_change (pid, status);
6443 }
6444 while (CAN_HANDLE_MULTIPLE_CHILDREN);
6501} 6445}
6502 6446
6503static void 6447static void
6504deliver_child_signal (int sig) 6448deliver_child_signal (int sig)
6505{ 6449{
6506 handle_on_main_thread (sig, handle_child_signal); 6450 deliver_process_signal (sig, handle_child_signal);
6507} 6451}
6508 6452
6509#endif /* SIGCHLD */ 6453#endif /* SIGCHLD */
diff --git a/src/profiler.c b/src/profiler.c
new file mode 100644
index 00000000000..51580710f28
--- /dev/null
+++ b/src/profiler.c
@@ -0,0 +1,546 @@
1/* Profiler implementation.
2
3Copyright (C) 2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#include <config.h>
21#include "lisp.h"
22#include "syssignal.h"
23#include "systime.h"
24
25/* Return A + B, but return the maximum fixnum if the result would overflow.
26 Assume A and B are nonnegative and in fixnum range. */
27
28static EMACS_INT
29saturated_add (EMACS_INT a, EMACS_INT b)
30{
31 return min (a + b, MOST_POSITIVE_FIXNUM);
32}
33
34/* Logs. */
35
36typedef struct Lisp_Hash_Table log_t;
37
38static Lisp_Object
39make_log (int heap_size, int max_stack_depth)
40{
41 /* We use a standard Elisp hash-table object, but we use it in
42 a special way. This is OK as long as the object is not exposed
43 to Elisp, i.e. until it is returned by *-profiler-log, after which
44 it can't be used any more. */
45 Lisp_Object log = make_hash_table (Qequal, make_number (heap_size),
46 make_float (DEFAULT_REHASH_SIZE),
47 make_float (DEFAULT_REHASH_THRESHOLD),
48 Qnil, Qnil, Qnil);
49 struct Lisp_Hash_Table *h = XHASH_TABLE (log);
50
51 /* What is special about our hash-tables is that the keys are pre-filled
52 with the vectors we'll put in them. */
53 int i = ASIZE (h->key_and_value) / 2;
54 while (0 < i)
55 set_hash_key_slot (h, --i,
56 Fmake_vector (make_number (max_stack_depth), Qnil));
57 return log;
58}
59
60/* Evict the least used half of the hash_table.
61
62 When the table is full, we have to evict someone.
63 The easiest and most efficient is to evict the value we're about to add
64 (i.e. once the table is full, stop sampling).
65
66 We could also pick the element with the lowest count and evict it,
67 but finding it is O(N) and for that amount of work we get very
68 little in return: for the next sample, this latest sample will have
69 count==1 and will hence be a prime candidate for eviction :-(
70
71 So instead, we take O(N) time to eliminate more or less half of the
72 entries (the half with the lowest counts). So we get an amortized
73 cost of O(1) and we get O(N) time for a new entry to grow larger
74 than the other least counts before a new round of eviction. */
75
76static EMACS_INT approximate_median (log_t *log,
77 ptrdiff_t start, ptrdiff_t size)
78{
79 eassert (size > 0);
80 if (size < 2)
81 return XINT (HASH_VALUE (log, start));
82 if (size < 3)
83 /* Not an actual median, but better for our application than
84 choosing either of the two numbers. */
85 return ((XINT (HASH_VALUE (log, start))
86 + XINT (HASH_VALUE (log, start + 1)))
87 / 2);
88 else
89 {
90 ptrdiff_t newsize = size / 3;
91 ptrdiff_t start2 = start + newsize;
92 EMACS_INT i1 = approximate_median (log, start, newsize);
93 EMACS_INT i2 = approximate_median (log, start2, newsize);
94 EMACS_INT i3 = approximate_median (log, start2 + newsize,
95 size - 2 * newsize);
96 return (i1 < i2
97 ? (i2 < i3 ? i2 : (i1 < i3 ? i3 : i1))
98 : (i1 < i3 ? i1 : (i2 < i3 ? i3 : i2)));
99 }
100}
101
102static void evict_lower_half (log_t *log)
103{
104 ptrdiff_t size = ASIZE (log->key_and_value) / 2;
105 EMACS_INT median = approximate_median (log, 0, size);
106 ptrdiff_t i;
107
108 for (i = 0; i < size; i++)
109 /* Evict not only values smaller but also values equal to the median,
110 so as to make sure we evict something no matter what. */
111 if (XINT (HASH_VALUE (log, i)) <= median)
112 {
113 Lisp_Object key = HASH_KEY (log, i);
114 { /* FIXME: we could make this more efficient. */
115 Lisp_Object tmp;
116 XSET_HASH_TABLE (tmp, log); /* FIXME: Use make_lisp_ptr. */
117 Fremhash (key, tmp);
118 }
119 eassert (EQ (log->next_free, make_number (i)));
120 {
121 int j;
122 eassert (VECTORP (key));
123 for (j = 0; j < ASIZE (key); j++)
124 ASET (key, j, Qnil);
125 }
126 set_hash_key_slot (log, i, key);
127 }
128}
129
130/* Record the current backtrace in LOG. COUNT is the weight of this
131 current backtrace: interrupt counts for CPU, and the allocation
132 size for memory. */
133
134static void
135record_backtrace (log_t *log, EMACS_INT count)
136{
137 struct backtrace *backlist = backtrace_list;
138 Lisp_Object backtrace;
139 ptrdiff_t index, i = 0;
140 ptrdiff_t asize;
141
142 if (!INTEGERP (log->next_free))
143 /* FIXME: transfer the evicted counts to a special entry rather
144 than dropping them on the floor. */
145 evict_lower_half (log);
146 index = XINT (log->next_free);
147
148 /* Get a "working memory" vector. */
149 backtrace = HASH_KEY (log, index);
150 asize = ASIZE (backtrace);
151
152 /* Copy the backtrace contents into working memory. */
153 for (; i < asize && backlist; i++, backlist = backlist->next)
154 /* FIXME: For closures we should ignore the environment. */
155 ASET (backtrace, i, backlist->function);
156
157 /* Make sure that unused space of working memory is filled with nil. */
158 for (; i < asize; i++)
159 ASET (backtrace, i, Qnil);
160
161 { /* We basically do a `gethash+puthash' here, except that we have to be
162 careful to avoid memory allocation since we're in a signal
163 handler, and we optimize the code to try and avoid computing the
164 hash+lookup twice. See fns.c:Fputhash for reference. */
165 EMACS_UINT hash;
166 ptrdiff_t j = hash_lookup (log, backtrace, &hash);
167 if (j >= 0)
168 {
169 EMACS_INT old_val = XINT (HASH_VALUE (log, j));
170 EMACS_INT new_val = saturated_add (old_val, count);
171 set_hash_value_slot (log, j, make_number (new_val));
172 }
173 else
174 { /* BEWARE! hash_put in general can allocate memory.
175 But currently it only does that if log->next_free is nil. */
176 int j;
177 eassert (!NILP (log->next_free));
178 j = hash_put (log, backtrace, make_number (count), hash);
179 /* Let's make sure we've put `backtrace' right where it
180 already was to start with. */
181 eassert (index == j);
182
183 /* FIXME: If the hash-table is almost full, we should set
184 some global flag so that some Elisp code can offload its
185 data elsewhere, so as to avoid the eviction code.
186 There are 2 ways to do that, AFAICT:
187 - Set a flag checked in QUIT, such that QUIT can then call
188 Fprofiler_cpu_log and stash the full log for later use.
189 - Set a flag check in post-gc-hook, so that Elisp code can call
190 profiler-cpu-log. That gives us more flexibility since that
191 Elisp code can then do all kinds of fun stuff like write
192 the log to disk. Or turn it right away into a call tree.
193 Of course, using Elisp is generally preferable, but it may
194 take longer until we get a chance to run the Elisp code, so
195 there's more risk that the table will get full before we
196 get there. */
197 }
198 }
199}
200
201/* Sampling profiler. */
202
203#ifdef PROFILER_CPU_SUPPORT
204
205/* The profiler timer and whether it was properly initialized, if
206 POSIX timers are available. */
207#ifdef HAVE_ITIMERSPEC
208static timer_t profiler_timer;
209static bool profiler_timer_ok;
210#endif
211
212/* Status of sampling profiler. */
213static enum profiler_cpu_running
214 { NOT_RUNNING, TIMER_SETTIME_RUNNING, SETITIMER_RUNNING }
215 profiler_cpu_running;
216
217/* Hash-table log of CPU profiler. */
218static Lisp_Object cpu_log;
219
220/* Separate counter for the time spent in the GC. */
221static EMACS_INT cpu_gc_count;
222
223/* The current sampling interval in nanoseconds. */
224static EMACS_INT current_sampling_interval;
225
226/* Signal handler for sampling profiler. */
227
228static void
229handle_profiler_signal (int signal)
230{
231 if (backtrace_list && EQ (backtrace_list->function, Qautomatic_gc))
232 /* Special case the time-count inside GC because the hash-table
233 code is not prepared to be used while the GC is running.
234 More specifically it uses ASIZE at many places where it does
235 not expect the ARRAY_MARK_FLAG to be set. We could try and
236 harden the hash-table code, but it doesn't seem worth the
237 effort. */
238 cpu_gc_count = saturated_add (cpu_gc_count, 1);
239 else
240 {
241 Lisp_Object oquit;
242 bool saved_pending_signals;
243 EMACS_INT count = 1;
244#ifdef HAVE_ITIMERSPEC
245 if (profiler_timer_ok)
246 {
247 int overruns = timer_getoverrun (profiler_timer);
248 eassert (0 <= overruns);
249 count += overruns;
250 }
251#endif
252 /* record_backtrace uses hash functions that call Fequal, which
253 uses QUIT, which can call malloc, which can cause disaster in
254 a signal handler. So inhibit QUIT. */
255 oquit = Vinhibit_quit;
256 saved_pending_signals = pending_signals;
257 Vinhibit_quit = Qt;
258 pending_signals = 0;
259
260 eassert (HASH_TABLE_P (cpu_log));
261 record_backtrace (XHASH_TABLE (cpu_log), count);
262
263 Vinhibit_quit = oquit;
264 pending_signals = saved_pending_signals;
265 }
266}
267
268static void
269deliver_profiler_signal (int signal)
270{
271 deliver_process_signal (signal, handle_profiler_signal);
272}
273
274static enum profiler_cpu_running
275setup_cpu_timer (Lisp_Object sampling_interval)
276{
277 struct sigaction action;
278 struct itimerval timer;
279 struct timespec interval;
280 int billion = 1000000000;
281
282 if (! RANGED_INTEGERP (1, sampling_interval,
283 (TYPE_MAXIMUM (time_t) < EMACS_INT_MAX / billion
284 ? ((EMACS_INT) TYPE_MAXIMUM (time_t) * billion
285 + (billion - 1))
286 : EMACS_INT_MAX)))
287 return NOT_RUNNING;
288
289 current_sampling_interval = XINT (sampling_interval);
290 interval = make_emacs_time (current_sampling_interval / billion,
291 current_sampling_interval % billion);
292 emacs_sigaction_init (&action, deliver_profiler_signal);
293 sigaction (SIGPROF, &action, 0);
294
295#ifdef HAVE_ITIMERSPEC
296 if (! profiler_timer_ok)
297 {
298 /* System clocks to try, in decreasing order of desirability. */
299 static clockid_t const system_clock[] = {
300#ifdef CLOCK_THREAD_CPUTIME_ID
301 CLOCK_THREAD_CPUTIME_ID,
302#endif
303#ifdef CLOCK_PROCESS_CPUTIME_ID
304 CLOCK_PROCESS_CPUTIME_ID,
305#endif
306#ifdef CLOCK_MONOTONIC
307 CLOCK_MONOTONIC,
308#endif
309 CLOCK_REALTIME
310 };
311 int i;
312 struct sigevent sigev;
313 sigev.sigev_value.sival_ptr = &profiler_timer;
314 sigev.sigev_signo = SIGPROF;
315 sigev.sigev_notify = SIGEV_SIGNAL;
316
317 for (i = 0; i < sizeof system_clock / sizeof *system_clock; i++)
318 if (timer_create (system_clock[i], &sigev, &profiler_timer) == 0)
319 {
320 profiler_timer_ok = 1;
321 break;
322 }
323 }
324
325 if (profiler_timer_ok)
326 {
327 struct itimerspec ispec;
328 ispec.it_value = ispec.it_interval = interval;
329 if (timer_settime (profiler_timer, 0, &ispec, 0) == 0)
330 return TIMER_SETTIME_RUNNING;
331 }
332#endif
333
334#ifdef HAVE_SETITIMER
335 timer.it_value = timer.it_interval = make_timeval (interval);
336 if (setitimer (ITIMER_PROF, &timer, 0) == 0)
337 return SETITIMER_RUNNING;
338#endif
339
340 return NOT_RUNNING;
341}
342
343DEFUN ("profiler-cpu-start", Fprofiler_cpu_start, Sprofiler_cpu_start,
344 1, 1, 0,
345 doc: /* Start or restart the cpu profiler.
346It takes call-stack samples each SAMPLING-INTERVAL nanoseconds, approximately.
347See also `profiler-log-size' and `profiler-max-stack-depth'. */)
348 (Lisp_Object sampling_interval)
349{
350 if (profiler_cpu_running)
351 error ("CPU profiler is already running");
352
353 if (NILP (cpu_log))
354 {
355 cpu_gc_count = 0;
356 cpu_log = make_log (profiler_log_size,
357 profiler_max_stack_depth);
358 }
359
360 profiler_cpu_running = setup_cpu_timer (sampling_interval);
361 if (! profiler_cpu_running)
362 error ("Invalid sampling interval");
363
364 return Qt;
365}
366
367DEFUN ("profiler-cpu-stop", Fprofiler_cpu_stop, Sprofiler_cpu_stop,
368 0, 0, 0,
369 doc: /* Stop the cpu profiler. The profiler log is not affected.
370Return non-nil if the profiler was running. */)
371 (void)
372{
373 switch (profiler_cpu_running)
374 {
375 case NOT_RUNNING:
376 return Qnil;
377
378#ifdef HAVE_ITIMERSPEC
379 case TIMER_SETTIME_RUNNING:
380 {
381 struct itimerspec disable;
382 memset (&disable, 0, sizeof disable);
383 timer_settime (profiler_timer, 0, &disable, 0);
384 }
385 break;
386#endif
387
388#ifdef HAVE_SETITIMER
389 case SETITIMER_RUNNING:
390 {
391 struct itimerval disable;
392 memset (&disable, 0, sizeof disable);
393 setitimer (ITIMER_PROF, &disable, 0);
394 }
395 break;
396#endif
397 }
398
399 signal (SIGPROF, SIG_IGN);
400 profiler_cpu_running = NOT_RUNNING;
401 return Qt;
402}
403
404DEFUN ("profiler-cpu-running-p",
405 Fprofiler_cpu_running_p, Sprofiler_cpu_running_p,
406 0, 0, 0,
407 doc: /* Return non-nil iff cpu profiler is running. */)
408 (void)
409{
410 return profiler_cpu_running ? Qt : Qnil;
411}
412
413DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log,
414 0, 0, 0,
415 doc: /* Return the current cpu profiler log.
416The log is a hash-table mapping backtraces to counters which represent
417the amount of time spent at those points. Every backtrace is a vector
418of functions, where the last few elements may be nil.
419Before returning, a new log is allocated for future samples. */)
420 (void)
421{
422 Lisp_Object result = cpu_log;
423 /* Here we're making the log visible to Elisp, so it's not safe any
424 more for our use afterwards since we can't rely on its special
425 pre-allocated keys anymore. So we have to allocate a new one. */
426 cpu_log = (profiler_cpu_running
427 ? make_log (profiler_log_size, profiler_max_stack_depth)
428 : Qnil);
429 Fputhash (Fmake_vector (make_number (1), Qautomatic_gc),
430 make_number (cpu_gc_count),
431 result);
432 cpu_gc_count = 0;
433 return result;
434}
435#endif /* PROFILER_CPU_SUPPORT */
436
437/* Memory profiler. */
438
439/* True if memory profiler is running. */
440bool profiler_memory_running;
441
442static Lisp_Object memory_log;
443
444DEFUN ("profiler-memory-start", Fprofiler_memory_start, Sprofiler_memory_start,
445 0, 0, 0,
446 doc: /* Start/restart the memory profiler.
447The memory profiler will take samples of the call-stack whenever a new
448allocation takes place. Note that most small allocations only trigger
449the profiler occasionally.
450See also `profiler-log-size' and `profiler-max-stack-depth'. */)
451 (void)
452{
453 if (profiler_memory_running)
454 error ("Memory profiler is already running");
455
456 if (NILP (memory_log))
457 memory_log = make_log (profiler_log_size,
458 profiler_max_stack_depth);
459
460 profiler_memory_running = true;
461
462 return Qt;
463}
464
465DEFUN ("profiler-memory-stop",
466 Fprofiler_memory_stop, Sprofiler_memory_stop,
467 0, 0, 0,
468 doc: /* Stop the memory profiler. The profiler log is not affected.
469Return non-nil if the profiler was running. */)
470 (void)
471{
472 if (!profiler_memory_running)
473 return Qnil;
474 profiler_memory_running = false;
475 return Qt;
476}
477
478DEFUN ("profiler-memory-running-p",
479 Fprofiler_memory_running_p, Sprofiler_memory_running_p,
480 0, 0, 0,
481 doc: /* Return non-nil if memory profiler is running. */)
482 (void)
483{
484 return profiler_memory_running ? Qt : Qnil;
485}
486
487DEFUN ("profiler-memory-log",
488 Fprofiler_memory_log, Sprofiler_memory_log,
489 0, 0, 0,
490 doc: /* Return the current memory profiler log.
491The log is a hash-table mapping backtraces to counters which represent
492the amount of memory allocated at those points. Every backtrace is a vector
493of functions, where the last few elements may be nil.
494Before returning, a new log is allocated for future samples. */)
495 (void)
496{
497 Lisp_Object result = memory_log;
498 /* Here we're making the log visible to Elisp , so it's not safe any
499 more for our use afterwards since we can't rely on its special
500 pre-allocated keys anymore. So we have to allocate a new one. */
501 memory_log = (profiler_memory_running
502 ? make_log (profiler_log_size, profiler_max_stack_depth)
503 : Qnil);
504 return result;
505}
506
507
508/* Signals and probes. */
509
510/* Record that the current backtrace allocated SIZE bytes. */
511void
512malloc_probe (size_t size)
513{
514 eassert (HASH_TABLE_P (memory_log));
515 record_backtrace (XHASH_TABLE (memory_log), min (size, MOST_POSITIVE_FIXNUM));
516}
517
518void
519syms_of_profiler (void)
520{
521 DEFVAR_INT ("profiler-max-stack-depth", profiler_max_stack_depth,
522 doc: /* Number of elements from the call-stack recorded in the log. */);
523 profiler_max_stack_depth = 16;
524 DEFVAR_INT ("profiler-log-size", profiler_log_size,
525 doc: /* Number of distinct call-stacks that can be recorded in a profiler log.
526If the log gets full, some of the least-seen call-stacks will be evicted
527to make room for new entries. */);
528 profiler_log_size = 10000;
529
530#ifdef PROFILER_CPU_SUPPORT
531 profiler_cpu_running = NOT_RUNNING;
532 cpu_log = Qnil;
533 staticpro (&cpu_log);
534 defsubr (&Sprofiler_cpu_start);
535 defsubr (&Sprofiler_cpu_stop);
536 defsubr (&Sprofiler_cpu_running_p);
537 defsubr (&Sprofiler_cpu_log);
538#endif
539 profiler_memory_running = false;
540 memory_log = Qnil;
541 staticpro (&memory_log);
542 defsubr (&Sprofiler_memory_start);
543 defsubr (&Sprofiler_memory_stop);
544 defsubr (&Sprofiler_memory_running_p);
545 defsubr (&Sprofiler_memory_log);
546}
diff --git a/src/ralloc.c b/src/ralloc.c
index 9a4b1ada229..11897411930 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -72,7 +72,7 @@ static void r_alloc_init (void);
72/* Declarations for working with the malloc, ralloc, and system breaks. */ 72/* Declarations for working with the malloc, ralloc, and system breaks. */
73 73
74/* Function to set the real break value. */ 74/* Function to set the real break value. */
75POINTER (*real_morecore) (long int); 75POINTER (*real_morecore) (ptrdiff_t);
76 76
77/* The break value, as seen by malloc. */ 77/* The break value, as seen by malloc. */
78static POINTER virtual_break_value; 78static POINTER virtual_break_value;
@@ -91,18 +91,18 @@ static int extra_bytes;
91/* Macros for rounding. Note that rounding to any value is possible 91/* Macros for rounding. Note that rounding to any value is possible
92 by changing the definition of PAGE. */ 92 by changing the definition of PAGE. */
93#define PAGE (getpagesize ()) 93#define PAGE (getpagesize ())
94#define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ 94#define ROUNDUP(size) (((size_t) (size) + page_size - 1) \
95 & ~(page_size - 1)) 95 & ~((size_t)(page_size - 1)))
96 96
97#define MEM_ALIGN sizeof (double) 97#define MEM_ALIGN sizeof (double)
98#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ 98#define MEM_ROUNDUP(addr) (((size_t)(addr) + MEM_ALIGN - 1) \
99 & ~(MEM_ALIGN - 1)) 99 & ~(MEM_ALIGN - 1))
100 100
101/* The hook `malloc' uses for the function which gets more space 101/* The hook `malloc' uses for the function which gets more space
102 from the system. */ 102 from the system. */
103 103
104#ifndef SYSTEM_MALLOC 104#ifndef SYSTEM_MALLOC
105extern POINTER (*__morecore) (long int); 105extern POINTER (*__morecore) (ptrdiff_t);
106#endif 106#endif
107 107
108 108
@@ -308,7 +308,7 @@ static void
308relinquish (void) 308relinquish (void)
309{ 309{
310 register heap_ptr h; 310 register heap_ptr h;
311 long excess = 0; 311 ptrdiff_t excess = 0;
312 312
313 /* Add the amount of space beyond break_value 313 /* Add the amount of space beyond break_value
314 in all heaps which have extend beyond break_value at all. */ 314 in all heaps which have extend beyond break_value at all. */
@@ -327,10 +327,11 @@ relinquish (void)
327 327
328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) 328 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess)
329 { 329 {
330 /* This heap should have no blocs in it. */ 330 /* This heap should have no blocs in it. If it does, we
331 cannot return it to the system. */
331 if (last_heap->first_bloc != NIL_BLOC 332 if (last_heap->first_bloc != NIL_BLOC
332 || last_heap->last_bloc != NIL_BLOC) 333 || last_heap->last_bloc != NIL_BLOC)
333 emacs_abort (); 334 return;
334 335
335 /* Return the last heap, with its header, to the system. */ 336 /* Return the last heap, with its header, to the system. */
336 excess = (char *)last_heap->end - (char *)last_heap->start; 337 excess = (char *)last_heap->end - (char *)last_heap->start;
@@ -752,7 +753,7 @@ free_bloc (bloc_ptr bloc)
752 GNU malloc package. */ 753 GNU malloc package. */
753 754
754static POINTER 755static POINTER
755r_alloc_sbrk (long int size) 756r_alloc_sbrk (ptrdiff_t size)
756{ 757{
757 register bloc_ptr b; 758 register bloc_ptr b;
758 POINTER address; 759 POINTER address;
@@ -1199,9 +1200,9 @@ r_alloc_init (void)
1199#endif 1200#endif
1200 1201
1201#ifdef DOUG_LEA_MALLOC 1202#ifdef DOUG_LEA_MALLOC
1202 BLOCK_INPUT; 1203 block_input ();
1203 mallopt (M_TOP_PAD, 64 * 4096); 1204 mallopt (M_TOP_PAD, 64 * 4096);
1204 UNBLOCK_INPUT; 1205 unblock_input ();
1205#else 1206#else
1206#ifndef SYSTEM_MALLOC 1207#ifndef SYSTEM_MALLOC
1207 /* Give GNU malloc's morecore some hysteresis so that we move all 1208 /* Give GNU malloc's morecore some hysteresis so that we move all
diff --git a/src/search.c b/src/search.c
index 99fd7971e4c..7c084c62e28 100644
--- a/src/search.c
+++ b/src/search.c
@@ -156,7 +156,7 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object tra
156 re_set_whitespace_regexp (NULL); 156 re_set_whitespace_regexp (NULL);
157 157
158 re_set_syntax (old); 158 re_set_syntax (old);
159 /* UNBLOCK_INPUT; */ 159 /* unblock_input (); */
160 if (val) 160 if (val)
161 xsignal1 (Qinvalid_regexp, build_string (val)); 161 xsignal1 (Qinvalid_regexp, build_string (val));
162 162
@@ -674,7 +674,7 @@ scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end,
674 obstacle --- the last character the dumb search loop should 674 obstacle --- the last character the dumb search loop should
675 examine. */ 675 examine. */
676 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end) - 1; 676 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end) - 1;
677 ptrdiff_t start_byte = CHAR_TO_BYTE (start); 677 ptrdiff_t start_byte;
678 ptrdiff_t tem; 678 ptrdiff_t tem;
679 679
680 /* If we're looking for a newline, consult the newline cache 680 /* If we're looking for a newline, consult the newline cache
@@ -684,18 +684,22 @@ scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end,
684 ptrdiff_t next_change; 684 ptrdiff_t next_change;
685 immediate_quit = 0; 685 immediate_quit = 0;
686 while (region_cache_forward 686 while (region_cache_forward
687 (current_buffer, newline_cache, start_byte, &next_change)) 687 (current_buffer, newline_cache, start, &next_change))
688 start_byte = next_change; 688 start = next_change;
689 immediate_quit = allow_quit; 689 immediate_quit = allow_quit;
690 690
691 start_byte = CHAR_TO_BYTE (start);
692
691 /* START should never be after END. */ 693 /* START should never be after END. */
692 if (start_byte > ceiling_byte) 694 if (start_byte > ceiling_byte)
693 start_byte = ceiling_byte; 695 start_byte = ceiling_byte;
694 696
695 /* Now the text after start is an unknown region, and 697 /* Now the text after start is an unknown region, and
696 next_change is the position of the next known region. */ 698 next_change is the position of the next known region. */
697 ceiling_byte = min (next_change - 1, ceiling_byte); 699 ceiling_byte = min (CHAR_TO_BYTE (next_change) - 1, ceiling_byte);
698 } 700 }
701 else
702 start_byte = CHAR_TO_BYTE (start);
699 703
700 /* The dumb loop can only scan text stored in contiguous 704 /* The dumb loop can only scan text stored in contiguous
701 bytes. BUFFER_CEILING_OF returns the last character 705 bytes. BUFFER_CEILING_OF returns the last character
@@ -747,7 +751,7 @@ scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end,
747 { 751 {
748 /* The last character to check before the next obstacle. */ 752 /* The last character to check before the next obstacle. */
749 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end); 753 ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end);
750 ptrdiff_t start_byte = CHAR_TO_BYTE (start); 754 ptrdiff_t start_byte;
751 ptrdiff_t tem; 755 ptrdiff_t tem;
752 756
753 /* Consult the newline cache, if appropriate. */ 757 /* Consult the newline cache, if appropriate. */
@@ -756,18 +760,22 @@ scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end,
756 ptrdiff_t next_change; 760 ptrdiff_t next_change;
757 immediate_quit = 0; 761 immediate_quit = 0;
758 while (region_cache_backward 762 while (region_cache_backward
759 (current_buffer, newline_cache, start_byte, &next_change)) 763 (current_buffer, newline_cache, start, &next_change))
760 start_byte = next_change; 764 start = next_change;
761 immediate_quit = allow_quit; 765 immediate_quit = allow_quit;
762 766
767 start_byte = CHAR_TO_BYTE (start);
768
763 /* Start should never be at or before end. */ 769 /* Start should never be at or before end. */
764 if (start_byte <= ceiling_byte) 770 if (start_byte <= ceiling_byte)
765 start_byte = ceiling_byte + 1; 771 start_byte = ceiling_byte + 1;
766 772
767 /* Now the text before start is an unknown region, and 773 /* Now the text before start is an unknown region, and
768 next_change is the position of the next known region. */ 774 next_change is the position of the next known region. */
769 ceiling_byte = max (next_change, ceiling_byte); 775 ceiling_byte = max (CHAR_TO_BYTE (next_change), ceiling_byte);
770 } 776 }
777 else
778 start_byte = CHAR_TO_BYTE (start);
771 779
772 /* Stop scanning before the gap. */ 780 /* Stop scanning before the gap. */
773 tem = BUFFER_FLOOR_OF (start_byte - 1); 781 tem = BUFFER_FLOOR_OF (start_byte - 1);
@@ -2212,15 +2220,14 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
2212 doc: /* Replace text matched by last search with NEWTEXT. 2220 doc: /* Replace text matched by last search with NEWTEXT.
2213Leave point at the end of the replacement text. 2221Leave point at the end of the replacement text.
2214 2222
2215If second arg FIXEDCASE is non-nil, do not alter case of replacement text. 2223If optional second arg FIXEDCASE is non-nil, do not alter the case of
2216Otherwise maybe capitalize the whole text, or maybe just word initials, 2224the replacement text. Otherwise, maybe capitalize the whole text, or
2217based on the replaced text. 2225maybe just word initials, based on the replaced text. If the replaced
2218If the replaced text has only capital letters 2226text has only capital letters and has at least one multiletter word,
2219and has at least one multiletter word, convert NEWTEXT to all caps. 2227convert NEWTEXT to all caps. Otherwise if all words are capitalized
2220Otherwise if all words are capitalized in the replaced text, 2228in the replaced text, capitalize each word in NEWTEXT.
2221capitalize each word in NEWTEXT.
2222 2229
2223If third arg LITERAL is non-nil, insert NEWTEXT literally. 2230If optional third arg LITERAL is non-nil, insert NEWTEXT literally.
2224Otherwise treat `\\' as special: 2231Otherwise treat `\\' as special:
2225 `\\&' in NEWTEXT means substitute original matched text. 2232 `\\&' in NEWTEXT means substitute original matched text.
2226 `\\N' means substitute what matched the Nth `\\(...\\)'. 2233 `\\N' means substitute what matched the Nth `\\(...\\)'.
@@ -2231,13 +2238,11 @@ Otherwise treat `\\' as special:
2231 Any other character following `\\' signals an error. 2238 Any other character following `\\' signals an error.
2232Case conversion does not apply to these substitutions. 2239Case conversion does not apply to these substitutions.
2233 2240
2234FIXEDCASE and LITERAL are optional arguments. 2241If optional fourth argument STRING is non-nil, it should be a string
2235 2242to act on; this should be the string on which the previous match was
2236The optional fourth argument STRING can be a string to modify. 2243done via `string-match'. In this case, `replace-match' creates and
2237This is meaningful when the previous match was done against STRING, 2244returns a new string, made by copying STRING and replacing the part of
2238using `string-match'. When used this way, `replace-match' 2245STRING that was matched (the original STRING itself is not altered).
2239creates and returns a new string made by copying STRING and replacing
2240the part of STRING that was matched.
2241 2246
2242The optional fifth argument SUBEXP specifies a subexpression; 2247The optional fifth argument SUBEXP specifies a subexpression;
2243it says to replace just that subexpression with NEWTEXT, 2248it says to replace just that subexpression with NEWTEXT,
diff --git a/src/syntax.c b/src/syntax.c
index 91ef4e66663..d3cafcc472e 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -151,7 +151,7 @@ static void scan_sexps_forward (struct lisp_parse_state *,
151static int in_classes (int, Lisp_Object); 151static int in_classes (int, Lisp_Object);
152 152
153/* This setter is used only in this file, so it can be private. */ 153/* This setter is used only in this file, so it can be private. */
154static inline void 154static void
155bset_syntax_table (struct buffer *b, Lisp_Object val) 155bset_syntax_table (struct buffer *b, Lisp_Object val)
156{ 156{
157 b->INTERNAL_FIELD (syntax_table) = val; 157 b->INTERNAL_FIELD (syntax_table) = val;
@@ -372,7 +372,7 @@ char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos)
372/* Return the bytepos one character before BYTEPOS. 372/* Return the bytepos one character before BYTEPOS.
373 We assume that BYTEPOS is not at the start of the buffer. */ 373 We assume that BYTEPOS is not at the start of the buffer. */
374 374
375static inline ptrdiff_t 375static ptrdiff_t
376dec_bytepos (ptrdiff_t bytepos) 376dec_bytepos (ptrdiff_t bytepos)
377{ 377{
378 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 378 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
diff --git a/src/sysdep.c b/src/sysdep.c
index dbfd9efc7d4..35beeaa7202 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -54,6 +54,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
54#ifdef WINDOWSNT 54#ifdef WINDOWSNT
55#define read sys_read 55#define read sys_read
56#define write sys_write 56#define write sys_write
57#ifndef STDERR_FILENO
58#define STDERR_FILENO fileno(GetStdHandle(STD_ERROR_HANDLE))
59#endif
57#include <windows.h> 60#include <windows.h>
58#endif /* not WINDOWSNT */ 61#endif /* not WINDOWSNT */
59 62
@@ -279,10 +282,6 @@ init_baud_rate (int fd)
279 282
280 283
281 284
282/* Set nonzero to make following function work under dbx
283 (at least for bsd). */
284int wait_debugging EXTERNALLY_VISIBLE;
285
286#ifndef MSDOS 285#ifndef MSDOS
287 286
288static void 287static void
@@ -290,48 +289,24 @@ wait_for_termination_1 (pid_t pid, int interruptible)
290{ 289{
291 while (1) 290 while (1)
292 { 291 {
293#if (defined (BSD_SYSTEM) || defined (HPUX)) && !defined (__GNU__)
294 /* Note that kill returns -1 even if the process is just a zombie now.
295 But inevitably a SIGCHLD interrupt should be generated
296 and child_sig will do waitpid and make the process go away. */
297 /* There is some indication that there is a bug involved with
298 termination of subprocesses, perhaps involving a kernel bug too,
299 but no idea what it is. Just as a hunch we signal SIGCHLD to see
300 if that causes the problem to go away or get worse. */
301 sigset_t sigchild_mask;
302 sigemptyset (&sigchild_mask);
303 sigaddset (&sigchild_mask, SIGCHLD);
304 pthread_sigmask (SIG_SETMASK, &sigchild_mask, 0);
305
306 if (0 > kill (pid, 0))
307 {
308 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
309 kill (getpid (), SIGCHLD);
310 break;
311 }
312 if (wait_debugging)
313 sleep (1);
314 else
315 sigsuspend (&empty_mask);
316#else /* not BSD_SYSTEM, and not HPUX version >= 6 */
317#ifdef WINDOWSNT 292#ifdef WINDOWSNT
318 wait (0); 293 wait (0);
319 break; 294 break;
320#else /* not WINDOWSNT */ 295#else /* not WINDOWSNT */
321 sigset_t blocked; 296 int status;
322 sigemptyset (&blocked); 297 int wait_result = waitpid (pid, &status, 0);
323 sigaddset (&blocked, SIGCHLD); 298 if (wait_result < 0)
324 pthread_sigmask (SIG_BLOCK, &blocked, 0); 299 {
325 errno = 0; 300 if (errno != EINTR)
326 if (kill (pid, 0) == -1 && errno == ESRCH) 301 break;
302 }
303 else
327 { 304 {
328 pthread_sigmask (SIG_UNBLOCK, &blocked, 0); 305 record_child_status_change (wait_result, status);
329 break; 306 break;
330 } 307 }
331 308
332 sigsuspend (&empty_mask);
333#endif /* not WINDOWSNT */ 309#endif /* not WINDOWSNT */
334#endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
335 if (interruptible) 310 if (interruptible)
336 QUIT; 311 QUIT;
337 } 312 }
@@ -1438,40 +1413,80 @@ init_system_name (void)
1438 1413
1439sigset_t empty_mask; 1414sigset_t empty_mask;
1440 1415
1441/* Store into *ACTION a signal action suitable for Emacs, with handler 1416static struct sigaction process_fatal_action;
1442 HANDLER. */ 1417
1443void 1418static int
1444emacs_sigaction_init (struct sigaction *action, signal_handler_t handler) 1419emacs_sigaction_flags (void)
1445{ 1420{
1446 sigemptyset (&action->sa_mask); 1421#ifdef SA_RESTART
1447 action->sa_handler = handler;
1448 action->sa_flags = 0;
1449#if defined (SA_RESTART)
1450 /* SA_RESTART causes interruptible functions with timeouts (e.g., 1422 /* SA_RESTART causes interruptible functions with timeouts (e.g.,
1451 'select') to reset their timeout on some platforms (e.g., 1423 'select') to reset their timeout on some platforms (e.g.,
1452 HP-UX 11), which is not what we want. Also, when Emacs is 1424 HP-UX 11), which is not what we want. Also, when Emacs is
1453 interactive, we don't want SA_RESTART because we need to poll 1425 interactive, we don't want SA_RESTART because we need to poll
1454 for pending input so we need long-running syscalls to be interrupted 1426 for pending input so we need long-running syscalls to be interrupted
1455 after a signal that sets the interrupt_input_pending flag. */ 1427 after a signal that sets pending_signals.
1456 /* Non-interactive keyboard input goes through stdio, where we always 1428
1457 want restartable system calls. */ 1429 Non-interactive keyboard input goes through stdio, where we
1430 always want restartable system calls. */
1458 if (noninteractive) 1431 if (noninteractive)
1459 action->sa_flags = SA_RESTART; 1432 return SA_RESTART;
1433#endif
1434 return 0;
1435}
1436
1437/* Store into *ACTION a signal action suitable for Emacs, with handler
1438 HANDLER. */
1439void
1440emacs_sigaction_init (struct sigaction *action, signal_handler_t handler)
1441{
1442 sigemptyset (&action->sa_mask);
1443
1444 /* When handling a signal, block nonfatal system signals that are caught
1445 by Emacs. This makes race conditions less likely. */
1446 sigaddset (&action->sa_mask, SIGALRM);
1447#ifdef SIGCHLD
1448 sigaddset (&action->sa_mask, SIGCHLD);
1449#endif
1450#ifdef SIGDANGER
1451 sigaddset (&action->sa_mask, SIGDANGER);
1452#endif
1453#ifdef PROFILER_CPU_SUPPORT
1454 sigaddset (&action->sa_mask, SIGPROF);
1460#endif 1455#endif
1456#ifdef SIGWINCH
1457 sigaddset (&action->sa_mask, SIGWINCH);
1458#endif
1459 if (! noninteractive)
1460 {
1461 sigaddset (&action->sa_mask, SIGINT);
1462 sigaddset (&action->sa_mask, SIGQUIT);
1463#ifdef USABLE_SIGIO
1464 sigaddset (&action->sa_mask, SIGIO);
1465#endif
1466 }
1467
1468 if (! IEEE_FLOATING_POINT)
1469 sigaddset (&action->sa_mask, SIGFPE);
1470
1471 action->sa_handler = handler;
1472 action->sa_flags = emacs_sigaction_flags ();
1461} 1473}
1462 1474
1463#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD 1475#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
1464static pthread_t main_thread; 1476static pthread_t main_thread;
1465#endif 1477#endif
1466 1478
1467/* If we are on the main thread, handle the signal SIG with HANDLER. 1479/* SIG has arrived at the current process. Deliver it to the main
1480 thread, which should handle it with HANDLER.
1481
1482 If we are on the main thread, handle the signal SIG with HANDLER.
1468 Otherwise, redirect the signal to the main thread, blocking it from 1483 Otherwise, redirect the signal to the main thread, blocking it from
1469 this thread. POSIX says any thread can receive a signal that is 1484 this thread. POSIX says any thread can receive a signal that is
1470 associated with a process, process group, or asynchronous event. 1485 associated with a process, process group, or asynchronous event.
1471 On GNU/Linux that is not true, but for other systems (FreeBSD at 1486 On GNU/Linux that is not true, but for other systems (FreeBSD at
1472 least) it is. */ 1487 least) it is. */
1473void 1488void
1474handle_on_main_thread (int sig, signal_handler_t handler) 1489deliver_process_signal (int sig, signal_handler_t handler)
1475{ 1490{
1476 /* Preserve errno, to avoid race conditions with signal handlers that 1491 /* Preserve errno, to avoid race conditions with signal handlers that
1477 might change errno. Races can occur even in single-threaded hosts. */ 1492 might change errno. Races can occur even in single-threaded hosts. */
@@ -1494,30 +1509,120 @@ handle_on_main_thread (int sig, signal_handler_t handler)
1494 1509
1495 errno = old_errno; 1510 errno = old_errno;
1496} 1511}
1512
1513/* Static location to save a fatal backtrace in a thread.
1514 FIXME: If two subsidiary threads fail simultaneously, the resulting
1515 backtrace may be garbage. */
1516enum { BACKTRACE_LIMIT_MAX = 500 };
1517static void *thread_backtrace_buffer[BACKTRACE_LIMIT_MAX + 1];
1518static int thread_backtrace_npointers;
1519
1520/* SIG has arrived at the current thread.
1521 If we are on the main thread, handle the signal SIG with HANDLER.
1522 Otherwise, this is a fatal error in the handling thread. */
1523static void
1524deliver_thread_signal (int sig, signal_handler_t handler)
1525{
1526 int old_errno = errno;
1527
1528#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
1529 if (! pthread_equal (pthread_self (), main_thread))
1530 {
1531 thread_backtrace_npointers
1532 = backtrace (thread_backtrace_buffer, BACKTRACE_LIMIT_MAX);
1533 sigaction (sig, &process_fatal_action, 0);
1534 pthread_kill (main_thread, sig);
1535
1536 /* Avoid further damage while the main thread is exiting. */
1537 while (1)
1538 sigsuspend (&empty_mask);
1539 }
1540#endif
1541
1542 handler (sig);
1543 errno = old_errno;
1544}
1497 1545
1498#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST 1546#if !HAVE_DECL_SYS_SIGLIST
1499static char *my_sys_siglist[NSIG]; 1547# undef sys_siglist
1500# ifdef sys_siglist 1548# ifdef _sys_siglist
1501# undef sys_siglist 1549# define sys_siglist _sys_siglist
1550# else
1551# define sys_siglist my_sys_siglist
1552static char const *sys_siglist[NSIG];
1502# endif 1553# endif
1503# define sys_siglist my_sys_siglist
1504#endif 1554#endif
1505 1555
1556#ifdef _sys_nsig
1557# define sys_siglist_entries _sys_nsig
1558#else
1559# define sys_siglist_entries NSIG
1560#endif
1561
1562/* Handle bus errors, invalid instruction, etc. */
1563static void
1564handle_fatal_signal (int sig)
1565{
1566 terminate_due_to_signal (sig, 40);
1567}
1568
1569static void
1570deliver_fatal_signal (int sig)
1571{
1572 deliver_process_signal (sig, handle_fatal_signal);
1573}
1574
1575static void
1576deliver_fatal_thread_signal (int sig)
1577{
1578 deliver_thread_signal (sig, handle_fatal_signal);
1579}
1580
1581static _Noreturn void
1582handle_arith_signal (int sig)
1583{
1584 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
1585 xsignal0 (Qarith_error);
1586}
1587
1588static void
1589deliver_arith_signal (int sig)
1590{
1591 deliver_thread_signal (sig, handle_arith_signal);
1592}
1593
1594/* Treat SIG as a terminating signal, unless it is already ignored and
1595 we are in --batch mode. Among other things, this makes nohup work. */
1596static void
1597maybe_fatal_sig (int sig)
1598{
1599 bool catch_sig = !noninteractive;
1600 if (!catch_sig)
1601 {
1602 struct sigaction old_action;
1603 sigaction (sig, 0, &old_action);
1604 catch_sig = old_action.sa_handler != SIG_IGN;
1605 }
1606 if (catch_sig)
1607 sigaction (sig, &process_fatal_action, 0);
1608}
1609
1506void 1610void
1507init_signals (void) 1611init_signals (bool dumping)
1508{ 1612{
1613 struct sigaction thread_fatal_action;
1614 struct sigaction action;
1615
1509 sigemptyset (&empty_mask); 1616 sigemptyset (&empty_mask);
1510 1617
1511#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD 1618#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
1512 main_thread = pthread_self (); 1619 main_thread = pthread_self ();
1513#endif 1620#endif
1514 1621
1515#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST 1622#if !HAVE_DECL_SYS_SIGLIST && !defined _sys_siglist
1516 if (! initialized) 1623 if (! initialized)
1517 { 1624 {
1518# ifdef SIGABRT
1519 sys_siglist[SIGABRT] = "Aborted"; 1625 sys_siglist[SIGABRT] = "Aborted";
1520# endif
1521# ifdef SIGAIO 1626# ifdef SIGAIO
1522 sys_siglist[SIGAIO] = "LAN I/O interrupt"; 1627 sys_siglist[SIGAIO] = "LAN I/O interrupt";
1523# endif 1628# endif
@@ -1545,9 +1650,7 @@ init_signals (void)
1545# ifdef SIGEMT 1650# ifdef SIGEMT
1546 sys_siglist[SIGEMT] = "Emulation trap"; 1651 sys_siglist[SIGEMT] = "Emulation trap";
1547# endif 1652# endif
1548# ifdef SIGFPE
1549 sys_siglist[SIGFPE] = "Arithmetic exception"; 1653 sys_siglist[SIGFPE] = "Arithmetic exception";
1550# endif
1551# ifdef SIGFREEZE 1654# ifdef SIGFREEZE
1552 sys_siglist[SIGFREEZE] = "SIGFREEZE"; 1655 sys_siglist[SIGFREEZE] = "SIGFREEZE";
1553# endif 1656# endif
@@ -1557,12 +1660,8 @@ init_signals (void)
1557# ifdef SIGHUP 1660# ifdef SIGHUP
1558 sys_siglist[SIGHUP] = "Hangup"; 1661 sys_siglist[SIGHUP] = "Hangup";
1559# endif 1662# endif
1560# ifdef SIGILL
1561 sys_siglist[SIGILL] = "Illegal instruction"; 1663 sys_siglist[SIGILL] = "Illegal instruction";
1562# endif
1563# ifdef SIGINT
1564 sys_siglist[SIGINT] = "Interrupt"; 1664 sys_siglist[SIGINT] = "Interrupt";
1565# endif
1566# ifdef SIGIO 1665# ifdef SIGIO
1567 sys_siglist[SIGIO] = "I/O possible"; 1666 sys_siglist[SIGIO] = "I/O possible";
1568# endif 1667# endif
@@ -1611,9 +1710,7 @@ init_signals (void)
1611# ifdef SIGSAK 1710# ifdef SIGSAK
1612 sys_siglist[SIGSAK] = "Secure attention"; 1711 sys_siglist[SIGSAK] = "Secure attention";
1613# endif 1712# endif
1614# ifdef SIGSEGV
1615 sys_siglist[SIGSEGV] = "Segmentation violation"; 1713 sys_siglist[SIGSEGV] = "Segmentation violation";
1616# endif
1617# ifdef SIGSOUND 1714# ifdef SIGSOUND
1618 sys_siglist[SIGSOUND] = "Sound completed"; 1715 sys_siglist[SIGSOUND] = "Sound completed";
1619# endif 1716# endif
@@ -1626,9 +1723,7 @@ init_signals (void)
1626# ifdef SIGSYS 1723# ifdef SIGSYS
1627 sys_siglist[SIGSYS] = "Bad argument to system call"; 1724 sys_siglist[SIGSYS] = "Bad argument to system call";
1628# endif 1725# endif
1629# ifdef SIGTERM
1630 sys_siglist[SIGTERM] = "Terminated"; 1726 sys_siglist[SIGTERM] = "Terminated";
1631# endif
1632# ifdef SIGTHAW 1727# ifdef SIGTHAW
1633 sys_siglist[SIGTHAW] = "SIGTHAW"; 1728 sys_siglist[SIGTHAW] = "SIGTHAW";
1634# endif 1729# endif
@@ -1672,7 +1767,130 @@ init_signals (void)
1672 sys_siglist[SIGXFSZ] = "File size limit exceeded"; 1767 sys_siglist[SIGXFSZ] = "File size limit exceeded";
1673# endif 1768# endif
1674 } 1769 }
1675#endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */ 1770#endif /* !HAVE_DECL_SYS_SIGLIST && !_sys_siglist */
1771
1772 /* Don't alter signal handlers if dumping. On some machines,
1773 changing signal handlers sets static data that would make signals
1774 fail to work right when the dumped Emacs is run. */
1775 if (dumping)
1776 return;
1777
1778 sigfillset (&process_fatal_action.sa_mask);
1779 process_fatal_action.sa_handler = deliver_fatal_signal;
1780 process_fatal_action.sa_flags = emacs_sigaction_flags ();
1781
1782 sigfillset (&thread_fatal_action.sa_mask);
1783 thread_fatal_action.sa_handler = deliver_fatal_thread_signal;
1784 thread_fatal_action.sa_flags = process_fatal_action.sa_flags;
1785
1786 /* SIGINT may need special treatment on MS-Windows. See
1787 http://lists.gnu.org/archive/html/emacs-devel/2010-09/msg01062.html
1788 Please update the doc of kill-emacs, kill-emacs-hook, and
1789 NEWS if you change this. */
1790
1791 maybe_fatal_sig (SIGHUP);
1792 maybe_fatal_sig (SIGINT);
1793 maybe_fatal_sig (SIGTERM);
1794
1795 /* Emacs checks for write errors, so it can safely ignore SIGPIPE.
1796 However, in batch mode leave SIGPIPE alone, as that causes Emacs
1797 to behave more like typical batch applications do. */
1798 if (! noninteractive)
1799 signal (SIGPIPE, SIG_IGN);
1800
1801 sigaction (SIGQUIT, &process_fatal_action, 0);
1802 sigaction (SIGILL, &thread_fatal_action, 0);
1803 sigaction (SIGTRAP, &thread_fatal_action, 0);
1804
1805 /* Typically SIGFPE is thread-specific and is fatal, like SIGILL.
1806 But on a non-IEEE host SIGFPE can come from a trap in the Lisp
1807 interpreter's floating point operations, so treat SIGFPE as an
1808 arith-error if it arises in the main thread. */
1809 if (IEEE_FLOATING_POINT)
1810 sigaction (SIGFPE, &thread_fatal_action, 0);
1811 else
1812 {
1813 emacs_sigaction_init (&action, deliver_arith_signal);
1814 sigaction (SIGFPE, &action, 0);
1815 }
1816
1817#ifdef SIGUSR1
1818 add_user_signal (SIGUSR1, "sigusr1");
1819#endif
1820#ifdef SIGUSR2
1821 add_user_signal (SIGUSR2, "sigusr2");
1822#endif
1823 sigaction (SIGABRT, &thread_fatal_action, 0);
1824#ifdef SIGPRE
1825 sigaction (SIGPRE, &thread_fatal_action, 0);
1826#endif
1827#ifdef SIGORE
1828 sigaction (SIGORE, &thread_fatal_action, 0);
1829#endif
1830#ifdef SIGUME
1831 sigaction (SIGUME, &thread_fatal_action, 0);
1832#endif
1833#ifdef SIGDLK
1834 sigaction (SIGDLK, &process_fatal_action, 0);
1835#endif
1836#ifdef SIGCPULIM
1837 sigaction (SIGCPULIM, &process_fatal_action, 0);
1838#endif
1839#ifdef SIGIOT
1840 sigaction (SIGIOT, &thread_fatal_action, 0);
1841#endif
1842#ifdef SIGEMT
1843 sigaction (SIGEMT, &thread_fatal_action, 0);
1844#endif
1845#ifdef SIGBUS
1846 sigaction (SIGBUS, &thread_fatal_action, 0);
1847#endif
1848 sigaction (SIGSEGV, &thread_fatal_action, 0);
1849#ifdef SIGSYS
1850 sigaction (SIGSYS, &thread_fatal_action, 0);
1851#endif
1852 sigaction (SIGTERM, &process_fatal_action, 0);
1853#ifdef SIGPROF
1854 signal (SIGPROF, SIG_IGN);
1855#endif
1856#ifdef SIGVTALRM
1857 sigaction (SIGVTALRM, &process_fatal_action, 0);
1858#endif
1859#ifdef SIGXCPU
1860 sigaction (SIGXCPU, &process_fatal_action, 0);
1861#endif
1862#ifdef SIGXFSZ
1863 sigaction (SIGXFSZ, &process_fatal_action, 0);
1864#endif
1865
1866#ifdef SIGDANGER
1867 /* This just means available memory is getting low. */
1868 emacs_sigaction_init (&action, deliver_danger_signal);
1869 sigaction (SIGDANGER, &action, 0);
1870#endif
1871
1872 /* AIX-specific signals. */
1873#ifdef SIGGRANT
1874 sigaction (SIGGRANT, &process_fatal_action, 0);
1875#endif
1876#ifdef SIGMIGRATE
1877 sigaction (SIGMIGRATE, &process_fatal_action, 0);
1878#endif
1879#ifdef SIGMSG
1880 sigaction (SIGMSG, &process_fatal_action, 0);
1881#endif
1882#ifdef SIGRETRACT
1883 sigaction (SIGRETRACT, &process_fatal_action, 0);
1884#endif
1885#ifdef SIGSAK
1886 sigaction (SIGSAK, &process_fatal_action, 0);
1887#endif
1888#ifdef SIGSOUND
1889 sigaction (SIGSOUND, &process_fatal_action, 0);
1890#endif
1891#ifdef SIGTALRM
1892 sigaction (SIGTALRM, &thread_fatal_action, 0);
1893#endif
1676} 1894}
1677 1895
1678#ifndef HAVE_RANDOM 1896#ifndef HAVE_RANDOM
@@ -1811,23 +2029,36 @@ snprintf (char *buf, size_t bufsize, char const *format, ...)
1811void 2029void
1812emacs_backtrace (int backtrace_limit) 2030emacs_backtrace (int backtrace_limit)
1813{ 2031{
1814 enum { BACKTRACE_LIMIT_MAX = 500 }; 2032 void *main_backtrace_buffer[BACKTRACE_LIMIT_MAX + 1];
1815 void *buffer[BACKTRACE_LIMIT_MAX + 1];
1816 int bounded_limit = min (backtrace_limit, BACKTRACE_LIMIT_MAX); 2033 int bounded_limit = min (backtrace_limit, BACKTRACE_LIMIT_MAX);
1817 int npointers = backtrace (buffer, bounded_limit + 1); 2034 void *buffer;
2035 int npointers;
2036
2037 if (thread_backtrace_npointers)
2038 {
2039 buffer = thread_backtrace_buffer;
2040 npointers = thread_backtrace_npointers;
2041 }
2042 else
2043 {
2044 buffer = main_backtrace_buffer;
2045 npointers = backtrace (buffer, bounded_limit + 1);
2046 }
2047
1818 if (npointers) 2048 if (npointers)
1819 ignore_value (write (STDERR_FILENO, "\nBacktrace:\n", 12)); 2049 {
1820 backtrace_symbols_fd (buffer, bounded_limit, STDERR_FILENO); 2050 ignore_value (write (STDERR_FILENO, "\nBacktrace:\n", 12));
1821 if (bounded_limit < npointers) 2051 backtrace_symbols_fd (buffer, npointers, STDERR_FILENO);
1822 ignore_value (write (STDERR_FILENO, "...\n", 4)); 2052 if (bounded_limit < npointers)
2053 ignore_value (write (STDERR_FILENO, "...\n", 4));
2054 }
1823} 2055}
1824 2056
1825#ifndef HAVE_NTGUI 2057#ifndef HAVE_NTGUI
1826/* Using emacs_abort lets GDB return from a breakpoint here. */
1827void 2058void
1828emacs_abort (void) 2059emacs_abort (void)
1829{ 2060{
1830 fatal_error_backtrace (SIGABRT, 10); 2061 terminate_due_to_signal (SIGABRT, 10);
1831} 2062}
1832#endif 2063#endif
1833 2064
@@ -1910,7 +2141,8 @@ emacs_write (int fildes, const char *buf, ptrdiff_t nbyte)
1910 { 2141 {
1911 /* I originally used `QUIT' but that might causes files to 2142 /* I originally used `QUIT' but that might causes files to
1912 be truncated if you hit C-g in the middle of it. --Stef */ 2143 be truncated if you hit C-g in the middle of it. --Stef */
1913 process_pending_signals (); 2144 if (pending_signals)
2145 process_pending_signals ();
1914 continue; 2146 continue;
1915 } 2147 }
1916 else 2148 else
@@ -1975,11 +2207,11 @@ getwd (char *pathname)
1975 char *npath, *spath; 2207 char *npath, *spath;
1976 extern char *getcwd (char *, size_t); 2208 extern char *getcwd (char *, size_t);
1977 2209
1978 BLOCK_INPUT; /* getcwd uses malloc */ 2210 block_input (); /* getcwd uses malloc */
1979 spath = npath = getcwd ((char *) 0, MAXPATHLEN); 2211 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
1980 if (spath == 0) 2212 if (spath == 0)
1981 { 2213 {
1982 UNBLOCK_INPUT; 2214 unblock_input ();
1983 return spath; 2215 return spath;
1984 } 2216 }
1985 /* On Altos 3068, getcwd can return @hostname/dir, so discard 2217 /* On Altos 3068, getcwd can return @hostname/dir, so discard
@@ -1988,7 +2220,7 @@ getwd (char *pathname)
1988 npath++; 2220 npath++;
1989 strcpy (pathname, npath); 2221 strcpy (pathname, npath);
1990 free (spath); /* getcwd uses malloc */ 2222 free (spath); /* getcwd uses malloc */
1991 UNBLOCK_INPUT; 2223 unblock_input ();
1992 return pathname; 2224 return pathname;
1993} 2225}
1994 2226
@@ -2056,21 +2288,20 @@ set_file_times (int fd, const char *filename,
2056 return fdutimens (fd, filename, timespec); 2288 return fdutimens (fd, filename, timespec);
2057} 2289}
2058 2290
2059#ifndef HAVE_STRSIGNAL 2291/* Like strsignal, except async-signal-safe, and this function typically
2060char * 2292 returns a string in the C locale rather than the current locale. */
2061strsignal (int code) 2293char const *
2294safe_strsignal (int code)
2062{ 2295{
2063 char *signame = 0; 2296 char const *signame = 0;
2064 2297
2065 if (0 <= code && code < NSIG) 2298 if (0 <= code && code < sys_siglist_entries)
2066 { 2299 signame = sys_siglist[code];
2067 /* Cast to suppress warning if the table has const char *. */ 2300 if (! signame)
2068 signame = (char *) sys_siglist[code]; 2301 signame = "Unknown signal";
2069 }
2070 2302
2071 return signame; 2303 return signame;
2072} 2304}
2073#endif /* HAVE_STRSIGNAL */
2074 2305
2075#ifndef DOS_NT 2306#ifndef DOS_NT
2076/* For make-serial-process */ 2307/* For make-serial-process */
@@ -2422,7 +2653,7 @@ get_up_time (void)
2422 FILE *fup; 2653 FILE *fup;
2423 EMACS_TIME up = make_emacs_time (0, 0); 2654 EMACS_TIME up = make_emacs_time (0, 0);
2424 2655
2425 BLOCK_INPUT; 2656 block_input ();
2426 fup = fopen ("/proc/uptime", "r"); 2657 fup = fopen ("/proc/uptime", "r");
2427 2658
2428 if (fup) 2659 if (fup)
@@ -2453,7 +2684,7 @@ get_up_time (void)
2453 } 2684 }
2454 fclose (fup); 2685 fclose (fup);
2455 } 2686 }
2456 UNBLOCK_INPUT; 2687 unblock_input ();
2457 2688
2458 return up; 2689 return up;
2459} 2690}
@@ -2467,7 +2698,7 @@ procfs_ttyname (int rdev)
2467 FILE *fdev = NULL; 2698 FILE *fdev = NULL;
2468 char name[PATH_MAX]; 2699 char name[PATH_MAX];
2469 2700
2470 BLOCK_INPUT; 2701 block_input ();
2471 fdev = fopen ("/proc/tty/drivers", "r"); 2702 fdev = fopen ("/proc/tty/drivers", "r");
2472 2703
2473 if (fdev) 2704 if (fdev)
@@ -2499,7 +2730,7 @@ procfs_ttyname (int rdev)
2499 } 2730 }
2500 fclose (fdev); 2731 fclose (fdev);
2501 } 2732 }
2502 UNBLOCK_INPUT; 2733 unblock_input ();
2503 return build_string (name); 2734 return build_string (name);
2504} 2735}
2505 2736
@@ -2509,7 +2740,7 @@ procfs_get_total_memory (void)
2509 FILE *fmem = NULL; 2740 FILE *fmem = NULL;
2510 unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */ 2741 unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */
2511 2742
2512 BLOCK_INPUT; 2743 block_input ();
2513 fmem = fopen ("/proc/meminfo", "r"); 2744 fmem = fopen ("/proc/meminfo", "r");
2514 2745
2515 if (fmem) 2746 if (fmem)
@@ -2528,7 +2759,7 @@ procfs_get_total_memory (void)
2528 } 2759 }
2529 fclose (fmem); 2760 fclose (fmem);
2530 } 2761 }
2531 UNBLOCK_INPUT; 2762 unblock_input ();
2532 return retval; 2763 return retval;
2533} 2764}
2534 2765
@@ -2574,17 +2805,17 @@ system_process_attributes (Lisp_Object pid)
2574 /* euid egid */ 2805 /* euid egid */
2575 uid = st.st_uid; 2806 uid = st.st_uid;
2576 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); 2807 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
2577 BLOCK_INPUT; 2808 block_input ();
2578 pw = getpwuid (uid); 2809 pw = getpwuid (uid);
2579 UNBLOCK_INPUT; 2810 unblock_input ();
2580 if (pw) 2811 if (pw)
2581 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 2812 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
2582 2813
2583 gid = st.st_gid; 2814 gid = st.st_gid;
2584 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); 2815 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
2585 BLOCK_INPUT; 2816 block_input ();
2586 gr = getgrgid (gid); 2817 gr = getgrgid (gid);
2587 UNBLOCK_INPUT; 2818 unblock_input ();
2588 if (gr) 2819 if (gr)
2589 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); 2820 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
2590 2821
@@ -2812,17 +3043,17 @@ system_process_attributes (Lisp_Object pid)
2812 /* euid egid */ 3043 /* euid egid */
2813 uid = st.st_uid; 3044 uid = st.st_uid;
2814 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); 3045 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
2815 BLOCK_INPUT; 3046 block_input ();
2816 pw = getpwuid (uid); 3047 pw = getpwuid (uid);
2817 UNBLOCK_INPUT; 3048 unblock_input ();
2818 if (pw) 3049 if (pw)
2819 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 3050 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
2820 3051
2821 gid = st.st_gid; 3052 gid = st.st_gid;
2822 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); 3053 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
2823 BLOCK_INPUT; 3054 block_input ();
2824 gr = getgrgid (gid); 3055 gr = getgrgid (gid);
2825 UNBLOCK_INPUT; 3056 unblock_input ();
2826 if (gr) 3057 if (gr)
2827 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); 3058 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
2828 3059
@@ -2943,17 +3174,17 @@ system_process_attributes (Lisp_Object pid)
2943 3174
2944 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs); 3175 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs);
2945 3176
2946 BLOCK_INPUT; 3177 block_input ();
2947 pw = getpwuid (proc.ki_uid); 3178 pw = getpwuid (proc.ki_uid);
2948 UNBLOCK_INPUT; 3179 unblock_input ();
2949 if (pw) 3180 if (pw)
2950 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); 3181 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
2951 3182
2952 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (proc.ki_svgid)), attrs); 3183 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (proc.ki_svgid)), attrs);
2953 3184
2954 BLOCK_INPUT; 3185 block_input ();
2955 gr = getgrgid (proc.ki_svgid); 3186 gr = getgrgid (proc.ki_svgid);
2956 UNBLOCK_INPUT; 3187 unblock_input ();
2957 if (gr) 3188 if (gr)
2958 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); 3189 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
2959 3190
@@ -2993,9 +3224,9 @@ system_process_attributes (Lisp_Object pid)
2993 attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.ki_pgid)), attrs); 3224 attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.ki_pgid)), attrs);
2994 attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (proc.ki_sid)), attrs); 3225 attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (proc.ki_sid)), attrs);
2995 3226
2996 BLOCK_INPUT; 3227 block_input ();
2997 ttyname = proc.ki_tdev == NODEV ? NULL : devname (proc.ki_tdev, S_IFCHR); 3228 ttyname = proc.ki_tdev == NODEV ? NULL : devname (proc.ki_tdev, S_IFCHR);
2998 UNBLOCK_INPUT; 3229 unblock_input ();
2999 if (ttyname) 3230 if (ttyname)
3000 attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs); 3231 attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
3001 3232
diff --git a/src/syssignal.h b/src/syssignal.h
index e309e6725b7..2bf2f046aa5 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -18,8 +18,9 @@ You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20#include <signal.h> 20#include <signal.h>
21#include <stdbool.h>
21 22
22extern void init_signals (void); 23extern void init_signals (bool);
23 24
24#ifdef HAVE_PTHREAD 25#ifdef HAVE_PTHREAD
25#include <pthread.h> 26#include <pthread.h>
@@ -28,17 +29,31 @@ extern void init_signals (void);
28#define FORWARD_SIGNAL_TO_MAIN_THREAD 29#define FORWARD_SIGNAL_TO_MAIN_THREAD
29#endif 30#endif
30 31
32#if defined HAVE_TIMER_SETTIME && defined SIGEV_SIGNAL
33# define HAVE_ITIMERSPEC
34#endif
35
36#if (defined SIGPROF && !defined PROFILING \
37 && (defined HAVE_SETITIMER || defined HAVE_ITIMERSPEC))
38# define PROFILER_CPU_SUPPORT
39#endif
40
31extern sigset_t empty_mask; 41extern sigset_t empty_mask;
32 42
33typedef void (*signal_handler_t) (int); 43typedef void (*signal_handler_t) (int);
34 44
35extern void emacs_sigaction_init (struct sigaction *, signal_handler_t); 45extern void emacs_sigaction_init (struct sigaction *, signal_handler_t);
46char const *safe_strsignal (int) ATTRIBUTE_CONST;
36 47
37#if NSIG < NSIG_MINIMUM 48#if NSIG < NSIG_MINIMUM
38# undef NSIG 49# undef NSIG
39# define NSIG NSIG_MINIMUM 50# define NSIG NSIG_MINIMUM
40#endif 51#endif
41 52
53#ifndef emacs_raise
54# define emacs_raise(sig) raise (sig)
55#endif
56
42/* On bsd, [man says] kill does not accept a negative number to kill a pgrp. 57/* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
43 Must do that using the killpg call. */ 58 Must do that using the killpg call. */
44#ifdef BSD_SYSTEM 59#ifdef BSD_SYSTEM
@@ -60,8 +75,7 @@ extern void emacs_sigaction_init (struct sigaction *, signal_handler_t);
60#endif /* ! defined (SIGCLD) */ 75#endif /* ! defined (SIGCLD) */
61 76
62#ifndef HAVE_STRSIGNAL 77#ifndef HAVE_STRSIGNAL
63/* strsignal is in sysdep.c */ 78# define strsignal(sig) safe_strsignal (sig)
64char *strsignal (int);
65#endif 79#endif
66 80
67void handle_on_main_thread (int, signal_handler_t); 81void deliver_process_signal (int, signal_handler_t);
diff --git a/src/syswait.h b/src/syswait.h
index 9d84876d4be..aa4c4bcf527 100644
--- a/src/syswait.h
+++ b/src/syswait.h
@@ -51,4 +51,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#define WTERMSIG(status) ((status) & 0x7f) 51#define WTERMSIG(status) ((status) & 0x7f)
52#endif 52#endif
53 53
54/* Defined in process.c. */
55extern void record_child_status_change (pid_t, int);
56
57/* Defined in sysdep.c. */
58extern void wait_for_termination (pid_t);
59extern void interruptible_wait_for_termination (pid_t);
60
54#endif /* EMACS_SYSWAIT_H */ 61#endif /* EMACS_SYSWAIT_H */
diff --git a/src/term.c b/src/term.c
index f4117d67dec..189fb783cbc 100644
--- a/src/term.c
+++ b/src/term.c
@@ -753,13 +753,13 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
753 conversion_buffer = encode_terminal_code (string, n, coding); 753 conversion_buffer = encode_terminal_code (string, n, coding);
754 if (coding->produced > 0) 754 if (coding->produced > 0)
755 { 755 {
756 BLOCK_INPUT; 756 block_input ();
757 fwrite (conversion_buffer, 1, coding->produced, tty->output); 757 fwrite (conversion_buffer, 1, coding->produced, tty->output);
758 if (ferror (tty->output)) 758 if (ferror (tty->output))
759 clearerr (tty->output); 759 clearerr (tty->output);
760 if (tty->termscript) 760 if (tty->termscript)
761 fwrite (conversion_buffer, 1, coding->produced, tty->termscript); 761 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
762 UNBLOCK_INPUT; 762 unblock_input ();
763 } 763 }
764 string += n; 764 string += n;
765 765
@@ -814,13 +814,13 @@ tty_write_glyphs_with_face (register struct frame *f, register struct glyph *str
814 conversion_buffer = encode_terminal_code (string, len, coding); 814 conversion_buffer = encode_terminal_code (string, len, coding);
815 if (coding->produced > 0) 815 if (coding->produced > 0)
816 { 816 {
817 BLOCK_INPUT; 817 block_input ();
818 fwrite (conversion_buffer, 1, coding->produced, tty->output); 818 fwrite (conversion_buffer, 1, coding->produced, tty->output);
819 if (ferror (tty->output)) 819 if (ferror (tty->output))
820 clearerr (tty->output); 820 clearerr (tty->output);
821 if (tty->termscript) 821 if (tty->termscript)
822 fwrite (conversion_buffer, 1, coding->produced, tty->termscript); 822 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
823 UNBLOCK_INPUT; 823 unblock_input ();
824 } 824 }
825 825
826 /* Turn appearance modes off. */ 826 /* Turn appearance modes off. */
@@ -900,13 +900,13 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
900 900
901 if (coding->produced > 0) 901 if (coding->produced > 0)
902 { 902 {
903 BLOCK_INPUT; 903 block_input ();
904 fwrite (conversion_buffer, 1, coding->produced, tty->output); 904 fwrite (conversion_buffer, 1, coding->produced, tty->output);
905 if (ferror (tty->output)) 905 if (ferror (tty->output))
906 clearerr (tty->output); 906 clearerr (tty->output);
907 if (tty->termscript) 907 if (tty->termscript)
908 fwrite (conversion_buffer, 1, coding->produced, tty->termscript); 908 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
909 UNBLOCK_INPUT; 909 unblock_input ();
910 } 910 }
911 911
912 OUTPUT1_IF (tty, tty->TS_pad_inserted_char); 912 OUTPUT1_IF (tty, tty->TS_pad_inserted_char);
diff --git a/src/termhooks.h b/src/termhooks.h
index 0864b80da84..42f2e16e577 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -591,24 +591,14 @@ struct terminal
591 /* Called to read input events. 591 /* Called to read input events.
592 592
593 TERMINAL indicates which terminal device to read from. Input 593 TERMINAL indicates which terminal device to read from. Input
594 events should be read into BUF, the size of which is given in 594 events should be read into HOLD_QUIT.
595 SIZE. EXPECTED is non-zero if the caller suspects that new input
596 is available.
597 595
598 A positive return value indicates that that many input events 596 A positive return value indicates that that many input events
599 where read into BUF. 597 were read into BUF.
600 Zero means no events were immediately available. 598 Zero means no events were immediately available.
601 A value of -1 means a transient read error, while -2 indicates 599 A value of -1 means a transient read error, while -2 indicates
602 that the device was closed (hangup), and it should be deleted. 600 that the device was closed (hangup), and it should be deleted. */
603
604 XXX Please note that a non-zero value of EXPECTED only means that
605 there is available input on at least one of the currently opened
606 terminal devices -- but not necessarily on this device.
607 Therefore, in most cases EXPECTED should be simply ignored.
608
609 XXX This documentation needs to be updated. */
610 int (*read_socket_hook) (struct terminal *terminal, 601 int (*read_socket_hook) (struct terminal *terminal,
611 int expected,
612 struct input_event *hold_quit); 602 struct input_event *hold_quit);
613 603
614 /* Called when a frame's display becomes entirely up to date. */ 604 /* Called when a frame's display becomes entirely up to date. */
diff --git a/src/terminal.c b/src/terminal.c
index 719c2a36111..2c0c60e7345 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -42,7 +42,7 @@ struct terminal *initial_terminal;
42static void delete_initial_terminal (struct terminal *); 42static void delete_initial_terminal (struct terminal *);
43 43
44/* This setter is used only in this file, so it can be private. */ 44/* This setter is used only in this file, so it can be private. */
45static inline void 45static void
46tset_param_alist (struct terminal *t, Lisp_Object val) 46tset_param_alist (struct terminal *t, Lisp_Object val)
47{ 47{
48 t->param_alist = val; 48 t->param_alist = val;
diff --git a/src/textprop.c b/src/textprop.c
index 872912ea706..379eafb73f7 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -241,7 +241,7 @@ interval_has_all_properties (Lisp_Object plist, INTERVAL i)
241/* Return nonzero if the plist of interval I has any of the 241/* Return nonzero if the plist of interval I has any of the
242 properties of PLIST, regardless of their values. */ 242 properties of PLIST, regardless of their values. */
243 243
244static inline int 244static int
245interval_has_some_properties (Lisp_Object plist, INTERVAL i) 245interval_has_some_properties (Lisp_Object plist, INTERVAL i)
246{ 246{
247 register Lisp_Object tail1, tail2, sym; 247 register Lisp_Object tail1, tail2, sym;
@@ -263,7 +263,7 @@ interval_has_some_properties (Lisp_Object plist, INTERVAL i)
263/* Return nonzero if the plist of interval I has any of the 263/* Return nonzero if the plist of interval I has any of the
264 property names in LIST, regardless of their values. */ 264 property names in LIST, regardless of their values. */
265 265
266static inline int 266static int
267interval_has_some_properties_list (Lisp_Object list, INTERVAL i) 267interval_has_some_properties_list (Lisp_Object list, INTERVAL i)
268{ 268{
269 register Lisp_Object tail1, tail2, sym; 269 register Lisp_Object tail1, tail2, sym;
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 05a16466dfb..d304e85d490 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -117,6 +117,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
117 117
118#include <assert.h> 118#include <assert.h>
119 119
120/* LC_DATA_IN_CODE is not defined in mach-o/loader.h on OS X 10.7.
121 But it is used if we build with "Command Line Tools for Xcode 4.5
122 (OS X Lion) - September 2012". */
123#ifndef LC_DATA_IN_CODE
124#define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
125#endif
126
120#ifdef _LP64 127#ifdef _LP64
121#define mach_header mach_header_64 128#define mach_header mach_header_64
122#define segment_command segment_command_64 129#define segment_command segment_command_64
@@ -612,6 +619,11 @@ print_load_command_name (int lc)
612 printf ("LC_MAIN "); 619 printf ("LC_MAIN ");
613 break; 620 break;
614#endif 621#endif
622#ifdef LC_DATA_IN_CODE
623 case LC_DATA_IN_CODE:
624 printf ("LC_DATA_IN_CODE ");
625 break;
626#endif
615#ifdef LC_SOURCE_VERSION 627#ifdef LC_SOURCE_VERSION
616 case LC_SOURCE_VERSION: 628 case LC_SOURCE_VERSION:
617 printf ("LC_SOURCE_VERSION"); 629 printf ("LC_SOURCE_VERSION");
@@ -1178,9 +1190,9 @@ copy_dyld_info (struct load_command *lc, long delta)
1178#endif 1190#endif
1179 1191
1180#ifdef LC_FUNCTION_STARTS 1192#ifdef LC_FUNCTION_STARTS
1181/* Copy a LC_FUNCTION_STARTS/LC_DYLIB_CODE_SIGN_DRS load command from 1193/* Copy a LC_FUNCTION_STARTS/LC_DATA_IN_CODE/LC_DYLIB_CODE_SIGN_DRS
1182 the input file to the output file, adjusting the data offset 1194 load command from the input file to the output file, adjusting the
1183 field. */ 1195 data offset field. */
1184static void 1196static void
1185copy_linkedit_data (struct load_command *lc, long delta) 1197copy_linkedit_data (struct load_command *lc, long delta)
1186{ 1198{
@@ -1274,6 +1286,9 @@ dump_it (void)
1274#endif 1286#endif
1275#ifdef LC_FUNCTION_STARTS 1287#ifdef LC_FUNCTION_STARTS
1276 case LC_FUNCTION_STARTS: 1288 case LC_FUNCTION_STARTS:
1289#ifdef LC_DATA_IN_CODE
1290 case LC_DATA_IN_CODE:
1291#endif
1277#ifdef LC_DYLIB_CODE_SIGN_DRS 1292#ifdef LC_DYLIB_CODE_SIGN_DRS
1278 case LC_DYLIB_CODE_SIGN_DRS: 1293 case LC_DYLIB_CODE_SIGN_DRS:
1279#endif 1294#endif
diff --git a/src/unexw32.c b/src/unexw32.c
index 8061227d3a8..d57378b2421 100644
--- a/src/unexw32.c
+++ b/src/unexw32.c
@@ -67,18 +67,18 @@ void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile);
67/* Cached info about the .data section in the executable. */ 67/* Cached info about the .data section in the executable. */
68PIMAGE_SECTION_HEADER data_section; 68PIMAGE_SECTION_HEADER data_section;
69PCHAR data_start = 0; 69PCHAR data_start = 0;
70DWORD data_size = 0; 70DWORD_PTR data_size = 0;
71 71
72/* Cached info about the .bss section in the executable. */ 72/* Cached info about the .bss section in the executable. */
73PIMAGE_SECTION_HEADER bss_section; 73PIMAGE_SECTION_HEADER bss_section;
74PCHAR bss_start = 0; 74PCHAR bss_start = 0;
75DWORD bss_size = 0; 75DWORD_PTR bss_size = 0;
76DWORD extra_bss_size = 0; 76DWORD_PTR extra_bss_size = 0;
77/* bss data that is static might be discontiguous from non-static. */ 77/* bss data that is static might be discontiguous from non-static. */
78PIMAGE_SECTION_HEADER bss_section_static; 78PIMAGE_SECTION_HEADER bss_section_static;
79PCHAR bss_start_static = 0; 79PCHAR bss_start_static = 0;
80DWORD bss_size_static = 0; 80DWORD_PTR bss_size_static = 0;
81DWORD extra_bss_size_static = 0; 81DWORD_PTR extra_bss_size_static = 0;
82 82
83PIMAGE_SECTION_HEADER heap_section; 83PIMAGE_SECTION_HEADER heap_section;
84 84
@@ -231,7 +231,7 @@ find_section (char * name, IMAGE_NT_HEADERS * nt_header)
231/* Return pointer to section header for section containing the given 231/* Return pointer to section header for section containing the given
232 relative virtual address. */ 232 relative virtual address. */
233IMAGE_SECTION_HEADER * 233IMAGE_SECTION_HEADER *
234rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header) 234rva_to_section (DWORD_PTR rva, IMAGE_NT_HEADERS * nt_header)
235{ 235{
236 PIMAGE_SECTION_HEADER section; 236 PIMAGE_SECTION_HEADER section;
237 int i; 237 int i;
@@ -246,7 +246,7 @@ rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
246 some very old exes (eg. gzip dated Dec 1993). Since 246 some very old exes (eg. gzip dated Dec 1993). Since
247 w32_executable_type relies on this function to work reliably, 247 w32_executable_type relies on this function to work reliably,
248 we need to cope with this. */ 248 we need to cope with this. */
249 DWORD real_size = max (section->SizeOfRawData, 249 DWORD_PTR real_size = max (section->SizeOfRawData,
250 section->Misc.VirtualSize); 250 section->Misc.VirtualSize);
251 if (rva >= section->VirtualAddress 251 if (rva >= section->VirtualAddress
252 && rva < section->VirtualAddress + real_size) 252 && rva < section->VirtualAddress + real_size)
@@ -259,7 +259,7 @@ rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
259/* Return pointer to section header for section containing the given 259/* Return pointer to section header for section containing the given
260 offset in its raw data area. */ 260 offset in its raw data area. */
261IMAGE_SECTION_HEADER * 261IMAGE_SECTION_HEADER *
262offset_to_section (DWORD offset, IMAGE_NT_HEADERS * nt_header) 262offset_to_section (DWORD_PTR offset, IMAGE_NT_HEADERS * nt_header)
263{ 263{
264 PIMAGE_SECTION_HEADER section; 264 PIMAGE_SECTION_HEADER section;
265 int i; 265 int i;
@@ -279,8 +279,8 @@ offset_to_section (DWORD offset, IMAGE_NT_HEADERS * nt_header)
279/* Return offset to an object in dst, given offset in src. We assume 279/* Return offset to an object in dst, given offset in src. We assume
280 there is at least one section in both src and dst images, and that 280 there is at least one section in both src and dst images, and that
281 the some sections may have been added to dst (after sections in src). */ 281 the some sections may have been added to dst (after sections in src). */
282DWORD 282DWORD_PTR
283relocate_offset (DWORD offset, 283relocate_offset (DWORD_PTR offset,
284 IMAGE_NT_HEADERS * src_nt_header, 284 IMAGE_NT_HEADERS * src_nt_header,
285 IMAGE_NT_HEADERS * dst_nt_header) 285 IMAGE_NT_HEADERS * dst_nt_header)
286{ 286{
@@ -314,25 +314,25 @@ relocate_offset (DWORD offset,
314} 314}
315 315
316#define OFFSET_TO_RVA(offset, section) \ 316#define OFFSET_TO_RVA(offset, section) \
317 (section->VirtualAddress + ((DWORD)(offset) - section->PointerToRawData)) 317 ((section)->VirtualAddress + ((DWORD_PTR)(offset) - (section)->PointerToRawData))
318 318
319#define RVA_TO_OFFSET(rva, section) \ 319#define RVA_TO_OFFSET(rva, section) \
320 (section->PointerToRawData + ((DWORD)(rva) - section->VirtualAddress)) 320 ((section)->PointerToRawData + ((DWORD_PTR)(rva) - (section)->VirtualAddress))
321 321
322#define RVA_TO_SECTION_OFFSET(rva, section) \ 322#define RVA_TO_SECTION_OFFSET(rva, section) \
323 ((DWORD)(rva) - section->VirtualAddress) 323 ((DWORD_PTR)(rva) - (section)->VirtualAddress)
324 324
325/* Convert address in executing image to RVA. */ 325/* Convert address in executing image to RVA. */
326#define PTR_TO_RVA(ptr) ((DWORD)(ptr) - (DWORD) GetModuleHandle (NULL)) 326#define PTR_TO_RVA(ptr) ((DWORD_PTR)(ptr) - (DWORD_PTR) GetModuleHandle (NULL))
327 327
328#define RVA_TO_PTR(var,section,filedata) \ 328#define RVA_TO_PTR(var,section,filedata) \
329 ((void *)(RVA_TO_OFFSET (var,section) + (filedata).file_base)) 329 ((unsigned char *)(RVA_TO_OFFSET (var,section) + (filedata).file_base))
330 330
331#define PTR_TO_OFFSET(ptr, pfile_data) \ 331#define PTR_TO_OFFSET(ptr, pfile_data) \
332 ((unsigned char *)(ptr) - (pfile_data)->file_base) 332 ((unsigned char *)(ptr) - (pfile_data)->file_base)
333 333
334#define OFFSET_TO_PTR(offset, pfile_data) \ 334#define OFFSET_TO_PTR(offset, pfile_data) \
335 ((pfile_data)->file_base + (DWORD)(offset)) 335 ((pfile_data)->file_base + (DWORD_PTR)(offset))
336 336
337 337
338/* Flip through the executable and cache the info necessary for dumping. */ 338/* Flip through the executable and cache the info necessary for dumping. */
@@ -349,7 +349,7 @@ get_section_info (file_data *p_infile)
349 printf ("Unknown EXE header in %s...bailing.\n", p_infile->name); 349 printf ("Unknown EXE header in %s...bailing.\n", p_infile->name);
350 exit (1); 350 exit (1);
351 } 351 }
352 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + 352 nt_header = (PIMAGE_NT_HEADERS) (((DWORD_PTR) dos_header) +
353 dos_header->e_lfanew); 353 dos_header->e_lfanew);
354 if (nt_header == NULL) 354 if (nt_header == NULL)
355 { 355 {
@@ -488,7 +488,7 @@ copy_executable_and_dump_data (file_data *p_infile,
488 PIMAGE_NT_HEADERS dst_nt_header; 488 PIMAGE_NT_HEADERS dst_nt_header;
489 PIMAGE_SECTION_HEADER section; 489 PIMAGE_SECTION_HEADER section;
490 PIMAGE_SECTION_HEADER dst_section; 490 PIMAGE_SECTION_HEADER dst_section;
491 DWORD offset; 491 DWORD_PTR offset;
492 int i; 492 int i;
493 int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0; 493 int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0;
494 494
@@ -541,17 +541,17 @@ copy_executable_and_dump_data (file_data *p_infile,
541 Note that dst is updated implicitly by each COPY_CHUNK. */ 541 Note that dst is updated implicitly by each COPY_CHUNK. */
542 542
543 dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base; 543 dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
544 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + 544 nt_header = (PIMAGE_NT_HEADERS) (((DWORD_PTR) dos_header) +
545 dos_header->e_lfanew); 545 dos_header->e_lfanew);
546 section = IMAGE_FIRST_SECTION (nt_header); 546 section = IMAGE_FIRST_SECTION (nt_header);
547 547
548 dst = (unsigned char *) p_outfile->file_base; 548 dst = (unsigned char *) p_outfile->file_base;
549 549
550 COPY_CHUNK ("Copying DOS header...", dos_header, 550 COPY_CHUNK ("Copying DOS header...", dos_header,
551 (DWORD) nt_header - (DWORD) dos_header, be_verbose); 551 (DWORD_PTR) nt_header - (DWORD_PTR) dos_header, be_verbose);
552 dst_nt_header = (PIMAGE_NT_HEADERS) dst; 552 dst_nt_header = (PIMAGE_NT_HEADERS) dst;
553 COPY_CHUNK ("Copying NT header...", nt_header, 553 COPY_CHUNK ("Copying NT header...", nt_header,
554 (DWORD) section - (DWORD) nt_header, be_verbose); 554 (DWORD_PTR) section - (DWORD_PTR) nt_header, be_verbose);
555 dst_section = (PIMAGE_SECTION_HEADER) dst; 555 dst_section = (PIMAGE_SECTION_HEADER) dst;
556 COPY_CHUNK ("Copying section table...", section, 556 COPY_CHUNK ("Copying section table...", section,
557 nt_header->FileHeader.NumberOfSections * sizeof (*section), 557 nt_header->FileHeader.NumberOfSections * sizeof (*section),
@@ -627,8 +627,8 @@ copy_executable_and_dump_data (file_data *p_infile,
627 } 627 }
628 if (section == heap_section) 628 if (section == heap_section)
629 { 629 {
630 DWORD heap_start = (DWORD) get_heap_start (); 630 DWORD_PTR heap_start = (DWORD_PTR) get_heap_start ();
631 DWORD heap_size = get_committed_heap_size (); 631 DWORD_PTR heap_size = get_committed_heap_size ();
632 632
633 /* Dump the used portion of the predump heap, adjusting the 633 /* Dump the used portion of the predump heap, adjusting the
634 section's size to the appropriate size. */ 634 section's size to the appropriate size. */
diff --git a/src/vm-limit.c b/src/vm-limit.c
index 8de0acd1bb2..3020b84858a 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -41,7 +41,7 @@ static void (*warn_function) (const char *);
41static POINTER data_space_start; 41static POINTER data_space_start;
42 42
43/* Number of bytes of writable memory we can expect to be able to get. */ 43/* Number of bytes of writable memory we can expect to be able to get. */
44static unsigned long lim_data; 44static size_t lim_data;
45 45
46 46
47#if defined (HAVE_GETRLIMIT) && defined (RLIMIT_AS) 47#if defined (HAVE_GETRLIMIT) && defined (RLIMIT_AS)
@@ -88,7 +88,7 @@ get_lim_data (void)
88static void 88static void
89get_lim_data (void) 89get_lim_data (void)
90{ 90{
91 extern unsigned long reserved_heap_size; 91 extern size_t reserved_heap_size;
92 lim_data = reserved_heap_size; 92 lim_data = reserved_heap_size;
93} 93}
94 94
@@ -166,13 +166,13 @@ static void
166check_memory_limits (void) 166check_memory_limits (void)
167{ 167{
168#ifdef REL_ALLOC 168#ifdef REL_ALLOC
169 extern POINTER (*real_morecore) (long); 169 extern POINTER (*real_morecore) (ptrdiff_t);
170#endif 170#endif
171 extern POINTER (*__morecore) (long); 171 extern POINTER (*__morecore) (ptrdiff_t);
172 172
173 register POINTER cp; 173 register POINTER cp;
174 unsigned long five_percent; 174 size_t five_percent;
175 unsigned long data_size; 175 size_t data_size;
176 enum warnlevel new_warnlevel; 176 enum warnlevel new_warnlevel;
177 177
178 if (lim_data == 0) 178 if (lim_data == 0)
diff --git a/src/w16select.c b/src/w16select.c
index a3f6f1fb9ae..b8aaa3619ba 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -459,7 +459,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
459 if ( !FRAME_MSDOS_P (XFRAME (frame))) 459 if ( !FRAME_MSDOS_P (XFRAME (frame)))
460 goto done; 460 goto done;
461 461
462 BLOCK_INPUT; 462 block_input ();
463 463
464 if (!open_clipboard ()) 464 if (!open_clipboard ())
465 goto error; 465 goto error;
@@ -520,7 +520,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
520 520
521 unblock: 521 unblock:
522 xfree (dst); 522 xfree (dst);
523 UNBLOCK_INPUT; 523 unblock_input ();
524 524
525 /* Notify user if the text is too large to fit into DOS memory. 525 /* Notify user if the text is too large to fit into DOS memory.
526 (This will happen somewhere after 600K bytes (470K in DJGPP v1.x), 526 (This will happen somewhere after 600K bytes (470K in DJGPP v1.x),
@@ -565,7 +565,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
565 if ( !FRAME_MSDOS_P (XFRAME (frame))) 565 if ( !FRAME_MSDOS_P (XFRAME (frame)))
566 goto done; 566 goto done;
567 567
568 BLOCK_INPUT; 568 block_input ();
569 569
570 if (!open_clipboard ()) 570 if (!open_clipboard ())
571 goto unblock; 571 goto unblock;
@@ -626,7 +626,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
626 close_clipboard (); 626 close_clipboard ();
627 627
628 unblock: 628 unblock:
629 UNBLOCK_INPUT; 629 unblock_input ();
630 630
631 done: 631 done:
632 632
diff --git a/src/w32.c b/src/w32.c
index d79065e76e0..85210cb8e4c 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1511,52 +1511,6 @@ is_unc_volume (const char *filename)
1511 return 1; 1511 return 1;
1512} 1512}
1513 1513
1514/* Routines that are no-ops on NT but are defined to get Emacs to compile. */
1515int
1516sigemptyset (sigset_t *set)
1517{
1518 *set = 0;
1519 return 0;
1520}
1521
1522int
1523sigaddset (sigset_t *set, int signo)
1524{
1525 return 0;
1526}
1527
1528int
1529sigfillset (sigset_t *set)
1530{
1531 return 0;
1532}
1533
1534int
1535sigprocmask (int how, const sigset_t *set, sigset_t *oset)
1536{
1537 return 0;
1538}
1539
1540int
1541pthread_sigmask (int how, const sigset_t *set, sigset_t *oset)
1542{
1543 if (sigprocmask (how, set, oset) == -1)
1544 return EINVAL;
1545 return 0;
1546}
1547
1548int
1549setpgrp (int pid, int gid)
1550{
1551 return 0;
1552}
1553
1554int
1555alarm (int seconds)
1556{
1557 return 0;
1558}
1559
1560#define REG_ROOT "SOFTWARE\\GNU\\Emacs" 1514#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
1561 1515
1562LPBYTE 1516LPBYTE
@@ -1767,7 +1721,8 @@ init_environment (char ** argv)
1767 /* FIXME: should use substring of get_emacs_configuration (). 1721 /* FIXME: should use substring of get_emacs_configuration ().
1768 But I don't think the Windows build supports alpha, mips etc 1722 But I don't think the Windows build supports alpha, mips etc
1769 anymore, so have taken the easy option for now. */ 1723 anymore, so have taken the easy option for now. */
1770 else if (p && xstrcasecmp (p, "\\i386") == 0) 1724 else if (p && (xstrcasecmp (p, "\\i386") == 0
1725 || xstrcasecmp (p, "\\AMD64") == 0))
1771 { 1726 {
1772 *p = 0; 1727 *p = 0;
1773 p = strrchr (modname, '\\'); 1728 p = strrchr (modname, '\\');
@@ -1915,7 +1870,16 @@ get_emacs_configuration (void)
1915 case PROCESSOR_INTEL_386: 1870 case PROCESSOR_INTEL_386:
1916 case PROCESSOR_INTEL_486: 1871 case PROCESSOR_INTEL_486:
1917 case PROCESSOR_INTEL_PENTIUM: 1872 case PROCESSOR_INTEL_PENTIUM:
1873#ifdef _WIN64
1874 arch = "amd64";
1875#else
1918 arch = "i386"; 1876 arch = "i386";
1877#endif
1878 break;
1879#endif
1880#ifdef PROCESSOR_AMD_X8664
1881 case PROCESSOR_AMD_X8664:
1882 arch = "amd64";
1919 break; 1883 break;
1920#endif 1884#endif
1921 1885
@@ -3971,9 +3935,13 @@ utime (const char *name, struct utimbuf *times)
3971 } 3935 }
3972 3936
3973 /* Need write access to set times. */ 3937 /* Need write access to set times. */
3974 fh = CreateFile (name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 3938 fh = CreateFile (name, FILE_WRITE_ATTRIBUTES,
3975 0, OPEN_EXISTING, 0, NULL); 3939 /* If NAME specifies a directory, FILE_SHARE_DELETE
3976 if (fh) 3940 allows other processes to delete files inside it,
3941 while we have the directory open. */
3942 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
3943 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
3944 if (fh != INVALID_HANDLE_VALUE)
3977 { 3945 {
3978 convert_from_time_t (times->actime, &atime); 3946 convert_from_time_t (times->actime, &atime);
3979 convert_from_time_t (times->modtime, &mtime); 3947 convert_from_time_t (times->modtime, &mtime);
@@ -6504,33 +6472,27 @@ sys_localtime (const time_t *t)
6504 6472
6505 6473
6506 6474
6507/* Delayed loading of libraries. */ 6475/* Try loading LIBRARY_ID from the file(s) specified in
6508 6476 Vdynamic_library_alist. If the library is loaded successfully,
6509Lisp_Object Vlibrary_cache; 6477 return the handle of the DLL, and record the filename in the
6510 6478 property :loaded-from of LIBRARY_ID. If the library could not be
6511/* The argument LIBRARIES is an alist that associates a symbol 6479 found, or when it was already loaded (because the handle is not
6512 LIBRARY_ID, identifying an external DLL library known to Emacs, to 6480 recorded anywhere, and so is lost after use), return NULL.
6513 a list of filenames under which the library is usually found. In 6481
6514 most cases, the argument passed as LIBRARIES is the variable 6482 We could also save the handle in :loaded-from, but currently
6515 `dynamic-library-alist', which is initialized to a list of common 6483 there's no use case for it. */
6516 library names. If the function loads the library successfully, it
6517 returns the handle of the DLL, and records the filename in the
6518 property :loaded-from of LIBRARY_ID; it returns NULL if the library
6519 could not be found, or when it was already loaded (because the
6520 handle is not recorded anywhere, and so is lost after use). It
6521 would be trivial to save the handle too in :loaded-from, but
6522 currently there's no use case for it. */
6523HMODULE 6484HMODULE
6524w32_delayed_load (Lisp_Object libraries, Lisp_Object library_id) 6485w32_delayed_load (Lisp_Object library_id)
6525{ 6486{
6526 HMODULE library_dll = NULL; 6487 HMODULE library_dll = NULL;
6527 6488
6528 CHECK_SYMBOL (library_id); 6489 CHECK_SYMBOL (library_id);
6529 6490
6530 if (CONSP (libraries) && NILP (Fassq (library_id, Vlibrary_cache))) 6491 if (CONSP (Vdynamic_library_alist)
6492 && NILP (Fassq (library_id, Vlibrary_cache)))
6531 { 6493 {
6532 Lisp_Object found = Qnil; 6494 Lisp_Object found = Qnil;
6533 Lisp_Object dlls = Fassq (library_id, libraries); 6495 Lisp_Object dlls = Fassq (library_id, Vdynamic_library_alist);
6534 6496
6535 if (CONSP (dlls)) 6497 if (CONSP (dlls))
6536 for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls)) 6498 for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls))
@@ -6609,8 +6571,12 @@ check_windows_init_file (void)
6609} 6571}
6610 6572
6611void 6573void
6612term_ntproc (void) 6574term_ntproc (int ignored)
6613{ 6575{
6576 (void)ignored;
6577
6578 term_timers ();
6579
6614 /* shutdown the socket interface if necessary */ 6580 /* shutdown the socket interface if necessary */
6615 term_winsock (); 6581 term_winsock ();
6616 6582
@@ -6618,8 +6584,10 @@ term_ntproc (void)
6618} 6584}
6619 6585
6620void 6586void
6621init_ntproc (void) 6587init_ntproc (int dumping)
6622{ 6588{
6589 sigset_t initial_mask = 0;
6590
6623 /* Initialize the socket interface now if available and requested by 6591 /* Initialize the socket interface now if available and requested by
6624 the user by defining PRELOAD_WINSOCK; otherwise loading will be 6592 the user by defining PRELOAD_WINSOCK; otherwise loading will be
6625 delayed until open-network-stream is called (w32-has-winsock can 6593 delayed until open-network-stream is called (w32-has-winsock can
@@ -6675,19 +6643,19 @@ init_ntproc (void)
6675 fclose (stderr); 6643 fclose (stderr);
6676 6644
6677 if (stdin_save != INVALID_HANDLE_VALUE) 6645 if (stdin_save != INVALID_HANDLE_VALUE)
6678 _open_osfhandle ((long) stdin_save, O_TEXT); 6646 _open_osfhandle ((intptr_t) stdin_save, O_TEXT);
6679 else 6647 else
6680 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY); 6648 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
6681 _fdopen (0, "r"); 6649 _fdopen (0, "r");
6682 6650
6683 if (stdout_save != INVALID_HANDLE_VALUE) 6651 if (stdout_save != INVALID_HANDLE_VALUE)
6684 _open_osfhandle ((long) stdout_save, O_TEXT); 6652 _open_osfhandle ((intptr_t) stdout_save, O_TEXT);
6685 else 6653 else
6686 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY); 6654 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
6687 _fdopen (1, "w"); 6655 _fdopen (1, "w");
6688 6656
6689 if (stderr_save != INVALID_HANDLE_VALUE) 6657 if (stderr_save != INVALID_HANDLE_VALUE)
6690 _open_osfhandle ((long) stderr_save, O_TEXT); 6658 _open_osfhandle ((intptr_t) stderr_save, O_TEXT);
6691 else 6659 else
6692 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY); 6660 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
6693 _fdopen (2, "w"); 6661 _fdopen (2, "w");
@@ -6695,7 +6663,13 @@ init_ntproc (void)
6695 6663
6696 /* unfortunately, atexit depends on implementation of malloc */ 6664 /* unfortunately, atexit depends on implementation of malloc */
6697 /* atexit (term_ntproc); */ 6665 /* atexit (term_ntproc); */
6698 signal (SIGABRT, term_ntproc); 6666 if (!dumping)
6667 {
6668 /* Make sure we start with all signals unblocked. */
6669 sigprocmask (SIG_SETMASK, &initial_mask, NULL);
6670 signal (SIGABRT, term_ntproc);
6671 }
6672 init_timers ();
6699 6673
6700 /* determine which drives are fixed, for GetCachedVolumeInformation */ 6674 /* determine which drives are fixed, for GetCachedVolumeInformation */
6701 { 6675 {
@@ -6752,9 +6726,6 @@ globals_of_w32 (void)
6752 6726
6753 DEFSYM (QCloaded_from, ":loaded-from"); 6727 DEFSYM (QCloaded_from, ":loaded-from");
6754 6728
6755 Vlibrary_cache = Qnil;
6756 staticpro (&Vlibrary_cache);
6757
6758 g_b_init_is_windows_9x = 0; 6729 g_b_init_is_windows_9x = 0;
6759 g_b_init_open_process_token = 0; 6730 g_b_init_open_process_token = 0;
6760 g_b_init_get_token_information = 0; 6731 g_b_init_get_token_information = 0;
@@ -6805,7 +6776,7 @@ serial_open (char *port)
6805 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); 6776 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
6806 if (hnd == INVALID_HANDLE_VALUE) 6777 if (hnd == INVALID_HANDLE_VALUE)
6807 error ("Could not open %s", port); 6778 error ("Could not open %s", port);
6808 fd = (int) _open_osfhandle ((int) hnd, 0); 6779 fd = (int) _open_osfhandle ((intptr_t) hnd, 0);
6809 if (fd == -1) 6780 if (fd == -1)
6810 error ("Could not open %s", port); 6781 error ("Could not open %s", port);
6811 6782
diff --git a/src/w32.h b/src/w32.h
index b83b716b617..c4cfdf5fedd 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -133,15 +133,18 @@ extern void reset_standard_handles (int in, int out,
133/* Return the string resource associated with KEY of type TYPE. */ 133/* Return the string resource associated with KEY of type TYPE. */
134extern LPBYTE w32_get_resource (char * key, LPDWORD type); 134extern LPBYTE w32_get_resource (char * key, LPDWORD type);
135 135
136extern void init_ntproc (void); 136extern void init_ntproc (int);
137extern void term_ntproc (void); 137extern void term_ntproc (int);
138extern void globals_of_w32 (void); 138extern void globals_of_w32 (void);
139 139
140extern void term_timers (void);
141extern void init_timers (void);
142
140extern int _sys_read_ahead (int fd); 143extern int _sys_read_ahead (int fd);
141extern int _sys_wait_accept (int fd); 144extern int _sys_wait_accept (int fd);
142 145
143extern Lisp_Object Vlibrary_cache, QCloaded_from; 146extern Lisp_Object QCloaded_from;
144extern HMODULE w32_delayed_load (Lisp_Object, Lisp_Object); 147extern HMODULE w32_delayed_load (Lisp_Object);
145 148
146#ifdef HAVE_GNUTLS 149#ifdef HAVE_GNUTLS
147#include <gnutls/gnutls.h> 150#include <gnutls/gnutls.h>
diff --git a/src/w32fns.c b/src/w32fns.c
index cd48ae65e32..7f0e6d5e5bf 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -83,9 +83,7 @@ extern void w32_free_menu_strings (HWND);
83extern const char *map_w32_filename (const char *, const char **); 83extern const char *map_w32_filename (const char *, const char **);
84extern char * w32_strerror (int error_no); 84extern char * w32_strerror (int error_no);
85 85
86/* If non-zero, a w32 timer that, when it expires, displays an 86/* If non-NULL, a handle to a frame where to display the hourglass cursor. */
87 hourglass cursor on all frames. */
88static unsigned hourglass_timer = 0;
89static HWND hourglass_hwnd = NULL; 87static HWND hourglass_hwnd = NULL;
90 88
91#ifndef IDC_HAND 89#ifndef IDC_HAND
@@ -143,7 +141,7 @@ struct MONITOR_INFO
143}; 141};
144 142
145/* Reportedly, MSVC does not have this in its headers. */ 143/* Reportedly, MSVC does not have this in its headers. */
146#ifdef _MSC_VER 144#if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
147DECLARE_HANDLE(HMONITOR); 145DECLARE_HANDLE(HMONITOR);
148#endif 146#endif
149 147
@@ -183,7 +181,6 @@ unsigned int msh_mousewheel = 0;
183#define MOUSE_BUTTON_ID 1 181#define MOUSE_BUTTON_ID 1
184#define MOUSE_MOVE_ID 2 182#define MOUSE_MOVE_ID 2
185#define MENU_FREE_ID 3 183#define MENU_FREE_ID 3
186#define HOURGLASS_ID 4
187/* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP 184/* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
188 is received. */ 185 is received. */
189#define MENU_FREE_DELAY 1000 186#define MENU_FREE_DELAY 1000
@@ -399,7 +396,7 @@ if the entry is new. */)
399 396
400 XSETINT (rgb, RGB (XUINT (red), XUINT (green), XUINT (blue))); 397 XSETINT (rgb, RGB (XUINT (red), XUINT (green), XUINT (blue)));
401 398
402 BLOCK_INPUT; 399 block_input ();
403 400
404 /* replace existing entry in w32-color-map or add new entry. */ 401 /* replace existing entry in w32-color-map or add new entry. */
405 entry = Fassoc (name, Vw32_color_map); 402 entry = Fassoc (name, Vw32_color_map);
@@ -414,7 +411,7 @@ if the entry is new. */)
414 Fsetcdr (entry, rgb); 411 Fsetcdr (entry, rgb);
415 } 412 }
416 413
417 UNBLOCK_INPUT; 414 unblock_input ();
418 415
419 return (oldrgb); 416 return (oldrgb);
420} 417}
@@ -677,7 +674,7 @@ w32_default_color_map (void)
677 colormap_t *pc = w32_color_map; 674 colormap_t *pc = w32_color_map;
678 Lisp_Object cmap; 675 Lisp_Object cmap;
679 676
680 BLOCK_INPUT; 677 block_input ();
681 678
682 cmap = Qnil; 679 cmap = Qnil;
683 680
@@ -687,7 +684,7 @@ w32_default_color_map (void)
687 make_number (pc->colorref)), 684 make_number (pc->colorref)),
688 cmap); 685 cmap);
689 686
690 UNBLOCK_INPUT; 687 unblock_input ();
691 688
692 return (cmap); 689 return (cmap);
693} 690}
@@ -704,7 +701,7 @@ w32_color_map_lookup (char *colorname)
704{ 701{
705 Lisp_Object tail, ret = Qnil; 702 Lisp_Object tail, ret = Qnil;
706 703
707 BLOCK_INPUT; 704 block_input ();
708 705
709 for (tail = Vw32_color_map; CONSP (tail); tail = XCDR (tail)) 706 for (tail = Vw32_color_map; CONSP (tail); tail = XCDR (tail))
710 { 707 {
@@ -724,7 +721,7 @@ w32_color_map_lookup (char *colorname)
724 QUIT; 721 QUIT;
725 } 722 }
726 723
727 UNBLOCK_INPUT; 724 unblock_input ();
728 725
729 return ret; 726 return ret;
730} 727}
@@ -736,7 +733,7 @@ add_system_logical_colors_to_map (Lisp_Object *system_colors)
736 HKEY colors_key; 733 HKEY colors_key;
737 734
738 /* Other registry operations are done with input blocked. */ 735 /* Other registry operations are done with input blocked. */
739 BLOCK_INPUT; 736 block_input ();
740 737
741 /* Look for "Control Panel/Colors" under User and Machine registry 738 /* Look for "Control Panel/Colors" under User and Machine registry
742 settings. */ 739 settings. */
@@ -774,7 +771,7 @@ add_system_logical_colors_to_map (Lisp_Object *system_colors)
774 RegCloseKey (colors_key); 771 RegCloseKey (colors_key);
775 } 772 }
776 773
777 UNBLOCK_INPUT; 774 unblock_input ();
778} 775}
779 776
780 777
@@ -783,7 +780,7 @@ x_to_w32_color (char * colorname)
783{ 780{
784 register Lisp_Object ret = Qnil; 781 register Lisp_Object ret = Qnil;
785 782
786 BLOCK_INPUT; 783 block_input ();
787 784
788 if (colorname[0] == '#') 785 if (colorname[0] == '#')
789 { 786 {
@@ -836,7 +833,7 @@ x_to_w32_color (char * colorname)
836 pos += 0x8; 833 pos += 0x8;
837 if (i == 2) 834 if (i == 2)
838 { 835 {
839 UNBLOCK_INPUT; 836 unblock_input ();
840 XSETINT (ret, colorval); 837 XSETINT (ret, colorval);
841 return ret; 838 return ret;
842 } 839 }
@@ -890,7 +887,7 @@ x_to_w32_color (char * colorname)
890 { 887 {
891 if (*end != '\0') 888 if (*end != '\0')
892 break; 889 break;
893 UNBLOCK_INPUT; 890 unblock_input ();
894 XSETINT (ret, colorval); 891 XSETINT (ret, colorval);
895 return ret; 892 return ret;
896 } 893 }
@@ -932,7 +929,7 @@ x_to_w32_color (char * colorname)
932 { 929 {
933 if (*end != '\0') 930 if (*end != '\0')
934 break; 931 break;
935 UNBLOCK_INPUT; 932 unblock_input ();
936 XSETINT (ret, colorval); 933 XSETINT (ret, colorval);
937 return ret; 934 return ret;
938 } 935 }
@@ -967,7 +964,7 @@ x_to_w32_color (char * colorname)
967 } 964 }
968 } 965 }
969 966
970 UNBLOCK_INPUT; 967 unblock_input ();
971 return ret; 968 return ret;
972} 969}
973 970
@@ -1106,7 +1103,7 @@ gamma_correct (struct frame *f, COLORREF *color)
1106 If ALLOC is nonzero, allocate a new colormap cell. */ 1103 If ALLOC is nonzero, allocate a new colormap cell. */
1107 1104
1108int 1105int
1109w32_defined_color (FRAME_PTR f, char *color, XColor *color_def, int alloc) 1106w32_defined_color (FRAME_PTR f, const char *color, XColor *color_def, int alloc)
1110{ 1107{
1111 register Lisp_Object tem; 1108 register Lisp_Object tem;
1112 COLORREF w32_color_ref; 1109 COLORREF w32_color_ref;
@@ -1270,7 +1267,7 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1270 f->output_data.w32->mouse_pixel = FRAME_FOREGROUND_PIXEL (f); 1267 f->output_data.w32->mouse_pixel = FRAME_FOREGROUND_PIXEL (f);
1271 1268
1272#if 0 /* TODO : Mouse cursor customization. */ 1269#if 0 /* TODO : Mouse cursor customization. */
1273 BLOCK_INPUT; 1270 block_input ();
1274 1271
1275 /* It's not okay to crash if the user selects a screwy cursor. */ 1272 /* It's not okay to crash if the user selects a screwy cursor. */
1276 count = x_catch_errors (FRAME_W32_DISPLAY (f)); 1273 count = x_catch_errors (FRAME_W32_DISPLAY (f));
@@ -1393,7 +1390,7 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1393 f->output_data.w32->hand_cursor = hand_cursor; 1390 f->output_data.w32->hand_cursor = hand_cursor;
1394 1391
1395 XFlush (FRAME_W32_DISPLAY (f)); 1392 XFlush (FRAME_W32_DISPLAY (f));
1396 UNBLOCK_INPUT; 1393 unblock_input ();
1397 1394
1398 update_face_from_frame_parameter (f, Qmouse_color, arg); 1395 update_face_from_frame_parameter (f, Qmouse_color, arg);
1399#endif /* TODO */ 1396#endif /* TODO */
@@ -1425,12 +1422,12 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1425 1422
1426 if (FRAME_W32_WINDOW (f) != 0) 1423 if (FRAME_W32_WINDOW (f) != 0)
1427 { 1424 {
1428 BLOCK_INPUT; 1425 block_input ();
1429 /* Update frame's cursor_gc. */ 1426 /* Update frame's cursor_gc. */
1430 f->output_data.w32->cursor_gc->foreground = fore_pixel; 1427 f->output_data.w32->cursor_gc->foreground = fore_pixel;
1431 f->output_data.w32->cursor_gc->background = pixel; 1428 f->output_data.w32->cursor_gc->background = pixel;
1432 1429
1433 UNBLOCK_INPUT; 1430 unblock_input ();
1434 1431
1435 if (FRAME_VISIBLE_P (f)) 1432 if (FRAME_VISIBLE_P (f))
1436 { 1433 {
@@ -1501,16 +1498,16 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1501 if (SYMBOLP (arg) && SYMBOLP (oldval) && EQ (arg, oldval)) 1498 if (SYMBOLP (arg) && SYMBOLP (oldval) && EQ (arg, oldval))
1502 return; 1499 return;
1503 1500
1504 BLOCK_INPUT; 1501 block_input ();
1505 1502
1506 result = x_bitmap_icon (f, arg); 1503 result = x_bitmap_icon (f, arg);
1507 if (result) 1504 if (result)
1508 { 1505 {
1509 UNBLOCK_INPUT; 1506 unblock_input ();
1510 error ("No icon window available"); 1507 error ("No icon window available");
1511 } 1508 }
1512 1509
1513 UNBLOCK_INPUT; 1510 unblock_input ();
1514} 1511}
1515 1512
1516void 1513void
@@ -1530,7 +1527,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1530 if (f->output_data.w32->icon_bitmap != 0) 1527 if (f->output_data.w32->icon_bitmap != 0)
1531 return; 1528 return;
1532 1529
1533 BLOCK_INPUT; 1530 block_input ();
1534 1531
1535 result = x_text_icon (f, 1532 result = x_text_icon (f,
1536 SSDATA ((!NILP (f->icon_name) 1533 SSDATA ((!NILP (f->icon_name)
@@ -1541,7 +1538,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1541 1538
1542 if (result) 1539 if (result)
1543 { 1540 {
1544 UNBLOCK_INPUT; 1541 unblock_input ();
1545 error ("No icon window available"); 1542 error ("No icon window available");
1546 } 1543 }
1547 1544
@@ -1556,7 +1553,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1556 } 1553 }
1557 1554
1558 XFlush (FRAME_W32_DISPLAY (f)); 1555 XFlush (FRAME_W32_DISPLAY (f));
1559 UNBLOCK_INPUT; 1556 unblock_input ();
1560#endif 1557#endif
1561} 1558}
1562 1559
@@ -1658,13 +1655,13 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1658 int width = FRAME_PIXEL_WIDTH (f); 1655 int width = FRAME_PIXEL_WIDTH (f);
1659 int y = nlines * FRAME_LINE_HEIGHT (f); 1656 int y = nlines * FRAME_LINE_HEIGHT (f);
1660 1657
1661 BLOCK_INPUT; 1658 block_input ();
1662 { 1659 {
1663 HDC hdc = get_frame_dc (f); 1660 HDC hdc = get_frame_dc (f);
1664 w32_clear_area (f, hdc, 0, y, width, height); 1661 w32_clear_area (f, hdc, 0, y, width, height);
1665 release_frame_dc (f, hdc); 1662 release_frame_dc (f, hdc);
1666 } 1663 }
1667 UNBLOCK_INPUT; 1664 unblock_input ();
1668 1665
1669 if (WINDOWP (f->tool_bar_window)) 1666 if (WINDOWP (f->tool_bar_window))
1670 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); 1667 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
@@ -1732,9 +1729,9 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
1732 if (STRING_MULTIBYTE (name)) 1729 if (STRING_MULTIBYTE (name))
1733 name = ENCODE_SYSTEM (name); 1730 name = ENCODE_SYSTEM (name);
1734 1731
1735 BLOCK_INPUT; 1732 block_input ();
1736 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); 1733 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
1737 UNBLOCK_INPUT; 1734 unblock_input ();
1738 } 1735 }
1739} 1736}
1740 1737
@@ -1778,9 +1775,9 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
1778 if (STRING_MULTIBYTE (name)) 1775 if (STRING_MULTIBYTE (name))
1779 name = ENCODE_SYSTEM (name); 1776 name = ENCODE_SYSTEM (name);
1780 1777
1781 BLOCK_INPUT; 1778 block_input ();
1782 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); 1779 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
1783 UNBLOCK_INPUT; 1780 unblock_input ();
1784 } 1781 }
1785} 1782}
1786 1783
@@ -2333,13 +2330,39 @@ w32_name_of_message (UINT msg)
2333} 2330}
2334#endif /* EMACSDEBUG */ 2331#endif /* EMACSDEBUG */
2335 2332
2333/* Here's an overview of how Emacs input works on MS-Windows.
2334
2335 System messages are read and processed by w32_msg_pump below. This
2336 function runs in a separate thread. It handles a small number of
2337 custom WM_EMACS_* messages (posted by the main thread, look for
2338 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2339 is the main window procedure for the entire Emacs application.
2340
2341 w32_wnd_proc also runs in the same separate input thread. It
2342 handles some messages, mostly those that need GDI calls, by itself.
2343 For the others, it calls my_post_msg, which inserts the messages
2344 into the input queue serviced by w32_read_socket.
2345
2346 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2347 called synchronously from keyboard.c when it is known or suspected
2348 that some input is available. w32_read_socket either handles
2349 messages immediately, or converts them into Emacs input events and
2350 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2351 them and process them when read_char and its callers require
2352 input.
2353
2354 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2355 select(2) takes the place of w32_read_socket.
2356
2357 */
2358
2336/* Main message dispatch loop. */ 2359/* Main message dispatch loop. */
2337 2360
2338static void 2361static void
2339w32_msg_pump (deferred_msg * msg_buf) 2362w32_msg_pump (deferred_msg * msg_buf)
2340{ 2363{
2341 MSG msg; 2364 MSG msg;
2342 int result; 2365 WPARAM result;
2343 HWND focus_window; 2366 HWND focus_window;
2344 2367
2345 msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL); 2368 msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL);
@@ -2374,7 +2397,7 @@ w32_msg_pump (deferred_msg * msg_buf)
2374 /* Reply is not expected. */ 2397 /* Reply is not expected. */
2375 break; 2398 break;
2376 case WM_EMACS_SETKEYBOARDLAYOUT: 2399 case WM_EMACS_SETKEYBOARDLAYOUT:
2377 result = (int) ActivateKeyboardLayout ((HKL) msg.wParam, 0); 2400 result = (WPARAM) ActivateKeyboardLayout ((HKL) msg.wParam, 0);
2378 if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 2401 if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE,
2379 result, 0)) 2402 result, 0))
2380 emacs_abort (); 2403 emacs_abort ();
@@ -3401,12 +3424,6 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3401 menubar_in_use = 0; 3424 menubar_in_use = 0;
3402 } 3425 }
3403 } 3426 }
3404 else if (wParam == hourglass_timer)
3405 {
3406 KillTimer (hwnd, hourglass_timer);
3407 hourglass_timer = 0;
3408 w32_show_hourglass (x_window_to_frame (dpyinfo, hwnd));
3409 }
3410 return 0; 3427 return 0;
3411 3428
3412 case WM_NCACTIVATE: 3429 case WM_NCACTIVATE:
@@ -3984,7 +4001,7 @@ my_create_tip_window (struct frame *f)
3984static void 4001static void
3985w32_window (struct frame *f, long window_prompting, int minibuffer_only) 4002w32_window (struct frame *f, long window_prompting, int minibuffer_only)
3986{ 4003{
3987 BLOCK_INPUT; 4004 block_input ();
3988 4005
3989 /* Use the resource name as the top-level window name 4006 /* Use the resource name as the top-level window name
3990 for looking up resources. Make a non-Lisp copy 4007 for looking up resources. Make a non-Lisp copy
@@ -4016,7 +4033,7 @@ w32_window (struct frame *f, long window_prompting, int minibuffer_only)
4016 x_set_name (f, name, explicit); 4033 x_set_name (f, name, explicit);
4017 } 4034 }
4018 4035
4019 UNBLOCK_INPUT; 4036 unblock_input ();
4020 4037
4021 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) 4038 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
4022 initialize_frame_menubar (f); 4039 initialize_frame_menubar (f);
@@ -4047,7 +4064,7 @@ x_icon (struct frame *f, Lisp_Object parms)
4047 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) 4064 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
4048 error ("Both left and top icon corners of icon must be specified"); 4065 error ("Both left and top icon corners of icon must be specified");
4049 4066
4050 BLOCK_INPUT; 4067 block_input ();
4051 4068
4052 if (! EQ (icon_x, Qunbound)) 4069 if (! EQ (icon_x, Qunbound))
4053 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); 4070 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
@@ -4064,7 +4081,7 @@ x_icon (struct frame *f, Lisp_Object parms)
4064 : f->name))); 4081 : f->name)));
4065#endif 4082#endif
4066 4083
4067 UNBLOCK_INPUT; 4084 unblock_input ();
4068} 4085}
4069 4086
4070 4087
@@ -4073,7 +4090,7 @@ x_make_gc (struct frame *f)
4073{ 4090{
4074 XGCValues gc_values; 4091 XGCValues gc_values;
4075 4092
4076 BLOCK_INPUT; 4093 block_input ();
4077 4094
4078 /* Create the GC's of this frame. 4095 /* Create the GC's of this frame.
4079 Note that many default values are used. */ 4096 Note that many default values are used. */
@@ -4093,7 +4110,7 @@ x_make_gc (struct frame *f)
4093 f->output_data.w32->white_relief.gc = 0; 4110 f->output_data.w32->white_relief.gc = 0;
4094 f->output_data.w32->black_relief.gc = 0; 4111 f->output_data.w32->black_relief.gc = 0;
4095 4112
4096 UNBLOCK_INPUT; 4113 unblock_input ();
4097} 4114}
4098 4115
4099 4116
@@ -4439,9 +4456,9 @@ This function is an internal primitive--use `make-frame' instead. */)
4439 /* Tell the server what size and position, etc, we want, and how 4456 /* Tell the server what size and position, etc, we want, and how
4440 badly we want them. This should be done after we have the menu 4457 badly we want them. This should be done after we have the menu
4441 bar so that its size can be taken into account. */ 4458 bar so that its size can be taken into account. */
4442 BLOCK_INPUT; 4459 block_input ();
4443 x_wm_set_size_hint (f, window_prompting, 0); 4460 x_wm_set_size_hint (f, window_prompting, 0);
4444 UNBLOCK_INPUT; 4461 unblock_input ();
4445 4462
4446 /* Make the window appear on the frame and enable display, unless 4463 /* Make the window appear on the frame and enable display, unless
4447 the caller says not to. However, with explicit parent, Emacs 4464 the caller says not to. However, with explicit parent, Emacs
@@ -4990,11 +5007,11 @@ If DISPLAY is nil, that stands for the selected frame's display. */)
4990 if (dpyinfo->reference_count > 0) 5007 if (dpyinfo->reference_count > 0)
4991 error ("Display still has frames on it"); 5008 error ("Display still has frames on it");
4992 5009
4993 BLOCK_INPUT; 5010 block_input ();
4994 x_destroy_all_bitmaps (dpyinfo); 5011 x_destroy_all_bitmaps (dpyinfo);
4995 5012
4996 x_delete_display (dpyinfo); 5013 x_delete_display (dpyinfo);
4997 UNBLOCK_INPUT; 5014 unblock_input ();
4998 5015
4999 return Qnil; 5016 return Qnil;
5000} 5017}
@@ -5063,7 +5080,7 @@ FRAME. Default is to change on the edit X window. */)
5063 CHECK_STRING (prop); 5080 CHECK_STRING (prop);
5064 CHECK_STRING (value); 5081 CHECK_STRING (value);
5065 5082
5066 BLOCK_INPUT; 5083 block_input ();
5067 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); 5084 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
5068 XChangeProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), 5085 XChangeProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
5069 prop_atom, XA_STRING, 8, PropModeReplace, 5086 prop_atom, XA_STRING, 8, PropModeReplace,
@@ -5071,7 +5088,7 @@ FRAME. Default is to change on the edit X window. */)
5071 5088
5072 /* Make sure the property is set when we return. */ 5089 /* Make sure the property is set when we return. */
5073 XFlush (FRAME_W32_DISPLAY (f)); 5090 XFlush (FRAME_W32_DISPLAY (f));
5074 UNBLOCK_INPUT; 5091 unblock_input ();
5075 5092
5076 return value; 5093 return value;
5077} 5094}
@@ -5087,13 +5104,13 @@ FRAME nil or omitted means use the selected frame. Value is PROP. */)
5087 Atom prop_atom; 5104 Atom prop_atom;
5088 5105
5089 CHECK_STRING (prop); 5106 CHECK_STRING (prop);
5090 BLOCK_INPUT; 5107 block_input ();
5091 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); 5108 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
5092 XDeleteProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), prop_atom); 5109 XDeleteProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), prop_atom);
5093 5110
5094 /* Make sure the property is removed when we return. */ 5111 /* Make sure the property is removed when we return. */
5095 XFlush (FRAME_W32_DISPLAY (f)); 5112 XFlush (FRAME_W32_DISPLAY (f));
5096 UNBLOCK_INPUT; 5113 unblock_input ();
5097 5114
5098 return prop; 5115 return prop;
5099} 5116}
@@ -5129,7 +5146,7 @@ no value of TYPE (always string in the MS Windows case). */)
5129 unsigned long actual_size, bytes_remaining; 5146 unsigned long actual_size, bytes_remaining;
5130 5147
5131 CHECK_STRING (prop); 5148 CHECK_STRING (prop);
5132 BLOCK_INPUT; 5149 block_input ();
5133 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); 5150 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
5134 rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), 5151 rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
5135 prop_atom, 0, 0, False, XA_STRING, 5152 prop_atom, 0, 0, False, XA_STRING,
@@ -5154,7 +5171,7 @@ no value of TYPE (always string in the MS Windows case). */)
5154 XFree (tmp_data); 5171 XFree (tmp_data);
5155 } 5172 }
5156 5173
5157 UNBLOCK_INPUT; 5174 unblock_input ();
5158 5175
5159 return prop_value; 5176 return prop_value;
5160 5177
@@ -5168,66 +5185,50 @@ no value of TYPE (always string in the MS Windows case). */)
5168 Busy cursor 5185 Busy cursor
5169 ***********************************************************************/ 5186 ***********************************************************************/
5170 5187
5171/* Default number of seconds to wait before displaying an hourglass
5172 cursor. Duplicated from xdisp.c, but cannot use the version there
5173 due to lack of atimers on w32. */
5174#define DEFAULT_HOURGLASS_DELAY 1
5175
5176/* Cancel a currently active hourglass timer, and start a new one. */
5177
5178void 5188void
5179start_hourglass (void) 5189w32_note_current_window (void)
5180{ 5190{
5181 DWORD delay;
5182 int secs, msecs = 0;
5183 struct frame * f = SELECTED_FRAME (); 5191 struct frame * f = SELECTED_FRAME ();
5184 5192
5185 /* No cursors on non GUI frames. */
5186 if (!FRAME_W32_P (f)) 5193 if (!FRAME_W32_P (f))
5187 return; 5194 return;
5188 5195
5189 cancel_hourglass ();
5190
5191 if (INTEGERP (Vhourglass_delay)
5192 && XINT (Vhourglass_delay) > 0)
5193 secs = XFASTINT (Vhourglass_delay);
5194 else if (FLOATP (Vhourglass_delay)
5195 && XFLOAT_DATA (Vhourglass_delay) > 0)
5196 {
5197 Lisp_Object tem;
5198 tem = Ftruncate (Vhourglass_delay, Qnil);
5199 secs = XFASTINT (tem);
5200 msecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000;
5201 }
5202 else
5203 secs = DEFAULT_HOURGLASS_DELAY;
5204
5205 delay = secs * 1000 + msecs;
5206 hourglass_hwnd = FRAME_W32_WINDOW (f); 5196 hourglass_hwnd = FRAME_W32_WINDOW (f);
5207 hourglass_timer = SetTimer (hourglass_hwnd, HOURGLASS_ID, delay, NULL);
5208} 5197}
5209 5198
5210
5211/* Cancel the hourglass cursor timer if active, hide an hourglass
5212 cursor if shown. */
5213
5214void 5199void
5215cancel_hourglass (void) 5200show_hourglass (struct atimer *timer)
5216{ 5201{
5217 if (hourglass_timer) 5202 struct frame *f;
5218 {
5219 KillTimer (hourglass_hwnd, hourglass_timer);
5220 hourglass_timer = 0;
5221 }
5222 5203
5223 if (hourglass_shown_p) 5204 hourglass_atimer = NULL;
5224 w32_hide_hourglass (); 5205
5206 block_input ();
5207 f = x_window_to_frame (&one_w32_display_info,
5208 hourglass_hwnd);
5209
5210 if (f)
5211 f->output_data.w32->hourglass_p = 0;
5212 else
5213 f = SELECTED_FRAME ();
5214
5215 if (!FRAME_W32_P (f))
5216 return;
5217
5218 w32_show_hourglass (f);
5219 unblock_input ();
5225} 5220}
5226 5221
5222void
5223hide_hourglass (void)
5224{
5225 block_input ();
5226 w32_hide_hourglass ();
5227 unblock_input ();
5228}
5227 5229
5228/* Timer function of hourglass_timer.
5229 5230
5230 Display an hourglass cursor. Set the hourglass_p flag in display info 5231/* Display an hourglass cursor. Set the hourglass_p flag in display info
5231 to indicate that an hourglass cursor is shown. */ 5232 to indicate that an hourglass cursor is shown. */
5232 5233
5233static void 5234static void
@@ -5477,9 +5478,9 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5477 f->left_fringe_width = 0; 5478 f->left_fringe_width = 0;
5478 f->right_fringe_width = 0; 5479 f->right_fringe_width = 0;
5479 5480
5480 BLOCK_INPUT; 5481 block_input ();
5481 my_create_tip_window (f); 5482 my_create_tip_window (f);
5482 UNBLOCK_INPUT; 5483 unblock_input ();
5483 5484
5484 x_make_gc (f); 5485 x_make_gc (f);
5485 5486
@@ -5585,11 +5586,11 @@ compute_tip_xy (struct frame *f,
5585 max_x = x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f)); 5586 max_x = x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f));
5586 max_y = x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f)); 5587 max_y = x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f));
5587 5588
5588 BLOCK_INPUT; 5589 block_input ();
5589 GetCursorPos (&pt); 5590 GetCursorPos (&pt);
5590 *root_x = pt.x; 5591 *root_x = pt.x;
5591 *root_y = pt.y; 5592 *root_y = pt.y;
5592 UNBLOCK_INPUT; 5593 unblock_input ();
5593 5594
5594 /* If multiple monitor support is available, constrain the tip onto 5595 /* If multiple monitor support is available, constrain the tip onto
5595 the current monitor. This improves the above by allowing negative 5596 the current monitor. This improves the above by allowing negative
@@ -5724,7 +5725,7 @@ Text larger than the specified size is clipped. */)
5724 call1 (Qcancel_timer, timer); 5725 call1 (Qcancel_timer, timer);
5725 } 5726 }
5726 5727
5727 BLOCK_INPUT; 5728 block_input ();
5728 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), 5729 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
5729 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); 5730 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
5730 5731
@@ -5738,7 +5739,7 @@ Text larger than the specified size is clipped. */)
5738 0, 0, 0, 0, 5739 0, 0, 0, 0,
5739 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 5740 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
5740 5741
5741 UNBLOCK_INPUT; 5742 unblock_input ();
5742 goto start_timer; 5743 goto start_timer;
5743 } 5744 }
5744 } 5745 }
@@ -5765,7 +5766,7 @@ Text larger than the specified size is clipped. */)
5765 5766
5766 /* Block input until the tip has been fully drawn, to avoid crashes 5767 /* Block input until the tip has been fully drawn, to avoid crashes
5767 when drawing tips in menus. */ 5768 when drawing tips in menus. */
5768 BLOCK_INPUT; 5769 block_input ();
5769 5770
5770 /* Create a frame for the tooltip, and record it in the global 5771 /* Create a frame for the tooltip, and record it in the global
5771 variable tip_frame. */ 5772 variable tip_frame. */
@@ -5937,7 +5938,7 @@ Text larger than the specified size is clipped. */)
5937 w->must_be_updated_p = 1; 5938 w->must_be_updated_p = 1;
5938 update_single_window (w, 1); 5939 update_single_window (w, 1);
5939 5940
5940 UNBLOCK_INPUT; 5941 unblock_input ();
5941 5942
5942 /* Restore original current buffer. */ 5943 /* Restore original current buffer. */
5943 set_buffer_internal_1 (old_buffer); 5944 set_buffer_internal_1 (old_buffer);
@@ -6077,7 +6078,7 @@ Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6077selection box, if specified. If MUSTMATCH is non-nil, the returned file 6078selection box, if specified. If MUSTMATCH is non-nil, the returned file
6078or directory must exist. 6079or directory must exist.
6079 6080
6080This function is only defined on MS Windows, and X Windows with the 6081This function is only defined on NS, MS Windows, and X Windows with the
6081Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. 6082Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6082Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 6083Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6083 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 6084 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
@@ -6215,7 +6216,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6215 { 6216 {
6216 int count = SPECPDL_INDEX (); 6217 int count = SPECPDL_INDEX ();
6217 specbind (Qinhibit_redisplay, Qt); 6218 specbind (Qinhibit_redisplay, Qt);
6218 BLOCK_INPUT; 6219 block_input ();
6219 file_details->lpfnHook = file_dialog_callback; 6220 file_details->lpfnHook = file_dialog_callback;
6220 6221
6221#ifdef NTGUI_UNICODE 6222#ifdef NTGUI_UNICODE
@@ -6223,7 +6224,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6223#else /* !NTGUI_UNICODE */ 6224#else /* !NTGUI_UNICODE */
6224 file_opened = GetOpenFileNameA (file_details); 6225 file_opened = GetOpenFileNameA (file_details);
6225#endif /* NTGUI_UNICODE */ 6226#endif /* NTGUI_UNICODE */
6226 UNBLOCK_INPUT; 6227 unblock_input ();
6227 unbind_to (count, Qnil); 6228 unbind_to (count, Qnil);
6228 } 6229 }
6229 6230
@@ -7613,7 +7614,6 @@ only be necessary if the default setting causes problems. */);
7613 7614
7614 check_window_system_func = check_w32; 7615 check_window_system_func = check_w32;
7615 7616
7616 hourglass_timer = 0;
7617 hourglass_hwnd = NULL; 7617 hourglass_hwnd = NULL;
7618 7618
7619 defsubr (&Sx_show_tip); 7619 defsubr (&Sx_show_tip);
diff --git a/src/w32gui.h b/src/w32gui.h
index 1ea185bfaa1..0da8de97f23 100644
--- a/src/w32gui.h
+++ b/src/w32gui.h
@@ -118,9 +118,6 @@ extern int nCmdShow;
118#define PBaseSize (1L << 8) /* program specified base for incrementing */ 118#define PBaseSize (1L << 8) /* program specified base for incrementing */
119#define PWinGravity (1L << 9) /* program specified window gravity */ 119#define PWinGravity (1L << 9) /* program specified window gravity */
120 120
121extern int XParseGeometry (char *, int *, int *, unsigned *, unsigned *);
122
123
124typedef struct { 121typedef struct {
125 int x, y; 122 int x, y;
126 unsigned width, height; 123 unsigned width, height;
diff --git a/src/w32heap.c b/src/w32heap.c
index e7d4c29e043..bc8aa356923 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -26,7 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include "w32heap.h" 26#include "w32heap.h"
27#include "lisp.h" /* for VALMASK */ 27#include "lisp.h" /* for VALMASK */
28 28
29#define RVA_TO_PTR(rva) ((unsigned char *)((DWORD)(rva) + (DWORD)GetModuleHandle (NULL))) 29#define RVA_TO_PTR(rva) ((unsigned char *)((DWORD_PTR)(rva) + (DWORD_PTR)GetModuleHandle (NULL)))
30 30
31/* This gives us the page size and the size of the allocation unit on NT. */ 31/* This gives us the page size and the size of the allocation unit on NT. */
32SYSTEM_INFO sysinfo_cache; 32SYSTEM_INFO sysinfo_cache;
@@ -35,6 +35,8 @@ SYSTEM_INFO sysinfo_cache;
35extern unsigned long syspage_mask; 35extern unsigned long syspage_mask;
36OSVERSIONINFO osinfo_cache; 36OSVERSIONINFO osinfo_cache;
37 37
38size_t syspage_mask = 0;
39
38/* The major and minor versions of NT. */ 40/* The major and minor versions of NT. */
39int w32_major_version; 41int w32_major_version;
40int w32_minor_version; 42int w32_minor_version;
@@ -58,7 +60,7 @@ PIMAGE_SECTION_HEADER preload_heap_section;
58unsigned char *data_region_base = NULL; 60unsigned char *data_region_base = NULL;
59unsigned char *data_region_end = NULL; 61unsigned char *data_region_end = NULL;
60unsigned char *real_data_region_end = NULL; 62unsigned char *real_data_region_end = NULL;
61unsigned long reserved_heap_size = 0; 63size_t reserved_heap_size = 0;
62 64
63/* The start of the data segment. */ 65/* The start of the data segment. */
64unsigned char * 66unsigned char *
@@ -82,16 +84,20 @@ allocate_heap (void)
82 the preload heap section up to the usable address limit. Since GNU 84 the preload heap section up to the usable address limit. Since GNU
83 malloc can handle gaps in the memory it gets from sbrk, we can 85 malloc can handle gaps in the memory it gets from sbrk, we can
84 simply set the sbrk pointer to the base of the new heap region. */ 86 simply set the sbrk pointer to the base of the new heap region. */
85 unsigned long base = 87 DWORD_PTR base =
86 ROUND_UP ((RVA_TO_PTR (preload_heap_section->VirtualAddress) 88 ROUND_UP ((RVA_TO_PTR (preload_heap_section->VirtualAddress)
87 + preload_heap_section->Misc.VirtualSize), 89 + preload_heap_section->Misc.VirtualSize),
88 get_allocation_unit ()); 90 get_allocation_unit ());
89 unsigned long end = 1 << VALBITS; /* 256MB */ 91 DWORD_PTR end = ((unsigned __int64)1) << VALBITS; /* 256MB */
90 void *ptr = NULL; 92 void *ptr = NULL;
91 93
92 while (!ptr && (base < end)) 94 while (!ptr && (base < end))
93 { 95 {
96#ifdef _WIN64
97 reserved_heap_size = min(end - base, 0x4000000000i64); /* Limit to 256Gb */
98#else
94 reserved_heap_size = end - base; 99 reserved_heap_size = end - base;
100#endif
95 ptr = VirtualAlloc ((void *) base, 101 ptr = VirtualAlloc ((void *) base,
96 get_reserved_heap_size (), 102 get_reserved_heap_size (),
97 MEM_RESERVE, 103 MEM_RESERVE,
@@ -105,7 +111,11 @@ allocate_heap (void)
105static char * 111static char *
106allocate_heap (void) 112allocate_heap (void)
107{ 113{
108 unsigned long size = 0x80000000; /* start by asking for 2GB */ 114#ifdef _WIN64
115 size_t size = 0x4000000000i64; /* start by asking for 32GB */
116#else
117 size_t size = 0x80000000; /* start by asking for 2GB */
118#endif
109 void *ptr = NULL; 119 void *ptr = NULL;
110 120
111 while (!ptr && size > 0x00100000) 121 while (!ptr && size > 0x00100000)
@@ -127,17 +137,17 @@ allocate_heap (void)
127 be the address of the _start_ (not end) of the new block in case of 137 be the address of the _start_ (not end) of the new block in case of
128 success, and zero (not -1) in case of failure. */ 138 success, and zero (not -1) in case of failure. */
129void * 139void *
130sbrk (unsigned long increment) 140sbrk (ptrdiff_t increment)
131{ 141{
132 void *result; 142 void *result;
133 long size = (long) increment; 143 ptrdiff_t size = increment;
134 144
135 result = data_region_end; 145 result = data_region_end;
136 146
137 /* If size is negative, shrink the heap by decommitting pages. */ 147 /* If size is negative, shrink the heap by decommitting pages. */
138 if (size < 0) 148 if (size < 0)
139 { 149 {
140 int new_size; 150 ptrdiff_t new_size;
141 unsigned char *new_data_region_end; 151 unsigned char *new_data_region_end;
142 152
143 size = -size; 153 size = -size;
@@ -150,7 +160,7 @@ sbrk (unsigned long increment)
150 partial deallocation [cga]. */ 160 partial deallocation [cga]. */
151 new_data_region_end = (data_region_end - size); 161 new_data_region_end = (data_region_end - size);
152 new_data_region_end = (unsigned char *) 162 new_data_region_end = (unsigned char *)
153 ((long) (new_data_region_end + syspage_mask) & ~syspage_mask); 163 ((DWORD_PTR) (new_data_region_end + syspage_mask) & ~syspage_mask);
154 new_size = real_data_region_end - new_data_region_end; 164 new_size = real_data_region_end - new_data_region_end;
155 real_data_region_end = new_data_region_end; 165 real_data_region_end = new_data_region_end;
156 if (new_size > 0) 166 if (new_size > 0)
@@ -181,7 +191,7 @@ sbrk (unsigned long increment)
181 /* We really only commit full pages, so record where 191 /* We really only commit full pages, so record where
182 the real end of committed memory is [cga]. */ 192 the real end of committed memory is [cga]. */
183 real_data_region_end = (unsigned char *) 193 real_data_region_end = (unsigned char *)
184 ((long) (data_region_end + syspage_mask) & ~syspage_mask); 194 ((DWORD_PTR) (data_region_end + syspage_mask) & ~syspage_mask);
185 } 195 }
186 196
187 return result; 197 return result;
@@ -206,7 +216,7 @@ init_heap (void)
206 PIMAGE_NT_HEADERS nt_header; 216 PIMAGE_NT_HEADERS nt_header;
207 217
208 dos_header = (PIMAGE_DOS_HEADER) RVA_TO_PTR (0); 218 dos_header = (PIMAGE_DOS_HEADER) RVA_TO_PTR (0);
209 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + 219 nt_header = (PIMAGE_NT_HEADERS) (((DWORD_PTR) dos_header) +
210 dos_header->e_lfanew); 220 dos_header->e_lfanew);
211 preload_heap_section = find_section ("EMHEAP", nt_header); 221 preload_heap_section = find_section ("EMHEAP", nt_header);
212 222
@@ -222,7 +232,7 @@ init_heap (void)
222#if !USE_LSB_TAG 232#if !USE_LSB_TAG
223 /* Ensure that the addresses don't use the upper tag bits since 233 /* Ensure that the addresses don't use the upper tag bits since
224 the Lisp type goes there. */ 234 the Lisp type goes there. */
225 if (((unsigned long) data_region_base & ~VALMASK) != 0) 235 if (((DWORD_PTR) data_region_base & ~VALMASK) != 0)
226 { 236 {
227 printf ("Error: The heap was allocated in upper memory.\n"); 237 printf ("Error: The heap was allocated in upper memory.\n");
228 exit (1); 238 exit (1);
@@ -245,13 +255,13 @@ init_heap (void)
245 255
246/* Round the heap up to the given alignment. */ 256/* Round the heap up to the given alignment. */
247void 257void
248round_heap (unsigned long align) 258round_heap (size_t align)
249{ 259{
250 unsigned long needs_to_be; 260 DWORD_PTR needs_to_be;
251 unsigned long need_to_alloc; 261 DWORD_PTR need_to_alloc;
252 262
253 needs_to_be = (unsigned long) ROUND_UP (get_heap_end (), align); 263 needs_to_be = (DWORD_PTR) ROUND_UP (get_heap_end (), align);
254 need_to_alloc = needs_to_be - (unsigned long) get_heap_end (); 264 need_to_alloc = needs_to_be - (DWORD_PTR) get_heap_end ();
255 265
256 if (need_to_alloc) 266 if (need_to_alloc)
257 sbrk (need_to_alloc); 267 sbrk (need_to_alloc);
diff --git a/src/w32heap.h b/src/w32heap.h
index fda3c58bf01..aae4845b4cc 100644
--- a/src/w32heap.h
+++ b/src/w32heap.h
@@ -24,8 +24,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 24
25#include <windows.h> 25#include <windows.h>
26 26
27#define ROUND_UP(p, align) (((DWORD)(p) + (align)-1) & ~((align)-1)) 27#define ROUND_UP(p, align) (((DWORD_PTR)(p) + (align)-1) & ~((DWORD_PTR)(align)-1))
28#define ROUND_DOWN(p, align) ((DWORD)(p) & ~((align)-1)) 28#define ROUND_DOWN(p, align) ((DWORD_PTR)(p) & ~((DWORD_PTR)(align)-1))
29 29
30/* 30/*
31 * Heap related stuff. 31 * Heap related stuff.
@@ -42,7 +42,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
42 42
43extern unsigned char *get_data_start (void); 43extern unsigned char *get_data_start (void);
44extern unsigned char *get_data_end (void); 44extern unsigned char *get_data_end (void);
45extern unsigned long reserved_heap_size; 45extern size_t reserved_heap_size;
46extern SYSTEM_INFO sysinfo_cache; 46extern SYSTEM_INFO sysinfo_cache;
47extern OSVERSIONINFO osinfo_cache; 47extern OSVERSIONINFO osinfo_cache;
48extern BOOL using_dynamic_heap; 48extern BOOL using_dynamic_heap;
@@ -58,13 +58,13 @@ enum {
58extern int os_subtype; 58extern int os_subtype;
59 59
60/* Emulation of Unix sbrk(). */ 60/* Emulation of Unix sbrk(). */
61extern void *sbrk (unsigned long size); 61extern void *sbrk (ptrdiff_t size);
62 62
63/* Initialize heap structures for sbrk on startup. */ 63/* Initialize heap structures for sbrk on startup. */
64extern void init_heap (void); 64extern void init_heap (void);
65 65
66/* Round the heap to this size. */ 66/* Round the heap to this size. */
67extern void round_heap (unsigned long size); 67extern void round_heap (size_t size);
68 68
69/* Cache system info, e.g., the NT page size. */ 69/* Cache system info, e.g., the NT page size. */
70extern void cache_system_info (void); 70extern void cache_system_info (void);
@@ -89,6 +89,6 @@ IMAGE_SECTION_HEADER * find_section (char * name, IMAGE_NT_HEADERS * nt_header);
89 89
90/* Return pointer to section header for section containing the given 90/* Return pointer to section header for section containing the given
91 relative virtual address. */ 91 relative virtual address. */
92IMAGE_SECTION_HEADER * rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header); 92IMAGE_SECTION_HEADER * rva_to_section (DWORD_PTR rva, IMAGE_NT_HEADERS * nt_header);
93 93
94#endif /* NTHEAP_H_ */ 94#endif /* NTHEAP_H_ */
diff --git a/src/w32inevt.c b/src/w32inevt.c
index a036fcbefe1..c322d3a0b44 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -401,7 +401,7 @@ w32_console_mouse_position (FRAME_PTR *f,
401 Lisp_Object *y, 401 Lisp_Object *y,
402 Time *time) 402 Time *time)
403{ 403{
404 BLOCK_INPUT; 404 block_input ();
405 405
406 insist = insist; 406 insist = insist;
407 407
@@ -414,7 +414,7 @@ w32_console_mouse_position (FRAME_PTR *f,
414 XSETINT (*y, movement_pos.Y); 414 XSETINT (*y, movement_pos.Y);
415 *time = movement_time; 415 *time = movement_time;
416 416
417 UNBLOCK_INPUT; 417 unblock_input ();
418} 418}
419 419
420/* Remember mouse motion and notify emacs. */ 420/* Remember mouse motion and notify emacs. */
@@ -578,20 +578,12 @@ maybe_generate_resize_event (void)
578 578
579int 579int
580w32_console_read_socket (struct terminal *terminal, 580w32_console_read_socket (struct terminal *terminal,
581 int expected,
582 struct input_event *hold_quit) 581 struct input_event *hold_quit)
583{ 582{
584 int nev, ret = 0, add; 583 int nev, add;
585 int isdead; 584 int isdead;
586 585
587 if (interrupt_input_blocked) 586 block_input ();
588 {
589 interrupt_input_pending = 1;
590 return -1;
591 }
592
593 interrupt_input_pending = 0;
594 BLOCK_INPUT;
595 587
596 for (;;) 588 for (;;)
597 { 589 {
@@ -601,8 +593,7 @@ w32_console_read_socket (struct terminal *terminal,
601 /* If nev == -1, there was some kind of error 593 /* If nev == -1, there was some kind of error
602 If nev == 0 then waitp must be zero and no events were available 594 If nev == 0 then waitp must be zero and no events were available
603 so return. */ 595 so return. */
604 UNBLOCK_INPUT; 596 break;
605 return nev;
606 } 597 }
607 598
608 while (nev > 0) 599 while (nev > 0)
@@ -646,9 +637,6 @@ w32_console_read_socket (struct terminal *terminal,
646 queue_ptr++; 637 queue_ptr++;
647 nev--; 638 nev--;
648 } 639 }
649
650 if (ret > 0 || expected == 0)
651 break;
652 } 640 }
653 641
654 /* We don't get told about changes in the window size (only the buffer 642 /* We don't get told about changes in the window size (only the buffer
@@ -657,6 +645,6 @@ w32_console_read_socket (struct terminal *terminal,
657 if (!w32_use_full_screen_buffer) 645 if (!w32_use_full_screen_buffer)
658 maybe_generate_resize_event (); 646 maybe_generate_resize_event ();
659 647
660 UNBLOCK_INPUT; 648 unblock_input ();
661 return ret; 649 return nev;
662} 650}
diff --git a/src/w32inevt.h b/src/w32inevt.h
index c874e58ef39..319688b877b 100644
--- a/src/w32inevt.h
+++ b/src/w32inevt.h
@@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 21
22extern int w32_console_unicode_input; 22extern int w32_console_unicode_input;
23 23
24extern int w32_console_read_socket (struct terminal *term, int numchars, 24extern int w32_console_read_socket (struct terminal *term,
25 struct input_event *hold_quit); 25 struct input_event *hold_quit);
26extern void w32_console_mouse_position (FRAME_PTR *f, int insist, 26extern void w32_console_mouse_position (FRAME_PTR *f, int insist,
27 Lisp_Object *bar_window, 27 Lisp_Object *bar_window,
diff --git a/src/w32menu.c b/src/w32menu.c
index 4d820471f17..40ee82d42d5 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -100,7 +100,7 @@ MessageBoxW_Proc unicode_message_box = NULL;
100 100
101Lisp_Object Qdebug_on_next_call; 101Lisp_Object Qdebug_on_next_call;
102 102
103void set_frame_menubar (FRAME_PTR, int, int); 103void set_frame_menubar (FRAME_PTR, bool, bool);
104 104
105#ifdef HAVE_DIALOGS 105#ifdef HAVE_DIALOGS
106static Lisp_Object w32_dialog_show (FRAME_PTR, int, Lisp_Object, char**); 106static Lisp_Object w32_dialog_show (FRAME_PTR, int, Lisp_Object, char**);
@@ -237,9 +237,9 @@ otherwise it is "Question". */)
237 list_of_panes (Fcons (contents, Qnil)); 237 list_of_panes (Fcons (contents, Qnil));
238 238
239 /* Display them in a dialog box. */ 239 /* Display them in a dialog box. */
240 BLOCK_INPUT; 240 block_input ();
241 selection = w32_dialog_show (f, 0, title, header, &error_name); 241 selection = w32_dialog_show (f, 0, title, header, &error_name);
242 UNBLOCK_INPUT; 242 unblock_input ();
243 243
244 discard_menu_items (); 244 discard_menu_items ();
245 FRAME_X_DISPLAY_INFO (f)->grabbed = 0; 245 FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
@@ -372,7 +372,7 @@ menubar_selection_callback (FRAME_PTR f, void * client_data)
372 it is set the first time this is called, from initialize_frame_menubar. */ 372 it is set the first time this is called, from initialize_frame_menubar. */
373 373
374void 374void
375set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) 375set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
376{ 376{
377 HMENU menubar_widget = f->output_data.w32->menubar_widget; 377 HMENU menubar_widget = f->output_data.w32->menubar_widget;
378 Lisp_Object items; 378 Lisp_Object items;
@@ -587,7 +587,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
587 587
588 /* Create or update the menu bar widget. */ 588 /* Create or update the menu bar widget. */
589 589
590 BLOCK_INPUT; 590 block_input ();
591 591
592 if (menubar_widget) 592 if (menubar_widget)
593 { 593 {
@@ -617,7 +617,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
617 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); 617 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
618 } 618 }
619 619
620 UNBLOCK_INPUT; 620 unblock_input ();
621} 621}
622 622
623/* Called from Fx_create_frame to create the initial menubar of a frame 623/* Called from Fx_create_frame to create the initial menubar of a frame
@@ -640,7 +640,7 @@ initialize_frame_menubar (FRAME_PTR f)
640void 640void
641free_frame_menubar (FRAME_PTR f) 641free_frame_menubar (FRAME_PTR f)
642{ 642{
643 BLOCK_INPUT; 643 block_input ();
644 644
645 { 645 {
646 HMENU old = GetMenu (FRAME_W32_WINDOW (f)); 646 HMENU old = GetMenu (FRAME_W32_WINDOW (f));
@@ -649,7 +649,7 @@ free_frame_menubar (FRAME_PTR f)
649 DestroyMenu (old); 649 DestroyMenu (old);
650 } 650 }
651 651
652 UNBLOCK_INPUT; 652 unblock_input ();
653} 653}
654 654
655 655
@@ -1503,8 +1503,8 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1503 1503
1504 utf8to16 (out_string, utf8_len, utf16_string); 1504 utf8to16 (out_string, utf8_len, utf16_string);
1505 return_value = unicode_append_menu (menu, fuFlags, 1505 return_value = unicode_append_menu (menu, fuFlags,
1506 item != NULL ? (UINT) item 1506 item != NULL ? (UINT_PTR) item
1507 : (UINT) wv->call_data, 1507 : (UINT_PTR) wv->call_data,
1508 utf16_string); 1508 utf16_string);
1509 1509
1510#ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */ 1510#ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */
@@ -1518,7 +1518,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1518 of minor importance compared with menus not working at all. */ 1518 of minor importance compared with menus not working at all. */
1519 return_value = 1519 return_value =
1520 AppendMenu (menu, fuFlags, 1520 AppendMenu (menu, fuFlags,
1521 item != NULL ? (UINT) item: (UINT) wv->call_data, 1521 item != NULL ? (UINT_PTR) item: (UINT_PTR) wv->call_data,
1522 out_string); 1522 out_string);
1523 /* Don't use Unicode menus in future, unless this is Windows 1523 /* Don't use Unicode menus in future, unless this is Windows
1524 NT or later, where a failure of AppendMenuW does NOT mean 1524 NT or later, where a failure of AppendMenuW does NOT mean
@@ -1536,7 +1536,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1536 return_value = 1536 return_value =
1537 AppendMenu (menu, 1537 AppendMenu (menu,
1538 fuFlags, 1538 fuFlags,
1539 item != NULL ? (UINT) item : (UINT) wv->call_data, 1539 item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data,
1540 out_string ); 1540 out_string );
1541 } 1541 }
1542 1542
@@ -1573,7 +1573,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1573 } 1573 }
1574 1574
1575 set_menu_item_info (menu, 1575 set_menu_item_info (menu,
1576 item != NULL ? (UINT) item : (UINT) wv->call_data, 1576 item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data,
1577 FALSE, &info); 1577 FALSE, &info);
1578 } 1578 }
1579 } 1579 }
diff --git a/src/w32proc.c b/src/w32proc.c
index 27d93e4a7b4..7d0039d0d5e 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -62,7 +62,7 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD);
62 62
63#define RVA_TO_PTR(var,section,filedata) \ 63#define RVA_TO_PTR(var,section,filedata) \
64 ((void *)((section)->PointerToRawData \ 64 ((void *)((section)->PointerToRawData \
65 + ((DWORD)(var) - (section)->VirtualAddress) \ 65 + ((DWORD_PTR)(var) - (section)->VirtualAddress) \
66 + (filedata).file_base)) 66 + (filedata).file_base))
67 67
68Lisp_Object Qhigh, Qlow; 68Lisp_Object Qhigh, Qlow;
@@ -72,19 +72,39 @@ typedef void (_CALLBACK_ *signal_handler) (int);
72/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */ 72/* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */
73static signal_handler sig_handlers[NSIG]; 73static signal_handler sig_handlers[NSIG];
74 74
75/* Fake signal implementation to record the SIGCHLD handler. */ 75static sigset_t sig_mask;
76
77static CRITICAL_SECTION crit_sig;
78
79/* Improve on the CRT 'signal' implementation so that we could record
80 the SIGCHLD handler and fake interval timers. */
76signal_handler 81signal_handler
77sys_signal (int sig, signal_handler handler) 82sys_signal (int sig, signal_handler handler)
78{ 83{
79 signal_handler old; 84 signal_handler old;
80 85
81 if (sig != SIGCHLD) 86 /* SIGCHLD is needed for supporting subprocesses, see sys_kill
87 below. SIGALRM and SIGPROF are used by setitimer. All the
88 others are the only ones supported by the MS runtime. */
89 if (!(sig == SIGCHLD || sig == SIGSEGV || sig == SIGILL
90 || sig == SIGFPE || sig == SIGABRT || sig == SIGTERM
91 || sig == SIGALRM || sig == SIGPROF))
82 { 92 {
83 errno = EINVAL; 93 errno = EINVAL;
84 return SIG_ERR; 94 return SIG_ERR;
85 } 95 }
86 old = sig_handlers[sig]; 96 old = sig_handlers[sig];
87 sig_handlers[sig] = handler; 97 /* SIGABRT is treated specially because w32.c installs term_ntproc
98 as its handler, so we don't want to override that afterwards.
99 Aborting Emacs works specially anyway: either by calling
100 emacs_abort directly or through terminate_due_to_signal, which
101 calls emacs_abort through emacs_raise. */
102 if (!(sig == SIGABRT && old == term_ntproc))
103 {
104 sig_handlers[sig] = handler;
105 if (!(sig == SIGCHLD || sig == SIGALRM || sig == SIGPROF))
106 signal (sig, handler);
107 }
88 return old; 108 return old;
89} 109}
90 110
@@ -92,25 +112,562 @@ sys_signal (int sig, signal_handler handler)
92int 112int
93sigaction (int sig, const struct sigaction *act, struct sigaction *oact) 113sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
94{ 114{
95 signal_handler old; 115 signal_handler old = SIG_DFL;
116 int retval = 0;
117
118 if (act)
119 old = sys_signal (sig, act->sa_handler);
120 else if (oact)
121 old = sig_handlers[sig];
96 122
97 if (sig != SIGCHLD) 123 if (old == SIG_ERR)
98 { 124 {
99 errno = EINVAL; 125 errno = EINVAL;
100 return -1; 126 retval = -1;
101 } 127 }
102 old = sig_handlers[sig];
103 if (act)
104 sig_handlers[sig] = act->sa_handler;
105 if (oact) 128 if (oact)
106 { 129 {
107 oact->sa_handler = old; 130 oact->sa_handler = old;
108 oact->sa_flags = 0; 131 oact->sa_flags = 0;
109 oact->sa_mask = empty_mask; 132 oact->sa_mask = empty_mask;
110 } 133 }
134 return retval;
135}
136
137/* Emulate signal sets and blocking of signals used by timers. */
138
139int
140sigemptyset (sigset_t *set)
141{
142 *set = 0;
143 return 0;
144}
145
146int
147sigaddset (sigset_t *set, int signo)
148{
149 if (!set)
150 {
151 errno = EINVAL;
152 return -1;
153 }
154 if (signo < 0 || signo >= NSIG)
155 {
156 errno = EINVAL;
157 return -1;
158 }
159
160 *set |= (1U << signo);
161
162 return 0;
163}
164
165int
166sigfillset (sigset_t *set)
167{
168 if (!set)
169 {
170 errno = EINVAL;
171 return -1;
172 }
173
174 *set = 0xFFFFFFFF;
175 return 0;
176}
177
178int
179sigprocmask (int how, const sigset_t *set, sigset_t *oset)
180{
181 if (!(how == SIG_BLOCK || how == SIG_UNBLOCK || how == SIG_SETMASK))
182 {
183 errno = EINVAL;
184 return -1;
185 }
186
187 if (oset)
188 *oset = sig_mask;
189
190 if (!set)
191 return 0;
192
193 switch (how)
194 {
195 case SIG_BLOCK:
196 sig_mask |= *set;
197 break;
198 case SIG_SETMASK:
199 sig_mask = *set;
200 break;
201 case SIG_UNBLOCK:
202 /* FIXME: Catch signals that are blocked and reissue them when
203 they are unblocked. Important for SIGALRM and SIGPROF only. */
204 sig_mask &= ~(*set);
205 break;
206 }
207
208 return 0;
209}
210
211int
212pthread_sigmask (int how, const sigset_t *set, sigset_t *oset)
213{
214 if (sigprocmask (how, set, oset) == -1)
215 return EINVAL;
216 return 0;
217}
218
219int
220sigismember (const sigset_t *set, int signo)
221{
222 if (signo < 0 || signo >= NSIG)
223 {
224 errno = EINVAL;
225 return -1;
226 }
227 if (signo > sizeof (*set) * BITS_PER_CHAR)
228 emacs_abort ();
229
230 return (*set & (1U << signo)) != 0;
231}
232
233int
234setpgrp (int pid, int gid)
235{
236 return 0;
237}
238
239/* Emulations of interval timers.
240
241 Limitations: only ITIMER_REAL and ITIMER_PROF are supported.
242
243 Implementation: a separate thread is started for each timer type,
244 the thread calls the appropriate signal handler when the timer
245 expires, after stopping the thread which installed the timer. */
246
247/* FIXME: clock_t counts overflow after 49 days, need to handle the
248 wrap-around. */
249struct itimer_data {
250 clock_t expire;
251 clock_t reload;
252 int terminate;
253 int type;
254 HANDLE caller_thread;
255 HANDLE timer_thread;
256};
257
258static clock_t ticks_now;
259static struct itimer_data real_itimer, prof_itimer;
260static clock_t clocks_min;
261/* If non-zero, itimers are disabled. Used during shutdown, when we
262 delete the critical sections used by the timer threads. */
263static int disable_itimers;
264
265static CRITICAL_SECTION crit_real, crit_prof;
266
267#define MAX_SINGLE_SLEEP 30
268
269static DWORD WINAPI
270timer_loop (LPVOID arg)
271{
272 struct itimer_data *itimer = (struct itimer_data *)arg;
273 int which = itimer->type;
274 int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF;
275 CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
276 const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / CLOCKS_PER_SEC;
277 int new_count = 0;
278
279 while (1)
280 {
281 DWORD sleep_time;
282 signal_handler handler;
283 clock_t now, expire, reload;
284
285 /* Load new values if requested by setitimer. */
286 EnterCriticalSection (crit);
287 expire = itimer->expire;
288 reload = itimer->reload;
289 LeaveCriticalSection (crit);
290 if (itimer->terminate)
291 return 0;
292
293 if (itimer->expire == 0)
294 {
295 /* We are idle. */
296 Sleep (max_sleep);
297 continue;
298 }
299
300 expire = itimer->expire;
301 if (expire > (now = clock ()))
302 sleep_time = expire - now;
303 else
304 sleep_time = 0;
305 /* Don't sleep too long at a time, to be able to see the
306 termination flag without too long a delay. */
307 while (sleep_time > max_sleep)
308 {
309 if (itimer->terminate)
310 return 0;
311 Sleep (max_sleep);
312 expire = itimer->expire;
313 sleep_time = (expire > (now = clock ())) ? expire - now : 0;
314 }
315 if (itimer->terminate)
316 return 0;
317 if (sleep_time > 0)
318 {
319 Sleep (sleep_time * 1000 / CLOCKS_PER_SEC);
320 /* Always sleep past the expiration time, to make sure we
321 never call the handler _before_ the expiration time,
322 always slightly after it. Sleep(5) makes sure we don't
323 hog the CPU by calling 'clock' with high frequency, and
324 also let other threads work. */
325 while (clock () < expire)
326 Sleep (5);
327 }
328
329 if (itimer->expire == 0)
330 continue;
331
332 /* Time's up. */
333 handler = sig_handlers[sig];
334 if (!(handler == SIG_DFL || handler == SIG_IGN || handler == SIG_ERR)
335 /* FIXME: Don't ignore masked signals. Instead, record that
336 they happened and reissue them when the signal is
337 unblocked. */
338 && !sigismember (&sig_mask, sig)
339 /* Simulate masking of SIGALRM and SIGPROF when processing
340 fatal signals. */
341 && !fatal_error_in_progress
342 && itimer->caller_thread)
343 {
344 /* Simulate a signal delivered to the thread which installed
345 the timer, by suspending that thread while the handler
346 runs. */
347 DWORD result = SuspendThread (itimer->caller_thread);
348
349 if (result == (DWORD)-1)
350 return 2;
351
352 handler (sig);
353 ResumeThread (itimer->caller_thread);
354 }
355
356 if (itimer->expire == 0)
357 continue;
358
359 /* Update expiration time and loop. */
360 EnterCriticalSection (crit);
361 expire = itimer->expire;
362 reload = itimer->reload;
363 if (reload > 0)
364 {
365 now = clock ();
366 if (expire <= now)
367 {
368 clock_t lag = now - expire;
369
370 /* If we missed some opportunities (presumably while
371 sleeping or while the signal handler ran), skip
372 them. */
373 if (lag > reload)
374 expire = now - (lag % reload);
375
376 expire += reload;
377 }
378 }
379 else
380 expire = 0; /* become idle */
381 itimer->expire = expire;
382 LeaveCriticalSection (crit);
383 }
384 return 0;
385}
386
387static void
388stop_timer_thread (int which)
389{
390 struct itimer_data *itimer =
391 (which == ITIMER_REAL) ? &real_itimer : &prof_itimer;
392 int i;
393 DWORD err, exit_code = 255;
394 BOOL status;
395
396 /* Signal the thread that it should terminate. */
397 itimer->terminate = 1;
398
399 if (itimer->timer_thread == NULL)
400 return;
401
402 /* Wait for the timer thread to terminate voluntarily, then kill it
403 if it doesn't. This loop waits twice more than the maximum
404 amount of time a timer thread sleeps, see above. */
405 for (i = 0; i < MAX_SINGLE_SLEEP / 5; i++)
406 {
407 if (!((status = GetExitCodeThread (itimer->timer_thread, &exit_code))
408 && exit_code == STILL_ACTIVE))
409 break;
410 Sleep (10);
411 }
412 if ((status == FALSE && (err = GetLastError ()) == ERROR_INVALID_HANDLE)
413 || exit_code == STILL_ACTIVE)
414 {
415 if (!(status == FALSE && err == ERROR_INVALID_HANDLE))
416 TerminateThread (itimer->timer_thread, 0);
417 }
418
419 /* Clean up. */
420 CloseHandle (itimer->timer_thread);
421 itimer->timer_thread = NULL;
422 if (itimer->caller_thread)
423 {
424 CloseHandle (itimer->caller_thread);
425 itimer->caller_thread = NULL;
426 }
427}
428
429/* This is called at shutdown time from term_ntproc. */
430void
431term_timers (void)
432{
433 if (real_itimer.timer_thread)
434 stop_timer_thread (ITIMER_REAL);
435 if (prof_itimer.timer_thread)
436 stop_timer_thread (ITIMER_PROF);
437
438 /* We are going to delete the critical sections, so timers cannot
439 work after this. */
440 disable_itimers = 1;
441
442 DeleteCriticalSection (&crit_real);
443 DeleteCriticalSection (&crit_prof);
444 DeleteCriticalSection (&crit_sig);
445}
446
447/* This is called at initialization time from init_ntproc. */
448void
449init_timers (void)
450{
451 /* Make sure we start with zeroed out itimer structures, since
452 dumping may have left there traces of threads long dead. */
453 memset (&real_itimer, 0, sizeof real_itimer);
454 memset (&prof_itimer, 0, sizeof prof_itimer);
455
456 InitializeCriticalSection (&crit_real);
457 InitializeCriticalSection (&crit_prof);
458 InitializeCriticalSection (&crit_sig);
459
460 disable_itimers = 0;
461}
462
463static int
464start_timer_thread (int which)
465{
466 DWORD exit_code;
467 struct itimer_data *itimer =
468 (which == ITIMER_REAL) ? &real_itimer : &prof_itimer;
469
470 if (itimer->timer_thread
471 && GetExitCodeThread (itimer->timer_thread, &exit_code)
472 && exit_code == STILL_ACTIVE)
473 return 0;
474
475 /* Start a new thread. */
476 if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
477 GetCurrentProcess (), &itimer->caller_thread, 0,
478 FALSE, DUPLICATE_SAME_ACCESS))
479 {
480 errno = ESRCH;
481 return -1;
482 }
483
484 itimer->terminate = 0;
485 itimer->type = which;
486 /* Request that no more than 64KB of stack be reserved for this
487 thread, to avoid reserving too much memory, which would get in
488 the way of threads we start to wait for subprocesses. See also
489 new_child below. */
490 itimer->timer_thread = CreateThread (NULL, 64 * 1024, timer_loop,
491 (void *)itimer, 0x00010000, NULL);
492
493 if (!itimer->timer_thread)
494 {
495 CloseHandle (itimer->caller_thread);
496 itimer->caller_thread = NULL;
497 errno = EAGAIN;
498 return -1;
499 }
500
501 /* This is needed to make sure that the timer thread running for
502 profiling gets CPU as soon as the Sleep call terminates. */
503 if (which == ITIMER_PROF)
504 SetThreadPriority (itimer->caller_thread, THREAD_PRIORITY_TIME_CRITICAL);
505
111 return 0; 506 return 0;
112} 507}
113 508
509/* Most of the code of getitimer and setitimer (but not of their
510 subroutines) was shamelessly stolen from itimer.c in the DJGPP
511 library, see www.delorie.com/djgpp. */
512int
513getitimer (int which, struct itimerval *value)
514{
515 volatile clock_t *t_expire;
516 volatile clock_t *t_reload;
517 clock_t expire, reload;
518 __int64 usecs;
519 CRITICAL_SECTION *crit;
520
521 if (disable_itimers)
522 return -1;
523
524 ticks_now = clock ();
525
526 if (!value)
527 {
528 errno = EFAULT;
529 return -1;
530 }
531
532 if (which != ITIMER_REAL && which != ITIMER_PROF)
533 {
534 errno = EINVAL;
535 return -1;
536 }
537
538 t_expire = (which == ITIMER_REAL) ? &real_itimer.expire: &prof_itimer.expire;
539 t_reload = (which == ITIMER_REAL) ? &real_itimer.reload: &prof_itimer.reload;
540 crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
541
542 EnterCriticalSection (crit);
543 reload = *t_reload;
544 expire = *t_expire;
545 LeaveCriticalSection (crit);
546
547 if (expire)
548 expire -= ticks_now;
549
550 value->it_value.tv_sec = expire / CLOCKS_PER_SEC;
551 usecs = (expire % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC;
552 value->it_value.tv_usec = usecs;
553 value->it_interval.tv_sec = reload / CLOCKS_PER_SEC;
554 usecs = (reload % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC;
555 value->it_interval.tv_usec= usecs;
556
557 return 0;
558}
559
560int
561setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
562{
563 volatile clock_t *t_expire, *t_reload;
564 clock_t expire, reload, expire_old, reload_old;
565 __int64 usecs;
566 CRITICAL_SECTION *crit;
567
568 if (disable_itimers)
569 return -1;
570
571 /* Posix systems expect timer values smaller than the resolution of
572 the system clock be rounded up to the clock resolution. First
573 time we are called, measure the clock tick resolution. */
574 if (!clocks_min)
575 {
576 clock_t t1, t2;
577
578 for (t1 = clock (); (t2 = clock ()) == t1; )
579 ;
580 clocks_min = t2 - t1;
581 }
582
583 if (ovalue)
584 {
585 if (getitimer (which, ovalue)) /* also sets ticks_now */
586 return -1; /* errno already set */
587 }
588 else
589 ticks_now = clock ();
590
591 if (which != ITIMER_REAL && which != ITIMER_PROF)
592 {
593 errno = EINVAL;
594 return -1;
595 }
596
597 t_expire =
598 (which == ITIMER_REAL) ? &real_itimer.expire : &prof_itimer.expire;
599 t_reload =
600 (which == ITIMER_REAL) ? &real_itimer.reload : &prof_itimer.reload;
601
602 crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
603
604 if (!value
605 || (value->it_value.tv_sec == 0 && value->it_value.tv_usec == 0))
606 {
607 EnterCriticalSection (crit);
608 /* Disable the timer. */
609 *t_expire = 0;
610 *t_reload = 0;
611 LeaveCriticalSection (crit);
612 return 0;
613 }
614
615 reload = value->it_interval.tv_sec * CLOCKS_PER_SEC;
616
617 usecs = value->it_interval.tv_usec;
618 if (value->it_interval.tv_sec == 0
619 && usecs && usecs * CLOCKS_PER_SEC < clocks_min * 1000000)
620 reload = clocks_min;
621 else
622 {
623 usecs *= CLOCKS_PER_SEC;
624 reload += usecs / 1000000;
625 }
626
627 expire = value->it_value.tv_sec * CLOCKS_PER_SEC;
628 usecs = value->it_value.tv_usec;
629 if (value->it_value.tv_sec == 0
630 && usecs * CLOCKS_PER_SEC < clocks_min * 1000000)
631 expire = clocks_min;
632 else
633 {
634 usecs *= CLOCKS_PER_SEC;
635 expire += usecs / 1000000;
636 }
637
638 expire += ticks_now;
639
640 EnterCriticalSection (crit);
641 expire_old = *t_expire;
642 reload_old = *t_reload;
643 if (!(expire == expire_old && reload == reload_old))
644 {
645 *t_reload = reload;
646 *t_expire = expire;
647 }
648 LeaveCriticalSection (crit);
649
650 return start_timer_thread (which);
651}
652
653int
654alarm (int seconds)
655{
656#ifdef HAVE_SETITIMER
657 struct itimerval new_values, old_values;
658
659 new_values.it_value.tv_sec = seconds;
660 new_values.it_value.tv_usec = 0;
661 new_values.it_interval.tv_sec = new_values.it_interval.tv_usec = 0;
662
663 if (setitimer (ITIMER_REAL, &new_values, &old_values) < 0)
664 return 0;
665 return old_values.it_value.tv_sec;
666#else
667 return seconds;
668#endif
669}
670
114/* Defined in <process.h> which conflicts with the local copy */ 671/* Defined in <process.h> which conflicts with the local copy */
115#define _P_NOWAIT 1 672#define _P_NOWAIT 1
116 673
@@ -561,7 +1118,7 @@ get_result:
561 else if (WIFSIGNALED (retval)) 1118 else if (WIFSIGNALED (retval))
562 { 1119 {
563 int code = WTERMSIG (retval); 1120 int code = WTERMSIG (retval);
564 char *signame; 1121 const char *signame;
565 1122
566 synchronize_system_messages_locale (); 1123 synchronize_system_messages_locale ();
567 signame = strsignal (code); 1124 signame = strsignal (code);
@@ -636,7 +1193,7 @@ w32_executable_type (char * filename,
636 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) 1193 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
637 goto unwind; 1194 goto unwind;
638 1195
639 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew); 1196 nt_header = (PIMAGE_NT_HEADERS) ((unsigned char *) dos_header + dos_header->e_lfanew);
640 1197
641 if ((char *) nt_header > (char *) dos_header + executable.size) 1198 if ((char *) nt_header > (char *) dos_header + executable.size)
642 { 1199 {
@@ -1406,6 +1963,7 @@ find_child_console (HWND hwnd, LPARAM arg)
1406 return TRUE; 1963 return TRUE;
1407} 1964}
1408 1965
1966/* Emulate 'kill', but only for other processes. */
1409int 1967int
1410sys_kill (int pid, int sig) 1968sys_kill (int pid, int sig)
1411{ 1969{
@@ -1414,9 +1972,6 @@ sys_kill (int pid, int sig)
1414 int need_to_free = 0; 1972 int need_to_free = 0;
1415 int rc = 0; 1973 int rc = 0;
1416 1974
1417 if (pid == getpid () && sig == SIGABRT)
1418 emacs_abort ();
1419
1420 /* Only handle signals that will result in the process dying */ 1975 /* Only handle signals that will result in the process dying */
1421 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP) 1976 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
1422 { 1977 {
@@ -1427,6 +1982,11 @@ sys_kill (int pid, int sig)
1427 cp = find_child_pid (pid); 1982 cp = find_child_pid (pid);
1428 if (cp == NULL) 1983 if (cp == NULL)
1429 { 1984 {
1985 /* We were passed a PID of something other than our subprocess.
1986 If that is our own PID, we will send to ourself a message to
1987 close the selected frame, which does not necessarily
1988 terminates Emacs. But then we are not supposed to call
1989 sys_kill with our own PID. */
1430 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid); 1990 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
1431 if (proc_hand == NULL) 1991 if (proc_hand == NULL)
1432 { 1992 {
diff --git a/src/w32reg.c b/src/w32reg.c
index 8a6a3c853b1..8b6c76503a6 100644
--- a/src/w32reg.c
+++ b/src/w32reg.c
@@ -84,7 +84,7 @@ w32_get_string_resource (char *name, char *class, DWORD dwexptype)
84 84
85 trykey: 85 trykey:
86 86
87 BLOCK_INPUT; 87 block_input ();
88 88
89 /* Check both the current user and the local machine to see if we have 89 /* Check both the current user and the local machine to see if we have
90 any resources */ 90 any resources */
@@ -115,7 +115,7 @@ w32_get_string_resource (char *name, char *class, DWORD dwexptype)
115 RegCloseKey (hrootkey); 115 RegCloseKey (hrootkey);
116 } 116 }
117 117
118 UNBLOCK_INPUT; 118 unblock_input ();
119 119
120 if (!ok) 120 if (!ok)
121 { 121 {
diff --git a/src/w32select.c b/src/w32select.c
index b616f232eea..1690c3b7824 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -396,7 +396,7 @@ run_protected (Lisp_Object (*code) (Lisp_Object), Lisp_Object arg)
396 extern int waiting_for_input; /* from keyboard.c */ 396 extern int waiting_for_input; /* from keyboard.c */
397 int owfi; 397 int owfi;
398 398
399 BLOCK_INPUT; 399 block_input ();
400 400
401 /* Fsignal calls emacs_abort () if it sees that waiting_for_input is 401 /* Fsignal calls emacs_abort () if it sees that waiting_for_input is
402 set. */ 402 set. */
@@ -407,7 +407,7 @@ run_protected (Lisp_Object (*code) (Lisp_Object), Lisp_Object arg)
407 407
408 waiting_for_input = owfi; 408 waiting_for_input = owfi;
409 409
410 UNBLOCK_INPUT; 410 unblock_input ();
411} 411}
412 412
413static Lisp_Object 413static Lisp_Object
@@ -479,7 +479,10 @@ term_w32select (void)
479{ 479{
480 /* This is needed to trigger WM_RENDERALLFORMATS. */ 480 /* This is needed to trigger WM_RENDERALLFORMATS. */
481 if (clipboard_owner != NULL) 481 if (clipboard_owner != NULL)
482 DestroyWindow (clipboard_owner); 482 {
483 DestroyWindow (clipboard_owner);
484 clipboard_owner = NULL;
485 }
483} 486}
484 487
485static void 488static void
@@ -699,7 +702,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
699 current_num_nls = 0; 702 current_num_nls = 0;
700 current_requires_encoding = 0; 703 current_requires_encoding = 0;
701 704
702 BLOCK_INPUT; 705 block_input ();
703 706
704 /* Check for non-ASCII characters. While we are at it, count the 707 /* Check for non-ASCII characters. While we are at it, count the
705 number of LFs, so we know how many CRs we will have to add later 708 number of LFs, so we know how many CRs we will have to add later
@@ -787,7 +790,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
787 current_coding_system = Qnil; 790 current_coding_system = Qnil;
788 791
789 done: 792 done:
790 UNBLOCK_INPUT; 793 unblock_input ();
791 794
792 return (ok ? string : Qnil); 795 return (ok ? string : Qnil);
793} 796}
@@ -815,7 +818,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
815 setup_config (); 818 setup_config ();
816 actual_clipboard_type = cfg_clipboard_type; 819 actual_clipboard_type = cfg_clipboard_type;
817 820
818 BLOCK_INPUT; 821 block_input ();
819 822
820 if (!OpenClipboard (clipboard_owner)) 823 if (!OpenClipboard (clipboard_owner))
821 goto done; 824 goto done;
@@ -1005,7 +1008,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
1005 CloseClipboard (); 1008 CloseClipboard ();
1006 1009
1007 done: 1010 done:
1008 UNBLOCK_INPUT; 1011 unblock_input ();
1009 1012
1010 return (ret); 1013 return (ret);
1011} 1014}
diff --git a/src/w32term.c b/src/w32term.c
index af075955e2c..627ff54394b 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -109,7 +109,7 @@ 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 !defined (GLYPHSET) && _WIN32_WINNT < 0x500 112#if _WIN32_WINNT < 0x0500
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 115
@@ -211,7 +211,7 @@ static void w32_define_cursor (Window, Cursor);
211 211
212void x_lower_frame (struct frame *); 212void x_lower_frame (struct frame *);
213void x_scroll_bar_clear (struct frame *); 213void x_scroll_bar_clear (struct frame *);
214void x_wm_set_size_hint (struct frame *, long, int); 214void x_wm_set_size_hint (struct frame *, long, bool);
215void x_raise_frame (struct frame *); 215void x_raise_frame (struct frame *);
216void x_set_window_size (struct frame *, int, int, int); 216void x_set_window_size (struct frame *, int, int, int);
217void x_wm_set_window_state (struct frame *, int); 217void x_wm_set_window_state (struct frame *, int);
@@ -374,7 +374,11 @@ w32_draw_underwave (struct glyph_string *s, COLORREF color)
374 374
375 /* Find and set clipping rectangle */ 375 /* Find and set clipping rectangle */
376 376
377 wave_clip = (XRectangle){ x0, y0, width, wave_height }; 377 wave_clip.x = x0;
378 wave_clip.y = y0;
379 wave_clip.width = width;
380 wave_clip.height = wave_height;
381
378 get_glyph_string_clip_rect (s, &w32_string_clip); 382 get_glyph_string_clip_rect (s, &w32_string_clip);
379 CONVERT_TO_XRECT (string_clip, w32_string_clip); 383 CONVERT_TO_XRECT (string_clip, w32_string_clip);
380 384
@@ -577,7 +581,7 @@ x_update_window_begin (struct window *w)
577 updated_window = w; 581 updated_window = w;
578 set_output_cursor (&w->cursor); 582 set_output_cursor (&w->cursor);
579 583
580 BLOCK_INPUT; 584 block_input ();
581 585
582 if (f == hlinfo->mouse_face_mouse_frame) 586 if (f == hlinfo->mouse_face_mouse_frame)
583 { 587 {
@@ -616,7 +620,7 @@ x_update_window_begin (struct window *w)
616#endif /* 0 */ 620#endif /* 0 */
617 } 621 }
618 622
619 UNBLOCK_INPUT; 623 unblock_input ();
620} 624}
621 625
622/* Draw a vertical window border from (x,y0) to (x,y1) */ 626/* Draw a vertical window border from (x,y0) to (x,y1) */
@@ -666,7 +670,7 @@ x_update_window_end (struct window *w, int cursor_on_p,
666 670
667 if (!w->pseudo_window_p) 671 if (!w->pseudo_window_p)
668 { 672 {
669 BLOCK_INPUT; 673 block_input ();
670 674
671 if (cursor_on_p) 675 if (cursor_on_p)
672 display_and_set_cursor (w, 1, output_cursor.hpos, 676 display_and_set_cursor (w, 1, output_cursor.hpos,
@@ -676,7 +680,7 @@ x_update_window_end (struct window *w, int cursor_on_p,
676 if (draw_window_fringes (w, 1)) 680 if (draw_window_fringes (w, 1))
677 x_draw_vertical_border (w); 681 x_draw_vertical_border (w);
678 682
679 UNBLOCK_INPUT; 683 unblock_input ();
680 } 684 }
681 685
682 /* If a row with mouse-face was overwritten, arrange for 686 /* If a row with mouse-face was overwritten, arrange for
@@ -728,13 +732,13 @@ w32_frame_up_to_date (struct frame *f)
728 if (hlinfo->mouse_face_deferred_gc 732 if (hlinfo->mouse_face_deferred_gc
729 || f == hlinfo->mouse_face_mouse_frame) 733 || f == hlinfo->mouse_face_mouse_frame)
730 { 734 {
731 BLOCK_INPUT; 735 block_input ();
732 if (hlinfo->mouse_face_mouse_frame) 736 if (hlinfo->mouse_face_mouse_frame)
733 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, 737 note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
734 hlinfo->mouse_face_mouse_x, 738 hlinfo->mouse_face_mouse_x,
735 hlinfo->mouse_face_mouse_y); 739 hlinfo->mouse_face_mouse_y);
736 hlinfo->mouse_face_deferred_gc = 0; 740 hlinfo->mouse_face_deferred_gc = 0;
737 UNBLOCK_INPUT; 741 unblock_input ();
738 } 742 }
739 } 743 }
740} 744}
@@ -775,7 +779,7 @@ x_after_update_window_line (struct glyph_row *desired_row)
775 { 779 {
776 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); 780 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
777 781
778 BLOCK_INPUT; 782 block_input ();
779 { 783 {
780 HDC hdc = get_frame_dc (f); 784 HDC hdc = get_frame_dc (f);
781 w32_clear_area (f, hdc, 0, y, width, height); 785 w32_clear_area (f, hdc, 0, y, width, height);
@@ -783,7 +787,7 @@ x_after_update_window_line (struct glyph_row *desired_row)
783 y, width, height); 787 y, width, height);
784 release_frame_dc (f, hdc); 788 release_frame_dc (f, hdc);
785 } 789 }
786 UNBLOCK_INPUT; 790 unblock_input ();
787 } 791 }
788} 792}
789 793
@@ -2660,7 +2664,7 @@ x_clear_frame (struct frame *f)
2660 2664
2661 /* We don't set the output cursor here because there will always 2665 /* We don't set the output cursor here because there will always
2662 follow an explicit cursor_to. */ 2666 follow an explicit cursor_to. */
2663 BLOCK_INPUT; 2667 block_input ();
2664 2668
2665 w32_clear_window (f); 2669 w32_clear_window (f);
2666 2670
@@ -2668,7 +2672,7 @@ x_clear_frame (struct frame *f)
2668 colors or something like that, then they should be notified. */ 2672 colors or something like that, then they should be notified. */
2669 x_scroll_bar_clear (f); 2673 x_scroll_bar_clear (f);
2670 2674
2671 UNBLOCK_INPUT; 2675 unblock_input ();
2672} 2676}
2673 2677
2674 2678
@@ -2677,7 +2681,7 @@ x_clear_frame (struct frame *f)
2677static void 2681static void
2678w32_ring_bell (struct frame *f) 2682w32_ring_bell (struct frame *f)
2679{ 2683{
2680 BLOCK_INPUT; 2684 block_input ();
2681 2685
2682 if (FRAME_W32_P (f) && visible_bell) 2686 if (FRAME_W32_P (f) && visible_bell)
2683 { 2687 {
@@ -2694,7 +2698,7 @@ w32_ring_bell (struct frame *f)
2694 else 2698 else
2695 w32_sys_ring_bell (f); 2699 w32_sys_ring_bell (f);
2696 2700
2697 UNBLOCK_INPUT; 2701 unblock_input ();
2698} 2702}
2699 2703
2700 2704
@@ -2793,7 +2797,7 @@ x_scroll_run (struct window *w, struct run *run)
2793 expect_dirty = CreateRectRgn (x, y, x + width, to_y); 2797 expect_dirty = CreateRectRgn (x, y, x + width, to_y);
2794 } 2798 }
2795 2799
2796 BLOCK_INPUT; 2800 block_input ();
2797 2801
2798 /* Cursor off. Will be switched on again in x_update_window_end. */ 2802 /* Cursor off. Will be switched on again in x_update_window_end. */
2799 updated_window = w; 2803 updated_window = w;
@@ -2827,7 +2831,7 @@ x_scroll_run (struct window *w, struct run *run)
2827 DeleteObject (combined); 2831 DeleteObject (combined);
2828 } 2832 }
2829 2833
2830 UNBLOCK_INPUT; 2834 unblock_input ();
2831 DeleteObject (expect_dirty); 2835 DeleteObject (expect_dirty);
2832} 2836}
2833 2837
@@ -3012,9 +3016,9 @@ x_get_keysym_name (int keysym)
3012 /* Make static so we can always return it */ 3016 /* Make static so we can always return it */
3013 static char value[100]; 3017 static char value[100];
3014 3018
3015 BLOCK_INPUT; 3019 block_input ();
3016 GetKeyNameText (keysym, value, 100); 3020 GetKeyNameText (keysym, value, 100);
3017 UNBLOCK_INPUT; 3021 unblock_input ();
3018 3022
3019 return value; 3023 return value;
3020} 3024}
@@ -3322,7 +3326,7 @@ w32_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
3322{ 3326{
3323 FRAME_PTR f1; 3327 FRAME_PTR f1;
3324 3328
3325 BLOCK_INPUT; 3329 block_input ();
3326 3330
3327 if (! NILP (last_mouse_scroll_bar) && insist == 0) 3331 if (! NILP (last_mouse_scroll_bar) && insist == 0)
3328 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); 3332 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
@@ -3396,7 +3400,7 @@ w32_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
3396 } 3400 }
3397 } 3401 }
3398 3402
3399 UNBLOCK_INPUT; 3403 unblock_input ();
3400} 3404}
3401 3405
3402 3406
@@ -3494,12 +3498,12 @@ w32_set_scroll_bar_thumb (struct scroll_bar *bar,
3494 if (draggingp) 3498 if (draggingp)
3495 { 3499 {
3496 int near_bottom_p; 3500 int near_bottom_p;
3497 BLOCK_INPUT; 3501 block_input ();
3498 si.cbSize = sizeof (si); 3502 si.cbSize = sizeof (si);
3499 si.fMask = SIF_POS | SIF_PAGE; 3503 si.fMask = SIF_POS | SIF_PAGE;
3500 GetScrollInfo (w, SB_CTL, &si); 3504 GetScrollInfo (w, SB_CTL, &si);
3501 near_bottom_p = si.nPos + si.nPage >= range; 3505 near_bottom_p = si.nPos + si.nPage >= range;
3502 UNBLOCK_INPUT; 3506 unblock_input ();
3503 if (!near_bottom_p) 3507 if (!near_bottom_p)
3504 return; 3508 return;
3505 } 3509 }
@@ -3528,7 +3532,7 @@ w32_set_scroll_bar_thumb (struct scroll_bar *bar,
3528 3532
3529 sb_page = max (sb_page, VERTICAL_SCROLL_BAR_MIN_HANDLE); 3533 sb_page = max (sb_page, VERTICAL_SCROLL_BAR_MIN_HANDLE);
3530 3534
3531 BLOCK_INPUT; 3535 block_input ();
3532 3536
3533 si.cbSize = sizeof (si); 3537 si.cbSize = sizeof (si);
3534 si.fMask = SIF_PAGE | SIF_POS; 3538 si.fMask = SIF_PAGE | SIF_POS;
@@ -3537,7 +3541,7 @@ w32_set_scroll_bar_thumb (struct scroll_bar *bar,
3537 3541
3538 SetScrollInfo (w, SB_CTL, &si, TRUE); 3542 SetScrollInfo (w, SB_CTL, &si, TRUE);
3539 3543
3540 UNBLOCK_INPUT; 3544 unblock_input ();
3541} 3545}
3542 3546
3543 3547
@@ -3628,7 +3632,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
3628 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); 3632 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
3629 Lisp_Object barobj; 3633 Lisp_Object barobj;
3630 3634
3631 BLOCK_INPUT; 3635 block_input ();
3632 3636
3633 XSETWINDOW (bar->window, w); 3637 XSETWINDOW (bar->window, w);
3634 XSETINT (bar->top, top); 3638 XSETINT (bar->top, top);
@@ -3664,7 +3668,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
3664 if (! NILP (bar->next)) 3668 if (! NILP (bar->next))
3665 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); 3669 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
3666 3670
3667 UNBLOCK_INPUT; 3671 unblock_input ();
3668 3672
3669 return bar; 3673 return bar;
3670} 3674}
@@ -3678,7 +3682,7 @@ x_scroll_bar_remove (struct scroll_bar *bar)
3678{ 3682{
3679 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 3683 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3680 3684
3681 BLOCK_INPUT; 3685 block_input ();
3682 3686
3683 /* Destroy the window. */ 3687 /* Destroy the window. */
3684 my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar)); 3688 my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar));
@@ -3686,7 +3690,7 @@ x_scroll_bar_remove (struct scroll_bar *bar)
3686 /* Dissociate this scroll bar from its window. */ 3690 /* Dissociate this scroll bar from its window. */
3687 wset_vertical_scroll_bar (XWINDOW (bar->window), Qnil); 3691 wset_vertical_scroll_bar (XWINDOW (bar->window), Qnil);
3688 3692
3689 UNBLOCK_INPUT; 3693 unblock_input ();
3690} 3694}
3691 3695
3692/* Set the handle of the vertical scroll bar for WINDOW to indicate 3696/* Set the handle of the vertical scroll bar for WINDOW to indicate
@@ -3741,7 +3745,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3741 if (NILP (w->vertical_scroll_bar)) 3745 if (NILP (w->vertical_scroll_bar))
3742 { 3746 {
3743 HDC hdc; 3747 HDC hdc;
3744 BLOCK_INPUT; 3748 block_input ();
3745 if (width > 0 && height > 0) 3749 if (width > 0 && height > 0)
3746 { 3750 {
3747 hdc = get_frame_dc (f); 3751 hdc = get_frame_dc (f);
@@ -3751,7 +3755,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3751 w32_clear_area (f, hdc, left, top, width, height); 3755 w32_clear_area (f, hdc, left, top, width, height);
3752 release_frame_dc (f, hdc); 3756 release_frame_dc (f, hdc);
3753 } 3757 }
3754 UNBLOCK_INPUT; 3758 unblock_input ();
3755 3759
3756 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); 3760 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height);
3757 } 3761 }
@@ -3779,7 +3783,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3779 HDC hdc; 3783 HDC hdc;
3780 SCROLLINFO si; 3784 SCROLLINFO si;
3781 3785
3782 BLOCK_INPUT; 3786 block_input ();
3783 if (width && height) 3787 if (width && height)
3784 { 3788 {
3785 hdc = get_frame_dc (f); 3789 hdc = get_frame_dc (f);
@@ -3815,7 +3819,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3815 XSETINT (bar->width, sb_width); 3819 XSETINT (bar->width, sb_width);
3816 XSETINT (bar->height, height); 3820 XSETINT (bar->height, height);
3817 3821
3818 UNBLOCK_INPUT; 3822 unblock_input ();
3819 } 3823 }
3820 } 3824 }
3821 bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil; 3825 bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil;
@@ -4057,7 +4061,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
4057 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 4061 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4058 SCROLLINFO si; 4062 SCROLLINFO si;
4059 4063
4060 BLOCK_INPUT; 4064 block_input ();
4061 4065
4062 *fp = f; 4066 *fp = f;
4063 *bar_window = bar->window; 4067 *bar_window = bar->window;
@@ -4094,7 +4098,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
4094 4098
4095 *time = last_mouse_movement_time; 4099 *time = last_mouse_movement_time;
4096 4100
4097 UNBLOCK_INPUT; 4101 unblock_input ();
4098} 4102}
4099 4103
4100 4104
@@ -4148,11 +4152,12 @@ static char dbcs_lead = 0;
4148 This routine is called by the SIGIO handler. 4152 This routine is called by the SIGIO handler.
4149 We return as soon as there are no more events to be read. 4153 We return as soon as there are no more events to be read.
4150 4154
4155 For an overview of how Emacs input works on MS-Windows, see the
4156 commentary before w32_msg_pump in w32fns.c.
4157
4151 We return the number of characters stored into the buffer, 4158 We return the number of characters stored into the buffer,
4152 thus pretending to be `read'. 4159 thus pretending to be `read'.
4153 4160
4154 EXPECTED is nonzero if the caller knows input is available.
4155
4156 Some of these messages are reposted back to the message queue since the 4161 Some of these messages are reposted back to the message queue since the
4157 system calls the windows proc directly in a context where we cannot return 4162 system calls the windows proc directly in a context where we cannot return
4158 the data nor can we guarantee the state we are in. So if we dispatch them 4163 the data nor can we guarantee the state we are in. So if we dispatch them
@@ -4163,7 +4168,7 @@ static char dbcs_lead = 0;
4163*/ 4168*/
4164 4169
4165static int 4170static int
4166w32_read_socket (struct terminal *terminal, int expected, 4171w32_read_socket (struct terminal *terminal,
4167 struct input_event *hold_quit) 4172 struct input_event *hold_quit)
4168{ 4173{
4169 int count = 0; 4174 int count = 0;
@@ -4174,15 +4179,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4174 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight; 4179 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
4175 static char buf[1]; 4180 static char buf[1];
4176 4181
4177 if (interrupt_input_blocked) 4182 block_input ();
4178 {
4179 interrupt_input_pending = 1;
4180 pending_signals = 1;
4181 return -1;
4182 }
4183
4184 interrupt_input_pending = 0;
4185 BLOCK_INPUT;
4186 4183
4187 /* So people can tell when we have read the available input. */ 4184 /* So people can tell when we have read the available input. */
4188 input_signal_count++; 4185 input_signal_count++;
@@ -4985,7 +4982,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4985 } 4982 }
4986 } 4983 }
4987 4984
4988 UNBLOCK_INPUT; 4985 unblock_input ();
4989 return count; 4986 return count;
4990} 4987}
4991 4988
@@ -5500,7 +5497,7 @@ x_set_offset (struct frame *f, register int xoff, register int yoff,
5500 } 5497 }
5501 x_calc_absolute_position (f); 5498 x_calc_absolute_position (f);
5502 5499
5503 BLOCK_INPUT; 5500 block_input ();
5504 x_wm_set_size_hint (f, (long) 0, 0); 5501 x_wm_set_size_hint (f, (long) 0, 0);
5505 5502
5506 modified_left = f->left_pos; 5503 modified_left = f->left_pos;
@@ -5511,7 +5508,7 @@ x_set_offset (struct frame *f, register int xoff, register int yoff,
5511 modified_left, modified_top, 5508 modified_left, modified_top,
5512 0, 0, 5509 0, 0,
5513 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); 5510 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
5514 UNBLOCK_INPUT; 5511 unblock_input ();
5515} 5512}
5516 5513
5517 5514
@@ -5552,7 +5549,7 @@ x_set_window_size (struct frame *f, int change_gravity, int cols, int rows)
5552{ 5549{
5553 int pixelwidth, pixelheight; 5550 int pixelwidth, pixelheight;
5554 5551
5555 BLOCK_INPUT; 5552 block_input ();
5556 5553
5557 check_frame_size (f, &rows, &cols); 5554 check_frame_size (f, &rows, &cols);
5558 f->scroll_bar_actual_width 5555 f->scroll_bar_actual_width
@@ -5632,7 +5629,7 @@ x_set_window_size (struct frame *f, int change_gravity, int cols, int rows)
5632 cancel_mouse_face (f); 5629 cancel_mouse_face (f);
5633#endif 5630#endif
5634 5631
5635 UNBLOCK_INPUT; 5632 unblock_input ();
5636} 5633}
5637 5634
5638/* Mouse warping. */ 5635/* Mouse warping. */
@@ -5662,7 +5659,7 @@ x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
5662 RECT rect; 5659 RECT rect;
5663 POINT pt; 5660 POINT pt;
5664 5661
5665 BLOCK_INPUT; 5662 block_input ();
5666 5663
5667 GetClientRect (FRAME_W32_WINDOW (f), &rect); 5664 GetClientRect (FRAME_W32_WINDOW (f), &rect);
5668 pt.x = rect.left + pix_x; 5665 pt.x = rect.left + pix_x;
@@ -5671,7 +5668,7 @@ x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
5671 5668
5672 SetCursorPos (pt.x, pt.y); 5669 SetCursorPos (pt.x, pt.y);
5673 5670
5674 UNBLOCK_INPUT; 5671 unblock_input ();
5675} 5672}
5676 5673
5677 5674
@@ -5683,7 +5680,7 @@ x_focus_on_frame (struct frame *f)
5683 struct w32_display_info *dpyinfo = &one_w32_display_info; 5680 struct w32_display_info *dpyinfo = &one_w32_display_info;
5684 5681
5685 /* Give input focus to frame. */ 5682 /* Give input focus to frame. */
5686 BLOCK_INPUT; 5683 block_input ();
5687#if 0 5684#if 0
5688 /* Try not to change its Z-order if possible. */ 5685 /* Try not to change its Z-order if possible. */
5689 if (x_window_to_frame (dpyinfo, GetForegroundWindow ())) 5686 if (x_window_to_frame (dpyinfo, GetForegroundWindow ()))
@@ -5691,7 +5688,7 @@ x_focus_on_frame (struct frame *f)
5691 else 5688 else
5692#endif 5689#endif
5693 my_set_foreground_window (FRAME_W32_WINDOW (f)); 5690 my_set_foreground_window (FRAME_W32_WINDOW (f));
5694 UNBLOCK_INPUT; 5691 unblock_input ();
5695} 5692}
5696 5693
5697void 5694void
@@ -5703,7 +5700,7 @@ x_unfocus_frame (struct frame *f)
5703void 5700void
5704x_raise_frame (struct frame *f) 5701x_raise_frame (struct frame *f)
5705{ 5702{
5706 BLOCK_INPUT; 5703 block_input ();
5707 5704
5708 /* Strictly speaking, raise-frame should only change the frame's Z 5705 /* Strictly speaking, raise-frame should only change the frame's Z
5709 order, leaving input focus unchanged. This is reasonable behavior 5706 order, leaving input focus unchanged. This is reasonable behavior
@@ -5758,19 +5755,19 @@ x_raise_frame (struct frame *f)
5758 my_bring_window_to_top (FRAME_W32_WINDOW (f)); 5755 my_bring_window_to_top (FRAME_W32_WINDOW (f));
5759 } 5756 }
5760 5757
5761 UNBLOCK_INPUT; 5758 unblock_input ();
5762} 5759}
5763 5760
5764/* Lower frame F. */ 5761/* Lower frame F. */
5765void 5762void
5766x_lower_frame (struct frame *f) 5763x_lower_frame (struct frame *f)
5767{ 5764{
5768 BLOCK_INPUT; 5765 block_input ();
5769 my_set_window_pos (FRAME_W32_WINDOW (f), 5766 my_set_window_pos (FRAME_W32_WINDOW (f),
5770 HWND_BOTTOM, 5767 HWND_BOTTOM,
5771 0, 0, 0, 0, 5768 0, 0, 0, 0,
5772 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); 5769 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
5773 UNBLOCK_INPUT; 5770 unblock_input ();
5774} 5771}
5775 5772
5776static void 5773static void
@@ -5799,7 +5796,7 @@ x_make_frame_visible (struct frame *f)
5799{ 5796{
5800 Lisp_Object type; 5797 Lisp_Object type;
5801 5798
5802 BLOCK_INPUT; 5799 block_input ();
5803 5800
5804 type = x_icon_type (f); 5801 type = x_icon_type (f);
5805 if (!NILP (type)) 5802 if (!NILP (type))
@@ -5851,7 +5848,7 @@ x_make_frame_visible (struct frame *f)
5851 int count; 5848 int count;
5852 5849
5853 /* This must come after we set COUNT. */ 5850 /* This must come after we set COUNT. */
5854 UNBLOCK_INPUT; 5851 unblock_input ();
5855 5852
5856 XSETFRAME (frame, f); 5853 XSETFRAME (frame, f);
5857 5854
@@ -5894,7 +5891,7 @@ x_make_frame_invisible (struct frame *f)
5894 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f) 5891 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f)
5895 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0; 5892 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0;
5896 5893
5897 BLOCK_INPUT; 5894 block_input ();
5898 5895
5899 my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE); 5896 my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE);
5900 5897
@@ -5908,7 +5905,7 @@ x_make_frame_invisible (struct frame *f)
5908 f->async_visible = 0; 5905 f->async_visible = 0;
5909 f->async_iconified = 0; 5906 f->async_iconified = 0;
5910 5907
5911 UNBLOCK_INPUT; 5908 unblock_input ();
5912} 5909}
5913 5910
5914/* Change window state from mapped to iconified. */ 5911/* Change window state from mapped to iconified. */
@@ -5925,7 +5922,7 @@ x_iconify_frame (struct frame *f)
5925 if (f->async_iconified) 5922 if (f->async_iconified)
5926 return; 5923 return;
5927 5924
5928 BLOCK_INPUT; 5925 block_input ();
5929 5926
5930 type = x_icon_type (f); 5927 type = x_icon_type (f);
5931 if (!NILP (type)) 5928 if (!NILP (type))
@@ -5934,7 +5931,7 @@ x_iconify_frame (struct frame *f)
5934 /* Simulate the user minimizing the frame. */ 5931 /* Simulate the user minimizing the frame. */
5935 SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0); 5932 SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0);
5936 5933
5937 UNBLOCK_INPUT; 5934 unblock_input ();
5938} 5935}
5939 5936
5940 5937
@@ -5946,7 +5943,7 @@ x_free_frame_resources (struct frame *f)
5946 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); 5943 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
5947 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 5944 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
5948 5945
5949 BLOCK_INPUT; 5946 block_input ();
5950 5947
5951 /* We must free faces before destroying windows because some 5948 /* We must free faces before destroying windows because some
5952 font-driver (e.g. xft) access a window while finishing a 5949 font-driver (e.g. xft) access a window while finishing a
@@ -5994,7 +5991,7 @@ x_free_frame_resources (struct frame *f)
5994 hlinfo->mouse_face_mouse_frame = 0; 5991 hlinfo->mouse_face_mouse_frame = 0;
5995 } 5992 }
5996 5993
5997 UNBLOCK_INPUT; 5994 unblock_input ();
5998} 5995}
5999 5996
6000 5997
@@ -6014,10 +6011,10 @@ x_destroy_window (struct frame *f)
6014/* Set the normal size hints for the window manager, for frame F. 6011/* Set the normal size hints for the window manager, for frame F.
6015 FLAGS is the flags word to use--or 0 meaning preserve the flags 6012 FLAGS is the flags word to use--or 0 meaning preserve the flags
6016 that the window now has. 6013 that the window now has.
6017 If USER_POSITION is nonzero, we set the USPosition 6014 If USER_POSITION, set the USPosition
6018 flag (this is useful when FLAGS is 0). */ 6015 flag (this is useful when FLAGS is 0). */
6019void 6016void
6020x_wm_set_size_hint (struct frame *f, long flags, int user_position) 6017x_wm_set_size_hint (struct frame *f, long flags, bool user_position)
6021{ 6018{
6022 Window window = FRAME_W32_WINDOW (f); 6019 Window window = FRAME_W32_WINDOW (f);
6023 6020
@@ -6278,10 +6275,10 @@ x_delete_terminal (struct terminal *terminal)
6278 if (!terminal->name) 6275 if (!terminal->name)
6279 return; 6276 return;
6280 6277
6281 BLOCK_INPUT; 6278 block_input ();
6282 6279
6283 x_delete_display (dpyinfo); 6280 x_delete_display (dpyinfo);
6284 UNBLOCK_INPUT; 6281 unblock_input ();
6285} 6282}
6286 6283
6287struct w32_display_info * 6284struct w32_display_info *
@@ -6291,7 +6288,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6291 struct terminal *terminal; 6288 struct terminal *terminal;
6292 HDC hdc; 6289 HDC hdc;
6293 6290
6294 BLOCK_INPUT; 6291 block_input ();
6295 6292
6296 if (!w32_initialized) 6293 if (!w32_initialized)
6297 { 6294 {
@@ -6351,7 +6348,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6351 the bitmaps. */ 6348 the bitmaps. */
6352 w32_init_fringe (terminal->rif); 6349 w32_init_fringe (terminal->rif);
6353 6350
6354 UNBLOCK_INPUT; 6351 unblock_input ();
6355 6352
6356 return dpyinfo; 6353 return dpyinfo;
6357} 6354}
diff --git a/src/w32term.h b/src/w32term.h
index 434eb92fdea..9fb37b9f030 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -204,9 +204,8 @@ extern void x_focus_on_frame (struct frame *f);
204extern struct w32_display_info *w32_term_init (Lisp_Object, 204extern struct w32_display_info *w32_term_init (Lisp_Object,
205 char *, char *); 205 char *, char *);
206extern void check_w32 (void); 206extern void check_w32 (void);
207extern int w32_defined_color (FRAME_PTR f, char *color, 207extern int w32_defined_color (FRAME_PTR f, const char *color,
208 XColor *color_def, int alloc); 208 XColor *color_def, int alloc);
209extern void set_frame_menubar (struct frame *f, int first_time, int deep_p);
210extern void x_set_window_size (struct frame *f, int change_grav, 209extern void x_set_window_size (struct frame *f, int change_grav,
211 int cols, int rows); 210 int cols, int rows);
212extern int x_display_pixel_height (struct w32_display_info *); 211extern int x_display_pixel_height (struct w32_display_info *);
@@ -231,7 +230,6 @@ extern void x_activate_menubar (struct frame *);
231extern int x_bitmap_icon (struct frame *, Lisp_Object); 230extern int x_bitmap_icon (struct frame *, Lisp_Object);
232extern void initialize_frame_menubar (struct frame *); 231extern void initialize_frame_menubar (struct frame *);
233extern void x_free_frame_resources (struct frame *); 232extern void x_free_frame_resources (struct frame *);
234extern void x_wm_set_size_hint (struct frame *, long, int);
235extern void x_real_positions (struct frame *, int *, int *); 233extern void x_real_positions (struct frame *, int *, int *);
236 234
237/* w32inevt.c */ 235/* w32inevt.c */
@@ -239,6 +237,8 @@ extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
239extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key); 237extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
240 238
241 239
240extern Lisp_Object x_get_focus_frame (struct frame *);
241
242 242
243#define PIX_TYPE COLORREF 243#define PIX_TYPE COLORREF
244 244
@@ -469,7 +469,15 @@ struct scroll_bar {
469/* Turning a lisp vector value into a pointer to a struct scroll_bar. */ 469/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
470#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) 470#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
471 471
472#ifdef _WIN64
473/* Building a 64-bit C integer from two 32-bit lisp integers. */
474#define SCROLL_BAR_PACK(low, high) (XINT (high) << 32 | XINT (low))
472 475
476/* Setting two lisp integers to the low and high words of a 64-bit C int. */
477#define SCROLL_BAR_UNPACK(low, high, int64) \
478 (XSETINT ((low), ((DWORDLONG)(int64)) & 0xffffffff), \
479 XSETINT ((high), ((DWORDLONG)(int64) >> 32) & 0xffffffff))
480#else /* not _WIN64 */
473/* Building a 32-bit C integer from two 16-bit lisp integers. */ 481/* Building a 32-bit C integer from two 16-bit lisp integers. */
474#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low)) 482#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
475 483
@@ -477,7 +485,7 @@ struct scroll_bar {
477#define SCROLL_BAR_UNPACK(low, high, int32) \ 485#define SCROLL_BAR_UNPACK(low, high, int32) \
478 (XSETINT ((low), (int32) & 0xffff), \ 486 (XSETINT ((low), (int32) & 0xffff), \
479 XSETINT ((high), ((int32) >> 16) & 0xffff)) 487 XSETINT ((high), ((int32) >> 16) & 0xffff))
480 488#endif /* not _WIN64 */
481 489
482/* Extract the window id of the scroll bar from a struct scroll_bar. */ 490/* Extract the window id of the scroll bar from a struct scroll_bar. */
483#define SCROLL_BAR_W32_WINDOW(ptr) \ 491#define SCROLL_BAR_W32_WINDOW(ptr) \
@@ -485,7 +493,7 @@ struct scroll_bar {
485 493
486/* Store a window id in a struct scroll_bar. */ 494/* Store a window id in a struct scroll_bar. */
487#define SET_SCROLL_BAR_W32_WINDOW(ptr, id) \ 495#define SET_SCROLL_BAR_W32_WINDOW(ptr, id) \
488 (SCROLL_BAR_UNPACK ((ptr)->w32_window_low, (ptr)->w32_window_high, (int) id)) 496 (SCROLL_BAR_UNPACK ((ptr)->w32_window_low, (ptr)->w32_window_high, (intptr_t) id))
489 497
490/* Extract the X widget of the scroll bar from a struct scroll_bar. */ 498/* Extract the X widget of the scroll bar from a struct scroll_bar. */
491#define SCROLL_BAR_X_WIDGET(ptr) \ 499#define SCROLL_BAR_X_WIDGET(ptr) \
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 1a67b018dd5..cb452571665 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -327,138 +327,6 @@ drain_message_queue (void)
327 } 327 }
328} 328}
329 329
330
331/*
332 * XParseGeometry parses strings of the form
333 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
334 * width, height, xoffset, and yoffset are unsigned integers.
335 * Example: "=80x24+300-49"
336 * The equal sign is optional.
337 * It returns a bitmask that indicates which of the four values
338 * were actually found in the string. For each value found,
339 * the corresponding argument is updated; for each value
340 * not found, the corresponding argument is left unchanged.
341 */
342
343static int
344read_integer (register char *string, char **NextString)
345{
346 register int Result = 0;
347 int Sign = 1;
348
349 if (*string == '+')
350 string++;
351 else if (*string == '-')
352 {
353 string++;
354 Sign = -1;
355 }
356 for (; (*string >= '0') && (*string <= '9'); string++)
357 {
358 Result = (Result * 10) + (*string - '0');
359 }
360 *NextString = string;
361 if (Sign >= 0)
362 return (Result);
363 else
364 return (-Result);
365}
366
367int
368XParseGeometry (char *string,
369 int *x, int *y,
370 unsigned int *width, unsigned int *height)
371{
372 int mask = NoValue;
373 register char *strind;
374 unsigned int tempWidth, tempHeight;
375 int tempX, tempY;
376 char *nextCharacter;
377
378 if ((string == NULL) || (*string == '\0')) return (mask);
379 if (*string == '=')
380 string++; /* ignore possible '=' at beg of geometry spec */
381
382 strind = (char *)string;
383 if (*strind != '+' && *strind != '-' && *strind != 'x')
384 {
385 tempWidth = read_integer (strind, &nextCharacter);
386 if (strind == nextCharacter)
387 return (0);
388 strind = nextCharacter;
389 mask |= WidthValue;
390 }
391
392 if (*strind == 'x' || *strind == 'X')
393 {
394 strind++;
395 tempHeight = read_integer (strind, &nextCharacter);
396 if (strind == nextCharacter)
397 return (0);
398 strind = nextCharacter;
399 mask |= HeightValue;
400 }
401
402 if ((*strind == '+') || (*strind == '-'))
403 {
404 if (*strind == '-')
405 {
406 strind++;
407 tempX = -read_integer (strind, &nextCharacter);
408 if (strind == nextCharacter)
409 return (0);
410 strind = nextCharacter;
411 mask |= XNegative;
412
413 }
414 else
415 {
416 strind++;
417 tempX = read_integer (strind, &nextCharacter);
418 if (strind == nextCharacter)
419 return (0);
420 strind = nextCharacter;
421 }
422 mask |= XValue;
423 if ((*strind == '+') || (*strind == '-'))
424 {
425 if (*strind == '-')
426 {
427 strind++;
428 tempY = -read_integer (strind, &nextCharacter);
429 if (strind == nextCharacter)
430 return (0);
431 strind = nextCharacter;
432 mask |= YNegative;
433 }
434 else
435 {
436 strind++;
437 tempY = read_integer (strind, &nextCharacter);
438 if (strind == nextCharacter)
439 return (0);
440 strind = nextCharacter;
441 }
442 mask |= YValue;
443 }
444 }
445
446 /* If strind isn't at the end of the string then it's an invalid
447 geometry specification. */
448
449 if (*strind != '\0') return (0);
450
451 if (mask & XValue)
452 *x = tempX;
453 if (mask & YValue)
454 *y = tempY;
455 if (mask & WidthValue)
456 *width = tempWidth;
457 if (mask & HeightValue)
458 *height = tempHeight;
459 return (mask);
460}
461
462/* x_sync is a no-op on W32. */ 330/* x_sync is a no-op on W32. */
463void 331void
464x_sync (struct frame *f) 332x_sync (struct frame *f)
diff --git a/src/widget.c b/src/widget.c
index fd5ad167125..1f472c6231c 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -677,13 +677,13 @@ EmacsFrameDestroy (Widget widget)
677 if (! s) emacs_abort (); 677 if (! s) emacs_abort ();
678 if (! s->output_data.x) emacs_abort (); 678 if (! s->output_data.x) emacs_abort ();
679 679
680 BLOCK_INPUT; 680 block_input ();
681 x_free_gcs (s); 681 x_free_gcs (s);
682 if (s->output_data.x->white_relief.gc) 682 if (s->output_data.x->white_relief.gc)
683 XFreeGC (XtDisplay (widget), s->output_data.x->white_relief.gc); 683 XFreeGC (XtDisplay (widget), s->output_data.x->white_relief.gc);
684 if (s->output_data.x->black_relief.gc) 684 if (s->output_data.x->black_relief.gc)
685 XFreeGC (XtDisplay (widget), s->output_data.x->black_relief.gc); 685 XFreeGC (XtDisplay (widget), s->output_data.x->black_relief.gc);
686 UNBLOCK_INPUT; 686 unblock_input ();
687} 687}
688 688
689static void 689static void
diff --git a/src/window.c b/src/window.c
index 114bd28c310..61d2a8b073f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -60,8 +60,7 @@ static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
60static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window; 60static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
61static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically; 61static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
62static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command; 62static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
63static Lisp_Object Qsafe, Qabove, Qbelow; 63static Lisp_Object Qsafe, Qabove, Qbelow, Qwindow_size, Qclone_of;
64static Lisp_Object Qclone_of;
65 64
66static int displayed_window_lines (struct window *); 65static int displayed_window_lines (struct window *);
67static int count_windows (struct window *); 66static int count_windows (struct window *);
@@ -134,102 +133,102 @@ static EMACS_INT window_scroll_preserve_hpos;
134static EMACS_INT window_scroll_preserve_vpos; 133static EMACS_INT window_scroll_preserve_vpos;
135 134
136/* These setters are used only in this file, so they can be private. */ 135/* These setters are used only in this file, so they can be private. */
137static inline void 136static void
138wset_combination_limit (struct window *w, Lisp_Object val) 137wset_combination_limit (struct window *w, Lisp_Object val)
139{ 138{
140 w->combination_limit = val; 139 w->combination_limit = val;
141} 140}
142static inline void 141static void
143wset_dedicated (struct window *w, Lisp_Object val) 142wset_dedicated (struct window *w, Lisp_Object val)
144{ 143{
145 w->dedicated = val; 144 w->dedicated = val;
146} 145}
147static inline void 146static void
148wset_display_table (struct window *w, Lisp_Object val) 147wset_display_table (struct window *w, Lisp_Object val)
149{ 148{
150 w->display_table = val; 149 w->display_table = val;
151} 150}
152static inline void 151static void
153wset_hchild (struct window *w, Lisp_Object val) 152wset_hchild (struct window *w, Lisp_Object val)
154{ 153{
155 w->hchild = val; 154 w->hchild = val;
156} 155}
157static inline void 156static void
158wset_left_fringe_width (struct window *w, Lisp_Object val) 157wset_left_fringe_width (struct window *w, Lisp_Object val)
159{ 158{
160 w->left_fringe_width = val; 159 w->left_fringe_width = val;
161} 160}
162static inline void 161static void
163wset_left_margin_cols (struct window *w, Lisp_Object val) 162wset_left_margin_cols (struct window *w, Lisp_Object val)
164{ 163{
165 w->left_margin_cols = val; 164 w->left_margin_cols = val;
166} 165}
167static inline void 166static void
168wset_new_normal (struct window *w, Lisp_Object val) 167wset_new_normal (struct window *w, Lisp_Object val)
169{ 168{
170 w->new_normal = val; 169 w->new_normal = val;
171} 170}
172static inline void 171static void
173wset_new_total (struct window *w, Lisp_Object val) 172wset_new_total (struct window *w, Lisp_Object val)
174{ 173{
175 w->new_total = val; 174 w->new_total = val;
176} 175}
177static inline void 176static void
178wset_normal_cols (struct window *w, Lisp_Object val) 177wset_normal_cols (struct window *w, Lisp_Object val)
179{ 178{
180 w->normal_cols = val; 179 w->normal_cols = val;
181} 180}
182static inline void 181static void
183wset_normal_lines (struct window *w, Lisp_Object val) 182wset_normal_lines (struct window *w, Lisp_Object val)
184{ 183{
185 w->normal_lines = val; 184 w->normal_lines = val;
186} 185}
187static inline void 186static void
188wset_parent (struct window *w, Lisp_Object val) 187wset_parent (struct window *w, Lisp_Object val)
189{ 188{
190 w->parent = val; 189 w->parent = val;
191} 190}
192static inline void 191static void
193wset_pointm (struct window *w, Lisp_Object val) 192wset_pointm (struct window *w, Lisp_Object val)
194{ 193{
195 w->pointm = val; 194 w->pointm = val;
196} 195}
197static inline void 196static void
198wset_right_fringe_width (struct window *w, Lisp_Object val) 197wset_right_fringe_width (struct window *w, Lisp_Object val)
199{ 198{
200 w->right_fringe_width = val; 199 w->right_fringe_width = val;
201} 200}
202static inline void 201static void
203wset_right_margin_cols (struct window *w, Lisp_Object val) 202wset_right_margin_cols (struct window *w, Lisp_Object val)
204{ 203{
205 w->right_margin_cols = val; 204 w->right_margin_cols = val;
206} 205}
207static inline void 206static void
208wset_scroll_bar_width (struct window *w, Lisp_Object val) 207wset_scroll_bar_width (struct window *w, Lisp_Object val)
209{ 208{
210 w->scroll_bar_width = val; 209 w->scroll_bar_width = val;
211} 210}
212static inline void 211static void
213wset_start (struct window *w, Lisp_Object val) 212wset_start (struct window *w, Lisp_Object val)
214{ 213{
215 w->start = val; 214 w->start = val;
216} 215}
217static inline void 216static void
218wset_temslot (struct window *w, Lisp_Object val) 217wset_temslot (struct window *w, Lisp_Object val)
219{ 218{
220 w->temslot = val; 219 w->temslot = val;
221} 220}
222static inline void 221static void
223wset_vchild (struct window *w, Lisp_Object val) 222wset_vchild (struct window *w, Lisp_Object val)
224{ 223{
225 w->vchild = val; 224 w->vchild = val;
226} 225}
227static inline void 226static void
228wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val) 227wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val)
229{ 228{
230 w->vertical_scroll_bar_type = val; 229 w->vertical_scroll_bar_type = val;
231} 230}
232static inline void 231static void
233wset_window_parameters (struct window *w, Lisp_Object val) 232wset_window_parameters (struct window *w, Lisp_Object val)
234{ 233{
235 w->window_parameters = val; 234 w->window_parameters = val;
@@ -613,10 +612,10 @@ WINDOW are never \(re-)combined with WINDOW's siblings. */)
613DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0, 612DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
614 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT. 613 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
615WINDOW must be a valid window and defaults to the selected one. 614WINDOW must be a valid window and defaults to the selected one.
616If LIMIT is nil, child windows of WINDOW can be recombined with 615If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
617WINDOW's siblings. LIMIT t means that child windows of WINDOW are 616siblings. LIMIT t means that child windows of WINDOW are never
618never \(re-)combined with WINDOW's siblings. Other values are reserved 617\(re-)combined with WINDOW's siblings. Other values are reserved for
619for future use. */) 618future use. */)
620 (Lisp_Object window, Lisp_Object limit) 619 (Lisp_Object window, Lisp_Object limit)
621{ 620{
622 wset_combination_limit (decode_valid_window (window), limit); 621 wset_combination_limit (decode_valid_window (window), limit);
@@ -2820,7 +2819,7 @@ window-start value is reasonable when this function is called. */)
2820 } 2819 }
2821 } 2820 }
2822 2821
2823 BLOCK_INPUT; 2822 block_input ();
2824 if (!FRAME_INITIAL_P (f)) 2823 if (!FRAME_INITIAL_P (f))
2825 { 2824 {
2826 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 2825 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
@@ -2962,7 +2961,7 @@ window-start value is reasonable when this function is called. */)
2962 } 2961 }
2963 2962
2964 adjust_glyphs (f); 2963 adjust_glyphs (f);
2965 UNBLOCK_INPUT; 2964 unblock_input ();
2966 2965
2967 run_window_configuration_change_hook (f); 2966 run_window_configuration_change_hook (f);
2968 2967
@@ -3462,6 +3461,10 @@ make_window (void)
3462 wset_vertical_scroll_bar_type (w, Qt); 3461 wset_vertical_scroll_bar_type (w, Qt);
3463 wset_window_end_pos (w, make_number (0)); 3462 wset_window_end_pos (w, make_number (0));
3464 wset_window_end_vpos (w, make_number (0)); 3463 wset_window_end_vpos (w, make_number (0));
3464 /* These Lisp fields are marked specially so they're not set to nil by
3465 allocate_window. */
3466 wset_prev_buffers (w, Qnil);
3467 wset_next_buffers (w, Qnil);
3465 3468
3466 /* Initialize non-Lisp data. Note that allocate_window zeroes out all 3469 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3467 non-Lisp data, so do it only for slots which should not be zero. */ 3470 non-Lisp data, so do it only for slots which should not be zero. */
@@ -3693,14 +3696,14 @@ be applied on the Elisp level. */)
3693 (horflag ? r->total_cols : r->total_lines))) 3696 (horflag ? r->total_cols : r->total_lines)))
3694 return Qnil; 3697 return Qnil;
3695 3698
3696 BLOCK_INPUT; 3699 block_input ();
3697 window_resize_apply (r, horflag); 3700 window_resize_apply (r, horflag);
3698 3701
3699 windows_or_buffers_changed++; 3702 windows_or_buffers_changed++;
3700 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 3703 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3701 3704
3702 adjust_glyphs (f); 3705 adjust_glyphs (f);
3703 UNBLOCK_INPUT; 3706 unblock_input ();
3704 3707
3705 run_window_configuration_change_hook (f); 3708 run_window_configuration_change_hook (f);
3706 3709
@@ -3844,7 +3847,7 @@ set correctly. See the code of `split-window' for how this is done. */)
3844 We do that if either `window-combination-limit' is t, or OLD has no 3847 We do that if either `window-combination-limit' is t, or OLD has no
3845 parent, or OLD is ortho-combined. */ 3848 parent, or OLD is ortho-combined. */
3846 combination_limit = 3849 combination_limit =
3847 !NILP (Vwindow_combination_limit) 3850 EQ (Vwindow_combination_limit, Qt)
3848 || NILP (o->parent) 3851 || NILP (o->parent)
3849 || NILP (horflag 3852 || NILP (horflag
3850 ? (XWINDOW (o->parent)->hchild) 3853 ? (XWINDOW (o->parent)->hchild)
@@ -3899,9 +3902,9 @@ set correctly. See the code of `split-window' for how this is done. */)
3899 3902
3900 make_parent_window (old, horflag); 3903 make_parent_window (old, horflag);
3901 p = XWINDOW (o->parent); 3904 p = XWINDOW (o->parent);
3902 /* Store value of `window-combination-limit' in new parent's 3905 /* Store t in the new parent's combination_limit slot to avoid
3903 combination_limit slot. */ 3906 that its children get merged into another window. */
3904 wset_combination_limit (p, Vwindow_combination_limit); 3907 wset_combination_limit (p, Qt);
3905 /* These get applied below. */ 3908 /* These get applied below. */
3906 wset_new_total (p, horflag ? o->total_cols : o->total_lines); 3909 wset_new_total (p, horflag ? o->total_cols : o->total_lines);
3907 wset_new_normal (p, new_normal); 3910 wset_new_normal (p, new_normal);
@@ -3970,13 +3973,13 @@ set correctly. See the code of `split-window' for how this is done. */)
3970 wset_new_total (n, total_size); 3973 wset_new_total (n, total_size);
3971 wset_new_normal (n, normal_size); 3974 wset_new_normal (n, normal_size);
3972 3975
3973 BLOCK_INPUT; 3976 block_input ();
3974 window_resize_apply (p, horflag); 3977 window_resize_apply (p, horflag);
3975 adjust_glyphs (f); 3978 adjust_glyphs (f);
3976 /* Set buffer of NEW to buffer of reference window. Don't run 3979 /* Set buffer of NEW to buffer of reference window. Don't run
3977 any hooks. */ 3980 any hooks. */
3978 set_window_buffer (new, r->buffer, 0, 1); 3981 set_window_buffer (new, r->buffer, 0, 1);
3979 UNBLOCK_INPUT; 3982 unblock_input ();
3980 3983
3981 /* Maybe we should run the scroll functions in Elisp (which already 3984 /* Maybe we should run the scroll functions in Elisp (which already
3982 runs the configuration change hook). */ 3985 runs the configuration change hook). */
@@ -4057,7 +4060,7 @@ Signal an error when WINDOW is the only window on its frame. */)
4057 { 4060 {
4058 4061
4059 /* Block input. */ 4062 /* Block input. */
4060 BLOCK_INPUT; 4063 block_input ();
4061 window_resize_apply (p, horflag); 4064 window_resize_apply (p, horflag);
4062 4065
4063 /* If this window is referred to by the dpyinfo's mouse 4066 /* If this window is referred to by the dpyinfo's mouse
@@ -4129,7 +4132,7 @@ Signal an error when WINDOW is the only window on its frame. */)
4129 else 4132 else
4130 fset_selected_window (f, new_selected_window); 4133 fset_selected_window (f, new_selected_window);
4131 4134
4132 UNBLOCK_INPUT; 4135 unblock_input ();
4133 4136
4134 /* Now look whether `get-mru-window' gets us something. */ 4137 /* Now look whether `get-mru-window' gets us something. */
4135 mru_window = call1 (Qget_mru_window, frame); 4138 mru_window = call1 (Qget_mru_window, frame);
@@ -4144,7 +4147,7 @@ Signal an error when WINDOW is the only window on its frame. */)
4144 fset_selected_window (f, new_selected_window); 4147 fset_selected_window (f, new_selected_window);
4145 } 4148 }
4146 else 4149 else
4147 UNBLOCK_INPUT; 4150 unblock_input ();
4148 4151
4149 /* Must be run by the caller: 4152 /* Must be run by the caller:
4150 run_window_configuration_change_hook (f); */ 4153 run_window_configuration_change_hook (f); */
@@ -4194,7 +4197,7 @@ grow_mini_window (struct window *w, int delta)
4194 root, make_number (- delta)); 4197 root, make_number (- delta));
4195 if (INTEGERP (value) && window_resize_check (r, 0)) 4198 if (INTEGERP (value) && window_resize_check (r, 0))
4196 { 4199 {
4197 BLOCK_INPUT; 4200 block_input ();
4198 window_resize_apply (r, 0); 4201 window_resize_apply (r, 0);
4199 4202
4200 /* Grow the mini-window. */ 4203 /* Grow the mini-window. */
@@ -4206,7 +4209,7 @@ grow_mini_window (struct window *w, int delta)
4206 w->last_overlay_modified = 0; 4209 w->last_overlay_modified = 0;
4207 4210
4208 adjust_glyphs (f); 4211 adjust_glyphs (f);
4209 UNBLOCK_INPUT; 4212 unblock_input ();
4210 } 4213 }
4211} 4214}
4212 4215
@@ -4231,7 +4234,7 @@ shrink_mini_window (struct window *w)
4231 root, make_number (size - 1)); 4234 root, make_number (size - 1));
4232 if (INTEGERP (value) && window_resize_check (r, 0)) 4235 if (INTEGERP (value) && window_resize_check (r, 0))
4233 { 4236 {
4234 BLOCK_INPUT; 4237 block_input ();
4235 window_resize_apply (r, 0); 4238 window_resize_apply (r, 0);
4236 4239
4237 /* Shrink the mini-window. */ 4240 /* Shrink the mini-window. */
@@ -4243,7 +4246,7 @@ shrink_mini_window (struct window *w)
4243 w->last_overlay_modified = 0; 4246 w->last_overlay_modified = 0;
4244 4247
4245 adjust_glyphs (f); 4248 adjust_glyphs (f);
4246 UNBLOCK_INPUT; 4249 unblock_input ();
4247 } 4250 }
4248 /* If the above failed for whatever strange reason we must make a 4251 /* If the above failed for whatever strange reason we must make a
4249 one window frame here. The same routine will be needed when 4252 one window frame here. The same routine will be needed when
@@ -4275,7 +4278,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4275 && XINT (w->new_total) > 0 4278 && XINT (w->new_total) > 0
4276 && height == XINT (r->new_total) + XINT (w->new_total)) 4279 && height == XINT (r->new_total) + XINT (w->new_total))
4277 { 4280 {
4278 BLOCK_INPUT; 4281 block_input ();
4279 window_resize_apply (r, 0); 4282 window_resize_apply (r, 0);
4280 4283
4281 wset_total_lines (w, w->new_total); 4284 wset_total_lines (w, w->new_total);
@@ -4285,7 +4288,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4285 windows_or_buffers_changed++; 4288 windows_or_buffers_changed++;
4286 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4289 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4287 adjust_glyphs (f); 4290 adjust_glyphs (f);
4288 UNBLOCK_INPUT; 4291 unblock_input ();
4289 4292
4290 run_window_configuration_change_hook (f); 4293 run_window_configuration_change_hook (f);
4291 return Qt; 4294 return Qt;
@@ -5621,7 +5624,7 @@ the return value is nil. Otherwise the value is t. */)
5621 5624
5622 /* The mouse highlighting code could get screwed up 5625 /* The mouse highlighting code could get screwed up
5623 if it runs during this. */ 5626 if it runs during this. */
5624 BLOCK_INPUT; 5627 block_input ();
5625 5628
5626 if (data->frame_lines != previous_frame_lines 5629 if (data->frame_lines != previous_frame_lines
5627 || data->frame_cols != previous_frame_cols) 5630 || data->frame_cols != previous_frame_cols)
@@ -5872,7 +5875,7 @@ the return value is nil. Otherwise the value is t. */)
5872 } 5875 }
5873 5876
5874 adjust_glyphs (f); 5877 adjust_glyphs (f);
5875 UNBLOCK_INPUT; 5878 unblock_input ();
5876 5879
5877 /* Scan dead buffer windows. */ 5880 /* Scan dead buffer windows. */
5878 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows)) 5881 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows))
@@ -6701,6 +6704,7 @@ syms_of_window (void)
6701 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows"); 6704 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows");
6702 DEFSYM (Qrecord_window_buffer, "record-window-buffer"); 6705 DEFSYM (Qrecord_window_buffer, "record-window-buffer");
6703 DEFSYM (Qget_mru_window, "get-mru-window"); 6706 DEFSYM (Qget_mru_window, "get-mru-window");
6707 DEFSYM (Qwindow_size, "window-size");
6704 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook"); 6708 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6705 DEFSYM (Qabove, "above"); 6709 DEFSYM (Qabove, "above");
6706 DEFSYM (Qbelow, "below"); 6710 DEFSYM (Qbelow, "below");
@@ -6796,23 +6800,36 @@ This variable takes no effect if `window-combination-limit' is non-nil. */);
6796 Vwindow_combination_resize = Qnil; 6800 Vwindow_combination_resize = Qnil;
6797 6801
6798 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit, 6802 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit,
6799 doc: /* If t, splitting a window makes a new parent window. 6803 doc: /* If non-nil, splitting a window makes a new parent window.
6800If this variable is nil, splitting a window will create a new parent 6804The following values are recognized:
6801window only if the window has no parent window or the window shall 6805
6802become a combination orthogonal to the one it is part of. 6806nil means splitting a window will create a new parent window only if the
6803 6807 window has no parent window or the window shall become part of a
6804If this variable is t, splitting a window always creates a new parent 6808 combination orthogonal to the one it is part of.
6805window. If all splits behave this way, each frame's window tree is a 6809
6806binary tree and every window but the frame's root window has exactly one 6810`window-size' means that splitting a window for displaying a buffer
6807sibling. 6811 makes a new parent window provided `display-buffer' is supposed to
6808 6812 explicitly set the window's size due to the presence of a
6809Other values are reserved for future use. 6813 `window-height' or `window-width' entry in the alist used by
6810 6814 `display-buffer'. Otherwise, this value is handled like nil.
6811The value of this variable is also assigned to the combination limit of 6815
6812the new parent window. The combination limit of a window can be 6816`temp-buffer' means that splitting a window for displaying a temporary
6813retrieved via the function `window-combination-limit' and altered by the 6817 buffer always makes a new parent window. Otherwise, this value is
6814function `set-window-combination-limit'. */); 6818 handled like nil.
6815 Vwindow_combination_limit = Qnil; 6819
6820`display-buffer' means that splitting a window for displaying a buffer
6821 always makes a new parent window. Since temporary buffers are
6822 displayed by the function `display-buffer', this value is stronger
6823 than `temp-buffer'. Splitting a window for other purpose makes a
6824 new parent window only if needed.
6825
6826t means that splitting a window always creates a new parent window. If
6827 all splits behave this way, each frame's window tree is a binary
6828 tree and every window but the frame's root window has exactly one
6829 sibling.
6830
6831Other values are reserved for future use. */);
6832 Vwindow_combination_limit = Qwindow_size;
6816 6833
6817 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters, 6834 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters,
6818 doc: /* Alist of persistent window parameters. 6835 doc: /* Alist of persistent window parameters.
diff --git a/src/window.h b/src/window.h
index 62ae43a999d..115b361194c 100644
--- a/src/window.h
+++ b/src/window.h
@@ -220,13 +220,6 @@ struct window
220 /* t means this window's child windows are not (re-)combined. */ 220 /* t means this window's child windows are not (re-)combined. */
221 Lisp_Object combination_limit; 221 Lisp_Object combination_limit;
222 222
223 /* Alist of <buffer, window-start, window-point> triples listing
224 buffers previously shown in this window. */
225 Lisp_Object prev_buffers;
226
227 /* List of buffers re-shown in this window. */
228 Lisp_Object next_buffers;
229
230 /* An alist with parameters. */ 223 /* An alist with parameters. */
231 Lisp_Object window_parameters; 224 Lisp_Object window_parameters;
232 225
@@ -238,6 +231,14 @@ struct window
238 struct glyph_matrix *current_matrix; 231 struct glyph_matrix *current_matrix;
239 struct glyph_matrix *desired_matrix; 232 struct glyph_matrix *desired_matrix;
240 233
234 /* The two Lisp_Object fields below are marked in a special way,
235 which is why they're placed after `current_matrix'. */
236 /* Alist of <buffer, window-start, window-point> triples listing
237 buffers previously shown in this window. */
238 Lisp_Object prev_buffers;
239 /* List of buffers re-shown in this window. */
240 Lisp_Object next_buffers;
241
241 /* Number saying how recently window was selected. */ 242 /* Number saying how recently window was selected. */
242 int use_time; 243 int use_time;
243 244
diff --git a/src/xdisp.c b/src/xdisp.c
index 1f6a60c0b87..2047c0e78c1 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -275,6 +275,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
275#include <limits.h> 275#include <limits.h>
276 276
277#include "lisp.h" 277#include "lisp.h"
278#include "atimer.h"
278#include "keyboard.h" 279#include "keyboard.h"
279#include "frame.h" 280#include "frame.h"
280#include "window.h" 281#include "window.h"
@@ -332,10 +333,10 @@ static Lisp_Object Qinhibit_eval_during_redisplay;
332static Lisp_Object Qbuffer_position, Qposition, Qobject; 333static Lisp_Object Qbuffer_position, Qposition, Qobject;
333static Lisp_Object Qright_to_left, Qleft_to_right; 334static Lisp_Object Qright_to_left, Qleft_to_right;
334 335
335/* Cursor shapes */ 336/* Cursor shapes. */
336Lisp_Object Qbar, Qhbar, Qbox, Qhollow; 337Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
337 338
338/* Pointer shapes */ 339/* Pointer shapes. */
339static Lisp_Object Qarrow, Qhand; 340static Lisp_Object Qarrow, Qhand;
340Lisp_Object Qtext; 341Lisp_Object Qtext;
341 342
@@ -346,6 +347,7 @@ static Lisp_Object Qfontification_functions;
346 347
347static Lisp_Object Qwrap_prefix; 348static Lisp_Object Qwrap_prefix;
348static Lisp_Object Qline_prefix; 349static Lisp_Object Qline_prefix;
350static Lisp_Object Qredisplay_internal;
349 351
350/* Non-nil means don't actually do any redisplay. */ 352/* Non-nil means don't actually do any redisplay. */
351 353
@@ -365,22 +367,22 @@ static Lisp_Object Qmargin, Qpointer;
365static Lisp_Object Qline_height; 367static Lisp_Object Qline_height;
366 368
367/* These setters are used only in this file, so they can be private. */ 369/* These setters are used only in this file, so they can be private. */
368static inline void 370static void
369wset_base_line_number (struct window *w, Lisp_Object val) 371wset_base_line_number (struct window *w, Lisp_Object val)
370{ 372{
371 w->base_line_number = val; 373 w->base_line_number = val;
372} 374}
373static inline void 375static void
374wset_base_line_pos (struct window *w, Lisp_Object val) 376wset_base_line_pos (struct window *w, Lisp_Object val)
375{ 377{
376 w->base_line_pos = val; 378 w->base_line_pos = val;
377} 379}
378static inline void 380static void
379wset_column_number_displayed (struct window *w, Lisp_Object val) 381wset_column_number_displayed (struct window *w, Lisp_Object val)
380{ 382{
381 w->column_number_displayed = val; 383 w->column_number_displayed = val;
382} 384}
383static inline void 385static void
384wset_region_showing (struct window *w, Lisp_Object val) 386wset_region_showing (struct window *w, Lisp_Object val)
385{ 387{
386 w->region_showing = val; 388 w->region_showing = val;
@@ -1189,7 +1191,7 @@ window_box (struct window *w, int area, int *box_x, int *box_y,
1189 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the 1191 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1190 box. */ 1192 box. */
1191 1193
1192static inline void 1194static void
1193window_box_edges (struct window *w, int area, int *top_left_x, int *top_left_y, 1195window_box_edges (struct window *w, int area, int *top_left_x, int *top_left_y,
1194 int *bottom_right_x, int *bottom_right_y) 1196 int *bottom_right_x, int *bottom_right_y)
1195{ 1197{
@@ -1276,7 +1278,7 @@ string_from_display_spec (Lisp_Object spec)
1276/* Limit insanely large values of W->hscroll on frame F to the largest 1278/* Limit insanely large values of W->hscroll on frame F to the largest
1277 value that will still prevent first_visible_x and last_visible_x of 1279 value that will still prevent first_visible_x and last_visible_x of
1278 'struct it' from overflowing an int. */ 1280 'struct it' from overflowing an int. */
1279static inline int 1281static int
1280window_hscroll_limited (struct window *w, struct frame *f) 1282window_hscroll_limited (struct window *w, struct frame *f)
1281{ 1283{
1282 ptrdiff_t window_hscroll = w->hscroll; 1284 ptrdiff_t window_hscroll = w->hscroll;
@@ -1623,7 +1625,7 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y,
1623 returns an invalid character. If we find one, we return a `?', but 1625 returns an invalid character. If we find one, we return a `?', but
1624 with the length of the invalid character. */ 1626 with the length of the invalid character. */
1625 1627
1626static inline int 1628static int
1627string_char_and_length (const unsigned char *str, int *len) 1629string_char_and_length (const unsigned char *str, int *len)
1628{ 1630{
1629 int c; 1631 int c;
@@ -1671,7 +1673,7 @@ string_pos_nchars_ahead (struct text_pos pos, Lisp_Object string, ptrdiff_t ncha
1671/* Value is the text position, i.e. character and byte position, 1673/* Value is the text position, i.e. character and byte position,
1672 for character position CHARPOS in STRING. */ 1674 for character position CHARPOS in STRING. */
1673 1675
1674static inline struct text_pos 1676static struct text_pos
1675string_pos (ptrdiff_t charpos, Lisp_Object string) 1677string_pos (ptrdiff_t charpos, Lisp_Object string)
1676{ 1678{
1677 struct text_pos pos; 1679 struct text_pos pos;
@@ -5346,6 +5348,7 @@ next_overlay_string (struct it *it)
5346 SET_TEXT_POS (it->current.string_pos, 0, 0); 5348 SET_TEXT_POS (it->current.string_pos, 0, 0);
5347 it->method = GET_FROM_STRING; 5349 it->method = GET_FROM_STRING;
5348 it->stop_charpos = 0; 5350 it->stop_charpos = 0;
5351 it->end_charpos = SCHARS (it->string);
5349 if (it->cmp_it.stop_pos >= 0) 5352 if (it->cmp_it.stop_pos >= 0)
5350 it->cmp_it.stop_pos = 0; 5353 it->cmp_it.stop_pos = 0;
5351 it->prev_stop = 0; 5354 it->prev_stop = 0;
@@ -7755,7 +7758,7 @@ compute_stop_pos_backwards (struct it *it)
7755 { 7758 {
7756 it->end_charpos = min (charpos + 1, ZV); 7759 it->end_charpos = min (charpos + 1, ZV);
7757 charpos = max (charpos - SCAN_BACK_LIMIT, BEGV); 7760 charpos = max (charpos - SCAN_BACK_LIMIT, BEGV);
7758 SET_TEXT_POS (pos, charpos, BYTE_TO_CHAR (charpos)); 7761 SET_TEXT_POS (pos, charpos, CHAR_TO_BYTE (charpos));
7759 reseat_1 (it, pos, 0); 7762 reseat_1 (it, pos, 0);
7760 compute_stop_pos (it); 7763 compute_stop_pos (it);
7761 /* We must advance forward, right? */ 7764 /* We must advance forward, right? */
@@ -11401,11 +11404,11 @@ x_cursor_to (int vpos, int hpos, int y, int x)
11401 This will also set the cursor position of W. */ 11404 This will also set the cursor position of W. */
11402 if (updated_window == NULL) 11405 if (updated_window == NULL)
11403 { 11406 {
11404 BLOCK_INPUT; 11407 block_input ();
11405 display_and_set_cursor (w, 1, hpos, vpos, x, y); 11408 display_and_set_cursor (w, 1, hpos, vpos, x, y);
11406 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional) 11409 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
11407 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ()); 11410 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11408 UNBLOCK_INPUT; 11411 unblock_input ();
11409 } 11412 }
11410} 11413}
11411 11414
@@ -11519,11 +11522,11 @@ update_tool_bar (struct frame *f, int save_match_data)
11519 /* Redisplay that happens asynchronously due to an expose event 11522 /* Redisplay that happens asynchronously due to an expose event
11520 may access f->tool_bar_items. Make sure we update both 11523 may access f->tool_bar_items. Make sure we update both
11521 variables within BLOCK_INPUT so no such event interrupts. */ 11524 variables within BLOCK_INPUT so no such event interrupts. */
11522 BLOCK_INPUT; 11525 block_input ();
11523 fset_tool_bar_items (f, new_tool_bar); 11526 fset_tool_bar_items (f, new_tool_bar);
11524 f->n_tool_bar_items = new_n_tool_bar; 11527 f->n_tool_bar_items = new_n_tool_bar;
11525 w->update_mode_line = 1; 11528 w->update_mode_line = 1;
11526 UNBLOCK_INPUT; 11529 unblock_input ();
11527 } 11530 }
11528 11531
11529 UNGCPRO; 11532 UNGCPRO;
@@ -12574,7 +12577,7 @@ debug_method_add (struct window *w, char const *fmt, ...)
12574 buffer position, END is given as a distance from Z. Used in 12577 buffer position, END is given as a distance from Z. Used in
12575 redisplay_internal for display optimization. */ 12578 redisplay_internal for display optimization. */
12576 12579
12577static inline int 12580static int
12578text_outside_line_unchanged_p (struct window *w, 12581text_outside_line_unchanged_p (struct window *w,
12579 ptrdiff_t start, ptrdiff_t end) 12582 ptrdiff_t start, ptrdiff_t end)
12580{ 12583{
@@ -12835,7 +12838,7 @@ check_point_in_composition (struct buffer *prev_buf, ptrdiff_t prev_pt,
12835/* Reconsider the setting of B->clip_changed which is displayed 12838/* Reconsider the setting of B->clip_changed which is displayed
12836 in window W. */ 12839 in window W. */
12837 12840
12838static inline void 12841static void
12839reconsider_clip_changes (struct window *w, struct buffer *b) 12842reconsider_clip_changes (struct window *w, struct buffer *b)
12840{ 12843{
12841 if (b->clip_changed 12844 if (b->clip_changed
@@ -12927,12 +12930,13 @@ redisplay_internal (void)
12927 struct frame *sf; 12930 struct frame *sf;
12928 int polling_stopped_here = 0; 12931 int polling_stopped_here = 0;
12929 Lisp_Object old_frame = selected_frame; 12932 Lisp_Object old_frame = selected_frame;
12933 struct backtrace backtrace;
12930 12934
12931 /* Non-zero means redisplay has to consider all windows on all 12935 /* Non-zero means redisplay has to consider all windows on all
12932 frames. Zero means, only selected_window is considered. */ 12936 frames. Zero means, only selected_window is considered. */
12933 int consider_all_windows_p; 12937 int consider_all_windows_p;
12934 12938
12935 /* Non-zero means redisplay has to redisplay the miniwindow */ 12939 /* Non-zero means redisplay has to redisplay the miniwindow. */
12936 int update_miniwindow_p = 0; 12940 int update_miniwindow_p = 0;
12937 12941
12938 TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p)); 12942 TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p));
@@ -12969,6 +12973,14 @@ redisplay_internal (void)
12969 redisplaying_p = 1; 12973 redisplaying_p = 1;
12970 specbind (Qinhibit_free_realized_faces, Qnil); 12974 specbind (Qinhibit_free_realized_faces, Qnil);
12971 12975
12976 /* Record this function, so it appears on the profiler's backtraces. */
12977 backtrace.next = backtrace_list;
12978 backtrace.function = Qredisplay_internal;
12979 backtrace.args = &Qnil;
12980 backtrace.nargs = 0;
12981 backtrace.debug_on_exit = 0;
12982 backtrace_list = &backtrace;
12983
12972 { 12984 {
12973 Lisp_Object tail, frame; 12985 Lisp_Object tail, frame;
12974 12986
@@ -13666,6 +13678,7 @@ redisplay_internal (void)
13666#endif /* HAVE_WINDOW_SYSTEM */ 13678#endif /* HAVE_WINDOW_SYSTEM */
13667 13679
13668 end_of_redisplay: 13680 end_of_redisplay:
13681 backtrace_list = backtrace.next;
13669 unbind_to (count, Qnil); 13682 unbind_to (count, Qnil);
13670 RESUME_POLLING; 13683 RESUME_POLLING;
13671} 13684}
@@ -14525,7 +14538,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
14525 14538
14526 We assume that the window's buffer is really current. */ 14539 We assume that the window's buffer is really current. */
14527 14540
14528static inline struct text_pos 14541static struct text_pos
14529run_window_scroll_functions (Lisp_Object window, struct text_pos startp) 14542run_window_scroll_functions (Lisp_Object window, struct text_pos startp)
14530{ 14543{
14531 struct window *w = XWINDOW (window); 14544 struct window *w = XWINDOW (window);
@@ -16204,10 +16217,10 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
16204 || w->pseudo_window_p))) 16217 || w->pseudo_window_p)))
16205 { 16218 {
16206 update_begin (f); 16219 update_begin (f);
16207 BLOCK_INPUT; 16220 block_input ();
16208 if (draw_window_fringes (w, 1)) 16221 if (draw_window_fringes (w, 1))
16209 x_draw_vertical_border (w); 16222 x_draw_vertical_border (w);
16210 UNBLOCK_INPUT; 16223 unblock_input ();
16211 update_end (f); 16224 update_end (f);
16212 } 16225 }
16213#endif /* HAVE_WINDOW_SYSTEM */ 16226#endif /* HAVE_WINDOW_SYSTEM */
@@ -16744,28 +16757,33 @@ try_window_reusing_current_matrix (struct window *w)
16744 } 16757 }
16745 if (row < bottom_row) 16758 if (row < bottom_row)
16746 { 16759 {
16747 struct glyph *glyph = row->glyphs[TEXT_AREA] + w->cursor.hpos; 16760 /* Can't simply scan the row for point with
16748 struct glyph *end = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA]; 16761 bidi-reordered glyph rows. Let set_cursor_from_row
16749 16762 figure out where to put the cursor, and if it fails,
16750 /* Can't use this optimization with bidi-reordered glyph 16763 give up. */
16751 rows, unless cursor is already at point. */
16752 if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))) 16764 if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
16753 { 16765 {
16754 if (!(w->cursor.hpos >= 0 16766 if (!set_cursor_from_row (w, row, w->current_matrix,
16755 && w->cursor.hpos < row->used[TEXT_AREA] 16767 0, 0, 0, 0))
16756 && BUFFERP (glyph->object) 16768 {
16757 && glyph->charpos == PT)) 16769 clear_glyph_matrix (w->desired_matrix);
16758 return 0; 16770 return 0;
16771 }
16759 } 16772 }
16760 else 16773 else
16761 for (; glyph < end 16774 {
16762 && (!BUFFERP (glyph->object) 16775 struct glyph *glyph = row->glyphs[TEXT_AREA] + w->cursor.hpos;
16763 || glyph->charpos < PT); 16776 struct glyph *end = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA];
16764 glyph++) 16777
16765 { 16778 for (; glyph < end
16766 w->cursor.hpos++; 16779 && (!BUFFERP (glyph->object)
16767 w->cursor.x += glyph->pixel_width; 16780 || glyph->charpos < PT);
16768 } 16781 glyph++)
16782 {
16783 w->cursor.hpos++;
16784 w->cursor.x += glyph->pixel_width;
16785 }
16786 }
16769 } 16787 }
16770 } 16788 }
16771 16789
@@ -20155,10 +20173,6 @@ display_menu_bar (struct window *w)
20155 this. */ 20173 this. */
20156 it.paragraph_embedding = L2R; 20174 it.paragraph_embedding = L2R;
20157 20175
20158 if (! mode_line_inverse_video)
20159 /* Force the menu-bar to be displayed in the default face. */
20160 it.base_face_id = it.face_id = DEFAULT_FACE_ID;
20161
20162 /* Clear all rows of the menu bar. */ 20176 /* Clear all rows of the menu bar. */
20163 for (i = 0; i < FRAME_MENU_BAR_LINES (f); ++i) 20177 for (i = 0; i < FRAME_MENU_BAR_LINES (f); ++i)
20164 { 20178 {
@@ -20328,10 +20342,6 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
20328 20342
20329 it.glyph_row->mode_line_p = 1; 20343 it.glyph_row->mode_line_p = 1;
20330 20344
20331 if (! mode_line_inverse_video)
20332 /* Force the mode-line to be displayed in the default face. */
20333 it.base_face_id = it.face_id = DEFAULT_FACE_ID;
20334
20335 /* FIXME: This should be controlled by a user option. But 20345 /* FIXME: This should be controlled by a user option. But
20336 supporting such an option is not trivial, since the mode line is 20346 supporting such an option is not trivial, since the mode line is
20337 made up of many separate strings. */ 20347 made up of many separate strings. */
@@ -22481,7 +22491,7 @@ init_glyph_string (struct glyph_string *s,
22481/* Append the list of glyph strings with head H and tail T to the list 22491/* Append the list of glyph strings with head H and tail T to the list
22482 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ 22492 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22483 22493
22484static inline void 22494static void
22485append_glyph_string_lists (struct glyph_string **head, struct glyph_string **tail, 22495append_glyph_string_lists (struct glyph_string **head, struct glyph_string **tail,
22486 struct glyph_string *h, struct glyph_string *t) 22496 struct glyph_string *h, struct glyph_string *t)
22487{ 22497{
@@ -22501,7 +22511,7 @@ append_glyph_string_lists (struct glyph_string **head, struct glyph_string **tai
22501 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the 22511 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22502 result. */ 22512 result. */
22503 22513
22504static inline void 22514static void
22505prepend_glyph_string_lists (struct glyph_string **head, struct glyph_string **tail, 22515prepend_glyph_string_lists (struct glyph_string **head, struct glyph_string **tail,
22506 struct glyph_string *h, struct glyph_string *t) 22516 struct glyph_string *h, struct glyph_string *t)
22507{ 22517{
@@ -22520,7 +22530,7 @@ prepend_glyph_string_lists (struct glyph_string **head, struct glyph_string **ta
22520/* Append glyph string S to the list with head *HEAD and tail *TAIL. 22530/* Append glyph string S to the list with head *HEAD and tail *TAIL.
22521 Set *HEAD and *TAIL to the resulting list. */ 22531 Set *HEAD and *TAIL to the resulting list. */
22522 22532
22523static inline void 22533static void
22524append_glyph_string (struct glyph_string **head, struct glyph_string **tail, 22534append_glyph_string (struct glyph_string **head, struct glyph_string **tail,
22525 struct glyph_string *s) 22535 struct glyph_string *s)
22526{ 22536{
@@ -22535,7 +22545,7 @@ append_glyph_string (struct glyph_string **head, struct glyph_string **tail,
22535 Value is a pointer to a realized face that is ready for display if 22545 Value is a pointer to a realized face that is ready for display if
22536 DISPLAY_P is non-zero. */ 22546 DISPLAY_P is non-zero. */
22537 22547
22538static inline struct face * 22548static struct face *
22539get_char_face_and_encoding (struct frame *f, int c, int face_id, 22549get_char_face_and_encoding (struct frame *f, int c, int face_id,
22540 XChar2b *char2b, int display_p) 22550 XChar2b *char2b, int display_p)
22541{ 22551{
@@ -22568,7 +22578,7 @@ get_char_face_and_encoding (struct frame *f, int c, int face_id,
22568 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is 22578 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22569 a pointer to a realized face that is ready for display. */ 22579 a pointer to a realized face that is ready for display. */
22570 22580
22571static inline struct face * 22581static struct face *
22572get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph, 22582get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
22573 XChar2b *char2b, int *two_byte_p) 22583 XChar2b *char2b, int *two_byte_p)
22574{ 22584{
@@ -22605,7 +22615,7 @@ get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
22605/* Get glyph code of character C in FONT in the two-byte form CHAR2B. 22615/* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22606 Return 1 if FONT has a glyph for C, otherwise return 0. */ 22616 Return 1 if FONT has a glyph for C, otherwise return 0. */
22607 22617
22608static inline int 22618static int
22609get_char_glyph_code (int c, struct font *font, XChar2b *char2b) 22619get_char_glyph_code (int c, struct font *font, XChar2b *char2b)
22610{ 22620{
22611 unsigned code; 22621 unsigned code;
@@ -23079,7 +23089,7 @@ right_overwriting (struct glyph_string *s)
23079 first glyph following S. LAST_X is the right-most x-position + 1 23089 first glyph following S. LAST_X is the right-most x-position + 1
23080 in the drawing area. */ 23090 in the drawing area. */
23081 23091
23082static inline void 23092static void
23083set_glyph_string_background_width (struct glyph_string *s, int start, int last_x) 23093set_glyph_string_background_width (struct glyph_string *s, int start, int last_x)
23084{ 23094{
23085 /* If the face of this glyph string has to be drawn to the end of 23095 /* If the face of this glyph string has to be drawn to the end of
@@ -23640,7 +23650,7 @@ draw_glyphs (struct window *w, int x, struct glyph_row *row,
23640/* Store one glyph for IT->char_to_display in IT->glyph_row. 23650/* Store one glyph for IT->char_to_display in IT->glyph_row.
23641 Called from x_produce_glyphs when IT->glyph_row is non-null. */ 23651 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23642 23652
23643static inline void 23653static void
23644append_glyph (struct it *it) 23654append_glyph (struct it *it)
23645{ 23655{
23646 struct glyph *glyph; 23656 struct glyph *glyph;
@@ -23714,7 +23724,7 @@ append_glyph (struct it *it)
23714 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is 23724 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23715 non-null. */ 23725 non-null. */
23716 23726
23717static inline void 23727static void
23718append_composite_glyph (struct it *it) 23728append_composite_glyph (struct it *it)
23719{ 23729{
23720 struct glyph *glyph; 23730 struct glyph *glyph;
@@ -23783,7 +23793,7 @@ append_composite_glyph (struct it *it)
23783/* Change IT->ascent and IT->height according to the setting of 23793/* Change IT->ascent and IT->height according to the setting of
23784 IT->voffset. */ 23794 IT->voffset. */
23785 23795
23786static inline void 23796static void
23787take_vertical_position_into_account (struct it *it) 23797take_vertical_position_into_account (struct it *it)
23788{ 23798{
23789 if (it->voffset) 23799 if (it->voffset)
@@ -25321,7 +25331,7 @@ x_write_glyphs (struct glyph *start, int len)
25321 if (updated_row->reversed_p && chpos >= updated_row->used[TEXT_AREA]) 25331 if (updated_row->reversed_p && chpos >= updated_row->used[TEXT_AREA])
25322 chpos = updated_row->used[TEXT_AREA] - 1; 25332 chpos = updated_row->used[TEXT_AREA] - 1;
25323 25333
25324 BLOCK_INPUT; 25334 block_input ();
25325 25335
25326 /* Write glyphs. */ 25336 /* Write glyphs. */
25327 25337
@@ -25339,7 +25349,7 @@ x_write_glyphs (struct glyph *start, int len)
25339 && chpos < hpos + len) 25349 && chpos < hpos + len)
25340 updated_window->phys_cursor_on_p = 0; 25350 updated_window->phys_cursor_on_p = 0;
25341 25351
25342 UNBLOCK_INPUT; 25352 unblock_input ();
25343 25353
25344 /* Advance the output cursor. */ 25354 /* Advance the output cursor. */
25345 output_cursor.hpos += len; 25355 output_cursor.hpos += len;
@@ -25362,7 +25372,7 @@ x_insert_glyphs (struct glyph *start, int len)
25362 ptrdiff_t hpos; 25372 ptrdiff_t hpos;
25363 25373
25364 eassert (updated_window && updated_row); 25374 eassert (updated_window && updated_row);
25365 BLOCK_INPUT; 25375 block_input ();
25366 w = updated_window; 25376 w = updated_window;
25367 f = XFRAME (WINDOW_FRAME (w)); 25377 f = XFRAME (WINDOW_FRAME (w));
25368 25378
@@ -25396,7 +25406,7 @@ x_insert_glyphs (struct glyph *start, int len)
25396 /* Advance the output cursor. */ 25406 /* Advance the output cursor. */
25397 output_cursor.hpos += len; 25407 output_cursor.hpos += len;
25398 output_cursor.x += shift_by_width; 25408 output_cursor.x += shift_by_width;
25399 UNBLOCK_INPUT; 25409 unblock_input ();
25400} 25410}
25401 25411
25402 25412
@@ -25465,10 +25475,10 @@ x_clear_end_of_line (int to_x)
25465 /* Prevent inadvertently clearing to end of the X window. */ 25475 /* Prevent inadvertently clearing to end of the X window. */
25466 if (to_x > from_x && to_y > from_y) 25476 if (to_x > from_x && to_y > from_y)
25467 { 25477 {
25468 BLOCK_INPUT; 25478 block_input ();
25469 FRAME_RIF (f)->clear_frame_area (f, from_x, from_y, 25479 FRAME_RIF (f)->clear_frame_area (f, from_x, from_y,
25470 to_x - from_x, to_y - from_y); 25480 to_x - from_x, to_y - from_y);
25471 UNBLOCK_INPUT; 25481 unblock_input ();
25472 } 25482 }
25473} 25483}
25474 25484
@@ -25795,7 +25805,7 @@ x_fix_overlapping_area (struct window *w, struct glyph_row *row,
25795{ 25805{
25796 int i, x; 25806 int i, x;
25797 25807
25798 BLOCK_INPUT; 25808 block_input ();
25799 25809
25800 x = 0; 25810 x = 0;
25801 for (i = 0; i < row->used[area];) 25811 for (i = 0; i < row->used[area];)
@@ -25823,7 +25833,7 @@ x_fix_overlapping_area (struct window *w, struct glyph_row *row,
25823 } 25833 }
25824 } 25834 }
25825 25835
25826 UNBLOCK_INPUT; 25836 unblock_input ();
25827} 25837}
25828 25838
25829 25839
@@ -26041,7 +26051,7 @@ display_and_set_cursor (struct window *w, int on,
26041 || (0 <= hpos && hpos < glyph_row->used[TEXT_AREA])) 26051 || (0 <= hpos && hpos < glyph_row->used[TEXT_AREA]))
26042 glyph = glyph_row->glyphs[TEXT_AREA] + hpos; 26052 glyph = glyph_row->glyphs[TEXT_AREA] + hpos;
26043 26053
26044 eassert (interrupt_input_blocked); 26054 eassert (input_blocked_p ());
26045 26055
26046 /* Set new_cursor_type to the cursor we want to be displayed. */ 26056 /* Set new_cursor_type to the cursor we want to be displayed. */
26047 new_cursor_type = get_window_cursor_type (w, glyph, 26057 new_cursor_type = get_window_cursor_type (w, glyph,
@@ -26111,10 +26121,10 @@ update_window_cursor (struct window *w, int on)
26111 if (row->reversed_p && hpos >= row->used[TEXT_AREA]) 26121 if (row->reversed_p && hpos >= row->used[TEXT_AREA])
26112 hpos = row->used[TEXT_AREA] - 1; 26122 hpos = row->used[TEXT_AREA] - 1;
26113 26123
26114 BLOCK_INPUT; 26124 block_input ();
26115 display_and_set_cursor (w, on, hpos, vpos, 26125 display_and_set_cursor (w, on, hpos, vpos,
26116 w->phys_cursor.x, w->phys_cursor.y); 26126 w->phys_cursor.x, w->phys_cursor.y);
26117 UNBLOCK_INPUT; 26127 unblock_input ();
26118 } 26128 }
26119} 26129}
26120 26130
@@ -26292,10 +26302,10 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
26292 if (row->reversed_p && hpos >= row->used[TEXT_AREA]) 26302 if (row->reversed_p && hpos >= row->used[TEXT_AREA])
26293 hpos = row->used[TEXT_AREA] - 1; 26303 hpos = row->used[TEXT_AREA] - 1;
26294 26304
26295 BLOCK_INPUT; 26305 block_input ();
26296 display_and_set_cursor (w, 1, hpos, w->phys_cursor.vpos, 26306 display_and_set_cursor (w, 1, hpos, w->phys_cursor.vpos,
26297 w->phys_cursor.x, w->phys_cursor.y); 26307 w->phys_cursor.x, w->phys_cursor.y);
26298 UNBLOCK_INPUT; 26308 unblock_input ();
26299 } 26309 }
26300#endif /* HAVE_WINDOW_SYSTEM */ 26310#endif /* HAVE_WINDOW_SYSTEM */
26301 } 26311 }
@@ -28110,11 +28120,11 @@ x_clear_window_mouse_face (struct window *w)
28110 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame)); 28120 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
28111 Lisp_Object window; 28121 Lisp_Object window;
28112 28122
28113 BLOCK_INPUT; 28123 block_input ();
28114 XSETWINDOW (window, w); 28124 XSETWINDOW (window, w);
28115 if (EQ (window, hlinfo->mouse_face_window)) 28125 if (EQ (window, hlinfo->mouse_face_window))
28116 clear_mouse_face (hlinfo); 28126 clear_mouse_face (hlinfo);
28117 UNBLOCK_INPUT; 28127 unblock_input ();
28118} 28128}
28119 28129
28120 28130
@@ -28684,6 +28694,7 @@ syms_of_xdisp (void)
28684 staticpro (&Vmessage_stack); 28694 staticpro (&Vmessage_stack);
28685 28695
28686 DEFSYM (Qinhibit_redisplay, "inhibit-redisplay"); 28696 DEFSYM (Qinhibit_redisplay, "inhibit-redisplay");
28697 DEFSYM (Qredisplay_internal, "redisplay_internal (C function)");
28687 28698
28688 message_dolog_marker1 = Fmake_marker (); 28699 message_dolog_marker1 = Fmake_marker ();
28689 staticpro (&message_dolog_marker1); 28700 staticpro (&message_dolog_marker1);
@@ -28923,12 +28934,6 @@ A value of nil means to respect the value of `truncate-lines'.
28923If `word-wrap' is enabled, you might want to reduce this. */); 28934If `word-wrap' is enabled, you might want to reduce this. */);
28924 Vtruncate_partial_width_windows = make_number (50); 28935 Vtruncate_partial_width_windows = make_number (50);
28925 28936
28926 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video,
28927 doc: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28928Any other value means to use the appropriate face, `mode-line',
28929`header-line', or `menu' respectively. */);
28930 mode_line_inverse_video = 1;
28931
28932 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit, 28937 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit,
28933 doc: /* Maximum buffer size for which line number should be displayed. 28938 doc: /* Maximum buffer size for which line number should be displayed.
28934If the buffer is bigger than this, the line number does not appear 28939If the buffer is bigger than this, the line number does not appear
@@ -28981,7 +28986,7 @@ and is used only on frames for which no explicit name has been set
28981 doc: /* Maximum number of lines to keep in the message log buffer. 28986 doc: /* Maximum number of lines to keep in the message log buffer.
28982If nil, disable message logging. If t, log messages but don't truncate 28987If nil, disable message logging. If t, log messages but don't truncate
28983the buffer when it becomes large. */); 28988the buffer when it becomes large. */);
28984 Vmessage_log_max = make_number (100); 28989 Vmessage_log_max = make_number (1000);
28985 28990
28986 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions, 28991 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions,
28987 doc: /* Functions called before redisplay, if window sizes have changed. 28992 doc: /* Functions called before redisplay, if window sizes have changed.
@@ -29352,11 +29357,7 @@ init_xdisp (void)
29352 help_echo_showing_p = 0; 29357 help_echo_showing_p = 0;
29353} 29358}
29354 29359
29355/* Since w32 does not support atimers, it defines its own implementation of 29360/* Platform-independent portion of hourglass implementation. */
29356 the following three functions in w32fns.c. */
29357#ifndef HAVE_NTGUI
29358
29359/* Platform-independent portion of hourglass implementation. */
29360 29361
29361/* Cancel a currently active hourglass timer, and start a new one. */ 29362/* Cancel a currently active hourglass timer, and start a new one. */
29362void 29363void
@@ -29378,6 +29379,10 @@ start_hourglass (void)
29378 else 29379 else
29379 delay = make_emacs_time (DEFAULT_HOURGLASS_DELAY, 0); 29380 delay = make_emacs_time (DEFAULT_HOURGLASS_DELAY, 0);
29380 29381
29382#ifdef WINDOWSNT
29383 w32_note_current_window ();
29384#endif
29385
29381 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, 29386 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay,
29382 show_hourglass, NULL); 29387 show_hourglass, NULL);
29383#endif 29388#endif
@@ -29400,4 +29405,3 @@ cancel_hourglass (void)
29400 hide_hourglass (); 29405 hide_hourglass ();
29401#endif 29406#endif
29402} 29407}
29403#endif /* ! HAVE_NTGUI */
diff --git a/src/xfaces.c b/src/xfaces.c
index 51e568547ee..3e6e9dc8ec0 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -601,13 +601,13 @@ x_free_dpy_colors (Display *dpy, Screen *screen, Colormap cmap,
601/* Create and return a GC for use on frame F. GC values and mask 601/* Create and return a GC for use on frame F. GC values and mask
602 are given by XGCV and MASK. */ 602 are given by XGCV and MASK. */
603 603
604static inline GC 604static GC
605x_create_gc (struct frame *f, long unsigned int mask, XGCValues *xgcv) 605x_create_gc (struct frame *f, long unsigned int mask, XGCValues *xgcv)
606{ 606{
607 GC gc; 607 GC gc;
608 BLOCK_INPUT; 608 block_input ();
609 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, xgcv); 609 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, xgcv);
610 UNBLOCK_INPUT; 610 unblock_input ();
611 IF_DEBUG (++ngcs); 611 IF_DEBUG (++ngcs);
612 return gc; 612 return gc;
613} 613}
@@ -615,10 +615,10 @@ x_create_gc (struct frame *f, long unsigned int mask, XGCValues *xgcv)
615 615
616/* Free GC which was used on frame F. */ 616/* Free GC which was used on frame F. */
617 617
618static inline void 618static void
619x_free_gc (struct frame *f, GC gc) 619x_free_gc (struct frame *f, GC gc)
620{ 620{
621 eassert (interrupt_input_blocked); 621 eassert (input_blocked_p ());
622 IF_DEBUG (eassert (--ngcs >= 0)); 622 IF_DEBUG (eassert (--ngcs >= 0));
623 XFreeGC (FRAME_X_DISPLAY (f), gc); 623 XFreeGC (FRAME_X_DISPLAY (f), gc);
624} 624}
@@ -628,13 +628,13 @@ x_free_gc (struct frame *f, GC gc)
628#ifdef HAVE_NTGUI 628#ifdef HAVE_NTGUI
629/* W32 emulation of GCs */ 629/* W32 emulation of GCs */
630 630
631static inline GC 631static GC
632x_create_gc (struct frame *f, unsigned long mask, XGCValues *xgcv) 632x_create_gc (struct frame *f, unsigned long mask, XGCValues *xgcv)
633{ 633{
634 GC gc; 634 GC gc;
635 BLOCK_INPUT; 635 block_input ();
636 gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, xgcv); 636 gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, xgcv);
637 UNBLOCK_INPUT; 637 unblock_input ();
638 IF_DEBUG (++ngcs); 638 IF_DEBUG (++ngcs);
639 return gc; 639 return gc;
640} 640}
@@ -642,7 +642,7 @@ x_create_gc (struct frame *f, unsigned long mask, XGCValues *xgcv)
642 642
643/* Free GC which was used on frame F. */ 643/* Free GC which was used on frame F. */
644 644
645static inline void 645static void
646x_free_gc (struct frame *f, GC gc) 646x_free_gc (struct frame *f, GC gc)
647{ 647{
648 IF_DEBUG (eassert (--ngcs >= 0)); 648 IF_DEBUG (eassert (--ngcs >= 0));
@@ -654,7 +654,7 @@ x_free_gc (struct frame *f, GC gc)
654#ifdef HAVE_NS 654#ifdef HAVE_NS
655/* NS emulation of GCs */ 655/* NS emulation of GCs */
656 656
657static inline GC 657static GC
658x_create_gc (struct frame *f, 658x_create_gc (struct frame *f,
659 unsigned long mask, 659 unsigned long mask,
660 XGCValues *xgcv) 660 XGCValues *xgcv)
@@ -664,7 +664,7 @@ x_create_gc (struct frame *f,
664 return gc; 664 return gc;
665} 665}
666 666
667static inline void 667static void
668x_free_gc (struct frame *f, GC gc) 668x_free_gc (struct frame *f, GC gc)
669{ 669{
670 xfree (gc); 670 xfree (gc);
@@ -677,7 +677,7 @@ x_free_gc (struct frame *f, GC gc)
677 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in 677 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
678 Lisp function definitions. */ 678 Lisp function definitions. */
679 679
680static inline struct frame * 680static struct frame *
681frame_or_selected_frame (Lisp_Object frame, int nparam) 681frame_or_selected_frame (Lisp_Object frame, int nparam)
682{ 682{
683 if (NILP (frame)) 683 if (NILP (frame))
@@ -907,7 +907,7 @@ load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr,
907 907
908 CHECK_TYPE (!NILP (Fbitmap_spec_p (name)), Qbitmap_spec_p, name); 908 CHECK_TYPE (!NILP (Fbitmap_spec_p (name)), Qbitmap_spec_p, name);
909 909
910 BLOCK_INPUT; 910 block_input ();
911 if (CONSP (name)) 911 if (CONSP (name))
912 { 912 {
913 /* Decode a bitmap spec into a bitmap. */ 913 /* Decode a bitmap spec into a bitmap. */
@@ -927,7 +927,7 @@ load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr,
927 /* It must be a string -- a file name. */ 927 /* It must be a string -- a file name. */
928 bitmap_id = x_create_bitmap_from_file (f, name); 928 bitmap_id = x_create_bitmap_from_file (f, name);
929 } 929 }
930 UNBLOCK_INPUT; 930 unblock_input ();
931 931
932 if (bitmap_id < 0) 932 if (bitmap_id < 0)
933 { 933 {
@@ -991,7 +991,7 @@ parse_rgb_list (Lisp_Object rgb_list, XColor *color)
991 non-zero, then the `standard' definition of the same color is 991 non-zero, then the `standard' definition of the same color is
992 returned in it. */ 992 returned in it. */
993 993
994static int 994static bool
995tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color, 995tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color,
996 XColor *std_color) 996 XColor *std_color)
997{ 997{
@@ -1052,11 +1052,11 @@ tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color,
1052 1052
1053/* A version of defined_color for non-X frames. */ 1053/* A version of defined_color for non-X frames. */
1054 1054
1055static int 1055static bool
1056tty_defined_color (struct frame *f, const char *color_name, 1056tty_defined_color (struct frame *f, const char *color_name,
1057 XColor *color_def, int alloc) 1057 XColor *color_def, bool alloc)
1058{ 1058{
1059 int status = 1; 1059 bool status = 1;
1060 1060
1061 /* Defaults. */ 1061 /* Defaults. */
1062 color_def->pixel = FACE_TTY_DEFAULT_COLOR; 1062 color_def->pixel = FACE_TTY_DEFAULT_COLOR;
@@ -1084,13 +1084,13 @@ tty_defined_color (struct frame *f, const char *color_name,
1084 1084
1085/* Decide if color named COLOR_NAME is valid for the display 1085/* Decide if color named COLOR_NAME is valid for the display
1086 associated with the frame F; if so, return the rgb values in 1086 associated with the frame F; if so, return the rgb values in
1087 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell. 1087 COLOR_DEF. If ALLOC, allocate a new colormap cell.
1088 1088
1089 This does the right thing for any type of frame. */ 1089 This does the right thing for any type of frame. */
1090 1090
1091static int 1091static bool
1092defined_color (struct frame *f, const char *color_name, XColor *color_def, 1092defined_color (struct frame *f, const char *color_name, XColor *color_def,
1093 int alloc) 1093 bool alloc)
1094{ 1094{
1095 if (!FRAME_WINDOW_P (f)) 1095 if (!FRAME_WINDOW_P (f))
1096 return tty_defined_color (f, color_name, color_def, alloc); 1096 return tty_defined_color (f, color_name, color_def, alloc);
@@ -1364,9 +1364,9 @@ unload_color (struct frame *f, long unsigned int pixel)
1364#ifdef HAVE_X_WINDOWS 1364#ifdef HAVE_X_WINDOWS
1365 if (pixel != -1) 1365 if (pixel != -1)
1366 { 1366 {
1367 BLOCK_INPUT; 1367 block_input ();
1368 x_free_colors (f, &pixel, 1); 1368 x_free_colors (f, &pixel, 1);
1369 UNBLOCK_INPUT; 1369 unblock_input ();
1370 } 1370 }
1371#endif 1371#endif
1372} 1372}
@@ -1382,7 +1382,7 @@ free_face_colors (struct frame *f, struct face *face)
1382 if (face->colors_copied_bitwise_p) 1382 if (face->colors_copied_bitwise_p)
1383 return; 1383 return;
1384 1384
1385 BLOCK_INPUT; 1385 block_input ();
1386 1386
1387 if (!face->foreground_defaulted_p) 1387 if (!face->foreground_defaulted_p)
1388 { 1388 {
@@ -1424,7 +1424,7 @@ free_face_colors (struct frame *f, struct face *face)
1424 IF_DEBUG (--ncolors_allocated); 1424 IF_DEBUG (--ncolors_allocated);
1425 } 1425 }
1426 1426
1427 UNBLOCK_INPUT; 1427 unblock_input ();
1428#endif /* HAVE_X_WINDOWS */ 1428#endif /* HAVE_X_WINDOWS */
1429} 1429}
1430 1430
@@ -1920,7 +1920,7 @@ struct named_merge_point
1920 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list 1920 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1921 pointed to by NAMED_MERGE_POINTS, and return 1. */ 1921 pointed to by NAMED_MERGE_POINTS, and return 1. */
1922 1922
1923static inline int 1923static int
1924push_named_merge_point (struct named_merge_point *new_named_merge_point, 1924push_named_merge_point (struct named_merge_point *new_named_merge_point,
1925 Lisp_Object face_name, 1925 Lisp_Object face_name,
1926 enum named_merge_point_kind named_merge_point_kind, 1926 enum named_merge_point_kind named_merge_point_kind,
@@ -2004,7 +2004,7 @@ resolve_face_name (Lisp_Object face_name, int signal_p)
2004 face text properties; Ediff uses that). If SIGNAL_P is non-zero, 2004 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2005 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P 2005 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2006 is zero, value is nil if FACE_NAME is not a valid face name. */ 2006 is zero, value is nil if FACE_NAME is not a valid face name. */
2007static inline Lisp_Object 2007static Lisp_Object
2008lface_from_face_name_no_resolve (struct frame *f, Lisp_Object face_name, 2008lface_from_face_name_no_resolve (struct frame *f, Lisp_Object face_name,
2009 int signal_p) 2009 int signal_p)
2010{ 2010{
@@ -2033,7 +2033,7 @@ lface_from_face_name_no_resolve (struct frame *f, Lisp_Object face_name,
2033 non-zero, signal an error if FACE_NAME is not a valid face name. 2033 non-zero, signal an error if FACE_NAME is not a valid face name.
2034 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face 2034 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2035 name. */ 2035 name. */
2036static inline Lisp_Object 2036static Lisp_Object
2037lface_from_face_name (struct frame *f, Lisp_Object face_name, int signal_p) 2037lface_from_face_name (struct frame *f, Lisp_Object face_name, int signal_p)
2038{ 2038{
2039 face_name = resolve_face_name (face_name, signal_p); 2039 face_name = resolve_face_name (face_name, signal_p);
@@ -2047,7 +2047,7 @@ lface_from_face_name (struct frame *f, Lisp_Object face_name, int signal_p)
2047 is non-zero, signal an error if FACE_NAME does not name a face. 2047 is non-zero, signal an error if FACE_NAME does not name a face.
2048 Otherwise, value is zero if FACE_NAME is not a face. */ 2048 Otherwise, value is zero if FACE_NAME is not a face. */
2049 2049
2050static inline int 2050static int
2051get_lface_attributes_no_remap (struct frame *f, Lisp_Object face_name, 2051get_lface_attributes_no_remap (struct frame *f, Lisp_Object face_name,
2052 Lisp_Object *attrs, int signal_p) 2052 Lisp_Object *attrs, int signal_p)
2053{ 2053{
@@ -2069,7 +2069,7 @@ get_lface_attributes_no_remap (struct frame *f, Lisp_Object face_name,
2069 non-zero, signal an error if FACE_NAME does not name a face. 2069 non-zero, signal an error if FACE_NAME does not name a face.
2070 Otherwise, value is zero if FACE_NAME is not a face. */ 2070 Otherwise, value is zero if FACE_NAME is not a face. */
2071 2071
2072static inline int 2072static int
2073get_lface_attributes (struct frame *f, Lisp_Object face_name, 2073get_lface_attributes (struct frame *f, Lisp_Object face_name,
2074 Lisp_Object *attrs, int signal_p, 2074 Lisp_Object *attrs, int signal_p,
2075 struct named_merge_point *named_merge_points) 2075 struct named_merge_point *named_merge_points)
@@ -2234,7 +2234,7 @@ merge_face_heights (Lisp_Object from, Lisp_Object to, Lisp_Object invalid)
2234 loops in face inheritance/remapping; it should be 0 when called from 2234 loops in face inheritance/remapping; it should be 0 when called from
2235 other places. */ 2235 other places. */
2236 2236
2237static inline void 2237static void
2238merge_face_vectors (struct frame *f, Lisp_Object *from, Lisp_Object *to, 2238merge_face_vectors (struct frame *f, Lisp_Object *from, Lisp_Object *to,
2239 struct named_merge_point *named_merge_points) 2239 struct named_merge_point *named_merge_points)
2240{ 2240{
@@ -3438,10 +3438,10 @@ DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource,
3438 CHECK_STRING (resource); 3438 CHECK_STRING (resource);
3439 CHECK_STRING (class); 3439 CHECK_STRING (class);
3440 CHECK_LIVE_FRAME (frame); 3440 CHECK_LIVE_FRAME (frame);
3441 BLOCK_INPUT; 3441 block_input ();
3442 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)), 3442 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)),
3443 resource, class, Qnil, Qnil); 3443 resource, class, Qnil, Qnil);
3444 UNBLOCK_INPUT; 3444 unblock_input ();
3445 return value; 3445 return value;
3446} 3446}
3447 3447
@@ -3906,7 +3906,7 @@ return the font name used for CHARACTER. */)
3906 all attributes are `equal'. Tries to be fast because this function 3906 all attributes are `equal'. Tries to be fast because this function
3907 is called quite often. */ 3907 is called quite often. */
3908 3908
3909static inline int 3909static int
3910face_attr_equal_p (Lisp_Object v1, Lisp_Object v2) 3910face_attr_equal_p (Lisp_Object v1, Lisp_Object v2)
3911{ 3911{
3912 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil, 3912 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
@@ -3939,7 +3939,7 @@ face_attr_equal_p (Lisp_Object v1, Lisp_Object v2)
3939 all attributes are `equal'. Tries to be fast because this function 3939 all attributes are `equal'. Tries to be fast because this function
3940 is called quite often. */ 3940 is called quite often. */
3941 3941
3942static inline int 3942static int
3943lface_equal_p (Lisp_Object *v1, Lisp_Object *v2) 3943lface_equal_p (Lisp_Object *v1, Lisp_Object *v2)
3944{ 3944{
3945 int i, equal_p = 1; 3945 int i, equal_p = 1;
@@ -4024,7 +4024,7 @@ For internal use only. */)
4024/* Return a hash code for Lisp string STRING with case ignored. Used 4024/* Return a hash code for Lisp string STRING with case ignored. Used
4025 below in computing a hash value for a Lisp face. */ 4025 below in computing a hash value for a Lisp face. */
4026 4026
4027static inline unsigned 4027static unsigned
4028hash_string_case_insensitive (Lisp_Object string) 4028hash_string_case_insensitive (Lisp_Object string)
4029{ 4029{
4030 const unsigned char *s; 4030 const unsigned char *s;
@@ -4038,7 +4038,7 @@ hash_string_case_insensitive (Lisp_Object string)
4038 4038
4039/* Return a hash code for face attribute vector V. */ 4039/* Return a hash code for face attribute vector V. */
4040 4040
4041static inline unsigned 4041static unsigned
4042lface_hash (Lisp_Object *v) 4042lface_hash (Lisp_Object *v)
4043{ 4043{
4044 return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX]) 4044 return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX])
@@ -4057,7 +4057,7 @@ lface_hash (Lisp_Object *v)
4057 family, point size, weight, width, slant, and font. Both 4057 family, point size, weight, width, slant, and font. Both
4058 LFACE1 and LFACE2 must be fully-specified. */ 4058 LFACE1 and LFACE2 must be fully-specified. */
4059 4059
4060static inline int 4060static int
4061lface_same_font_attributes_p (Lisp_Object *lface1, Lisp_Object *lface2) 4061lface_same_font_attributes_p (Lisp_Object *lface1, Lisp_Object *lface2)
4062{ 4062{
4063 eassert (lface_fully_specified_p (lface1) 4063 eassert (lface_fully_specified_p (lface1)
@@ -4114,12 +4114,12 @@ free_realized_face (struct frame *f, struct face *face)
4114 free_face_fontset (f, face); 4114 free_face_fontset (f, face);
4115 if (face->gc) 4115 if (face->gc)
4116 { 4116 {
4117 BLOCK_INPUT; 4117 block_input ();
4118 if (face->font) 4118 if (face->font)
4119 font_done_for_face (f, face); 4119 font_done_for_face (f, face);
4120 x_free_gc (f, face->gc); 4120 x_free_gc (f, face->gc);
4121 face->gc = 0; 4121 face->gc = 0;
4122 UNBLOCK_INPUT; 4122 unblock_input ();
4123 } 4123 }
4124 4124
4125 free_face_colors (f, face); 4125 free_face_colors (f, face);
@@ -4153,7 +4153,7 @@ prepare_face_for_display (struct frame *f, struct face *face)
4153 xgcv.graphics_exposures = False; 4153 xgcv.graphics_exposures = False;
4154#endif 4154#endif
4155 4155
4156 BLOCK_INPUT; 4156 block_input ();
4157#ifdef HAVE_X_WINDOWS 4157#ifdef HAVE_X_WINDOWS
4158 if (face->stipple) 4158 if (face->stipple)
4159 { 4159 {
@@ -4165,7 +4165,7 @@ prepare_face_for_display (struct frame *f, struct face *face)
4165 face->gc = x_create_gc (f, mask, &xgcv); 4165 face->gc = x_create_gc (f, mask, &xgcv);
4166 if (face->font) 4166 if (face->font)
4167 font_prepare_for_face (f, face); 4167 font_prepare_for_face (f, face);
4168 UNBLOCK_INPUT; 4168 unblock_input ();
4169 } 4169 }
4170#endif /* HAVE_WINDOW_SYSTEM */ 4170#endif /* HAVE_WINDOW_SYSTEM */
4171} 4171}
@@ -4263,12 +4263,12 @@ clear_face_gcs (struct face_cache *c)
4263 struct face *face = c->faces_by_id[i]; 4263 struct face *face = c->faces_by_id[i];
4264 if (face && face->gc) 4264 if (face && face->gc)
4265 { 4265 {
4266 BLOCK_INPUT; 4266 block_input ();
4267 if (face->font) 4267 if (face->font)
4268 font_done_for_face (c->f, face); 4268 font_done_for_face (c->f, face);
4269 x_free_gc (c->f, face->gc); 4269 x_free_gc (c->f, face->gc);
4270 face->gc = 0; 4270 face->gc = 0;
4271 UNBLOCK_INPUT; 4271 unblock_input ();
4272 } 4272 }
4273 } 4273 }
4274#endif /* HAVE_WINDOW_SYSTEM */ 4274#endif /* HAVE_WINDOW_SYSTEM */
@@ -4292,7 +4292,7 @@ free_realized_faces (struct face_cache *c)
4292 /* We must block input here because we can't process X events 4292 /* We must block input here because we can't process X events
4293 safely while only some faces are freed, or when the frame's 4293 safely while only some faces are freed, or when the frame's
4294 current matrix still references freed faces. */ 4294 current matrix still references freed faces. */
4295 BLOCK_INPUT; 4295 block_input ();
4296 4296
4297 for (i = 0; i < c->used; ++i) 4297 for (i = 0; i < c->used; ++i)
4298 { 4298 {
@@ -4314,7 +4314,7 @@ free_realized_faces (struct face_cache *c)
4314 ++windows_or_buffers_changed; 4314 ++windows_or_buffers_changed;
4315 } 4315 }
4316 4316
4317 UNBLOCK_INPUT; 4317 unblock_input ();
4318 } 4318 }
4319} 4319}
4320 4320
@@ -4453,7 +4453,7 @@ uncache_face (struct face_cache *c, struct face *face)
4453 Value is the ID of the face found. If no suitable face is found, 4453 Value is the ID of the face found. If no suitable face is found,
4454 realize a new one. */ 4454 realize a new one. */
4455 4455
4456static inline int 4456static int
4457lookup_face (struct frame *f, Lisp_Object *attr) 4457lookup_face (struct frame *f, Lisp_Object *attr)
4458{ 4458{
4459 struct face_cache *cache = FRAME_FACE_CACHE (f); 4459 struct face_cache *cache = FRAME_FACE_CACHE (f);
@@ -5275,7 +5275,7 @@ realize_basic_faces (struct frame *f)
5275 5275
5276 /* Block input here so that we won't be surprised by an X expose 5276 /* Block input here so that we won't be surprised by an X expose
5277 event, for instance, without having the faces set up. */ 5277 event, for instance, without having the faces set up. */
5278 BLOCK_INPUT; 5278 block_input ();
5279 specbind (Qscalable_fonts_allowed, Qt); 5279 specbind (Qscalable_fonts_allowed, Qt);
5280 5280
5281 if (realize_default_face (f)) 5281 if (realize_default_face (f))
@@ -5306,7 +5306,7 @@ realize_basic_faces (struct frame *f)
5306 } 5306 }
5307 5307
5308 unbind_to (count, Qnil); 5308 unbind_to (count, Qnil);
5309 UNBLOCK_INPUT; 5309 unblock_input ();
5310 return success_p; 5310 return success_p;
5311} 5311}
5312 5312
@@ -6352,7 +6352,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6352 int red, green, blue; 6352 int red, green, blue;
6353 int num; 6353 int num;
6354 6354
6355 BLOCK_INPUT; 6355 block_input ();
6356 6356
6357 while (fgets (buf, sizeof (buf), fp) != NULL) { 6357 while (fgets (buf, sizeof (buf), fp) != NULL) {
6358 if (sscanf (buf, "%u %u %u %n", &red, &green, &blue, &num) == 3) 6358 if (sscanf (buf, "%u %u %u %n", &red, &green, &blue, &num) == 3)
@@ -6372,7 +6372,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6372 } 6372 }
6373 fclose (fp); 6373 fclose (fp);
6374 6374
6375 UNBLOCK_INPUT; 6375 unblock_input ();
6376 } 6376 }
6377 6377
6378 return cmap; 6378 return cmap;
diff --git a/src/xfns.c b/src/xfns.c
index 8304a3df04f..d497cffe3df 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -425,7 +425,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
425 unsigned char *tmp_data = NULL; 425 unsigned char *tmp_data = NULL;
426 Atom target_type = XA_CARDINAL; 426 Atom target_type = XA_CARDINAL;
427 427
428 BLOCK_INPUT; 428 block_input ();
429 429
430 x_catch_errors (dpy); 430 x_catch_errors (dpy);
431 431
@@ -543,7 +543,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
543 543
544 x_uncatch_errors (); 544 x_uncatch_errors ();
545 545
546 UNBLOCK_INPUT; 546 unblock_input ();
547 547
548 if (had_errors) return; 548 if (had_errors) return;
549 549
@@ -575,27 +575,27 @@ gamma_correct (struct frame *f, XColor *color)
575 575
576 576
577/* Decide if color named COLOR_NAME is valid for use on frame F. If 577/* Decide if color named COLOR_NAME is valid for use on frame F. If
578 so, return the RGB values in COLOR. If ALLOC_P is non-zero, 578 so, return the RGB values in COLOR. If ALLOC_P,
579 allocate the color. Value is zero if COLOR_NAME is invalid, or 579 allocate the color. Value is false if COLOR_NAME is invalid, or
580 no color could be allocated. */ 580 no color could be allocated. */
581 581
582int 582bool
583x_defined_color (struct frame *f, const char *color_name, 583x_defined_color (struct frame *f, const char *color_name,
584 XColor *color, int alloc_p) 584 XColor *color, bool alloc_p)
585{ 585{
586 int success_p = 0; 586 bool success_p = 0;
587 Display *dpy = FRAME_X_DISPLAY (f); 587 Display *dpy = FRAME_X_DISPLAY (f);
588 Colormap cmap = FRAME_X_COLORMAP (f); 588 Colormap cmap = FRAME_X_COLORMAP (f);
589 589
590 BLOCK_INPUT; 590 block_input ();
591#ifdef USE_GTK 591#ifdef USE_GTK
592 success_p = xg_check_special_colors (f, color_name, color); 592 success_p = xg_check_special_colors (f, color_name, color);
593#endif 593#endif
594 if (!success_p) 594 if (!success_p)
595 success_p = XParseColor (dpy, cmap, color_name, color); 595 success_p = XParseColor (dpy, cmap, color_name, color) != 0;
596 if (success_p && alloc_p) 596 if (success_p && alloc_p)
597 success_p = x_alloc_nearest_color (f, cmap, color); 597 success_p = x_alloc_nearest_color (f, cmap, color);
598 UNBLOCK_INPUT; 598 unblock_input ();
599 599
600 return success_p; 600 return success_p;
601} 601}
@@ -656,8 +656,8 @@ x_set_tool_bar_position (struct frame *f,
656 if (EQ (new_value, old_value)) return; 656 if (EQ (new_value, old_value)) return;
657 657
658#ifdef USE_GTK 658#ifdef USE_GTK
659 if (xg_change_toolbar_position (f, new_value)) 659 xg_change_toolbar_position (f, new_value);
660 fset_tool_bar_position (f, new_value); 660 fset_tool_bar_position (f, new_value);
661#endif 661#endif
662} 662}
663 663
@@ -679,7 +679,7 @@ xg_set_icon (FRAME_PTR f, Lisp_Object file)
679 GdkPixbuf *pixbuf; 679 GdkPixbuf *pixbuf;
680 GError *err = NULL; 680 GError *err = NULL;
681 char *filename = SSDATA (found); 681 char *filename = SSDATA (found);
682 BLOCK_INPUT; 682 block_input ();
683 683
684 pixbuf = gdk_pixbuf_new_from_file (filename, &err); 684 pixbuf = gdk_pixbuf_new_from_file (filename, &err);
685 685
@@ -694,7 +694,7 @@ xg_set_icon (FRAME_PTR f, Lisp_Object file)
694 else 694 else
695 g_error_free (err); 695 g_error_free (err);
696 696
697 UNBLOCK_INPUT; 697 unblock_input ();
698 } 698 }
699 699
700 return result; 700 return result;
@@ -737,7 +737,7 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
737 { 737 {
738 Display *dpy = FRAME_X_DISPLAY (f); 738 Display *dpy = FRAME_X_DISPLAY (f);
739 739
740 BLOCK_INPUT; 740 block_input ();
741 XSetForeground (dpy, x->normal_gc, fg); 741 XSetForeground (dpy, x->normal_gc, fg);
742 XSetBackground (dpy, x->reverse_gc, fg); 742 XSetBackground (dpy, x->reverse_gc, fg);
743 743
@@ -748,7 +748,7 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
748 XSetBackground (dpy, x->cursor_gc, x->cursor_pixel); 748 XSetBackground (dpy, x->cursor_gc, x->cursor_pixel);
749 } 749 }
750 750
751 UNBLOCK_INPUT; 751 unblock_input ();
752 752
753 update_face_from_frame_parameter (f, Qforeground_color, arg); 753 update_face_from_frame_parameter (f, Qforeground_color, arg);
754 754
@@ -773,7 +773,7 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
773 { 773 {
774 Display *dpy = FRAME_X_DISPLAY (f); 774 Display *dpy = FRAME_X_DISPLAY (f);
775 775
776 BLOCK_INPUT; 776 block_input ();
777 XSetBackground (dpy, x->normal_gc, bg); 777 XSetBackground (dpy, x->normal_gc, bg);
778 XSetForeground (dpy, x->reverse_gc, bg); 778 XSetForeground (dpy, x->reverse_gc, bg);
779 XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg); 779 XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg);
@@ -797,7 +797,7 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
797 } 797 }
798#endif /* USE_TOOLKIT_SCROLL_BARS */ 798#endif /* USE_TOOLKIT_SCROLL_BARS */
799 799
800 UNBLOCK_INPUT; 800 unblock_input ();
801 update_face_from_frame_parameter (f, Qbackground_color, arg); 801 update_face_from_frame_parameter (f, Qbackground_color, arg);
802 802
803 if (FRAME_VISIBLE_P (f)) 803 if (FRAME_VISIBLE_P (f))
@@ -854,7 +854,7 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
854 unload_color (f, x->mouse_pixel); 854 unload_color (f, x->mouse_pixel);
855 x->mouse_pixel = pixel; 855 x->mouse_pixel = pixel;
856 856
857 BLOCK_INPUT; 857 block_input ();
858 858
859 /* It's not okay to crash if the user selects a screwy cursor. */ 859 /* It's not okay to crash if the user selects a screwy cursor. */
860 x_catch_errors (dpy); 860 x_catch_errors (dpy);
@@ -974,7 +974,7 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
974 x->horizontal_drag_cursor = horizontal_drag_cursor; 974 x->horizontal_drag_cursor = horizontal_drag_cursor;
975 975
976 XFlush (dpy); 976 XFlush (dpy);
977 UNBLOCK_INPUT; 977 unblock_input ();
978 978
979 update_face_from_frame_parameter (f, Qmouse_color, arg); 979 update_face_from_frame_parameter (f, Qmouse_color, arg);
980} 980}
@@ -1031,10 +1031,10 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1031 1031
1032 if (FRAME_X_WINDOW (f) != 0) 1032 if (FRAME_X_WINDOW (f) != 0)
1033 { 1033 {
1034 BLOCK_INPUT; 1034 block_input ();
1035 XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel); 1035 XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel);
1036 XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel); 1036 XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel);
1037 UNBLOCK_INPUT; 1037 unblock_input ();
1038 1038
1039 if (FRAME_VISIBLE_P (f)) 1039 if (FRAME_VISIBLE_P (f))
1040 { 1040 {
@@ -1058,9 +1058,9 @@ x_set_border_pixel (struct frame *f, int pix)
1058 1058
1059 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0) 1059 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0)
1060 { 1060 {
1061 BLOCK_INPUT; 1061 block_input ();
1062 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), pix); 1062 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), pix);
1063 UNBLOCK_INPUT; 1063 unblock_input ();
1064 1064
1065 if (FRAME_VISIBLE_P (f)) 1065 if (FRAME_VISIBLE_P (f))
1066 redraw_frame (f); 1066 redraw_frame (f);
@@ -1112,7 +1112,7 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1112 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) 1112 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1113 return; 1113 return;
1114 1114
1115 BLOCK_INPUT; 1115 block_input ();
1116 if (NILP (arg)) 1116 if (NILP (arg))
1117 result = x_text_icon (f, 1117 result = x_text_icon (f,
1118 SSDATA ((!NILP (f->icon_name) 1118 SSDATA ((!NILP (f->icon_name)
@@ -1123,12 +1123,12 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1123 1123
1124 if (result) 1124 if (result)
1125 { 1125 {
1126 UNBLOCK_INPUT; 1126 unblock_input ();
1127 error ("No icon window available"); 1127 error ("No icon window available");
1128 } 1128 }
1129 1129
1130 XFlush (FRAME_X_DISPLAY (f)); 1130 XFlush (FRAME_X_DISPLAY (f));
1131 UNBLOCK_INPUT; 1131 unblock_input ();
1132} 1132}
1133 1133
1134static void 1134static void
@@ -1149,7 +1149,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1149 if (f->output_data.x->icon_bitmap != 0) 1149 if (f->output_data.x->icon_bitmap != 0)
1150 return; 1150 return;
1151 1151
1152 BLOCK_INPUT; 1152 block_input ();
1153 1153
1154 result = x_text_icon (f, 1154 result = x_text_icon (f,
1155 SSDATA ((!NILP (f->icon_name) 1155 SSDATA ((!NILP (f->icon_name)
@@ -1160,12 +1160,12 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1160 1160
1161 if (result) 1161 if (result)
1162 { 1162 {
1163 UNBLOCK_INPUT; 1163 unblock_input ();
1164 error ("No icon window available"); 1164 error ("No icon window available");
1165 } 1165 }
1166 1166
1167 XFlush (FRAME_X_DISPLAY (f)); 1167 XFlush (FRAME_X_DISPLAY (f));
1168 UNBLOCK_INPUT; 1168 unblock_input ();
1169} 1169}
1170 1170
1171 1171
@@ -1228,10 +1228,10 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1228 { 1228 {
1229 y = FRAME_TOP_MARGIN_HEIGHT (f); 1229 y = FRAME_TOP_MARGIN_HEIGHT (f);
1230 1230
1231 BLOCK_INPUT; 1231 block_input ();
1232 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 1232 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1233 0, y, width, height, False); 1233 0, y, width, height, False);
1234 UNBLOCK_INPUT; 1234 unblock_input ();
1235 } 1235 }
1236 1236
1237 if (nlines > 1 && nlines > olines) 1237 if (nlines > 1 && nlines > olines)
@@ -1239,10 +1239,10 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1239 y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f); 1239 y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f);
1240 height = nlines * FRAME_LINE_HEIGHT (f) - y; 1240 height = nlines * FRAME_LINE_HEIGHT (f) - y;
1241 1241
1242 BLOCK_INPUT; 1242 block_input ();
1243 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 1243 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1244 0, y, width, height, False); 1244 0, y, width, height, False);
1245 UNBLOCK_INPUT; 1245 unblock_input ();
1246 } 1246 }
1247 1247
1248 if (nlines == 0 && WINDOWP (f->menu_bar_window)) 1248 if (nlines == 0 && WINDOWP (f->menu_bar_window))
@@ -1338,10 +1338,10 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1338 /* height can be zero here. */ 1338 /* height can be zero here. */
1339 if (height > 0 && width > 0) 1339 if (height > 0 && width > 0)
1340 { 1340 {
1341 BLOCK_INPUT; 1341 block_input ();
1342 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 1342 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1343 0, y, width, height, False); 1343 0, y, width, height, False);
1344 UNBLOCK_INPUT; 1344 unblock_input ();
1345 } 1345 }
1346 1346
1347 if (WINDOWP (f->tool_bar_window)) 1347 if (WINDOWP (f->tool_bar_window))
@@ -1494,7 +1494,7 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
1494{ 1494{
1495 if (FRAME_X_WINDOW (f)) 1495 if (FRAME_X_WINDOW (f))
1496 { 1496 {
1497 BLOCK_INPUT; 1497 block_input ();
1498 { 1498 {
1499 XTextProperty text, icon; 1499 XTextProperty text, icon;
1500 ptrdiff_t bytes; 1500 ptrdiff_t bytes;
@@ -1586,7 +1586,7 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
1586 if (do_free_text_value) 1586 if (do_free_text_value)
1587 xfree (text.value); 1587 xfree (text.value);
1588 } 1588 }
1589 UNBLOCK_INPUT; 1589 unblock_input ();
1590 } 1590 }
1591} 1591}
1592 1592
@@ -1779,7 +1779,7 @@ hack_wm_protocols (FRAME_PTR f, Widget widget)
1779 int need_focus = 1; 1779 int need_focus = 1;
1780 int need_save = 1; 1780 int need_save = 1;
1781 1781
1782 BLOCK_INPUT; 1782 block_input ();
1783 { 1783 {
1784 Atom type; 1784 Atom type;
1785 unsigned char *catoms; 1785 unsigned char *catoms;
@@ -1827,7 +1827,7 @@ hack_wm_protocols (FRAME_PTR f, Widget widget)
1827 XA_ATOM, 32, PropModeAppend, 1827 XA_ATOM, 32, PropModeAppend,
1828 (unsigned char *) props, count); 1828 (unsigned char *) props, count);
1829 } 1829 }
1830 UNBLOCK_INPUT; 1830 unblock_input ();
1831} 1831}
1832#endif 1832#endif
1833 1833
@@ -2350,7 +2350,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2350 Arg al [25]; 2350 Arg al [25];
2351 int ac; 2351 int ac;
2352 2352
2353 BLOCK_INPUT; 2353 block_input ();
2354 2354
2355 /* Use the resource name as the top-level widget name 2355 /* Use the resource name as the top-level widget name
2356 for looking up resources. Make a non-Lisp copy 2356 for looking up resources. Make a non-Lisp copy
@@ -2572,7 +2572,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2572 f->output_data.x->current_cursor 2572 f->output_data.x->current_cursor
2573 = f->output_data.x->text_cursor); 2573 = f->output_data.x->text_cursor);
2574 2574
2575 UNBLOCK_INPUT; 2575 unblock_input ();
2576 2576
2577 /* This is a no-op, except under Motif. Make sure main areas are 2577 /* This is a no-op, except under Motif. Make sure main areas are
2578 set to something reasonable, in case we get an error later. */ 2578 set to something reasonable, in case we get an error later. */
@@ -2591,7 +2591,7 @@ x_window (FRAME_PTR f)
2591 FRAME_XIC (f) = NULL; 2591 FRAME_XIC (f) = NULL;
2592 if (use_xim) 2592 if (use_xim)
2593 { 2593 {
2594 BLOCK_INPUT; 2594 block_input ();
2595 create_frame_xic (f); 2595 create_frame_xic (f);
2596 if (FRAME_XIC (f)) 2596 if (FRAME_XIC (f))
2597 { 2597 {
@@ -2613,7 +2613,7 @@ x_window (FRAME_PTR f)
2613 attribute_mask, &attributes); 2613 attribute_mask, &attributes);
2614 } 2614 }
2615 } 2615 }
2616 UNBLOCK_INPUT; 2616 unblock_input ();
2617 } 2617 }
2618#endif 2618#endif
2619} 2619}
@@ -2638,7 +2638,7 @@ x_window (struct frame *f)
2638 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask 2638 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
2639 | CWColormap); 2639 | CWColormap);
2640 2640
2641 BLOCK_INPUT; 2641 block_input ();
2642 FRAME_X_WINDOW (f) 2642 FRAME_X_WINDOW (f)
2643 = XCreateWindow (FRAME_X_DISPLAY (f), 2643 = XCreateWindow (FRAME_X_DISPLAY (f),
2644 f->output_data.x->parent_desc, 2644 f->output_data.x->parent_desc,
@@ -2715,7 +2715,7 @@ x_window (struct frame *f)
2715 f->output_data.x->current_cursor 2715 f->output_data.x->current_cursor
2716 = f->output_data.x->text_cursor); 2716 = f->output_data.x->text_cursor);
2717 2717
2718 UNBLOCK_INPUT; 2718 unblock_input ();
2719 2719
2720 if (FRAME_X_WINDOW (f) == 0) 2720 if (FRAME_X_WINDOW (f) == 0)
2721 error ("Unable to create window"); 2721 error ("Unable to create window");
@@ -2768,7 +2768,7 @@ x_icon (struct frame *f, Lisp_Object parms)
2768 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) 2768 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2769 error ("Both left and top icon corners of icon must be specified"); 2769 error ("Both left and top icon corners of icon must be specified");
2770 2770
2771 BLOCK_INPUT; 2771 block_input ();
2772 2772
2773 if (! EQ (icon_x, Qunbound)) 2773 if (! EQ (icon_x, Qunbound))
2774 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); 2774 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
@@ -2787,7 +2787,7 @@ x_icon (struct frame *f, Lisp_Object parms)
2787 ? f->icon_name 2787 ? f->icon_name
2788 : f->name))); 2788 : f->name)));
2789 2789
2790 UNBLOCK_INPUT; 2790 unblock_input ();
2791} 2791}
2792 2792
2793/* Make the GCs needed for this window, setting the 2793/* Make the GCs needed for this window, setting the
@@ -2799,7 +2799,7 @@ x_make_gc (struct frame *f)
2799{ 2799{
2800 XGCValues gc_values; 2800 XGCValues gc_values;
2801 2801
2802 BLOCK_INPUT; 2802 block_input ();
2803 2803
2804 /* Create the GCs of this frame. 2804 /* Create the GCs of this frame.
2805 Note that many default values are used. */ 2805 Note that many default values are used. */
@@ -2847,7 +2847,7 @@ x_make_gc (struct frame *f)
2847 FRAME_BACKGROUND_PIXEL (f), 2847 FRAME_BACKGROUND_PIXEL (f),
2848 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); 2848 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2849 2849
2850 UNBLOCK_INPUT; 2850 unblock_input ();
2851} 2851}
2852 2852
2853 2853
@@ -2858,7 +2858,7 @@ x_free_gcs (struct frame *f)
2858{ 2858{
2859 Display *dpy = FRAME_X_DISPLAY (f); 2859 Display *dpy = FRAME_X_DISPLAY (f);
2860 2860
2861 BLOCK_INPUT; 2861 block_input ();
2862 2862
2863 if (f->output_data.x->normal_gc) 2863 if (f->output_data.x->normal_gc)
2864 { 2864 {
@@ -2884,7 +2884,7 @@ x_free_gcs (struct frame *f)
2884 f->output_data.x->border_tile = 0; 2884 f->output_data.x->border_tile = 0;
2885 } 2885 }
2886 2886
2887 UNBLOCK_INPUT; 2887 unblock_input ();
2888} 2888}
2889 2889
2890 2890
@@ -3007,10 +3007,10 @@ If FRAME is nil, use the selected frame. */)
3007 if (NILP (frame)) 3007 if (NILP (frame))
3008 frame = selected_frame; 3008 frame = selected_frame;
3009 f = XFRAME (frame); 3009 f = XFRAME (frame);
3010 BLOCK_INPUT; 3010 block_input ();
3011 if (FRAME_X_P (f)) 3011 if (FRAME_X_P (f))
3012 x_wm_set_size_hint (f, 0, 0); 3012 x_wm_set_size_hint (f, 0, 0);
3013 UNBLOCK_INPUT; 3013 unblock_input ();
3014 return Qnil; 3014 return Qnil;
3015} 3015}
3016 3016
@@ -3405,9 +3405,9 @@ This function is an internal primitive--use `make-frame' instead. */)
3405 /* Tell the server what size and position, etc, we want, and how 3405 /* Tell the server what size and position, etc, we want, and how
3406 badly we want them. This should be done after we have the menu 3406 badly we want them. This should be done after we have the menu
3407 bar so that its size can be taken into account. */ 3407 bar so that its size can be taken into account. */
3408 BLOCK_INPUT; 3408 block_input ();
3409 x_wm_set_size_hint (f, window_prompting, 0); 3409 x_wm_set_size_hint (f, window_prompting, 0);
3410 UNBLOCK_INPUT; 3410 unblock_input ();
3411 3411
3412 /* Make the window appear on the frame and enable display, unless 3412 /* Make the window appear on the frame and enable display, unless
3413 the caller says not to. However, with explicit parent, Emacs 3413 the caller says not to. However, with explicit parent, Emacs
@@ -3431,7 +3431,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3431 } 3431 }
3432 } 3432 }
3433 3433
3434 BLOCK_INPUT; 3434 block_input ();
3435 3435
3436 /* Set machine name and pid for the purpose of window managers. */ 3436 /* Set machine name and pid for the purpose of window managers. */
3437 set_machine_and_pid_properties (f); 3437 set_machine_and_pid_properties (f);
@@ -3447,7 +3447,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3447 (unsigned char *) &dpyinfo->client_leader_window, 1); 3447 (unsigned char *) &dpyinfo->client_leader_window, 1);
3448 } 3448 }
3449 3449
3450 UNBLOCK_INPUT; 3450 unblock_input ();
3451 3451
3452 /* Initialize `default-minibuffer-frame' in case this is the first 3452 /* Initialize `default-minibuffer-frame' in case this is the first
3453 frame on this terminal. */ 3453 frame on this terminal. */
@@ -3506,7 +3506,7 @@ FRAME nil means use the selected frame. */)
3506 struct frame *f = check_x_frame (frame); 3506 struct frame *f = check_x_frame (frame);
3507 Display *dpy = FRAME_X_DISPLAY (f); 3507 Display *dpy = FRAME_X_DISPLAY (f);
3508 3508
3509 BLOCK_INPUT; 3509 block_input ();
3510 x_catch_errors (dpy); 3510 x_catch_errors (dpy);
3511 3511
3512 if (FRAME_X_EMBEDDED_P (f)) 3512 if (FRAME_X_EMBEDDED_P (f))
@@ -3524,7 +3524,7 @@ FRAME nil means use the selected frame. */)
3524 } 3524 }
3525 3525
3526 x_uncatch_errors (); 3526 x_uncatch_errors ();
3527 UNBLOCK_INPUT; 3527 unblock_input ();
3528 3528
3529 return Qnil; 3529 return Qnil;
3530} 3530}
@@ -4152,9 +4152,9 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display. */
4152void 4152void
4153x_sync (FRAME_PTR f) 4153x_sync (FRAME_PTR f)
4154{ 4154{
4155 BLOCK_INPUT; 4155 block_input ();
4156 XSync (FRAME_X_DISPLAY (f), False); 4156 XSync (FRAME_X_DISPLAY (f), False);
4157 UNBLOCK_INPUT; 4157 unblock_input ();
4158} 4158}
4159 4159
4160 4160
@@ -4229,7 +4229,7 @@ FRAME. Default is to change on the edit X window. */)
4229 nelements = SBYTES (value); 4229 nelements = SBYTES (value);
4230 } 4230 }
4231 4231
4232 BLOCK_INPUT; 4232 block_input ();
4233 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); 4233 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False);
4234 if (! NILP (type)) 4234 if (! NILP (type))
4235 { 4235 {
@@ -4248,7 +4248,7 @@ FRAME. Default is to change on the edit X window. */)
4248 4248
4249 /* Make sure the property is set when we return. */ 4249 /* Make sure the property is set when we return. */
4250 XFlush (FRAME_X_DISPLAY (f)); 4250 XFlush (FRAME_X_DISPLAY (f));
4251 UNBLOCK_INPUT; 4251 unblock_input ();
4252 4252
4253 return value; 4253 return value;
4254} 4254}
@@ -4264,13 +4264,13 @@ FRAME nil or omitted means use the selected frame. Value is PROP. */)
4264 Atom prop_atom; 4264 Atom prop_atom;
4265 4265
4266 CHECK_STRING (prop); 4266 CHECK_STRING (prop);
4267 BLOCK_INPUT; 4267 block_input ();
4268 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); 4268 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False);
4269 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom); 4269 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom);
4270 4270
4271 /* Make sure the property is removed when we return. */ 4271 /* Make sure the property is removed when we return. */
4272 XFlush (FRAME_X_DISPLAY (f)); 4272 XFlush (FRAME_X_DISPLAY (f));
4273 UNBLOCK_INPUT; 4273 unblock_input ();
4274 4274
4275 return prop; 4275 return prop;
4276} 4276}
@@ -4318,7 +4318,7 @@ no value of TYPE (always string in the MS Windows case). */)
4318 target_window = FRAME_X_DISPLAY_INFO (f)->root_window; 4318 target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
4319 } 4319 }
4320 4320
4321 BLOCK_INPUT; 4321 block_input ();
4322 if (STRINGP (type)) 4322 if (STRINGP (type))
4323 { 4323 {
4324 if (strcmp ("AnyPropertyType", SSDATA (type)) == 0) 4324 if (strcmp ("AnyPropertyType", SSDATA (type)) == 0)
@@ -4384,7 +4384,7 @@ no value of TYPE (always string in the MS Windows case). */)
4384 if (tmp_data) XFree (tmp_data); 4384 if (tmp_data) XFree (tmp_data);
4385 } 4385 }
4386 4386
4387 UNBLOCK_INPUT; 4387 unblock_input ();
4388 UNGCPRO; 4388 UNGCPRO;
4389 return prop_value; 4389 return prop_value;
4390} 4390}
@@ -4415,7 +4415,7 @@ show_hourglass (struct atimer *timer)
4415 { 4415 {
4416 Lisp_Object rest, frame; 4416 Lisp_Object rest, frame;
4417 4417
4418 BLOCK_INPUT; 4418 block_input ();
4419 4419
4420 FOR_EACH_FRAME (rest, frame) 4420 FOR_EACH_FRAME (rest, frame)
4421 { 4421 {
@@ -4459,7 +4459,7 @@ show_hourglass (struct atimer *timer)
4459 } 4459 }
4460 4460
4461 hourglass_shown_p = 1; 4461 hourglass_shown_p = 1;
4462 UNBLOCK_INPUT; 4462 unblock_input ();
4463 } 4463 }
4464} 4464}
4465 4465
@@ -4474,7 +4474,7 @@ hide_hourglass (void)
4474 { 4474 {
4475 Lisp_Object rest, frame; 4475 Lisp_Object rest, frame;
4476 4476
4477 BLOCK_INPUT; 4477 block_input ();
4478 FOR_EACH_FRAME (rest, frame) 4478 FOR_EACH_FRAME (rest, frame)
4479 { 4479 {
4480 struct frame *f = XFRAME (frame); 4480 struct frame *f = XFRAME (frame);
@@ -4493,7 +4493,7 @@ hide_hourglass (void)
4493 } 4493 }
4494 4494
4495 hourglass_shown_p = 0; 4495 hourglass_shown_p = 0;
4496 UNBLOCK_INPUT; 4496 unblock_input ();
4497 } 4497 }
4498} 4498}
4499 4499
@@ -4743,7 +4743,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4743 unsigned long mask; 4743 unsigned long mask;
4744 Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip; 4744 Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip;
4745 4745
4746 BLOCK_INPUT; 4746 block_input ();
4747 mask = CWBackPixel | CWOverrideRedirect | CWEventMask; 4747 mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
4748 if (DoesSaveUnders (dpyinfo->screen)) 4748 if (DoesSaveUnders (dpyinfo->screen))
4749 mask |= CWSaveUnder; 4749 mask |= CWSaveUnder;
@@ -4770,7 +4770,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4770 FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type, 4770 FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type,
4771 XA_ATOM, 32, PropModeReplace, 4771 XA_ATOM, 32, PropModeReplace,
4772 (unsigned char *)&type, 1); 4772 (unsigned char *)&type, 1);
4773 UNBLOCK_INPUT; 4773 unblock_input ();
4774 } 4774 }
4775 4775
4776 x_make_gc (f); 4776 x_make_gc (f);
@@ -4884,10 +4884,10 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object
4884 show it. */ 4884 show it. */
4885 if (!INTEGERP (left) || !INTEGERP (top)) 4885 if (!INTEGERP (left) || !INTEGERP (top))
4886 { 4886 {
4887 BLOCK_INPUT; 4887 block_input ();
4888 XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, 4888 XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
4889 &root, &child, root_x, root_y, &win_x, &win_y, &pmask); 4889 &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
4890 UNBLOCK_INPUT; 4890 unblock_input ();
4891 } 4891 }
4892 4892
4893 if (INTEGERP (top)) 4893 if (INTEGERP (top))
@@ -4985,20 +4985,21 @@ Text larger than the specified size is clipped. */)
4985#ifdef USE_GTK 4985#ifdef USE_GTK
4986 if (x_gtk_use_system_tooltips) 4986 if (x_gtk_use_system_tooltips)
4987 { 4987 {
4988 int ok; 4988 bool ok;
4989 4989
4990 /* Hide a previous tip, if any. */ 4990 /* Hide a previous tip, if any. */
4991 Fx_hide_tip (); 4991 Fx_hide_tip ();
4992 4992
4993 BLOCK_INPUT; 4993 block_input ();
4994 if ((ok = xg_prepare_tooltip (f, string, &width, &height)) != 0) 4994 ok = xg_prepare_tooltip (f, string, &width, &height);
4995 if (ok)
4995 { 4996 {
4996 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); 4997 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
4997 xg_show_tooltip (f, root_x, root_y); 4998 xg_show_tooltip (f, root_x, root_y);
4998 /* This is used in Fx_hide_tip. */ 4999 /* This is used in Fx_hide_tip. */
4999 XSETFRAME (tip_frame, f); 5000 XSETFRAME (tip_frame, f);
5000 } 5001 }
5001 UNBLOCK_INPUT; 5002 unblock_input ();
5002 if (ok) goto start_timer; 5003 if (ok) goto start_timer;
5003 } 5004 }
5004#endif /* USE_GTK */ 5005#endif /* USE_GTK */
@@ -5026,12 +5027,12 @@ Text larger than the specified size is clipped. */)
5026 call1 (Qcancel_timer, timer); 5027 call1 (Qcancel_timer, timer);
5027 } 5028 }
5028 5029
5029 BLOCK_INPUT; 5030 block_input ();
5030 compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f), 5031 compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f),
5031 FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y); 5032 FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y);
5032 XMoveWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f), 5033 XMoveWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f),
5033 root_x, root_y); 5034 root_x, root_y);
5034 UNBLOCK_INPUT; 5035 unblock_input ();
5035 goto start_timer; 5036 goto start_timer;
5036 } 5037 }
5037 } 5038 }
@@ -5185,11 +5186,11 @@ Text larger than the specified size is clipped. */)
5185 show it. */ 5186 show it. */
5186 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); 5187 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
5187 5188
5188 BLOCK_INPUT; 5189 block_input ();
5189 XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5190 XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5190 root_x, root_y, width, height); 5191 root_x, root_y, width, height);
5191 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 5192 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5192 UNBLOCK_INPUT; 5193 unblock_input ();
5193 5194
5194 /* Draw into the window. */ 5195 /* Draw into the window. */
5195 w->must_be_updated_p = 1; 5196 w->must_be_updated_p = 1;
@@ -5261,9 +5262,9 @@ Value is t if tooltip was open, nil otherwise. */)
5261 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen) 5262 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
5262 && w != NULL) 5263 && w != NULL)
5263 { 5264 {
5264 BLOCK_INPUT; 5265 block_input ();
5265 xlwmenu_redisplay (w); 5266 xlwmenu_redisplay (w);
5266 UNBLOCK_INPUT; 5267 unblock_input ();
5267 } 5268 }
5268 } 5269 }
5269#endif /* USE_LUCID */ 5270#endif /* USE_LUCID */
@@ -5327,11 +5328,11 @@ clean_up_file_dialog (Lisp_Object arg)
5327 Widget dialog = (Widget) p->pointer; 5328 Widget dialog = (Widget) p->pointer;
5328 5329
5329 /* Clean up. */ 5330 /* Clean up. */
5330 BLOCK_INPUT; 5331 block_input ();
5331 XtUnmanageChild (dialog); 5332 XtUnmanageChild (dialog);
5332 XtDestroyWidget (dialog); 5333 XtDestroyWidget (dialog);
5333 x_menu_set_in_use (0); 5334 x_menu_set_in_use (0);
5334 UNBLOCK_INPUT; 5335 unblock_input ();
5335 5336
5336 return Qnil; 5337 return Qnil;
5337} 5338}
@@ -5343,7 +5344,7 @@ Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5343selection box, if specified. If MUSTMATCH is non-nil, the returned file 5344selection box, if specified. If MUSTMATCH is non-nil, the returned file
5344or directory must exist. 5345or directory must exist.
5345 5346
5346This function is only defined on MS Windows, and X Windows with the 5347This function is only defined on NS, MS Windows, and X Windows with the
5347Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. 5348Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5348Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 5349Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5349 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 5350 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
@@ -5372,7 +5373,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5372 /* Prevent redisplay. */ 5373 /* Prevent redisplay. */
5373 specbind (Qinhibit_redisplay, Qt); 5374 specbind (Qinhibit_redisplay, Qt);
5374 5375
5375 BLOCK_INPUT; 5376 block_input ();
5376 5377
5377 /* Create the dialog with PROMPT as title, using DIR as initial 5378 /* Create the dialog with PROMPT as title, using DIR as initial
5378 directory and using "*" as pattern. */ 5379 directory and using "*" as pattern. */
@@ -5486,7 +5487,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5486 else 5487 else
5487 file = Qnil; 5488 file = Qnil;
5488 5489
5489 UNBLOCK_INPUT; 5490 unblock_input ();
5490 UNGCPRO; 5491 UNGCPRO;
5491 5492
5492 /* Make "Cancel" equivalent to C-g. */ 5493 /* Make "Cancel" equivalent to C-g. */
@@ -5516,7 +5517,7 @@ Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5516selection box, if specified. If MUSTMATCH is non-nil, the returned file 5517selection box, if specified. If MUSTMATCH is non-nil, the returned file
5517or directory must exist. 5518or directory must exist.
5518 5519
5519This function is only defined on MS Windows, and X Windows with the 5520This function is only defined on NS, MS Windows, and X Windows with the
5520Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. 5521Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5521Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 5522Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5522 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 5523 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
@@ -5543,7 +5544,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5543 specbind (Qinhibit_redisplay, Qt); 5544 specbind (Qinhibit_redisplay, Qt);
5544 record_unwind_protect (clean_up_dialog, Qnil); 5545 record_unwind_protect (clean_up_dialog, Qnil);
5545 5546
5546 BLOCK_INPUT; 5547 block_input ();
5547 5548
5548 if (STRINGP (default_filename)) 5549 if (STRINGP (default_filename))
5549 cdef_file = SSDATA (default_filename); 5550 cdef_file = SSDATA (default_filename);
@@ -5560,7 +5561,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5560 xfree (fn); 5561 xfree (fn);
5561 } 5562 }
5562 5563
5563 UNBLOCK_INPUT; 5564 unblock_input ();
5564 UNGCPRO; 5565 UNGCPRO;
5565 5566
5566 /* Make "Cancel" equivalent to C-g. */ 5567 /* Make "Cancel" equivalent to C-g. */
@@ -5600,7 +5601,7 @@ nil, it defaults to the selected frame. */)
5600 specbind (Qinhibit_redisplay, Qt); 5601 specbind (Qinhibit_redisplay, Qt);
5601 record_unwind_protect (clean_up_dialog, Qnil); 5602 record_unwind_protect (clean_up_dialog, Qnil);
5602 5603
5603 BLOCK_INPUT; 5604 block_input ();
5604 5605
5605 GCPRO2 (font_param, font); 5606 GCPRO2 (font_param, font);
5606 5607
@@ -5618,7 +5619,7 @@ nil, it defaults to the selected frame. */)
5618 font = xg_get_font (f, default_name); 5619 font = xg_get_font (f, default_name);
5619 xfree (default_name); 5620 xfree (default_name);
5620 5621
5621 UNBLOCK_INPUT; 5622 unblock_input ();
5622 5623
5623 if (NILP (font)) 5624 if (NILP (font))
5624 Fsignal (Qquit, Qnil); 5625 Fsignal (Qquit, Qnil);
@@ -5655,14 +5656,14 @@ present and mapped to the usual X keysyms. */)
5655 Lisp_Object have_keys; 5656 Lisp_Object have_keys;
5656 int major, minor, op, event, error_code; 5657 int major, minor, op, event, error_code;
5657 5658
5658 BLOCK_INPUT; 5659 block_input ();
5659 5660
5660 /* Check library version in case we're dynamically linked. */ 5661 /* Check library version in case we're dynamically linked. */
5661 major = XkbMajorVersion; 5662 major = XkbMajorVersion;
5662 minor = XkbMinorVersion; 5663 minor = XkbMinorVersion;
5663 if (!XkbLibraryVersion (&major, &minor)) 5664 if (!XkbLibraryVersion (&major, &minor))
5664 { 5665 {
5665 UNBLOCK_INPUT; 5666 unblock_input ();
5666 return Qlambda; 5667 return Qlambda;
5667 } 5668 }
5668 5669
@@ -5671,7 +5672,7 @@ present and mapped to the usual X keysyms. */)
5671 minor = XkbMinorVersion; 5672 minor = XkbMinorVersion;
5672 if (!XkbQueryExtension (dpy, &op, &event, &error_code, &major, &minor)) 5673 if (!XkbQueryExtension (dpy, &op, &event, &error_code, &major, &minor))
5673 { 5674 {
5674 UNBLOCK_INPUT; 5675 unblock_input ();
5675 return Qlambda; 5676 return Qlambda;
5676 } 5677 }
5677 5678
@@ -5724,7 +5725,7 @@ present and mapped to the usual X keysyms. */)
5724 && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode) 5725 && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode)
5725 have_keys = Qt; 5726 have_keys = Qt;
5726 } 5727 }
5727 UNBLOCK_INPUT; 5728 unblock_input ();
5728 return have_keys; 5729 return have_keys;
5729#else /* not HAVE_XKBGETKEYBOARD */ 5730#else /* not HAVE_XKBGETKEYBOARD */
5730 return Qlambda; 5731 return Qlambda;
diff --git a/src/xfont.c b/src/xfont.c
index 1f2fd13f1b7..2d493088b0b 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -362,7 +362,7 @@ xfont_list_pattern (Display *display, const char *pattern,
362 } 362 }
363 } 363 }
364 364
365 BLOCK_INPUT; 365 block_input ();
366 x_catch_errors (display); 366 x_catch_errors (display);
367 367
368 for (limit = 512; ; limit *= 2) 368 for (limit = 512; ; limit *= 2)
@@ -479,7 +479,7 @@ xfont_list_pattern (Display *display, const char *pattern,
479 } 479 }
480 480
481 x_uncatch_errors (); 481 x_uncatch_errors ();
482 UNBLOCK_INPUT; 482 unblock_input ();
483 483
484 FONT_ADD_LOG ("xfont-list", build_string (pattern), list); 484 FONT_ADD_LOG ("xfont-list", build_string (pattern), list);
485 return list; 485 return list;
@@ -588,7 +588,7 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
588 if (xfont_encode_coding_xlfd (name) < 0) 588 if (xfont_encode_coding_xlfd (name) < 0)
589 return Qnil; 589 return Qnil;
590 590
591 BLOCK_INPUT; 591 block_input ();
592 entity = Qnil; 592 entity = Qnil;
593 xfont = XLoadQueryFont (display, name); 593 xfont = XLoadQueryFont (display, name);
594 if (xfont) 594 if (xfont)
@@ -615,7 +615,7 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
615 } 615 }
616 XFreeFont (display, xfont); 616 XFreeFont (display, xfont);
617 } 617 }
618 UNBLOCK_INPUT; 618 unblock_input ();
619 619
620 FONT_ADD_LOG ("xfont-match", spec, entity); 620 FONT_ADD_LOG ("xfont-match", spec, entity);
621 return entity; 621 return entity;
@@ -632,7 +632,7 @@ xfont_list_family (Lisp_Object frame)
632 char *last_family IF_LINT (= 0); 632 char *last_family IF_LINT (= 0);
633 int last_len; 633 int last_len;
634 634
635 BLOCK_INPUT; 635 block_input ();
636 x_catch_errors (dpyinfo->display); 636 x_catch_errors (dpyinfo->display);
637 names = XListFonts (dpyinfo->display, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", 637 names = XListFonts (dpyinfo->display, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
638 0x8000, &num_fonts); 638 0x8000, &num_fonts);
@@ -673,7 +673,7 @@ xfont_list_family (Lisp_Object frame)
673 673
674 XFreeFontNames (names); 674 XFreeFontNames (names);
675 x_uncatch_errors (); 675 x_uncatch_errors ();
676 UNBLOCK_INPUT; 676 unblock_input ();
677 677
678 return list; 678 return list;
679} 679}
@@ -717,7 +717,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
717 return Qnil; 717 return Qnil;
718 } 718 }
719 719
720 BLOCK_INPUT; 720 block_input ();
721 x_catch_errors (display); 721 x_catch_errors (display);
722 xfont = XLoadQueryFont (display, name); 722 xfont = XLoadQueryFont (display, name);
723 if (x_had_errors_p (display)) 723 if (x_had_errors_p (display))
@@ -784,7 +784,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
784 XFree (p0); 784 XFree (p0);
785 } 785 }
786 x_uncatch_errors (); 786 x_uncatch_errors ();
787 UNBLOCK_INPUT; 787 unblock_input ();
788 788
789 if (! xfont) 789 if (! xfont)
790 { 790 {
@@ -866,7 +866,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
866 } 866 }
867 } 867 }
868 868
869 BLOCK_INPUT; 869 block_input ();
870 font->underline_thickness 870 font->underline_thickness
871 = (XGetFontProperty (xfont, XA_UNDERLINE_THICKNESS, &value) 871 = (XGetFontProperty (xfont, XA_UNDERLINE_THICKNESS, &value)
872 ? (long) value : 0); 872 ? (long) value : 0);
@@ -882,7 +882,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
882 font->default_ascent 882 font->default_ascent
883 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value) 883 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value)
884 ? (long) value : 0); 884 ? (long) value : 0);
885 UNBLOCK_INPUT; 885 unblock_input ();
886 886
887 if (NILP (fullname)) 887 if (NILP (fullname))
888 fullname = AREF (font_object, FONT_NAME_INDEX); 888 fullname = AREF (font_object, FONT_NAME_INDEX);
@@ -897,18 +897,18 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
897static void 897static void
898xfont_close (FRAME_PTR f, struct font *font) 898xfont_close (FRAME_PTR f, struct font *font)
899{ 899{
900 BLOCK_INPUT; 900 block_input ();
901 XFreeFont (FRAME_X_DISPLAY (f), ((struct xfont_info *) font)->xfont); 901 XFreeFont (FRAME_X_DISPLAY (f), ((struct xfont_info *) font)->xfont);
902 UNBLOCK_INPUT; 902 unblock_input ();
903} 903}
904 904
905static int 905static int
906xfont_prepare_face (FRAME_PTR f, struct face *face) 906xfont_prepare_face (FRAME_PTR f, struct face *face)
907{ 907{
908 BLOCK_INPUT; 908 block_input ();
909 XSetFont (FRAME_X_DISPLAY (f), face->gc, 909 XSetFont (FRAME_X_DISPLAY (f), face->gc,
910 ((struct xfont_info *) face->font)->xfont->fid); 910 ((struct xfont_info *) face->font)->xfont->fid);
911 UNBLOCK_INPUT; 911 unblock_input ();
912 912
913 return 0; 913 return 0;
914} 914}
@@ -1028,9 +1028,9 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1028 1028
1029 if (s->gc != s->face->gc) 1029 if (s->gc != s->face->gc)
1030 { 1030 {
1031 BLOCK_INPUT; 1031 block_input ();
1032 XSetFont (s->display, gc, xfont->fid); 1032 XSetFont (s->display, gc, xfont->fid);
1033 UNBLOCK_INPUT; 1033 unblock_input ();
1034 } 1034 }
1035 1035
1036 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0) 1036 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
@@ -1039,7 +1039,7 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1039 char *str = SAFE_ALLOCA (len); 1039 char *str = SAFE_ALLOCA (len);
1040 for (i = 0; i < len ; i++) 1040 for (i = 0; i < len ; i++)
1041 str[i] = XCHAR2B_BYTE2 (s->char2b + from + i); 1041 str[i] = XCHAR2B_BYTE2 (s->char2b + from + i);
1042 BLOCK_INPUT; 1042 block_input ();
1043 if (with_background) 1043 if (with_background)
1044 { 1044 {
1045 if (s->padding_p) 1045 if (s->padding_p)
@@ -1060,12 +1060,12 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1060 XDrawString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), 1060 XDrawString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
1061 gc, x, y, str, len); 1061 gc, x, y, str, len);
1062 } 1062 }
1063 UNBLOCK_INPUT; 1063 unblock_input ();
1064 SAFE_FREE (); 1064 SAFE_FREE ();
1065 return s->nchars; 1065 return s->nchars;
1066 } 1066 }
1067 1067
1068 BLOCK_INPUT; 1068 block_input ();
1069 if (with_background) 1069 if (with_background)
1070 { 1070 {
1071 if (s->padding_p) 1071 if (s->padding_p)
@@ -1086,7 +1086,7 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1086 XDrawString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), 1086 XDrawString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
1087 gc, x, y, s->char2b + from, len); 1087 gc, x, y, s->char2b + from, len);
1088 } 1088 }
1089 UNBLOCK_INPUT; 1089 unblock_input ();
1090 1090
1091 return len; 1091 return len;
1092} 1092}
diff --git a/src/xftfont.c b/src/xftfont.c
index 9f52eb8b233..372ed87705f 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -93,7 +93,7 @@ xftfont_get_colors (FRAME_PTR f, struct face *face, GC gc, struct xftface_info *
93 XGCValues xgcv; 93 XGCValues xgcv;
94 bool fg_done = 0, bg_done = 0; 94 bool fg_done = 0, bg_done = 0;
95 95
96 BLOCK_INPUT; 96 block_input ();
97 XGetGCValues (FRAME_X_DISPLAY (f), gc, 97 XGetGCValues (FRAME_X_DISPLAY (f), gc,
98 GCForeground | GCBackground, &xgcv); 98 GCForeground | GCBackground, &xgcv);
99 if (xftface_info) 99 if (xftface_info)
@@ -131,7 +131,7 @@ xftfont_get_colors (FRAME_PTR f, struct face *face, GC gc, struct xftface_info *
131 bg->color.blue = colors[1].blue; 131 bg->color.blue = colors[1].blue;
132 } 132 }
133 } 133 }
134 UNBLOCK_INPUT; 134 unblock_input ();
135 } 135 }
136} 136}
137 137
@@ -324,7 +324,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
324 FcPatternAddInteger (pat, FC_INDEX, XINT (idx)); 324 FcPatternAddInteger (pat, FC_INDEX, XINT (idx));
325 325
326 326
327 BLOCK_INPUT; 327 block_input ();
328 /* Make sure that the Xrender extension is added before the Xft one. 328 /* Make sure that the Xrender extension is added before the Xft one.
329 Otherwise, the close-display hook set by Xft is called after the 329 Otherwise, the close-display hook set by Xft is called after the
330 one for Xrender, and the former tries to re-add the latter. This 330 one for Xrender, and the former tries to re-add the latter. This
@@ -345,12 +345,12 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
345 xftfont = XftFontOpenPattern (display, match); 345 xftfont = XftFontOpenPattern (display, match);
346 if (!xftfont) 346 if (!xftfont)
347 { 347 {
348 UNBLOCK_INPUT; 348 unblock_input ();
349 XftPatternDestroy (match); 349 XftPatternDestroy (match);
350 return Qnil; 350 return Qnil;
351 } 351 }
352 ft_face = XftLockFace (xftfont); 352 ft_face = XftLockFace (xftfont);
353 UNBLOCK_INPUT; 353 unblock_input ();
354 354
355 /* We should not destroy PAT here because it is kept in XFTFONT and 355 /* We should not destroy PAT here because it is kept in XFTFONT and
356 destroyed automatically when XFTFONT is closed. */ 356 destroyed automatically when XFTFONT is closed. */
@@ -399,7 +399,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
399 for (ch = 0; ch < 95; ch++) 399 for (ch = 0; ch < 95; ch++)
400 ascii_printable[ch] = ' ' + ch; 400 ascii_printable[ch] = ' ' + ch;
401 } 401 }
402 BLOCK_INPUT; 402 block_input ();
403 403
404 /* Unfortunately Xft doesn't provide a way to get minimum char 404 /* Unfortunately Xft doesn't provide a way to get minimum char
405 width. So, we set min_width to space_width. */ 405 width. So, we set min_width to space_width. */
@@ -425,7 +425,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
425 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); 425 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents);
426 font->average_width = (font->space_width + extents.xOff) / 95; 426 font->average_width = (font->space_width + extents.xOff) / 95;
427 } 427 }
428 UNBLOCK_INPUT; 428 unblock_input ();
429 429
430 font->ascent = xftfont->ascent; 430 font->ascent = xftfont->ascent;
431 font->descent = xftfont->descent; 431 font->descent = xftfont->descent;
@@ -494,10 +494,10 @@ xftfont_close (FRAME_PTR f, struct font *font)
494 if (xftfont_info->otf) 494 if (xftfont_info->otf)
495 OTF_close (xftfont_info->otf); 495 OTF_close (xftfont_info->otf);
496#endif 496#endif
497 BLOCK_INPUT; 497 block_input ();
498 XftUnlockFace (xftfont_info->xftfont); 498 XftUnlockFace (xftfont_info->xftfont);
499 XftFontClose (xftfont_info->display, xftfont_info->xftfont); 499 XftFontClose (xftfont_info->display, xftfont_info->xftfont);
500 UNBLOCK_INPUT; 500 unblock_input ();
501} 501}
502 502
503static int 503static int
@@ -581,10 +581,10 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct
581 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; 581 struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
582 XGlyphInfo extents; 582 XGlyphInfo extents;
583 583
584 BLOCK_INPUT; 584 block_input ();
585 XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs, 585 XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs,
586 &extents); 586 &extents);
587 UNBLOCK_INPUT; 587 unblock_input ();
588 if (metrics) 588 if (metrics)
589 { 589 {
590 metrics->lbearing = - extents.x; 590 metrics->lbearing = - extents.x;
@@ -603,12 +603,12 @@ xftfont_get_xft_draw (FRAME_PTR f)
603 603
604 if (! xft_draw) 604 if (! xft_draw)
605 { 605 {
606 BLOCK_INPUT; 606 block_input ();
607 xft_draw= XftDrawCreate (FRAME_X_DISPLAY (f), 607 xft_draw= XftDrawCreate (FRAME_X_DISPLAY (f),
608 FRAME_X_WINDOW (f), 608 FRAME_X_WINDOW (f),
609 FRAME_X_VISUAL (f), 609 FRAME_X_VISUAL (f),
610 FRAME_X_COLORMAP (f)); 610 FRAME_X_COLORMAP (f));
611 UNBLOCK_INPUT; 611 unblock_input ();
612 eassert (xft_draw != NULL); 612 eassert (xft_draw != NULL);
613 font_put_frame_data (f, &xftfont_driver, xft_draw); 613 font_put_frame_data (f, &xftfont_driver, xft_draw);
614 } 614 }
@@ -633,7 +633,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y,
633 xftface_info = (struct xftface_info *) face->extra; 633 xftface_info = (struct xftface_info *) face->extra;
634 xftfont_get_colors (f, face, s->gc, xftface_info, 634 xftfont_get_colors (f, face, s->gc, xftface_info,
635 &fg, with_background ? &bg : NULL); 635 &fg, with_background ? &bg : NULL);
636 BLOCK_INPUT; 636 block_input ();
637 if (s->num_clips > 0) 637 if (s->num_clips > 0)
638 XftDrawSetClipRectangles (xft_draw, 0, 0, s->clip, s->num_clips); 638 XftDrawSetClipRectangles (xft_draw, 0, 0, s->clip, s->num_clips);
639 else 639 else
@@ -654,7 +654,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y,
654 else 654 else
655 XftDrawGlyphs (xft_draw, &fg, xftfont_info->xftfont, 655 XftDrawGlyphs (xft_draw, &fg, xftfont_info->xftfont,
656 x, y, code, len); 656 x, y, code, len);
657 UNBLOCK_INPUT; 657 unblock_input ();
658 658
659 return len; 659 return len;
660} 660}
@@ -690,9 +690,9 @@ xftfont_end_for_frame (FRAME_PTR f)
690 690
691 if (xft_draw) 691 if (xft_draw)
692 { 692 {
693 BLOCK_INPUT; 693 block_input ();
694 XftDrawDestroy (xft_draw); 694 XftDrawDestroy (xft_draw);
695 UNBLOCK_INPUT; 695 unblock_input ();
696 font_put_frame_data (f, &xftfont_driver, NULL); 696 font_put_frame_data (f, &xftfont_driver, NULL);
697 } 697 }
698 return 0; 698 return 0;
diff --git a/src/xmenu.c b/src/xmenu.c
index d03a4bc974b..96a1ae87fdc 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -165,7 +165,7 @@ mouse_position_for_popup (FRAME_PTR f, int *x, int *y)
165 if (! FRAME_X_P (f)) 165 if (! FRAME_X_P (f))
166 emacs_abort (); 166 emacs_abort ();
167 167
168 BLOCK_INPUT; 168 block_input ();
169 169
170 XQueryPointer (FRAME_X_DISPLAY (f), 170 XQueryPointer (FRAME_X_DISPLAY (f),
171 DefaultRootWindow (FRAME_X_DISPLAY (f)), 171 DefaultRootWindow (FRAME_X_DISPLAY (f)),
@@ -186,7 +186,7 @@ mouse_position_for_popup (FRAME_PTR f, int *x, int *y)
186 we don't care. */ 186 we don't care. */
187 (unsigned int *) &dummy); 187 (unsigned int *) &dummy);
188 188
189 UNBLOCK_INPUT; 189 unblock_input ();
190 190
191 /* xmenu_show expects window coordinates, not root window 191 /* xmenu_show expects window coordinates, not root window
192 coordinates. Translate. */ 192 coordinates. Translate. */
@@ -328,9 +328,9 @@ for instance using the window manager, then this produces a quit and
328 list_of_panes (Fcons (contents, Qnil)); 328 list_of_panes (Fcons (contents, Qnil));
329 329
330 /* Display them in a dialog box. */ 330 /* Display them in a dialog box. */
331 BLOCK_INPUT; 331 block_input ();
332 selection = xdialog_show (f, 0, title, header, &error_name); 332 selection = xdialog_show (f, 0, title, header, &error_name);
333 UNBLOCK_INPUT; 333 unblock_input ();
334 334
335 unbind_to (specpdl_count, Qnil); 335 unbind_to (specpdl_count, Qnil);
336 discard_menu_items (); 336 discard_menu_items ();
@@ -490,7 +490,7 @@ If FRAME is nil or not given, use the selected frame. */)
490 XEvent ev; 490 XEvent ev;
491 FRAME_PTR f = check_x_frame (frame); 491 FRAME_PTR f = check_x_frame (frame);
492 Widget menubar; 492 Widget menubar;
493 BLOCK_INPUT; 493 block_input ();
494 494
495 if (FRAME_EXTERNAL_MENU_BAR (f)) 495 if (FRAME_EXTERNAL_MENU_BAR (f))
496 set_frame_menubar (f, 0, 1); 496 set_frame_menubar (f, 0, 1);
@@ -548,7 +548,7 @@ If FRAME is nil or not given, use the selected frame. */)
548 } 548 }
549 } 549 }
550 550
551 UNBLOCK_INPUT; 551 unblock_input ();
552 552
553 return Qnil; 553 return Qnil;
554} 554}
@@ -569,9 +569,9 @@ If FRAME is nil or not given, use the selected frame. */)
569 FRAME_PTR f; 569 FRAME_PTR f;
570 570
571 /* gcc 2.95 doesn't accept the FRAME_PTR declaration after 571 /* gcc 2.95 doesn't accept the FRAME_PTR declaration after
572 BLOCK_INPUT. */ 572 block_input (). */
573 573
574 BLOCK_INPUT; 574 block_input ();
575 f = check_x_frame (frame); 575 f = check_x_frame (frame);
576 576
577 if (FRAME_EXTERNAL_MENU_BAR (f)) 577 if (FRAME_EXTERNAL_MENU_BAR (f))
@@ -590,7 +590,7 @@ If FRAME is nil or not given, use the selected frame. */)
590 g_list_free (children); 590 g_list_free (children);
591 } 591 }
592 } 592 }
593 UNBLOCK_INPUT; 593 unblock_input ();
594 594
595 return Qnil; 595 return Qnil;
596} 596}
@@ -642,7 +642,7 @@ x_activate_menubar (FRAME_PTR f)
642#endif 642#endif
643 643
644 set_frame_menubar (f, 0, 1); 644 set_frame_menubar (f, 0, 1);
645 BLOCK_INPUT; 645 block_input ();
646 popup_activated_flag = 1; 646 popup_activated_flag = 1;
647#ifdef USE_GTK 647#ifdef USE_GTK
648 XPutBackEvent (f->output_data.x->display_info->display, 648 XPutBackEvent (f->output_data.x->display_info->display,
@@ -650,7 +650,7 @@ x_activate_menubar (FRAME_PTR f)
650#else 650#else
651 XtDispatchEvent (f->output_data.x->saved_menu_event); 651 XtDispatchEvent (f->output_data.x->saved_menu_event);
652#endif 652#endif
653 UNBLOCK_INPUT; 653 unblock_input ();
654 654
655 /* Ignore this if we get it a second time. */ 655 /* Ignore this if we get it a second time. */
656 f->output_data.x->saved_menu_event->type = 0; 656 f->output_data.x->saved_menu_event->type = 0;
@@ -803,10 +803,10 @@ menubar_selection_callback (GtkWidget *widget, gpointer client_data)
803 sit-for will exit at once if the focus event follows the menu selection 803 sit-for will exit at once if the focus event follows the menu selection
804 event. */ 804 event. */
805 805
806 BLOCK_INPUT; 806 block_input ();
807 while (gtk_events_pending ()) 807 while (gtk_events_pending ())
808 gtk_main_iteration (); 808 gtk_main_iteration ();
809 UNBLOCK_INPUT; 809 unblock_input ();
810 810
811 find_and_call_menu_selection (cb_data->cl_data->f, 811 find_and_call_menu_selection (cb_data->cl_data->f,
812 cb_data->cl_data->menu_bar_items_used, 812 cb_data->cl_data->menu_bar_items_used,
@@ -834,13 +834,13 @@ menubar_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
834#endif /* not USE_GTK */ 834#endif /* not USE_GTK */
835 835
836/* Recompute all the widgets of frame F, when the menu bar has been 836/* Recompute all the widgets of frame F, when the menu bar has been
837 changed. Value is non-zero if widgets were updated. */ 837 changed. */
838 838
839static int 839static void
840update_frame_menubar (FRAME_PTR f) 840update_frame_menubar (FRAME_PTR f)
841{ 841{
842#ifdef USE_GTK 842#ifdef USE_GTK
843 return xg_update_frame_menubar (f); 843 xg_update_frame_menubar (f);
844#else 844#else
845 struct x_output *x; 845 struct x_output *x;
846 int columns, rows; 846 int columns, rows;
@@ -851,9 +851,9 @@ update_frame_menubar (FRAME_PTR f)
851 x = f->output_data.x; 851 x = f->output_data.x;
852 852
853 if (!x->menubar_widget || XtIsManaged (x->menubar_widget)) 853 if (!x->menubar_widget || XtIsManaged (x->menubar_widget))
854 return 0; 854 return;
855 855
856 BLOCK_INPUT; 856 block_input ();
857 /* Save the size of the frame because the pane widget doesn't accept 857 /* Save the size of the frame because the pane widget doesn't accept
858 to resize itself. So force it. */ 858 to resize itself. So force it. */
859 columns = FRAME_COLS (f); 859 columns = FRAME_COLS (f);
@@ -880,9 +880,8 @@ update_frame_menubar (FRAME_PTR f)
880 880
881 /* Force the pane widget to resize itself with the right values. */ 881 /* Force the pane widget to resize itself with the right values. */
882 EmacsFrameSetCharSize (x->edit_widget, columns, rows); 882 EmacsFrameSetCharSize (x->edit_widget, columns, rows);
883 UNBLOCK_INPUT; 883 unblock_input ();
884#endif 884#endif
885 return 1;
886} 885}
887 886
888#ifdef USE_LUCID 887#ifdef USE_LUCID
@@ -921,7 +920,7 @@ apply_systemfont_to_menu (struct frame *f, Widget w)
921 it is set the first time this is called, from initialize_frame_menubar. */ 920 it is set the first time this is called, from initialize_frame_menubar. */
922 921
923void 922void
924set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) 923set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
925{ 924{
926 xt_or_gtk_widget menubar_widget; 925 xt_or_gtk_widget menubar_widget;
927#ifdef USE_X_TOOLKIT 926#ifdef USE_X_TOOLKIT
@@ -1164,7 +1163,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
1164 1163
1165 /* Create or update the menu bar widget. */ 1164 /* Create or update the menu bar widget. */
1166 1165
1167 BLOCK_INPUT; 1166 block_input ();
1168 1167
1169#ifdef USE_GTK 1168#ifdef USE_GTK
1170 xg_crazy_callback_abort = 1; 1169 xg_crazy_callback_abort = 1;
@@ -1264,7 +1263,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
1264 xg_crazy_callback_abort = 0; 1263 xg_crazy_callback_abort = 0;
1265#endif 1264#endif
1266 1265
1267 UNBLOCK_INPUT; 1266 unblock_input ();
1268} 1267}
1269 1268
1270/* Called from Fx_create_frame to create the initial menubar of a frame 1269/* Called from Fx_create_frame to create the initial menubar of a frame
@@ -1313,7 +1312,7 @@ free_frame_menubar (FRAME_PTR f)
1313 Position x0, y0, x1, y1; 1312 Position x0, y0, x1, y1;
1314#endif 1313#endif
1315 1314
1316 BLOCK_INPUT; 1315 block_input ();
1317 1316
1318#ifdef USE_MOTIF 1317#ifdef USE_MOTIF
1319 if (f->output_data.x->widget) 1318 if (f->output_data.x->widget)
@@ -1332,7 +1331,7 @@ free_frame_menubar (FRAME_PTR f)
1332#endif 1331#endif
1333 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); 1332 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
1334 } 1333 }
1335 UNBLOCK_INPUT; 1334 unblock_input ();
1336 } 1335 }
1337} 1336}
1338#endif /* not USE_GTK */ 1337#endif /* not USE_GTK */
@@ -1417,9 +1416,9 @@ pop_down_menu (Lisp_Object arg)
1417 struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 1416 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
1418 1417
1419 popup_activated_flag = 0; 1418 popup_activated_flag = 0;
1420 BLOCK_INPUT; 1419 block_input ();
1421 gtk_widget_destroy (GTK_WIDGET (p->pointer)); 1420 gtk_widget_destroy (GTK_WIDGET (p->pointer));
1422 UNBLOCK_INPUT; 1421 unblock_input ();
1423 return Qnil; 1422 return Qnil;
1424} 1423}
1425 1424
@@ -1527,9 +1526,9 @@ pop_down_menu (Lisp_Object arg)
1527 LWLIB_ID id = (XINT (XCAR (arg)) << 4 * sizeof (LWLIB_ID) 1526 LWLIB_ID id = (XINT (XCAR (arg)) << 4 * sizeof (LWLIB_ID)
1528 | XINT (XCDR (arg))); 1527 | XINT (XCDR (arg)));
1529 1528
1530 BLOCK_INPUT; 1529 block_input ();
1531 lw_destroy_all_widgets (id); 1530 lw_destroy_all_widgets (id);
1532 UNBLOCK_INPUT; 1531 unblock_input ();
1533 popup_activated_flag = 0; 1532 popup_activated_flag = 0;
1534 1533
1535 return Qnil; 1534 return Qnil;
@@ -1955,9 +1954,9 @@ dialog_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
1955 if ((intptr_t) client_data != -1) 1954 if ((intptr_t) client_data != -1)
1956 menu_item_selection = (Lisp_Object *) client_data; 1955 menu_item_selection = (Lisp_Object *) client_data;
1957 1956
1958 BLOCK_INPUT; 1957 block_input ();
1959 lw_destroy_all_widgets (id); 1958 lw_destroy_all_widgets (id);
1960 UNBLOCK_INPUT; 1959 unblock_input ();
1961 popup_activated_flag = 0; 1960 popup_activated_flag = 0;
1962} 1961}
1963 1962
@@ -2251,7 +2250,7 @@ pop_down_menu (Lisp_Object arg)
2251 FRAME_PTR f = p1->pointer; 2250 FRAME_PTR f = p1->pointer;
2252 XMenu *menu = p2->pointer; 2251 XMenu *menu = p2->pointer;
2253 2252
2254 BLOCK_INPUT; 2253 block_input ();
2255#ifndef MSDOS 2254#ifndef MSDOS
2256 XUngrabPointer (FRAME_X_DISPLAY (f), CurrentTime); 2255 XUngrabPointer (FRAME_X_DISPLAY (f), CurrentTime);
2257 XUngrabKeyboard (FRAME_X_DISPLAY (f), CurrentTime); 2256 XUngrabKeyboard (FRAME_X_DISPLAY (f), CurrentTime);
@@ -2271,7 +2270,7 @@ pop_down_menu (Lisp_Object arg)
2271 2270
2272#endif /* HAVE_X_WINDOWS */ 2271#endif /* HAVE_X_WINDOWS */
2273 2272
2274 UNBLOCK_INPUT; 2273 unblock_input ();
2275 2274
2276 return Qnil; 2275 return Qnil;
2277} 2276}
diff --git a/src/xml.c b/src/xml.c
index b668525cf26..a0c4fe17fc4 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -73,7 +73,7 @@ libxml2_loaded_p (void)
73#define fn_xmlCleanupParser xmlCleanupParser 73#define fn_xmlCleanupParser xmlCleanupParser
74#define fn_xmlCheckVersion xmlCheckVersion 74#define fn_xmlCheckVersion xmlCheckVersion
75 75
76static inline int 76static int
77libxml2_loaded_p (void) 77libxml2_loaded_p (void)
78{ 78{
79 return 1; 79 return 1;
@@ -82,7 +82,7 @@ libxml2_loaded_p (void)
82#endif /* !WINDOWSNT */ 82#endif /* !WINDOWSNT */
83 83
84static int 84static int
85init_libxml2_functions (Lisp_Object libraries) 85init_libxml2_functions (void)
86{ 86{
87#ifdef WINDOWSNT 87#ifdef WINDOWSNT
88 if (libxml2_loaded_p ()) 88 if (libxml2_loaded_p ())
@@ -91,7 +91,7 @@ init_libxml2_functions (Lisp_Object libraries)
91 { 91 {
92 HMODULE library; 92 HMODULE library;
93 93
94 if (!(library = w32_delayed_load (libraries, Qlibxml2_dll))) 94 if (!(library = w32_delayed_load (Qlibxml2_dll)))
95 { 95 {
96 message ("%s", "libxml2 library not found"); 96 message ("%s", "libxml2 library not found");
97 return 0; 97 return 0;
@@ -257,7 +257,7 @@ DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,
257If BASE-URL is non-nil, it is used to expand relative URLs. */) 257If BASE-URL is non-nil, it is used to expand relative URLs. */)
258 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 258 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
259{ 259{
260 if (init_libxml2_functions (Vdynamic_library_alist)) 260 if (init_libxml2_functions ())
261 return parse_region (start, end, base_url, 1); 261 return parse_region (start, end, base_url, 1);
262 return Qnil; 262 return Qnil;
263} 263}
@@ -269,7 +269,7 @@ DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region,
269If BASE-URL is non-nil, it is used to expand relative URLs. */) 269If BASE-URL is non-nil, it is used to expand relative URLs. */)
270 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 270 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
271{ 271{
272 if (init_libxml2_functions (Vdynamic_library_alist)) 272 if (init_libxml2_functions ())
273 return parse_region (start, end, base_url, 0); 273 return parse_region (start, end, base_url, 0);
274 return Qnil; 274 return Qnil;
275} 275}
diff --git a/src/xselect.c b/src/xselect.c
index ab199e0b9b9..de9386bd7d9 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -247,9 +247,9 @@ symbol_to_x_atom (struct x_display_info *dpyinfo, Lisp_Object sym)
247 if (!SYMBOLP (sym)) emacs_abort (); 247 if (!SYMBOLP (sym)) emacs_abort ();
248 248
249 TRACE1 (" XInternAtom %s", SSDATA (SYMBOL_NAME (sym))); 249 TRACE1 (" XInternAtom %s", SSDATA (SYMBOL_NAME (sym)));
250 BLOCK_INPUT; 250 block_input ();
251 val = XInternAtom (dpyinfo->display, SSDATA (SYMBOL_NAME (sym)), False); 251 val = XInternAtom (dpyinfo->display, SSDATA (SYMBOL_NAME (sym)), False);
252 UNBLOCK_INPUT; 252 unblock_input ();
253 return val; 253 return val;
254} 254}
255 255
@@ -307,16 +307,16 @@ x_atom_to_symbol (Display *dpy, Atom atom)
307 if (atom == dpyinfo->Xatom_NULL) 307 if (atom == dpyinfo->Xatom_NULL)
308 return QNULL; 308 return QNULL;
309 309
310 BLOCK_INPUT; 310 block_input ();
311 str = XGetAtomName (dpy, atom); 311 str = XGetAtomName (dpy, atom);
312 UNBLOCK_INPUT; 312 unblock_input ();
313 TRACE1 ("XGetAtomName --> %s", str); 313 TRACE1 ("XGetAtomName --> %s", str);
314 if (! str) return Qnil; 314 if (! str) return Qnil;
315 val = intern (str); 315 val = intern (str);
316 BLOCK_INPUT; 316 block_input ();
317 /* This was allocated by Xlib, so use XFree. */ 317 /* This was allocated by Xlib, so use XFree. */
318 XFree (str); 318 XFree (str);
319 UNBLOCK_INPUT; 319 unblock_input ();
320 return val; 320 return val;
321} 321}
322 322
@@ -336,12 +336,12 @@ x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
336 Time timestamp = last_event_timestamp; 336 Time timestamp = last_event_timestamp;
337 Atom selection_atom = symbol_to_x_atom (dpyinfo, selection_name); 337 Atom selection_atom = symbol_to_x_atom (dpyinfo, selection_name);
338 338
339 BLOCK_INPUT; 339 block_input ();
340 x_catch_errors (display); 340 x_catch_errors (display);
341 XSetSelectionOwner (display, selection_atom, selecting_window, timestamp); 341 XSetSelectionOwner (display, selection_atom, selecting_window, timestamp);
342 x_check_errors (display, "Can't set selection: %s"); 342 x_check_errors (display, "Can't set selection: %s");
343 x_uncatch_errors (); 343 x_uncatch_errors ();
344 UNBLOCK_INPUT; 344 unblock_input ();
345 345
346 /* Now update the local cache */ 346 /* Now update the local cache */
347 { 347 {
@@ -469,12 +469,12 @@ x_decline_selection_request (struct input_event *event)
469 469
470 /* The reason for the error may be that the receiver has 470 /* The reason for the error may be that the receiver has
471 died in the meantime. Handle that case. */ 471 died in the meantime. Handle that case. */
472 BLOCK_INPUT; 472 block_input ();
473 x_catch_errors (reply->display); 473 x_catch_errors (reply->display);
474 XSendEvent (reply->display, reply->requestor, False, 0L, &reply_base); 474 XSendEvent (reply->display, reply->requestor, False, 0L, &reply_base);
475 XFlush (reply->display); 475 XFlush (reply->display);
476 x_uncatch_errors (); 476 x_uncatch_errors ();
477 UNBLOCK_INPUT; 477 unblock_input ();
478} 478}
479 479
480/* This is the selection request currently being processed. 480/* This is the selection request currently being processed.
@@ -536,9 +536,9 @@ x_selection_request_lisp_error (Lisp_Object ignore)
536static Lisp_Object 536static Lisp_Object
537x_catch_errors_unwind (Lisp_Object dummy) 537x_catch_errors_unwind (Lisp_Object dummy)
538{ 538{
539 BLOCK_INPUT; 539 block_input ();
540 x_uncatch_errors (); 540 x_uncatch_errors ();
541 UNBLOCK_INPUT; 541 unblock_input ();
542 return Qnil; 542 return Qnil;
543} 543}
544 544
@@ -610,7 +610,7 @@ x_reply_selection_request (struct input_event *event,
610 if (reply->property == None) 610 if (reply->property == None)
611 reply->property = reply->target; 611 reply->property = reply->target;
612 612
613 BLOCK_INPUT; 613 block_input ();
614 /* The protected block contains wait_for_property_change, which can 614 /* The protected block contains wait_for_property_change, which can
615 run random lisp code (process handlers) or signal. Therefore, we 615 run random lisp code (process handlers) or signal. Therefore, we
616 put the x_uncatch_errors call in an unwind. */ 616 put the x_uncatch_errors call in an unwind. */
@@ -682,7 +682,7 @@ x_reply_selection_request (struct input_event *event,
682 { 682 {
683 int format_bytes = cs->format / 8; 683 int format_bytes = cs->format / 8;
684 int had_errors = x_had_errors_p (display); 684 int had_errors = x_had_errors_p (display);
685 UNBLOCK_INPUT; 685 unblock_input ();
686 686
687 bytes_remaining = cs->size; 687 bytes_remaining = cs->size;
688 bytes_remaining *= format_bytes; 688 bytes_remaining *= format_bytes;
@@ -703,7 +703,7 @@ x_reply_selection_request (struct input_event *event,
703 int i = ((bytes_remaining < max_bytes) 703 int i = ((bytes_remaining < max_bytes)
704 ? bytes_remaining 704 ? bytes_remaining
705 : max_bytes) / format_bytes; 705 : max_bytes) / format_bytes;
706 BLOCK_INPUT; 706 block_input ();
707 707
708 cs->wait_object 708 cs->wait_object
709 = expect_property_change (display, window, cs->property, 709 = expect_property_change (display, window, cs->property,
@@ -722,7 +722,7 @@ x_reply_selection_request (struct input_event *event,
722 : format_bytes); 722 : format_bytes);
723 XFlush (display); 723 XFlush (display);
724 had_errors = x_had_errors_p (display); 724 had_errors = x_had_errors_p (display);
725 UNBLOCK_INPUT; 725 unblock_input ();
726 726
727 if (had_errors) break; 727 if (had_errors) break;
728 728
@@ -735,7 +735,7 @@ x_reply_selection_request (struct input_event *event,
735 735
736 /* Now write a zero-length chunk to the property to tell the 736 /* Now write a zero-length chunk to the property to tell the
737 requestor that we're done. */ 737 requestor that we're done. */
738 BLOCK_INPUT; 738 block_input ();
739 if (! waiting_for_other_props_on_window (display, window)) 739 if (! waiting_for_other_props_on_window (display, window))
740 XSelectInput (display, window, 0L); 740 XSelectInput (display, window, 0L);
741 741
@@ -757,15 +757,15 @@ x_reply_selection_request (struct input_event *event,
757 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are 757 /* 2004-09-10: XSync and UNBLOCK so that possible protocol errors are
758 delivered before uncatch errors. */ 758 delivered before uncatch errors. */
759 XSync (display, False); 759 XSync (display, False);
760 UNBLOCK_INPUT; 760 unblock_input ();
761 761
762 /* GTK queues events in addition to the queue in Xlib. So we 762 /* GTK queues events in addition to the queue in Xlib. So we
763 UNBLOCK to enter the event loop and get possible errors delivered, 763 UNBLOCK to enter the event loop and get possible errors delivered,
764 and then BLOCK again because x_uncatch_errors requires it. */ 764 and then BLOCK again because x_uncatch_errors requires it. */
765 BLOCK_INPUT; 765 block_input ();
766 /* This calls x_uncatch_errors. */ 766 /* This calls x_uncatch_errors. */
767 unbind_to (count, Qnil); 767 unbind_to (count, Qnil);
768 UNBLOCK_INPUT; 768 unblock_input ();
769} 769}
770 770
771/* Handle a SelectionRequest event EVENT. 771/* Handle a SelectionRequest event EVENT.
@@ -1232,7 +1232,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1232 if (! NILP (time_stamp)) 1232 if (! NILP (time_stamp))
1233 CONS_TO_INTEGER (time_stamp, Time, requestor_time); 1233 CONS_TO_INTEGER (time_stamp, Time, requestor_time);
1234 1234
1235 BLOCK_INPUT; 1235 block_input ();
1236 TRACE2 ("Get selection %s, type %s", 1236 TRACE2 ("Get selection %s, type %s",
1237 XGetAtomName (display, type_atom), 1237 XGetAtomName (display, type_atom),
1238 XGetAtomName (display, target_property)); 1238 XGetAtomName (display, target_property));
@@ -1257,7 +1257,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1257 record_unwind_protect (queue_selection_requests_unwind, Qnil); 1257 record_unwind_protect (queue_selection_requests_unwind, Qnil);
1258#endif 1258#endif
1259 1259
1260 UNBLOCK_INPUT; 1260 unblock_input ();
1261 1261
1262 /* This allows quits. Also, don't wait forever. */ 1262 /* This allows quits. Also, don't wait forever. */
1263 timeout = max (0, x_selection_timeout); 1263 timeout = max (0, x_selection_timeout);
@@ -1309,7 +1309,7 @@ x_get_window_property (Display *display, Window window, Atom property,
1309 ? min (PTRDIFF_MAX, SIZE_MAX) - 1 1309 ? min (PTRDIFF_MAX, SIZE_MAX) - 1
1310 : LONG_MAX * x_long_size); 1310 : LONG_MAX * x_long_size);
1311 1311
1312 BLOCK_INPUT; 1312 block_input ();
1313 1313
1314 /* First probe the thing to find out how big it is. */ 1314 /* First probe the thing to find out how big it is. */
1315 result = XGetWindowProperty (display, window, property, 1315 result = XGetWindowProperty (display, window, property,
@@ -1410,19 +1410,19 @@ x_get_window_property (Display *display, Window window, Atom property,
1410 data[offset] = '\0'; 1410 data[offset] = '\0';
1411 1411
1412 done: 1412 done:
1413 UNBLOCK_INPUT; 1413 unblock_input ();
1414 *data_ret = data; 1414 *data_ret = data;
1415 *bytes_ret = offset; 1415 *bytes_ret = offset;
1416 return; 1416 return;
1417 1417
1418 size_overflow: 1418 size_overflow:
1419 free (data); 1419 free (data);
1420 UNBLOCK_INPUT; 1420 unblock_input ();
1421 memory_full (SIZE_MAX); 1421 memory_full (SIZE_MAX);
1422 1422
1423 memory_exhausted: 1423 memory_exhausted:
1424 free (data); 1424 free (data);
1425 UNBLOCK_INPUT; 1425 unblock_input ();
1426 memory_full (total_size + 1); 1426 memory_full (total_size + 1);
1427} 1427}
1428 1428
@@ -1454,7 +1454,7 @@ receive_incremental_selection (Display *display, Window window, Atom property,
1454 that property, then reading the property, then deleting it to ack. 1454 that property, then reading the property, then deleting it to ack.
1455 We are done when the sender places a property of length 0. 1455 We are done when the sender places a property of length 0.
1456 */ 1456 */
1457 BLOCK_INPUT; 1457 block_input ();
1458 XSelectInput (display, window, STANDARD_EVENT_SET | PropertyChangeMask); 1458 XSelectInput (display, window, STANDARD_EVENT_SET | PropertyChangeMask);
1459 TRACE1 (" Delete property %s", 1459 TRACE1 (" Delete property %s",
1460 SDATA (SYMBOL_NAME (x_atom_to_symbol (display, property)))); 1460 SDATA (SYMBOL_NAME (x_atom_to_symbol (display, property))));
@@ -1464,7 +1464,7 @@ receive_incremental_selection (Display *display, Window window, Atom property,
1464 wait_object = expect_property_change (display, window, property, 1464 wait_object = expect_property_change (display, window, property,
1465 PropertyNewValue); 1465 PropertyNewValue);
1466 XFlush (display); 1466 XFlush (display);
1467 UNBLOCK_INPUT; 1467 unblock_input ();
1468 1468
1469 while (1) 1469 while (1)
1470 { 1470 {
@@ -1496,14 +1496,14 @@ receive_incremental_selection (Display *display, Window window, Atom property,
1496 break; 1496 break;
1497 } 1497 }
1498 1498
1499 BLOCK_INPUT; 1499 block_input ();
1500 TRACE1 (" ACK by deleting property %s", 1500 TRACE1 (" ACK by deleting property %s",
1501 XGetAtomName (display, property)); 1501 XGetAtomName (display, property));
1502 XDeleteProperty (display, window, property); 1502 XDeleteProperty (display, window, property);
1503 wait_object = expect_property_change (display, window, property, 1503 wait_object = expect_property_change (display, window, property,
1504 PropertyNewValue); 1504 PropertyNewValue);
1505 XFlush (display); 1505 XFlush (display);
1506 UNBLOCK_INPUT; 1506 unblock_input ();
1507 1507
1508 if (*size_bytes_ret - offset < tmp_size_bytes) 1508 if (*size_bytes_ret - offset < tmp_size_bytes)
1509 *data_ret = xpalloc (*data_ret, size_bytes_ret, 1509 *data_ret = xpalloc (*data_ret, size_bytes_ret,
@@ -1545,10 +1545,10 @@ x_get_window_property_as_lisp_data (Display *display, Window window,
1545 if (! data) 1545 if (! data)
1546 { 1546 {
1547 int there_is_a_selection_owner; 1547 int there_is_a_selection_owner;
1548 BLOCK_INPUT; 1548 block_input ();
1549 there_is_a_selection_owner 1549 there_is_a_selection_owner
1550 = XGetSelectionOwner (display, selection_atom); 1550 = XGetSelectionOwner (display, selection_atom);
1551 UNBLOCK_INPUT; 1551 unblock_input ();
1552 if (there_is_a_selection_owner) 1552 if (there_is_a_selection_owner)
1553 signal_error ("Selection owner couldn't convert", 1553 signal_error ("Selection owner couldn't convert",
1554 actual_type 1554 actual_type
@@ -1565,22 +1565,22 @@ x_get_window_property_as_lisp_data (Display *display, Window window,
1565 /* That wasn't really the data, just the beginning. */ 1565 /* That wasn't really the data, just the beginning. */
1566 1566
1567 unsigned int min_size_bytes = * ((unsigned int *) data); 1567 unsigned int min_size_bytes = * ((unsigned int *) data);
1568 BLOCK_INPUT; 1568 block_input ();
1569 /* Use xfree, not XFree, because x_get_window_property 1569 /* Use xfree, not XFree, because x_get_window_property
1570 calls xmalloc itself. */ 1570 calls xmalloc itself. */
1571 xfree (data); 1571 xfree (data);
1572 UNBLOCK_INPUT; 1572 unblock_input ();
1573 receive_incremental_selection (display, window, property, target_type, 1573 receive_incremental_selection (display, window, property, target_type,
1574 min_size_bytes, &data, &bytes, 1574 min_size_bytes, &data, &bytes,
1575 &actual_type, &actual_format, 1575 &actual_type, &actual_format,
1576 &actual_size); 1576 &actual_size);
1577 } 1577 }
1578 1578
1579 BLOCK_INPUT; 1579 block_input ();
1580 TRACE1 (" Delete property %s", XGetAtomName (display, property)); 1580 TRACE1 (" Delete property %s", XGetAtomName (display, property));
1581 XDeleteProperty (display, window, property); 1581 XDeleteProperty (display, window, property);
1582 XFlush (display); 1582 XFlush (display);
1583 UNBLOCK_INPUT; 1583 unblock_input ();
1584 1584
1585 /* It's been read. Now convert it to a lisp object in some semi-rational 1585 /* It's been read. Now convert it to a lisp object in some semi-rational
1586 manner. */ 1586 manner. */
@@ -2096,13 +2096,13 @@ On MS-DOS, all this does is return non-nil if we own the selection. */)
2096 2096
2097 selection_atom = symbol_to_x_atom (dpyinfo, selection); 2097 selection_atom = symbol_to_x_atom (dpyinfo, selection);
2098 2098
2099 BLOCK_INPUT; 2099 block_input ();
2100 if (NILP (time_object)) 2100 if (NILP (time_object))
2101 timestamp = last_event_timestamp; 2101 timestamp = last_event_timestamp;
2102 else 2102 else
2103 CONS_TO_INTEGER (time_object, Time, timestamp); 2103 CONS_TO_INTEGER (time_object, Time, timestamp);
2104 XSetSelectionOwner (dpyinfo->display, selection_atom, None, timestamp); 2104 XSetSelectionOwner (dpyinfo->display, selection_atom, None, timestamp);
2105 UNBLOCK_INPUT; 2105 unblock_input ();
2106 2106
2107 /* It doesn't seem to be guaranteed that a SelectionClear event will be 2107 /* It doesn't seem to be guaranteed that a SelectionClear event will be
2108 generated for a window which owns the selection when that window sets 2108 generated for a window which owns the selection when that window sets
@@ -2179,9 +2179,9 @@ On Nextstep, TERMINAL is unused. */)
2179 2179
2180 atom = symbol_to_x_atom (dpyinfo, selection); 2180 atom = symbol_to_x_atom (dpyinfo, selection);
2181 if (atom == 0) return Qnil; 2181 if (atom == 0) return Qnil;
2182 BLOCK_INPUT; 2182 block_input ();
2183 owner = XGetSelectionOwner (dpyinfo->display, atom); 2183 owner = XGetSelectionOwner (dpyinfo->display, atom);
2184 UNBLOCK_INPUT; 2184 unblock_input ();
2185 return (owner ? Qt : Qnil); 2185 return (owner ? Qt : Qnil);
2186} 2186}
2187 2187
@@ -2353,9 +2353,9 @@ x_fill_property_data (Display *dpy, Lisp_Object data, void *ret, int format)
2353 val = cons_to_signed (o, LONG_MIN, LONG_MAX); 2353 val = cons_to_signed (o, LONG_MIN, LONG_MAX);
2354 else if (STRINGP (o)) 2354 else if (STRINGP (o))
2355 { 2355 {
2356 BLOCK_INPUT; 2356 block_input ();
2357 val = (long) XInternAtom (dpy, SSDATA (o), False); 2357 val = (long) XInternAtom (dpy, SSDATA (o), False);
2358 UNBLOCK_INPUT; 2358 unblock_input ();
2359 } 2359 }
2360 else 2360 else
2361 error ("Wrong type, must be string, number or cons"); 2361 error ("Wrong type, must be string, number or cons");
@@ -2413,7 +2413,7 @@ mouse_position_for_drop (FRAME_PTR f, int *x, int *y)
2413 Window root, dummy_window; 2413 Window root, dummy_window;
2414 int dummy; 2414 int dummy;
2415 2415
2416 BLOCK_INPUT; 2416 block_input ();
2417 2417
2418 XQueryPointer (FRAME_X_DISPLAY (f), 2418 XQueryPointer (FRAME_X_DISPLAY (f),
2419 DefaultRootWindow (FRAME_X_DISPLAY (f)), 2419 DefaultRootWindow (FRAME_X_DISPLAY (f)),
@@ -2439,7 +2439,7 @@ mouse_position_for_drop (FRAME_PTR f, int *x, int *y)
2439 *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); 2439 *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
2440 *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); 2440 *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
2441 2441
2442 UNBLOCK_INPUT; 2442 unblock_input ();
2443} 2443}
2444 2444
2445DEFUN ("x-get-atom-name", Fx_get_atom_name, 2445DEFUN ("x-get-atom-name", Fx_get_atom_name,
@@ -2462,7 +2462,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2462 2462
2463 CONS_TO_INTEGER (value, Atom, atom); 2463 CONS_TO_INTEGER (value, Atom, atom);
2464 2464
2465 BLOCK_INPUT; 2465 block_input ();
2466 x_catch_errors (dpy); 2466 x_catch_errors (dpy);
2467 name = atom ? XGetAtomName (dpy, atom) : empty; 2467 name = atom ? XGetAtomName (dpy, atom) : empty;
2468 had_errors = x_had_errors_p (dpy); 2468 had_errors = x_had_errors_p (dpy);
@@ -2474,7 +2474,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2474 if (atom && name) XFree (name); 2474 if (atom && name) XFree (name);
2475 if (NILP (ret)) ret = empty_unibyte_string; 2475 if (NILP (ret)) ret = empty_unibyte_string;
2476 2476
2477 UNBLOCK_INPUT; 2477 unblock_input ();
2478 2478
2479 return ret; 2479 return ret;
2480} 2480}
@@ -2496,9 +2496,9 @@ FRAME is on. If FRAME is nil, the selected frame is used. */)
2496 x_atom = symbol_to_x_atom (dpyinfo, atom); 2496 x_atom = symbol_to_x_atom (dpyinfo, atom);
2497 else if (STRINGP (atom)) 2497 else if (STRINGP (atom))
2498 { 2498 {
2499 BLOCK_INPUT; 2499 block_input ();
2500 x_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (atom), False); 2500 x_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (atom), False);
2501 UNBLOCK_INPUT; 2501 unblock_input ();
2502 } 2502 }
2503 else 2503 else
2504 error ("ATOM must be a symbol or a string"); 2504 error ("ATOM must be a symbol or a string");
@@ -2657,7 +2657,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2657 if (wdest == 0) wdest = dpyinfo->root_window; 2657 if (wdest == 0) wdest = dpyinfo->root_window;
2658 to_root = wdest == dpyinfo->root_window; 2658 to_root = wdest == dpyinfo->root_window;
2659 2659
2660 BLOCK_INPUT; 2660 block_input ();
2661 2661
2662 event.xclient.message_type = message_type; 2662 event.xclient.message_type = message_type;
2663 event.xclient.display = dpyinfo->display; 2663 event.xclient.display = dpyinfo->display;
@@ -2683,7 +2683,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2683 XFlush (dpyinfo->display); 2683 XFlush (dpyinfo->display);
2684 } 2684 }
2685 x_uncatch_errors (); 2685 x_uncatch_errors ();
2686 UNBLOCK_INPUT; 2686 unblock_input ();
2687} 2687}
2688 2688
2689 2689
diff --git a/src/xsettings.c b/src/xsettings.c
index 58c84495489..7c68ff295cf 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -929,7 +929,7 @@ init_xsettings (struct x_display_info *dpyinfo)
929{ 929{
930 Display *dpy = dpyinfo->display; 930 Display *dpy = dpyinfo->display;
931 931
932 BLOCK_INPUT; 932 block_input ();
933 933
934 /* Select events so we can detect client messages sent when selection 934 /* Select events so we can detect client messages sent when selection
935 owner changes. */ 935 owner changes. */
@@ -939,7 +939,7 @@ init_xsettings (struct x_display_info *dpyinfo)
939 if (dpyinfo->xsettings_window != None) 939 if (dpyinfo->xsettings_window != None)
940 read_and_apply_settings (dpyinfo, False); 940 read_and_apply_settings (dpyinfo, False);
941 941
942 UNBLOCK_INPUT; 942 unblock_input ();
943} 943}
944 944
945void 945void
diff --git a/src/xterm.c b/src/xterm.c
index 9ab53dc087a..a4c3e125d8d 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -287,7 +287,7 @@ enum xembed_message
287 287
288/* Used in x_flush. */ 288/* Used in x_flush. */
289 289
290static int x_alloc_nearest_color_1 (Display *, Colormap, XColor *); 290static bool x_alloc_nearest_color_1 (Display *, Colormap, XColor *);
291static void x_set_window_size_1 (struct frame *, int, int, int); 291static void x_set_window_size_1 (struct frame *, int, int, int);
292static void x_raise_frame (struct frame *); 292static void x_raise_frame (struct frame *);
293static void x_lower_frame (struct frame *); 293static void x_lower_frame (struct frame *);
@@ -353,7 +353,7 @@ x_flush (struct frame *f)
353 if (!NILP (Vinhibit_redisplay)) 353 if (!NILP (Vinhibit_redisplay))
354 return; 354 return;
355 355
356 BLOCK_INPUT; 356 block_input ();
357 if (f == NULL) 357 if (f == NULL)
358 { 358 {
359 Lisp_Object rest, frame; 359 Lisp_Object rest, frame;
@@ -363,7 +363,7 @@ x_flush (struct frame *f)
363 } 363 }
364 else if (FRAME_X_P (f)) 364 else if (FRAME_X_P (f))
365 XFlush (FRAME_X_DISPLAY (f)); 365 XFlush (FRAME_X_DISPLAY (f));
366 UNBLOCK_INPUT; 366 unblock_input ();
367} 367}
368 368
369 369
@@ -564,7 +564,7 @@ x_update_window_begin (struct window *w)
564 updated_window = w; 564 updated_window = w;
565 set_output_cursor (&w->cursor); 565 set_output_cursor (&w->cursor);
566 566
567 BLOCK_INPUT; 567 block_input ();
568 568
569 if (f == hlinfo->mouse_face_mouse_frame) 569 if (f == hlinfo->mouse_face_mouse_frame)
570 { 570 {
@@ -577,7 +577,7 @@ x_update_window_begin (struct window *w)
577 hlinfo->mouse_face_window = Qnil; 577 hlinfo->mouse_face_window = Qnil;
578 } 578 }
579 579
580 UNBLOCK_INPUT; 580 unblock_input ();
581} 581}
582 582
583 583
@@ -618,7 +618,7 @@ x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritt
618 618
619 if (!w->pseudo_window_p) 619 if (!w->pseudo_window_p)
620 { 620 {
621 BLOCK_INPUT; 621 block_input ();
622 622
623 if (cursor_on_p) 623 if (cursor_on_p)
624 display_and_set_cursor (w, 1, output_cursor.hpos, 624 display_and_set_cursor (w, 1, output_cursor.hpos,
@@ -628,7 +628,7 @@ x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritt
628 if (draw_window_fringes (w, 1)) 628 if (draw_window_fringes (w, 1))
629 x_draw_vertical_border (w); 629 x_draw_vertical_border (w);
630 630
631 UNBLOCK_INPUT; 631 unblock_input ();
632 } 632 }
633 633
634 /* If a row with mouse-face was overwritten, arrange for 634 /* If a row with mouse-face was overwritten, arrange for
@@ -654,9 +654,9 @@ x_update_end (struct frame *f)
654 MOUSE_HL_INFO (f)->mouse_face_defer = 0; 654 MOUSE_HL_INFO (f)->mouse_face_defer = 0;
655 655
656#ifndef XFlush 656#ifndef XFlush
657 BLOCK_INPUT; 657 block_input ();
658 XFlush (FRAME_X_DISPLAY (f)); 658 XFlush (FRAME_X_DISPLAY (f));
659 UNBLOCK_INPUT; 659 unblock_input ();
660#endif 660#endif
661} 661}
662 662
@@ -675,13 +675,13 @@ XTframe_up_to_date (struct frame *f)
675 if (hlinfo->mouse_face_deferred_gc 675 if (hlinfo->mouse_face_deferred_gc
676 || f == hlinfo->mouse_face_mouse_frame) 676 || f == hlinfo->mouse_face_mouse_frame)
677 { 677 {
678 BLOCK_INPUT; 678 block_input ();
679 if (hlinfo->mouse_face_mouse_frame) 679 if (hlinfo->mouse_face_mouse_frame)
680 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, 680 note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
681 hlinfo->mouse_face_mouse_x, 681 hlinfo->mouse_face_mouse_x,
682 hlinfo->mouse_face_mouse_y); 682 hlinfo->mouse_face_mouse_y);
683 hlinfo->mouse_face_deferred_gc = 0; 683 hlinfo->mouse_face_deferred_gc = 0;
684 UNBLOCK_INPUT; 684 unblock_input ();
685 } 685 }
686 } 686 }
687} 687}
@@ -722,13 +722,13 @@ x_after_update_window_line (struct glyph_row *desired_row)
722 { 722 {
723 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); 723 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
724 724
725 BLOCK_INPUT; 725 block_input ();
726 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 726 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
727 0, y, width, height, False); 727 0, y, width, height, False);
728 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 728 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
729 FRAME_PIXEL_WIDTH (f) - width, 729 FRAME_PIXEL_WIDTH (f) - width,
730 y, width, height, False); 730 y, width, height, False);
731 UNBLOCK_INPUT; 731 unblock_input ();
732 } 732 }
733} 733}
734 734
@@ -899,8 +899,8 @@ static void x_compute_glyph_string_overhangs (struct glyph_string *);
899static void x_set_cursor_gc (struct glyph_string *); 899static void x_set_cursor_gc (struct glyph_string *);
900static void x_set_mode_line_face_gc (struct glyph_string *); 900static void x_set_mode_line_face_gc (struct glyph_string *);
901static void x_set_mouse_face_gc (struct glyph_string *); 901static void x_set_mouse_face_gc (struct glyph_string *);
902static int x_alloc_lighter_color (struct frame *, Display *, Colormap, 902static bool x_alloc_lighter_color (struct frame *, Display *, Colormap,
903 unsigned long *, double, int); 903 unsigned long *, double, int);
904static void x_setup_relief_color (struct frame *, struct relief *, 904static void x_setup_relief_color (struct frame *, struct relief *,
905 double, int, unsigned long); 905 double, int, unsigned long);
906static void x_setup_relief_colors (struct glyph_string *); 906static void x_setup_relief_colors (struct glyph_string *);
@@ -1027,7 +1027,7 @@ x_set_mouse_face_gc (struct glyph_string *s)
1027 Faces to use in the mode line have already been computed when the 1027 Faces to use in the mode line have already been computed when the
1028 matrix was built, so there isn't much to do, here. */ 1028 matrix was built, so there isn't much to do, here. */
1029 1029
1030static inline void 1030static void
1031x_set_mode_line_face_gc (struct glyph_string *s) 1031x_set_mode_line_face_gc (struct glyph_string *s)
1032{ 1032{
1033 s->gc = s->face->gc; 1033 s->gc = s->face->gc;
@@ -1038,7 +1038,7 @@ x_set_mode_line_face_gc (struct glyph_string *s)
1038 S->stippled_p to a non-zero value if the face of S has a stipple 1038 S->stippled_p to a non-zero value if the face of S has a stipple
1039 pattern. */ 1039 pattern. */
1040 1040
1041static inline void 1041static void
1042x_set_glyph_string_gc (struct glyph_string *s) 1042x_set_glyph_string_gc (struct glyph_string *s)
1043{ 1043{
1044 PREPARE_FACE_FOR_DISPLAY (s->f, s->face); 1044 PREPARE_FACE_FOR_DISPLAY (s->f, s->face);
@@ -1083,7 +1083,7 @@ x_set_glyph_string_gc (struct glyph_string *s)
1083/* Set clipping for output of glyph string S. S may be part of a mode 1083/* Set clipping for output of glyph string S. S may be part of a mode
1084 line or menu if we don't have X toolkit support. */ 1084 line or menu if we don't have X toolkit support. */
1085 1085
1086static inline void 1086static void
1087x_set_glyph_string_clipping (struct glyph_string *s) 1087x_set_glyph_string_clipping (struct glyph_string *s)
1088{ 1088{
1089 XRectangle *r = s->clip; 1089 XRectangle *r = s->clip;
@@ -1156,7 +1156,7 @@ x_compute_glyph_string_overhangs (struct glyph_string *s)
1156 1156
1157/* Fill rectangle X, Y, W, H with background color of glyph string S. */ 1157/* Fill rectangle X, Y, W, H with background color of glyph string S. */
1158 1158
1159static inline void 1159static void
1160x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h) 1160x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h)
1161{ 1161{
1162 XGCValues xgcv; 1162 XGCValues xgcv;
@@ -1469,9 +1469,9 @@ x_frame_of_widget (Widget widget)
1469 If this produces the same color as PIXEL, try a color where all RGB 1469 If this produces the same color as PIXEL, try a color where all RGB
1470 values have DELTA added. Return the allocated color in *PIXEL. 1470 values have DELTA added. Return the allocated color in *PIXEL.
1471 DISPLAY is the X display, CMAP is the colormap to operate on. 1471 DISPLAY is the X display, CMAP is the colormap to operate on.
1472 Value is non-zero if successful. */ 1472 Value is true if successful. */
1473 1473
1474int 1474bool
1475x_alloc_lighter_color_for_widget (Widget widget, Display *display, Colormap cmap, 1475x_alloc_lighter_color_for_widget (Widget widget, Display *display, Colormap cmap,
1476 unsigned long *pixel, double factor, int delta) 1476 unsigned long *pixel, double factor, int delta)
1477{ 1477{
@@ -1696,15 +1696,15 @@ x_query_color (struct frame *f, XColor *color)
1696 1696
1697/* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an 1697/* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1698 exact match can't be allocated, try the nearest color available. 1698 exact match can't be allocated, try the nearest color available.
1699 Value is non-zero if successful. Set *COLOR to the color 1699 Value is true if successful. Set *COLOR to the color
1700 allocated. */ 1700 allocated. */
1701 1701
1702static int 1702static bool
1703x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color) 1703x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1704{ 1704{
1705 int rc; 1705 bool rc;
1706 1706
1707 rc = XAllocColor (dpy, cmap, color); 1707 rc = XAllocColor (dpy, cmap, color) != 0;
1708 if (rc == 0) 1708 if (rc == 0)
1709 { 1709 {
1710 /* If we got to this point, the colormap is full, so we're going 1710 /* If we got to this point, the colormap is full, so we're going
@@ -1735,7 +1735,7 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1735 color->red = cells[nearest].red; 1735 color->red = cells[nearest].red;
1736 color->green = cells[nearest].green; 1736 color->green = cells[nearest].green;
1737 color->blue = cells[nearest].blue; 1737 color->blue = cells[nearest].blue;
1738 rc = XAllocColor (dpy, cmap, color); 1738 rc = XAllocColor (dpy, cmap, color) != 0;
1739 } 1739 }
1740 else 1740 else
1741 { 1741 {
@@ -1768,10 +1768,10 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
1768 1768
1769/* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an 1769/* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1770 exact match can't be allocated, try the nearest color available. 1770 exact match can't be allocated, try the nearest color available.
1771 Value is non-zero if successful. Set *COLOR to the color 1771 Value is true if successful. Set *COLOR to the color
1772 allocated. */ 1772 allocated. */
1773 1773
1774int 1774bool
1775x_alloc_nearest_color (struct frame *f, Colormap cmap, XColor *color) 1775x_alloc_nearest_color (struct frame *f, Colormap cmap, XColor *color)
1776{ 1776{
1777 gamma_correct (f, color); 1777 gamma_correct (f, color);
@@ -1789,10 +1789,10 @@ x_copy_color (struct frame *f, long unsigned int pixel)
1789 XColor color; 1789 XColor color;
1790 1790
1791 color.pixel = pixel; 1791 color.pixel = pixel;
1792 BLOCK_INPUT; 1792 block_input ();
1793 x_query_color (f, &color); 1793 x_query_color (f, &color);
1794 XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); 1794 XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color);
1795 UNBLOCK_INPUT; 1795 unblock_input ();
1796#ifdef DEBUG_X_COLORS 1796#ifdef DEBUG_X_COLORS
1797 register_color (pixel); 1797 register_color (pixel);
1798#endif 1798#endif
@@ -1821,12 +1821,12 @@ x_copy_color (struct frame *f, long unsigned int pixel)
1821 DISPLAY is the X display, CMAP is the colormap to operate on. 1821 DISPLAY is the X display, CMAP is the colormap to operate on.
1822 Value is non-zero if successful. */ 1822 Value is non-zero if successful. */
1823 1823
1824static int 1824static bool
1825x_alloc_lighter_color (struct frame *f, Display *display, Colormap cmap, long unsigned int *pixel, double factor, int delta) 1825x_alloc_lighter_color (struct frame *f, Display *display, Colormap cmap, long unsigned int *pixel, double factor, int delta)
1826{ 1826{
1827 XColor color, new; 1827 XColor color, new;
1828 long bright; 1828 long bright;
1829 int success_p; 1829 bool success_p;
1830 1830
1831 /* Get RGB color values. */ 1831 /* Get RGB color values. */
1832 color.pixel = *pixel; 1832 color.pixel = *pixel;
@@ -3028,7 +3028,7 @@ x_clear_frame (struct frame *f)
3028 3028
3029 /* We don't set the output cursor here because there will always 3029 /* We don't set the output cursor here because there will always
3030 follow an explicit cursor_to. */ 3030 follow an explicit cursor_to. */
3031 BLOCK_INPUT; 3031 block_input ();
3032 3032
3033 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 3033 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
3034 3034
@@ -3045,7 +3045,7 @@ x_clear_frame (struct frame *f)
3045 3045
3046 XFlush (FRAME_X_DISPLAY (f)); 3046 XFlush (FRAME_X_DISPLAY (f));
3047 3047
3048 UNBLOCK_INPUT; 3048 unblock_input ();
3049} 3049}
3050 3050
3051 3051
@@ -3055,7 +3055,7 @@ x_clear_frame (struct frame *f)
3055static void 3055static void
3056XTflash (struct frame *f) 3056XTflash (struct frame *f)
3057{ 3057{
3058 BLOCK_INPUT; 3058 block_input ();
3059 3059
3060 { 3060 {
3061#ifdef USE_GTK 3061#ifdef USE_GTK
@@ -3208,14 +3208,14 @@ XTflash (struct frame *f)
3208 } 3208 }
3209 } 3209 }
3210 3210
3211 UNBLOCK_INPUT; 3211 unblock_input ();
3212} 3212}
3213 3213
3214 3214
3215static void 3215static void
3216XTtoggle_invisible_pointer (FRAME_PTR f, int invisible) 3216XTtoggle_invisible_pointer (FRAME_PTR f, int invisible)
3217{ 3217{
3218 BLOCK_INPUT; 3218 block_input ();
3219 if (invisible) 3219 if (invisible)
3220 { 3220 {
3221 if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor != 0) 3221 if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor != 0)
@@ -3226,7 +3226,7 @@ XTtoggle_invisible_pointer (FRAME_PTR f, int invisible)
3226 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 3226 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3227 f->output_data.x->current_cursor); 3227 f->output_data.x->current_cursor);
3228 f->pointer_invisible = invisible; 3228 f->pointer_invisible = invisible;
3229 UNBLOCK_INPUT; 3229 unblock_input ();
3230} 3230}
3231 3231
3232 3232
@@ -3241,10 +3241,10 @@ XTring_bell (struct frame *f)
3241 XTflash (f); 3241 XTflash (f);
3242 else 3242 else
3243 { 3243 {
3244 BLOCK_INPUT; 3244 block_input ();
3245 XBell (FRAME_X_DISPLAY (f), 0); 3245 XBell (FRAME_X_DISPLAY (f), 0);
3246 XFlush (FRAME_X_DISPLAY (f)); 3246 XFlush (FRAME_X_DISPLAY (f));
3247 UNBLOCK_INPUT; 3247 unblock_input ();
3248 } 3248 }
3249 } 3249 }
3250} 3250}
@@ -3341,7 +3341,7 @@ x_scroll_run (struct window *w, struct run *run)
3341 height = run->height; 3341 height = run->height;
3342 } 3342 }
3343 3343
3344 BLOCK_INPUT; 3344 block_input ();
3345 3345
3346 /* Cursor off. Will be switched on again in x_update_window_end. */ 3346 /* Cursor off. Will be switched on again in x_update_window_end. */
3347 updated_window = w; 3347 updated_window = w;
@@ -3354,7 +3354,7 @@ x_scroll_run (struct window *w, struct run *run)
3354 width, height, 3354 width, height,
3355 x, to_y); 3355 x, to_y);
3356 3356
3357 UNBLOCK_INPUT; 3357 unblock_input ();
3358} 3358}
3359 3359
3360 3360
@@ -3371,7 +3371,7 @@ frame_highlight (struct frame *f)
3371 the ICCCM (section 4.1.6) says that the window's border pixmap 3371 the ICCCM (section 4.1.6) says that the window's border pixmap
3372 and border pixel are window attributes which are "private to the 3372 and border pixel are window attributes which are "private to the
3373 client", so we can always change it to whatever we want. */ 3373 client", so we can always change it to whatever we want. */
3374 BLOCK_INPUT; 3374 block_input ();
3375 /* I recently started to get errors in this XSetWindowBorder, depending on 3375 /* I recently started to get errors in this XSetWindowBorder, depending on
3376 the window-manager in use, tho something more is at play since I've been 3376 the window-manager in use, tho something more is at play since I've been
3377 using that same window-manager binary for ever. Let's not crash just 3377 using that same window-manager binary for ever. Let's not crash just
@@ -3380,7 +3380,7 @@ frame_highlight (struct frame *f)
3380 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 3380 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3381 f->output_data.x->border_pixel); 3381 f->output_data.x->border_pixel);
3382 x_uncatch_errors (); 3382 x_uncatch_errors ();
3383 UNBLOCK_INPUT; 3383 unblock_input ();
3384 x_update_cursor (f, 1); 3384 x_update_cursor (f, 1);
3385 x_set_frame_alpha (f); 3385 x_set_frame_alpha (f);
3386} 3386}
@@ -3392,13 +3392,13 @@ frame_unhighlight (struct frame *f)
3392 the ICCCM (section 4.1.6) says that the window's border pixmap 3392 the ICCCM (section 4.1.6) says that the window's border pixmap
3393 and border pixel are window attributes which are "private to the 3393 and border pixel are window attributes which are "private to the
3394 client", so we can always change it to whatever we want. */ 3394 client", so we can always change it to whatever we want. */
3395 BLOCK_INPUT; 3395 block_input ();
3396 /* Same as above for XSetWindowBorder (bug#9310). */ 3396 /* Same as above for XSetWindowBorder (bug#9310). */
3397 x_catch_errors (FRAME_X_DISPLAY (f)); 3397 x_catch_errors (FRAME_X_DISPLAY (f));
3398 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 3398 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3399 f->output_data.x->border_tile); 3399 f->output_data.x->border_tile);
3400 x_uncatch_errors (); 3400 x_uncatch_errors ();
3401 UNBLOCK_INPUT; 3401 unblock_input ();
3402 x_update_cursor (f, 1); 3402 x_update_cursor (f, 1);
3403 x_set_frame_alpha (f); 3403 x_set_frame_alpha (f);
3404} 3404}
@@ -3765,9 +3765,9 @@ x_get_keysym_name (int keysym)
3765{ 3765{
3766 char *value; 3766 char *value;
3767 3767
3768 BLOCK_INPUT; 3768 block_input ();
3769 value = XKeysymToString (keysym); 3769 value = XKeysymToString (keysym);
3770 UNBLOCK_INPUT; 3770 unblock_input ();
3771 3771
3772 return value; 3772 return value;
3773} 3773}
@@ -3897,7 +3897,7 @@ XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
3897{ 3897{
3898 FRAME_PTR f1; 3898 FRAME_PTR f1;
3899 3899
3900 BLOCK_INPUT; 3900 block_input ();
3901 3901
3902 if (! NILP (last_mouse_scroll_bar) && insist == 0) 3902 if (! NILP (last_mouse_scroll_bar) && insist == 0)
3903 x_scroll_bar_report_motion (fp, bar_window, part, x, y, timestamp); 3903 x_scroll_bar_report_motion (fp, bar_window, part, x, y, timestamp);
@@ -4078,7 +4078,7 @@ XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
4078 } 4078 }
4079 } 4079 }
4080 4080
4081 UNBLOCK_INPUT; 4081 unblock_input ();
4082} 4082}
4083 4083
4084 4084
@@ -4267,7 +4267,7 @@ x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole)
4267 struct frame *f = XFRAME (w->frame); 4267 struct frame *f = XFRAME (w->frame);
4268 ptrdiff_t i; 4268 ptrdiff_t i;
4269 4269
4270 BLOCK_INPUT; 4270 block_input ();
4271 4271
4272 /* Construct a ClientMessage event to send to the frame. */ 4272 /* Construct a ClientMessage event to send to the frame. */
4273 ev->type = ClientMessage; 4273 ev->type = ClientMessage;
@@ -4314,7 +4314,7 @@ x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole)
4314 be sent to the client that created the window, and if that 4314 be sent to the client that created the window, and if that
4315 window no longer exists, no event will be sent. */ 4315 window no longer exists, no event will be sent. */
4316 XSendEvent (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), False, 0, &event); 4316 XSendEvent (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), False, 0, &event);
4317 UNBLOCK_INPUT; 4317 unblock_input ();
4318} 4318}
4319 4319
4320 4320
@@ -4405,9 +4405,9 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4405 int slider_size; 4405 int slider_size;
4406 4406
4407 /* Get the slider size. */ 4407 /* Get the slider size. */
4408 BLOCK_INPUT; 4408 block_input ();
4409 XtVaGetValues (widget, XmNsliderSize, &slider_size, NULL); 4409 XtVaGetValues (widget, XmNsliderSize, &slider_size, NULL);
4410 UNBLOCK_INPUT; 4410 unblock_input ();
4411 4411
4412 whole = XM_SB_MAX - slider_size; 4412 whole = XM_SB_MAX - slider_size;
4413 portion = min (cs->value, whole); 4413 portion = min (cs->value, whole);
@@ -4528,9 +4528,9 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4528 int part; 4528 int part;
4529 4529
4530 /* Get the size of the thumb, a value between 0 and 1. */ 4530 /* Get the size of the thumb, a value between 0 and 1. */
4531 BLOCK_INPUT; 4531 block_input ();
4532 XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL); 4532 XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL);
4533 UNBLOCK_INPUT; 4533 unblock_input ();
4534 4534
4535 whole = 10000000; 4535 whole = 10000000;
4536 portion = shown < 1 ? top * whole : 0; 4536 portion = shown < 1 ? top * whole : 0;
@@ -4570,9 +4570,9 @@ xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4570 int part; 4570 int part;
4571 4571
4572 /* Get the height of the scroll bar. */ 4572 /* Get the height of the scroll bar. */
4573 BLOCK_INPUT; 4573 block_input ();
4574 XtVaGetValues (widget, XtNheight, &height, NULL); 4574 XtVaGetValues (widget, XtNheight, &height, NULL);
4575 UNBLOCK_INPUT; 4575 unblock_input ();
4576 4576
4577 if (eabs (position) >= height) 4577 if (eabs (position) >= height)
4578 part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle; 4578 part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle;
@@ -4603,11 +4603,11 @@ x_create_toolkit_scroll_bar (struct frame *f, struct scroll_bar *bar)
4603{ 4603{
4604 const char *scroll_bar_name = SCROLL_BAR_NAME; 4604 const char *scroll_bar_name = SCROLL_BAR_NAME;
4605 4605
4606 BLOCK_INPUT; 4606 block_input ();
4607 xg_create_scroll_bar (f, bar, G_CALLBACK (xg_scroll_callback), 4607 xg_create_scroll_bar (f, bar, G_CALLBACK (xg_scroll_callback),
4608 G_CALLBACK (xg_end_scroll_callback), 4608 G_CALLBACK (xg_end_scroll_callback),
4609 scroll_bar_name); 4609 scroll_bar_name);
4610 UNBLOCK_INPUT; 4610 unblock_input ();
4611} 4611}
4612 4612
4613#else /* not USE_GTK */ 4613#else /* not USE_GTK */
@@ -4622,7 +4622,7 @@ x_create_toolkit_scroll_bar (struct frame *f, struct scroll_bar *bar)
4622 const char *scroll_bar_name = SCROLL_BAR_NAME; 4622 const char *scroll_bar_name = SCROLL_BAR_NAME;
4623 unsigned long pixel; 4623 unsigned long pixel;
4624 4624
4625 BLOCK_INPUT; 4625 block_input ();
4626 4626
4627#ifdef USE_MOTIF 4627#ifdef USE_MOTIF
4628 /* Set resources. Create the widget. */ 4628 /* Set resources. Create the widget. */
@@ -4806,7 +4806,7 @@ x_create_toolkit_scroll_bar (struct frame *f, struct scroll_bar *bar)
4806 xwindow = XtWindow (widget); 4806 xwindow = XtWindow (widget);
4807 bar->x_window = xwindow; 4807 bar->x_window = xwindow;
4808 4808
4809 UNBLOCK_INPUT; 4809 unblock_input ();
4810} 4810}
4811#endif /* not USE_GTK */ 4811#endif /* not USE_GTK */
4812 4812
@@ -4830,7 +4830,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4830 Widget widget = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar); 4830 Widget widget = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar);
4831 float top, shown; 4831 float top, shown;
4832 4832
4833 BLOCK_INPUT; 4833 block_input ();
4834 4834
4835#ifdef USE_MOTIF 4835#ifdef USE_MOTIF
4836 4836
@@ -4921,7 +4921,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4921 } 4921 }
4922#endif /* !USE_MOTIF */ 4922#endif /* !USE_MOTIF */
4923 4923
4924 UNBLOCK_INPUT; 4924 unblock_input ();
4925} 4925}
4926#endif /* not USE_GTK */ 4926#endif /* not USE_GTK */
4927 4927
@@ -4946,7 +4946,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
4946 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, x_window, PVEC_OTHER); 4946 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, x_window, PVEC_OTHER);
4947 Lisp_Object barobj; 4947 Lisp_Object barobj;
4948 4948
4949 BLOCK_INPUT; 4949 block_input ();
4950 4950
4951#ifdef USE_TOOLKIT_SCROLL_BARS 4951#ifdef USE_TOOLKIT_SCROLL_BARS
4952 x_create_toolkit_scroll_bar (f, bar); 4952 x_create_toolkit_scroll_bar (f, bar);
@@ -5034,7 +5034,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
5034 XMapRaised (FRAME_X_DISPLAY (f), bar->x_window); 5034 XMapRaised (FRAME_X_DISPLAY (f), bar->x_window);
5035#endif /* not USE_TOOLKIT_SCROLL_BARS */ 5035#endif /* not USE_TOOLKIT_SCROLL_BARS */
5036 5036
5037 UNBLOCK_INPUT; 5037 unblock_input ();
5038 return bar; 5038 return bar;
5039} 5039}
5040 5040
@@ -5068,7 +5068,7 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5068 && end == bar->end) 5068 && end == bar->end)
5069 return; 5069 return;
5070 5070
5071 BLOCK_INPUT; 5071 block_input ();
5072 5072
5073 { 5073 {
5074 int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f, bar->width); 5074 int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f, bar->width);
@@ -5144,7 +5144,7 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5144 5144
5145 } 5145 }
5146 5146
5147 UNBLOCK_INPUT; 5147 unblock_input ();
5148} 5148}
5149 5149
5150#endif /* !USE_TOOLKIT_SCROLL_BARS */ 5150#endif /* !USE_TOOLKIT_SCROLL_BARS */
@@ -5156,7 +5156,7 @@ static void
5156x_scroll_bar_remove (struct scroll_bar *bar) 5156x_scroll_bar_remove (struct scroll_bar *bar)
5157{ 5157{
5158 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5158 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5159 BLOCK_INPUT; 5159 block_input ();
5160 5160
5161#ifdef USE_TOOLKIT_SCROLL_BARS 5161#ifdef USE_TOOLKIT_SCROLL_BARS
5162#ifdef USE_GTK 5162#ifdef USE_GTK
@@ -5171,7 +5171,7 @@ x_scroll_bar_remove (struct scroll_bar *bar)
5171 /* Dissociate this scroll bar from its window. */ 5171 /* Dissociate this scroll bar from its window. */
5172 wset_vertical_scroll_bar (XWINDOW (bar->window), Qnil); 5172 wset_vertical_scroll_bar (XWINDOW (bar->window), Qnil);
5173 5173
5174 UNBLOCK_INPUT; 5174 unblock_input ();
5175} 5175}
5176 5176
5177 5177
@@ -5239,7 +5239,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5239 { 5239 {
5240 if (width > 0 && height > 0) 5240 if (width > 0 && height > 0)
5241 { 5241 {
5242 BLOCK_INPUT; 5242 block_input ();
5243#ifdef USE_TOOLKIT_SCROLL_BARS 5243#ifdef USE_TOOLKIT_SCROLL_BARS
5244 if (fringe_extended_p) 5244 if (fringe_extended_p)
5245 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5245 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -5248,7 +5248,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5248#endif 5248#endif
5249 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5249 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5250 left, top, width, height, False); 5250 left, top, width, height, False);
5251 UNBLOCK_INPUT; 5251 unblock_input ();
5252 } 5252 }
5253 5253
5254 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); 5254 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height);
@@ -5260,7 +5260,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5260 5260
5261 bar = XSCROLL_BAR (w->vertical_scroll_bar); 5261 bar = XSCROLL_BAR (w->vertical_scroll_bar);
5262 5262
5263 BLOCK_INPUT; 5263 block_input ();
5264 5264
5265 if (sb_left != bar->left) 5265 if (sb_left != bar->left)
5266 mask |= CWX; 5266 mask |= CWX;
@@ -5357,7 +5357,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5357 bar->width = sb_width; 5357 bar->width = sb_width;
5358 bar->height = height; 5358 bar->height = height;
5359 5359
5360 UNBLOCK_INPUT; 5360 unblock_input ();
5361 } 5361 }
5362 5362
5363#ifdef USE_TOOLKIT_SCROLL_BARS 5363#ifdef USE_TOOLKIT_SCROLL_BARS
@@ -5508,7 +5508,7 @@ x_scroll_bar_expose (struct scroll_bar *bar, XEvent *event)
5508 GC gc = f->output_data.x->normal_gc; 5508 GC gc = f->output_data.x->normal_gc;
5509 int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM; 5509 int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM;
5510 5510
5511 BLOCK_INPUT; 5511 block_input ();
5512 5512
5513 x_scroll_bar_set_handle (bar, bar->start, bar->end, 1); 5513 x_scroll_bar_set_handle (bar, bar->start, bar->end, 1);
5514 5514
@@ -5530,7 +5530,7 @@ x_scroll_bar_expose (struct scroll_bar *bar, XEvent *event)
5530 XSetForeground (FRAME_X_DISPLAY (f), gc, 5530 XSetForeground (FRAME_X_DISPLAY (f), gc,
5531 FRAME_FOREGROUND_PIXEL (f)); 5531 FRAME_FOREGROUND_PIXEL (f));
5532 5532
5533 UNBLOCK_INPUT; 5533 unblock_input ();
5534 5534
5535} 5535}
5536#endif /* not USE_TOOLKIT_SCROLL_BARS */ 5536#endif /* not USE_TOOLKIT_SCROLL_BARS */
@@ -5643,7 +5643,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
5643 int dummy_coord; 5643 int dummy_coord;
5644 unsigned int dummy_mask; 5644 unsigned int dummy_mask;
5645 5645
5646 BLOCK_INPUT; 5646 block_input ();
5647 5647
5648 /* Get the mouse's position relative to the scroll bar window, and 5648 /* Get the mouse's position relative to the scroll bar window, and
5649 report that. */ 5649 report that. */
@@ -5695,7 +5695,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
5695 5695
5696 *timestamp = last_mouse_movement_time; 5696 *timestamp = last_mouse_movement_time;
5697 5697
5698 UNBLOCK_INPUT; 5698 unblock_input ();
5699} 5699}
5700 5700
5701 5701
@@ -5816,7 +5816,7 @@ event_handler_gdk (GdkXEvent *gxev, GdkEvent *ev, gpointer data)
5816{ 5816{
5817 XEvent *xev = (XEvent *) gxev; 5817 XEvent *xev = (XEvent *) gxev;
5818 5818
5819 BLOCK_INPUT; 5819 block_input ();
5820 if (current_count >= 0) 5820 if (current_count >= 0)
5821 { 5821 {
5822 struct x_display_info *dpyinfo; 5822 struct x_display_info *dpyinfo;
@@ -5831,7 +5831,7 @@ event_handler_gdk (GdkXEvent *gxev, GdkEvent *ev, gpointer data)
5831 && dpyinfo 5831 && dpyinfo
5832 && x_filter_event (dpyinfo, xev)) 5832 && x_filter_event (dpyinfo, xev))
5833 { 5833 {
5834 UNBLOCK_INPUT; 5834 unblock_input ();
5835 return GDK_FILTER_REMOVE; 5835 return GDK_FILTER_REMOVE;
5836 } 5836 }
5837#endif 5837#endif
@@ -5846,7 +5846,7 @@ event_handler_gdk (GdkXEvent *gxev, GdkEvent *ev, gpointer data)
5846 else 5846 else
5847 current_finish = x_dispatch_event (xev, xev->xany.display); 5847 current_finish = x_dispatch_event (xev, xev->xany.display);
5848 5848
5849 UNBLOCK_INPUT; 5849 unblock_input ();
5850 5850
5851 if (current_finish == X_EVENT_GOTO_OUT || current_finish == X_EVENT_DROP) 5851 if (current_finish == X_EVENT_GOTO_OUT || current_finish == X_EVENT_DROP)
5852 return GDK_FILTER_REMOVE; 5852 return GDK_FILTER_REMOVE;
@@ -7041,10 +7041,10 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
7041 default: 7041 default:
7042 OTHER: 7042 OTHER:
7043#ifdef USE_X_TOOLKIT 7043#ifdef USE_X_TOOLKIT
7044 BLOCK_INPUT; 7044 block_input ();
7045 if (*finish != X_EVENT_DROP) 7045 if (*finish != X_EVENT_DROP)
7046 XtDispatchEvent (&event); 7046 XtDispatchEvent (&event);
7047 UNBLOCK_INPUT; 7047 unblock_input ();
7048#endif /* USE_X_TOOLKIT */ 7048#endif /* USE_X_TOOLKIT */
7049 break; 7049 break;
7050 } 7050 }
@@ -7109,33 +7109,20 @@ x_dispatch_event (XEvent *event, Display *display)
7109 7109
7110 7110
7111/* Read events coming from the X server. 7111/* Read events coming from the X server.
7112 This routine is called by the SIGIO handler only if SYNC_INPUT is 7112 Return as soon as there are no more events to be read.
7113 not defined.
7114 We return as soon as there are no more events to be read.
7115 7113
7116 We return the number of characters stored into the buffer, 7114 Return the number of characters stored into the buffer,
7117 thus pretending to be `read' (except the characters we store 7115 thus pretending to be `read' (except the characters we store
7118 in the keyboard buffer can be multibyte, so are not necessarily 7116 in the keyboard buffer can be multibyte, so are not necessarily
7119 C chars). 7117 C chars). */
7120
7121 EXPECTED is nonzero if the caller knows input is available. */
7122 7118
7123static int 7119static int
7124XTread_socket (struct terminal *terminal, int expected, struct input_event *hold_quit) 7120XTread_socket (struct terminal *terminal, struct input_event *hold_quit)
7125{ 7121{
7126 int count = 0; 7122 int count = 0;
7127 int event_found = 0; 7123 int event_found = 0;
7128 7124
7129 if (interrupt_input_blocked) 7125 block_input ();
7130 {
7131 interrupt_input_pending = 1;
7132 pending_signals = 1;
7133 return -1;
7134 }
7135
7136 interrupt_input_pending = 0;
7137 pending_signals = pending_atimers;
7138 BLOCK_INPUT;
7139 7126
7140 /* So people can tell when we have read the available input. */ 7127 /* So people can tell when we have read the available input. */
7141 input_signal_count++; 7128 input_signal_count++;
@@ -7228,7 +7215,7 @@ XTread_socket (struct terminal *terminal, int expected, struct input_event *hold
7228 pending_autoraise_frame = 0; 7215 pending_autoraise_frame = 0;
7229 } 7216 }
7230 7217
7231 UNBLOCK_INPUT; 7218 unblock_input ();
7232 7219
7233 return count; 7220 return count;
7234} 7221}
@@ -7664,7 +7651,7 @@ x_uncatch_errors (void)
7664{ 7651{
7665 struct x_error_message_stack *tmp; 7652 struct x_error_message_stack *tmp;
7666 7653
7667 BLOCK_INPUT; 7654 block_input ();
7668 7655
7669 /* The display may have been closed before this function is called. 7656 /* The display may have been closed before this function is called.
7670 Check if it is still open before calling XSync. */ 7657 Check if it is still open before calling XSync. */
@@ -7674,7 +7661,7 @@ x_uncatch_errors (void)
7674 tmp = x_error_message; 7661 tmp = x_error_message;
7675 x_error_message = x_error_message->prev; 7662 x_error_message = x_error_message->prev;
7676 xfree (tmp); 7663 xfree (tmp);
7677 UNBLOCK_INPUT; 7664 unblock_input ();
7678} 7665}
7679 7666
7680/* If any X protocol errors have arrived since the last call to 7667/* If any X protocol errors have arrived since the last call to
@@ -7737,26 +7724,6 @@ x_trace_wire (void)
7737#endif /* ! 0 */ 7724#endif /* ! 0 */
7738 7725
7739 7726
7740/* Handle SIGPIPE, which can happen when the connection to a server
7741 simply goes away. SIGPIPE is handled by x_connection_signal.
7742 Don't need to do anything, because the write which caused the
7743 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7744 which will do the appropriate cleanup for us. */
7745
7746static void
7747x_connection_signal (int signalnum) /* If we don't have an argument, */
7748 /* some compilers complain in signal calls. */
7749{
7750#ifdef USG
7751 /* USG systems forget handlers when they are used;
7752 must reestablish each time */
7753 struct sigaction action;
7754 emacs_sigaction_init (&action, x_connection_signal);
7755 sigaction (signalnum, &action, 0);
7756#endif /* USG */
7757}
7758
7759
7760/************************************************************************ 7727/************************************************************************
7761 Handling X errors 7728 Handling X errors
7762 ************************************************************************/ 7729 ************************************************************************/
@@ -7860,17 +7827,7 @@ For details, see etc/PROBLEMS.\n",
7860 /* NOTREACHED */ 7827 /* NOTREACHED */
7861 } 7828 }
7862 7829
7863 /* Ordinary stack unwind doesn't deal with these. */ 7830 totally_unblock_input ();
7864 {
7865 sigset_t unblocked;
7866 sigemptyset (&unblocked);
7867#ifdef USABLE_SIGIO
7868 sigaddset (&unblocked, SIGIO);
7869#endif
7870 sigaddset (&unblocked, SIGALRM);
7871 pthread_sigmask (SIG_UNBLOCK, &unblocked, 0);
7872 }
7873 TOTALLY_UNBLOCK_INPUT;
7874 7831
7875 unbind_to (idx, Qnil); 7832 unbind_to (idx, Qnil);
7876 clear_waiting_for_input (); 7833 clear_waiting_for_input ();
@@ -8009,9 +7966,9 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
8009 if (FRAME_XIC (f) 7966 if (FRAME_XIC (f)
8010 && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea))) 7967 && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
8011 { 7968 {
8012 BLOCK_INPUT; 7969 block_input ();
8013 xic_set_xfontset (f, SSDATA (fontset_ascii (fontset))); 7970 xic_set_xfontset (f, SSDATA (fontset_ascii (fontset)));
8014 UNBLOCK_INPUT; 7971 unblock_input ();
8015 } 7972 }
8016#endif 7973#endif
8017 7974
@@ -8037,7 +7994,7 @@ xim_destroy_callback (XIM xim, XPointer client_data, XPointer call_data)
8037 struct x_display_info *dpyinfo = (struct x_display_info *) client_data; 7994 struct x_display_info *dpyinfo = (struct x_display_info *) client_data;
8038 Lisp_Object frame, tail; 7995 Lisp_Object frame, tail;
8039 7996
8040 BLOCK_INPUT; 7997 block_input ();
8041 7998
8042 /* No need to call XDestroyIC.. */ 7999 /* No need to call XDestroyIC.. */
8043 FOR_EACH_FRAME (tail, frame) 8000 FOR_EACH_FRAME (tail, frame)
@@ -8053,7 +8010,7 @@ xim_destroy_callback (XIM xim, XPointer client_data, XPointer call_data)
8053 /* No need to call XCloseIM. */ 8010 /* No need to call XCloseIM. */
8054 dpyinfo->xim = NULL; 8011 dpyinfo->xim = NULL;
8055 XFree (dpyinfo->xim_styles); 8012 XFree (dpyinfo->xim_styles);
8056 UNBLOCK_INPUT; 8013 unblock_input ();
8057} 8014}
8058 8015
8059#endif /* HAVE_X11R6 */ 8016#endif /* HAVE_X11R6 */
@@ -8128,7 +8085,7 @@ xim_instantiate_callback (Display *display, XPointer client_data, XPointer call_
8128 { 8085 {
8129 Lisp_Object tail, frame; 8086 Lisp_Object tail, frame;
8130 8087
8131 BLOCK_INPUT; 8088 block_input ();
8132 FOR_EACH_FRAME (tail, frame) 8089 FOR_EACH_FRAME (tail, frame)
8133 { 8090 {
8134 struct frame *f = XFRAME (frame); 8091 struct frame *f = XFRAME (frame);
@@ -8148,7 +8105,7 @@ xim_instantiate_callback (Display *display, XPointer client_data, XPointer call_
8148 } 8105 }
8149 } 8106 }
8150 8107
8151 UNBLOCK_INPUT; 8108 unblock_input ();
8152 } 8109 }
8153} 8110}
8154 8111
@@ -8295,7 +8252,7 @@ x_set_offset (struct frame *f, register int xoff, register int yoff, int change_
8295 } 8252 }
8296 x_calc_absolute_position (f); 8253 x_calc_absolute_position (f);
8297 8254
8298 BLOCK_INPUT; 8255 block_input ();
8299 x_wm_set_size_hint (f, (long) 0, 0); 8256 x_wm_set_size_hint (f, (long) 0, 0);
8300 8257
8301 modified_left = f->left_pos; 8258 modified_left = f->left_pos;
@@ -8334,7 +8291,7 @@ x_set_offset (struct frame *f, register int xoff, register int yoff, int change_
8334 && FRAME_X_OUTPUT (f)->move_offset_top == 0)))) 8291 && FRAME_X_OUTPUT (f)->move_offset_top == 0))))
8335 x_check_expected_move (f, modified_left, modified_top); 8292 x_check_expected_move (f, modified_left, modified_top);
8336 8293
8337 UNBLOCK_INPUT; 8294 unblock_input ();
8338} 8295}
8339 8296
8340/* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED 8297/* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
@@ -8357,7 +8314,7 @@ wm_supports (struct frame *f, Atom want_atom)
8357 unsigned char *tmp_data = NULL; 8314 unsigned char *tmp_data = NULL;
8358 Atom target_type = XA_WINDOW; 8315 Atom target_type = XA_WINDOW;
8359 8316
8360 BLOCK_INPUT; 8317 block_input ();
8361 8318
8362 x_catch_errors (dpy); 8319 x_catch_errors (dpy);
8363 rc = XGetWindowProperty (dpy, target_window, 8320 rc = XGetWindowProperty (dpy, target_window,
@@ -8370,7 +8327,7 @@ wm_supports (struct frame *f, Atom want_atom)
8370 { 8327 {
8371 if (tmp_data) XFree (tmp_data); 8328 if (tmp_data) XFree (tmp_data);
8372 x_uncatch_errors (); 8329 x_uncatch_errors ();
8373 UNBLOCK_INPUT; 8330 unblock_input ();
8374 return 0; 8331 return 0;
8375 } 8332 }
8376 8333
@@ -8383,7 +8340,7 @@ wm_supports (struct frame *f, Atom want_atom)
8383 if (x_had_errors_p (dpy)) 8340 if (x_had_errors_p (dpy))
8384 { 8341 {
8385 x_uncatch_errors (); 8342 x_uncatch_errors ();
8386 UNBLOCK_INPUT; 8343 unblock_input ();
8387 return 0; 8344 return 0;
8388 } 8345 }
8389 8346
@@ -8408,7 +8365,7 @@ wm_supports (struct frame *f, Atom want_atom)
8408 { 8365 {
8409 if (tmp_data) XFree (tmp_data); 8366 if (tmp_data) XFree (tmp_data);
8410 x_uncatch_errors (); 8367 x_uncatch_errors ();
8411 UNBLOCK_INPUT; 8368 unblock_input ();
8412 return 0; 8369 return 0;
8413 } 8370 }
8414 8371
@@ -8423,7 +8380,7 @@ wm_supports (struct frame *f, Atom want_atom)
8423 rc = dpyinfo->net_supported_atoms[i] == want_atom; 8380 rc = dpyinfo->net_supported_atoms[i] == want_atom;
8424 8381
8425 x_uncatch_errors (); 8382 x_uncatch_errors ();
8426 UNBLOCK_INPUT; 8383 unblock_input ();
8427 8384
8428 return rc; 8385 return rc;
8429} 8386}
@@ -8482,7 +8439,7 @@ get_current_wm_state (struct frame *f,
8482 *sticky = 0; 8439 *sticky = 0;
8483 *size_state = FULLSCREEN_NONE; 8440 *size_state = FULLSCREEN_NONE;
8484 8441
8485 BLOCK_INPUT; 8442 block_input ();
8486 x_catch_errors (dpy); 8443 x_catch_errors (dpy);
8487 rc = XGetWindowProperty (dpy, window, dpyinfo->Xatom_net_wm_state, 8444 rc = XGetWindowProperty (dpy, window, dpyinfo->Xatom_net_wm_state,
8488 0, max_len, False, target_type, 8445 0, max_len, False, target_type,
@@ -8493,7 +8450,7 @@ get_current_wm_state (struct frame *f,
8493 { 8450 {
8494 if (tmp_data) XFree (tmp_data); 8451 if (tmp_data) XFree (tmp_data);
8495 x_uncatch_errors (); 8452 x_uncatch_errors ();
8496 UNBLOCK_INPUT; 8453 unblock_input ();
8497 return ! f->iconified; 8454 return ! f->iconified;
8498 } 8455 }
8499 8456
@@ -8528,7 +8485,7 @@ get_current_wm_state (struct frame *f,
8528 } 8485 }
8529 8486
8530 if (tmp_data) XFree (tmp_data); 8487 if (tmp_data) XFree (tmp_data);
8531 UNBLOCK_INPUT; 8488 unblock_input ();
8532 return ! is_hidden; 8489 return ! is_hidden;
8533} 8490}
8534 8491
@@ -8608,10 +8565,10 @@ XTfullscreen_hook (FRAME_PTR f)
8608{ 8565{
8609 if (f->async_visible) 8566 if (f->async_visible)
8610 { 8567 {
8611 BLOCK_INPUT; 8568 block_input ();
8612 x_check_fullscreen (f); 8569 x_check_fullscreen (f);
8613 x_sync (f); 8570 x_sync (f);
8614 UNBLOCK_INPUT; 8571 unblock_input ();
8615 } 8572 }
8616} 8573}
8617 8574
@@ -8796,10 +8753,10 @@ x_wait_for_event (struct frame *f, int eventtype)
8796 8753
8797 while (pending_event_wait.eventtype) 8754 while (pending_event_wait.eventtype)
8798 { 8755 {
8799 interrupt_input_pending = 1; 8756 pending_signals = 1;
8800 TOTALLY_UNBLOCK_INPUT; 8757 totally_unblock_input ();
8801 /* XTread_socket is called after unblock. */ 8758 /* XTread_socket is called after unblock. */
8802 BLOCK_INPUT; 8759 block_input ();
8803 interrupt_input_blocked = level; 8760 interrupt_input_blocked = level;
8804 8761
8805 FD_ZERO (&fds); 8762 FD_ZERO (&fds);
@@ -8890,7 +8847,7 @@ x_set_window_size_1 (struct frame *f, int change_gravity, int cols, int rows)
8890void 8847void
8891x_set_window_size (struct frame *f, int change_gravity, int cols, int rows) 8848x_set_window_size (struct frame *f, int change_gravity, int cols, int rows)
8892{ 8849{
8893 BLOCK_INPUT; 8850 block_input ();
8894 8851
8895 if (NILP (tip_frame) || XFRAME (tip_frame) != f) 8852 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
8896 { 8853 {
@@ -8938,7 +8895,7 @@ x_set_window_size (struct frame *f, int change_gravity, int cols, int rows)
8938 so don't try--just let the highlighting be done afresh with new size. */ 8895 so don't try--just let the highlighting be done afresh with new size. */
8939 cancel_mouse_face (f); 8896 cancel_mouse_face (f);
8940 8897
8941 UNBLOCK_INPUT; 8898 unblock_input ();
8942} 8899}
8943 8900
8944/* Mouse warping. */ 8901/* Mouse warping. */
@@ -8957,11 +8914,11 @@ x_set_mouse_position (struct frame *f, int x, int y)
8957 if (pix_y < 0) pix_y = 0; 8914 if (pix_y < 0) pix_y = 0;
8958 if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f); 8915 if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
8959 8916
8960 BLOCK_INPUT; 8917 block_input ();
8961 8918
8962 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), 8919 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
8963 0, 0, 0, 0, pix_x, pix_y); 8920 0, 0, 0, 0, pix_x, pix_y);
8964 UNBLOCK_INPUT; 8921 unblock_input ();
8965} 8922}
8966 8923
8967/* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */ 8924/* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
@@ -8969,11 +8926,11 @@ x_set_mouse_position (struct frame *f, int x, int y)
8969void 8926void
8970x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) 8927x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
8971{ 8928{
8972 BLOCK_INPUT; 8929 block_input ();
8973 8930
8974 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), 8931 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
8975 0, 0, 0, 0, pix_x, pix_y); 8932 0, 0, 0, 0, pix_x, pix_y);
8976 UNBLOCK_INPUT; 8933 unblock_input ();
8977} 8934}
8978 8935
8979/* Raise frame F. */ 8936/* Raise frame F. */
@@ -8981,12 +8938,12 @@ x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
8981void 8938void
8982x_raise_frame (struct frame *f) 8939x_raise_frame (struct frame *f)
8983{ 8940{
8984 BLOCK_INPUT; 8941 block_input ();
8985 if (f->async_visible) 8942 if (f->async_visible)
8986 XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f)); 8943 XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f));
8987 8944
8988 XFlush (FRAME_X_DISPLAY (f)); 8945 XFlush (FRAME_X_DISPLAY (f));
8989 UNBLOCK_INPUT; 8946 unblock_input ();
8990} 8947}
8991 8948
8992/* Lower frame F. */ 8949/* Lower frame F. */
@@ -8996,10 +8953,10 @@ x_lower_frame (struct frame *f)
8996{ 8953{
8997 if (f->async_visible) 8954 if (f->async_visible)
8998 { 8955 {
8999 BLOCK_INPUT; 8956 block_input ();
9000 XLowerWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f)); 8957 XLowerWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f));
9001 XFlush (FRAME_X_DISPLAY (f)); 8958 XFlush (FRAME_X_DISPLAY (f));
9002 UNBLOCK_INPUT; 8959 unblock_input ();
9003 } 8960 }
9004} 8961}
9005 8962
@@ -9108,7 +9065,7 @@ x_make_frame_visible (struct frame *f)
9108 9065
9109 retry: 9066 retry:
9110 9067
9111 BLOCK_INPUT; 9068 block_input ();
9112 9069
9113 type = x_icon_type (f); 9070 type = x_icon_type (f);
9114 if (!NILP (type)) 9071 if (!NILP (type))
@@ -9167,7 +9124,7 @@ x_make_frame_visible (struct frame *f)
9167 original_top = f->top_pos; 9124 original_top = f->top_pos;
9168 9125
9169 /* This must come after we set COUNT. */ 9126 /* This must come after we set COUNT. */
9170 UNBLOCK_INPUT; 9127 unblock_input ();
9171 9128
9172 /* We unblock here so that arriving X events are processed. */ 9129 /* We unblock here so that arriving X events are processed. */
9173 9130
@@ -9190,7 +9147,7 @@ x_make_frame_visible (struct frame *f)
9190 int x, y; 9147 int x, y;
9191 unsigned int width, height, border, depth; 9148 unsigned int width, height, border, depth;
9192 9149
9193 BLOCK_INPUT; 9150 block_input ();
9194 9151
9195 /* On some window managers (such as FVWM) moving an existing 9152 /* On some window managers (such as FVWM) moving an existing
9196 window, even to the same place, causes the window manager 9153 window, even to the same place, causes the window manager
@@ -9206,7 +9163,7 @@ x_make_frame_visible (struct frame *f)
9206 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), 9163 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
9207 original_left, original_top); 9164 original_left, original_top);
9208 9165
9209 UNBLOCK_INPUT; 9166 unblock_input ();
9210 } 9167 }
9211 9168
9212 XSETFRAME (frame, f); 9169 XSETFRAME (frame, f);
@@ -9273,7 +9230,7 @@ x_make_frame_invisible (struct frame *f)
9273 if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) 9230 if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f)
9274 FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; 9231 FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0;
9275 9232
9276 BLOCK_INPUT; 9233 block_input ();
9277 9234
9278 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim 9235 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9279 that the current position of the window is user-specified, rather than 9236 that the current position of the window is user-specified, rather than
@@ -9296,7 +9253,7 @@ x_make_frame_invisible (struct frame *f)
9296 if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window, 9253 if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window,
9297 DefaultScreen (FRAME_X_DISPLAY (f)))) 9254 DefaultScreen (FRAME_X_DISPLAY (f))))
9298 { 9255 {
9299 UNBLOCK_INPUT_RESIGNAL; 9256 unblock_input ();
9300 error ("Can't notify window manager of window withdrawal"); 9257 error ("Can't notify window manager of window withdrawal");
9301 } 9258 }
9302 } 9259 }
@@ -9313,7 +9270,7 @@ x_make_frame_invisible (struct frame *f)
9313 9270
9314 x_sync (f); 9271 x_sync (f);
9315 9272
9316 UNBLOCK_INPUT; 9273 unblock_input ();
9317} 9274}
9318 9275
9319/* Change window state from mapped to iconified. */ 9276/* Change window state from mapped to iconified. */
@@ -9333,7 +9290,7 @@ x_iconify_frame (struct frame *f)
9333 if (f->async_iconified) 9290 if (f->async_iconified)
9334 return; 9291 return;
9335 9292
9336 BLOCK_INPUT; 9293 block_input ();
9337 9294
9338 FRAME_SAMPLE_VISIBILITY (f); 9295 FRAME_SAMPLE_VISIBILITY (f);
9339 9296
@@ -9352,7 +9309,7 @@ x_iconify_frame (struct frame *f)
9352 f->visible = 1; 9309 f->visible = 1;
9353 f->async_iconified = 1; 9310 f->async_iconified = 1;
9354 f->async_visible = 0; 9311 f->async_visible = 0;
9355 UNBLOCK_INPUT; 9312 unblock_input ();
9356 return; 9313 return;
9357 } 9314 }
9358#endif 9315#endif
@@ -9372,14 +9329,14 @@ x_iconify_frame (struct frame *f)
9372 f->visible = 1; 9329 f->visible = 1;
9373 f->async_iconified = 1; 9330 f->async_iconified = 1;
9374 f->async_visible = 0; 9331 f->async_visible = 0;
9375 UNBLOCK_INPUT; 9332 unblock_input ();
9376 return; 9333 return;
9377 } 9334 }
9378 9335
9379 result = XIconifyWindow (FRAME_X_DISPLAY (f), 9336 result = XIconifyWindow (FRAME_X_DISPLAY (f),
9380 XtWindow (f->output_data.x->widget), 9337 XtWindow (f->output_data.x->widget),
9381 DefaultScreen (FRAME_X_DISPLAY (f))); 9338 DefaultScreen (FRAME_X_DISPLAY (f)));
9382 UNBLOCK_INPUT; 9339 unblock_input ();
9383 9340
9384 if (!result) 9341 if (!result)
9385 error ("Can't notify window manager of iconification"); 9342 error ("Can't notify window manager of iconification");
@@ -9388,9 +9345,9 @@ x_iconify_frame (struct frame *f)
9388 f->async_visible = 0; 9345 f->async_visible = 0;
9389 9346
9390 9347
9391 BLOCK_INPUT; 9348 block_input ();
9392 XFlush (FRAME_X_DISPLAY (f)); 9349 XFlush (FRAME_X_DISPLAY (f));
9393 UNBLOCK_INPUT; 9350 unblock_input ();
9394#else /* not USE_X_TOOLKIT */ 9351#else /* not USE_X_TOOLKIT */
9395 9352
9396 /* Make sure the X server knows where the window should be positioned, 9353 /* Make sure the X server knows where the window should be positioned,
@@ -9420,7 +9377,7 @@ x_iconify_frame (struct frame *f)
9420 SubstructureRedirectMask | SubstructureNotifyMask, 9377 SubstructureRedirectMask | SubstructureNotifyMask,
9421 &msg)) 9378 &msg))
9422 { 9379 {
9423 UNBLOCK_INPUT_RESIGNAL; 9380 unblock_input ();
9424 error ("Can't notify window manager of iconification"); 9381 error ("Can't notify window manager of iconification");
9425 } 9382 }
9426 } 9383 }
@@ -9439,7 +9396,7 @@ x_iconify_frame (struct frame *f)
9439 f->async_visible = 0; 9396 f->async_visible = 0;
9440 9397
9441 XFlush (FRAME_X_DISPLAY (f)); 9398 XFlush (FRAME_X_DISPLAY (f));
9442 UNBLOCK_INPUT; 9399 unblock_input ();
9443#endif /* not USE_X_TOOLKIT */ 9400#endif /* not USE_X_TOOLKIT */
9444} 9401}
9445 9402
@@ -9456,7 +9413,7 @@ x_free_frame_resources (struct frame *f)
9456 struct scroll_bar *b; 9413 struct scroll_bar *b;
9457#endif 9414#endif
9458 9415
9459 BLOCK_INPUT; 9416 block_input ();
9460 9417
9461 /* If a display connection is dead, don't try sending more 9418 /* If a display connection is dead, don't try sending more
9462 commands to the X server. */ 9419 commands to the X server. */
@@ -9559,7 +9516,7 @@ x_free_frame_resources (struct frame *f)
9559 hlinfo->mouse_face_mouse_frame = 0; 9516 hlinfo->mouse_face_mouse_frame = 0;
9560 } 9517 }
9561 9518
9562 UNBLOCK_INPUT; 9519 unblock_input ();
9563} 9520}
9564 9521
9565 9522
@@ -9584,13 +9541,13 @@ x_destroy_window (struct frame *f)
9584/* Set the normal size hints for the window manager, for frame F. 9541/* Set the normal size hints for the window manager, for frame F.
9585 FLAGS is the flags word to use--or 0 meaning preserve the flags 9542 FLAGS is the flags word to use--or 0 meaning preserve the flags
9586 that the window now has. 9543 that the window now has.
9587 If USER_POSITION is nonzero, we set the USPosition 9544 If USER_POSITION, set the USPosition
9588 flag (this is useful when FLAGS is 0). 9545 flag (this is useful when FLAGS is 0).
9589 The GTK version is in gtkutils.c */ 9546 The GTK version is in gtkutils.c. */
9590 9547
9591#ifndef USE_GTK 9548#ifndef USE_GTK
9592void 9549void
9593x_wm_set_size_hint (struct frame *f, long flags, int user_position) 9550x_wm_set_size_hint (struct frame *f, long flags, bool user_position)
9594{ 9551{
9595 XSizeHints size_hints; 9552 XSizeHints size_hints;
9596 Window window = FRAME_OUTER_WINDOW (f); 9553 Window window = FRAME_OUTER_WINDOW (f);
@@ -9939,7 +9896,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9939 Mouse_HLInfo *hlinfo; 9896 Mouse_HLInfo *hlinfo;
9940 ptrdiff_t lim; 9897 ptrdiff_t lim;
9941 9898
9942 BLOCK_INPUT; 9899 block_input ();
9943 9900
9944 if (!x_initialized) 9901 if (!x_initialized)
9945 { 9902 {
@@ -10000,11 +9957,13 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10000 Call before gtk_init so Gtk+ event filters comes after our. */ 9957 Call before gtk_init so Gtk+ event filters comes after our. */
10001 gdk_window_add_filter (NULL, event_handler_gdk, NULL); 9958 gdk_window_add_filter (NULL, event_handler_gdk, NULL);
10002 9959
9960 /* gtk_init does set_locale. Fix locale before and after. */
9961 fixup_locale ();
10003 gtk_init (&argc, &argv2); 9962 gtk_init (&argc, &argv2);
9963 fixup_locale ();
9964
10004 g_log_remove_handler ("GLib", id); 9965 g_log_remove_handler ("GLib", id);
10005 9966
10006 /* gtk_init does set_locale. We must fix locale after calling it. */
10007 fixup_locale ();
10008 xg_initialize (); 9967 xg_initialize ();
10009 9968
10010 dpy = DEFAULT_GDK_DISPLAY (); 9969 dpy = DEFAULT_GDK_DISPLAY ();
@@ -10071,7 +10030,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10071 /* Detect failure. */ 10030 /* Detect failure. */
10072 if (dpy == 0) 10031 if (dpy == 0)
10073 { 10032 {
10074 UNBLOCK_INPUT; 10033 unblock_input ();
10075 return 0; 10034 return 0;
10076 } 10035 }
10077 10036
@@ -10118,12 +10077,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10118 10077
10119 /* Temporarily hide the partially initialized terminal. */ 10078 /* Temporarily hide the partially initialized terminal. */
10120 terminal_list = terminal->next_terminal; 10079 terminal_list = terminal->next_terminal;
10121 UNBLOCK_INPUT; 10080 unblock_input ();
10122 kset_system_key_alist 10081 kset_system_key_alist
10123 (terminal->kboard, 10082 (terminal->kboard,
10124 call1 (Qvendor_specific_keysyms, 10083 call1 (Qvendor_specific_keysyms,
10125 vendor ? build_string (vendor) : empty_unibyte_string)); 10084 vendor ? build_string (vendor) : empty_unibyte_string));
10126 BLOCK_INPUT; 10085 block_input ();
10127 terminal->next_terminal = terminal_list; 10086 terminal->next_terminal = terminal_list;
10128 terminal_list = terminal; 10087 terminal_list = terminal;
10129 UNGCPRO; 10088 UNGCPRO;
@@ -10472,7 +10431,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10472 x_session_initialize (dpyinfo); 10431 x_session_initialize (dpyinfo);
10473#endif 10432#endif
10474 10433
10475 UNBLOCK_INPUT; 10434 unblock_input ();
10476 10435
10477 return dpyinfo; 10436 return dpyinfo;
10478} 10437}
@@ -10552,7 +10511,7 @@ x_delete_display (struct x_display_info *dpyinfo)
10552static void 10511static void
10553x_process_timeouts (struct atimer *timer) 10512x_process_timeouts (struct atimer *timer)
10554{ 10513{
10555 BLOCK_INPUT; 10514 block_input ();
10556 x_timeout_atimer_activated_flag = 0; 10515 x_timeout_atimer_activated_flag = 0;
10557 if (toolkit_scroll_bar_interaction || popup_activated ()) 10516 if (toolkit_scroll_bar_interaction || popup_activated ())
10558 { 10517 {
@@ -10561,7 +10520,7 @@ x_process_timeouts (struct atimer *timer)
10561 /* Reactivate the atimer for next time. */ 10520 /* Reactivate the atimer for next time. */
10562 x_activate_timeout_atimer (); 10521 x_activate_timeout_atimer ();
10563 } 10522 }
10564 UNBLOCK_INPUT; 10523 unblock_input ();
10565} 10524}
10566 10525
10567/* Install an asynchronous timer that processes Xt timeout events 10526/* Install an asynchronous timer that processes Xt timeout events
@@ -10575,14 +10534,14 @@ x_process_timeouts (struct atimer *timer)
10575void 10534void
10576x_activate_timeout_atimer (void) 10535x_activate_timeout_atimer (void)
10577{ 10536{
10578 BLOCK_INPUT; 10537 block_input ();
10579 if (!x_timeout_atimer_activated_flag) 10538 if (!x_timeout_atimer_activated_flag)
10580 { 10539 {
10581 EMACS_TIME interval = make_emacs_time (0, 100 * 1000 * 1000); 10540 EMACS_TIME interval = make_emacs_time (0, 100 * 1000 * 1000);
10582 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0); 10541 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0);
10583 x_timeout_atimer_activated_flag = 1; 10542 x_timeout_atimer_activated_flag = 1;
10584 } 10543 }
10585 UNBLOCK_INPUT; 10544 unblock_input ();
10586} 10545}
10587 10546
10588#endif /* USE_X_TOOLKIT */ 10547#endif /* USE_X_TOOLKIT */
@@ -10635,7 +10594,7 @@ x_delete_terminal (struct terminal *terminal)
10635 if (!terminal->name) 10594 if (!terminal->name)
10636 return; 10595 return;
10637 10596
10638 BLOCK_INPUT; 10597 block_input ();
10639#ifdef HAVE_X_I18N 10598#ifdef HAVE_X_I18N
10640 /* We must close our connection to the XIM server before closing the 10599 /* We must close our connection to the XIM server before closing the
10641 X display. */ 10600 X display. */
@@ -10690,7 +10649,7 @@ x_delete_terminal (struct terminal *terminal)
10690 /* Mark as dead. */ 10649 /* Mark as dead. */
10691 dpyinfo->display = NULL; 10650 dpyinfo->display = NULL;
10692 x_delete_display (dpyinfo); 10651 x_delete_display (dpyinfo);
10693 UNBLOCK_INPUT; 10652 unblock_input ();
10694} 10653}
10695 10654
10696/* Create a struct terminal, initialize it with the X11 specific 10655/* Create a struct terminal, initialize it with the X11 specific
@@ -10747,8 +10706,6 @@ x_create_terminal (struct x_display_info *dpyinfo)
10747void 10706void
10748x_initialize (void) 10707x_initialize (void)
10749{ 10708{
10750 struct sigaction action;
10751
10752 baud_rate = 19200; 10709 baud_rate = 19200;
10753 10710
10754 x_noop_count = 0; 10711 x_noop_count = 0;
@@ -10794,9 +10751,6 @@ x_initialize (void)
10794 original error handler. */ 10751 original error handler. */
10795 XSetErrorHandler (x_error_handler); 10752 XSetErrorHandler (x_error_handler);
10796 XSetIOErrorHandler (x_io_error_quitter); 10753 XSetIOErrorHandler (x_io_error_quitter);
10797
10798 emacs_sigaction_init (&action, x_connection_signal);
10799 sigaction (SIGPIPE, &action, 0);
10800} 10754}
10801 10755
10802 10756
diff --git a/src/xterm.h b/src/xterm.h
index 8b8ae2a12f5..4bc8f9813ed 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -962,11 +962,12 @@ extern XtAppContext Xt_app_con;
962extern void x_activate_timeout_atimer (void); 962extern void x_activate_timeout_atimer (void);
963#endif 963#endif
964#ifdef USE_LUCID 964#ifdef USE_LUCID
965extern int x_alloc_lighter_color_for_widget (Widget, Display *, Colormap, 965extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
966 unsigned long *, 966 unsigned long *,
967 double, int); 967 double, int);
968#endif 968#endif
969extern int x_alloc_nearest_color (struct frame *, Colormap, XColor *); 969extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
970extern void x_query_color (struct frame *f, XColor *);
970extern void x_clear_area (Display *, Window, int, int, int, int, int); 971extern void x_clear_area (Display *, Window, int, int, int, int, int);
971#if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK 972#if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
972extern void x_mouse_leave (struct x_display_info *); 973extern void x_mouse_leave (struct x_display_info *);
@@ -1033,7 +1034,7 @@ extern void xic_set_statusarea (struct frame *);
1033extern void xic_set_xfontset (struct frame *, const char *); 1034extern void xic_set_xfontset (struct frame *, const char *);
1034extern int x_pixel_width (struct frame *); 1035extern int x_pixel_width (struct frame *);
1035extern int x_pixel_height (struct frame *); 1036extern int x_pixel_height (struct frame *);
1036extern int x_defined_color (struct frame *, const char *, XColor *, int); 1037extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1037#ifdef HAVE_X_I18N 1038#ifdef HAVE_X_I18N
1038extern void free_frame_xic (struct frame *); 1039extern void free_frame_xic (struct frame *);
1039# if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT 1040# if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT