mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 10:48:20 +08:00
mdbx: add STATIC_ASSERT_MSG, refine STATIC_ASSERT.
This commit is contained in:
parent
b038767a18
commit
18cf804d0b
@ -31,6 +31,9 @@
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Should be defined before any includes */
|
/* Should be defined before any includes */
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
|
#endif
|
||||||
#ifndef _FILE_OFFSET_BITS
|
#ifndef _FILE_OFFSET_BITS
|
||||||
#define _FILE_OFFSET_BITS 64
|
#define _FILE_OFFSET_BITS 64
|
||||||
#endif
|
#endif
|
||||||
|
15
src/defs.h
15
src/defs.h
@ -368,15 +368,20 @@
|
|||||||
|
|
||||||
#define FIXME "FIXME: " __FILE__ ", " STRINGIFY(__LINE__)
|
#define FIXME "FIXME: " __FILE__ ", " STRINGIFY(__LINE__)
|
||||||
|
|
||||||
#ifndef STATIC_ASSERT
|
#ifndef STATIC_ASSERT_MSG
|
||||||
# if __STDC_VERSION__ >= 201112L
|
# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
|
||||||
# define STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
|
|| __has_feature(c_static_assert)
|
||||||
|
# define STATIC_ASSERT_MSG(expr, msg) _Static_assert(expr, msg)
|
||||||
# elif defined(static_assert)
|
# elif defined(static_assert)
|
||||||
# define STATIC_ASSERT(expr, msg) static_assert(expr, msg)
|
# define STATIC_ASSERT_MSG(expr, msg) static_assert(expr, msg)
|
||||||
# else
|
# else
|
||||||
# define STATIC_ASSERT(expr, msg) switch (0) {case 0:case (expr):;}
|
# define STATIC_ASSERT_MSG(expr, msg) switch (0) {case 0:case (expr):;}
|
||||||
# endif
|
# endif
|
||||||
#endif /* STATIC_ASSERT */
|
#endif /* STATIC_ASSERT */
|
||||||
|
|
||||||
|
#ifndef STATIC_ASSERT
|
||||||
|
# define STATIC_ASSERT(expr) STATIC_ASSERT_MSG(expr, #expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
20
src/osal.c
20
src/osal.c
@ -407,8 +407,8 @@ int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, uint64_t offset) {
|
|||||||
return (rc == MDBX_SUCCESS) ? /* paranoia */ ERROR_READ_FAULT : rc;
|
return (rc == MDBX_SUCCESS) ? /* paranoia */ ERROR_READ_FAULT : rc;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
STATIC_ASSERT(sizeof(off_t) >= sizeof(size_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
ssize_t read = pread(fd, buf, bytes, offset);
|
ssize_t read = pread(fd, buf, bytes, offset);
|
||||||
if (read < 0) {
|
if (read < 0) {
|
||||||
int rc = errno;
|
int rc = errno;
|
||||||
@ -437,8 +437,8 @@ int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes,
|
|||||||
int rc;
|
int rc;
|
||||||
ssize_t written;
|
ssize_t written;
|
||||||
do {
|
do {
|
||||||
STATIC_ASSERT(sizeof(off_t) >= sizeof(size_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
written = pwrite(fd, buf, bytes, offset);
|
written = pwrite(fd, buf, bytes, offset);
|
||||||
if (likely(bytes == (size_t)written))
|
if (likely(bytes == (size_t)written))
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
@ -465,8 +465,8 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
|
|||||||
int rc;
|
int rc;
|
||||||
ssize_t written;
|
ssize_t written;
|
||||||
do {
|
do {
|
||||||
STATIC_ASSERT(sizeof(off_t) >= sizeof(size_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
written = pwritev(fd, iov, iovcnt, offset);
|
written = pwritev(fd, iov, iovcnt, offset);
|
||||||
if (likely(expected_written == (size_t)written))
|
if (likely(expected_written == (size_t)written))
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
@ -556,8 +556,8 @@ int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) {
|
|||||||
#else
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
STATIC_ASSERT(sizeof(off_t) <= sizeof(uint64_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) <= sizeof(uint64_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
if (fstat(fd, &st))
|
if (fstat(fd, &st))
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
@ -574,8 +574,8 @@ int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
|
|||||||
? MDBX_SUCCESS
|
? MDBX_SUCCESS
|
||||||
: mdbx_get_errno_checked();
|
: mdbx_get_errno_checked();
|
||||||
#else
|
#else
|
||||||
STATIC_ASSERT(sizeof(off_t) >= sizeof(size_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
return ftruncate(fd, length) == 0 ? MDBX_SUCCESS : errno;
|
return ftruncate(fd, length) == 0 ? MDBX_SUCCESS : errno;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user