Skip to content

Commit

Permalink
THRIFT-3788 Compatibility improvements and Win64 support
Browse files Browse the repository at this point in the history
Client: Delphi
Patch: Nick Homolibere

Tested on XE, XE5, XE8, XE10

This closes #987
  • Loading branch information
homolibere authored and Jens-G committed Apr 14, 2016
1 parent 3ca89e6 commit 4f5229e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 16 deletions.
10 changes: 9 additions & 1 deletion lib/delphi/src/Thrift.Serializer.pas
Expand Up @@ -18,10 +18,18 @@
*)
unit Thrift.Serializer;

{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

interface

uses
Classes, Windows, SysUtils,
{$IF CompilerVersion < 23.0}
Classes, Windows, SysUtils,
{$ELSE}
System.Classes, Winapi.Windows, System.SysUtils,
{$IFEND}
Thrift.Protocol,
Thrift.Transport,
Thrift.Stream;
Expand Down
9 changes: 8 additions & 1 deletion lib/delphi/src/Thrift.Server.pas
Expand Up @@ -20,11 +20,18 @@
unit Thrift.Server;

{$I-} // prevent annoying errors with default log delegate and no console
{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

interface

uses
Windows, SysUtils,
{$IF CompilerVersion < 23.0}
Windows, SysUtils,
{$ELSE}
Winapi.Windows, System.SysUtils,
{$IFEND}
Thrift,
Thrift.Protocol,
Thrift.Transport;
Expand Down
14 changes: 11 additions & 3 deletions lib/delphi/src/Thrift.Stream.pas
Expand Up @@ -19,15 +19,23 @@

unit Thrift.Stream;

{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

interface

uses
Classes,
SysUtils,
SysConst,
RTLConsts,
Thrift.Utils,
ActiveX;
{$IF CompilerVersion < 23.0}
ActiveX,
{$ELSE}
Winapi.ActiveX,
{$IFEND}
Thrift.Utils;

type

Expand Down Expand Up @@ -140,7 +148,7 @@ function TThriftStreamAdapterCOM.ToArray: TBytes;
var
statstg: TStatStg;
len : Integer;
NewPos : {$IF CompilerVersion >= 30.0} UInt64 {$ELSE} Int64 {$IFEND};
NewPos : {$IF CompilerVersion >= 29.0} UInt64 {$ELSE} Int64 {$IFEND};
cbRead : Integer;
begin
FillChar( statstg, SizeOf( statstg), 0);
Expand Down
27 changes: 26 additions & 1 deletion lib/delphi/src/Thrift.Transport.Pipes.pas
Expand Up @@ -19,11 +19,18 @@
unit Thrift.Transport.Pipes;

{$WARN SYMBOL_PLATFORM OFF}
{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

interface

uses
{$IF CompilerVersion < 23.0}
Windows, SysUtils, Math, AccCtrl, AclAPI, SyncObjs,
{$ELSE}
Winapi.Windows, System.SysUtils, System.Math, Winapi.AccCtrl, Winapi.AclAPI, System.SyncObjs,
{$IFEND}
Thrift.Transport,
Thrift.Utils,
Thrift.Stream;
Expand Down Expand Up @@ -896,9 +903,14 @@ procedure TNamedPipeServerTransportImpl.InternalClose;


function TNamedPipeServerTransportImpl.Handle : THandle;
{$IFDEF WIN64}
var
Hndl: Integer;
{$ENDIF}
begin
{$IFDEF WIN64}
result := THandle( InterlockedExchangeAdd64( Integer(FHandle), 0));
Hndl := Integer(FHandle);
result := THandle( InterlockedExchangeAdd( Hndl, 0));
{$ELSE}
result := THandle( InterlockedExchangeAdd( Integer(FHandle), 0));
{$ENDIF}
Expand Down Expand Up @@ -946,6 +958,7 @@ function TNamedPipeServerTransportImpl.CreateNamedPipe : THandle;
sa.bInheritHandle := FALSE;

// Create an instance of the named pipe
{$IF CompilerVersion < 23.0}
result := Windows.CreateNamedPipe( PChar( FPipeName), // pipe name
PIPE_ACCESS_DUPLEX or // read/write access
FILE_FLAG_OVERLAPPED, // async mode
Expand All @@ -956,6 +969,18 @@ function TNamedPipeServerTransportImpl.CreateNamedPipe : THandle;
FBufSize, // input buffer size
FTimeout, // time-out, see MSDN
@sa); // default security attribute
{$ELSE}
result := Winapi.Windows.CreateNamedPipe( PChar( FPipeName), // pipe name
PIPE_ACCESS_DUPLEX or // read/write access
FILE_FLAG_OVERLAPPED, // async mode
PIPE_TYPE_BYTE or // byte type pipe
PIPE_READMODE_BYTE, // byte read mode
FMaxConns, // max. instances
FBufSize, // output buffer size
FBufSize, // input buffer size
FTimeout, // time-out, see MSDN
@sa); // default security attribute
{$IFEND}

if( result <> INVALID_HANDLE_VALUE)
then InterlockedExchangePointer( Pointer(FHandle), Pointer(result))
Expand Down
31 changes: 23 additions & 8 deletions lib/delphi/src/Thrift.Transport.pas
Expand Up @@ -17,7 +17,10 @@
* under the License.
*)

{$SCOPEDENUMS ON}
{$SCOPEDENUMS ON}
{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

{$IF CompilerVersion < 28.0}
{$DEFINE OLD_SOCKETS} // TODO: add socket support for CompilerVersion >= 28.0
Expand All @@ -32,16 +35,20 @@ interface
Classes,
SysUtils,
Math,
WinSock,
{$IFDEF OLD_SOCKETS}
Sockets,
{$ENDIF}
Generics.Collections,
{$IF CompilerVersion < 23.0}
ActiveX, msxml, WinSock, Sockets,
{$ELSE}
Winapi.ActiveX, Winapi.msxml, Winapi.WinSock,
{$IF CompilerVersion < 28.0}
Web.Win.Sockets,
{$ELSE}
System.Win.ScktComp,
{$IFEND}
{$IFEND}
Thrift.Collections,
Thrift.Utils,
Thrift.Stream,
ActiveX,
msxml;
Thrift.Stream;

type
ITransport = interface
Expand Down Expand Up @@ -1253,7 +1260,11 @@ function TTcpSocketStreamImpl.Select( ReadReady, WriteReady, ExceptFlag: PBoolea
wsaError := 0;
try
{$IFDEF MSWINDOWS}
{$IF CompilerVersion < 23.0}
result := WinSock.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
{$ELSE}
result := Winapi.WinSock.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
{$IFEND}
{$ENDIF}
{$IFDEF LINUX}
result := Libc.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
Expand Down Expand Up @@ -1293,7 +1304,11 @@ function TTcpSocketStreamImpl.WaitForData( TimeOut : Integer; pBuf : Pointer;

// recv() returns the number of bytes received, or -1 if an error occurred.
// The return value will be 0 when the peer has performed an orderly shutdown.
{$IF CompilerVersion < 23.0}
retval := recv( FTcpClient.Handle, pBuf^, DesiredBytes, WinSock.MSG_PEEK);
{$ELSE}
retval := recv( FTcpClient.Handle, pBuf^, DesiredBytes, Winapi.WinSock.MSG_PEEK);
{$IFEND}
if retval <= 0
then Exit( TWaitForData.wfd_Error);

Expand Down
20 changes: 18 additions & 2 deletions lib/delphi/src/Thrift.Utils.pas
Expand Up @@ -21,8 +21,16 @@

interface

{$IF CompilerVersion >= 23.0}
{$LEGACYIFEND ON}
{$IFEND}

uses
{$IF CompilerVersion < 23.0}
Classes, Windows, SysUtils, Character, SyncObjs;
{$ELSE}
System.Classes, Winapi.Windows, System.SysUtils, System.Character, System.SyncObjs;
{$IFEND}

type
IOverlappedHelper = interface
Expand Down Expand Up @@ -199,7 +207,11 @@ class function CharUtils.IsHighSurrogate( const c : Char) : Boolean;
{$IF RTLVersion >= 28.0} // XE7+
result := c.IsHighSurrogate();
{$ELSE}
result := Character.IsHighSurrogate( c);
{$IF CompilerVersion < 23.0}
result := Character.IsHighSurrogate( c);
{$ELSE}
result := c.IsHighSurrogate;
{$IFEND}
{$IFEND}
end;

Expand All @@ -209,7 +221,11 @@ class function CharUtils.IsLowSurrogate( const c : Char) : Boolean;
{$IF RTLVersion >= 28.0} // XE7+
result := c.IsLowSurrogate();
{$ELSE}
result := Character.IsLowSurrogate( c);
{$IF CompilerVersion < 23.0}
result := Character.IsLowSurrogate( c);
{$ELSE}
result := c.IsLowSurrogate;
{$IFEND}
{$IFEND}
end;

Expand Down

0 comments on commit 4f5229e

Please sign in to comment.