From 0cff9fe83ccc3cd90a401b0cc27a34ed59f9b11b Mon Sep 17 00:00:00 2001 From: maciej-izak Date: Sun, 19 Feb 2017 12:47:31 +0000 Subject: [PATCH] * Call management operator (Initialize) for records when SetLength for dynamic arrays is used. git-svn-id: trunk@35450 - --- rtl/inc/aliases.inc | 1 + rtl/inc/dynarr.inc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/rtl/inc/aliases.inc b/rtl/inc/aliases.inc index 04ba0cd3d4..12b003063c 100644 --- a/rtl/inc/aliases.inc +++ b/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)} diff --git a/rtl/inc/dynarr.inc b/rtl/inc/dynarr.inc index bd64acc82e..30c790ef69 100644 --- a/rtl/inc/dynarr.inc +++ b/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;