comparison src/alloc.c @ 109126:aec1143e8d85

Convert (most) functions in src to standard C. * src/alloc.c: Convert function definitions to standard C. * src/atimer.c: * src/bidi.c: * src/bytecode.c: * src/callint.c: * src/callproc.c: * src/casefiddle.c: * src/casetab.c: * src/category.c: * src/ccl.c: * src/character.c: * src/charset.c: * src/chartab.c: * src/cmds.c: * src/coding.c: * src/composite.c: * src/data.c: * src/dbusbind.c: * src/dired.c: * src/dispnew.c: * src/doc.c: * src/doprnt.c: * src/ecrt0.c: * src/editfns.c: * src/fileio.c: * src/filelock.c: * src/filemode.c: * src/fns.c: * src/font.c: * src/fontset.c: * src/frame.c: * src/fringe.c: * src/ftfont.c: * src/ftxfont.c: * src/gtkutil.c: * src/indent.c: * src/insdel.c: * src/intervals.c: * src/keymap.c: * src/lread.c: * src/macros.c: * src/marker.c: * src/md5.c: * src/menu.c: * src/minibuf.c: * src/prefix-args.c: * src/print.c: * src/ralloc.c: * src/regex.c: * src/region-cache.c: * src/scroll.c: * src/search.c: * src/sound.c: * src/strftime.c: * src/syntax.c: * src/sysdep.c: * src/termcap.c: * src/terminal.c: * src/terminfo.c: * src/textprop.c: * src/tparam.c: * src/undo.c: * src/unexelf.c: * src/window.c: * src/xfaces.c: * src/xfns.c: * src/xfont.c: * src/xftfont.c: * src/xgselect.c: * src/xmenu.c: * src/xrdb.c: * src/xselect.c: * src/xsettings.c: * src/xsmfns.c: * src/xterm.c: Likewise.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 04 Jul 2010 00:50:25 -0700
parents 2bc9a0c04c87
children c25c24812fb1
comparison
equal deleted inserted replaced
109125:12b02558bf51 109126:aec1143e8d85
369 MEM_TYPE_VECTORLIKE 369 MEM_TYPE_VECTORLIKE
370 }; 370 };
371 371
372 static POINTER_TYPE *lisp_align_malloc (size_t, enum mem_type); 372 static POINTER_TYPE *lisp_align_malloc (size_t, enum mem_type);
373 static POINTER_TYPE *lisp_malloc (size_t, enum mem_type); 373 static POINTER_TYPE *lisp_malloc (size_t, enum mem_type);
374 void refill_memory_reserve (); 374 void refill_memory_reserve (void);
375 375
376 376
377 #if GC_MARK_STACK || defined GC_MALLOC_CHECK 377 #if GC_MARK_STACK || defined GC_MALLOC_CHECK
378 378
379 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 379 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
512 ************************************************************************/ 512 ************************************************************************/
513 513
514 /* Function malloc calls this if it finds we are near exhausting storage. */ 514 /* Function malloc calls this if it finds we are near exhausting storage. */
515 515
516 void 516 void
517 malloc_warning (str) 517 malloc_warning (char *str)
518 char *str;
519 { 518 {
520 pending_malloc_warning = str; 519 pending_malloc_warning = str;
521 } 520 }
522 521
523 522
524 /* Display an already-pending malloc warning. */ 523 /* Display an already-pending malloc warning. */
525 524
526 void 525 void
527 display_malloc_warning () 526 display_malloc_warning (void)
528 { 527 {
529 call3 (intern ("display-warning"), 528 call3 (intern ("display-warning"),
530 intern ("alloc"), 529 intern ("alloc"),
531 build_string (pending_malloc_warning), 530 build_string (pending_malloc_warning),
532 intern ("emergency")); 531 intern ("emergency"));
541 #endif 540 #endif
542 541
543 /* Called if we can't allocate relocatable space for a buffer. */ 542 /* Called if we can't allocate relocatable space for a buffer. */
544 543
545 void 544 void
546 buffer_memory_full () 545 buffer_memory_full (void)
547 { 546 {
548 /* If buffers use the relocating allocator, no need to free 547 /* If buffers use the relocating allocator, no need to free
549 spare_memory, because we may have plenty of malloc space left 548 spare_memory, because we may have plenty of malloc space left
550 that we could get, and if we don't, the malloc that fails will 549 that we could get, and if we don't, the malloc that fails will
551 itself cause spare_memory to be freed. If buffers don't use the 550 itself cause spare_memory to be freed. If buffers don't use the
740 #endif 739 #endif
741 740
742 /* Like malloc but check for no memory and block interrupt input.. */ 741 /* Like malloc but check for no memory and block interrupt input.. */
743 742
744 POINTER_TYPE * 743 POINTER_TYPE *
745 xmalloc (size) 744 xmalloc (size_t size)
746 size_t size;
747 { 745 {
748 register POINTER_TYPE *val; 746 register POINTER_TYPE *val;
749 747
750 MALLOC_BLOCK_INPUT; 748 MALLOC_BLOCK_INPUT;
751 val = (POINTER_TYPE *) malloc (size); 749 val = (POINTER_TYPE *) malloc (size);
758 756
759 757
760 /* Like realloc but check for no memory and block interrupt input.. */ 758 /* Like realloc but check for no memory and block interrupt input.. */
761 759
762 POINTER_TYPE * 760 POINTER_TYPE *
763 xrealloc (block, size) 761 xrealloc (POINTER_TYPE *block, size_t size)
764 POINTER_TYPE *block;
765 size_t size;
766 { 762 {
767 register POINTER_TYPE *val; 763 register POINTER_TYPE *val;
768 764
769 MALLOC_BLOCK_INPUT; 765 MALLOC_BLOCK_INPUT;
770 /* We must call malloc explicitly when BLOCK is 0, since some 766 /* We must call malloc explicitly when BLOCK is 0, since some
781 777
782 778
783 /* Like free but block interrupt input. */ 779 /* Like free but block interrupt input. */
784 780
785 void 781 void
786 xfree (block) 782 xfree (POINTER_TYPE *block)
787 POINTER_TYPE *block;
788 { 783 {
789 if (!block) 784 if (!block)
790 return; 785 return;
791 MALLOC_BLOCK_INPUT; 786 MALLOC_BLOCK_INPUT;
792 free (block); 787 free (block);
798 793
799 794
800 /* Like strdup, but uses xmalloc. */ 795 /* Like strdup, but uses xmalloc. */
801 796
802 char * 797 char *
803 xstrdup (s) 798 xstrdup (const char *s)
804 const char *s;
805 { 799 {
806 size_t len = strlen (s) + 1; 800 size_t len = strlen (s) + 1;
807 char *p = (char *) xmalloc (len); 801 char *p = (char *) xmalloc (len);
808 bcopy (s, p, len); 802 bcopy (s, p, len);
809 return p; 803 return p;
811 805
812 806
813 /* Unwind for SAFE_ALLOCA */ 807 /* Unwind for SAFE_ALLOCA */
814 808
815 Lisp_Object 809 Lisp_Object
816 safe_alloca_unwind (arg) 810 safe_alloca_unwind (Lisp_Object arg)
817 Lisp_Object arg;
818 { 811 {
819 register struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 812 register struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
820 813
821 p->dogc = 0; 814 p->dogc = 0;
822 xfree (p->pointer); 815 xfree (p->pointer);
833 #ifndef USE_LSB_TAG 826 #ifndef USE_LSB_TAG
834 static void *lisp_malloc_loser; 827 static void *lisp_malloc_loser;
835 #endif 828 #endif
836 829
837 static POINTER_TYPE * 830 static POINTER_TYPE *
838 lisp_malloc (nbytes, type) 831 lisp_malloc (size_t nbytes, enum mem_type type)
839 size_t nbytes;
840 enum mem_type type;
841 { 832 {
842 register void *val; 833 register void *val;
843 834
844 MALLOC_BLOCK_INPUT; 835 MALLOC_BLOCK_INPUT;
845 836
879 870
880 /* Free BLOCK. This must be called to free memory allocated with a 871 /* Free BLOCK. This must be called to free memory allocated with a
881 call to lisp_malloc. */ 872 call to lisp_malloc. */
882 873
883 static void 874 static void
884 lisp_free (block) 875 lisp_free (POINTER_TYPE *block)
885 POINTER_TYPE *block;
886 { 876 {
887 MALLOC_BLOCK_INPUT; 877 MALLOC_BLOCK_INPUT;
888 free (block); 878 free (block);
889 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK 879 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK
890 mem_delete (mem_find (block)); 880 mem_delete (mem_find (block));
979 969
980 /* Allocate an aligned block of nbytes. 970 /* Allocate an aligned block of nbytes.
981 Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be 971 Alignment is on a multiple of BLOCK_ALIGN and `nbytes' has to be
982 smaller or equal to BLOCK_BYTES. */ 972 smaller or equal to BLOCK_BYTES. */
983 static POINTER_TYPE * 973 static POINTER_TYPE *
984 lisp_align_malloc (nbytes, type) 974 lisp_align_malloc (size_t nbytes, enum mem_type type)
985 size_t nbytes;
986 enum mem_type type;
987 { 975 {
988 void *base, *val; 976 void *base, *val;
989 struct ablocks *abase; 977 struct ablocks *abase;
990 978
991 eassert (nbytes <= BLOCK_BYTES); 979 eassert (nbytes <= BLOCK_BYTES);
1088 eassert (0 == ((EMACS_UINT)val) % BLOCK_ALIGN); 1076 eassert (0 == ((EMACS_UINT)val) % BLOCK_ALIGN);
1089 return val; 1077 return val;
1090 } 1078 }
1091 1079
1092 static void 1080 static void
1093 lisp_align_free (block) 1081 lisp_align_free (POINTER_TYPE *block)
1094 POINTER_TYPE *block;
1095 { 1082 {
1096 struct ablock *ablock = block; 1083 struct ablock *ablock = block;
1097 struct ablocks *abase = ABLOCK_ABASE (ablock); 1084 struct ablocks *abase = ABLOCK_ABASE (ablock);
1098 1085
1099 MALLOC_BLOCK_INPUT; 1086 MALLOC_BLOCK_INPUT;
1134 1121
1135 /* Return a new buffer structure allocated from the heap with 1122 /* Return a new buffer structure allocated from the heap with
1136 a call to lisp_malloc. */ 1123 a call to lisp_malloc. */
1137 1124
1138 struct buffer * 1125 struct buffer *
1139 allocate_buffer () 1126 allocate_buffer (void)
1140 { 1127 {
1141 struct buffer *b 1128 struct buffer *b
1142 = (struct buffer *) lisp_malloc (sizeof (struct buffer), 1129 = (struct buffer *) lisp_malloc (sizeof (struct buffer),
1143 MEM_TYPE_BUFFER); 1130 MEM_TYPE_BUFFER);
1144 b->size = sizeof (struct buffer) / sizeof (EMACS_INT); 1131 b->size = sizeof (struct buffer) / sizeof (EMACS_INT);
1432 1419
1433 1420
1434 /* Initialize interval allocation. */ 1421 /* Initialize interval allocation. */
1435 1422
1436 static void 1423 static void
1437 init_intervals () 1424 init_intervals (void)
1438 { 1425 {
1439 interval_block = NULL; 1426 interval_block = NULL;
1440 interval_block_index = INTERVAL_BLOCK_SIZE; 1427 interval_block_index = INTERVAL_BLOCK_SIZE;
1441 interval_free_list = 0; 1428 interval_free_list = 0;
1442 n_interval_blocks = 0; 1429 n_interval_blocks = 0;
1444 1431
1445 1432
1446 /* Return a new interval. */ 1433 /* Return a new interval. */
1447 1434
1448 INTERVAL 1435 INTERVAL
1449 make_interval () 1436 make_interval (void)
1450 { 1437 {
1451 INTERVAL val; 1438 INTERVAL val;
1452 1439
1453 /* eassert (!handling_signal); */ 1440 /* eassert (!handling_signal); */
1454 1441
1487 1474
1488 1475
1489 /* Mark Lisp objects in interval I. */ 1476 /* Mark Lisp objects in interval I. */
1490 1477
1491 static void 1478 static void
1492 mark_interval (i, dummy) 1479 mark_interval (register INTERVAL i, Lisp_Object dummy)
1493 register INTERVAL i;
1494 Lisp_Object dummy;
1495 { 1480 {
1496 eassert (!i->gcmarkbit); /* Intervals are never shared. */ 1481 eassert (!i->gcmarkbit); /* Intervals are never shared. */
1497 i->gcmarkbit = 1; 1482 i->gcmarkbit = 1;
1498 mark_object (i->plist); 1483 mark_object (i->plist);
1499 } 1484 }
1501 1486
1502 /* Mark the interval tree rooted in TREE. Don't call this directly; 1487 /* Mark the interval tree rooted in TREE. Don't call this directly;
1503 use the macro MARK_INTERVAL_TREE instead. */ 1488 use the macro MARK_INTERVAL_TREE instead. */
1504 1489
1505 static void 1490 static void
1506 mark_interval_tree (tree) 1491 mark_interval_tree (register INTERVAL tree)
1507 register INTERVAL tree;
1508 { 1492 {
1509 /* No need to test if this tree has been marked already; this 1493 /* No need to test if this tree has been marked already; this
1510 function is always called through the MARK_INTERVAL_TREE macro, 1494 function is always called through the MARK_INTERVAL_TREE macro,
1511 which takes care of that. */ 1495 which takes care of that. */
1512 1496
1749 #define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE) 1733 #define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE)
1750 1734
1751 /* Initialize string allocation. Called from init_alloc_once. */ 1735 /* Initialize string allocation. Called from init_alloc_once. */
1752 1736
1753 static void 1737 static void
1754 init_strings () 1738 init_strings (void)
1755 { 1739 {
1756 total_strings = total_free_strings = total_string_size = 0; 1740 total_strings = total_free_strings = total_string_size = 0;
1757 oldest_sblock = current_sblock = large_sblocks = NULL; 1741 oldest_sblock = current_sblock = large_sblocks = NULL;
1758 string_blocks = NULL; 1742 string_blocks = NULL;
1759 n_string_blocks = 0; 1743 n_string_blocks = 0;
1871 #endif 1855 #endif
1872 1856
1873 /* Return a new Lisp_String. */ 1857 /* Return a new Lisp_String. */
1874 1858
1875 static struct Lisp_String * 1859 static struct Lisp_String *
1876 allocate_string () 1860 allocate_string (void)
1877 { 1861 {
1878 struct Lisp_String *s; 1862 struct Lisp_String *s;
1879 1863
1880 /* eassert (!handling_signal); */ 1864 /* eassert (!handling_signal); */
1881 1865
1942 set S->data to its `u.data' member. Store a NUL byte at the end of 1926 set S->data to its `u.data' member. Store a NUL byte at the end of
1943 S->data. Set S->size to NCHARS and S->size_byte to NBYTES. Free 1927 S->data. Set S->size to NCHARS and S->size_byte to NBYTES. Free
1944 S->data if it was initially non-null. */ 1928 S->data if it was initially non-null. */
1945 1929
1946 void 1930 void
1947 allocate_string_data (s, nchars, nbytes) 1931 allocate_string_data (struct Lisp_String *s, int nchars, int nbytes)
1948 struct Lisp_String *s;
1949 int nchars, nbytes;
1950 { 1932 {
1951 struct sdata *data, *old_data; 1933 struct sdata *data, *old_data;
1952 struct sblock *b; 1934 struct sblock *b;
1953 int needed, old_nbytes; 1935 int needed, old_nbytes;
1954 1936
2041 2023
2042 2024
2043 /* Sweep and compact strings. */ 2025 /* Sweep and compact strings. */
2044 2026
2045 static void 2027 static void
2046 sweep_strings () 2028 sweep_strings (void)
2047 { 2029 {
2048 struct string_block *b, *next; 2030 struct string_block *b, *next;
2049 struct string_block *live_blocks = NULL; 2031 struct string_block *live_blocks = NULL;
2050 2032
2051 string_free_list = NULL; 2033 string_free_list = NULL;
2141 2123
2142 2124
2143 /* Free dead large strings. */ 2125 /* Free dead large strings. */
2144 2126
2145 static void 2127 static void
2146 free_large_strings () 2128 free_large_strings (void)
2147 { 2129 {
2148 struct sblock *b, *next; 2130 struct sblock *b, *next;
2149 struct sblock *live_blocks = NULL; 2131 struct sblock *live_blocks = NULL;
2150 2132
2151 for (b = large_sblocks; b; b = next) 2133 for (b = large_sblocks; b; b = next)
2167 2149
2168 /* Compact data of small strings. Free sblocks that don't contain 2150 /* Compact data of small strings. Free sblocks that don't contain
2169 data of live strings after compaction. */ 2151 data of live strings after compaction. */
2170 2152
2171 static void 2153 static void
2172 compact_small_strings () 2154 compact_small_strings (void)
2173 { 2155 {
2174 struct sblock *b, *tb, *next; 2156 struct sblock *b, *tb, *next;
2175 struct sdata *from, *to, *end, *tb_end; 2157 struct sdata *from, *to, *end, *tb_end;
2176 struct sdata *to_end, *from_end; 2158 struct sdata *to_end, *from_end;
2177 2159
2355 /* Make a string from NBYTES bytes at CONTENTS, and compute the number 2337 /* Make a string from NBYTES bytes at CONTENTS, and compute the number
2356 of characters from the contents. This string may be unibyte or 2338 of characters from the contents. This string may be unibyte or
2357 multibyte, depending on the contents. */ 2339 multibyte, depending on the contents. */
2358 2340
2359 Lisp_Object 2341 Lisp_Object
2360 make_string (contents, nbytes) 2342 make_string (const char *contents, int nbytes)
2361 const char *contents;
2362 int nbytes;
2363 { 2343 {
2364 register Lisp_Object val; 2344 register Lisp_Object val;
2365 int nchars, multibyte_nbytes; 2345 int nchars, multibyte_nbytes;
2366 2346
2367 parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes); 2347 parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes);
2376 2356
2377 2357
2378 /* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2358 /* Make an unibyte string from LENGTH bytes at CONTENTS. */
2379 2359
2380 Lisp_Object 2360 Lisp_Object
2381 make_unibyte_string (contents, length) 2361 make_unibyte_string (const char *contents, int length)
2382 const char *contents;
2383 int length;
2384 { 2362 {
2385 register Lisp_Object val; 2363 register Lisp_Object val;
2386 val = make_uninit_string (length); 2364 val = make_uninit_string (length);
2387 bcopy (contents, SDATA (val), length); 2365 bcopy (contents, SDATA (val), length);
2388 STRING_SET_UNIBYTE (val); 2366 STRING_SET_UNIBYTE (val);
2392 2370
2393 /* Make a multibyte string from NCHARS characters occupying NBYTES 2371 /* Make a multibyte string from NCHARS characters occupying NBYTES
2394 bytes at CONTENTS. */ 2372 bytes at CONTENTS. */
2395 2373
2396 Lisp_Object 2374 Lisp_Object
2397 make_multibyte_string (contents, nchars, nbytes) 2375 make_multibyte_string (const char *contents, int nchars, int nbytes)
2398 const char *contents;
2399 int nchars, nbytes;
2400 { 2376 {
2401 register Lisp_Object val; 2377 register Lisp_Object val;
2402 val = make_uninit_multibyte_string (nchars, nbytes); 2378 val = make_uninit_multibyte_string (nchars, nbytes);
2403 bcopy (contents, SDATA (val), nbytes); 2379 bcopy (contents, SDATA (val), nbytes);
2404 return val; 2380 return val;
2407 2383
2408 /* Make a string from NCHARS characters occupying NBYTES bytes at 2384 /* Make a string from NCHARS characters occupying NBYTES bytes at
2409 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */ 2385 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */
2410 2386
2411 Lisp_Object 2387 Lisp_Object
2412 make_string_from_bytes (contents, nchars, nbytes) 2388 make_string_from_bytes (const char *contents, int nchars, int nbytes)
2413 const char *contents;
2414 int nchars, nbytes;
2415 { 2389 {
2416 register Lisp_Object val; 2390 register Lisp_Object val;
2417 val = make_uninit_multibyte_string (nchars, nbytes); 2391 val = make_uninit_multibyte_string (nchars, nbytes);
2418 bcopy (contents, SDATA (val), nbytes); 2392 bcopy (contents, SDATA (val), nbytes);
2419 if (SBYTES (val) == SCHARS (val)) 2393 if (SBYTES (val) == SCHARS (val))
2426 CONTENTS. The argument MULTIBYTE controls whether to label the 2400 CONTENTS. The argument MULTIBYTE controls whether to label the
2427 string as multibyte. If NCHARS is negative, it counts the number of 2401 string as multibyte. If NCHARS is negative, it counts the number of
2428 characters by itself. */ 2402 characters by itself. */
2429 2403
2430 Lisp_Object 2404 Lisp_Object
2431 make_specified_string (contents, nchars, nbytes, multibyte) 2405 make_specified_string (const char *contents, int nchars, int nbytes, int multibyte)
2432 const char *contents;
2433 int nchars, nbytes;
2434 int multibyte;
2435 { 2406 {
2436 register Lisp_Object val; 2407 register Lisp_Object val;
2437 2408
2438 if (nchars < 0) 2409 if (nchars < 0)
2439 { 2410 {
2452 2423
2453 /* Make a string from the data at STR, treating it as multibyte if the 2424 /* Make a string from the data at STR, treating it as multibyte if the
2454 data warrants. */ 2425 data warrants. */
2455 2426
2456 Lisp_Object 2427 Lisp_Object
2457 build_string (str) 2428 build_string (const char *str)
2458 const char *str;
2459 { 2429 {
2460 return make_string (str, strlen (str)); 2430 return make_string (str, strlen (str));
2461 } 2431 }
2462 2432
2463 2433
2464 /* Return an unibyte Lisp_String set up to hold LENGTH characters 2434 /* Return an unibyte Lisp_String set up to hold LENGTH characters
2465 occupying LENGTH bytes. */ 2435 occupying LENGTH bytes. */
2466 2436
2467 Lisp_Object 2437 Lisp_Object
2468 make_uninit_string (length) 2438 make_uninit_string (int length)
2469 int length;
2470 { 2439 {
2471 Lisp_Object val; 2440 Lisp_Object val;
2472 2441
2473 if (!length) 2442 if (!length)
2474 return empty_unibyte_string; 2443 return empty_unibyte_string;
2480 2449
2481 /* Return a multibyte Lisp_String set up to hold NCHARS characters 2450 /* Return a multibyte Lisp_String set up to hold NCHARS characters
2482 which occupy NBYTES bytes. */ 2451 which occupy NBYTES bytes. */
2483 2452
2484 Lisp_Object 2453 Lisp_Object
2485 make_uninit_multibyte_string (nchars, nbytes) 2454 make_uninit_multibyte_string (int nchars, int nbytes)
2486 int nchars, nbytes;
2487 { 2455 {
2488 Lisp_Object string; 2456 Lisp_Object string;
2489 struct Lisp_String *s; 2457 struct Lisp_String *s;
2490 2458
2491 if (nchars < 0) 2459 if (nchars < 0)
2571 2539
2572 2540
2573 /* Initialize float allocation. */ 2541 /* Initialize float allocation. */
2574 2542
2575 static void 2543 static void
2576 init_float () 2544 init_float (void)
2577 { 2545 {
2578 float_block = NULL; 2546 float_block = NULL;
2579 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */ 2547 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */
2580 float_free_list = 0; 2548 float_free_list = 0;
2581 n_float_blocks = 0; 2549 n_float_blocks = 0;
2583 2551
2584 2552
2585 /* Explicitly free a float cell by putting it on the free-list. */ 2553 /* Explicitly free a float cell by putting it on the free-list. */
2586 2554
2587 static void 2555 static void
2588 free_float (ptr) 2556 free_float (struct Lisp_Float *ptr)
2589 struct Lisp_Float *ptr;
2590 { 2557 {
2591 ptr->u.chain = float_free_list; 2558 ptr->u.chain = float_free_list;
2592 float_free_list = ptr; 2559 float_free_list = ptr;
2593 } 2560 }
2594 2561
2595 2562
2596 /* Return a new float object with value FLOAT_VALUE. */ 2563 /* Return a new float object with value FLOAT_VALUE. */
2597 2564
2598 Lisp_Object 2565 Lisp_Object
2599 make_float (float_value) 2566 make_float (double float_value)
2600 double float_value;
2601 { 2567 {
2602 register Lisp_Object val; 2568 register Lisp_Object val;
2603 2569
2604 /* eassert (!handling_signal); */ 2570 /* eassert (!handling_signal); */
2605 2571
2695 2661
2696 2662
2697 /* Initialize cons allocation. */ 2663 /* Initialize cons allocation. */
2698 2664
2699 static void 2665 static void
2700 init_cons () 2666 init_cons (void)
2701 { 2667 {
2702 cons_block = NULL; 2668 cons_block = NULL;
2703 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */ 2669 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */
2704 cons_free_list = 0; 2670 cons_free_list = 0;
2705 n_cons_blocks = 0; 2671 n_cons_blocks = 0;
2707 2673
2708 2674
2709 /* Explicitly free a cons cell by putting it on the free-list. */ 2675 /* Explicitly free a cons cell by putting it on the free-list. */
2710 2676
2711 void 2677 void
2712 free_cons (ptr) 2678 free_cons (struct Lisp_Cons *ptr)
2713 struct Lisp_Cons *ptr;
2714 { 2679 {
2715 ptr->u.chain = cons_free_list; 2680 ptr->u.chain = cons_free_list;
2716 #if GC_MARK_STACK 2681 #if GC_MARK_STACK
2717 ptr->car = Vdead; 2682 ptr->car = Vdead;
2718 #endif 2683 #endif
2764 return val; 2729 return val;
2765 } 2730 }
2766 2731
2767 /* Get an error now if there's any junk in the cons free list. */ 2732 /* Get an error now if there's any junk in the cons free list. */
2768 void 2733 void
2769 check_cons_list () 2734 check_cons_list (void)
2770 { 2735 {
2771 #ifdef GC_CHECK_CONS_LIST 2736 #ifdef GC_CHECK_CONS_LIST
2772 struct Lisp_Cons *tail = cons_free_list; 2737 struct Lisp_Cons *tail = cons_free_list;
2773 2738
2774 while (tail) 2739 while (tail)
2777 } 2742 }
2778 2743
2779 /* Make a list of 1, 2, 3, 4 or 5 specified objects. */ 2744 /* Make a list of 1, 2, 3, 4 or 5 specified objects. */
2780 2745
2781 Lisp_Object 2746 Lisp_Object
2782 list1 (arg1) 2747 list1 (Lisp_Object arg1)
2783 Lisp_Object arg1;
2784 { 2748 {
2785 return Fcons (arg1, Qnil); 2749 return Fcons (arg1, Qnil);
2786 } 2750 }
2787 2751
2788 Lisp_Object 2752 Lisp_Object
2789 list2 (arg1, arg2) 2753 list2 (Lisp_Object arg1, Lisp_Object arg2)
2790 Lisp_Object arg1, arg2;
2791 { 2754 {
2792 return Fcons (arg1, Fcons (arg2, Qnil)); 2755 return Fcons (arg1, Fcons (arg2, Qnil));
2793 } 2756 }
2794 2757
2795 2758
2796 Lisp_Object 2759 Lisp_Object
2797 list3 (arg1, arg2, arg3) 2760 list3 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
2798 Lisp_Object arg1, arg2, arg3;
2799 { 2761 {
2800 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Qnil))); 2762 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Qnil)));
2801 } 2763 }
2802 2764
2803 2765
2804 Lisp_Object 2766 Lisp_Object
2805 list4 (arg1, arg2, arg3, arg4) 2767 list4 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4)
2806 Lisp_Object arg1, arg2, arg3, arg4;
2807 { 2768 {
2808 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Qnil)))); 2769 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Qnil))));
2809 } 2770 }
2810 2771
2811 2772
2812 Lisp_Object 2773 Lisp_Object
2813 list5 (arg1, arg2, arg3, arg4, arg5) 2774 list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
2814 Lisp_Object arg1, arg2, arg3, arg4, arg5;
2815 { 2775 {
2816 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, 2776 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4,
2817 Fcons (arg5, Qnil))))); 2777 Fcons (arg5, Qnil)))));
2818 } 2778 }
2819 2779
2902 2862
2903 /* Value is a pointer to a newly allocated Lisp_Vector structure 2863 /* Value is a pointer to a newly allocated Lisp_Vector structure
2904 with room for LEN Lisp_Objects. */ 2864 with room for LEN Lisp_Objects. */
2905 2865
2906 static struct Lisp_Vector * 2866 static struct Lisp_Vector *
2907 allocate_vectorlike (len) 2867 allocate_vectorlike (EMACS_INT len)
2908 EMACS_INT len;
2909 { 2868 {
2910 struct Lisp_Vector *p; 2869 struct Lisp_Vector *p;
2911 size_t nbytes; 2870 size_t nbytes;
2912 2871
2913 MALLOC_BLOCK_INPUT; 2872 MALLOC_BLOCK_INPUT;
2944 2903
2945 2904
2946 /* Allocate a vector with NSLOTS slots. */ 2905 /* Allocate a vector with NSLOTS slots. */
2947 2906
2948 struct Lisp_Vector * 2907 struct Lisp_Vector *
2949 allocate_vector (nslots) 2908 allocate_vector (EMACS_INT nslots)
2950 EMACS_INT nslots;
2951 { 2909 {
2952 struct Lisp_Vector *v = allocate_vectorlike (nslots); 2910 struct Lisp_Vector *v = allocate_vectorlike (nslots);
2953 v->size = nslots; 2911 v->size = nslots;
2954 return v; 2912 return v;
2955 } 2913 }
2956 2914
2957 2915
2958 /* Allocate other vector-like structures. */ 2916 /* Allocate other vector-like structures. */
2959 2917
2960 struct Lisp_Vector * 2918 struct Lisp_Vector *
2961 allocate_pseudovector (memlen, lisplen, tag) 2919 allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag)
2962 int memlen, lisplen;
2963 EMACS_INT tag;
2964 { 2920 {
2965 struct Lisp_Vector *v = allocate_vectorlike (memlen); 2921 struct Lisp_Vector *v = allocate_vectorlike (memlen);
2966 EMACS_INT i; 2922 EMACS_INT i;
2967 2923
2968 /* Only the first lisplen slots will be traced normally by the GC. */ 2924 /* Only the first lisplen slots will be traced normally by the GC. */
2980 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE); 2936 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE);
2981 } 2937 }
2982 2938
2983 2939
2984 struct window * 2940 struct window *
2985 allocate_window () 2941 allocate_window (void)
2986 { 2942 {
2987 return ALLOCATE_PSEUDOVECTOR(struct window, current_matrix, PVEC_WINDOW); 2943 return ALLOCATE_PSEUDOVECTOR(struct window, current_matrix, PVEC_WINDOW);
2988 } 2944 }
2989 2945
2990 2946
2991 struct terminal * 2947 struct terminal *
2992 allocate_terminal () 2948 allocate_terminal (void)
2993 { 2949 {
2994 struct terminal *t = ALLOCATE_PSEUDOVECTOR (struct terminal, 2950 struct terminal *t = ALLOCATE_PSEUDOVECTOR (struct terminal,
2995 next_terminal, PVEC_TERMINAL); 2951 next_terminal, PVEC_TERMINAL);
2996 /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ 2952 /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */
2997 bzero (&(t->next_terminal), 2953 bzero (&(t->next_terminal),
2999 2955
3000 return t; 2956 return t;
3001 } 2957 }
3002 2958
3003 struct frame * 2959 struct frame *
3004 allocate_frame () 2960 allocate_frame (void)
3005 { 2961 {
3006 struct frame *f = ALLOCATE_PSEUDOVECTOR (struct frame, 2962 struct frame *f = ALLOCATE_PSEUDOVECTOR (struct frame,
3007 face_cache, PVEC_FRAME); 2963 face_cache, PVEC_FRAME);
3008 /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */ 2964 /* Zero out the non-GC'd fields. FIXME: This should be made unnecessary. */
3009 bzero (&(f->face_cache), 2965 bzero (&(f->face_cache),
3011 return f; 2967 return f;
3012 } 2968 }
3013 2969
3014 2970
3015 struct Lisp_Process * 2971 struct Lisp_Process *
3016 allocate_process () 2972 allocate_process (void)
3017 { 2973 {
3018 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS); 2974 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
3019 } 2975 }
3020 2976
3021 2977
3140 3096
3141 3097
3142 /* Initialize symbol allocation. */ 3098 /* Initialize symbol allocation. */
3143 3099
3144 static void 3100 static void
3145 init_symbol () 3101 init_symbol (void)
3146 { 3102 {
3147 symbol_block = NULL; 3103 symbol_block = NULL;
3148 symbol_block_index = SYMBOL_BLOCK_SIZE; 3104 symbol_block_index = SYMBOL_BLOCK_SIZE;
3149 symbol_free_list = 0; 3105 symbol_free_list = 0;
3150 n_symbol_blocks = 0; 3106 n_symbol_blocks = 0;
3231 /* Total number of marker blocks now in use. */ 3187 /* Total number of marker blocks now in use. */
3232 3188
3233 static int n_marker_blocks; 3189 static int n_marker_blocks;
3234 3190
3235 static void 3191 static void
3236 init_marker () 3192 init_marker (void)
3237 { 3193 {
3238 marker_block = NULL; 3194 marker_block = NULL;
3239 marker_block_index = MARKER_BLOCK_SIZE; 3195 marker_block_index = MARKER_BLOCK_SIZE;
3240 marker_free_list = 0; 3196 marker_free_list = 0;
3241 n_marker_blocks = 0; 3197 n_marker_blocks = 0;
3242 } 3198 }
3243 3199
3244 /* Return a newly allocated Lisp_Misc object, with no substructure. */ 3200 /* Return a newly allocated Lisp_Misc object, with no substructure. */
3245 3201
3246 Lisp_Object 3202 Lisp_Object
3247 allocate_misc () 3203 allocate_misc (void)
3248 { 3204 {
3249 Lisp_Object val; 3205 Lisp_Object val;
3250 3206
3251 /* eassert (!handling_signal); */ 3207 /* eassert (!handling_signal); */
3252 3208
3284 } 3240 }
3285 3241
3286 /* Free a Lisp_Misc object */ 3242 /* Free a Lisp_Misc object */
3287 3243
3288 void 3244 void
3289 free_misc (misc) 3245 free_misc (Lisp_Object misc)
3290 Lisp_Object misc;
3291 { 3246 {
3292 XMISCTYPE (misc) = Lisp_Misc_Free; 3247 XMISCTYPE (misc) = Lisp_Misc_Free;
3293 XMISC (misc)->u_free.chain = marker_free_list; 3248 XMISC (misc)->u_free.chain = marker_free_list;
3294 marker_free_list = XMISC (misc); 3249 marker_free_list = XMISC (misc);
3295 3250
3299 /* Return a Lisp_Misc_Save_Value object containing POINTER and 3254 /* Return a Lisp_Misc_Save_Value object containing POINTER and
3300 INTEGER. This is used to package C values to call record_unwind_protect. 3255 INTEGER. This is used to package C values to call record_unwind_protect.
3301 The unwind function can get the C values back using XSAVE_VALUE. */ 3256 The unwind function can get the C values back using XSAVE_VALUE. */
3302 3257
3303 Lisp_Object 3258 Lisp_Object
3304 make_save_value (pointer, integer) 3259 make_save_value (void *pointer, int integer)
3305 void *pointer;
3306 int integer;
3307 { 3260 {
3308 register Lisp_Object val; 3261 register Lisp_Object val;
3309 register struct Lisp_Save_Value *p; 3262 register struct Lisp_Save_Value *p;
3310 3263
3311 val = allocate_misc (); 3264 val = allocate_misc ();
3336 } 3289 }
3337 3290
3338 /* Put MARKER back on the free list after using it temporarily. */ 3291 /* Put MARKER back on the free list after using it temporarily. */
3339 3292
3340 void 3293 void
3341 free_marker (marker) 3294 free_marker (Lisp_Object marker)
3342 Lisp_Object marker;
3343 { 3295 {
3344 unchain_marker (XMARKER (marker)); 3296 unchain_marker (XMARKER (marker));
3345 free_misc (marker); 3297 free_misc (marker);
3346 } 3298 }
3347 3299
3351 in a string of events, make a string; otherwise, make a vector. 3303 in a string of events, make a string; otherwise, make a vector.
3352 3304
3353 Any number of arguments, even zero arguments, are allowed. */ 3305 Any number of arguments, even zero arguments, are allowed. */
3354 3306
3355 Lisp_Object 3307 Lisp_Object
3356 make_event_array (nargs, args) 3308 make_event_array (register int nargs, Lisp_Object *args)
3357 register int nargs;
3358 Lisp_Object *args;
3359 { 3309 {
3360 int i; 3310 int i;
3361 3311
3362 for (i = 0; i < nargs; i++) 3312 for (i = 0; i < nargs; i++)
3363 /* The things that fit in a string 3313 /* The things that fit in a string
3393 3343
3394 3344
3395 /* Called if malloc returns zero. */ 3345 /* Called if malloc returns zero. */
3396 3346
3397 void 3347 void
3398 memory_full () 3348 memory_full (void)
3399 { 3349 {
3400 int i; 3350 int i;
3401 3351
3402 Vmemory_full = Qt; 3352 Vmemory_full = Qt;
3403 3353
3433 3383
3434 This is called when a relocatable block is freed in ralloc.c, 3384 This is called when a relocatable block is freed in ralloc.c,
3435 and also directly from this file, in case we're not using ralloc.c. */ 3385 and also directly from this file, in case we're not using ralloc.c. */
3436 3386
3437 void 3387 void
3438 refill_memory_reserve () 3388 refill_memory_reserve (void)
3439 { 3389 {
3440 #ifndef SYSTEM_MALLOC 3390 #ifndef SYSTEM_MALLOC
3441 if (spare_memory[0] == 0) 3391 if (spare_memory[0] == 0)
3442 spare_memory[0] = (char *) malloc ((size_t) SPARE_MEMORY); 3392 spare_memory[0] = (char *) malloc ((size_t) SPARE_MEMORY);
3443 if (spare_memory[1] == 0) 3393 if (spare_memory[1] == 0)
3481 object or not. */ 3431 object or not. */
3482 3432
3483 /* Initialize this part of alloc.c. */ 3433 /* Initialize this part of alloc.c. */
3484 3434
3485 static void 3435 static void
3486 mem_init () 3436 mem_init (void)
3487 { 3437 {
3488 mem_z.left = mem_z.right = MEM_NIL; 3438 mem_z.left = mem_z.right = MEM_NIL;
3489 mem_z.parent = NULL; 3439 mem_z.parent = NULL;
3490 mem_z.color = MEM_BLACK; 3440 mem_z.color = MEM_BLACK;
3491 mem_z.start = mem_z.end = NULL; 3441 mem_z.start = mem_z.end = NULL;
3495 3445
3496 /* Value is a pointer to the mem_node containing START. Value is 3446 /* Value is a pointer to the mem_node containing START. Value is
3497 MEM_NIL if there is no node in the tree containing START. */ 3447 MEM_NIL if there is no node in the tree containing START. */
3498 3448
3499 static INLINE struct mem_node * 3449 static INLINE struct mem_node *
3500 mem_find (start) 3450 mem_find (void *start)
3501 void *start;
3502 { 3451 {
3503 struct mem_node *p; 3452 struct mem_node *p;
3504 3453
3505 if (start < min_heap_address || start > max_heap_address) 3454 if (start < min_heap_address || start > max_heap_address)
3506 return MEM_NIL; 3455 return MEM_NIL;
3519 /* Insert a new node into the tree for a block of memory with start 3468 /* Insert a new node into the tree for a block of memory with start
3520 address START, end address END, and type TYPE. Value is a 3469 address START, end address END, and type TYPE. Value is a
3521 pointer to the node that was inserted. */ 3470 pointer to the node that was inserted. */
3522 3471
3523 static struct mem_node * 3472 static struct mem_node *
3524 mem_insert (start, end, type) 3473 mem_insert (void *start, void *end, enum mem_type type)
3525 void *start, *end;
3526 enum mem_type type;
3527 { 3474 {
3528 struct mem_node *c, *parent, *x; 3475 struct mem_node *c, *parent, *x;
3529 3476
3530 if (min_heap_address == NULL || start < min_heap_address) 3477 if (min_heap_address == NULL || start < min_heap_address)
3531 min_heap_address = start; 3478 min_heap_address = start;
3593 3540
3594 /* Re-establish the red-black properties of the tree, and thereby 3541 /* Re-establish the red-black properties of the tree, and thereby
3595 balance the tree, after node X has been inserted; X is always red. */ 3542 balance the tree, after node X has been inserted; X is always red. */
3596 3543
3597 static void 3544 static void
3598 mem_insert_fixup (x) 3545 mem_insert_fixup (struct mem_node *x)
3599 struct mem_node *x;
3600 { 3546 {
3601 while (x != mem_root && x->parent->color == MEM_RED) 3547 while (x != mem_root && x->parent->color == MEM_RED)
3602 { 3548 {
3603 /* X is red and its parent is red. This is a violation of 3549 /* X is red and its parent is red. This is a violation of
3604 red-black tree property #3. */ 3550 red-black tree property #3. */
3672 a (y) ===> (x) c 3618 a (y) ===> (x) c
3673 / \ / \ 3619 / \ / \
3674 b c a b */ 3620 b c a b */
3675 3621
3676 static void 3622 static void
3677 mem_rotate_left (x) 3623 mem_rotate_left (struct mem_node *x)
3678 struct mem_node *x;
3679 { 3624 {
3680 struct mem_node *y; 3625 struct mem_node *y;
3681 3626
3682 /* Turn y's left sub-tree into x's right sub-tree. */ 3627 /* Turn y's left sub-tree into x's right sub-tree. */
3683 y = x->right; 3628 y = x->right;
3712 (y) c ===> a (x) 3657 (y) c ===> a (x)
3713 / \ / \ 3658 / \ / \
3714 a b b c */ 3659 a b b c */
3715 3660
3716 static void 3661 static void
3717 mem_rotate_right (x) 3662 mem_rotate_right (struct mem_node *x)
3718 struct mem_node *x;
3719 { 3663 {
3720 struct mem_node *y = x->left; 3664 struct mem_node *y = x->left;
3721 3665
3722 x->left = y->right; 3666 x->left = y->right;
3723 if (y->right != MEM_NIL) 3667 if (y->right != MEM_NIL)
3742 3686
3743 3687
3744 /* Delete node Z from the tree. If Z is null or MEM_NIL, do nothing. */ 3688 /* Delete node Z from the tree. If Z is null or MEM_NIL, do nothing. */
3745 3689
3746 static void 3690 static void
3747 mem_delete (z) 3691 mem_delete (struct mem_node *z)
3748 struct mem_node *z;
3749 { 3692 {
3750 struct mem_node *x, *y; 3693 struct mem_node *x, *y;
3751 3694
3752 if (!z || z == MEM_NIL) 3695 if (!z || z == MEM_NIL)
3753 return; 3696 return;
3797 3740
3798 /* Re-establish the red-black properties of the tree, after a 3741 /* Re-establish the red-black properties of the tree, after a
3799 deletion. */ 3742 deletion. */
3800 3743
3801 static void 3744 static void
3802 mem_delete_fixup (x) 3745 mem_delete_fixup (struct mem_node *x)
3803 struct mem_node *x;
3804 { 3746 {
3805 while (x != mem_root && x->color == MEM_BLACK) 3747 while (x != mem_root && x->color == MEM_BLACK)
3806 { 3748 {
3807 if (x == x->parent->left) 3749 if (x == x->parent->left)
3808 { 3750 {
3879 3821
3880 /* Value is non-zero if P is a pointer to a live Lisp string on 3822 /* Value is non-zero if P is a pointer to a live Lisp string on
3881 the heap. M is a pointer to the mem_block for P. */ 3823 the heap. M is a pointer to the mem_block for P. */
3882 3824
3883 static INLINE int 3825 static INLINE int
3884 live_string_p (m, p) 3826 live_string_p (struct mem_node *m, void *p)
3885 struct mem_node *m;
3886 void *p;
3887 { 3827 {
3888 if (m->type == MEM_TYPE_STRING) 3828 if (m->type == MEM_TYPE_STRING)
3889 { 3829 {
3890 struct string_block *b = (struct string_block *) m->start; 3830 struct string_block *b = (struct string_block *) m->start;
3891 int offset = (char *) p - (char *) &b->strings[0]; 3831 int offset = (char *) p - (char *) &b->strings[0];
3904 3844
3905 /* Value is non-zero if P is a pointer to a live Lisp cons on 3845 /* Value is non-zero if P is a pointer to a live Lisp cons on
3906 the heap. M is a pointer to the mem_block for P. */ 3846 the heap. M is a pointer to the mem_block for P. */
3907 3847
3908 static INLINE int 3848 static INLINE int
3909 live_cons_p (m, p) 3849 live_cons_p (struct mem_node *m, void *p)
3910 struct mem_node *m;
3911 void *p;
3912 { 3850 {
3913 if (m->type == MEM_TYPE_CONS) 3851 if (m->type == MEM_TYPE_CONS)
3914 { 3852 {
3915 struct cons_block *b = (struct cons_block *) m->start; 3853 struct cons_block *b = (struct cons_block *) m->start;
3916 int offset = (char *) p - (char *) &b->conses[0]; 3854 int offset = (char *) p - (char *) &b->conses[0];
3932 3870
3933 /* Value is non-zero if P is a pointer to a live Lisp symbol on 3871 /* Value is non-zero if P is a pointer to a live Lisp symbol on
3934 the heap. M is a pointer to the mem_block for P. */ 3872 the heap. M is a pointer to the mem_block for P. */
3935 3873
3936 static INLINE int 3874 static INLINE int
3937 live_symbol_p (m, p) 3875 live_symbol_p (struct mem_node *m, void *p)
3938 struct mem_node *m;
3939 void *p;
3940 { 3876 {
3941 if (m->type == MEM_TYPE_SYMBOL) 3877 if (m->type == MEM_TYPE_SYMBOL)
3942 { 3878 {
3943 struct symbol_block *b = (struct symbol_block *) m->start; 3879 struct symbol_block *b = (struct symbol_block *) m->start;
3944 int offset = (char *) p - (char *) &b->symbols[0]; 3880 int offset = (char *) p - (char *) &b->symbols[0];
3960 3896
3961 /* Value is non-zero if P is a pointer to a live Lisp float on 3897 /* Value is non-zero if P is a pointer to a live Lisp float on
3962 the heap. M is a pointer to the mem_block for P. */ 3898 the heap. M is a pointer to the mem_block for P. */
3963 3899
3964 static INLINE int 3900 static INLINE int
3965 live_float_p (m, p) 3901 live_float_p (struct mem_node *m, void *p)
3966 struct mem_node *m;
3967 void *p;
3968 { 3902 {
3969 if (m->type == MEM_TYPE_FLOAT) 3903 if (m->type == MEM_TYPE_FLOAT)
3970 { 3904 {
3971 struct float_block *b = (struct float_block *) m->start; 3905 struct float_block *b = (struct float_block *) m->start;
3972 int offset = (char *) p - (char *) &b->floats[0]; 3906 int offset = (char *) p - (char *) &b->floats[0];
3986 3920
3987 /* Value is non-zero if P is a pointer to a live Lisp Misc on 3921 /* Value is non-zero if P is a pointer to a live Lisp Misc on
3988 the heap. M is a pointer to the mem_block for P. */ 3922 the heap. M is a pointer to the mem_block for P. */
3989 3923
3990 static INLINE int 3924 static INLINE int
3991 live_misc_p (m, p) 3925 live_misc_p (struct mem_node *m, void *p)
3992 struct mem_node *m;
3993 void *p;
3994 { 3926 {
3995 if (m->type == MEM_TYPE_MISC) 3927 if (m->type == MEM_TYPE_MISC)
3996 { 3928 {
3997 struct marker_block *b = (struct marker_block *) m->start; 3929 struct marker_block *b = (struct marker_block *) m->start;
3998 int offset = (char *) p - (char *) &b->markers[0]; 3930 int offset = (char *) p - (char *) &b->markers[0];
4014 3946
4015 /* Value is non-zero if P is a pointer to a live vector-like object. 3947 /* Value is non-zero if P is a pointer to a live vector-like object.
4016 M is a pointer to the mem_block for P. */ 3948 M is a pointer to the mem_block for P. */
4017 3949
4018 static INLINE int 3950 static INLINE int
4019 live_vector_p (m, p) 3951 live_vector_p (struct mem_node *m, void *p)
4020 struct mem_node *m;
4021 void *p;
4022 { 3952 {
4023 return (p == m->start && m->type == MEM_TYPE_VECTORLIKE); 3953 return (p == m->start && m->type == MEM_TYPE_VECTORLIKE);
4024 } 3954 }
4025 3955
4026 3956
4027 /* Value is non-zero if P is a pointer to a live buffer. M is a 3957 /* Value is non-zero if P is a pointer to a live buffer. M is a
4028 pointer to the mem_block for P. */ 3958 pointer to the mem_block for P. */
4029 3959
4030 static INLINE int 3960 static INLINE int
4031 live_buffer_p (m, p) 3961 live_buffer_p (struct mem_node *m, void *p)
4032 struct mem_node *m;
4033 void *p;
4034 { 3962 {
4035 /* P must point to the start of the block, and the buffer 3963 /* P must point to the start of the block, and the buffer
4036 must not have been killed. */ 3964 must not have been killed. */
4037 return (m->type == MEM_TYPE_BUFFER 3965 return (m->type == MEM_TYPE_BUFFER
4038 && p == m->start 3966 && p == m->start
4094 4022
4095 4023
4096 /* Mark OBJ if we can prove it's a Lisp_Object. */ 4024 /* Mark OBJ if we can prove it's a Lisp_Object. */
4097 4025
4098 static INLINE void 4026 static INLINE void
4099 mark_maybe_object (obj) 4027 mark_maybe_object (Lisp_Object obj)
4100 Lisp_Object obj;
4101 { 4028 {
4102 void *po = (void *) XPNTR (obj); 4029 void *po = (void *) XPNTR (obj);
4103 struct mem_node *m = mem_find (po); 4030 struct mem_node *m = mem_find (po);
4104 4031
4105 if (m != MEM_NIL) 4032 if (m != MEM_NIL)
4158 4085
4159 /* If P points to Lisp data, mark that as live if it isn't already 4086 /* If P points to Lisp data, mark that as live if it isn't already
4160 marked. */ 4087 marked. */
4161 4088
4162 static INLINE void 4089 static INLINE void
4163 mark_maybe_pointer (p) 4090 mark_maybe_pointer (void *p)
4164 void *p;
4165 { 4091 {
4166 struct mem_node *m; 4092 struct mem_node *m;
4167 4093
4168 /* Quickly rule out some values which can't point to Lisp data. */ 4094 /* Quickly rule out some values which can't point to Lisp data. */
4169 if ((EMACS_INT) p % 4095 if ((EMACS_INT) p %
4239 4165
4240 /* Mark Lisp objects referenced from the address range START+OFFSET..END 4166 /* Mark Lisp objects referenced from the address range START+OFFSET..END
4241 or END+OFFSET..START. */ 4167 or END+OFFSET..START. */
4242 4168
4243 static void 4169 static void
4244 mark_memory (start, end, offset) 4170 mark_memory (void *start, void *end, int offset)
4245 void *start, *end;
4246 int offset;
4247 { 4171 {
4248 Lisp_Object *p; 4172 Lisp_Object *p;
4249 void **pp; 4173 void **pp;
4250 4174
4251 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 4175 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
4457 4381
4458 The current code assumes by default that Lisp_Objects are aligned 4382 The current code assumes by default that Lisp_Objects are aligned
4459 equally on the stack. */ 4383 equally on the stack. */
4460 4384
4461 static void 4385 static void
4462 mark_stack () 4386 mark_stack (void)
4463 { 4387 {
4464 int i; 4388 int i;
4465 /* jmp_buf may not be aligned enough on darwin-ppc64 */ 4389 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4466 union aligned_jmpbuf { 4390 union aligned_jmpbuf {
4467 Lisp_Object o; 4391 Lisp_Object o;
4532 #endif /* GC_MARK_STACK != 0 */ 4456 #endif /* GC_MARK_STACK != 0 */
4533 4457
4534 4458
4535 /* Determine whether it is safe to access memory at address P. */ 4459 /* Determine whether it is safe to access memory at address P. */
4536 static int 4460 static int
4537 valid_pointer_p (p) 4461 valid_pointer_p (void *p)
4538 void *p;
4539 { 4462 {
4540 #ifdef WINDOWSNT 4463 #ifdef WINDOWSNT
4541 return w32_valid_pointer_p (p, 16); 4464 return w32_valid_pointer_p (p, 16);
4542 #else 4465 #else
4543 int fd; 4466 int fd;
4564 Return -1 if we cannot validate OBJ. 4487 Return -1 if we cannot validate OBJ.
4565 This function can be quite slow, 4488 This function can be quite slow,
4566 so it should only be used in code for manual debugging. */ 4489 so it should only be used in code for manual debugging. */
4567 4490
4568 int 4491 int
4569 valid_lisp_object_p (obj) 4492 valid_lisp_object_p (Lisp_Object obj)
4570 Lisp_Object obj;
4571 { 4493 {
4572 void *p; 4494 void *p;
4573 #if GC_MARK_STACK 4495 #if GC_MARK_STACK
4574 struct mem_node *m; 4496 struct mem_node *m;
4575 #endif 4497 #endif
4643 /* Allocate room for SIZE bytes from pure Lisp storage and return a 4565 /* Allocate room for SIZE bytes from pure Lisp storage and return a
4644 pointer to it. TYPE is the Lisp type for which the memory is 4566 pointer to it. TYPE is the Lisp type for which the memory is
4645 allocated. TYPE < 0 means it's not used for a Lisp object. */ 4567 allocated. TYPE < 0 means it's not used for a Lisp object. */
4646 4568
4647 static POINTER_TYPE * 4569 static POINTER_TYPE *
4648 pure_alloc (size, type) 4570 pure_alloc (size_t size, int type)
4649 size_t size;
4650 int type;
4651 { 4571 {
4652 POINTER_TYPE *result; 4572 POINTER_TYPE *result;
4653 #ifdef USE_LSB_TAG 4573 #ifdef USE_LSB_TAG
4654 size_t alignment = (1 << GCTYPEBITS); 4574 size_t alignment = (1 << GCTYPEBITS);
4655 #else 4575 #else
4699 4619
4700 4620
4701 /* Print a warning if PURESIZE is too small. */ 4621 /* Print a warning if PURESIZE is too small. */
4702 4622
4703 void 4623 void
4704 check_pure_size () 4624 check_pure_size (void)
4705 { 4625 {
4706 if (pure_bytes_used_before_overflow) 4626 if (pure_bytes_used_before_overflow)
4707 message ("emacs:0:Pure Lisp storage overflow (approx. %d bytes needed)", 4627 message ("emacs:0:Pure Lisp storage overflow (approx. %d bytes needed)",
4708 (int) (pure_bytes_used + pure_bytes_used_before_overflow)); 4628 (int) (pure_bytes_used + pure_bytes_used_before_overflow));
4709 } 4629 }
4712 /* Find the byte sequence {DATA[0], ..., DATA[NBYTES-1], '\0'} from 4632 /* Find the byte sequence {DATA[0], ..., DATA[NBYTES-1], '\0'} from
4713 the non-Lisp data pool of the pure storage, and return its start 4633 the non-Lisp data pool of the pure storage, and return its start
4714 address. Return NULL if not found. */ 4634 address. Return NULL if not found. */
4715 4635
4716 static char * 4636 static char *
4717 find_string_data_in_pure (data, nbytes) 4637 find_string_data_in_pure (const char *data, int nbytes)
4718 const char *data;
4719 int nbytes;
4720 { 4638 {
4721 int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4639 int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4722 const unsigned char *p; 4640 const unsigned char *p;
4723 char *non_lisp_beg; 4641 char *non_lisp_beg;
4724 4642
4783 Must get an error if pure storage is full, since if it cannot hold 4701 Must get an error if pure storage is full, since if it cannot hold
4784 a large string it may be able to hold conses that point to that 4702 a large string it may be able to hold conses that point to that
4785 string; then the string is not protected from gc. */ 4703 string; then the string is not protected from gc. */
4786 4704
4787 Lisp_Object 4705 Lisp_Object
4788 make_pure_string (data, nchars, nbytes, multibyte) 4706 make_pure_string (const char *data, int nchars, int nbytes, int multibyte)
4789 const char *data;
4790 int nchars, nbytes;
4791 int multibyte;
4792 { 4707 {
4793 Lisp_Object string; 4708 Lisp_Object string;
4794 struct Lisp_String *s; 4709 struct Lisp_String *s;
4795 4710
4796 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4711 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4829 4744
4830 /* Return a cons allocated from pure space. Give it pure copies 4745 /* Return a cons allocated from pure space. Give it pure copies
4831 of CAR as car and CDR as cdr. */ 4746 of CAR as car and CDR as cdr. */
4832 4747
4833 Lisp_Object 4748 Lisp_Object
4834 pure_cons (car, cdr) 4749 pure_cons (Lisp_Object car, Lisp_Object cdr)
4835 Lisp_Object car, cdr;
4836 { 4750 {
4837 register Lisp_Object new; 4751 register Lisp_Object new;
4838 struct Lisp_Cons *p; 4752 struct Lisp_Cons *p;
4839 4753
4840 p = (struct Lisp_Cons *) pure_alloc (sizeof *p, Lisp_Cons); 4754 p = (struct Lisp_Cons *) pure_alloc (sizeof *p, Lisp_Cons);
4846 4760
4847 4761
4848 /* Value is a float object with value NUM allocated from pure space. */ 4762 /* Value is a float object with value NUM allocated from pure space. */
4849 4763
4850 static Lisp_Object 4764 static Lisp_Object
4851 make_pure_float (num) 4765 make_pure_float (double num)
4852 double num;
4853 { 4766 {
4854 register Lisp_Object new; 4767 register Lisp_Object new;
4855 struct Lisp_Float *p; 4768 struct Lisp_Float *p;
4856 4769
4857 p = (struct Lisp_Float *) pure_alloc (sizeof *p, Lisp_Float); 4770 p = (struct Lisp_Float *) pure_alloc (sizeof *p, Lisp_Float);
4863 4776
4864 /* Return a vector with room for LEN Lisp_Objects allocated from 4777 /* Return a vector with room for LEN Lisp_Objects allocated from
4865 pure space. */ 4778 pure space. */
4866 4779
4867 Lisp_Object 4780 Lisp_Object
4868 make_pure_vector (len) 4781 make_pure_vector (EMACS_INT len)
4869 EMACS_INT len;
4870 { 4782 {
4871 Lisp_Object new; 4783 Lisp_Object new;
4872 struct Lisp_Vector *p; 4784 struct Lisp_Vector *p;
4873 size_t size = sizeof *p + (len - 1) * sizeof (Lisp_Object); 4785 size_t size = sizeof *p + (len - 1) * sizeof (Lisp_Object);
4874 4786
4947 4859
4948 /* Put an entry in staticvec, pointing at the variable with address 4860 /* Put an entry in staticvec, pointing at the variable with address
4949 VARADDRESS. */ 4861 VARADDRESS. */
4950 4862
4951 void 4863 void
4952 staticpro (varaddress) 4864 staticpro (Lisp_Object *varaddress)
4953 Lisp_Object *varaddress;
4954 { 4865 {
4955 staticvec[staticidx++] = varaddress; 4866 staticvec[staticidx++] = varaddress;
4956 if (staticidx >= NSTATICS) 4867 if (staticidx >= NSTATICS)
4957 abort (); 4868 abort ();
4958 } 4869 }
4963 ***********************************************************************/ 4874 ***********************************************************************/
4964 4875
4965 /* Temporarily prevent garbage collection. */ 4876 /* Temporarily prevent garbage collection. */
4966 4877
4967 int 4878 int
4968 inhibit_garbage_collection () 4879 inhibit_garbage_collection (void)
4969 { 4880 {
4970 int count = SPECPDL_INDEX (); 4881 int count = SPECPDL_INDEX ();
4971 int nbits = min (VALBITS, BITS_PER_INT); 4882 int nbits = min (VALBITS, BITS_PER_INT);
4972 4883
4973 specbind (Qgc_cons_threshold, make_number (((EMACS_INT) 1 << (nbits - 1)) - 1)); 4884 specbind (Qgc_cons_threshold, make_number (((EMACS_INT) 1 << (nbits - 1)) - 1));
5295 5206
5296 /* Mark Lisp objects in glyph matrix MATRIX. Currently the 5207 /* Mark Lisp objects in glyph matrix MATRIX. Currently the
5297 only interesting objects referenced from glyphs are strings. */ 5208 only interesting objects referenced from glyphs are strings. */
5298 5209
5299 static void 5210 static void
5300 mark_glyph_matrix (matrix) 5211 mark_glyph_matrix (struct glyph_matrix *matrix)
5301 struct glyph_matrix *matrix;
5302 { 5212 {
5303 struct glyph_row *row = matrix->rows; 5213 struct glyph_row *row = matrix->rows;
5304 struct glyph_row *end = row + matrix->nrows; 5214 struct glyph_row *end = row + matrix->nrows;
5305 5215
5306 for (; row < end; ++row) 5216 for (; row < end; ++row)
5322 5232
5323 5233
5324 /* Mark Lisp faces in the face cache C. */ 5234 /* Mark Lisp faces in the face cache C. */
5325 5235
5326 static void 5236 static void
5327 mark_face_cache (c) 5237 mark_face_cache (struct face_cache *c)
5328 struct face_cache *c;
5329 { 5238 {
5330 if (c) 5239 if (c)
5331 { 5240 {
5332 int i, j; 5241 int i, j;
5333 for (i = 0; i < c->used; ++i) 5242 for (i = 0; i < c->used; ++i)
5358 the call to abort will hit a breakpoint. 5267 the call to abort will hit a breakpoint.
5359 Normally this is zero and the check never goes off. */ 5268 Normally this is zero and the check never goes off. */
5360 static int mark_object_loop_halt; 5269 static int mark_object_loop_halt;
5361 5270
5362 static void 5271 static void
5363 mark_vectorlike (ptr) 5272 mark_vectorlike (struct Lisp_Vector *ptr)
5364 struct Lisp_Vector *ptr;
5365 { 5273 {
5366 register EMACS_INT size = ptr->size; 5274 register EMACS_INT size = ptr->size;
5367 register int i; 5275 register int i;
5368 5276
5369 eassert (!VECTOR_MARKED_P (ptr)); 5277 eassert (!VECTOR_MARKED_P (ptr));
5382 /* Like mark_vectorlike but optimized for char-tables (and 5290 /* Like mark_vectorlike but optimized for char-tables (and
5383 sub-char-tables) assuming that the contents are mostly integers or 5291 sub-char-tables) assuming that the contents are mostly integers or
5384 symbols. */ 5292 symbols. */
5385 5293
5386 static void 5294 static void
5387 mark_char_table (ptr) 5295 mark_char_table (struct Lisp_Vector *ptr)
5388 struct Lisp_Vector *ptr;
5389 { 5296 {
5390 register EMACS_INT size = ptr->size & PSEUDOVECTOR_SIZE_MASK; 5297 register EMACS_INT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
5391 register int i; 5298 register int i;
5392 5299
5393 eassert (!VECTOR_MARKED_P (ptr)); 5300 eassert (!VECTOR_MARKED_P (ptr));
5407 mark_object (val); 5314 mark_object (val);
5408 } 5315 }
5409 } 5316 }
5410 5317
5411 void 5318 void
5412 mark_object (arg) 5319 mark_object (Lisp_Object arg)
5413 Lisp_Object arg;
5414 { 5320 {
5415 register Lisp_Object obj = arg; 5321 register Lisp_Object obj = arg;
5416 #ifdef GC_CHECK_MARKED_OBJECTS 5322 #ifdef GC_CHECK_MARKED_OBJECTS
5417 void *po; 5323 void *po;
5418 struct mem_node *m; 5324 struct mem_node *m;
5717 } 5623 }
5718 5624
5719 /* Mark the pointers in a buffer structure. */ 5625 /* Mark the pointers in a buffer structure. */
5720 5626
5721 static void 5627 static void
5722 mark_buffer (buf) 5628 mark_buffer (Lisp_Object buf)
5723 Lisp_Object buf;
5724 { 5629 {
5725 register struct buffer *buffer = XBUFFER (buf); 5630 register struct buffer *buffer = XBUFFER (buf);
5726 register Lisp_Object *ptr, tmp; 5631 register Lisp_Object *ptr, tmp;
5727 Lisp_Object base_buffer; 5632 Lisp_Object base_buffer;
5728 5633
5785 5690
5786 /* Value is non-zero if OBJ will survive the current GC because it's 5691 /* Value is non-zero if OBJ will survive the current GC because it's
5787 either marked or does not need to be marked to survive. */ 5692 either marked or does not need to be marked to survive. */
5788 5693
5789 int 5694 int
5790 survives_gc_p (obj) 5695 survives_gc_p (Lisp_Object obj)
5791 Lisp_Object obj;
5792 { 5696 {
5793 int survives_p; 5697 int survives_p;
5794 5698
5795 switch (XTYPE (obj)) 5699 switch (XTYPE (obj))
5796 { 5700 {
5832 5736
5833 5737
5834 /* Sweep: find all structures not marked, and free them. */ 5738 /* Sweep: find all structures not marked, and free them. */
5835 5739
5836 static void 5740 static void
5837 gc_sweep () 5741 gc_sweep (void)
5838 { 5742 {
5839 /* Remove or mark entries in weak hash tables. 5743 /* Remove or mark entries in weak hash tables.
5840 This must be done before any object is unmarked. */ 5744 This must be done before any object is unmarked. */
5841 sweep_weak_hash_tables (); 5745 sweep_weak_hash_tables ();
5842 5746
6249 } 6153 }
6250 6154
6251 int suppress_checking; 6155 int suppress_checking;
6252 6156
6253 void 6157 void
6254 die (msg, file, line) 6158 die (const char *msg, const char *file, int line)
6255 const char *msg;
6256 const char *file;
6257 int line;
6258 { 6159 {
6259 fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n", 6160 fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n",
6260 file, line, msg); 6161 file, line, msg);
6261 abort (); 6162 abort ();
6262 } 6163 }
6263 6164
6264 /* Initialization */ 6165 /* Initialization */
6265 6166
6266 void 6167 void
6267 init_alloc_once () 6168 init_alloc_once (void)
6268 { 6169 {
6269 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */ 6170 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */
6270 purebeg = PUREBEG; 6171 purebeg = PUREBEG;
6271 pure_size = PURESIZE; 6172 pure_size = PURESIZE;
6272 pure_bytes_used = 0; 6173 pure_bytes_used = 0;
6317 malloc_sbrk_used = 100000; /* as reasonable as any number */ 6218 malloc_sbrk_used = 100000; /* as reasonable as any number */
6318 #endif /* VIRT_ADDR_VARIES */ 6219 #endif /* VIRT_ADDR_VARIES */
6319 } 6220 }
6320 6221
6321 void 6222 void
6322 init_alloc () 6223 init_alloc (void)
6323 { 6224 {
6324 gcprolist = 0; 6225 gcprolist = 0;
6325 byte_stack_list = 0; 6226 byte_stack_list = 0;
6326 #if GC_MARK_STACK 6227 #if GC_MARK_STACK
6327 #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS 6228 #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS
6331 Vgc_elapsed = make_float (0.0); 6232 Vgc_elapsed = make_float (0.0);
6332 gcs_done = 0; 6233 gcs_done = 0;
6333 } 6234 }
6334 6235
6335 void 6236 void
6336 syms_of_alloc () 6237 syms_of_alloc (void)
6337 { 6238 {
6338 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold, 6239 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold,
6339 doc: /* *Number of bytes of consing between garbage collections. 6240 doc: /* *Number of bytes of consing between garbage collections.
6340 Garbage collection can happen automatically once this many bytes have been 6241 Garbage collection can happen automatically once this many bytes have been
6341 allocated since the last garbage collection. All data types count. 6242 allocated since the last garbage collection. All data types count.