Skip to content

Commit 50c1c7f

Browse files
authored
Fix keyword is hidden by macro definition compiler warning (#209)
* Do not redefine keyword thread_local * Eliminate implicit type conversions * Add news item * Remove unused inline functions in timeconv.h * Add note on `thread_local` to src/README.md
1 parent 4033e81 commit 50c1c7f

File tree

6 files changed

+11
-21
lines changed

6 files changed

+11
-21
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# later (development version)
22

3+
* Fixed #208: Fixed `keyword is hidden by macro definition` compiler warning when using a C23 compiler. (@shikokuchuo, #209)
4+
35
# later 1.4.1
46

57
* Fixed #203: Resolves an issue where packages that have `LinkingTo: later` (including `promises` and `httpuv`) and were built against `later` 1.4.0, would fail to load on systems that actually had older versions of `later` installed, erroring out with the message "function 'execLaterFdNative' not provided by package 'later'". With this fix, such dependent packages should gracefully deal with older versions at load time, and complain with helpful error messages if newer C interfaces (than are available on the installed `later`) are accessed. (#204)

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The tinycthread library is from https://github.com/tinycthread/tinycthread, and
1010

1111
To work around the problem of linking to (incorrect) system functions with the same name, our version of tinycthread has modified names for all externally-visible functions and values: they all begin with `tct_`.
1212

13-
We also added a dummry header file called `badthreads.h`. For all of the names from C11 threads.h, it `#define`s them to a value that will cause an error at compile time. This is to make sure that we don't accidentally use anything from threads.h.
13+
We also added a dummy header file called `badthreads.h`. For all of the names from C11 threads.h, it `#define`s them to a value that will cause an error at compile time. This is to make sure that we don't accidentally use anything from threads.h. Note: `thread_local` is no longer redefined as it has become a keyword in C23 - it is not used in our code base and we should take care not to use it.
1414

1515
There is another change that we have made to tinycthread is in `tinycthread.h`. It is a workaround for building on CRAN's Solaris build machine which was needed at some point in the past. Note that when we tested on a Solaris VM, it didn't seem to be necessary, but we kept it there just to be safe, because we can't actually test on the CRAN Solaris build machine.
1616

src/badthreads.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define cnd_wait THREADS_H_ERROR
4646
#define cnd_timedwait THREADS_H_ERROR
4747
#define cnd_destroy THREADS_H_ERROR
48-
#define thread_local THREADS_H_ERROR
48+
// #define thread_local THREADS_H_ERROR /* Don't redefine thread_local as it is a keyword in C23 */
4949
#define tss_t THREADS_H_ERROR
5050
#define TSS_DTOR_ITERATIONS THREADS_H_ERROR
5151
#define tss_dtor_t THREADS_H_ERROR

src/fd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int wait_thread(void *arg) {
119119
do {
120120
// Never wait for longer than ~1 second so we can check for cancellation
121121
waitFor = std::fmin(waitFor, 1.024);
122-
ready = LATER_POLL_FUNC(args->fds.data(), args->fds.size(), static_cast<int>(waitFor * 1000));
122+
ready = LATER_POLL_FUNC(args->fds.data(), static_cast<LATER_NFDS_T>(args->fds.size()), static_cast<int>(waitFor * 1000));
123123
if (!args->active->load()) return 1;
124124
if (ready) break;
125125
} while ((waitFor = args->timeout.diff_secs(Timestamp())) > 0);

src/fd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
#ifdef _WIN32
1414
#define LATER_POLL_FUNC WSAPoll
15+
#define LATER_NFDS_T ULONG
1516
#else
1617
#define LATER_POLL_FUNC poll
18+
#define LATER_NFDS_T nfds_t
1719
#endif
1820

1921
#endif // _LATER_FD_H_

src/timeconv.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,16 @@
88
// anyone who uses these functions.
99
#include "tinycthread.h"
1010

11-
inline timespec timevalToTimespec(const timeval& tv) {
12-
timespec ts;
13-
ts.tv_sec = tv.tv_sec;
14-
ts.tv_nsec = tv.tv_usec * 1000;
15-
return ts;
16-
}
17-
18-
inline timeval timespecToTimeval(const timespec& ts) {
19-
timeval tv;
20-
tv.tv_sec = ts.tv_sec;
21-
tv.tv_usec = ts.tv_nsec / 1000;
22-
return tv;
23-
}
24-
2511
inline timespec addSeconds(const timespec& time, double secs) {
2612
timespec ts = time;
2713
ts.tv_sec += (time_t)secs;
28-
ts.tv_nsec += (secs - (time_t)secs) * 1e9;
14+
ts.tv_nsec += (secs - (time_t)secs) * 1e9L;
2915
if (ts.tv_nsec < 0) {
30-
ts.tv_nsec += 1e9;
16+
ts.tv_nsec += 1e9L;
3117
ts.tv_sec--;
3218
}
33-
if (ts.tv_nsec >= 1e9) {
34-
ts.tv_nsec -= 1e9;
19+
if (ts.tv_nsec >= 1e9L) {
20+
ts.tv_nsec -= 1e9L;
3521
ts.tv_sec++;
3622
}
3723
return ts;

0 commit comments

Comments
 (0)