emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding


From: Spencer Baugh
Subject: [PATCH 09/10] Access buffer_defaults in BVAR if there's no local binding
Date: Thu, 19 Nov 2020 10:38:13 -0500

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]