Browse Source

Proper work around implemented for TList.ToArray

1. Reduced the number of Skybuck comments significantly.
2. Removed FGL unit from UCommon.Data.pas.
3. Reverted TFPGList back to TList.
4. Renamed ReturnArrayFromList to ToArrayWorkAround.
5. ToArrayWorkAround now simply returns TList.ToArray.
Skybuck 4 years ago
parent
commit
95c9cce565

+ 2 - 2
src/gui-experimental/UFRMAccountSelect.pas

@@ -169,10 +169,10 @@ procedure TSearchThread.BCExecute;
         isValid := TAccountComp.IsAccountForSale(account.accountInfo);
         isValid := TAccountComp.IsAccountForSale(account.accountInfo);
       end;
       end;
       If IsValid and (FSearchValues.onlyForPublicSale) then begin
       If IsValid and (FSearchValues.onlyForPublicSale) then begin
-        isValid := (TAccountComp.IsAccountForSale(account.accountInfo)) And (Not TAccountComp.IsAccountForSaleOrSwapAcceptingTransactions(account, FSearchValues.SafeBox.BlocksCount, FSearchValues.SafeBox.CurrentProtocol, nil));  // Skybuck: todo check/debug if this is safe
+        isValid := (TAccountComp.IsAccountForSale(account.accountInfo)) And (Not TAccountComp.IsAccountForSaleOrSwapAcceptingTransactions(account, FSearchValues.SafeBox.BlocksCount, FSearchValues.SafeBox.CurrentProtocol, nil));  // Skybuck: todo check/debug !
       end;
       end;
       If IsValid and (FSearchValues.onlyForPrivateSaleToMe) then begin
       If IsValid and (FSearchValues.onlyForPrivateSaleToMe) then begin
-        isValid := ( TAccountComp.IsAccountForSaleOrSwapAcceptingTransactions(account,FSearchValues.SafeBox.BlocksCount, FSearchValues.SafeBox.CurrentProtocol, nil)) And // Skybuck: todo check/debug if this is safe
+        isValid := ( TAccountComp.IsAccountForSaleOrSwapAcceptingTransactions(account,FSearchValues.SafeBox.BlocksCount, FSearchValues.SafeBox.CurrentProtocol, nil)) And // Skybuck: todo check/debug !
           (Assigned(FSearchValues.inWalletKeys)) And (FSearchValues.inWalletKeys.IndexOfAccountKey(account.accountInfo.new_publicKey)>=0);
           (Assigned(FSearchValues.inWalletKeys)) And (FSearchValues.inWalletKeys.IndexOfAccountKey(account.accountInfo.new_publicKey)>=0);
       end;
       end;
       If IsValid then begin
       If IsValid then begin

+ 3 - 5
src/gui-experimental/UFRMOperation.pas

@@ -294,8 +294,8 @@ loop_start:
         if signerAccount.balance>DefaultFee then _fee := DefaultFee
         if signerAccount.balance>DefaultFee then _fee := DefaultFee
         else _fee := signerAccount.balance;
         else _fee := signerAccount.balance;
         if (rbListAccountForPublicSale.Checked) then begin
         if (rbListAccountForPublicSale.Checked) then begin
-          LHashLock := CT_HashLock_NUL; // Skybuck: check or debug ! passed in function below !
-          // Skybuck: LNewAccountState parameter added, check or debug this later ! passed in function below !
+          LHashLock := CT_HashLock_NUL; // Skybuck: check or debug ! LHashLock zero value array passed in function below perhaps replace with correctly filled hash array !
+          // Skybuck: LNewAccountState parameter added, check or debug this later ! passed in function below ! LNewAccountState is not set yet !
           op := TOpListAccountForSaleOrSwap.CreateListAccountForSaleOrSwap(FNode.Bank.SafeBox.CurrentProtocol, LNewAccountState, signerAccount.account,signerAccount.n_operation+1+iAcc, account.account,_salePrice,_fee, destAccount.account,CT_TECDSA_Public_Nul,0,wk.PrivateKey,LHashLock, FOperationPayload);
           op := TOpListAccountForSaleOrSwap.CreateListAccountForSaleOrSwap(FNode.Bank.SafeBox.CurrentProtocol, LNewAccountState, signerAccount.account,signerAccount.n_operation+1+iAcc, account.account,_salePrice,_fee, destAccount.account,CT_TECDSA_Public_Nul,0,wk.PrivateKey,LHashLock, FOperationPayload);
         end else if (rbListAccountForPrivateSale.Checked) then begin
         end else if (rbListAccountForPrivateSale.Checked) then begin
           op := TOpListAccountForSaleOrSwap.CreateListAccountForSaleOrSwap(FNode.Bank.SafeBox.CurrentProtocol, LNewAccountState, signerAccount.account,signerAccount.n_operation+1+iAcc, account.account,_salePrice,_fee, destAccount.account,_newOwnerPublicKey,_lockedUntil,wk.PrivateKey,LHashLock, FOperationPayload);
           op := TOpListAccountForSaleOrSwap.CreateListAccountForSaleOrSwap(FNode.Bank.SafeBox.CurrentProtocol, LNewAccountState, signerAccount.account,signerAccount.n_operation+1+iAcc, account.account,_salePrice,_fee, destAccount.account,_newOwnerPublicKey,_lockedUntil,wk.PrivateKey,LHashLock, FOperationPayload);
@@ -320,7 +320,7 @@ loop_start:
         if not UpdateOpChangeInfo(account,signerAccount,_changeName,_newName,_changeType,_newType,errors) then raise Exception.Create(errors);
         if not UpdateOpChangeInfo(account,signerAccount,_changeName,_newName,_changeType,_newType,errors) then raise Exception.Create(errors);
         if signerAccount.balance>DefaultFee then _fee := DefaultFee
         if signerAccount.balance>DefaultFee then _fee := DefaultFee
         else _fee := signerAccount.balance;
         else _fee := signerAccount.balance;
-        // Skybuck: check or debug LChangeData and LNewData !!
+        // Skybuck: check or debug LChangeData and LNewData !! (newly added, no correct values yet set in these two variables !?!)
         op := TOpChangeAccountInfo.CreateChangeAccountInfo(FNode.Bank.SafeBox.CurrentProtocol,signerAccount.account,signerAccount.n_operation+1,account.account,wk.PrivateKey,false,CT_TECDSA_Public_Nul,
         op := TOpChangeAccountInfo.CreateChangeAccountInfo(FNode.Bank.SafeBox.CurrentProtocol,signerAccount.account,signerAccount.n_operation+1,account.account,wk.PrivateKey,false,CT_TECDSA_Public_Nul,
            _changeName,_newName,_changeType,_newType,LChangeData,LNewData,_fee,FOperationPayload);
            _changeName,_newName,_changeType,_newType,LChangeData,LNewData,_fee,FOperationPayload);
         {%endregion}
         {%endregion}
@@ -1255,7 +1255,6 @@ Var payload_u : AnsiString;
 begin
 begin
   valid := false;
   valid := false;
   payload_encrypted := Nil;
   payload_encrypted := Nil;
-//  FEncodedPayload := Nil;  // Skybuck: old/deprecated
   FOperationPayload.payload_raw := nil;
   FOperationPayload.payload_raw := nil;
   errors := 'Unknown error';
   errors := 'Unknown error';
   payload_u := memoPayload.Lines.Text;
   payload_u := memoPayload.Lines.Text;
@@ -1359,7 +1358,6 @@ begin
       lblEncryptionErrors.Caption := errors;
       lblEncryptionErrors.Caption := errors;
       lblPayloadLength.Caption := Format('(%db -> ?)',[length(payload_u)]);
       lblPayloadLength.Caption := Format('(%db -> ?)',[length(payload_u)]);
     end;
     end;
-//    FEncodedPayload := payload_encrypted; // Skybuck: old/deprecated
     FOperationPayload.payload_raw := payload_encrypted;
     FOperationPayload.payload_raw := payload_encrypted;
 
 
     Result := valid;
     Result := valid;

+ 4 - 4
src/gui-experimental/UFRMPascalCoinWalletConfig.pas

@@ -135,12 +135,12 @@ end;
 
 
 procedure TFRMPascalCoinWalletConfig.bbOpenDataFolderClick(Sender: TObject);
 procedure TFRMPascalCoinWalletConfig.bbOpenDataFolderClick(Sender: TObject);
 begin
 begin
