Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions compiler/cpp/src/thrift/generate/t_rb_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,16 +1055,21 @@ void t_rb_generator::generate_service_client(t_service* tservice) {
f_service_.indent() << "validate_message_begin(fname, mtype, rseqid, \"" << funname << "\")"
<< '\n';

f_service_.indent() << "result = receive_message(" << resultname << ")" << '\n';
t_struct* xs = (*f_iter)->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;

f_service_.indent();
if (!(*f_iter)->get_returntype()->is_void() || !xceptions.empty()) {
f_service_ << "result = ";
}
f_service_ << "receive_message(" << resultname << ")" << '\n';

// Careful, only return _result if not a void function
if (!(*f_iter)->get_returntype()->is_void()) {
f_service_.indent() << "return result.success unless result.success.nil?" << '\n';
}

t_struct* xs = (*f_iter)->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
f_service_.indent() << "raise result." << (*x_iter)->get_name() << " unless result."
<< (*x_iter)->get_name() << ".nil?" << '\n';
Expand Down Expand Up @@ -1148,7 +1153,14 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
string argsname = capitalize(tfunction->get_name()) + "_args";
string resultname = capitalize(tfunction->get_name()) + "_result";

f_service_.indent() << "args = read_args(iprot, " << argsname << ")" << '\n';
t_struct* arg_struct = tfunction->get_arglist();
const std::vector<t_field*>& fields = arg_struct->get_members();

f_service_.indent();
if (!fields.empty()) {
f_service_ << "args = ";
}
f_service_ << "read_args(iprot, " << argsname << ")" << '\n';

t_struct* xs = tfunction->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
Expand All @@ -1166,8 +1178,6 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
}

// Generate the function call
t_struct* arg_struct = tfunction->get_arglist();
const std::vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator f_iter;

