[Git][NTPsec/ntpsec][ntp.util-codacy] wafhelpers/check_sizeof: refactor
James Browning
gitlab at mg.gitlab.com
Mon Sep 14 13:10:48 UTC 2020
James Browning pushed to branch ntp.util-codacy at NTPsec / ntpsec
Commits:
3858b2fb by James Browning at 2020-09-14T06:10:23-07:00
wafhelpers/check_sizeof: refactor
- - - - -
1 changed file:
- wafhelpers/check_sizeof.py
Changes:
=====================================
wafhelpers/check_sizeof.py
=====================================
@@ -21,7 +21,18 @@ int main(void) {
"""
-def check_sizeof_c(ctx, header, header_snippet, sizeof, name, mandatory=True):
+def check_sizeof_common(ctx, header, sizeof):
+ sizeof_ns = sizeof.replace(" ", "_")
+ name = "NTP_SIZEOF_%s" % sizeof_ns.upper()
+
+ if header:
+ ctx.start_msg("Checking sizeof %s (%s)" % (sizeof, header))
+ return "#include <%s>" % header, name
+ ctx.start_msg("Checking sizeof %s" % (sizeof))
+ return "", name
+
+def check_sizeof_c(ctx, header, sizeof, mandatory=True):
+ header_snippet, name = check_sizeof_common(ctx, header, sizeof)
for size in range(2, 13):
try:
ctx.check_cc(
@@ -40,7 +51,8 @@ def check_sizeof_c(ctx, header, header_snippet, sizeof, name, mandatory=True):
raise # never reached.
-def check_sizeof_n(ctx, header, header_snippet, sizeof, name, mandatory=True):
+def check_sizeof_n(ctx, header, sizeof, mandatory=True):
+ header_snippet, name = check_sizeof_common(ctx, header, sizeof)
ctx.check_cc(
fragment=SIZE_FRAG % (header_snippet, sizeof),
define_name=name,
@@ -59,15 +71,5 @@ def check_sizeof(ctx, header, sizeof):
The cross compile check is O(n) slower so we do not run it all the time.
"""
- sizeof_ns = sizeof.replace(" ", "_")
- name = "NTP_SIZEOF_%s" % sizeof_ns.upper()
-
- header_snippet = ""
- if header:
- ctx.start_msg("Checking sizeof %s (%s)" % (sizeof, header))
- header_snippet = "#include <%s>" % header
- else:
- ctx.start_msg("Checking sizeof %s" % (sizeof))
-
cb = check_sizeof_c if ctx.env.ENABLE_CROSS else check_sizeof_n
- cb(ctx, header, header_snippet, sizeof, name, mandatory=True)
+ cb(ctx, header, sizeof, mandatory=True)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/3858b2fb2edba5056a5b047e9572d2e7f760582e
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/3858b2fb2edba5056a5b047e9572d2e7f760582e
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20200914/838abeab/attachment-0001.htm>
More information about the vc
mailing list