-//  OpenDocument(PChar(TFolderHelper.GetPascalCoinDataFolder)) // Skybuck: old, don't work no more.
-  // Skybuck: two solutions possible:
+  // Skybuck:TFolderHelper.GetPascalCoinDataFolder don't exist no more replaced with TNode.GetPascalCoinDataFolder
+  // OpenDocument(PChar(TFolderHelper.GetPascalCoinDataFolder))
+  // Two solutions possible:
   // 1: TNode.GetPascalCoinDataFolder
   // 1: TNode.GetPascalCoinDataFolder
   // 2. TFolderHelper.GetDataFolder(CT_PascalCoin_Data_Folder
   // 2. TFolderHelper.GetDataFolder(CT_PascalCoin_Data_Folder
-
-  // Skybuck: I will try TNode first if this does not work use solution 2.
+  // I will try TNode first if this does not work use solution 2.
   OpenDocument(PChar(TNode.GetPascalCoinDataFolder));
   OpenDocument(PChar(TNode.GetPascalCoinDataFolder));
 end;
 end;
 
 

+ 0 - 4
src/gui-experimental/UUserInterface.pas

@@ -342,7 +342,6 @@ begin
     FLog.SaveTypes := [];
     FLog.SaveTypes := [];
 
 
     // Create data directories
     // Create data directories
-    // Skybuck: using solution 1 for now: TNode.GetPascalCoinDataFolder
     If Not ForceDirectories(TNode.GetPascalCoinDataFolder) then
     If Not ForceDirectories(TNode.GetPascalCoinDataFolder) then
       raise Exception.Create('Cannot create dir: '+TNode.GetPascalCoinDataFolder);
       raise Exception.Create('Cannot create dir: '+TNode.GetPascalCoinDataFolder);
 
 
@@ -379,7 +378,6 @@ begin
 
 
     // Initialise Database
     // Initialise Database
     FNode.Bank.StorageClass := TFileStorage;
     FNode.Bank.StorageClass := TFileStorage;
-    // skybuck: using solution 1 for now: TNode.GetPascalCoinDataFolder
     TFileStorage(FNode.Bank.Storage).DatabaseFolder := TNode.GetPascalCoinDataFolder+PathDelim+'Data';
     TFileStorage(FNode.Bank.Storage).DatabaseFolder := TNode.GetPascalCoinDataFolder+PathDelim+'Data';
     TFileStorage(FNode.Bank.Storage).Initialize;
     TFileStorage(FNode.Bank.Storage).Initialize;
 
 
@@ -618,7 +616,6 @@ begin
       FLog.SaveTypes := CT_TLogTypes_ALL
       FLog.SaveTypes := CT_TLogTypes_ALL
     else
     else
       FLog.SaveTypes := CT_TLogTypes_DEFAULT;
       FLog.SaveTypes := CT_TLogTypes_DEFAULT;
-    // Skybuck: Using solution 1 for now: TNode.GetPascalCoinDataFolder
     FLog.FileName := TNode.GetPascalCoinDataFolder+PathDelim+'PascalCointWallet.log';
     FLog.FileName := TNode.GetPascalCoinDataFolder+PathDelim+'PascalCointWallet.log';
   end else begin
   end else begin
     FLog.SaveTypes := [];
     FLog.SaveTypes := [];
@@ -634,7 +631,6 @@ begin
     finally
     finally
       FNode.UnlockMempoolWrite;
       FNode.UnlockMempoolWrite;
     end;
     end;
-    // Skybuck: Using solution 1 for now: TNode.GetPascalCoinDataFolder
     FNode.NodeLogFilename := TNode.GetPascalCoinDataFolder+PathDelim+'blocks.log';
     FNode.NodeLogFilename := TNode.GetPascalCoinDataFolder+PathDelim+'blocks.log';
   end;
   end;
   if Assigned(FPoolMiningServer) then begin
   if Assigned(FPoolMiningServer) then begin

+ 4 - 4
src/libraries/sphere10/UCommon.Collections.pas

@@ -347,7 +347,7 @@ type
   __TArrayTool_IComparer_T = TArrayTool<__IComparer_T>;
   __TArrayTool_IComparer_T = TArrayTool<__IComparer_T>;
 
 
 begin
 begin
-  Result := TManyComparer<T>.Create( __TArrayTool_IComparer_T.Copy(comparers) ); // Skybuck: re-enabled
+  Result := TManyComparer<T>.Create( __TArrayTool_IComparer_T.Copy(comparers) );
 end;
 end;
 
 
 class function TComparerTool<T>.Many(const comparers: TEnumerable<__IComparer_T>) : IComparer<T>;
 class function TComparerTool<T>.Many(const comparers: TEnumerable<__IComparer_T>) : IComparer<T>;
