[cmake-developers] [PATCH] Improve encoding handling on Windows

Brad King brad.king at kitware.com
Fri Jul 1 09:09:55 EDT 2016


On 07/01/2016 08:25 AM, Daniel Pfeifer wrote:
> On Fri, Jul 1, 2016 at 4:18 AM, Dāvis Mosāns <davispuh at gmail.com> wrote:
>> On Windows getenv uses ANSI codepage so it needs to be encoded to
>> internally used encoding (eg. UTF-8). Here we use _wgetenv instead
>> and encode that.

Thanks.  Clinton (in Cc) did quite a bit of work to get argv[] and
file processing to use wide character APIs on Windows.  It looks like
environment variables are next.

> Your change to the SystemTools::GetEnv function introduces memory
> leaks, since you return a pointer to a new[]-ed array.
> It seems impossible to refactor SystemTools::GetEnv to use _wgetenv
> and provide interface compatability.

We could keep our own std::map around to own the memory and use that
to retain compatibility in the existing API.

It would be nice to also offer an alternative API that passes
ownership of the result to the caller.

> You should probably introduce a function that returns std::string and
> uses GetEnvironmentVariableW internally.

The signature also needs to allow callers to determine whether the
environment variable was set to empty or not set at all.

Thanks,
-Brad



More information about the cmake-developers mailing list