From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.devel Subject: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding Date: Thu, 19 Nov 2020 10:38:13 -0500 Message-ID: <20201119153814.17541-10-sbaugh@catern.com> References: <87mtzil519.fsf@catern.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30952"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Spencer Baugh , Arnold Noronha , Stefan Monnier , Dmitry Gutov To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 19 16:39:36 2020 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 1kfm23-0007tl-8R for ged-emacs-devel@m.gmane-mx.org; Thu, 19 Nov 2020 16:39:35 +0100 Original-Received: from localhost ([::1]:48776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfm22-000748-80 for ged-emacs-devel@m.gmane-mx.org; Thu, 19 Nov 2020 10:39:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfm0t-0005MW-AY for emacs-devel@gnu.org; Thu, 19 Nov 2020 10:38:23 -0500 Original-Received: from venus.catern.com ([68.183.49.163]:54702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfm0q-0000eM-E2 for emacs-devel@gnu.org; Thu, 19 Nov 2020 10:38:22 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605800299; bh=RVMoFyWgCyyRtyy2yak/zB3IgM1zG4lCmEF/1lh/kYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aOCqslVJGKO0ps7lcxSRGOLhOD3jZ70CF3hO2tgD48RFXdszS951WILYxLeV9sF7O wdV3/Dk0eFvlQI78hiu79wwM0ZriwldrI/EnlEdaiHuE/xDf6fmihe0eBfFu9QoVbH VWatIhftvgmp9xIrhpaSSb9WNqF6hctuEUVXacYU= Original-Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id CF1A82DDABC; Thu, 19 Nov 2020 15:38:19 +0000 (UTC) X-Mailer: git-send-email 2.28.0 In-Reply-To: <87mtzil519.fsf@catern.com> Received-SPF: pass client-ip=68.183.49.163; envelope-from=sbaugh@catern.com; helo=venus.catern.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/19 09:22:08 X-ACL-Warn: Detected OS = Linux 3.11 and newer 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, 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.23 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" Xref: news.gmane.io gmane.emacs.devel:259432 Archived-At: In SHOULD_USE_BUFFER_DEFAULTS, we have to extract the buffer field index from buffer_local_flags. If the buffer_local_flags Lisp_Object is 0, though, it means this field in buffer_local_flags wasn't initialized, which means this field is always buffer-local (and therefore doesn't use buffer_defaults). Otherwise, it should be a fixnum. If it's less than 1, it also means that this field is always buffer-local, and we shouldn't use buffer_defaults. Finally, if it's 1 or greater, it's a valid index into local_flags. If local_flags is 0, that means there's no local value for this buffer variable. Which means we should use buffer_defaults. --- src/buffer.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/buffer.h b/src/buffer.h index 077edb893a..d0e44c35bb 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -825,9 +825,31 @@ set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value) *(Lisp_Object *)(offset + (char *) b) = value; } +INLINE bool +SHOULD_USE_BUFFER_DEFAULTS(struct buffer *b, ptrdiff_t offset) +{ + Lisp_Object obj = *((Lisp_Object *) (offset + (char *) &buffer_local_flags)); + if (obj.i == 0) + return false; + int idx = XFIXNUM(obj); + if (idx < 1) + return false; + return b->local_flags[idx] == 0; +} + +INLINE Lisp_Object +bvar_get(struct buffer *b, ptrdiff_t offset) +{ + if (SHOULD_USE_BUFFER_DEFAULTS(b, offset)) { + return per_buffer_value(&buffer_defaults, offset); + } else { + return per_buffer_value(b, offset); + } +} + /* Most code should use this macro to access Lisp fields in struct buffer. */ -#define BVAR(buf, field) ((void)0, (buf)->field ## _) +#define BVAR(buf, field) bvar_get(buf, PER_BUFFER_VAR_OFFSET (field)) /* Access a BVAR from buffer_defaults */ #define BVAR_DEFAULT(field) (buffer_defaults.field ## _) -- 2.28.0