Skip to content

Use file handles directly instead of C file descriptors on Win32#14501

Merged
straight-shoota merged 9 commits intocrystal-lang:masterfrom
HertzDevil:refactor/win32-file-handle
Apr 21, 2024
Merged

Use file handles directly instead of C file descriptors on Win32#14501
straight-shoota merged 9 commits intocrystal-lang:masterfrom
HertzDevil:refactor/win32-file-handle

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Apr 16, 2024

Resolves #14389.

This makes IO::FileDescriptor#@volatile_fd an Atomic(LibC::UIntPtrT) rather than an Atomic(LibC::HANDLE), to avoid breaking #fd's return type.

@HertzDevil HertzDevil added kind:refactor platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files labels Apr 16, 2024
Comment on lines +87 to +89
ORIGINAL_STDIN = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDIN_HANDLE, blocking: true)
ORIGINAL_STDOUT = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDOUT_HANDLE, blocking: true)
ORIGINAL_STDERR = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDERR_HANDLE, blocking: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be shortened to:

Suggested change
ORIGINAL_STDIN = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDIN_HANDLE, blocking: true)
ORIGINAL_STDOUT = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDOUT_HANDLE, blocking: true)
ORIGINAL_STDERR = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDERR_HANDLE, blocking: true)
ORIGINAL_STDIN = IO::FileDescriptor.new(FileDescriptor::STDIN_HANDLE, blocking: true)
ORIGINAL_STDOUT = IO::FileDescriptor.new(FileDescriptor::STDOUT_HANDLE, blocking: true)
ORIGINAL_STDERR = IO::FileDescriptor.new(FileDescriptor::STDERR_HANDLE, blocking: true)

@HertzDevil
Copy link
Contributor Author

Note to self: lib/reply/src/term_size.cr also defines LibC::STD_OUTPUT_HANDLE which should be dropped after this PR (this doesn't show up on CI because the interpreter is still disabled)

@straight-shoota straight-shoota added this to the 1.13.0 milestone Apr 19, 2024
@straight-shoota straight-shoota merged commit 096f89b into crystal-lang:master Apr 21, 2024
@HertzDevil HertzDevil deleted the refactor/win32-file-handle branch April 21, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:refactor platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Introduce platform-specific FileDescriptor::Handle

3 participants