Subject: Re: bug#24368: 25.1; Assertion failure in attach_marker

From: martin rudalics <[email-masked]>
Date: Mon, 05 Sep 2016 19:58:19 +0200

>> How?  In attach_frame, the buffer where the positions came from is not
 >> known.
 >
 > It looks like the callers already take care of that?  Or did you find
 > a case where this is not happening?

How would you then explain the assertion failure I reported initially?

 >> Anyway, I passed an extra boolean to attach_marker to fix that
 >> and now I get a similar assertion violation in temp_set_point_both.
 >> This is a can of worms :-(
 >
 > Sorry, I guess you lost me: what did you try to fix and how?

I applied the attached patch.

martin
diff --git a/src/marker.c b/src/marker.c
index febdb17..92ba7dd 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -426,11 +426,12 @@ DEFUN ("marker-position", Fmarker_position, Smarker_position, 1, 1, 0,

 static void
 attach_marker (struct Lisp_Marker *m, struct buffer *b,
-	       ptrdiff_t charpos, ptrdiff_t bytepos)
+	       ptrdiff_t charpos, ptrdiff_t bytepos,
+	       bool from_other_buffer)
 {
   /* In a single-byte buffer, two positions must be equal.
      Otherwise, every character is at least one byte.  */
-  if (BUF_Z (b) == BUF_Z_BYTE (b))
+  if ((!from_other_buffer) && (BUF_Z (b) == BUF_Z_BYTE (b)))
     eassert (charpos == bytepos);
   else
     eassert (charpos <= bytepos);
@@ -514,7 +515,10 @@ set_marker_internal (Lisp_Object marker, Lisp_Object position,
 	  (restricted ? BUF_BEGV_BYTE (b) : BUF_BEG_BYTE (b),
 	   bytepos, restricted ? BUF_ZV_BYTE (b) : BUF_Z_BYTE (b));

-      attach_marker (m, b, charpos, bytepos);
+      attach_marker (m, b, charpos, bytepos,
+		     MARKERP (position)
+		     ? b != XMARKER (position)->buffer
+		     : false);
     }
   return marker;
 }
@@ -552,7 +556,7 @@ set_marker_both (Lisp_Object marker, Lisp_Object buffer,
   m = XMARKER (marker);

   if (b)
-    attach_marker (m, b, charpos, bytepos);
+    attach_marker (m, b, charpos, bytepos, false);
   else
     unchain_marker (m);
   return marker;
@@ -575,7 +579,8 @@ set_marker_restricted_both (Lisp_Object marker, Lisp_Object buffer,
       attach_marker
 	(m, b,
 	 clip_to_bounds (BUF_BEGV (b), charpos, BUF_ZV (b)),
-	 clip_to_bounds (BUF_BEGV_BYTE (b), bytepos, BUF_ZV_BYTE (b)));
+	 clip_to_bounds (BUF_BEGV_BYTE (b), bytepos, BUF_ZV_BYTE (b)),
+	 false);
     }
   else
     unchain_marker (m);