diff options
| author | Joakim Verona | 2013-03-26 16:14:01 +0100 |
|---|---|---|
| committer | Joakim Verona | 2013-03-26 16:14:01 +0100 |
| commit | 48c226c2c2592e31a47559bd1689fcc4354d9479 (patch) | |
| tree | 2f79cf5a16930fbd09d965be98b6d145c9984eb6 /src/alloc.c | |
| parent | e11705b616777a8a72363b2037d989987630e863 (diff) | |
| parent | 9536ec028c24fbedf617b67e98a108504e5b1e73 (diff) | |
| download | emacs-48c226c2c2592e31a47559bd1689fcc4354d9479.tar.gz emacs-48c226c2c2592e31a47559bd1689fcc4354d9479.zip | |
auto upstream
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 119 |
1 files changed, 43 insertions, 76 deletions
diff --git a/src/alloc.c b/src/alloc.c index b2703c5f961..ea833c62b94 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -323,20 +323,7 @@ static void *min_heap_address, *max_heap_address; | |||
| 323 | static struct mem_node mem_z; | 323 | static struct mem_node mem_z; |
| 324 | #define MEM_NIL &mem_z | 324 | #define MEM_NIL &mem_z |
| 325 | 325 | ||
| 326 | static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t); | ||
| 327 | static void lisp_free (void *); | ||
| 328 | static void mark_stack (void); | ||
| 329 | static bool live_vector_p (struct mem_node *, void *); | ||
| 330 | static bool live_buffer_p (struct mem_node *, void *); | ||
| 331 | static bool live_string_p (struct mem_node *, void *); | ||
| 332 | static bool live_cons_p (struct mem_node *, void *); | ||
| 333 | static bool live_symbol_p (struct mem_node *, void *); | ||
| 334 | static bool live_float_p (struct mem_node *, void *); | ||
| 335 | static bool live_misc_p (struct mem_node *, void *); | ||
| 336 | static void mark_maybe_object (Lisp_Object); | ||
| 337 | static void mark_memory (void *, void *); | ||
| 338 | #if GC_MARK_STACK || defined GC_MALLOC_CHECK | 326 | #if GC_MARK_STACK || defined GC_MALLOC_CHECK |
| 339 | static void mem_init (void); | ||
| 340 | static struct mem_node *mem_insert (void *, void *, enum mem_type); | 327 | static struct mem_node *mem_insert (void *, void *, enum mem_type); |
| 341 | static void mem_insert_fixup (struct mem_node *); | 328 | static void mem_insert_fixup (struct mem_node *); |
| 342 | static void mem_rotate_left (struct mem_node *); | 329 | static void mem_rotate_left (struct mem_node *); |
| @@ -346,11 +333,6 @@ static void mem_delete_fixup (struct mem_node *); | |||
| 346 | static struct mem_node *mem_find (void *); | 333 | static struct mem_node *mem_find (void *); |
| 347 | #endif | 334 | #endif |
| 348 | 335 | ||
| 349 | |||
| 350 | #if GC_MARK_STACK == GC_MARK_STACK_CHECK_GCPROS | ||
| 351 | static void check_gcpros (void); | ||
| 352 | #endif | ||
| 353 | |||
| 354 | #endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ | 336 | #endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ |
| 355 | 337 | ||
| 356 | #ifndef DEADP | 338 | #ifndef DEADP |
| @@ -797,7 +779,7 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, | |||
| 797 | ptrdiff_t nitems_incr_max = n_max - n; | 779 | ptrdiff_t nitems_incr_max = n_max - n; |
| 798 | ptrdiff_t incr = max (nitems_incr_min, min (incr_estimate, nitems_incr_max)); | 780 | ptrdiff_t incr = max (nitems_incr_min, min (incr_estimate, nitems_incr_max)); |
| 799 | 781 | ||
| 800 | eassert (0 < item_size && 0 < nitems_incr_min && 0 <= n && -1 <= nitems_max); | 782 | eassert (item_size > 0 && nitems_incr_min > 0 && n >= 0 && nitems_max >= -1); |
| 801 | if (! pa) | 783 | if (! pa) |
| 802 | *nitems = 0; | 784 | *nitems = 0; |
| 803 | if (nitems_incr_max < incr) | 785 | if (nitems_incr_max < incr) |
| @@ -1162,7 +1144,7 @@ lisp_align_free (void *block) | |||
| 1162 | #define INTERVAL_BLOCK_SIZE \ | 1144 | #define INTERVAL_BLOCK_SIZE \ |
| 1163 | ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval)) | 1145 | ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval)) |
| 1164 | 1146 | ||
| 1165 | /* Intervals are allocated in chunks in form of an interval_block | 1147 | /* Intervals are allocated in chunks in the form of an interval_block |
| 1166 | structure. */ | 1148 | structure. */ |
| 1167 | 1149 | ||
| 1168 | struct interval_block | 1150 | struct interval_block |
| @@ -3344,56 +3326,50 @@ free_misc (Lisp_Object misc) | |||
| 3344 | total_free_markers++; | 3326 | total_free_markers++; |
| 3345 | } | 3327 | } |
| 3346 | 3328 | ||
| 3329 | /* Verify properties of Lisp_Save_Value's representation | ||
| 3330 | that are assumed here and elsewhere. */ | ||
| 3331 | |||
| 3332 | verify (SAVE_UNUSED == 0); | ||
| 3333 | verify ((SAVE_INTEGER | SAVE_POINTER | SAVE_OBJECT) >> SAVE_SLOT_BITS == 0); | ||
| 3334 | |||
| 3347 | /* Return a Lisp_Save_Value object with the data saved according to | 3335 | /* Return a Lisp_Save_Value object with the data saved according to |
| 3348 | FMT. Format specifiers are `i' for an integer, `p' for a pointer | 3336 | DATA_TYPE. DATA_TYPE should be one of SAVE_TYPE_INT_INT, etc. */ |
| 3349 | and `o' for Lisp_Object. Up to 4 objects can be specified. */ | ||
| 3350 | 3337 | ||
| 3351 | Lisp_Object | 3338 | Lisp_Object |
| 3352 | make_save_value (const char *fmt, ...) | 3339 | make_save_value (enum Lisp_Save_Type save_type, ...) |
| 3353 | { | 3340 | { |
| 3354 | va_list ap; | 3341 | va_list ap; |
| 3355 | int len = strlen (fmt); | 3342 | int i; |
| 3356 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); | 3343 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); |
| 3357 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); | 3344 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); |
| 3358 | 3345 | ||
| 3359 | eassert (0 < len && len < 5); | 3346 | eassert (0 < save_type |
| 3360 | va_start (ap, fmt); | 3347 | && (save_type < 1 << (SAVE_TYPE_BITS - 1) |
| 3361 | 3348 | || save_type == SAVE_TYPE_MEMORY)); | |
| 3362 | #define INITX(index) \ | 3349 | p->save_type = save_type; |
| 3363 | do { \ | 3350 | va_start (ap, save_type); |
| 3364 | if (len <= index) \ | 3351 | save_type &= ~ (1 << (SAVE_TYPE_BITS - 1)); |
| 3365 | p->type ## index = SAVE_UNUSED; \ | 3352 | |
| 3366 | else \ | 3353 | for (i = 0; save_type; i++, save_type >>= SAVE_SLOT_BITS) |
| 3367 | { \ | 3354 | switch (save_type & ((1 << SAVE_SLOT_BITS) - 1)) |
| 3368 | if (fmt[index] == 'i') \ | 3355 | { |
| 3369 | { \ | 3356 | case SAVE_POINTER: |
| 3370 | p->type ## index = SAVE_INTEGER; \ | 3357 | p->data[i].pointer = va_arg (ap, void *); |
| 3371 | p->data[index].integer = va_arg (ap, ptrdiff_t); \ | 3358 | break; |
| 3372 | } \ | ||
| 3373 | else if (fmt[index] == 'p') \ | ||
| 3374 | { \ | ||
| 3375 | p->type ## index = SAVE_POINTER; \ | ||
| 3376 | p->data[index].pointer = va_arg (ap, void *); \ | ||
| 3377 | } \ | ||
| 3378 | else if (fmt[index] == 'o') \ | ||
| 3379 | { \ | ||
| 3380 | p->type ## index = SAVE_OBJECT; \ | ||
| 3381 | p->data[index].object = va_arg (ap, Lisp_Object); \ | ||
| 3382 | } \ | ||
| 3383 | else \ | ||
| 3384 | emacs_abort (); \ | ||
| 3385 | } \ | ||
| 3386 | } while (0) | ||
| 3387 | 3359 | ||
| 3388 | INITX (0); | 3360 | case SAVE_INTEGER: |
| 3389 | INITX (1); | 3361 | p->data[i].integer = va_arg (ap, ptrdiff_t); |
| 3390 | INITX (2); | 3362 | break; |
| 3391 | INITX (3); | ||
| 3392 | 3363 | ||
| 3393 | #undef INITX | 3364 | case SAVE_OBJECT: |
| 3365 | p->data[i].object = va_arg (ap, Lisp_Object); | ||
| 3366 | break; | ||
| 3367 | |||
| 3368 | default: | ||
| 3369 | emacs_abort (); | ||
| 3370 | } | ||
| 3394 | 3371 | ||
| 3395 | va_end (ap); | 3372 | va_end (ap); |
| 3396 | p->area = 0; | ||
| 3397 | return val; | 3373 | return val; |
| 3398 | } | 3374 | } |
| 3399 | 3375 | ||
| @@ -3404,11 +3380,8 @@ make_save_pointer (void *pointer) | |||
| 3404 | { | 3380 | { |
| 3405 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); | 3381 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); |
| 3406 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); | 3382 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); |
| 3407 | 3383 | p->save_type = SAVE_POINTER; | |
| 3408 | p->area = 0; | ||
| 3409 | p->type0 = SAVE_POINTER; | ||
| 3410 | p->data[0].pointer = pointer; | 3384 | p->data[0].pointer = pointer; |
| 3411 | p->type1 = p->type2 = p->type3 = SAVE_UNUSED; | ||
| 3412 | return val; | 3385 | return val; |
| 3413 | } | 3386 | } |
| 3414 | 3387 | ||
| @@ -5403,7 +5376,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5403 | double tot = total_bytes_of_live_objects (); | 5376 | double tot = total_bytes_of_live_objects (); |
| 5404 | 5377 | ||
| 5405 | tot *= XFLOAT_DATA (Vgc_cons_percentage); | 5378 | tot *= XFLOAT_DATA (Vgc_cons_percentage); |
| 5406 | if (0 < tot) | 5379 | if (tot > 0) |
| 5407 | { | 5380 | { |
| 5408 | if (tot < TYPE_MAXIMUM (EMACS_INT)) | 5381 | if (tot < TYPE_MAXIMUM (EMACS_INT)) |
| 5409 | gc_relative_threshold = tot; | 5382 | gc_relative_threshold = tot; |
| @@ -5976,12 +5949,11 @@ mark_object (Lisp_Object arg) | |||
| 5976 | case Lisp_Misc_Save_Value: | 5949 | case Lisp_Misc_Save_Value: |
| 5977 | XMISCANY (obj)->gcmarkbit = 1; | 5950 | XMISCANY (obj)->gcmarkbit = 1; |
| 5978 | { | 5951 | { |
| 5979 | register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); | 5952 | struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); |
| 5980 | /* If `area' is nonzero, `data[0].pointer' is the address | 5953 | /* If `save_type' is zero, `data[0].pointer' is the address |
| 5981 | of a memory area containing `data[1].integer' potential | 5954 | of a memory area containing `data[1].integer' potential |
| 5982 | Lisp_Objects. */ | 5955 | Lisp_Objects. */ |
| 5983 | #if GC_MARK_STACK | 5956 | if (GC_MARK_STACK && ptr->save_type == SAVE_TYPE_MEMORY) |
| 5984 | if (ptr->area) | ||
| 5985 | { | 5957 | { |
| 5986 | Lisp_Object *p = ptr->data[0].pointer; | 5958 | Lisp_Object *p = ptr->data[0].pointer; |
| 5987 | ptrdiff_t nelt; | 5959 | ptrdiff_t nelt; |
| @@ -5989,17 +5961,12 @@ mark_object (Lisp_Object arg) | |||
| 5989 | mark_maybe_object (*p); | 5961 | mark_maybe_object (*p); |
| 5990 | } | 5962 | } |
| 5991 | else | 5963 | else |
| 5992 | #endif /* GC_MARK_STACK */ | ||
| 5993 | { | 5964 | { |
| 5994 | /* Find Lisp_Objects in `data[N]' slots and mark them. */ | 5965 | /* Find Lisp_Objects in `data[N]' slots and mark them. */ |
| 5995 | if (ptr->type0 == SAVE_OBJECT) | 5966 | int i; |
| 5996 | mark_object (ptr->data[0].object); | 5967 | for (i = 0; i < SAVE_VALUE_SLOTS; i++) |
| 5997 | if (ptr->type1 == SAVE_OBJECT) | 5968 | if (save_type (ptr, i) == SAVE_OBJECT) |
| 5998 | mark_object (ptr->data[1].object); | 5969 | mark_object (ptr->data[i].object); |
| 5999 | if (ptr->type2 == SAVE_OBJECT) | ||
| 6000 | mark_object (ptr->data[2].object); | ||
| 6001 | if (ptr->type3 == SAVE_OBJECT) | ||
| 6002 | mark_object (ptr->data[3].object); | ||
| 6003 | } | 5970 | } |
| 6004 | } | 5971 | } |
| 6005 | break; | 5972 | break; |