Skip to content

Commit fd2ad28

Browse files
authored
fix: improve compiler compatibility and warnings (#647)
* fix: improve compatibility checks for atomic operations - Replace GNUC macro check with __GNUC_PREREQ(4, 1) for more precise version control - Add fallback definition for __GNUC_PREREQ macro when not available * fix: add explicit type casting in gettick_ms() - Add explicit (unsigned int) casting to tv_sec and tv_nsec/tv_usec calculations to prevent potential integer overflow * fix: suppress compiler warnings for unused variable and function - Add (void) cast and inline qualifier to eliminate unused warnings --------- Co-authored-by: tayne3 <tayne3@dingtalk.com>
1 parent 15df63d commit fd2ad28

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

base/hatomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static inline bool atomic_flag_test_and_set(atomic_flag* p) {
5757
#define ATOMIC_INC InterlockedIncrement
5858
#define ATOMIC_DEC InterlockedDecrement
5959

60-
#elif defined(__GNUC__)
60+
#elif __GNUC_PREREQ(4, 1)
6161

6262
#define ATOMIC_FLAG_TEST_AND_SET atomic_flag_test_and_set
6363
static inline bool atomic_flag_test_and_set(atomic_flag* p) {

base/hplatform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@
141141
#warning "Untested compiler!"
142142
#endif
143143

144+
#ifndef __GNUC_PREREQ
145+
#define __GNUC_PREREQ(a, b) 0
146+
#endif
147+
144148
// headers
145149
#ifdef OS_WIN
146150
#ifndef _WIN32_WINNT

base/htime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ unsigned int gettick_ms() {
1515
#elif HAVE_CLOCK_GETTIME
1616
struct timespec ts;
1717
clock_gettime(CLOCK_MONOTONIC, &ts);
18-
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
18+
return (unsigned int)ts.tv_sec * 1000 + (unsigned int)ts.tv_nsec / 1000000;
1919
#else
2020
struct timeval tv;
2121
gettimeofday(&tv, NULL);
22-
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
22+
return (unsigned int)tv.tv_sec * 1000 + (unsigned int)tv.tv_usec / 1000;
2323
#endif
2424
}
2525

event/hloop.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ int hloop_process_events(hloop_t* loop, int timeout_ms) {
187187
// blocktime, nios, loop->nios, ntimers, loop->ntimers, nidles, loop->nidles,
188188
// loop->nactives, npendings, ncbs);
189189
return ncbs;
190+
(void)nios;
190191
}
191192

193+
#ifdef DEBUG
192194
static void hloop_stat_timer_cb(htimer_t* timer) {
193195
hloop_t* loop = timer->loop;
194196
// hlog_set_level(LOG_LEVEL_DEBUG);
@@ -198,6 +200,7 @@ static void hloop_stat_timer_cb(htimer_t* timer) {
198200
(unsigned long long)loop->loop_cnt,
199201
loop->nactives, loop->nios, loop->ntimers, loop->nidles);
200202
}
203+
#endif
201204

202205
static void eventfd_read_cb(hio_t* io, void* buf, int readbytes) {
203206
hloop_t* loop = io->loop;

ssl/wintls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const char* hssl_backend()
8585
return "schannel";
8686
}
8787

88-
static PCCERT_CONTEXT getservercert(const char* path)
88+
static inline PCCERT_CONTEXT getservercert(const char* path)
8989
{
9090
/*
9191
According to the information I searched from the internet, it is not possible to specify an x509 private key and certificate using the

0 commit comments

Comments
 (0)