]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use compiler tests to determine how to define _U_.
authorGuy Harris <[email protected]>
Wed, 15 Nov 2017 22:21:44 +0000 (14:21 -0800)
committerGuy Harris <[email protected]>
Wed, 15 Nov 2017 22:21:44 +0000 (14:21 -0800)
One less thing that has to be done in autotools and CMake.

15 files changed:
CMakeLists.txt
Makefile.in
aclocal.m4
configure
configure.ac
pcap-int.h
tests/can_set_rfmon_test.c
tests/capturetest.c
tests/filtertest.c
tests/opentest.c
tests/reactivatetest.c
tests/selpolltest.c
tests/threadsignaltest.c
tests/valgrindtest.c
varattrs.h [new file with mode: 0644]

index 5b3074030eb422c0f4404cff9e8ecaefb3d9a8f9..4d57446cbbb4fec680ebd6cb2f9dae83923fb3d9 100644 (file)
@@ -247,11 +247,6 @@ add_definitions(-DBUILDING_PCAP)
 if(MSVC)
     add_definitions(-D__STDC__)
     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
-    add_definitions("-D_U_=")
-elseif(CMAKE_COMPILER_IS_GNUCXX)
-    add_definitions("-D_U_=__attribute__((unused))")
-else(MSVC)
-    add_definitions("-D_U_=")
 endif(MSVC)
 
 if(USE_STATIC_RT)
index 136e84e042975fc7347ee784176482a875ef1a5e..4a8034677f172a807989943a1252d0ccbff9309f 100644 (file)
@@ -155,7 +155,8 @@ HDR = $(PUBHDR) \
        rpcapd/win32-svc.h \
        sf-pcap.h \
        sf-pcap-ng.h \
-       sunatmpos.h
+       sunatmpos.h \
+       varattrs.h
 
 TESTS = \
        @VALGRINDTEST@ \
index f922759f6b420c860e96359e90d754a7ba741ba0..4362d4ff8e3f061accea5b1a54bbb9dd931d3229 100644 (file)
@@ -1101,48 +1101,10 @@ ac_cv___attribute__=yes,
 ac_cv___attribute__=no)])
 if test "$ac_cv___attribute__" = "yes"; then
   AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
-else
-  #
-  # We can't use __attribute__, so we can't use __attribute__((unused)),
-  # so we define _U_ to an empty string.
-  #
-  V_DEFS="$V_DEFS -D_U_=\"\""
 fi
 AC_MSG_RESULT($ac_cv___attribute__)
 ])
 
-dnl
-dnl Test whether __attribute__((unused)) can be used without warnings
-dnl
-
-AC_DEFUN(AC_C___ATTRIBUTE___UNUSED, [
-AC_MSG_CHECKING([whether __attribute__((unused)) can be used without warnings])
-AC_CACHE_VAL(ac_cv___attribute___unused, [
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-AC_COMPILE_IFELSE([
-  AC_LANG_SOURCE([[
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main(int argc  __attribute((unused)), char **argv __attribute((unused)))
-{
-  printf("Hello, world!\n");
-  return 0;
-}
-  ]])],
-ac_cv___attribute___unused=yes,
-ac_cv___attribute___unused=no)])
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___unused" = "yes"; then
-  V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
-else
-  V_DEFS="$V_DEFS -D_U_=\"\""
-fi
-AC_MSG_RESULT($ac_cv___attribute___unused)
-])
-
 dnl
 dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
 dnl If so then pcap-linux.c can use this to report proper statistics.
index 30c6bdc1ced2520172dce86c792303d95f463ea6..8b9a8ea6a664deb3e9545f037595619ef6d880e1 100755 (executable)
--- a/configure
+++ b/configure
@@ -3870,59 +3870,10 @@ if test "$ac_cv___attribute__" = "yes"; then
 
 $as_echo "#define HAVE___ATTRIBUTE__ 1" >>confdefs.h
 
-else
-  #
-  # We can't use __attribute__, so we can't use __attribute__((unused)),
-  # so we define _U_ to an empty string.
-  #
-  V_DEFS="$V_DEFS -D_U_=\"\""
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute__" >&5
 $as_echo "$ac_cv___attribute__" >&6; }
 
-if test "$ac_cv___attribute__" = "yes"; then
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __attribute__((unused)) can be used without warnings" >&5
-$as_echo_n "checking whether __attribute__((unused)) can be used without warnings... " >&6; }
-if ${ac_cv___attribute___unused+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main(int argc  __attribute((unused)), char **argv __attribute((unused)))
-{
-  printf("Hello, world!\n");
-  return 0;
-}
-
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv___attribute___unused=yes
-else
-  ac_cv___attribute___unused=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___unused" = "yes"; then
-  V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
-else
-  V_DEFS="$V_DEFS -D_U_=\"\""
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute___unused" >&5
-$as_echo "$ac_cv___attribute___unused" >&6; }
-
-fi
 
 #
 # Try to arrange for large file support.
index a20f376ae572c833b1b7df294249e3fa8cbc9069..7f16399cf86c49c1f47c6330ca0925fa7b3e4da4 100644 (file)
@@ -28,9 +28,6 @@ AC_LBL_C_INIT(V_CCOPT, V_INCLS)
 AC_LBL_SHLIBS_INIT
 AC_LBL_C_INLINE
 AC_C___ATTRIBUTE__
-if test "$ac_cv___attribute__" = "yes"; then
-       AC_C___ATTRIBUTE___UNUSED
-fi
 
 #
 # Try to arrange for large file support.
index d1ea4a159f6788e84efebd70fa209ffdd8954abe..516b49c3561e02ad2e4e80f00c33c886044fcec4 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <pcap/pcap.h>
 
+#include "varattrs.h"
 #include "fmtutils.h"
 
 /*
index 88661d63f6cd6811a43fba656022e81e245c4ab4..ea4f0c40aa7c41848ce1240a023d1a897e2aa9a6 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index 1cebae01d5ef0d8f365f77a353f4cffa7820a24e..573239f2c0fc1193dbe55184822441dfd34e3c77 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index 9d5973969f0871d91b14b5c6468321009f0d6335..380cb73e76c48ad842bd5403a3bf1cd31e24f12e 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index 79c9c941a13936f04f4b2630445059c45a8e5b23..bad38eb0e9fbc0712f5193ff704b9cdc80d6a63a 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index f3485cbda81bd9c97c5bba546715956d2bc19687..42b2c3b8bab64ac3b61facb25760df0ed9ada4d8 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index f8005d6efc538d9cfa213d8b4343ccbdc04fe30a..dbd1c424db1da325ce42b22c26171e20ccbcdd71 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index 2a4932238b045645b7ffa53aa93ad32ace04ff8e..bd46f93601dd525cd57354d6a006fc728dd2b9ce 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 #ifndef lint
 static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
index 6bb6d4f6d839c6fedc408585f5ab4337f0b9461a..ef387c9770161abe88707ffdeb8379a0217cfd90 100644 (file)
@@ -19,6 +19,8 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#include "varattrs.h"
+
 /*
  * This doesn't actually test libpcap itself; it tests whether
  * valgrind properly handles the APIs libpcap uses.  If it doesn't,
diff --git a/varattrs.h b/varattrs.h
new file mode 100644 (file)
index 0000000..05bfe8c
--- /dev/null
@@ -0,0 +1,59 @@
+/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
+/*
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the Computer Systems
+ *     Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef varattrs_h
+#define varattrs_h
+
+#include <pcap/compiler-tests.h>
+
+/*
+ * Attributes to apply to variables, using various compiler-specific
+ * extensions.
+ */
+
+#if __has_attribute(unused) \
+    || PCAP_IS_AT_LEAST_GNUC_VERSION(2,0)
+  /*
+   * Compiler with support for __attribute__((unused)), or GCC 2.0 and
+   * later, so it supports __attribute__((unused)).
+   */
+  #define _U_ __attribute__((unused))
+#else
+  /*
+   * We don't know of any way to mark a variable as unused.
+   */
+  #define _U_
+#endif
+
+#endif