Mercurial > emacs
comparison src/alloc.c @ 49600:23a1cea22d13
Trailing whitespace deleted.
| author | Juanma Barranquero <lekktu@gmail.com> |
|---|---|
| date | Tue, 04 Feb 2003 14:56:31 +0000 |
| parents | fd79b3081e01 |
| children | d9ade23e09df d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
| 49599:5ade352e8d1c | 49600:23a1cea22d13 |
|---|---|
| 354 /* Start and end of allocated region. */ | 354 /* Start and end of allocated region. */ |
| 355 void *start, *end; | 355 void *start, *end; |
| 356 | 356 |
| 357 /* Node color. */ | 357 /* Node color. */ |
| 358 enum {MEM_BLACK, MEM_RED} color; | 358 enum {MEM_BLACK, MEM_RED} color; |
| 359 | 359 |
| 360 /* Memory type. */ | 360 /* Memory type. */ |
| 361 enum mem_type type; | 361 enum mem_type type; |
| 362 }; | 362 }; |
| 363 | 363 |
| 364 /* Base address of stack. Set in main. */ | 364 /* Base address of stack. Set in main. */ |
| 594 BLOCK_INPUT; | 594 BLOCK_INPUT; |
| 595 | 595 |
| 596 #ifdef GC_MALLOC_CHECK | 596 #ifdef GC_MALLOC_CHECK |
| 597 allocated_mem_type = type; | 597 allocated_mem_type = type; |
| 598 #endif | 598 #endif |
| 599 | 599 |
| 600 val = (void *) malloc (nbytes); | 600 val = (void *) malloc (nbytes); |
| 601 | 601 |
| 602 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | 602 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK |
| 603 if (val && type != MEM_TYPE_NON_LISP) | 603 if (val && type != MEM_TYPE_NON_LISP) |
| 604 mem_insert (val, (char *) val + nbytes, type); | 604 mem_insert (val, (char *) val + nbytes, type); |
| 605 #endif | 605 #endif |
| 606 | 606 |
| 607 UNBLOCK_INPUT; | 607 UNBLOCK_INPUT; |
| 608 if (!val && nbytes) | 608 if (!val && nbytes) |
| 609 memory_full (); | 609 memory_full (); |
| 610 return val; | 610 return val; |
| 611 } | 611 } |
| 615 a call to lisp_malloc. */ | 615 a call to lisp_malloc. */ |
| 616 | 616 |
| 617 struct buffer * | 617 struct buffer * |
| 618 allocate_buffer () | 618 allocate_buffer () |
| 619 { | 619 { |
| 620 struct buffer *b | 620 struct buffer *b |
| 621 = (struct buffer *) lisp_malloc (sizeof (struct buffer), | 621 = (struct buffer *) lisp_malloc (sizeof (struct buffer), |
| 622 MEM_TYPE_BUFFER); | 622 MEM_TYPE_BUFFER); |
| 623 VALIDATE_LISP_STORAGE (b, sizeof *b); | 623 VALIDATE_LISP_STORAGE (b, sizeof *b); |
| 624 return b; | 624 return b; |
| 625 } | 625 } |
| 672 | 672 |
| 673 #ifdef GC_MALLOC_CHECK | 673 #ifdef GC_MALLOC_CHECK |
| 674 if (ptr) | 674 if (ptr) |
| 675 { | 675 { |
| 676 struct mem_node *m; | 676 struct mem_node *m; |
| 677 | 677 |
| 678 m = mem_find (ptr); | 678 m = mem_find (ptr); |
| 679 if (m == MEM_NIL || m->start != ptr) | 679 if (m == MEM_NIL || m->start != ptr) |
| 680 { | 680 { |
| 681 fprintf (stderr, | 681 fprintf (stderr, |
| 682 "Freeing `%p' which wasn't allocated with malloc\n", ptr); | 682 "Freeing `%p' which wasn't allocated with malloc\n", ptr); |
| 687 /* fprintf (stderr, "free %p...%p (%p)\n", m->start, m->end, ptr); */ | 687 /* fprintf (stderr, "free %p...%p (%p)\n", m->start, m->end, ptr); */ |
| 688 mem_delete (m); | 688 mem_delete (m); |
| 689 } | 689 } |
| 690 } | 690 } |
| 691 #endif /* GC_MALLOC_CHECK */ | 691 #endif /* GC_MALLOC_CHECK */ |
| 692 | 692 |
| 693 __free_hook = old_free_hook; | 693 __free_hook = old_free_hook; |
| 694 free (ptr); | 694 free (ptr); |
| 695 | 695 |
| 696 /* If we released our reserve (due to running out of memory), | 696 /* If we released our reserve (due to running out of memory), |
| 697 and we have a fair amount free once again, | 697 and we have a fair amount free once again, |
| 698 try to set aside another reserve in case we run out once more. */ | 698 try to set aside another reserve in case we run out once more. */ |
| 699 if (spare_memory == 0 | 699 if (spare_memory == 0 |
| 700 /* Verify there is enough space that even with the malloc | 700 /* Verify there is enough space that even with the malloc |
| 760 mem_insert (value, (char *) value + max (1, size), allocated_mem_type); | 760 mem_insert (value, (char *) value + max (1, size), allocated_mem_type); |
| 761 allocated_mem_type = MEM_TYPE_NON_LISP; | 761 allocated_mem_type = MEM_TYPE_NON_LISP; |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 #endif /* GC_MALLOC_CHECK */ | 764 #endif /* GC_MALLOC_CHECK */ |
| 765 | 765 |
| 766 __malloc_hook = emacs_blocked_malloc; | 766 __malloc_hook = emacs_blocked_malloc; |
| 767 UNBLOCK_INPUT; | 767 UNBLOCK_INPUT; |
| 768 | 768 |
| 769 /* fprintf (stderr, "%p malloc\n", value); */ | 769 /* fprintf (stderr, "%p malloc\n", value); */ |
| 770 return value; | 770 return value; |
| 795 abort (); | 795 abort (); |
| 796 } | 796 } |
| 797 | 797 |
| 798 mem_delete (m); | 798 mem_delete (m); |
| 799 } | 799 } |
| 800 | 800 |
| 801 /* fprintf (stderr, "%p -> realloc\n", ptr); */ | 801 /* fprintf (stderr, "%p -> realloc\n", ptr); */ |
| 802 | 802 |
| 803 /* Prevent malloc from registering blocks. */ | 803 /* Prevent malloc from registering blocks. */ |
| 804 dont_register_blocks = 1; | 804 dont_register_blocks = 1; |
| 805 #endif /* GC_MALLOC_CHECK */ | 805 #endif /* GC_MALLOC_CHECK */ |
| 806 | 806 |
| 807 value = (void *) realloc (ptr, size); | 807 value = (void *) realloc (ptr, size); |
| 818 } | 818 } |
| 819 | 819 |
| 820 /* Can't handle zero size regions in the red-black tree. */ | 820 /* Can't handle zero size regions in the red-black tree. */ |
| 821 mem_insert (value, (char *) value + max (size, 1), MEM_TYPE_NON_LISP); | 821 mem_insert (value, (char *) value + max (size, 1), MEM_TYPE_NON_LISP); |
| 822 } | 822 } |
| 823 | 823 |
| 824 /* fprintf (stderr, "%p <- realloc\n", value); */ | 824 /* fprintf (stderr, "%p <- realloc\n", value); */ |
| 825 #endif /* GC_MALLOC_CHECK */ | 825 #endif /* GC_MALLOC_CHECK */ |
| 826 | 826 |
| 827 __realloc_hook = emacs_blocked_realloc; | 827 __realloc_hook = emacs_blocked_realloc; |
| 828 UNBLOCK_INPUT; | 828 UNBLOCK_INPUT; |
| 829 | 829 |
| 830 return value; | 830 return value; |
| 831 } | 831 } |
| 1067 (STRING) is the size of the data, and DATA contains the string's | 1067 (STRING) is the size of the data, and DATA contains the string's |
| 1068 contents. */ | 1068 contents. */ |
| 1069 struct Lisp_String *string; | 1069 struct Lisp_String *string; |
| 1070 | 1070 |
| 1071 #ifdef GC_CHECK_STRING_BYTES | 1071 #ifdef GC_CHECK_STRING_BYTES |
| 1072 | 1072 |
| 1073 EMACS_INT nbytes; | 1073 EMACS_INT nbytes; |
| 1074 unsigned char data[1]; | 1074 unsigned char data[1]; |
| 1075 | 1075 |
| 1076 #define SDATA_NBYTES(S) (S)->nbytes | 1076 #define SDATA_NBYTES(S) (S)->nbytes |
| 1077 #define SDATA_DATA(S) (S)->data | 1077 #define SDATA_DATA(S) (S)->data |
| 1078 | 1078 |
| 1079 #else /* not GC_CHECK_STRING_BYTES */ | 1079 #else /* not GC_CHECK_STRING_BYTES */ |
| 1080 | 1080 |
| 1081 union | 1081 union |
| 1082 { | 1082 { |
| 1083 /* When STRING in non-null. */ | 1083 /* When STRING in non-null. */ |
| 1084 unsigned char data[1]; | 1084 unsigned char data[1]; |
| 1085 | 1085 |
| 1086 /* When STRING is null. */ | 1086 /* When STRING is null. */ |
| 1087 EMACS_INT nbytes; | 1087 EMACS_INT nbytes; |
| 1088 } u; | 1088 } u; |
| 1089 | 1089 |
| 1090 | 1090 |
| 1091 #define SDATA_NBYTES(S) (S)->u.nbytes | 1091 #define SDATA_NBYTES(S) (S)->u.nbytes |
| 1092 #define SDATA_DATA(S) (S)->u.data | 1092 #define SDATA_DATA(S) (S)->u.data |
| 1093 | 1093 |
| 1094 #endif /* not GC_CHECK_STRING_BYTES */ | 1094 #endif /* not GC_CHECK_STRING_BYTES */ |
| 1163 | 1163 |
| 1164 /* Return a pointer to the sdata structure belonging to Lisp string S. | 1164 /* Return a pointer to the sdata structure belonging to Lisp string S. |
| 1165 S must be live, i.e. S->data must not be null. S->data is actually | 1165 S must be live, i.e. S->data must not be null. S->data is actually |
| 1166 a pointer to the `u.data' member of its sdata structure; the | 1166 a pointer to the `u.data' member of its sdata structure; the |
| 1167 structure starts at a constant offset in front of that. */ | 1167 structure starts at a constant offset in front of that. */ |
| 1168 | 1168 |
| 1169 #ifdef GC_CHECK_STRING_BYTES | 1169 #ifdef GC_CHECK_STRING_BYTES |
| 1170 | 1170 |
| 1171 #define SDATA_OF_STRING(S) \ | 1171 #define SDATA_OF_STRING(S) \ |
| 1172 ((struct sdata *) ((S)->data - sizeof (struct Lisp_String *) \ | 1172 ((struct sdata *) ((S)->data - sizeof (struct Lisp_String *) \ |
| 1173 - sizeof (EMACS_INT))) | 1173 - sizeof (EMACS_INT))) |
| 1236 && s->data | 1236 && s->data |
| 1237 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) | 1237 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) |
| 1238 abort (); | 1238 abort (); |
| 1239 return nbytes; | 1239 return nbytes; |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 /* Check validity of Lisp strings' string_bytes member in B. */ | 1242 /* Check validity of Lisp strings' string_bytes member in B. */ |
| 1243 | 1243 |
| 1244 void | 1244 void |
| 1245 check_sblock (b) | 1245 check_sblock (b) |
| 1246 struct sblock *b; | 1246 struct sblock *b; |
| 1247 { | 1247 { |
| 1248 struct sdata *from, *end, *from_end; | 1248 struct sdata *from, *end, *from_end; |
| 1249 | 1249 |
| 1250 end = b->next_free; | 1250 end = b->next_free; |
| 1251 | 1251 |
| 1252 for (from = &b->first_data; from < end; from = from_end) | 1252 for (from = &b->first_data; from < end; from = from_end) |
| 1253 { | 1253 { |
| 1254 /* Compute the next FROM here because copying below may | 1254 /* Compute the next FROM here because copying below may |
| 1255 overwrite data we need to compute it. */ | 1255 overwrite data we need to compute it. */ |
| 1256 int nbytes; | 1256 int nbytes; |
| 1257 | 1257 |
| 1258 /* Check that the string size recorded in the string is the | 1258 /* Check that the string size recorded in the string is the |
| 1259 same as the one recorded in the sdata structure. */ | 1259 same as the one recorded in the sdata structure. */ |
| 1260 if (from->string) | 1260 if (from->string) |
| 1261 CHECK_STRING_BYTES (from->string); | 1261 CHECK_STRING_BYTES (from->string); |
| 1262 | 1262 |
| 1263 if (from->string) | 1263 if (from->string) |
| 1264 nbytes = GC_STRING_BYTES (from->string); | 1264 nbytes = GC_STRING_BYTES (from->string); |
| 1265 else | 1265 else |
| 1266 nbytes = SDATA_NBYTES (from); | 1266 nbytes = SDATA_NBYTES (from); |
| 1267 | 1267 |
| 1268 nbytes = SDATA_SIZE (nbytes); | 1268 nbytes = SDATA_SIZE (nbytes); |
| 1269 from_end = (struct sdata *) ((char *) from + nbytes); | 1269 from_end = (struct sdata *) ((char *) from + nbytes); |
| 1270 } | 1270 } |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1287 { | 1287 { |
| 1288 struct Lisp_String *s = b->first_data.string; | 1288 struct Lisp_String *s = b->first_data.string; |
| 1289 if (s) | 1289 if (s) |
| 1290 CHECK_STRING_BYTES (s); | 1290 CHECK_STRING_BYTES (s); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 for (b = oldest_sblock; b; b = b->next) | 1293 for (b = oldest_sblock; b; b = b->next) |
| 1294 check_sblock (b); | 1294 check_sblock (b); |
| 1295 } | 1295 } |
| 1296 else | 1296 else |
| 1297 check_sblock (current_sblock); | 1297 check_sblock (current_sblock); |
| 1393 a dumped Emacs. */ | 1393 a dumped Emacs. */ |
| 1394 mallopt (M_MMAP_MAX, 0); | 1394 mallopt (M_MMAP_MAX, 0); |
| 1395 #endif | 1395 #endif |
| 1396 | 1396 |
| 1397 b = (struct sblock *) lisp_malloc (size, MEM_TYPE_NON_LISP); | 1397 b = (struct sblock *) lisp_malloc (size, MEM_TYPE_NON_LISP); |
| 1398 | 1398 |
| 1399 #ifdef DOUG_LEA_MALLOC | 1399 #ifdef DOUG_LEA_MALLOC |
| 1400 /* Back to a reasonable maximum of mmap'ed areas. */ | 1400 /* Back to a reasonable maximum of mmap'ed areas. */ |
| 1401 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 1401 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 1402 #endif | 1402 #endif |
| 1403 | 1403 |
| 1404 b->next_free = &b->first_data; | 1404 b->next_free = &b->first_data; |
| 1405 b->first_data.string = NULL; | 1405 b->first_data.string = NULL; |
| 1406 b->next = large_sblocks; | 1406 b->next = large_sblocks; |
| 1407 large_sblocks = b; | 1407 large_sblocks = b; |
| 1408 } | 1408 } |
| 1426 else | 1426 else |
| 1427 b = current_sblock; | 1427 b = current_sblock; |
| 1428 | 1428 |
| 1429 old_data = s->data ? SDATA_OF_STRING (s) : NULL; | 1429 old_data = s->data ? SDATA_OF_STRING (s) : NULL; |
| 1430 old_nbytes = GC_STRING_BYTES (s); | 1430 old_nbytes = GC_STRING_BYTES (s); |
| 1431 | 1431 |
| 1432 data = b->next_free; | 1432 data = b->next_free; |
| 1433 data->string = s; | 1433 data->string = s; |
| 1434 s->data = SDATA_DATA (data); | 1434 s->data = SDATA_DATA (data); |
| 1435 #ifdef GC_CHECK_STRING_BYTES | 1435 #ifdef GC_CHECK_STRING_BYTES |
| 1436 SDATA_NBYTES (data) = nbytes; | 1436 SDATA_NBYTES (data) = nbytes; |
| 1437 #endif | 1437 #endif |
| 1438 s->size = nchars; | 1438 s->size = nchars; |
| 1439 s->size_byte = nbytes; | 1439 s->size_byte = nbytes; |
| 1440 s->data[nbytes] = '\0'; | 1440 s->data[nbytes] = '\0'; |
| 1441 b->next_free = (struct sdata *) ((char *) data + needed); | 1441 b->next_free = (struct sdata *) ((char *) data + needed); |
| 1442 | 1442 |
| 1443 /* If S had already data assigned, mark that as free by setting its | 1443 /* If S had already data assigned, mark that as free by setting its |
| 1444 string back-pointer to null, and recording the size of the data | 1444 string back-pointer to null, and recording the size of the data |
| 1445 in it. */ | 1445 in it. */ |
| 1446 if (old_data) | 1446 if (old_data) |
| 1447 { | 1447 { |
| 1458 static void | 1458 static void |
| 1459 sweep_strings () | 1459 sweep_strings () |
| 1460 { | 1460 { |
| 1461 struct string_block *b, *next; | 1461 struct string_block *b, *next; |
| 1462 struct string_block *live_blocks = NULL; | 1462 struct string_block *live_blocks = NULL; |
| 1463 | 1463 |
| 1464 string_free_list = NULL; | 1464 string_free_list = NULL; |
| 1465 total_strings = total_free_strings = 0; | 1465 total_strings = total_free_strings = 0; |
| 1466 total_string_size = 0; | 1466 total_string_size = 0; |
| 1467 | 1467 |
| 1468 /* Scan strings_blocks, free Lisp_Strings that aren't marked. */ | 1468 /* Scan strings_blocks, free Lisp_Strings that aren't marked. */ |
| 1482 /* String was not on free-list before. */ | 1482 /* String was not on free-list before. */ |
| 1483 if (STRING_MARKED_P (s)) | 1483 if (STRING_MARKED_P (s)) |
| 1484 { | 1484 { |
| 1485 /* String is live; unmark it and its intervals. */ | 1485 /* String is live; unmark it and its intervals. */ |
| 1486 UNMARK_STRING (s); | 1486 UNMARK_STRING (s); |
| 1487 | 1487 |
| 1488 if (!NULL_INTERVAL_P (s->intervals)) | 1488 if (!NULL_INTERVAL_P (s->intervals)) |
| 1489 UNMARK_BALANCE_INTERVALS (s->intervals); | 1489 UNMARK_BALANCE_INTERVALS (s->intervals); |
| 1490 | 1490 |
| 1491 ++total_strings; | 1491 ++total_strings; |
| 1492 total_string_size += STRING_BYTES (s); | 1492 total_string_size += STRING_BYTES (s); |
| 1554 static void | 1554 static void |
| 1555 free_large_strings () | 1555 free_large_strings () |
| 1556 { | 1556 { |
| 1557 struct sblock *b, *next; | 1557 struct sblock *b, *next; |
| 1558 struct sblock *live_blocks = NULL; | 1558 struct sblock *live_blocks = NULL; |
| 1559 | 1559 |
| 1560 for (b = large_sblocks; b; b = next) | 1560 for (b = large_sblocks; b; b = next) |
| 1561 { | 1561 { |
| 1562 next = b->next; | 1562 next = b->next; |
| 1563 | 1563 |
| 1564 if (b->first_data.string == NULL) | 1564 if (b->first_data.string == NULL) |
| 1595 copying will happen this way. */ | 1595 copying will happen this way. */ |
| 1596 for (b = oldest_sblock; b; b = b->next) | 1596 for (b = oldest_sblock; b; b = b->next) |
| 1597 { | 1597 { |
| 1598 end = b->next_free; | 1598 end = b->next_free; |
| 1599 xassert ((char *) end <= (char *) b + SBLOCK_SIZE); | 1599 xassert ((char *) end <= (char *) b + SBLOCK_SIZE); |
| 1600 | 1600 |
| 1601 for (from = &b->first_data; from < end; from = from_end) | 1601 for (from = &b->first_data; from < end; from = from_end) |
| 1602 { | 1602 { |
| 1603 /* Compute the next FROM here because copying below may | 1603 /* Compute the next FROM here because copying below may |
| 1604 overwrite data we need to compute it. */ | 1604 overwrite data we need to compute it. */ |
| 1605 int nbytes; | 1605 int nbytes; |
| 1609 same as the one recorded in the sdata structure. */ | 1609 same as the one recorded in the sdata structure. */ |
| 1610 if (from->string | 1610 if (from->string |
| 1611 && GC_STRING_BYTES (from->string) != SDATA_NBYTES (from)) | 1611 && GC_STRING_BYTES (from->string) != SDATA_NBYTES (from)) |
| 1612 abort (); | 1612 abort (); |
| 1613 #endif /* GC_CHECK_STRING_BYTES */ | 1613 #endif /* GC_CHECK_STRING_BYTES */ |
| 1614 | 1614 |
| 1615 if (from->string) | 1615 if (from->string) |
| 1616 nbytes = GC_STRING_BYTES (from->string); | 1616 nbytes = GC_STRING_BYTES (from->string); |
| 1617 else | 1617 else |
| 1618 nbytes = SDATA_NBYTES (from); | 1618 nbytes = SDATA_NBYTES (from); |
| 1619 | 1619 |
| 1620 nbytes = SDATA_SIZE (nbytes); | 1620 nbytes = SDATA_SIZE (nbytes); |
| 1621 from_end = (struct sdata *) ((char *) from + nbytes); | 1621 from_end = (struct sdata *) ((char *) from + nbytes); |
| 1622 | 1622 |
| 1623 /* FROM->string non-null means it's alive. Copy its data. */ | 1623 /* FROM->string non-null means it's alive. Copy its data. */ |
| 1624 if (from->string) | 1624 if (from->string) |
| 1625 { | 1625 { |
| 1626 /* If TB is full, proceed with the next sblock. */ | 1626 /* If TB is full, proceed with the next sblock. */ |
| 1627 to_end = (struct sdata *) ((char *) to + nbytes); | 1627 to_end = (struct sdata *) ((char *) to + nbytes); |
| 1631 tb = tb->next; | 1631 tb = tb->next; |
| 1632 tb_end = (struct sdata *) ((char *) tb + SBLOCK_SIZE); | 1632 tb_end = (struct sdata *) ((char *) tb + SBLOCK_SIZE); |
| 1633 to = &tb->first_data; | 1633 to = &tb->first_data; |
| 1634 to_end = (struct sdata *) ((char *) to + nbytes); | 1634 to_end = (struct sdata *) ((char *) to + nbytes); |
| 1635 } | 1635 } |
| 1636 | 1636 |
| 1637 /* Copy, and update the string's `data' pointer. */ | 1637 /* Copy, and update the string's `data' pointer. */ |
| 1638 if (from != to) | 1638 if (from != to) |
| 1639 { | 1639 { |
| 1640 xassert (tb != b || to <= from); | 1640 xassert (tb != b || to <= from); |
| 1641 safe_bcopy ((char *) from, (char *) to, nbytes); | 1641 safe_bcopy ((char *) from, (char *) to, nbytes); |
| 1698 { | 1698 { |
| 1699 bcopy (str, p, len); | 1699 bcopy (str, p, len); |
| 1700 p += len; | 1700 p += len; |
| 1701 } | 1701 } |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 *p = 0; | 1704 *p = 0; |
| 1705 return val; | 1705 return val; |
| 1706 } | 1706 } |
| 1707 | 1707 |
| 1708 | 1708 |
| 1726 | 1726 |
| 1727 /* We must allocate one more elements than LENGTH_IN_ELTS for the | 1727 /* We must allocate one more elements than LENGTH_IN_ELTS for the |
| 1728 slot `size' of the struct Lisp_Bool_Vector. */ | 1728 slot `size' of the struct Lisp_Bool_Vector. */ |
| 1729 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); | 1729 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); |
| 1730 p = XBOOL_VECTOR (val); | 1730 p = XBOOL_VECTOR (val); |
| 1731 | 1731 |
| 1732 /* Get rid of any bits that would cause confusion. */ | 1732 /* Get rid of any bits that would cause confusion. */ |
| 1733 p->vector_size = 0; | 1733 p->vector_size = 0; |
| 1734 XSETBOOL_VECTOR (val, p); | 1734 XSETBOOL_VECTOR (val, p); |
| 1735 p->size = XFASTINT (length); | 1735 p->size = XFASTINT (length); |
| 1736 | 1736 |
| 1737 real_init = (NILP (init) ? 0 : -1); | 1737 real_init = (NILP (init) ? 0 : -1); |
| 1738 for (i = 0; i < length_in_chars ; i++) | 1738 for (i = 0; i < length_in_chars ; i++) |
| 1739 p->data[i] = real_init; | 1739 p->data[i] = real_init; |
| 1740 | 1740 |
| 1741 /* Clear the extraneous bits in the last byte. */ | 1741 /* Clear the extraneous bits in the last byte. */ |
| 1742 if (XINT (length) != length_in_chars * BITS_PER_CHAR) | 1742 if (XINT (length) != length_in_chars * BITS_PER_CHAR) |
| 1743 XBOOL_VECTOR (val)->data[length_in_chars - 1] | 1743 XBOOL_VECTOR (val)->data[length_in_chars - 1] |
| 1744 &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1; | 1744 &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1; |
| 1745 | 1745 |
| 1980 float_block_index = 0; | 1980 float_block_index = 0; |
| 1981 n_float_blocks++; | 1981 n_float_blocks++; |
| 1982 } | 1982 } |
| 1983 XSETFLOAT (val, &float_block->floats[float_block_index++]); | 1983 XSETFLOAT (val, &float_block->floats[float_block_index++]); |
| 1984 } | 1984 } |
| 1985 | 1985 |
| 1986 XFLOAT_DATA (val) = float_value; | 1986 XFLOAT_DATA (val) = float_value; |
| 1987 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */ | 1987 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */ |
| 1988 consing_since_gc += sizeof (struct Lisp_Float); | 1988 consing_since_gc += sizeof (struct Lisp_Float); |
| 1989 floats_consed++; | 1989 floats_consed++; |
| 1990 return val; | 1990 return val; |
| 2087 cons_block_index = 0; | 2087 cons_block_index = 0; |
| 2088 n_cons_blocks++; | 2088 n_cons_blocks++; |
| 2089 } | 2089 } |
| 2090 XSETCONS (val, &cons_block->conses[cons_block_index++]); | 2090 XSETCONS (val, &cons_block->conses[cons_block_index++]); |
| 2091 } | 2091 } |
| 2092 | 2092 |
| 2093 XSETCAR (val, car); | 2093 XSETCAR (val, car); |
| 2094 XSETCDR (val, cdr); | 2094 XSETCDR (val, cdr); |
| 2095 consing_since_gc += sizeof (struct Lisp_Cons); | 2095 consing_since_gc += sizeof (struct Lisp_Cons); |
| 2096 cons_cells_consed++; | 2096 cons_cells_consed++; |
| 2097 return val; | 2097 return val; |
| 2172 | 2172 |
| 2173 if (size > 0) | 2173 if (size > 0) |
| 2174 { | 2174 { |
| 2175 val = Fcons (init, val); | 2175 val = Fcons (init, val); |
| 2176 --size; | 2176 --size; |
| 2177 | 2177 |
| 2178 if (size > 0) | 2178 if (size > 0) |
| 2179 { | 2179 { |
| 2180 val = Fcons (init, val); | 2180 val = Fcons (init, val); |
| 2181 --size; | 2181 --size; |
| 2182 | 2182 |
| 2183 if (size > 0) | 2183 if (size > 0) |
| 2184 { | 2184 { |
| 2185 val = Fcons (init, val); | 2185 val = Fcons (init, val); |
| 2186 --size; | 2186 --size; |
| 2187 | 2187 |
| 2188 if (size > 0) | 2188 if (size > 0) |
| 2189 { | 2189 { |
| 2190 val = Fcons (init, val); | 2190 val = Fcons (init, val); |
| 2191 --size; | 2191 --size; |
| 2192 } | 2192 } |
| 2194 } | 2194 } |
| 2195 } | 2195 } |
| 2196 | 2196 |
| 2197 QUIT; | 2197 QUIT; |
| 2198 } | 2198 } |
| 2199 | 2199 |
| 2200 return val; | 2200 return val; |
| 2201 } | 2201 } |
| 2202 | 2202 |
| 2203 | 2203 |
| 2204 | 2204 |
| 2230 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 2230 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed |
| 2231 because mapped region contents are not preserved in | 2231 because mapped region contents are not preserved in |
| 2232 a dumped Emacs. */ | 2232 a dumped Emacs. */ |
| 2233 mallopt (M_MMAP_MAX, 0); | 2233 mallopt (M_MMAP_MAX, 0); |
| 2234 #endif | 2234 #endif |
| 2235 | 2235 |
| 2236 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0]; | 2236 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0]; |
| 2237 p = (struct Lisp_Vector *) lisp_malloc (nbytes, type); | 2237 p = (struct Lisp_Vector *) lisp_malloc (nbytes, type); |
| 2238 | 2238 |
| 2239 #ifdef DOUG_LEA_MALLOC | 2239 #ifdef DOUG_LEA_MALLOC |
| 2240 /* Back to a reasonable maximum of mmap'ed areas. */ | 2240 /* Back to a reasonable maximum of mmap'ed areas. */ |
| 2241 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 2241 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 2242 #endif | 2242 #endif |
| 2243 | 2243 |
| 2244 VALIDATE_LISP_STORAGE (p, 0); | 2244 VALIDATE_LISP_STORAGE (p, 0); |
| 2245 consing_since_gc += nbytes; | 2245 consing_since_gc += nbytes; |
| 2246 vector_cells_consed += len; | 2246 vector_cells_consed += len; |
| 2247 | 2247 |
| 2248 p->next = all_vectors; | 2248 p->next = all_vectors; |
| 2270 allocate_hash_table () | 2270 allocate_hash_table () |
| 2271 { | 2271 { |
| 2272 EMACS_INT len = VECSIZE (struct Lisp_Hash_Table); | 2272 EMACS_INT len = VECSIZE (struct Lisp_Hash_Table); |
| 2273 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_HASH_TABLE); | 2273 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_HASH_TABLE); |
| 2274 EMACS_INT i; | 2274 EMACS_INT i; |
| 2275 | 2275 |
| 2276 v->size = len; | 2276 v->size = len; |
| 2277 for (i = 0; i < len; ++i) | 2277 for (i = 0; i < len; ++i) |
| 2278 v->contents[i] = Qnil; | 2278 v->contents[i] = Qnil; |
| 2279 | 2279 |
| 2280 return (struct Lisp_Hash_Table *) v; | 2280 return (struct Lisp_Hash_Table *) v; |
| 2281 } | 2281 } |
| 2282 | 2282 |
| 2283 | 2283 |
| 2284 struct window * | 2284 struct window * |
| 2285 allocate_window () | 2285 allocate_window () |
| 2286 { | 2286 { |
| 2287 EMACS_INT len = VECSIZE (struct window); | 2287 EMACS_INT len = VECSIZE (struct window); |
| 2288 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_WINDOW); | 2288 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_WINDOW); |
| 2289 EMACS_INT i; | 2289 EMACS_INT i; |
| 2290 | 2290 |
| 2291 for (i = 0; i < len; ++i) | 2291 for (i = 0; i < len; ++i) |
| 2292 v->contents[i] = Qnil; | 2292 v->contents[i] = Qnil; |
| 2293 v->size = len; | 2293 v->size = len; |
| 2294 | 2294 |
| 2295 return (struct window *) v; | 2295 return (struct window *) v; |
| 2296 } | 2296 } |
| 2297 | 2297 |
| 2298 | 2298 |
| 2299 struct frame * | 2299 struct frame * |
| 2300 allocate_frame () | 2300 allocate_frame () |
| 2301 { | 2301 { |
| 2302 EMACS_INT len = VECSIZE (struct frame); | 2302 EMACS_INT len = VECSIZE (struct frame); |
| 2303 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_FRAME); | 2303 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_FRAME); |
| 2304 EMACS_INT i; | 2304 EMACS_INT i; |
| 2305 | 2305 |
| 2306 for (i = 0; i < len; ++i) | 2306 for (i = 0; i < len; ++i) |
| 2307 v->contents[i] = make_number (0); | 2307 v->contents[i] = make_number (0); |
| 2308 v->size = len; | 2308 v->size = len; |
| 2309 return (struct frame *) v; | 2309 return (struct frame *) v; |
| 2310 } | 2310 } |
| 2314 allocate_process () | 2314 allocate_process () |
| 2315 { | 2315 { |
| 2316 EMACS_INT len = VECSIZE (struct Lisp_Process); | 2316 EMACS_INT len = VECSIZE (struct Lisp_Process); |
| 2317 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_PROCESS); | 2317 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_PROCESS); |
| 2318 EMACS_INT i; | 2318 EMACS_INT i; |
| 2319 | 2319 |
| 2320 for (i = 0; i < len; ++i) | 2320 for (i = 0; i < len; ++i) |
| 2321 v->contents[i] = Qnil; | 2321 v->contents[i] = Qnil; |
| 2322 v->size = len; | 2322 v->size = len; |
| 2323 | 2323 |
| 2324 return (struct Lisp_Process *) v; | 2324 return (struct Lisp_Process *) v; |
| 2325 } | 2325 } |
| 2326 | 2326 |
| 2327 | 2327 |
| 2328 struct Lisp_Vector * | 2328 struct Lisp_Vector * |
| 2329 allocate_other_vector (len) | 2329 allocate_other_vector (len) |
| 2330 EMACS_INT len; | 2330 EMACS_INT len; |
| 2331 { | 2331 { |
| 2332 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_VECTOR); | 2332 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_VECTOR); |
| 2333 EMACS_INT i; | 2333 EMACS_INT i; |
| 2334 | 2334 |
| 2335 for (i = 0; i < len; ++i) | 2335 for (i = 0; i < len; ++i) |
| 2336 v->contents[i] = Qnil; | 2336 v->contents[i] = Qnil; |
| 2337 v->size = len; | 2337 v->size = len; |
| 2338 | 2338 |
| 2339 return v; | 2339 return v; |
| 2340 } | 2340 } |
| 2341 | 2341 |
| 2342 | 2342 |
| 2343 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, | 2343 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, |
| 2545 symbol_block_index = 0; | 2545 symbol_block_index = 0; |
| 2546 n_symbol_blocks++; | 2546 n_symbol_blocks++; |
| 2547 } | 2547 } |
| 2548 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index++]); | 2548 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index++]); |
| 2549 } | 2549 } |
| 2550 | 2550 |
| 2551 p = XSYMBOL (val); | 2551 p = XSYMBOL (val); |
| 2552 p->xname = name; | 2552 p->xname = name; |
| 2553 p->plist = Qnil; | 2553 p->plist = Qnil; |
| 2554 p->value = Qunbound; | 2554 p->value = Qunbound; |
| 2555 p->function = Qunbound; | 2555 p->function = Qunbound; |
| 2626 marker_block_index = 0; | 2626 marker_block_index = 0; |
| 2627 n_marker_blocks++; | 2627 n_marker_blocks++; |
| 2628 } | 2628 } |
| 2629 XSETMISC (val, &marker_block->markers[marker_block_index++]); | 2629 XSETMISC (val, &marker_block->markers[marker_block_index++]); |
| 2630 } | 2630 } |
| 2631 | 2631 |
| 2632 consing_since_gc += sizeof (union Lisp_Misc); | 2632 consing_since_gc += sizeof (union Lisp_Misc); |
| 2633 misc_objects_consed++; | 2633 misc_objects_consed++; |
| 2634 return val; | 2634 return val; |
| 2635 } | 2635 } |
| 2636 | 2636 |
| 2711 | 2711 |
| 2712 /* Since the loop exited, we know that all the things in it are | 2712 /* Since the loop exited, we know that all the things in it are |
| 2713 characters, so we can make a string. */ | 2713 characters, so we can make a string. */ |
| 2714 { | 2714 { |
| 2715 Lisp_Object result; | 2715 Lisp_Object result; |
| 2716 | 2716 |
| 2717 result = Fmake_string (make_number (nargs), make_number (0)); | 2717 result = Fmake_string (make_number (nargs), make_number (0)); |
| 2718 for (i = 0; i < nargs; i++) | 2718 for (i = 0; i < nargs; i++) |
| 2719 { | 2719 { |
| 2720 SSET (result, i, XINT (args[i])); | 2720 SSET (result, i, XINT (args[i])); |
| 2721 /* Move the meta bit to the right place for a string char. */ | 2721 /* Move the meta bit to the right place for a string char. */ |
| 2722 if (XINT (args[i]) & CHAR_META) | 2722 if (XINT (args[i]) & CHAR_META) |
| 2723 SSET (result, i, SREF (result, i) | 0x80); | 2723 SSET (result, i, SREF (result, i) | 0x80); |
| 2724 } | 2724 } |
| 2725 | 2725 |
| 2726 return result; | 2726 return result; |
| 2727 } | 2727 } |
| 2728 } | 2728 } |
| 2729 | 2729 |
| 2730 | 2730 |
| 2803 present. For debugging purposes, let's check that. */ | 2803 present. For debugging purposes, let's check that. */ |
| 2804 c = mem_root; | 2804 c = mem_root; |
| 2805 parent = NULL; | 2805 parent = NULL; |
| 2806 | 2806 |
| 2807 #if GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS | 2807 #if GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS |
| 2808 | 2808 |
| 2809 while (c != MEM_NIL) | 2809 while (c != MEM_NIL) |
| 2810 { | 2810 { |
| 2811 if (start >= c->start && start < c->end) | 2811 if (start >= c->start && start < c->end) |
| 2812 abort (); | 2812 abort (); |
| 2813 parent = c; | 2813 parent = c; |
| 2814 c = start < c->start ? c->left : c->right; | 2814 c = start < c->start ? c->left : c->right; |
| 2815 } | 2815 } |
| 2816 | 2816 |
| 2817 #else /* GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS */ | 2817 #else /* GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS */ |
| 2818 | 2818 |
| 2819 while (c != MEM_NIL) | 2819 while (c != MEM_NIL) |
| 2820 { | 2820 { |
| 2821 parent = c; | 2821 parent = c; |
| 2822 c = start < c->start ? c->left : c->right; | 2822 c = start < c->start ? c->left : c->right; |
| 2823 } | 2823 } |
| 2824 | 2824 |
| 2825 #endif /* GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS */ | 2825 #endif /* GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS */ |
| 2826 | 2826 |
| 2827 /* Create a new node. */ | 2827 /* Create a new node. */ |
| 2828 #ifdef GC_MALLOC_CHECK | 2828 #ifdef GC_MALLOC_CHECK |
| 2829 x = (struct mem_node *) _malloc_internal (sizeof *x); | 2829 x = (struct mem_node *) _malloc_internal (sizeof *x); |
| 2845 if (start < parent->start) | 2845 if (start < parent->start) |
| 2846 parent->left = x; | 2846 parent->left = x; |
| 2847 else | 2847 else |
| 2848 parent->right = x; | 2848 parent->right = x; |
| 2849 } | 2849 } |
| 2850 else | 2850 else |
| 2851 mem_root = x; | 2851 mem_root = x; |
| 2852 | 2852 |
| 2853 /* Re-establish red-black tree properties. */ | 2853 /* Re-establish red-black tree properties. */ |
| 2854 mem_insert_fixup (x); | 2854 mem_insert_fixup (x); |
| 2855 | 2855 |
| 2866 { | 2866 { |
| 2867 while (x != mem_root && x->parent->color == MEM_RED) | 2867 while (x != mem_root && x->parent->color == MEM_RED) |
| 2868 { | 2868 { |
| 2869 /* X is red and its parent is red. This is a violation of | 2869 /* X is red and its parent is red. This is a violation of |
| 2870 red-black tree property #3. */ | 2870 red-black tree property #3. */ |
| 2871 | 2871 |
| 2872 if (x->parent == x->parent->parent->left) | 2872 if (x->parent == x->parent->parent->left) |
| 2873 { | 2873 { |
| 2874 /* We're on the left side of our grandparent, and Y is our | 2874 /* We're on the left side of our grandparent, and Y is our |
| 2875 "uncle". */ | 2875 "uncle". */ |
| 2876 struct mem_node *y = x->parent->parent->right; | 2876 struct mem_node *y = x->parent->parent->right; |
| 2877 | 2877 |
| 2878 if (y->color == MEM_RED) | 2878 if (y->color == MEM_RED) |
| 2879 { | 2879 { |
| 2880 /* Uncle and parent are red but should be black because | 2880 /* Uncle and parent are red but should be black because |
| 2881 X is red. Change the colors accordingly and proceed | 2881 X is red. Change the colors accordingly and proceed |
| 2882 with the grandparent. */ | 2882 with the grandparent. */ |
| 2902 } | 2902 } |
| 2903 else | 2903 else |
| 2904 { | 2904 { |
| 2905 /* This is the symmetrical case of above. */ | 2905 /* This is the symmetrical case of above. */ |
| 2906 struct mem_node *y = x->parent->parent->left; | 2906 struct mem_node *y = x->parent->parent->left; |
| 2907 | 2907 |
| 2908 if (y->color == MEM_RED) | 2908 if (y->color == MEM_RED) |
| 2909 { | 2909 { |
| 2910 x->parent->color = MEM_BLACK; | 2910 x->parent->color = MEM_BLACK; |
| 2911 y->color = MEM_BLACK; | 2911 y->color = MEM_BLACK; |
| 2912 x->parent->parent->color = MEM_RED; | 2912 x->parent->parent->color = MEM_RED; |
| 2917 if (x == x->parent->left) | 2917 if (x == x->parent->left) |
| 2918 { | 2918 { |
| 2919 x = x->parent; | 2919 x = x->parent; |
| 2920 mem_rotate_right (x); | 2920 mem_rotate_right (x); |
| 2921 } | 2921 } |
| 2922 | 2922 |
| 2923 x->parent->color = MEM_BLACK; | 2923 x->parent->color = MEM_BLACK; |
| 2924 x->parent->parent->color = MEM_RED; | 2924 x->parent->parent->color = MEM_RED; |
| 2925 mem_rotate_left (x->parent->parent); | 2925 mem_rotate_left (x->parent->parent); |
| 2926 } | 2926 } |
| 2927 } | 2927 } |
| 2931 it to black so that property #5 is satisfied. */ | 2931 it to black so that property #5 is satisfied. */ |
| 2932 mem_root->color = MEM_BLACK; | 2932 mem_root->color = MEM_BLACK; |
| 2933 } | 2933 } |
| 2934 | 2934 |
| 2935 | 2935 |
| 2936 /* (x) (y) | 2936 /* (x) (y) |
| 2937 / \ / \ | 2937 / \ / \ |
| 2938 a (y) ===> (x) c | 2938 a (y) ===> (x) c |
| 2939 / \ / \ | 2939 / \ / \ |
| 2940 b c a b */ | 2940 b c a b */ |
| 2941 | 2941 |
| 2942 static void | 2942 static void |
| 2971 if (x != MEM_NIL) | 2971 if (x != MEM_NIL) |
| 2972 x->parent = y; | 2972 x->parent = y; |
| 2973 } | 2973 } |
| 2974 | 2974 |
| 2975 | 2975 |
| 2976 /* (x) (Y) | 2976 /* (x) (Y) |
| 2977 / \ / \ | 2977 / \ / \ |
| 2978 (y) c ===> a (x) | 2978 (y) c ===> a (x) |
| 2979 / \ / \ | 2979 / \ / \ |
| 2980 a b b c */ | 2980 a b b c */ |
| 2981 | 2981 |
| 2982 static void | 2982 static void |
| 2983 mem_rotate_right (x) | 2983 mem_rotate_right (x) |
| 2984 struct mem_node *x; | 2984 struct mem_node *x; |
| 2986 struct mem_node *y = x->left; | 2986 struct mem_node *y = x->left; |
| 2987 | 2987 |
| 2988 x->left = y->right; | 2988 x->left = y->right; |
| 2989 if (y->right != MEM_NIL) | 2989 if (y->right != MEM_NIL) |
| 2990 y->right->parent = x; | 2990 y->right->parent = x; |
| 2991 | 2991 |
| 2992 if (y != MEM_NIL) | 2992 if (y != MEM_NIL) |
| 2993 y->parent = x->parent; | 2993 y->parent = x->parent; |
| 2994 if (x->parent) | 2994 if (x->parent) |
| 2995 { | 2995 { |
| 2996 if (x == x->parent->right) | 2996 if (x == x->parent->right) |
| 2998 else | 2998 else |
| 2999 x->parent->left = y; | 2999 x->parent->left = y; |
| 3000 } | 3000 } |
| 3001 else | 3001 else |
| 3002 mem_root = y; | 3002 mem_root = y; |
| 3003 | 3003 |
| 3004 y->right = x; | 3004 y->right = x; |
| 3005 if (x != MEM_NIL) | 3005 if (x != MEM_NIL) |
| 3006 x->parent = y; | 3006 x->parent = y; |
| 3007 } | 3007 } |
| 3008 | 3008 |
| 3047 { | 3047 { |
| 3048 z->start = y->start; | 3048 z->start = y->start; |
| 3049 z->end = y->end; | 3049 z->end = y->end; |
| 3050 z->type = y->type; | 3050 z->type = y->type; |
| 3051 } | 3051 } |
| 3052 | 3052 |
| 3053 if (y->color == MEM_BLACK) | 3053 if (y->color == MEM_BLACK) |
| 3054 mem_delete_fixup (x); | 3054 mem_delete_fixup (x); |
| 3055 | 3055 |
| 3056 #ifdef GC_MALLOC_CHECK | 3056 #ifdef GC_MALLOC_CHECK |
| 3057 _free_internal (y); | 3057 _free_internal (y); |
| 3071 while (x != mem_root && x->color == MEM_BLACK) | 3071 while (x != mem_root && x->color == MEM_BLACK) |
| 3072 { | 3072 { |
| 3073 if (x == x->parent->left) | 3073 if (x == x->parent->left) |
| 3074 { | 3074 { |
| 3075 struct mem_node *w = x->parent->right; | 3075 struct mem_node *w = x->parent->right; |
| 3076 | 3076 |
| 3077 if (w->color == MEM_RED) | 3077 if (w->color == MEM_RED) |
| 3078 { | 3078 { |
| 3079 w->color = MEM_BLACK; | 3079 w->color = MEM_BLACK; |
| 3080 x->parent->color = MEM_RED; | 3080 x->parent->color = MEM_RED; |
| 3081 mem_rotate_left (x->parent); | 3081 mem_rotate_left (x->parent); |
| 3082 w = x->parent->right; | 3082 w = x->parent->right; |
| 3083 } | 3083 } |
| 3084 | 3084 |
| 3085 if (w->left->color == MEM_BLACK && w->right->color == MEM_BLACK) | 3085 if (w->left->color == MEM_BLACK && w->right->color == MEM_BLACK) |
| 3086 { | 3086 { |
| 3087 w->color = MEM_RED; | 3087 w->color = MEM_RED; |
| 3088 x = x->parent; | 3088 x = x->parent; |
| 3089 } | 3089 } |
| 3104 } | 3104 } |
| 3105 } | 3105 } |
| 3106 else | 3106 else |
| 3107 { | 3107 { |
| 3108 struct mem_node *w = x->parent->left; | 3108 struct mem_node *w = x->parent->left; |
| 3109 | 3109 |
| 3110 if (w->color == MEM_RED) | 3110 if (w->color == MEM_RED) |
| 3111 { | 3111 { |
| 3112 w->color = MEM_BLACK; | 3112 w->color = MEM_BLACK; |
| 3113 x->parent->color = MEM_RED; | 3113 x->parent->color = MEM_RED; |
| 3114 mem_rotate_right (x->parent); | 3114 mem_rotate_right (x->parent); |
| 3115 w = x->parent->left; | 3115 w = x->parent->left; |
| 3116 } | 3116 } |
| 3117 | 3117 |
| 3118 if (w->right->color == MEM_BLACK && w->left->color == MEM_BLACK) | 3118 if (w->right->color == MEM_BLACK && w->left->color == MEM_BLACK) |
| 3119 { | 3119 { |
| 3120 w->color = MEM_RED; | 3120 w->color = MEM_RED; |
| 3121 x = x->parent; | 3121 x = x->parent; |
| 3122 } | 3122 } |
| 3127 w->right->color = MEM_BLACK; | 3127 w->right->color = MEM_BLACK; |
| 3128 w->color = MEM_RED; | 3128 w->color = MEM_RED; |
| 3129 mem_rotate_left (w); | 3129 mem_rotate_left (w); |
| 3130 w = x->parent->left; | 3130 w = x->parent->left; |
| 3131 } | 3131 } |
| 3132 | 3132 |
| 3133 w->color = x->parent->color; | 3133 w->color = x->parent->color; |
| 3134 x->parent->color = MEM_BLACK; | 3134 x->parent->color = MEM_BLACK; |
| 3135 w->left->color = MEM_BLACK; | 3135 w->left->color = MEM_BLACK; |
| 3136 mem_rotate_right (x->parent); | 3136 mem_rotate_right (x->parent); |
| 3137 x = mem_root; | 3137 x = mem_root; |
| 3138 } | 3138 } |
| 3139 } | 3139 } |
| 3140 } | 3140 } |
| 3141 | 3141 |
| 3142 x->color = MEM_BLACK; | 3142 x->color = MEM_BLACK; |
| 3143 } | 3143 } |
| 3144 | 3144 |
| 3145 | 3145 |
| 3146 /* Value is non-zero if P is a pointer to a live Lisp string on | 3146 /* Value is non-zero if P is a pointer to a live Lisp string on |
| 3204 { | 3204 { |
| 3205 if (m->type == MEM_TYPE_SYMBOL) | 3205 if (m->type == MEM_TYPE_SYMBOL) |
| 3206 { | 3206 { |
| 3207 struct symbol_block *b = (struct symbol_block *) m->start; | 3207 struct symbol_block *b = (struct symbol_block *) m->start; |
| 3208 int offset = (char *) p - (char *) &b->symbols[0]; | 3208 int offset = (char *) p - (char *) &b->symbols[0]; |
| 3209 | 3209 |
| 3210 /* P must point to the start of a Lisp_Symbol, not be | 3210 /* P must point to the start of a Lisp_Symbol, not be |
| 3211 one of the unused cells in the current symbol block, | 3211 one of the unused cells in the current symbol block, |
| 3212 and not be on the free-list. */ | 3212 and not be on the free-list. */ |
| 3213 return (offset >= 0 | 3213 return (offset >= 0 |
| 3214 && offset % sizeof b->symbols[0] == 0 | 3214 && offset % sizeof b->symbols[0] == 0 |
| 3231 { | 3231 { |
| 3232 if (m->type == MEM_TYPE_FLOAT) | 3232 if (m->type == MEM_TYPE_FLOAT) |
| 3233 { | 3233 { |
| 3234 struct float_block *b = (struct float_block *) m->start; | 3234 struct float_block *b = (struct float_block *) m->start; |
| 3235 int offset = (char *) p - (char *) &b->floats[0]; | 3235 int offset = (char *) p - (char *) &b->floats[0]; |
| 3236 | 3236 |
| 3237 /* P must point to the start of a Lisp_Float, not be | 3237 /* P must point to the start of a Lisp_Float, not be |
| 3238 one of the unused cells in the current float block, | 3238 one of the unused cells in the current float block, |
| 3239 and not be on the free-list. */ | 3239 and not be on the free-list. */ |
| 3240 return (offset >= 0 | 3240 return (offset >= 0 |
| 3241 && offset % sizeof b->floats[0] == 0 | 3241 && offset % sizeof b->floats[0] == 0 |
| 3258 { | 3258 { |
| 3259 if (m->type == MEM_TYPE_MISC) | 3259 if (m->type == MEM_TYPE_MISC) |
| 3260 { | 3260 { |
| 3261 struct marker_block *b = (struct marker_block *) m->start; | 3261 struct marker_block *b = (struct marker_block *) m->start; |
| 3262 int offset = (char *) p - (char *) &b->markers[0]; | 3262 int offset = (char *) p - (char *) &b->markers[0]; |
| 3263 | 3263 |
| 3264 /* P must point to the start of a Lisp_Misc, not be | 3264 /* P must point to the start of a Lisp_Misc, not be |
| 3265 one of the unused cells in the current misc block, | 3265 one of the unused cells in the current misc block, |
| 3266 and not be on the free-list. */ | 3266 and not be on the free-list. */ |
| 3267 return (offset >= 0 | 3267 return (offset >= 0 |
| 3268 && offset % sizeof b->markers[0] == 0 | 3268 && offset % sizeof b->markers[0] == 0 |
| 3364 mark_maybe_object (obj) | 3364 mark_maybe_object (obj) |
| 3365 Lisp_Object obj; | 3365 Lisp_Object obj; |
| 3366 { | 3366 { |
| 3367 void *po = (void *) XPNTR (obj); | 3367 void *po = (void *) XPNTR (obj); |
| 3368 struct mem_node *m = mem_find (po); | 3368 struct mem_node *m = mem_find (po); |
| 3369 | 3369 |
| 3370 if (m != MEM_NIL) | 3370 if (m != MEM_NIL) |
| 3371 { | 3371 { |
| 3372 int mark_p = 0; | 3372 int mark_p = 0; |
| 3373 | 3373 |
| 3374 switch (XGCTYPE (obj)) | 3374 switch (XGCTYPE (obj)) |
| 3410 switch (XMISCTYPE (obj)) | 3410 switch (XMISCTYPE (obj)) |
| 3411 { | 3411 { |
| 3412 case Lisp_Misc_Marker: | 3412 case Lisp_Misc_Marker: |
| 3413 mark_p = !XMARKBIT (XMARKER (obj)->chain); | 3413 mark_p = !XMARKBIT (XMARKER (obj)->chain); |
| 3414 break; | 3414 break; |
| 3415 | 3415 |
| 3416 case Lisp_Misc_Buffer_Local_Value: | 3416 case Lisp_Misc_Buffer_Local_Value: |
| 3417 case Lisp_Misc_Some_Buffer_Local_Value: | 3417 case Lisp_Misc_Some_Buffer_Local_Value: |
| 3418 mark_p = !XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); | 3418 mark_p = !XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); |
| 3419 break; | 3419 break; |
| 3420 | 3420 |
| 3421 case Lisp_Misc_Overlay: | 3421 case Lisp_Misc_Overlay: |
| 3422 mark_p = !XMARKBIT (XOVERLAY (obj)->plist); | 3422 mark_p = !XMARKBIT (XOVERLAY (obj)->plist); |
| 3423 break; | 3423 break; |
| 3424 } | 3424 } |
| 3425 } | 3425 } |
| 3454 | 3454 |
| 3455 /* Quickly rule out some values which can't point to Lisp data. We | 3455 /* Quickly rule out some values which can't point to Lisp data. We |
| 3456 assume that Lisp data is aligned on even addresses. */ | 3456 assume that Lisp data is aligned on even addresses. */ |
| 3457 if ((EMACS_INT) p & 1) | 3457 if ((EMACS_INT) p & 1) |
| 3458 return; | 3458 return; |
| 3459 | 3459 |
| 3460 m = mem_find (p); | 3460 m = mem_find (p); |
| 3461 if (m != MEM_NIL) | 3461 if (m != MEM_NIL) |
| 3462 { | 3462 { |
| 3463 Lisp_Object obj = Qnil; | 3463 Lisp_Object obj = Qnil; |
| 3464 | 3464 |
| 3465 switch (m->type) | 3465 switch (m->type) |
| 3466 { | 3466 { |
| 3467 case MEM_TYPE_NON_LISP: | 3467 case MEM_TYPE_NON_LISP: |
| 3468 /* Nothing to do; not a pointer to Lisp memory. */ | 3468 /* Nothing to do; not a pointer to Lisp memory. */ |
| 3469 break; | 3469 break; |
| 3470 | 3470 |
| 3471 case MEM_TYPE_BUFFER: | 3471 case MEM_TYPE_BUFFER: |
| 3472 if (live_buffer_p (m, p) | 3472 if (live_buffer_p (m, p) |
| 3473 && !XMARKBIT (((struct buffer *) p)->name)) | 3473 && !XMARKBIT (((struct buffer *) p)->name)) |
| 3474 XSETVECTOR (obj, p); | 3474 XSETVECTOR (obj, p); |
| 3475 break; | 3475 break; |
| 3476 | 3476 |
| 3477 case MEM_TYPE_CONS: | 3477 case MEM_TYPE_CONS: |
| 3478 if (live_cons_p (m, p) | 3478 if (live_cons_p (m, p) |
| 3479 && !XMARKBIT (((struct Lisp_Cons *) p)->car)) | 3479 && !XMARKBIT (((struct Lisp_Cons *) p)->car)) |
| 3480 XSETCONS (obj, p); | 3480 XSETCONS (obj, p); |
| 3481 break; | 3481 break; |
| 3482 | 3482 |
| 3483 case MEM_TYPE_STRING: | 3483 case MEM_TYPE_STRING: |
| 3484 if (live_string_p (m, p) | 3484 if (live_string_p (m, p) |
| 3485 && !STRING_MARKED_P ((struct Lisp_String *) p)) | 3485 && !STRING_MARKED_P ((struct Lisp_String *) p)) |
| 3486 XSETSTRING (obj, p); | 3486 XSETSTRING (obj, p); |
| 3487 break; | 3487 break; |
| 3489 case MEM_TYPE_MISC: | 3489 case MEM_TYPE_MISC: |
| 3490 if (live_misc_p (m, p)) | 3490 if (live_misc_p (m, p)) |
| 3491 { | 3491 { |
| 3492 Lisp_Object tem; | 3492 Lisp_Object tem; |
| 3493 XSETMISC (tem, p); | 3493 XSETMISC (tem, p); |
| 3494 | 3494 |
| 3495 switch (XMISCTYPE (tem)) | 3495 switch (XMISCTYPE (tem)) |
| 3496 { | 3496 { |
| 3497 case Lisp_Misc_Marker: | 3497 case Lisp_Misc_Marker: |
| 3498 if (!XMARKBIT (XMARKER (tem)->chain)) | 3498 if (!XMARKBIT (XMARKER (tem)->chain)) |
| 3499 obj = tem; | 3499 obj = tem; |
| 3500 break; | 3500 break; |
| 3501 | 3501 |
| 3502 case Lisp_Misc_Buffer_Local_Value: | 3502 case Lisp_Misc_Buffer_Local_Value: |
| 3503 case Lisp_Misc_Some_Buffer_Local_Value: | 3503 case Lisp_Misc_Some_Buffer_Local_Value: |
| 3504 if (!XMARKBIT (XBUFFER_LOCAL_VALUE (tem)->realvalue)) | 3504 if (!XMARKBIT (XBUFFER_LOCAL_VALUE (tem)->realvalue)) |
| 3505 obj = tem; | 3505 obj = tem; |
| 3506 break; | 3506 break; |
| 3507 | 3507 |
| 3508 case Lisp_Misc_Overlay: | 3508 case Lisp_Misc_Overlay: |
| 3509 if (!XMARKBIT (XOVERLAY (tem)->plist)) | 3509 if (!XMARKBIT (XOVERLAY (tem)->plist)) |
| 3510 obj = tem; | 3510 obj = tem; |
| 3511 break; | 3511 break; |
| 3512 } | 3512 } |
| 3513 } | 3513 } |
| 3514 break; | 3514 break; |
| 3515 | 3515 |
| 3516 case MEM_TYPE_SYMBOL: | 3516 case MEM_TYPE_SYMBOL: |
| 3517 if (live_symbol_p (m, p) | 3517 if (live_symbol_p (m, p) |
| 3518 && !XMARKBIT (((struct Lisp_Symbol *) p)->plist)) | 3518 && !XMARKBIT (((struct Lisp_Symbol *) p)->plist)) |
| 3519 XSETSYMBOL (obj, p); | 3519 XSETSYMBOL (obj, p); |
| 3520 break; | 3520 break; |
| 3521 | 3521 |
| 3522 case MEM_TYPE_FLOAT: | 3522 case MEM_TYPE_FLOAT: |
| 3523 if (live_float_p (m, p) | 3523 if (live_float_p (m, p) |
| 3524 && !XMARKBIT (((struct Lisp_Float *) p)->type)) | 3524 && !XMARKBIT (((struct Lisp_Float *) p)->type)) |
| 3525 XSETFLOAT (obj, p); | 3525 XSETFLOAT (obj, p); |
| 3526 break; | 3526 break; |
| 3527 | 3527 |
| 3528 case MEM_TYPE_VECTOR: | 3528 case MEM_TYPE_VECTOR: |
| 3529 case MEM_TYPE_PROCESS: | 3529 case MEM_TYPE_PROCESS: |
| 3530 case MEM_TYPE_HASH_TABLE: | 3530 case MEM_TYPE_HASH_TABLE: |
| 3531 case MEM_TYPE_FRAME: | 3531 case MEM_TYPE_FRAME: |
| 3532 case MEM_TYPE_WINDOW: | 3532 case MEM_TYPE_WINDOW: |
| 3550 } | 3550 } |
| 3551 | 3551 |
| 3552 | 3552 |
| 3553 /* Mark Lisp objects referenced from the address range START..END. */ | 3553 /* Mark Lisp objects referenced from the address range START..END. */ |
| 3554 | 3554 |
| 3555 static void | 3555 static void |
| 3556 mark_memory (start, end) | 3556 mark_memory (start, end) |
| 3557 void *start, *end; | 3557 void *start, *end; |
| 3558 { | 3558 { |
| 3559 Lisp_Object *p; | 3559 Lisp_Object *p; |
| 3560 void **pp; | 3560 void **pp; |
| 3591 } | 3591 } |
| 3592 | 3592 |
| 3593 Here, `obj' isn't really used, and the compiler optimizes it | 3593 Here, `obj' isn't really used, and the compiler optimizes it |
| 3594 away. The only reference to the life string is through the | 3594 away. The only reference to the life string is through the |
| 3595 pointer `s'. */ | 3595 pointer `s'. */ |
| 3596 | 3596 |
| 3597 for (pp = (void **) start; (void *) pp < end; ++pp) | 3597 for (pp = (void **) start; (void *) pp < end; ++pp) |
| 3598 mark_maybe_pointer (*pp); | 3598 mark_maybe_pointer (*pp); |
| 3599 } | 3599 } |
| 3600 | 3600 |
| 3601 /* setjmp will work with GCC unless NON_SAVING_SETJMP is defined in | 3601 /* setjmp will work with GCC unless NON_SAVING_SETJMP is defined in |
| 3781 needed on ia64 too. See mach_dep.c, where it also says inline | 3781 needed on ia64 too. See mach_dep.c, where it also says inline |
| 3782 assembler doesn't work with relevant proprietary compilers. */ | 3782 assembler doesn't work with relevant proprietary compilers. */ |
| 3783 #ifdef sparc | 3783 #ifdef sparc |
| 3784 asm ("ta 3"); | 3784 asm ("ta 3"); |
| 3785 #endif | 3785 #endif |
| 3786 | 3786 |
| 3787 /* Save registers that we need to see on the stack. We need to see | 3787 /* Save registers that we need to see on the stack. We need to see |
| 3788 registers used to hold register variables and registers used to | 3788 registers used to hold register variables and registers used to |
| 3789 pass parameters. */ | 3789 pass parameters. */ |
| 3790 #ifdef GC_SAVE_REGISTERS_ON_STACK | 3790 #ifdef GC_SAVE_REGISTERS_ON_STACK |
| 3791 GC_SAVE_REGISTERS_ON_STACK (end); | 3791 GC_SAVE_REGISTERS_ON_STACK (end); |
| 3792 #else /* not GC_SAVE_REGISTERS_ON_STACK */ | 3792 #else /* not GC_SAVE_REGISTERS_ON_STACK */ |
| 3793 | 3793 |
| 3794 #ifndef GC_SETJMP_WORKS /* If it hasn't been checked yet that | 3794 #ifndef GC_SETJMP_WORKS /* If it hasn't been checked yet that |
| 3795 setjmp will definitely work, test it | 3795 setjmp will definitely work, test it |
| 3796 and print a message with the result | 3796 and print a message with the result |
| 3797 of the test. */ | 3797 of the test. */ |
| 3798 if (!setjmp_tested_p) | 3798 if (!setjmp_tested_p) |
| 3799 { | 3799 { |
| 3800 setjmp_tested_p = 1; | 3800 setjmp_tested_p = 1; |
| 3801 test_setjmp (); | 3801 test_setjmp (); |
| 3802 } | 3802 } |
| 3803 #endif /* GC_SETJMP_WORKS */ | 3803 #endif /* GC_SETJMP_WORKS */ |
| 3804 | 3804 |
| 3805 setjmp (j); | 3805 setjmp (j); |
| 3806 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j; | 3806 end = stack_grows_down_p ? (char *) &j + sizeof j : (char *) &j; |
| 3807 #endif /* not GC_SAVE_REGISTERS_ON_STACK */ | 3807 #endif /* not GC_SAVE_REGISTERS_ON_STACK */ |
| 3808 | 3808 |
| 3809 /* This assumes that the stack is a contiguous region in memory. If | 3809 /* This assumes that the stack is a contiguous region in memory. If |
| 4144 /* If a buffer's undo list is Qt, that means that undo is | 4144 /* If a buffer's undo list is Qt, that means that undo is |
| 4145 turned off in that buffer. Calling truncate_undo_list on | 4145 turned off in that buffer. Calling truncate_undo_list on |
| 4146 Qt tends to return NULL, which effectively turns undo back on. | 4146 Qt tends to return NULL, which effectively turns undo back on. |
| 4147 So don't call truncate_undo_list if undo_list is Qt. */ | 4147 So don't call truncate_undo_list if undo_list is Qt. */ |
| 4148 if (! EQ (nextb->undo_list, Qt)) | 4148 if (! EQ (nextb->undo_list, Qt)) |
| 4149 nextb->undo_list | 4149 nextb->undo_list |
| 4150 = truncate_undo_list (nextb->undo_list, undo_limit, | 4150 = truncate_undo_list (nextb->undo_list, undo_limit, |
| 4151 undo_strong_limit); | 4151 undo_strong_limit); |
| 4152 | 4152 |
| 4153 /* Shrink buffer gaps, but skip indirect and dead buffers. */ | 4153 /* Shrink buffer gaps, but skip indirect and dead buffers. */ |
| 4154 if (nextb->base_buffer == 0 && !NILP (nextb->name)) | 4154 if (nextb->base_buffer == 0 && !NILP (nextb->name)) |
| 4197 discarding the `volatile' qualifier. */ | 4197 discarding the `volatile' qualifier. */ |
| 4198 mark_object ((Lisp_Object *)&tail->var[i]); | 4198 mark_object ((Lisp_Object *)&tail->var[i]); |
| 4199 XMARK (tail->var[i]); | 4199 XMARK (tail->var[i]); |
| 4200 } | 4200 } |
| 4201 #endif | 4201 #endif |
| 4202 | 4202 |
| 4203 mark_byte_stack (); | 4203 mark_byte_stack (); |
| 4204 for (bind = specpdl; bind != specpdl_ptr; bind++) | 4204 for (bind = specpdl; bind != specpdl_ptr; bind++) |
| 4205 { | 4205 { |
| 4206 mark_object (&bind->symbol); | 4206 mark_object (&bind->symbol); |
| 4207 mark_object (&bind->old_value); | 4207 mark_object (&bind->old_value); |
| 4208 } | 4208 } |
| 4209 for (catch = catchlist; catch; catch = catch->next) | 4209 for (catch = catchlist; catch; catch = catch->next) |
| 4210 { | 4210 { |
| 4211 mark_object (&catch->tag); | 4211 mark_object (&catch->tag); |
| 4212 mark_object (&catch->val); | 4212 mark_object (&catch->val); |
| 4213 } | 4213 } |
| 4214 for (handler = handlerlist; handler; handler = handler->next) | 4214 for (handler = handlerlist; handler; handler = handler->next) |
| 4215 { | 4215 { |
| 4216 mark_object (&handler->handler); | 4216 mark_object (&handler->handler); |
| 4217 mark_object (&handler->var); | 4217 mark_object (&handler->var); |
| 4218 } | 4218 } |
| 4219 for (backlist = backtrace_list; backlist; backlist = backlist->next) | 4219 for (backlist = backtrace_list; backlist; backlist = backlist->next) |
| 4220 { | 4220 { |
| 4221 if (!XMARKBIT (*backlist->function)) | 4221 if (!XMARKBIT (*backlist->function)) |
| 4222 { | 4222 { |
| 4223 mark_object (backlist->function); | 4223 mark_object (backlist->function); |
| 4231 if (!XMARKBIT (backlist->args[i])) | 4231 if (!XMARKBIT (backlist->args[i])) |
| 4232 { | 4232 { |
| 4233 mark_object (&backlist->args[i]); | 4233 mark_object (&backlist->args[i]); |
| 4234 XMARK (backlist->args[i]); | 4234 XMARK (backlist->args[i]); |
| 4235 } | 4235 } |
| 4236 } | 4236 } |
| 4237 mark_kboards (); | 4237 mark_kboards (); |
| 4238 | 4238 |
| 4239 /* Look thru every buffer's undo list | 4239 /* Look thru every buffer's undo list |
| 4240 for elements that update markers that were not marked, | 4240 for elements that update markers that were not marked, |
| 4241 and delete them. */ | 4241 and delete them. */ |
| 4298 || GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES) | 4298 || GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES) |
| 4299 for (tail = gcprolist; tail; tail = tail->next) | 4299 for (tail = gcprolist; tail; tail = tail->next) |
| 4300 for (i = 0; i < tail->nvars; i++) | 4300 for (i = 0; i < tail->nvars; i++) |
| 4301 XUNMARK (tail->var[i]); | 4301 XUNMARK (tail->var[i]); |
| 4302 #endif | 4302 #endif |
| 4303 | 4303 |
| 4304 unmark_byte_stack (); | 4304 unmark_byte_stack (); |
| 4305 for (backlist = backtrace_list; backlist; backlist = backlist->next) | 4305 for (backlist = backtrace_list; backlist; backlist = backlist->next) |
| 4306 { | 4306 { |
| 4307 XUNMARK (*backlist->function); | 4307 XUNMARK (*backlist->function); |
| 4308 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | 4308 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) |
| 4309 i = 0; | 4309 i = 0; |
| 4310 else | 4310 else |
| 4311 i = backlist->nargs - 1; | 4311 i = backlist->nargs - 1; |
| 4312 for (; i >= 0; i--) | 4312 for (; i >= 0; i--) |
| 4313 XUNMARK (backlist->args[i]); | 4313 XUNMARK (backlist->args[i]); |
| 4314 } | 4314 } |
| 4315 XUNMARK (buffer_defaults.name); | 4315 XUNMARK (buffer_defaults.name); |
| 4316 XUNMARK (buffer_local_symbols.name); | 4316 XUNMARK (buffer_local_symbols.name); |
| 4317 | 4317 |
| 4318 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0 | 4318 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0 |
| 4319 dump_zombies (); | 4319 dump_zombies (); |
| 4355 | 4355 |
| 4356 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 4356 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 4357 { | 4357 { |
| 4358 /* Compute average percentage of zombies. */ | 4358 /* Compute average percentage of zombies. */ |
| 4359 double nlive = 0; | 4359 double nlive = 0; |
| 4360 | 4360 |
| 4361 for (i = 0; i < 7; ++i) | 4361 for (i = 0; i < 7; ++i) |
| 4362 if (CONSP (total[i])) | 4362 if (CONSP (total[i])) |
| 4363 nlive += XFASTINT (XCAR (total[i])); | 4363 nlive += XFASTINT (XCAR (total[i])); |
| 4364 | 4364 |
| 4365 avg_live = (avg_live * ngcs + nlive) / (ngcs + 1); | 4365 avg_live = (avg_live * ngcs + nlive) / (ngcs + 1); |
| 4406 int area; | 4406 int area; |
| 4407 for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area) | 4407 for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area) |
| 4408 { | 4408 { |
| 4409 struct glyph *glyph = row->glyphs[area]; | 4409 struct glyph *glyph = row->glyphs[area]; |
| 4410 struct glyph *end_glyph = glyph + row->used[area]; | 4410 struct glyph *end_glyph = glyph + row->used[area]; |
| 4411 | 4411 |
| 4412 for (; glyph < end_glyph; ++glyph) | 4412 for (; glyph < end_glyph; ++glyph) |
| 4413 if (GC_STRINGP (glyph->object) | 4413 if (GC_STRINGP (glyph->object) |
| 4414 && !STRING_MARKED_P (XSTRING (glyph->object))) | 4414 && !STRING_MARKED_P (XSTRING (glyph->object))) |
| 4415 mark_object (&glyph->object); | 4415 mark_object (&glyph->object); |
| 4416 } | 4416 } |
| 4448 static void | 4448 static void |
| 4449 mark_image (img) | 4449 mark_image (img) |
| 4450 struct image *img; | 4450 struct image *img; |
| 4451 { | 4451 { |
| 4452 mark_object (&img->spec); | 4452 mark_object (&img->spec); |
| 4453 | 4453 |
| 4454 if (!NILP (img->data.lisp_val)) | 4454 if (!NILP (img->data.lisp_val)) |
| 4455 mark_object (&img->data.lisp_val); | 4455 mark_object (&img->data.lisp_val); |
| 4456 } | 4456 } |
| 4457 | 4457 |
| 4458 | 4458 |
| 4536 #define CHECK_ALLOCATED_AND_LIVE(LIVEP) \ | 4536 #define CHECK_ALLOCATED_AND_LIVE(LIVEP) \ |
| 4537 do { \ | 4537 do { \ |
| 4538 CHECK_ALLOCATED (); \ | 4538 CHECK_ALLOCATED (); \ |
| 4539 CHECK_LIVE (LIVEP); \ | 4539 CHECK_LIVE (LIVEP); \ |
| 4540 } while (0) \ | 4540 } while (0) \ |
| 4541 | 4541 |
| 4542 #else /* not GC_CHECK_MARKED_OBJECTS */ | 4542 #else /* not GC_CHECK_MARKED_OBJECTS */ |
| 4543 | 4543 |
| 4544 #define CHECK_ALLOCATED() (void) 0 | 4544 #define CHECK_ALLOCATED() (void) 0 |
| 4545 #define CHECK_LIVE(LIVEP) (void) 0 | 4545 #define CHECK_LIVE(LIVEP) (void) 0 |
| 4546 #define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0 | 4546 #define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0 |
| 4547 | 4547 |
| 4548 #endif /* not GC_CHECK_MARKED_OBJECTS */ | 4548 #endif /* not GC_CHECK_MARKED_OBJECTS */ |
| 4549 | 4549 |
| 4550 switch (SWITCH_ENUM_CAST (XGCTYPE (obj))) | 4550 switch (SWITCH_ENUM_CAST (XGCTYPE (obj))) |
| 4551 { | 4551 { |
| 4552 case Lisp_String: | 4552 case Lisp_String: |
| 4569 if (m == MEM_NIL && !GC_SUBRP (obj) | 4569 if (m == MEM_NIL && !GC_SUBRP (obj) |
| 4570 && po != &buffer_defaults | 4570 && po != &buffer_defaults |
| 4571 && po != &buffer_local_symbols) | 4571 && po != &buffer_local_symbols) |
| 4572 abort (); | 4572 abort (); |
| 4573 #endif /* GC_CHECK_MARKED_OBJECTS */ | 4573 #endif /* GC_CHECK_MARKED_OBJECTS */ |
| 4574 | 4574 |
| 4575 if (GC_BUFFERP (obj)) | 4575 if (GC_BUFFERP (obj)) |
| 4576 { | 4576 { |
| 4577 if (!XMARKBIT (XBUFFER (obj)->name)) | 4577 if (!XMARKBIT (XBUFFER (obj)->name)) |
| 4578 { | 4578 { |
| 4579 #ifdef GC_CHECK_MARKED_OBJECTS | 4579 #ifdef GC_CHECK_MARKED_OBJECTS |
| 4600 register EMACS_INT size = ptr->size; | 4600 register EMACS_INT size = ptr->size; |
| 4601 register int i; | 4601 register int i; |
| 4602 | 4602 |
| 4603 if (size & ARRAY_MARK_FLAG) | 4603 if (size & ARRAY_MARK_FLAG) |
| 4604 break; /* Already marked */ | 4604 break; /* Already marked */ |
| 4605 | 4605 |
| 4606 CHECK_LIVE (live_vector_p); | 4606 CHECK_LIVE (live_vector_p); |
| 4607 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | 4607 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ |
| 4608 size &= PSEUDOVECTOR_SIZE_MASK; | 4608 size &= PSEUDOVECTOR_SIZE_MASK; |
| 4609 for (i = 0; i < size; i++) /* and then mark its elements */ | 4609 for (i = 0; i < size; i++) /* and then mark its elements */ |
| 4610 { | 4610 { |
| 4693 } | 4693 } |
| 4694 else if (GC_HASH_TABLE_P (obj)) | 4694 else if (GC_HASH_TABLE_P (obj)) |
| 4695 { | 4695 { |
| 4696 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); | 4696 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); |
| 4697 EMACS_INT size = h->size; | 4697 EMACS_INT size = h->size; |
| 4698 | 4698 |
| 4699 /* Stop if already marked. */ | 4699 /* Stop if already marked. */ |
| 4700 if (size & ARRAY_MARK_FLAG) | 4700 if (size & ARRAY_MARK_FLAG) |
| 4701 break; | 4701 break; |
| 4702 | 4702 |
| 4703 /* Mark it. */ | 4703 /* Mark it. */ |
| 4704 CHECK_LIVE (live_vector_p); | 4704 CHECK_LIVE (live_vector_p); |
| 4705 h->size |= ARRAY_MARK_FLAG; | 4705 h->size |= ARRAY_MARK_FLAG; |
| 4706 | 4706 |
| 4707 /* Mark contents. */ | 4707 /* Mark contents. */ |
| 4708 /* Do not mark next_free or next_weak. | 4708 /* Do not mark next_free or next_weak. |
| 4709 Being in the next_weak chain | 4709 Being in the next_weak chain |
| 4710 should not keep the hash table alive. | 4710 should not keep the hash table alive. |
| 4711 No need to mark `count' since it is an integer. */ | 4711 No need to mark `count' since it is an integer. */ |
| 4712 mark_object (&h->test); | 4712 mark_object (&h->test); |
| 4713 mark_object (&h->weak); | 4713 mark_object (&h->weak); |
| 4714 mark_object (&h->rehash_size); | 4714 mark_object (&h->rehash_size); |
| 4723 For weak tables, mark only the vector. */ | 4723 For weak tables, mark only the vector. */ |
| 4724 if (GC_NILP (h->weak)) | 4724 if (GC_NILP (h->weak)) |
| 4725 mark_object (&h->key_and_value); | 4725 mark_object (&h->key_and_value); |
| 4726 else | 4726 else |
| 4727 XVECTOR (h->key_and_value)->size |= ARRAY_MARK_FLAG; | 4727 XVECTOR (h->key_and_value)->size |= ARRAY_MARK_FLAG; |
| 4728 | 4728 |
| 4729 } | 4729 } |
| 4730 else | 4730 else |
| 4731 { | 4731 { |
| 4732 register struct Lisp_Vector *ptr = XVECTOR (obj); | 4732 register struct Lisp_Vector *ptr = XVECTOR (obj); |
| 4733 register EMACS_INT size = ptr->size; | 4733 register EMACS_INT size = ptr->size; |
| 4757 mark_object (&ptr->plist); | 4757 mark_object (&ptr->plist); |
| 4758 | 4758 |
| 4759 if (!PURE_POINTER_P (XSTRING (ptr->xname))) | 4759 if (!PURE_POINTER_P (XSTRING (ptr->xname))) |
| 4760 MARK_STRING (XSTRING (ptr->xname)); | 4760 MARK_STRING (XSTRING (ptr->xname)); |
| 4761 MARK_INTERVAL_TREE (STRING_INTERVALS (ptr->xname)); | 4761 MARK_INTERVAL_TREE (STRING_INTERVALS (ptr->xname)); |
| 4762 | 4762 |
| 4763 /* Note that we do not mark the obarray of the symbol. | 4763 /* Note that we do not mark the obarray of the symbol. |
| 4764 It is safe not to do so because nothing accesses that | 4764 It is safe not to do so because nothing accesses that |
| 4765 slot except to check whether it is nil. */ | 4765 slot except to check whether it is nil. */ |
| 4766 ptr = ptr->next; | 4766 ptr = ptr->next; |
| 4767 if (ptr) | 4767 if (ptr) |
| 4931 mark_object (ptr); | 4931 mark_object (ptr); |
| 4932 | 4932 |
| 4933 /* If this is an indirect buffer, mark its base buffer. */ | 4933 /* If this is an indirect buffer, mark its base buffer. */ |
| 4934 if (buffer->base_buffer && !XMARKBIT (buffer->base_buffer->name)) | 4934 if (buffer->base_buffer && !XMARKBIT (buffer->base_buffer->name)) |
| 4935 { | 4935 { |
| 4936 XSETBUFFER (base_buffer, buffer->base_buffer); | 4936 XSETBUFFER (base_buffer, buffer->base_buffer); |
| 4937 mark_buffer (base_buffer); | 4937 mark_buffer (base_buffer); |
| 4938 } | 4938 } |
| 4939 } | 4939 } |
| 4940 | 4940 |
| 4941 | 4941 |
| 4973 int | 4973 int |
| 4974 survives_gc_p (obj) | 4974 survives_gc_p (obj) |
| 4975 Lisp_Object obj; | 4975 Lisp_Object obj; |
| 4976 { | 4976 { |
| 4977 int survives_p; | 4977 int survives_p; |
| 4978 | 4978 |
| 4979 switch (XGCTYPE (obj)) | 4979 switch (XGCTYPE (obj)) |
| 4980 { | 4980 { |
| 4981 case Lisp_Int: | 4981 case Lisp_Int: |
| 4982 survives_p = 1; | 4982 survives_p = 1; |
| 4983 break; | 4983 break; |
| 4990 switch (XMISCTYPE (obj)) | 4990 switch (XMISCTYPE (obj)) |
| 4991 { | 4991 { |
| 4992 case Lisp_Misc_Marker: | 4992 case Lisp_Misc_Marker: |
| 4993 survives_p = XMARKBIT (obj); | 4993 survives_p = XMARKBIT (obj); |
| 4994 break; | 4994 break; |
| 4995 | 4995 |
| 4996 case Lisp_Misc_Buffer_Local_Value: | 4996 case Lisp_Misc_Buffer_Local_Value: |
| 4997 case Lisp_Misc_Some_Buffer_Local_Value: | 4997 case Lisp_Misc_Some_Buffer_Local_Value: |
| 4998 survives_p = XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); | 4998 survives_p = XMARKBIT (XBUFFER_LOCAL_VALUE (obj)->realvalue); |
| 4999 break; | 4999 break; |
| 5000 | 5000 |
| 5001 case Lisp_Misc_Intfwd: | 5001 case Lisp_Misc_Intfwd: |
| 5002 case Lisp_Misc_Boolfwd: | 5002 case Lisp_Misc_Boolfwd: |
| 5003 case Lisp_Misc_Objfwd: | 5003 case Lisp_Misc_Objfwd: |
| 5004 case Lisp_Misc_Buffer_Objfwd: | 5004 case Lisp_Misc_Buffer_Objfwd: |
| 5005 case Lisp_Misc_Kboard_Objfwd: | 5005 case Lisp_Misc_Kboard_Objfwd: |
| 5006 survives_p = 1; | 5006 survives_p = 1; |
| 5007 break; | 5007 break; |
| 5008 | 5008 |
| 5009 case Lisp_Misc_Overlay: | 5009 case Lisp_Misc_Overlay: |
| 5010 survives_p = XMARKBIT (XOVERLAY (obj)->plist); | 5010 survives_p = XMARKBIT (XOVERLAY (obj)->plist); |
| 5011 break; | 5011 break; |
| 5012 | 5012 |
| 5013 default: | 5013 default: |
| 5069 struct cons_block **cprev = &cons_block; | 5069 struct cons_block **cprev = &cons_block; |
| 5070 register int lim = cons_block_index; | 5070 register int lim = cons_block_index; |
| 5071 register int num_free = 0, num_used = 0; | 5071 register int num_free = 0, num_used = 0; |
| 5072 | 5072 |
| 5073 cons_free_list = 0; | 5073 cons_free_list = 0; |
| 5074 | 5074 |
| 5075 for (cblk = cons_block; cblk; cblk = *cprev) | 5075 for (cblk = cons_block; cblk; cblk = *cprev) |
| 5076 { | 5076 { |
| 5077 register int i; | 5077 register int i; |
| 5078 int this_free = 0; | 5078 int this_free = 0; |
| 5079 for (i = 0; i < lim; i++) | 5079 for (i = 0; i < lim; i++) |
| 5119 struct float_block **fprev = &float_block; | 5119 struct float_block **fprev = &float_block; |
| 5120 register int lim = float_block_index; | 5120 register int lim = float_block_index; |
| 5121 register int num_free = 0, num_used = 0; | 5121 register int num_free = 0, num_used = 0; |
| 5122 | 5122 |
| 5123 float_free_list = 0; | 5123 float_free_list = 0; |
| 5124 | 5124 |
| 5125 for (fblk = float_block; fblk; fblk = *fprev) | 5125 for (fblk = float_block; fblk; fblk = *fprev) |
| 5126 { | 5126 { |
| 5127 register int i; | 5127 register int i; |
| 5128 int this_free = 0; | 5128 int this_free = 0; |
| 5129 for (i = 0; i < lim; i++) | 5129 for (i = 0; i < lim; i++) |
| 5219 struct symbol_block **sprev = &symbol_block; | 5219 struct symbol_block **sprev = &symbol_block; |
| 5220 register int lim = symbol_block_index; | 5220 register int lim = symbol_block_index; |
| 5221 register int num_free = 0, num_used = 0; | 5221 register int num_free = 0, num_used = 0; |
| 5222 | 5222 |
| 5223 symbol_free_list = NULL; | 5223 symbol_free_list = NULL; |
| 5224 | 5224 |
| 5225 for (sblk = symbol_block; sblk; sblk = *sprev) | 5225 for (sblk = symbol_block; sblk; sblk = *sprev) |
| 5226 { | 5226 { |
| 5227 int this_free = 0; | 5227 int this_free = 0; |
| 5228 struct Lisp_Symbol *sym = sblk->symbols; | 5228 struct Lisp_Symbol *sym = sblk->symbols; |
| 5229 struct Lisp_Symbol *end = sym + lim; | 5229 struct Lisp_Symbol *end = sym + lim; |
| 5232 { | 5232 { |
| 5233 /* Check if the symbol was created during loadup. In such a case | 5233 /* Check if the symbol was created during loadup. In such a case |
| 5234 it might be pointed to by pure bytecode which we don't trace, | 5234 it might be pointed to by pure bytecode which we don't trace, |
| 5235 so we conservatively assume that it is live. */ | 5235 so we conservatively assume that it is live. */ |
| 5236 int pure_p = PURE_POINTER_P (XSTRING (sym->xname)); | 5236 int pure_p = PURE_POINTER_P (XSTRING (sym->xname)); |
| 5237 | 5237 |
| 5238 if (!XMARKBIT (sym->plist) && !pure_p) | 5238 if (!XMARKBIT (sym->plist) && !pure_p) |
| 5239 { | 5239 { |
| 5240 *(struct Lisp_Symbol **) &sym->value = symbol_free_list; | 5240 *(struct Lisp_Symbol **) &sym->value = symbol_free_list; |
| 5241 symbol_free_list = sym; | 5241 symbol_free_list = sym; |
| 5242 #if GC_MARK_STACK | 5242 #if GC_MARK_STACK |
| 5250 if (!pure_p) | 5250 if (!pure_p) |
| 5251 UNMARK_STRING (XSTRING (sym->xname)); | 5251 UNMARK_STRING (XSTRING (sym->xname)); |
| 5252 XUNMARK (sym->plist); | 5252 XUNMARK (sym->plist); |
| 5253 } | 5253 } |
| 5254 } | 5254 } |
| 5255 | 5255 |
| 5256 lim = SYMBOL_BLOCK_SIZE; | 5256 lim = SYMBOL_BLOCK_SIZE; |
| 5257 /* If this block contains only free symbols and we have already | 5257 /* If this block contains only free symbols and we have already |
| 5258 seen more than two blocks worth of free symbols then deallocate | 5258 seen more than two blocks worth of free symbols then deallocate |
| 5259 this block. */ | 5259 this block. */ |
| 5260 if (this_free == SYMBOL_BLOCK_SIZE && num_free > SYMBOL_BLOCK_SIZE) | 5260 if (this_free == SYMBOL_BLOCK_SIZE && num_free > SYMBOL_BLOCK_SIZE) |
| 5282 struct marker_block **mprev = &marker_block; | 5282 struct marker_block **mprev = &marker_block; |
| 5283 register int lim = marker_block_index; | 5283 register int lim = marker_block_index; |
| 5284 register int num_free = 0, num_used = 0; | 5284 register int num_free = 0, num_used = 0; |
| 5285 | 5285 |
| 5286 marker_free_list = 0; | 5286 marker_free_list = 0; |
| 5287 | 5287 |
| 5288 for (mblk = marker_block; mblk; mblk = *mprev) | 5288 for (mblk = marker_block; mblk; mblk = *mprev) |
| 5289 { | 5289 { |
| 5290 register int i; | 5290 register int i; |
| 5291 int this_free = 0; | 5291 int this_free = 0; |
| 5292 EMACS_INT already_free = -1; | 5292 EMACS_INT already_free = -1; |
| 5412 else | 5412 else |
| 5413 total_vector_size += vector->size; | 5413 total_vector_size += vector->size; |
| 5414 prev = vector, vector = vector->next; | 5414 prev = vector, vector = vector->next; |
| 5415 } | 5415 } |
| 5416 } | 5416 } |
| 5417 | 5417 |
| 5418 #ifdef GC_CHECK_STRING_BYTES | 5418 #ifdef GC_CHECK_STRING_BYTES |
| 5419 if (!noninteractive) | 5419 if (!noninteractive) |
| 5420 check_string_bytes (1); | 5420 check_string_bytes (1); |
| 5421 #endif | 5421 #endif |
| 5422 } | 5422 } |
