-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
ICU-13842 Use GetDynamicTimeZoneInformation instead of Windows registry access in wintz.cpp #55
ICU-13842 Use GetDynamicTimeZoneInformation instead of Windows registry access in wintz.cpp #55
Conversation
icu4c/source/common/wintz.cpp
Outdated
// This file contains only desktop Windows behavior | ||
// Windows UWP calls Windows::Globalization directly, so this isn't needed there. | ||
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0) | ||
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API [](start = 2, length = 61)
Doesn't this also require changes elsewhere, specifically in the caller? putil.cpp has this, which seems like it is wrong now:
#if U_PLATFORM_HAS_WINUWP_API == 0
include "wintz.h"
#else // U_PLATFORM_HAS_WINUWP_API
typedef PVOID LPMSG; // TODO: figure out how to get rid of this typedef
#include <Windows.Globalization.h>
#include <windows.system.userprofile.h>
#include <wrl/wrappers/corewrappers.h>
#include <wrl/client.h>
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
#endif
And then of course the actual call site. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commits fixed the related codes for this change.
icu4c/source/common/wintz.cpp
Outdated
|
||
Author: Alan Liu | ||
Since: ICU 2.6 | ||
Based on original code by Carl Brown <cbrown@xnetinc.com> | ||
|
||
Modified on 8/13/2018 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment.
I don't think any changes/modification history are recorded in the source comments anymore. (Or I haven't see anyone do this recently). I would suggest removing this comment, as the change history is stored in Git now.
icu4c/source/common/wintz.cpp
Outdated
icuid = (char*)uprv_calloc(len + 1, sizeof(char)); | ||
if (icuid != NULL) | ||
{ | ||
uprv_strcpy(icuid, tmpid); | ||
uprv_wcstombs(icuid, dynamicTZI.TimeZoneKeyName, len + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right. This will actually end up using wcstombs
to convert the string, meaning that it will be converted from UTF-16 (wide string) to a code-page dependent string -- which isn't what you want at all.
icu4c/source/common/wintz.cpp
Outdated
@@ -36,174 +34,16 @@ | |||
|
|||
#define MAX_LENGTH_ID 40 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest update uses it.
@@ -13,14 +13,12 @@ | |||
|
|||
#include "unicode/utypes.h" | |||
|
|||
// This file contains only desktop Windows behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is currently excluded from the UWP project file for the common
project. If the plan is to replace the Windows.Globalization code with this API call (which is goodness), then you will need to modify the common_uwp.vcxproj
file too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is updated in the latest change.
icu4c/source/common/wintz.cpp
Outdated
{ | ||
UResourceBundle* winTZ = ures_getByKey(bundle, regStdName, NULL, &status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still need to look up the ICU time zone in the resources. You can't just take the Windows time zone string from the API and just return that.
You need to handle the Windows -> IANA/CLDR time zone mapping.
icu4c/source/common/wintz.cpp
Outdated
} | ||
} | ||
|
||
ures_close(bundle); | ||
|
||
return icuid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the mapping between the Windows Time zone names and the ICU Time zone names handled? I don't see it anywhere in here. In fact it looks like you deleted the code that currently does that. (Perhaps that was an accident?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
icu4c/source/common/wintz.h
Outdated
@@ -18,7 +18,7 @@ | |||
|
|||
// This file contains only desktop windows behavior | |||
// Windows UWP calls Windows::Globalization directly, so this isn't needed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer correct. You should likely remove it. #Resolved
icu4c/source/common/wintz.h
Outdated
@@ -18,7 +18,7 @@ | |||
|
|||
// This file contains only desktop windows behavior | |||
// Windows UWP calls Windows::Globalization directly, so this isn't needed there. | |||
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0) | |||
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could probably be changed to just U_PLATFORM_HAS_WIN32_API
.
icu4c/source/common/wintz.cpp
Outdated
// This file contains only desktop Windows behavior | ||
// Windows UWP calls Windows::Globalization directly, so this isn't needed there. | ||
#if U_PLATFORM_USES_ONLY_WIN32_API && (U_PLATFORM_HAS_WINUWP_API == 0) | ||
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM_HAS_WINUWP_API | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could likely be changed to just U_PLATFORM_HAS_WIN32_API
.
icu4c/source/common/wintz.cpp
Outdated
if(ERROR_SUCCESS == result) | ||
/* Convert the wchar_t* standard name to char* */ | ||
uprv_memset(dynamicTZKeyName, 0, sizeof(dynamicTZKeyName)); | ||
wcstombs(dynamicTZKeyName, dynamicTZI.TimeZoneKeyName, MAX_LENGTH_ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wcstombs [](start = 4, length = 8)
We still don't want to use/call this API. The results that it gives are OS-locale/codepage dependent, and the API that we are calling now is not.
GetDynamicTimeZoneInformation TimeZoneKeyName is UTF-16 encoded.
We should probably use something like u_strToUTF8
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the PR here for an example of how to use it:
https://github.com/unicode-org/icu/pull/31/files
In reply to: 211446320 [](ancestors = 211446320)
icu4c/source/common/wintz.cpp
Outdated
@@ -36,219 +34,31 @@ | |||
|
|||
#define MAX_LENGTH_ID 40 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAX_LENGTH_ID [](start = 8, length = 13)
Note: The size/number is not correct anymore.
TimeZoneKeyName can be up to 128 WCHARs long, so 40 is way to small now. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks!
icu4c/source/common/wintz.cpp
Outdated
{ | ||
UErrorCode status = U_ZERO_ERROR; | ||
UResourceBundle* bundle = NULL; | ||
char* icuid = NULL; | ||
char apiStdName[MAX_LENGTH_ID]; | ||
char regStdName[MAX_LENGTH_ID]; | ||
char dynamicTZKeyName[MAX_LENGTH_ID]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we zero init this like this?:
char dynamicTZKeyName[MAX_LENGTH_ID] = {};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @mingyzha !
It is looking better, but please take a look at the recent comments. Thanks!
icu4c/source/common/wintz.cpp
Outdated
SYSTEMTIME standardDate; | ||
SYSTEMTIME daylightDate; | ||
} TZI; | ||
#define MAX_LENGTH_ID 128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment for this define to indicate where the value comes from?
Nit: Also I wonder if MAX_TIMEZONE_ID_LENGTH
might be slightly more clear? (Up to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments added. Thanks!
icu4c/source/common/wintz.cpp
Outdated
wcstombs(apiStdName, apiTZI.StandardName, MAX_LENGTH_ID); | ||
/* Obtain TIME_ZONE_INFORMATION from the API and get the non-localized time zone name. */ | ||
uprv_memset(&dynamicTZI, 0, sizeof(dynamicTZI)); | ||
GetDynamicTimeZoneInformation(&dynamicTZI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetDynamicTimeZoneInformation [](start = 4, length = 29)
Check for failure? #Closed
Thanks @mingyzha! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
…ry access in wintz.cpp (unicode-org#55) Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
This reverts commit ccad447 in M71 branch. There's an issue with DST detection so that we revert it in M71 branch. For M72 or later, we'll find a better fix. > Fix the timezone detection on Windows with RDP. > > This is to cherry-pick fixes from the upstream to fix > the timezone detection issue when a remote Windows > session is used. The detected timezone should be that of > a remote machine Chrome is running on, but without this > fix, it uses the timezone of machine where a RDP connection > originates. > > Bugs: > > https://unicode-org.atlassian.net/browse/ICU-13842 > https://unicode-org.atlassian.net/browse/ICU-13827 > > Fixes (included in the upstream ICU 63 release candidate) > unicode-org/icu#55 > unicode-org/icu#129 > > TBR=yangguo@chromium.org > Bug: 854387 > Test: Manual. See the bug > Change-Id: Ic21e82987c1569e107d9b5e17bdc0d21e65fda3c > Reviewed-on: https://chromium-review.googlesource.com/c/1270635 Bug: 854387, 913298
…h RDP."" This reverts commit 751b643, which reverted the following earlier commit (ccad447) to deal with a regression on Windows 7 timezone detection. (https://crbug.com/913298) This CL will reintroduce the change made in ccad447 for bug 854387 to M71 branch and be followed by the proper fix for bug 913298. > Fix the timezone detection on Windows with RDP. > > This is to cherry-pick fixes from the upstream to fix > the timezone detection issue when a remote Windows > session is used. The detected timezone should be that of > a remote machine Chrome is running on, but without this > fix, it uses the timezone of machine where a RDP connection > originates. > > Bugs: > > https://unicode-org.atlassian.net/browse/ICU-13842 > https://unicode-org.atlassian.net/browse/ICU-13827 > > Fixes (included in the upstream ICU 63 release candidate) > unicode-org/icu#55 > unicode-org/icu#129 > > TBR=yangguo@chromium.org > Bug: 854387 > Test: Manual. See the bug > Change-Id: Ic21e82987c1569e107d9b5e17bdc0d21e65fda3c > Reviewed-on: https://chromium-review.googlesource.com/c/1270635 Bug: 854387, 913298 Test: Manual. See the bug
…verter add comment about ratesInfo param in UnitConverter
Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
Checklist