Skip to content

Commit a0415a7

Browse files
committed
Remove Fixnum references to support modern Ruby versions
Fixnum type has been deprecated since Ruby 2.4 and removed in Ruby 3.0, which makes BaseProtocol incompatible with modern Ruby versions. This change removes the Fixnum reference, as well as a monkey-patch that introduces Fixnum#ord() to Ruby versions below 1.8.7. **This change essentially makes it officially required to use Ruby 2.4 or newer.** Fixes the following test failures: 1) BaseProtocol Thrift::BaseProtocol should write out the different types (deprecated write_type signature) Failure/Error: if field_info.is_a? Fixnum NameError: uninitialized constant Thrift::BaseProtocol::Fixnum # ./lib/thrift/protocol/base_protocol.rb:256:in 'Thrift::BaseProtocol#write_type' # ./spec/base_protocol_spec.rb:65:in 'block (3 levels) in <top (required)>' 2) BaseProtocol Thrift::BaseProtocol should write out the different types Failure/Error: if field_info.is_a? Fixnum NameError: uninitialized constant Thrift::BaseProtocol::Fixnum # ./lib/thrift/protocol/base_protocol.rb:256:in 'Thrift::BaseProtocol#write_type' # ./spec/base_protocol_spec.rb:90:in 'block (3 levels) in <top (required)>' 3) BaseProtocol Thrift::BaseProtocol should read the different types (deprecated read_type signature) Failure/Error: if field_info.is_a? Fixnum NameError: uninitialized constant Thrift::BaseProtocol::Fixnum # ./lib/thrift/protocol/base_protocol.rb:296:in 'Thrift::BaseProtocol#read_type' # ./spec/base_protocol_spec.rb:113:in 'block (3 levels) in <top (required)>' 4) BaseProtocol Thrift::BaseProtocol should read the different types Failure/Error: if field_info.is_a? Fixnum NameError: uninitialized constant Thrift::BaseProtocol::Fixnum # ./lib/thrift/protocol/base_protocol.rb:296:in 'Thrift::BaseProtocol#read_type' # ./spec/base_protocol_spec.rb:136:in 'block (3 levels) in <top (required)>'
1 parent 10d5a65 commit a0415a7

File tree

10 files changed

+14
-65
lines changed

10 files changed

+14
-65
lines changed

LANGUAGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Thrift's core protocol is TBinary, supported by all languages except for JavaScr
312312
<td align=left><a href="https://github.com/apache/thrift/blob/master/lib/rb/README.md">Ruby</a></td>
313313
<!-- Since -----------------><td>0.2.0</td>
314314
<!-- Build Systems ---------><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td>
315-
<!-- Language Levels -------><td>2.3.1p112</td><td>2.5.1p57</td>
315+
<!-- Language Levels -------><td>2.4.0</td><td>2.5.1p57</td>
316316
<!-- Field types -----------><td><img src="/doc/images/cred.png" alt=""/></td>
317317
<!-- Low-Level Transports --><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td>
318318
<!-- Transport Wrappers ----><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td>

lib/rb/lib/thrift.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
$:.unshift File.dirname(__FILE__)
2424

2525
require 'thrift/bytes'
26-
require 'thrift/core_ext'
2726
require 'thrift/exceptions'
2827
require 'thrift/types'
2928
require 'thrift/processor'

lib/rb/lib/thrift/core_ext.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/rb/lib/thrift/core_ext/fixnum.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/rb/lib/thrift/protocol/base_protocol.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ def write_field(*args)
251251
#
252252
# Returns nothing.
253253
def write_type(field_info, value)
254-
# if field_info is a Fixnum, assume it is a Thrift::Types constant
254+
# if field_info is a Integer, assume it is a Thrift::Types constant
255255
# convert it into a field_info Hash for backwards compatibility
256-
if field_info.is_a? Fixnum
256+
if field_info.is_a? Integer
257257
field_info = {:type => field_info}
258258
end
259259

@@ -291,9 +291,9 @@ def write_type(field_info, value)
291291
#
292292
# Returns the value read; object type varies based on field_info[:type].
293293
def read_type(field_info)
294-
# if field_info is a Fixnum, assume it is a Thrift::Types constant
294+
# if field_info is a Integer, assume it is a Thrift::Types constant
295295
# convert it into a field_info Hash for backwards compatibility
296-
if field_info.is_a? Fixnum
296+
if field_info.is_a? Integer
297297
field_info = {:type => field_info}
298298
end
299299

lib/rb/lib/thrift/transport/base_transport.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def read(sz)
6262
raise NotImplementedError
6363
end
6464

65-
# Returns an unsigned byte as a Fixnum in the range (0..255).
65+
# Returns an unsigned byte as a Integer in the range (0..255).
6666
def read_byte
6767
buf = read_all(1)
6868
return Bytes.get_string_byte(buf, 0)

lib/rb/spec/struct_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def validate_default_arguments(object)
227227
it "should support optional type-checking in Thrift::Struct.new" do
228228
Thrift.type_checking = true
229229
begin
230-
expect { SpecNamespace::Hello.new(:greeting => 3) }.to raise_error(Thrift::TypeError, /Expected Types::STRING, received (Integer|Fixnum) for field greeting/)
230+
expect { SpecNamespace::Hello.new(:greeting => 3) }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
231231
ensure
232232
Thrift.type_checking = false
233233
end
@@ -238,7 +238,7 @@ def validate_default_arguments(object)
238238
Thrift.type_checking = true
239239
begin
240240
hello = SpecNamespace::Hello.new
241-
expect { hello.greeting = 3 }.to raise_error(Thrift::TypeError, /Expected Types::STRING, received (Integer|Fixnum) for field greeting/)
241+
expect { hello.greeting = 3 }.to raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
242242
ensure
243243
Thrift.type_checking = false
244244
end

lib/rb/spec/types_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100
end
101101

102102
it "should give the Thrift::TypeError a readable message" do
103-
msg = /Expected Types::STRING, received (Integer|Fixnum) for field foo/
103+
msg = "Expected Types::STRING, received Integer for field foo"
104104
expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError, msg)
105-
msg = /Expected Types::STRING, received (Integer|Fixnum) for field foo.element/
105+
msg = "Expected Types::STRING, received Integer for field foo.element"
106106
field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
107107
expect { Thrift.check_type([3], field, :foo) }.to raise_error(Thrift::TypeError, msg)
108108
msg = "Expected Types::I32, received NilClass for field foo.element.key"

lib/rb/thrift.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
1212
s.license = 'Apache-2.0'
1313
s.extensions = ['ext/extconf.rb']
1414

15+
s.required_ruby_version = '>= 2.4.0'
16+
1517
s.rdoc_options = %w[--line-numbers --inline-source --title Thrift --main README]
1618

1719
s.rubyforge_project = 'thrift'

test/rb/integration/TestClient.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ def test_enum
225225
ret = @client.testEnum(val)
226226

227227
assert_equal(ret, 6)
228-
assert_kind_of(Fixnum, ret)
228+
assert_kind_of(Integer, ret)
229229
end
230230

231231
def test_typedef
232232
p 'test_typedef'
233233
#UserId testTypedef(1: UserId thing),
234234
assert_equal(@client.testTypedef(309858235082523), 309858235082523)
235-
assert_kind_of(Fixnum, @client.testTypedef(309858235082523))
235+
assert_kind_of(Integer, @client.testTypedef(309858235082523))
236236
true
237237
end
238238

0 commit comments

Comments
 (0)