Patch 9.0.0181
Problem:    Textprop test with line2byte() fails on MS-Windows.
Solution:   Fix updating chuncks in ml_delete_int().
Files:      src/memline.c, src/testdir/test_textprop.vim


*** ../vim-9.0.0180/src/memline.c       2022-08-07 21:48:33.600845564 +0100
--- src/memline.c       2022-08-09 21:36:30.367490903 +0100
***************
*** 3313,3319 ****
            (long)text_len
  # else
            (long)len
! #endif
            , ML_CHNK_ADDLINE);
  #endif
  
--- 3313,3319 ----
            (long)text_len
  # else
            (long)len
! # endif
            , ML_CHNK_ADDLINE);
  #endif
  
***************
*** 3667,3673 ****
      int               ret = FAIL;
  #ifdef FEAT_PROP_POPUP
      char_u    *textprop_save = NULL;
!     int               textprop_save_len = 0;
  #endif
  
      if (lowest_marked && lowest_marked > lnum)
--- 3667,3673 ----
      int               ret = FAIL;
  #ifdef FEAT_PROP_POPUP
      char_u    *textprop_save = NULL;
!     long      textprop_len = 0;
  #endif
  
      if (lowest_marked && lowest_marked > lnum)
***************
*** 3723,3740 ****
        netbeans_removed(buf, lnum, 0, line_size);
  #endif
  #ifdef FEAT_PROP_POPUP
!     // If there are text properties, make a copy, so that we can update
!     // properties in preceding and following lines.
!     if (buf->b_has_textprop && !(flags & (ML_DEL_UNDO | ML_DEL_NOPROP)))
      {
        size_t  textlen = STRLEN((char_u *)dp + line_start) + 1;
  
!       if ((long)textlen < line_size)
!       {
!           textprop_save_len = line_size - (int)textlen;
            textprop_save = vim_memsave((char_u *)dp + line_start + textlen,
!                                                         textprop_save_len);
!       }
      }
  #endif
  
--- 3723,3739 ----
        netbeans_removed(buf, lnum, 0, line_size);
  #endif
  #ifdef FEAT_PROP_POPUP
!     // If there are text properties compute their byte length.
!     // if needed make a copy, so that we can update properties in preceding 
and
!     // following lines.
!     if (buf->b_has_textprop)
      {
        size_t  textlen = STRLEN((char_u *)dp + line_start) + 1;
  
!       textprop_len = line_size - (long)textlen;
!       if (!(flags & (ML_DEL_UNDO | ML_DEL_NOPROP)) && textprop_len > 0)
            textprop_save = vim_memsave((char_u *)dp + line_start + textlen,
!                                                                textprop_len);
      }
  #endif
  
***************
*** 3820,3828 ****
  #ifdef FEAT_BYTEOFF
      ml_updatechunk(buf, lnum, line_size
  # ifdef FEAT_PROP_POPUP
!                                       - textprop_save_len
  # endif
!                                                           , ML_CHNK_DELLINE);
  #endif
      ret = OK;
  
--- 3819,3827 ----
  #ifdef FEAT_BYTEOFF
      ml_updatechunk(buf, lnum, line_size
  # ifdef FEAT_PROP_POPUP
!                                       - textprop_len
  # endif
!                                                   , ML_CHNK_DELLINE);
  #endif
      ret = OK;
  
***************
*** 3833,3842 ****
        // Adjust text properties in the line above and below.
        if (lnum > 1)
            adjust_text_props_for_delete(buf, lnum - 1, textprop_save,
!                                                     textprop_save_len, TRUE);
        if (lnum <= buf->b_ml.ml_line_count)
            adjust_text_props_for_delete(buf, lnum, textprop_save,
!                                                    textprop_save_len, FALSE);
      }
      vim_free(textprop_save);
  #endif
--- 3832,3841 ----
        // Adjust text properties in the line above and below.
        if (lnum > 1)
            adjust_text_props_for_delete(buf, lnum - 1, textprop_save,
!                                                     (int)textprop_len, TRUE);
        if (lnum <= buf->b_ml.ml_line_count)
            adjust_text_props_for_delete(buf, lnum, textprop_save,
!                                                    (int)textprop_len, FALSE);
      }
      vim_free(textprop_save);
  #endif
***************
*** 5684,5690 ****
                    // the text prop info would also be counted.  Go over the
                    // lines.
                    for (i = end_idx; i < idx; ++i)
!                       size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & 
DB_INDEX_MASK)) + 1;
                }
                else
  #endif
--- 5683,5690 ----
                    // the text prop info would also be counted.  Go over the
                    // lines.
                    for (i = end_idx; i < idx; ++i)
