From ad013ba63134d4fe6470665abf2f9e33a595848a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 18 Dec 2014 18:12:01 -0800 Subject: [PATCH] Minor cleanups for Lisp objects and symbols * alloc.c (next_vector, set_next_vector): * lisp.h (lisp_h_INTEGERP, make_number, XFASTINT, make_natnum): (lisp_h_make_number) [USE_LSB_TAG]: Use Lisp_Int0 instead of the mystery constant 0. * alloc.c (mark_object): Always set and use po; that's simpler. (CHECK_LIVE, CHECK_ALLOCATED_AND_LIVE): Properly parenthesize definientia. * bidi.c (bidi_initialize): * buffer.c (init_buffer_once): * nsfns.m (syms_of_nsfns): * nsmenu.m (syms_of_nsmenu): * nsselect.m (syms_of_nsselect): Prefer DEFSYM to defining by hand. * data.c: Fix too-long line. * lisp.h (DECLARE_GDB_SYM): New macro. (DEFINE_GDB_SYMBOL_BEGIN): Use it. (DEFINE_GDB_SYMBOL_BEGIN, DEFINE_GDB_SYMBOL_END) [!MAIN_PROGRAM]: Declare the symbol, so it's visible to everywhere lisp.h is included. Move forward decls as far forward as they can go, to allow future changes to use them. --- src/ChangeLog | 24 ++++++++ src/alloc.c | 15 +++-- src/bidi.c | 6 +- src/buffer.c | 12 ++-- src/data.c | 3 +- src/lisp.h | 156 ++++++++++++++++++++++++++----------------------- src/nsfns.m | 3 +- src/nsmenu.m | 3 +- src/nsselect.m | 8 +-- 9 files changed, 128 insertions(+), 102 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 359dca97f48..5bab023fd86 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,27 @@ +2014-12-19 Paul Eggert + + Minor cleanups for Lisp objects and symbols + * alloc.c (next_vector, set_next_vector): + * lisp.h (lisp_h_INTEGERP, make_number, XFASTINT, make_natnum): + (lisp_h_make_number) [USE_LSB_TAG]: + Use Lisp_Int0 instead of the mystery constant 0. + * alloc.c (mark_object): Always set and use po; that's simpler. + (CHECK_LIVE, CHECK_ALLOCATED_AND_LIVE): + Properly parenthesize definientia. + * bidi.c (bidi_initialize): + * buffer.c (init_buffer_once): + * nsfns.m (syms_of_nsfns): + * nsmenu.m (syms_of_nsmenu): + * nsselect.m (syms_of_nsselect): + Prefer DEFSYM to defining by hand. + * data.c: Fix too-long line. + * lisp.h (DECLARE_GDB_SYM): New macro. + (DEFINE_GDB_SYMBOL_BEGIN): Use it. + (DEFINE_GDB_SYMBOL_BEGIN, DEFINE_GDB_SYMBOL_END) [!MAIN_PROGRAM]: + Declare the symbol, so it's visible to everywhere lisp.h is included. + Move forward decls as far forward as they can go, + to allow future changes to use them. + 2014-12-18 Paul Eggert * gnutls.c: Include gnutls.h. diff --git a/src/alloc.c b/src/alloc.c index 43287457c8d..eada96c0c10 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2719,13 +2719,13 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0, static struct Lisp_Vector * next_vector (struct Lisp_Vector *v) { - return XUNTAG (v->contents[0], 0); + return XUNTAG (v->contents[0], Lisp_Int0); } static void set_next_vector (struct Lisp_Vector *v, struct Lisp_Vector *p) { - v->contents[0] = make_lisp_ptr (p, 0); + v->contents[0] = make_lisp_ptr (p, Lisp_Int0); } /* This value is balanced well enough to avoid too much internal overhead @@ -6155,15 +6155,16 @@ void mark_object (Lisp_Object arg) { register Lisp_Object obj = arg; -#ifdef GC_CHECK_MARKED_OBJECTS void *po; +#ifdef GC_CHECK_MARKED_OBJECTS struct mem_node *m; #endif ptrdiff_t cdr_count = 0; loop: - if (PURE_POINTER_P (XPNTR (obj))) + po = XPNTR (obj); + if (PURE_POINTER_P (po)) return; last_marked[last_marked_index++] = obj; @@ -6175,8 +6176,6 @@ mark_object (Lisp_Object arg) by ~80%, and requires compilation with GC_MARK_STACK != 0. */ #ifdef GC_CHECK_MARKED_OBJECTS - po = (void *) XPNTR (obj); - /* Check that the object pointed to by PO is known to be a Lisp structure allocated from the heap. */ #define CHECK_ALLOCATED() \ @@ -6203,8 +6202,8 @@ mark_object (Lisp_Object arg) #else /* not GC_CHECK_MARKED_OBJECTS */ -#define CHECK_LIVE(LIVEP) (void) 0 -#define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0 +#define CHECK_LIVE(LIVEP) ((void) 0) +#define CHECK_ALLOCATED_AND_LIVE(LIVEP) ((void) 0) #endif /* not GC_CHECK_MARKED_OBJECTS */ diff --git a/src/bidi.c b/src/bidi.c index 0d291fcb033..45385452755 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -1108,14 +1108,12 @@ bidi_initialize (void) emacs_abort (); staticpro (&bidi_brackets_table); - Qparagraph_start = intern ("paragraph-start"); - staticpro (&Qparagraph_start); + DEFSYM (Qparagraph_start, "paragraph-start"); paragraph_start_re = Fsymbol_value (Qparagraph_start); if (!STRINGP (paragraph_start_re)) paragraph_start_re = build_string ("\f\\|[ \t]*$"); staticpro (¶graph_start_re); - Qparagraph_separate = intern ("paragraph-separate"); - staticpro (&Qparagraph_separate); + DEFSYM (Qparagraph_separate, "paragraph-separate"); paragraph_separate_re = Fsymbol_value (Qparagraph_separate); if (!STRINGP (paragraph_separate_re)) paragraph_separate_re = build_string ("[ \t\f]*$"); diff --git a/src/buffer.c b/src/buffer.c index 9bdbfb830fd..ba3245fa5ad 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5224,16 +5224,14 @@ init_buffer_once (void) QSFundamental = build_pure_c_string ("Fundamental"); - Qfundamental_mode = intern_c_string ("fundamental-mode"); + DEFSYM (Qfundamental_mode, "fundamental-mode"); bset_major_mode (&buffer_defaults, Qfundamental_mode); - Qmode_class = intern_c_string ("mode-class"); + DEFSYM (Qmode_class, "mode-class"); + DEFSYM (Qprotected_field, "protected-field"); - Qprotected_field = intern_c_string ("protected-field"); - - Qpermanent_local = intern_c_string ("permanent-local"); - - Qkill_buffer_hook = intern_c_string ("kill-buffer-hook"); + DEFSYM (Qpermanent_local, "permanent-local"); + DEFSYM (Qkill_buffer_hook, "kill-buffer-hook"); Fput (Qkill_buffer_hook, Qpermanent_local, Qt); /* super-magic invisible buffer */ diff --git a/src/data.c b/src/data.c index b48dbbebabc..7151d220b05 100644 --- a/src/data.c +++ b/src/data.c @@ -89,7 +89,8 @@ static Lisp_Object Qdefun; Lisp_Object Qinteractive_form; static Lisp_Object Qdefalias_fset_function; -static void swap_in_symval_forwarding (struct Lisp_Symbol *, struct Lisp_Buffer_Local_Value *); +static void swap_in_symval_forwarding (struct Lisp_Symbol *, + struct Lisp_Buffer_Local_Value *); static bool BOOLFWDP (union Lisp_Fwd *a) diff --git a/src/lisp.h b/src/lisp.h index 37172c6b049..3a6d247f6d5 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -44,12 +44,13 @@ INLINE_HEADER_BEGIN definitions or enums visible to the debugger. It's used for symbols that .gdbinit needs. */ +#define DECLARE_GDB_SYM(type, id) type const id EXTERNALLY_VISIBLE #ifdef MAIN_PROGRAM -# define DEFINE_GDB_SYMBOL_BEGIN(type, id) type const id EXTERNALLY_VISIBLE +# define DEFINE_GDB_SYMBOL_BEGIN(type, id) DECLARE_GDB_SYM (type, id) # define DEFINE_GDB_SYMBOL_END(id) = id; #else -# define DEFINE_GDB_SYMBOL_BEGIN(type, id) -# define DEFINE_GDB_SYMBOL_END(val) +# define DEFINE_GDB_SYMBOL_BEGIN(type, id) extern DECLARE_GDB_SYM (type, id) +# define DEFINE_GDB_SYMBOL_END(val) ; #endif /* The ubiquitous max and min macros. */ @@ -337,7 +338,7 @@ error !; #define lisp_h_CONSP(x) (XTYPE (x) == Lisp_Cons) #define lisp_h_EQ(x, y) (XLI (x) == XLI (y)) #define lisp_h_FLOATP(x) (XTYPE (x) == Lisp_Float) -#define lisp_h_INTEGERP(x) ((XTYPE (x) & ~Lisp_Int1) == 0) +#define lisp_h_INTEGERP(x) ((XTYPE (x) & (Lisp_Int0 | ~Lisp_Int1)) == Lisp_Int0) #define lisp_h_MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker) #define lisp_h_MISCP(x) (XTYPE (x) == Lisp_Misc) #define lisp_h_NILP(x) EQ (x, Qnil) @@ -361,7 +362,7 @@ error !; #endif #if USE_LSB_TAG # define lisp_h_make_number(n) \ - XIL ((EMACS_INT) ((EMACS_UINT) (n) << INTTYPEBITS)) + XIL ((EMACS_INT) (((EMACS_UINT) (n) << INTTYPEBITS) + Lisp_Int0)) # define lisp_h_XFASTINT(a) XINT (a) # define lisp_h_XINT(a) (XLI (a) >> INTTYPEBITS) # define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK)) @@ -573,7 +574,73 @@ typedef EMACS_INT Lisp_Object; #define LISP_INITIALLY_ZERO 0 enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = false }; #endif /* CHECK_LISP_OBJECT_TYPE */ + +/* Forward declarations. */ + +/* Defined in this file. */ +union Lisp_Fwd; +INLINE bool BOOL_VECTOR_P (Lisp_Object); +INLINE bool BUFFER_OBJFWDP (union Lisp_Fwd *); +INLINE bool BUFFERP (Lisp_Object); +INLINE bool CHAR_TABLE_P (Lisp_Object); +INLINE Lisp_Object CHAR_TABLE_REF_ASCII (Lisp_Object, ptrdiff_t); +INLINE bool (CONSP) (Lisp_Object); +INLINE bool (FLOATP) (Lisp_Object); +INLINE bool functionp (Lisp_Object); +INLINE bool (INTEGERP) (Lisp_Object); +INLINE bool (MARKERP) (Lisp_Object); +INLINE bool (MISCP) (Lisp_Object); +INLINE bool (NILP) (Lisp_Object); +INLINE bool OVERLAYP (Lisp_Object); +INLINE bool PROCESSP (Lisp_Object); +INLINE bool PSEUDOVECTORP (Lisp_Object, int); +INLINE bool SAVE_VALUEP (Lisp_Object); +INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, + Lisp_Object); +INLINE bool STRINGP (Lisp_Object); +INLINE bool SUB_CHAR_TABLE_P (Lisp_Object); +INLINE bool SUBRP (Lisp_Object); +INLINE bool (SYMBOLP) (Lisp_Object); +INLINE bool (VECTORLIKEP) (Lisp_Object); +INLINE bool WINDOWP (Lisp_Object); +INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object); + +/* Defined in chartab.c. */ +extern Lisp_Object char_table_ref (Lisp_Object, int); +extern void char_table_set (Lisp_Object, int, Lisp_Object); +/* Defined in data.c. */ +extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p; +extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil; +extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qt, Qvectorp; +extern Lisp_Object Qbool_vector_p; +extern Lisp_Object Qvector_or_char_table_p, Qwholenump; +extern Lisp_Object Qwindow; +extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object); +extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object); + +/* Defined in emacs.c. */ +extern bool might_dump; +/* True means Emacs has already been initialized. + Used during startup to detect startup of dumped Emacs. */ +extern bool initialized; + +/* Defined in eval.c. */ +extern Lisp_Object Qautoload; + +/* Defined in floatfns.c. */ +extern double extract_float (Lisp_Object); + +/* Defined in process.c. */ +extern Lisp_Object Qprocessp; + +/* Defined in window.c. */ +extern Lisp_Object Qwindowp; + +/* Defined in xdisp.c. */ +extern Lisp_Object Qimage; +extern Lisp_Object Qfontification_functions; + /* Convert a Lisp_Object to the corresponding EMACS_INT and vice versa. At the machine level, these operations are no-ops. */ LISP_MACRO_DEFUN (XLI, EMACS_INT, (Lisp_Object o), (o)) @@ -673,13 +740,18 @@ LISP_MACRO_DEFUN (XUNTAG, void *, (Lisp_Object a, int type), (a, type)) INLINE Lisp_Object make_number (EMACS_INT n) { + EMACS_INT int0 = Lisp_Int0; if (USE_LSB_TAG) { EMACS_UINT u = n; n = u << INTTYPEBITS; + n += int0; } else - n &= INTMASK; + { + n &= INTMASK; + n += (int0 << VALBITS); + } return XIL (n); } @@ -702,7 +774,8 @@ XINT (Lisp_Object a) INLINE EMACS_INT XFASTINT (Lisp_Object a) { - EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a); + EMACS_INT int0 = Lisp_Int0; + EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS); eassert (0 <= n); return n; } @@ -747,7 +820,8 @@ INLINE Lisp_Object make_natnum (EMACS_INT n) { eassert (0 <= n && n <= MOST_POSITIVE_FIXNUM); - return USE_LSB_TAG ? make_number (n) : XIL (n); + EMACS_INT int0 = Lisp_Int0; + return USE_LSB_TAG ? make_number (n) : XIL (n + (int0 << VALBITS)); } /* Return true if X and Y are the same object. */ @@ -766,72 +840,6 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper) return num < lower ? lower : num <= upper ? num : upper; } -/* Forward declarations. */ - -/* Defined in this file. */ -union Lisp_Fwd; -INLINE bool BOOL_VECTOR_P (Lisp_Object); -INLINE bool BUFFER_OBJFWDP (union Lisp_Fwd *); -INLINE bool BUFFERP (Lisp_Object); -INLINE bool CHAR_TABLE_P (Lisp_Object); -INLINE Lisp_Object CHAR_TABLE_REF_ASCII (Lisp_Object, ptrdiff_t); -INLINE bool (CONSP) (Lisp_Object); -INLINE bool (FLOATP) (Lisp_Object); -INLINE bool functionp (Lisp_Object); -INLINE bool (INTEGERP) (Lisp_Object); -INLINE bool (MARKERP) (Lisp_Object); -INLINE bool (MISCP) (Lisp_Object); -INLINE bool (NILP) (Lisp_Object); -INLINE bool OVERLAYP (Lisp_Object); -INLINE bool PROCESSP (Lisp_Object); -INLINE bool PSEUDOVECTORP (Lisp_Object, int); -INLINE bool SAVE_VALUEP (Lisp_Object); -INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, - Lisp_Object); -INLINE bool STRINGP (Lisp_Object); -INLINE bool SUB_CHAR_TABLE_P (Lisp_Object); -INLINE bool SUBRP (Lisp_Object); -INLINE bool (SYMBOLP) (Lisp_Object); -INLINE bool (VECTORLIKEP) (Lisp_Object); -INLINE bool WINDOWP (Lisp_Object); -INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object); - -/* Defined in chartab.c. */ -extern Lisp_Object char_table_ref (Lisp_Object, int); -extern void char_table_set (Lisp_Object, int, Lisp_Object); - -/* Defined in data.c. */ -extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p; -extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil; -extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qt, Qvectorp; -extern Lisp_Object Qbool_vector_p; -extern Lisp_Object Qvector_or_char_table_p, Qwholenump; -extern Lisp_Object Qwindow; -extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object); -extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object); - -/* Defined in emacs.c. */ -extern bool might_dump; -/* True means Emacs has already been initialized. - Used during startup to detect startup of dumped Emacs. */ -extern bool initialized; - -/* Defined in eval.c. */ -extern Lisp_Object Qautoload; - -/* Defined in floatfns.c. */ -extern double extract_float (Lisp_Object); - -/* Defined in process.c. */ -extern Lisp_Object Qprocessp; - -/* Defined in window.c. */ -extern Lisp_Object Qwindowp; - -/* Defined in xdisp.c. */ -extern Lisp_Object Qimage; -extern Lisp_Object Qfontification_functions; - /* Extract a value or address from a Lisp_Object. */ diff --git a/src/nsfns.m b/src/nsfns.m index a5ff6346d74..578ec12588c 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -2971,8 +2971,7 @@ handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent) void syms_of_nsfns (void) { - Qfontsize = intern_c_string ("fontsize"); - staticpro (&Qfontsize); + DEFSYM (Qfontsize, "fontsize"); DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist, doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames. diff --git a/src/nsmenu.m b/src/nsmenu.m index 0e8b68b38f1..ffd1e4db78a 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1876,6 +1876,5 @@ syms_of_nsmenu (void) defsubr (&Sns_reset_menu); defsubr (&Smenu_or_popup_active_p); - Qdebug_on_next_call = intern_c_string ("debug-on-next-call"); - staticpro (&Qdebug_on_next_call); + DEFSYM (Qdebug_on_next_call, "debug-on-next-call"); } diff --git a/src/nsselect.m b/src/nsselect.m index bcf2ac1fe63..3b33a97ca73 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -504,10 +504,10 @@ nxatoms_of_nsselect (void) void syms_of_nsselect (void) { - QCLIPBOARD = intern_c_string ("CLIPBOARD"); staticpro (&QCLIPBOARD); - QSECONDARY = intern_c_string ("SECONDARY"); staticpro (&QSECONDARY); - QTEXT = intern_c_string ("TEXT"); staticpro (&QTEXT); - QFILE_NAME = intern_c_string ("FILE_NAME"); staticpro (&QFILE_NAME); + DEFSYM (QCLIPBOARD, "CLIPBOARD"); + DEFSYM (QSECONDARY, "SECONDARY"); + DEFSYM (QTEXT, "TEXT"); + DEFSYM (QFILE_NAME, "FILE_NAME"); defsubr (&Sns_disown_selection_internal); defsubr (&Sns_get_selection); -- 2.39.2