Skip to content

Commit 4c9e5ef

Browse files
committed
Fix conversion warnings, and mapHeader wrong error value
+ constexpr and some noexcepts
1 parent 6e3f779 commit 4c9e5ef

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/jrd/replication/ChangeLog.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ using namespace Replication;
6666

6767
namespace
6868
{
69-
const unsigned FLUSH_WAIT_INTERVAL = 1; // milliseconds
69+
inline constexpr unsigned FLUSH_WAIT_INTERVAL = 1; // milliseconds
7070

71-
const unsigned NO_SPACE_TIMEOUT = 10; // seconds
72-
const unsigned NO_SPACE_RETRIES = 6; // up to one minute
71+
inline constexpr unsigned NO_SPACE_TIMEOUT = 10; // seconds
72+
inline constexpr unsigned NO_SPACE_RETRIES = 6; // up to one minute
7373

74-
const unsigned COPY_BLOCK_SIZE = 64 * 1024; // 64 KB
74+
inline constexpr unsigned COPY_BLOCK_SIZE = 64 * 1024; // 64 KB
7575

76-
const char* FILENAME_PATTERN = "%s.journal-%09" UQUADFORMAT;
76+
inline constexpr const char* FILENAME_PATTERN = "%s.journal-%09" UQUADFORMAT;
7777

78-
const char* FILENAME_WILDCARD = "$(filename)";
79-
const char* PATHNAME_WILDCARD = "$(pathname)";
80-
const char* ARCHPATHNAME_WILDCARD = "$(archivepathname)";
78+
inline constexpr const char* FILENAME_WILDCARD = "$(filename)";
79+
inline constexpr const char* PATHNAME_WILDCARD = "$(pathname)";
80+
inline constexpr const char* ARCHPATHNAME_WILDCARD = "$(archivepathname)";
8181

8282
static THREAD_ENTRY_DECLARE archiver_thread(THREAD_ENTRY_PARAM arg)
8383
{
@@ -300,7 +300,7 @@ void ChangeLog::Segment::mapHeader()
300300
m_mapping = CreateFileMapping((HANDLE) _get_osfhandle(m_handle), NULL, PAGE_READWRITE,
301301
0, sizeof(SegmentHeader), NULL);
302302

303-
if (m_mapping == INVALID_HANDLE_VALUE)
303+
if (!m_mapping)
304304
raiseError("Journal file %s mapping failed (error %d)", m_filename.c_str(), ERRNO);
305305

306306
auto address = MapViewOfFile(m_mapping, FILE_MAP_READ | FILE_MAP_WRITE,
@@ -323,7 +323,7 @@ void ChangeLog::Segment::unmapHeader()
323323
#ifdef WIN_NT
324324
UnmapViewOfFile(m_header);
325325
CloseHandle(m_mapping);
326-
m_mapping = INVALID_HANDLE_VALUE;
326+
m_mapping = 0;
327327
#else
328328
munmap(m_header, sizeof(SegmentHeader));
329329
#endif
@@ -683,13 +683,13 @@ bool ChangeLog::archiveExecute(Segment* segment)
683683
size_t pos;
684684

685685
while ( (pos = archiveCommand.find(FILENAME_WILDCARD)) != string::npos)
686-
archiveCommand.replace(pos, strlen(FILENAME_WILDCARD), filename);
686+
archiveCommand.replace(pos, fb_strlen(FILENAME_WILDCARD), filename);
687687

688688
while ( (pos = archiveCommand.find(PATHNAME_WILDCARD)) != string::npos)
689-
archiveCommand.replace(pos, strlen(PATHNAME_WILDCARD), pathname);
689+
archiveCommand.replace(pos, fb_strlen(PATHNAME_WILDCARD), pathname);
690690

691691
while ( (pos = archiveCommand.find(ARCHPATHNAME_WILDCARD)) != string::npos)
692-
archiveCommand.replace(pos, strlen(ARCHPATHNAME_WILDCARD), archpathname);
692+
archiveCommand.replace(pos, fb_strlen(ARCHPATHNAME_WILDCARD), archpathname);
693693

694694
LockCheckout checkout(this);
695695

@@ -944,7 +944,7 @@ ChangeLog::Segment* ChangeLog::createSegment()
944944

945945
const auto fd = os_utils::openCreateSharedFile(filename.c_str(), O_EXCL | O_BINARY);
946946

947-
SegmentHeader dummyHeader = {0};
947+
const SegmentHeader dummyHeader = {0};
948948
if (::write(fd, &dummyHeader, sizeof(SegmentHeader)) != sizeof(SegmentHeader))
949949
{
950950
::close(fd);

src/jrd/replication/ChangeLog.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ namespace Replication
5555
FB_UINT64 hdr_length;
5656
};
5757

58-
const char CHANGELOG_SIGNATURE[] = "FBCHANGELOG";
58+
inline constexpr char CHANGELOG_SIGNATURE[] = "FBCHANGELOG";
5959

60-
const USHORT CHANGELOG_VERSION_1 = 1;
61-
const USHORT CHANGELOG_CURRENT_VERSION = CHANGELOG_VERSION_1;
60+
inline constexpr USHORT CHANGELOG_VERSION_1 = 1;
61+
inline constexpr USHORT CHANGELOG_CURRENT_VERSION = CHANGELOG_VERSION_1;
6262

6363
class ChangeLog : protected Firebird::PermanentStorage, public Firebird::IpcObject
6464
{
@@ -77,11 +77,11 @@ namespace Replication
7777
};
7878

7979
// Shared memory layout format
80-
static const USHORT STATE_VERSION = 1;
80+
static inline constexpr USHORT STATE_VERSION = 1;
8181
// Mapping size (not extendable for the time being)
82-
static const ULONG STATE_MAPPING_SIZE = 64 * 1024; // 64 KB
82+
static inline constexpr ULONG STATE_MAPPING_SIZE = 64 * 1024; // 64 KB
8383
// Max number of processes accessing the shared state
84-
static const ULONG PID_CAPACITY = (STATE_MAPPING_SIZE - offsetof(State, pids)) / sizeof(int); // ~16K
84+
static inline constexpr ULONG PID_CAPACITY = (STATE_MAPPING_SIZE - offsetof(State, pids)) / sizeof(int); // ~16K
8585

8686
// RAII helper to lock the shared state
8787

@@ -148,27 +148,27 @@ namespace Replication
148148
void append(ULONG length, const UCHAR* data);
149149
void copyTo(const Firebird::PathName& filename) const;
150150

151-
bool isEmpty() const
151+
bool isEmpty() const noexcept
152152
{
153153
return (m_header->hdr_length == sizeof(SegmentHeader));
154154
}
155155

156-
bool hasData() const
156+
bool hasData() const noexcept
157157
{
158158
return (m_header->hdr_length > sizeof(SegmentHeader));
159159
}
160160

161-
ULONG getLength() const
161+
ULONG getLength() const noexcept
162162
{
163163
return m_header->hdr_length;
164164
}
165165

166-
FB_UINT64 getSequence() const
166+
FB_UINT64 getSequence() const noexcept
167167
{
168168
return m_header->hdr_sequence;
169169
}
170170

171-
SegmentState getState() const
171+
SegmentState getState() const noexcept
172172
{
173173
return m_header->hdr_state;
174174
}
@@ -180,7 +180,7 @@ namespace Replication
180180

181181
Firebird::PathName getFileName() const;
182182

183-
const Firebird::PathName& getPathName() const
183+
const Firebird::PathName& getPathName() const noexcept
184184
{
185185
return m_filename;
186186
}
@@ -197,7 +197,7 @@ namespace Replication
197197
SegmentHeader m_builtinHeader; // used by free segments when there is no mapping
198198

199199
#ifdef WIN_NT
200-
HANDLE m_mapping;
200+
HANDLE m_mapping = 0;
201201
#endif
202202
};
203203

0 commit comments

Comments
 (0)