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 21:59:38 +0200 Message-ID: <87tthjxwet.fsf@gmail.com> References: <878qyy1f55.fsf@gmail.com> <87o77szwif.fsf@gmail.com> <877cegzu5j.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="19681"; 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 22:00:35 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 1sLTO7-0004wv-1Q for ged-emacs-devel@m.gmane-mx.org; Sun, 23 Jun 2024 22:00:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLTNJ-0002m0-Uv; Sun, 23 Jun 2024 15:59:45 -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 1sLTNI-0002lb-Gw for emacs-devel@gnu.org; Sun, 23 Jun 2024 15:59:44 -0400 Original-Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLTNG-00030y-ML; Sun, 23 Jun 2024 15:59:44 -0400 Original-Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-57d1012e52fso4130854a12.3; Sun, 23 Jun 2024 12:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719172780; x=1719777580; 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=hsVyDXMU6QI+PDgeqNrUCV2gNG8s+hpaz16Y6w5z+hU=; b=lrbvF6h58RcTlOjoK7A5NYO7fdo7scIfKYm7GonfVBNwRnjRfPQZU7mn5h9uVJmtw8 bCwVS/IJLJQ6xGL4weSU0t2aaBacQXODG9QshWGIBnjZuDw84bcjuNsTiMxouqrRr6w1 j6S+togKIGTxsTNxA1i/5x48h1z5ZMe6jovrSSvoFmPjiBTYM51gAaL5SpaiRH6yO0+e w23N9wJKW83ai/0we/qri9OIbJJIXw9pjaUm+LjBbq/G6dojz7OYEhLTiNmcLcgmPteO ypOF0y4okG/6gu9rCHMjIWLgPK1Dvk7GkuFCOj8AyaM9VkIVKJZecX07NFW66uYh8LDI pmKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719172780; x=1719777580; 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=hsVyDXMU6QI+PDgeqNrUCV2gNG8s+hpaz16Y6w5z+hU=; b=XYnqzXAnZpF6hoDxXclJyn/a3GKqW/v99jGQ3Use3xFkWMFXSM5dMrGACpm2fmNsY7 0xhgUFWnM4S7MEM/Fw5MA2+R7WVc2KgYt1P9pO1PB6e5HHn23Z42sR1kr5pLYyoI9QxI UIkSDLX2Lr4JwZripgDbe+9/rM3DjaBSyu5jqbd1xUsDOqIAbv+0XsIXn7zmiCistHLx ccyqaTwN8DL1kMbENHsPxt5UFQI9sW4GuiDIUmEI6DwJwp0vxyPn6pSPZO4KCTqtR6WR rbQqVGyXraSX9SHMJ6OnWqj37cT5p6ba4fuTk8MUsaf/cz8vCeZYyiH1E8uLfWVi4/dz raPw== X-Forwarded-Encrypted: i=1; AJvYcCVenilE2pJyEA7NzXqS1TMVAyMahVSDPPEZQ0skV3HEXOMz1EWjQmVUggMZI0BDbvOZsPlg7gQfBtG6eu4= X-Gm-Message-State: AOJu0YyO9ep+tfHy6Mgpdhss9kT2dDwsAtWOZ98zfyT4PVNEt2xzaNI8 bqBUUybIGSkCICL/4oJtVz51hBnpiWDi4zTnG3dN171JGebDbf81U050Ig== X-Google-Smtp-Source: AGHT+IF9nRnyHPAdlatzd8W9O4HnPkcWanFyd70/25XyOdmrrDsP9/Qhxb74ogakh9ry+trHF68Tzw== X-Received: by 2002:a50:cc85:0:b0:57c:c166:ba6 with SMTP id 4fb4d7f45d1cf-57d4bd77304mr1686187a12.19.1719172779968; Sun, 23 Jun 2024 12:59:39 -0700 (PDT) Original-Received: from caladan ([31.177.116.19]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d30536dcesm3815328a12.63.2024.06.23.12.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jun 2024 12:59:39 -0700 (PDT) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llman?= =?utf-8?Q?n=22's?= message of "Sat, 22 Jun 2024 21:26:31 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=eller.helmut@gmail.com; helo=mail-ed1-x529.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:320569 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Jun 22 2024, Gerd M=C3=B6llmann wrote: >> The symbol is needed in store_symval_forwarding. It looks in the plist >> for 'choice and 'range. In addition to the five symbols mentioned in >> the definition of Lisp_Buffer_Objfwd, predicate can also be >> 'overwrite-mode, 'vertical-scroll-bar and 'fraction. I think those have >> those properties; weird. > > I guess then it's better to leave the enum part out. That seems to > become too much work. What an ugly corner. Here is an attempt to use an enum. I'm not sure that it's easier to read and the enum constants have odd names. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Introduce-an-enum-Lisp_Fwd_Predicate.patch >From ad356aea9eb894baec5541d2203e97a0f42e382e Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 23 Jun 2024 21:46:16 +0200 Subject: [PATCH] Introduce an enum Lisp_Fwd_Predicate Using an enum instead of a symbol makes it obvious that this field is of no concern to the GC. * src/lisp.h (enum Lisp_Fwd_Predicate): New. (struct Lisp_Fwd): Use it instead of a symbol. * src/buffer.c (DEFVAR_PER_BUFFER): Create the necessary enum constant instead of a symbol. * src/data.c (check_fwd_predicate, check_choice): New helpers. (store_symval_forwarding): Use it. --- src/buffer.c | 22 ++++++-------- src/data.c | 83 ++++++++++++++++++++++++++++++++++------------------ src/lisp.h | 17 ++++++++--- 3 files changed, 77 insertions(+), 45 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index ae5016df50e..39b5e29067a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5017,19 +5017,15 @@ init_buffer (void) that nil is allowed too). DOC is a dummy where you write the doc string as a comment. */ -/* 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, \ - .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); \ +#define DEFVAR_PER_BUFFER(lname, vname, predicate, doc) \ + do { \ + static const struct Lisp_Fwd bo_fwd \ + = { .type = Lisp_Fwd_Buffer_Obj, \ + .bufoffset = offsetof (struct buffer, vname##_), \ + .u.bufpredicate = FWDPRED_##predicate }; \ + static_assert (offsetof (struct buffer, vname##_) \ + < (1 << 8 * sizeof bo_fwd.bufoffset)); \ + defvar_per_buffer (&bo_fwd, lname); \ } while (0) static void diff --git a/src/data.c b/src/data.c index e0133d81771..9fd439e07b5 100644 --- a/src/data.c +++ b/src/data.c @@ -1399,6 +1399,59 @@ wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong) wrong); } +static void +check_choice (Lisp_Object choice, Lisp_Object val) +{ + eassert (CONSP (choice)); + if (NILP (Fmemq (val, choice))) + wrong_choice (choice, val); +} + +static void +check_fwd_predicate (enum Lisp_Fwd_Predicate p, Lisp_Object val) +{ + switch (p) + { + case FWDPRED_Qnil: + return; + case FWDPRED_Qstringp: + if (!STRINGP (val)) + wrong_type_argument (Qstringp, val); + return; + case FWDPRED_Qsymbolp: + if (!SYMBOLP (val)) + wrong_type_argument (Qsymbolp, val); + return; + case FWDPRED_Qintegerp: + if (!INTEGERP (val)) + wrong_type_argument (Qintegerp, val); + return; + case FWDPRED_Qnumberp: + if (!NUMBERP (val)) + wrong_type_argument (Qnumberp, val); + return; + case FWDPRED_Qfraction: + { + if (!NUMBERP (val)) + wrong_type_argument (Qnumberp, val); + Lisp_Object range = Fget (Qfraction, Qrange); + eassert (CONSP (range)); + Lisp_Object min = XCAR (range); + Lisp_Object max = XCDR (range); + if (NILP (CALLN (Fleq, min, val, max))) + wrong_range (min, max, val); + } + return; + case FWDPRED_Qvertical_scroll_bar: + check_choice (Fget (Qvertical_scroll_bar, Qchoice), val); + return; + case FWDPRED_Qoverwrite_mode: + check_choice (Fget (Qoverwrite_mode, Qchoice), val); + return; + } + emacs_abort (); +} + /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the buffer-independent contents of the value cell: forwarded just one @@ -1459,34 +1512,8 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, case Lisp_Fwd_Buffer_Obj: { int offset = XBUFFER_OFFSET (valcontents); - Lisp_Object predicate = valcontents->u.bufpredicate; - - if (!NILP (newval) && !NILP (predicate)) - { - eassert (SYMBOLP (predicate)); - Lisp_Object choiceprop = Fget (predicate, Qchoice); - if (!NILP (choiceprop)) - { - if (NILP (Fmemq (newval, choiceprop))) - wrong_choice (choiceprop, newval); - } - else - { - Lisp_Object rangeprop = Fget (predicate, Qrange); - if (CONSP (rangeprop)) - { - Lisp_Object min = XCAR (rangeprop), max = XCDR (rangeprop); - if (! NUMBERP (newval) - || NILP (CALLN (Fleq, min, newval, max))) - wrong_range (min, max, newval); - } - else if (FUNCTIONP (predicate)) - { - if (NILP (call1 (predicate, newval))) - wrong_type_argument (predicate, newval); - } - } - } + if (!NILP (newval)) + check_fwd_predicate (valcontents->u.bufpredicate, newval); if (buf == NULL) buf = current_buffer; set_per_buffer_value (buf, offset, newval); diff --git a/src/lisp.h b/src/lisp.h index c20bc9aa76e..e3c2dce7df0 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3158,6 +3158,18 @@ #define INT_TO_INTEGER(expr) \ Lisp_Object valcell; }; +enum Lisp_Fwd_Predicate +{ + FWDPRED_Qnil, + FWDPRED_Qintegerp, + FWDPRED_Qsymbolp, + FWDPRED_Qstringp, + FWDPRED_Qnumberp, + FWDPRED_Qfraction, + FWDPRED_Qvertical_scroll_bar, + FWDPRED_Qoverwrite_mode, +}; + /* A struct Lisp_Fwd is used to locate a variable. See Lisp_Fwd_Type for the various types of variables. @@ -3174,10 +3186,7 @@ #define INT_TO_INTEGER(expr) \ intmax_t *intvar; bool *boolvar; Lisp_Object *objvar; - /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp, Qnumberp, - Qfraction, Qvertical_scroll_bar, or Qoverwrite_mode. - */ - Lisp_Object bufpredicate; + enum Lisp_Fwd_Predicate bufpredicate; int kbdoffset; } u; }; -- 2.39.2 --=-=-=--