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

Try to convert OS::execute() output to Unicode on Windows #60920

Merged
merged 1 commit into from
May 10, 2022

Conversation

timothyqiu
Copy link
Member

Resolves #60897

Windows defaults to ANSI instead of 8-bit ASCII. Full characters are sent but using different encodings according to the code page. This is why godot prints lots of "Unicode parsing error" when trying to interpret these bytes as UTF-8 which is most of the time an incorrect encoding (but compatible with the ASCII part).

This PR uses MultiByteToWideChar to convert the output bytes from system default ANSI encoding to Unicode (wchar_t) so that a String can be constructed correctly. If the API fails, we fallback to the original "treat as UTF-8" approach.

I only tested this on a Simplified Chinese version of Windows. CC @bruvzg

For cherry-pick: is_empty()empty().

@timothyqiu timothyqiu added bug platform:windows topic:core cherrypick:3.x Considered for cherry-picking into a future 3.x release labels May 10, 2022
@timothyqiu timothyqiu requested a review from a team as a code owner May 10, 2022 11:11
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

MultiByteToWideChar probably will work for most cases

But I'm not sure about reading everything to the buffer and converting it at once. This will prevent receiving long output in portions (e.g., from the other thread).

Breaking it at the arbitrary points might break multibyte conversion, but the same is true for old code and Unix version. So might be better to look for the new like characters and do converting/adding to string for a single line at a time.

@timothyqiu
Copy link
Member Author

Updated to convert available lines at each iteration.

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

It seems to be working fine.

@akien-mga akien-mga merged commit 0841f72 into godotengine:master May 10, 2022
@akien-mga akien-mga added this to the 4.0 milestone May 10, 2022
@akien-mga
Copy link
Member

Thanks!

@timothyqiu timothyqiu deleted the execute-cp branch May 10, 2022 15:47
@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OS.execute should output PackedByteArray?
3 participants