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

Fix EventPipe utf8 conversion methods to match between JIT and AOT #89353

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,10 @@ ep_rt_utf8_to_utf16le_string (
if (!str)
return NULL;

if (len == (size_t) -1) {
len = strlen(str);
}

if (len == 0) {
// Return an empty string if the length is 0
CHAR16_T * lpDestEmptyStr = reinterpret_cast<CHAR16_T *>(malloc(1 * sizeof(CHAR16_T)));
Expand All @@ -1395,11 +1399,6 @@ ep_rt_utf8_to_utf16le_string (
return reinterpret_cast<ep_char16_t*>(lpDestEmptyStr);
}

if (len == (size_t) -1) {
// Following the pattern used in EventPipe library where it allocates 1 extra character
len = strlen(str) + 1;
}

int32_t flags = MINIPAL_MB_NO_REPLACE_INVALID_CHARS | MINIPAL_TREAT_AS_LITTLE_ENDIAN;

size_t ret = minipal_get_length_utf8_to_utf16 (str, len, flags);
Expand Down Expand Up @@ -1466,6 +1465,10 @@ ep_rt_utf16_to_utf8_string (
if (!str)
return NULL;

if (len == (size_t) -1) {
len = ep_rt_utf16_string_len (str);
}

if (len == 0) {
// Return an empty string if the length is 0
char * lpDestEmptyStr = reinterpret_cast<char *>(malloc(1 * sizeof(char)));
Expand All @@ -1476,11 +1479,6 @@ ep_rt_utf16_to_utf8_string (
return reinterpret_cast<ep_char8_t*>(lpDestEmptyStr);
}

if (len == (size_t) -1) {
// Following the pattern used in EventPipe library where it allocates 1 extra character
len = ep_rt_utf16_string_len (str) + 1;
}

size_t ret = minipal_get_length_utf16_to_utf8 (reinterpret_cast<const CHAR16_T *>(str), len, 0);

if (ret <= 0)
Expand Down