diff options
author | Bryan Duxbury <bryanduxbury@apache.org> | 2009-03-25 21:06:53 +0000 |
---|---|---|
committer | Bryan Duxbury <bryanduxbury@apache.org> | 2009-03-25 21:06:53 +0000 |
commit | e3ab50d0f300da7aa3bf018de805fa154afeb53f (patch) | |
tree | 8a19d2666e67a477b202edbed1a72a85db3fe9a3 /lib/rb/lib | |
parent | d73255d1acfd83ca65d3293a0d6a6c8f25c834f4 (diff) | |
download | thrift-e3ab50d0f300da7aa3bf018de805fa154afeb53f.tar.gz |
THRIFT-374. rb: ruby 1.9 compatibility
This patch updates the thrift_native package to use 1.9 compatible macros and fixes the pure ruby stuff to behave equally well in ruby1.8.6-ruby1.9.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@758435 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/rb/lib')
-rw-r--r-- | lib/rb/lib/thrift.rb | 1 | ||||
-rw-r--r-- | lib/rb/lib/thrift/core_ext.rb | 4 | ||||
-rw-r--r-- | lib/rb/lib/thrift/core_ext/fixnum.rb | 29 | ||||
-rw-r--r-- | lib/rb/lib/thrift/protocol/binaryprotocol.rb | 4 | ||||
-rw-r--r-- | lib/rb/lib/thrift/transport.rb | 1 |
5 files changed, 38 insertions, 1 deletions
diff --git a/lib/rb/lib/thrift.rb b/lib/rb/lib/thrift.rb index df447a043..d3fe7abe6 100644 --- a/lib/rb/lib/thrift.rb +++ b/lib/rb/lib/thrift.rb @@ -24,6 +24,7 @@ module Thrift DEPRECATION = false unless const_defined? :DEPRECATION end +require 'thrift/core_ext' require 'thrift/exceptions' require 'thrift/types' require 'thrift/processor' diff --git a/lib/rb/lib/thrift/core_ext.rb b/lib/rb/lib/thrift/core_ext.rb new file mode 100644 index 000000000..7a90d0a0b --- /dev/null +++ b/lib/rb/lib/thrift/core_ext.rb @@ -0,0 +1,4 @@ +Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each do |file| + name = File.basename(file, '.rb') + require "thrift/core_ext/#{name}" +end diff --git a/lib/rb/lib/thrift/core_ext/fixnum.rb b/lib/rb/lib/thrift/core_ext/fixnum.rb new file mode 100644 index 000000000..b4fc90dd6 --- /dev/null +++ b/lib/rb/lib/thrift/core_ext/fixnum.rb @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Versions of ruby pre 1.8.7 do not have an .ord method available in the Fixnum +# class. +# +if RUBY_VERSION < "1.8.7" + class Fixnum + def ord + self + end + end +end
\ No newline at end of file diff --git a/lib/rb/lib/thrift/protocol/binaryprotocol.rb b/lib/rb/lib/thrift/protocol/binaryprotocol.rb index dd963f2c5..ca9ffeadf 100644 --- a/lib/rb/lib/thrift/protocol/binaryprotocol.rb +++ b/lib/rb/lib/thrift/protocol/binaryprotocol.rb @@ -80,6 +80,7 @@ module Thrift end def write_byte(byte) + raise RangeError if byte < -2**31 || byte >= 2**32 trans.write([byte].pack('c')) end @@ -93,6 +94,7 @@ module Thrift end def write_i64(i64) + raise RangeError if i64 < -2**63 || i64 >= 2**64 hi = i64 >> 32 lo = i64 & 0xffffffff trans.write([hi, lo].pack('N2')) @@ -166,7 +168,7 @@ module Thrift def read_byte dat = trans.read_all(1) - val = dat[0] + val = dat[0].ord if (val > 0x7f) val = 0 - ((val - 1) ^ 0xff) end diff --git a/lib/rb/lib/thrift/transport.rb b/lib/rb/lib/thrift/transport.rb index 6c75ce865..503c6dd0f 100644 --- a/lib/rb/lib/thrift/transport.rb +++ b/lib/rb/lib/thrift/transport.rb @@ -1,3 +1,4 @@ +# encoding: ascii-8bit # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file |