File tree Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -60,19 +60,14 @@ class RubyObjectEncoder {
60
60
}
61
61
62
62
void encode_bignum (VALUE b) {
63
- b = rb_big_norm (b);
64
- if (FIXNUM_P (b)) {
65
- return encode_fixnum (b);
66
- }
67
-
68
- bool negative = rb_big_cmp (b, INT2FIX (0 )) == INT2FIX (-1 );
69
- if (negative) {
70
- long long ll = rb_big2ll (b);
71
- writer.Int64 (ll);
72
- } else {
73
- unsigned long long ull = rb_big2ull (b);
74
- writer.Uint64 (ull);
75
- }
63
+ // Some T_BIGNUM might be small enough to fit in long long or unsigned long long
64
+ // but this being the slow path, it's not really worth it.
65
+ VALUE str = rb_funcall (b, id_to_s, 0 );
66
+ Check_Type (str, T_STRING);
67
+
68
+ // We should be able to use RawNumber here, but it's buggy
69
+ // https://github.com/Tencent/rapidjson/issues/852
70
+ writer.RawValue (RSTRING_PTR (str), RSTRING_LEN (str), kNumberType );
76
71
}
77
72
78
73
void encode_float (VALUE v) {
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ def test_encode_bignum
33
33
assert_equal "18446744073709551615" , encode ( 2 **64 - 1 )
34
34
end
35
35
36
+ def test_encore_arbitrary_size_num
37
+ assert_equal "340282366920938463463374607431768211456" , encode ( 2 **128 )
38
+ end
39
+
36
40
def test_encode_fixnum_exponents
37
41
tests = [ ]
38
42
0 . upto ( 65 ) do |exponent |
You can’t perform that action at this time.
0 commit comments