Skip to content

Make Kernel#fork a simple delegator to Process.fork #4361

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

Closed
wants to merge 1 commit into from

Conversation

casperisfine
Copy link
Contributor

This change makes it much easier to properly decorate the fork method like in nakayoshi_fork.

For context I was about do a feature request for a proper before_fork / after_fork API (e.g. https://bugs.ruby-lang.org/issues/5446), but ultimately I think that if it was easy and clean enough to decorate the fork method with a prepended module, such extra API wouldn't be needed.

Right now such decorator is a bit involved because the method is available as both Kernel.fork and Process.fork, so doing it cleanly is quite complicated, and as a matter of fact, nakayoshi_fork doesn't decorate Process.fork:

>> require 'nakayoshi_fork'
=> true
>> Process.fork(cow_friendly: true)
(irb):2:in `fork': wrong number of arguments (given 1, expected 0) (ArgumentError)

With Kernel.fork becoming a delegator, it makes it much easier and reliable.

@ko1 would you be open to this change?

Also @tenderlove since you were involved in the at_fork discussion, as well as in the nakayoshi_fork issues.

kernel.rb Outdated
Comment on lines 183 to 185
def fork(*args, **kwargs, &block)
Process.fork(*args, **kwargs, &block)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use ... argument forwarding here, but apparently that's not possible?

making kernel.rbinc
Traceback (most recent call last):
	4: from ./tool/mk_builtin_loader.rb:364:in `<main>'
	3: from ./tool/mk_builtin_loader.rb:364:in `each'
	2: from ./tool/mk_builtin_loader.rb:366:in `block in <main>'
	1: from ./tool/mk_builtin_loader.rb:247:in `mk_builtin_header'
./tool/mk_builtin_loader.rb:247:in `compile': <compiled>:183: syntax error, unexpected ..., expecting ')' (SyntaxError)
  def fork(...)
           ^~~
<compiled>:184: syntax error, unexpected ..., expecting ')'
    Process.fork(...)
                 ^~~
make: *** [kernel.rbinc] Error 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I had to move it back to process.c to be able to alias it as rb_f_notimplement on Windows.

This change makes it much easier to properly decorate
the fork method like in `nakayoshi_fork`.
@ko1
Copy link
Contributor

ko1 commented Nov 9, 2021

Process._fork is introduced. 13068eb

@ko1 ko1 closed this Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy