Skip to content

Commit e6701a2

Browse files
committed
constexpr + noexcept in mod_loader (windows only)
1 parent d57053c commit e6701a2

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/common/os/mod_loader.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class ModuleLoader
7272
/// Destructor
7373
virtual ~Module() {}
7474

75+
/// Copy construction is not supported
76+
Module(const Module&) = delete;
77+
/// assignment of Modules isn't supported
78+
const Module& operator=(const Module&) = delete;
79+
7580
const Firebird::PathName fileName;
7681

7782
protected:
@@ -82,11 +87,6 @@ class ModuleLoader
8287
{
8388
}
8489

85-
private:
86-
/// Copy construction is not supported, hence the copy constructor is private
87-
Module(const Module&); // no impl
88-
/// assignment of Modules isn't supported so the assignment operator is private
89-
const Module& operator=(const Module&); // no impl
9090
};
9191

9292
/** loadModule is given as a string the path to the module to load. It

src/common/os/win32/mod_loader.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ template <typename PFN>
3939
class WinApiFunction
4040
{
4141
public:
42-
WinApiFunction(const char *dllName, const char *fnName)
42+
WinApiFunction(const char *dllName, const char *fnName) noexcept
4343
{
4444
m_ptr = NULL;
4545
const HMODULE hDll = GetModuleHandle(dllName);
@@ -50,21 +50,21 @@ class WinApiFunction
5050
~WinApiFunction()
5151
{}
5252

53-
PFN operator* () const { return m_ptr; }
53+
PFN operator* () const noexcept { return m_ptr; }
5454

55-
operator bool() const { return (m_ptr != NULL); }
55+
operator bool() const noexcept { return (m_ptr != NULL); }
5656

5757
private:
5858
PFN m_ptr;
5959
};
6060

61-
const char* const KERNEL32_DLL = "kernel32.dll";
61+
constexpr const char* KERNEL32_DLL = "kernel32.dll";
6262

6363

6464
class ContextActivator
6565
{
6666
public:
67-
ContextActivator() :
67+
ContextActivator() noexcept :
6868
mFindActCtxSectionString(KERNEL32_DLL, "FindActCtxSectionStringA"),
6969
mCreateActCtx(KERNEL32_DLL, "CreateActCtxA"),
7070
mReleaseActCtx(KERNEL32_DLL, "ReleaseActCtx"),
@@ -83,11 +83,7 @@ class ContextActivator
8383
if (!mCreateActCtx)
8484
return;
8585

86-
ACTCTX_SECTION_KEYED_DATA ackd;
87-
memset(&ackd, 0, sizeof(ackd));
88-
ackd.cbSize = sizeof(ackd);
89-
90-
const char* crtDll =
86+
constexpr const char* crtDll =
9187
#if _MSC_VER == 1400
9288
"msvcr80.dll";
9389
#elif _MSC_VER == 1500
@@ -110,6 +106,9 @@ class ContextActivator
110106
// #error Specify CRT DLL name here !
111107
#endif
112108

109+
ACTCTX_SECTION_KEYED_DATA ackd{};
110+
ackd.cbSize = sizeof(ackd);
111+
113112
// if CRT already present in some activation context then nothing to do
114113
if ((*mFindActCtxSectionString)
115114
(0, NULL,
@@ -120,8 +119,7 @@ class ContextActivator
120119
}
121120

122121
// create and use activation context from our own manifest
123-
ACTCTXA actCtx;
124-
memset(&actCtx, 0, sizeof(actCtx));
122+
ACTCTXA actCtx{};
125123
actCtx.cbSize = sizeof(actCtx);
126124
actCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
127125
actCtx.lpResourceName = ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
@@ -157,7 +155,7 @@ class ContextActivator
157155
WinApiFunction<PFN_DAC> mDeactivateActCtx;
158156

159157
HANDLE hActCtx;
160-
ULONG_PTR mCookie;
158+
ULONG_PTR mCookie = 0;
161159
};
162160

163161

0 commit comments

Comments
 (0)