[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/10] Disallow using BVAR as an lvalue
From: |
Spencer Baugh |
Subject: |
[PATCH 06/10] Disallow using BVAR as an lvalue |
Date: |
Thu, 19 Nov 2020 10:38:10 -0500 |
This is a prerequisite for later changing BVAR into a function call.
buffer.c keeps the ability to directly access struct buffer Lisp
fields; it has to change to using the new local macro BVAR_DIRECT for
this. buffer.c exclusively uses this ability to access the special
struct buffer instances: buffer_local_flags, buffer_local_symbols, and
buffer_defaults. None of those should fall back to looking up
variables in buffer_defaults.
---
src/buffer.c | 104 ++++++++++++++++++++++++++-------------------------
src/buffer.h | 2 +-
2 files changed, 54 insertions(+), 52 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
index ba03fed3b9..6bcf1ad596 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -89,6 +89,8 @@ struct buffer buffer_local_symbols;
#define PER_BUFFER_SYMBOL(OFFSET) \
(*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_symbols))
+#define BVAR_DIRECT(buf, field) ((buf)->field ## _)
+
/* Maximum length of an overlay vector. */
#define OVERLAY_COUNT_MAX \
((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \
@@ -5183,53 +5185,53 @@ init_buffer_once (void)
bset_last_selected_window (&buffer_local_flags, make_fixnum (0));
idx = 1;
- XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, abbrev_mode), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, overwrite_mode), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx);
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, mode_line_format), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, abbrev_mode), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, overwrite_mode), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, case_fold_search), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, auto_fill_function), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, selective_display), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, selective_display_ellipses),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, tab_width), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, truncate_lines), idx);
/* Make this one a permanent local. */
buffer_permanent_local_flags[idx++] = 1;
- XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, ctl_arrow), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, fill_column), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, left_margin), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, cache_long_scans), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_separate_re), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_start_re), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, buffer_file_coding_system), idx);
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, word_wrap), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, ctl_arrow), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, fill_column), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, left_margin), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, abbrev_table), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, display_table), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, syntax_table), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, cache_long_scans), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, category_table), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, bidi_display_reordering),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, bidi_paragraph_direction),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, bidi_paragraph_separate_re),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, bidi_paragraph_start_re),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, buffer_file_coding_system),
idx);
/* Make this one a permanent local. */
buffer_permanent_local_flags[idx++] = 1;
- XSETFASTINT (BVAR (&buffer_local_flags, left_margin_cols), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, right_margin_cols), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, left_fringe_width), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, right_fringe_width), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, fringes_outside_margins), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, scroll_bar_width), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, scroll_bar_height), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, vertical_scroll_bar_type), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, horizontal_scroll_bar_type), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, indicate_empty_lines), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, indicate_buffer_boundaries), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, fringe_indicator_alist), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, fringe_cursor_alist), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, scroll_up_aggressively), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, scroll_down_aggressively), idx);
++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, header_line_format), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, tab_line_format), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, cursor_type), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx;
- XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, left_margin_cols), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, right_margin_cols), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, left_fringe_width), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, right_fringe_width), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, fringes_outside_margins),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, scroll_bar_width), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, scroll_bar_height), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, vertical_scroll_bar_type),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, horizontal_scroll_bar_type),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, indicate_empty_lines), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, indicate_buffer_boundaries),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, fringe_indicator_alist),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, fringe_cursor_alist), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, scroll_up_aggressively),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, scroll_down_aggressively),
idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, header_line_format), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, tab_line_format), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, cursor_type), idx); ++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags, extra_line_spacing), idx);
++idx;
+ XSETFASTINT (BVAR_DIRECT (&buffer_local_flags,
cursor_in_non_selected_windows), idx); ++idx;
/* buffer_local_flags contains no pointers, so it's safe to treat it
as a blob for pdumper. */
@@ -5244,9 +5246,9 @@ init_buffer_once (void)
/* Make sure all markable slots in buffer_defaults
are initialized reasonably, so mark_buffer won't choke. */
reset_buffer (&buffer_defaults);
- eassert (NILP (BVAR (&buffer_defaults, name)));
+ eassert (NILP (BVAR_DIRECT (&buffer_defaults, name)));
reset_buffer_local_variables (&buffer_defaults, 1);
- eassert (NILP (BVAR (&buffer_local_symbols, name)));
+ eassert (NILP (BVAR_DIRECT (&buffer_local_symbols, name)));
reset_buffer (&buffer_local_symbols);
reset_buffer_local_variables (&buffer_local_symbols, 1);
/* Prevent GC from getting confused. */
@@ -5289,7 +5291,7 @@ init_buffer_once (void)
set_buffer_overlays_after (&buffer_defaults, NULL);
buffer_defaults.overlay_center = BEG;
- XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8);
+ XSETFASTINT (BVAR_DIRECT (&buffer_defaults, tab_width), 8);
bset_truncate_lines (&buffer_defaults, Qnil);
bset_word_wrap (&buffer_defaults, Qnil);
bset_ctl_arrow (&buffer_defaults, Qt);
@@ -5303,13 +5305,13 @@ init_buffer_once (void)
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);
+ XSETFASTINT (BVAR_DIRECT (&buffer_defaults, fill_column), 70);
+ XSETFASTINT (BVAR_DIRECT (&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);
+ XSETFASTINT (BVAR_DIRECT (&buffer_defaults, display_count), 0);
+ XSETFASTINT (BVAR_DIRECT (&buffer_defaults, left_margin_cols), 0);
+ XSETFASTINT (BVAR_DIRECT (&buffer_defaults, right_margin_cols), 0);
bset_left_fringe_width (&buffer_defaults, Qnil);
bset_right_fringe_width (&buffer_defaults, Qnil);
bset_fringes_outside_margins (&buffer_defaults, Qnil);
diff --git a/src/buffer.h b/src/buffer.h
index 0b26c56e89..ae2d785aff 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -282,7 +282,7 @@ struct buffer_text
/* Most code should use this macro to access Lisp fields in struct buffer. */
-#define BVAR(buf, field) ((buf)->field ## _)
+#define BVAR(buf, field) ((void)0, (buf)->field ## _)
/* Access a BVAR from buffer_defaults */
#define BVAR_DEFAULT(field) (buffer_defaults.field ## _)
--
2.28.0
- Re: ido-switch-buffer is slow with many buffers; others are fast, (continued)
- Re: ido-switch-buffer is slow with many buffers; others are fast, Spencer Baugh, 2020/11/14
- Re: ido-switch-buffer is slow with many buffers; others are fast, Stefan Monnier, 2020/11/15
- Re: ido-switch-buffer is slow with many buffers; others are fast, Spencer Baugh, 2020/11/15
- Re: ido-switch-buffer is slow with many buffers; others are fast, Arnold Noronha, 2020/11/15
- [PATCH 02/10] Add bset_save_length and use it, Spencer Baugh, 2020/11/19
- [PATCH 04/10] Use bset_enable_multibyte_characters everywhere, Spencer Baugh, 2020/11/19
- [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER (Was: ido-switch-buffer is slow), Spencer Baugh, 2020/11/19
- Re: [PATCH 00/10] Speeding up DEFVAR_PER_BUFFER, Stefan Monnier, 2020/11/19
- [PATCH 03/10] Use bset_last_selected_window everywhere, Spencer Baugh, 2020/11/19
- [PATCH 01/10] Take buffer field name in DEFVAR_PER_BUFFER, Spencer Baugh, 2020/11/19
- [PATCH 06/10] Disallow using BVAR as an lvalue,
Spencer Baugh <=
- [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Spencer Baugh, 2020/11/19
- Re: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Stefan Monnier, 2020/11/19
- Re: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding, Eli Zaretskii, 2020/11/19
- [PATCH 05/10] Add BVAR_DEFAULT for access to buffer defaults, Spencer Baugh, 2020/11/19
- [PATCH 08/10] Make cache_long_scans buffer-local when setting it, Spencer Baugh, 2020/11/19
- [PATCH 07/10] Reorder buffer.h for upcoming rework of BVAR, Spencer Baugh, 2020/11/19
- [PATCH 10/10] Don't iterate over all buffers in set_default_internal, Spencer Baugh, 2020/11/19
- Re: [PATCH 10/10] Don't iterate over all buffers in set_default_internal, Stefan Monnier, 2020/11/19