فهرست منبع

* synchronized with trunk

git-svn-id: branches/wasm@48440 -
nickysn 4 سال پیش
والد
کامیت
605246ac3c
3فایلهای تغییر یافته به همراه48 افزوده شده و 6 حذف شده
  1. 42 3
      packages/fcl-stl/src/gdeque.pp
  2. 2 2
      rtl/objpas/sysconst.pp
  3. 4 1
      utils/fpdoc/dw_chm.pp

+ 42 - 3
packages/fcl-stl/src/gdeque.pp

@@ -14,6 +14,11 @@
 
 unit gdeque;
 
+{
+  Implements a generic double ended queue.
+  (See: https://en.wikipedia.org/wiki/Double-ended_queue)
+}
+
 interface
 
 type
@@ -35,9 +40,13 @@ type
     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;
+    property Data: TArr read FData;
   public
     function Size():SizeUInt;inline;
     constructor Create();
+    destructor Destroy(); override;
     Procedure  Clear;
     procedure PushBack(value:T);inline;
     procedure PushFront(value:T);inline;
@@ -63,8 +72,15 @@ begin
   FStart:=0;
 end;
 
+destructor TDeque.Destroy();
+begin
+  Clear;
+  inherited Destroy;
+end;
+
 procedure TDeque.Clear;
 begin
+ ClearData;
  FDataSize:=0;
  FStart:=0;
 end;
@@ -91,6 +107,7 @@ procedure TDeque.PopFront();inline;
 begin
   if(FDataSize>0) then
   begin
+    ClearSingleDataEntry(FStart);
     inc(FStart);
     dec(FDataSize);
     if(FStart=FCapacity) then
@@ -101,7 +118,10 @@ end;
 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 +151,7 @@ end;
 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 +168,6 @@ begin
 end;
 
 
-
 procedure TDeque.MoveSimpleData(StartIndex: SizeUInt; Offset: SizeInt;  NrElems: SizeUInt);
 begin
   Move(FData[StartIndex], FData[StartIndex+Offset], NrElems*SizeOf(T));
@@ -182,6 +200,27 @@ begin
     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

+ 2 - 2
rtl/objpas/sysconst.pp

@@ -90,13 +90,13 @@ const
   SNoDynLibsSupport      = 'Dynamic libraries not supported. Recompile program with dynamic library driver.';
   SMissingWStringManager = 'Widestring manager not available. Recompile program with appropriate manager.';
   SSigQuit               = 'SIGQUIT signal received.';
-  SObjectCheckError      = 'Object reference is Nil';
+  SObjectCheckError      = 'Object reference is Nil or VMT is damaged';
   SOSError               = 'System error, (OS Code %d):'+LineEnding+'%s';
   SOutOfMemory           = 'Out of memory';
   SOverflow              = 'Floating point overflow';
   SPrivilege             = 'Privileged instruction';
   SRangeError            = 'Range check error';
-  SStackOverflow         = 'Stack overflow';
+  SStackOverflow         = 'Stack overflow or stack misalignment';
   SSafecallException     = 'Exception in safecall method';
   SiconvError            = 'iconv error';
   SThreadError           = 'Thread error';

+ 4 - 1
utils/fpdoc/dw_chm.pp

@@ -72,6 +72,7 @@ var
   n,s: String;
   i: Integer;
   excl: Boolean; //search
+  MElement: TPasElement;
 begin
   Result:='';
   excl := False;
@@ -120,7 +121,9 @@ begin
       excl := (ASubindex > 0);
     end;
     // cut off Package Name
-    AElement:= AElement.GetModule;
+    MElement:= AElement.GetModule;
+    if Assigned(MElement) then
+      AElement:= MElement;
     Result := Copy(Result, Length(AElement.Parent.Name) + 2, MaxInt);
     // to skip dots in unit name
     i := Length(AElement.Name);