Mercurial > emacs
comparison src/alloc.c @ 90072:cb67264d6096
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-2
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-83
- miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-84
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-3
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-4
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-5
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-6
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-11
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-12
Remove "-face" suffix from lazy-highlight face name
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-13
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-16
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-17
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-18
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-21
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-22
<no summary provided>
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-23
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-39
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40
Fix regressions from latest reftex update
* miles@gnu.org--gnu-2005/gnus--rel--5.10--base-0
tag of miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-1
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-2
Merge from miles@gnu.org--gnu-2004
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-3
Merge from emacs--cvs-trunk--0
| author | Miles Bader <miles@gnu.org> |
|---|---|
| date | Sun, 16 Jan 2005 03:40:12 +0000 |
| parents | 95879cc1ed20 eeb8b96d077d |
| children | 6d92d69fae33 |
comparison
equal
deleted
inserted
replaced
| 90071:f6b4d0ebf147 | 90072:cb67264d6096 |
|---|---|
| 101 of these threads preempts the Emacs main thread and the hook variables | 101 of these threads preempts the Emacs main thread and the hook variables |
| 102 end up in an inconsistent state. So we have a mutex to prevent that (note | 102 end up in an inconsistent state. So we have a mutex to prevent that (note |
| 103 that the backend handles concurrent access to malloc within its own threads | 103 that the backend handles concurrent access to malloc within its own threads |
| 104 but Emacs code running in the main thread is not included in that control). | 104 but Emacs code running in the main thread is not included in that control). |
| 105 | 105 |
| 106 When UNBLOCK_INPUT is called, revoke_input_signal may be called. If this | 106 When UNBLOCK_INPUT is called, reinvoke_input_signal may be called. If this |
| 107 happens in one of the backend threads we will have two threads that tries | 107 happens in one of the backend threads we will have two threads that tries |
| 108 to run Emacs code at once, and the code is not prepared for that. | 108 to run Emacs code at once, and the code is not prepared for that. |
| 109 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ | 109 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ |
| 110 | 110 |
| 111 static pthread_mutex_t alloc_mutex; | 111 static pthread_mutex_t alloc_mutex; |
| 307 static void gc_sweep P_ ((void)); | 307 static void gc_sweep P_ ((void)); |
| 308 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); | 308 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); |
| 309 static void mark_face_cache P_ ((struct face_cache *)); | 309 static void mark_face_cache P_ ((struct face_cache *)); |
| 310 | 310 |
| 311 #ifdef HAVE_WINDOW_SYSTEM | 311 #ifdef HAVE_WINDOW_SYSTEM |
| 312 extern void mark_fringe_data P_ ((void)); | |
| 312 static void mark_image P_ ((struct image *)); | 313 static void mark_image P_ ((struct image *)); |
| 313 static void mark_image_cache P_ ((struct frame *)); | 314 static void mark_image_cache P_ ((struct frame *)); |
| 314 #endif /* HAVE_WINDOW_SYSTEM */ | 315 #endif /* HAVE_WINDOW_SYSTEM */ |
| 315 | 316 |
| 316 static struct Lisp_String *allocate_string P_ ((void)); | 317 static struct Lisp_String *allocate_string P_ ((void)); |
| 702 size_t osize = XMALLOC_GET_SIZE (val); | 703 size_t osize = XMALLOC_GET_SIZE (val); |
| 703 if (bcmp (xmalloc_overrun_check_trailer, | 704 if (bcmp (xmalloc_overrun_check_trailer, |
| 704 val + osize, | 705 val + osize, |
| 705 XMALLOC_OVERRUN_CHECK_SIZE)) | 706 XMALLOC_OVERRUN_CHECK_SIZE)) |
| 706 abort (); | 707 abort (); |
| 708 #ifdef XMALLOC_CLEAR_FREE_MEMORY | |
| 709 val -= XMALLOC_OVERRUN_CHECK_SIZE; | |
| 710 memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_SIZE*2); | |
| 711 #else | |
| 707 bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); | 712 bzero (val + osize, XMALLOC_OVERRUN_CHECK_SIZE); |
| 708 val -= XMALLOC_OVERRUN_CHECK_SIZE; | 713 val -= XMALLOC_OVERRUN_CHECK_SIZE; |
| 709 bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | 714 bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); |
| 715 #endif | |
| 710 } | 716 } |
| 711 | 717 |
| 712 free (val); | 718 free (val); |
| 713 --check_depth; | 719 --check_depth; |
| 714 } | 720 } |
| 1111 MEM_TYPE_BUFFER); | 1117 MEM_TYPE_BUFFER); |
| 1112 return b; | 1118 return b; |
| 1113 } | 1119 } |
| 1114 | 1120 |
| 1115 | 1121 |
| 1122 #ifndef SYSTEM_MALLOC | |
| 1123 | |
| 1124 /* If we released our reserve (due to running out of memory), | |
| 1125 and we have a fair amount free once again, | |
| 1126 try to set aside another reserve in case we run out once more. | |
| 1127 | |
| 1128 This is called when a relocatable block is freed in ralloc.c. */ | |
| 1129 | |
| 1130 void | |
| 1131 refill_memory_reserve () | |
| 1132 { | |
| 1133 if (spare_memory == 0) | |
| 1134 spare_memory = (char *) malloc ((size_t) SPARE_MEMORY); | |
| 1135 } | |
| 1136 | |
| 1137 | |
| 1116 /* Arranging to disable input signals while we're in malloc. | 1138 /* Arranging to disable input signals while we're in malloc. |
| 1117 | 1139 |
| 1118 This only works with GNU malloc. To help out systems which can't | 1140 This only works with GNU malloc. To help out systems which can't |
| 1119 use GNU malloc, all the calls to malloc, realloc, and free | 1141 use GNU malloc, all the calls to malloc, realloc, and free |
| 1120 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT | 1142 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT |
| 1121 pairs; unfortunately, we have no idea what C library functions | 1143 pair; unfortunately, we have no idea what C library functions |
| 1122 might call malloc, so we can't really protect them unless you're | 1144 might call malloc, so we can't really protect them unless you're |
| 1123 using GNU malloc. Fortunately, most of the major operating systems | 1145 using GNU malloc. Fortunately, most of the major operating systems |
| 1124 can use GNU malloc. */ | 1146 can use GNU malloc. */ |
| 1125 | 1147 |
| 1126 #ifndef SYSTEM_MALLOC | 1148 #ifndef SYNC_INPUT |
| 1149 | |
| 1127 #ifndef DOUG_LEA_MALLOC | 1150 #ifndef DOUG_LEA_MALLOC |
| 1128 extern void * (*__malloc_hook) P_ ((size_t)); | 1151 extern void * (*__malloc_hook) P_ ((size_t)); |
| 1129 extern void * (*__realloc_hook) P_ ((void *, size_t)); | 1152 extern void * (*__realloc_hook) P_ ((void *, size_t)); |
| 1130 extern void (*__free_hook) P_ ((void *)); | 1153 extern void (*__free_hook) P_ ((void *)); |
| 1131 /* Else declared in malloc.h, perhaps with an extra arg. */ | 1154 /* Else declared in malloc.h, perhaps with an extra arg. */ |
| 1180 __free_hook = emacs_blocked_free; | 1203 __free_hook = emacs_blocked_free; |
| 1181 UNBLOCK_INPUT_ALLOC; | 1204 UNBLOCK_INPUT_ALLOC; |
| 1182 } | 1205 } |
| 1183 | 1206 |
| 1184 | 1207 |
| 1185 /* If we released our reserve (due to running out of memory), | |
| 1186 and we have a fair amount free once again, | |
| 1187 try to set aside another reserve in case we run out once more. | |
| 1188 | |
| 1189 This is called when a relocatable block is freed in ralloc.c. */ | |
| 1190 | |
| 1191 void | |
| 1192 refill_memory_reserve () | |
| 1193 { | |
| 1194 if (spare_memory == 0) | |
| 1195 spare_memory = (char *) malloc ((size_t) SPARE_MEMORY); | |
| 1196 } | |
| 1197 | |
| 1198 | |
| 1199 /* This function is the malloc hook that Emacs uses. */ | 1208 /* This function is the malloc hook that Emacs uses. */ |
| 1200 | 1209 |
| 1201 static void * | 1210 static void * |
| 1202 emacs_blocked_malloc (size) | 1211 emacs_blocked_malloc (size) |
| 1203 size_t size; | 1212 size_t size; |
| 1345 if (__realloc_hook != emacs_blocked_realloc) | 1354 if (__realloc_hook != emacs_blocked_realloc) |
| 1346 old_realloc_hook = __realloc_hook; | 1355 old_realloc_hook = __realloc_hook; |
| 1347 __realloc_hook = emacs_blocked_realloc; | 1356 __realloc_hook = emacs_blocked_realloc; |
| 1348 } | 1357 } |
| 1349 | 1358 |
| 1359 #endif /* not SYNC_INPUT */ | |
| 1350 #endif /* not SYSTEM_MALLOC */ | 1360 #endif /* not SYSTEM_MALLOC */ |
| 1351 | 1361 |
| 1352 | 1362 |
| 1353 | 1363 |
| 1354 /*********************************************************************** | 1364 /*********************************************************************** |
| 4638 { | 4648 { |
| 4639 /* If a buffer's undo list is Qt, that means that undo is | 4649 /* If a buffer's undo list is Qt, that means that undo is |
| 4640 turned off in that buffer. Calling truncate_undo_list on | 4650 turned off in that buffer. Calling truncate_undo_list on |
| 4641 Qt tends to return NULL, which effectively turns undo back on. | 4651 Qt tends to return NULL, which effectively turns undo back on. |
| 4642 So don't call truncate_undo_list if undo_list is Qt. */ | 4652 So don't call truncate_undo_list if undo_list is Qt. */ |
| 4643 if (! EQ (nextb->undo_list, Qt)) | 4653 if (! NILP (nextb->name) && ! EQ (nextb->undo_list, Qt)) |
| 4644 truncate_undo_list (nextb); | 4654 truncate_undo_list (nextb); |
| 4645 | 4655 |
| 4646 /* Shrink buffer gaps, but skip indirect and dead buffers. */ | 4656 /* Shrink buffer gaps, but skip indirect and dead buffers. */ |
| 4647 if (nextb->base_buffer == 0 && !NILP (nextb->name)) | 4657 if (nextb->base_buffer == 0 && !NILP (nextb->name)) |
| 4648 { | 4658 { |
| 4749 { | 4759 { |
| 4750 mark_object (handler->handler); | 4760 mark_object (handler->handler); |
| 4751 mark_object (handler->var); | 4761 mark_object (handler->var); |
| 4752 } | 4762 } |
| 4753 mark_backtrace (); | 4763 mark_backtrace (); |
| 4764 | |
| 4765 #ifdef HAVE_WINDOW_SYSTEM | |
| 4766 mark_fringe_data (); | |
| 4767 #endif | |
| 4754 | 4768 |
| 4755 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES | 4769 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES |
| 4756 mark_stack (); | 4770 mark_stack (); |
| 4757 #endif | 4771 #endif |
| 4758 | 4772 |
