#1 2022-08-01 06:01:02

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Using CopyObject always copies arrays without creating copies elements

Hi,

not sure, whether it is as-designed, or a bug.

I have a KDD object with published object arrays (all deriving from TSynAutoCreateFields. When creating a copy, using CopyObject from mormot.core.rtti, all properties get copied.

However, for dynarrays, it creates a copy of the array, but not the elements itself.

Internally, it flows from CopyObject -> cf.Props.CopyProperties(pointer(aTo), pointer(aFrom)) -> Value.ValueCopy(Dest + OffsetSet, Source + OffsetGet) -> fCopy(Dest, Source, fCache.Info) [aka mormot.core.rtti. _DynArrayCopy ] -> DynArrayCopy. There it calls Info^.DynArrayItemType(itemsize) to determine the array element type.

In mormot.core.rtti.delphi.inc, this is defined as

function TRttiInfo.DynArrayItemType(out aDataSize: PtrInt): PRttiInfo;
begin
  with GetTypeData(@self)^ do
  begin
    aDataSize := elSize;
    result := pointer(elType);
    if result <> nil then
      result := PPointer(result)^;
  end;
end;

elType seems to be nil always. Defined in Delphi Rtti only for managed arrays, which those seem not to be. However, using

result := pointer(elType2);

will actually return the expected array element type.

So, my question would be, is CopyObject supposed to create copies of the array elements, or just the array itself. If later, the idea of TSynAutoCreateFields breaks, however.
Using Delphi 11 ;-)

Regards,
Daniel

Offline

#2 2022-08-01 12:06:42

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: Using CopyObject always copies arrays without creating copies elements

Created a sample, explaining what I'd expect from copy object, and what I actually get...

https://pastebin.com/M4h7sWTb

Offline

#3 2022-08-11 10:41:30

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: Using CopyObject always copies arrays without creating copies elements

still wondering what copyobject does, if not copy an objects properties...

Offline

#4 2022-10-25 06:16:21

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: Using CopyObject always copies arrays without creating copies elements

no comments?

Offline

Board footer

Powered by FluxBB