Skip to content
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

Remove SString ANSI representation. #71186

Merged
merged 8 commits into from
Jun 24, 2022

Conversation

jkoritzinsky
Copy link
Member

99% of usages were just ASCII, so switch to using UTF8 as the underlying representation as it will have the same semantics for ASCII strings.

The main area of concern would be in the implementation of SString::VPrintf(CHAR*, ...). I believe this will work correctly, but I'd like a second pair of eyes to verify.

Builds off of some of the ideas in #69748

99% of usages were just ASCII, so switch to using UTF8 as the underlying representation as it will have the same semantics for ASCII strings.

The main area of concern would be in the implementation of `SString::VPrintf(CHAR*, ...)`. I believe this will work correctly, but I'd like a second pair of eyes to verify.
@@ -1939,6 +1795,7 @@ void SString::VPrintf(const CHAR *format, va_list args)
CONTRACT_VOID
{
INSTANCE_CHECK;
PRECONDITION(GetRepresentation() == REPRESENTATION_ASCII || GetRepresentation() == REPRESENTATION_UTF8);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we care about the representation of the existing content? The existing content will be overwritten so it should not matter.

Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason I got confused between the AppendPrintf method and this one and didn't realize that this one overrides all of the contents.

@@ -127,7 +124,7 @@ void CHECK::Trigger(LPCSTR reason)
pMessage->AppendASCII(m_condition);
#endif

messageString = pMessage->GetANSI(*pScratch);
messageString = pMessage->GetUTF8();
Copy link
Member

Choose a reason for hiding this comment

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

If the message string is Utf8 now, we should use OutputDebugStringUtf8 below to print it.

Copy link
Member

Choose a reason for hiding this comment

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

Also, fix DbgAssertDialog to expect Utf8. It ends up hitting OutputDebugStringA(szExpr) that has similar problem.

@jkotas
Copy link
Member

jkotas commented Jun 23, 2022

SString::VPrintf(CHAR*, ...). I believe this will work correctly

I think so as well. Could you please do a quick ad-hoc test with non-ASCII Utf8 string to verify it?

@jkoritzinsky
Copy link
Member Author

I did a quick test and it seems like it works (the outputs match the input), but I was having issues getting MSVC to actually correctly handle non-ASCII unicode characters so the input didn't look right (but the underlying bytes were correct).

@jkoritzinsky jkoritzinsky merged commit bc5eda4 into dotnet:main Jun 24, 2022
@jkoritzinsky jkoritzinsky deleted the no-sstring-ansi branch June 24, 2022 21:17
@ghost ghost locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants