-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use utf conversions from minipal #89036
Conversation
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsLeverage the UTF conversion functionality needed for
|
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.
👍
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
The test failures here are known |
ep_char16_t* lpDestStr = NULL; | ||
|
||
if (static_cast<int>(len) < 0) | ||
len = strlen(str) + 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.
Why do we need the +1 here? Adding the null terminator is handled explicitly below?
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 is an existing pattern:
runtime/src/mono/mono/eglib/giconv.c
Lines 340 to 343 in 8f8a007
if (len < 0) | |
len = (glong)strlen(str) + 1; | |
glong ret = (glong)minipal_get_length_utf8_to_utf16 (str, len, flags); |
Reason is, minipal get_length API needs the source length with null-terminator accounted for, so it returns the correct destination count. Handling it within minipal was requiring some additional conditions which we decided to leave out for the caller to handle.
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.
Does the length in ep_rt_utf16_to_utf8_string
need +1 too, then?
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 is an existing pattern:
It has the same issue of allocating one extra byte than necessary, and it is further complicated by returning items_written
.
We do not need to replicate the issue here.
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.
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.
@jkotas, not sure which issue you are referring to.
Allocating buffer that is one character longer than necessary.
For example, if ep_rt_utf8_to_utf16le_string
is called with a string that is 1 ascii character + zero terminator, the current code allocates 3 * sizeof(CHAR16_T)
. It is one CHAR16_T
more than what is actually needed.
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.
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.
Are you saying that the event pipe code expects the strings returned by this method to have double zero terminators? It is very atypical contract. If it is really the case, these should be a long comment explaining it.
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.
Allocating buffer that is one character longer than necessary.
PAL, COM and reflection tests are very sensitive about "fill the exact slot or fail" cases. So if that was the case, they all will fail. IOW, that +1 effect gets cancelled out how the code in utf8.c works.
|
||
ep_char8_t *str_utf8 = reinterpret_cast<ep_char8_t *>(malloc ((len_utf16 + 1) * sizeof (ep_char8_t))); | ||
if (!str_utf8) | ||
ep_char8_t* lpDestStr = NULL; |
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.
nit: rename to str_utf8
and move the declaration down to where it is first assigned.
Leverage the UTF conversion functionality needed for
EventPipe
fromminipal
.