aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorDmitry Antipov2013-01-15 12:38:07 +0400
committerDmitry Antipov2013-01-15 12:38:07 +0400
commit1b971ac155006504b6b1c2688199747f976723af (patch)
tree0e5f4dc8243cec3591ce8ee659b5babc0a6639f9 /src/alloc.c
parentcb9c0a53bc4a6d67f10d4674472b2884a71852c8 (diff)
downloademacs-1b971ac155006504b6b1c2688199747f976723af.tar.gz
emacs-1b971ac155006504b6b1c2688199747f976723af.zip
Some convenient bits to deal with Lisp_Save_Values.
* lisp.h (XSAVE_OBJECT): New macro to extract saved objects. (allocate_misc): Remove prototype. (format_save_value): New prototype. * alloc.c (allocate_misc): Revert back to static. (format_save_value): New function to build Lisp_Save_Value object with the specified internal structure. (make_save_value): Reimplement using format_save_value. * editfns.c (save_excursion_save): Use format_save_value. (save_excursion_restore): Use XSAVE_OBJECT.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c68
1 files changed, 55 insertions, 13 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 3f1ccc82a58..e1cb97163ce 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3302,7 +3302,7 @@ static union Lisp_Misc *marker_free_list;
3302 3302
3303/* Return a newly allocated Lisp_Misc object of specified TYPE. */ 3303/* Return a newly allocated Lisp_Misc object of specified TYPE. */
3304 3304
3305Lisp_Object 3305static Lisp_Object
3306allocate_misc (enum Lisp_Misc_Type type) 3306allocate_misc (enum Lisp_Misc_Type type)
3307{ 3307{
3308 Lisp_Object val; 3308 Lisp_Object val;
@@ -3350,6 +3350,59 @@ free_misc (Lisp_Object misc)
3350 total_free_markers++; 3350 total_free_markers++;
3351} 3351}
3352 3352
3353/* Return a Lisp_Save_Value object with the data saved according to
3354 FMT. Format specifiers are `i' for an integer, `p' for a pointer
3355 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3356
3357Lisp_Object
3358format_save_value (const char *fmt, ...)
3359{
3360 va_list ap;
3361 int len = strlen (fmt);
3362 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3363 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3364
3365 eassert (0 < len && len < 5);
3366 va_start (ap, fmt);
3367
3368#define INITX(index) \
3369 do { \
3370 if (len <= index) \
3371 p->type ## index = SAVE_UNUSED; \
3372 else \
3373 { \
3374 if (fmt[index] == 'i') \
3375 { \
3376 p->type ## index = SAVE_INTEGER; \
3377 p->data[index].integer = va_arg (ap, ptrdiff_t); \
3378 } \
3379 else if (fmt[index] == 'p') \
3380 { \
3381 p->type ## index = SAVE_POINTER; \
3382 p->data[index].pointer = va_arg (ap, void *); \
3383 } \
3384 else if (fmt[index] == 'o') \
3385 { \
3386 p->type ## index = SAVE_OBJECT; \
3387 p->data[index].object = va_arg (ap, Lisp_Object); \
3388 } \
3389 else \
3390 emacs_abort (); \
3391 } \
3392 } while (0)
3393
3394 INITX (0);
3395 INITX (1);
3396 INITX (2);
3397 INITX (3);
3398
3399#undef INITX
3400
3401 va_end (ap);
3402 p->area = 0;
3403 return val;
3404}
3405
3353/* Return a Lisp_Save_Value object containing POINTER and INTEGER. 3406/* Return a Lisp_Save_Value object containing POINTER and INTEGER.
3354 Most code should use this to package C integers and pointers 3407 Most code should use this to package C integers and pointers
3355 to call record_unwind_protect. The unwind function can get the 3408 to call record_unwind_protect. The unwind function can get the
@@ -3358,18 +3411,7 @@ free_misc (Lisp_Object misc)
3358Lisp_Object 3411Lisp_Object
3359make_save_value (void *pointer, ptrdiff_t integer) 3412make_save_value (void *pointer, ptrdiff_t integer)
3360{ 3413{
3361 register Lisp_Object val; 3414 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} 3415}
3374 3416
3375/* Free a Lisp_Save_Value object. Do not use this function 3417/* Free a Lisp_Save_Value object. Do not use this function