mirror of
https://github.com/ruby/ruby.git
synced 2026-11-08 01:20:26 +08:00
Check Bignum arguments in C API specs
Reject non-Bignum values before Bignum-only APIs can access their representation.
This commit is contained in:
parent
2019f0f50e
commit
11589a5b92
Notes:
git
2026-11-07 15:18:29 +00:00
@ -26,6 +26,10 @@ describe "CApiBignumSpecs" do
|
||||
end
|
||||
|
||||
describe "rb_big2long" do
|
||||
it "raises TypeError for a non-Bignum argument" do
|
||||
-> { @s.rb_big2long(0) }.should.raise(TypeError)
|
||||
end
|
||||
|
||||
it "handles Bignum values at the long boundary" do
|
||||
if @max_long > @max_fixnum
|
||||
@s.rb_big2long(@max_long).should == @max_long
|
||||
|
||||
@ -6,6 +6,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
static VALUE bignum_spec_rb_big2dbl(VALUE self, VALUE num) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return rb_float_new(rb_big2dbl(num));
|
||||
}
|
||||
|
||||
@ -16,30 +17,37 @@ static VALUE bignum_spec_rb_dbl2big(VALUE self, VALUE num) {
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big2ll(VALUE self, VALUE num) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return rb_ll2inum(rb_big2ll(num));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big2ull(VALUE self, VALUE num) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return rb_ull2inum(rb_big2ull(num));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big2long(VALUE self, VALUE num) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return LONG2NUM(rb_big2long(num));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big2str(VALUE self, VALUE num, VALUE base) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return rb_big2str(num, FIX2INT(base));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big2ulong(VALUE self, VALUE num) {
|
||||
Check_Type(num, T_BIGNUM);
|
||||
return ULONG2NUM(rb_big2ulong(num));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_RBIGNUM_SIGN(VALUE self, VALUE val) {
|
||||
Check_Type(val, T_BIGNUM);
|
||||
return INT2FIX(RBIGNUM_SIGN(val));
|
||||
}
|
||||
|
||||
static VALUE bignum_spec_rb_big_cmp(VALUE self, VALUE x, VALUE y) {
|
||||
Check_Type(x, T_BIGNUM);
|
||||
return rb_big_cmp(x, y);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user