mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-26 15:10:25 +02:00
* The order of calling class constructors is not guaranteed.
But LookupExtendedEqualityComparer is called during class constructor of another class. So it needs to init tables, or it returns a nil result. This results in a crash when the comparer is used because FEqualitycomparer is nil.
This commit is contained in:
parent
d45556666e
commit
2e9a846543
@ -644,8 +644,10 @@ type
|
|||||||
|
|
||||||
|
|
||||||
FEqualityComparerInstances: array[TTypeKind] of TInstance;
|
FEqualityComparerInstances: array[TTypeKind] of TInstance;
|
||||||
|
TablesInitialized : Boolean;
|
||||||
private
|
private
|
||||||
class constructor Create;
|
class constructor Create;
|
||||||
|
class procedure InitTables;
|
||||||
public
|
public
|
||||||
class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
|
class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
|
||||||
end;
|
end;
|
||||||
@ -763,8 +765,10 @@ type
|
|||||||
|
|
||||||
// all instances
|
// all instances
|
||||||
FExtendedEqualityComparerInstances: array[TTypeKind] of TInstance;
|
FExtendedEqualityComparerInstances: array[TTypeKind] of TInstance;
|
||||||
|
TablesInitialized : Boolean;
|
||||||
private
|
private
|
||||||
class constructor Create;
|
class constructor Create;
|
||||||
|
class procedure InitTables;
|
||||||
public
|
public
|
||||||
class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
|
class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
|
||||||
end;
|
end;
|
||||||
@ -2306,6 +2310,8 @@ begin
|
|||||||
Exit(SelectBinaryEqualityComparer(Nil, ASize))
|
Exit(SelectBinaryEqualityComparer(Nil, ASize))
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
If not TablesInitialized then
|
||||||
|
InitTables;
|
||||||
LInstance := @FEqualityComparerInstances[ATypeInfo.Kind];
|
LInstance := @FEqualityComparerInstances[ATypeInfo.Kind];
|
||||||
Result := LInstance.Instance;
|
Result := LInstance.Instance;
|
||||||
if LInstance.Selector then
|
if LInstance.Selector then
|
||||||
@ -2319,6 +2325,16 @@ end;
|
|||||||
|
|
||||||
class constructor THashService<T>.Create;
|
class constructor THashService<T>.Create;
|
||||||
begin
|
begin
|
||||||
|
if not TablesInitialized then
|
||||||
|
InitTables
|
||||||
|
end;
|
||||||
|
|
||||||
|
class Procedure THashService<T>.InitTables;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if TablesInitialized then
|
||||||
|
exit;
|
||||||
|
TablesInitialized:=true;
|
||||||
FEqualityComparer_Int8_VMT := EqualityComparer_Int8_VMT ;
|
FEqualityComparer_Int8_VMT := EqualityComparer_Int8_VMT ;
|
||||||
FEqualityComparer_Int16_VMT := EqualityComparer_Int16_VMT ;
|
FEqualityComparer_Int16_VMT := EqualityComparer_Int16_VMT ;
|
||||||
FEqualityComparer_Int32_VMT := EqualityComparer_Int32_VMT ;
|
FEqualityComparer_Int32_VMT := EqualityComparer_Int32_VMT ;
|
||||||
@ -2510,6 +2526,8 @@ begin
|
|||||||
Exit(SelectBinaryEqualityComparer(Nil, ASize))
|
Exit(SelectBinaryEqualityComparer(Nil, ASize))
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
if not TablesInitialized then
|
||||||
|
InitTables;
|
||||||
LInstance := @FExtendedEqualityComparerInstances[ATypeInfo.Kind];
|
LInstance := @FExtendedEqualityComparerInstances[ATypeInfo.Kind];
|
||||||
Result := LInstance.Instance;
|
Result := LInstance.Instance;
|
||||||
if LInstance.Selector then
|
if LInstance.Selector then
|
||||||
@ -2523,6 +2541,16 @@ end;
|
|||||||
|
|
||||||
class constructor TExtendedHashService<T>.Create;
|
class constructor TExtendedHashService<T>.Create;
|
||||||
begin
|
begin
|
||||||
|
// The InitTables can have been called before from the class constructors of other classes.
|
||||||
|
if not TablesInitialized then
|
||||||
|
InitTables
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TExtendedHashService<T>.InitTables;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if TablesInitialized then exit;
|
||||||
|
TablesInitialized:=True;
|
||||||
FExtendedEqualityComparer_Int8_VMT := ExtendedEqualityComparer_Int8_VMT ;
|
FExtendedEqualityComparer_Int8_VMT := ExtendedEqualityComparer_Int8_VMT ;
|
||||||
FExtendedEqualityComparer_Int16_VMT := ExtendedEqualityComparer_Int16_VMT ;
|
FExtendedEqualityComparer_Int16_VMT := ExtendedEqualityComparer_Int16_VMT ;
|
||||||
FExtendedEqualityComparer_Int32_VMT := ExtendedEqualityComparer_Int32_VMT ;
|
FExtendedEqualityComparer_Int32_VMT := ExtendedEqualityComparer_Int32_VMT ;
|
||||||
@ -3409,7 +3437,6 @@ begin
|
|||||||
begin
|
begin
|
||||||
if AFactory = nil then
|
if AFactory = nil then
|
||||||
AFactory := TDefaultHashFactory;
|
AFactory := TDefaultHashFactory;
|
||||||
|
|
||||||
Exit(
|
Exit(
|
||||||
AFactory.GetHashService.LookupEqualityComparer(ATypeInfo, ASize));
|
AFactory.GetHashService.LookupEqualityComparer(ATypeInfo, ASize));
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user