From 7f5103ec59e1e1da6c32e2bb0a3b1b6e437d57e4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 25 Sep 2014 11:20:04 -0400 Subject: [PATCH 1/3] Require two c99 features (midblock decls, designated initializers) c99 lets us do neat stuff like: { int j, k; foo(&j, &k); int z = j + k; } and also struct point { int x; int y; }; struct point pt = { .x=5, .y=5 }; This commit makes the configure scripts check to make sure your compiler implements them. It also disables our longstanding warning about midblock declarations. Closes ticket 13233. --- changes/require-c99 | 10 ++++++++++ configure.ac | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 changes/require-c99 diff --git a/changes/require-c99 b/changes/require-c99 new file mode 100644 index 0000000000..61d961273a --- /dev/null +++ b/changes/require-c99 @@ -0,0 +1,10 @@ + o New compiler requirements: + - Tor 0.2.6.x requires that your compiler support more of the C99 + language standard than before. The 'configure' script now detects + whether your compiler supports C99 mid-block declarations and + designated initializers. If it does not, Tor will not compile. + + We may revisit this requirement if it turns out that a significant + number of people need to build Tor with compilers that don't + bother implementing a 15-year-old standard. Closes ticket 13233. + diff --git a/configure.ac b/configure.ac index 5aeeeb4025..15154b3414 100644 --- a/configure.ac +++ b/configure.ac @@ -221,6 +221,28 @@ AC_C_FLEXIBLE_ARRAY_MEMBER fi ]) +AC_CACHE_CHECK([for working C99 mid-block declaration syntax], + tor_cv_c_c99_decl, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])], + [tor_cv_c_c99_decl=yes], + [tor_cv_c_c99_decl=no] )]) +if test "$tor_cv_c_c99_decl" != "yes"; then + AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x]) +fi + +AC_CACHE_CHECK([for working C99 designated initializers], + tor_cv_c_c99_designated_init, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([struct s { int a; int b; };], + [[ struct s ss = { .b = 5, .a = 6 }; ]])], + [tor_cv_c_c99_designated_init=yes], + [tor_cv_c_c99_designated_init=no] )]) + +if test "$tor_cv_c_c99_designated_init" != "yes"; then + AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x]) +fi + AC_PATH_PROG([SHA1SUM], [sha1sum], none) AC_PATH_PROG([OPENSSL], [openssl], none) @@ -1500,7 +1522,7 @@ if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xy if test x$have_gcc4 = xyes ; then # These warnings break gcc 3.3.5 and work on gcc 4.0.2 - CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition" + CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition" fi if test x$have_gcc42 = xyes ; then From 0ca83872468af59b94e14fe7fdfcb38cb5a3f496 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 25 Sep 2014 11:22:02 -0400 Subject: [PATCH 2/3] Tweak address.c to use a little c99 syntax Since address.c is the first file to get compiled, let's have it use a little judicious c99 in order to catch broken compilers that somehow make it past our autoconf tests. --- src/common/address.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/address.c b/src/common/address.c index 3a78f0be55..f79736dd0b 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -323,10 +323,9 @@ tor_addr_is_internal_(const tor_addr_t *addr, int for_listening, { uint32_t iph4 = 0; uint32_t iph6[4]; - sa_family_t v_family; tor_assert(addr); - v_family = tor_addr_family(addr); + sa_family_t v_family = tor_addr_family(addr); if (v_family == AF_INET) { iph4 = tor_addr_to_ipv4h(addr); @@ -605,7 +604,7 @@ tor_addr_parse_mask_ports(const char *s, int any_flag=0, v4map=0; sa_family_t family; struct in6_addr in6_tmp; - struct in_addr in_tmp; + struct in_addr in_tmp = { .s_addr = 0 }; tor_assert(s); tor_assert(addr_out); @@ -666,7 +665,7 @@ tor_addr_parse_mask_ports(const char *s, tor_addr_from_ipv4h(addr_out, 0); any_flag = 1; } else if (!strcmp(address, "*6") && (flags & TAPMP_EXTENDED_STAR)) { - static char nil_bytes[16] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }; + static char nil_bytes[16] = { [0]=0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }; family = AF_INET6; tor_addr_from_ipv6_bytes(addr_out, nil_bytes); any_flag = 1; From b0767e85b8214677b7989723e55fbbf3ce24f3f2 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 25 Sep 2014 11:36:28 -0400 Subject: [PATCH 3/3] Tell autoconf to make the compiler act as c99 Apparently some compilers want extra switches. --- configure.ac | 1 + src/common/address.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 15154b3414..416215836e 100644 --- a/configure.ac +++ b/configure.ac @@ -191,6 +191,7 @@ AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue) AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue) AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue) AM_PROG_CC_C_O +AC_PROG_CC_C99 AC_ARG_VAR(PYTHON) AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3]) diff --git a/src/common/address.c b/src/common/address.c index f79736dd0b..07b76597da 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -471,7 +471,6 @@ tor_addr_parse_PTR_name(tor_addr_t *result, const char *address, if (!strcasecmpend(address, ".ip6.arpa")) { const char *cp; - int i; int n0, n1; struct in6_addr in6; @@ -479,7 +478,7 @@ tor_addr_parse_PTR_name(tor_addr_t *result, const char *address, return -1; cp = address; - for (i = 0; i < 16; ++i) { + for (int i = 0; i < 16; ++i) { n0 = hex_decode_digit(*cp++); /* The low-order nybble appears first. */ if (*cp++ != '.') return -1; /* Then a dot. */ n1 = hex_decode_digit(*cp++); /* The high-order nybble appears first. */