Skip to content

Commit c256268

Browse files
committed
clean up arm detection logic
1 parent 1b2405e commit c256268

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

HashLib/src/Utils/HlpArmHwCapProvider.pas

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ TArmHwCapProvider = class sealed
9292
strict private
9393
class var
9494
FGetAuxVal: TGetAuxValFunc;
95-
FResolved: Boolean;
9695

97-
strict private
98-
class procedure ResolveOnce(); static;
96+
private
97+
class procedure ResolveDynamicImports(); static;
9998

10099
public
101100
class function GetHwCap(): UInt64; static;
@@ -110,10 +109,9 @@ TArmHwCapProvider = class sealed
110109
strict private
111110
class var
112111
FElfAuxInfo: TElfAuxInfoFunc;
113-
FResolved: Boolean;
114112

115-
strict private
116-
class procedure ResolveOnce(); static;
113+
private
114+
class procedure ResolveDynamicImports(); static;
117115

118116
public
119117
class function GetHwCap(): UInt64; static;
@@ -139,15 +137,11 @@ implementation
139137

140138
{$IF DEFINED(HASHLIB_LINUX) OR DEFINED(HASHLIB_ANDROID)}
141139

142-
class procedure TArmHwCapProvider.ResolveOnce();
140+
class procedure TArmHwCapProvider.ResolveDynamicImports();
143141
var
144142
LHandle: Pointer;
145143
begin
146-
if FResolved then
147-
Exit;
148-
149144
FGetAuxVal := nil;
150-
FResolved := True;
151145

152146
LHandle := dlopen(nil, RTLD_NOW);
153147
if LHandle = nil then
@@ -163,7 +157,6 @@ class procedure TArmHwCapProvider.ResolveOnce();
163157

164158
class function TArmHwCapProvider.GetHwCap(): UInt64;
165159
begin
166-
ResolveOnce();
167160
if System.Assigned(FGetAuxVal) then
168161
Result := FGetAuxVal(AT_HWCAP)
169162
else
@@ -172,7 +165,6 @@ class function TArmHwCapProvider.GetHwCap(): UInt64;
172165

173166
class function TArmHwCapProvider.GetHwCap2(): UInt64;
174167
begin
175-
ResolveOnce();
176168
if System.Assigned(FGetAuxVal) then
177169
Result := FGetAuxVal(AT_HWCAP2)
178170
else
@@ -185,15 +177,11 @@ class function TArmHwCapProvider.GetHwCap2(): UInt64;
185177

186178
{$IF DEFINED(HASHLIB_BSD)}
187179

188-
class procedure TArmHwCapProvider.ResolveOnce();
180+
class procedure TArmHwCapProvider.ResolveDynamicImports();
189181
var
190182
LHandle: Pointer;
191183
begin
192-
if FResolved then
193-
Exit;
194-
195184
FElfAuxInfo := nil;
196-
FResolved := True;
197185

198186
LHandle := dlopen(nil, RTLD_NOW);
199187
if LHandle = nil then
@@ -216,7 +204,6 @@ class function TArmHwCapProvider.GetHwCap(): UInt64;
216204
var
217205
LValue: UInt64;
218206
begin
219-
ResolveOnce();
220207
if System.Assigned(FElfAuxInfo) then
221208
begin
222209
LValue := 0;
@@ -233,7 +220,6 @@ class function TArmHwCapProvider.GetHwCap2(): UInt64;
233220
var
234221
LValue: UInt64;
235222
begin
236-
ResolveOnce();
237223
if System.Assigned(FElfAuxInfo) then
238224
begin
239225
LValue := 0;
@@ -259,6 +245,11 @@ class function TArmHwCapProvider.HasProcessorFeature(AFeature: UInt32): Boolean;
259245

260246
{$IFEND} // HASHLIB_MSWINDOWS
261247

248+
{$IF DEFINED(HASHLIB_LINUX) OR DEFINED(HASHLIB_ANDROID) OR DEFINED(HASHLIB_BSD)}
249+
initialization
250+
TArmHwCapProvider.ResolveDynamicImports;
251+
{$IFEND}
252+
262253
{$IFEND} // HASHLIB_ARM
263254

264255
end.

HashLib/src/Utils/HlpDarwinSysCtl.pas

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ TDarwinSysCtl = class sealed
3131
strict private
3232
class var
3333
FSysCtlByName: TSysCtlByNameFunc;
34-
FResolved: Boolean;
3534

36-
strict private
37-
class procedure ResolveOnce(); static;
35+
private
36+
class procedure ResolveDynamicImports(); static;
3837

3938
/// <summary>
4039
/// Queries a single sysctl key. Returns True if the key exists and
@@ -63,15 +62,11 @@ implementation
6362

6463
{ TDarwinSysCtl }
6564

66-
class procedure TDarwinSysCtl.ResolveOnce();
65+
class procedure TDarwinSysCtl.ResolveDynamicImports();
6766
var
6867
LHandle: Pointer;
6968
begin
70-
if FResolved then
71-
Exit;
72-
7369
FSysCtlByName := nil;
74-
FResolved := True;
7570

7671
LHandle := dlopen(nil, RTLD_NOW);
7772
if LHandle = nil then
@@ -107,8 +102,6 @@ class function TDarwinSysCtl.QueryKey(const AName: PAnsiChar): Boolean;
107102
class function TDarwinSysCtl.HasFeature(const AModernName: PAnsiChar;
108103
const ALegacyName: PAnsiChar): Boolean;
109104
begin
110-
ResolveOnce();
111-
112105
if not System.Assigned(FSysCtlByName) then
113106
begin
114107
Result := False;
@@ -123,6 +116,9 @@ class function TDarwinSysCtl.HasFeature(const AModernName: PAnsiChar;
123116
Result := QueryKey(ALegacyName);
124117
end;
125118

119+
initialization
120+
TDarwinSysCtl.ResolveDynamicImports;
121+
126122
{$IFEND} // HASHLIB_MACOS OR HASHLIB_IOS
127123
{$IFEND} // HASHLIB_ARM
128124

0 commit comments

Comments
 (0)