Take XPNTR private

* src/alloc.c (PURE_POINTER_P): Remove.
All uses replaced with PURE_P.
(XPNTR_OR_SYMBOL_OFFSET): New function.
(XPNTR): Move here from lisp.h.
Reimplement in terms of XPNTR_OR_SYMBOL_OFFSET.
(mark_maybe_object, valid_lisp_object_p, survives_gc_p):
Remove unnecessary cast.
(purecopy): Use XPNTR_OR_SYMBOL_OFFSET instead of XPNTR,
to avoid an unnecessary runtime test for symbols.
* src/lisp.h (lisp_h_XPNTR, XPNTR): Remove, moving XPNTR to alloc.c.
Only alloc.c needs XPNTR now.
This commit is contained in:
Paul Eggert 2015-10-13 23:09:43 -07:00
parent 3fa424ca48
commit 2cc412cdc2
2 changed files with 35 additions and 30 deletions

View file

@ -179,11 +179,6 @@ static ptrdiff_t pure_size;
static ptrdiff_t pure_bytes_used_before_overflow;
/* True if P points into pure space. */
#define PURE_POINTER_P(P) \
((uintptr_t) (P) - (uintptr_t) purebeg <= pure_size)
/* Index in pure at which next pure Lisp object will be allocated.. */
static ptrdiff_t pure_bytes_used_lisp;
@ -406,6 +401,28 @@ ALIGN (void *ptr, int alignment)
return (void *) ROUNDUP ((uintptr_t) ptr, alignment);
}
/* Extract the pointer hidden within A, if A is not a symbol.
If A is a symbol, extract the hidden pointer's offset from lispsym,
converted to void *. */
static void *
XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a)
{
intptr_t i = USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK;
return (void *) i;
}
/* Extract the pointer hidden within A. */
static void *
XPNTR (Lisp_Object a)
{
void *p = XPNTR_OR_SYMBOL_OFFSET (a);
if (SYMBOLP (a))
p = (intptr_t) p + (char *) lispsym;
return p;
}
static void
XFLOAT_INIT (Lisp_Object f, double n)
{
@ -1587,9 +1604,7 @@ string_bytes (struct Lisp_String *s)
ptrdiff_t nbytes =
(s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
if (!PURE_POINTER_P (s)
&& s->data
&& nbytes != SDATA_NBYTES (SDATA_OF_STRING (s)))
if (!PURE_P (s) && s->data && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s)))
emacs_abort ();
return nbytes;
}
@ -4463,9 +4478,6 @@ live_buffer_p (struct mem_node *m, void *p)
static void
mark_maybe_object (Lisp_Object obj)
{
void *po;
struct mem_node *m;
#if USE_VALGRIND
if (valgrind_p)
VALGRIND_MAKE_MEM_DEFINED (&obj, sizeof (obj));
@ -4474,12 +4486,12 @@ mark_maybe_object (Lisp_Object obj)
if (INTEGERP (obj))
return;
po = (void *) XPNTR (obj);
m = mem_find (po);
void *po = XPNTR (obj);
struct mem_node *m = mem_find (po);
if (m != MEM_NIL)
{
bool mark_p = 0;
bool mark_p = false;
switch (XTYPE (obj))
{
@ -4860,14 +4872,11 @@ valid_pointer_p (void *p)
int
valid_lisp_object_p (Lisp_Object obj)
{
void *p;
struct mem_node *m;
if (INTEGERP (obj))
return 1;
p = (void *) XPNTR (obj);
if (PURE_POINTER_P (p))
void *p = XPNTR (obj);
if (PURE_P (p))
return 1;
if (SYMBOLP (obj) && c_symbol_p (p))
@ -4876,7 +4885,7 @@ valid_lisp_object_p (Lisp_Object obj)
if (p == &buffer_defaults || p == &buffer_local_symbols)
return 2;
m = mem_find (p);
struct mem_node *m = mem_find (p);
if (m == MEM_NIL)
{
@ -5155,7 +5164,9 @@ Does not copy symbols. Copies strings without text properties. */)
static Lisp_Object
purecopy (Lisp_Object obj)
{
if (PURE_POINTER_P (XPNTR (obj)) || INTEGERP (obj) || SUBRP (obj))
if (INTEGERP (obj)
|| (! SYMBOLP (obj) && PURE_P (XPNTR_OR_SYMBOL_OFFSET (obj)))
|| SUBRP (obj))
return obj; /* Already pure. */
if (STRINGP (obj) && XSTRING (obj)->intervals)
@ -5976,7 +5987,7 @@ mark_object (Lisp_Object arg)
loop:
po = XPNTR (obj);
if (PURE_POINTER_P (po))
if (PURE_P (po))
return;
last_marked[last_marked_index++] = obj;
@ -6213,7 +6224,7 @@ mark_object (Lisp_Object arg)
break;
default: emacs_abort ();
}
if (!PURE_POINTER_P (XSTRING (ptr->name)))
if (!PURE_P (XSTRING (ptr->name)))
MARK_STRING (XSTRING (ptr->name));
MARK_INTERVAL_TREE (string_intervals (ptr->name));
/* Inner loop to mark next symbol in this bucket, if any. */
@ -6360,7 +6371,7 @@ survives_gc_p (Lisp_Object obj)
emacs_abort ();
}
return survives_p || PURE_POINTER_P ((void *) XPNTR (obj));
return survives_p || PURE_P (XPNTR (obj));
}

View file

@ -351,8 +351,6 @@ error !;
#define lisp_h_XCONS(a) \
(eassert (CONSP (a)), (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
#define lisp_h_XHASH(a) XUINT (a)
#define lisp_h_XPNTR(a) \
(SYMBOLP (a) ? XSYMBOL (a) : (void *) ((intptr_t) (XLI (a) & VALMASK)))
#ifndef GC_CHECK_CONS_LIST
# define lisp_h_check_cons_list() ((void) 0)
#endif
@ -397,7 +395,6 @@ error !;
# define XCDR(c) lisp_h_XCDR (c)
# define XCONS(a) lisp_h_XCONS (a)
# define XHASH(a) lisp_h_XHASH (a)
# define XPNTR(a) lisp_h_XPNTR (a)
# ifndef GC_CHECK_CONS_LIST
# define check_cons_list() lisp_h_check_cons_list ()
# endif
@ -916,9 +913,6 @@ XUNTAG (Lisp_Object a, int type)
#endif /* ! USE_LSB_TAG */
/* Extract the pointer hidden within A. */
LISP_MACRO_DEFUN (XPNTR, void *, (Lisp_Object a), (a))
/* Extract A's value as an unsigned integer. */
INLINE EMACS_UINT
XUINT (Lisp_Object a)