Inline functions to examine and change buffer intervals.
[bpt/emacs.git] / src / buffer.c
index c017db7..fab7330 100644 (file)
@@ -19,6 +19,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#define BUFFER_INLINE EXTERN_INLINE
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
@@ -56,7 +58,7 @@ struct buffer *all_buffers;
    Setting the default value also goes through the alist of buffers
    and stores into each buffer that does not say it has a local value.  */
 
-DECL_ALIGN (struct buffer, buffer_defaults);
+struct buffer alignas (GCALIGNMENT) buffer_defaults;
 
 /* A Lisp_Object pointer to the above, used for staticpro */
 
@@ -83,7 +85,7 @@ struct buffer buffer_local_flags;
 /* This structure holds the names of symbols whose values may be
    buffer-local.  It is indexed and accessed in the same way as the above. */
 
-DECL_ALIGN (struct buffer, buffer_local_symbols);
+struct buffer alignas (GCALIGNMENT) buffer_local_symbols;
 
 /* A Lisp_Object pointer to the above, used for staticpro */
 static Lisp_Object Vbuffer_local_symbols;
@@ -97,7 +99,7 @@ static Lisp_Object Vbuffer_local_symbols;
 /* Maximum length of an overlay vector.  */
 #define OVERLAY_COUNT_MAX                                              \
   ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM,                              \
-                   min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)))
+                   min (PTRDIFF_MAX, SIZE_MAX) / word_size))
 
 /* Flags indicating which built-in buffer-local variables
    are permanent locals.  */
@@ -358,7 +360,7 @@ even if it is dead.  The return value is never nil.  */)
   BUF_CHARS_MODIFF (b) = 1;
   BUF_OVERLAY_MODIFF (b) = 1;
   BUF_SAVE_MODIFF (b) = 1;
-  BUF_INTERVALS (b) = 0;
+  buffer_set_intervals (b, NULL);
   BUF_UNCHANGED_MODIFIED (b) = 1;
   BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
   BUF_END_UNCHANGED (b) = 0;
@@ -382,7 +384,7 @@ even if it is dead.  The return value is never nil.  */)
   BVAR (b, zv_marker) = Qnil;
 
   name = Fcopy_sequence (buffer_or_name);
-  STRING_SET_INTERVALS (name, NULL_INTERVAL);
+  string_set_intervals (name, NULL);
   BVAR (b, name) = name;
 
   BVAR (b, undo_list) = (SREF (name, 0) != ' ') ? Qnil : Qt;
@@ -587,7 +589,7 @@ CLONE nil means the indirect buffer's state is reset to default values.  */)
   all_buffers = b;
 
   name = Fcopy_sequence (name);
-  STRING_SET_INTERVALS (name, NULL_INTERVAL);
+  string_set_intervals (name, NULL);
   BVAR (b, name) = name;
 
   reset_buffer (b);
