summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2022-09-10 00:55:02 +0200
committerJens Geyer <jensg@apache.org>2022-09-10 00:55:55 +0200
commitf8f62786e90ecfe5dea8ab8c4ee4698bb35a6cb5 (patch)
treedc64c909fd3caca56280212e4be1542a69b1a52d /lib
parent60970c4e10b0014005bc68f07f4e5c5987b41e3a (diff)
downloadthrift-f8f62786e90ecfe5dea8ab8c4ee4698bb35a6cb5.tar.gz
THRIFT-5625 SysUtils.TGuidHelper collides with ThriftUtils.TGuidHelper
Client: Delphi Patch: Jens Geyer
Diffstat (limited to 'lib')
-rw-r--r--lib/delphi/src/Thrift.Protocol.Compact.pas4
-rw-r--r--lib/delphi/src/Thrift.Protocol.pas4
-rw-r--r--lib/delphi/src/Thrift.Utils.pas24
3 files changed, 19 insertions, 13 deletions
diff --git a/lib/delphi/src/Thrift.Protocol.Compact.pas b/lib/delphi/src/Thrift.Protocol.Compact.pas
index 02a19ea80..80f1ce58a 100644
--- a/lib/delphi/src/Thrift.Protocol.Compact.pas
+++ b/lib/delphi/src/Thrift.Protocol.Compact.pas
@@ -546,7 +546,7 @@ procedure TCompactProtocolImpl.WriteUuid( const uuid: TGuid);
var network : TGuid; // in network order (Big Endian)
begin
ASSERT( SizeOf(uuid) = 16);
- network := uuid.SwapByteOrder;
+ network := GuidUtils.SwapByteOrder(uuid);
Transport.Write( @network, 0, SizeOf(network));
end;
@@ -868,7 +868,7 @@ var network : TGuid; // in network order (Big Endian)
begin
ASSERT( SizeOf(result) = 16);
FTrans.ReadAll( @network, SizeOf(network), 0, SizeOf(network));
- result := network.SwapByteOrder;
+ result := GuidUtils.SwapByteOrder(network);
end;
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index 636f20100..c6b1a00a5 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -889,7 +889,7 @@ var network : TGuid; // in network order (Big Endian)
begin
ASSERT( SizeOf(result) = 16);
FTrans.ReadAll( @network, SizeOf(network), 0, SizeOf(network));
- result := network.SwapByteOrder;
+ result := GuidUtils.SwapByteOrder(network);
end;
function TBinaryProtocolImpl.ReadBool: Boolean;
@@ -1064,7 +1064,7 @@ procedure TBinaryProtocolImpl.WriteUuid( const uuid: TGuid);
var network : TGuid; // in network order (Big Endian)
begin
ASSERT( SizeOf(uuid) = 16);
- network := uuid.SwapByteOrder;
+ network := GuidUtils.SwapByteOrder(uuid);
Transport.Write( @network, 0, SizeOf(network));
end;
diff --git a/lib/delphi/src/Thrift.Utils.pas b/lib/delphi/src/Thrift.Utils.pas
index 122653572..fff6b86c0 100644
--- a/lib/delphi/src/Thrift.Utils.pas
+++ b/lib/delphi/src/Thrift.Utils.pas
@@ -96,9 +96,12 @@ type
end;
- TGuidHelper = record helper for System.TGuid
+ // problem: inheritance possible for class helpers ONLY but not with record helpers
+ // workaround: use static class method instead of record helper :-(
+ GuidUtils = class sealed
public
- function SwapByteOrder : TGuid;
+ // new stuff
+ class function SwapByteOrder( const aGuid : TGuid) : TGuid; static;
{$IFDEF Debug}
class procedure SelfTest; static;
@@ -355,16 +358,16 @@ begin
end;
-{ TGuidHelper }
+{ GuidUtils }
-function TGuidHelper.SwapByteOrder : TGuid;
+class function GuidUtils.SwapByteOrder( const aGuid : TGuid) : TGuid;
// convert to/from network byte order
// - https://www.ietf.org/rfc/rfc4122.txt
// - https://stackoverflow.com/questions/10850075/guid-uuid-compatibility-issue-between-net-and-linux
// - https://lists.gnu.org/archive/html/bug-parted/2002-01/msg00099.html
begin
- result := Self;
+ result := aGuid;
IntegerUtils.SwapByteOrder( @result.D1, SizeOf(result.D1));
IntegerUtils.SwapByteOrder( @result.D2, SizeOf(result.D2));
@@ -374,7 +377,7 @@ end;
{$IFDEF Debug}
-class procedure TGuidHelper.SelfTest;
+class procedure GuidUtils.SelfTest;
var guid : TGuid;
pBytes : PByteArray;
i, expected : Integer;
@@ -382,7 +385,7 @@ const TEST_GUID : TGuid = '{00112233-4455-6677-8899-aabbccddeeff}';
begin
// host to network
guid := TEST_GUID;
- guid := guid.SwapByteOrder;
+ guid := GuidUtils.SwapByteOrder(guid);
// validate network order
pBytes := @guid;
@@ -392,8 +395,11 @@ begin
end;
// network to host and final validation
- guid := guid.SwapByteOrder;
+ guid := GuidUtils.SwapByteOrder(guid);
ASSERT( IsEqualGuid( guid, TEST_GUID));
+
+ // prevent collisions with SysUtils.TGuidHelper
+ guid := TGuid.NewGuid;
end;
{$ENDIF}
@@ -494,6 +500,6 @@ end;
begin
{$IFDEF Debug}
- TGuid.SelfTest;
+ GuidUtils.SelfTest;
{$ENDIF}
end.