@@ -365,7 +365,7 @@ end;
 
 
 class function TComparerTool<T>.AlwaysEqual : IComparer<T>;
 class function TComparerTool<T>.AlwaysEqual : IComparer<T>;
 type
 type
-  __TGlobalComparerFunc_T = TGlobalComparerFunc<T>;  // Skybuck: Re-enabled
+  __TGlobalComparerFunc_T = TGlobalComparerFunc<T>;
 begin
 begin
   Result :=  TComparerTool<T>.FromFunc( AlwaysEqualHandler );
   Result :=  TComparerTool<T>.FromFunc( AlwaysEqualHandler );
 end;
 end;
@@ -514,9 +514,9 @@ end;
 
 
 class function TPredicateTool<T>.OrMany(const APredicates : array of IPredicate<T>) : IPredicate<T>;
 class function TPredicateTool<T>.OrMany(const APredicates : array of IPredicate<T>) : IPredicate<T>;
 type
 type
-  __TArrayTool_IPredicate_T = TArrayTool<__IPredicate_T>; // Skybuck: Re-enabled
+  __TArrayTool_IPredicate_T = TArrayTool<__IPredicate_T>;
 begin
 begin
-  Result := TOrManyPredicate<T>.Create( __TArrayTool_IPredicate_T.Copy( APredicates) ); // Skybuck: Re-enabled
+  Result := TOrManyPredicate<T>.Create( __TArrayTool_IPredicate_T.Copy( APredicates) );
 end;
 end;
 
 
 class function TPredicateTool<T>.OrMany(const APredicates : array of TNestedPredicateFunc<T>) : IPredicate<T>;
 class function TPredicateTool<T>.OrMany(const APredicates : array of TNestedPredicateFunc<T>) : IPredicate<T>;

+ 13 - 25
src/libraries/sphere10/UCommon.Data.pas

@@ -23,7 +23,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, Generics.Collections, UMemory, UCommon, UCommon.Collections, Generics.Defaults,
   Classes, SysUtils, Generics.Collections, UMemory, UCommon, UCommon.Collections, Generics.Defaults,
-  Variants, LazUTF8, math, typinfo, syncobjs, fgl;
+  Variants, LazUTF8, math, typinfo, syncobjs;
 
 
 type
 type
   TSortDirection = (sdNone, sdAscending, sdDescending);
   TSortDirection = (sdNone, sdAscending, sdDescending);
@@ -234,10 +234,9 @@ const
   TDataSourceTool<T> = class
   TDataSourceTool<T> = class
     protected type
     protected type
       __IPredicate_T = IPredicate<T>;
       __IPredicate_T = IPredicate<T>;
-//      __TList_IPredicate_T = TList<__IPredicate_T>; // Skybuck: TList is buggy, disabled and replaced with TFPGList
-      __TList_IPredicate_T = TFPGlist<IPredicate<T>>;
+      __TList_IPredicate_T = TList<__IPredicate_T>;
     public
     public
-     class function ArrayFromList( ParaList : __TList_IPredicate_T ) : TArray<IPredicate<T>>;
+     class function ToArrayWorkAround( ParaList : __TList_IPredicate_T ) : TArray<IPredicate<T>>; // Skybuck: work around for buggy TList.ToArray
      class function ConstructRowComparer(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplySortDelegate<T>) : IComparer<T>;
      class function ConstructRowComparer(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplySortDelegate<T>) : IComparer<T>;
      class function ConstructRowPredicate(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplyFilterDelegate<T>; const AOperand : TFilterOperand) : IPredicate<T>;
      class function ConstructRowPredicate(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplyFilterDelegate<T>; const AOperand : TFilterOperand) : IPredicate<T>;
   end;
   end;
@@ -640,14 +639,13 @@ end;
 
 
 class function TDataSourceTool<T>.ConstructRowComparer(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplySortDelegate<T>) : IComparer<T>;
 class function TDataSourceTool<T>.ConstructRowComparer(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplySortDelegate<T>) : IComparer<T>;
 type
 type
-  __IComparer_T = IComparer<T>; // Skybuck: Re-enabled
+  __IComparer_T = IComparer<T>;
 var
 var
   i : integer;
   i : integer;
-  comparers : TList<__IComparer_T>; // Skybuck: Re-enabled
+  comparers : TList<__IComparer_T>;
   filter : TColumnFilter;
   filter : TColumnFilter;
   GC : TDisposables;
   GC : TDisposables;
 begin
 begin