@@ -658,7 +660,8 @@ static void
 drop_overlay (struct buffer *b, struct Lisp_Overlay *ov)
 {
   eassert (b == XBUFFER (Fmarker_buffer (ov->start)));
-  modify_overlay (b, marker_position (ov->start), marker_position (ov->end));
+  modify_overlay (b, marker_position (ov->start),
+                 marker_position (ov->end));
   Fset_marker (ov->start, Qnil, Qnil);
   Fset_marker (ov->end, Qnil, Qnil);
 
@@ -1446,7 +1449,7 @@ compact_buffer (struct buffer *buffer)
 
   /* Skip dead buffers, indirect buffers and buffers
      which aren't changed since last compaction.  */
-  if (!NILP (buffer->BUFFER_INTERNAL_FIELD (name))
+  if (!NILP (buffer->INTERNAL_FIELD (name))
       && (buffer->base_buffer == NULL)
       && (buffer->text->compact != buffer->text->modiff))
     {
@@ -1454,7 +1457,7 @@ compact_buffer (struct buffer *buffer)
         turned off in that buffer.  Calling truncate_undo_list on
         Qt tends to return NULL, which effectively turns undo back on.
         So don't call truncate_undo_list if undo_list is Qt.  */
-      if (!EQ (buffer->BUFFER_INTERNAL_FIELD (undo_list), Qt))
+      if (!EQ (buffer->INTERNAL_FIELD (undo_list), Qt))
        truncate_undo_list (buffer);
 
       /* Shrink buffer gaps.  */
@@ -1560,14 +1563,6 @@ cleaning up all windows currently displaying the buffer to be killed. */)
   if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
     return Qnil;
 
-  /* Notify our base buffer that we don't share the text anymore.  */
-  if (b->base_buffer)
-    {
-      eassert (b->indirections == -1);
-      b->base_buffer->indirections--;
-      eassert (b->base_buffer->indirections >= 0);
-    }
-
   /* When we kill an ordinary buffer which shares it's buffer text
      with indirect buffer(s), we must kill indirect buffer(s) too.
      We do it at this stage so nothing terrible happens if they
@@ -1693,7 +1688,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
          m = next;
        }
       BUF_MARKERS (b) = NULL;
-      BUF_INTERVALS (b) = NULL_INTERVAL;
+      buffer_set_intervals (b, NULL);
 
       /* Perhaps we should explicitly free the interval tree here... */
     }
@@ -1708,7 +1703,15 @@ cleaning up all windows currently displaying the buffer to be killed. */)
   BVAR (b, name) = Qnil;
 
   BLOCK_INPUT;
-  if (! b->base_buffer)
+  if (b->base_buffer)
+    {
+      /* Notify our base buffer that we don't share the text anymore.  */
+      eassert (b->indirections == -1);
+      b->base_buffer->indirections--;
+      eassert (b->base_buffer->indirections >= 0);
+    }
+  else
+    /* No one shares our buffer text, can free it.  */
     free_buffer_text (b);
 
   if (b->newline_cache)
@@ -1764,8 +1767,8 @@ record_buffer (Lisp_Object buffer)
   Vinhibit_quit = tem;
 
   /* Update buffer list of selected frame.  */
-  f->buffer_list = Fcons (buffer, Fdelq (buffer, f->buffer_list));
-  f->buried_buffer_list = Fdelq (buffer, f->buried_buffer_list);
+  FSET (f, buffer_list, Fcons (buffer, Fdelq (buffer, f->buffer_list)));
+  FSET (f, buried_buffer_list, Fdelq (buffer, f->buried_buffer_list));
 
   /* Run buffer-list-update-hook.  */
   if (!NILP (Vrun_hooks))
@@ -1802,8 +1805,9 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
   Vinhibit_quit = tem;
 
   /* Update buffer lists of selected frame.  */
-  f->buffer_list = Fdelq (buffer, f->buffer_list);
-  f->buried_buffer_list = Fcons (buffer, Fdelq (buffer, f->buried_buffer_list));
+  FSET (f, buffer_list, Fdelq (buffer, f->buffer_list));
+  FSET (f, buried_buffer_list,
+       Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
 
   /* Run buffer-list-update-hook.  */
   if (!NILP (Vrun_hooks))
@@ -2193,7 +2197,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
            && (EQ (XWINDOW (w)->buffer, buf1)
                || EQ (XWINDOW (w)->buffer, buf2)))
          Fset_marker (XWINDOW (w)->pointm,
-                      make_number (BUF_BEGV (XBUFFER (XWINDOW (w)->buffer))),
+                      make_number
+                      (BUF_BEGV (XBUFFER (XWINDOW (w)->buffer))),
                       XWINDOW (w)->buffer);
        w = Fnext_window (w, Qt, Qt);
       }
@@ -4086,8 +4091,8 @@ VALUE will be returned.*/)
       }
   /* It wasn't in the list, so add it to the front.  */
   changed = !NILP (value);
