* ralloc.c (r_alloc_reset_variable): New function.
authorJason Rumney <jasonr@gnu.org>
Wed, 24 Dec 2008 11:20:32 +0000 (11:20 +0000)
committerJason Rumney <jasonr@gnu.org>
Wed, 24 Dec 2008 11:20:32 +0000 (11:20 +0000)
* buffer.c (Fbuffer_swap_text) [REL_ALLOC]: Reset ralloc's internal
record of what points where.

src/ChangeLog
src/buffer.c
src/ralloc.c

index e7d44c3..56bb534 100644 (file)
@@ -1,3 +1,10 @@
+2008-12-24  Jason Rumney  <jasonr@gnu.org>
+
+       * ralloc.c (r_alloc_reset_variable): New function.
+
+       * buffer.c (Fbuffer_swap_text) [REL_ALLOC]: Reset ralloc's internal
+       record of what points where.
+
 2008-12-22  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * minibuf.c (read_minibuf): Follow the non-interactive case when
index 110cb4f..33667b7 100644 (file)
@@ -2182,6 +2182,10 @@ advance_to_char_boundary (byte_pos)
   return byte_pos;
 }
 
+#ifdef REL_ALLOC
+extern void r_alloc_reset_variable P_ ((PTR *, PTR *));
+#endif /* REL_ALLOC */
+
 DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
        1, 1, 0,
        doc: /* Swap the text between current buffer and BUFFER.  */)
@@ -2223,6 +2227,13 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
   swapfield (own_text, struct buffer_text);
   eassert (current_buffer->text == &current_buffer->own_text);
   eassert (other_buffer->text == &other_buffer->own_text);
+#ifdef REL_ALLOC
+  r_alloc_reset_variable ((PTR *) &current_buffer->own_text.beg,
+                         (PTR *) &other_buffer->own_text.beg);
+  r_alloc_reset_variable ((PTR *) &other_buffer->own_text.beg,
+                         (PTR *) &current_buffer->own_text.beg);
+#endif /* REL_ALLOC */
+
   swapfield (pt, EMACS_INT);
   swapfield (pt_byte, EMACS_INT);
   swapfield (begv, EMACS_INT);
index 30ed888..61f7aff 100644 (file)
@@ -1223,6 +1223,34 @@ r_alloc_check ()
 
 #endif /* DEBUG */
 
+/* Update the internal record of which variable points to some data to NEW.
+   Used by buffer-swap-text in Emacs to restore consistency after it
+   swaps the buffer text between two buffer objects.  The OLD pointer
+   is checked to ensure that memory corruption does not occur due to
+   misuse.  */
+void
+r_alloc_reset_variable (old, new)
+     POINTER *old, *new;
+{
+  bloc_ptr bloc = first_bloc;
+
+  /* Find the bloc that corresponds to the data pointed to by pointer.
+     find_bloc cannot be used, as it has internal consistency checks
+     which fail when the variable needs reseting.  */
+  while (bloc != NIL_BLOC)
+    {
+      if (bloc->data == *new)
+       break;
+
+      bloc = bloc->next;
+    }
+
+  if (bloc == NIL_BLOC || bloc->variable != old)
+    abort ();
+
+  /* Update variable to point to the new location.  */
+  bloc->variable = new;
+}
 
 \f
 /***********************************************************************