all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug of auto saving
@ 2003-06-10  7:03 Kenichi Handa
  2003-06-11  0:25 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Kenichi Handa @ 2003-06-10  7:03 UTC (permalink / raw)


It seems that my recent change as to auto saving revealed an
old bug.

Currently Fwrite_region has this code.

  /* Special kludge to simplify auto-saving.  */
  if (NILP (start))
    {
      XSETFASTINT (start, BEG);
      XSETFASTINT (end, Z);
    }

And we later calls annotations and per-write-conversion as this:

      res = call2 (XCAR (p), start, end);
or
      res = call2 (pre_write_conversion, start, end);

But, it doesn't pay attention to the case that a buffer is
narrowed.  In such a case, when the called Lisp functions
try to access the buffer region between START and END, an
error happens.

I think the attached change fixes this bug.  I'll install it
after testing it for a while.

---
Ken'ichi HANDA
handa@m17n.org

2003-06-10  Kenichi Handa  <handa@m17n.org>

	* fileio.c (build_annotations_unwind): Arg changed.  Restore
	narrowing if any.
	(Fwrite_region): For auto-saving, widen the buffer.

*** fileio.c.~1.487.~	Sat May 31 10:52:35 2003
--- fileio.c	Tue Jun 10 15:44:38 2003
***************
*** 4659,4674 ****
     -- K.Handa */
  
  static Lisp_Object
! build_annotations_unwind (buf)
!      Lisp_Object buf;
  {
    Lisp_Object tembuf;
  
!   if (XBUFFER (buf) == current_buffer)
!     return Qnil;
!   tembuf = Fcurrent_buffer ();
!   Fset_buffer (buf);
!   Fkill_buffer (tembuf);
    return Qnil;
  }
  
--- 4659,4680 ----
     -- K.Handa */
  
  static Lisp_Object
! build_annotations_unwind (buf_and_region)
!      Lisp_Object buf_and_region;
  {
+   Lisp_Object buf = XCAR (buf_and_region);
+   Lisp_Object begv_pos = XCAR (XCDR (buf_and_region));
+   Lisp_Object zv_pos = XCAR (XCDR (XCDR (buf_and_region)));
    Lisp_Object tembuf;
  
!   if (XBUFFER (buf) != current_buffer)
!     {
!       tembuf = Fcurrent_buffer ();
!       Fset_buffer (buf);
!       Fkill_buffer (tembuf);
!     }
!   if (XINT (begv_pos) > BEG || XINT (zv_pos) < Z)
!     Fnarrow_to_region (begv_pos, zv_pos);
    return Qnil;
  }
  
***************
*** 4892,4905 ****
        return val;
      }
  
    /* Special kludge to simplify auto-saving.  */
    if (NILP (start))
      {
        XSETFASTINT (start, BEG);
        XSETFASTINT (end, Z);
      }
  
-   record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ());
    count1 = SPECPDL_INDEX ();
  
    given_buffer = current_buffer;
--- 4898,4914 ----
        return val;
      }
  
+   record_unwind_protect (build_annotations_unwind,
+ 			 list3 (Fcurrent_buffer (),
+ 				make_number (BEGV), make_number (ZV)));
    /* Special kludge to simplify auto-saving.  */
    if (NILP (start))
      {
        XSETFASTINT (start, BEG);
        XSETFASTINT (end, Z);
+       Fwiden ();
      }
  
    count1 = SPECPDL_INDEX ();
  
    given_buffer = current_buffer;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug of auto saving
  2003-06-10  7:03 bug of auto saving Kenichi Handa
@ 2003-06-11  0:25 ` Richard Stallman
  2003-06-11  1:05   ` Kenichi Handa
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2003-06-11  0:25 UTC (permalink / raw)
  Cc: emacs-devel

I agree with you, and your fix seems correct.  However, it would be
cleaner to call save_restriction_save and save_restriction_restore.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug of auto saving
  2003-06-11  0:25 ` Richard Stallman
@ 2003-06-11  1:05   ` Kenichi Handa
  0 siblings, 0 replies; 3+ messages in thread
From: Kenichi Handa @ 2003-06-11  1:05 UTC (permalink / raw)
  Cc: emacs-devel

In article <E19PtQG-0006XU-Rb@fencepost.gnu.org>, Richard Stallman <rms@gnu.org> writes:
> I agree with you, and your fix seems correct.  However, it
> would be cleaner to call save_restriction_save and
> save_restriction_restore.

Oops, you are right!  Then, the total change can be just
like this:

*** fileio.c.~1.487.~	Sat May 31 10:52:35 2003
--- fileio.c	Wed Jun 11 10:01:46 2003
***************
*** 4892,4902 ****
--- 4892,4905 ----
        return val;
      }
  
+   record_unwind_protect (save_restriction_restore, save_restriction_save ());
+ 
    /* Special kludge to simplify auto-saving.  */
    if (NILP (start))
      {
        XSETFASTINT (start, BEG);
        XSETFASTINT (end, Z);
+       Fwiden ();
      }
  
    record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ());

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-06-11  1:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-10  7:03 bug of auto saving Kenichi Handa
2003-06-11  0:25 ` Richard Stallman
2003-06-11  1:05   ` Kenichi Handa

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.