From a48726ebae2f44ed15b97cb72bc7eca199d8de47 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 23 Jul 2019 11:18:16 -0700 Subject: [PATCH] Merge pdumper.c and alloc.c builtin symbol tests * src/alloc.c (c_symbol_p): Move from here ... * src/lisp.h (c_symbol_p): ... to here, and make it more portable to hypothetical platforms where pointers are wider than ptrdiff_t. * src/pdumper.c (dump_builtin_symbol_p): Use c_symbol_p. --- src/alloc.c | 9 --------- src/lisp.h | 14 ++++++++++++++ src/pdumper.c | 7 +------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index f256ff71b07..c17bdb719a9 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4964,15 +4964,6 @@ flush_stack_call_func (void (*func) (void *arg), void *arg) eassert (current_thread == self); } -static bool -c_symbol_p (struct Lisp_Symbol *sym) -{ - char *lispsym_ptr = (char *) lispsym; - char *sym_ptr = (char *) sym; - ptrdiff_t lispsym_offset = sym_ptr - lispsym_ptr; - return 0 <= lispsym_offset && lispsym_offset < sizeof lispsym; -} - /* Determine whether it is safe to access memory at address P. */ static int valid_pointer_p (void *p) diff --git a/src/lisp.h b/src/lisp.h index e96fcfe94d3..17495777378 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1024,6 +1024,20 @@ builtin_lisp_symbol (int index) return make_lisp_symbol (&lispsym[index]); } +INLINE bool +c_symbol_p (struct Lisp_Symbol *sym) +{ + char *bp = (char *) lispsym; + char *sp = (char *) sym; + if (PTRDIFF_MAX < INTPTR_MAX) + return bp <= sp && sp < bp + sizeof lispsym; + else + { + ptrdiff_t offset = sp - bp; + return 0 <= offset && offset < sizeof lispsym; + } +} + INLINE void (CHECK_SYMBOL) (Lisp_Object x) { diff --git a/src/pdumper.c b/src/pdumper.c index 84147353e85..ddf44a53f86 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -719,12 +719,7 @@ emacs_offset (const void *emacs_ptr) static bool dump_builtin_symbol_p (Lisp_Object object) { - if (!SYMBOLP (object)) - return false; - char *bp = (char *) lispsym; - struct Lisp_Symbol *s = XSYMBOL (object); - char *sp = (char *) s; - return bp <= sp && sp < bp + sizeof (lispsym); + return SYMBOLP (object) && c_symbol_p (XSYMBOL (object)); } /* Return whether OBJECT has the same bit pattern in all Emacs -- 2.39.2