From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: MPS: Forwording symbols Date: Sun, 23 Jun 2024 17:59:39 +0200 Message-ID: <87zfrby7is.fsf@gmail.com> References: <878qyy1f55.fsf@gmail.com> <87o77szwif.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35083"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Emacs Devel , Eli Zaretskii To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 23 18:00:31 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sLPdn-0008yl-3T for ged-emacs-devel@m.gmane-mx.org; Sun, 23 Jun 2024 18:00:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLPd9-000330-Fp; Sun, 23 Jun 2024 11:59:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLPd7-00032q-Mw for emacs-devel@gnu.org; Sun, 23 Jun 2024 11:59:49 -0400 Original-Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLPd1-0000h9-EK; Sun, 23 Jun 2024 11:59:48 -0400 Original-Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-421bb51d81aso29677415e9.3; Sun, 23 Jun 2024 08:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719158381; x=1719763181; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=hkAFOxxOYtB7vVeVK3wd6SYxBZlpkPiiozdHhVVMAT0=; b=RCtB2+p4a8gUlhUcBH4XVnlvW5hWbfR2dQ1LUwrZaknQHzlhmdDiF80OmKn8SgTJiG U86k7X38ena75yEY3ktRqPs4mwsfcH9V8qTPTWUA/IN7H5W1BUWd2twcOK7Kcx4a8qbF ttVgCLwMJBbi3/AqLAbx4zfDDgXyqIuwQMfnln4hDdpdddRr/dIFzFuCXVIUwRhuG1sQ 0yqoli8BBe7VgVEu1orxt/gygfH2CrnTbY2YPZMu5LcOkPxw+MctxDrKDG9y3Ln51D3J MMuAFGJHOAt7dNhzQOz0EvpOsKvFwPN9AB6fWv4V6RfGnlNcMlljUdm1+RuEkwhwb+zM A18g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719158381; x=1719763181; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hkAFOxxOYtB7vVeVK3wd6SYxBZlpkPiiozdHhVVMAT0=; b=PmgvDhkelZJIgLdfcYyDANxQcUXYngTNHlVdUcE7qNhM1b6GhBwqefolk829mPHZir juCiLAs48DqDQDJMQHHy/QeaqRcZcQ7h3t+09r5G0W2Cgccl3k+DcOpNYqb7WeQ9GTv9 mvg/66flloZoAhTulfJx+Suz9bYJYYjIUVVz953SUSMVrp4Bg/VV4r3YzHx9TesJbcU5 Pll697oSVnSCaLRtff1JIfXqFRLqH+wd7fkCl0WJTQ9F6Gm8vGxY1FnUob4FRh6IeuMM s2FS9GF2Ajz3yAunPWNPNPwaQ3bcz0oGvu/gRwX1sNN3cHS36rFXFBY+6Gaq3Ay1A8FP aCIw== X-Forwarded-Encrypted: i=1; AJvYcCW5bfK3MTUpr009ZMSWTGizB8okyzjlacQu6dOcVavDO2MNFJ45iKbFKTuZFFT67zwB8jTpVp7daLk803o= X-Gm-Message-State: AOJu0YyPIj3TppOYiMJwQ3Ndr/LpYyBY7wfkbvFm/uLdIyPcWln/ctHA QJg07YA7C+FcYREoxUB9HpjfKG0hsl9b3SHLD9shjK8my4rsmZlxVVcrSg== X-Google-Smtp-Source: AGHT+IEF3cHfSTXfq8CIgNs8JTM+vwEt/3/i3l5PWLUt95P8IDGKrWpziYUvIl9DC0PutWJmdf87ZA== X-Received: by 2002:a05:600c:15d1:b0:422:3da0:3ca3 with SMTP id 5b1f17b1804b1-4248cc669f8mr17389605e9.34.1719158381154; Sun, 23 Jun 2024 08:59:41 -0700 (PDT) Original-Received: from caladan ([31.177.116.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366388c3d57sm7646773f8f.35.2024.06.23.08.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jun 2024 08:59:40 -0700 (PDT) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llman?= =?utf-8?Q?n=22's?= message of "Sat, 22 Jun 2024 20:27:12 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=eller.helmut@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:320550 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Jun 22 2024, Gerd M=C3=B6llmann wrote: > I was thinking of using 1 struct instead of 4, like so > > enum Lisp_Fwd_Pred > { > /* Something with values for the Lisp_Object predicate ... */ > ...=20=20 > }; > > struct Lisp_Fwd > { > enum Lisp_Fwd_Type : 8; > enum Lisp_Fwd_Predicate predicate : 8; > union > { > intmax_t *intvar; > bool *boolvar; > Lisp_Object *objvar; > int offset; > } u; > }; > > Then removing the Lisp_Fwd_Bool etc. structures that currently exist and > replace this > > typedef struct { void const *fwdptr; } lispfwd; > > which is just a void * with ornaments, with const struct Lisp_Fwd *. These patches do this; only that the predicate is still a Lisp_Object. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Introduce-a-struct-Lisp_Fwd.patch >From 3aae2499b62770364983a75e99c2fca2bba2bee6 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 06:39:18 +0200 Subject: [PATCH 1/6] Introduce a struct Lisp_Fwd This contains the type and an union of Lisp_Objfwd, Lisp_Intfwd etc. lispfwd is now a pointer to a struct Lisp_Fwd; the fwdptr field is gone. * src/lisp.h (struct Lisp_Fwd): New. (Lisp_Intfwd, Lisp_Boolfwd, Lisp_Objfwd, Lisp_Buffer_Objfwd) (Lisp_Kboard_Objfwd): The type is in in Lisp_Fwd. (lispwfd): Is now a pointer to struct Lisp_Fwd. (SYMBOL_BLV, SET_SYMBOL_FWD, XFWDTYPE, BUFFER_OBJFWDP): Update accordingly. (defvar_lisp, defvar_lisp_nopro, defvar_bool, defvar_int) (defvar_kboard): These all take now a Lisp_Fwd. (DEFVAR_LISP, DEFVAR_LISP_NOPRO, DEFVAR_BOOL, DEFVAR_INT) (DEFVAR_KBOARD): Update for new types. * src/lread.c (defvar_int, defvar_bool, defvar_lisp_nopro) (defvar_lisp, defvar_kboard): Update for new types. * src/pdumper.c (dump_field_fwd, dump_blv): Update accordingly. * src/buffer.c (DEFVAR_PER_BUFFER, defvar_per_buffer, buffer_local_value) (set_buffer_internal_1): Update accordingly for new types. * src/data.c (XBOOLFWD, XKBOARD_OBJFWD, XFIXNUMFWD, XOBJFWD, boundp) (store_symval_forwarding, swap_in_global_binding) (swap_in_symval_forwarding, find_symbol_value, set_internal) (default_value, set_default_internal, make_blv, Fmake_local_variable): Update accordingly. --- src/buffer.c | 17 +++++---- src/data.c | 39 ++++++++++--------- src/lisp.h | 104 +++++++++++++++++++++++++++----------------------- src/lread.c | 17 ++++++--- src/pdumper.c | 10 ++--- 5 files changed, 102 insertions(+), 85 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index d864560ec85..e55560b1cd9 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1366,7 +1366,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object buffer) result = assq_no_quit (variable, BVAR (buf, local_var_alist)); if (!NILP (result)) { - if (blv->fwd.fwdptr) + if (blv->fwd) { /* What binding is loaded right now? */ Lisp_Object current_alist_element = blv->valcell; @@ -2365,7 +2365,7 @@ set_buffer_internal_1 (register struct buffer *b) Lisp_Object var = XCAR (XCAR (tail)); struct Lisp_Symbol *sym = XSYMBOL (var); if (sym->u.s.redirect == SYMBOL_LOCALIZED /* Just to be sure. */ - && SYMBOL_BLV (sym)->fwd.fwdptr) + && SYMBOL_BLV (sym)->fwd) /* Just reference the variable to cause it to become set for this buffer. */ Fsymbol_value (var); @@ -5023,24 +5023,25 @@ #define DEFVAR_PER_BUFFER(lname, vname, predicate_, doc) \ { \ const Lisp_Object sym = TAG_PTR_INITIALLY ( \ Lisp_Symbol, (intptr_t)((i##predicate_) * sizeof *lispsym)); \ - static const struct Lisp_Buffer_Objfwd bo_fwd = { \ + static const struct Lisp_Fwd bo_fwd = { \ .type = Lisp_Fwd_Buffer_Obj, \ - .offset = offsetof (struct buffer, vname##_), \ - .predicate = sym, \ + .u.bufobjfwd = { .offset = offsetof (struct buffer, vname##_), \ + .predicate = sym }, \ }; \ defvar_per_buffer (&bo_fwd, lname); \ } \ while (0) static void -defvar_per_buffer (const struct Lisp_Buffer_Objfwd *bo_fwd, - const char *namestring) +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, bo_fwd); + SET_SYMBOL_FWD (sym, fwd); XSETSYMBOL (PER_BUFFER_SYMBOL (bo_fwd->offset), sym); if (PER_BUFFER_IDX (bo_fwd->offset) == 0) diff --git a/src/data.c b/src/data.c index efce262f8e6..4a6a247e89e 100644 --- a/src/data.c +++ b/src/data.c @@ -59,25 +59,25 @@ OBJFWDP (lispfwd a) XBOOLFWD (lispfwd a) { eassert (BOOLFWDP (a)); - return a.fwdptr; + return &a->u.boolfwd; } static struct Lisp_Kboard_Objfwd const * XKBOARD_OBJFWD (lispfwd a) { eassert (KBOARD_OBJFWDP (a)); - return a.fwdptr; + return &a->u.kboardobjfwd; } static struct Lisp_Intfwd const * XFIXNUMFWD (lispfwd a) { eassert (INTFWDP (a)); - return a.fwdptr; + return &a->u.intfwd; } static struct Lisp_Objfwd const * XOBJFWD (lispfwd a) { eassert (OBJFWDP (a)); - return a.fwdptr; + return &a->u.objfwd; } static void @@ -731,7 +731,7 @@ DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, case SYMBOL_LOCALIZED: { struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); - if (blv->fwd.fwdptr) + if (blv->fwd) /* In set_internal, we un-forward vars when their value is set to Qunbound. */ return Qt; @@ -1458,8 +1458,9 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, case Lisp_Fwd_Buffer_Obj: { - int offset = XBUFFER_OBJFWD (valcontents)->offset; - Lisp_Object predicate = XBUFFER_OBJFWD (valcontents)->predicate; + const struct Lisp_Buffer_Objfwd *fwd = XBUFFER_OBJFWD (valcontents); + int offset = fwd->offset; + Lisp_Object predicate = fwd->predicate; if (!NILP (newval) && !NILP (predicate)) { @@ -1517,12 +1518,12 @@ swap_in_global_binding (struct Lisp_Symbol *symbol) struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (symbol); /* Unload the previously loaded binding. */ - if (blv->fwd.fwdptr) + if (blv->fwd) set_blv_value (blv, do_symval_forwarding (blv->fwd)); /* Select the global binding in the symbol. */ set_blv_valcell (blv, blv->defcell); - if (blv->fwd.fwdptr) + if (blv->fwd) store_symval_forwarding (blv->fwd, XCDR (blv->defcell), NULL); /* Indicate that the global binding is set up now. */ @@ -1552,7 +1553,7 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_ /* Unload the previously loaded binding. */ tem1 = blv->valcell; - if (blv->fwd.fwdptr) + if (blv->fwd) set_blv_value (blv, do_symval_forwarding (blv->fwd)); /* Choose the new binding. */ { @@ -1566,7 +1567,7 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_ /* Load the new binding. */ set_blv_valcell (blv, tem1); - if (blv->fwd.fwdptr) + if (blv->fwd) store_symval_forwarding (blv->fwd, blv_value (blv), NULL); } } @@ -1599,7 +1600,7 @@ find_symbol_value (Lisp_Object symbol) { struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); swap_in_symval_forwarding (sym, blv); - return (blv->fwd.fwdptr + return (blv->fwd ? do_symval_forwarding (blv->fwd) : blv_value (blv)); } @@ -1700,7 +1701,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, We need to unload it, and choose a new binding. */ /* Write out `realvalue' to the old loaded binding. */ - if (blv->fwd.fwdptr) + if (blv->fwd) set_blv_value (blv, do_symval_forwarding (blv->fwd)); /* Find the new binding. */ @@ -1748,12 +1749,12 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, /* Store the new value in the cons cell. */ set_blv_value (blv, newval); - if (blv->fwd.fwdptr) + if (blv->fwd) { if (voide) /* If storing void (making the symbol void), forward only through buffer-local indicator, not through Lisp_Objfwd, etc. */ - blv->fwd.fwdptr = NULL; + blv->fwd = NULL; else store_symval_forwarding (blv->fwd, newval, BUFFERP (where) @@ -1944,7 +1945,7 @@ default_value (Lisp_Object symbol) But the `realvalue' slot may be more up to date, since ordinary setq stores just that slot. So use that. */ struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); - if (blv->fwd.fwdptr && EQ (blv->valcell, blv->defcell)) + if (blv->fwd && EQ (blv->valcell, blv->defcell)) return do_symval_forwarding (blv->fwd); else return XCDR (blv->defcell); @@ -2039,7 +2040,7 @@ set_default_internal (Lisp_Object symbol, Lisp_Object value, XSETCDR (blv->defcell, value); /* If the default binding is now loaded, set the REALVALUE slot too. */ - if (blv->fwd.fwdptr && EQ (blv->defcell, blv->valcell)) + if (blv->fwd && EQ (blv->defcell, blv->valcell)) store_symval_forwarding (blv->fwd, value, NULL); return; } @@ -2136,7 +2137,7 @@ make_blv (struct Lisp_Symbol *sym, bool forwarded, if (forwarded) blv->fwd = valcontents.fwd; else - blv->fwd.fwdptr = NULL; + blv->fwd = NULL; set_blv_where (blv, Qnil); blv->local_if_set = 0; set_blv_defcell (blv, tem); @@ -2311,7 +2312,7 @@ DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, Otherwise, if C code modifies the variable before we load the binding in, then that new value would clobber the default binding the next time we unload it. See bug#34318. */ - if (blv->fwd.fwdptr) + if (blv->fwd) swap_in_symval_forwarding (sym, blv); } diff --git a/src/lisp.h b/src/lisp.h index f85dd348aa3..3ce5e2b4d66 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -799,7 +799,7 @@ #define XUNTAG(a, type, ctype) \ union of the possible values (struct Lisp_Objfwd, struct Lisp_Intfwd, etc.). The pointer is packaged inside a struct to help static checking. */ -typedef struct { void const *fwdptr; } lispfwd; +typedef const struct Lisp_Fwd *lispfwd; /* Interned state of a symbol. */ @@ -2358,7 +2358,7 @@ SYMBOL_BLV (struct Lisp_Symbol *sym) INLINE lispfwd SYMBOL_FWD (struct Lisp_Symbol *sym) { - eassume (sym->u.s.redirect == SYMBOL_FORWARDED && sym->u.s.val.fwd.fwdptr); + eassume (sym->u.s.redirect == SYMBOL_FORWARDED && sym->u.s.val.fwd); return sym->u.s.val.fwd; } @@ -2382,10 +2382,10 @@ SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v) sym->u.s.val.blv = v; } INLINE void -SET_SYMBOL_FWD (struct Lisp_Symbol *sym, void const *v) +SET_SYMBOL_FWD (struct Lisp_Symbol *sym, lispfwd fwd) { - eassume (sym->u.s.redirect == SYMBOL_FORWARDED && v); - sym->u.s.val.fwd.fwdptr = v; + eassume (sym->u.s.redirect == SYMBOL_FORWARDED && fwd); + sym->u.s.val.fwd = fwd; } INLINE Lisp_Object @@ -3121,7 +3121,6 @@ #define INT_TO_INTEGER(expr) \ specified int variable. */ struct Lisp_Intfwd { - enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Int */ intmax_t *intvar; }; @@ -3131,7 +3130,6 @@ #define INT_TO_INTEGER(expr) \ nil if it is false. */ struct Lisp_Boolfwd { - enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Bool */ bool *boolvar; }; @@ -3141,7 +3139,6 @@ #define INT_TO_INTEGER(expr) \ specified variable. */ struct Lisp_Objfwd { - enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Obj */ Lisp_Object *objvar; }; @@ -3149,7 +3146,6 @@ #define INT_TO_INTEGER(expr) \ current buffer. Value is byte index of slot within buffer. */ struct Lisp_Buffer_Objfwd { - enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Buffer_Obj */ int offset; /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp or Qnumberp. */ Lisp_Object predicate; @@ -3202,15 +3198,26 @@ #define INT_TO_INTEGER(expr) \ current kboard. */ struct Lisp_Kboard_Objfwd { - enum Lisp_Fwd_Type type; /* = Lisp_Fwd_Kboard_Obj */ int offset; }; +struct Lisp_Fwd +{ + enum Lisp_Fwd_Type type; + union + { + struct Lisp_Intfwd intfwd; + struct Lisp_Boolfwd boolfwd; + struct Lisp_Objfwd objfwd; + struct Lisp_Buffer_Objfwd bufobjfwd; + struct Lisp_Kboard_Objfwd kboardobjfwd; + } u; +}; + INLINE enum Lisp_Fwd_Type XFWDTYPE (lispfwd a) { - enum Lisp_Fwd_Type const *p = a.fwdptr; - return *p; + return a->type; } INLINE bool @@ -3223,7 +3230,7 @@ BUFFER_OBJFWDP (lispfwd a) XBUFFER_OBJFWD (lispfwd a) { eassert (BUFFER_OBJFWDP (a)); - return a.fwdptr; + return &a->u.bufobjfwd; } INLINE bool @@ -3559,11 +3566,11 @@ call0 (Lisp_Object fn) return Ffuncall (1, &fn); } -extern void defvar_lisp (struct Lisp_Objfwd const *, char const *); -extern void defvar_lisp_nopro (struct Lisp_Objfwd const *, char const *); -extern void defvar_bool (struct Lisp_Boolfwd const *, char const *); -extern void defvar_int (struct Lisp_Intfwd const *, char const *); -extern void defvar_kboard (struct Lisp_Kboard_Objfwd const *, char const *); +extern void defvar_lisp (struct Lisp_Fwd const *, char const *); +extern void defvar_lisp_nopro (struct Lisp_Fwd const *, char const *); +extern void defvar_bool (struct Lisp_Fwd const *, char const *); +extern void defvar_int (struct Lisp_Fwd const *, char const *); +extern void defvar_kboard (struct Lisp_Fwd const *, char const *); /* Macros we use to define forwarded Lisp variables. These are used in the syms_of_FILENAME functions. @@ -3582,18 +3589,18 @@ call0 (Lisp_Object fn) All C code uses the `cons_cells_consed' name. This is all done this way to support indirection for multi-threaded Emacs. */ -#define DEFVAR_LISP(lname, vname, doc) \ - do { \ - static struct Lisp_Objfwd const o_fwd \ - = {Lisp_Fwd_Obj, &globals.f_##vname}; \ - defvar_lisp (&o_fwd, lname); \ +#define DEFVAR_LISP(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ + defvar_lisp (&o_fwd, lname); \ } while (false) #ifdef HAVE_MPS -#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ - do { \ - static struct Lisp_Objfwd const o_fwd \ - = {Lisp_Fwd_Obj, &globals.f_##vname}; \ - defvar_lisp (&o_fwd, lname); \ +#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ + defvar_lisp (&o_fwd, lname); \ } while (false) #define DEFVAR_LISP_NOPROX(lname, vname, doc) \ do { \ @@ -3602,11 +3609,11 @@ #define DEFVAR_LISP_NOPROX(lname, vname, doc) \ defvar_lisp_nopro (&o_fwd, lname); \ } while (false) #else -#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ - do { \ - static struct Lisp_Objfwd const o_fwd \ - = {Lisp_Fwd_Obj, &globals.f_##vname}; \ - defvar_lisp_nopro (&o_fwd, lname); \ +#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ + defvar_lisp_nopro (&o_fwd, lname); \ } while (false) #define DEFVAR_LISP_NOPROX(lname, vname, doc) \ do { \ @@ -3615,25 +3622,28 @@ #define DEFVAR_LISP_NOPROX(lname, vname, doc) \ defvar_lisp_nopro (&o_fwd, lname); \ } while (false) #endif -#define DEFVAR_BOOL(lname, vname, doc) \ - do { \ - static struct Lisp_Boolfwd const b_fwd \ - = {Lisp_Fwd_Bool, &globals.f_##vname}; \ - defvar_bool (&b_fwd, lname); \ +#define DEFVAR_BOOL(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const b_fwd \ + = {Lisp_Fwd_Bool, .u.boolfwd = {&globals.f_##vname}}; \ + defvar_bool (&b_fwd, lname); \ } while (false) -#define DEFVAR_INT(lname, vname, doc) \ - do { \ - static struct Lisp_Intfwd const i_fwd \ - = {Lisp_Fwd_Int, &globals.f_##vname}; \ - defvar_int (&i_fwd, lname); \ +#define DEFVAR_INT(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const i_fwd \ + = {Lisp_Fwd_Int, .u.intfwd = {&globals.f_##vname}}; \ + defvar_int (&i_fwd, lname); \ } while (false) #define DEFVAR_KBOARD(lname, vname, doc) \ - do { \ - static struct Lisp_Kboard_Objfwd const ko_fwd \ - = {Lisp_Fwd_Kboard_Obj, offsetof (KBOARD, vname##_)}; \ +do \ + { \ + static struct Lisp_Fwd const ko_fwd \ + = { Lisp_Fwd_Kboard_Obj, \ + .u.kboardobjfwd = {offsetof (KBOARD, vname##_)}}; \ defvar_kboard (&ko_fwd, lname); \ - } while (false) + } \ +while (false) /* Elisp uses multiple stacks: diff --git a/src/lread.c b/src/lread.c index 068ae1a4e4b..db3f520c020 100644 --- a/src/lread.c +++ b/src/lread.c @@ -5466,8 +5466,9 @@ defsubr (union Aligned_Lisp_Subr *aname) C variable of type intmax_t. Sample call (with "xx" to fool make-docfile): DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ void -defvar_int (struct Lisp_Intfwd const *i_fwd, char const *namestring) +defvar_int (struct Lisp_Fwd const *i_fwd, char const *namestring) { + eassert (i_fwd->type == Lisp_Fwd_Int); Lisp_Object sym = intern_c_string (namestring); XBARE_SYMBOL (sym)->u.s.declared_special = true; XBARE_SYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; @@ -5476,8 +5477,9 @@ defvar_int (struct Lisp_Intfwd const *i_fwd, char const *namestring) /* Similar but define a variable whose value is t if 1, nil if 0. */ void -defvar_bool (struct Lisp_Boolfwd const *b_fwd, char const *namestring) +defvar_bool (struct Lisp_Fwd const *b_fwd, char const *namestring) { + eassert (b_fwd->type == Lisp_Fwd_Bool); Lisp_Object sym = intern_c_string (namestring); XBARE_SYMBOL (sym)->u.s.declared_special = true; XBARE_SYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; @@ -5491,8 +5493,9 @@ defvar_bool (struct Lisp_Boolfwd const *b_fwd, char const *namestring) gc-marked for some other reason, since marking the same slot twice can cause trouble with strings. */ void -defvar_lisp_nopro (struct Lisp_Objfwd const *o_fwd, char const *namestring) +defvar_lisp_nopro (struct Lisp_Fwd const *o_fwd, char const *namestring) { + eassert (o_fwd->type == Lisp_Fwd_Obj); Lisp_Object sym = intern_c_string (namestring); XBARE_SYMBOL (sym)->u.s.declared_special = true; XBARE_SYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; @@ -5500,18 +5503,20 @@ defvar_lisp_nopro (struct Lisp_Objfwd const *o_fwd, char const *namestring) } void -defvar_lisp (struct Lisp_Objfwd const *o_fwd, char const *namestring) +defvar_lisp (struct Lisp_Fwd const *o_fwd, char const *namestring) { + eassert (o_fwd->type == Lisp_Fwd_Obj); defvar_lisp_nopro (o_fwd, namestring); - staticpro (o_fwd->objvar); + staticpro (o_fwd->u.objfwd.objvar); } /* Similar but define a variable whose value is the Lisp Object stored at a particular offset in the current kboard object. */ void -defvar_kboard (struct Lisp_Kboard_Objfwd const *ko_fwd, char const *namestring) +defvar_kboard (struct Lisp_Fwd const *ko_fwd, char const *namestring) { + eassert (ko_fwd->type == Lisp_Fwd_Kboard_Obj); Lisp_Object sym = intern_c_string (namestring); XBARE_SYMBOL (sym)->u.s.declared_special = true; XBARE_SYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; diff --git a/src/pdumper.c b/src/pdumper.c index 21343d42082..d8e21b569f1 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -2362,24 +2362,24 @@ dump_float (struct dump_context *ctx, const struct Lisp_Float *lfloat) dump_field_fwd (struct dump_context *ctx, void *out, const void *in_start, const lispfwd *in_field) { - dump_field_emacs_ptr (ctx, out, in_start, &in_field->fwdptr); + dump_field_emacs_ptr (ctx, out, in_start, in_field); switch (XFWDTYPE (*in_field)) { case Lisp_Fwd_Int: { - const struct Lisp_Intfwd *fwd = in_field->fwdptr; + const struct Lisp_Intfwd *fwd = &(*in_field)->u.intfwd; dump_emacs_reloc_immediate_intmax_t (ctx, fwd->intvar, *fwd->intvar); } return; case Lisp_Fwd_Bool: { - const struct Lisp_Boolfwd *fwd = in_field->fwdptr; + const struct Lisp_Boolfwd *fwd = &(*in_field)->u.boolfwd; dump_emacs_reloc_immediate_bool (ctx, fwd->boolvar, *fwd->boolvar); } return; case Lisp_Fwd_Obj: { - const struct Lisp_Objfwd *fwd = in_field->fwdptr; + const struct Lisp_Objfwd *fwd = &(*in_field)->u.objfwd; if (NILP (Fgethash (dump_off_to_lisp (emacs_offset (fwd->objvar)), ctx->staticpro_table, Qnil))) dump_emacs_reloc_to_lv (ctx, fwd->objvar, *fwd->objvar); @@ -2403,7 +2403,7 @@ dump_blv (struct dump_context *ctx, dump_object_start (ctx, blv, IGC_OBJ_BLV, &out, sizeof (out)); DUMP_FIELD_COPY (&out, blv, local_if_set); DUMP_FIELD_COPY (&out, blv, found); - if (blv->fwd.fwdptr) + if (blv->fwd) dump_field_fwd (ctx, &out, blv, &blv->fwd); dump_field_lv (ctx, &out, blv, &blv->where, WEIGHT_NORMAL); dump_field_lv (ctx, &out, blv, &blv->defcell, WEIGHT_STRONG); -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Remove-struct-Lisp_Intfwd.patch >From 67cb8dd5e597e3725f7adfccadc14ac18f2ec241 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 11:25:35 +0200 Subject: [PATCH 2/6] Remove struct Lisp_Intfwd It was a struct with a single field. * src/lisp.h (struct Lisp_Intfwd): Deleted. (struct Lisp_Fwd): Add an intvar field instead. (DEFVAR_INT): Update accordingly. * src/data.c (XINTVAR): Updated and renamed from XFIXNUMFWD. (do_symval_forwarding, store_symval_forwarding): Use it. --- src/data.c | 10 +++++----- src/lisp.h | 22 ++++++---------------- src/pdumper.c | 4 ++-- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/data.c b/src/data.c index 4a6a247e89e..9b3984d80e6 100644 --- a/src/data.c +++ b/src/data.c @@ -67,11 +67,11 @@ XKBOARD_OBJFWD (lispfwd a) eassert (KBOARD_OBJFWDP (a)); return &a->u.kboardobjfwd; } -static struct Lisp_Intfwd const * -XFIXNUMFWD (lispfwd a) +static intmax_t * +XINTVAR (lispfwd a) { eassert (INTFWDP (a)); - return &a->u.intfwd; + return a->u.intvar; } static struct Lisp_Objfwd const * XOBJFWD (lispfwd a) @@ -1333,7 +1333,7 @@ do_symval_forwarding (lispfwd valcontents) switch (XFWDTYPE (valcontents)) { case Lisp_Fwd_Int: - return make_int (*XFIXNUMFWD (valcontents)->intvar); + return make_int (*XINTVAR (valcontents)); case Lisp_Fwd_Bool: return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); @@ -1419,7 +1419,7 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, CHECK_INTEGER (newval); if (! integer_to_intmax (newval, &i)) xsignal1 (Qoverflow_error, newval); - *XFIXNUMFWD (valcontents)->intvar = i; + *XINTVAR (valcontents) = i; } break; diff --git a/src/lisp.h b/src/lisp.h index 3ce5e2b4d66..bfbf2447635 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)) -/* Forwarding pointer to an int variable. - This is allowed only in the value cell of a symbol, - and it means that the symbol's value really lives in the - specified int variable. */ -struct Lisp_Intfwd - { - intmax_t *intvar; - }; - /* Boolean forwarding pointer to an int variable. This is like Lisp_Intfwd except that the ostensible "value" of the symbol is t if the bool variable is true, @@ -3206,7 +3197,7 @@ #define INT_TO_INTEGER(expr) \ enum Lisp_Fwd_Type type; union { - struct Lisp_Intfwd intfwd; + intmax_t *intvar; struct Lisp_Boolfwd boolfwd; struct Lisp_Objfwd objfwd; struct Lisp_Buffer_Objfwd bufobjfwd; @@ -3628,13 +3619,12 @@ #define DEFVAR_BOOL(lname, vname, doc) \ = {Lisp_Fwd_Bool, .u.boolfwd = {&globals.f_##vname}}; \ defvar_bool (&b_fwd, lname); \ } while (false) -#define DEFVAR_INT(lname, vname, doc) \ - do { \ - static struct Lisp_Fwd const i_fwd \ - = {Lisp_Fwd_Int, .u.intfwd = {&globals.f_##vname}}; \ - defvar_int (&i_fwd, lname); \ +#define DEFVAR_INT(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const i_fwd \ + = {Lisp_Fwd_Int, .u.intvar = &globals.f_##vname}; \ + defvar_int (&i_fwd, lname); \ } while (false) - #define DEFVAR_KBOARD(lname, vname, doc) \ do \ { \ diff --git a/src/pdumper.c b/src/pdumper.c index d8e21b569f1..84175ea9a2c 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -2367,8 +2367,8 @@ dump_field_fwd (struct dump_context *ctx, void *out, const void *in_start, { case Lisp_Fwd_Int: { - const struct Lisp_Intfwd *fwd = &(*in_field)->u.intfwd; - dump_emacs_reloc_immediate_intmax_t (ctx, fwd->intvar, *fwd->intvar); + const intmax_t *intvar = (*in_field)->u.intvar; + dump_emacs_reloc_immediate_intmax_t (ctx, intvar, *intvar); } return; case Lisp_Fwd_Bool: -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0003-Remove-struct-Lisp_Boolfwd.patch >From 26b43b4b58e62ab2c6c0ce438d9b17a2abce0ef9 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 11:37:58 +0200 Subject: [PATCH 3/6] Remove struct Lisp_Boolfwd * src/lisp.h (struct Lisp Boolfwd): Deleted (struct Lisp_Fwd): Replaced it with a boolvar field. (DEFVAR_BOOL): Update. * src/data.c (XBOOLVAR): Renamed from XBOOLFWD. (do_symval_forwarding, store_symval_forwarding): Use it. * src/pdumper.c (dump_field_fwd): Use boolvar field. --- src/data.c | 10 +++++----- src/lisp.h | 13 ++----------- src/pdumper.c | 4 ++-- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/data.c b/src/data.c index 9b3984d80e6..292a2f2cf06 100644 --- a/src/data.c +++ b/src/data.c @@ -55,11 +55,11 @@ OBJFWDP (lispfwd a) return XFWDTYPE (a) == Lisp_Fwd_Obj; } -static struct Lisp_Boolfwd const * -XBOOLFWD (lispfwd a) +static bool * +XBOOLVAR (lispfwd a) { eassert (BOOLFWDP (a)); - return &a->u.boolfwd; + return a->u.boolvar; } static struct Lisp_Kboard_Objfwd const * XKBOARD_OBJFWD (lispfwd a) @@ -1336,7 +1336,7 @@ do_symval_forwarding (lispfwd valcontents) return make_int (*XINTVAR (valcontents)); case Lisp_Fwd_Bool: - return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); + return (*XBOOLVAR (valcontents) ? Qt : Qnil); case Lisp_Fwd_Obj: return *XOBJFWD (valcontents)->objvar; @@ -1424,7 +1424,7 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, break; case Lisp_Fwd_Bool: - *XBOOLFWD (valcontents)->boolvar = !NILP (newval); + *XBOOLVAR (valcontents) = !NILP (newval); break; case Lisp_Fwd_Obj: diff --git a/src/lisp.h b/src/lisp.h index bfbf2447635..a31079ad4bd 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)) -/* Boolean forwarding pointer to an int variable. - This is like Lisp_Intfwd except that the ostensible - "value" of the symbol is t if the bool variable is true, - nil if it is false. */ -struct Lisp_Boolfwd - { - bool *boolvar; - }; - /* Forwarding pointer to a Lisp_Object variable. This is allowed only in the value cell of a symbol, and it means that the symbol's value really lives in the @@ -3198,7 +3189,7 @@ #define INT_TO_INTEGER(expr) \ union { intmax_t *intvar; - struct Lisp_Boolfwd boolfwd; + bool *boolvar; struct Lisp_Objfwd objfwd; struct Lisp_Buffer_Objfwd bufobjfwd; struct Lisp_Kboard_Objfwd kboardobjfwd; @@ -3616,7 +3607,7 @@ #define DEFVAR_LISP_NOPROX(lname, vname, doc) \ #define DEFVAR_BOOL(lname, vname, doc) \ do { \ static struct Lisp_Fwd const b_fwd \ - = {Lisp_Fwd_Bool, .u.boolfwd = {&globals.f_##vname}}; \ + = {Lisp_Fwd_Bool, .u.boolvar = &globals.f_##vname}; \ defvar_bool (&b_fwd, lname); \ } while (false) #define DEFVAR_INT(lname, vname, doc) \ diff --git a/src/pdumper.c b/src/pdumper.c index 84175ea9a2c..7bb7ecc7a07 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -2373,8 +2373,8 @@ dump_field_fwd (struct dump_context *ctx, void *out, const void *in_start, return; case Lisp_Fwd_Bool: { - const struct Lisp_Boolfwd *fwd = &(*in_field)->u.boolfwd; - dump_emacs_reloc_immediate_bool (ctx, fwd->boolvar, *fwd->boolvar); + const bool *boolvar = (*in_field)->u.boolvar; + dump_emacs_reloc_immediate_bool (ctx, boolvar, *boolvar); } return; case Lisp_Fwd_Obj: -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0004-Remove-struct-Lisp_Objfwd.patch >From 26e61c573801f3fde32446c704b2c2b72da6fdc7 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 15:34:55 +0200 Subject: [PATCH 4/6] Remove struct Lisp_Objfwd * src/lisp.h (struct Lisp_Objfwd): Deleted. (struct Lisp_Fwd): Replace it with objvar field. (DEFVAR_LISP, DEFVAR_LISP_NOPRO, DEFVAR_LISP_NOPROX): Use the field. * src/lread.c (defvar_lisp): Updated as needed. * src/pdumper.c (dump_field_fwd): Use the field. * src/data.c (XOBJVAR): Renamed and updated from XOBJFWD. (do_symval_forwarding, store_symval_forwarding): Use it. --- src/data.c | 16 ++++++++-------- src/lisp.h | 53 +++++++++++++++++++++------------------------------ src/lread.c | 2 +- src/pdumper.c | 6 +++--- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/data.c b/src/data.c index 292a2f2cf06..af4802f54a0 100644 --- a/src/data.c +++ b/src/data.c @@ -73,11 +73,11 @@ XINTVAR (lispfwd a) eassert (INTFWDP (a)); return a->u.intvar; } -static struct Lisp_Objfwd const * -XOBJFWD (lispfwd a) +static Lisp_Object * +XOBJVAR (lispfwd a) { eassert (OBJFWDP (a)); - return &a->u.objfwd; + return a->u.objvar; } static void @@ -1339,7 +1339,7 @@ do_symval_forwarding (lispfwd valcontents) return (*XBOOLVAR (valcontents) ? Qt : Qnil); case Lisp_Fwd_Obj: - return *XOBJFWD (valcontents)->objvar; + return *XOBJVAR (valcontents); case Lisp_Fwd_Buffer_Obj: return per_buffer_value (current_buffer, @@ -1428,16 +1428,16 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, break; case Lisp_Fwd_Obj: - *XOBJFWD (valcontents)->objvar = newval; + *XOBJVAR (valcontents) = newval; /* If this variable is a default for something stored in the buffer itself, such as default-fill-column, find the buffers that don't have local values for it and update them. */ - if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults - && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1)) + if (XOBJVAR (valcontents) > (Lisp_Object *) &buffer_defaults + && XOBJVAR (valcontents) < (Lisp_Object *) (&buffer_defaults + 1)) { - int offset = ((char *) XOBJFWD (valcontents)->objvar + int offset = ((char *) XOBJVAR (valcontents) - (char *) &buffer_defaults); int idx = PER_BUFFER_IDX (offset); diff --git a/src/lisp.h b/src/lisp.h index a31079ad4bd..d0eef3e4aa1 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)) -/* Forwarding pointer to a Lisp_Object variable. - This is allowed only in the value cell of a symbol, - and it means that the symbol's value really lives in the - specified variable. */ -struct Lisp_Objfwd - { - Lisp_Object *objvar; - }; - /* 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 @@ -3190,7 +3181,7 @@ #define INT_TO_INTEGER(expr) \ { intmax_t *intvar; bool *boolvar; - struct Lisp_Objfwd objfwd; + Lisp_Object *objvar; struct Lisp_Buffer_Objfwd bufobjfwd; struct Lisp_Kboard_Objfwd kboardobjfwd; } u; @@ -3571,37 +3562,37 @@ call0 (Lisp_Object fn) All C code uses the `cons_cells_consed' name. This is all done this way to support indirection for multi-threaded Emacs. */ -#define DEFVAR_LISP(lname, vname, doc) \ - do { \ - static struct Lisp_Fwd const o_fwd \ - = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ - defvar_lisp (&o_fwd, lname); \ +#define DEFVAR_LISP(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objvar = &globals.f_##vname}; \ + defvar_lisp (&o_fwd, lname); \ } while (false) #ifdef HAVE_MPS -#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ - do { \ - static struct Lisp_Fwd const o_fwd \ - = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ - defvar_lisp (&o_fwd, lname); \ +#define DEFVAR_LISP_NOPRO(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objvar = &globals.f_##vname}; \ + defvar_lisp (&o_fwd, lname); \ } while (false) -#define DEFVAR_LISP_NOPROX(lname, vname, doc) \ - do { \ - static struct Lisp_Objfwd const o_fwd \ - = {Lisp_Fwd_Obj, &globals.f_##vname}; \ - defvar_lisp_nopro (&o_fwd, lname); \ +#define DEFVAR_LISP_NOPROX(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, .u.objvar = &globals.f_##vname}; \ + defvar_lisp_nopro (&o_fwd, lname); \ } while (false) #else #define DEFVAR_LISP_NOPRO(lname, vname, doc) \ do { \ static struct Lisp_Fwd const o_fwd \ - = {Lisp_Fwd_Obj, .u.objfwd = {&globals.f_##vname}}; \ + = {Lisp_Fwd_Obj, .u.objvar = &globals.f_##vname}; \ defvar_lisp_nopro (&o_fwd, lname); \ } while (false) -#define DEFVAR_LISP_NOPROX(lname, vname, doc) \ - do { \ - static struct Lisp_Objfwd const o_fwd \ - = {Lisp_Fwd_Obj, &globals.f_##vname}; \ - defvar_lisp_nopro (&o_fwd, lname); \ +#define DEFVAR_LISP_NOPROX(lname, vname, doc) \ + do { \ + static struct Lisp_Fwd const o_fwd \ + = {Lisp_Fwd_Obj, u.objvar = &globals.f_##vname}; \ + defvar_lisp_nopro (&o_fwd, lname); \ } while (false) #endif #define DEFVAR_BOOL(lname, vname, doc) \ diff --git a/src/lread.c b/src/lread.c index db3f520c020..188922516ea 100644 --- a/src/lread.c +++ b/src/lread.c @@ -5507,7 +5507,7 @@ defvar_lisp (struct Lisp_Fwd const *o_fwd, char const *namestring) { eassert (o_fwd->type == Lisp_Fwd_Obj); defvar_lisp_nopro (o_fwd, namestring); - staticpro (o_fwd->u.objfwd.objvar); + staticpro (o_fwd->u.objvar); } /* Similar but define a variable whose value is the Lisp Object stored diff --git a/src/pdumper.c b/src/pdumper.c index 7bb7ecc7a07..d975c65ed59 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -2379,10 +2379,10 @@ dump_field_fwd (struct dump_context *ctx, void *out, const void *in_start, return; case Lisp_Fwd_Obj: { - const struct Lisp_Objfwd *fwd = &(*in_field)->u.objfwd; - if (NILP (Fgethash (dump_off_to_lisp (emacs_offset (fwd->objvar)), + const Lisp_Object *objvar = (*in_field)->u.objvar; + if (NILP (Fgethash (dump_off_to_lisp (emacs_offset (objvar)), ctx->staticpro_table, Qnil))) - dump_emacs_reloc_to_lv (ctx, fwd->objvar, *fwd->objvar); + dump_emacs_reloc_to_lv (ctx, objvar, *objvar); } return; case Lisp_Fwd_Kboard_Obj: -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0005-Remove-struct-Lisp_Kboard_Objfwd.patch >From 6d42135f0ef647a41de26577dc62c3aca23c0865 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 16:36:13 +0200 Subject: [PATCH 5/6] Remove struct Lisp_Kboard_Objfwd * src/lisp.h (struct Lisp_Kboard_Objfwd): Deleted ... (struct Lisp_Fwd): ... replaced with field kbdoffset. (DEFVAR_KBOARD): Use new field. * src/data.c (XKBOARD_OFFSET): Renamed from XKBOARD_OBJFWD. (do_symval_forwarding, store_symval_forwarding (set_default_internal): Use it . --- src/data.c | 12 ++++++------ src/lisp.h | 17 ++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/data.c b/src/data.c index af4802f54a0..9f344474692 100644 --- a/src/data.c +++ b/src/data.c @@ -61,11 +61,11 @@ XBOOLVAR (lispfwd a) eassert (BOOLFWDP (a)); return a->u.boolvar; } -static struct Lisp_Kboard_Objfwd const * -XKBOARD_OBJFWD (lispfwd a) +static int +XKBOARD_OFFSET (lispfwd a) { eassert (KBOARD_OBJFWDP (a)); - return &a->u.kboardobjfwd; + return a->u.kbdoffset; } static intmax_t * XINTVAR (lispfwd a) @@ -1346,7 +1346,7 @@ do_symval_forwarding (lispfwd valcontents) XBUFFER_OBJFWD (valcontents)->offset); case Lisp_Fwd_Kboard_Obj: - return *(Lisp_Object *) (XKBOARD_OBJFWD (valcontents)->offset + return *(Lisp_Object *) (XKBOARD_OFFSET (valcontents) + (char *) kboard_for_bindings ()); default: emacs_abort (); } @@ -1497,7 +1497,7 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, case Lisp_Fwd_Kboard_Obj: { char *base = (char *) kboard_for_bindings (); - char *p = base + XKBOARD_OBJFWD (valcontents)->offset; + char *p = base + XKBOARD_OFFSET (valcontents); *(Lisp_Object *) p = newval; } break; @@ -2083,7 +2083,7 @@ set_default_internal (Lisp_Object symbol, Lisp_Object value, { char *base = (char *) (where ? where : kboard_for_bindings ()); - char *p = base + XKBOARD_OBJFWD (valcontents)->offset; + char *p = base + XKBOARD_OFFSET (valcontents); *(Lisp_Object *) p = value; } else diff --git a/src/lisp.h b/src/lisp.h index d0eef3e4aa1..2dc3530337b 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3167,13 +3167,6 @@ #define INT_TO_INTEGER(expr) \ Lisp_Object valcell; }; -/* Like Lisp_Objfwd except that value lives in a slot in the - current kboard. */ -struct Lisp_Kboard_Objfwd - { - int offset; - }; - struct Lisp_Fwd { enum Lisp_Fwd_Type type; @@ -3183,7 +3176,7 @@ #define INT_TO_INTEGER(expr) \ bool *boolvar; Lisp_Object *objvar; struct Lisp_Buffer_Objfwd bufobjfwd; - struct Lisp_Kboard_Objfwd kboardobjfwd; + int kbdoffset; } u; }; @@ -3608,14 +3601,12 @@ #define DEFVAR_INT(lname, vname, doc) \ defvar_int (&i_fwd, lname); \ } while (false) #define DEFVAR_KBOARD(lname, vname, doc) \ -do \ - { \ + do { \ static struct Lisp_Fwd const ko_fwd \ = { Lisp_Fwd_Kboard_Obj, \ - .u.kboardobjfwd = {offsetof (KBOARD, vname##_)}}; \ + .u.kbdoffset = offsetof (KBOARD, vname##_)}; \ defvar_kboard (&ko_fwd, lname); \ - } \ -while (false) + } while (false) /* Elisp uses multiple stacks: -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0006-Remove-struct-Lisp_Buffer_Objfwd.patch >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 --=-=-=--