You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2017/09/08 22:00:25 UTC
[1/2] thrift git commit: THRIFT-4323 range check errors or NPE in
edge cases Client: Delphi Patch: Jens Geyer
Repository: thrift
Updated Branches:
refs/heads/master a62efa410 -> 078281dcd
THRIFT-4323 range check errors or NPE in edge cases
Client: Delphi
Patch: Jens Geyer
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a76e6c79
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a76e6c79
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a76e6c79
Branch: refs/heads/master
Commit: a76e6c7920f682c0da08e9f83df6758a68bc98d0
Parents: a62efa4
Author: Jens Geyer <je...@apache.org>
Authored: Fri Sep 8 21:03:30 2017 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Fri Sep 8 23:55:01 2017 +0200
----------------------------------------------------------------------
lib/delphi/src/Thrift.Stream.pas | 7 +++++--
lib/delphi/src/Thrift.Transport.pas | 17 ++++++++++++-----
2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/a76e6c79/lib/delphi/src/Thrift.Stream.pas
----------------------------------------------------------------------
diff --git a/lib/delphi/src/Thrift.Stream.pas b/lib/delphi/src/Thrift.Stream.pas
index 1d357c3..b6e0cbf 100644
--- a/lib/delphi/src/Thrift.Stream.pas
+++ b/lib/delphi/src/Thrift.Stream.pas
@@ -197,7 +197,9 @@ end;
function TThriftStreamImpl.Read(var buffer: TBytes; offset, count: Integer): Integer;
begin
- Result := Read( @buffer[0], Length(buffer), offset, count);
+ if Length(buffer) > 0
+ then Result := Read( @buffer[0], Length(buffer), offset, count)
+ else Result := 0;
end;
function TThriftStreamImpl.Read( const pBuf : Pointer; const buflen : Integer; offset: Integer; count: Integer): Integer;
@@ -208,7 +210,8 @@ end;
procedure TThriftStreamImpl.Write(const buffer: TBytes; offset, count: Integer);
begin
- Write( @buffer[0], offset, count);
+ if Length(buffer) > 0
+ then Write( @buffer[0], offset, count);
end;
procedure TThriftStreamImpl.Write( const pBuf : Pointer; offset: Integer; count: Integer);
http://git-wip-us.apache.org/repos/asf/thrift/blob/a76e6c79/lib/delphi/src/Thrift.Transport.pas
----------------------------------------------------------------------
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index d20eb2f..52b617b 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -414,22 +414,28 @@ end;
function TTransportImpl.Read(var buf: TBytes; off: Integer; len: Integer): Integer;
begin
- result := Read( @buf[0], Length(buf), off, len);
+ if Length(buf) > 0
+ then result := Read( @buf[0], Length(buf), off, len)
+ else result := 0;
end;
function TTransportImpl.ReadAll(var buf: TBytes; off: Integer; len: Integer): Integer;
begin
- result := ReadAll( @buf[0], Length(buf), off, len);
+ if Length(buf) > 0
+ then result := ReadAll( @buf[0], Length(buf), off, len)
+ else result := 0;
end;
procedure TTransportImpl.Write( const buf: TBytes);
begin
- Write( @buf[0], 0, Length(buf));
+ if Length(buf) > 0
+ then Write( @buf[0], 0, Length(buf));
end;
procedure TTransportImpl.Write( const buf: TBytes; off: Integer; len: Integer);
begin
- Write( @buf[0], off, len);
+ if Length(buf) > 0
+ then Write( @buf[0], off, len);
end;
function TTransportImpl.ReadAll(const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer): Integer;
@@ -1282,7 +1288,8 @@ begin
FTransport.ReadAll( buff, 0, size );
FReadBuffer.Free;
FReadBuffer := TMemoryStream.Create;
- FReadBuffer.Write( Pointer(@buff[0])^, size );
+ if Length(buff) > 0
+ then FReadBuffer.Write( Pointer(@buff[0])^, size );
FReadBuffer.Position := 0;
end;
[2/2] thrift git commit: THRIFT-4324 field names can conflict with
local vars in generated code Client: Delphi Patch: Jens Geyer
Posted by je...@apache.org.
THRIFT-4324 field names can conflict with local vars in generated code
Client: Delphi
Patch: Jens Geyer
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/078281dc
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/078281dc
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/078281dc
Branch: refs/heads/master
Commit: 078281dcd3ff0d122711453f28ff8e62f44d11b6
Parents: a76e6c7
Author: Jens Geyer <je...@apache.org>
Authored: Fri Sep 8 22:09:52 2017 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Fri Sep 8 23:55:02 2017 +0200
----------------------------------------------------------------------
.../src/thrift/generate/t_delphi_generator.cc | 42 +++++++++---------
lib/delphi/test/codegen/ReservedKeywords.thrift | 45 ++++++++++++++++++++
lib/delphi/test/serializer/TestSerializer.dpr | 1 +
3 files changed, 67 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/078281dc/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 854013f..1894fe8 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -2029,7 +2029,7 @@ void t_delphi_generator::generate_service_client(t_service* tservice) {
indent_up_impl();
indent_impl(s_service_impl) << "seqid_ := seqid_ + 1;" << endl;
- indent_impl(s_service_impl) << "Init( " << msgvar << ", '" << funname
+ indent_impl(s_service_impl) << "Thrift.Protocol.Init( " << msgvar << ", '" << funname
<< "', " << ((*f_iter)->is_oneway() ? "TMessageType.Oneway"
: "TMessageType.Call")
<< ", seqid_);" << endl;
@@ -2257,7 +2257,7 @@ void t_delphi_generator::generate_service_server(t_service* tservice) {
"TApplicationExceptionUnknownMethod.Create("
"'Invalid method name: ''' + msg.Name + '''');" << endl;
indent_impl(s_service_impl)
- << "Init( msg, msg.Name, TMessageType.Exception, msg.SeqID);"
+ << "Thrift.Protocol.Init( msg, msg.Name, TMessageType.Exception, msg.SeqID);"
<< endl;
indent_impl(s_service_impl) << "oprot.WriteMessageBegin( msg);" << endl;
indent_impl(s_service_impl) << "x.Write(oprot);" << endl;
@@ -2459,7 +2459,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi
if(events_) {
indent_impl(s_service_impl) << "if events <> nil then events.PreWrite;" << endl;
}
- indent_impl(s_service_impl) << "Init( msg, '"
+ indent_impl(s_service_impl) << "Thrift.Protocol.Init( msg, '"
<< tfunction->get_name() << "', TMessageType.Exception, seqid);"
<< endl;
indent_impl(s_service_impl) << "oprot.WriteMessageBegin( msg);" << endl;
@@ -2487,7 +2487,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi
if (events_) {
indent_impl(s_service_impl) << "if events <> nil then events.PreWrite;" << endl;
}
- indent_impl(s_service_impl) << "Init( msg, '"
+ indent_impl(s_service_impl) << "Thrift.Protocol.Init( msg, '"
<< tfunction->get_name() << "', TMessageType.Reply, seqid); "
<< endl;
indent_impl(s_service_impl) << "oprot.WriteMessageBegin( msg); " << endl;
@@ -2804,7 +2804,7 @@ void t_delphi_generator::generate_serialize_container(ostream& out,
if (ttype->is_map()) {
obj = tmp("map");
local_vars << " " << obj << " : TThriftMap;" << endl;
- indent_impl(out) << "Init( " << obj << ", "
+ indent_impl(out) << "Thrift.Protocol.Init( " << obj << ", "
<< type_to_enum(((t_map*)ttype)->get_key_type()) << ", "
<< type_to_enum(((t_map*)ttype)->get_val_type()) << ", " << prefix
<< ".Count);" << endl;
@@ -2812,14 +2812,14 @@ void t_delphi_generator::generate_serialize_container(ostream& out,
} else if (ttype->is_set()) {
obj = tmp("set_");
local_vars << " " << obj << " : TThriftSet;" << endl;
- indent_impl(out) << "Init( " << obj << ", "
+ indent_impl(out) << "Thrift.Protocol.Init( " << obj << ", "
<< type_to_enum(((t_set*)ttype)->get_elem_type()) << ", " << prefix
<< ".Count);" << endl;
indent_impl(out) << "oprot.WriteSetBegin( " << obj << ");" << endl;
} else if (ttype->is_list()) {
obj = tmp("list_");
local_vars << " " << obj << " : TThriftList;" << endl;
- indent_impl(out) << "Init( " << obj << ", "
+ indent_impl(out) << "Thrift.Protocol.Init( " << obj << ", "
<< type_to_enum(((t_list*)ttype)->get_elem_type()) << ", " << prefix
<< ".Count);" << endl;
indent_impl(out) << "oprot.WriteListBegin( " << obj << ");" << endl;
@@ -3548,7 +3548,7 @@ void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out,
<< ") then begin" << endl;
indent_up_impl();
- generate_deserialize_field(code_block, is_exception, *f_iter, "", local_vars);
+ generate_deserialize_field(code_block, is_exception, *f_iter, "Self.", local_vars);
// required field?
if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
@@ -3642,11 +3642,11 @@ void t_delphi_generator::generate_delphi_struct_result_writer_impl(ostream& out,
indent_impl(local_vars) << "tracker : IProtocolRecursionTracker;" << endl;
indent_impl(code_block) << "tracker := oprot.NextRecursionLevel;" << endl;
- indent_impl(code_block) << "Init( struc, '" << name << "');" << endl;
+ indent_impl(code_block) << "Thrift.Protocol.Init( struc, '" << name << "');" << endl;
indent_impl(code_block) << "oprot.WriteStructBegin(struc);" << endl;
if (fields.size() > 0) {
- indent_impl(code_block) << "Init( field_);" << endl;
+ indent_impl(code_block) << "Thrift.Protocol.Init( field_);" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
indent_impl(code_block) << "if (__isset_" << prop_name(*f_iter, is_exception) << ") then"
<< endl;
@@ -3657,7 +3657,7 @@ void t_delphi_generator::generate_delphi_struct_result_writer_impl(ostream& out,
<< endl;
indent_impl(code_block) << "field_.ID := " << (*f_iter)->get_key() << ";" << endl;
indent_impl(code_block) << "oprot.WriteFieldBegin(field_);" << endl;
- generate_serialize_field(code_block, is_exception, *f_iter, "", local_vars);
+ generate_serialize_field(code_block, is_exception, *f_iter, "Self.", local_vars);
indent_impl(code_block) << "oprot.WriteFieldEnd();" << endl;
indent_down_impl();
}
@@ -3706,11 +3706,11 @@ void t_delphi_generator::generate_delphi_struct_writer_impl(ostream& out,
indent_impl(local_vars) << "tracker : IProtocolRecursionTracker;" << endl;
indent_impl(code_block) << "tracker := oprot.NextRecursionLevel;" << endl;
- indent_impl(code_block) << "Init( struc, '" << name << "');" << endl;
+ indent_impl(code_block) << "Thrift.Protocol.Init( struc, '" << name << "');" << endl;
indent_impl(code_block) << "oprot.WriteStructBegin(struc);" << endl;
if (fields.size() > 0) {
- indent_impl(code_block) << "Init( field_);" << endl;
+ indent_impl(code_block) << "Thrift.Protocol.Init( field_);" << endl;
}
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
@@ -3720,13 +3720,13 @@ void t_delphi_generator::generate_delphi_struct_writer_impl(ostream& out,
bool has_isset = (!is_required);
if (is_required && null_allowed) {
null_allowed = false;
- indent_impl(code_block) << "if (" << fieldname << " = nil)" << endl;
+ indent_impl(code_block) << "if (Self." << fieldname << " = nil)" << endl;
indent_impl(code_block) << "then raise TProtocolExceptionInvalidData.Create("
<< "'required field " << fieldname << " not set');"
<< endl;
}
if (null_allowed) {
- indent_impl(code_block) << "if (" << fieldname << " <> nil)";
+ indent_impl(code_block) << "if (Self." << fieldname << " <> nil)";
if (has_isset) {
code_block << " and __isset_" << fieldname;
}
@@ -3743,7 +3743,7 @@ void t_delphi_generator::generate_delphi_struct_writer_impl(ostream& out,
<< endl;
indent_impl(code_block) << "field_.ID := " << (*f_iter)->get_key() << ";" << endl;
indent_impl(code_block) << "oprot.WriteFieldBegin(field_);" << endl;
- generate_serialize_field(code_block, is_exception, *f_iter, "", local_vars);
+ generate_serialize_field(code_block, is_exception, *f_iter, "Self.", local_vars);
indent_impl(code_block) << "oprot.WriteFieldEnd();" << endl;
if (null_allowed || has_isset) {
indent_down_impl();
@@ -3825,7 +3825,7 @@ void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out,
bool null_allowed = type_can_be_null((*f_iter)->get_type());
bool is_optional = ((*f_iter)->get_req() != t_field::T_REQUIRED);
if (null_allowed) {
- indent_impl(out) << "if (" << prop_name((*f_iter), is_exception) << " <> nil)";
+ indent_impl(out) << "if (Self." << prop_name((*f_iter), is_exception) << " <> nil)";
if (is_optional) {
out << " and __isset_" << prop_name(*f_iter, is_exception);
}
@@ -3857,14 +3857,14 @@ void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out,
}
if (ttype->is_xception() || ttype->is_struct()) {
- indent_impl(out) << "if (" << prop_name((*f_iter), is_exception) << " = nil) then " << tmp_sb
- << ".Append('<null>') else " << tmp_sb << ".Append("
+ indent_impl(out) << "if (Self." << prop_name((*f_iter), is_exception) << " = nil) then " << tmp_sb
+ << ".Append('<null>') else " << tmp_sb << ".Append( Self."
<< prop_name((*f_iter), is_exception) << ".ToString());" << endl;
} else if (ttype->is_enum()) {
- indent_impl(out) << tmp_sb << ".Append(Integer(" << prop_name((*f_iter), is_exception)
+ indent_impl(out) << tmp_sb << ".Append(Integer( Self." << prop_name((*f_iter), is_exception)
<< "));" << endl;
} else {
- indent_impl(out) << tmp_sb << ".Append(" << prop_name((*f_iter), is_exception) << ");"
+ indent_impl(out) << tmp_sb << ".Append( Self." << prop_name((*f_iter), is_exception) << ");"
<< endl;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/078281dc/lib/delphi/test/codegen/ReservedKeywords.thrift
----------------------------------------------------------------------
diff --git a/lib/delphi/test/codegen/ReservedKeywords.thrift b/lib/delphi/test/codegen/ReservedKeywords.thrift
index 300adf9..8db3ea5 100644
--- a/lib/delphi/test/codegen/ReservedKeywords.thrift
+++ b/lib/delphi/test/codegen/ReservedKeywords.thrift
@@ -52,4 +52,49 @@ enum keywords {
}
+struct Struct_lists {
+ 1: list<Struct_simple> init;
+ 2: list<Struct_simple> struc;
+ 3: list<Struct_simple> field;
+ 4: list<Struct_simple> field_;
+ 5: list<Struct_simple> tracker;
+ 6: list<Struct_simple> Self;
+}
+
+struct Struct_structs {
+ 1: Struct_simple init;
+ 2: Struct_simple struc;
+ 3: Struct_simple field;
+ 4: Struct_simple field_;
+ 5: Struct_simple tracker;
+ 6: Struct_simple Self;
+}
+
+struct Struct_simple {
+ 1: bool init;
+ 2: bool struc;
+ 3: bool field;
+ 4: bool field_;
+ 5: bool tracker;
+ 6: bool Self;
+}
+
+struct Struct_strings {
+ 1: string init;
+ 2: string struc;
+ 3: string field;
+ 4: string field_;
+ 5: string tracker;
+ 6: string Self;
+}
+
+struct Struct_binary {
+ 1: binary init;
+ 2: binary struc;
+ 3: binary field;
+ 4: binary field_;
+ 5: binary tracker;
+ 6: binary Self;
+}
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/078281dc/lib/delphi/test/serializer/TestSerializer.dpr
----------------------------------------------------------------------
diff --git a/lib/delphi/test/serializer/TestSerializer.dpr b/lib/delphi/test/serializer/TestSerializer.dpr
index 9e283e5..14be502 100644
--- a/lib/delphi/test/serializer/TestSerializer.dpr
+++ b/lib/delphi/test/serializer/TestSerializer.dpr
@@ -35,6 +35,7 @@ uses
Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
+ ReservedKeywords,
DebugProtoTest,
TestSerializer.Data;