Subject: bug#9006: 24.0.50; Abort in unshow_buffer/kill-buffer

From: martin rudalics <[email-masked]>
Date: Mon, 11 Jul 2011 21:14:07 +0200

> I applied the patch and rebuilt Emacs, then started with my
 > initializations under gdb.  Emacs came up fine, then I type C-h C-a and
 > it aborted in unshow_buffer; the backtrace is almost identical to the
 > one I posted previously.

Why am I not surprised?  Though, it doesn't abort here.

 > Then I started Emacs again, started Gnus, as
 > with your first suggested patch with set_marker_both (w->buffer, BEG,
 > BEGV)

I suppose you mean set_marker_both (w->pointm, w->buffer, BEG, BEGV)
here.

 > the display was unstable (unselected window at first blank, then
 > blank fringe), then tried `h' and it worked a few times but the response
 > was slow, and then (after `h' not C-g) Emacs aborted in unshow_buffer;
 > backtrace below.  Just out of curiosity (since I don't understand the
 > code), I rebuilt again with the following call (old_buffer instead of
 > w->buffer):
 >
 >        set_marker_both
 >  	(w->pointm, old_buffer, BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer));
 >
 > This did not cause an abort with C-h C-a nor with h in Gnus, but it
 > showed the same problem of point in the non-selected window jumping to
 > point-min, despite not passing BEG and BEGV.

The strange thing about this is that when old_buffer is not the current
buffer, this will set the marker in the wrong buffer which should cause
an abort.  But as I stated earlier I'm still completely lost here :-(

Anyway, I attached another patch.  Things are getting more and more
complicated because I have zero experience working with markers in C.

martin
=== modified file 'src/indent.c'
*** src/indent.c	2011-07-10 08:20:10 +0000
--- src/indent.c	2011-07-11 19:05:41 +0000
***************
*** 1985,1991 ****
    struct text_pos pt;
    struct window *w;
    Lisp_Object old_buffer;
!   struct gcpro gcpro1;
    Lisp_Object lcols = Qnil;
    double cols IF_LINT (= 0);
  
--- 1985,1992 ----
    struct text_pos pt;
    struct window *w;
    Lisp_Object old_buffer;
!   EMACS_INT old_charpos, old_bytepos;
!   struct gcpro gcpro1, gcpro2, gcpro3;
    Lisp_Object lcols = Qnil;
    double cols IF_LINT (= 0);
  
***************
*** 2005,2016 ****
    w = XWINDOW (window);
  
    old_buffer = Qnil;
!   GCPRO1 (old_buffer);
    if (XBUFFER (w->buffer) != current_buffer)
      {
        /* Set the window's buffer temporarily to the current buffer.  */
        old_buffer = w->buffer;
        XSETBUFFER (w->buffer, current_buffer);
      }
  
    if (noninteractive)
--- 2006,2021 ----
    w = XWINDOW (window);
  
    old_buffer = Qnil;
!   GCPRO3 (old_buffer, old_charpos, old_bytepos);
    if (XBUFFER (w->buffer) != current_buffer)
      {
        /* Set the window's buffer temporarily to the current buffer.  */
        old_buffer = w->buffer;
+       old_charpos = XMARKER (w->pointm)->charpos;
+       old_bytepos = XMARKER (w->pointm)->bytepos;
        XSETBUFFER (w->buffer, current_buffer);
+       set_marker_both
+ 	(w->pointm, w->buffer, BUF_PT (current_buffer), BUF_PT_BYTE (current_buffer));
      }
  
    if (noninteractive)
***************
*** 2131,2137 ****
      }
  
    if (BUFFERP (old_buffer))
!     w->buffer = old_buffer;
  
    RETURN_UNGCPRO (make_number (it.vpos));
  }
--- 2136,2145 ----
      }
  
    if (BUFFERP (old_buffer))
!     {
!       w->buffer = old_buffer;
!       set_marker_both (w->pointm, w->buffer, old_charpos, old_bytepos);
!     }
  
    RETURN_UNGCPRO (make_number (it.vpos));
  }