Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-05

TypeInfo RTTI / possible inconsistency

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

I was looking at TypeInfo (based on 3.2.2rc)

line 632  unit TypInfo

Show quoted text 18 lines
            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)

Reply by email

Martin Frb
to Martin Frb
Martin Frb wrote 16 lines
I was looking at TypeInfo (based on 3.2.2rc) line 632  unit TypInfo >             tkMethod: > .... >               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:

And just to confirm, if anyone knows....

Those are indeed PPTypeInfo ? (even in 3.0?)

Since a lot of other TypeInfos are:
{$ifdef ver3_0}
{$define TypeInfoPtr := PTypeInfo}
{$else}
{$define TypeInfoPtr := PPTypeInfo}
{$endif}

Rtti.pas in 3.0.0 seems to tread them as PPTypeInfo. So that would indicate they indeed are PPTypeInfo.

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 31 lines
On 18/05/2021 15:24, Martin Frb via fpc-devel wrote: > I was looking at TypeInfo (based on 3.2.2rc) > > line 632  unit TypInfo >>             tkMethod: >> .... >>               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: And just to confirm, if anyone knows.... Those are indeed PPTypeInfo ? (even in 3.0?) Since a lot of other TypeInfos are: {$ifdef ver3_0} {$define TypeInfoPtr := PTypeInfo} {$else} {$define TypeInfoPtr := PPTypeInfo} {$endif} Rtti.pas in 3.0.0 seems to tread them as PPTypeInfo. So that would indicate they indeed are PPTypeInfo.

Yes. An additional level of indirection was introduced, for runtime package support, if I recall correctly. This also makes it Delphi compatible.

But Sven can confirm this, I think he introduced the change.

Michael.

Reply by email

Martin Frb
to Martin Frb: And just to confirm, if anyone knows.... Those are indeed PPTypeInfo ? (even in 3.0?)…
Martin Frb wrote 23 lines
On 18/05/2021 15:24, Martin Frb via fpc-devel wrote: > line 632  unit TypInfo >>             tkMethod: >> .... >>               followed by >>                   ResultType : ShortString     // for mkFunction, >> mkClassFunction only >>                   ResultTypeRef : PPTypeInfo;  // for mkFunction, >> mkClassFunction only >>                   CC : TCallConv; >>                   ParamTypeRefs : array[1..ParamCount] of PPTypeInfo;} >>               ); And just to confirm, if anyone knows.... Those are indeed PPTypeInfo ? (even in 3.0?) Since a lot of other TypeInfos are: {$ifdef ver3_0} {$define TypeInfoPtr := PTypeInfo} {$else} {$define TypeInfoPtr := PPTypeInfo} {$endif}

I looked at ncgrtti in the compiler.

It looks like ResultTypeRef and ParamTypeRef are TypeInfoPtr  and not PPTypeInfo

Rtti.pas in 3.0.0 seems to tread them as PPTypeInfo. So that would indicate they indeed are PPTypeInfo.

3.0 does not have rtti.pp => I was in the wrong directory

Reply by email

Sven Barth
to Martin Frb: I was looking at TypeInfo (based on 3.2.2rc) line 632  unit TypInfo To find out about…
Martin Frb wrote 30 lines
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.

It does at line 285.

Show quoted text 13 lines
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?

They are for different parts of the structure, cause they have different alignment requirements (e.g. the param names and flags are aligned to the TParamFlags (which is 2 Byte) while the ResultType is aligned to a pointer. Though right now I don't know why the last one uses AlignTypeData which would align to the QWord fields instead of Pointer ones...

A few other notes: FPC_REQUIRES_PROPER_ALIGNMENT does not seem to be listed on https://www.freepascal.org/docs-html/prog/progap7.html

There are a few from TOption.TargetOptions (in options.pas) that are not yet documented.

Show quoted text 7 lines
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)

That one is already fixed in trunk.

