From 27c626245bf850b88283b76e80101d1a00b3ef44 Mon Sep 17 00:00:00 2001 From: sergei Date: Sun, 23 Dec 2012 12:10:11 +0000 Subject: [PATCH] * Reuse RecordRTTI to finalize class instances. This is possible because RTTI for classes is the same as for records (except different value of tkKind field), and RecordRTTI ignores tkKind (assuming that required checks are done by its caller). git-svn-id: trunk@23213 - --- rtl/inc/aliases.inc | 6 +++++ rtl/inc/objpas.inc | 55 ++++----------------------------------------- rtl/inc/rtti.inc | 2 -- 3 files changed, 10 insertions(+), 53 deletions(-) diff --git a/rtl/inc/aliases.inc b/rtl/inc/aliases.inc index f061bad919..497a5bcd5b 100644 --- a/rtl/inc/aliases.inc +++ b/rtl/inc/aliases.inc @@ -29,3 +29,9 @@ Procedure int_Addref (Data,TypeInfo : Pointer); [external name 'FPC_ADDREF']; Procedure int_Initialize (Data,TypeInfo: Pointer); [external name 'FPC_INITIALIZE']; procedure int_FinalizeArray(data,typeinfo : pointer;count : longint); [external name 'FPC_FINALIZE_ARRAY']; +{$ifdef FPC_HAS_FEATURE_RTTI} +type + TRTTIProc=procedure(Data,TypeInfo:Pointer); + +procedure RecordRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc); forward; +{$endif FPC_HAS_FEATURE_RTTI} diff --git a/rtl/inc/objpas.inc b/rtl/inc/objpas.inc index 12c545001d..37b4453795 100644 --- a/rtl/inc/objpas.inc +++ b/rtl/inc/objpas.inc @@ -610,9 +610,6 @@ procedure TObject.DispatchStr(var message); - type - PSizeUInt = ^SizeUInt; - var name : shortstring; count,i : longint; @@ -662,62 +659,18 @@ procedure TObject.CleanupInstance; - Type - TRecElem = packed Record - Info : Pointer; - Offset : Longint; - end; - -{$ifdef CPU16} - TRecElemArray = packed array[1..Maxint div sizeof(TRecElem)-1] of TRecElem; -{$else CPU16} - TRecElemArray = packed array[1..Maxint] of TRecElem; -{$endif CPU16} - - PRecRec = ^TRecRec; - TRecRec = record - Size,Count : Longint; - Elements : TRecElemArray; - end; - var vmt : PVmt; - temp : pbyte; - count, - i : longint; -{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} - recelem : TRecElem; -{$endif FPC_REQUIRES_PROPER_ALIGNMENT} + temp : pointer; begin vmt := PVmt(ClassType); while vmt<>nil do begin - { This need to be included here, because Finalize() - has should support for tkClass } Temp:= vmt^.vInitTable; + { The RTTI format matches one for records, except the type is tkClass. + Since RecordRTTI does not check the type, calling it yields the desired result. } if Assigned(Temp) then - begin - inc(Temp); - I:=Temp^; - inc(temp,I+1); // skip name string; - temp:=aligntoptr(temp); -{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} - move(PRecRec(Temp)^.Count,Count,sizeof(Count)); -{$else FPC_REQUIRES_PROPER_ALIGNMENT} - Count:=PRecRec(Temp)^.Count; // get element Count -{$endif FPC_REQUIRES_PROPER_ALIGNMENT} - For I:=1 to count do -{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} - begin - move(PRecRec(Temp)^.elements[I],RecElem,sizeof(RecElem)); - With RecElem do - int_Finalize (pointer(self)+Offset,Info); - end; -{$else FPC_REQUIRES_PROPER_ALIGNMENT} - With PRecRec(Temp)^.elements[I] do - int_Finalize (pointer(self)+Offset,Info); -{$endif FPC_REQUIRES_PROPER_ALIGNMENT} - end; + RecordRTTI(Self,Temp,@int_finalize); vmt:= vmt^.vParent; end; end; diff --git a/rtl/inc/rtti.inc b/rtl/inc/rtti.inc index 91a8335297..caaf389652 100644 --- a/rtl/inc/rtti.inc +++ b/rtl/inc/rtti.inc @@ -17,8 +17,6 @@ { the tk* constants are now declared in system.inc } type - TRTTIProc=procedure(Data,TypeInfo:Pointer); - PRecordElement=^TRecordElement; TRecordElement=packed record TypeInfo: Pointer;