From xemacs-m  Wed Aug 13 06:32:26 1997
Received: from gol1.gol.com (gol1.gol.com [202.243.48.4])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id GAA20810
	for <xemacs-beta@xemacs.org>; Wed, 13 Aug 1997 06:32:24 -0500 (CDT)
Received: from pentagana.camelot.jp (tc-1-001.tokyo.gol.ne.jp [203.216.9.1])
	by gol1.gol.com (8.8.7/8.8.7) with ESMTP id UAA03542
	for <xemacs-beta@xemacs.org>; Wed, 13 Aug 1997 20:31:05 +0900 (JST)
Received: (from jhod@localhost)
	by pentagana.camelot.jp (8.8.6/8.8.6) id PAA21948;
	Wed, 13 Aug 1997 15:23:25 +0900
To: XEmacs Beta Mailing List <xemacs-beta@xemacs.org>
Subject: [patch] Fix for bug in insdel.c
From: jareth@camelot-soft.com (P. E. Jareth Hein)
Mime-Version: 1.0 (generated by tm-edit 1.1.1.1)
Content-Type: multipart/mixed;
 boundary="Multipart_Wed_Aug_13_15:23:24_1997-1"
Content-Transfer-Encoding: 7bit
Date: 13 Aug 1997 15:23:24 +0900
Message-ID: <ohvi1alhyb.fsf@pentagana.camelot.jp>
Lines: 88

--Multipart_Wed_Aug_13_15:23:24_1997-1
Content-Type: text/plain; charset=US-ASCII

Here's a patch that corrects a series of errors all over the
place.  The symptoms were an assert error with any of the VALID_BYTIND 
or VALID_BUFPOS functions, usually somewhere in the extents code.  The 
correction is simply changing the order of where things are shifted
around when a region is deleted.  After banging on it hard for a day,
I'm fairly sure it's safe, but I'd like some other environment
testing.

I'm not sure if this affects any of the crashes Karl reported earlier...

-- 
Jareth Hein
jareth@camelot-soft.com


--Multipart_Wed_Aug_13_15:23:24_1997-1
Content-Type: application/octet-stream; type=patch
Content-Disposition: attachment; filename="insdel.patch"
Content-Transfer-Encoding: 7bit

Index: src/ChangeLog
===================================================================
RCS file: /CVSroot/XEmacs/src/ChangeLog,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ChangeLog
--- ChangeLog	1997/08/12 14:25:43	1.1.1.1
+++ ChangeLog	1997/08/13 06:12:40
@@ -1,3 +1,9 @@
+1997-08-13  P E Jareth Hein  <jareth@camelot-soft.com>
+
+	* insdel.c (buffer_delete_range): Changed the location where point
+ 	was actually moved to after all other movement handling.  This
+ 	prevents a MULE related crash in VALID_BYTIND.
+
 1997-08-05  Jens-Ulrik Holger Petersen  <petersen@kurims.kyoto-u.ac.jp>
 
 	* eval.c (vars_of_eval): Updated docstring for `debug_on_error' to 
Index: src/insdel.c
===================================================================
RCS file: /CVSroot/XEmacs/src/insdel.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 insdel.c
--- insdel.c	1997/08/12 14:25:46	1.1.1.1
+++ insdel.c	1997/08/13 06:09:17
@@ -2678,15 +2678,12 @@
       BUF_MODIFF (buf)++;
       MARK_BUFFERS_CHANGED;
 
-      /* Relocate point as if it were a marker.  */
-      if (bi_from < BI_BUF_PT (buf))
-	{
-	  if (BI_BUF_PT (buf) < bi_to)
-	    JUST_SET_POINT (buf, from, bi_from);
-	  else
-	    JUST_SET_POINT (buf, BUF_PT (buf) - numdel,
-			    BI_BUF_PT (buf) - bc_numdel);
-	}
+      /* ### Point used to be modified here, but this causes problems with MULE,
+	 as point is used to calculate bytinds, and if the offset in bc_numdel causes
+	 point to move to a non first-byte location, causing some other function to 
+	 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after
+	  the other movements and adjustments, but before the gap is moved.
+	  -- jh 970813 */
 
       /* Detach any extents that are completely within the range [FROM, TO],
 	 if the extents are detachable.
@@ -2706,6 +2703,16 @@
       /* Relocate any extent endpoints just like markers. */
       adjust_extents_for_deletion (bufobj, bi_from, bi_to, BUF_GAP_SIZE (buf),
 				   bc_numdel, BUF_GAP_SIZE (buf));
+
+      /* Relocate point as if it were a marker.  */
+      if (bi_from < BI_BUF_PT (buf))
+	{
+	  if (BI_BUF_PT (buf) < bi_to)
+	    JUST_SET_POINT (buf, from, bi_from);
+	  else
+	    JUST_SET_POINT (buf, BUF_PT (buf) - numdel,
+			    BI_BUF_PT (buf) - bc_numdel);
+	}
 
       SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + bc_numdel);
       SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel);

--Multipart_Wed_Aug_13_15:23:24_1997-1--

