diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-07 11:47:43 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-14 14:57:57 +0900 |
commit | b6de0a6c69a4857ca4347f65d7c9a5cb6e52c5bd (patch) | |
tree | 6b90f30c0c988ce997c204d478e3074fb05845ba /process.c | |
parent | efe5e6e8d05d607dde38ece66e035b8e746e65fb (diff) | |
download | ruby-b6de0a6c69a4857ca4347f65d7c9a5cb6e52c5bd.tar.gz |
[Bug #19868] Suggest other Process::Status method for `&` and `>>`
`Process::Status#&` and `Process::Status#>>` are provided only for
the backward compatibility with older Ruby than 1.8 where `$?` was
a `Fixnum`, and the knowledge about internals of system dependent
macros is necessary to use them. Modern programs and libraries
should not need these methods.
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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); |