Negative value to Process::Status method for compatibility

This commit is contained in:
Nobuyoshi Nakada 2023-09-07 11:33:42 +09:00
parent e50fcca9a7
commit efe5e6e8d0
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2023-09-14 07:41:31 +00:00
2 changed files with 19 additions and 3 deletions

View File

@ -877,12 +877,19 @@ pst_equal(VALUE st1, VALUE st2)
* 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) & NUM2INT(st2);
int status = PST2INT(st1);
int mask = NUM2INT(st2);
if (mask < 0) {
rb_raise(rb_eArgError, "negative mask value: %d", mask);
}
status &= mask;
return INT2NUM(status);
}
@ -900,13 +907,19 @@ pst_bitand(VALUE st1, VALUE st2)
* stat >> 1 # => 128
* stat >> 2 # => 64
*
* The behavior is unspecified if +places+ is negative.
* ArgumentError is raised if +places+ is negative.
*/
static VALUE
pst_rshift(VALUE st1, VALUE st2)
{
int status = PST2INT(st1) >> NUM2INT(st2);
int status = PST2INT(st1);
int places = NUM2INT(st2);
if (places < 0) {
rb_raise(rb_eArgError, "negative shift value: %d", places);
}
status >>= places;
return INT2NUM(status);
}

View File

@ -1453,6 +1453,9 @@ class TestProcess < Test::Unit::TestCase
assert_equal(s.to_i & 0x55555555, s & 0x55555555)
assert_equal(s.to_i >> 1, s >> 1)
assert_raise(ArgumentError) do
s >> -1
end
assert_equal(false, s.stopped?)
assert_equal(nil, s.stopsig)