posix-spawn icon indicating copy to clipboard operation
posix-spawn copied to clipboard

Fix compilation on newer clang

Open casperisfine opened this issue 1 year ago • 6 comments

posix-spawn.c:226:27: error: incompatible function pointer types passing 'int (VALUE, VALUE, posix_spawn_file_actions_t *)' (aka 'int (unsigned long, unsigned long, void **)') to parameter of type 'int
(*)(VALUE, VALUE, VALUE)' (aka 'int (*)(unsigned long, unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
        rb_hash_foreach(options, posixspawn_file_actions_operations_iter, (VALUE)fops);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/rubies/3.4-dev-03-19/include/ruby-3.4.0+0/ruby/internal/intern/hash.h:83:40: note: passing argument to parameter 'func' here
void rb_hash_foreach(VALUE hash, int (*func)(VALUE key, VALUE val, VALUE arg), VALUE arg);

casperisfine avatar Mar 19 '24 15:03 casperisfine

I wanted to bump this as I am coming across the same issue at the moment. I ran the tests and observed these failures.

Finished in 1.940804s, 76.7723 runs/s, 242.1677 assertions/s.

  1) Failure:
ChildTest#test_max_with_stubborn_child_pgroup_kill [test/test_child.rb:127]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

  2) Failure:
ChildTest#test_max_with_stubborn_child [test/test_child.rb:120]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

  3) Failure:
ChildTest#test_max_with_child_hierarchy_pgroup_kill [test/test_child.rb:113]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

  4) Failure:
ChildTest#test_max_with_partial_output [test/test_child.rb:135]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

  5) Failure:
ChildTest#test_max [test/test_child.rb:92]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

  6) Failure:
ChildTest#test_max_with_child_hierarchy [test/test_child.rb:106]:
POSIX::Spawn::MaximumOutputExceeded expected but nothing was raised.

I am not super familiar with the project and these may already be known issues.

Additionally, the benchmarks seem to run without issue.

benchmarking fork/exec vs. posix_spawn over 1000 runs at 100M res
                                               user     system      total        real
fspawn (fork/exec):                        0.025123   0.284463   1.182938 (  1.492710)
pspawn (posix_spawn):                      0.011391   0.393620   0.833269 (  0.944768)
spawn (native):                            0.020049   0.270129   0.903074 (  1.162991)

Let me know if I can help move this along. I am on MacOS Sonoma 14.4, M1

dtaivpp avatar Mar 27 '24 18:03 dtaivpp

@dtaivpp just FYI, posix-spawn usefulness with modern rubies is rather limited. A long time ago Ruby started using vfork to spawn sub processes, which is essentially the same thing posix-spawn does.

THe only exception to that is if you are running as root, Ruby de-optimize to use regular fork.

All this to say, unless some other gem cause you this hard dependency, the best course of action is likely to just stop using posix-spawn. I only submitted the PR because it was easy in case it was helpful for others.

casperisfine avatar Mar 27 '24 18:03 casperisfine

@casperisfine thanks for the context. jekyll-last-modified-at depends on it and looks to be unmaintained so I was hoping to find a fix here. Maybe I should look to see if someone has a replacement for it at this point though. 😐

Thanks for the info as well!

dtaivpp avatar Mar 27 '24 18:03 dtaivpp

As short term you can point your gemfile at this PR:

gem "posix-spawn", github: "https://github.com/rtomayko/posix-spawn/pull/93"

NB: make sure you don't have a git_source(:github) { |repo| "https://github.com/#{repo}.git" } line in your Gemfile, if you do, just delete it.

casperisfine avatar Mar 28 '24 10:03 casperisfine

This worked for me on clang 15.0.0 (clang-1500.3.9.4) on arm64-apple-darwin23.5.0, and also for a coworker on archlinux.

ThisIsMissEm avatar Jun 19 '24 18:06 ThisIsMissEm

I was having problems on Arch Linux after Ruby updated to 3.2.0.

gem "posix-spawn", github: "https://github.com/rtomayko/posix-spawn/pull/93"

This worked! Thanks!

sol2070 avatar Aug 09 '24 19:08 sol2070