Skip to content

Commit 8170611

Browse files
committed
Fix rb_integer_pack() for values between 2**62 and 2**63
* Fixes oracle/truffleruby#3352 * Add specs for it.
1 parent d872514 commit 8170611

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

optional/capi/integer_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@
140140
result.should == -1
141141
@words.should == "\x11\x32\x54\x76\x98\xBA\xDC\xFE"
142142
end
143+
144+
it "converts numbers near the fixnum limit successfully" do
145+
result = @s.rb_integer_pack(0x7123_4567_89ab_cdef, @words, 1, 8, 0,
146+
CApiIntegerSpecs::NATIVE|CApiIntegerSpecs::PACK_2COMP)
147+
result.should == 1
148+
@words.should == "\xEF\xCD\xAB\x89\x67\x45\x23\x71"
149+
150+
result = @s.rb_integer_pack(2**62-1, @words, 1, 8, 0,
151+
CApiIntegerSpecs::NATIVE|CApiIntegerSpecs::PACK_2COMP)
152+
result.should == 1
153+
@words.should == "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x3F"
154+
155+
result = @s.rb_integer_pack(2**63-1, @words, 1, 8, 0,
156+
CApiIntegerSpecs::NATIVE|CApiIntegerSpecs::PACK_2COMP)
157+
result.should == 1
158+
@words.should == "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F"
159+
end
143160
end
144161
end
145162
end

0 commit comments

Comments
 (0)