To: vim_dev@googlegroups.com Subject: Patch 8.2.4375 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4375 Problem: ctx_imports is not used. Solution: Delete ctx_imports. Add missing dependency. Files: src/vim9.h, src/vim9compile.c, src/proto/vim9compile.pro, src/eval.c, src/evalfunc.c, src/evalvars.c, src/userfunc.c, src/vim9expr.c, src/vim9script.c, src/Makefile *** ../vim-8.2.4374/src/vim9.h 2022-01-25 15:51:52.430855187 +0000 --- src/vim9.h 2022-02-13 21:48:10.836678533 +0000 *************** *** 691,697 **** } lhs_T; /* ! * Context for compiling lines of Vim script. * Stores info about the local variables and condition stack. */ struct cctx_S { --- 691,697 ---- } lhs_T; /* ! * Context for compiling lines of a :def function. * Stores info about the local variables and condition stack. */ struct cctx_S { *************** *** 710,717 **** int ctx_has_closure; // set to one if a closure was created in // the function - garray_T ctx_imports; // imported items - skip_T ctx_skip; scope_T *ctx_scope; // current scope, NULL at toplevel int ctx_had_return; // last seen statement was "return" --- 710,715 ---- *** ../vim-8.2.4374/src/vim9compile.c 2022-02-13 21:20:17.458804169 +0000 --- src/vim9compile.c 2022-02-13 21:44:41.804916759 +0000 *************** *** 281,287 **** && (lookup_local(name, len, NULL, cctx) == OK || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)) || script_var_exists(name, len, cctx, NULL) == OK ! || find_imported(name, len, FALSE, cctx) != NULL; } /* --- 281,287 ---- && (lookup_local(name, len, NULL, cctx) == OK || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)) || script_var_exists(name, len, cctx, NULL) == OK ! || find_imported(name, len, FALSE) != NULL; } /* *************** *** 329,335 **** if ((cctx != NULL && (lookup_local(p, len, NULL, cctx) == OK || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) ! || find_imported(p, len, FALSE, cctx) != NULL || (ufunc = find_func_even_dead(p, 0)) != NULL) { // A local or script-local function can shadow a global function. --- 329,335 ---- if ((cctx != NULL && (lookup_local(p, len, NULL, cctx) == OK || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) ! || find_imported(p, len, FALSE) != NULL || (ufunc = find_func_even_dead(p, 0)) != NULL) { // A local or script-local function can shadow a global function. *************** *** 594,629 **** } /* ! * Find "name" in imported items of the current script or in "cctx" if not ! * NULL. * If "load" is TRUE and the script was not loaded yet, load it now. */ imported_T * ! find_imported(char_u *name, size_t len, int load, cctx_T *cctx) { ! int idx; ! imported_T *ret = NULL; if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) return NULL; - if (cctx != NULL) - for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx) - { - imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data) - + idx; - - if (len == 0 ? STRCMP(name, import->imp_name) == 0 - : STRLEN(import->imp_name) == len - && STRNCMP(name, import->imp_name, len) == 0) - { - ret = import; - break; - } - } - - if (ret == NULL) - ret = find_imported_in_script(name, len, current_sctx.sc_sid); if (ret != NULL && load && (ret->imp_flags & IMP_FLAGS_AUTOLOAD)) { scid_T dummy; --- 594,611 ---- } /* ! * Find "name" in imported items of the current script. * If "load" is TRUE and the script was not loaded yet, load it now. */ imported_T * ! find_imported(char_u *name, size_t len, int load) { ! imported_T *ret; if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) return NULL; + ret = find_imported_in_script(name, len, current_sctx.sc_sid); if (ret != NULL && load && (ret->imp_flags & IMP_FLAGS_AUTOLOAD)) { scid_T dummy; *************** *** 637,659 **** } /* - * Free all imported variables. - */ - static void - free_imported(cctx_T *cctx) - { - int idx; - - for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx) - { - imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data) + idx; - - vim_free(import->imp_name); - } - ga_clear(&cctx->ctx_imports); - } - - /* * Called when checking for a following operator at "arg". When the rest of * the line is empty or only a comment, peek the next line. If there is a next * line return a pointer to it and set "nextp". --- 619,624 ---- *************** *** 1364,1370 **** : script_var_exists(var_start, lhs->lhs_varlen, cctx, NULL)) == OK; imported_T *import = ! find_imported(var_start, lhs->lhs_varlen, FALSE, cctx); if (script_namespace || script_var || import != NULL) { --- 1329,1335 ---- : script_var_exists(var_start, lhs->lhs_varlen, cctx, NULL)) == OK; imported_T *import = ! find_imported(var_start, lhs->lhs_varlen, FALSE); if (script_namespace || script_var || import != NULL) { *************** *** 2600,2606 **** ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10); // Each entry on the type stack consists of two type pointers. ga_init2(&cctx.ctx_type_stack, sizeof(type2_T), 50); - ga_init2(&cctx.ctx_imports, sizeof(imported_T), 10); cctx.ctx_type_list = &ufunc->uf_type_list; ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50); instr = &cctx.ctx_instr; --- 2565,2570 ---- *************** *** 3291,3297 **** estack_pop(); ga_clear_strings(&lines_to_free); - free_imported(&cctx); free_locals(&cctx); ga_clear(&cctx.ctx_type_stack); return ret; --- 3255,3260 ---- *** ../vim-8.2.4374/src/proto/vim9compile.pro 2022-02-08 21:17:18.885463903 +0000 --- src/proto/vim9compile.pro 2022-02-13 21:34:50.429609070 +0000 *************** *** 8,14 **** int need_type(type_T *actual, type_T *expected, int offset, int arg_idx, cctx_T *cctx, int silent, int actual_is_const); lvar_T *reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type); int get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx, cstack_T *cstack); ! imported_T *find_imported(char_u *name, size_t len, int load, cctx_T *cctx); char_u *may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp); char_u *peek_next_line_from_context(cctx_T *cctx); char_u *next_line_from_context(cctx_T *cctx, int skip_comment); --- 8,14 ---- int need_type(type_T *actual, type_T *expected, int offset, int arg_idx, cctx_T *cctx, int silent, int actual_is_const); lvar_T *reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type); int get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx, cstack_T *cstack); ! imported_T *find_imported(char_u *name, size_t len, int load); char_u *may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp); char_u *peek_next_line_from_context(cctx_T *cctx); char_u *next_line_from_context(cctx_T *cctx, int skip_comment); *** ../vim-8.2.4374/src/eval.c 2022-02-13 11:57:25.283251618 +0000 --- src/eval.c 2022-02-13 21:31:53.121826858 +0000 *************** *** 967,974 **** if (*p == '.') { ! imported_T *import = find_imported(lp->ll_name, p - lp->ll_name, ! TRUE, NULL); if (import != NULL) { --- 967,973 ---- if (*p == '.') { ! imported_T *import = find_imported(lp->ll_name, p - lp->ll_name, TRUE); if (import != NULL) { *** ../vim-8.2.4374/src/evalfunc.c 2022-02-12 11:18:32.318462415 +0000 --- src/evalfunc.c 2022-02-13 21:32:25.177786934 +0000 *************** *** 3131,3137 **** dot = vim_strchr(func, '.'); if (dot != NULL) { ! imported_T *import = find_imported(func, dot - func, TRUE, NULL); if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) { --- 3131,3137 ---- dot = vim_strchr(func, '.'); if (dot != NULL) { ! imported_T *import = find_imported(func, dot - func, TRUE); if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) { *** ../vim-8.2.4374/src/evalvars.c 2022-02-13 13:56:25.798074089 +0000 --- src/evalvars.c 2022-02-13 21:33:12.541728410 +0000 *************** *** 2735,2741 **** char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name; if (sid == 0) ! import = find_imported(p, 0, TRUE, NULL); // imported variable from another script if (import != NULL || sid != 0) --- 2735,2741 ---- char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name; if (sid == 0) ! import = find_imported(p, 0, TRUE); // imported variable from another script if (import != NULL || sid != 0) *************** *** 3096,3102 **** res = HASHITEM_EMPTY(hi) ? FAIL : OK; // if not script-local, then perhaps imported ! if (res == FAIL && find_imported(p, 0, FALSE, NULL) != NULL) res = OK; if (p != buffer) vim_free(p); --- 3096,3102 ---- res = HASHITEM_EMPTY(hi) ? FAIL : OK; // if not script-local, then perhaps imported ! if (res == FAIL && find_imported(p, 0, FALSE) != NULL) res = OK; if (p != buffer) vim_free(p); *************** *** 3491,3497 **** if (di == NULL && var_in_vim9script) { ! imported_T *import = find_imported(varname, 0, FALSE, NULL); if (import != NULL) { --- 3491,3497 ---- if (di == NULL && var_in_vim9script) { ! imported_T *import = find_imported(varname, 0, FALSE); if (import != NULL) { *************** *** 4696,4702 **** p = vim_strchr(name, '.'); if (p == NULL) return; ! import = find_imported(name, p - name, FALSE, NULL); if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) { scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); --- 4696,4702 ---- p = vim_strchr(name, '.'); if (p == NULL) return; ! import = find_imported(name, p - name, FALSE); if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) { scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); *** ../vim-8.2.4374/src/userfunc.c 2022-02-13 11:57:25.283251618 +0000 --- src/userfunc.c 2022-02-13 21:33:33.637702536 +0000 *************** *** 1614,1620 **** p = name + 2; len -= 2; } ! import = find_imported(p, len, FALSE, NULL); // imported function from another script if (import != NULL) --- 1614,1620 ---- p = name + 2; len -= 2; } ! import = find_imported(p, len, FALSE); // imported function from another script if (import != NULL) *************** *** 4591,4598 **** { char_u *uname = untrans_function_name(name); ! import = find_imported(uname == NULL ? name : uname, 0, ! FALSE, NULL); } if (fp != NULL || import != NULL) --- 4591,4597 ---- { char_u *uname = untrans_function_name(name); ! import = find_imported(uname == NULL ? name : uname, 0, FALSE); } if (fp != NULL || import != NULL) *** ../vim-8.2.4374/src/vim9expr.c 2022-02-08 21:17:18.881463910 +0000 --- src/vim9expr.c 2022-02-13 21:34:26.929637535 +0000 *************** *** 266,272 **** return OK; } ! import = end == NULL ? NULL : find_imported(name, 0, FALSE, cctx); if (import != NULL) { char_u *p = skipwhite(*end); --- 266,272 ---- return OK; } ! import = end == NULL ? NULL : find_imported(name, 0, FALSE); if (import != NULL) { char_u *p = skipwhite(*end); *************** *** 502,508 **** // "var" can be script-local even without using "s:" if it // already exists in a Vim9 script or when it's imported. if (script_var_exists(*arg, len, cctx, NULL) == OK ! || find_imported(name, 0, FALSE, cctx) != NULL) res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE); // When evaluating an expression and the name starts with an --- 502,508 ---- // "var" can be script-local even without using "s:" if it // already exists in a Vim9 script or when it's imported. if (script_var_exists(*arg, len, cctx, NULL) == OK ! || find_imported(name, 0, FALSE) != NULL) res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE); // When evaluating an expression and the name starts with an *************** *** 681,687 **** } vim_strncpy(namebuf, *arg, varlen); ! import = find_imported(name, varlen, FALSE, cctx); if (import != NULL) { semsg(_(e_cannot_use_str_itself_it_is_imported), namebuf); --- 681,687 ---- } vim_strncpy(namebuf, *arg, varlen); ! import = find_imported(name, varlen, FALSE); if (import != NULL) { semsg(_(e_cannot_use_str_itself_it_is_imported), namebuf); *** ../vim-8.2.4374/src/vim9script.c 2022-02-08 21:17:18.881463910 +0000 --- src/vim9script.c 2022-02-13 21:34:33.517629549 +0000 *************** *** 593,599 **** { imported_T *imported; ! imported = find_imported(as_name, STRLEN(as_name), FALSE, cctx); if (imported != NULL && imported->imp_sid != sid) { semsg(_(e_name_already_defined_str), as_name); --- 593,599 ---- { imported_T *imported; ! imported = find_imported(as_name, STRLEN(as_name), FALSE); if (imported != NULL && imported->imp_sid != sid) { semsg(_(e_name_already_defined_str), as_name); *** ../vim-8.2.4374/src/Makefile 2022-02-02 15:19:08.652845890 +0000 --- src/Makefile 2022-02-13 21:47:08.664749176 +0000 *************** *** 4187,4193 **** objects/vim9type.o: vim9type.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ ! proto.h globals.h errors.h objects/viminfo.o: viminfo.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ --- 4187,4193 ---- objects/vim9type.o: vim9type.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ ! proto.h globals.h errors.h vim9.h objects/viminfo.o: viminfo.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ *** ../vim-8.2.4374/src/version.c 2022-02-13 21:20:17.458804169 +0000 --- src/version.c 2022-02-13 21:27:16.886184649 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4375, /**/ -- Bumper sticker: Honk if you love peace and quiet. /// Bram Moolenaar -- Bram@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 ///