aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2013-03-21 13:56:22 -0700
committerPaul Eggert2013-03-21 13:56:22 -0700
commit7b1123d824e51d40496c242e7a7f173de8936100 (patch)
tree0aaafb8bc660f02c35516227bfde2fef344d318a /src/alloc.c
parentd6723bf7e58e17c889e354bc429f3f134281953a (diff)
downloademacs-7b1123d824e51d40496c242e7a7f173de8936100.tar.gz
emacs-7b1123d824e51d40496c242e7a7f173de8936100.zip
Use functions and constants to manipulate Lisp_Save_Value objects.
This replaces code that used macros and strings and token-pasting. The change makes the C source a bit easier to follow, and shrinks the Emacs executable a bit. * alloc.c: Verify some properties of Lisp_Save_Value's representation. (make_save_value): Change 1st arg from string to enum. All callers changed. (INTX): Remove. (mark_object): Use if, not #if, for GC_MARK_STACK. * lisp.h (SAVE_VALUEP, XSAVE_VALUE, XSAVE_POINTER, XSAVE_INTEGER) (XSAVE_OBJECT): Now functions, not macros. (STRING_BYTES_BOUND): Now just a macro, not a constant too; the constant was never used. (SAVE_SLOT_BITS, SAVE_VALUE_SLOTS, SAVE_TYPE_BITS, SAVE_TYPE_INT_INT) (SAVE_TYPE_INT_INT_INT, SAVE_TYPE_OBJ_OBJ, SAVE_TYPE_OBJ_OBJ_OBJ) (SAVE_TYPE_OBJ_OBJ_OBJ_OBJ, SAVE_TYPE_PTR_INT, SAVE_TYPE_PTR_OBJ) (SAVE_TYPE_PTR_PTR, SAVE_TYPE_PTR_PTR_OBJ, SAVE_TYPE_MEMORY): New constants. (struct Lisp_Save_Value): Replace members area, type0, type1, type2, type3 with a single member save_type. All uses changed. (save_type, set_save_pointer, set_save_integer): New functions. * print.c (PRINTX): Remove.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c95
1 files changed, 40 insertions, 55 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 39379bc3bd7..4245b3069fa 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3326,56 +3326,50 @@ free_misc (Lisp_Object misc)
3326 total_free_markers++; 3326 total_free_markers++;
3327} 3327}
3328 3328
3329/* Verify properties of Lisp_Save_Value's representation
3330 that are assumed here and elsewhere. */
3331
3332verify (SAVE_UNUSED == 0);
3333verify ((SAVE_INTEGER | SAVE_POINTER | SAVE_OBJECT) >> SAVE_SLOT_BITS == 0);
3334
3329/* 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
3330 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. */
3331 and `o' for Lisp_Object. Up to 4 objects can be specified. */
3332 3337
3333Lisp_Object 3338Lisp_Object
3334make_save_value (const char *fmt, ...) 3339make_save_value (enum Lisp_Save_Type save_type, ...)
3335{ 3340{
3336 va_list ap; 3341 va_list ap;
3337 int len = strlen (fmt); 3342 int i;
3338 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3343 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3339 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3344 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3340 3345
3341 eassert (0 < len && len < 5); 3346 eassert (0 < save_type
3342 va_start (ap, fmt); 3347 && (save_type < 1 << (SAVE_TYPE_BITS - 1)
3343 3348 || save_type == SAVE_TYPE_MEMORY));
3344#define INITX(index) \ 3349 p->save_type = save_type;
3345 do { \ 3350 va_start (ap, save_type);
3346 if (len <= index) \ 3351 save_type &= ~ (1 << (SAVE_TYPE_BITS - 1));
3347 p->type ## index = SAVE_UNUSED; \ 3352
3348 else \ 3353 for (i = 0; save_type; i++, save_type >>= SAVE_SLOT_BITS)
3349 { \ 3354 switch (save_type & ((1 << SAVE_SLOT_BITS) - 1))
3350 if (fmt[index] == 'i') \ 3355 {
3351 { \ 3356 case SAVE_POINTER:
3352 p->type ## index = SAVE_INTEGER; \ 3357 p->data[i].pointer = va_arg (ap, void *);
3353 p->data[index].integer = va_arg (ap, ptrdiff_t); \ 3358 break;
3354 } \
3355 else if (fmt[index] == 'p') \
3356 { \
3357 p->type ## index = SAVE_POINTER; \
3358 p->data[index].pointer = va_arg (ap, void *); \
3359 } \
3360 else if (fmt[index] == 'o') \
3361 { \
3362 p->type ## index = SAVE_OBJECT; \
3363 p->data[index].object = va_arg (ap, Lisp_Object); \
3364 } \
3365 else \
3366 emacs_abort (); \
3367 } \
3368 } while (0)
3369 3359
3370 INITX (0); 3360 case SAVE_INTEGER:
3371 INITX (1); 3361 p->data[i].integer = va_arg (ap, ptrdiff_t);
3372 INITX (2); 3362 break;
3373 INITX (3);
3374 3363
3375#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 }
3376 3371
3377 va_end (ap); 3372 va_end (ap);
3378 p->area = 0;
3379 return val; 3373 return val;
3380} 3374}
3381 3375
@@ -3386,11 +3380,8 @@ make_save_pointer (void *pointer)
3386{ 3380{
3387 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value); 3381 Lisp_Object val = allocate_misc (Lisp_Misc_Save_Value);
3388 struct Lisp_Save_Value *p = XSAVE_VALUE (val); 3382 struct Lisp_Save_Value *p = XSAVE_VALUE (val);
3389 3383 p->save_type = SAVE_POINTER;
3390 p->area = 0;
3391 p->type0 = SAVE_POINTER;
3392 p->data[0].pointer = pointer; 3384 p->data[0].pointer = pointer;
3393 p->type1 = p->type2 = p->type3 = SAVE_UNUSED;
3394 return val; 3385 return val;
3395} 3386}
3396 3387
@@ -5958,12 +5949,11 @@ mark_object (Lisp_Object arg)
5958 case Lisp_Misc_Save_Value: 5949 case Lisp_Misc_Save_Value:
5959 XMISCANY (obj)->gcmarkbit = 1; 5950 XMISCANY (obj)->gcmarkbit = 1;
5960 { 5951 {
5961 register struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj); 5952 struct Lisp_Save_Value *ptr = XSAVE_VALUE (obj);
5962 /* If `area' is nonzero, `data[0].pointer' is the address 5953 /* If `save_type' is zero, `data[0].pointer' is the address
5963 of a memory area containing `data[1].integer' potential 5954 of a memory area containing `data[1].integer' potential
5964 Lisp_Objects. */ 5955 Lisp_Objects. */
5965#if GC_MARK_STACK 5956 if (GC_MARK_STACK && ptr->save_type == SAVE_TYPE_MEMORY)
5966 if (ptr->area)
5967 { 5957 {
5968 Lisp_Object *p = ptr->data[0].pointer; 5958 Lisp_Object *p = ptr->data[0].pointer;
5969 ptrdiff_t nelt; 5959 ptrdiff_t nelt;
@@ -5971,17 +5961,12 @@ mark_object (Lisp_Object arg)
5971 mark_maybe_object (*p); 5961 mark_maybe_object (*p);
5972 } 5962 }
5973 else 5963 else
5974#endif /* GC_MARK_STACK */
5975 { 5964 {
5976 /* Find Lisp_Objects in `data[N]' slots and mark them. */ 5965 /* Find Lisp_Objects in `data[N]' slots and mark them. */
5977 if (ptr->type0 == SAVE_OBJECT) 5966 int i;
5978 mark_object (ptr->data[0].object); 5967 for (i = 0; i < SAVE_VALUE_SLOTS; i++)
5979 if (ptr->type1 == SAVE_OBJECT) 5968 if (save_type (ptr, i) == SAVE_OBJECT)
5980 mark_object (ptr->data[1].object); 5969 mark_object (ptr->data[i].object);
5981 if (ptr->type2 == SAVE_OBJECT)
5982 mark_object (ptr->data[2].object);
5983 if (ptr->type3 == SAVE_OBJECT)
5984 mark_object (ptr->data[3].object);
5985 } 5970 }
5986 } 5971 }
5987 break; 5972 break;