aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog26
-rw-r--r--src/alloc.c489
-rw-r--r--src/dispnew.c2
-rw-r--r--src/keyboard.c47
-rw-r--r--src/keyboard.h5
-rw-r--r--src/nsterm.m68
-rw-r--r--src/termhooks.h15
-rw-r--r--src/w32gui.h3
-rw-r--r--src/w32inevt.c1
-rw-r--r--src/w32inevt.h2
-rw-r--r--src/w32term.c4
-rw-r--r--src/window.c6
-rw-r--r--src/window.h15
-rw-r--r--src/xterm.c12
14 files changed, 175 insertions, 520 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e8827c2de18..c3ce1ee1b0b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,29 @@
12012-09-20 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * alloc.c (mark_object) <PVEC_WINDOW>: Mark prev/next_buffers *after*
4 calling mark_vectorlike since that's the one that marks the window.
5 (mark_discard_killed_buffers): Mark the final cdr.
6 * window.h (struct window): Move prev/next_buffers to the
7 non-standard fields.
8 * window.c (make_window): Initialize prev/next_buffers manually.
9
102012-09-20 Paul Eggert <eggert@cs.ucla.edu>
11
12 Omit unused arg EXPECTED from socket hooks.
13 * keyboard.c (gobble_input, read_avail_input, tty_read_avail_input):
14 * nsterm.m (ns_term_init):
15 * termhooks.h (struct terminal.read_socket_hook):
16 * w32inevt.c (w32_console_read_socket):
17 * w32term.c (w32_read_socket):
18 * xterm.c (XTread_socket):
19 Omit unused arg EXPECTED. All callers changed.
20 (store_user_signal_events): Return void, not int, since callers no
21 longer care about the return value. All uses changed.
22
232012-09-20 Juanma Barranquero <lekktu@gmail.com>
24
25 * w32gui.h (XParseGeometry): Do not declare.
26
12012-09-19 Paul Eggert <eggert@cs.ucla.edu> 272012-09-19 Paul Eggert <eggert@cs.ucla.edu>
2 28
3 * w32inevt.c (w32_console_read_socket): Return -1 on failure, not 0. 29 * w32inevt.c (w32_console_read_socket): Return -1 on failure, not 0.
diff --git a/src/alloc.c b/src/alloc.c
index 61cb7086c25..02ba2f5f9e3 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -24,7 +24,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24 24
25#include <stdio.h> 25#include <stdio.h>
26#include <limits.h> /* For CHAR_BIT. */ 26#include <limits.h> /* For CHAR_BIT. */
27#include <setjmp.h>
28 27
29#ifdef ENABLE_CHECKING 28#ifdef ENABLE_CHECKING
30#include <signal.h> /* For SIGABRT. */ 29#include <signal.h> /* For SIGABRT. */
@@ -45,7 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
45#include "frame.h" 44#include "frame.h"
46#include "blockinput.h" 45#include "blockinput.h"
47#include "termhooks.h" /* For struct terminal. */ 46#include "termhooks.h" /* For struct terminal. */
48#include <setjmp.h> 47
49#include <verify.h> 48#include <verify.h>
50 49
51/* GC_CHECK_MARKED_OBJECTS means do sanity checks on allocated objects. 50/* GC_CHECK_MARKED_OBJECTS means do sanity checks on allocated objects.
@@ -86,66 +85,8 @@ extern void *sbrk ();
86 85
87#define MMAP_MAX_AREAS 100000000 86#define MMAP_MAX_AREAS 100000000
88 87
89#else /* not DOUG_LEA_MALLOC */
90
91/* The following come from gmalloc.c. */
92
93extern size_t _bytes_used;
94extern size_t __malloc_extra_blocks;
95extern void *_malloc_internal (size_t);
96extern void _free_internal (void *);
97
98#endif /* not DOUG_LEA_MALLOC */ 88#endif /* not DOUG_LEA_MALLOC */
99 89
100#if ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT
101#ifdef HAVE_PTHREAD
102
103/* When GTK uses the file chooser dialog, different backends can be loaded
104 dynamically. One such a backend is the Gnome VFS backend that gets loaded
105 if you run Gnome. That backend creates several threads and also allocates
106 memory with malloc.
107
108 Also, gconf and gsettings may create several threads.
109
110 If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_*
111 functions below are called from malloc, there is a chance that one
112 of these threads preempts the Emacs main thread and the hook variables
113 end up in an inconsistent state. So we have a mutex to prevent that (note
114 that the backend handles concurrent access to malloc within its own threads
115 but Emacs code running in the main thread is not included in that control).
116
117 When UNBLOCK_INPUT is called, reinvoke_input_signal may be called. If this
118 happens in one of the backend threads we will have two threads that tries
119 to run Emacs code at once, and the code is not prepared for that.
120 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */
121
122static pthread_mutex_t alloc_mutex;
123
124#define BLOCK_INPUT_ALLOC \
125 do \
126 { \
127 if (pthread_equal (pthread_self (), main_thread)) \
128 BLOCK_INPUT; \
129 pthread_mutex_lock (&alloc_mutex); \
130 } \
131 while (0)
132#define UNBLOCK_INPUT_ALLOC \
133 do \
134 { \
135 pthread_mutex_unlock (&alloc_mutex); \
136 if (pthread_equal (pthread_self (), main_thread)) \
137 UNBLOCK_INPUT; \
138 } \
139 while (0)
140
141#else /* ! defined HAVE_PTHREAD */
142
143#define BLOCK_INPUT_ALLOC BLOCK_INPUT
144#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT
145
146#endif /* ! defined HAVE_PTHREAD */
147#endif /* ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT */
148
149/* 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
150 to a struct Lisp_String. */ 91 to a struct Lisp_String. */
151 92
@@ -204,10 +145,6 @@ static char *spare_memory[7];
204 145
205#define SPARE_MEMORY (1 << 14) 146#define SPARE_MEMORY (1 << 14)
206 147
207/* Number of extra blocks malloc should get when it needs more core. */
208
209static int malloc_hysteresis;
210
211/* 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
212 (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
213 space (pure), on some systems. We have not implemented the 150 space (pure), on some systems. We have not implemented the
@@ -412,12 +349,12 @@ static void mark_memory (void *, void *);
412static void mem_init (void); 349static void mem_init (void);
413static struct mem_node *mem_insert (void *, void *, enum mem_type); 350static struct mem_node *mem_insert (void *, void *, enum mem_type);
414static void mem_insert_fixup (struct mem_node *); 351static void mem_insert_fixup (struct mem_node *);
415#endif
416static void mem_rotate_left (struct mem_node *); 352static void mem_rotate_left (struct mem_node *);
417static void mem_rotate_right (struct mem_node *); 353static void mem_rotate_right (struct mem_node *);
418static void mem_delete (struct mem_node *); 354static void mem_delete (struct mem_node *);
419static void mem_delete_fixup (struct mem_node *); 355static void mem_delete_fixup (struct mem_node *);
420static inline struct mem_node *mem_find (void *); 356static inline struct mem_node *mem_find (void *);
357#endif
421 358
422 359
423#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS 360#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS
@@ -586,39 +523,17 @@ xmalloc_get_size (unsigned char *ptr)
586} 523}
587 524
588 525
589/* The call depth in overrun_check functions. For example, this might happen:
590 xmalloc()
591 overrun_check_malloc()
592 -> malloc -> (via hook)_-> emacs_blocked_malloc
593 -> overrun_check_malloc
594 call malloc (hooks are NULL, so real malloc is called).
595 malloc returns 10000.
596 add overhead, return 10016.
597 <- (back in overrun_check_malloc)
598 add overhead again, return 10032
599 xmalloc returns 10032.
600
601 (time passes).
602
603 xfree(10032)
604 overrun_check_free(10032)
605 decrease overhead
606 free(10016) <- crash, because 10000 is the original pointer. */
607
608static ptrdiff_t check_depth;
609
610/* Like malloc, but wraps allocated block with header and trailer. */ 526/* Like malloc, but wraps allocated block with header and trailer. */
611 527
612static void * 528static void *
613overrun_check_malloc (size_t size) 529overrun_check_malloc (size_t size)
614{ 530{
615 register unsigned char *val; 531 register unsigned char *val;
616 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; 532 if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size)
617 if (SIZE_MAX - overhead < size)
618 emacs_abort (); 533 emacs_abort ();
619 534
620 val = malloc (size + overhead); 535 val = malloc (size + XMALLOC_OVERRUN_CHECK_OVERHEAD);
621 if (val && check_depth == 1) 536 if (val)
622 { 537 {
623 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); 538 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE);
624 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; 539 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE;
@@ -626,7 +541,6 @@ overrun_check_malloc (size_t size)
626 memcpy (val + size, xmalloc_overrun_check_trailer, 541 memcpy (val + size, xmalloc_overrun_check_trailer,
627 XMALLOC_OVERRUN_CHECK_SIZE); 542 XMALLOC_OVERRUN_CHECK_SIZE);
628 } 543 }
629 --check_depth;
630 return val; 544 return val;
631} 545}
632 546
@@ -638,12 +552,10 @@ static void *
638overrun_check_realloc (void *block, size_t size) 552overrun_check_realloc (void *block, size_t size)
639{ 553{
640 register unsigned char *val = (unsigned char *) block; 554 register unsigned char *val = (unsigned char *) block;
641 int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; 555 if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size)
642 if (SIZE_MAX - overhead < size)
643 emacs_abort (); 556 emacs_abort ();
644 557
645 if (val 558 if (val
646 && check_depth == 1
647 && memcmp (xmalloc_overrun_check_header, 559 && memcmp (xmalloc_overrun_check_header,
648 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, 560 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE,
649 XMALLOC_OVERRUN_CHECK_SIZE) == 0) 561 XMALLOC_OVERRUN_CHECK_SIZE) == 0)
@@ -657,9 +569,9 @@ overrun_check_realloc (void *block, size_t size)
657 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE); 569 memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE);
658 } 570 }
659 571
660 val = realloc (val, size + overhead); 572 val = realloc (val, size + XMALLOC_OVERRUN_CHECK_OVERHEAD);
661 573
662 if (val && check_depth == 1) 574 if (val)
663 { 575 {
664 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); 576 memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE);
665 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; 577 val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE;
@@ -667,7 +579,6 @@ overrun_check_realloc (void *block, size_t size)
667 memcpy (val + size, xmalloc_overrun_check_trailer, 579 memcpy (val + size, xmalloc_overrun_check_trailer,
668 XMALLOC_OVERRUN_CHECK_SIZE); 580 XMALLOC_OVERRUN_CHECK_SIZE);
669 } 581 }
670 --check_depth;
671 return val; 582 return val;
672} 583}
673 584
@@ -678,9 +589,7 @@ overrun_check_free (void *block)
678{ 589{
679 unsigned char *val = (unsigned char *) block; 590 unsigned char *val = (unsigned char *) block;
680 591
681 ++check_depth;
682 if (val 592 if (val
683 && check_depth == 1
684 && memcmp (xmalloc_overrun_check_header, 593 && memcmp (xmalloc_overrun_check_header,
685 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, 594 val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE,
686 XMALLOC_OVERRUN_CHECK_SIZE) == 0) 595 XMALLOC_OVERRUN_CHECK_SIZE) == 0)
@@ -700,7 +609,6 @@ overrun_check_free (void *block)
700 } 609 }
701 610
702 free (val); 611 free (val);
703 --check_depth;
704} 612}
705 613
706#undef malloc 614#undef malloc
@@ -711,14 +619,33 @@ overrun_check_free (void *block)
711#define free overrun_check_free 619#define free overrun_check_free
712#endif 620#endif
713 621
714#ifdef SYNC_INPUT 622/* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol
715/* 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.
716 there's no need to block input around malloc. */ 624 If that variable is set, block input while in one of Emacs's memory
717#define MALLOC_BLOCK_INPUT ((void)0) 625 allocation functions. There should be no need for this debugging
718#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 ()
719#else 646#else
720#define MALLOC_BLOCK_INPUT BLOCK_INPUT 647# define MALLOC_BLOCK_INPUT ((void) 0)
721#define MALLOC_UNBLOCK_INPUT UNBLOCK_INPUT 648# define MALLOC_UNBLOCK_INPUT ((void) 0)
722#endif 649#endif
723 650
724/* Like malloc but check for no memory and block interrupt input.. */ 651/* Like malloc but check for no memory and block interrupt input.. */
@@ -787,8 +714,7 @@ xfree (void *block)
787 free (block); 714 free (block);
788 MALLOC_UNBLOCK_INPUT; 715 MALLOC_UNBLOCK_INPUT;
789 /* We don't call refill_memory_reserve here 716 /* We don't call refill_memory_reserve here
790 because that duplicates doing so in emacs_blocked_free 717 because in practice the call in r_alloc_free seems to suffice. */
791 and the criterion should go there. */
792} 718}
793 719
794 720
@@ -1215,256 +1141,6 @@ lisp_align_free (void *block)
1215} 1141}
1216 1142
1217 1143
1218#ifndef SYSTEM_MALLOC
1219
1220/* Arranging to disable input signals while we're in malloc.
1221
1222 This only works with GNU malloc. To help out systems which can't
1223 use GNU malloc, all the calls to malloc, realloc, and free
1224 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT
1225 pair; unfortunately, we have no idea what C library functions
1226 might call malloc, so we can't really protect them unless you're
1227 using GNU malloc. Fortunately, most of the major operating systems
1228 can use GNU malloc. */
1229
1230#ifndef SYNC_INPUT
1231/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
1232 there's no need to block input around malloc. */
1233
1234#ifndef DOUG_LEA_MALLOC
1235extern void * (*__malloc_hook) (size_t, const void *);
1236extern void * (*__realloc_hook) (void *, size_t, const void *);
1237extern void (*__free_hook) (void *, const void *);
1238/* Else declared in malloc.h, perhaps with an extra arg. */
1239#endif /* DOUG_LEA_MALLOC */
1240static void * (*old_malloc_hook) (size_t, const void *);
1241static void * (*old_realloc_hook) (void *, size_t, const void*);
1242static void (*old_free_hook) (void*, const void*);
1243
1244#ifdef DOUG_LEA_MALLOC
1245# define BYTES_USED (mallinfo ().uordblks)
1246#else
1247# define BYTES_USED _bytes_used
1248#endif
1249
1250#ifdef GC_MALLOC_CHECK
1251static bool dont_register_blocks;
1252#endif
1253
1254static size_t bytes_used_when_reconsidered;
1255
1256/* Value of _bytes_used, when spare_memory was freed. */
1257
1258static size_t bytes_used_when_full;
1259
1260/* This function is used as the hook for free to call. */
1261
1262static void
1263emacs_blocked_free (void *ptr, const void *ptr2)
1264{
1265 BLOCK_INPUT_ALLOC;
1266
1267#ifdef GC_MALLOC_CHECK
1268 if (ptr)
1269 {
1270 struct mem_node *m;
1271
1272 m = mem_find (ptr);
1273 if (m == MEM_NIL || m->start != ptr)
1274 {
1275 fprintf (stderr,
1276 "Freeing `%p' which wasn't allocated with malloc\n", ptr);
1277 emacs_abort ();
1278 }
1279 else
1280 {
1281 /* fprintf (stderr, "free %p...%p (%p)\n", m->start, m->end, ptr); */
1282 mem_delete (m);
1283 }
1284 }
1285#endif /* GC_MALLOC_CHECK */
1286
1287 __free_hook = old_free_hook;
1288 free (ptr);
1289
1290 /* If we released our reserve (due to running out of memory),
1291 and we have a fair amount free once again,
1292 try to set aside another reserve in case we run out once more. */
1293 if (! NILP (Vmemory_full)
1294 /* Verify there is enough space that even with the malloc
1295 hysteresis this call won't run out again.
1296 The code here is correct as long as SPARE_MEMORY
1297 is substantially larger than the block size malloc uses. */
1298 && (bytes_used_when_full
1299 > ((bytes_used_when_reconsidered = BYTES_USED)
1300 + max (malloc_hysteresis, 4) * SPARE_MEMORY)))
1301 refill_memory_reserve ();
1302
1303 __free_hook = emacs_blocked_free;
1304 UNBLOCK_INPUT_ALLOC;
1305}
1306
1307
1308/* This function is the malloc hook that Emacs uses. */
1309
1310static void *
1311emacs_blocked_malloc (size_t size, const void *ptr)
1312{
1313 void *value;
1314
1315 BLOCK_INPUT_ALLOC;
1316 __malloc_hook = old_malloc_hook;
1317#ifdef DOUG_LEA_MALLOC
1318 /* Segfaults on my system. --lorentey */
1319 /* mallopt (M_TOP_PAD, malloc_hysteresis * 4096); */
1320#else
1321 __malloc_extra_blocks = malloc_hysteresis;
1322#endif
1323
1324 value = malloc (size);
1325
1326#ifdef GC_MALLOC_CHECK
1327 {
1328 struct mem_node *m = mem_find (value);
1329 if (m != MEM_NIL)
1330 {
1331 fprintf (stderr, "Malloc returned %p which is already in use\n",
1332 value);
1333 fprintf (stderr, "Region in use is %p...%p, %td bytes, type %d\n",
1334 m->start, m->end, (char *) m->end - (char *) m->start,
1335 m->type);
1336 emacs_abort ();
1337 }
1338
1339 if (!dont_register_blocks)
1340 {
1341 mem_insert (value, (char *) value + max (1, size), allocated_mem_type);
1342 allocated_mem_type = MEM_TYPE_NON_LISP;
1343 }
1344 }
1345#endif /* GC_MALLOC_CHECK */
1346
1347 __malloc_hook = emacs_blocked_malloc;
1348 UNBLOCK_INPUT_ALLOC;
1349
1350 /* fprintf (stderr, "%p malloc\n", value); */
1351 return value;
1352}
1353
1354
1355/* This function is the realloc hook that Emacs uses. */
1356
1357static void *
1358emacs_blocked_realloc (void *ptr, size_t size, const void *ptr2)
1359{
1360 void *value;
1361
1362 BLOCK_INPUT_ALLOC;
1363 __realloc_hook = old_realloc_hook;
1364
1365#ifdef GC_MALLOC_CHECK
1366 if (ptr)
1367 {
1368 struct mem_node *m = mem_find (ptr);
1369 if (m == MEM_NIL || m->start != ptr)
1370 {
1371 fprintf (stderr,
1372 "Realloc of %p which wasn't allocated with malloc\n",
1373 ptr);
1374 emacs_abort ();
1375 }
1376
1377 mem_delete (m);
1378 }
1379
1380 /* fprintf (stderr, "%p -> realloc\n", ptr); */
1381
1382 /* Prevent malloc from registering blocks. */
1383 dont_register_blocks = 1;
1384#endif /* GC_MALLOC_CHECK */
1385
1386 value = realloc (ptr, size);
1387
1388#ifdef GC_MALLOC_CHECK
1389 dont_register_blocks = 0;
1390
1391 {
1392 struct mem_node *m = mem_find (value);
1393 if (m != MEM_NIL)
1394 {
1395 fprintf (stderr, "Realloc returns memory that is already in use\n");
1396 emacs_abort ();
1397 }
1398
1399 /* Can't handle zero size regions in the red-black tree. */
1400 mem_insert (value, (char *) value + max (size, 1), MEM_TYPE_NON_LISP);
1401 }
1402
1403 /* fprintf (stderr, "%p <- realloc\n", value); */
1404#endif /* GC_MALLOC_CHECK */
1405
1406 __realloc_hook = emacs_blocked_realloc;
1407 UNBLOCK_INPUT_ALLOC;
1408
1409 return value;
1410}
1411
1412
1413#ifdef HAVE_PTHREAD
1414/* Called from Fdump_emacs so that when the dumped Emacs starts, it has a
1415 normal malloc. Some thread implementations need this as they call
1416 malloc before main. The pthread_self call in BLOCK_INPUT_ALLOC then
1417 calls malloc because it is the first call, and we have an endless loop. */
1418
1419void
1420reset_malloc_hooks (void)
1421{
1422 __free_hook = old_free_hook;
1423 __malloc_hook = old_malloc_hook;
1424 __realloc_hook = old_realloc_hook;
1425}
1426#endif /* HAVE_PTHREAD */
1427
1428
1429/* Called from main to set up malloc to use our hooks. */
1430
1431void
1432uninterrupt_malloc (void)
1433{
1434#ifdef HAVE_PTHREAD
1435#ifdef DOUG_LEA_MALLOC
1436 pthread_mutexattr_t attr;
1437
1438 /* GLIBC has a faster way to do this, but let's keep it portable.
1439 This is according to the Single UNIX Specification. */
1440 pthread_mutexattr_init (&attr);
1441 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
1442 pthread_mutex_init (&alloc_mutex, &attr);
1443#else /* !DOUG_LEA_MALLOC */
1444 /* Some systems such as Solaris 2.6 don't have a recursive mutex,
1445 and the bundled gmalloc.c doesn't require it. */
1446 pthread_mutex_init (&alloc_mutex, NULL);
1447#endif /* !DOUG_LEA_MALLOC */
1448#endif /* HAVE_PTHREAD */
1449
1450 if (__free_hook != emacs_blocked_free)
1451 old_free_hook = __free_hook;
1452 __free_hook = emacs_blocked_free;
1453
1454 if (__malloc_hook != emacs_blocked_malloc)
1455 old_malloc_hook = __malloc_hook;
1456 __malloc_hook = emacs_blocked_malloc;
1457
1458 if (__realloc_hook != emacs_blocked_realloc)
1459 old_realloc_hook = __realloc_hook;
1460 __realloc_hook = emacs_blocked_realloc;
1461}
1462
1463#endif /* not SYNC_INPUT */
1464#endif /* not SYSTEM_MALLOC */
1465
1466
1467
1468/*********************************************************************** 1144/***********************************************************************
1469 Interval Allocation 1145 Interval Allocation
1470 ***********************************************************************/ 1146 ***********************************************************************/
@@ -1510,8 +1186,6 @@ make_interval (void)
1510{ 1186{
1511 INTERVAL val; 1187 INTERVAL val;
1512 1188
1513 /* eassert (!handling_signal); */
1514
1515 MALLOC_BLOCK_INPUT; 1189 MALLOC_BLOCK_INPUT;
1516 1190
1517 if (interval_free_list) 1191 if (interval_free_list)
@@ -1895,8 +1569,6 @@ allocate_string (void)
1895{ 1569{
1896 struct Lisp_String *s; 1570 struct Lisp_String *s;
1897 1571
1898 /* eassert (!handling_signal); */
1899
1900 MALLOC_BLOCK_INPUT; 1572 MALLOC_BLOCK_INPUT;
1901 1573
1902 /* 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
@@ -2588,8 +2260,6 @@ make_float (double float_value)
2588{ 2260{
2589 register Lisp_Object val; 2261 register Lisp_Object val;
2590 2262
2591 /* eassert (!handling_signal); */
2592
2593 MALLOC_BLOCK_INPUT; 2263 MALLOC_BLOCK_INPUT;
2594 2264
2595 if (float_free_list) 2265 if (float_free_list)
@@ -2697,8 +2367,6 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2697{ 2367{
2698 register Lisp_Object val; 2368 register Lisp_Object val;
2699 2369
2700 /* eassert (!handling_signal); */
2701
2702 MALLOC_BLOCK_INPUT; 2370 MALLOC_BLOCK_INPUT;
2703 2371
2704 if (cons_free_list) 2372 if (cons_free_list)
@@ -3204,9 +2872,6 @@ allocate_vectorlike (ptrdiff_t len)
3204 2872
3205 MALLOC_BLOCK_INPUT; 2873 MALLOC_BLOCK_INPUT;
3206 2874
3207 /* This gets triggered by code which I haven't bothered to fix. --Stef */
3208 /* eassert (!handling_signal); */
3209
3210 if (len == 0) 2875 if (len == 0)
3211 p = XVECTOR (zero_vector); 2876 p = XVECTOR (zero_vector);
3212 else 2877 else
@@ -3491,8 +3156,6 @@ Its value and function definition are void, and its property list is nil. */)
3491 3156
3492 CHECK_STRING (name); 3157 CHECK_STRING (name);
3493 3158
3494 /* eassert (!handling_signal); */
3495
3496 MALLOC_BLOCK_INPUT; 3159 MALLOC_BLOCK_INPUT;
3497 3160
3498 if (symbol_free_list) 3161 if (symbol_free_list)
@@ -3577,8 +3240,6 @@ allocate_misc (enum Lisp_Misc_Type type)
3577{ 3240{
3578 Lisp_Object val; 3241 Lisp_Object val;
3579 3242
3580 /* eassert (!handling_signal); */
3581
3582 MALLOC_BLOCK_INPUT; 3243 MALLOC_BLOCK_INPUT;
3583 3244
3584 if (marker_free_list) 3245 if (marker_free_list)
@@ -3798,12 +3459,6 @@ memory_full (size_t nbytes)
3798 lisp_free (spare_memory[i]); 3459 lisp_free (spare_memory[i]);
3799 spare_memory[i] = 0; 3460 spare_memory[i] = 0;
3800 } 3461 }
3801
3802 /* Record the space now used. When it decreases substantially,
3803 we can refill the memory reserve. */
3804#if !defined SYSTEM_MALLOC && !defined SYNC_INPUT
3805 bytes_used_when_full = BYTES_USED;
3806#endif
3807 } 3462 }
3808 3463
3809 /* 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
@@ -3941,7 +3596,7 @@ mem_insert (void *start, void *end, enum mem_type type)
3941 3596
3942 /* Create a new node. */ 3597 /* Create a new node. */
3943#ifdef GC_MALLOC_CHECK 3598#ifdef GC_MALLOC_CHECK
3944 x = _malloc_internal (sizeof *x); 3599 x = malloc (sizeof *x);
3945 if (x == NULL) 3600 if (x == NULL)
3946 emacs_abort (); 3601 emacs_abort ();
3947#else 3602#else
@@ -4165,7 +3820,7 @@ mem_delete (struct mem_node *z)
4165 mem_delete_fixup (x); 3820 mem_delete_fixup (x);
4166 3821
4167#ifdef GC_MALLOC_CHECK 3822#ifdef GC_MALLOC_CHECK
4168 _free_internal (y); 3823 free (y);
4169#else 3824#else
4170 xfree (y); 3825 xfree (y);
4171#endif 3826#endif
@@ -4762,14 +4417,14 @@ test_setjmp (void)
4762{ 4417{
4763 char buf[10]; 4418 char buf[10];
4764 register int x; 4419 register int x;
4765 jmp_buf jbuf; 4420 sys_jmp_buf jbuf;
4766 4421
4767 /* Arrange for X to be put in a register. */ 4422 /* Arrange for X to be put in a register. */
4768 sprintf (buf, "1"); 4423 sprintf (buf, "1");
4769 x = strlen (buf); 4424 x = strlen (buf);
4770 x = 2 * x - 1; 4425 x = 2 * x - 1;
4771 4426
4772 _setjmp (jbuf); 4427 sys_setjmp (jbuf);
4773 if (longjmps_done == 1) 4428 if (longjmps_done == 1)
4774 { 4429 {
4775 /* Came here after the longjmp at the end of the function. 4430 /* Came here after the longjmp at the end of the function.
@@ -4794,7 +4449,7 @@ test_setjmp (void)
4794 ++longjmps_done; 4449 ++longjmps_done;
4795 x = 2; 4450 x = 2;
4796 if (longjmps_done == 1) 4451 if (longjmps_done == 1)
4797 _longjmp (jbuf, 1); 4452 sys_longjmp (jbuf, 1);
4798} 4453}
4799 4454
4800#endif /* not GC_SAVE_REGISTERS_ON_STACK && not GC_SETJMP_WORKS */ 4455#endif /* not GC_SAVE_REGISTERS_ON_STACK && not GC_SETJMP_WORKS */
@@ -4900,7 +4555,7 @@ mark_stack (void)
4900 /* jmp_buf may not be aligned enough on darwin-ppc64 */ 4555 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4901 union aligned_jmpbuf { 4556 union aligned_jmpbuf {
4902 Lisp_Object o; 4557 Lisp_Object o;
4903 jmp_buf j; 4558 sys_jmp_buf j;
4904 } j; 4559 } j;
4905 volatile bool stack_grows_down_p = (char *) &j > (char *) stack_base; 4560 volatile bool stack_grows_down_p = (char *) &j > (char *) stack_base;
4906#endif 4561#endif
@@ -4936,7 +4591,7 @@ mark_stack (void)
4936 } 4591 }
4937#endif /* GC_SETJMP_WORKS */ 4592#endif /* GC_SETJMP_WORKS */
4938 4593
4939 _setjmp (j.j); 4594 sys_setjmp (j.j);
4940 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j; 4595 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j;
4941#endif /* not GC_SAVE_REGISTERS_ON_STACK */ 4596#endif /* not GC_SAVE_REGISTERS_ON_STACK */
4942#endif /* not HAVE___BUILTIN_UNWIND_INIT */ 4597#endif /* not HAVE___BUILTIN_UNWIND_INIT */
@@ -5865,16 +5520,16 @@ mark_buffer (struct buffer *buffer)
5865 mark_buffer (buffer->base_buffer); 5520 mark_buffer (buffer->base_buffer);
5866} 5521}
5867 5522
5868/* Remove killed buffers or items whose car is a killed buffer 5523/* Remove killed buffers or items whose car is a killed buffer from
5869 from LIST and return changed LIST. Called during GC. */ 5524 LIST, and mark other items. Return changed LIST, which is marked. */
5870 5525
5871static Lisp_Object 5526static Lisp_Object
5872discard_killed_buffers (Lisp_Object list) 5527mark_discard_killed_buffers (Lisp_Object list)
5873{ 5528{
5874 Lisp_Object *prev = &list; 5529 Lisp_Object tail, *prev = &list;
5875 Lisp_Object tail;
5876 5530
5877 for (tail = list; CONSP (tail); tail = XCDR (tail)) 5531 for (tail = list; CONSP (tail) && !CONS_MARKED_P (XCONS (tail));
5532 tail = XCDR (tail))
5878 { 5533 {
5879 Lisp_Object tem = XCAR (tail); 5534 Lisp_Object tem = XCAR (tail);
5880 if (CONSP (tem)) 5535 if (CONSP (tem))
@@ -5882,8 +5537,13 @@ discard_killed_buffers (Lisp_Object list)
5882 if (BUFFERP (tem) && !BUFFER_LIVE_P (XBUFFER (tem))) 5537 if (BUFFERP (tem) && !BUFFER_LIVE_P (XBUFFER (tem)))
5883 *prev = XCDR (tail); 5538 *prev = XCDR (tail);
5884 else 5539 else
5885 prev = &XCDR_AS_LVALUE (tail); 5540 {
5541 CONS_MARK (XCONS (tail));
5542 mark_object (XCAR (tail));
5543 prev = &XCDR_AS_LVALUE (tail);
5544 }
5886 } 5545 }
5546 mark_object (tail);
5887 return list; 5547 return list;
5888} 5548}
5889 5549
@@ -6023,18 +5683,8 @@ mark_object (Lisp_Object arg)
6023 break; 5683 break;
6024 5684
6025 case PVEC_FRAME: 5685 case PVEC_FRAME:
6026 { 5686 mark_vectorlike (ptr);
6027 struct frame *f = (struct frame *) ptr; 5687 mark_face_cache (((struct frame *) ptr)->face_cache);
6028
6029 /* For live frames, killed buffers are filtered out by
6030 store_frame_param. For dead frames, we do it here in
6031 attempt to help GC to reclaim killed buffers faster. */
6032 if (!FRAME_LIVE_P (f))
6033 fset_buffer_list (f, discard_killed_buffers (f->buffer_list));
6034
6035 mark_vectorlike (ptr);
6036 mark_face_cache (f->face_cache);
6037 }
6038 break; 5688 break;
6039 5689
6040 case PVEC_WINDOW: 5690 case PVEC_WINDOW:
@@ -6042,18 +5692,8 @@ mark_object (Lisp_Object arg)
6042 struct window *w = (struct window *) ptr; 5692 struct window *w = (struct window *) ptr;
6043 bool leaf = NILP (w->hchild) && NILP (w->vchild); 5693 bool leaf = NILP (w->hchild) && NILP (w->vchild);
6044 5694
6045 /* For live windows, Lisp code filters out killed buffers
6046 from both buffer lists. For dead windows, we do it here
6047 in attempt to help GC to reclaim killed buffers faster. */
6048 if (leaf && NILP (w->buffer))
6049 {
6050 wset_prev_buffers
6051 (w, discard_killed_buffers (w->prev_buffers));
6052 wset_next_buffers
6053 (w, discard_killed_buffers (w->next_buffers));
6054 }
6055
6056 mark_vectorlike (ptr); 5695 mark_vectorlike (ptr);
5696
6057 /* Mark glyphs for leaf windows. Marking window 5697 /* Mark glyphs for leaf windows. Marking window
6058 matrices is sufficient because frame matrices 5698 matrices is sufficient because frame matrices
6059 use the same glyph memory. */ 5699 use the same glyph memory. */
@@ -6062,6 +5702,15 @@ mark_object (Lisp_Object arg)
6062 mark_glyph_matrix (w->current_matrix); 5702 mark_glyph_matrix (w->current_matrix);
6063 mark_glyph_matrix (w->desired_matrix); 5703 mark_glyph_matrix (w->desired_matrix);
6064 } 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));
6065 } 5714 }
6066 break; 5715 break;
6067 5716
@@ -6772,12 +6421,6 @@ init_alloc_once (void)
6772 init_strings (); 6421 init_strings ();
6773 init_vectors (); 6422 init_vectors ();
6774 6423
6775#ifdef REL_ALLOC
6776 malloc_hysteresis = 32;
6777#else
6778 malloc_hysteresis = 0;
6779#endif
6780
6781 refill_memory_reserve (); 6424 refill_memory_reserve ();
6782 gc_cons_threshold = GC_DEFAULT_THRESHOLD; 6425 gc_cons_threshold = GC_DEFAULT_THRESHOLD;
6783} 6426}
diff --git a/src/dispnew.c b/src/dispnew.c
index 9cc7349f1b0..f62ee9dc96e 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5982,7 +5982,7 @@ sit_for (Lisp_Object timeout, bool reading, int do_display)
5982 5982
5983 5983
5984#ifdef USABLE_SIGIO 5984#ifdef USABLE_SIGIO
5985 gobble_input (0); 5985 gobble_input ();
5986#endif 5986#endif
5987 5987
5988 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display, 5988 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
diff --git a/src/keyboard.c b/src/keyboard.c
index c80f1d61e77..2c8d6fabf19 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -416,7 +416,7 @@ static EMACS_TIME timer_last_idleness_start_time;
416/* Function for init_keyboard to call with no args (if nonzero). */ 416/* Function for init_keyboard to call with no args (if nonzero). */
417static void (*keyboard_init_hook) (void); 417static void (*keyboard_init_hook) (void);
418 418
419static int read_avail_input (int); 419static int read_avail_input (void);
420static void get_input_pending (int *, int); 420static void get_input_pending (int *, int);
421static int readable_events (int); 421static int readable_events (int);
422static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *, 422static Lisp_Object read_char_x_menu_prompt (ptrdiff_t, Lisp_Object *,
@@ -451,7 +451,7 @@ static void timer_stop_idle (void);
451static void timer_resume_idle (void); 451static void timer_resume_idle (void);
452static void deliver_user_signal (int); 452static void deliver_user_signal (int);
453static char *find_user_signal_name (int); 453static char *find_user_signal_name (int);
454static int store_user_signal_events (void); 454static void store_user_signal_events (void);
455 455
456/* These setters are used only in this file, so they can be private. */ 456/* These setters are used only in this file, so they can be private. */
457static inline void 457static inline void
@@ -2013,7 +2013,7 @@ poll_for_input_1 (void)
2013{ 2013{
2014 if (interrupt_input_blocked == 0 2014 if (interrupt_input_blocked == 0
2015 && !waiting_for_input) 2015 && !waiting_for_input)
2016 read_avail_input (0); 2016 read_avail_input ();
2017} 2017}
2018 2018
2019/* Timer callback function for poll_timer. TIMER is equal to 2019/* Timer callback function for poll_timer. TIMER is equal to
@@ -3846,7 +3846,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3846 interrupt handlers have not read it, read it now. */ 3846 interrupt handlers have not read it, read it now. */
3847 3847
3848#ifdef USABLE_SIGIO 3848#ifdef USABLE_SIGIO
3849 gobble_input (0); 3849 gobble_input ();
3850#endif 3850#endif
3851 if (kbd_fetch_ptr != kbd_store_ptr) 3851 if (kbd_fetch_ptr != kbd_store_ptr)
3852 break; 3852 break;
@@ -3872,8 +3872,7 @@ kbd_buffer_get_event (KBOARD **kbp,
3872 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0); 3872 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0);
3873 3873
3874 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) 3874 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr)
3875 /* Pass 1 for EXPECT since we just waited to have input. */ 3875 read_avail_input ();
3876 read_avail_input (1);
3877 } 3876 }
3878 3877
3879 if (CONSP (Vunread_command_events)) 3878 if (CONSP (Vunread_command_events))
@@ -6750,14 +6749,14 @@ get_input_pending (int *addr, int flags)
6750 return; 6749 return;
6751 6750
6752 /* Try to read some input and see how much we get. */ 6751 /* Try to read some input and see how much we get. */
6753 gobble_input (0); 6752 gobble_input ();
6754 *addr = (!NILP (Vquit_flag) || readable_events (flags)); 6753 *addr = (!NILP (Vquit_flag) || readable_events (flags));
6755} 6754}
6756 6755
6757/* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ 6756/* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6758 6757
6759void 6758void
6760gobble_input (int expected) 6759gobble_input (void)
6761{ 6760{
6762#ifdef USABLE_SIGIO 6761#ifdef USABLE_SIGIO
6763 if (interrupt_input) 6762 if (interrupt_input)
@@ -6766,7 +6765,7 @@ gobble_input (int expected)
6766 sigemptyset (&blocked); 6765 sigemptyset (&blocked);
6767 sigaddset (&blocked, SIGIO); 6766 sigaddset (&blocked, SIGIO);
6768 pthread_sigmask (SIG_BLOCK, &blocked, &procmask); 6767 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6769 read_avail_input (expected); 6768 read_avail_input ();
6770 pthread_sigmask (SIG_SETMASK, &procmask, 0); 6769 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6771 } 6770 }
6772 else 6771 else
@@ -6780,13 +6779,13 @@ gobble_input (int expected)
6780 sigemptyset (&blocked); 6779 sigemptyset (&blocked);
6781 sigaddset (&blocked, SIGALRM); 6780 sigaddset (&blocked, SIGALRM);
6782 pthread_sigmask (SIG_BLOCK, &blocked, &procmask); 6781 pthread_sigmask (SIG_BLOCK, &blocked, &procmask);
6783 read_avail_input (expected); 6782 read_avail_input ();
6784 pthread_sigmask (SIG_SETMASK, &procmask, 0); 6783 pthread_sigmask (SIG_SETMASK, &procmask, 0);
6785 } 6784 }
6786 else 6785 else
6787#endif 6786#endif
6788#endif 6787#endif
6789 read_avail_input (expected); 6788 read_avail_input ();
6790} 6789}
6791 6790
6792/* Put a BUFFER_SWITCH_EVENT in the buffer 6791/* Put a BUFFER_SWITCH_EVENT in the buffer
@@ -6842,15 +6841,14 @@ record_asynch_buffer_change (void)
6842 this is a bad time to try to read input. */ 6841 this is a bad time to try to read input. */
6843 6842
6844static int 6843static int
6845read_avail_input (int expected) 6844read_avail_input (void)
6846{ 6845{
6847 int nread = 0; 6846 int nread = 0;
6848 int err = 0; 6847 int err = 0;
6849 struct terminal *t; 6848 struct terminal *t;
6850 6849
6851 /* Store pending user signal events, if any. */ 6850 /* Store pending user signal events, if any. */
6852 if (store_user_signal_events ()) 6851 store_user_signal_events ();
6853 expected = 0;
6854 6852
6855 /* Loop through the available terminals, and call their input hooks. */ 6853 /* Loop through the available terminals, and call their input hooks. */
6856 t = terminal_list; 6854 t = terminal_list;
@@ -6867,11 +6865,8 @@ read_avail_input (int expected)
6867 hold_quit.kind = NO_EVENT; 6865 hold_quit.kind = NO_EVENT;
6868 6866
6869 /* No need for FIONREAD or fcntl; just say don't wait. */ 6867 /* No need for FIONREAD or fcntl; just say don't wait. */
6870 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0) 6868 while (0 < (nr = (*t->read_socket_hook) (t, &hold_quit)))
6871 { 6869 nread += nr;
6872 nread += nr;
6873 expected = 0;
6874 }
6875 6870
6876 if (nr == -1) /* Not OK to read input now. */ 6871 if (nr == -1) /* Not OK to read input now. */
6877 { 6872 {
@@ -6966,7 +6961,6 @@ decode_keyboard_code (struct tty_display_info *tty,
6966 6961
6967int 6962int
6968tty_read_avail_input (struct terminal *terminal, 6963tty_read_avail_input (struct terminal *terminal,
6969 int expected,
6970 struct input_event *hold_quit) 6964 struct input_event *hold_quit)
6971{ 6965{
6972 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 6966 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
@@ -7186,8 +7180,7 @@ handle_async_input (void)
7186 7180
7187 while (1) 7181 while (1)
7188 { 7182 {
7189 int nread; 7183 int nread = read_avail_input ();
7190 nread = read_avail_input (1);
7191 /* -1 means it's not ok to read the input now. 7184 /* -1 means it's not ok to read the input now.
7192 UNBLOCK_INPUT will read it later; now, avoid infinite loop. 7185 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7193 0 means there was no keyboard input available. */ 7186 0 means there was no keyboard input available. */
@@ -7339,25 +7332,25 @@ find_user_signal_name (int sig)
7339 return NULL; 7332 return NULL;
7340} 7333}
7341 7334
7342static int 7335static void
7343store_user_signal_events (void) 7336store_user_signal_events (void)
7344{ 7337{
7345 struct user_signal_info *p; 7338 struct user_signal_info *p;
7346 struct input_event buf; 7339 struct input_event buf;
7347 int nstored = 0; 7340 bool buf_initialized = 0;
7348 7341
7349 for (p = user_signals; p; p = p->next) 7342 for (p = user_signals; p; p = p->next)
7350 if (p->npending > 0) 7343 if (p->npending > 0)
7351 { 7344 {
7352 sigset_t blocked, procmask; 7345 sigset_t blocked, procmask;
7353 7346
7354 if (nstored == 0) 7347 if (! buf_initialized)
7355 { 7348 {
7356 memset (&buf, 0, sizeof buf); 7349 memset (&buf, 0, sizeof buf);
7357 buf.kind = USER_SIGNAL_EVENT; 7350 buf.kind = USER_SIGNAL_EVENT;
7358 buf.frame_or_window = selected_frame; 7351 buf.frame_or_window = selected_frame;
7352 buf_initialized = 1;
7359 } 7353 }
7360 nstored += p->npending;
7361 7354
7362 sigemptyset (&blocked); 7355 sigemptyset (&blocked);
7363 sigaddset (&blocked, p->sig); 7356 sigaddset (&blocked, p->sig);
@@ -7373,8 +7366,6 @@ store_user_signal_events (void)
7373 7366
7374 pthread_sigmask (SIG_SETMASK, &procmask, 0); 7367 pthread_sigmask (SIG_SETMASK, &procmask, 0);
7375 } 7368 }
7376
7377 return nstored;
7378} 7369}
7379 7370
7380 7371
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/nsterm.m b/src/nsterm.m
index f9611fd1210..aa869e3ff44 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -35,7 +35,6 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
35#include <time.h> 35#include <time.h>
36#include <signal.h> 36#include <signal.h>
37#include <unistd.h> 37#include <unistd.h>
38#include <setjmp.h>
39 38
40#include <c-ctype.h> 39#include <c-ctype.h>
41#include <c-strcase.h> 40#include <c-strcase.h>
@@ -628,7 +627,7 @@ ns_update_begin (struct frame *f)
628{ 627{
629 NSView *view = FRAME_NS_VIEW (f); 628 NSView *view = FRAME_NS_VIEW (f);
630 NSRect r = [view frame]; 629 NSRect r = [view frame];
631 NSBezierPath *bp = [NSBezierPath bezierPath]; 630 NSBezierPath *bp;
632 NSTRACE (ns_update_begin); 631 NSTRACE (ns_update_begin);
633 632
634 ns_update_auto_hide_menu_bar (); 633 ns_update_auto_hide_menu_bar ();
@@ -640,8 +639,9 @@ ns_update_begin (struct frame *f)
640 is for the minibuffer. But the display engine may draw more because 639 is for the minibuffer. But the display engine may draw more because
641 we have set the frame as garbaged. So reset clip path to the whole 640 we have set the frame as garbaged. So reset clip path to the whole
642 view. */ 641 view. */
643 [bp appendBezierPathWithRect: r]; 642 bp = [[NSBezierPath bezierPathWithRect: r] retain];
644 [bp setClip]; 643 [bp setClip];
644 [bp release];
645 645
646#ifdef NS_IMPL_GNUSTEP 646#ifdef NS_IMPL_GNUSTEP
647 uRect = NSMakeRect (0, 0, 0, 0); 647 uRect = NSMakeRect (0, 0, 0, 0);
@@ -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
@@ -3977,33 +3972,34 @@ ns_term_init (Lisp_Object display_name)
3977 static int ns_initialized = 0; 3972 static int ns_initialized = 0;
3978 Lisp_Object tmp; 3973 Lisp_Object tmp;
3979 3974
3975 if (ns_initialized) return x_display_list;
3976 ns_initialized = 1;
3977
3980 NSTRACE (ns_term_init); 3978 NSTRACE (ns_term_init);
3981 3979
3980 [outerpool release];
3981 outerpool = [[NSAutoreleasePool alloc] init];
3982
3982 /* 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 */
3983 /*GSDebugAllocationActive (YES); */ 3984 /*GSDebugAllocationActive (YES); */
3984 BLOCK_INPUT; 3985 BLOCK_INPUT;
3985 handling_signal = 0;
3986 3986
3987 if (!ns_initialized) 3987 baud_rate = 38400;
3988 { 3988 Fset_input_interrupt_mode (Qnil);
3989 baud_rate = 38400;
3990 Fset_input_interrupt_mode (Qnil);
3991 3989
3992 if (selfds[0] == -1) 3990 if (selfds[0] == -1)
3991 {
3992 if (pipe (selfds) == -1)
3993 { 3993 {
3994 if (pipe (selfds) == -1) 3994 fprintf (stderr, "Failed to create pipe: %s\n",
3995 { 3995 emacs_strerror (errno));
3996 fprintf (stderr, "Failed to create pipe: %s\n", 3996 emacs_abort ();
3997 emacs_strerror (errno));
3998 emacs_abort ();
3999 }
4000
4001 fcntl (selfds[0], F_SETFL, O_NONBLOCK|fcntl (selfds[0], F_GETFL));
4002 FD_ZERO (&select_readfds);
4003 FD_ZERO (&select_writefds);
4004 pthread_mutex_init (&select_mutex, NULL);
4005 } 3997 }
4006 ns_initialized = 1; 3998
3999 fcntl (selfds[0], F_SETFL, O_NONBLOCK|fcntl (selfds[0], F_GETFL));
4000 FD_ZERO (&select_readfds);
4001 FD_ZERO (&select_writefds);
4002 pthread_mutex_init (&select_mutex, NULL);
4007 } 4003 }
4008 4004
4009 ns_pending_files = [[NSMutableArray alloc] init]; 4005 ns_pending_files = [[NSMutableArray alloc] init];
@@ -4194,6 +4190,20 @@ ns_term_init (Lisp_Object display_name)
4194 } 4190 }
4195#endif /* MAC OS X menu setup */ 4191#endif /* MAC OS X menu setup */
4196 4192
4193 /* Register our external input/output types, used for determining
4194 applicable services and also drag/drop eligibility. */
4195 ns_send_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] retain];
4196 ns_return_types = [[NSArray arrayWithObjects: NSStringPboardType, nil]
4197 retain];
4198 ns_drag_types = [[NSArray arrayWithObjects:
4199 NSStringPboardType,
4200 NSTabularTextPboardType,
4201 NSFilenamesPboardType,
4202 NSURLPboardType,
4203 NSColorPboardType,
4204 NSFontPboardType, nil] retain];
4205
4206
4197 [NSApp run]; 4207 [NSApp run];
4198 ns_do_open_file = YES; 4208 ns_do_open_file = YES;
4199 return dpyinfo; 4209 return dpyinfo;
@@ -6223,7 +6233,7 @@ not_in_argv (NSString *arg)
6223 NSRect r = [super constrainFrameRect:frameRect toScreen:screen]; 6233 NSRect r = [super constrainFrameRect:frameRect toScreen:screen];
6224 return r; 6234 return r;
6225 } 6235 }
6226 6236
6227 if (f->output_data.ns->dont_constrain 6237 if (f->output_data.ns->dont_constrain
6228 || ns_menu_bar_should_be_hidden ()) 6238 || ns_menu_bar_should_be_hidden ())
6229 return frameRect; 6239 return frameRect;
diff --git a/src/termhooks.h b/src/termhooks.h
index a1164be85cc..e5a59cfaf79 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -595,23 +595,14 @@ struct terminal
595 595
596 TERMINAL indicates which terminal device to read from. Input 596 TERMINAL indicates which terminal device to read from. Input
597 events should be read into BUF, the size of which is given in 597 events should be read into BUF, the size of which is given in
598 SIZE. EXPECTED is non-zero if the caller suspects that new input 598 SIZE.
599 is available.
600 599
601 A positive return value indicates that that many input events 600 A positive return value indicates that that many input events
602 where read into BUF. 601 were read into BUF.
603 Zero means no events were immediately available. 602 Zero means no events were immediately available.
604 A value of -1 means a transient read error, while -2 indicates 603 A value of -1 means a transient read error, while -2 indicates
605 that the device was closed (hangup), and it should be deleted. 604 that the device was closed (hangup), and it should be deleted. */
606
607 XXX Please note that a non-zero value of EXPECTED only means that
608 there is available input on at least one of the currently opened
609 terminal devices -- but not necessarily on this device.
610 Therefore, in most cases EXPECTED should be simply ignored.
611
612 XXX This documentation needs to be updated. */
613 int (*read_socket_hook) (struct terminal *terminal, 605 int (*read_socket_hook) (struct terminal *terminal,
614 int expected,
615 struct input_event *hold_quit); 606 struct input_event *hold_quit);
616 607
617 /* Called when a frame's display becomes entirely up to date. */ 608 /* Called when a frame's display becomes entirely up to date. */
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 d4cc620335c..a96d8d70483 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -744,7 +744,6 @@ 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, add; 749 int nev, add;
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 6244728b264..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;
diff --git a/src/window.c b/src/window.c
index 2589596ccfd..abdee7ec19b 100644
--- a/src/window.c
+++ b/src/window.c
@@ -3463,7 +3463,11 @@ make_window (void)
3463 wset_vertical_scroll_bar_type (w, Qt); 3463 wset_vertical_scroll_bar_type (w, Qt);
3464 wset_window_end_pos (w, make_number (0)); 3464 wset_window_end_pos (w, make_number (0));
3465 wset_window_end_vpos (w, make_number (0)); 3465 wset_window_end_vpos (w, make_number (0));
3466 3466 /* These Lisp fields are marked specially so they're not set to nil by
3467 allocate_window. */
3468 wset_prev_buffers (w, Qnil);
3469 wset_next_buffers (w, Qnil);
3470
3467 /* Initialize non-Lisp data. Note that allocate_window zeroes out all 3471 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3468 non-Lisp data, so do it only for slots which should not be zero. */ 3472 non-Lisp data, so do it only for slots which should not be zero. */
3469 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3473 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/xterm.c b/src/xterm.c
index 5bc87d0ec64..a47056a6f94 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -7118,19 +7118,15 @@ x_dispatch_event (XEvent *event, Display *display)
7118 7118
7119 7119
7120/* Read events coming from the X server. 7120/* Read events coming from the X server.
7121 This routine is called by the SIGIO handler only if SYNC_INPUT is 7121 Return as soon as there are no more events to be read.
7122 not defined.
7123 We return as soon as there are no more events to be read.
7124 7122
7125 We return the number of characters stored into the buffer, 7123 Return the number of characters stored into the buffer,
7126 thus pretending to be `read' (except the characters we store 7124 thus pretending to be `read' (except the characters we store
7127 in the keyboard buffer can be multibyte, so are not necessarily 7125 in the keyboard buffer can be multibyte, so are not necessarily
7128 C chars). 7126 C chars). */
7129
7130 EXPECTED is nonzero if the caller knows input is available. */
7131 7127
7132static int 7128static int
7133XTread_socket (struct terminal *terminal, int expected, struct input_event *hold_quit) 7129XTread_socket (struct terminal *terminal, struct input_event *hold_quit)
7134{ 7130{
7135 int count = 0; 7131 int count = 0;
7136 int event_found = 0; 7132 int event_found = 0;