зеркало из https://github.com/github/ruby.git
[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.
This commit is contained in:
Родитель
efe5e6e8d0
Коммит
b6de0a6c69
36
process.c
36
process.c
|
@ -870,6 +870,8 @@ pst_equal(VALUE st1, VALUE st2)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* stat & mask -> integer
|
* 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+:
|
* Returns the logical AND of the value of #to_i with +mask+:
|
||||||
*
|
*
|
||||||
* `cat /nop`
|
* `cat /nop`
|
||||||
|
@ -889,6 +891,25 @@ pst_bitand(VALUE st1, VALUE st2)
|
||||||
if (mask < 0) {
|
if (mask < 0) {
|
||||||
rb_raise(rb_eArgError, "negative mask value: %d", mask);
|
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;
|
status &= mask;
|
||||||
|
|
||||||
return INT2NUM(status);
|
return INT2NUM(status);
|
||||||
|
@ -899,6 +920,8 @@ pst_bitand(VALUE st1, VALUE st2)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* stat >> places -> integer
|
* 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:
|
* Returns the value of #to_i, shifted +places+ to the right:
|
||||||
*
|
*
|
||||||
* `cat /nop`
|
* `cat /nop`
|
||||||
|
@ -919,6 +942,19 @@ pst_rshift(VALUE st1, VALUE st2)
|
||||||
if (places < 0) {
|
if (places < 0) {
|
||||||
rb_raise(rb_eArgError, "negative shift value: %d", places);
|
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;
|
status >>= places;
|
||||||
|
|
||||||
return INT2NUM(status);
|
return INT2NUM(status);
|
||||||
|
|
|
@ -1451,8 +1451,12 @@ class TestProcess < Test::Unit::TestCase
|
||||||
assert_equal(s, s)
|
assert_equal(s, s)
|
||||||
assert_equal(s, s.to_i)
|
assert_equal(s, s.to_i)
|
||||||
|
|
||||||
|
assert_warn(/\bUse .*Process::Status/) do
|
||||||
assert_equal(s.to_i & 0x55555555, s & 0x55555555)
|
assert_equal(s.to_i & 0x55555555, s & 0x55555555)
|
||||||
|
end
|
||||||
|
assert_warn(/\bUse .*Process::Status/) do
|
||||||
assert_equal(s.to_i >> 1, s >> 1)
|
assert_equal(s.to_i >> 1, s >> 1)
|
||||||
|
end
|
||||||
assert_raise(ArgumentError) do
|
assert_raise(ArgumentError) do
|
||||||
s >> -1
|
s >> -1
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче