View Issue Details

IDProjectCategoryView StatusLast Update
0038406FPCFCLpublic2021-01-27 16:19
ReporterBart Broersma Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Platformi386OSWindows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038406: gdeque.pp: more adaptations to handle managed data.
DescriptionIn r48405 some improvements were made to handle managed data.
As indicated in the assosciated bugreport (0038306), that patch wasn't complete yet.

I have adapted some more methods to finalize data (if required) before discarding (PopXXX) or overwriting them.
I've made them all virtual so they can be overridden in e.g. a TDeque derived class that handels classes.
TagsNo tags attached.
Fixed in Revision48435
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Bart Broersma

2021-01-27 11:45

reporter  

gdeque.cleardata.diff (2,655 bytes)   
Index: packages/fcl-stl/src/gdeque.pp
===================================================================
--- packages/fcl-stl/src/gdeque.pp	(revision 48433)
+++ packages/fcl-stl/src/gdeque.pp	(working copy)
@@ -35,9 +35,12 @@
     procedure MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
     procedure MoveManagedData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
     procedure MoveData(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt);
+    procedure ClearSingleDataEntry(Index: SizeUInt); virtual;
+    procedure ClearData; virtual;
   public
     function Size():SizeUInt;inline;
     constructor Create();
+    destructor Destroy(); override;
     Procedure  Clear;
     procedure PushBack(value:T);inline;
     procedure PushFront(value:T);inline;
@@ -63,8 +66,15 @@
   FStart:=0;
 end;
 
+destructor TDeque.Destroy();
+begin
+  Clear;
+  inherited Destroy;
+end;
+
 procedure TDeque.Clear;
 begin
+ ClearData;
  FDataSize:=0;
  FStart:=0;
 end;
@@ -91,6 +101,7 @@
 begin
   if(FDataSize>0) then
   begin
+    ClearSingleDataEntry(FStart);
     inc(FStart);
     dec(FDataSize);
     if(FStart=FCapacity) then
@@ -101,7 +112,10 @@
 procedure TDeque.PopBack();inline;
 begin
   if(FDataSize>0) then
+  begin
+    ClearSingleDataEntry((FStart+FDataSize-1)mod FCapacity);
     dec(FDataSize);
+  end;
 end;
 
 procedure TDeque.PushFront(value:T);inline;
@@ -131,8 +145,7 @@
 procedure TDeque.SetValue(position:SizeUInt; value:T);inline;
 begin
   Assert(position < size, 'Deque access out of range');
-  if IsManagedType(T) then
-    Finalize(FData[(FStart+position)mod FCapacity]);
+  ClearSingleDataEntry((FStart+position)mod FCapacity);
   FData[(FStart+position)mod FCapacity]:=value;
 end;
 
@@ -149,7 +162,6 @@
 end;
 
 
-
 procedure TDeque.MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt;  NrElems: SizeUInt);
 begin
   Move(FData[StartIndex], FData[StartIndex+Offset], NrElems*SizeOf(T));
@@ -182,6 +194,27 @@
     MoveSimpleData(StartIndex, Offset, NrElems);
 end;
 
+procedure TDeque.ClearSingleDataEntry(Index: SizeUInt);
+begin
+  if IsManagedType(T) then
+  begin
+    Finalize(FData[Index]);
+    FillChar(FData[Index], SizeOf(T), 0);
+  end
+  else
+    FData[Index] := default(T);
+end;
+
+procedure TDeque.ClearData;
+var
+  i: SizeUint;
+begin
+  if IsManagedType(T) then
+    for i := Low(FData) to High(FData) do
+      Finalize(FData[i]);
+  FillChar(FData[Low(FData)], SizeUInt(Length(FData))*SizeOf(T), 0);
+end;
+
 procedure TDeque.IncreaseCapacity;
   function Min(const A,B: SizeUInt): SizeUInt; inline; //no need to drag in the entire Math unit ;-)
   begin
gdeque.cleardata.diff (2,655 bytes)   

Michael Van Canneyt

2021-01-27 12:40

administrator   ~0128614

Applied, thank you very much !

Issue History

Date Modified Username Field Change
2021-01-27 11:45 Bart Broersma New Issue
2021-01-27 11:45 Bart Broersma File Added: gdeque.cleardata.diff
2021-01-27 12:40 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-01-27 12:40 Michael Van Canneyt Status new => resolved
2021-01-27 12:40 Michael Van Canneyt Resolution open => fixed
2021-01-27 12:40 Michael Van Canneyt Fixed in Version => 3.3.1
2021-01-27 12:40 Michael Van Canneyt Fixed in Revision => 48435
2021-01-27 12:40 Michael Van Canneyt FPCTarget => 3.2.2
2021-01-27 12:40 Michael Van Canneyt Note Added: 0128614
2021-01-27 16:19 Bart Broersma Status resolved => closed