mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-10 17:28:55 -04:00
[9.18] fix: dev: Change the NS_PER_SEC (and friends) from enum to #define
New version of clang (19) has introduced a stricter checks when mixing
integer (and float types) with enums. In this case, we used enum {}
as C17 doesn't have constexpr yet. Change the time conversion constants
to be #defined constants because of RHEL 8 compiler doesn't consider
static const unsigned int to be constant.
Closes #4845
Backport of MR !9313
Merge branch 'backport-4845-change-NS_PER_SEC-type-from-enum-to-integer-9.18' into 'bind-9.18'
See merge request isc-projects/bind9!9340
This commit is contained in:
commit
0da22fc138
5 changed files with 18 additions and 16 deletions
|
|
@ -2187,9 +2187,9 @@ main(int argc, char *argv[]) {
|
|||
RUNCHECK(isc_time_now(&now));
|
||||
if (isc_time_seconds(&start) == isc_time_seconds(&now))
|
||||
{
|
||||
int us = US_PER_SEC -
|
||||
(isc_time_nanoseconds(&now) /
|
||||
NS_PER_US);
|
||||
unsigned int us = US_PER_SEC -
|
||||
(isc_time_nanoseconds(&now) /
|
||||
NS_PER_US);
|
||||
if (us > US_PER_MS) {
|
||||
usleep(us - US_PER_MS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,15 @@
|
|||
#include <isc/lang.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
enum {
|
||||
MS_PER_SEC = 1000, /*%< Milliseonds per second. */
|
||||
US_PER_MS = 1000, /*%< Microseconds per millisecond. */
|
||||
US_PER_SEC = 1000 * 1000, /*%< Microseconds per second. */
|
||||
NS_PER_US = 1000, /*%< Nanoseconds per millisecond. */
|
||||
NS_PER_MS = 1000 * 1000, /*%< Nanoseconds per microsecond. */
|
||||
NS_PER_SEC = 1000 * 1000 * 1000, /*%< Nanoseconds per second. */
|
||||
};
|
||||
/*
|
||||
* Define various time conversion constants.
|
||||
*/
|
||||
#define MS_PER_SEC 1000U
|
||||
#define US_PER_MS 1000U
|
||||
#define NS_PER_US 1000U
|
||||
#define US_PER_SEC (1000U * 1000U)
|
||||
#define NS_PER_MS (1000U * 1000U)
|
||||
#define NS_PER_SEC (1000U * 1000U * 1000U)
|
||||
|
||||
/***
|
||||
*** Intervals
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ isc_stdtime_get(isc_stdtime_t *t) {
|
|||
FATAL_SYSERROR(errno, "clock_gettime()");
|
||||
}
|
||||
|
||||
REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
|
||||
REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 &&
|
||||
ts.tv_nsec < (long)NS_PER_SEC);
|
||||
|
||||
*t = (isc_stdtime_t)ts.tv_sec;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ time_now(isc_time_t *t, clockid_t clock) {
|
|||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
|
||||
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= (long)NS_PER_SEC) {
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
|
|||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
|
||||
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= (long)NS_PER_SEC) {
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,8 +198,8 @@ void
|
|||
dns_test_nap(uint32_t usec) {
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = usec / 1000000;
|
||||
ts.tv_nsec = (usec % 1000000) * 1000;
|
||||
ts.tv_sec = usec / (long)US_PER_SEC;
|
||||
ts.tv_nsec = (usec % (long)US_PER_SEC) * (long)NS_PER_US;
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue