Skip to content

Commit cf84093

Browse files
committed
inline constexpr + const in install
1 parent 52e23f8 commit cf84093

File tree

5 files changed

+89
-84
lines changed

5 files changed

+89
-84
lines changed

builds/win32/msvc15/instclient.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
<ClCompile Include="..\..\..\src\utilities\install\install_client.cpp" />
255255
</ItemGroup>
256256
<ItemGroup>
257+
<ClInclude Include="..\..\..\src\utilities\install\install_nt.h" />
257258
<ClInclude Include="..\..\..\src\utilities\install\install_proto.h" />
258259
</ItemGroup>
259260
<ItemGroup>
@@ -269,4 +270,4 @@
269270
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
270271
<ImportGroup Label="ExtensionTargets">
271272
</ImportGroup>
272-
</Project>
273+
</Project>

builds/win32/msvc15/instclient.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<ClInclude Include="..\..\..\src\utilities\install\install_proto.h">
2626
<Filter>Header files</Filter>
2727
</ClInclude>
28+
<ClInclude Include="..\..\..\src\utilities\install\install_nt.h">
29+
<Filter>Header files</Filter>
30+
</ClInclude>
2831
</ItemGroup>
2932
<ItemGroup>
3033
<ResourceCompile Include="..\..\..\src\jrd\version.rc">

src/utilities/install/install.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
#include "../utilities/install/install_nt.h"
3333
#include "../utilities/install/install_proto.h"
3434

35-
const DWORD GDSVER_MAJOR = 6;
36-
const DWORD GDSVER_MINOR = 3;
35+
constexpr DWORD GDSVER_MAJOR = 6;
36+
constexpr DWORD GDSVER_MINOR = 3;
3737

38-
const char* SHARED_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs";
38+
constexpr const char* SHARED_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs";
3939

