Mercurial > vim
comparison src/scriptfile.c @ 32200:730eebd56f48 v9.0.1431
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Commit: https://github.com/vim/vim/commit/2d68b722e3bca7532eb0d83ce773934618f12db5
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Mar 30 21:50:37 2023 +0100
patch 9.0.1431: getscriptinfo() loops even when specific SID is given
Problem: getscriptinfo() loops even when specific SID is given.
Solution: Only loop when needed. Give a clearer error message.
(closes #12207)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 30 Mar 2023 23:00:06 +0200 |
parents | 04d9dff67d99 |
children | 5372bf23bf72 |
comparison
equal
deleted
inserted
replaced
32199:dc4f9a9d07a1 | 32200:730eebd56f48 |
---|---|
1297 | 1297 |
1298 /* | 1298 /* |
1299 * ":source" and associated commands. | 1299 * ":source" and associated commands. |
1300 */ | 1300 */ |
1301 | 1301 |
1302 #ifdef FEAT_EVAL | 1302 #if defined(FEAT_EVAL) || defined(PROTO) |
1303 /* | 1303 /* |
1304 * Return the address holding the next breakpoint line for a source cookie. | 1304 * Return the address holding the next breakpoint line for a source cookie. |
1305 */ | 1305 */ |
1306 linenr_T * | 1306 linenr_T * |
1307 source_breakpoint(void *cookie) | 1307 source_breakpoint(void *cookie) |
2094 * getscriptinfo() function | 2094 * getscriptinfo() function |
2095 */ | 2095 */ |
2096 void | 2096 void |
2097 f_getscriptinfo(typval_T *argvars, typval_T *rettv) | 2097 f_getscriptinfo(typval_T *argvars, typval_T *rettv) |
2098 { | 2098 { |
2099 int i; | |
2100 list_T *l; | 2099 list_T *l; |
2101 char_u *pat = NULL; | 2100 char_u *pat = NULL; |
2102 regmatch_T regmatch; | 2101 regmatch_T regmatch; |
2103 int filterpat = FALSE; | 2102 int filterpat = FALSE; |
2104 scid_T sid = -1; | 2103 scid_T sid = -1; |
2114 regmatch.regprog = NULL; | 2113 regmatch.regprog = NULL; |
2115 regmatch.rm_ic = p_ic; | 2114 regmatch.rm_ic = p_ic; |
2116 | 2115 |
2117 if (argvars[0].v_type == VAR_DICT) | 2116 if (argvars[0].v_type == VAR_DICT) |
2118 { | 2117 { |
2119 sid = dict_get_number_def(argvars[0].vval.v_dict, "sid", -1); | 2118 dictitem_T *sid_di = dict_find(argvars[0].vval.v_dict, |
2120 if (sid == -1) | 2119 (char_u *)"sid", 3); |
2120 if (sid_di != NULL) | |
2121 { | |
2122 int error = FALSE; | |
2123 sid = tv_get_number_chk(&sid_di->di_tv, &error); | |
2124 if (error) | |
2125 return; | |
2126 if (sid <= 0) | |
2127 { | |
2128 semsg(e_invalid_value_for_argument_str_str, "sid", | |
2129 tv_get_string(&sid_di->di_tv)); | |
2130 return; | |
2131 } | |
2132 } | |
2133 else | |
2121 { | 2134 { |
2122 pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE); | 2135 pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE); |
2123 if (pat != NULL) | 2136 if (pat != NULL) |
2124 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | 2137 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
2125 if (regmatch.regprog != NULL) | 2138 if (regmatch.regprog != NULL) |
2126 filterpat = TRUE; | 2139 filterpat = TRUE; |
2127 } | 2140 } |
2128 } | 2141 } |
2129 | 2142 |
2130 for (i = 1; i <= script_items.ga_len; ++i) | 2143 for (varnumber_T i = sid > 0 ? sid : 1; |
2144 (i == sid || sid <= 0) && i <= script_items.ga_len; ++i) | |
2131 { | 2145 { |
2132 scriptitem_T *si = SCRIPT_ITEM(i); | 2146 scriptitem_T *si = SCRIPT_ITEM(i); |
2133 dict_T *d; | 2147 dict_T *d; |
2134 | 2148 |
2135 if (si->sn_name == NULL) | 2149 if (si->sn_name == NULL) |
2136 continue; | 2150 continue; |
2137 | 2151 |
2138 if (filterpat && !vim_regexec(®match, si->sn_name, (colnr_T)0)) | 2152 if (filterpat && !vim_regexec(®match, si->sn_name, (colnr_T)0)) |
2139 continue; | |
2140 | |
2141 if (sid != -1 && sid != i) | |
2142 continue; | 2153 continue; |
2143 | 2154 |
2144 if ((d = dict_alloc()) == NULL | 2155 if ((d = dict_alloc()) == NULL |
2145 || list_append_dict(l, d) == FAIL | 2156 || list_append_dict(l, d) == FAIL |
2146 || dict_add_string(d, "name", si->sn_name) == FAIL | 2157 || dict_add_string(d, "name", si->sn_name) == FAIL |
2149 || dict_add_number(d, "version", si->sn_version) == FAIL | 2160 || dict_add_number(d, "version", si->sn_version) == FAIL |
2150 || dict_add_bool(d, "autoload", | 2161 || dict_add_bool(d, "autoload", |
2151 si->sn_state == SN_STATE_NOT_LOADED) == FAIL) | 2162 si->sn_state == SN_STATE_NOT_LOADED) == FAIL) |
2152 return; | 2163 return; |
2153 | 2164 |
2154 // When a filter pattern is specified to return information about only | 2165 // When a script ID is specified, return information about only the |
2155 // specific script(s), also add the script-local variables and | 2166 // specified script, and add the script-local variables and functions. |
2156 // functions. | 2167 if (sid > 0) |
2157 if (sid != -1) | |
2158 { | 2168 { |
2159 dict_T *var_dict; | 2169 dict_T *var_dict; |
2160 | 2170 |
2161 var_dict = dict_copy(&si->sn_vars->sv_dict, TRUE, TRUE, | 2171 var_dict = dict_copy(&si->sn_vars->sv_dict, TRUE, TRUE, |
2162 get_copyID()); | 2172 get_copyID()); |