Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What pointer-related things don't work in Delphi XE8's mobile compilers?

Embarcadero's docwiki page LLVM-based Delphi Compilers lists several language changes in Delphi XE8. One of the bullets says:

Use of pointers is not supported by LLVM-based Delphi compilers.

What exactly does this mean in practice? Which pointer-related things that used to work in Delphi XE7, no longer work in Delphi XE8? I can't seem to find in-depth explanation on this on Embarcadero's web site. The page Migrating Delphi Code to Mobile from Desktop that's said to contain more information, does not mention the word "Pointer", for example.

like image 246
Side S. Fresh Avatar asked Jun 29 '15 11:06

Side S. Fresh


1 Answers

Use of pointers is not supported by LLVM-based Delphi compilers.

That has to be an error in the documentation. Just take a look at the RTL. It is thick with the use of pointers.

For instance, how about CompareMem. It is defined like this:

function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;

And the implementation runs like this:

function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
{$IF defined(POSIX)}
begin
  if Length <= 0 then
    Result := True
  else
    Result := memcmp(P1^, P2^, Length) = 0;
end;
{$ELSEIF defined(PUREPASCAL)}
....
{$ENDIF !PUREPASCAL}

The POSIX code is used by the mobile targets.

Or how about TObject which looks like this:

type
  TObject = class
  public
    constructor Create;
    procedure Free;
    procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}
    class function InitInstance(Instance: Pointer): TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF};
    procedure CleanupInstance;
    function ClassType: TClass; inline;
    class function ClassName: string;
    class function ClassNameIs(const Name: string): Boolean;
    class function ClassParent: TClass;
    class function ClassInfo: Pointer; inline;
    class function InstanceSize: Integer; inline;
    class function InheritsFrom(AClass: TClass): Boolean;
    class function MethodAddress(const Name: _ShortStr): Pointer; overload;
    class function MethodAddress(const Name: string): Pointer; overload;
    class function MethodName(Address: Pointer): string;
    class function QualifiedClassName: string;
    function FieldAddress(const Name: _ShortStr): Pointer; overload;
    function FieldAddress(const Name: string): Pointer; overload;
    function GetInterface(const IID: TGUID; out Obj): Boolean;
    class function GetInterfaceEntry(const IID: TGUID): PInterfaceEntry;
    class function GetInterfaceTable: PInterfaceTable;
    class function UnitName: string;
    class function UnitScope: string;
{$IFDEF AUTOREFCOUNT}
    function __ObjAddRef: Integer; virtual;
    function __ObjRelease: Integer; virtual;
{$ENDIF}
    function Equals(Obj: TObject): Boolean; virtual;
    function GetHashCode: Integer; virtual;
    function ToString: string; virtual;
    function SafeCallException(ExceptObject: TObject;
      ExceptAddr: Pointer): HResult; virtual;
    procedure AfterConstruction; virtual;
    procedure BeforeDestruction; virtual;
    procedure Dispatch(var Message); virtual;
    procedure DefaultHandler(var Message); virtual;
    class function NewInstance: TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF}; virtual;
    procedure FreeInstance; virtual;
{$IFDEF AUTOREFCOUNT}
  protected
{$ENDIF}
    destructor Destroy; virtual;

{$IFDEF CPP_ABI_SUPPORT}
    procedure CPP_ABI_1; virtual;
    procedure CPP_ABI_2; virtual;
    procedure CPP_ABI_3; virtual;
{$ENDIF !CPP_ABI_SUPPORT}

  protected
    function GetDisposed: Boolean; inline;
    procedure CheckDisposed; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}

{$IFDEF AUTOREFCOUNT}
  private const
    objDestroyingFlag = Integer($80000000);
    objDisposedFlag = Integer($40000000);
  protected
    [Volatile] FRefCount: Integer;
    class procedure __MarkDestroying(const Obj); static; inline;
    class function __SetDisposed(const Obj): Boolean; static; inline;
  public
    property RefCount: Integer read FRefCount;
{$ENDIF}
    property Disposed: Boolean read GetDisposed;
  end;

It's pretty clear that pointers are used here on mobile platforms.

Have a read of the Embarcadero whitepaper on the subject: The Delphi Language for Mobile Development. Again it covers the use of pointers on multiple occasions and it is clear that they are supported. Now, it's also true that the use of pointers is discouraged and if pointers can readily be avoided then your are encouraged to do so. But that's quite different from stating that pointers are not supported by the compilers.

It seems at the very least to be mildly ironic that Embarcadero are spreading FUD of their own products.

like image 172
David Heffernan Avatar answered Nov 08 '22 03:11

David Heffernan