Skip to content

Conversation

@eldakesh-ms
Copy link
Contributor

put_time(%r) does the wrong thing when we use the C locale, due to some
internal machinery. It could get fixed further down level, but that
change is a lot more impactful. Instead, we simply rewrite %r when the C
locale is used in chrono.

This basically has to do with the way that _Strftime, _Gettnames, and
expand_time work together. _Gettnames returns a copy of its data and
expand_time figures out the locale based on pointer comparison.

put_time(%r) does the wrong thing when we use the C locale, due to some
internal machinery. It could get fixed further down level, but that
change is a lot more impactful. Instead, we simply rewrite %r when the C
locale is used in chrono.

This basically has to do with the way that _Strftime, _Gettnames, and
expand_time work together. _Gettnames returns a copy of its data and
expand_time figures out the locale based on pointer comparison.
@eldakesh-ms eldakesh-ms requested a review from a team as a code owner April 20, 2021 15:21
@mnatsuhara mnatsuhara added the chrono C++20 chrono label Apr 20, 2021
Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My single comment isn't blocking, otherwise looks good!

Comment on lines +6004 to +6009
// put_time uses _Strftime in order to bypass reference-counting that locale uses. This function
// takes the locale information by pointer, but the pointer (from _Gettnames) returns a copy.
// _Strftime delegates to other functions but eventually (for the C locale) has the %r specifier
// rewritten. It checks for the locale by comparing pointers, which do not compare equal as we have
// a copy of the pointer instead of the original. Therefore, we replace %r for the C locale
// ourselves.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're reporting this as a UCRT bug (which I think was our conclusion in the internal chat), should this be marked as // TRANSITION, ... with a bug number? Theoretically, we won't have to special-case this forever!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly a UCRT bug. They can't really tell we mean the C locale when we pass it in through _Strftime because they are fundamentally different pointers. And we are the ones trying to circumvent the ref counting of locale. Maybe we can fix time_put? People might rely on the %r behavior though...

@eldakesh-ms eldakesh-ms merged commit d488200 into microsoft:chronat2 Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chrono C++20 chrono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants