emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/src/editfns.c [emacs-unicode-2]


From: Miles Bader
Subject: [Emacs-diffs] Changes to emacs/src/editfns.c [emacs-unicode-2]
Date: Tue, 29 Jun 2004 13:08:10 -0400

Index: emacs/src/editfns.c
diff -c emacs/src/editfns.c:1.359.2.7 emacs/src/editfns.c:1.359.2.8
*** emacs/src/editfns.c:1.359.2.7       Mon Jun 28 07:29:19 2004
--- emacs/src/editfns.c Tue Jun 29 16:46:02 2004
***************
*** 3381,3386 ****
--- 3381,3387 ----
    int longest_format;
    Lisp_Object val;
    int arg_intervals = 0;
+   USE_SAFE_ALLOCA;
  
    /* discarded[I] is 1 if byte I of the format
       string was not copied into the output.
***************
*** 3429,3435 ****
    longest_format = 0;
  
    /* Make room in result for all the non-%-codes in the control string.  */
!   total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]);
  
    /* Allocate the info and discarded tables.  */
    {
--- 3430,3436 ----
    longest_format = 0;
  
    /* Make room in result for all the non-%-codes in the control string.  */
!   total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]) + 1;
  
    /* Allocate the info and discarded tables.  */
    {
***************
*** 3622,3631 ****
  
    /* Allocate the space for the result.
       Note that TOTAL is an overestimate.  */
!   if (total < 1000)
!     buf = (char *) alloca (total + 1);
!   else
!     buf = (char *) xmalloc (total + 1);
  
    p = buf;
    nchars = 0;
--- 3623,3629 ----
  
    /* Allocate the space for the result.
       Note that TOTAL is an overestimate.  */
!   SAFE_ALLOCA (buf, char *, total);
  
    p = buf;
    nchars = 0;
***************
*** 3758,3764 ****
                maybe_combine_byte = 1;
              this_nchars = strlen (p);
              if (multibyte)
!               p += str_to_multibyte (p, buf + total - p, this_nchars);
              else
                p += this_nchars;
              nchars += this_nchars;
--- 3756,3762 ----
                maybe_combine_byte = 1;
              this_nchars = strlen (p);
              if (multibyte)
!               p += str_to_multibyte (p, buf + total - 1 - p, this_nchars);
              else
                p += this_nchars;
              nchars += this_nchars;
***************
*** 3795,3801 ****
        *p++ = *format++, nchars++;
      }
  
!   if (p > buf + total + 1)
      abort ();
  
    if (maybe_combine_byte)
--- 3793,3799 ----
        *p++ = *format++, nchars++;
      }
  
!   if (p > buf + total)
      abort ();
  
    if (maybe_combine_byte)
***************
*** 3803,3810 ****
    val = make_specified_string (buf, nchars, p - buf, multibyte);
  
    /* If we allocated BUF with malloc, free it too.  */
!   if (total >= 1000)
!     xfree (buf);
  
    /* If the format string has text properties, or any of the string
       arguments has text properties, set up text properties of the
--- 3801,3807 ----
    val = make_specified_string (buf, nchars, p - buf, multibyte);
  
    /* If we allocated BUF with malloc, free it too.  */
