Skip to contentSkip to conversation

Remove flexible array member autoconf check

PATCH In review Arne Schwabe 2 participants 4 messages Mar 28, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 Remove flexible array member autoconf check

This is configure macro that tries out how to declare a variable array at the end of struct. This has been standardised in C99, so there is no more need for non C99 magic. See also this stackoverflow discussion:

https://stackoverflow.com/questions/14643406/whats-the-need-of-array-with-zero-elements

Patch V2: Also remove AX_EMPTY_ARRAY from configure.ac

---
 config-msvc.h           |  1 -
 configure.ac            |  1 -
 m4/ax_emptyarray.m4     | 40 ----------------------------------------
 src/openvpn/circ_list.h |  2 +-
 src/openvpn/syshead.h   |  2 --
 5 files changed, 1 insertion(+), 45 deletions(-)
 delete mode 100644 m4/ax_emptyarray.m4
config-msvc.h +0 -1
index e430ca96f..0260927ce 100644
@@ -119,7 +119,6 @@
 #define inline __inline
 #endif
 
-#define EMPTY_ARRAY_SIZE 0
 #define TARGET_WIN32 1
 #define TARGET_ALIAS "Windows-MSVC"
 
configure.ac +0 -1
index 428bebeda..c17266a0a 100644
@@ -421,7 +421,6 @@ AC_TYPE_SIGNAL
 AX_CPP_VARARG_MACRO_ISO
 AX_CPP_VARARG_MACRO_GCC
 AX_TYPE_SOCKLEN_T
