aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c73
1 files changed, 58 insertions, 15 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 3f1ccc82a58..7275a01bb73 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -209,6 +209,7 @@ Lisp_Object Qchar_table_extra_slots;
209 209
210static Lisp_Object Qpost_gc_hook; 210static Lisp_Object Qpost_gc_hook;
211 211
212static void free_save_value (Lisp_Object);
212static void mark_terminals (void); 213static void mark_terminals (void);
213static void gc_sweep (void); 214static void gc_sweep (void);
214static Lisp_Object make_pure_vector (ptrdiff_t); 215static Lisp_Object make_pure_vector (ptrdiff_t);
@@ -3302,7 +3303,7 @@ static union Lisp_Misc *marker_free_list;
3302 3303
3303/* Return a newly allocated Lisp_Misc object of specified TYPE. */ 3304/* Return a newly allocated Lisp_Misc object of specified TYPE. */
3304 3305
3305Lisp_Object 3306static Lisp_Object
3306allocate_misc (enum Lisp_Misc_Type type) 3307allocate_misc (enum Lisp_Misc_Type type)
3307{ 3308{
3308 Lisp_Object val; 3309 Lisp_Object val;
@@ -3350,6 +3351,59 @@ free_misc (Lisp_Object misc)
3350 total_free_markers++; 3351 total_free_markers++;
3351} 3352}
3352 3353
3354/* Return a Lisp_Save_Value object with the data saved according to
3355 FMT. Format specifiers are `i' for an integer, `p' for a pointer
3356 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3357
3358Lisp_Object
3359format_save_value (const char *fmt, ...)
3360{
3361 va_list ap;
3362 int len = strlen (fmt);
3363 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3364 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3365
3366 eassert (0 < len && len < 5);
3367 va_start (ap, fmt);
3368
3369#define INITX(index) \
3370 do { \
3371 if (len <= index) \
3372 p->type ## index = SAVE_UNUSED; \
3373 else \
3374 { \
3375 if (fmt[index] == 'i') \
3376 { \
3377 p->type ## index = SAVE_INTEGER; \
3378 p->data[index].integer = va_arg (ap, ptrdiff_t); \
3379 } \
3380 else if (fmt[index] == 'p') \
3381 { \
3382 p->type ## index = SAVE_POINTER; \
3383 p->data[index].pointer = va_arg (ap, void *); \
3384 } \
3385 else if (fmt[index] == 'o') \
3386 { \
3387 p->type ## index = SAVE_OBJECT; \
3388 p->data[index].object = va_arg (ap, Lisp_Object); \
3389 } \
3390 else \
3391 emacs_abort (); \
3392 } \
3393 } while (0)
3394
3395 INITX (0);
3396 INITX (1);
3397 INITX (2);
3398 INITX (3);
3399
3400#undef INITX
3401
3402 va_end (ap);
3403 p->area = 0;
3404 return val;
3405}
3406
3353/* Return a Lisp_Save_Value object containing POINTER and INTEGER. 3407/* Return a Lisp_Save_Value object containing POINTER and INTEGER.
3354 Most code should use this to package C integers and pointers 3408 Most code should use this to package C integers and pointers
3355 to call record_unwind_protect. The unwind function can get the 3409 to call record_unwind_protect. The unwind function can get the
@@ -3358,27 +3412,16 @@ free_misc (Lisp_Object misc)
3358Lisp_Object 3412Lisp_Object
3359make_save_value (void *pointer, ptrdiff_t integer) 3413make_save_value (void *pointer, ptrdiff_t integer)
3360{ 3414{
3361 register Lisp_Object val; 3415 return format_save_value ("pi", pointer, integer);
3362 register struct Lisp_Save_Value *p;
3363
3364 val = allocate_misc (Lisp_Misc_Save_Value);
3365 p = XSAVE_VALUE (val);
3366 p->type0 = SAVE_POINTER;
3367 p->data[0].pointer = pointer;
3368 p->type1 = SAVE_INTEGER;
3369 p->data[1].integer = integer;
3370 p->type2 = p->type3 = SAVE_UNUSED;
3371 p->area = 0;
3372 return val;
3373} 3416}
3374 3417
3375/* Free a Lisp_Save_Value object. Do not use this function 3418/* Free a Lisp_Save_Value object. Do not use this function
3376 if SAVE contains pointer other than returned by xmalloc. */ 3419 if SAVE contains pointer other than returned by xmalloc. */
3377 3420
3378void 3421static void
3379free_save_value (Lisp_Object save) 3422free_save_value (Lisp_Object save)
3380{ 3423{
3381 xfree (XSAVE_POINTER (save)); 3424 xfree (XSAVE_POINTER (save, 0));
3382 free_misc (save); 3425 free_misc (save);
3383} 3426}
3384 3427