diff options
| author | Tom Tromey | 2013-01-16 11:48:32 -0700 |
|---|---|---|
| committer | Tom Tromey | 2013-01-16 11:48:32 -0700 |
| commit | 6f4de085f065e11f4df3195d47479f28f5ef08ba (patch) | |
| tree | 1211a00f1afc86c2b73624897993db02a4852943 /src/alloc.c | |
| parent | e078a23febca14bc919c5806670479c395e3253e (diff) | |
| parent | ffe04adc88e546c406f9b050238fb98a7243c7a0 (diff) | |
| download | emacs-6f4de085f065e11f4df3195d47479f28f5ef08ba.tar.gz emacs-6f4de085f065e11f4df3195d47479f28f5ef08ba.zip | |
merge from trunk
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 117 |
1 files changed, 84 insertions, 33 deletions
diff --git a/src/alloc.c b/src/alloc.c index c2b2a4c1ed7..b7c17fbd6fb 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -209,6 +209,7 @@ Lisp_Object Qchar_table_extra_slots; | |||
| 209 | 209 | ||
| 210 | static Lisp_Object Qpost_gc_hook; | 210 | static Lisp_Object Qpost_gc_hook; |
| 211 | 211 | ||
| 212 | static void free_save_value (Lisp_Object); | ||
| 212 | static void mark_terminals (void); | 213 | static void mark_terminals (void); |
| 213 | static void gc_sweep (void); | 214 | static void gc_sweep (void); |
| 214 | static Lisp_Object make_pure_vector (ptrdiff_t); | 215 | static Lisp_Object make_pure_vector (ptrdiff_t); |
| @@ -219,7 +220,6 @@ static void refill_memory_reserve (void); | |||
| 219 | #endif | 220 | #endif |
| 220 | static void compact_small_strings (void); | 221 | static void compact_small_strings (void); |
| 221 | static void free_large_strings (void); | 222 | static void free_large_strings (void); |
| 222 | static void free_misc (Lisp_Object); | ||
| 223 | extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE; | 223 | extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE; |
| 224 | 224 | ||
| 225 | /* When scanning the C stack for live Lisp objects, Emacs keeps track of | 225 | /* When scanning the C stack for live Lisp objects, Emacs keeps track of |
| @@ -3337,9 +3337,9 @@ allocate_misc (enum Lisp_Misc_Type type) | |||
| 3337 | return val; | 3337 | return val; |
| 3338 | } | 3338 | } |
| 3339 | 3339 | ||
| 3340 | /* Free a Lisp_Misc object */ | 3340 | /* Free a Lisp_Misc object. */ |
| 3341 | 3341 | ||
| 3342 | static void | 3342 | void |
| 3343 | free_misc (Lisp_Object misc) | 3343 | free_misc (Lisp_Object misc) |
| 3344 | { | 3344 | { |
| 3345 | XMISCTYPE (misc) = Lisp_Misc_Free; | 3345 | XMISCTYPE (misc) = Lisp_Misc_Free; |
| @@ -3349,34 +3349,77 @@ free_misc (Lisp_Object misc) | |||
| 3349 | total_free_markers++; | 3349 | total_free_markers++; |
| 3350 | } | 3350 | } |
| 3351 | 3351 | ||
| 3352 | /* Return a Lisp_Misc_Save_Value object containing POINTER and | 3352 | /* Return a Lisp_Save_Value object with the data saved according to |
| 3353 | INTEGER. This is used to package C values to call record_unwind_protect. | 3353 | FMT. Format specifiers are `i' for an integer, `p' for a pointer |
| 3354 | The unwind function can get the C values back using XSAVE_VALUE. */ | 3354 | and `o' for Lisp_Object. Up to 4 objects can be specified. */ |
| 3355 | 3355 | ||
| 3356 | Lisp_Object | 3356 | Lisp_Object |
| 3357 | make_save_value (void *pointer, ptrdiff_t integer) | 3357 | format_save_value (const char *fmt, ...) |
| 3358 | { | 3358 | { |
| 3359 | register Lisp_Object val; | 3359 | va_list ap; |
| 3360 | register struct Lisp_Save_Value *p; | 3360 | int len = strlen (fmt); |
| 3361 | Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); | ||
| 3362 | struct Lisp_Save_Value *p = XSAVE_VALUE (val); | ||
| 3363 | |||
| 3364 | eassert (0 < len && len < 5); | ||
| 3365 | va_start (ap, fmt); | ||
| 3366 | |||
| 3367 | #define INITX(index) \ | ||
| 3368 | do { \ | ||
| 3369 | if (len <= index) \ | ||
| 3370 | p->type ## index = SAVE_UNUSED; \ | ||
| 3371 | else \ | ||
| 3372 | { \ | ||
| 3373 | if (fmt[index] == 'i') \ | ||
| 3374 | { \ | ||
| 3375 | p->type ## index = SAVE_INTEGER; \ | ||
| 3376 | p->data[index].integer = va_arg (ap, ptrdiff_t); \ | ||
| 3377 | } \ | ||
| 3378 | else if (fmt[index] == 'p') \ | ||
| 3379 | { \ | ||
| 3380 | p->type ## index = SAVE_POINTER; \ | ||
| 3381 | p->data[index].pointer = va_arg (ap, void *); \ | ||
| 3382 | } \ | ||
| 3383 | else if (fmt[index] == 'o') \ | ||
| 3384 | { \ | ||
| 3385 | p->type ## index = SAVE_OBJECT; \ | ||
| 3386 | p->data[index].object = va_arg (ap, Lisp_Object); \ | ||
| 3387 | } \ | ||
| 3388 | else \ | ||
| 3389 | emacs_abort (); \ | ||
| 3390 | } \ | ||
| 3391 | } while (0) | ||
| 3392 | |||
| 3393 | INITX (0); | ||
| 3394 | INITX (1); | ||
| 3395 | INITX (2); | ||
| 3396 | INITX (3); | ||
| 3361 | 3397 | ||
| 3362 | val = allocate_misc (Lisp_Misc_Save_Value); | 3398 | #undef INITX |
| 3363 | p = XSAVE_VALUE (val); | 3399 | |
| 3364 | p->pointer = pointer; | 3400 | va_end (ap); |
| 3365 | p->integer = integer; | 3401 | p->area = 0; |
| 3366 | p->dogc = 0; | ||
| 3367 | return val; | 3402 | return val; |
| 3368 | } | 3403 | } |
| 3369 | 3404 | ||
| 3370 | /* Free a Lisp_Misc_Save_Value object. */ | 3405 | /* Return a Lisp_Save_Value object containing POINTER and INTEGER. |
| 3406 | Most code should use this to package C integers and pointers | ||
| 3407 | to call record_unwind_protect. The unwind function can get the | ||
| 3408 | C values back using XSAVE_POINTER and XSAVE_INTEGER. */ | ||
| 3371 | 3409 | ||
| 3372 | void | 3410 | Lisp_Object |
| 3373 | free_save_value (Lisp_Object save) | 3411 | make_save_value (void *pointer, ptrdiff_t integer) |
| 3374 | { | 3412 | { |
| 3375 | register struct Lisp_Save_Value *p = XSAVE_VALUE (save); | 3413 | return format_save_value ("pi", pointer, integer); |
| 3414 | } | ||
| 3415 | |||
| 3416 | /* Free a Lisp_Save_Value object. Do not use this function | ||
| 3417 | if SAVE contains pointer other than returned by xmalloc. */ | ||
| 3376 | 3418 | ||
| 3377 | p->dogc = 0; | 3419 | static void |
| 3378 | xfree (p->pointer); | 3420 | free_save_value (Lisp_Object save) |
| 3379 | p->pointer = NULL; | 3421 | { |
| 3422 | xfree (XSAVE_POINTER (save, 0)); | ||
| 3380 | free_misc (save); | 3423 | free_misc (save); |
| 3381 | } | 3424 | } |
| 3382 | 3425 | ||
| @@ -4444,11 +4487,6 @@ mark_memory (void *start, void *end) | |||
| 4444 | } | 4487 | } |
| 4445 | } | 4488 | } |
| 4446 | 4489 | ||
| 4447 | /* setjmp will work with GCC unless NON_SAVING_SETJMP is defined in | ||
| 4448 | the GCC system configuration. In gcc 3.2, the only systems for | ||
| 4449 | which this is so are i386-sco5 non-ELF, i386-sysv3 (maybe included | ||
| 4450 | by others?) and ns32k-pc532-min. */ | ||
| 4451 | |||
| 4452 | #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS | 4490 | #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS |
| 4453 | 4491 | ||
| 4454 | static bool setjmp_tested_p; | 4492 | static bool setjmp_tested_p; |
| @@ -5913,20 +5951,33 @@ mark_object (Lisp_Object arg) | |||
| 5913 | 5951 | ||
| 5914 | case Lisp_Misc_Save_Value: | 5952 | case Lisp_Misc_Save_Value: |
| 5915 | XMISCANY (obj)->gcmarkbit = 1; | 5953 | XMISCANY (obj)->gcmarkbit = 1; |
| 5916 | #if GC_MARK_STACK | ||
| 5917 | { | 5954 | { |
| 5918 | register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); | 5955 | register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); |
| 5919 | /* If DOGC is set, POINTER is the address of a memory | 5956 | /* If `area' is nonzero, `data[0].pointer' is the address |
| 5920 | area containing INTEGER potential Lisp_Objects. */ | 5957 | of a memory area containing `data[1].integer' potential |
| 5921 | if (ptr->dogc) | 5958 | Lisp_Objects. */ |
| 5959 | #if GC_MARK_STACK | ||
| 5960 | if (ptr->area) | ||
| 5922 | { | 5961 | { |
| 5923 | Lisp_Object *p = (Lisp_Object *) ptr->pointer; | 5962 | Lisp_Object *p = ptr->data[0].pointer; |
| 5924 | ptrdiff_t nelt; | 5963 | ptrdiff_t nelt; |
| 5925 | for (nelt = ptr->integer; nelt > 0; nelt--, p++) | 5964 | for (nelt = ptr->data[1].integer; nelt > 0; nelt--, p++) |
| 5926 | mark_maybe_object (*p); | 5965 | mark_maybe_object (*p); |
| 5927 | } | 5966 | } |
| 5967 | else | ||
| 5968 | #endif /* GC_MARK_STACK */ | ||
| 5969 | { | ||
| 5970 | /* Find Lisp_Objects in `data[N]' slots and mark them. */ | ||
| 5971 | if (ptr->type0 == SAVE_OBJECT) | ||
| 5972 | mark_object (ptr->data[0].object); | ||
| 5973 | if (ptr->type1 == SAVE_OBJECT) | ||
| 5974 | mark_object (ptr->data[1].object); | ||
| 5975 | if (ptr->type2 == SAVE_OBJECT) | ||
| 5976 | mark_object (ptr->data[2].object); | ||
| 5977 | if (ptr->type3 == SAVE_OBJECT) | ||
| 5978 | mark_object (ptr->data[3].object); | ||
| 5979 | } | ||
| 5928 | } | 5980 | } |
| 5929 | #endif | ||
| 5930 | break; | 5981 | break; |
| 5931 | 5982 | ||
| 5932 | case Lisp_Misc_Overlay: | 5983 | case Lisp_Misc_Overlay: |