[fpc-devel] TypeInfo RTTI / possible inconsistency
Martin Frb
lazarus at mfriebe.de
Tue May 18 15:24:44 CEST 2021
I was looking at TypeInfo (based on 3.2.2rc)
line 632 unit TypInfo
> tkMethod:
> (MethodKind : TMethodKind;
> ParamCount : Byte;
> ParamList : array[0..1023] of Char
> {in reality ParamList is a array[1..ParamCount] of:
> record
> Flags : TParamFlags;
> ParamName : ShortString;
> TypeName : ShortString;
> end;
> followed by
> ResultType : ShortString // for mkFunction,
> mkClassFunction only
> ResultTypeRef : PPTypeInfo; // for mkFunction,
> mkClassFunction only
> CC : TCallConv;
> ParamTypeRefs : array[1..ParamCount] of PPTypeInfo;}
> );
To find out about alignment (for any target which needs alignment), I
looked through other code:
fpc_3.2.2\source\tests\webtbs\tw12038.pp
line 194 procedure DisplayDetails(Informations : TPropInfo; const
expectedresult: ansistring);
appears to access the data (except for the ParamTypeRefs array)
The testcase does not seem to make any adjustments for alignment.
fpc_3.2.2\source\packages\rtl-objpas\src\inc\rtti.pp
line 3341 TRttiMethodType.GetParameters
also appears to access the same typeinfo.
It makes alignments in 3 different places
ptr := AlignTParamFlags(ptr); // foreach Flags :
TParamFlags; in the ParamList
ptr := AlignToPtr(PByte(ptr) + ptr^ + SizeOf(Byte)); // ResultTypeRef
paramtypes := PPPTypeInfo(AlignTypeData(ptr)); // ParamTypeRefs
Which is correct?
Or do they access different structures?
----------------------
A few other notes:
FPC_REQUIRES_PROPER_ALIGNMENT
does not seem to be listed on
https://www.freepascal.org/docs-html/prog/progap7.html
TypInfo line 1461
in Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
TP:=aligntoptr(PPropInfo(aligntoptr((Pointer(@TD^.UnitName)+Length(TD^.UnitName)+1))));
Why call aligntoptr twice?
The TypeCast in between does not change the alignment. (all the math is
done within the innermost call)
More information about the fpc-devel
mailing list