2019-03-06 12:21:46 +01:00
|
|
|
/// wrapper around FPC typinfo.pp unit for SynCommons.pas and mORMot.pas
|
2020-04-12 16:45:05 +02:00
|
|
|
// - this unit is a part of the freeware Synopse mORMot framework,
|
|
|
|
// licensed under a MPL/GPL/LGPL tri-license; version 1.18
|
2019-03-06 12:21:46 +01:00
|
|
|
unit SynFPCTypInfo;
|
|
|
|
|
|
|
|
{
|
|
|
|
This file is part of Synopse mORMot framework.
|
|
|
|
|
2021-04-23 10:11:05 +02:00
|
|
|
Synopse mORMot framework. Copyright (C) 2021 Arnaud Bouchez
|
2019-03-06 12:21:46 +01:00
|
|
|
Synopse Informatique - https://synopse.info
|
|
|
|
|
|
|
|
*** BEGIN LICENSE BLOCK *****
|
|
|
|
Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.mozilla.org/MPL
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
for the specific language governing rights and limitations under the License.
|
|
|
|
|
|
|
|
The Original Code is Synopse mORMot framework.
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is Alfred Glaenzer.
|
|
|
|
|
2021-04-23 10:11:05 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2021
|
2019-03-06 12:21:46 +01:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
- Arnaud Bouchez
|
|
|
|
|
|
|
|
|
|
|
|
Alternatively, the contents of this file may be used under the terms of
|
|
|
|
either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
of those above. if you wish to allow use of your version of this file only
|
|
|
|
under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
use your version of this file under the terms of the MPL, indicate your
|
|
|
|
decision by deleting the provisions above and replace them with the notice
|
|
|
|
and other provisions required by the GPL or the LGPL. if you do not delete
|
|
|
|
the provisions above, a recipient may use your version of this file under
|
|
|
|
the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
Unit created to avoid polluting the SynCommons.pas/mORMot.pas namespace
|
|
|
|
with overloaded typinfo.pp types.
|
2019-03-06 12:21:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2021-04-23 10:11:05 +02:00
|
|
|
{$ifndef FPC}
|
|
|
|
'this unit is for FPC only - do not include it in any Delphi project!'
|
|
|
|
{$endif FPC}
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
{$I Synopse.inc} // define HASINLINE CPU32 CPU64 OWNNORMTOUPPER
|
2019-03-06 12:21:46 +01:00
|
|
|
|
|
|
|
uses
|
|
|
|
SysUtils,
|
|
|
|
TypInfo;
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
{$ifdef FPC_PROVIDE_ATTR_TABLE}
|
|
|
|
type
|
|
|
|
// if you have a compilation error here, your FPC trunk is too old
|
|
|
|
// - TTypeData.AttributeTable was introduced in SVN 42356-42411 (2019/07)
|
|
|
|
// -> undefine FPC_PROVIDE_ATTR_TABLE in Synopse.inc and recompile
|
|
|
|
PFPCAttributeTable = TypInfo.PAttributeTable;
|
|
|
|
{$endif FPC_PROVIDE_ATTR_TABLE}
|
|
|
|
|
|
|
|
{$ifdef HASALIGNTYPEDATA}
|
|
|
|
function AlignTypeData(p: pointer): pointer; inline;
|
|
|
|
function AlignTypeDataClean(p: pointer): pointer; inline;
|
|
|
|
{$else}
|
|
|
|
type
|
|
|
|
AlignTypeData = pointer;
|
|
|
|
AlignTypeDataClean = pointer;
|
|
|
|
{$endif HASALIGNTYPEDATA}
|
|
|
|
|
2019-03-06 12:21:46 +01:00
|
|
|
|
|
|
|
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
|
2020-04-12 16:45:05 +02:00
|
|
|
function AlignToPtr(p: pointer): pointer; inline;
|
|
|
|
function AlignPTypeInfo(p: pointer): pointer; inline;
|
2019-03-06 12:21:46 +01:00
|
|
|
{$else FPC_REQUIRES_PROPER_ALIGNMENT}
|
|
|
|
type
|
|
|
|
AlignToPtr = pointer;
|
2020-04-12 16:45:05 +02:00
|
|
|
AlignPTypeInfo = pointer;
|
2019-03-06 12:21:46 +01:00
|
|
|
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
|
|
|
|
|
2019-11-17 12:09:05 +01:00
|
|
|
type
|
2020-04-12 16:45:05 +02:00
|
|
|
/// some type definition to avoid inclusion of TypInfo in SynCommons/mORMot.pas
|
|
|
|
PFPCInterfaceData = TypInfo.PInterfaceData;
|
|
|
|
PFPCVmtMethodParam = TypInfo.PVmtMethodParam;
|
|
|
|
PFPCIntfMethodTable = TypInfo.PIntfMethodTable;
|
|
|
|
PFPCIntfMethodEntry = TypInfo.PIntfMethodEntry;
|
|
|
|
{$ifdef FPC_NEWRTTI}
|
|
|
|
PFPCRecInitData = TypInfo.PRecInitData;
|
2019-11-17 12:09:05 +01:00
|
|
|
|
|
|
|
{$endif FPC_NEWRTTI}
|
2019-03-06 12:21:46 +01:00
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
procedure FPCDynArrayClear(var a: Pointer; TypeInfo: Pointer);
|
|
|
|
procedure FPCFinalizeArray(p: Pointer; TypeInfo: Pointer; elemCount: PtrUInt);
|
2019-03-06 12:21:46 +01:00
|
|
|
procedure FPCFinalize(Data: Pointer; TypeInfo: Pointer);
|
|
|
|
procedure FPCRecordCopy(const Source; var Dest; TypeInfo: pointer);
|
|
|
|
procedure FPCRecordAddRef(var Data; TypeInfo : pointer);
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
procedure FPCDynArrayClear(var a: Pointer; TypeInfo: Pointer);
|
|
|
|
external name 'FPC_DYNARRAY_CLEAR';
|
|
|
|
procedure FPCFinalizeArray(p: Pointer; TypeInfo: Pointer; elemCount: PtrUInt);
|
|
|
|
external name 'FPC_FINALIZE_ARRAY';
|
2019-03-06 12:21:46 +01:00
|
|
|
procedure FPCFinalize(Data: Pointer; TypeInfo: Pointer);
|
2020-04-12 16:45:05 +02:00
|
|
|
external name 'FPC_FINALIZE';
|
2019-03-06 12:21:46 +01:00
|
|
|
procedure FPCRecordCopy(const Source; var Dest; TypeInfo: pointer);
|
2020-04-12 16:45:05 +02:00
|
|
|
external name 'FPC_COPY';
|
2019-03-06 12:21:46 +01:00
|
|
|
procedure FPCRecordAddRef(var Data; TypeInfo : pointer);
|
2020-04-12 16:45:05 +02:00
|
|
|
external name 'FPC_ADDREF';
|
2019-03-06 12:21:46 +01:00
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} // copied from latest typinfo.pp
|
|
|
|
function AlignToPtr(p: pointer): pointer;
|
2019-03-06 12:21:46 +01:00
|
|
|
begin
|
|
|
|
result := align(p,sizeof(p));
|
|
|
|
end;
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
function AlignTypeData(p: pointer): pointer;
|
|
|
|
{$packrecords c}
|
|
|
|
type
|
|
|
|
TAlignCheck = record // match RTTI TTypeInfo definition
|
|
|
|
b : byte; // = TTypeKind
|
|
|
|
q : qword; // = this is where the PTypeData begins
|
|
|
|
end;
|
|
|
|
{$packrecords default}
|
2019-11-17 12:09:05 +01:00
|
|
|
begin
|
2020-04-12 16:45:05 +02:00
|
|
|
{$ifdef VER3_0}
|
|
|
|
result := Pointer(align(p,SizeOf(Pointer)));
|
|
|
|
{$else VER3_0}
|
|
|
|
result := Pointer(align(p,PtrInt(@TAlignCheck(nil^).q)));
|
|
|
|
{$endif VER3_0}
|
|
|
|
{$ifdef FPC_PROVIDE_ATTR_TABLE}
|
|
|
|
inc(PByte(result),SizeOf(PFPCAttributeTable)); // ignore attributes table
|
|
|
|
result := Pointer(align(result,PtrInt(@TAlignCheck(nil^).q)));
|
|
|
|
{$endif FPC_PROVIDE_ATTR_TABLE}
|
2019-11-17 12:09:05 +01:00
|
|
|
end;
|
2020-04-12 16:45:05 +02:00
|
|
|
{$else}
|
|
|
|
{$ifdef FPC_PROVIDE_ATTR_TABLE}
|
|
|
|
function AlignTypeData(p: pointer): pointer;
|
2019-03-06 12:21:46 +01:00
|
|
|
begin
|
2020-04-12 16:45:05 +02:00
|
|
|
result := p;
|
|
|
|
inc(PByte(result),SizeOf(PFPCAttributeTable)); // ignore attributes table
|
2019-03-06 12:21:46 +01:00
|
|
|
end;
|
2020-04-12 16:45:05 +02:00
|
|
|
{$endif FPC_PROVIDE_ATTR_TABLE}
|
|
|
|
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
|
2019-03-06 12:21:46 +01:00
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} // copied from latest typinfo.pp
|
2019-03-06 12:21:46 +01:00
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
function AlignTypeDataClean(p: pointer): pointer;
|
|
|
|
{$packrecords c}
|
|
|
|
type
|
|
|
|
TAlignCheck = record // match RTTI TTypeInfo definition
|
|
|
|
b : byte; // = TTypeKind
|
|
|
|
q : qword; // = this is where the PTypeData begins
|
|
|
|
end;
|
|
|
|
{$packrecords default}
|
2019-03-06 12:21:46 +01:00
|
|
|
begin
|
2020-04-12 16:45:05 +02:00
|
|
|
{$ifdef VER3_0}
|
|
|
|
result := Pointer(align(p,SizeOf(Pointer)));
|
|
|
|
{$else VER3_0}
|
|
|
|
result := Pointer(align(p,PtrInt(@TAlignCheck(nil^).q)));
|
|
|
|
{$endif VER3_0}
|
2019-03-06 12:21:46 +01:00
|
|
|
end;
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
function AlignPTypeInfo(p: pointer): pointer; inline;
|
|
|
|
{$packrecords c}
|
|
|
|
type
|
|
|
|
TAlignCheck = record
|
|
|
|
b : byte;
|
|
|
|
p : pointer;
|
|
|
|
end;
|
|
|
|
{$packrecords default}
|
2019-03-06 12:21:46 +01:00
|
|
|
begin
|
2020-04-12 16:45:05 +02:00
|
|
|
Result := Pointer(align(p,PtrInt(@TAlignCheck(nil^).p)))
|
2019-03-06 12:21:46 +01:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
2020-04-12 16:45:05 +02:00
|
|
|
{$else}
|
|
|
|
{$ifdef HASALIGNTYPEDATA}
|
|
|
|
function AlignTypeDataClean(p: pointer): pointer;
|
2019-03-06 12:21:46 +01:00
|
|
|
begin
|
2020-04-12 16:45:05 +02:00
|
|
|
result := p;
|
2019-03-06 12:21:46 +01:00
|
|
|
end;
|
2020-04-12 16:45:05 +02:00
|
|
|
{$endif HASALIGNTYPEDATA}
|
|
|
|
|
|
|
|
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
|
2019-03-06 12:21:46 +01:00
|
|
|
|
|
|
|
end.
|