diff options
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | Makefile.am | 13 | ||||
-rw-r--r-- | ws_attributes.h | 115 | ||||
-rw-r--r-- | ws_compiler_tests.h | 150 | ||||
-rw-r--r-- | ws_diag_control.h | 58 | ||||
-rw-r--r-- | ws_symbol_export.h | 80 |
6 files changed, 242 insertions, 179 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b25529cd1a..1e2c7ed339 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2992,12 +2992,13 @@ install( set(SHARK_PUBLIC_HEADERS cfile.h file.h - register.h globals.h log.h - ws_symbol_export.h + register.h ws_attributes.h + ws_compiler_tests.h ws_diag_control.h + ws_symbol_export.h ) if(NOT WIN32) diff --git a/Makefile.am b/Makefile.am index f7ff83aba0..a182ed0900 100644 --- a/Makefile.am +++ b/Makefile.am @@ -721,12 +721,13 @@ dumpcap_LDADD = \ pkginclude_HEADERS = \ cfile.h \ file.h \ - register.h \ globals.h \ log.h \ - ws_symbol_export.h \ + register.h \ ws_attributes.h \ - ws_diag_control.h + ws_compiler_tests.h \ + ws_diag_control.h \ + ws_symbol_export.h # this target needed for distribution only noinst_HEADERS = \ @@ -734,14 +735,14 @@ noinst_HEADERS = \ capture_opts.h \ capture_stop_conditions.h \ conditions.h \ + extcap.h \ + extcap_parser.h \ + extcap_spawn.h \ fileset.h \ frame_tvbuff.h \ ringbuffer.h \ summary.h \ sync_pipe.h \ - extcap.h \ - extcap_parser.h \ - extcap_spawn.h \ version_info.h # diff --git a/ws_attributes.h b/ws_attributes.h index fdac6a0d04..0f0fd2e21d 100644 --- a/ws_attributes.h +++ b/ws_attributes.h @@ -22,124 +22,13 @@ #ifndef __WS_ATTRIBUTES_H__ #define __WS_ATTRIBUTES_H__ +#include "ws_compiler_tests.h" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* - * This was introduced by Clang: - * - * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute - * - * in some version (which version?); it has been picked up by GCC 5.0. - */ -#ifndef __has_attribute - /* - * It's a macro, so you can check whether it's defined to check - * whether it's supported. - * - * If it's not, define it to always return 0, so that we move on to - * the fallback checks. - */ - #define __has_attribute(x) 0 -#endif - -/* - * Note that the C90 spec's "6.8.1 Conditional inclusion" and the - * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: - * - * Prior to evaluation, macro invocations in the list of preprocessing - * tokens that will become the controlling constant expression are - * replaced (except for those macro names modified by the defined unary - * operator), just as in normal text. If the token "defined" is - * generated as a result of this replacement process or use of the - * "defined" unary operator does not match one of the two specified - * forms prior to macro replacement, the behavior is undefined. - * - * so you shouldn't use defined() in a #define that's used in #if or - * #elif. Some versions of Clang, for example, will warn about this. - * - * Instead, we check whether the pre-defined macros for particular - * compilers are defined and, if not, define the "is this version XXX - * or a later version of this compiler" macros as 0. - */ - -/* - * Check whether this is GCC major.minor or a later release, or some - * compiler that claims to be "just like GCC" of that version or a - * later release. - */ - -#if !defined(__GNUC__) - #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 -#else - #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) \ - (__GNUC__ > (major) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) -#endif - -/* - * Check whether this is Sun C/SunPro C/Oracle Studio major.minor - * or a later release. - * - * The version number in __SUNPRO_C is encoded in hex BCD, with the - * uppermost hex digit being the major version number, the next - * one or two hex digits being the minor version number, and - * the last digit being the patch version. - * - * It represents the *compiler* version, not the product version; - * see - * - * https://sourceforge.net/p/predef/wiki/Compilers/ - * - * for a partial mapping, which we assume continues for later - * 12.x product releases. - */ - -#if !defined(__SUNPRO_C) - #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) 0 -#else - #define WS_SUNPRO_VERSION_TO_BCD(major, minor) \ - (((minor) >= 10) ? \ - (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ - (((major) << 8) | ((minor) << 4))) - #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) \ - (__SUNPRO_C >= WS_SUNPRO_VERSION_TO_BCD((major), (minor))) -#endif - -/* - * Check whether this is IBM XL C major.minor or a later release. - * - * The version number in __xlC__ has the major version in the - * upper 8 bits and the minor version in the lower 8 bits. - */ - -#if !defined(__xlC__) - #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) 0 -#else - #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) \ - (__xlC__ >= (((major) << 8) | (minor))) -#endif - -/* - * Check whether this is HP aC++/HP C major.minor or a later release. - * - * The version number in __HP_aCC is encoded in zero-padded decimal BCD, - * with the "A." stripped off, the uppermost two decimal digits being - * the major version number, the next two decimal digits being the minor - * version number, and the last two decimal digits being the patch version. - * (Strip off the A., remove the . between the major and minor version - * number, and add two digits of patch.) - */ - -#if !defined(__HP_aCC) - #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) 0 -#else - #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) \ - (__HP_aCC >= ((major)*10000 + (minor)*100)) -#endif - -/* * If we're running GCC or clang define _U_ to be "__attribute__((unused))" * so we can use _U_ to flag unused function parameters and not get warnings * about them. Otherwise, define _U_ to be an empty string so that _U_ used diff --git a/ws_compiler_tests.h b/ws_compiler_tests.h new file mode 100644 index 0000000000..0e0fb1b0e2 --- /dev/null +++ b/ws_compiler_tests.h @@ -0,0 +1,150 @@ +/* ws_compiler_tests.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WS_COMPILER_TESTS_H__ +#define __WS_COMPILER_TESTS_H__ + +/* + * This was introduced by Clang: + * + * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute + * + * in some version (which version?); it has been picked up by GCC 5.0. + */ +#ifndef __has_attribute + /* + * It's a macro, so you can check whether it's defined to check + * whether it's supported. + * + * If it's not, define it to always return 0, so that we move on to + * the fallback checks. + */ + #define __has_attribute(x) 0 +#endif + +/* + * Note that the C90 spec's "6.8.1 Conditional inclusion" and the + * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: + * + * Prior to evaluation, macro invocations in the list of preprocessing + * tokens that will become the controlling constant expression are + * replaced (except for those macro names modified by the defined unary + * operator), just as in normal text. If the token "defined" is + * generated as a result of this replacement process or use of the + * "defined" unary operator does not match one of the two specified + * forms prior to macro replacement, the behavior is undefined. + * + * so you shouldn't use defined() in a #define that's used in #if or + * #elif. Some versions of Clang, for example, will warn about this. + * + * Instead, we check whether the pre-defined macros for particular + * compilers are defined and, if not, define the "is this version XXX + * or a later version of this compiler" macros as 0. + */ + +/* + * Check whether this is GCC major.minor or a later release, or some + * compiler that claims to be "just like GCC" of that version or a + * later release. + */ + +#if !defined(__GNUC__) + #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 +#else + #define WS_IS_AT_LEAST_GNUC_VERSION(major, minor) \ + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#endif + +/* + * Check whether this is Clang major.minor or a later release. + */ + +#if !defined(__clang__) + #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) 0 +#else + #define WS_IS_AT_LEAST_CLANG_VERSION(major, minor) \ + (__clang_major__ > (major) || \ + (__clang_major__ == (major) && __clang_minor__ >= (minor))) +#endif + +/* + * Check whether this is Sun C/SunPro C/Oracle Studio major.minor + * or a later release. + * + * The version number in __SUNPRO_C is encoded in hex BCD, with the + * uppermost hex digit being the major version number, the next + * one or two hex digits being the minor version number, and + * the last digit being the patch version. + * + * It represents the *compiler* version, not the product version; + * see + * + * https://sourceforge.net/p/predef/wiki/Compilers/ + * + * for a partial mapping, which we assume continues for later + * 12.x product releases. + */ + +#if !defined(__SUNPRO_C) + #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) 0 +#else + #define WS_SUNPRO_VERSION_TO_BCD(major, minor) \ + (((minor) >= 10) ? \ + (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ + (((major) << 8) | ((minor) << 4))) + #define WS_IS_AT_LEAST_SUNC_VERSION(major, minor) \ + (__SUNPRO_C >= WS_SUNPRO_VERSION_TO_BCD((major), (minor))) +#endif + +/* + * Check whether this is IBM XL C major.minor or a later release. + * + * The version number in __xlC__ has the major version in the + * upper 8 bits and the minor version in the lower 8 bits. + */ + +#if !defined(__xlC__) + #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) 0 +#else + #define WS_IS_AT_LEAST_XL_C_VERSION(major, minor) \ + (__xlC__ >= (((major) << 8) | (minor))) +#endif + +/* + * Check whether this is HP aC++/HP C major.minor or a later release. + * + * The version number in __HP_aCC is encoded in zero-padded decimal BCD, + * with the "A." stripped off, the uppermost two decimal digits being + * the major version number, the next two decimal digits being the minor + * version number, and the last two decimal digits being the patch version. + * (Strip off the A., remove the . between the major and minor version + * number, and add two digits of patch.) + */ + +#if !defined(__HP_aCC) + #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) 0 +#else + #define WS_IS_AT_LEAST_HP_C_VERSION(major, minor) \ + (__HP_aCC >= ((major)*10000 + (minor)*100)) +#endif + +#endif /* __WS_COMPILER_TESTS_H__ */ diff --git a/ws_diag_control.h b/ws_diag_control.h index b2a4561f6f..428091addd 100644 --- a/ws_diag_control.h +++ b/ws_diag_control.h @@ -24,6 +24,8 @@ #ifndef __WS_DIAG_CONTROL_H__ #define __WS_DIAG_CONTROL_H__ +#include "ws_compiler_tests.h" + #ifdef __cplusplus extern "C" { #endif @@ -45,26 +47,35 @@ extern "C" { pragma clang diagnostic error/warning/ignored -Wxxx and pragma clang diagnostic push/pop were introduced in clang 2.8 */ -#if defined(__GNUC__) && !defined(__clang__) -# define gcc_version ((__GNUC__ * 1000) + (__GNUC_MINOR__ * 10)) -# if gcc_version >= 4080 - /* - * gcc version is >= 4.8.0. We can use "GCC diagnostic push/pop" *and* - * gcc supports "-Wpedantic". - */ -# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x) -# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) -# define DIAG_ON(x) DIAG_PRAGMA(pop) -# endif -#elif defined(__clang__) -# define clang_version ((__clang_major__ * 1000) + (__clang_minor__ * 10)) -# if clang_version >= 2080 - /* clang version is >= 2.8: we can use "clang diagnostic ignored -Wxxx" - and "clang diagnostic push/pop" */ -# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x) -# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) -# define DIAG_ON(x) DIAG_PRAGMA(pop) -# endif +#if !defined(__clang__) && WS_IS_AT_LEAST_GNUC_VERSION(4,8) + /* + * This is GCC, or a compiler that 1) claims to be GCC and 2) does + * *not* claim to be Clang, and is claiming to be GCC version 4.8.0 + * or later. + * We can use "GCC diagnostic push/pop" *and* gcc supports "-Wpedantic". + */ + #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x) + #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) + #define DIAG_ON(x) DIAG_PRAGMA(pop) +#elif WS_IS_AT_LEAST_CLANG_VERSION(2,8) + /* + * This is Clang 2.8 or later: we can use "clang diagnostic ignored -Wxxx" + * and "clang diagnostic push/pop". + */ + #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x) + #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) + #define DIAG_ON(x) DIAG_PRAGMA(pop) +#else + /* + * This is none of the above; we don't have any way to turn diagnostics + * on or off. + * + * XXX - you can do that in MSVC, but it's done differently; we'd + * have to have macros for *particular* diagnostics, using the + * warning flag for GCC and Clang and the error number for MSVC. + */ + #define DIAG_OFF(x) + #define DIAG_ON(x) #endif /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */ @@ -76,13 +87,6 @@ extern "C" { # define DIAG_ON_CLANG(x) #endif -#ifndef DIAG_OFF - /* no gcc or clang, or gcc version < 4.2.0, or clang version < 2.8: - we can't do anything */ -# define DIAG_OFF(x) -# define DIAG_ON(x) -#endif - /* * For dealing with APIs which are only deprecated in macOS (like the * OpenSSL and MIT/Heimdal Kerberos APIs). diff --git a/ws_symbol_export.h b/ws_symbol_export.h index 45082d3256..5a9b3f0bda 100644 --- a/ws_symbol_export.h +++ b/ws_symbol_export.h @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "ws_compiler_tests.h" + /** Reset symbol export behavior. * If you {un}define WS_BUILD_DLL on the fly you'll have to define this * as well. @@ -83,13 +85,13 @@ */ #ifdef __GNUC__ /* GCC */ -#define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport)) + #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport)) #else /* ! __GNUC__ */ /* * Presumably MSVC. * Note: actually gcc seems to also support this syntax. */ -#define WS_DLL_PUBLIC_DEF __declspec(dllexport) + #define WS_DLL_PUBLIC_DEF __declspec(dllexport) #endif /* __GNUC__ */ #else /* WS_BUILD_DLL */ /* @@ -103,19 +105,19 @@ */ #ifdef __GNUC__ /* GCC */ -#define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport)) + #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport)) #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */ /* * Presumably MSVC, and we're not building all-static. * Note: actually gcc seems to also support this syntax. */ -#define WS_DLL_PUBLIC_DEF __declspec(dllimport) + #define WS_DLL_PUBLIC_DEF __declspec(dllimport) #else /* ! __GNUC__ && ENABLE_STATIC */ /* * Presumably MSVC, and we're building all-static, so we're * not building any DLLs. */ -#define WS_DLL_PUBLIC_DEF + #define WS_DLL_PUBLIC_DEF #endif /* __GNUC__ */ #endif /* WS_BUILD_DLL */ @@ -129,42 +131,58 @@ /* * Compiling for UN*X, where the dllimport and dllexport stuff * is neither necessary nor supported; just specify the - * visibility if we have a compiler that claims compatibility - * with GCC 4 or later. + * visibility if we have a compiler that supports doing so. */ - #if __GNUC__ >= 4 + #if WS_IS_AT_LEAST_GNUC_VERSION(3,4) \ + || WS_IS_AT_LEAST_XL_C_VERSION(12,0) + /* + * GCC 3.4 or later, or some compiler asserting compatibility with + * GCC 3.4 or later, or XL C 13.0 or later, so we have + * __attribute__((visibility()). + */ + /* * Symbols exported from libraries. */ -#define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default"))) + #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default"))) /* * Non-static symbols *not* exported from libraries. */ -#define WS_DLL_LOCAL __attribute__ ((visibility ("hidden"))) - #else /* ! __GNUC__ >= 4 */ + #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden"))) + #elif WS_IS_AT_LEAST_SUNC_VERSION(5,5) /* - * We have no way to make stuff not explicitly marked as - * visible invisible outside a library, but we might have - * a way to make stuff explicitly marked as local invisible - * outside the library. - * - * This was lifted from GLib; see above for why we don't use - * G_GNUC_INTERNAL. + * Sun C 5.5 or later, so we have __global and __hidden. + * (Sun C 5.9 and later also have __attribute__((visibility()), + * but there's no reason to prefer it with Sun C.) */ - #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) - /* This supports GCC-style __attribute__ ((visibility (XXX))) */ - #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default"))) - #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden"))) - #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) - /* This doesn't, but supports __global and __hidden */ - #define WS_DLL_PUBLIC_DEF __global - #define WS_DLL_LOCAL __hidden - #else /* not Sun C with "hidden" support */ - #define WS_DLL_PUBLIC_DEF - #define WS_DLL_LOCAL - #endif - #endif /* __GNUC__ >= 4 */ + + /* + * Symbols exported from libraries. + */ + #define WS_DLL_PUBLIC_DEF __global + + /* + * Non-static symbols *not* exported from libraries. + */ + #define WS_DLL_LOCAL __hidden + #else + /* + * We have neither a way to make stuff not explicitly marked as + * visible invisible outside a library nor a way to make stuff + * explicitly marked as local invisible outside the library. + */ + + /* + * Symbols exported from libraries. + */ + #define WS_DLL_PUBLIC_DEF + + /* + * Non-static symbols *not* exported from libraries. + */ + #define WS_DLL_LOCAL + #endif #endif /* |