-AX_EMPTY_ARRAY
 AC_CHECK_SIZEOF([unsigned int])
 AC_CHECK_SIZEOF([unsigned long])
 AC_CHECK_HEADERS([ \
m4/ax_emptyarray.m4 deleted +0 -40
deleted file mode 100644
index c6781c179..000000000
@@ -1,40 +0,0 @@
-dnl @synopsis AX_EMPTY_ARRAY
-dnl
-dnl Define EMPTY_ARRAY_SIZE to be either "0"
-dnl or "" depending on which syntax the compiler
-dnl prefers for empty arrays in structs.
-dnl
-dnl @version
-dnl @author James Yonan <[email protected]...>
-AC_DEFUN([AX_EMPTY_ARRAY], [
-	AS_VAR_PUSHDEF([VAR],[ax_cv_c_empty_array])dnl
-	AC_CACHE_CHECK(
-		[for C compiler empty array size],
-		[VAR],
-		[AC_COMPILE_IFELSE(
-			[AC_LANG_PROGRAM(
-				,
-				[[
-struct { int foo; int bar[0]; } mystruct;
-				]]
-			)],
-			[VAR=0],
-			[AC_COMPILE_IFELSE(
-				[AC_LANG_PROGRAM(
-					,
-					[[
-struct { int foo; int bar[]; } mystruct;
-					]]
-				)],
-				[VAR=],
-				[AC_MSG_ERROR([C compiler is unable to creaty empty arrays])]
-			)]
-		)]
-	)dnl
-	AC_DEFINE_UNQUOTED(
-		[EMPTY_ARRAY_SIZE],
-		[$VAR],
-		[Dimension to use for empty array declaration]
-	)dnl
-	AS_VAR_POPDEF([VAR])dnl
-])
src/openvpn/circ_list.h +1 -1
index 23b42d2ab..ba9115eab 100644
@@ -34,7 +34,7 @@
         int x_size; \
         int x_cap; \
         int x_sizeof; \
-        type x_list[EMPTY_ARRAY_SIZE]; \
+        type x_list[]; \
     }
 
 #define CIRC_LIST_PUSH(obj, item) \
src/openvpn/syshead.h +0 -2
index 5ee9bf1e8..cf9714593 100644
@@ -392,8 +392,6 @@ typedef int MIB_TCP_STATE;
 #ifdef PEDANTIC
 #undef HAVE_CPP_VARARG_MACRO_GCC
 #undef HAVE_CPP_VARARG_MACRO_ISO
-#undef EMPTY_ARRAY_SIZE
-#define EMPTY_ARRAY_SIZE 1
 #undef inline
 #define inline
 #endif
Signature · 1 line
2.30.1
#1 lore raw

PATCH v2 2/2 Remove support for non ISO C99 vararg support

We require ISO C99 as minimum support for our source code and all compilers should support the ISO C99 macros. Especially gcc does not need the gcc extensions anymore. Also MSVC has support for it (as defined in the config-msvc.h but also double checked)

LCLINT seems to be a C analyzer that history has forgotten about. I could only find https://splint.org/release1.3.html and an similarly old research paper.

Patch V2: Also remove AX_ macros from configure.ac

---
 config-msvc.h       |  1 -
 configure.ac        |  2 --
 m4/ax_varargs.m4    | 77 ---------------------------------------------
 src/openvpn/error.c |  4 ---
 src/openvpn/error.h | 21 -------------
 src/tapctl/error.h  |  1 -
 6 files changed, 106 deletions(-)
 delete mode 100644 m4/ax_varargs.m4
config-msvc.h +0 -1
index 0260927ce..4db9efae2 100644
@@ -47,7 +47,6 @@
 #define HAVE_ACCESS 1
 #define HAVE_CHDIR 1
 #define HAVE_CHSIZE 1
-#define HAVE_CPP_VARARG_MACRO_ISO 1
 #define HAVE_CTIME 1
 #define HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH 1
 #define HAVE_IN_PKTINFO 1
configure.ac +0 -2
index c17266a0a..8e31dcb29 100644
@@ -418,8 +418,6 @@ AC_TYPE_UINT16_T
 AC_TYPE_UINT32_T
 AC_TYPE_UINT64_T
 AC_TYPE_SIGNAL
-AX_CPP_VARARG_MACRO_ISO
-AX_CPP_VARARG_MACRO_GCC
 AX_TYPE_SOCKLEN_T
 AC_CHECK_SIZEOF([unsigned int])
 AC_CHECK_SIZEOF([unsigned long])
m4/ax_varargs.m4 deleted +0 -77

77 lines not on this page · raw message

src/openvpn/error.c +0 -4
index 0ecbfc330..e6f7ff0ff 100644
@@ -236,26 +236,22 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
 
     void usage_small(void);
 
-#ifndef HAVE_VARARG_MACROS
     /* the macro has checked this otherwise */
     if (!msg_test(flags))
     {
         return;
     }
-#endif
 
     e = openvpn_errno();
 
     /*
      * Apply muting filter.
      */
-#ifndef HAVE_VARARG_MACROS
     /* the macro has checked this otherwise */
     if (!dont_mute(flags))
     {
         return;
     }
-#endif
 
     gc_init(&gc);
 
src/openvpn/error.h +0 -21
index eaedf172c..1a5521654 100644
@@ -146,33 +146,12 @@ bool dont_mute(unsigned int flags);
 /* Macro to ensure (and teach static analysis tools) we exit on fatal errors */
 #define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (false)
 
-#if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__)
-#define HAVE_VARARG_MACROS
 #define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
 #ifdef ENABLE_DEBUG
 #define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
 #else
 #define dmsg(flags, ...)
 #endif
-#elif defined(HAVE_CPP_VARARG_MACRO_GCC) && !defined(__LCLINT__)
-#define HAVE_VARARG_MACROS
-#define msg(flags, args ...) do { if (msg_test(flags)) {x_msg((flags), args);} EXIT_FATAL(flags); } while (false)
-#ifdef ENABLE_DEBUG
-#define dmsg(flags, args ...) do { if (msg_test(flags)) {x_msg((flags), args);} EXIT_FATAL(flags); } while (false)
-#else
-#define dmsg(flags, args ...)
-#endif
-#else  /* if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__) */
-#if !PEDANTIC
-#ifdef _MSC_VER
-#pragma message("this compiler appears to lack vararg macros which will cause a significant degradation in efficiency")
-#else
-#warning this compiler appears to lack vararg macros which will cause a significant degradation in efficiency (you can ignore this warning if you are using LCLINT)
-#endif
-#endif
-#define msg x_msg
-#define dmsg x_msg
-#endif /* if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__) */
 
 void x_msg(const unsigned int flags, const char *format, ...)
 #ifdef __GNUC__
src/tapctl/error.h +0 -1
index 924cbbe89..cea50ba52 100644
@@ -67,7 +67,6 @@ bool dont_mute(unsigned int flags);
 #endif
 #define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (false)
 
-#define HAVE_VARARG_MACROS
 #define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
 #ifdef ENABLE_DEBUG
 #define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
Signature · 1 line
2.30.1
Acked-by on v2 1/2
#3 lore raw
In reply to Arne Schwabe

Taking Steffan's ACK on the v1, and mine on the single-line change in v2 (which gets rid of these warnings). Buildbot army tested v1, so I'm reasonably sure nothing bad will happen on v2 either :-)

Your patch has been applied to the master branch.

commit 7975e33bd9122045d26d1a47294f2c47854a5f0e

Author: Arne Schwabe
Date:   Sun Mar 28 16:20:37 2021 +0200
     Remove flexible array member autoconf check

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21882.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v2 2/2
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove support for non ISO C99 vararg support

In reply to Arne Schwabe

Taking Steffan's ACK on the v1, and mine on the single-line change in v2 (which gets rid of these warnings). Buildbot army tested v1, so I'm reasonably sure nothing bad will happen on v2 either :-)

Your patch has been applied to the master branch.

commit f91e21163708b5dc01115806cb71643144d6c3d1

Author: Arne Schwabe
Date:   Sun Mar 28 16:20:38 2021 +0200
     Remove support for non ISO C99 vararg support

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21883.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering