Patch 9.0.1431
Problem:    getscriptinfo() loops even when specific SID is given.
Solution:   Only loop when needed.  Give a clearer error message.
            (closes #12207)
Files:      src/scriptfile.c, src/testdir/test_scriptnames.vim


*** ../vim-9.0.1430/src/scriptfile.c    2023-03-07 17:13:47.313107772 +0000
--- src/scriptfile.c    2023-03-30 21:45:43.502775895 +0100
***************
*** 1299,1305 ****
   * ":source" and associated commands.
   */
  
! #ifdef FEAT_EVAL
  /*
   * Return the address holding the next breakpoint line for a source cookie.
   */
--- 1299,1305 ----
   * ":source" and associated commands.
   */
  
! #if defined(FEAT_EVAL) || defined(PROTO)
  /*
   * Return the address holding the next breakpoint line for a source cookie.
   */
***************
*** 2096,2102 ****
      void
  f_getscriptinfo(typval_T *argvars, typval_T *rettv)
  {
-     int               i;
      list_T    *l;
      char_u    *pat = NULL;
      regmatch_T        regmatch;
--- 2096,2101 ----
***************
*** 2116,2123 ****
  
      if (argvars[0].v_type == VAR_DICT)
      {
!       sid = dict_get_number_def(argvars[0].vval.v_dict, "sid", -1);
!       if (sid == -1)
        {
            pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE);
            if (pat != NULL)
--- 2115,2136 ----
  
      if (argvars[0].v_type == VAR_DICT)
      {
!       dictitem_T *sid_di = dict_find(argvars[0].vval.v_dict,
!                                                          (char_u *)"sid", 3);
!       if (sid_di != NULL)
!       {
!           int error = FALSE;
!           sid = tv_get_number_chk(&sid_di->di_tv, &error);
!           if (error)
!               return;
!           if (sid <= 0)
!           {
!               semsg(e_invalid_value_for_argument_str_str, "sid",
!                                               tv_get_string(&sid_di->di_tv));
!               return;
!           }
!       }
!       else
        {
            pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE);
            if (pat != NULL)
***************
*** 2127,2133 ****
        }
      }
  
!     for (i = 1; i <= script_items.ga_len; ++i)
      {
        scriptitem_T    *si = SCRIPT_ITEM(i);
        dict_T          *d;
--- 2140,2147 ----
        }
      }
  
!     for (varnumber_T i = sid > 0 ? sid : 1;
!                      (i == sid || sid <= 0) && i <= script_items.ga_len; ++i)
      {
        scriptitem_T    *si = SCRIPT_ITEM(i);
        dict_T          *d;
***************
*** 2138,2146 ****
        if (filterpat && !vim_regexec(&regmatch, si->sn_name, (colnr_T)0))
            continue;
  
-       if (sid != -1 && sid != i)
-           continue;
- 
        if ((d = dict_alloc()) == NULL
                || list_append_dict(l, d) == FAIL
                || dict_add_string(d, "name", si->sn_name) == FAIL
--- 2152,2157 ----
***************
*** 2151,2160 ****
                                si->sn_state == SN_STATE_NOT_LOADED) == FAIL)
            return;
  
!       // When a filter pattern is specified to return information about only
!       // specific script(s), also add the script-local variables and
!       // functions.
!       if (sid != -1)
        {
            dict_T      *var_dict;
  
--- 2162,2170 ----
                                si->sn_state == SN_STATE_NOT_LOADED) == FAIL)
            return;
  
!       // When a script ID is specified, return information about only the
!       // specified script, and add the script-local variables and functions.
!       if (sid > 0)
        {
            dict_T      *var_dict;
  
*** ../vim-9.0.1430/src/testdir/test_scriptnames.vim    2022-10-10 
22:39:38.199545906 +0100
--- src/testdir/test_scriptnames.vim    2023-03-30 21:48:51.702661298 +0100
***************
*** 91,96 ****
--- 91,106 ----
    call assert_fails("echo getscriptinfo('foobar')", 'E1206:')
  
    call assert_fails("echo getscriptinfo({'sid': []})", 'E745:')
+   call assert_fails("echo getscriptinfo({'sid': {}})", 'E728:')
+   call assert_fails("echo getscriptinfo({'sid': 0})", 'E475:')
+   call assert_fails("echo getscriptinfo({'sid': -1})", 'E475:')
+   call assert_fails("echo getscriptinfo({'sid': -999})", 'E475:')
+ 
+   echo getscriptinfo({'sid': '1'})
+   call assert_fails("vim9cmd echo getscriptinfo({'sid': '1'})", 'E1030:')
+ 
+   let max_sid = max(map(getscriptinfo(), { k, v -> v.sid }))
+   call assert_equal([], getscriptinfo({'sid': max_sid + 1}))
  endfunc
  
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.1430/src/version.c       2023-03-28 21:28:32.694343665 +0100
--- src/version.c       2023-03-30 21:33:36.723059118 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1431,
  /**/

-- 
The question is:  What do you do with your life?
The wrong answer is: Become the richest guy in the graveyard.
                                (billionaire and Oracle founder Larry Ellison)

 /// 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/20230330205108.218B91C0CBD%40moolenaar.net.

Raspunde prin e-mail lui