-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor Process in preparation for Windows support #6744
Conversation
b8dceed
to
3aebf51
Compare
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.
Good changes overall. Just a few details I'd like to discuss.
3aebf51
to
bb6b770
Compare
Let's merge. |
I was planning on rebasing the windows part of the process refactor on top of this PR to make 100% sure that this PR was complete, but I'm moving back to university so havent had time :( I'm fine to merge this, but there's a very small but nonzero chance that there might be more amendments coming. |
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.
I liked the refactors. Rebase & merge when needed.
src/io/file_descriptor.cr
Outdated
@@ -147,6 +147,7 @@ class IO::FileDescriptor < IO | |||
end | |||
|
|||
def reopen(other : IO::FileDescriptor) | |||
return if self.fd == other.fd |
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.
should this return self?
will this introduce a Nil
into the types that can be returned?
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.
Thanks for spotting! (this method should probably return nil but thats for another PR.
Having a single fork_internal method allows all callers to replace it with Crystal::System::Process.fork more easily. Also a breaking change as Process.fork no longer uses `with self yield self`.
This is useful when porting to Windows, as Crystal::System::Process.spawn will take args as an array. This is because Windows's CreateProcess doesn't take an argument vector.
Previously only errors from LibC.execvp were caught.
This means that Process.exec_internal is always passed an IO::FileDescriptor, moving non platform-specific code outside of exec_internal and into it's callers. Also fixes Process.exec crashing with a non-descriptive error when passed an IO that's not an IO::FileDescriptor. Redirect::Pipe is also disallowed for exec.
bb6b770
to
7a95390
Compare
Commits are best read in order, with their descriptions.