f_service_.indent();
Expand Down
12 changes: 12 additions & 0 deletions compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ TEST_CASE("t_rb_generator formats service classes and positional arguments", "[f
"service PingService {\n"
" oneway void ping(1: i32 n)\n"
" i32 pong()\n"
" void noop()\n"
"}\n";

{
Expand All @@ -134,6 +135,17 @@ TEST_CASE("t_rb_generator formats service classes and positional arguments", "[f
REQUIRE(service.find("send_oneway_message(\"ping\", Ping_args, {n: n})") != string::npos);
REQUIRE(service.find("def pong()\n send_pong()\n recv_pong()\n end")
!= string::npos);
REQUIRE(service.find("def recv_noop()\n"
" fname, mtype, rseqid = receive_message_begin()\n"
" validate_message_begin(fname, mtype, rseqid, \"noop\")\n"
" receive_message(Noop_result)\n"
" nil\n"
" end")
!= string::npos);
REQUIRE(service.find("def process_pong(seqid, iprot, oprot)\n"
" read_args(iprot, Pong_args)\n"
" result = Pong_result.new()")
!= string::npos);
REQUIRE(service.find(expected_empty_result) != string::npos);
REQUIRE(service.find("\n\n end\n") == string::npos);

Expand Down
3 changes: 3 additions & 0 deletions lib/rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ Lint/RedundantStringCoercion:
Lint/UnreachableCode:
Enabled: true

Lint/UselessAssignment:
Enabled: true

Performance/BindCall:
Enabled: true

Expand Down
5 changes: 2 additions & 3 deletions lib/rb/benchmark/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ def analyze_output
end
end
@report = {}
@report[:total_calls] = call_times.inject(0.0) { |a, t| a += t }
@report[:total_calls] = call_times.inject(0.0) { |a, t| a + t }
@report[:avg_calls] = @report[:total_calls] / call_times.size
@report[:total_clients] = client_times.inject(0.0) { |a, t| a += t }
@report[:total_clients] = client_times.inject(0.0) { |a, t| a + t }
@report[:avg_clients] = @report[:total_clients] / client_times.size
@report[:connection_failures] = connection_failures.size
@report[:connection_errors] = connection_errors.size
Expand All @@ -209,7 +209,6 @@ def report_output
["Clients per process", @clients_per_process],
["Calls per client", @calls_per_client]
puts
failures = (@report[:connection_failures] > 0)
tabulate fmt,
[["Connection failures", "%d", [:red, :bold]], @report[:connection_failures]],
[["Connection errors", "%d", [:red, :bold]], @report[:connection_errors]],
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def read(iprot, remaining_depth = DEFAULT_RECURSION_DEPTH)
raise ProtocolException.new(ProtocolException::DEPTH_LIMIT, "Maximum recursion depth exceeded") if remaining_depth <= 0
iprot.read_struct_begin
while true
fname, ftype, fid = iprot.read_field_begin
_, ftype, fid = iprot.read_field_begin
if ftype == Types::STOP
break
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/protocol/base_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def skip(type, max_depth = 64)
when Types::STRUCT
read_struct_begin
while true
name, type, id = read_field_begin
_, type, _ = read_field_begin
break if type == Types::STOP
skip(type, max_depth - 1)
read_field_end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/nonblocking_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def serve
@logger.debug "Accepted socket: #{socket.inspect}"
@io_manager.add_connection socket
end
rescue IOError => e
rescue IOError
end
# we must be shutting down
@logger.info "#{self} is shutting down, goodbye"
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/thread_pool_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def serve
loop do
@processor.process(prot, prot)
end
rescue Thrift::TransportException, Thrift::ProtocolException => e
rescue Thrift::TransportException, Thrift::ProtocolException
ensure
trans.close
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def read(iprot, remaining_depth = DEFAULT_RECURSION_DEPTH)

iprot.read_struct_begin
loop do
fname, ftype, fid = iprot.read_field_begin
_, ftype, fid = iprot.read_field_begin
break if (ftype == Types::STOP)
handle_message(iprot, fid, ftype, remaining_depth)
iprot.read_field_end
Expand Down
4 changes: 2 additions & 2 deletions lib/rb/lib/thrift/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def read(iprot, remaining_depth = DEFAULT_RECURSION_DEPTH)
@value = nil

iprot.read_struct_begin
fname, ftype, fid = iprot.read_field_begin
_, ftype, fid = iprot.read_field_begin
handle_message(iprot, fid, ftype, remaining_depth)
iprot.read_field_end

fname, ftype, fid = iprot.read_field_begin
_, ftype, _ = iprot.read_field_begin
unless (ftype == Types::STOP)
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Too many fields for union")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/spec/compact_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
proto.write_field_end

proto = Thrift::CompactProtocol.new(trans)
name, type, id = proto.read_field_begin
_, type, id = proto.read_field_begin
expect(type).to eq(thrift_type)
expect(id).to eq(15)
read_back = proto.send(reader(primitive_type))
Expand Down
4 changes: 2 additions & 2 deletions lib/rb/spec/header_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@

read_protocol.read_message_begin
read_protocol.read_struct_begin
name, type, id = read_protocol.read_field_begin
_, type, id = read_protocol.read_field_begin
expect(type).to eq(Thrift::Types::I32)
expect(id).to eq(1)
value = read_protocol.read_i32
Expand Down Expand Up @@ -389,7 +389,7 @@
read_buffer = Thrift::MemoryBufferTransport.new(data)
read_protocol = Thrift::HeaderProtocol.new(read_buffer)

name, type, seqid = read_protocol.read_message_begin
name, _, seqid = read_protocol.read_message_begin
expect(name).to eq("compressed_test")
expect(seqid).to eq(42)

Expand Down
6 changes: 3 additions & 3 deletions lib/rb/spec/uuid_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ def expect_invalid_uuid(value, message)
@prot.write_struct_end

@prot.read_struct_begin
name, type, id = @prot.read_field_begin
_, type, _ = @prot.read_field_begin
expect(type).to eq(Thrift::Types::UUID)
expect(@prot.read_uuid).to eq("550e8400-e29b-41d4-a716-446655440000")
@prot.read_field_end

name, type, id = @prot.read_field_begin
_, type, _ = @prot.read_field_begin
expect(type).to eq(Thrift::Types::UUID)
expect(@prot.read_uuid).to eq("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
@prot.read_field_end

name, type, id = @prot.read_field_begin
_, type, _ = @prot.read_field_begin
expect(type).to eq(Thrift::Types::STOP)
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rb/thrift.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Gem::Specification.new do |s|

s.rdoc_options = %w[--line-numbers --inline-source --title Thrift --main README]

dir = File.expand_path(File.dirname(__FILE__))

s.files = Dir.glob("{lib,ext}/**/*.{c,h,rb}")
s.executables = Dir.glob("{bin}/**/*")

Expand Down
10 changes: 6 additions & 4 deletions test/rb/integration/TestClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ def test_void

def test_string
p "test_string"
test_string =
escaped_string =
'quote: \" backslash:' +
' forwardslash-escaped: \/ ' +
' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
' now-all-of-them-together: "\\\/\b\n\r\t' +
' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' +
' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ '
test_string = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
unicode_string = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
"Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
"Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +
"বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " +
Expand All @@ -191,8 +191,10 @@ def test_string
"Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
"Bân-lâm-gú, 粵語"

result_string = @client.testString(test_string)
assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8))
[escaped_string, unicode_string].each do |test_string|
result_string = @client.testString(test_string)
assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8))
end
end

def test_multiplexed
Expand Down
2 changes: 1 addition & 1 deletion tutorial/rb/RubyClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
work.op = Operation::DIVIDE
work.num1 = 1
work.num2 = 0
quot = client.calculate(1, work)
client.calculate(1, work)
puts "Whoa, we can divide by 0 now?"
rescue InvalidOperation => io
print "InvalidOperation: ", io.why, "\n"
Expand Down
Loading