aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2012-09-22 11:26:05 +0900
committerKenichi Handa2012-09-22 11:26:05 +0900
commitfa42927fd0ed023ec95a5475ce342429fd8a348d (patch)
tree5f37f88faa47b36dc85d19aedf89f483dc458358 /src
parent3cccbd87267735609a21df50b80b3aad07004555 (diff)
parent58f3a196fcd6c2f8b65e6b6cf1bc377d1a6287aa (diff)
downloademacs-fa42927fd0ed023ec95a5475ce342429fd8a348d.tar.gz
emacs-fa42927fd0ed023ec95a5475ce342429fd8a348d.zip
merge trunk
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog165
-rw-r--r--src/Makefile.in9
-rw-r--r--src/alloc.c448
-rw-r--r--src/atimer.c9
-rw-r--r--src/bytecode.c3
-rw-r--r--src/callproc.c25
-rw-r--r--src/conf_post.h1
-rw-r--r--src/dispnew.c2
-rw-r--r--src/emacs.c14
-rw-r--r--src/eval.c23
-rw-r--r--src/fileio.c7
-rw-r--r--src/font.c2
-rw-r--r--src/frame.c97
-rw-r--r--src/image.c8
-rw-r--r--src/intervals.c3
-rw-r--r--src/keyboard.c84
-rw-r--r--src/keyboard.h5
-rw-r--r--src/lisp.h13
-rw-r--r--src/ns.mk39
-rw-r--r--src/nsfns.m13
-rw-r--r--src/nsmenu.m5
-rw-r--r--src/nsterm.m14
-rw-r--r--src/process.c41
-rw-r--r--src/ralloc.c12
-rw-r--r--src/regex.c6
-rw-r--r--src/search.c24
-rw-r--r--src/sysdep.c18
-rw-r--r--src/syssignal.h4
-rw-r--r--src/termhooks.h15
-rw-r--r--src/unexmacosx.c21
-rw-r--r--src/w32gui.h3
-rw-r--r--src/w32inevt.c11
-rw-r--r--src/w32inevt.h2
-rw-r--r--src/w32term.c5
-rw-r--r--src/w32xfns.c132
-rw-r--r--src/window.c6
-rw-r--r--src/window.h15
-rw-r--r--src/xdisp.c49
-rw-r--r--src/xterm.c24
39 files changed, 472 insertions, 905 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8a05f19985f..0d441761ce5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -3,6 +3,171 @@
3 * composite.c (composition_reseat_it): Handle the case that a 3 * composite.c (composition_reseat_it): Handle the case that a
4 grapheme cluster is not covered by a single font (Bug#12352). 4 grapheme cluster is not covered by a single font (Bug#12352).
5 5
62012-09-21 Chong Yidong <cyd@gnu.org>
7
8 * image.c (define_image_type): Avoid adding duplicate types to
9 image_types (Bug#12463). Suggested by Jörg Walter.
10
112012-09-21 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
12
13 * unexmacosx.c: Define LC_DATA_IN_CODE if not defined.
14 (print_load_command_name): Add case LC_DATA_IN_CODE.
15 (dump_it) [LC_DATA_IN_CODE]: Call copy_linkedit_data.
16
172012-09-21 Glenn Morris <rgm@gnu.org>
18
19 * eval.c (Frun_hook_with_args_until_success)
20 (Frun_hook_with_args_until_failure): Doc fixes. (Bug#12393)
21
222012-09-21 Andreas Schwab <schwab@linux-m68k.org>
23
24 * fileio.c (Ffile_selinux_context): Only call freecon when
25 lgetfilecon succeeded.
26 (Fset_file_selinux_context): Likewise. (Bug#12444)
27
282012-09-21 Eli Zaretskii <eliz@gnu.org>
29
30 * xdisp.c (try_window_reusing_current_matrix): Under bidi
31 reordering, locate the cursor by calling set_cursor_from_row; if
32 that fails, clear the desired glyph matrix before returning a
33 failure indication to the caller. Fixes leaving garbled display
34 when fast scrolling with a down-key. (Bug#12403)
35 (compute_stop_pos_backwards): Fix a typo that caused crashes while
36 scrolling through multibyte text.
37
382012-09-20 Stefan Monnier <monnier@iro.umontreal.ca>
39
40 * alloc.c (mark_object) <PVEC_WINDOW>: Mark prev/next_buffers *after*
41 calling mark_vectorlike since that's the one that marks the window.
42 (mark_discard_killed_buffers): Mark the final cdr.
43 * window.h (struct window): Move prev/next_buffers to the
44 non-standard fields.
45 * window.c (make_window): Initialize prev/next_buffers manually.
46
472012-09-20 Paul Eggert <eggert@cs.ucla.edu>
48
49 Omit unused arg EXPECTED from socket hooks.
50 * keyboard.c (gobble_input, read_avail_input, tty_read_avail_input):
51 * nsterm.m (ns_term_init):
52 * termhooks.h (struct terminal.read_socket_hook):
53 * w32inevt.c (w32_console_read_socket):
54 * w32term.c (w32_read_socket):
55 * xterm.c (XTread_socket):
56 Omit unused arg EXPECTED. All callers changed.
57 (store_user_signal_events): Return void, not int, since callers no
58 longer care about the return value. All uses changed.
59
602012-09-20 Juanma Barranquero <lekktu@gmail.com>
61
62 * w32gui.h (XParseGeometry): Do not declare.
63
642012-09-19 Paul Eggert <eggert@cs.ucla.edu>
65
66 * w32inevt.c (w32_console_read_socket): Return -1 on failure, not 0.
67 Ignore 'expected'. See Eli Zaretskii in
68 <http://bugs.gnu.org/12471#8> (last line).
69
70 * frame.c (read_integer): Remove. All uses replaced by strtol/strtoul.
71 (XParseGeometry): Now static. Substitute extremal values for
72 values that are out of range.
73
742012-09-19 Jan Djärv <jan.h.d@swipnet.se>
75
76 * w32xfns.c (read_integer, XParseGeometry): Move to frame.c.
77
78 * nsfns.m (XParseGeometry): Remove.
79 (Fx_create_frame): Call x_set_offset to correctly interpret
80 top_pos in geometry.
81
82 * frame.c (read_integer, XParseGeometry): Moved from w32xfns.c.
83 (Fx_parse_geometry): If there is a space in string, call
84 Qns_parse_geometry, otherwise do as on other terms (Bug#12368).
85
862012-09-17 Eli Zaretskii <eliz@gnu.org>
87
88 * search.c (scan_buffer): Use character positions in calls to
89 region_cache_forward and region_cache_backward, not byte
90 positions. (Bug#12196)
91
92 * w32term.c (w32_read_socket): Set pending_signals to 1, like
93 xterm.c does. Reported by Daniel Colascione <dancol@dancol.org>.
94
95 * ralloc.c (r_alloc_init) [!SYSTEM_MALLOC]: Initialize
96 __malloc_extra_blocks to 32 instead of 64, like alloc.c did in
97 emacs_blocked_malloc, now deleted.
98
992012-09-17 Paul Eggert <eggert@cs.ucla.edu>
100
101 Remove no-longer-needed Solaris 2.4 vfork bug workaround.
102 The workaround was for improving performance on Solaris 2.4, but
103 is getting in the way now. Emacs will still work if someone is
104 still running Solaris 2.4 in a museum somewhere; Sun dropped
105 support for Solaris 2.4 in 2003.
106 * callproc.c (Fcall_process) [HAVE_WORKING_VFORK]:
107 * process.c (create_process) [HAVE_WORKING_VFORK]:
108 Omit now-unnecessary workaround for the Solaris 2.4 vfork bug,
109 since Emacs no longer uses vfork on that platform.
110
1112012-09-17 Glenn Morris <rgm@gnu.org>
112
113 * emacs.c: Use COPYRIGHT.
114
1152012-09-16 Paul Eggert <eggert@cs.ucla.edu>
116
117 Remove configure's --without-sync-input option (Bug#12450).
118 When auditing signal-handling in preparation for cleaning it up,
119 I found that SYNC_INPUT has race conditions and would be a real
120 pain to fix. Since it's an undocumented and deprecated
121 configure-time option, now seems like a good time to remove it.
122 Also see <http://bugs.gnu.org/11080#16>.
123 * alloc.c (_bytes_used, __malloc_extra_blocks, _malloc_internal)
124 (_free_internal) [!DOUG_LEA_MALLOC]: Remove decls.
125 (alloc_mutex) [!SYSTEM_MALLOC && !SYNC_INPUT && HAVE_PTHREAD]:
126 (malloc_hysteresis):
127 (check_depth) [XMALLOC_OVERRUN_CHECK]:
128 (MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT):
129 (__malloc_hook, __realloc_hook, __free_hook, BYTES_USED)
130 (dont_register_blocks, bytes_used_when_reconsidered)
131 (bytes_used_when_full, emacs_blocked_free, emacs_blocked_malloc)
132 (emacs_blocked_realloc, reset_malloc_hooks, uninterrupt_malloc):
133 [!SYSTEM_MALLOC && !SYNC_INPUT]:
134 Remove. All uses removed.
135 (MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): Use a different
136 implementation, one that depends on whether the new macro
137 XMALLOC_BLOCK_INPUT_CHECK is defined, not on whether SYNC_INPUT
138 is defined.
139 * atimer.c (run_timers, handle_alarm_signal):
140 * keyboard.c (pending_signal, poll_for_input_1, poll_for_input)
141 (handle_async_input, process_pending_signals)
142 (handle_input_available_signal, init_keyboard):
143 * nsterm.m (ns_read_socket):
144 * process.c (wait_reading_process_output):
145 * regex.c (immediate_quit, IMMEDIATE_QUIT_CHECK):
146 * sysdep.c (emacs_sigaction_init) [SA_RESTART]:
147 (emacs_write):
148 * xterm.c (XTread_socket):
149 Assume SYNC_INPUT.
150 * conf_post.h (SA_RESTART) [IRIX6_5]: Do not #undef.
151 * eval.c (handling_signal): Remove. All uses removed.
152 * lisp.h (ELSE_PENDING_SIGNALS): Remove.
153 All uses replaced with the SYNC_INPUT version.
154 (reset_malloc_hooks, uninterrupt_malloc, handling_signal):
155 Remove decls.
156 * sysdep.c, syssignal.h (main_thread) [FORWARD_SIGNAL_TO_MAIN_THREAD]:
157 Now static.
158
159 * font.c (Ffont_shape_gstring): Remove unused local.
160
1612012-09-16 Glenn Morris <rgm@gnu.org>
162
163 * Makefile.in (clean): No longer run nextstep's clean.
164
165 * Makefile.in (ns_appdir, ns_appbindir, ns_appsrc): Remove variables.
166 (ns_frag): Remove.
167 (ns-app): Move here from ns.mk, and simplify.
168 (clean): Simplify nextstep entry.
169 * ns.mk: Remove file.
170
62012-09-17 Kenichi Handa <handa@gnu.org> 1712012-09-17 Kenichi Handa <handa@gnu.org>
7 172
8 * font.c (Ffont_shape_gstring): Fix previous change; GLYPHs may 173 * font.c (Ffont_shape_gstring): Fix previous change; GLYPHs may
diff --git a/src/Makefile.in b/src/Makefile.in
index fe4cff5d8cc..37da170edbd 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -255,9 +255,6 @@ MSDOS_OBJ =
255## w16select.o termcap.o if MSDOS && HAVE_X_WINDOWS. 255## w16select.o termcap.o if MSDOS && HAVE_X_WINDOWS.
256MSDOS_X_OBJ = 256MSDOS_X_OBJ =
257 257
258ns_appdir=@ns_appdir@
259ns_appbindir=@ns_appbindir@
260ns_appsrc=@ns_appsrc@
261NS_OBJ=@NS_OBJ@ 258NS_OBJ=@NS_OBJ@
262## nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o if HAVE_NS. 259## nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o if HAVE_NS.
263NS_OBJC_OBJ=@NS_OBJC_OBJ@ 260NS_OBJC_OBJ=@NS_OBJC_OBJ@
@@ -501,8 +498,9 @@ $(OLDXMENU): $(OLDXMENU_TARGET)
501doc.o: buildobj.h 498doc.o: buildobj.h
502 499
503 500
504## If HAVE_NS, some ns-specific rules (for OTHER_FILES) are inserted here. 501ns-app: emacs$(EXEEXT)
505@ns_frag@ 502 cd ../nextstep && $(MAKE) $(MFLAGS) all
503
506 504
507.PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean 505.PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
508.PHONY: versionclean extraclean frc 506.PHONY: versionclean extraclean frc
@@ -516,7 +514,6 @@ mostlyclean:
516clean: mostlyclean 514clean: mostlyclean
517 rm -f emacs-*.*.*$(EXEEXT) emacs$(EXEEXT) 515 rm -f emacs-*.*.*$(EXEEXT) emacs$(EXEEXT)
518 -rm -rf $(DEPDIR) 516 -rm -rf $(DEPDIR)
519 test "X$(ns_appdir)" = "X" || rm -rf $(ns_appdir)
520 517
521## bootstrap-clean is used to clean up just before a bootstrap. 518## bootstrap-clean is used to clean up just before a bootstrap.
522## It should remove all files generated during a compilation/bootstrap, 519## It should remove all files generated during a compilation/bootstrap,
diff --git a/src/alloc.c b/src/alloc.c
index 0bfbb0c88b1..02ba2f5f9e3 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -85,68 +85,8 @@ extern void *sbrk ();
85 85
86#define MMAP_MAX_AREAS 100000000 86#define MMAP_MAX_AREAS 100000000
87 87
88#else /* not DOUG_LEA_MALLOC */
89
90/* The following come from gmalloc.c. */
91
92extern size_t _bytes_used;
93extern size_t __malloc_extra_blocks;
94extern void *_malloc_internal (size_t);
95extern void _free_internal (void *);
96
97#endif /* not DOUG_LEA_MALLOC */ 88#endif /* not DOUG_LEA_MALLOC */
98 89
99#if ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT
100#ifdef HAVE_PTHREAD
101
102# include "syssignal.h"
103
104/* When GTK uses the file chooser dialog, different backends can be loaded
105 dynamically. One such a backend is the Gnome VFS backend that gets loaded
106 if you run Gnome. That backend creates several threads and also allocates
107 memory with malloc.
108
109 Also, gconf and gsettings may create several threads.
110
111 If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_*
112 functions below are called from malloc, there is a chance that one
113 of these threads preempts the Emacs main thread and the hook variables
114 end up in an inconsistent state. So we have a mutex to prevent that (note
115 that the backend handles concurrent access to malloc within its own threads
116 but Emacs code running in the main thread is not included in that control).
117
118 When UNBLOCK_INPUT is called, reinvoke_input_signal may be called. If this
119 happens in one of the backend threads we will have two threads that tries
120 to run Emacs code at once, and the code is not prepared for that.
121 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */
122
123static pthread_mutex_t alloc_mutex;
124
125#define BLOCK_INPUT_ALLOC \
126 do \
127 { \
128 if (pthread_equal (pthread_self (), main_thread)) \
129 BLOCK_INPUT; \
130 pthread_mutex_lock (&alloc_mutex); \
131 } \
132 while (0)
133#define UNBLOCK_INPUT_ALLOC \
134 do \
135 { \
136 pthread_mutex_unlock (&alloc_mutex); \
137 if (pthread_equal (pthread_self (), main_thread)) \
138 UNBLOCK_INPUT; \
139 } \
140 while (0)
141
142#else /* ! defined HAVE_PTHREAD */
143
144#define BLOCK_INPUT_ALLOC BLOCK_INPUT
145#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT
146
147#endif /* ! defined HAVE_PTHREAD */
148#endif /* ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT */
149
150/* Mark, unmark, query mark bit of a Lisp string. S must be a pointer 90/* Mark, unmark, query mark bit of a Lisp string. S must be a pointer
151 to a struct Lisp_String. */ 91 to a struct Lisp_String. */
152 92
@@ -205,10 +145,6 @@ static char *spare_memory[7];
205 145
206#define SPARE_MEMORY (1 << 14) 146#define SPARE_MEMORY (1 << 14)
207 147
208/* Number of extra blocks malloc should get when it needs more core. */
209
210static int malloc_hysteresis;
211
212/* Initialize it to a nonzero value to force it into data space 148/* Initialize it to a nonzero value to force it into data space
213 (rather than bss space). That way unexec will remap it into text 149 (rather than bss space). That way unexec will remap it into text
214 space (pure), on some systems. We have not implemented the 150 space (pure), on some systems. We have not implemented the
@@ -413,12 +349,12 @@ static void mark_memory (void *, void *);
413static void mem_init (void); 349static void mem_init (void);
414static struct mem_node *mem_insert (void *, void *, enum mem_type); 350static struct mem_node *mem_insert (void *, void *, enum mem_type);
415static void mem_insert_fixup (struct mem_node *); 351static void mem_insert_fixup (struct mem_node *);
416#endif
417static void mem_rotate_left (struct mem_node *); 352static void mem_rotate_left (struct mem_node *);
418static void mem_rotate_right (struct mem_node *); 353static void mem_rotate_right (struct mem_node *);
419static void mem_delete (struct mem_node *); 354static void mem_delete (struct mem_node *);
420static void mem_delete_fixup (struct mem_node *); 355static void mem_delete_fixup (struct mem_node *);
421static inline struct mem_node *mem_find (void *); 356static inline struct mem_node *mem_find (void *);
357#endif
422 358
423 359
424#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS 360#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS
@@ -587,39 +523,17 @@ xmalloc_get_size (unsigned char *ptr)
587} 523}
588 524
589 525
590/* The call depth in overrun_check functions. For example, this might happen:
591 xmalloc()
592 overrun_check_malloc()
593 -> malloc -> (via hook)_-> emacs_blocked_malloc
594 -> overrun_check_malloc
595 call malloc (hooks are NULL, so real malloc is called).
596 malloc returns 10000.
597 add overhead, return 10016.
598 <- (back in overrun_check_malloc)
599 add overhead again, return 10032
600 xmalloc returns 10032.
601
602 (time passes).
603
604 xfree(10032)
605 overrun_check_free(10032)
606 decrease overhead
607 free(10016) <- crash, because 10000 is the original pointer. */
608
609static ptrdiff_t check_depth;
610
611/* Like malloc, but wraps allocated block with header and trailer. */ 526/* Like malloc, but wraps allocated block with header and trailer. */
612 527
613static void * 528static void *
614overrun_check_malloc (size_t size) 529overrun_check_malloc (size_t size)
615{ 530{
616 register unsigned char *val; 531 register unsigned char *val;
617 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; 532 if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size)
618 if (SIZE_MAX - overhead < size)
619 emacs_abort (); 533 emacs_abort ();
620 534
621 val = malloc (size + overhead); 535 val = malloc (size + XMALLOC_OVERRUN_CHECK_OVERHEAD);
622 if (val && check_depth == 1) 536 if (val)
623 { 537 {
624 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); 538 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE);
625 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; 539 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE;
@@ -627,7 +541,6 @@ overrun_check_malloc (size_t size)
627 memcpy (val + size, xmalloc_overrun_check_trailer, 541 memcpy (val + size, xmalloc_overrun_check_trailer,
628 XMALLOC_OVERRUN_CHECK_SIZE); 542 XMALLOC_OVERRUN_CHECK_SIZE);
629 } 543 }
630 --check_depth;
631 return val; 544 return val;
632} 545}
633 546
@@ -639,12 +552,10 @@ static void *
639overrun_check_realloc (void *block, size_t size) 552overrun_check_realloc (void *block, size_t size)
640{ 553{
641 register unsigned char *val = (unsigned char *) block; 554 register unsigned char *val = (unsigned char *) block;
642 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; 555 if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size)
643 if (SIZE_MAX - overhead < size)
644 emacs_abort (); 556 emacs_abort ();
645 557
646 if (val 558 if (val
647 && check_depth == 1
648 && memcmp (xmalloc_overrun_check_header, 559 && memcmp (xmalloc_overrun_check_header,
649 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, 560 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE,
650 XMALLOC_OVERRUN_CHECK_SIZE) == 0) 561 XMALLOC_OVERRUN_CHECK_SIZE) == 0)
@@ -658,9 +569,9 @@ overrun_check_realloc (void *block, size_t size)
658 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE); 569 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE);
659 } 570 }
660 571
661 val = realloc (val, size + overhead); 572 val = realloc (val, size + XMALLOC_OVERRUN_CHECK_OVERHEAD);
662 573
663 if (val && check_depth == 1) 574 if (val)
664 { 575 {
665 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); 576 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE);
666 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; 577 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE;
@@ -668,7 +579,6 @@ overrun_check_realloc (void *block, size_t size)
668 memcpy (val + size, xmalloc_overrun_check_trailer, 579 memcpy (val + size, xmalloc_overrun_check_trailer,
669 XMALLOC_OVERRUN_CHECK_SIZE); 580 XMALLOC_OVERRUN_CHECK_SIZE);
670 } 581 }
671 --check_depth;
672 return val; 582 return val;
673} 583}
674 584
@@ -679,9 +589,7 @@ overrun_check_free (void *block)
679{ 589{
680 unsigned char *val = (unsigned char *) block; 590 unsigned char *val = (unsigned char *) block;
681 591
682 ++check_depth;
683 if (val 592 if (val
684 && check_depth == 1
685 && memcmp (xmalloc_overrun_check_header, 593 && memcmp (xmalloc_overrun_check_header,
686 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, 594 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE,
687 XMALLOC_OVERRUN_CHECK_SIZE) == 0) 595 XMALLOC_OVERRUN_CHECK_SIZE) == 0)
@@ -701,7 +609,6 @@ overrun_check_free (void *block)
701 } 609 }
702 610
703 free (val); 611 free (val);
704 --check_depth;
705} 612}
706 613
707#undef malloc 614#undef malloc
@@ -712,14 +619,33 @@ overrun_check_free (void *block)
712#define free overrun_check_free 619#define free overrun_check_free
713#endif 620#endif
714 621
715#ifdef SYNC_INPUT 622/* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol
716/* When using SYNC_INPUT, we don't call malloc from a signal handler, so 623 BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger.
717 there's no need to block input around malloc. */ 624 If that variable is set, block input while in one of Emacs's memory
718#define MALLOC_BLOCK_INPUT ((void)0) 625 allocation functions. There should be no need for this debugging
719#define MALLOC_UNBLOCK_INPUT ((void)0) 626 option, since signal handlers do not allocate memory, but Emacs
627 formerly allocated memory in signal handlers and this compile-time
628 option remains as a way to help debug the issue should it rear its
629 ugly head again. */
630#ifdef XMALLOC_BLOCK_INPUT_CHECK
631bool block_input_in_memory_allocators EXTERNALLY_VISIBLE;
632static void
633malloc_block_input (void)
634{
635 if (block_input_in_memory_allocators)
636 BLOCK_INPUT;
637}
638static void
639malloc_unblock_input (void)
640{
641 if (block_input_in_memory_allocators)
642 UNBLOCK_INPUT;
643}
644# define MALLOC_BLOCK_INPUT malloc_block_input ()
645# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
720#else 646#else
721#define MALLOC_BLOCK_INPUT BLOCK_INPUT 647# define MALLOC_BLOCK_INPUT ((void) 0)
722#define MALLOC_UNBLOCK_INPUT UNBLOCK_INPUT 648# define MALLOC_UNBLOCK_INPUT ((void) 0)
723#endif 649#endif
724 650
725/* Like malloc but check for no memory and block interrupt input.. */ 651/* Like malloc but check for no memory and block interrupt input.. */
@@ -788,8 +714,7 @@ xfree (void *block)
788 free (block); 714 free (block);
789 MALLOC_UNBLOCK_INPUT; 715 MALLOC_UNBLOCK_INPUT;
790 /* We don't call refill_memory_reserve here 716 /* We don't call refill_memory_reserve here
791 because that duplicates doing so in emacs_blocked_free 717 because in practice the call in r_alloc_free seems to suffice. */
792 and the criterion should go there. */
793} 718}
794 719
795 720
@@ -1216,256 +1141,6 @@ lisp_align_free (void *block)
1216} 1141}
1217 1142
1218 1143
1219#ifndef SYSTEM_MALLOC
1220
1221/* Arranging to disable input signals while we're in malloc.
1222
1223 This only works with GNU malloc. To help out systems which can't
1224 use GNU malloc, all the calls to malloc, realloc, and free
1225 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT
1226 pair; unfortunately, we have no idea what C library functions
1227 might call malloc, so we can't really protect them unless you're
1228 using GNU malloc. Fortunately, most of the major operating systems
1229 can use GNU malloc. */
1230
1231#ifndef SYNC_INPUT
1232/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
1233 there's no need to block input around malloc. */
1234
1235#ifndef DOUG_LEA_MALLOC
1236extern void * (*__malloc_hook) (size_t, const void *);
1237extern void * (*__realloc_hook) (void *, size_t, const void *);
1238extern void (*__free_hook) (void *, const void *);
1239/* Else declared in malloc.h, perhaps with an extra arg. */
1240#endif /* DOUG_LEA_MALLOC */
1241static void * (*old_malloc_hook) (size_t, const void *);
1242static void * (*old_realloc_hook) (void *, size_t, const void*);
1243static void (*old_free_hook) (void*, const void*);
1244
1245#ifdef DOUG_LEA_MALLOC
1246# define BYTES_USED (mallinfo ().uordblks)
1247#else
1248# define BYTES_USED _bytes_used
1249#endif
1250
1251#ifdef GC_MALLOC_CHECK
1252static bool dont_register_blocks;
1253#endif
1254
1255static size_t bytes_used_when_reconsidered;
1256
1257/* Value of _bytes_used, when spare_memory was freed. */
1258
1259static size_t bytes_used_when_full;
1260
1261/* This function is used as the hook for free to call. */
1262
1263static void
1264emacs_blocked_free (void *ptr, const void *ptr2)
1265{
1266 BLOCK_INPUT_ALLOC;
1267
1268#ifdef GC_MALLOC_CHECK
1269 if (ptr)
1270 {
1271 struct mem_node *m;
1272
1273 m = mem_find (ptr);
1274 if (m == MEM_NIL || m->start != ptr)
1275 {
1276 fprintf (stderr,
1277 "Freeing `%p' which wasn't allocated with malloc\n", ptr);
1278 emacs_abort ();
1279 }
1280 else
1281 {
1282 /* fprintf (stderr, "free %p...%p (%p)\n", m->start, m->end, ptr); */
1283 mem_delete (m);
1284 }
1285 }
1286#endif /* GC_MALLOC_CHECK */
1287
1288 __free_hook = old_free_hook;
1289 free (ptr);
1290
1291 /* If we released our reserve (due to running out of memory),
1292 and we have a fair amount free once again,
1293 try to set aside another reserve in case we run out once more. */
1294 if (! NILP (Vmemory_full)
1295 /* Verify there is enough space that even with the malloc
1296 hysteresis this call won't run out again.
1297 The code here is correct as long as SPARE_MEMORY
1298 is substantially larger than the block size malloc uses. */
1299 && (bytes_used_when_full
1300 > ((bytes_used_when_reconsidered = BYTES_USED)
1301 + max (malloc_hysteresis, 4) * SPARE_MEMORY)))
1302 refill_memory_reserve ();
1303
1304 __free_hook = emacs_blocked_free;
1305 UNBLOCK_INPUT_ALLOC;
1306}
1307
1308
1309/* This function is the malloc hook that Emacs uses. */
1310
1311static void *
1312emacs_blocked_malloc (size_t size, const void *ptr)
1313{
1314 void *value;
1315
1316 BLOCK_INPUT_ALLOC;
1317 __malloc_hook = old_malloc_hook;
1318#ifdef DOUG_LEA_MALLOC
1319 /* Segfaults on my system. --lorentey */
1320 /* mallopt (M_TOP_PAD, malloc_hysteresis * 4096); */
1321#else
1322 __malloc_extra_blocks = malloc_hysteresis;
1323#endif
1324
1325 value = malloc (size);
1326
1327#ifdef GC_MALLOC_CHECK
1328 {
1329 struct mem_node *m = mem_find (value);
1330 if (m != MEM_NIL)
1331 {
1332 fprintf (stderr, "Malloc returned %p which is already in use\n",
1333 value);
1334 fprintf (stderr, "Region in use is %p...%p, %td bytes, type %d\n",
1335 m->start, m->end, (char *) m->end - (char *) m->start,
1336 m->type);
1337 emacs_abort ();
1338 }
1339
1340 if (!dont_register_blocks)
1341 {
1342 mem_insert (value, (char *) value + max (1, size), allocated_mem_type);
1343 allocated_mem_type = MEM_TYPE_NON_LISP;
1344 }
1345 }
1346#endif /* GC_MALLOC_CHECK */
1347
1348 __malloc_hook = emacs_blocked_malloc;
1349 UNBLOCK_INPUT_ALLOC;
1350
1351 /* fprintf (stderr, "%p malloc\n", value); */
1352 return value;
1353}
1354
1355
1356/* This function is the realloc hook that Emacs uses. */
1357
1358static void *
1359emacs_blocked_realloc (void *ptr, size_t size, const void *ptr2)
1360{
1361 void *value;
1362
1363 BLOCK_INPUT_ALLOC;
1364 __realloc_hook = old_realloc_hook;
1365
1366#ifdef GC_MALLOC_CHECK
1367 if (ptr)
1368 {
1369 struct mem_node *m = mem_find (ptr);
1370 if (m == MEM_NIL || m->start != ptr)
1371 {
1372 fprintf (stderr,
1373 "Realloc of %p which wasn't allocated with malloc\n",
1374 ptr);
1375 emacs_abort ();
1376 }
1377
1378 mem_delete (m);
1379 }
1380
1381 /* fprintf (stderr, "%p -> realloc\n", ptr); */
1382
1383 /* Prevent malloc from registering blocks. */
1384 dont_register_blocks = 1;
1385#endif /* GC_MALLOC_CHECK */
1386
1387 value = realloc (ptr, size);
1388
1389#ifdef GC_MALLOC_CHECK
1390 dont_register_blocks = 0;
1391
1392 {
1393 struct mem_node *m = mem_find (value);
1394 if (m != MEM_NIL)
1395 {
1396 fprintf (stderr, "Realloc returns memory that is already in use\n");
1397 emacs_abort ();
1398 }
1399
1400 /* Can't handle zero size regions in the red-black tree. */
1401 mem_insert (value, (char *) value + max (size, 1), MEM_TYPE_NON_LISP);
1402 }
1403
1404 /* fprintf (stderr, "%p <- realloc\n", value); */
1405#endif /* GC_MALLOC_CHECK */
1406
1407 __realloc_hook = emacs_blocked_realloc;
1408 UNBLOCK_INPUT_ALLOC;
1409
1410 return value;
1411}
1412
1413
1414#ifdef HAVE_PTHREAD
1415/* Called from Fdump_emacs so that when the dumped Emacs starts, it has a
1416 normal malloc. Some thread implementations need this as they call
1417 malloc before main. The pthread_self call in BLOCK_INPUT_ALLOC then
1418 calls malloc because it is the first call, and we have an endless loop. */
1419
1420void
1421reset_malloc_hooks (void)
1422{
1423 __free_hook = old_free_hook;
1424 __malloc_hook = old_malloc_hook;
1425 __realloc_hook = old_realloc_hook;
1426}
1427#endif /* HAVE_PTHREAD */
1428
1429
1430/* Called from main to set up malloc to use our hooks. */
1431
1432void
1433uninterrupt_malloc (void)
1434{
1435#ifdef HAVE_PTHREAD
1436#ifdef DOUG_LEA_MALLOC
1437 pthread_mutexattr_t attr;
1438
1439 /* GLIBC has a faster way to do this, but let's keep it portable.
1440 This is according to the Single UNIX Specification. */
1441 pthread_mutexattr_init (&attr);
1442 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
1443 pthread_mutex_init (&alloc_mutex, &attr);
1444#else /* !DOUG_LEA_MALLOC */
1445 /* Some systems such as Solaris 2.6 don't have a recursive mutex,
1446 and the bundled gmalloc.c doesn't require it. */
1447 pthread_mutex_init (&alloc_mutex, NULL);
1448#endif /* !DOUG_LEA_MALLOC */
1449#endif /* HAVE_PTHREAD */
1450
1451 if (__free_hook != emacs_blocked_free)
1452 old_free_hook = __free_hook;
1453 __free_hook = emacs_blocked_free;
1454
1455 if (__malloc_hook != emacs_blocked_malloc)
1456 old_malloc_hook = __malloc_hook;
1457 __malloc_hook = emacs_blocked_malloc;
1458
1459 if (__realloc_hook != emacs_blocked_realloc)
1460 old_realloc_hook = __realloc_hook;
1461 __realloc_hook = emacs_blocked_realloc;
1462}
1463
1464#endif /* not SYNC_INPUT */
1465#endif /* not SYSTEM_MALLOC */
1466
1467
1468
1469/*********************************************************************** 1144/***********************************************************************
1470 Interval Allocation 1145 Interval Allocation
1471 ***********************************************************************/ 1146 ***********************************************************************/
@@ -1511,8 +1186,6 @@ make_interval (void)
1511{ 1186{
1512 INTERVAL val; 1187 INTERVAL val;
1513 1188
1514 /* eassert (!handling_signal); */
1515
1516 MALLOC_BLOCK_INPUT; 1189 MALLOC_BLOCK_INPUT;
1517 1190
1518 if (interval_free_list) 1191 if (interval_free_list)
@@ -1896,8 +1569,6 @@ allocate_string (void)
1896{ 1569{
1897 struct Lisp_String *s; 1570 struct Lisp_String *s;
1898 1571
1899 /* eassert (!handling_signal); */
1900
1901 MALLOC_BLOCK_INPUT; 1572 MALLOC_BLOCK_INPUT;
1902 1573
1903 /* If the free-list is empty, allocate a new string_block, and 1574 /* If the free-list is empty, allocate a new string_block, and
@@ -2589,8 +2260,6 @@ make_float (double float_value)
2589{ 2260{
2590 register Lisp_Object val; 2261 register Lisp_Object val;
2591 2262
2592 /* eassert (!handling_signal); */
2593
2594 MALLOC_BLOCK_INPUT; 2263 MALLOC_BLOCK_INPUT;
2595 2264
2596 if (float_free_list) 2265 if (float_free_list)
@@ -2698,8 +2367,6 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2698{ 2367{
2699 register Lisp_Object val; 2368 register Lisp_Object val;
2700 2369
2701 /* eassert (!handling_signal); */
2702
2703 MALLOC_BLOCK_INPUT; 2370 MALLOC_BLOCK_INPUT;
2704 2371
2705 if (cons_free_list) 2372 if (cons_free_list)
@@ -3205,9 +2872,6 @@ allocate_vectorlike (ptrdiff_t len)
3205 2872
3206 MALLOC_BLOCK_INPUT; 2873 MALLOC_BLOCK_INPUT;
3207 2874
3208 /* This gets triggered by code which I haven't bothered to fix. --Stef */
3209 /* eassert (!handling_signal); */
3210
3211 if (len == 0) 2875 if (len == 0)
3212 p = XVECTOR (zero_vector); 2876 p = XVECTOR (zero_vector);
3213 else 2877 else
@@ -3492,8 +3156,6 @@ Its value and function definition are void, and its property list is nil. */)
3492 3156
3493 CHECK_STRING (name); 3157 CHECK_STRING (name);
3494 3158
3495 /* eassert (!handling_signal); */
3496
3497 MALLOC_BLOCK_INPUT; 3159 MALLOC_BLOCK_INPUT;
3498 3160
3499 if (symbol_free_list) 3161 if (symbol_free_list)
@@ -3578,8 +3240,6 @@ allocate_misc (enum Lisp_Misc_Type type)
3578{ 3240{
3579 Lisp_Object val; 3241 Lisp_Object val;
3580 3242
3581 /* eassert (!handling_signal); */
3582
3583 MALLOC_BLOCK_INPUT; 3243 MALLOC_BLOCK_INPUT;
3584 3244
3585 if (marker_free_list) 3245 if (marker_free_list)
@@ -3799,12 +3459,6 @@ memory_full (size_t nbytes)
3799 lisp_free (spare_memory[i]); 3459 lisp_free (spare_memory[i]);
3800 spare_memory[i] = 0; 3460 spare_memory[i] = 0;
3801 } 3461 }
3802
3803 /* Record the space now used. When it decreases substantially,
3804 we can refill the memory reserve. */
3805#if !defined SYSTEM_MALLOC && !defined SYNC_INPUT
3806 bytes_used_when_full = BYTES_USED;
3807#endif
3808 } 3462 }
3809 3463
3810 /* This used to call error, but if we've run out of memory, we could 3464 /* This used to call error, but if we've run out of memory, we could
@@ -3942,7 +3596,7 @@ mem_insert (void *start, void *end, enum mem_type type)
3942 3596
3943 /* Create a new node. */ 3597 /* Create a new node. */
3944#ifdef GC_MALLOC_CHECK 3598#ifdef GC_MALLOC_CHECK
3945 x = _malloc_internal (sizeof *x); 3599 x = malloc (sizeof *x);
3946 if (x == NULL) 3600 if (x == NULL)
3947 emacs_abort (); 3601 emacs_abort ();
3948#else 3602#else
@@ -4166,7 +3820,7 @@ mem_delete (struct mem_node *z)
4166 mem_delete_fixup (x); 3820 mem_delete_fixup (x);
4167 3821
4168#ifdef GC_MALLOC_CHECK 3822#ifdef GC_MALLOC_CHECK
4169 _free_internal (y); 3823 free (y);
4170#else 3824#else
4171 xfree (y); 3825 xfree (y);
4172#endif 3826#endif
@@ -5867,7 +5521,7 @@ mark_buffer (struct buffer *buffer)
5867} 5521}
5868 5522
5869/* Remove killed buffers or items whose car is a killed buffer from 5523/* Remove killed buffers or items whose car is a killed buffer from
5870 LIST, and mark other items. Return changed LIST, which is marked. */ 5524 LIST, and mark other items. Return changed LIST, which is marked. */
5871 5525
5872static Lisp_Object 5526static Lisp_Object
5873mark_discard_killed_buffers (Lisp_Object list) 5527mark_discard_killed_buffers (Lisp_Object list)
@@ -5889,6 +5543,7 @@ mark_discard_killed_buffers (Lisp_Object list)
5889 prev = &XCDR_AS_LVALUE (tail); 5543 prev = &XCDR_AS_LVALUE (tail);
5890 } 5544 }
5891 } 5545 }
5546 mark_object (tail);
5892 return list; 5547 return list;
5893} 5548}
5894 5549
@@ -6037,18 +5692,8 @@ mark_object (Lisp_Object arg)
6037 struct window *w = (struct window *) ptr; 5692 struct window *w = (struct window *) ptr;
6038 bool leaf = NILP (w->hchild) && NILP (w->vchild); 5693 bool leaf = NILP (w->hchild) && NILP (w->vchild);
6039 5694
6040 /* For live windows, Lisp code filters out killed buffers
6041 from both buffer lists. For dead windows, we do it here
6042 in attempt to help GC to reclaim killed buffers faster. */
6043 if (leaf && NILP (w->buffer))
6044 {
6045 wset_prev_buffers
6046 (w, mark_discard_killed_buffers (w->prev_buffers));
6047 wset_next_buffers
6048 (w, mark_discard_killed_buffers (w->next_buffers));
6049 }
6050
6051 mark_vectorlike (ptr); 5695 mark_vectorlike (ptr);
5696
6052 /* Mark glyphs for leaf windows. Marking window 5697 /* Mark glyphs for leaf windows. Marking window
6053 matrices is sufficient because frame matrices 5698 matrices is sufficient because frame matrices
6054 use the same glyph memory. */ 5699 use the same glyph memory. */
@@ -6057,6 +5702,15 @@ mark_object (Lisp_Object arg)
6057 mark_glyph_matrix (w->current_matrix); 5702 mark_glyph_matrix (w->current_matrix);
6058 mark_glyph_matrix (w->desired_matrix); 5703 mark_glyph_matrix (w->desired_matrix);
6059 } 5704 }
5705
5706 /* Filter out killed buffers from both buffer lists
5707 in attempt to help GC to reclaim killed buffers faster.
5708 We can do it elsewhere for live windows, but this is the
5709 best place to do it for dead windows. */
5710 wset_prev_buffers
5711 (w, mark_discard_killed_buffers (w->prev_buffers));
5712 wset_next_buffers
5713 (w, mark_discard_killed_buffers (w->next_buffers));
6060 } 5714 }
6061 break; 5715 break;
6062 5716
@@ -6767,12 +6421,6 @@ init_alloc_once (void)
6767 init_strings (); 6421 init_strings ();
6768 init_vectors (); 6422 init_vectors ();
6769 6423
6770#ifdef REL_ALLOC
6771 malloc_hysteresis = 32;
6772#else
6773 malloc_hysteresis = 0;
6774#endif
6775
6776 refill_memory_reserve (); 6424 refill_memory_reserve ();
6777 gc_cons_threshold = GC_DEFAULT_THRESHOLD; 6425 gc_cons_threshold = GC_DEFAULT_THRESHOLD;
6778} 6426}
diff --git a/src/atimer.c b/src/atimer.c
index 80b813fe4fe..5dbd807872a 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -369,7 +369,6 @@ run_timers (void)
369 if (! atimers) 369 if (! atimers)
370 pending_atimers = 0; 370 pending_atimers = 0;
371 371
372#ifdef SYNC_INPUT
373 if (pending_atimers) 372 if (pending_atimers)
374 pending_signals = 1; 373 pending_signals = 1;
375 else 374 else
@@ -377,10 +376,6 @@ run_timers (void)
377 pending_signals = interrupt_input_pending; 376 pending_signals = interrupt_input_pending;
378 set_alarm (); 377 set_alarm ();
379 } 378 }
380#else
381 if (! pending_atimers)
382 set_alarm ();
383#endif
384} 379}
385 380
386 381
@@ -391,11 +386,7 @@ static void
391handle_alarm_signal (int sig) 386handle_alarm_signal (int sig)
392{ 387{
393 pending_atimers = 1; 388 pending_atimers = 1;
394#ifdef SYNC_INPUT
395 pending_signals = 1; 389 pending_signals = 1;
396#else
397 run_timers ();
398#endif
399} 390}
400 391
401static void 392static void
diff --git a/src/bytecode.c b/src/bytecode.c
index b151078f60f..5f4fdcc5eff 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -458,7 +458,8 @@ unmark_byte_stack (void)
458 Fsignal (Qquit, Qnil); \ 458 Fsignal (Qquit, Qnil); \
459 AFTER_POTENTIAL_GC (); \ 459 AFTER_POTENTIAL_GC (); \
460 } \ 460 } \
461 ELSE_PENDING_SIGNALS \ 461 else if (pending_signals) \
462 process_pending_signals (); \
462 } while (0) 463 } while (0)
463 464
464 465
diff --git a/src/callproc.c b/src/callproc.c
index 9171337ee76..2604d295f3e 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -496,11 +496,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
496 register char **save_environ = environ; 496 register char **save_environ = environ;
497 register int fd1 = fd[1]; 497 register int fd1 = fd[1];
498 int fd_error = fd1; 498 int fd_error = fd1;
499#ifdef HAVE_WORKING_VFORK
500 sigset_t procmask;
501 sigset_t blocked;
502 struct sigaction sigpipe_action;
503#endif
504 499
505 if (fd_output >= 0) 500 if (fd_output >= 0)
506 fd1 = fd_output; 501 fd1 = fd_output;
@@ -587,17 +582,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
587 0, current_dir); 582 0, current_dir);
588#else /* not WINDOWSNT */ 583#else /* not WINDOWSNT */
589 584
590#ifdef HAVE_WORKING_VFORK
591 /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal',
592 this sets the parent's signal handlers as well as the child's.
593 So delay all interrupts whose handlers the child might munge,
594 and record the current handlers so they can be restored later. */
595 sigemptyset (&blocked);
596 sigaddset (&blocked, SIGPIPE);
597 sigaction (SIGPIPE, 0, &sigpipe_action);
598 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
599#endif
600
601 BLOCK_INPUT; 585 BLOCK_INPUT;
602 586
603 /* vfork, and prevent local vars from being clobbered by the vfork. */ 587 /* vfork, and prevent local vars from being clobbered by the vfork. */
@@ -645,9 +629,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
645 /* GConf causes us to ignore SIGPIPE, make sure it is restored 629 /* GConf causes us to ignore SIGPIPE, make sure it is restored
646 in the child. */ 630 in the child. */
647 signal (SIGPIPE, SIG_DFL); 631 signal (SIGPIPE, SIG_DFL);
648#ifdef HAVE_WORKING_VFORK
649 pthread_sigmask (SIG_SETMASK, &procmask, 0);
650#endif
651 632
652 child_setup (filefd, fd1, fd_error, (char **) new_argv, 633 child_setup (filefd, fd1, fd_error, (char **) new_argv,
653 0, current_dir); 634 0, current_dir);
@@ -655,12 +636,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
655 636
656 UNBLOCK_INPUT; 637 UNBLOCK_INPUT;
657 638
658#ifdef HAVE_WORKING_VFORK
659 /* Restore the signal state. */
660 sigaction (SIGPIPE, &sigpipe_action, 0);
661 pthread_sigmask (SIG_SETMASK, &procmask, 0);
662#endif
663
664#endif /* not WINDOWSNT */ 639#endif /* not WINDOWSNT */
665 640
666 /* The MSDOS case did this already. */ 641 /* The MSDOS case did this already. */
diff --git a/src/conf_post.h b/src/conf_post.h
index 94934ffeadf..0c4d029bc5d 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -90,7 +90,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
90char *_getpty(); 90char *_getpty();
91#endif 91#endif
92 92
93#undef SA_RESTART /* not the same as defining BROKEN_SA_RESTART */
94#endif /* IRIX6_5 */ 93#endif /* IRIX6_5 */
95 94
96#ifdef MSDOS 95#ifdef MSDOS
diff --git a/src/dispnew.c b/src/dispnew.c
index 5827316a7b7..fc966581adb 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5971,7 +5971,7 @@ sit_for (Lisp_Object timeout, bool reading, int do_display)
5971 5971
5972 5972
5973#ifdef USABLE_SIGIO 5973#ifdef USABLE_SIGIO
5974 gobble_input (0); 5974 gobble_input ();
5975#endif 5975#endif
5976 5976
5977 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display, 5977 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
diff --git a/src/emacs.c b/src/emacs.c
index 1416bf76c43..d4b52ab64ea 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -88,7 +88,7 @@ extern void moncontrol (int mode);
88#endif 88#endif
89 89
90static const char emacs_version[] = VERSION; 90static const char emacs_version[] = VERSION;
91static const char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc."; 91static const char emacs_copyright[] = COPYRIGHT;
92 92
93/* Empty lisp strings. To avoid having to build any others. */ 93/* Empty lisp strings. To avoid having to build any others. */
94Lisp_Object empty_unibyte_string, empty_multibyte_string; 94Lisp_Object empty_unibyte_string, empty_multibyte_string;
@@ -848,14 +848,10 @@ main (int argc, char **argv)
848 /* Arrange to get warning messages as memory fills up. */ 848 /* Arrange to get warning messages as memory fills up. */
849 memory_warnings (0, malloc_warning); 849 memory_warnings (0, malloc_warning);
850 850
851 /* Call malloc at least once, to run the initial __malloc_hook. 851 /* Call malloc at least once, to run malloc_initialize_hook.
852 Also call realloc and free for consistency. */ 852 Also call realloc and free for consistency. */
853 free (realloc (malloc (4), 4)); 853 free (realloc (malloc (4), 4));
854 854
855# ifndef SYNC_INPUT
856 /* Arrange to disable interrupt input inside malloc etc. */
857 uninterrupt_malloc ();
858# endif /* not SYNC_INPUT */
859#endif /* not SYSTEM_MALLOC */ 855#endif /* not SYSTEM_MALLOC */
860 856
861#if defined (MSDOS) || defined (WINDOWSNT) 857#if defined (MSDOS) || defined (WINDOWSNT)
@@ -2143,12 +2139,6 @@ You must run Emacs in batch mode in order to dump it. */)
2143 memory_warnings (my_edata, malloc_warning); 2139 memory_warnings (my_edata, malloc_warning);
2144 } 2140 }
2145#endif /* not WINDOWSNT */ 2141#endif /* not WINDOWSNT */
2146#if defined (HAVE_PTHREAD) && !defined SYNC_INPUT
2147 /* Pthread may call malloc before main, and then we will get an endless
2148 loop, because pthread_self (see alloc.c) calls malloc the first time
2149 it is called on some systems. */
2150 reset_malloc_hooks ();
2151#endif
2152#endif /* not SYSTEM_MALLOC */ 2142#endif /* not SYSTEM_MALLOC */
2153#ifdef DOUG_LEA_MALLOC 2143#ifdef DOUG_LEA_MALLOC
2154 malloc_state_ptr = malloc_get_state (); 2144 malloc_state_ptr = malloc_get_state ();
diff --git a/src/eval.c b/src/eval.c
index 6cca13a8fda..e47478bb1f1 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -117,12 +117,6 @@ static EMACS_INT when_entered_debugger;
117 117
118Lisp_Object Vsignaling_function; 118Lisp_Object Vsignaling_function;
119 119
120/* Set to non-zero while processing X events. Checked in Feval to
121 make sure the Lisp interpreter isn't called from a signal handler,
122 which is unsafe because the interpreter isn't reentrant. */
123
124int handling_signal;
125
126/* If non-nil, Lisp code must not be run since some part of Emacs is 120/* If non-nil, Lisp code must not be run since some part of Emacs is
127 in an inconsistent state. Currently, x-create-frame uses this to 121 in an inconsistent state. Currently, x-create-frame uses this to
128 avoid triggering window-configuration-change-hook while the new 122 avoid triggering window-configuration-change-hook while the new
@@ -1106,7 +1100,6 @@ unwind_to_catch (struct catchtag *catch, Lisp_Object value)
1106 /* Restore certain special C variables. */ 1100 /* Restore certain special C variables. */
1107 set_poll_suppress_count (catch->poll_suppress_count); 1101 set_poll_suppress_count (catch->poll_suppress_count);
1108 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked); 1102 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
1109 handling_signal = 0;
1110 immediate_quit = 0; 1103 immediate_quit = 0;
1111 1104
1112 do 1105 do
@@ -1486,7 +1479,7 @@ See also the function `condition-case'. */)
1486 struct handler *h; 1479 struct handler *h;
1487 struct backtrace *bp; 1480 struct backtrace *bp;
1488 1481
1489 immediate_quit = handling_signal = 0; 1482 immediate_quit = 0;
1490 abort_on_gc = 0; 1483 abort_on_gc = 0;
1491 if (gc_in_progress || waiting_for_input) 1484 if (gc_in_progress || waiting_for_input)
1492 emacs_abort (); 1485 emacs_abort ();
@@ -2039,9 +2032,6 @@ eval_sub (Lisp_Object form)
2039 struct backtrace backtrace; 2032 struct backtrace backtrace;
2040 struct gcpro gcpro1, gcpro2, gcpro3; 2033 struct gcpro gcpro1, gcpro2, gcpro3;
2041 2034
2042 if (handling_signal)
2043 emacs_abort ();
2044
2045 if (SYMBOLP (form)) 2035 if (SYMBOLP (form))
2046 { 2036 {
2047 /* Look up its binding in the lexical environment. 2037 /* Look up its binding in the lexical environment.
@@ -2409,6 +2399,7 @@ If it is a list of functions, those functions are called, in order,
2409with the given arguments ARGS, until one of them 2399with the given arguments ARGS, until one of them
2410returns a non-nil value. Then we return that value. 2400returns a non-nil value. Then we return that value.
2411However, if they all return nil, we return nil. 2401However, if they all return nil, we return nil.
2402If the value of HOOK is nil, this function returns nil.
2412 2403
2413Do 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.
2414Instead, use `add-hook' and specify t for the LOCAL argument. 2405Instead, use `add-hook' and specify t for the LOCAL argument.
@@ -2430,10 +2421,12 @@ DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2430HOOK should be a symbol, a hook variable. If HOOK has a non-nil 2421HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2431value, that value may be a function or a list of functions to be 2422value, that value may be a function or a list of functions to be
2432called to run the hook. If the value is a function, it is called with 2423called to run the hook. If the value is a function, it is called with
2433the given arguments and its return value is returned. 2424the given arguments. Then we return nil if the function returns nil,
2425and t if it returns non-nil.
2434If it is a list of functions, those functions are called, in order, 2426If it is a list of functions, those functions are called, in order,
2435with the given arguments ARGS, until one of them returns nil. 2427with the given arguments ARGS, until one of them returns nil.
2436Then we return nil. However, if they all return non-nil, we return non-nil. 2428Then we return nil. However, if they all return non-nil, we return t.
2429If the value of HOOK is nil, this function returns t.
2437 2430
2438Do not use `make-local-variable' to make a hook variable buffer-local. 2431Do not use `make-local-variable' to make a hook variable buffer-local.
2439Instead, use `add-hook' and specify t for the LOCAL argument. 2432Instead, use `add-hook' and specify t for the LOCAL argument.
@@ -3104,8 +3097,6 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3104{ 3097{
3105 struct Lisp_Symbol *sym; 3098 struct Lisp_Symbol *sym;
3106 3099
3107 eassert (!handling_signal);
3108
3109 CHECK_SYMBOL (symbol); 3100 CHECK_SYMBOL (symbol);
3110 sym = XSYMBOL (symbol); 3101 sym = XSYMBOL (symbol);
3111 if (specpdl_ptr == specpdl + specpdl_size) 3102 if (specpdl_ptr == specpdl + specpdl_size)
@@ -3199,8 +3190,6 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3199void 3190void
3200record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg) 3191record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
3201{ 3192{
3202 eassert (!handling_signal);
3203
3204 if (specpdl_ptr == specpdl + specpdl_size) 3193 if (specpdl_ptr == specpdl + specpdl_size)
3205 grow_specpdl (); 3194 grow_specpdl ();
3206 specpdl_ptr->func = function; 3195 specpdl_ptr->func = function;
diff --git a/src/fileio.c b/src/fileio.c
index ca71af7ed95..6c4e34d7312 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -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
diff --git a/src/font.c b/src/font.c
index fc970254a62..1f22fee88ee 100644
--- a/src/font.c
+++ b/src/font.c
@@ -4303,7 +4303,7 @@ GSTRING. */)
4303{ 4303{
4304 struct font *font; 4304 struct font *font;
4305 Lisp_Object font_object, n, glyph; 4305 Lisp_Object font_object, n, glyph;
4306 ptrdiff_t i, j, from, to; 4306 ptrdiff_t i, from, to;
4307 4307
4308 if (! composition_gstring_p (gstring)) 4308 if (! composition_gstring_p (gstring))
4309 signal_error ("Invalid glyph-string: ", gstring); 4309 signal_error ("Invalid glyph-string: ", gstring);
diff --git a/src/frame.c b/src/frame.c
index 6930dac3ce8..f3d16171516 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -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/image.c b/src/image.c
index 8fc1c8637eb..8d690df8abb 100644
--- a/src/image.c
+++ b/src/image.c
@@ -590,9 +590,15 @@ define_image_type (struct image_type *type, int loaded)
590 success = Qnil; 590 success = Qnil;
591 else 591 else
592 { 592 {
593 struct image_type *p;
594 Lisp_Object target_type = *(type->type);
595 for (p = image_types; p; p = p->next)
596 if (EQ (*(p->type), target_type))
597 return Qt;
598
593 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 599 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
594 The initialized data segment is read-only. */ 600 The initialized data segment is read-only. */
595 struct image_type *p = xmalloc (sizeof *p); 601 p = xmalloc (sizeof *p);
596 *p = *type; 602 *p = *type;
597 p->next = image_types; 603 p->next = image_types;
598 image_types = p; 604 image_types = p;
diff --git a/src/intervals.c b/src/intervals.c
index 5a47cacb2dd..584ee1e923d 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -673,8 +673,7 @@ find_interval (register INTERVAL tree, register ptrdiff_t position)
673 673
674 eassert (relative_position <= TOTAL_LENGTH (tree)); 674 eassert (relative_position <= TOTAL_LENGTH (tree));
675 675
676 if (!handling_signal) 676 tree = balance_possible_root_interval (tree);
677 tree = balance_possible_root_interval (tree);
678 677
679 while (1) 678 while (1)
680 { 679 {
diff --git a/src/keyboard.c b/src/keyboard.c
index d164083fb86..098d3530ef8 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -84,9 +84,7 @@ int interrupt_input_pending;
84 pending_atimers separately, to reduce code size. So, any code that 84 pending_atimers separately, to reduce code size. So, any code that
85 changes interrupt_input_pending or pending_atimers should update 85 changes interrupt_input_pending or pending_atimers should update
86 this too. */ 86 this too. */
87#ifdef SYNC_INPUT
88int pending_signals; 87int pending_signals;
89#endif
90 88
91#define KBD_BUFFER_SIZE 4096 89#define KBD_BUFFER_SIZE 4096
92 90
@@ -415,7 +413,7 @@ static EMACS_TIME timer_last_idleness_start_time;
415/* Function for init_keyboard to call with no args (if nonzero). */ 413/* Function for init_keyboard to call with no args (if nonzero). */
416static void (*keyboard_init_hook) (void); 414static void (*keyboard_init_hook) (void);
417 415
418static int read_avail_input (int); 416static int read_avail_input (void);
419static void get_input_pending (int *, int); 417static void get_input_pending (int *, int);
420static int readable_events (int); 418static int readable_events (int);
421static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *, 419static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *,
@@ -450,7 +448,7 @@ static void timer_stop_idle (void);
450static void timer_resume_idle (void); 448static void timer_resume_idle (void);
451static void deliver_user_signal (int); 449static void deliver_user_signal (int);
452static char *find_user_signal_name (int); 450static char *find_user_signal_name (int);
453static int store_user_signal_events (void); 451static void store_user_signal_events (void);
454 452
455/* These setters are used only in this file, so they can be private. */ 453/* These setters are used only in this file, so they can be private. */
456static inline void 454static inline void
@@ -2010,17 +2008,9 @@ static struct atimer *poll_timer;
2010void 2008void
2011poll_for_input_1 (void) 2009poll_for_input_1 (void)
2012{ 2010{
2013/* Tell ns_read_socket() it is being called asynchronously so it can avoid
2014 doing anything dangerous. */
2015#ifdef HAVE_NS
2016 ++handling_signal;
2017#endif
2018 if (interrupt_input_blocked == 0 2011 if (interrupt_input_blocked == 0
2019 && !waiting_for_input) 2012 && !waiting_for_input)
2020 read_avail_input (0); 2013 read_avail_input ();
2021#ifdef HAVE_NS
2022 --handling_signal;
2023#endif
2024} 2014}
2025 2015
2026/* Timer callback function for poll_timer. TIMER is equal to 2016/* Timer callback function for poll_timer. TIMER is equal to
@@ -2031,12 +2021,8 @@ poll_for_input (struct atimer *timer)
2031{ 2021{
2032 if (poll_suppress_count == 0) 2022 if (poll_suppress_count == 0)
2033 { 2023 {
2034#ifdef SYNC_INPUT
2035 interrupt_input_pending = 1; 2024 interrupt_input_pending = 1;
2036 pending_signals = 1; 2025 pending_signals = 1;
2037#else
2038 poll_for_input_1 ();
2039#endif
2040 } 2026 }
2041} 2027}
2042 2028
@@ -3857,7 +3843,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3857 interrupt handlers have not read it, read it now. */ 3843 interrupt handlers have not read it, read it now. */
3858 3844
3859#ifdef USABLE_SIGIO 3845#ifdef USABLE_SIGIO
3860 gobble_input (0); 3846 gobble_input ();
3861#endif 3847#endif
3862 if (kbd_fetch_ptr != kbd_store_ptr) 3848 if (kbd_fetch_ptr != kbd_store_ptr)
3863 break; 3849 break;
@@ -3883,8 +3869,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3883 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0); 3869 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0);
3884 3870
3885 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) 3871 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr)
3886 /* Pass 1 for EXPECT since we just waited to have input. */ 3872 read_avail_input ();
3887 read_avail_input (1);
3888 } 3873 }
3889 3874
3890 if (CONSP (Vunread_command_events)) 3875 if (CONSP (Vunread_command_events))
@@ -6748,14 +6733,14 @@ get_input_pending (int *addr, int flags)
6748 return; 6733 return;
6749 6734
6750 /* Try to read some input and see how much we get. */ 6735 /* Try to read some input and see how much we get. */
6751 gobble_input (0); 6736 gobble_input ();
6752 *addr = (!NILP (Vquit_flag) || readable_events (flags)); 6737 *addr = (!NILP (Vquit_flag) || readable_events (flags));
6753} 6738}
6754 6739
6755/* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ 6740/* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6756 6741
6757void 6742void
6758gobble_input (int expected) 6743gobble_input (void)
6759{ 6744{
6760#ifdef USABLE_SIGIO 6745#ifdef USABLE_SIGIO
6761 if (interrupt_input) 6746 if (interrupt_input)
@@ -6764,7 +6749,7 @@ gobble_input (int expected)
6764 sigemptyset (&blocked); 6749 sigemptyset (&blocked);
6765 sigaddset (&blocked, SIGIO); 6750 sigaddset (&blocked, SIGIO);
6766 pthread_sigmask (SIG_BLOCK, &blocked, &procmask); 6751 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6767 read_avail_input (expected); 6752 read_avail_input ();
6768 pthread_sigmask (SIG_SETMASK, &procmask, 0); 6753 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6769 } 6754 }
6770 else 6755 else
@@ -6778,13 +6763,13 @@ gobble_input (int expected)
6778 sigemptyset (&blocked); 6763 sigemptyset (&blocked);
6779 sigaddset (&blocked, SIGALRM); 6764 sigaddset (&blocked, SIGALRM);
6780 pthread_sigmask (SIG_BLOCK, &blocked, &procmask); 6765 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6781 read_avail_input (expected); 6766 read_avail_input ();
6782 pthread_sigmask (SIG_SETMASK, &procmask, 0); 6767 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6783 } 6768 }
6784 else 6769 else
6785#endif 6770#endif
6786#endif 6771#endif
6787 read_avail_input (expected); 6772 read_avail_input ();
6788} 6773}
6789 6774
6790/* Put a BUFFER_SWITCH_EVENT in the buffer 6775/* Put a BUFFER_SWITCH_EVENT in the buffer
@@ -6840,15 +6825,14 @@ record_asynch_buffer_change (void)
6840 this is a bad time to try to read input. */ 6825 this is a bad time to try to read input. */
6841 6826
6842static int 6827static int
6843read_avail_input (int expected) 6828read_avail_input (void)
6844{ 6829{
6845 int nread = 0; 6830 int nread = 0;
6846 int err = 0; 6831 int err = 0;
6847 struct terminal *t; 6832 struct terminal *t;
6848 6833
6849 /* Store pending user signal events, if any. */ 6834 /* Store pending user signal events, if any. */
6850 if (store_user_signal_events ()) 6835 store_user_signal_events ();
6851 expected = 0;
6852 6836
6853 /* Loop through the available terminals, and call their input hooks. */ 6837 /* Loop through the available terminals, and call their input hooks. */
6854 t = terminal_list; 6838 t = terminal_list;
@@ -6865,11 +6849,8 @@ read_avail_input (int expected)
6865 hold_quit.kind = NO_EVENT; 6849 hold_quit.kind = NO_EVENT;
6866 6850
6867 /* No need for FIONREAD or fcntl; just say don't wait. */ 6851 /* No need for FIONREAD or fcntl; just say don't wait. */
6868 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0) 6852 while (0 < (nr = (*t->read_socket_hook) (t, &hold_quit)))
6869 { 6853 nread += nr;
6870 nread += nr;
6871 expected = 0;
6872 }
6873 6854
6874 if (nr == -1) /* Not OK to read input now. */ 6855 if (nr == -1) /* Not OK to read input now. */
6875 { 6856 {
@@ -6964,7 +6945,6 @@ decode_keyboard_code (struct tty_display_info *tty,
6964 6945
6965int 6946int
6966tty_read_avail_input (struct terminal *terminal, 6947tty_read_avail_input (struct terminal *terminal,
6967 int expected,
6968 struct input_event *hold_quit) 6948 struct input_event *hold_quit)
6969{ 6949{
6970 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 6950 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
@@ -7176,36 +7156,23 @@ tty_read_avail_input (struct terminal *terminal,
7176 return nread; 7156 return nread;
7177} 7157}
7178 7158
7179#if defined SYNC_INPUT || defined USABLE_SIGIO
7180static void 7159static void
7181handle_async_input (void) 7160handle_async_input (void)
7182{ 7161{
7183 interrupt_input_pending = 0; 7162 interrupt_input_pending = 0;
7184#ifdef SYNC_INPUT
7185 pending_signals = pending_atimers; 7163 pending_signals = pending_atimers;
7186#endif 7164
7187/* Tell ns_read_socket() it is being called asynchronously so it can avoid
7188 doing anything dangerous. */
7189#ifdef HAVE_NS
7190 ++handling_signal;
7191#endif
7192 while (1) 7165 while (1)
7193 { 7166 {
7194 int nread; 7167 int nread = read_avail_input ();
7195 nread = read_avail_input (1);
7196 /* -1 means it's not ok to read the input now. 7168 /* -1 means it's not ok to read the input now.
7197 UNBLOCK_INPUT will read it later; now, avoid infinite loop. 7169 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7198 0 means there was no keyboard input available. */ 7170 0 means there was no keyboard input available. */
7199 if (nread <= 0) 7171 if (nread <= 0)
7200 break; 7172 break;
7201 } 7173 }
7202#ifdef HAVE_NS
7203 --handling_signal;
7204#endif
7205} 7174}
7206#endif /* SYNC_INPUT || USABLE_SIGIO */
7207 7175
7208#ifdef SYNC_INPUT
7209void 7176void
7210process_pending_signals (void) 7177process_pending_signals (void)
7211{ 7178{
@@ -7213,24 +7180,17 @@ process_pending_signals (void)
7213 handle_async_input (); 7180 handle_async_input ();
7214 do_pending_atimers (); 7181 do_pending_atimers ();
7215} 7182}
7216#endif
7217 7183
7218#ifdef USABLE_SIGIO 7184#ifdef USABLE_SIGIO
7219 7185
7220static void 7186static void
7221handle_input_available_signal (int sig) 7187handle_input_available_signal (int sig)
7222{ 7188{
7223#ifdef SYNC_INPUT
7224 interrupt_input_pending = 1; 7189 interrupt_input_pending = 1;
7225 pending_signals = 1; 7190 pending_signals = 1;
7226#endif
7227 7191
7228 if (input_available_clear_time) 7192 if (input_available_clear_time)
7229 *input_available_clear_time = make_emacs_time (0, 0); 7193 *input_available_clear_time = make_emacs_time (0, 0);
7230
7231#ifndef SYNC_INPUT
7232 handle_async_input ();
7233#endif
7234} 7194}
7235 7195
7236static void 7196static void
@@ -7356,25 +7316,25 @@ find_user_signal_name (int sig)
7356 return NULL; 7316 return NULL;
7357} 7317}
7358 7318
7359static int 7319static void
7360store_user_signal_events (void) 7320store_user_signal_events (void)
7361{ 7321{
7362 struct user_signal_info *p; 7322 struct user_signal_info *p;
7363 struct input_event buf; 7323 struct input_event buf;
7364 int nstored = 0; 7324 bool buf_initialized = 0;
7365 7325
7366 for (p = user_signals; p; p = p->next) 7326 for (p = user_signals; p; p = p->next)
7367 if (p->npending > 0) 7327 if (p->npending > 0)
7368 { 7328 {
7369 sigset_t blocked, procmask; 7329 sigset_t blocked, procmask;
7370 7330
7371 if (nstored == 0) 7331 if (! buf_initialized)
7372 { 7332 {
7373 memset (&buf, 0, sizeof buf); 7333 memset (&buf, 0, sizeof buf);
7374 buf.kind = USER_SIGNAL_EVENT; 7334 buf.kind = USER_SIGNAL_EVENT;
7375 buf.frame_or_window = selected_frame; 7335 buf.frame_or_window = selected_frame;
7336 buf_initialized = 1;
7376 } 7337 }
7377 nstored += p->npending;
7378 7338
7379 sigemptyset (&blocked); 7339 sigemptyset (&blocked);
7380 sigaddset (&blocked, p->sig); 7340 sigaddset (&blocked, p->sig);
@@ -7390,8 +7350,6 @@ store_user_signal_events (void)
7390 7350
7391 pthread_sigmask (SIG_SETMASK, &procmask, 0); 7351 pthread_sigmask (SIG_SETMASK, &procmask, 0);
7392 } 7352 }
7393
7394 return nstored;
7395} 7353}
7396 7354
7397 7355
@@ -11365,9 +11323,7 @@ init_keyboard (void)
11365 input_pending = 0; 11323 input_pending = 0;
11366 interrupt_input_blocked = 0; 11324 interrupt_input_blocked = 0;
11367 interrupt_input_pending = 0; 11325 interrupt_input_pending = 0;
11368#ifdef SYNC_INPUT
11369 pending_signals = 0; 11326 pending_signals = 0;
11370#endif
11371 11327
11372 /* This means that command_loop_1 won't try to select anything the first 11328 /* This means that command_loop_1 won't try to select anything the first
11373 time through. */ 11329 time through. */
diff --git a/src/keyboard.h b/src/keyboard.h
index 91484b3649b..3601f68be9f 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 void 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/lisp.h b/src/lisp.h
index 447c6bd296b..3a473a60b48 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2107,22 +2107,16 @@ extern char *stack_bottom;
2107 If quit-flag is set to `kill-emacs' the SIGINT handler has received 2107 If quit-flag is set to `kill-emacs' the SIGINT handler has received
2108 a request to exit Emacs when it is safe to do. */ 2108 a request to exit Emacs when it is safe to do. */
2109 2109
2110#ifdef SYNC_INPUT
2111extern void process_pending_signals (void); 2110extern void process_pending_signals (void);
2112extern int pending_signals; 2111extern int pending_signals;
2113#define ELSE_PENDING_SIGNALS \
2114 else if (pending_signals) \
2115 process_pending_signals ();
2116#else /* not SYNC_INPUT */
2117#define ELSE_PENDING_SIGNALS
2118#endif /* not SYNC_INPUT */
2119 2112
2120extern void process_quit_flag (void); 2113extern void process_quit_flag (void);
2121#define QUIT \ 2114#define QUIT \
2122 do { \ 2115 do { \
2123 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \ 2116 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
2124 process_quit_flag (); \ 2117 process_quit_flag (); \
2125 ELSE_PENDING_SIGNALS \ 2118 else if (pending_signals) \
2119 process_pending_signals (); \
2126 } while (0) 2120 } while (0)
2127 2121
2128 2122
@@ -2846,8 +2840,6 @@ extern void memory_warnings (void *, void (*warnfun) (const char *));
2846/* Defined in alloc.c. */ 2840/* Defined in alloc.c. */
2847extern void check_pure_size (void); 2841extern void check_pure_size (void);
2848extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT); 2842extern void allocate_string_data (struct Lisp_String *, EMACS_INT, EMACS_INT);
2849extern void reset_malloc_hooks (void);
2850extern void uninterrupt_malloc (void);
2851extern void malloc_warning (const char *); 2843extern void malloc_warning (const char *);
2852extern _Noreturn void memory_full (size_t); 2844extern _Noreturn void memory_full (size_t);
2853extern _Noreturn void buffer_memory_full (ptrdiff_t); 2845extern _Noreturn void buffer_memory_full (ptrdiff_t);
@@ -3043,7 +3035,6 @@ extern Lisp_Object Qand_rest;
3043extern Lisp_Object Vautoload_queue; 3035extern Lisp_Object Vautoload_queue;
3044extern Lisp_Object Vsignaling_function; 3036extern Lisp_Object Vsignaling_function;
3045extern Lisp_Object inhibit_lisp_code; 3037extern Lisp_Object inhibit_lisp_code;
3046extern int handling_signal;
3047#if BYTE_MARK_STACK 3038#if BYTE_MARK_STACK
3048extern struct catchtag *catchlist; 3039extern struct catchtag *catchlist;
3049extern struct handler *handlerlist; 3040extern struct handler *handlerlist;
diff --git a/src/ns.mk b/src/ns.mk
deleted file mode 100644
index 77fbf5845d9..00000000000
--- a/src/ns.mk
+++ /dev/null
@@ -1,39 +0,0 @@
1### autodeps.mk --- src/Makefile fragment for GNU Emacs
2
3## Copyright (C) 2008-2012 Free Software Foundation, Inc.
4
5## This file is part of GNU Emacs.
6
7## GNU Emacs is free software: you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation, either version 3 of the License, or
10## (at your option) any later version.
11##
12## GNU Emacs is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20### Commentary:
21
22## This is inserted in src/Makefile if HAVE_NS.
23
24## The only reason this is in a separate file is because $ns_appdir,
25## which appears as a target, is empty on non-NS builds. Some makes
26## do not like empty targets, even if they are never used.
27
28${ns_appdir}: ${ns_appsrc}
29 rm -fr ${ns_appdir}
30 ${MKDIR_P} ${ns_appdir}
31 ( cd ${ns_appsrc} ; tar cfh - . ) | ( cd ${ns_appdir} ; umask 022; tar xf - )
32
33${ns_appbindir}/Emacs: emacs${EXEEXT}
34 ${MKDIR_P} ${ns_appbindir}
35 cp -f emacs${EXEEXT} ${ns_appbindir}/Emacs
36
37ns-app: ${ns_appdir} ${ns_appbindir}/Emacs
38
39### ns.mk ends here
diff --git a/src/nsfns.m b/src/nsfns.m
index 072005d2d3d..e2c8c3722c0 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -870,16 +870,6 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
870} 870}
871 871
872 872
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? */ 873/* TODO: move to nsterm? */
884int 874int
885ns_lisp_to_cursor_type (Lisp_Object arg) 875ns_lisp_to_cursor_type (Lisp_Object arg)
@@ -1399,6 +1389,9 @@ This function is an internal primitive--use `make-frame' instead. */)
1399 1389
1400 UNGCPRO; 1390 UNGCPRO;
1401 1391
1392 if (window_prompting & USPosition)
1393 x_set_offset (f, f->left_pos, f->top_pos, 1);
1394
1402 /* Make sure windows on this frame appear in calls to next-window 1395 /* Make sure windows on this frame appear in calls to next-window
1403 and similar functions. */ 1396 and similar functions. */
1404 Vwindow_list = Qnil; 1397 Vwindow_list = Qnil;
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 3057f4f6a20..907d3eac622 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -588,10 +588,7 @@ extern NSString *NSMenuDidBeginTrackingNotification;
588 From 10.6 on, we could also use -[NSMenu propertiesToUpdate]: In the 588 From 10.6 on, we could also use -[NSMenu propertiesToUpdate]: In the
589 key press case, NSMenuPropertyItemImage (e.g.) won't be set. 589 key press case, NSMenuPropertyItemImage (e.g.) won't be set.
590 */ 590 */
591 if (trackingMenu == 0 591 if (trackingMenu == 0)
592 /* Also, don't try this if from an event picked up asynchronously,
593 as lots of lisp evaluation happens in ns_update_menubar. */
594 || handling_signal != 0)
595 return; 592 return;
596/*fprintf (stderr, "Updating menu '%s'\n", [[self title] UTF8String]); NSLog (@"%@\n", event); */ 593/*fprintf (stderr, "Updating menu '%s'\n", [[self title] UTF8String]); NSLog (@"%@\n", event); */
597 ns_update_menubar (frame, 1, self); 594 ns_update_menubar (frame, 1, self);
diff --git a/src/nsterm.m b/src/nsterm.m
index 41520ce74d1..aa869e3ff44 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3336,8 +3336,7 @@ ns_send_appdefined (int value)
3336} 3336}
3337 3337
3338static int 3338static int
3339ns_read_socket (struct terminal *terminal, int expected, 3339ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
3340 struct input_event *hold_quit)
3341/* -------------------------------------------------------------------------- 3340/* --------------------------------------------------------------------------
3342 External (hook): Post an event to ourself and keep reading events until 3341 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. 3342 we read it back again. In effect process all events which were waiting.
@@ -3355,16 +3354,12 @@ ns_read_socket (struct terminal *terminal, int expected,
3355 if (interrupt_input_blocked) 3354 if (interrupt_input_blocked)
3356 { 3355 {
3357 interrupt_input_pending = 1; 3356 interrupt_input_pending = 1;
3358#ifdef SYNC_INPUT
3359 pending_signals = 1; 3357 pending_signals = 1;
3360#endif
3361 return -1; 3358 return -1;
3362 } 3359 }
3363 3360
3364 interrupt_input_pending = 0; 3361 interrupt_input_pending = 0;
3365#ifdef SYNC_INPUT
3366 pending_signals = pending_atimers; 3362 pending_signals = pending_atimers;
3367#endif
3368 3363
3369 BLOCK_INPUT; 3364 BLOCK_INPUT;
3370 n_emacs_events_pending = 0; 3365 n_emacs_events_pending = 0;
@@ -3726,7 +3721,7 @@ ns_judge_scroll_bars (struct frame *f)
3726 removed = YES; 3721 removed = YES;
3727 } 3722 }
3728 3723
3729 if (removed) 3724 if (removed)
3730 [eview updateFrameSize: NO]; 3725 [eview updateFrameSize: NO];
3731} 3726}
3732 3727
@@ -3988,7 +3983,6 @@ ns_term_init (Lisp_Object display_name)
3988 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */ 3983 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3989 /*GSDebugAllocationActive (YES); */ 3984 /*GSDebugAllocationActive (YES); */
3990 BLOCK_INPUT; 3985 BLOCK_INPUT;
3991 handling_signal = 0;
3992 3986
3993 baud_rate = 38400; 3987 baud_rate = 38400;
3994 Fset_input_interrupt_mode (Qnil); 3988 Fset_input_interrupt_mode (Qnil);
@@ -4209,7 +4203,7 @@ ns_term_init (Lisp_Object display_name)
4209 NSColorPboardType, 4203 NSColorPboardType,
4210 NSFontPboardType, nil] retain]; 4204 NSFontPboardType, nil] retain];
4211 4205
4212 4206
4213 [NSApp run]; 4207 [NSApp run];
4214 ns_do_open_file = YES; 4208 ns_do_open_file = YES;
4215 return dpyinfo; 4209 return dpyinfo;
@@ -6239,7 +6233,7 @@ not_in_argv (NSString *arg)
6239 NSRect r = [super constrainFrameRect:frameRect toScreen:screen]; 6233 NSRect r = [super constrainFrameRect:frameRect toScreen:screen];
6240 return r; 6234 return r;
6241 } 6235 }
6242 6236
6243 if (f->output_data.ns->dont_constrain 6237 if (f->output_data.ns->dont_constrain
6244 || ns_menu_bar_should_be_hidden ()) 6238 || ns_menu_bar_should_be_hidden ())
6245 return frameRect; 6239 return frameRect;
diff --git a/src/process.c b/src/process.c
index 6dbff6f4b16..c654369627d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1609,14 +1609,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1609#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) 1609#if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1610 int wait_child_setup[2]; 1610 int wait_child_setup[2];
1611#endif 1611#endif
1612#ifdef SIGCHLD
1612 sigset_t blocked, procmask; 1613 sigset_t blocked, procmask;
1613 struct sigaction sigint_action;
1614 struct sigaction sigquit_action;
1615 struct sigaction sigpipe_action;
1616#ifdef AIX
1617 struct sigaction sighup_action;
1618#endif 1614#endif
1619 /* Use volatile to protect variables from being clobbered by longjmp. */ 1615 /* Use volatile to protect variables from being clobbered by vfork. */
1620 volatile int forkin, forkout; 1616 volatile int forkin, forkout;
1621 volatile int pty_flag = 0; 1617 volatile int pty_flag = 0;
1622 1618
@@ -1708,25 +1704,13 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1708 XPROCESS (process)->pty_flag = pty_flag; 1704 XPROCESS (process)->pty_flag = pty_flag;
1709 pset_status (XPROCESS (process), Qrun); 1705 pset_status (XPROCESS (process), Qrun);
1710 1706
1707#ifdef SIGCHLD
1711 /* Delay interrupts until we have a chance to store 1708 /* Delay interrupts until we have a chance to store
1712 the new fork's pid in its process structure */ 1709 the new fork's pid in its process structure */
1713 sigemptyset (&blocked); 1710 sigemptyset (&blocked);
1714#ifdef SIGCHLD
1715 sigaddset (&blocked, SIGCHLD); 1711 sigaddset (&blocked, SIGCHLD);
1716#endif
1717#ifdef HAVE_WORKING_VFORK
1718 /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal',
1719 this sets the parent's signal handlers as well as the child's.
1720 So delay all interrupts whose handlers the child might munge,
1721 and record the current handlers so they can be restored later. */
1722 sigaddset (&blocked, SIGINT ); sigaction (SIGINT , 0, &sigint_action );
1723 sigaddset (&blocked, SIGQUIT); sigaction (SIGQUIT, 0, &sigquit_action);
1724 sigaddset (&blocked, SIGPIPE); sigaction (SIGPIPE, 0, &sigpipe_action);
1725#ifdef AIX
1726 sigaddset (&blocked, SIGHUP ); sigaction (SIGHUP , 0, &sighup_action );
1727#endif
1728#endif /* HAVE_WORKING_VFORK */
1729 pthread_sigmask (SIG_BLOCK, &blocked, &procmask); 1712 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
1713#endif
1730 1714
1731 FD_SET (inchannel, &input_wait_mask); 1715 FD_SET (inchannel, &input_wait_mask);
1732 FD_SET (inchannel, &non_keyboard_wait_mask); 1716 FD_SET (inchannel, &non_keyboard_wait_mask);
@@ -1879,8 +1863,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1879 in the child. */ 1863 in the child. */
1880 signal (SIGPIPE, SIG_DFL); 1864 signal (SIGPIPE, SIG_DFL);
1881 1865
1866#ifdef SIGCHLD
1882 /* Stop blocking signals in the child. */ 1867 /* Stop blocking signals in the child. */
1883 pthread_sigmask (SIG_SETMASK, &procmask, 0); 1868 pthread_sigmask (SIG_SETMASK, &procmask, 0);
1869#endif
1884 1870
1885 if (pty_flag) 1871 if (pty_flag)
1886 child_setup_tty (xforkout); 1872 child_setup_tty (xforkout);
@@ -1959,19 +1945,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1959#endif 1945#endif
1960 } 1946 }
1961 1947
1962 /* Restore the signal state whether vfork succeeded or not. 1948#ifdef SIGCHLD
1963 (We will signal an error, below, if it failed.) */
1964#ifdef HAVE_WORKING_VFORK
1965 /* Restore the parent's signal handlers. */
1966 sigaction (SIGINT, &sigint_action, 0);
1967 sigaction (SIGQUIT, &sigquit_action, 0);
1968 sigaction (SIGPIPE, &sigpipe_action, 0);
1969#ifdef AIX
1970 sigaction (SIGHUP, &sighup_action, 0);
1971#endif
1972#endif /* HAVE_WORKING_VFORK */
1973 /* Stop blocking signals in the parent. */ 1949 /* Stop blocking signals in the parent. */
1974 pthread_sigmask (SIG_SETMASK, &procmask, 0); 1950 pthread_sigmask (SIG_SETMASK, &procmask, 0);
1951#endif
1975 1952
1976 /* Now generate the error if vfork failed. */ 1953 /* Now generate the error if vfork failed. */
1977 if (pid < 0) 1954 if (pid < 0)
@@ -4395,10 +4372,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4395 Otherwise, do pending quit if requested. */ 4372 Otherwise, do pending quit if requested. */
4396 if (read_kbd >= 0) 4373 if (read_kbd >= 0)
4397 QUIT; 4374 QUIT;
4398#ifdef SYNC_INPUT
4399 else 4375 else
4400 process_pending_signals (); 4376 process_pending_signals ();
4401#endif
4402 4377
4403 /* Exit now if the cell we're waiting for became non-nil. */ 4378 /* Exit now if the cell we're waiting for became non-nil. */
4404 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) 4379 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
diff --git a/src/ralloc.c b/src/ralloc.c
index b0134ea730a..9a4b1ada229 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1204,9 +1204,15 @@ r_alloc_init (void)
1204 UNBLOCK_INPUT; 1204 UNBLOCK_INPUT;
1205#else 1205#else
1206#ifndef SYSTEM_MALLOC 1206#ifndef SYSTEM_MALLOC
1207 /* Give GNU malloc's morecore some hysteresis 1207 /* Give GNU malloc's morecore some hysteresis so that we move all
1208 so that we move all the relocatable blocks much less often. */ 1208 the relocatable blocks much less often. The number used to be
1209 __malloc_extra_blocks = 64; 1209 64, but alloc.c would override that with 32 in code that was
1210 removed when SYNC_INPUT became the only input handling mode.
1211 That code was conditioned on !DOUG_LEA_MALLOC, so the call to
1212 mallopt above is left unchanged. (Actually, I think there's no
1213 system nowadays that uses DOUG_LEA_MALLOC and also uses
1214 REL_ALLOC.) */
1215 __malloc_extra_blocks = 32;
1210#endif 1216#endif
1211#endif 1217#endif
1212 1218
diff --git a/src/regex.c b/src/regex.c
index 92264ccae23..17562043df1 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -1831,9 +1831,9 @@ typedef struct
1831/* The next available element. */ 1831/* The next available element. */
1832#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) 1832#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
1833 1833
1834/* Explicit quit checking is only used on NTemacs and whenever we 1834/* Explicit quit checking is needed for Emacs, which uses polling to
1835 use polling to process input events. */ 1835 process input events. */
1836#if defined emacs && (defined WINDOWSNT || defined SYNC_INPUT) && defined QUIT 1836#ifdef emacs
1837extern int immediate_quit; 1837extern int immediate_quit;
1838# define IMMEDIATE_QUIT_CHECK \ 1838# define IMMEDIATE_QUIT_CHECK \
1839 do { \ 1839 do { \
diff --git a/src/search.c b/src/search.c
index 99fd7971e4c..1735ade5d8a 100644
--- a/src/search.c
+++ b/src/search.c
@@ -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);
diff --git a/src/sysdep.c b/src/sysdep.c
index 9065b38d6fc..dbfd9efc7d4 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1447,27 +1447,21 @@ emacs_sigaction_init (struct sigaction *action, signal_handler_t handler)
1447 action->sa_handler = handler; 1447 action->sa_handler = handler;
1448 action->sa_flags = 0; 1448 action->sa_flags = 0;
1449#if defined (SA_RESTART) 1449#if defined (SA_RESTART)
1450 /* Emacs mostly works better with restartable system services. If this 1450 /* SA_RESTART causes interruptible functions with timeouts (e.g.,
1451 flag exists, we probably want to turn it on here. 1451 'select') to reset their timeout on some platforms (e.g.,
1452 However, on some systems (only hpux11 at present) this resets the 1452 HP-UX 11), which is not what we want. Also, when Emacs is
1453 timeout of `select' which means that `select' never finishes if 1453 interactive, we don't want SA_RESTART because we need to poll
1454 it keeps getting signals.
1455 We define BROKEN_SA_RESTART on those systems. */
1456 /* It's not clear why the comment above says "mostly works better". --Stef
1457 When SYNC_INPUT is set, we don't want SA_RESTART because we need to poll
1458 for pending input so we need long-running syscalls to be interrupted 1454 for pending input so we need long-running syscalls to be interrupted
1459 after a signal that sets the interrupt_input_pending flag. */ 1455 after a signal that sets the interrupt_input_pending flag. */
1460 /* Non-interactive keyboard input goes through stdio, where we always 1456 /* Non-interactive keyboard input goes through stdio, where we always
1461 want restartable system calls. */ 1457 want restartable system calls. */
1462# if defined (BROKEN_SA_RESTART) || defined (SYNC_INPUT)
1463 if (noninteractive) 1458 if (noninteractive)
1464# endif
1465 action->sa_flags = SA_RESTART; 1459 action->sa_flags = SA_RESTART;
1466#endif 1460#endif
1467} 1461}
1468 1462
1469#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD 1463#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
1470pthread_t main_thread; 1464static pthread_t main_thread;
1471#endif 1465#endif
1472 1466
1473/* If we are on the main thread, handle the signal SIG with HANDLER. 1467/* If we are on the main thread, handle the signal SIG with HANDLER.
@@ -1914,11 +1908,9 @@ emacs_write (int fildes, const char *buf, ptrdiff_t nbyte)
1914 { 1908 {
1915 if (errno == EINTR) 1909 if (errno == EINTR)
1916 { 1910 {
1917#ifdef SYNC_INPUT
1918 /* I originally used `QUIT' but that might causes files to 1911 /* I originally used `QUIT' but that might causes files to
1919 be truncated if you hit C-g in the middle of it. --Stef */ 1912 be truncated if you hit C-g in the middle of it. --Stef */
1920 process_pending_signals (); 1913 process_pending_signals ();
1921#endif
1922 continue; 1914 continue;
1923 } 1915 }
1924 else 1916 else
diff --git a/src/syssignal.h b/src/syssignal.h
index 5e733dd812d..e309e6725b7 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -64,8 +64,4 @@ extern void emacs_sigaction_init (struct sigaction *, signal_handler_t);
64char *strsignal (int); 64char *strsignal (int);
65#endif 65#endif
66 66
67#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
68extern pthread_t main_thread;
69#endif
70
71void handle_on_main_thread (int, signal_handler_t); 67void handle_on_main_thread (int, signal_handler_t);
diff --git a/src/termhooks.h b/src/termhooks.h
index 46962a1217d..53e401de409 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -592,23 +592,14 @@ struct terminal
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 BUF, the size of which is given in
595 SIZE. EXPECTED is non-zero if the caller suspects that new input 595 SIZE.
596 is available.
597 596
598 A positive return value indicates that that many input events 597 A positive return value indicates that that many input events
599 where read into BUF. 598 were read into BUF.
600 Zero means no events were immediately available. 599 Zero means no events were immediately available.
601 A value of -1 means a transient read error, while -2 indicates 600 A value of -1 means a transient read error, while -2 indicates
602 that the device was closed (hangup), and it should be deleted. 601 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, 602 int (*read_socket_hook) (struct terminal *terminal,
611 int expected,
612 struct input_event *hold_quit); 603 struct input_event *hold_quit);
613 604
614 /* Called when a frame's display becomes entirely up to date. */ 605 /* Called when a frame's display becomes entirely up to date. */
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 05a16466dfb..d38b91e955a 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) - Septemper 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/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/w32inevt.c b/src/w32inevt.c
index ee07db5335b..a96d8d70483 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -744,10 +744,9 @@ maybe_generate_resize_event (void)
744 744
745int 745int
746w32_console_read_socket (struct terminal *terminal, 746w32_console_read_socket (struct terminal *terminal,
747 int expected,
748 struct input_event *hold_quit) 747 struct input_event *hold_quit)
749{ 748{
750 int nev, ret = 0, add; 749 int nev, add;
751 int isdead; 750 int isdead;
752 751
753 if (interrupt_input_blocked) 752 if (interrupt_input_blocked)
@@ -767,8 +766,7 @@ w32_console_read_socket (struct terminal *terminal,
767 /* If nev == -1, there was some kind of error 766 /* If nev == -1, there was some kind of error
768 If nev == 0 then waitp must be zero and no events were available 767 If nev == 0 then waitp must be zero and no events were available
769 so return. */ 768 so return. */
770 UNBLOCK_INPUT; 769 break;
771 return nev;
772 } 770 }
773 771
774 while (nev > 0) 772 while (nev > 0)
@@ -812,9 +810,6 @@ w32_console_read_socket (struct terminal *terminal,
812 queue_ptr++; 810 queue_ptr++;
813 nev--; 811 nev--;
814 } 812 }
815
816 if (ret > 0 || expected == 0)
817 break;
818 } 813 }
819 814
820 /* We don't get told about changes in the window size (only the buffer 815 /* We don't get told about changes in the window size (only the buffer
@@ -824,5 +819,5 @@ w32_console_read_socket (struct terminal *terminal,
824 maybe_generate_resize_event (); 819 maybe_generate_resize_event ();
825 820
826 UNBLOCK_INPUT; 821 UNBLOCK_INPUT;
827 return ret; 822 return nev;
828} 823}
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/w32term.c b/src/w32term.c
index 69a16e1852b..b8227c52fed 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -4137,8 +4137,6 @@ static char dbcs_lead = 0;
4137 We return the number of characters stored into the buffer, 4137 We return the number of characters stored into the buffer,
4138 thus pretending to be `read'. 4138 thus pretending to be `read'.
4139 4139
4140 EXPECTED is nonzero if the caller knows input is available.
4141
4142 Some of these messages are reposted back to the message queue since the 4140 Some of these messages are reposted back to the message queue since the
4143 system calls the windows proc directly in a context where we cannot return 4141 system calls the windows proc directly in a context where we cannot return
4144 the data nor can we guarantee the state we are in. So if we dispatch them 4142 the data nor can we guarantee the state we are in. So if we dispatch them
@@ -4149,7 +4147,7 @@ static char dbcs_lead = 0;
4149*/ 4147*/
4150 4148
4151static int 4149static int
4152w32_read_socket (struct terminal *terminal, int expected, 4150w32_read_socket (struct terminal *terminal,
4153 struct input_event *hold_quit) 4151 struct input_event *hold_quit)
4154{ 4152{
4155 int count = 0; 4153 int count = 0;
@@ -4162,6 +4160,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4162 if (interrupt_input_blocked) 4160 if (interrupt_input_blocked)
4163 { 4161 {
4164 interrupt_input_pending = 1; 4162 interrupt_input_pending = 1;
4163 pending_signals = 1;
4165 return -1; 4164 return -1;
4166 } 4165 }
4167 4166
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 33f40fc7c01..018dd14cb80 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -303,138 +303,6 @@ drain_message_queue (void)
303 } 303 }
304} 304}
305 305
306
307/*
308 * XParseGeometry parses strings of the form
309 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
310 * width, height, xoffset, and yoffset are unsigned integers.
311 * Example: "=80x24+300-49"
312 * The equal sign is optional.
313 * It returns a bitmask that indicates which of the four values
314 * were actually found in the string. For each value found,
315 * the corresponding argument is updated; for each value
316 * not found, the corresponding argument is left unchanged.
317 */
318
319static int
320read_integer (register char *string, char **NextString)
321{
322 register int Result = 0;
323 int Sign = 1;
324
325 if (*string == '+')
326 string++;
327 else if (*string == '-')
328 {
329 string++;
330 Sign = -1;
331 }
332 for (; (*string >= '0') && (*string <= '9'); string++)
333 {
334 Result = (Result * 10) + (*string - '0');
335 }
336 *NextString = string;
337 if (Sign >= 0)
338 return (Result);
339 else
340 return (-Result);
341}
342
343int
344XParseGeometry (char *string,
345 int *x, int *y,
346 unsigned int *width, unsigned int *height)
347{
348 int mask = NoValue;
349 register char *strind;
350 unsigned int tempWidth, tempHeight;
351 int tempX, tempY;
352 char *nextCharacter;
353
354 if ((string == NULL) || (*string == '\0')) return (mask);
355 if (*string == '=')
356 string++; /* ignore possible '=' at beg of geometry spec */
357
358 strind = (char *)string;
359 if (*strind != '+' && *strind != '-' && *strind != 'x')
360 {
361 tempWidth = read_integer (strind, &nextCharacter);
362 if (strind == nextCharacter)
363 return (0);
364 strind = nextCharacter;
365 mask |= WidthValue;
366 }
367
368 if (*strind == 'x' || *strind == 'X')
369 {
370 strind++;
371 tempHeight = read_integer (strind, &nextCharacter);
372 if (strind == nextCharacter)
373 return (0);
374 strind = nextCharacter;
375 mask |= HeightValue;
376 }
377
378 if ((*strind == '+') || (*strind == '-'))
379 {
380 if (*strind == '-')
381 {
382 strind++;
383 tempX = -read_integer (strind, &nextCharacter);
384 if (strind == nextCharacter)
385 return (0);
386 strind = nextCharacter;
387 mask |= XNegative;
388
389 }
390 else
391 {
392 strind++;
393 tempX = read_integer (strind, &nextCharacter);
394 if (strind == nextCharacter)
395 return (0);
396 strind = nextCharacter;
397 }
398 mask |= XValue;
399 if ((*strind == '+') || (*strind == '-'))
400 {
401 if (*strind == '-')
402 {
403 strind++;
404 tempY = -read_integer (strind, &nextCharacter);
405 if (strind == nextCharacter)
406 return (0);
407 strind = nextCharacter;
408 mask |= YNegative;
409 }
410 else
411 {
412 strind++;
413 tempY = read_integer (strind, &nextCharacter);
414 if (strind == nextCharacter)
415 return (0);
416 strind = nextCharacter;
417 }
418 mask |= YValue;
419 }
420 }
421
422 /* If strind isn't at the end of the string then it's an invalid
423 geometry specification. */
424
425 if (*strind != '\0') return (0);
426
427 if (mask & XValue)
428 *x = tempX;
429 if (mask & YValue)
430 *y = tempY;
431 if (mask & WidthValue)
432 *width = tempWidth;
433 if (mask & HeightValue)
434 *height = tempHeight;
435 return (mask);
436}
437
438/* x_sync is a no-op on W32. */ 306/* x_sync is a no-op on W32. */
439void 307void
440x_sync (struct frame *f) 308x_sync (struct frame *f)
diff --git a/src/window.c b/src/window.c
index fbccab8b358..a6f1104587e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -3462,7 +3462,11 @@ make_window (void)
3462 wset_vertical_scroll_bar_type (w, Qt); 3462 wset_vertical_scroll_bar_type (w, Qt);
3463 wset_window_end_pos (w, make_number (0)); 3463 wset_window_end_pos (w, make_number (0));
3464 wset_window_end_vpos (w, make_number (0)); 3464 wset_window_end_vpos (w, make_number (0));
3465 3465 /* These Lisp fields are marked specially so they're not set to nil by
3466 allocate_window. */
3467 wset_prev_buffers (w, Qnil);
3468 wset_next_buffers (w, Qnil);
3469
3466 /* Initialize non-Lisp data. Note that allocate_window zeroes out all 3470 /* 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. */ 3471 non-Lisp data, so do it only for slots which should not be zero. */
3468 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3472 w->nrows_scale_factor = w->ncols_scale_factor = 1;
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 8e0975cf65a..f00719be37a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -7755,7 +7755,7 @@ compute_stop_pos_backwards (struct it *it)
7755 { 7755 {
7756 it->end_charpos = min (charpos + 1, ZV); 7756 it->end_charpos = min (charpos + 1, ZV);
7757 charpos = max (charpos - SCAN_BACK_LIMIT, BEGV); 7757 charpos = max (charpos - SCAN_BACK_LIMIT, BEGV);
7758 SET_TEXT_POS (pos, charpos, BYTE_TO_CHAR (charpos)); 7758 SET_TEXT_POS (pos, charpos, CHAR_TO_BYTE (charpos));
7759 reseat_1 (it, pos, 0); 7759 reseat_1 (it, pos, 0);
7760 compute_stop_pos (it); 7760 compute_stop_pos (it);
7761 /* We must advance forward, right? */ 7761 /* We must advance forward, right? */
@@ -9290,12 +9290,6 @@ add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
9290 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 9290 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9291 USE_SAFE_ALLOCA; 9291 USE_SAFE_ALLOCA;
9292 9292
9293 /* Do nothing if called asynchronously. Inserting text into
9294 a buffer may call after-change-functions and alike and
9295 that would means running Lisp asynchronously. */
9296 if (handling_signal)
9297 return;
9298
9299 fmt = msg = Qnil; 9293 fmt = msg = Qnil;
9300 GCPRO4 (fmt, msg, arg1, arg2); 9294 GCPRO4 (fmt, msg, arg1, arg2);
9301 9295
@@ -16750,28 +16744,33 @@ try_window_reusing_current_matrix (struct window *w)
16750 } 16744 }
16751 if (row < bottom_row) 16745 if (row < bottom_row)
16752 { 16746 {
16753 struct glyph *glyph = row->glyphs[TEXT_AREA] + w->cursor.hpos; 16747 /* Can't simply scan the row for point with
16754 struct glyph *end = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA]; 16748 bidi-reordered glyph rows. Let set_cursor_from_row
16755 16749 figure out where to put the cursor, and if it fails,
16756 /* Can't use this optimization with bidi-reordered glyph 16750 give up. */
16757 rows, unless cursor is already at point. */
16758 if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))) 16751 if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
16759 { 16752 {
16760 if (!(w->cursor.hpos >= 0 16753 if (!set_cursor_from_row (w, row, w->current_matrix,
16761 && w->cursor.hpos < row->used[TEXT_AREA] 16754 0, 0, 0, 0))
16762 && BUFFERP (glyph->object) 16755 {
16763 && glyph->charpos == PT)) 16756 clear_glyph_matrix (w->desired_matrix);
16764 return 0; 16757 return 0;
16758 }
16765 } 16759 }
16766 else 16760 else
16767 for (; glyph < end 16761 {
16768 && (!BUFFERP (glyph->object) 16762 struct glyph *glyph = row->glyphs[TEXT_AREA] + w->cursor.hpos;
16769 || glyph->charpos < PT); 16763 struct glyph *end = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA];
16770 glyph++) 16764
16771 { 16765 for (; glyph < end
16772 w->cursor.hpos++; 16766 && (!BUFFERP (glyph->object)
16773 w->cursor.x += glyph->pixel_width; 16767 || glyph->charpos < PT);
16774 } 16768 glyph++)
16769 {
16770 w->cursor.hpos++;
16771 w->cursor.x += glyph->pixel_width;
16772 }
16773 }
16775 } 16774 }
16776 } 16775 }
16777 16776
diff --git a/src/xterm.c b/src/xterm.c
index 900a1d78b80..8c955d0e576 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -7109,19 +7109,15 @@ 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;
@@ -7129,25 +7125,17 @@ XTread_socket (struct terminal *terminal, int expected, struct input_event *hold
7129 if (interrupt_input_blocked) 7125 if (interrupt_input_blocked)
7130 { 7126 {
7131 interrupt_input_pending = 1; 7127 interrupt_input_pending = 1;
7132#ifdef SYNC_INPUT
7133 pending_signals = 1; 7128 pending_signals = 1;
7134#endif
7135 return -1; 7129 return -1;
7136 } 7130 }
7137 7131
7138 interrupt_input_pending = 0; 7132 interrupt_input_pending = 0;
7139#ifdef SYNC_INPUT
7140 pending_signals = pending_atimers; 7133 pending_signals = pending_atimers;
7141#endif
7142 BLOCK_INPUT; 7134 BLOCK_INPUT;
7143 7135
7144 /* So people can tell when we have read the available input. */ 7136 /* So people can tell when we have read the available input. */
7145 input_signal_count++; 7137 input_signal_count++;
7146 7138
7147#ifndef SYNC_INPUT
7148 ++handling_signal;
7149#endif
7150
7151 /* For debugging, this gives a way to fake an I/O error. */ 7139 /* For debugging, this gives a way to fake an I/O error. */
7152 if (terminal->display_info.x == XTread_socket_fake_io_error) 7140 if (terminal->display_info.x == XTread_socket_fake_io_error)
7153 { 7141 {
@@ -7236,9 +7224,6 @@ XTread_socket (struct terminal *terminal, int expected, struct input_event *hold
7236 pending_autoraise_frame = 0; 7224 pending_autoraise_frame = 0;
7237 } 7225 }
7238 7226
7239#ifndef SYNC_INPUT
7240 --handling_signal;
7241#endif
7242 UNBLOCK_INPUT; 7227 UNBLOCK_INPUT;
7243 7228
7244 return count; 7229 return count;
@@ -7788,7 +7773,6 @@ x_connection_closed (Display *dpy, const char *error_message)
7788 7773
7789 error_msg = alloca (strlen (error_message) + 1); 7774 error_msg = alloca (strlen (error_message) + 1);
7790 strcpy (error_msg, error_message); 7775 strcpy (error_msg, error_message);
7791 handling_signal = 0;
7792 7776
7793 /* Inhibit redisplay while frames are being deleted. */ 7777 /* Inhibit redisplay while frames are being deleted. */
7794 specbind (Qinhibit_redisplay, Qt); 7778 specbind (Qinhibit_redisplay, Qt);