-  XOVERLAY (overlay)->plist
-    = Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist));
+  set_overlay_plist
+    (overlay, Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist)));
  found:
   if (! NILP (buffer))
     {
@@ -4262,7 +4267,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
     ptrdiff_t i;
 
     memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
-           size * sizeof (Lisp_Object));
+           size * word_size);
     gcpro1.var = copy;
     gcpro1.nvars = size;
 
@@ -4881,8 +4886,7 @@ init_buffer_once (void)
      sure that this is still correct.  Otherwise, mark_vectorlike may not
      trace all Lisp_Objects in buffer_defaults and buffer_local_symbols.  */
   const int pvecsize
-    = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header))
-    / sizeof (Lisp_Object);
+    = (offsetof (struct buffer, own_text) - header_size) / word_size;
 
   memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
 
@@ -4897,8 +4901,11 @@ init_buffer_once (void)
   /* Prevent GC from getting confused.  */
   buffer_defaults.text = &buffer_defaults.own_text;
   buffer_local_symbols.text = &buffer_local_symbols.own_text;
-  BUF_INTERVALS (&buffer_defaults) = 0;
-  BUF_INTERVALS (&buffer_local_symbols) = 0;
+  /* No one will share the text with these buffers, but let's play it safe.  */
+  buffer_defaults.indirections = 0;
+  buffer_local_symbols.indirections = 0;
+  buffer_set_intervals (&buffer_defaults, NULL);
+  buffer_set_intervals (&buffer_local_symbols, NULL);
   XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
   XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
   XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
@@ -4964,7 +4971,7 @@ init_buffer_once (void)
      The local flag bits are in the local_var_flags slot of the buffer.  */
 
   /* Nothing can work if this isn't true */
-  { verify (sizeof (EMACS_INT) == sizeof (Lisp_Object)); }
+  { verify (sizeof (EMACS_INT) == word_size); }
 
   /* 0 means not a lisp var, -1 means always local, else mask */
   memset (&buffer_local_flags, 0, sizeof buffer_local_flags);
@@ -5209,7 +5216,7 @@ syms_of_buffer (void)
   DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions");
 
   Fput (Qprotected_field, Qerror_conditions,
-       pure_cons (Qprotected_field, pure_cons (Qerror, Qnil)));
+       listn (CONSTYPE_PURE, 2, Qprotected_field, Qerror));
   Fput (Qprotected_field, Qerror_message,
        build_pure_c_string ("Attempt to modify a protected field"));
 
@@ -5454,17 +5461,17 @@ Use the command `abbrev-mode' to change this variable.  */);
                     doc: /* Non-nil if searches and matches should ignore case.  */);
 
   DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column),
-                    make_number (LISP_INT_TAG),
+                    make_number (Lisp_Int0),
                     doc: /* Column beyond which automatic line-wrapping should happen.
 Interactively, you can set the buffer local value using \\[set-fill-column].  */);
 
   DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer, left_margin),
-                    make_number (LISP_INT_TAG),
+                    make_number (Lisp_Int0),
                     doc: /* Column for the default `indent-line-function' to indent to.
 Linefeed indents to this column in Fundamental mode.  */);
 
   DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer, tab_width),
-                    make_number (LISP_INT_TAG),
+                    make_number (Lisp_Int0),
                     doc: /* Distance between tab stops (for display of tab characters), in columns.
 This should be an integer greater than zero.  */);
 
@@ -5585,7 +5592,7 @@ If it is nil, that means don't auto-save this buffer.  */);
 Backing up is done before the first time the file is saved.  */);
 
   DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer, save_length),
-                    make_number (LISP_INT_TAG),
+                    make_number (Lisp_Int0),
                     doc: /* Length of current buffer when last read in, saved or auto-saved.
 0 initially.
 -1 means auto-saving turned off until next real save.