!   SAFE_FREE (total);
  
    /* If the format string has text properties, or any of the string
       arguments has text properties, set up text properties of the
***************
*** 4173,4184 ****
        /* First region smaller than second.  */
        if (len1_byte < len2_byte)
          {
!         /* We use alloca only if it is small,
!            because we want to avoid stack overflow.  */
!         if (len2_byte > 20000)
!           temp = (unsigned char *) xmalloc (len2_byte);
!         else
!           temp = (unsigned char *) alloca (len2_byte);
  
          /* Don't precompute these addresses.  We have to compute them
             at the last minute, because the relocating allocator might
--- 4170,4178 ----
        /* First region smaller than second.  */
        if (len1_byte < len2_byte)
          {
!         USE_SAFE_ALLOCA;
! 
!         SAFE_ALLOCA (temp, unsigned char *, len2_byte);
  
          /* Don't precompute these addresses.  We have to compute them
             at the last minute, because the relocating allocator might
***************
*** 4189,4211 ****
            bcopy (start2_addr, temp, len2_byte);
            bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
            bcopy (temp, start1_addr, len2_byte);
!         if (len2_byte > 20000)
!           xfree (temp);
          }
        else
        /* First region not smaller than second.  */
          {
!         if (len1_byte > 20000)
!           temp = (unsigned char *) xmalloc (len1_byte);
!         else
!           temp = (unsigned char *) alloca (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (temp, start1_addr + len2_byte, len1_byte);
!         if (len1_byte > 20000)
!           xfree (temp);
          }
        graft_intervals_into_buffer (tmp_interval1, start1 + len2,
                                     len1, current_buffer, 0);
--- 4183,4202 ----
            bcopy (start2_addr, temp, len2_byte);
            bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
            bcopy (temp, start1_addr, len2_byte);
!         SAFE_FREE (len2_byte);
          }
        else
        /* First region not smaller than second.  */
          {
!         USE_SAFE_ALLOCA;
! 
!         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (temp, start1_addr + len2_byte, len1_byte);
!         SAFE_FREE (len1_byte);
          }
        graft_intervals_into_buffer (tmp_interval1, start1 + len2,
                                     len1, current_buffer, 0);
***************
*** 4222,4227 ****
--- 4213,4220 ----
        if (len1_byte == len2_byte)
        /* Regions are same size, though, how nice.  */
          {
+         USE_SAFE_ALLOCA;
+ 
            modify_region (current_buffer, start1, end1);
            modify_region (current_buffer, start2, end2);
            record_change (start1, len1);
***************
*** 4233,4249 ****
            Fset_text_properties (make_number (start2), make_number (end2),
                                Qnil, Qnil);
  
!         if (len1_byte > 20000)
!           temp = (unsigned char *) xmalloc (len1_byte);
!         else
!           temp = (unsigned char *) alloca (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (temp, start2_addr, len1_byte);
!         if (len1_byte > 20000)
!           xfree (temp);
            graft_intervals_into_buffer (tmp_interval1, start2,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval2, start1,
--- 4226,4239 ----
            Fset_text_properties (make_number (start2), make_number (end2),
                                Qnil, Qnil);
  
!         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (temp, start2_addr, len1_byte);
!         SAFE_FREE (len1_byte);
! 
            graft_intervals_into_buffer (tmp_interval1, start2,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval2, start1,
***************
*** 4253,4258 ****
--- 4243,4250 ----
        else if (len1_byte < len2_byte) /* Second region larger than first */
          /* Non-adjacent & unequal size, area between must also be shifted.  */
          {
+         USE_SAFE_ALLOCA;
+ 
            modify_region (current_buffer, start1, end2);
            record_change (start1, (end2 - start1));
            tmp_interval1 = copy_intervals (cur_intv, start1, len1);
***************
*** 4262,4279 ****
                                Qnil, Qnil);
  
          /* holds region 2 */
!         if (len2_byte > 20000)
!           temp = (unsigned char *) xmalloc (len2_byte);
!         else
!           temp = (unsigned char *) alloca (len2_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start2_addr, temp, len2_byte);
            bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
            safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, 
len_mid);
            bcopy (temp, start1_addr, len2_byte);
!         if (len2_byte > 20000)
!           xfree (temp);
            graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
--- 4254,4268 ----
                                Qnil, Qnil);
  
          /* holds region 2 */
!         SAFE_ALLOCA (temp, unsigned char *, len2_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start2_addr, temp, len2_byte);
            bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
            safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, 
len_mid);
            bcopy (temp, start1_addr, len2_byte);
!         SAFE_FREE (len2_byte);
! 
            graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
***************
*** 4284,4289 ****
--- 4273,4280 ----
        else
        /* Second region smaller than first.  */
          {
+         USE_SAFE_ALLOCA;
+ 
            record_change (start1, (end2 - start1));
            modify_region (current_buffer, start1, end2);
  
***************
*** 4294,4311 ****
                                Qnil, Qnil);
  
          /* holds region 1 */
!         if (len1_byte > 20000)
!           temp = (unsigned char *) xmalloc (len1_byte);
!         else
!           temp = (unsigned char *) alloca (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
            bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
!         if (len1_byte > 20000)
!           xfree (temp);
            graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
--- 4285,4299 ----
                                Qnil, Qnil);
  
          /* holds region 1 */
!         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
            bcopy (start1_addr, temp, len1_byte);
            bcopy (start2_addr, start1_addr, len2_byte);
            bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
            bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
!         SAFE_FREE (len1_byte);
! 
            graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                         len1, current_buffer, 0);
            graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]