Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

blueyed
Copy link

@blueyed blueyed commented Jul 30, 2019

@k-takata
Copy link
Member

Setting an empty string to an environment variable deletes the variable on Windows.
So, exists() will return 0 on Windows.

@blueyed
Copy link
Author

blueyed commented Jul 30, 2019

Setting an empty string to an environment variable deletes the variable on Windows.

Is that a Windows issue, or due to how Vim does it?
It appears to work with Neovim, which uses libuv.

For setting: https://github.com/neovim/libuv/blob/c41b31ed3b88aacae1d8498d0f3f6bbc20d56f9a/src/win/util.c#L1456-L1484

But likely more related to how it gets it: https://github.com/neovim/libuv/blob/c41b31ed3b88aacae1d8498d0f3f6bbc20d56f9a/src/win/util.c#L1456-L1484
It uses GetEnvironmentVariableW and checks for ERROR_ENVVAR_NOT_FOUND when it gets an empty value.

@k-takata
Copy link
Member

Is that a Windows issue, or due to how Vim does it?

It's the behavior of _wputenv. The set command of cmd.exe is also the same. So, this behavior is natural for Windows users.
It seems that SetEnvironmentVariable API can set an empty string, but it doesn't set an environment variable for C runtime library. So we cannot use it. (E.g. gettext depends on it.)

@blueyed
Copy link
Author

blueyed commented Jul 30, 2019

I see. Should we adjust this test and the one in #4751 for win32 behavior then?

@k-takata
Copy link
Member

I think so.

@blueyed
Copy link
Author

blueyed commented Jul 30, 2019

btw: I've also noted that getenv() might return something that environ() does not contain:

unlet! $VIMRUNTIME
" Fails
echo environ()['VIMRUNTIME']
" Works
echo getenv('VIMRUNTIME')
echo environ()['VIMRUNTIME']

This is due to the side-effect of vim_getenv handling and setting this.

@brammool
Copy link
Contributor

This is not portable, different systems have different ideas about whether an environment variable with an empty value exists or not.
The special handling of $VIMRUNTIME is documented, I thought. Anyway, one should not delete it.
I don't think we should have a test for undefined behavior.

@brammool brammool closed this Jul 30, 2019
@blueyed
Copy link
Author

blueyed commented Jul 30, 2019

different systems have different ideas about whether an environment variable with an empty value exists or not.
I don't think we should have a test for undefined behavior.

I think Vim is defining it in this case (since Neovim handles it differently on the same system (Windows)), and if the special behavior with win32 is kept, then it would be good to have this tested / documented.
It is not "undefined" really as in "changes randomly".

blueyed added a commit to blueyed/vim that referenced this pull request Aug 8, 2019
This adds coverage for this in general, and tests the specific/current
behavior on Windows.

Ref: vim#4750 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants