Skip to content

Commit 39f2462

Browse files
XrXrheadius
authored andcommitted
Add "c_long_size" guard, supplanting "wordsize" and stop using Integer#size
What a "word" is when talking about sizes is confusing because it's a highly overloaded term. Intel, Microsoft, and GDB are just a few vendors that have their own definition of what a "word" is. Specs that used the "wordsize" guard actually were mostly testing for the size of the C `long` fundamental type, so rename the guard for clarity. Also, get the size of `long` directly from RbConfig instead of guessing using Integer#size. Integer#size is not guaranteed to have anything to do with the `long` type.
1 parent 6f6918a commit 39f2462

File tree

14 files changed

+35
-35
lines changed

14 files changed

+35
-35
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164
platform_is_not :linux, :darwin do # Not Linux and not Darwin
165165
end
166166

167-
platform_is wordsize: 64 do
167+
platform_is pointer_size: 64 do
168168
# 64-bit platform
169169
end
170170

core/array/pack/l_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
it_behaves_like :array_pack_32bit_be, 'L>'
3030
end
3131

32-
platform_is wordsize: 32 do
32+
platform_is c_long_size: 32 do
3333
describe "with modifier '<' and '_'" do
3434
it_behaves_like :array_pack_32bit_le, 'L<_'
3535
it_behaves_like :array_pack_32bit_le, 'L_<'
@@ -51,7 +51,7 @@
5151
end
5252
end
5353

54-
platform_is wordsize: 64 do
54+
platform_is c_long_size: 64 do
5555
describe "with modifier '<' and '_'" do
5656
it_behaves_like :array_pack_64bit_le, 'L<_'
5757
it_behaves_like :array_pack_64bit_le, 'L_<'
@@ -83,7 +83,7 @@
8383
it_behaves_like :array_pack_32bit_be, 'l>'
8484
end
8585

86-
platform_is wordsize: 32 do
86+
platform_is c_long_size: 32 do
8787
describe "with modifier '<' and '_'" do
8888
it_behaves_like :array_pack_32bit_le, 'l<_'
8989
it_behaves_like :array_pack_32bit_le, 'l_<'
@@ -105,7 +105,7 @@
105105
end
106106
end
107107

108-
platform_is wordsize: 64 do
108+
platform_is c_long_size: 64 do
109109
describe "with modifier '<' and '_'" do
110110
it_behaves_like :array_pack_64bit_le, 'l<_'
111111
it_behaves_like :array_pack_64bit_le, 'l_<'
@@ -137,7 +137,7 @@
137137
it_behaves_like :array_pack_32bit_le, 'l'
138138
end
139139

140-
platform_is wordsize: 32 do
140+
platform_is c_long_size: 32 do
141141
describe "Array#pack with format 'L' with modifier '_'" do
142142
it_behaves_like :array_pack_32bit_le, 'L_'
143143
end
@@ -155,7 +155,7 @@
155155
end
156156
end
157157

158-
platform_is wordsize: 64 do
158+
platform_is c_long_size: 64 do
159159
describe "Array#pack with format 'L' with modifier '_'" do
160160
it_behaves_like :array_pack_64bit_le, 'L_'
161161
end
@@ -183,7 +183,7 @@
183183
it_behaves_like :array_pack_32bit_be, 'l'
184184
end
185185

186-
platform_is wordsize: 32 do
186+
platform_is c_long_size: 32 do
187187
describe "Array#pack with format 'L' with modifier '_'" do
188188
it_behaves_like :array_pack_32bit_be, 'L_'
189189
end
@@ -201,7 +201,7 @@
201201
end
202202
end
203203

204-
platform_is wordsize: 64 do
204+
platform_is c_long_size: 64 do
205205
describe "Array#pack with format 'L' with modifier '_'" do
206206
it_behaves_like :array_pack_64bit_be, 'L_'
207207
end

core/array/pack/shared/integer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78"
274274
end
275275

