Browse Source

* TVmtFieldEntry.FieldOffset needs to be SizeUInt instead of PtrUInt, so that it works correctly on the various memory models of i8086 as well
+ added test

Sven/Sarah Barth 1 year ago
parent
commit
7eea850726
2 changed files with 63 additions and 1 deletions
  1. 1 1
      rtl/objpas/typinfo.pp
  2. 62 0
      tests/test/trtti25.pp

+ 1 - 1
rtl/objpas/typinfo.pp

@@ -220,7 +220,7 @@ unit TypInfo;
         function GetNext: PVmtFieldEntry; inline;
         function GetNext: PVmtFieldEntry; inline;
         function GetTail: Pointer; inline;
         function GetTail: Pointer; inline;
       public
       public
-        FieldOffset: PtrUInt;
+        FieldOffset: SizeUInt;
         TypeIndex: Word;
         TypeIndex: Word;
         Name: ShortString;
         Name: ShortString;
         property Tail: Pointer read GetTail;
         property Tail: Pointer read GetTail;

+ 62 - 0
tests/test/trtti25.pp

@@ -0,0 +1,62 @@
+program trtti25;
+
+{$mode objfpc}{$H+}
+
+uses
+  TypInfo;
+
+type
+  {$M+}
+  TSub1 = class
+
+  end;
+
+  TSub2 = class
+
+  end;
+
+  TTest = class
+  published
+    Field1: TSub1;
+    Field2: TSub2;
+    Field3: TSub1;
+  end;
+
+var
+  vmt: PVmt;
+  vft: PVmtFieldTable;
+  vfe: PVmtFieldEntry;
+  vfct: PVmtFieldClassTab;
+begin
+  vmt := PVmt(TTest);
+  vft := PVmtFieldTable(vmt^.vFieldTable);
+  if vft^.Count <> 3 then
+    Halt(1);
+  vfct := PVmtFieldClassTab(vft^.ClassTab);
+  if not Assigned(vfct) then
+    Halt(2);
+
+  vfe := vft^.Field[0];
+  if vfe^.Name <> 'Field1' then
+    Halt(3);
+  if vfe^.TypeIndex > vfct^.Count then
+    Halt(4);
+  if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
+    Halt(5);
+
+  vfe := vft^.Field[1];
+  if vfe^.Name <> 'Field2' then
+    Halt(6);
+  if vfe^.TypeIndex > vfct^.Count then
+    Halt(7);
+  if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub2' then
+    Halt(8);
+
+  vfe := vft^.Field[2];
+  if vfe^.Name <> 'Field3' then
+    Halt(9);
+  if vfe^.TypeIndex > vfct^.Count then
+    Halt(10);
+  if vfct^.ClassRef[vfe^.TypeIndex - 1]^.ClassName <> 'TSub1' then
+    Halt(11);
+end.