Skip to content

Commit 11271db

Browse files
committed
constexpr + noexcept in config & init
1 parent 9ce53b2 commit 11271db

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

src/common/classes/init.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static bool dontCleanup = false;
5252
namespace
5353
{
5454
#ifdef DEV_BUILD
55-
void cleanError(const Firebird::Exception* e)
55+
[[noreturn]] void cleanError(const Firebird::Exception* e)
5656
{
5757
if (e)
5858
{
@@ -65,7 +65,7 @@ namespace
6565
abort();
6666
}
6767
#else
68-
void cleanError(const Firebird::Exception*) { }
68+
inline void cleanError(const Firebird::Exception*) noexcept { }
6969
#endif
7070

7171
// This helps initialize globals, needed before regular ctors run
@@ -175,8 +175,7 @@ namespace
175175

176176
initDone = 1;
177177
#ifdef HAVE_PTHREAD_ATFORK
178-
int ret = pthread_atfork(NULL, NULL, child);
179-
(void) ret;
178+
std::ignore = pthread_atfork(NULL, NULL, child);
180179
#endif
181180

182181
Firebird::MemoryPool::contextPoolInit();
@@ -219,7 +218,7 @@ namespace Firebird
219218
unlist();
220219
}
221220

222-
void InstanceControl::InstanceList::unlist()
221+
void InstanceControl::InstanceList::unlist() noexcept
223222
{
224223
if (instanceList == this)
225224
instanceList = next;
@@ -319,7 +318,7 @@ namespace Firebird
319318
gdsShutdown = shutdown;
320319
}
321320

322-
void InstanceControl::cancelCleanup()
321+
void InstanceControl::cancelCleanup() noexcept
323322
{
324323
dontCleanup = true;
325324
}
@@ -328,13 +327,13 @@ namespace Firebird
328327
{
329328
Firebird::Mutex* mutex = NULL;
330329

331-
void create()
330+
void create() noexcept
332331
{
333332
static char place[sizeof(Firebird::Mutex) + FB_ALIGNMENT];
334333
mutex = new((void*) FB_ALIGN(place, FB_ALIGNMENT)) Firebird::Mutex;
335334
}
336335

337-
void release()
336+
void release() noexcept
338337
{
339338
mutex->~Mutex();
340339
}

src/common/classes/init.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace StaticMutex
3737
{
3838
// Support for common mutex for various inits
3939
extern Mutex* mutex;
40-
void create();
41-
void release();
40+
void create() noexcept;
41+
void release() noexcept;
4242
}
4343

4444
// InstanceControl - interface for almost all global variables
@@ -77,7 +77,7 @@ class InstanceControl
7777

7878
private:
7979
virtual void dtor() = 0;
80-
void unlist();
80+
void unlist() noexcept;
8181

8282
InstanceList* next;
8383
InstanceList* prev;
@@ -118,7 +118,7 @@ class InstanceControl
118118
static void registerGdsCleanup(FPTR_VOID cleanup);
119119
static void registerShutdown(FPTR_VOID shutdown);
120120

121-
static void cancelCleanup();
121+
static void cancelCleanup() noexcept;
122122
};
123123

124124

@@ -131,7 +131,7 @@ class GlobalPtr : private InstanceControl
131131
T* instance;
132132

133133
public:
134-
void dtor()
134+
void dtor() noexcept
135135
{
136136
delete instance;
137137
instance = 0;
@@ -177,7 +177,7 @@ class InitMutex
177177
const char* from;
178178
#endif
179179
public:
180-
explicit InitMutex(const char* f)
180+
explicit InitMutex(const char* f) noexcept
181181
: flag(false)
182182
#ifdef DEV_BUILD
183183
, from(f)
@@ -224,7 +224,7 @@ class DefaultInstanceAllocator
224224
return FB_NEW_POOL(*getDefaultMemoryPool()) T(*getDefaultMemoryPool());
225225
}
226226

227-
static void destroy(T* inst)
227+
static void destroy(T* inst) noexcept
228228
{
229229
delete inst;
230230
}
@@ -275,7 +275,7 @@ class InitInstance : private DestroyControl<InitInstance<T, A, DestroyControl> >
275275
A allocator;
276276

277277
public:
278-
InitInstance()
278+
InitInstance() noexcept
279279
: instance(NULL), flag(false)
280280
{ }
281281

src/common/config/config.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ConfigImpl : public Firebird::PermanentStorage
7676
}
7777
}
7878

