mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
refactor: use C++ static_assert; remove TR_STATIC_ASERT (#1959)
This commit is contained in:
@@ -706,9 +706,9 @@ bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, tr_error
|
|||||||
|
|
||||||
bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t origin, uint64_t* new_offset, tr_error** error)
|
bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t origin, uint64_t* new_offset, tr_error** error)
|
||||||
{
|
{
|
||||||
TR_STATIC_ASSERT(TR_SEEK_SET == SEEK_SET, "values should match");
|
static_assert(TR_SEEK_SET == SEEK_SET, "values should match");
|
||||||
TR_STATIC_ASSERT(TR_SEEK_CUR == SEEK_CUR, "values should match");
|
static_assert(TR_SEEK_CUR == SEEK_CUR, "values should match");
|
||||||
TR_STATIC_ASSERT(TR_SEEK_END == SEEK_END, "values should match");
|
static_assert(TR_SEEK_END == SEEK_END, "values should match");
|
||||||
|
|
||||||
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
||||||
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
|
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
|
||||||
@@ -716,7 +716,7 @@ bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t ori
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
off_t my_new_offset;
|
off_t my_new_offset;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(*new_offset) >= sizeof(my_new_offset), "");
|
static_assert(sizeof(*new_offset) >= sizeof(my_new_offset), "");
|
||||||
|
|
||||||
my_new_offset = lseek(handle, offset, origin);
|
my_new_offset = lseek(handle, offset, origin);
|
||||||
|
|
||||||
@@ -745,7 +745,7 @@ bool tr_sys_file_read(tr_sys_file_t handle, void* buffer, uint64_t size, uint64_
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
ssize_t my_bytes_read;
|
ssize_t my_bytes_read;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
|
static_assert(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
|
||||||
|
|
||||||
my_bytes_read = read(handle, buffer, size);
|
my_bytes_read = read(handle, buffer, size);
|
||||||
|
|
||||||
@@ -782,7 +782,7 @@ bool tr_sys_file_read_at(
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
ssize_t my_bytes_read;
|
ssize_t my_bytes_read;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
|
static_assert(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
|
||||||
|
|
||||||
#ifdef HAVE_PREAD
|
#ifdef HAVE_PREAD
|
||||||
|
|
||||||
@@ -826,7 +826,7 @@ bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size,
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
ssize_t my_bytes_written;
|
ssize_t my_bytes_written;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
|
static_assert(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
|
||||||
|
|
||||||
my_bytes_written = write(handle, buffer, size);
|
my_bytes_written = write(handle, buffer, size);
|
||||||
|
|
||||||
@@ -863,7 +863,7 @@ bool tr_sys_file_write_at(
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
ssize_t my_bytes_written;
|
ssize_t my_bytes_written;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
|
static_assert(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
|
||||||
|
|
||||||
#ifdef HAVE_PWRITE
|
#ifdef HAVE_PWRITE
|
||||||
|
|
||||||
|
|||||||
@@ -998,9 +998,9 @@ bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, tr_error
|
|||||||
|
|
||||||
bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t origin, uint64_t* new_offset, tr_error** error)
|
bool tr_sys_file_seek(tr_sys_file_t handle, int64_t offset, tr_seek_origin_t origin, uint64_t* new_offset, tr_error** error)
|
||||||
{
|
{
|
||||||
TR_STATIC_ASSERT(TR_SEEK_SET == FILE_BEGIN, "values should match");
|
static_assert(TR_SEEK_SET == FILE_BEGIN, "values should match");
|
||||||
TR_STATIC_ASSERT(TR_SEEK_CUR == FILE_CURRENT, "values should match");
|
static_assert(TR_SEEK_CUR == FILE_CURRENT, "values should match");
|
||||||
TR_STATIC_ASSERT(TR_SEEK_END == FILE_END, "values should match");
|
static_assert(TR_SEEK_END == FILE_END, "values should match");
|
||||||
|
|
||||||
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
||||||
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
|
TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
|
||||||
@@ -1387,7 +1387,7 @@ tr_sys_dir_t tr_sys_dir_open(char const* path, tr_error** error)
|
|||||||
{
|
{
|
||||||
#ifndef __clang__
|
#ifndef __clang__
|
||||||
/* Clang gives "static_assert expression is not an integral constant expression" error */
|
/* Clang gives "static_assert expression is not an integral constant expression" error */
|
||||||
TR_STATIC_ASSERT(TR_BAD_SYS_DIR == nullptr, "values should match");
|
static_assert(TR_BAD_SYS_DIR == nullptr, "values should match");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TR_ASSERT(path != nullptr);
|
TR_ASSERT(path != nullptr);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ static bool tr_spawn_async_in_parent(int pipe_fd, tr_error** error)
|
|||||||
int child_errno;
|
int child_errno;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
|
|
||||||
TR_STATIC_ASSERT(sizeof(child_errno) == sizeof(errno), "");
|
static_assert(sizeof(child_errno) == sizeof(errno), "");
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ int tr_lpdInit(tr_session* ss, [[maybe_unused]] tr_address* tr_addr)
|
|||||||
* string handling in tr_lpdSendAnnounce() and tr_lpdConsiderAnnounce().
|
* string handling in tr_lpdSendAnnounce() and tr_lpdConsiderAnnounce().
|
||||||
* However, the code should work as long as interfaces to the rest of
|
* However, the code should work as long as interfaces to the rest of
|
||||||
* libtransmission are compatible with char* strings. */
|
* libtransmission are compatible with char* strings. */
|
||||||
TR_STATIC_ASSERT(sizeof(((struct tr_info*)nullptr)->hashString[0]) == sizeof(char), "");
|
static_assert(sizeof(((struct tr_info*)nullptr)->hashString[0]) == sizeof(char), "");
|
||||||
|
|
||||||
struct ip_mreq mcastReq;
|
struct ip_mreq mcastReq;
|
||||||
int const opt_on = 1;
|
int const opt_on = 1;
|
||||||
|
|||||||
@@ -114,26 +114,6 @@
|
|||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
|
||||||
/**
|
|
||||||
* @def TR_STATIC_ASSERT
|
|
||||||
* @brief This helper allows to perform static checks at compile time
|
|
||||||
*/
|
|
||||||
#if defined(__cplusplus) || defined(static_assert)
|
|
||||||
#define TR_STATIC_ASSERT static_assert
|
|
||||||
#elif __has_feature(c_static_assert) || __has_extension(c_static_assert) || TR_GNUC_CHECK_VERSION(4, 6)
|
|
||||||
#define TR_STATIC_ASSERT _Static_assert
|
|
||||||
#else
|
|
||||||
#define TR_STATIC_ASSERT(x, msg) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
((void)sizeof(x)); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/***
|
|
||||||
****
|
|
||||||
***/
|
|
||||||
|
|
||||||
/* Only use this macro to suppress false-positive alignment warnings */
|
/* Only use this macro to suppress false-positive alignment warnings */
|
||||||
#define TR_DISCARD_ALIGN(ptr, type) ((type)(void*)(ptr))
|
#define TR_DISCARD_ALIGN(ptr, type) ((type)(void*)(ptr))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user