aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorTom Tromey2013-06-03 12:25:05 -0600
committerTom Tromey2013-06-03 12:25:05 -0600
commit68359abba96d7ec4db8aab3d3dd9cf1105c3bab5 (patch)
tree862703e7e1a1888170136a8296a5750d6b2ae2eb /src/alloc.c
parentcbcba8ce7f980b01c18c0fd561ef6687b1361507 (diff)
parente2d8a6f0a229b4ebe26484b892ec4f14888f58b6 (diff)
downloademacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.tar.gz
emacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.zip
merge from trunk; clean up some issues
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c129
1 files changed, 44 insertions, 85 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 6da0ac428ab..b5885bdb283 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -319,19 +319,7 @@ static void *min_heap_address, *max_heap_address;
319static struct mem_node mem_z; 319static struct mem_node mem_z;
320#define MEM_NIL &mem_z 320#define MEM_NIL &mem_z
321 321
322static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t);
323static void lisp_free (void *);
324static bool live_vector_p (struct mem_node *, void *);
325static bool live_buffer_p (struct mem_node *, void *);
326static bool live_string_p (struct mem_node *, void *);
327static bool live_cons_p (struct mem_node *, void *);
328static bool live_symbol_p (struct mem_node *, void *);
329static bool live_float_p (struct mem_node *, void *);
330static bool live_misc_p (struct mem_node *, void *);
331static void mark_maybe_object (Lisp_Object);
332static void mark_memory (void *, void *);
333#if GC_MARK_STACK || defined GC_MALLOC_CHECK 322#if GC_MARK_STACK || defined GC_MALLOC_CHECK
334static void mem_init (void);
335static struct mem_node *mem_insert (void *, void *, enum mem_type); 323static struct mem_node *mem_insert (void *, void *, enum mem_type);
336static void mem_insert_fixup (struct mem_node *); 324static void mem_insert_fixup (struct mem_node *);
337static void mem_rotate_left (struct mem_node *); 325static void mem_rotate_left (struct mem_node *);
@@ -341,11 +329,6 @@ static void mem_delete_fixup (struct mem_node *);
341static struct mem_node *mem_find (void *); 329static struct mem_node *mem_find (void *);
342#endif 330#endif
343 331
344
345#if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS
346static void check_gcpros (void);
347#endif
348
349#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ 332#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */
350 333
351#ifndef DEADP 334#ifndef DEADP
@@ -1153,7 +1136,7 @@ lisp_align_free (void *block)
1153#define INTERVAL_BLOCK_SIZE \ 1136#define INTERVAL_BLOCK_SIZE \
1154 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval)) 1137 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval))
1155 1138
1156/* Intervals are allocated in chunks in form of an interval_block 1139/* Intervals are allocated in chunks in the form of an interval_block
1157 structure. */ 1140 structure. */
1158 1141
1159struct interval_block 1142struct interval_block
@@ -3342,56 +3325,50 @@ free_misc (Lisp_Object misc)
3342 total_free_markers++; 3325 total_free_markers++;
3343} 3326}
3344 3327
3328/* Verify properties of Lisp_Save_Value's representation
3329 that are assumed here and elsewhere. */
3330
3331verify (SAVE_UNUSED == 0);
3332verify ((SAVE_INTEGER | SAVE_POINTER | SAVE_OBJECT) >> SAVE_SLOT_BITS == 0);
3333
3345/* Return a Lisp_Save_Value object with the data saved according to 3334/* Return a Lisp_Save_Value object with the data saved according to
3346 FMT. Format specifiers are `i' for an integer, `p' for a pointer 3335 DATA_TYPE. DATA_TYPE should be one of SAVE_TYPE_INT_INT, etc. */
3347 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3348 3336
3349Lisp_Object 3337Lisp_Object
3350make_save_value (const char *fmt, ...) 3338make_save_value (enum Lisp_Save_Type save_type, ...)
3351{ 3339{
3352 va_list ap; 3340 va_list ap;
3353 int len = strlen (fmt); 3341 int i;
3354 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3342 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3355 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3343 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3356 3344
3357 eassert (0 < len && len < 5); 3345 eassert (0 < save_type
3358 va_start (ap, fmt); 3346 && (save_type < 1 << (SAVE_TYPE_BITS - 1)
3359 3347 || save_type == SAVE_TYPE_MEMORY));
3360#define INITX(index) \ 3348 p->save_type = save_type;
3361 do { \ 3349 va_start (ap, save_type);
3362 if (len <= index) \ 3350 save_type &= ~ (1 << (SAVE_TYPE_BITS - 1));
3363 p->type ## index = SAVE_UNUSED; \ 3351
3364 else \ 3352 for (i = 0; save_type; i++, save_type >>= SAVE_SLOT_BITS)
3365 { \ 3353 switch (save_type & ((1 << SAVE_SLOT_BITS) - 1))
3366 if (fmt[index] == 'i') \ 3354 {
3367 { \ 3355 case SAVE_POINTER:
3368 p->type ## index = SAVE_INTEGER; \ 3356 p->data[i].pointer = va_arg (ap, void *);
3369 p->data[index].integer = va_arg (ap, ptrdiff_t); \ 3357 break;
3370 } \
3371 else if (fmt[index] == 'p') \
3372 { \
3373 p->type ## index = SAVE_POINTER; \
3374 p->data[index].pointer = va_arg (ap, void *); \
3375 } \
3376 else if (fmt[index] == 'o') \
3377 { \
3378 p->type ## index = SAVE_OBJECT; \
3379 p->data[index].object = va_arg (ap, Lisp_Object); \
3380 } \
3381 else \
3382 emacs_abort (); \
3383 } \
3384 } while (0)
3385 3358
3386 INITX (0); 3359 case SAVE_INTEGER:
3387 INITX (1); 3360 p->data[i].integer = va_arg (ap, ptrdiff_t);
3388 INITX (2); 3361 break;
3389 INITX (3);
3390 3362
3391#undef INITX 3363 case SAVE_OBJECT:
3364 p->data[i].object = va_arg (ap, Lisp_Object);
3365 break;
3366
3367 default:
3368 emacs_abort ();
3369 }
3392 3370
3393 va_end (ap); 3371 va_end (ap);
3394 p->area = 0;
3395 return val; 3372 return val;
3396} 3373}
3397 3374
@@ -3402,11 +3379,8 @@ make_save_pointer (void *pointer)
3402{ 3379{
3403 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3380 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3404 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3381 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3405 3382 p->save_type = SAVE_POINTER;
3406 p->area = 0;
3407 p->type0 = SAVE_POINTER;
3408 p->data[0].pointer = pointer; 3383 p->data[0].pointer = pointer;
3409 p->type1 = p->type2 = p->type3 = SAVE_UNUSED;
3410 return val; 3384 return val;
3411} 3385}
3412 3386
@@ -5197,7 +5171,6 @@ returns nil, because real GC can't be done.
5197See Info node `(elisp)Garbage Collection'. */) 5171See Info node `(elisp)Garbage Collection'. */)
5198 (void) 5172 (void)
5199{ 5173{
5200 struct specbinding *bind;
5201 struct buffer *nextb; 5174 struct buffer *nextb;
5202 char stack_top_variable; 5175 char stack_top_variable;
5203 ptrdiff_t i; 5176 ptrdiff_t i;
@@ -5206,7 +5179,6 @@ See Info node `(elisp)Garbage Collection'. */)
5206 EMACS_TIME start; 5179 EMACS_TIME start;
5207 Lisp_Object retval = Qnil; 5180 Lisp_Object retval = Qnil;
5208 size_t tot_before = 0; 5181 size_t tot_before = 0;
5209 struct backtrace backtrace;
5210 5182
5211 if (abort_on_gc) 5183 if (abort_on_gc)
5212 emacs_abort (); 5184 emacs_abort ();
@@ -5217,12 +5189,7 @@ See Info node `(elisp)Garbage Collection'. */)
5217 return Qnil; 5189 return Qnil;
5218 5190
5219 /* Record this function, so it appears on the profiler's backtraces. */ 5191 /* Record this function, so it appears on the profiler's backtraces. */
5220 backtrace.next = backtrace_list; 5192 record_in_backtrace (Qautomatic_gc, &Qnil, 0);
5221 backtrace.function = Qautomatic_gc;
5222 backtrace.args = &Qnil;
5223 backtrace.nargs = 0;
5224 backtrace.debug_on_exit = 0;
5225 backtrace_list = &backtrace;
5226 5193
5227 check_cons_list (); 5194 check_cons_list ();
5228 5195
@@ -5486,7 +5453,6 @@ See Info node `(elisp)Garbage Collection'. */)
5486 malloc_probe (swept); 5453 malloc_probe (swept);
5487 } 5454 }
5488 5455
5489 backtrace_list = backtrace.next;
5490 return retval; 5456 return retval;
5491} 5457}
5492 5458
@@ -5810,14 +5776,13 @@ mark_object (Lisp_Object arg)
5810 case PVEC_WINDOW: 5776 case PVEC_WINDOW:
5811 { 5777 {
5812 struct window *w = (struct window *) ptr; 5778 struct window *w = (struct window *) ptr;
5813 bool leaf = NILP (w->hchild) && NILP (w->vchild);
5814 5779
5815 mark_vectorlike (ptr); 5780 mark_vectorlike (ptr);
5816 5781
5817 /* Mark glyphs for leaf windows. Marking window 5782 /* Mark glyph matrices, if any. Marking window
5818 matrices is sufficient because frame matrices 5783 matrices is sufficient because frame matrices
5819 use the same glyph memory. */ 5784 use the same glyph memory. */
5820 if (leaf && w->current_matrix) 5785 if (w->current_matrix)
5821 { 5786 {
5822 mark_glyph_matrix (w->current_matrix); 5787 mark_glyph_matrix (w->current_matrix);
5823 mark_glyph_matrix (w->desired_matrix); 5788 mark_glyph_matrix (w->desired_matrix);
@@ -5949,12 +5914,11 @@ mark_object (Lisp_Object arg)
5949 case Lisp_Misc_Save_Value: 5914 case Lisp_Misc_Save_Value:
5950 XMISCANY (obj)->gcmarkbit = 1; 5915 XMISCANY (obj)->gcmarkbit = 1;
5951 { 5916 {
5952 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); 5917 struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj);
5953 /* If `area' is nonzero, `data[0].pointer' is the address 5918 /* If `save_type' is zero, `data[0].pointer' is the address
5954 of a memory area containing `data[1].integer' potential 5919 of a memory area containing `data[1].integer' potential
5955 Lisp_Objects. */ 5920 Lisp_Objects. */
5956#if GC_MARK_STACK 5921 if (GC_MARK_STACK && ptr->save_type == SAVE_TYPE_MEMORY)
5957 if (ptr->area)
5958 { 5922 {
5959 Lisp_Object *p = ptr->data[0].pointer; 5923 Lisp_Object *p = ptr->data[0].pointer;
5960 ptrdiff_t nelt; 5924 ptrdiff_t nelt;
@@ -5962,17 +5926,12 @@ mark_object (Lisp_Object arg)
5962 mark_maybe_object (*p); 5926 mark_maybe_object (*p);
5963 } 5927 }
5964 else 5928 else
5965#endif /* GC_MARK_STACK */
5966 { 5929 {
5967 /* Find Lisp_Objects in `data[N]' slots and mark them. */ 5930 /* Find Lisp_Objects in `data[N]' slots and mark them. */
5968 if (ptr->type0 == SAVE_OBJECT) 5931 int i;
5969 mark_object (ptr->data[0].object); 5932 for (i = 0; i < SAVE_VALUE_SLOTS; i++)
5970 if (ptr->type1 == SAVE_OBJECT) 5933 if (save_type (ptr, i) == SAVE_OBJECT)
5971 mark_object (ptr->data[1].object); 5934 mark_object (ptr->data[i].object);
5972 if (ptr->type2 == SAVE_OBJECT)
5973 mark_object (ptr->data[2].object);
5974 if (ptr->type3 == SAVE_OBJECT)
5975 mark_object (ptr->data[3].object);
5976 } 5935 }
5977 } 5936 }
5978 break; 5937 break;