!                       size += (int)STRLEN((char_u *)dp
!                                     + (dp->db_index[i] & DB_INDEX_MASK)) + 1;
                }
                else
  #endif
***************
*** 5693,5699 ****
                        text_end = dp->db_txt_end;
                    else
                        text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
!                   size += text_end - ((dp->db_index[end_idx]) & 
DB_INDEX_MASK);
                }
            }
            buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt;
--- 5693,5700 ----
                        text_end = dp->db_txt_end;
                    else
                        text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
!                   size += text_end
!                                  - ((dp->db_index[end_idx]) & DB_INDEX_MASK);
                }
            }
            buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt;
***************
*** 5749,5757 ****
      {
        curchnk->mlcs_numlines--;
        ml_upd_lastbuf = NULL;   // Force recalc of curix & curline
!       if (curix < (buf->b_ml.ml_usedchunks - 1)
!               && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines)
!                  <= MLCS_MINL)
        {
            curix++;
            curchnk = buf->b_ml.ml_chunksize + curix;
--- 5750,5758 ----
      {
        curchnk->mlcs_numlines--;
        ml_upd_lastbuf = NULL;   // Force recalc of curix & curline
!       if (curix < buf->b_ml.ml_usedchunks - 1
!               && curchnk->mlcs_numlines + curchnk[1].mlcs_numlines
!                                                                 <= MLCS_MINL)
        {
            curix++;
            curchnk = buf->b_ml.ml_chunksize + curix;
***************
*** 5764,5771 ****
            return;
        }
        else if (curix == 0 || (curchnk->mlcs_numlines > 10
!                   && (curchnk->mlcs_numlines + curchnk[-1].mlcs_numlines)
!                      > MLCS_MINL))
        {
            return;
        }
--- 5765,5772 ----
            return;
        }
        else if (curix == 0 || (curchnk->mlcs_numlines > 10
!                   && curchnk->mlcs_numlines + curchnk[-1].mlcs_numlines
!                                                                 > MLCS_MINL))
        {
            return;
        }
***************
*** 5775,5786 ****
        curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize;
        buf->b_ml.ml_usedchunks--;
        if (curix < buf->b_ml.ml_usedchunks)
-       {
            mch_memmove(buf->b_ml.ml_chunksize + curix,
                        buf->b_ml.ml_chunksize + curix + 1,
                        (buf->b_ml.ml_usedchunks - curix) *
                        sizeof(chunksize_T));
-       }
        return;
      }
      ml_upd_lastbuf = buf;
--- 5776,5785 ----
*** ../vim-9.0.0180/src/testdir/test_textprop.vim       2022-08-09 
19:30:16.373348780 +0100
--- src/testdir/test_textprop.vim       2022-08-09 21:35:22.443780686 +0100
***************
*** 922,941 ****
    if a:add_props
      call prop_type_add('textprop', #{highlight: 'Search'})
    endif
    for nr in range(1, 1000)
      call setline(nr, 'some longer text here')
!     if a:add_props && nr % 17 == 0
        call prop_add(nr, 13, #{type: 'textprop', length: 4})
      endif
    endfor
!   call assert_equal(21935, line2byte(998))
!   for nr in range(1, 1000, 7)
      exe nr .. "s/longer/much more/"
    endfor
-   " FIXME: somehow this fails on MS-Windows
-   if !(a:add_props && has('win32'))
-     call assert_equal(22364, line2byte(998))
-   endif
  
    if a:add_props
      call prop_type_delete('textprop')
--- 922,943 ----
    if a:add_props
      call prop_type_add('textprop', #{highlight: 'Search'})
    endif
+   " Add a text prop to every fourth line and then change every fifth line so
+   " that it causes a data block split a few times.
    for nr in range(1, 1000)
      call setline(nr, 'some longer text here')
!     if a:add_props && nr % 4 == 0
        call prop_add(nr, 13, #{type: 'textprop', length: 4})
      endif
    endfor
!   let expected = 22 * 997 + 1
!   call assert_equal(expected, line2byte(998))
! 
!   for nr in range(1, 1000, 5)
      exe nr .. "s/longer/much more/"
+     let expected += 3
+     call assert_equal(expected, line2byte(998), 'line ' .. nr)
    endfor
  
    if a:add_props
      call prop_type_delete('textprop')
*** ../vim-9.0.0180/src/version.c       2022-08-09 19:30:16.373348780 +0100
--- src/version.c       2022-08-09 21:35:16.583806941 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     181,
  /**/

-- 
press CTRL-ALT-DEL for more information

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220809204401.7953D1C05A0%40moolenaar.net.

Raspunde prin e-mail lui