summaryrefslogtreecommitdiff
path: root/spec/mspec/lib
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2024-07-23 18:21:38 -0400
committerBenoit Daloze <[email protected]>2024-07-24 18:20:30 +0200
commitfbb981b9f819d24c4e11132c02ec02401eabcc5e (patch)
tree8fa1940f730c73dcb2b5b5f16f3b256c1c81342b /spec/mspec/lib
parent12e6cf77efae6804063dbebe84e4080ca78958e7 (diff)
Stop depending on Integer#size to return `sizeof(long)`
There is no guarantee that Integer#size will continue to return `sizeof(long)` for small integers. Use the `l!` specifier for Array#pack instead. It is a public interface that has a direct relationship with the `long` type.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11130
Diffstat (limited to 'spec/mspec/lib')
-rw-r--r--spec/mspec/lib/mspec/helpers/numeric.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/spec/mspec/lib/mspec/helpers/numeric.rb b/spec/mspec/lib/mspec/helpers/numeric.rb
index 46d3d7b182..3be3dcdcd1 100644
--- a/spec/mspec/lib/mspec/helpers/numeric.rb
+++ b/spec/mspec/lib/mspec/helpers/numeric.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'mspec/guards/platform'
def nan_value
@@ -15,11 +16,13 @@ def bignum_value(plus = 0)
end
def max_long
- 2**(0.size * 8 - 1) - 1
+ long_byte_size = [0].pack('l!').size
+ 2**(long_byte_size * 8 - 1) - 1
end
def min_long
- -(2**(0.size * 8 - 1))
+ long_byte_size = [0].pack('l!').size
+ -(2**(long_byte_size * 8 - 1))
end
# This is a bit hairy, but we need to be able to write specs that cover the