Patch 9.0.0063

2022-07-23 Fir de Conversatie Bram Moolenaar


Patch 9.0.0063
Problem:Too many type casts for dict_get functions.
Solution:   Change the key argument from "char_u *" to "char *".
Files:  src/dict.c, src/proto/dict.pro, src/autocmd.c, src/change.c,
src/evalbuffer.c, src/evalfunc.c, src/evalwindow.c, src/fileio.c,
src/filepath.c, src/highlight.c, src/insexpand.c, src/gui_w32.c,
src/map.c, src/match.c, src/popupwin.c, src/quickfix.c,
src/search.c, src/sign.c, src/tag.c, src/terminal.c,
src/testing.c, src/textprop.c, src/time.c


*** ../vim-9.0.0062/src/dict.c  2022-06-14 13:39:28.0 +0100
--- src/dict.c  2022-07-23 09:45:42.021708123 +0100
***
*** 662,672 
   * Returns FAIL if the entry doesn't exist or out of memory.
   */
  int
! dict_get_tv(dict_T *d, char_u *key, typval_T *rettv)
  {
  dictitem_T*di;
  
! di = dict_find(d, key, -1);
  if (di == NULL)
return FAIL;
  copy_tv(>di_tv, rettv);
--- 662,672 
   * Returns FAIL if the entry doesn't exist or out of memory.
   */
  int
! dict_get_tv(dict_T *d, char *key, typval_T *rettv)
  {
  dictitem_T*di;
  
! di = dict_find(d, (char_u *)key, -1);
  if (di == NULL)
return FAIL;
  copy_tv(>di_tv, rettv);
***
*** 680,691 
   * Returns NULL if the entry doesn't exist or out of memory.
   */
  char_u *
! dict_get_string(dict_T *d, char_u *key, int save)
  {
  dictitem_T*di;
  char_u*s;
  
! di = dict_find(d, key, -1);
  if (di == NULL)
return NULL;
  s = tv_get_string(>di_tv);
--- 680,691 
   * Returns NULL if the entry doesn't exist or out of memory.
   */
  char_u *
! dict_get_string(dict_T *d, char *key, int save)
  {
  dictitem_T*di;
  char_u*s;
  
! di = dict_find(d, (char_u *)key, -1);
  if (di == NULL)
return NULL;
  s = tv_get_string(>di_tv);
***
*** 699,705 
   * Returns 0 if the entry doesn't exist.
   */
  varnumber_T
! dict_get_number(dict_T *d, char_u *key)
  {
  return dict_get_number_def(d, key, 0);
  }
--- 699,705 
   * Returns 0 if the entry doesn't exist.
   */
  varnumber_T
! dict_get_number(dict_T *d, char *key)
  {
  return dict_get_number_def(d, key, 0);
  }
***
*** 709,719 
   * Returns "def" if the entry doesn't exist.
   */
  varnumber_T
! dict_get_number_def(dict_T *d, char_u *key, int def)
  {
  dictitem_T*di;
  
! di = dict_find(d, key, -1);
  if (di == NULL)
return def;
  return tv_get_number(>di_tv);
--- 709,719 
   * Returns "def" if the entry doesn't exist.
   */
  varnumber_T
! dict_get_number_def(dict_T *d, char *key, int def)
  {
  dictitem_T*di;
  
! di = dict_find(d, (char_u *)key, -1);
  if (di == NULL)
return def;
  return tv_get_number(>di_tv);
***
*** 745,755 
   * Returns "def" if the entry doesn't exist.
   */
  varnumber_T
! dict_get_bool(dict_T *d, char_u *key, int def)
  {
  dictitem_T*di;
  
! di = dict_find(d, key, -1);
  if (di == NULL)
return def;
  return tv_get_bool(>di_tv);
--- 745,755 
   * Returns "def" if the entry doesn't exist.
   */
  varnumber_T
! dict_get_bool(dict_T *d, char *key, int def)
  {
  dictitem_T*di;
  
! di = dict_find(d, (char_u *)key, -1);
  if (di == NULL)
return def;
  return tv_get_bool(>di_tv);
*** ../vim-9.0.0062/src/proto/dict.pro  2022-06-27 23:15:00.0 +0100
--- src/proto/dict.pro  2022-07-23 09:49:17.817767276 +0100
***
*** 28,39 
  long dict_len(dict_T *d);
  dictitem_T *dict_find(dict_T *d, char_u *key, int len);
  int dict_has_key(dict_T *d, char *key);
! int dict_get_tv(dict_T *d, char_u *key, typval_T *rettv);
! char_u *dict_get_string(dict_T *d, char_u *key, int save);
! varnumber_T dict_get_number(dict_T *d, char_u *key);
! varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
  varnumber_T dict_get_number_check(dict_T *d, char_u *key);
! varnumber_T dict_get_bool(dict_T *d, char_u *key, int def);
  char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
  char_u *get_literal_key(char_u **arg);
  int eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal);
--- 28,39 
  long dict_len(dict_T *d);
  dictitem_T *dict_find(dict_T *d, char_u *key, int len);
  int dict_has_key(dict_T *d, char *key);
! int dict_get_tv(dict_T *d, char *key, typval_T *rettv);
! char_u *dict_get_string(dict_T *d, char *key, int save);
! varnumber_T dict_get_number(dict_T *d, char *key);
! varnumber_T dict_get_number_def(dict_T *d, char *key, int def);
  varnumber_T dict_get_number_check(dict_T *d, char_u *key);
! varnumber_T dict_get_bool(dict_T *d, char *key, int def);
  char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
  char_u *get_literal_key(char_u **arg);
  int 

Patch 9.0.0062

2022-07-23 Fir de Conversatie Bram Moolenaar


Patch 9.0.0062 (after 9.0.0058)
Problem:Compiler warnings for signed/unsigned char.
Solution:   Add type casts. (John Marriott)
Files:  src/gui_w32.c


*** ../vim-9.0.0061/src/gui_w32.c   2022-07-23 05:04:07.580839529 +0100
--- src/gui_w32.c   2022-07-23 09:19:17.40511 +0100
***
*** 8549,8555 
  char_u*event;
  INPUT inputs[1];
  
! event = dict_get_string(args, "event", TRUE);
  if (event == NULL)
return FALSE;
  
--- 8549,8555 
  char_u*event;
  INPUT inputs[1];
  
! event = dict_get_string(args, (char_u *)"event", TRUE);
  if (event == NULL)
return FALSE;
  
***
*** 8559,8565 
  {
WORDvkCode;
  
!   vkCode = dict_get_number_def(args, "keycode", 0);
if (vkCode <= 0 || vkCode >= 0xFF)
{
semsg(_(e_invalid_argument_nr), (long)vkCode);
--- 8559,8565 
  {
WORDvkCode;
  
!   vkCode = dict_get_number_def(args, (char_u *)"keycode", 0);
if (vkCode <= 0 || vkCode >= 0xFF)
{
semsg(_(e_invalid_argument_nr), (long)vkCode);
*** ../vim-9.0.0061/src/version.c   2022-07-23 09:06:23.624970753 +0100
--- src/version.c   2022-07-23 09:16:45.361266974 +0100
***
*** 737,738 
--- 737,740 
  {   /* Add new patch number below this line */
+ /**/
+ 62,
  /**/

-- 
To be rich is not the end, but only a change of worries.

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220723082414.ED9211C091B%40moolenaar.net.


Re: Patch 9.0.0058

2022-07-23 Fir de Conversatie Bram Moolenaar

John Marriott wrote:

> On 23-July-2022 14:05, Bram Moolenaar wrote:
> > Patch 9.0.0058
> > Problem:Win32: cannot test low level events.
> > Solution:   Add "sendevent" to test_gui_event(). (Yegappan Lakshmanan,
> >  closes #10679)
> > Files:  runtime/doc/testing.txt, src/errors.h, src/gui_w32.c,
> >  src/proto/gui_w32.pro, src/testing.c, src/testdir/test_gui.vim
> >
> >
> After this patch, mingw64 (gcc 12.1.0) throws this warning:
> 
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603 
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO 
> -pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return 
> -fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD gui_w32.c -o 
> gobjnative/gui_w32.o
> gui_w32.c:8552:35: warning: pointer targets in passing argument 2 of 
> 'dict_get_string' differ in signedness [-Wpointer-sign]
>   8552 | event = dict_get_string(args, "event", TRUE);
>    |   ^~~
>    |   |
>    |   char *
> In file included from proto.h:75,
>   from vim.h:2263,
>   from gui_w32.c:26:
> proto/dict.pro:32:44: note: expected 'char_u *' {aka 'unsigned char *'} 
> but argument is of type 'char *'
>     32 | char_u *dict_get_string(dict_T *d, char_u *key, int save);
>    |    ^~~
> gui_w32.c:8562:44: warning: pointer targets in passing argument 2 of 
> 'dict_get_number_def' differ in signedness [-Wpointer-sign]
>   8562 | vkCode = dict_get_number_def(args, "keycode", 0);
>    |    ^
>    |    |
>    |    char *
> proto/dict.pro:34:52: note: expected 'char_u *' {aka 'unsigned char *'} 
> but argument is of type 'char *'
>     34 | varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
>    |    ^~~
> 
> 
> The attached patch tries to fix it.

Thanks!

It looks like nearly all of these calls use a string constant, I'll make
the argument "char *" to avoid a lot of type casts.

-- 
Contrary to popular belief, Unix is user friendly.
It just happens to be selective about who it makes friends with.
   -- Dave Parnas

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220723082414.E901D1C0909%40moolenaar.net.


Patch 9.0.0060

2022-07-23 Fir de Conversatie Bram Moolenaar


Patch 9.0.0060
Problem:Accessing uninitialized memory when completing long line.
Solution:   Terminate string with NUL.
Files:  src/insexpand.c, src/testdir/test_ins_complete.vim


*** ../vim-9.0.0059/src/insexpand.c 2022-07-15 20:45:11.130168352 +0100
--- src/insexpand.c 2022-07-23 06:51:07.949613376 +0100
***
*** 642,647 
--- 642,648 
// growarray.  Add the character in the next round.
if (ga_grow(, IOSIZE) == FAIL)
return (char_u *)"[failed]";
+   *p = NUL;
STRCPY(gap.ga_data, IObuff);
gap.ga_len = (int)STRLEN(IObuff);
}
*** ../vim-9.0.0059/src/testdir/test_ins_complete.vim   2022-07-07 
19:59:45.466244217 +0100
--- src/testdir/test_ins_complete.vim   2022-07-23 06:46:41.445517250 +0100
***
*** 2108,2113 
--- 2108,2120 
exe "normal 2Go\\\"
call assert_equal(longLine, getline(3))
  
+   " check that the too long text is NUL terminated
+   %del
+   norm o
+   norm 1987ax
+   exec "norm ox\\"
+   call assert_equal(repeat('x', 1987), getline(3))
+ 
bwipe!
set noic noinfercase
  endfunc
*** ../vim-9.0.0059/src/version.c   2022-07-23 06:24:56.409106034 +0100
--- src/version.c   2022-07-23 06:52:32.717639744 +0100
***
*** 737,738 
--- 737,740 
  {   /* Add new patch number below this line */
+ /**/
+ 60,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
101. U can read htis w/o ny porblm and cant figur eout Y its evn listd.

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220723081053.DEE6F1C0909%40moolenaar.net.


Patch 9.0.0061

2022-07-23 Fir de Conversatie Bram Moolenaar


Patch 9.0.0061
Problem:ml_get error with nested autocommand.
Solution:   Also check line numbers for a nested autocommand. (closes #10761)
Files:  src/window.c, src/proto/window.pro, src/autocmd.c,
src/testdir/test_autocmd.vim


*** ../vim-9.0.0060/src/window.c2022-07-01 15:26:09.294541275 +0100
--- src/window.c2022-07-23 09:03:37.532879149 +0100
***
*** 6770,6781 
  }
  
  /*
!  * Correct the cursor line number in other windows.  Used after changing the
!  * current buffer, and before applying autocommands.
!  * When "do_curwin" is TRUE, also check current window.
   */
! void
! check_lnums(int do_curwin)
  {
  win_T *wp;
  tabpage_T *tp;
--- 6770,6779 
  }
  
  /*
!  * Implementation of check_lnums() and check_lnums_nested().
   */
! static void
! check_lnums_both(int do_curwin, int nested)
  {
  win_T *wp;
  tabpage_T *tp;
***
*** 6783,6804 
  FOR_ALL_TAB_WINDOWS(tp, wp)
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf)
{
!   // save the original cursor position and topline
!   wp->w_save_cursor.w_cursor_save = wp->w_cursor;
!   wp->w_save_cursor.w_topline_save = wp->w_topline;
  
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count)
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
if (wp->w_topline > curbuf->b_ml.ml_line_count)
wp->w_topline = curbuf->b_ml.ml_line_count;
  
!   // save the corrected cursor position and topline
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
wp->w_save_cursor.w_topline_corr = wp->w_topline;
}
  }
  
  /*
   * Reset cursor and topline to its stored values from check_lnums().
   * check_lnums() must have been called first!
   */
--- 6781,6825 
  FOR_ALL_TAB_WINDOWS(tp, wp)
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf)
{
!   if (!nested)
!   {
!   // save the original cursor position and topline
!   wp->w_save_cursor.w_cursor_save = wp->w_cursor;
!   wp->w_save_cursor.w_topline_save = wp->w_topline;
!   }
  
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count)
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
if (wp->w_topline > curbuf->b_ml.ml_line_count)
wp->w_topline = curbuf->b_ml.ml_line_count;
  
!   // save the (corrected) cursor position and topline
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
wp->w_save_cursor.w_topline_corr = wp->w_topline;
}
  }
  
  /*
+  * Correct the cursor line number in other windows.  Used after changing the
+  * current buffer, and before applying autocommands.
+  * When "do_curwin" is TRUE, also check current window.
+  */
+ void
+ check_lnums(int do_curwin)
+ {
+ check_lnums_both(do_curwin, FALSE);
+ }
+ 
+ /*
+  * Like check_lnums() but for when check_lnums() was already called.
+  */
+ void
+ check_lnums_nested(int do_curwin)
+ {
+ check_lnums_both(do_curwin, TRUE);
+ }
+ 
+ /*
   * Reset cursor and topline to its stored values from check_lnums().
   * check_lnums() must have been called first!
   */
*** ../vim-9.0.0060/src/proto/window.pro2022-06-27 23:15:31.0 
+0100
--- src/proto/window.pro2022-07-23 09:03:41.724881565 +0100
***
*** 77,82 
--- 77,83 
  int min_rows(void);
  int only_one_window(void);
  void check_lnums(int do_curwin);
+ void check_lnums_nested(int do_curwin);
  void reset_lnums(void);
  void make_snapshot(int idx);
  void restore_snapshot(int idx, int close_curwin);
*** ../vim-9.0.0060/src/autocmd.c   2022-06-14 13:41:08.0 +0100
--- src/autocmd.c   2022-07-23 09:03:20.104869054 +0100
***
*** 2209,2217 
ap->last = FALSE;
ap->last = TRUE;
  
if (nesting == 1)
-   // make sure cursor and topline are valid
check_lnums(TRUE);
  
save_did_emsg = did_emsg;
  
--- 2209,2221 
ap->last = FALSE;
ap->last = TRUE;
  
+   // Make sure cursor and topline are valid.  The first time the current
+   // values are saved, restored by reset_lnums().  When nested only the
+   // values are corrected when needed.
if (nesting == 1)
check_lnums(TRUE);
+   else
+   check_lnums_nested(TRUE);
  
save_did_emsg = did_emsg;
  
*** ../vim-9.0.0060/src/testdir/test_autocmd.vim2022-06-12 
23:23:27.0 +0100
--- src/testdir/test_autocmd.vim2022-07-23 09:01:06.532787863 +0100
***
*** 2301,2306 
--- 2301,2325 
call assert_fails('au WinNew * nested nested echo bad', 'E983:')
  endfunc
  
+ func Test_autocmd_nested_cursor_invalid()
+   set laststatus=0
+   copen
+   cclose
+   call setline(1, ['foo', 'bar', 'baz'])
+   3
+   augroup nested_inv
+ 

Re: Patch 9.0.0058

2022-07-23 Fir de Conversatie John Marriott


On 23-July-2022 14:05, Bram Moolenaar wrote:

Patch 9.0.0058
Problem:Win32: cannot test low level events.
Solution:   Add "sendevent" to test_gui_event(). (Yegappan Lakshmanan,
 closes #10679)
Files:  runtime/doc/testing.txt, src/errors.h, src/gui_w32.c,
 src/proto/gui_w32.pro, src/testing.c, src/testdir/test_gui.vim



After this patch, mingw64 (gcc 12.1.0) throws this warning:

gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603 
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO 
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return 
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD gui_w32.c -o 
gobjnative/gui_w32.o
gui_w32.c:8552:35: warning: pointer targets in passing argument 2 of 
'dict_get_string' differ in signedness [-Wpointer-sign]

 8552 | event = dict_get_string(args, "event", TRUE);
  |   ^~~
  |   |
  |   char *
In file included from proto.h:75,
 from vim.h:2263,
 from gui_w32.c:26:
proto/dict.pro:32:44: note: expected 'char_u *' {aka 'unsigned char *'} 
but argument is of type 'char *'

   32 | char_u *dict_get_string(dict_T *d, char_u *key, int save);
  |    ^~~
gui_w32.c:8562:44: warning: pointer targets in passing argument 2 of 
'dict_get_number_def' differ in signedness [-Wpointer-sign]

 8562 | vkCode = dict_get_number_def(args, "keycode", 0);
  |    ^
  |    |
  |    char *
proto/dict.pro:34:52: note: expected 'char_u *' {aka 'unsigned char *'} 
but argument is of type 'char *'

   34 | varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
  |    ^~~


The attached patch tries to fix it.

Cheers
John

--
--
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/ea1584af-b2a2-2ac0-6268-2dca5afaa46f%40internode.on.net.
--- gui_w32.c.orig  2022-07-23 16:39:07.751350900 +1000
+++ gui_w32.c   2022-07-23 16:46:55.972852600 +1000
@@ -8549,7 +8549,7 @@
 char_u *event;
 INPUT  inputs[1];
 
-event = dict_get_string(args, "event", TRUE);
+event = dict_get_string(args, (char_u *)"event", TRUE);
 if (event == NULL)
return FALSE;
 
@@ -8559,7 +8559,7 @@
 {
WORDvkCode;
 
-   vkCode = dict_get_number_def(args, "keycode", 0);
+   vkCode = dict_get_number_def(args, (char_u *)"keycode", 0);
if (vkCode <= 0 || vkCode >= 0xFF)
{
semsg(_(e_invalid_argument_nr), (long)vkCode);