maciej-izak / generics.collections Goto Github PK
View Code? Open in Web Editor NEWFreePascal Generics.Collections library (TList, TDictionary, THashMap and more...)
FreePascal Generics.Collections library (TList, TDictionary, THashMap and more...)
Sorry this may be a stupid question. First time Pascal/Lazarus user.
How do I compile/integrate this into Lazarus?
So far I checked out the source, then did fpc fpmake.pp
, and now when I type fpmake
I get this:
D:\Dev\Pascal\generics.collections>fpmake
The installer encountered the following error:
Could not find unit directory for dependency package "rtl"
I also tried (per the Lazarus Wiki):
set FPCDIR=D:\Dev\Lazarus\fpc\3.0.2
Still have the same problem. Is this code somehow incompatible with the latest Lazarus/FPC, or how are you supposed to install it for Lazarus?
Thanks.
Hi,
First of all, I must commend the nice job you are doing on Generics.Collections.
I encountered a bug today while using Generics.Collections in my project,
When I switched my project to Win64 x86_64, I encountered a compiler error on Line 1418 of generics.hashes.pas
Here is the Error Log
Compile package MyPackage 1.0: Exit code 1, Errors: 7
generics.hashes.pas(1418,29) Error: Identifier not found "ToByte"
generics.hashes.pas(1418,47) Error: Ordinal expression expected
generics.hashes.pas(1425,29) Error: Identifier not found "ToByte"
generics.hashes.pas(1426,29) Error: Identifier not found "ToByte"
generics.hashes.pas(1427,29) Error: Identifier not found "ToByte"
generics.hashes.pas(1432,29) Error: Identifier not found "ToByte"
generics.hashes.pas(1432,47) Error: Ordinal expression expected
Regards.
When I try to compile, I get the error:
Fatal: Syntax error, "EXCEPT" expected but "identifier CREATE" found
program Project;
{$MODE DELPHI}
...
var
Test :TArray<TArray<Double>>;
begin
...
Test := TArray<TArray<Double>>.Create( // <-
TArray<Double>.Create(0.0),
TArray<Double>.Create(1.0)
);
...
end.
I'm doing something wrong?
But the same code compiling and running in XE8.
This program never completes:
program broken;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, sysutils, Generics.Collections
{ you can add units after this };
type TQuadratic = specialize TOpenAddressingQP<string, pointer>;
var map: TQuadratic;
begin
map := TQuadratic.Create();
map.add(#178#178#107#141#143#151#168#39#172#38#83#194#130#90#101, nil);
map.add(#193#190#172#41#144#231#52#62#45#117#108#45#217#71#77, nil);
map.add(#49#116#202#160#38#131#41#37#217#171#227#215#122#151#71, nil);
map.add(#148#159#199#71#198#97#69#201#116#45#195#184#178#129#200, nil);
map.ContainsKey(#$E6'h=fzb'#$E5#$B4#$A0#$C4#$E6'B6r>');
writeln('done?');
end.
fpc 3.1.1, linux64
I simplified my code as follow, I was expecting to create a dictionary from another, but it fails.
actual := TCounter.Create(expected);
raise a compiling error.
dictionarytest.pas(12,37) Error: Incompatible type for arg no. 1: Got "TDictionary<System.Char,System.LongInt>", expected "TEnumerable<dictionarytest.TPair<System.Char,System.LongInt>>"
I dug some source code, but it is too complex to find the inheritance of TDictionary class.
Please help, if I took something wrong.
{$mode objfpc}{$H-}{$J+}
program dictionarytest;
uses Generics.Collections;
type
TCounter = specialize TDictionary<Char, Integer>;
var
expected, actual: TCounter;
begin
expected := TCounter.Create;
actual := TCounter.Create(expected);
end.
```
Might be the version of FPC/Lazarus im using (downloaded from "getLazarus", Lazarus 1.7 with FPC v3.0), but the exception EArgumentNilException is missing from the units.
Easy enough to solve, just defined it in Generics.Collections.pas and it compiled straight away -- but worth checking for & defining if missing.
Hi,
I am creating a package that would require generics.collections to function.
I would appreciate it if you could consider creating a package file (lpk) so I can simply add it as a dependency to my package than having to ship and update generics.collections anytime you make an update.
This would make it easy for users especially those using non trunk version of Lazarus/FPC.
Regards..
Hi, the xxHash32 function causes crash on startup when building project on Mac 64-bit. I noticed this when updating to latest Fpc sources that uses this code.
The following changes to the ifdefs seems to fix it:
{$ifdef CPUX64}
function xxHash32(crc: cardinal; P: Pointer; len: integer): cardinal;
asm
{$ifndef WIN64} // crc=rdi P=rsi len=rdx
mov r8, rdi
mov rcx, rsi
{$else} // crc=r8 P=rcx len=rdx
mov r10, r8
mov r8, rcx
mov rcx, rdx
mov rdx, r10
push rsi // Win64 expects those registers to be preserved
push rdi
{$endif}
// P=r8 len=rcx crc=rdx
push rbx
lea r10, [rcx+rdx]
cmp rdx, 15
lea eax, [r8+165667B1H]
jbe @2
lea rsi, [r10-10H]
lea ebx, [r8+24234428H]
lea edi, [r8-7A143589H]
lea eax, [r8+61C8864FH]
@1: imul r9d, dword ptr [rcx], -2048144777
add rcx, 16
imul r11d, dword ptr [rcx-0CH], -2048144777
add ebx, r9d
lea r9d, [r11+rdi]
rol ebx, 13
rol r9d, 13
imul ebx, ebx, -1640531535
imul edi, r9d, -1640531535
imul r9d, dword ptr [rcx-8H], -2048144777
add r8d, r9d
imul r9d, dword ptr [rcx-4H], -2048144777
rol r8d, 13
imul r8d, r8d, -1640531535
add eax, r9d
rol eax, 13
imul eax, eax, -1640531535
cmp rsi, rcx
jnc @1
rol edi, 7
rol ebx, 1
rol r8d, 12
mov r9d, edi
ror eax, 14
add r9d, ebx
add r8d, r9d
add eax, r8d
@2: lea r9, [rcx+4H]
add eax, edx
cmp r10, r9
jc @4
mov r8, r9
@3: imul edx, dword ptr [r8-4H], -1028477379
add r8, 4
add eax, edx
ror eax, 15
imul eax, eax, 668265263
cmp r10, r8
jnc @3
lea rdx, [r10-4H]
sub rdx, rcx
mov rcx, rdx
and rcx, 0FFFFFFFFFFFFFFFCH
add rcx, r9
@4: cmp r10, rcx
jbe @6
@5: movzx edx, byte ptr [rcx]
add rcx, 1
imul edx, edx, 374761393
add eax, edx
rol eax, 11
imul eax, eax, -1640531535
cmp r10, rcx
jnz @5
@6: mov edx, eax
shr edx, 15
xor eax, edx
imul eax, eax, -2048144777
mov edx, eax
shr edx, 13
xor eax, edx
imul eax, eax, -1028477379
mov edx, eax
shr edx, 16
xor eax, edx
pop rbx
{$ifdef WIN64}
pop rdi
pop rsi
{$endif}
end;
{$endif CPUX64}
Try the attached testcase with Generics.Hashes
in PUREPASCAL variant. I am testing on macOS now, with FPC 3.0.4 i386, which automatically uses PUREPASCAL.
The testcase creates a dictionary mapping string->string. Trying to use Map.TryGetValue('', V)
crashes:
$ fpc -gl -gh test_trygetvalue.lpr
$ ./test_trygetvalue
"some key" => some value
"some other key" doesn't exist
An unhandled exception occurred at $000A56CB:
EAccessViolation: Access violation
$000A56CB
...
GDB shows the reason: generics.hashes.pas
at line 1197 inside xxHash32 does this:
inc(result, PCardinal(P)^ * PRIME32_3);
This line is guarded by while P <= PEnd - 4 do
condition, and in this case both P and PEnd are nil. So in this case, PtrUInt(PEnd - 4)
is 4294967292 and the condition P <= PEnd - 4
is satisfied.
Thus, xxHash32 crashes when P = nil (which is the case when calling TryGetValue with key equal to an empty string).
I made a trivial fix in Castle Game Engine's copy of Generics.Collections (used for FPC 3.0.x), changing test P <= PEnd - 4
to P + 4 <= PEnd
. See my change, along with comments, on castle-engine/castle-engine@7271a76 .
Now the results are correct:
$ ./test_trygetvalue
"some key" => some value
"some other key" doesn't exist
"" doesn't exist
Heap dump by heaptrc unit
24 memory blocks allocated : 2689/2712
24 memory blocks freed : 2689/2712
0 unfreed memory blocks : 0
True heap size : 622592 (32 used in System startup)
True free heap : 622560
P.S. I should now submit this fix separately to FPC bugtracker, to have it applied to FPC 3.1.1 in FPC SVN, right? Let me know if it is so, it's not a problem for me:)
Compilation fails in generics.helpers.pas in TValueUInt32Helper.High because High(UInt32) does not fit in LongInt. The shortcut is write:
Result := LongInt(System.High(UInt32));
but I can't see where this method is used so I can't be sure how proper is.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.