Regards,
Sven

Reply by email

Sven Barth
to Martin Frb: And just to confirm, if anyone knows.... Those are indeed PPTypeInfo ? (even in 3.0?)…
Martin Frb wrote 31 lines
On 18/05/2021 15:24, Martin Frb via fpc-devel wrote: > I was looking at TypeInfo (based on 3.2.2rc) > > line 632  unit TypInfo >>             tkMethod: >> .... >>               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: And just to confirm, if anyone knows.... Those are indeed PPTypeInfo ? (even in 3.0?) Since a lot of other TypeInfos are: {$ifdef ver3_0} {$define TypeInfoPtr := PTypeInfo} {$else} {$define TypeInfoPtr := PPTypeInfo} {$endif} Rtti.pas in 3.0.0 seems to tread them as PPTypeInfo. So that would indicate they indeed are PPTypeInfo.

They were only introduced in 3.0.0, thus they were introduced as PPTypeInfo right away as that is required for dynamic packages on Windows to work correctly (as Michael mentioned).

Regards,
Sven

Reply by email

Sven Barth
to Martin Frb: I looked at ncgrtti in the compiler. It looks like ResultTypeRef and ParamTypeRef are…
Martin Frb wrote 29 lines
On 18/05/2021 15:50, Martin Frb via fpc-devel wrote: > On 18/05/2021 15:24, Martin Frb via fpc-devel wrote: >> line 632  unit TypInfo >>>             tkMethod: >>> .... >>>               followed by >>>                   ResultType : ShortString     // for mkFunction, >>> mkClassFunction only >>>                   ResultTypeRef : PPTypeInfo;  // for mkFunction, >>> mkClassFunction only >>>                   CC : TCallConv; >>>                   ParamTypeRefs : array[1..ParamCount] of PPTypeInfo;} >>>               ); > > And just to confirm, if anyone knows.... > Those are indeed PPTypeInfo ? (even in 3.0?) > > Since a lot of other TypeInfos are: > {$ifdef ver3_0} > {$define TypeInfoPtr := PTypeInfo} > {$else} > {$define TypeInfoPtr := PPTypeInfo} > {$endif} > I looked at ncgrtti in the compiler. It looks like ResultTypeRef and ParamTypeRef are TypeInfoPtr  and not PPTypeInfo

Right, sorry, in 3.0 they're indeed PTypeInfo. In 3.2.0 they were changed ot indirect references.

Regards,
Sven

Reply by email

Martin Frb
to Sven Barth: It does at line 285. They are for different parts of the structure, cause they have…
Sven Barth wrote 11 lines
Am 18.05.2021 um 15:24 schrieb Martin Frb via fpc-devel: > I was looking at TypeInfo (based on 3.2.2rc) > ..... > > 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. It does at line 285.

Ok, now I looked at trunk (should have done before). In 3.2.2rc the align is not present.

Show quoted text 13 lines
> > 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? They are for different parts of the structure,

Misunderstanding. Not "which of the 3", but "testcase or unit" => Solved, the latter (in trunk: both)

Anyway thanks for the feedback.

Reply by email

Sven Barth
to Martin Frb
Martin Frb wrote 14 lines
On 19/05/2021 22:10, Sven Barth wrote: > Am 18.05.2021 um 15:24 schrieb Martin Frb via fpc-devel: >> I was looking at TypeInfo (based on 3.2.2rc) >> ..... >> >> 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. > > It does at line 285. Ok, now I looked at trunk (should have done before). In 3.2.2rc the align is not present.

That is because the alignment requirements changed in trunks with the addition of the attributes (though I'm not entirely happy with that yet).

Show quoted text 17 lines
> >> >> 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? > > They are for different parts of the structure, Misunderstanding. Not "which of the 3", but "testcase or unit" => Solved, the latter (in trunk: both)

The test should be correct in 3.2.0 as well.

Regards,
Sven

Reply by email