rtl-generics: The program crashes when using the classes inherited from the TOrdinalComparer<T, THashFactory>
Original Reporter info from Mantis: ZOleg
-
Reporter name: Oleg
Original Reporter info from Mantis: ZOleg
- Reporter name: Oleg
Description:
The program crashes when calling methods GetHashCode, GetHashList and Equals classes TGOrdinalStringComparer&LtPos;T, THashFactory> and TGOrdinalIStringComparer&LtPos;T, THashFactory> - defined in the Generics.Defaults module.
Reason:
-
at the initialization stage of the program (in fpc_initializeunits), the class constructor TOrdinalComparer&LtPos;T, THashFactory>.Create is called before the call of the class constructors of the THashService&LtPos;T> and TExtendedHashService&LtPos;T>. Therefore, the fields FEqualityComparer and FExtendedEqualityComparer are initialized to nil.
-
also, in the class constructor TOrdinalComparer&LtPos;T, THashFactory>.Create, check is performed THashFactory.InheritsFrom(TExtendedHashService), while it is further assumed that the type THashFactory is an inheritor of the TExtendedHashFactory or THashFactory classes.
Steps to reproduce:
Test program: test_GCL.lpr
Additional information:
The problem is solved either by taking the definitions of the TOrdinalComparer&LtPos;T, THashFactory> class and his childrens classes into a separate module, or by replacing the constructors with the initialization procedures that are called if necessary. The latter allows you to get rid of the call to the constructors of unused classes at the initialization stage of the program.
Mantis conversion info:
- Mantis ID: 35926
- OS: Win32, Win64
- OS Build: Windows 7, 10
- Build: r42488
- Platform: i386, x86_64
- Version: 3.3.1