Discussion:
[fpc-devel] TypeInfo RTTI / possible inconsistency
Martin Frb via fpc-devel
2021-05-18 13:24:44 UTC
Permalink
I was looking at TypeInfo (based on 3.2.2rc)

line 632  unit TypInfo
              (MethodKind : TMethodKind;
               ParamCount : Byte;
               ParamList : array[0..1023] of Char
                  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)


_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-deve
Martin Frb via fpc-devel
2021-05-18 13:50:32 UTC
Permalink
Post by Martin Frb via fpc-devel
I was looking at TypeInfo (based on 3.2.2rc)
line 632  unit TypInfo
....
              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
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.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/
Michael Van Canneyt via fpc-devel
2021-05-18 14:58:41 UTC
Permalink
Post by Martin Frb via fpc-devel
Post by Martin Frb via fpc-devel
I was looking at TypeInfo (based on 3.2.2rc)
line 632  unit TypInfo
....
              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
And just to confirm, if anyone knows....
Those are indeed PPTypeInfo ? (even in 3.0?)
{$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.
Martin Frb via fpc-devel
2021-05-18 15:33:41 UTC
Permalink
Post by Martin Frb via fpc-devel
Post by Martin Frb via fpc-devel
line 632  unit TypInfo
....
              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?)
{$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
Post by Martin Frb via fpc-devel
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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-b
Sven Barth via fpc-devel
2021-05-19 20:21:34 UTC
Permalink
Post by Martin Frb via fpc-devel
Post by Martin Frb via fpc-devel
Post by Martin Frb via fpc-devel
line 632  unit TypInfo
....
              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?)
{$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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/f
Sven Barth via fpc-devel
2021-05-19 20:13:35 UTC
Permalink
Post by Martin Frb via fpc-devel
Post by Martin Frb via fpc-devel
I was looking at TypeInfo (based on 3.2.2rc)
line 632  unit TypInfo
....
              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
And just to confirm, if anyone knows....
Those are indeed PPTypeInfo ? (even in 3.0?)
{$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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal
Sven Barth via fpc-devel
2021-05-19 20:10:26 UTC
Permalink
Post by Martin Frb via fpc-devel
I was looking at TypeInfo (based on 3.2.2rc)
line 632  unit TypInfo
              (MethodKind : TMethodKind;
               ParamCount : Byte;
               ParamList : array[0..1023] of Char
                  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
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.
Post by Martin Frb via fpc-devel
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
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...
Post by Martin Frb via fpc-devel
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.
Post by Martin Frb via fpc-devel
TypInfo line 1461
in Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listin
Martin Frb via fpc-devel
2021-05-19 20:42:17 UTC
Permalink
Post by Sven Barth via fpc-devel
Post by 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.
Post by Sven Barth via fpc-devel
Post by Martin Frb via fpc-devel
It makes alignments in 3 different places
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.

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailm
Sven Barth via fpc-devel
2021-05-19 21:31:41 UTC
Permalink
Post by Martin Frb via fpc-devel
Post by Sven Barth via fpc-devel
Post by 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).
Post by Martin Frb via fpc-devel
Post by Sven Barth via fpc-devel
Post by Martin Frb via fpc-devel
It makes alignments in 3 different places
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
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
https://lists.

Loading...