Browse Source

* Call management operator (Initialize) for records when SetLength for dynamic arrays is used.

git-svn-id: trunk@35450 -
maciej-izak 8 years ago
parent
commit
0cff9fe83c
2 changed files with 12 additions and 0 deletions
  1. 1 0
      rtl/inc/aliases.inc
  2. 11 0
      rtl/inc/dynarr.inc

+ 1 - 0
rtl/inc/aliases.inc

@@ -27,6 +27,7 @@
 Procedure int_Finalize (Data,TypeInfo: Pointer); [external name 'FPC_FINALIZE'];
 Procedure int_Addref (Data,TypeInfo : Pointer); [external name 'FPC_ADDREF'];
 Procedure int_Initialize (Data,TypeInfo: Pointer); [external name 'FPC_INITIALIZE'];
+procedure int_InitializeArray(data,typeinfo : pointer;count : SizeInt); [external name 'FPC_INITIALIZE_ARRAY'];
 procedure int_FinalizeArray(data,typeinfo : pointer;count : SizeInt); [external name 'FPC_FINALIZE_ARRAY'];
 
 {$if defined(FPC_HAS_FEATURE_RTTI) and not defined(cpujvm)}

+ 11 - 0
rtl/inc/dynarr.inc

@@ -193,6 +193,11 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
             exit;
           getmem(newp,size);
           fillchar(newp^,size,0);
+{$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
+          { call int_InitializeArray for management operators }
+          if assigned(eletypemngd) and (PByte(eletype)^ in [tkRecord, tkObject]) then
+            int_InitializeArray(pointer(newp)+sizeof(tdynarray), eletype, dims[0]);
+{$endif FPC_HAS_MANAGEMENT_OPERATORS}
           updatep := true;
        end
      else
@@ -265,6 +270,12 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
                          reallocmem(realp,size);
                          fillchar((pointer(realp)+sizeof(tdynarray)+elesize*(realp^.high+1))^,
                            (dims[0]-realp^.high-1)*elesize,0);
+{$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
+                         { call int_InitializeArray for management operators }
+                         if assigned(eletypemngd) and (PByte(eletype)^ in [tkRecord, tkObject]) then
+                           int_InitializeArray(pointer(realp)+sizeof(tdynarray)+elesize*(realp^.high+1),
+                             eletype, dims[0]-realp^.high-1);
+{$endif FPC_HAS_MANAGEMENT_OPERATORS}
                       end;
                     newp := realp;
                     updatep := true;