[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: increasing of " *temp*" buffers



In article <b4mslw9e8x7.fsf@xxxxxxx>, Katsumi Yamaoka <yamaoka@xxxxxxx> writes:

> ふと気がついたのですが、以下のようなものを実行すると " *temp*"
> バッファが増殖します。

> (encode-coding-string "" 'chinese-hz)
> (encode-coding-string "" 'in-is13194)
> (encode-coding-string "" 'tibetan)
> (encode-coding-string "" 'vietnamese-viqr)

> いつバッファを消すべきかがわからないので、ここに投げてみました。
> これで困っているわけではありませんが。:)

報告ありがとうございます。 run_pre_post_conversion_on_str で
新しいバッファを kill するのを忘れていました。

Kyotaro HORIGUCHI <horiguti@xxxxxxxxxxx> writes:

>  みたところ -string では別にバッファを作る意味はまったくなさそうで
> すが, -region の方では pre-write-conversion が自分の判断で作業バッ
> ファの生成を行うことを許すようにしているようです. なので -string
> の方で pre-write-conversion が一時バッファを勝手に作ったときにはそ
> れを消すようにしてみました. これで症状は改善します.

パッチありがとうございます。ただ、

  Finsert_buffer_substring (new, Qnil, Qnil);

がちょっと無駄な気がしますので、以下のような修正を commit し
ました。最後の unbind_to で不必要なバッファを全部消すわけです。
この修正でも pre-write-conversion 内で新しいバッファを作って
からエラーが起るとそのバッファは残るのですが、デバッグの為に
はそれは残しておいた方が良さそうなので、あえてそれは消されな
いようしています。

---
けんちゃん@AIST

Index: coding.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/coding.c,v
retrieving revision 1.324
retrieving revision 1.325
diff -c -r1.324 -r1.325
*** coding.c	7 Aug 2005 12:33:16 -0000	1.324
--- coding.c	14 Sep 2005 07:05:43 -0000	1.325
***************
*** 5353,5360 ****
        }									\
    } while (0)
  
! /* ARG is (CODING . BUFFER) where CODING is what to be set in
!    Vlast_coding_system_used and BUFFER if non-nil is a buffer to
     kill.  */
  static Lisp_Object
  code_convert_region_unwind (arg)
--- 5353,5360 ----
        }									\
    } while (0)
  
! /* ARG is (CODING BUFFER ...) where CODING is what to be set in
!    Vlast_coding_system_used and the remaining elements are buffers to
     kill.  */
  static Lisp_Object
  code_convert_region_unwind (arg)
***************
*** 5362,5369 ****
  {
    inhibit_pre_post_conversion = 0;
    Vlast_coding_system_used = XCAR (arg);
!   if (! NILP (XCDR (arg)))
!     Fkill_buffer (XCDR (arg));
    return Qnil;
  }
  
--- 5362,5369 ----
  {
    inhibit_pre_post_conversion = 0;
    Vlast_coding_system_used = XCAR (arg);
!   for (arg = XCDR (arg); ! NILP (arg); arg = XCDR (arg))
!     Fkill_buffer (XCAR (arg));
    return Qnil;
  }
  
***************
*** 6081,6086 ****
--- 6081,6087 ----
    int multibyte = STRING_MULTIBYTE (str);
    Lisp_Object old_deactivate_mark;
    Lisp_Object buffer_to_kill;
+   Lisp_Object unwind_arg;
  
    record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
    /* It is not crucial to specbind this.  */
***************
*** 6091,6105 ****
       unibyte<->multibyte conversion.  For that, we adjust the
       multibyteness of the working buffer to that of STR.  */
    buffer_to_kill = set_conversion_work_buffer (multibyte);
!   record_unwind_protect (code_convert_region_unwind,
! 			 Fcons (Vlast_coding_system_used, buffer_to_kill));
  
    insert_from_string (str, 0, 0,
  		      SCHARS (str), SBYTES (str), 0);
    UNGCPRO;
    inhibit_pre_post_conversion = 1;
    if (encodep)
!     call2 (coding->pre_write_conversion, make_number (BEG), make_number (Z));
    else
      {
        Vlast_coding_system_used = coding->symbol;
--- 6092,6116 ----
       unibyte<->multibyte conversion.  For that, we adjust the
       multibyteness of the working buffer to that of STR.  */
    buffer_to_kill = set_conversion_work_buffer (multibyte);
!   if (NILP (buffer_to_kill))
!     unwind_arg = Fcons (Vlast_coding_system_used, Qnil);
!   else
!     unwind_arg = list2 (Vlast_coding_system_used, buffer_to_kill);
!   record_unwind_protect (code_convert_region_unwind, unwind_arg);
  
    insert_from_string (str, 0, 0,
  		      SCHARS (str), SBYTES (str), 0);
    UNGCPRO;
    inhibit_pre_post_conversion = 1;
    if (encodep)
!     {
!       struct buffer *prev = current_buffer;
! 
!       call2 (coding->pre_write_conversion, make_number (BEG), make_number (Z));
!       if (prev != current_buffer)
! 	/* We must kill the current buffer too.  */
! 	Fsetcdr (unwind_arg, Fcons (Fcurrent_buffer (), XCDR (unwind_arg)));
!     }
    else
      {
        Vlast_coding_system_used = coding->symbol;
***************
*** 6133,6138 ****
--- 6144,6150 ----
  {
    struct gcpro gcpro1, gcpro2;
    struct buffer *cur = current_buffer;
+   struct buffer *prev;
    Lisp_Object old_deactivate_mark, old_last_coding_system_used;
    Lisp_Object args[3];
    Lisp_Object buffer_to_kill;
***************
*** 6149,6154 ****
--- 6161,6167 ----
    insert_1_both (*str, nchars, nbytes, 0, 0, 0);
    UNGCPRO;
    inhibit_pre_post_conversion = 1;
+   prev = current_buffer;
    args[0] = coding->pre_write_conversion;
    args[1] = make_number (BEG);
    args[2] = make_number (Z);
***************
*** 6168,6173 ****
--- 6181,6188 ----
    bcopy (BEG_ADDR, *str, coding->produced);
    coding->src_multibyte
      = ! NILP (current_buffer->enable_multibyte_characters);
+   if (prev != current_buffer)
+     Fkill_buffer (Fcurrent_buffer ());
    set_buffer_internal (cur);
    if (! NILP (buffer_to_kill))
      Fkill_buffer (buffer_to_kill);