Recent

Author Topic: What is RecordMopInitTable used for  (Read 1530 times)

Warfley

  • Hero Member
  • *****
  • Posts: 1503
What is RecordMopInitTable used for
« on: September 04, 2023, 11:56:57 am »
I'm currently playing a bit around in the RTTI initialization and finalization code of the FPC, and I found the following:
Code: Pascal  [Select][+][-]
  1.            { for management operators like initialize call int_initialize }
  2.            vmt := PVmt(self);
  3.            if assigned(vmt) then
  4.              begin
  5.                inittable:=vmt^.vInitTable;
  6.                if assigned(inittable) then
  7.                  begin
  8.                    mopinittable:=RTTIRecordMopInitTable(inittable);
  9.                    if assigned(mopinittable) then
  10.                      begin
  11.                        {$push}
  12.                        { ensure that no range check errors pop up with the [0..0] array }
  13.                        {$R-}
  14.                        for i:=0 to mopinittable^.Count-1 do
  15.                          TRTTIRecVarOp(mopinittable^.Entries[i].ManagmentOperator)(PByte(Instance)+mopinittable^.Entries[i].FieldOffset);
  16.                        {$pop}
  17.                      end;
  18.                  end;
  19.              end;
  20.  
Which, first, the very first comment seems to be outdated as it does not call int_initialize/fpc_initialize anymore.
Second, when looking at how records are initialized, it uses a different approach, by simply iterating over the RTTI fields and calling fpc_initialize on them:
Code: Pascal  [Select][+][-]
  1.       { if possible try to use more optimal initrtti }
  2.       with RTTIRecordOp(typeinfo, typeinfo)^ do
  3.       begin
  4.         recordrtti(data,typeinfo,@int_initialize);
  5.         if Assigned(recordop) and Assigned(recordop^.Initialize) then
  6.           recordop^.Initialize(data);
  7.       end;
  8.  
Also CleanupInstance is using the "old" rtti way:
Code: Pascal  [Select][+][-]
  1.                { The RTTI format matches one for records, except the type is tkClass.
  2.                  Since RecordRTTI does not check the type, calling it yields the desired result. }
  3.                if Assigned(Temp) then
  4.                  RecordRTTI(Self,Temp,@int_finalize);
  5.  

As this is the only point where RTTIRecordMopInitTable is being used within the whole codebase (at least if the gitlab search is correct), I was wondering what this is about? Is there something special for classes, or is this maybe just a new implementation which is simply not fully finished and therefore just implemented for class initialization?

 

TinyPortal © 2005-2018