-// Skybuck: Re-enabled
   comparers := GC.AddObject(  TList<__IComparer_T>.Create ) as TList<__IComparer_T>;
   comparers := GC.AddObject(  TList<__IComparer_T>.Create ) as TList<__IComparer_T>;
   for i := Low(AFilters) to High(AFilters) do begin
   for i := Low(AFilters) to High(AFilters) do begin
     filter := AFilters[i];
     filter := AFilters[i];
@@ -662,22 +660,13 @@ begin
   end;
   end;
 end;
 end;
 
 
-// Skybuck: New temporarely ArrayFromList function until buggy TList is fixed by FPC compiler team (or generics team ?!?)
-class function TDataSourceTool<T>.ArrayFromList( ParaList : __TList_IPredicate_T ) : TArray<IPredicate<T>>;
-var
-  LIndex : integer;
+// Skybuck: ToArrayWorkAround implementation until TList.ToArray is fixed by FPC compiler and/or generics team ?
+class function TDataSourceTool<T>.ToArrayWorkAround( ParaList : __TList_IPredicate_T ) : TArray<IPredicate<T>>;
 begin
 begin
-  // Skybuck: untested code, check and/or debug it !
-  SetLength( result, ParaList.Count );
-
-  for LIndex := 0 to length(result)-1 do
-  begin
-    result[LIndex] := ParaList.Items[LIndex];
-  end;
+  result := ParaList.ToArray;
 end;
 end;
 
 
 class function TDataSourceTool<T>.ConstructRowPredicate(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplyFilterDelegate<T>; const AOperand : TFilterOperand) : IPredicate<T>;
 class function TDataSourceTool<T>.ConstructRowPredicate(const AFilters : TArray<TColumnFilter>; const ADelegate : TApplyFilterDelegate<T>; const AOperand : TFilterOperand) : IPredicate<T>;
-// Skybuck: Re-enabled
 type
 type
   __TColumnFilterPredicate_T = TColumnFilterPredicate<T>;
   __TColumnFilterPredicate_T = TColumnFilterPredicate<T>;
   __TPredicateTool_T = TPredicateTool<T>;
   __TPredicateTool_T = TPredicateTool<T>;
@@ -686,7 +675,6 @@ var
   filters : __TList_IPredicate_T;
   filters : __TList_IPredicate_T;
   GC : TDisposables;
   GC : TDisposables;
 begin
 begin
-  // Skybuck: Re-enabled
   filters := GC.AddObject( __TList_IPredicate_T.Create ) as __TList_IPredicate_T;
   filters := GC.AddObject( __TList_IPredicate_T.Create ) as __TList_IPredicate_T;
   for i := Low(AFilters) to High(AFilters) do begin
   for i := Low(AFilters) to High(AFilters) do begin
     if AFilters[i].Filter <> vgfSortable then begin
     if AFilters[i].Filter <> vgfSortable then begin
@@ -694,16 +682,16 @@ begin
     end;
     end;
   end;
   end;
 
 
-  // Skybuck: Free Pascal Compiler Bug/Internal Error 2015052501 caused by buggy TList, replaced with TFPGList.
+  // Skybuck: Free Pascal Compiler Bug/Internal Error 2015052501 caused by buggy TList.ToArray
   case filters.Count of
   case filters.Count of
     0: Result := nil;
     0: Result := nil;
     1: Result := filters[0];
     1: Result := filters[0];
     else case AOperand of
     else case AOperand of
-//      foAnd: Result := __TPredicateTool_T.AndMany(filters.ToArray); // Skybuck: old TList bug
-//      foOr: Result := __TPredicateTool_T.OrMany(filters.ToArray); // Skybuck: old TList bug
+//      foAnd: Result := __TPredicateTool_T.AndMany(filters.ToArray); // Skybuck: TList.ToArray causes FPC compiler to crash here.
+//      foOr: Result := __TPredicateTool_T.OrMany(filters.ToArray);
 
 
-      foAnd: Result := __TPredicateTool_T.AndMany(ArrayFromList(filters)); // skybuck: new TFPGList fix
-      foOr: Result := __TPredicateTool_T.OrMany(ArrayFromList(filters));  // Skybuck: new TFPGList fix
+      foAnd: Result := __TPredicateTool_T.AndMany(ToArrayWorkAround(filters));
+      foOr: Result := __TPredicateTool_T.OrMany(ToArrayWorkAround(filters));
     end;
     end;
   end;
   end;
 end;
 end;