276-
platform_is wordsize: 64 do
276+
platform_is c_long_size: 64 do
277277
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
278278
[ [[0xff_7865_4321], "\x21\x43\x65\x78"],
279279
[[-0xff_7865_4321], "\xdf\xbc\x9a\x87"]
@@ -299,7 +299,7 @@
299299
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21"
300300
end
301301

302-
platform_is wordsize: 64 do
302+
platform_is c_long_size: 64 do
303303
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
304304
[ [[0xff_7865_4321], "\x78\x65\x43\x21"],
305305
[[-0xff_7865_4321], "\x87\x9a\xbc\xdf"]

core/file/shared/update_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
end
8585

8686
platform_is :linux do
87-
platform_is wordsize: 64 do
87+
platform_is pointer_size: 64 do
8888
it "allows Time instances in the far future to set mtime and atime (but some filesystems limit it up to 2446-05-10 or 2038-01-19 or 2486-07-02)" do
8989
# https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Timestamps
9090
# "Therefore, timestamps should not overflow until May 2446."

core/integer/size_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
require_relative '../../spec_helper'
22

33
describe "Integer#size" do
4-
platform_is wordsize: 32 do
4+
platform_is c_long_size: 32 do
55
it "returns the number of bytes in the machine representation of self" do
66
-1.size.should == 4
77
0.size.should == 4
88
4091.size.should == 4
99
end
1010
end
1111

12-
platform_is wordsize: 64 do
12+
platform_is c_long_size: 64 do
1313
it "returns the number of bytes in the machine representation of self" do
1414
-1.size.should == 8
1515
0.size.should == 8

core/marshal/dump_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
].should be_computed_by(:dump)
3939
end
4040

41-
platform_is wordsize: 64 do
41+
platform_is c_long_size: 64 do
4242
it "dumps a positive Fixnum > 31 bits as a Bignum" do
4343
Marshal.dump(2**31 + 1).should == "\x04\bl+\a\x01\x00\x00\x80"
4444
end

core/marshal/shared/load.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def io.binmode; raise "binmode"; end
10491049
end
10501050

10511051
describe "for a Bignum" do
1052-
platform_is wordsize: 64 do
1052+
platform_is c_long_size: 64 do
10531053
context "that is Bignum on 32-bit platforms but Fixnum on 64-bit" do
10541054
it "dumps a Fixnum" do
10551055
val = Marshal.send(@method, "\004\bl+\ab:wU")

core/string/unpack/l_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>'
1515
end
1616

17-
platform_is wordsize: 32 do
17+
platform_is c_long_size: 32 do
1818
describe "with modifier '<' and '_'" do
1919
it_behaves_like :string_unpack_32bit_le, 'L<_'
2020
it_behaves_like :string_unpack_32bit_le, 'L_<'
@@ -44,7 +44,7 @@
4444
end
4545
end
4646

47-
platform_is wordsize: 64 do
47+
platform_is c_long_size: 64 do
4848
describe "with modifier '<' and '_'" do
4949
it_behaves_like :string_unpack_64bit_le, 'L<_'
5050
it_behaves_like :string_unpack_64bit_le, 'L_<'
@@ -86,7 +86,7 @@
8686
it_behaves_like :string_unpack_32bit_be_signed, 'l>'
8787
end
8888

89-
platform_is wordsize: 32 do
89+
platform_is c_long_size: 32 do
9090
describe "with modifier '<' and '_'" do
9191
it_behaves_like :string_unpack_32bit_le, 'l<_'
9292
it_behaves_like :string_unpack_32bit_le, 'l_<'
@@ -116,7 +116,7 @@
116116
end
117117
end
118118

119-
platform_is wordsize: 64 do
119+
platform_is c_long_size: 64 do
120120
describe "with modifier '<' and '_'" do
121121
it_behaves_like :string_unpack_64bit_le, 'l<_'
122122
it_behaves_like :string_unpack_64bit_le, 'l_<'
@@ -160,7 +160,7 @@
160160
it_behaves_like :string_unpack_32bit_le_signed, 'l'
161161
end
162162

163-
platform_is wordsize: 32 do
163+
platform_is c_long_size: 32 do
164164
describe "String#unpack with format 'L' with modifier '_'" do
165165
it_behaves_like :string_unpack_32bit_le, 'L_'
166166
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_'
@@ -182,7 +182,7 @@
182182
end
183183
end
184184

185-
platform_is wordsize: 64 do
185+
platform_is c_long_size: 64 do
186186
describe "String#unpack with format 'L' with modifier '_'" do
187187
it_behaves_like :string_unpack_64bit_le, 'L_'
188188
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_'
@@ -218,7 +218,7 @@
218218
it_behaves_like :string_unpack_32bit_be_signed, 'l'
219219
end
220220

221-
platform_is wordsize: 32 do
221+
platform_is c_long_size: 32 do
222222
describe "String#unpack with format 'L' with modifier '_'" do
223223
it_behaves_like :string_unpack_32bit_be, 'L_'
224224
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_'
@@ -240,7 +240,7 @@
240240
end
241241
end
242242

243-
platform_is wordsize: 64 do
243+
platform_is c_long_size: 64 do
244244
describe "String#unpack with format 'L' with modifier '_'" do
245245
it_behaves_like :string_unpack_64bit_be, 'L_'
246246
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_'

library/bigdecimal/sqrt_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
BigDecimal('121').sqrt(5).should be_close(11, 0.00001)
3737
end
3838

39-
platform_is_not wordsize: 32 do # fails on i686
39+
platform_is_not c_long_size: 32 do # fails on i686
4040
it "returns square root of 0.9E-99999 with desired precision" do
4141
@frac_2.sqrt(1).to_s.should =~ /\A0\.3E-49999\z/i
4242
end

optional/capi/bignum_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def ensure_bignum(n)
123123
val.should == @max_ulong
124124
end
125125

126-
platform_is wordsize: 64 do
126+
platform_is c_long_size: 64 do
127127
it "packs max_ulong into 2 ulongs to allow sign bit" do
128128
val = @s.rb_big_pack_length(@max_ulong)
129129
val.should == 2

0 commit comments

Comments
 (0)