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.bugs Subject: bug#48264: [PATCH v4 11/14] Set buffer_defaults fields without a default to Qunbound Date: Fri, 7 May 2021 22:09:02 -0400 Message-ID: <20210508020905.13583-13-sbaugh@catern.com> References: <20210506213346.9730-1-sbaugh@catern.com> <20210508020905.13583-1-sbaugh@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="6626"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Spencer Baugh To: 48264@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 08 04:50:08 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1lfD2e-0001Zm-M9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 May 2021 04:50:08 +0200 Original-Received: from localhost ([::1]:47294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfD2d-0002ky-Nz for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 May 2021 22:50:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfCPv-0001ML-EW for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 22:10:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfCPv-0007Zk-4h for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 22:10:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lfCPv-0006Ve-0J for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 22:10:07 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 08 May 2021 02:10:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48264 X-GNU-PR-Package: emacs Original-Received: via spool by 48264-submit@debbugs.gnu.org id=B48264.162043978524902 (code B ref 48264); Sat, 08 May 2021 02:10:06 +0000 Original-Received: (at 48264) by debbugs.gnu.org; 8 May 2021 02:09:45 +0000 Original-Received: from localhost ([127.0.0.1]:47181 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfCPY-0006TU-Gh for submit@debbugs.gnu.org; Fri, 07 May 2021 22:09:44 -0400 Original-Received: from venus.catern.com ([68.183.49.163]:47950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfCPG-0006Sa-C7 for 48264@debbugs.gnu.org; Fri, 07 May 2021 22:09:26 -0400 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=1620439765; bh=t1knBI2Ey3Z4g+LeC6FVD6cdXbxwEYJwDoVV7+tN6zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UwUpJ7WooUFgPG5B6vOOvgDOepwX6gAIZ0xwXt+owbqPt4tdBU21pkgJNk+dZRAWP wEJTlrOZZ8QkWS0uPAZyDTIEgAP3hgD1l61ccPM6rGWHg+LX1uCqekO8sSpEoLByjt FMqDgtpv4XDrZP6HpZb5WW+IDnEKpygnHIxl47EM= 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 7ACC92E9830; Sat, 8 May 2021 02:09:25 +0000 (UTC) X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210508020905.13583-1-sbaugh@catern.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:205982 Archived-At: In this way, we can be more sure that we aren't accidentally using these fields. We can also use the fact that fields without a default are set to Qunbound to implement BUFFER_DEFAULT_VALUE_P. * src/buffer.c (init_buffer_once): Set unused buffer_defaults fields to Qunbound. * src/buffer.h (BUFFER_DEFAULT_VALUE_P): Check if field is Qunbound to determine if there's a default. --- src/buffer.c | 42 ++++++++++++++++++++++++++++++------------ src/buffer.h | 6 ++++-- src/emacs.c | 4 ++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index a7d31c1e5b..a5606ce1d1 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -53,7 +53,9 @@ along with GNU Emacs. If not, see . */ /* This structure holds the default values of the buffer-local variables defined with DEFVAR_PER_BUFFER, that have special slots in each buffer. The default value occupies the same slot in this structure - as an individual buffer's value occupies in that buffer. */ + as an individual buffer's value occupies in that buffer. + Slots in this structure which are set to Qunbound are permanently + buffer-local. */ struct buffer buffer_defaults; @@ -5251,6 +5253,10 @@ init_buffer_once (void) /* Set up the default values of various buffer slots. */ /* Must do these before making the first buffer! */ + int offset; + FOR_EACH_PER_BUFFER_OBJECT_AT (offset) + set_per_buffer_default (offset, Qunbound); + set_per_buffer_default (PER_BUFFER_VAR_OFFSET (undo_list), Qunbound); /* real setup is done in bindings.el */ bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-")); @@ -5264,13 +5270,9 @@ init_buffer_once (void) bset_selective_display_ellipses (&buffer_defaults, Qt); bset_abbrev_table (&buffer_defaults, Qnil); bset_display_table (&buffer_defaults, Qnil); - bset_undo_list (&buffer_defaults, Qnil); - bset_mark_active (&buffer_defaults, Qnil); - bset_file_format (&buffer_defaults, Qnil); - bset_auto_save_file_format (&buffer_defaults, Qt); - set_buffer_overlays_before (&buffer_defaults, NULL); - set_buffer_overlays_after (&buffer_defaults, NULL); - buffer_defaults.overlay_center = BEG; + /* Later further initialized by init_{syntax,category}_once. */ + BVAR (&buffer_defaults, syntax_table) = Qnil; + BVAR (&buffer_defaults, category_table) = Qnil; XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8); bset_truncate_lines (&buffer_defaults, Qnil); @@ -5284,13 +5286,10 @@ init_buffer_once (void) bset_extra_line_spacing (&buffer_defaults, Qnil); bset_cursor_in_non_selected_windows (&buffer_defaults, Qt); - bset_enable_multibyte_characters (&buffer_defaults, Qt); bset_buffer_file_coding_system (&buffer_defaults, Qnil); XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); bset_cache_long_scans (&buffer_defaults, Qt); - bset_file_truename (&buffer_defaults, Qnil); - XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0); bset_left_fringe_width (&buffer_defaults, Qnil); @@ -5306,7 +5305,6 @@ init_buffer_once (void) bset_fringe_cursor_alist (&buffer_defaults, Qnil); bset_scroll_up_aggressively (&buffer_defaults, Qnil); bset_scroll_down_aggressively (&buffer_defaults, Qnil); - bset_display_time (&buffer_defaults, Qnil); /* Assign the local-flags to the slots that have default values. The local flag is a bit that is used in the buffer @@ -5332,6 +5330,26 @@ init_buffer_once (void) DEFSYM (Qkill_buffer_hook, "kill-buffer-hook"); Fput (Qkill_buffer_hook, Qpermanent_local, Qt); + /* Sanity check that we didn't set the default for slots which + are permanent-buffer-locals. */ + eassert (EQ (BVAR (&buffer_defaults, filename), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, directory), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, backed_up), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, save_length), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, auto_save_file_name), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, read_only), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, mode_name), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, undo_list), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, mark_active), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, point_before_scroll), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, file_truename), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, invisibility_spec), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, file_format), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, auto_save_file_format), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, display_count), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, display_time), Qunbound)); + eassert (EQ (BVAR (&buffer_defaults, enable_multibyte_characters), Qunbound)); + /* Super-magic invisible buffer. */ Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"), Qt); diff --git a/src/buffer.h b/src/buffer.h index 0445fe0edf..728dbb5272 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1101,7 +1101,9 @@ BUFFER_CHECK_INDIRECTION (struct buffer *b) /* This structure holds the default values of the buffer-local variables that have special slots in each buffer. The default value occupies the same slot in this structure - as an individual buffer's value occupies in that buffer. */ + as an individual buffer's value occupies in that buffer. + Slots in this structure which are set to Qunbound are permanently + buffer-local. */ extern struct buffer buffer_defaults; @@ -1473,7 +1475,7 @@ set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value) INLINE bool BVAR_HAS_DEFAULT_VALUE_P (int offset) { - return PER_BUFFER_IDX (offset) > 0; + return !EQ (per_buffer_default (offset), Qunbound); } /* Value is true if the variable with offset OFFSET has a local value diff --git a/src/emacs.c b/src/emacs.c index 9157cd84a9..a1ea9d8a8b 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1787,10 +1787,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_eval_once (); init_charset_once (); init_coding_once (); - init_syntax_once (); /* Create standard syntax table. */ - init_category_once (); /* Create standard category table. */ init_casetab_once (); /* Must be done before init_buffer_once. */ init_buffer_once (); /* Create buffer table and some buffers. */ + init_syntax_once (); /* Create standard syntax table. */ + init_category_once (); /* Create standard category table. */ init_minibuf_once (); /* Create list of minibuffers. */ /* Must precede init_window_once. */ -- 2.31.1