diff --git a/process.c b/process.c index a8de48a27f..97db867e82 100644 --- a/process.c +++ b/process.c @@ -870,6 +870,8 @@ pst_equal(VALUE st1, VALUE st2) * call-seq: * stat & mask -> integer * + * The use of this method is discouraged; use other attribute methods. + * * Returns the logical AND of the value of #to_i with +mask+: * * `cat /nop` @@ -889,6 +891,25 @@ pst_bitand(VALUE st1, VALUE st2) if (mask < 0) { rb_raise(rb_eArgError, "negative mask value: %d", mask); } +#define WARN_SUGGEST(suggest) rb_warn("Use " suggest " instead of Process::Status#&") + 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); @@ -899,6 +920,8 @@ pst_bitand(VALUE st1, VALUE st2) * call-seq: * stat >> places -> integer * + * The use of this method is discouraged; use other predicate methods. + * * Returns the value of #to_i, shifted +places+ to the right: * * `cat /nop` @@ -919,6 +942,19 @@ pst_rshift(VALUE st1, VALUE st2) if (places < 0) { rb_raise(rb_eArgError, "negative shift value: %d", places); } +#define WARN_SUGGEST(suggest) rb_warn("Use " suggest " instead of Process::Status#>>") + 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); diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 341bbebb35..d1fb8d366a 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1451,8 +1451,12 @@ class TestProcess < Test::Unit::TestCase assert_equal(s, s) assert_equal(s, s.to_i) - assert_equal(s.to_i & 0x55555555, s & 0x55555555) - assert_equal(s.to_i >> 1, s >> 1) + assert_warn(/\bUse .*Process::Status/) do + assert_equal(s.to_i & 0x55555555, s & 0x55555555) + end + assert_warn(/\bUse .*Process::Status/) do + assert_equal(s.to_i >> 1, s >> 1) + end assert_raise(ArgumentError) do s >> -1 end