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

Emulate non-blocking STDIN console on Windows #14947

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Aug 27, 2024

Resolves part of #14576. Thread::ConditionVariable is now used again.

There is no opt-out mechanism; while technically possible, there is probably no real benefit to it.

@HertzDevil HertzDevil marked this pull request as ready for review August 28, 2024 10:50
src/crystal/system/file_descriptor.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota added this to the 1.14.0 milestone Sep 4, 2024
@straight-shoota straight-shoota merged commit 95af602 into crystal-lang:master Sep 5, 2024
59 of 61 checks passed
@HertzDevil HertzDevil deleted the feature/windows-stdin-non-blocking branch September 5, 2024 09:24
straight-shoota added a commit that referenced this pull request Sep 16, 2024
The following should print the compiler help message to the file `foo.txt`:

```crystal
File.open("foo.txt", "w") do |f|
  Process.exec("crystal", output: f)
end
```

It used to work on Windows in Crystal 1.12, but is now broken since 1.13. This is because `LibC._wexecvp` only inherits file descriptors in the C runtime, not arbitrary Win32 file handles; since we stopped calling `LibC._open_osfhandle`, the C runtime knows nothing about any reopened standard streams in Win32. Thus the above merely prints the help message to the standard output.

This PR creates the missing C file descriptors right before `LibC._wexecvp`. It also fixes a different regression of #14947 where reconfiguring `STDIN.blocking` always fails.

Co-authored-by: Johannes Müller <straightshoota@gmail.com>
straight-shoota added a commit that referenced this pull request Sep 17, 2024
The following should print the compiler help message to the file `foo.txt`:

```crystal
File.open("foo.txt", "w") do |f|
  Process.exec("crystal", output: f)
end
```

It used to work on Windows in Crystal 1.12, but is now broken since 1.13. This is because `LibC._wexecvp` only inherits file descriptors in the C runtime, not arbitrary Win32 file handles; since we stopped calling `LibC._open_osfhandle`, the C runtime knows nothing about any reopened standard streams in Win32. Thus the above merely prints the help message to the standard output.

This PR creates the missing C file descriptors right before `LibC._wexecvp`. It also fixes a different regression of #14947 where reconfiguring `STDIN.blocking` always fails.

Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants