Browse Source

Copy operator (if declared) is executed instead of default fpc_Copy code (any other behavior has no sense).

rtti.inc:
  * modified fpc_Copy for mentioned behavior

* Test toperator96.pp modified

git-svn-id: branches/maciej/smart_pointers@33486 -
maciej-izak 9 years ago
parent
commit
e4aad22223
2 changed files with 29 additions and 25 deletions
  1. 25 22
      rtl/inc/rtti.inc
  2. 4 3
      tests/test/toperator96.pp

+ 25 - 22
rtl/inc/rtti.inc

@@ -395,31 +395,34 @@ begin
       begin
         Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
 {$if FPC_FULLVERSION>30100}
-        Result:=Size;
-        Inc(PRecordInfoInit(Temp));
+        if Assigned(recordop) and Assigned(recordop^.Copy) then
+          recordop^.Copy(Src,Dest)
+        else
+          begin
+            Result:=Size;
+            Inc(PRecordInfoInit(Temp));
 {$else FPC_FULLVERSION>30100}
-        Result:=PRecordInfoFull(Temp)^.Size;
-        Count:=PRecordInfoFull(Temp)^.Count;
-        Inc(PRecordInfoFull(Temp));
+            Result:=PRecordInfoFull(Temp)^.Size;
+            Count:=PRecordInfoFull(Temp)^.Count;
+            Inc(PRecordInfoFull(Temp));
 {$endif FPC_FULLVERSION>30100}
-        expectedoffset:=0;
-        { Process elements with rtti }
-        for i:=1 to Count Do
-          begin
-            Info:=PRecordElement(Temp)^.TypeInfo;
-            Offset:=PRecordElement(Temp)^.Offset;
-            Inc(PRecordElement(Temp));
-            if Offset>expectedoffset then
-              move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
-            copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
-            expectedoffset:=Offset+copiedsize;
-          end;
-        { elements remaining? }
-        if result>expectedoffset then
-          move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
+            expectedoffset:=0;
+            { Process elements with rtti }
+            for i:=1 to Count Do
+              begin
+                Info:=PRecordElement(Temp)^.TypeInfo;
+                Offset:=PRecordElement(Temp)^.Offset;
+                Inc(PRecordElement(Temp));
+                if Offset>expectedoffset then
+                  move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
+                copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
+                expectedoffset:=Offset+copiedsize;
+              end;
+            { elements remaining? }
+            if result>expectedoffset then
+              move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
 {$if FPC_FULLVERSION>30100}
-        if Assigned(recordop) and Assigned(recordop^.Copy) then
-          recordop^.Copy(Src,Dest);
+          end;
 {$endif FPC_FULLVERSION>30100}
       end;
 {$ifdef FPC_HAS_FEATURE_DYNARRAYS}

+ 4 - 3
tests/test/toperator96.pp

@@ -27,12 +27,12 @@ begin
   WriteLn('    AValue.Test = ', AValue.Test);
   if AValue.Test <> ATest then
     Halt(2);
-  WriteLn('    AValue.CopyState = ', Ord(AValue.CopyState));
-  if AValue.CopyState <> ACopyState then
-    Halt(3);
   WriteLn('    AValue.Ref = ', AValue.Ref);
   if AValue.Ref <> ARef then
     Halt(4);
+  WriteLn('    AValue.CopyState = ', Ord(AValue.CopyState));
+  if AValue.CopyState <> ACopyState then
+    Halt(3);
 end;
 
 class operator TFoo.Initialize(var aFoo: TFoo);
@@ -69,6 +69,7 @@ begin
   LSrc.CopyState := csSource;
   aDst.CopyState := csDest;
   aDst.Test := aSrc.Test + 1;
+  aDst.F := aSrc.F;
 end;
 
 procedure TestValue(Value: TFoo);