From 9a9c36d8fdf54039540c44d27ee91063e835500c Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 17:25:21 +0200 Subject: [PATCH 6/6] Remove struct Lisp_Buffer_Objfwd * src/lisp.h (struct Lisp_Buffer_Objfwd): Deleted. (struct Lisp_Fwd): Add the fields bufoffset and bufpredicate. Make the type a 1-byte bitfield so that the entire struct still fits in two words. (XBUFFER_OFFSET): Renamed from XBUFFER_OBJFWD. * src/buffer.c (DEFVAR_PER_BUFFER, defvar_per_buffer) (buffer_local_value): Update accordingly. * src/data.c (do_symval_forwarding, store_symval_forwarding) (set_internal, default_value, set_default_internal) (Fmake_local_variable, Fkill_local_variable, Flocal_variable_): Use XBUFFER_OFFSET. --- src/buffer.c | 29 ++++++++++++++--------------- src/data.c | 19 +++++++++---------- src/lisp.h | 30 ++++++++++++++++-------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index e55560b1cd9..ae5016df50e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1389,7 +1389,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object buffer) { lispfwd fwd = SYMBOL_FWD (sym); if (BUFFER_OBJFWDP (fwd)) - result = per_buffer_value (buf, XBUFFER_OBJFWD (fwd)->offset); + result = per_buffer_value (buf, XBUFFER_OFFSET (fwd)); else result = Fdefault_value (variable); break; @@ -5019,32 +5019,31 @@ init_buffer (void) /* FIXME: use LISPSYM_INITIALLY instead of TAG_PTR_INITIALLY */ #define DEFVAR_PER_BUFFER(lname, vname, predicate_, doc) \ -do \ - { \ - const Lisp_Object sym = TAG_PTR_INITIALLY ( \ - Lisp_Symbol, (intptr_t)((i##predicate_) * sizeof *lispsym)); \ - static const struct Lisp_Fwd bo_fwd = { \ - .type = Lisp_Fwd_Buffer_Obj, \ - .u.bufobjfwd = { .offset = offsetof (struct buffer, vname##_), \ - .predicate = sym }, \ - }; \ + do { \ + const Lisp_Object sym \ + = TAG_PTR_INITIALLY (Lisp_Symbol, (intptr_t)((i##predicate_) \ + * sizeof *lispsym)); \ + static const struct Lisp_Fwd bo_fwd \ + = { .type = Lisp_Fwd_Buffer_Obj, \ + .bufoffset = offsetof (struct buffer, vname##_), \ + .u.bufpredicate = sym }; \ + static_assert (offsetof (struct buffer, vname##_) \ + < (1 << 8 * sizeof bo_fwd.bufoffset)); \ defvar_per_buffer (&bo_fwd, lname); \ - } \ -while (0) + } while (0) static void defvar_per_buffer (const struct Lisp_Fwd *fwd, const char *namestring) { eassert (fwd->type == Lisp_Fwd_Buffer_Obj); - const struct Lisp_Buffer_Objfwd *bo_fwd = XBUFFER_OBJFWD (fwd); struct Lisp_Symbol *sym = XSYMBOL (intern (namestring)); sym->u.s.declared_special = true; sym->u.s.redirect = SYMBOL_FORWARDED; SET_SYMBOL_FWD (sym, fwd); - XSETSYMBOL (PER_BUFFER_SYMBOL (bo_fwd->offset), sym); + XSETSYMBOL (PER_BUFFER_SYMBOL (XBUFFER_OFFSET (fwd)), sym); - if (PER_BUFFER_IDX (bo_fwd->offset) == 0) + if (PER_BUFFER_IDX (XBUFFER_OFFSET (fwd)) == 0) /* Did a DEFVAR_PER_BUFFER without initializing the corresponding slot of buffer_local_flags. */ emacs_abort (); diff --git a/src/data.c b/src/data.c index 9f344474692..e0133d81771 100644 --- a/src/data.c +++ b/src/data.c @@ -1343,7 +1343,7 @@ do_symval_forwarding (lispfwd valcontents) case Lisp_Fwd_Buffer_Obj: return per_buffer_value (current_buffer, - XBUFFER_OBJFWD (valcontents)->offset); + XBUFFER_OFFSET (valcontents)); case Lisp_Fwd_Kboard_Obj: return *(Lisp_Object *) (XKBOARD_OFFSET (valcontents) @@ -1458,9 +1458,8 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, case Lisp_Fwd_Buffer_Obj: { - const struct Lisp_Buffer_Objfwd *fwd = XBUFFER_OBJFWD (valcontents); - int offset = fwd->offset; - Lisp_Object predicate = fwd->predicate; + int offset = XBUFFER_OFFSET (valcontents); + Lisp_Object predicate = valcontents->u.bufpredicate; if (!NILP (newval) && !NILP (predicate)) { @@ -1769,7 +1768,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, lispfwd innercontents = SYMBOL_FWD (sym); if (BUFFER_OBJFWDP (innercontents)) { - int offset = XBUFFER_OBJFWD (innercontents)->offset; + int offset = XBUFFER_OFFSET (innercontents); int idx = PER_BUFFER_IDX (offset); if (idx > 0 && bindflag == SET_INTERNAL_SET && !PER_BUFFER_VALUE_P (buf, idx)) @@ -1958,7 +1957,7 @@ default_value (Lisp_Object symbol) rather than letting do_symval_forwarding get the current value. */ if (BUFFER_OBJFWDP (valcontents)) { - int offset = XBUFFER_OBJFWD (valcontents)->offset; + int offset = XBUFFER_OFFSET (valcontents); if (PER_BUFFER_IDX (offset) != 0) return per_buffer_default (offset); } @@ -2053,7 +2052,7 @@ set_default_internal (Lisp_Object symbol, Lisp_Object value, Make them work apparently like Lisp_Buffer_Local_Value variables. */ if (BUFFER_OBJFWDP (valcontents)) { - int offset = XBUFFER_OBJFWD (valcontents)->offset; + int offset = XBUFFER_OFFSET (valcontents); int idx = PER_BUFFER_IDX (offset); set_per_buffer_default (offset, value); @@ -2270,7 +2269,7 @@ DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, { if (forwarded && BUFFER_OBJFWDP (valcontents.fwd)) { - int offset = XBUFFER_OBJFWD (valcontents.fwd)->offset; + int offset = XBUFFER_OFFSET (valcontents.fwd); int idx = PER_BUFFER_IDX (offset); eassert (idx); if (idx > 0) @@ -2342,7 +2341,7 @@ DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable, lispfwd valcontents = SYMBOL_FWD (sym); if (BUFFER_OBJFWDP (valcontents)) { - int offset = XBUFFER_OBJFWD (valcontents)->offset; + int offset = XBUFFER_OFFSET (valcontents); int idx = PER_BUFFER_IDX (offset); if (idx > 0) @@ -2423,7 +2422,7 @@ DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p, lispfwd valcontents = SYMBOL_FWD (sym); if (BUFFER_OBJFWDP (valcontents)) { - int offset = XBUFFER_OBJFWD (valcontents)->offset; + int offset = XBUFFER_OFFSET (valcontents); int idx = PER_BUFFER_IDX (offset); if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) return Qt; diff --git a/src/lisp.h b/src/lisp.h index 2dc3530337b..c20bc9aa76e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3115,15 +3115,6 @@ #define INT_TO_INTEGER(expr) \ (EXPR_SIGNED (expr) ? make_int (expr) : make_uint (expr)) -/* Like Lisp_Objfwd except that value lives in a slot in the - current buffer. Value is byte index of slot within buffer. */ -struct Lisp_Buffer_Objfwd - { - int offset; - /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp. */ - Lisp_Object predicate; - }; - /* struct Lisp_Buffer_Local_Value is used in a symbol value cell when the symbol has buffer-local bindings. (Exception: some buffer-local variables are built-in, with their values stored @@ -3167,15 +3158,26 @@ #define INT_TO_INTEGER(expr) \ Lisp_Object valcell; }; +/* A struct Lisp_Fwd is used to locate a variable. See Lisp_Fwd_Type + for the various types of variables. + + Lisp_Fwd structs are created by macros like DEFVAR_INT, DEFVAR_BOOL etc. + and are always kept in static variables. They are never allocated + dynamically. */ + struct Lisp_Fwd { - enum Lisp_Fwd_Type type; + enum Lisp_Fwd_Type type : 8; + uint16_t bufoffset; /* used if type == Lisp_Fwd_Buffer_Obj */ union { intmax_t *intvar; bool *boolvar; Lisp_Object *objvar; - struct Lisp_Buffer_Objfwd bufobjfwd; + /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp, Qnumberp, + Qfraction, Qvertical_scroll_bar, or Qoverwrite_mode. + */ + Lisp_Object bufpredicate; int kbdoffset; } u; }; @@ -3192,11 +3194,11 @@ BUFFER_OBJFWDP (lispfwd a) return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj; } -INLINE struct Lisp_Buffer_Objfwd const * -XBUFFER_OBJFWD (lispfwd a) +INLINE int +XBUFFER_OFFSET (lispfwd a) { eassert (BUFFER_OBJFWDP (a)); - return &a->u.bufobjfwd; + return a->bufoffset; } INLINE bool -- 2.39.2