4040
namespace
4141
{
@@ -78,7 +78,7 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
7878

7979
// Get Windows System Directory
8080
TEXT sysdir[MAXPATHLEN];
81-
int len = GetSystemDirectory(sysdir, sizeof(sysdir));
81+
const int len = GetSystemDirectory(sysdir, sizeof(sysdir));
8282
if (len == 0)
8383
return (*err_handler) (GetLastError(), "GetSystemDirectory()");
8484

@@ -172,12 +172,14 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
172172
// Move _FBCLIENT.DLL as the final target
173173
if (MoveFile(workfile, target) == 0)
174174
{
175-
// MoveFile failed, this is expected if target already exists
176-
ULONG werr = GetLastError();
177-
if (werr != ERROR_ALREADY_EXISTS)
178175
{
179-
DeleteFile(workfile);
180-
return (*err_handler) (werr, "MoveFile(_FBCLIENT.DLL, 'target')");
176+
// MoveFile failed, this is expected if target already exists
177+
const ULONG werr = GetLastError();
178+
if (werr != ERROR_ALREADY_EXISTS)
179+
{
180+
DeleteFile(workfile);
181+
return (*err_handler) (werr, "MoveFile(_FBCLIENT.DLL, 'target')");
182+
}
181183
}
182184

183185
// Failed moving because a destination target file already exists
@@ -207,15 +209,15 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
207209

208210
if ((*ntmove) (target, 0, MOVEFILE_DELAY_UNTIL_REBOOT) == 0)
209211
{
210-
ULONG werr = GetLastError();
212+
const ULONG werr = GetLastError();
211213
FreeLibrary(kernel32);
212214
DeleteFile(workfile);
213215
return (*err_handler) (werr, "MoveFileEx(delete 'target')");
214216
}
215217

216218
if ((*ntmove) (workfile, target, MOVEFILE_DELAY_UNTIL_REBOOT) == 0)
217219
{
218-
ULONG werr = GetLastError();
220+
const ULONG werr = GetLastError();
219221
FreeLibrary(kernel32);
220222
DeleteFile(workfile);
221223
return (*err_handler) (werr, "MoveFileEx(replace 'target')");
@@ -250,15 +252,15 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
250252
if (WritePrivateProfileString("rename", "NUL", starget,
251253
"WININIT.INI") == 0)
252254
{
253-
ULONG werr = GetLastError();
255+
const ULONG werr = GetLastError();
254256
DeleteFile(workfile);
255257
return (*err_handler) (werr, "WritePrivateProfileString(delete 'target')");
256258
}
257259

258260
if (WritePrivateProfileString("rename", starget, sworkfile,
259261
"WININIT.INI") == 0)
260262
{
261-
ULONG werr = GetLastError();
263+
const ULONG werr = GetLastError();
262264
DeleteFile(workfile);
263265
return (*err_handler) (werr, "WritePrivateProfileString(replace 'target')");
264266
}
@@ -301,7 +303,7 @@ USHORT CLIENT_remove(const TEXT* rootdir, USHORT client, bool sw_force, err_hand
301303

302304
// Get Windows System Directory
303305
TEXT sysdir[MAXPATHLEN];
304-
int len = GetSystemDirectory(sysdir, sizeof(sysdir));
306+
const int len = GetSystemDirectory(sysdir, sizeof(sysdir));
305307
if (len == 0)
306308
return (*err_handler) (GetLastError(), "GetSystemDirectory()");
307309

@@ -370,7 +372,7 @@ USHORT CLIENT_query(USHORT client, ULONG& verMS, ULONG& verLS, ULONG& sharedCoun
370372

371373
// Get Windows System Directory
372374
TEXT sysdir[MAXPATHLEN];
373-
int len = GetSystemDirectory(sysdir, sizeof(sysdir));
375+
const int len = GetSystemDirectory(sysdir, sizeof(sysdir));
374376
if (len == 0)
375377
return (*err_handler) (GetLastError(), "GetSystemDirectory()");
376378

@@ -380,13 +382,12 @@ USHORT CLIENT_query(USHORT client, ULONG& verMS, ULONG& verLS, ULONG& sharedCoun
380382
lstrcat(target, client == CLIENT_GDS ? GDS32_NAME : FBCLIENT_NAME);
381383

382384
verMS = verLS = sharedCount = 0;
383-
USHORT status = GetVersion(target, verMS, verLS, err_handler);
385+
const USHORT status = GetVersion(target, verMS, verLS, err_handler);
384386
if (status != FB_SUCCESS)
385387
return status; // FB_FAILURE or FB_INSTALL_FILE_NOT_FOUND
386388

387389
HKEY hkey;
388-
LONG keystatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SHARED_KEY, 0,
389-
KEY_READ, &hkey);
390+
const LONG keystatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SHARED_KEY, 0, KEY_READ, &hkey);
390391
if (keystatus != ERROR_SUCCESS)
391392
return (*err_handler) (keystatus, "RegOpenKeyEx");
392393

@@ -428,18 +429,18 @@ USHORT GetVersion(const TEXT* filename, DWORD& verMS, DWORD& verLS, err_handler_
428429
// can't be deleted between check for existence and version read.
429430

430431
DWORD dwUnused;
431-
DWORD rsize = GetFileVersionInfoSize(const_cast<TEXT*>(filename), &dwUnused);
432+
const DWORD rsize = GetFileVersionInfoSize(filename, &dwUnused);
432433
if (rsize == 0)
433434
{
434-
ULONG werr = GetLastError();
435+
const ULONG werr = GetLastError();
435436
CloseHandle(hfile);
436437
return (*err_handler) (werr, "GetFileVersionInfoSize()");
437438
}
438439

439440
BYTE* hver = new BYTE[rsize];
440-
if (! GetFileVersionInfo(const_cast<TEXT*>(filename), 0, rsize, hver))
441+
if (!GetFileVersionInfo(filename, 0, rsize, hver))
441442
{
442-
ULONG werr = GetLastError();
443+
const ULONG werr = GetLastError();
443444
delete[] hver;
444445
CloseHandle(hfile);
445446
return (*err_handler) (werr, "GetFileVersionInfo()");
@@ -450,7 +451,7 @@ USHORT GetVersion(const TEXT* filename, DWORD& verMS, DWORD& verLS, err_handler_
450451
UINT uiUnused;
451452
if (! VerQueryValue(hver, "\\", (void**)&ffi, &uiUnused))
452453
{
453-
ULONG werr = GetLastError();
454+
const ULONG werr = GetLastError();
454455
delete[] hver;
455456
return (*err_handler) (werr, "VerQueryValue()");
456457
}
@@ -495,13 +496,13 @@ USHORT PatchVersion(const TEXT* filename, DWORD verMS, err_handler_t err_handler
495496
if (hfile == INVALID_HANDLE_VALUE)
496497
return (*err_handler) (GetLastError(), "CreateFile()");
497498

498-
DWORD fsize = GetFileSize(hfile, 0);
499+
const DWORD fsize = GetFileSize(hfile, 0);
499500

500501
HANDLE hmap = CreateFileMapping(hfile, 0,
501502
PAGE_READWRITE | SEC_COMMIT, 0, 0, 0);
502503
if (hmap == 0)
503504
{
504-
ULONG werr = GetLastError();
505+
const ULONG werr = GetLastError();
505506
CloseHandle(hfile);
506507
return (*err_handler) (werr, "CreateFileMapping()");
507508
}
@@ -510,22 +511,22 @@ USHORT PatchVersion(const TEXT* filename, DWORD verMS, err_handler_t err_handler
510511
FILE_MAP_WRITE, 0, 0, 0));
511512
if (mem == 0)
512513
{
513-
ULONG werr = GetLastError();
514+
const ULONG werr = GetLastError();
514515
CloseHandle(hmap);
515516
CloseHandle(hfile);
516517
return (*err_handler) (werr, "MapViewOfFile()");
517518
}
518519

519520
// This is a "magic value" that will allow locating the version info.
520521
// Windows itself does something equivalent internally.
521-
const BYTE lookup[] =
522+
constexpr BYTE lookup[] =
522523
{
523524
'V', 0, 'S', 0, '_', 0,
524525
'V', 0, 'E', 0, 'R', 0, 'S', 0, 'I', 0, 'O', 0, 'N', 0, '_', 0,
525526
'I', 0, 'N', 0, 'F', 0, 'O', 0, 0, 0, 0, 0, 0xbd, 0x04, 0xef, 0xfe
526527
};
527-
BYTE* p = mem; // First byte of mapped file
528-
BYTE* end = mem + fsize; // Last byte + 1 of mapped file
528+
BYTE* p = mem; // First byte of mapped file
529+
const BYTE* end = mem + fsize; // Last byte + 1 of mapped file
529530

530531
int i = 0;
531532
while (p < end)

src/utilities/install/install_client.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
#include "../utilities/install/install_proto.h"
3636

3737
static USHORT inst_error(ULONG, const TEXT*);
38-
static void usage_exit();
38+
[[noreturn]] static void usage_exit();
3939

40-
static const struct
40+
static constexpr struct
4141
{
4242
const TEXT* name;
4343
USHORT abbrev;
@@ -50,7 +50,7 @@ static const struct
5050
{NULL, 0, 0}
5151
};
5252

53-
static const struct
53+
static constexpr struct
5454
{
5555
const TEXT* name;
5656
USHORT abbrev;
@@ -242,7 +242,7 @@ int CLIB_ROUTINE main( int argc, char **argv)
242242
if (sharedCount)
243243
{
244244
printf("Installed %s version : %u.%u.%u.%u "
245-
"(shared DLL count %d)\n",
245+
"(shared DLL count %u)\n",
246246
clientname,
247247
verMS >> 16, verMS & 0x0000ffff,
248248
verLS >> 16, verLS & 0x0000ffff,
@@ -302,7 +302,7 @@ static USHORT inst_error(ULONG status, const TEXT* string)
302302
sizeof(buffer),
303303
NULL))
304304
{
305-
printf("Windows NT error %" SLONGFORMAT"\n", status);
305+
printf("Windows NT error %u\n", status);
306306
}
307307
else
308308
{
@@ -313,7 +313,7 @@ static USHORT inst_error(ULONG status, const TEXT* string)
313313
return FB_FAILURE;
314314
}
315315

316-
static void usage_exit()
316+
[[noreturn]] static void usage_exit()
317317
{
318318
/**************************************
319319
*

src/utilities/install/install_nt.h

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,76 @@
2424
#ifndef UTILITIES_INSTALL_NT_H
2525
#define UTILITIES_INSTALL_NT_H
2626

27-
static const char* const REMOTE_SERVICE = "FirebirdServer%s";
28-
static const char* const REMOTE_DISPLAY_NAME = "Firebird Server - %s";
29-
static const char* const REMOTE_DISPLAY_DESCR = "Firebird Database Server - www.firebirdsql.org";
30-
static const char* const REMOTE_EXECUTABLE = "firebird";
27+
static inline constexpr const char* REMOTE_SERVICE = "FirebirdServer%s";
28+
static inline constexpr const char* REMOTE_DISPLAY_NAME = "Firebird Server - %s";
29+
static inline constexpr const char* REMOTE_DISPLAY_DESCR = "Firebird Database Server - www.firebirdsql.org";
30+
static inline constexpr const char* REMOTE_EXECUTABLE = "firebird";
3131

32-
static const char* const ISCGUARD_SERVICE = "FirebirdGuardian%s";
33-
static const char* const ISCGUARD_DISPLAY_NAME = "Firebird Guardian - %s";
34-
static const char* const ISCGUARD_DISPLAY_DESCR = "Firebird Server Guardian - www.firebirdsql.org";
35-
static const char* const ISCGUARD_EXECUTABLE = "fbguard";
32+
static inline constexpr const char* ISCGUARD_SERVICE = "FirebirdGuardian%s";
33+
static inline constexpr const char* ISCGUARD_DISPLAY_NAME = "Firebird Guardian - %s";
34+
static inline constexpr const char* ISCGUARD_DISPLAY_DESCR = "Firebird Server Guardian - www.firebirdsql.org";
35+
static inline constexpr const char* ISCGUARD_EXECUTABLE = "fbguard";
3636

37-
static const char* const SERVER_MUTEX = "FirebirdServerMutex%s";
38-
static const char* const GUARDIAN_MUTEX = "FirebirdGuardianMutex%s";
37+
static inline constexpr const char* SERVER_MUTEX = "FirebirdServerMutex%s";
38+
static inline constexpr const char* GUARDIAN_MUTEX = "FirebirdGuardianMutex%s";
3939

40-
static const char* const FB_DEFAULT_INSTANCE = "DefaultInstance";
40+
static inline constexpr const char* FB_DEFAULT_INSTANCE = "DefaultInstance";
4141

4242
// Starting with 128 the service params are user defined
43-
const DWORD SERVICE_CREATE_GUARDIAN_MUTEX = 128;
43+
inline constexpr DWORD SERVICE_CREATE_GUARDIAN_MUTEX = 128;
4444
//#define REMOTE_DEPENDENCIES "Tcpip\0\0"
4545

4646
// sw_command
47-
const USHORT COMMAND_NONE = 0;
48-
const USHORT COMMAND_INSTALL = 1;
49-
const USHORT COMMAND_REMOVE = 2;
50-
const USHORT COMMAND_START = 3;
51-
const USHORT COMMAND_STOP = 4;
52-
//const USHORT COMMAND_CONFIG = 5;
53-
const USHORT COMMAND_QUERY = 6;
47+
inline constexpr USHORT COMMAND_NONE = 0;
48+
inline constexpr USHORT COMMAND_INSTALL = 1;
49+
inline constexpr USHORT COMMAND_REMOVE = 2;
50+
inline constexpr USHORT COMMAND_START = 3;
51+
inline constexpr USHORT COMMAND_STOP = 4;
52+
//inline constexpr USHORT COMMAND_CONFIG = 5;
53+
inline constexpr USHORT COMMAND_QUERY = 6;
5454

5555
// sw_startup
56-
const USHORT STARTUP_DEMAND = 0;
57-
const USHORT STARTUP_AUTO = 1;
56+
inline constexpr USHORT STARTUP_DEMAND = 0;
57+
inline constexpr USHORT STARTUP_AUTO = 1;
5858

5959
// sw_guardian
60-
const USHORT NO_GUARDIAN = 0;
61-
const USHORT USE_GUARDIAN = 1;
60+
inline constexpr USHORT NO_GUARDIAN = 0;
61+
inline constexpr USHORT USE_GUARDIAN = 1;
6262

6363
// sw_mode
64-
const USHORT DEFAULT_PRIORITY = 0;
65-
const USHORT NORMAL_PRIORITY = 1;
66-
const USHORT HIGH_PRIORITY = 2;
64+
inline constexpr USHORT DEFAULT_PRIORITY = 0;
65+
inline constexpr USHORT NORMAL_PRIORITY = 1;
66+
inline constexpr USHORT HIGH_PRIORITY = 2;
6767

6868
// sw_arch
69-
const USHORT ARCH_SS = 0;
70-
const USHORT ARCH_CS = 1;
69+
inline constexpr USHORT ARCH_SS = 0;
70+
inline constexpr USHORT ARCH_CS = 1;
7171

7272
// sw_client
73-
const USHORT CLIENT_NONE = 0;
74-
const USHORT CLIENT_FB = 1;
75-
const USHORT CLIENT_GDS = 2;
73+
inline constexpr USHORT CLIENT_NONE = 0;
74+
inline constexpr USHORT CLIENT_FB = 1;
75+
inline constexpr USHORT CLIENT_GDS = 2;
7676

77-
static const char* const GDS32_NAME = "GDS32.DLL";
78-
static const char* const FBCLIENT_NAME = "FBCLIENT.DLL";
77+
static inline constexpr const char* GDS32_NAME = "GDS32.DLL";
78+
static inline constexpr const char* FBCLIENT_NAME = "FBCLIENT.DLL";
7979

8080
// instsvc status codes
81-
const USHORT IB_SERVICE_ALREADY_DEFINED = 100;
82-
const USHORT IB_SERVICE_RUNNING = 101;
83-
const USHORT FB_PRIVILEGE_ALREADY_GRANTED = 102;
84-
const USHORT FB_SERVICE_STATUS_RUNNING = 100;
85-
const USHORT FB_SERVICE_STATUS_STOPPED = 111;
86-
const USHORT FB_SERVICE_STATUS_PENDING = 112;
87-
const USHORT FB_SERVICE_STATUS_NOT_INSTALLED = 113;
88-
const USHORT FB_SERVICE_STATUS_UNKNOWN = 114;
81+
inline constexpr USHORT IB_SERVICE_ALREADY_DEFINED = 100;
82+
inline constexpr USHORT IB_SERVICE_RUNNING = 101;
83+
inline constexpr USHORT FB_PRIVILEGE_ALREADY_GRANTED = 102;
84+
inline constexpr USHORT FB_SERVICE_STATUS_RUNNING = 100;
85+
inline constexpr USHORT FB_SERVICE_STATUS_STOPPED = 111;
86+
inline constexpr USHORT FB_SERVICE_STATUS_PENDING = 112;
87+
inline constexpr USHORT FB_SERVICE_STATUS_NOT_INSTALLED = 113;
88+
inline constexpr USHORT FB_SERVICE_STATUS_UNKNOWN = 114;
8989

9090
// instclient status codes
91-
const USHORT FB_INSTALL_COPY_REQUIRES_REBOOT = 200;
92-
const USHORT FB_INSTALL_SAME_VERSION_FOUND = 201;
93-
const USHORT FB_INSTALL_NEWER_VERSION_FOUND = 202;
94-
const USHORT FB_INSTALL_FILE_NOT_FOUND = 203;
95-
const USHORT FB_INSTALL_CANT_REMOVE_ALIEN_VERSION = 204;
96-
const USHORT FB_INSTALL_FILE_PROBABLY_IN_USE = 205;
97-
const USHORT FB_INSTALL_SHARED_COUNT_ZERO = 206;
91+
inline constexpr USHORT FB_INSTALL_COPY_REQUIRES_REBOOT = 200;
92+
inline constexpr USHORT FB_INSTALL_SAME_VERSION_FOUND = 201;
93+
inline constexpr USHORT FB_INSTALL_NEWER_VERSION_FOUND = 202;
94+
inline constexpr USHORT FB_INSTALL_FILE_NOT_FOUND = 203;
95+
inline constexpr USHORT FB_INSTALL_CANT_REMOVE_ALIEN_VERSION = 204;
96+
inline constexpr USHORT FB_INSTALL_FILE_PROBABLY_IN_USE = 205;
97+
inline constexpr USHORT FB_INSTALL_SHARED_COUNT_ZERO = 206;
9898

9999
#endif // UTILITIES_INSTALL_NT_H

0 commit comments

Comments
 (0)