To: vim_dev@googlegroups.com Subject: Patch 8.2.4754 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4754 Problem: Still using cached values after unsetting some known environment variables. Solution: Take care of the side effects. (closes #10194) Files: src/evalfunc.c, src/evalvars.c, src/misc1.c, src/proto/misc1.pro, src/vim9execute.c, src/optionstr.c, src/testdir/test_environ.vim *** ../vim-8.2.4753/src/evalfunc.c 2022-04-15 13:53:30.048708690 +0100 --- src/evalfunc.c 2022-04-15 20:23:29.422002160 +0100 *************** *** 9223,9231 **** name = tv_get_string_buf(&argvars[0], namebuf); if (argvars[1].v_type == VAR_SPECIAL && argvars[1].vval.v_number == VVAL_NULL) ! vim_unsetenv(name); else ! vim_setenv(name, tv_get_string_buf(&argvars[1], valbuf)); } /* --- 9223,9231 ---- name = tv_get_string_buf(&argvars[0], namebuf); if (argvars[1].v_type == VAR_SPECIAL && argvars[1].vval.v_number == VVAL_NULL) ! vim_unsetenv_ext(name); else ! vim_setenv_ext(name, tv_get_string_buf(&argvars[1], valbuf)); } /* *** ../vim-8.2.4753/src/evalvars.c 2022-04-15 13:53:30.048708690 +0100 --- src/evalvars.c 2022-04-15 20:23:29.422002160 +0100 *************** *** 1795,1801 **** // Environment variable, normal name or expanded name. if (*lp->ll_name == '$') ! vim_unsetenv(lp->ll_name + 1); else if (do_unlet(lp->ll_name, forceit) == FAIL) ret = FAIL; *name_end = cc; --- 1795,1801 ---- // Environment variable, normal name or expanded name. if (*lp->ll_name == '$') ! vim_unsetenv_ext(lp->ll_name + 1); else if (do_unlet(lp->ll_name, forceit) == FAIL) ret = FAIL; *name_end = cc; *** ../vim-8.2.4753/src/misc1.c 2022-04-14 20:43:52.638894555 +0100 --- src/misc1.c 2022-04-15 20:27:09.572659178 +0100 *************** *** 1910,1915 **** --- 1910,1929 ---- #endif } + /* + * Removes environment variable "name" and take care of side effects. + */ + void + vim_unsetenv_ext(char_u *var) + { + vim_unsetenv(var); + + // "homedir" is not cleared, keep using the old value until $HOME is set. + if (STRICMP(var, "VIM") == 0) + didset_vim = FALSE; + else if (STRICMP(var, "VIMRUNTIME") == 0) + didset_vimruntime = FALSE; + } /* * Set environment variable "name" and take care of side effects. *************** *** 1922,1929 **** init_homedir(); else if (didset_vim && STRICMP(name, "VIM") == 0) didset_vim = FALSE; ! else if (didset_vimruntime ! && STRICMP(name, "VIMRUNTIME") == 0) didset_vimruntime = FALSE; } #endif --- 1936,1942 ---- init_homedir(); else if (didset_vim && STRICMP(name, "VIM") == 0) didset_vim = FALSE; ! else if (didset_vimruntime && STRICMP(name, "VIMRUNTIME") == 0) didset_vimruntime = FALSE; } #endif *** ../vim-8.2.4753/src/proto/misc1.pro 2022-04-09 18:17:30.056746549 +0100 --- src/proto/misc1.pro 2022-04-15 20:23:29.422002160 +0100 *************** *** 32,37 **** --- 32,38 ---- void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, int esc, int one, char_u *startstr); char_u *vim_getenv(char_u *name, int *mustfree); void vim_unsetenv(char_u *var); + void vim_unsetenv_ext(char_u *var); void vim_setenv_ext(char_u *name, char_u *val); void vim_setenv(char_u *name, char_u *val); char_u *get_env_name(expand_T *xp, int idx); *** ../vim-8.2.4753/src/vim9execute.c 2022-04-14 12:58:19.604895030 +0100 --- src/vim9execute.c 2022-04-15 20:23:29.426002162 +0100 *************** *** 2656,2661 **** --- 2656,2662 ---- case ISN_SOURCE: { int notused; + SOURCING_LNUM = iptr->isn_lnum; if (may_load_script((int)iptr->isn_arg.number, ¬used) == FAIL) *************** *** 3490,3496 **** goto on_error; break; case ISN_UNLETENV: ! vim_unsetenv(iptr->isn_arg.unlet.ul_name); break; case ISN_LOCKUNLOCK: --- 3491,3497 ---- goto on_error; break; case ISN_UNLETENV: ! vim_unsetenv_ext(iptr->isn_arg.unlet.ul_name); break; case ISN_LOCKUNLOCK: *** ../vim-8.2.4753/src/optionstr.c 2022-04-15 13:53:30.044708701 +0100 --- src/optionstr.c 2022-04-15 20:27:26.920504456 +0100 *************** *** 644,650 **** /* * Handle string options that need some action to perform when changed. ! * Returns NULL for success, or an error message for an error. */ char * did_set_string_option( --- 644,650 ---- /* * Handle string options that need some action to perform when changed. ! * Returns NULL for success, or an unstranslated error message for an error. */ char * did_set_string_option( *************** *** 787,801 **** { // May compute new values for $VIM and $VIMRUNTIME if (didset_vim) ! { ! vim_setenv((char_u *)"VIM", (char_u *)""); ! didset_vim = FALSE; ! } if (didset_vimruntime) ! { ! vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); ! didset_vimruntime = FALSE; ! } } #ifdef FEAT_SYN_HL --- 787,795 ---- { // May compute new values for $VIM and $VIMRUNTIME if (didset_vim) ! vim_unsetenv_ext((char_u *)"VIM"); if (didset_vimruntime) ! vim_unsetenv_ext((char_u *)"VIMRUNTIME"); } #ifdef FEAT_SYN_HL *** ../vim-8.2.4753/src/testdir/test_environ.vim 2020-09-27 15:03:11.504543029 +0100 --- src/testdir/test_environ.vim 2022-04-15 20:47:53.183491035 +0100 *************** *** 28,33 **** --- 28,53 ---- call assert_equal(v:null, getenv('TEST ENV')) endfunc + func Test_special_env() + " The value for $HOME is cached internally by Vim, ensure the value is up to + " date. + let orig_ENV = $HOME + + let $HOME = 'foo' + call assert_equal('foo', expand('~')) + " old $HOME value is kept until a new one is set + unlet $HOME + call assert_equal('foo', expand('~')) + + call setenv('HOME', 'bar') + call assert_equal('bar', expand('~')) + " old $HOME value is kept until a new one is set + call setenv('HOME', v:null) + call assert_equal('bar', expand('~')) + + let $HOME = orig_ENV + endfunc + func Test_external_env() call setenv('FOO', 'HelloWorld') if has('win32') *** ../vim-8.2.4753/src/version.c 2022-04-15 13:53:30.056708670 +0100 --- src/version.c 2022-04-15 20:49:02.543361955 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4754, /**/ -- Imagine a world without hypothetical situations. /// 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 ///