-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of platform-independ environment manipulations #1272
Conversation
I like the idea in general but I dunno why
For 2) needs to be taken care of as we use it everywhere and if there's something wrong for windows it should be fixed there. Also please replace _WIN32 by TARGET_WINDOWS. |
@wsoltys Answers: :)
_WIN32 is replaced. |
Before we even get into the code, where is the bug? |
At least one bug here, in Application.cpp:
We are trying to set "XBMC_HOME", so next call to CUtil::GetHomePath should use this environment variable instead of full detection. But "GetHomePath" uses runtime function "_wgetenv" (which one operates with separate environment copy) and never get this variable, so every time "GetHomePath" uses full detection again. As I see, XBMC code uses widely "SetEnvironmentVariable" (as it simpler than "putenv") for setting variables, but uses "getenv" for reading it (as it simpler than "GetEnvironmentVariable"). But it's wrong, as "getenv" will not see changes made by "SetEnvironmentVariable" and vice versa. To properly change variable on win32 platform you need to update it in:
Currently XBMC uses in some places "win32env.c" to update environment for python, but "win32env.c" is buggy and could crash after library unloading. If this code go to XBMC, we will need to get rid of "win32env.c". |
Given that win32env.cpp comes directly out of PostgreSQL, I'd suggest if there are any bugs in that code, you should direct them to PostgreSQL first and foremost. Perhaps any bugs are really only due to it's use in XBMC? If you want this accepted, remove all MultiByteToWideChar stuff, get rid of everything except char* (utf8) versions of put/get/set/unset designed so they work exactly like posix where doable. Once the trees are cleared we might be able to see the forest. |
@jmarshallnz May be PostgreSQL don't unload libs at runtime - I don't know. I removed all win32 charset conversions and split code to several commits. convertFromUtf8 and convertToUtf8 is just a wrappers for charsetconverter with additional checks and shortcuts useful mainly to Environment functions. |
@jmarshallnz @wsoltys |
Please drop the wide char versions - they're not required at all except for Further, you can probably drop the char * ones from the API as well and On Mon, Aug 27, 2012 at 10:08 AM, Karlson2k notifications@github.comwrote:
|
@jmarshallnz OK, wide char is really rare. |
I know, thus the suggest to accept a const std::string & which will quite happily take both. |
@jmarshallnz Rewritten. |
@jmarshallnz What can I do to improve this PR even more? :) |
@jmarshallnz @wsoltys |
XBMC does everything in utf8. Drop all wstring functions as they're not needed. Under which circumstances is the charset convertor not available? |
Apparently a wchar version was needed: c5f50fb |
Isn't that one just being used for utf8? On Mon, Apr 8, 2013 at 9:15 AM, wsoltys notifications@github.com wrote:
|
@chadoe can you tell us why the UTF8->wchar conversion was needed? |
I didn't read everything here but for the change @wsoltys is referring to: |
@wsoltys @jmarshallnz wchar version is mostly for win32-only code sections. It's easy to use wchar in win32 as windows doesn't support UTF-8 as input/output (except charset conversion functions). @jmarshallnz XBMC's charset converter is not available before initialization / if shutdown in progress. Same as for CLog: https://github.com/xbmc/xbmc/blob/master/xbmc/utils/log.cpp#L226 |
Is the environment stuff even used before initialization or after shutdown? If it is, then I'd tend to use the win32 API entirely for the utf8->wide conversion. If it's not, use the charsetconverter everywhere. Mixing and matching doesn't make much sense. XBMC doesn't use a wchar version of set/putenv at all so requires only a utf8 version (obviously wrapped to the wide API). There's no point having wrapping code that isn't used. |
Wchar is used only in https://github.com/xbmc/xbmc/blob/master/xbmc/win32/WIN32Util.cpp#L503 and https://github.com/xbmc/xbmc/blob/master/xbmc/win32/WIN32Util.cpp#L513, so wrappers can be really removed. Should I move all function to some class (XBMCEnv?) or to another namespace? |
Yeah, agreed - just use the win32 API for conversion to keep it simple. It might be useful to wrap in a (static?) class I guess. If so, keep the name of the functions simple, corresponding to the name of the posix function (SetEnv, PutEnv etc.) |
@jmarshallnz Rebased, all public wchar_t/wstring functions removed, WStdString usage removed, everything moved into static class, some functions was refactored, some rewritten. |
return CXbmcEnv::win32ConvertWToUtf8(Wvalue.c_str()); | ||
#else | ||
return std::string(::getenv(name.c_str())); | ||
#endif |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return Wret; | ||
} | ||
|
||
std::string CXbmcEnv::win32ConvertWToUtf8(const wchar_t *text, bool *resultSuccessful /*= NULL*/) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Just a few cosmetic comments more than anything. One last one: I'd name it Environment.h/cpp (CEnvironment) - we don't need to know it's in Xbmc :) |
@jmarshallnz Done + few more cosmetics. |
@@ -344,6 +344,10 @@ | |||
#include "android/activity/XBMCApp.h" | |||
#endif | |||
|
|||
#ifdef TARGET_WINDOWS | |||
#include "utils/XbmcEnv.h" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Looks good. Build needs testing on Linux, else drop the Makefile change. Will merge in May window. |
Small correction for Linux (replace "pop_back" with "erase" for std::string). "pop_back" is part of C++11, but for it's available on MSVC C++98. |
@jmarshallnz Is it OK for May window? |
@Memphiz Needs sync xcode projects. |
Fixed typo in comment |
@jmarshallnz Postpone until next window? |
If you drop the Makefile change it shouldn't affect other platforms at all, right? Or, if you've build tested on linux, the Makefile change can stay. Either or, I'm happy to pull this in as soon as that is done (this window). |
It's build tested on Linux (Ubuntu). |
Not according to github - needs rebase. |
…nment manipulation and add it files to project and to Makefile.in
@jmarshallnz, it's ready again. :) |
Implementation of platform-independ environment manipulations
Thanks :) |
@Memphiz Branch was merged, need xcode projects sync. |
@Karlson2k - done - i guess it needs codechanges somewhere to make use of it? |
Those functions are mostly wrappers around system native function. Special tricks used only on win32. |
We shouldn't display that error message to the GUI. It's been replaced by an error log message as requested.
While debugging of XBMC, I've discovered that win32 environment manipulation isn't working at all.
The problem is that win32 functions SetEnvironmentVariable/GetEnvironmentVariable and runtime functions getenv/putenv operate with separate copies of Environment. So after set (for example) of 'XBMC_HOME' with SetEnvironmentVariable, next call to getenv for 'XBMC_HOME' returns error (variable not set).
Other problem on win32 platform, that XBMC use UTF-8 for CStdString, but when it converted to 'char *' win32 use it as ANSI or OEM encoding. That can cause problems if variable value contains some national characters, as paths variables.
One more problem for win32 - different runtime libraries for third-party modules, which should be updated separately. This is done partially by win32env.c, but that implementation is buggy (new loaded libraries isn't checked, can potentially crash after library unload).
This implementation is uniform for all platforms, so we can drop a lot of "ifdef"s in code.
All UTF-8<->wide conversion is carefully implemented internally where is't needed.
Almost all strings forms used in XBMC is supported as arguments.
This PR is adds new functions support and only a few function uses (as a test), and only for win32 platform.
If it's OK, I'll create more PRs with total replace for setenv/getenv functions.