From 13399280dc154493fe71d99fd6b5c8d0e151b448 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 5 Oct 2010 14:56:48 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + compiler/ncgrtti.pas | 15 +++++++++------ tests/webtbs/tw17546.pp | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/webtbs/tw17546.pp diff --git a/.gitattributes b/.gitattributes index 5891c2a76c..7a435c2fc6 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ncgrtti.pas b/compiler/ncgrtti.pas index dcf6d896af..3b83cbf6b9 100644 --- a/compiler/ncgrtti.pas +++ b/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); diff --git a/tests/webtbs/tw17546.pp b/tests/webtbs/tw17546.pp new file mode 100644 index 0000000000..32fdb39494 --- /dev/null +++ b/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. +