[Git][NTPsec/ntpsec][master] Use waf's built-in struct field existence checks
Matt Selsky
gitlab at mg.gitlab.com
Tue Feb 7 14:24:51 UTC 2017
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
57bf0bec by Matt Selsky at 2017-02-07T09:21:41-05:00
Use waf's built-in struct field existence checks
- - - - -
6 changed files:
- devel/ifdex-ignores
- libntp/clockwork.c
- ntpfrob/tickadj.c
- ntptime/ntptime.c
- − wafhelpers/check_structfield.py
- wafhelpers/configure.py
Changes:
=====================================
devel/ifdex-ignores
=====================================
--- a/devel/ifdex-ignores
+++ b/devel/ifdex-ignores
@@ -190,10 +190,10 @@ __BUILTIN_VA_ARG_INCR # In ntpd/ntp_parser.tab.c
__SIZE_TYPE__ # In ntpd/ntp_parser.tab.c
EREALLOC_.*
INTPTR_MAX # Unity
-STRUCT_TIMEX_HAS_MODES
-STRUCT_TIMEX_HAS_TIME_TICK
-STRUCT_NTPTIMEVAL_HAS_TAI
-STRUCT_NTPTIMEVAL_HAS_TIME_TV_NSEC
+HAVE_STRUCT_TIMEX_MODES
+HAVE_STRUCT_TIMEX_TIME_TICK
+HAVE_STRUCT_NTPTIMEVAL_TAI
+HAVE_STRUCT_NTPTIMEVAL_TIME_TV_NSEC
# Inaccessible port guards
SYS_CYGWIN32
=====================================
libntp/clockwork.c
=====================================
--- a/libntp/clockwork.c
+++ b/libntp/clockwork.c
@@ -120,7 +120,7 @@ int ntp_gettime(struct ntptimeval *ntv)
ntv->time = tntx.time;
ntv->maxerror = tntx.maxerror;
ntv->esterror = tntx.esterror;
-#if defined(STRUCT_NTPTIMEVAL_HAS_TAI)
+#if defined(HAVE_STRUCT_NTPTIMEVAL_TAI)
ntv->tai = tntx.tai;
#endif
return result;
=====================================
ntpfrob/tickadj.c
=====================================
--- a/ntpfrob/tickadj.c
+++ b/ntpfrob/tickadj.c
@@ -37,11 +37,11 @@ void tickadj(const bool json, const int newtick)
#else
if (newtick != 0)
{
-#ifdef STRUCT_TIMEX_HAS_TIME_TICK
+#ifdef HAVE_STRUCT_TIMEX_TIME_TICK
if ( (txc.time_tick = newtick) < 1 )
#else
if ( (txc.tick = newtick) < 1 )
-#endif /* STRUCT_TIMEX_HAS_TIME_TICK */
+#endif /* HAVE_STRUCT_TIMEX_TIME_TICK */
{
fprintf(stderr, "ntpfrob: silly value for tick: %d\n", newtick);
exit(1);
@@ -49,11 +49,11 @@ void tickadj(const bool json, const int newtick)
#ifdef MOD_TIMETICK
txc.modes = MOD_TIMETICK;
#else
-#ifdef STRUCT_TIMEX_HAS_MODES
+#ifdef HAVE_STRUCT_TIMEX_MODES
txc.modes = ADJ_TICK;
#else
txc.mode = ADJ_TICK;
-#endif /* STRUCT_TIMEX_HAS_MODES */
+#endif /* HAVE_STRUCT_TIMEX_MODES */
#endif /* MOD_TIMETICK */
}
else
@@ -61,11 +61,11 @@ void tickadj(const bool json, const int newtick)
#ifdef MOD_TIMETICK
txc.modes = 0;
#else
-#ifdef STRUCT_TIMEX_HAS_MODES
+#ifdef HAVE_STRUCT_TIMEX_MODES
txc.modes = 0;
#else
txc.mode = 0;
-#endif /* STRUCT_TIMEX_HAS_MODES */
+#endif /* HAVE_STRUCT_TIMEX_MODES */
#endif /* MOD_TIMETICK */
}
@@ -75,7 +75,7 @@ void tickadj(const bool json, const int newtick)
}
else
{
-#ifdef STRUCT_TIMEX_HAS_TIME_TICK
+#ifdef HAVE_STRUCT_TIMEX_TIME_TICK
if (json)
printf("{\"tick\":%ld,\"tick_adj\":%ld}\n",
txc.time_tick, txc.tickadj);
@@ -87,7 +87,7 @@ void tickadj(const bool json, const int newtick)
printf("{\"tick\":%ld}\n", txc.tick);
else
printf("tick = %ld\n", txc.tick);
-#endif /* STRUCT_TIMEX_HAS_TIME_TICK */
+#endif /* HAVE_STRUCT_TIMEX_TIME_TICK */
}
#endif /* HAVE_ADJTIMEX */
=====================================
ntptime/ntptime.c
=====================================
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -20,7 +20,7 @@
#include <setjmp.h>
#include <stdbool.h>
-#ifdef STRUCT_NTPTIMEVAL_HAS_TIME_TV_NSEC
+#ifdef HAVE_STRUCT_NTPTIMEVAL_TIME_TV_NSEC
#define tv_frac_sec tv_nsec
#else
#define tv_frac_sec tv_usec
@@ -49,7 +49,7 @@ int ntp_gettime(struct ntptimeval *ntv)
ntv->time = tntx.time;
ntv->maxerror = tntx.maxerror;
ntv->esterror = tntx.esterror;
-#if defined(STRUCT_NTPTIMEVAL_HAS_TAI)
+#if defined(HAVE_STRUCT_NTPTIMEVAL_TAI)
ntv->tai = tntx.tai;
#endif
return result;
@@ -341,11 +341,11 @@ main(
(int)time_frac,
ctime_r((time_t *)&ntv.time.tv_sec, ascbuf));
-#if defined(STRUCT_NTPTIMEVAL_HAS_TAI)
+#if defined(HAVE_STRUCT_NTPTIMEVAL_TAI)
printf(json ? jfmt5 : ofmt5, (long)ntv.tai);
#else
fputs(json ? jfmt6 : ofmt6, stdout);
-#endif /* STRUCT_NTPTIMEVAL_HAS_TAI */
+#endif /* HAVE_STRUCT_NTPTIMEVAL_TAI */
}
status = ntp_adjtime_ns(&ntx);
if (status < 0) {
=====================================
wafhelpers/check_structfield.py deleted
=====================================
--- a/wafhelpers/check_structfield.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from waflib.Configure import conf
-
-TYPE_FRAG = """
-#include <stdint.h>
-#include <sys/types.h>
-%s
-int main(void) {
- struct %s x;
- if (sizeof (x.%s))
- return 0;
- return 0;
-}
-"""
-
-
- at conf
-def check_structfield(ctx, fld, type, hdrs, mandatory=False):
- name = "STRUCT_%s_HAS_%s" % (type.upper(), fld.upper().replace('.', '_'))
- src = ""
- for hdr in hdrs:
- src += "#include <%s>\n" % hdr
- ctx.check_cc(
- fragment=TYPE_FRAG % (src, type, fld),
- define_name=name,
- execute=False,
- msg="Checking for %s in struct %s" % (fld, type),
- mandatory=mandatory,
- comment="Whether struct '%s' has field '%s'" % (type, fld)
- )
=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -162,7 +162,6 @@ def cmd_configure(ctx, config):
ctx.setenv("main", ctx.env.derive())
from wafhelpers.check_sizeof import check_sizeof
- from wafhelpers.check_structfield import check_structfield
for opt in opt_map:
ctx.env[opt] = opt_map[opt]
@@ -257,14 +256,14 @@ def cmd_configure(ctx, config):
ctx.check_cc(type_name=s, header_name=h, mandatory=False)
structure_fields = (
- ("time_tick", "timex", ["sys/time.h", "sys/timex.h"]),
- ("modes", "timex", ["sys/time.h", "sys/timex.h"]),
- ("time.tv_nsec", "ntptimeval", ["sys/time.h", "sys/timex.h"]),
- ("tai", "ntptimeval", ["sys/time.h", "sys/timex.h"]),
+ ("time_tick", "struct timex", ["sys/time.h", "sys/timex.h"]),
+ ("modes", "struct timex", ["sys/time.h", "sys/timex.h"]),
+ ("time.tv_nsec", "struct ntptimeval", ["sys/time.h", "sys/timex.h"]),
+ ("tai", "struct ntptimeval", ["sys/time.h", "sys/timex.h"]),
# first in glibc 2.12
)
for (f, s, h) in structure_fields:
- check_structfield(ctx, f, s, h)
+ ctx.check_cc(type_name=s, field_name=f, header_name=h, mandatory=False)
# mostly used by timetoa.h and timespecops.h
sizeofs = [
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/57bf0bec28cab251e3d9d1f5e10005651c502171
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170207/e6d277a0/attachment.html>
More information about the vc
mailing list