Skip to content

Commit c0518a1

Browse files
committed
Improve noexcept/noreturn information for basic error handling
+ Some misc other changes
1 parent 1e2ef76 commit c0518a1

File tree

5 files changed

+51
-53
lines changed

5 files changed

+51
-53
lines changed

src/common/status.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#include "../common/utils_proto.h"
3636
#include <utility>
3737

38-
const int MAX_ERRMSG_LEN = 128;
39-
const int MAX_ERRSTR_LEN = 1024;
38+
inline constexpr int MAX_ERRMSG_LEN = 128;
39+
inline constexpr int MAX_ERRSTR_LEN = 1024;
4040

4141
namespace Firebird
4242
{
@@ -54,12 +54,12 @@ namespace Firebird
5454
: localStatus(p), localStatusVector(&localStatus, std::forward<Args>(args)...)
5555
{ }
5656

57-
SW* operator->()
57+
SW* operator->() noexcept
5858
{
5959
return &localStatusVector;
6060
}
6161

62-
SW* operator&()
62+
SW* operator&() noexcept
6363
{
6464
return &localStatusVector;
6565
}
@@ -70,12 +70,12 @@ namespace Firebird
7070
return localStatusVector.getErrors()[n];
7171
}
7272

73-
const SW* operator->() const
73+
const SW* operator->() const noexcept
7474
{
7575
return &localStatusVector;
7676
}
7777

78-
const SW* operator&() const
78+
const SW* operator&() const noexcept
7979
{
8080
return &localStatusVector;
8181
}
@@ -89,17 +89,17 @@ namespace Firebird
8989
}
9090
}
9191

92-
void copyTo(SW* to) const
92+
void copyTo(SW* to) const noexcept
9393
{
9494
fb_utils::copyStatus(to, &localStatusVector);
9595
}
9696

97-
void loadFrom(const SW* to)
97+
void loadFrom(const SW* to) noexcept
9898
{
9999
fb_utils::copyStatus(&localStatusVector, to);
100100
}
101101

102-
void raise() const
102+
[[noreturn]] void raise() const
103103
{
104104
Firebird::status_exception::raise(&localStatus);
105105
}
@@ -131,7 +131,7 @@ namespace Firebird
131131
}
132132

133133
public:
134-
static void checkException(LogWrapper* status)
134+
static void checkException(const LogWrapper* status)
135135
{
136136
if (status->dirty && (status->getState() & IStatus::STATE_ERRORS))
137137
iscLogStatus(status->text, status->status);
@@ -152,7 +152,7 @@ namespace Firebird
152152
}
153153

154154
public:
155-
static void checkException(ThrowWrapper* status)
155+
static void checkException(const ThrowWrapper* status)
156156
{
157157
if (status->dirty && (status->getState() & IStatus::STATE_ERRORS))
158158
status_exception::raise(status->status);
@@ -189,7 +189,7 @@ namespace Firebird
189189
}
190190
catch (...)
191191
{
192-
ISC_STATUS statusVector[] = {
192+
const ISC_STATUS statusVector[] = {
193193
isc_arg_gds, isc_random,
194194
isc_arg_string, (ISC_STATUS) "Unrecognized C++ exception",
195195
isc_arg_end};

src/dsql/errd.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ using namespace Jrd;
5858
using namespace Firebird;
5959

6060

61-
static void internal_post(const Arg::StatusVector& v);
61+
[[noreturn]] static void internal_post(const Arg::StatusVector& v);
6262

6363
#ifdef DEV_BUILD
6464
/**
@@ -73,14 +73,13 @@ static void internal_post(const Arg::StatusVector& v);
7373
@param lineno
7474
7575
**/
76-
void ERRD_assert_msg(const char* msg, const char* file, ULONG lineno)
76+
[[noreturn]] void ERRD_assert_msg(const char* msg, const char* file, ULONG lineno)
7777
{
78-
7978
char buffer[MAXPATHLEN + 100];
8079

81-
fb_utils::snprintf(buffer, sizeof(buffer),
82-
"Assertion failure: %s File: %s Line: %ld\n", //dev build
83-
(msg ? msg : ""), (file ? file : ""), lineno);
80+
snprintf(buffer, sizeof(buffer),
81+
"Assertion failure: %s File: %s Line: %" ULONGFORMAT "\n", //dev build
82+
(msg ? msg : ""), (file ? file : ""), lineno);
8483
ERRD_bugcheck(buffer);
8584
}
8685
#endif // DEV_BUILD
@@ -96,10 +95,10 @@ void ERRD_assert_msg(const char* msg, const char* file, ULONG lineno)
9695
@param text
9796
9897
**/
99-
void ERRD_bugcheck(const char* text)
98+
[[noreturn]] void ERRD_bugcheck(const char* text)
10099
{
101100
TEXT s[MAXPATHLEN + 120];
102-
fb_utils::snprintf(s, sizeof(s), "INTERNAL: %s", text); // TXNN
101+
snprintf(s, sizeof(s), "INTERNAL: %s", text);
103102
ERRD_error(s);
104103
}
105104

@@ -120,10 +119,10 @@ void ERRD_bugcheck(const char* text)
120119
@param text
121120
122121
**/
123-
void ERRD_error(const char* text)
122+
[[noreturn]] void ERRD_error(const char* text)
124123
{
125124
TEXT s[MAXPATHLEN + 140];
126-
fb_utils::snprintf(s, sizeof(s), "** DSQL error: %s **\n", text);
125+
snprintf(s, sizeof(s), "** DSQL error: %s **\n", text);
127126
TRACE(s);
128127

129128
status_exception::raise(Arg::Gds(isc_random) << Arg::Str(s));
@@ -165,7 +164,7 @@ void ERRD_post_warning(const Firebird::Arg::StatusVector& v)
165164
@param
166165
167166
**/
168-
void ERRD_post(const Arg::StatusVector& v)
167+
[[noreturn]] void ERRD_post(const Arg::StatusVector& v)
169168
{
170169
fb_assert(v.value()[0] == isc_arg_gds);
171170

@@ -185,7 +184,7 @@ void ERRD_post(const Arg::StatusVector& v)
185184
@param
186185
187186
**/
188-
static void internal_post(const Arg::StatusVector& v)
187+
[[noreturn]] static void internal_post(const Arg::StatusVector& v)
189188
{
190189
// start building resulting vector
191190
Jrd::FbStatusVector* status_vector = JRD_get_thread_data()->tdbb_status_vector;
@@ -219,7 +218,7 @@ static void internal_post(const Arg::StatusVector& v)
219218
220219
221220
**/
222-
void ERRD_punt(const Jrd::FbStatusVector* local)
221+
[[noreturn]] void ERRD_punt(const Jrd::FbStatusVector* local)
223222
{
224223
thread_db* tdbb = JRD_get_thread_data();
225224

src/dsql/errd_proto.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
#include "../jrd/status.h"
2828

2929
#ifdef DEV_BUILD
30-
void ERRD_assert_msg(const char*, const char*, ULONG);
30+
[[noreturn]] void ERRD_assert_msg(const char*, const char*, ULONG);
3131
#endif
3232

33-
void ERRD_bugcheck(const char*);
34-
void ERRD_error(const char*);
35-
void ERRD_post(const Firebird::Arg::StatusVector& v);
33+
[[noreturn]] void ERRD_bugcheck(const char*);
34+
[[noreturn]] void ERRD_error(const char*);
35+
[[noreturn]] void ERRD_post(const Firebird::Arg::StatusVector& v);
3636
void ERRD_post_warning(const Firebird::Arg::StatusVector& v);
37-
void ERRD_punt(const Jrd::FbStatusVector* = 0);
37+
[[noreturn]] void ERRD_punt(const Jrd::FbStatusVector* = 0);
3838

3939
#endif // DSQL_ERRD_PROTO_H
4040

src/jrd/err.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ using namespace Firebird;
5353
//#define JRD_FAILURE_UNKNOWN "<UNKNOWN>" // Used when buffer fails
5454

5555

56-
static void internal_error(ISC_STATUS status, int number, const TEXT* file = NULL, int line = 0);
56+
[[noreturn]] static void internal_error(ISC_STATUS status, int number, const TEXT* file = NULL, int line = 0);
5757
static void post_nothrow(const unsigned lenToAdd, const ISC_STATUS* toAdd, FbStatusVector* statusVector);
5858

5959

60-
void ERR_bugcheck(int number, const TEXT* file, int line)
60+
[[noreturn]] void ERR_bugcheck(int number, const TEXT* file, int line)
6161
{
6262
/**************************************
6363
*
@@ -79,7 +79,7 @@ void ERR_bugcheck(int number, const TEXT* file, int line)
7979
}
8080

8181

82-
void ERR_bugcheck_msg(const TEXT* msg)
82+
[[noreturn]] void ERR_bugcheck_msg(const TEXT* msg)
8383
{
8484
/**************************************
8585
*
@@ -101,7 +101,7 @@ void ERR_bugcheck_msg(const TEXT* msg)
101101
}
102102

103103

104-
void ERR_soft_bugcheck(int number, const TEXT* file, int line)
104+
[[noreturn]] void ERR_soft_bugcheck(int number, const TEXT* file, int line)
105105
{
106106
/**************************************
107107
*
@@ -121,7 +121,7 @@ void ERR_soft_bugcheck(int number, const TEXT* file, int line)
121121
}
122122

123123

124-
void ERR_corrupt(int number)
124+
[[noreturn]] void ERR_corrupt(int number)
125125
{
126126
/**************************************
127127
*
@@ -138,7 +138,7 @@ void ERR_corrupt(int number)
138138
}
139139

140140

141-
void ERR_error(int number)
141+
[[noreturn]] void ERR_error(int number)
142142
{
143143
/**************************************
144144
*
@@ -181,7 +181,7 @@ void ERR_log(int facility, int number, const TEXT* message)
181181
strcpy(errmsg, "Internal error code");
182182

183183
const size_t len = strlen(errmsg);
184-
fb_utils::snprintf(errmsg + len, sizeof(errmsg) - len, " (%d)", number);
184+
snprintf(errmsg + len, sizeof(errmsg) - len, " (%d)", number);
185185

186186
gds__log("Database: %s\n\t%s", (tdbb && tdbb->getAttachment()) ?
187187
tdbb->getAttachment()->att_filename.c_str() : "", errmsg);
@@ -214,7 +214,7 @@ void ERR_post_warning(const Arg::StatusVector& v)
214214
}
215215

216216
const ISC_STATUS* oldVector = statusVector->getWarnings();
217-
unsigned lenOld = fb_utils::statusLength(oldVector);
217+
const unsigned lenOld = fb_utils::statusLength(oldVector);
218218

219219
// check for duplicated error code
220220
if (fb_utils::subStatus(oldVector, lenOld, toAdd, lenToAdd) != ~0u)
@@ -289,7 +289,7 @@ static void post_nothrow(const unsigned lenToAdd, const ISC_STATUS* toAdd, FbSta
289289
}
290290

291291
const ISC_STATUS* oldVector = statusVector->getErrors();
292-
unsigned lenOld = fb_utils::statusLength(oldVector);
292+
const unsigned lenOld = fb_utils::statusLength(oldVector);
293293

294294
// check for duplicated error code
295295
if (fb_utils::subStatus(oldVector, lenOld, toAdd, lenToAdd) != ~0u)
@@ -303,7 +303,7 @@ static void post_nothrow(const unsigned lenToAdd, const ISC_STATUS* toAdd, FbSta
303303
}
304304

305305

306-
void ERR_post(const Arg::StatusVector& v)
306+
[[noreturn]] void ERR_post(const Arg::StatusVector& v)
307307
/**************************************
308308
*
309309
* E R R _ p o s t
@@ -321,7 +321,7 @@ void ERR_post(const Arg::StatusVector& v)
321321
}
322322

323323

324-
void ERR_punt()
324+
[[noreturn]] void ERR_punt()
325325
{
326326
/**************************************
327327
*
@@ -398,7 +398,7 @@ void ERR_append_status(FbStatusVector* status_vector, const Arg::StatusVector& v
398398
}
399399

400400

401-
void ERR_build_status(FbStatusVector* status_vector, const Arg::StatusVector& v)
401+
void ERR_build_status(FbStatusVector* status_vector, const Arg::StatusVector& v) noexcept
402402
{
403403
/**************************************
404404
*
@@ -414,7 +414,7 @@ void ERR_build_status(FbStatusVector* status_vector, const Arg::StatusVector& v)
414414
}
415415

416416

417-
static void internal_error(ISC_STATUS status, int number, const TEXT* file, int line)
417+
[[noreturn]] static void internal_error(ISC_STATUS status, int number, const TEXT* file, int line)
418418
{
419419
/**************************************
420420
*
@@ -445,11 +445,10 @@ static void internal_error(ISC_STATUS status, int number, const TEXT* file, int
445445
break;
446446
}
447447
}
448-
fb_utils::snprintf(errmsg + len, sizeof(errmsg) - len,
449-
" (%d), file: %s line: %d", number, ptr, line);
448+
snprintf(errmsg + len, sizeof(errmsg) - len, " (%d), file: %s line: %d", number, ptr, line);
450449
}
451450
else {
452-
fb_utils::snprintf(errmsg + len, sizeof(errmsg) - len, " (%d)", number);
451+
snprintf(errmsg + len, sizeof(errmsg) - len, " (%d)", number);
453452
}
454453

455454
ERR_post(Arg::Gds(status) << Arg::Str(errmsg));

src/jrd/err_proto.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ enum idx_e {
4747
} //namespace Jrd
4848

4949
void ERR_post_warning(const Firebird::Arg::StatusVector& v);
50-
void ERR_assert(const TEXT*, int);
51-
void ERR_bugcheck(int, const TEXT* = NULL, int = 0);
52-
void ERR_bugcheck_msg(const TEXT*);
53-
void ERR_soft_bugcheck(int, const TEXT*, int);
54-
void ERR_corrupt(int);
55-
void ERR_error(int);
50+
//void ERR_assert(const TEXT*, int);
51+
[[noreturn]] void ERR_bugcheck(int, const TEXT* = NULL, int = 0);
52+
[[noreturn]] void ERR_bugcheck_msg(const TEXT*);
53+
[[noreturn]] void ERR_soft_bugcheck(int, const TEXT*, int);
54+
[[noreturn]] void ERR_corrupt(int);
55+
[[noreturn]] void ERR_error(int);
5656
[[noreturn]] void ERR_post(const Firebird::Arg::StatusVector& v);
5757
void ERR_post_nothrow(const Firebird::Arg::StatusVector& v, Jrd::FbStatusVector* statusVector = NULL);
5858
void ERR_post_nothrow(const Firebird::IStatus* v, Jrd::FbStatusVector* statusVector = NULL);
5959
[[noreturn]] void ERR_punt();
6060
void ERR_warning(const Firebird::Arg::StatusVector& v);
6161
void ERR_log(int, int, const TEXT*);
6262
void ERR_append_status(Jrd::FbStatusVector*, const Firebird::Arg::StatusVector& v);
63-
void ERR_build_status(Jrd::FbStatusVector*, const Firebird::Arg::StatusVector& v);
63+
void ERR_build_status(Jrd::FbStatusVector*, const Firebird::Arg::StatusVector& v) noexcept;
6464

6565
#endif // JRD_ERR_PROTO_H

0 commit comments

Comments
 (0)