79+
ConfigImpl(const ConfigImpl&) = delete;
80+
void operator=(const ConfigImpl&) = delete;
81+
7982
/***
8083
It was a kind of getting ready for changing config remotely...
8184
@@ -85,12 +88,12 @@ class ConfigImpl : public Firebird::PermanentStorage
8588
}
8689
***/
8790

88-
Firebird::RefPtr<const Firebird::Config>& getDefaultConfig()
91+
Firebird::RefPtr<const Firebird::Config>& getDefaultConfig() noexcept
8992
{
9093
return defaultConfig;
9194
}
9295

93-
bool missFirebirdConf() const
96+
bool missFirebirdConf() const noexcept
9497
{
9598
return missConf;
9699
}
@@ -105,9 +108,6 @@ class ConfigImpl : public Firebird::PermanentStorage
105108
private:
106109
Firebird::RefPtr<const Firebird::Config> defaultConfig;
107110

108-
ConfigImpl(const ConfigImpl&);
109-
void operator=(const ConfigImpl&);
110-
111111
bool missConf;
112112
};
113113

@@ -150,7 +150,6 @@ Config::Config(const ConfigFile& file)
150150
serverMode(-1),
151151
defaultConfig(true)
152152
{
153-
memset(sourceIdx, 0, sizeof(sourceIdx));
154153
valuesSource.add(NULL);
155154

156155
setupDefaultConfig();
@@ -185,7 +184,6 @@ Config::Config(const ConfigFile& file, const char* srcName, const Config& base,
185184
serverMode(-1),
186185
defaultConfig(false)
187186
{
188-
memset(sourceIdx, 0, sizeof(sourceIdx));
189187
valuesSource.add(NULL);
190188

191189
for (FB_SIZE_T i = 1; i < base.valuesSource.getCount(); i++)
@@ -485,7 +483,7 @@ void Config::setRootDirectoryFromCommandLine(const PathName& newRoot)
485483
PathName(*getDefaultMemoryPool(), newRoot);
486484
}
487485

488-
const PathName* Config::getCommandLineRootDirectory()
486+
const PathName* Config::getCommandLineRootDirectory() noexcept
489487
{
490488
return rootFromCommandLine;
491489
}
@@ -563,7 +561,7 @@ bool Config::valueAsString(ConfigValue val, ConfigType type, string& str)
563561
return true;
564562
}
565563

566-
const char* Config::getKeyName(unsigned int key)
564+
const char* Config::getKeyName(unsigned int key) noexcept
567565
{
568566
if (key >= MAX_CONFIG_KEY)
569567
return nullptr;
@@ -732,13 +730,13 @@ int Config::getWireCrypt(WireCryptMode wcMode) const
732730
// array format: major, minor, release, build
733731
static constexpr unsigned short fileVerNumber[4] = {FILE_VER_NUMBER};
734732

735-
static inline unsigned int getPartialVersion()
733+
static inline constexpr unsigned int getPartialVersion() noexcept
736734
{
737735
// major // minor
738736
return (fileVerNumber[0] << 24) | (fileVerNumber[1] << 16);
739737
}
740738

741-
static inline unsigned int getFullVersion()
739+
static inline constexpr unsigned int getFullVersion() noexcept
742740
{
743741
// build_no
744742
return getPartialVersion() | fileVerNumber[3];
@@ -747,15 +745,15 @@ static inline unsigned int getFullVersion()
747745
static constexpr unsigned int PARTIAL_MASK = 0xFFFF0000;
748746
static constexpr unsigned int KEY_MASK = 0xFFFF;
749747

750-
static inline void checkKey(unsigned int& key)
748+
static inline void checkKey(unsigned int& key) noexcept
751749
{
752750
if ((key & PARTIAL_MASK) != getPartialVersion())
753751
key = KEY_MASK;
754752
else
755753
key &= KEY_MASK;
756754
}
757755

758-
unsigned int FirebirdConf::getVersion(CheckStatusWrapper* status)
756+
unsigned int FirebirdConf::getVersion(CheckStatusWrapper* status) noexcept
759757
{
760758
return getFullVersion();
761759
}

src/common/config/config.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ inline constexpr int MODE_SUPER = 0;
8888
inline constexpr int MODE_SUPERCLASSIC = 1;
8989
inline constexpr int MODE_CLASSIC = 2;
9090

91-
constexpr const char* CONFIG_FILE = "firebird.conf";
91+
inline constexpr const char* CONFIG_FILE = "firebird.conf";
9292

9393
struct ConfigValue
9494
{
95-
ConfigValue() : intVal(0) {};
96-
constexpr ConfigValue(const char* val) : strVal(val) {};
97-
constexpr ConfigValue(bool val) : boolVal(val) {};
98-
constexpr ConfigValue(int val) : intVal(val) {};
95+
ConfigValue() noexcept : intVal(0) {};
96+
constexpr ConfigValue(const char* val) noexcept : strVal(val) {};
97+
constexpr ConfigValue(bool val) noexcept : boolVal(val) {};
98+
constexpr ConfigValue(int val) noexcept : intVal(val) {};
9999

100100
union
101101
{
@@ -105,12 +105,12 @@ struct ConfigValue
105105
};
106106

107107
// simple bitwise comparison
108-
bool operator== (const ConfigValue& other) const
108+
bool operator== (const ConfigValue& other) const noexcept
109109
{
110110
return this->intVal == other.intVal;
111111
}
112112

113-
bool operator!= (const ConfigValue& other) const
113+
bool operator!= (const ConfigValue& other) const noexcept
114114
{
115115
return !(*this == other);
116116
}
@@ -356,10 +356,10 @@ class Config : public RefCounted, public GlobalStorage
356356
HalfStaticArray<const char*, 4> valuesSource;
357357

358358
// Index of value source, zero if not set
359-
UCHAR sourceIdx[MAX_CONFIG_KEY];
359+
UCHAR sourceIdx[MAX_CONFIG_KEY]{};
360360

361361
// test if given key value was set in config
362-
bool testKey(unsigned int key) const
362+
bool testKey(unsigned int key) const noexcept
363363
{
364364
return sourceIdx[key] != 0;
365365
}
@@ -389,7 +389,7 @@ class Config : public RefCounted, public GlobalStorage
389389
// cases firebird.conf may be also used to specify root.
390390

391391
static void setRootDirectoryFromCommandLine(const PathName& newRoot);
392-
static const PathName* getCommandLineRootDirectory();
392+
static const PathName* getCommandLineRootDirectory() noexcept;
393393

394394
// Master config - needed to provide per-database config
395395
static const RefPtr<const Config>& getDefaultConfig();
@@ -405,20 +405,20 @@ class Config : public RefCounted, public GlobalStorage
405405
bool getBoolean(unsigned int key) const;
406406

407407
// Number of known keys
408-
static unsigned int getKeyCount()
408+
static inline constexpr unsigned int getKeyCount() noexcept
409409
{
410410
return MAX_CONFIG_KEY;
411411
}
412412

413-
static const char* getKeyName(unsigned int key);
413+
static const char* getKeyName(unsigned int key) noexcept;
414414

415415
// false if value is null or key is not exists
416416
bool getValue(unsigned int key, string& str) const;
417417
static bool getDefaultValue(unsigned int key, string& str);
418418
// return true if value is set at some level
419-
bool getIsSet(unsigned int key) const { return testKey(key); }
419+
bool getIsSet(unsigned int key) const noexcept { return testKey(key); }
420420

421-
const char* getValueSource(unsigned int key) const
421+
const char* getValueSource(unsigned int key) const noexcept
422422
{
423423
return valuesSource[sourceIdx[key]];
424424
}
@@ -635,7 +635,7 @@ class FirebirdConf final :
635635
SINT64 asInteger(unsigned int key);
636636
const char* asString(unsigned int key);
637637
FB_BOOLEAN asBoolean(unsigned int key);
638-
unsigned int getVersion(CheckStatusWrapper* status);
638+
unsigned int getVersion(CheckStatusWrapper* status) noexcept;
639639

640640
private:
641641
RefPtr<const Config> config;

0 commit comments

Comments
 (0)