diff options
-rw-r--r-- | process.c | 105 | ||||
-rw-r--r-- | spec/ruby/core/process/status/bit_and_spec.rb | 49 | ||||
-rw-r--r-- | spec/ruby/core/process/status/right_shift_spec.rb | 47 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 9 |
4 files changed, 51 insertions, 159 deletions
@@ -875,109 +875,6 @@ pst_equal(VALUE st1, VALUE st2) /* * call-seq: - * stat & mask -> integer - * - * This method is deprecated as #to_i value is system-specific; use - * predicate methods like #exited? or #stopped?, or getters like #exitstatus - * or #stopsig. - * - * Returns the logical AND of the value of #to_i with +mask+: - * - * `cat /nop` - * stat = $? # => #<Process::Status: pid 1155508 exit 1> - * sprintf('%x', stat.to_i) # => "100" - * stat & 0x00 # => 0 - * - * ArgumentError is raised if +mask+ is negative. - */ - -static VALUE -pst_bitand(VALUE st1, VALUE st2) -{ - int status = PST2INT(st1); - int mask = NUM2INT(st2); - - if (mask < 0) { - rb_raise(rb_eArgError, "negative mask value: %d", mask); - } -#define WARN_SUGGEST(suggest) \ - rb_warn_deprecated_to_remove_at(3.5, "Process::Status#&", suggest) - - switch (mask) { - case 0x80: - WARN_SUGGEST("Process::Status#coredump?"); - break; - case 0x7f: - WARN_SUGGEST("Process::Status#signaled? or Process::Status#termsig"); - break; - case 0xff: - WARN_SUGGEST("Process::Status#exited?, Process::Status#stopped? or Process::Status#coredump?"); - break; - case 0xff00: - WARN_SUGGEST("Process::Status#exitstatus or Process::Status#stopsig"); - break; - default: - WARN_SUGGEST("other Process::Status predicates"); - break; - } -#undef WARN_SUGGEST - status &= mask; - - return INT2NUM(status); -} - - -/* - * call-seq: - * stat >> places -> integer - * - * This method is deprecated as #to_i value is system-specific; use - * predicate methods like #exited? or #stopped?, or getters like #exitstatus - * or #stopsig. - * - * Returns the value of #to_i, shifted +places+ to the right: - * - * `cat /nop` - * stat = $? # => #<Process::Status: pid 1155508 exit 1> - * stat.to_i # => 256 - * stat >> 1 # => 128 - * stat >> 2 # => 64 - * - * ArgumentError is raised if +places+ is negative. - */ - -static VALUE -pst_rshift(VALUE st1, VALUE st2) -{ - int status = PST2INT(st1); - int places = NUM2INT(st2); - - if (places < 0) { - rb_raise(rb_eArgError, "negative shift value: %d", places); - } -#define WARN_SUGGEST(suggest) \ - rb_warn_deprecated_to_remove_at(3.5, "Process::Status#>>", suggest) - - switch (places) { - case 7: - WARN_SUGGEST("Process::Status#coredump?"); - break; - case 8: - WARN_SUGGEST("Process::Status#exitstatus or Process::Status#stopsig"); - break; - default: - WARN_SUGGEST("other Process::Status attributes"); - break; - } -#undef WARN_SUGGEST - status >>= places; - - return INT2NUM(status); -} - - -/* - * call-seq: * stopped? -> true or false * * Returns +true+ if this process is stopped, @@ -9346,8 +9243,6 @@ InitVM_process(void) rb_define_singleton_method(rb_cProcessStatus, "wait", rb_process_status_waitv, -1); rb_define_method(rb_cProcessStatus, "==", pst_equal, 1); - rb_define_method(rb_cProcessStatus, "&", pst_bitand, 1); - rb_define_method(rb_cProcessStatus, ">>", pst_rshift, 1); rb_define_method(rb_cProcessStatus, "to_i", pst_to_i, 0); rb_define_method(rb_cProcessStatus, "to_s", pst_to_s, 0); rb_define_method(rb_cProcessStatus, "inspect", pst_inspect, 0); diff --git a/spec/ruby/core/process/status/bit_and_spec.rb b/spec/ruby/core/process/status/bit_and_spec.rb index f4a4328907..6a29988da2 100644 --- a/spec/ruby/core/process/status/bit_and_spec.rb +++ b/spec/ruby/core/process/status/bit_and_spec.rb @@ -1,35 +1,38 @@ require_relative '../../../spec_helper' -describe "Process::Status#&" do - it "returns a bitwise and of the integer status of an exited child" do - suppress_warning do - ruby_exe("exit(29)", exit_status: 29) - ($? & 0).should == 0 - ($? & $?.to_i).should == $?.to_i +ruby_version_is ""..."3.5" do - # Actual value is implementation specific - platform_is :linux do - # 29 == 0b11101 - ($? & 0b1011100000000).should == 0b1010100000000 + describe "Process::Status#&" do + it "returns a bitwise and of the integer status of an exited child" do + suppress_warning do + ruby_exe("exit(29)", exit_status: 29) + ($? & 0).should == 0 + ($? & $?.to_i).should == $?.to_i + + # Actual value is implementation specific + platform_is :linux do + # 29 == 0b11101 + ($? & 0b1011100000000).should == 0b1010100000000 + end end end - end - ruby_version_is "3.3" do - it "raises an ArgumentError if mask is negative" do - suppress_warning do + ruby_version_is "3.3" do + it "raises an ArgumentError if mask is negative" do + suppress_warning do + ruby_exe("exit(0)") + -> { + $? & -1 + }.should raise_error(ArgumentError, 'negative mask value: -1') + end + end + + it "shows a deprecation warning" do ruby_exe("exit(0)") -> { - $? & -1 - }.should raise_error(ArgumentError, 'negative mask value: -1') + $? & 0 + }.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/) end end - - it "shows a deprecation warning" do - ruby_exe("exit(0)") - -> { - $? & 0 - }.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/) - end end end diff --git a/spec/ruby/core/process/status/right_shift_spec.rb b/spec/ruby/core/process/status/right_shift_spec.rb index 034ce348cb..af2cd2a4b3 100644 --- a/spec/ruby/core/process/status/right_shift_spec.rb +++ b/spec/ruby/core/process/status/right_shift_spec.rb @@ -1,34 +1,37 @@ require_relative '../../../spec_helper' -describe "Process::Status#>>" do - it "returns a right shift of the integer status of an exited child" do - suppress_warning do - ruby_exe("exit(29)", exit_status: 29) - ($? >> 0).should == $?.to_i - ($? >> 1).should == $?.to_i >> 1 +ruby_version_is ""..."3.5" do - # Actual value is implementation specific - platform_is :linux do - ($? >> 8).should == 29 + describe "Process::Status#>>" do + it "returns a right shift of the integer status of an exited child" do + suppress_warning do + ruby_exe("exit(29)", exit_status: 29) + ($? >> 0).should == $?.to_i + ($? >> 1).should == $?.to_i >> 1 + + # Actual value is implementation specific + platform_is :linux do + ($? >> 8).should == 29 + end end end - end - ruby_version_is "3.3" do - it "raises an ArgumentError if shift value is negative" do - suppress_warning do + ruby_version_is "3.3" do + it "raises an ArgumentError if shift value is negative" do + suppress_warning do + ruby_exe("exit(0)") + -> { + $? >> -1 + }.should raise_error(ArgumentError, 'negative shift value: -1') + end + end + + it "shows a deprecation warning" do ruby_exe("exit(0)") -> { - $? >> -1 - }.should raise_error(ArgumentError, 'negative shift value: -1') + $? >> 0 + }.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/) end end - - it "shows a deprecation warning" do - ruby_exe("exit(0)") - -> { - $? >> 0 - }.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/) - end end end diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 6e8ba484a4..7057e0b837 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1454,15 +1454,6 @@ class TestProcess < Test::Unit::TestCase assert_equal(s, s) assert_equal(s, s.to_i) - assert_deprecated_warn(/\buse .*Process::Status/) do - assert_equal(s.to_i & 0x55555555, s & 0x55555555) - end - assert_deprecated_warn(/\buse .*Process::Status/) do - assert_equal(s.to_i >> 1, s >> 1) - end - assert_raise(ArgumentError) do - s >> -1 - end assert_equal(false, s.stopped?) assert_equal(nil, s.stopsig) |