Bläddra i källkod

* don't write rtti for static fields so we don't try to initialise/finalise
them (mantis #17546)
* fixed the various field rtti methods so that they only operate on fields
and skip the rest (at the end they always typecast the sym to a
tfieldvarsym, so this could result in wrong memory accesses)

git-svn-id: trunk@16086 -

Jonas Maebe 15 år sedan
förälder
incheckning
13399280dc
3 ändrade filer med 38 tillägg och 6 borttagningar
  1. 1 0
      .gitattributes
  2. 9 6
      compiler/ncgrtti.pas
  3. 28 0
      tests/webtbs/tw17546.pp

+ 1 - 0
.gitattributes

@@ -10689,6 +10689,7 @@ tests/webtbs/tw17402a.pp svneol=native#text/pascal
 tests/webtbs/tw17413.pp svneol=native#text/plain
 tests/webtbs/tw17430.pp svneol=native#text/plain
 tests/webtbs/tw1744.pp svneol=native#text/plain
+tests/webtbs/tw17546.pp svneol=native#text/plain
 tests/webtbs/tw1754c.pp svneol=native#text/plain
 tests/webtbs/tw1755.pp svneol=native#text/plain
 tests/webtbs/tw1758.pp svneol=native#text/plain

+ 9 - 6
compiler/ncgrtti.pas

@@ -121,9 +121,10 @@ implementation
         for i:=0 to st.SymList.Count-1 do
           begin
             sym:=tsym(st.SymList[i]);
-            if (rt=fullrtti) or
+            if (tsym(sym).typ=fieldvarsym) and
+               not(sp_static in tsym(sym).symoptions) and
                (
-                (tsym(sym).typ=fieldvarsym) and
+                (rt=fullrtti) or
                 tfieldvarsym(sym).vardef.needs_inittable
                ) then
               inc(result);
@@ -139,9 +140,10 @@ implementation
         for i:=0 to st.SymList.Count-1 do
           begin
             sym:=tsym(st.SymList[i]);
-            if (rt=fullrtti) or
+            if (tsym(sym).typ=fieldvarsym) and
+               not(sp_static in tsym(sym).symoptions) and
                (
-                (tsym(sym).typ=fieldvarsym) and
+                (rt=fullrtti) or
                 tfieldvarsym(sym).vardef.needs_inittable
                ) then
               begin
@@ -160,9 +162,10 @@ implementation
         for i:=0 to st.SymList.Count-1 do
           begin
             sym:=tsym(st.SymList[i]);
-            if (rt=fullrtti) or
+            if (tsym(sym).typ=fieldvarsym) and
+               not(sp_static in tsym(sym).symoptions) and
                (
-                (tsym(sym).typ=fieldvarsym) and
+                (rt=fullrtti) or
                 tfieldvarsym(sym).vardef.needs_inittable
                ) then
               write_rtti(tfieldvarsym(sym).vardef,rt);

+ 28 - 0
tests/webtbs/tw17546.pp

@@ -0,0 +1,28 @@
+{ %opt=-gh }
+
+{$MODE OBJFPC}
+
+program test02;
+
+{$STATIC ON}
+
+type
+
+  TDummyClass = class
+    IdName: AnsiString; static;
+  end;
+
+var
+
+  o: TDummyClass;
+
+begin
+  HaltOnNotReleased := true;
+  TDummyClass.IdName := 'Test';
+  TDummyClass.IdName := TDummyClass.IdName + 'a';
+  o := TDummyClass.Create;
+  WriteLn('Here we go');
+  o.Free;
+  WriteLn('We did it!');
+end.
+