From 7b0d77e0c0a3caf020f8f12a0217555ac826bb56 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 14 Apr 2022 00:27:19 +0200 Subject: [PATCH] Remove checks for [v]snprintf() and vsscanf() declarations Consider that all still supported/existing platforms provide these declarations, if they provide these functions at all (and they probably all do, so we almost certainly could remove all the test for them, but keep them for now). Note that we still test for broken declarations as this might still be useful on HP-UX 11 systems, where this problem was reported "only" 8 years ago. By not using AC_CHECK_FUNCS() we avoid the problem when using it with snprintf() when cross-compiling with the latest MinGW API headers, see https://sourceforge.net/p/mingw-w64/bugs/935/ for more details. This commit is best viewed ignoring whitespace-only changes. --- build/cmake/setup.h.in | 9 -- configure | 237 +++++++++++----------------------- configure.in | 143 ++++---------------- include/wx/osx/config_xcode.h | 3 - include/wx/wxcrtvararg.h | 27 ---- setup.h.in | 9 -- setup.h_vms | 15 --- 7 files changed, 97 insertions(+), 346 deletions(-) diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in index 42ab868fa8..25d2582208 100644 --- a/build/cmake/setup.h.in +++ b/build/cmake/setup.h.in @@ -980,9 +980,6 @@ /* Define if you have snprintf() */ #cmakedefine HAVE_SNPRINTF 1 -/* Define if you have snprintf() declaration in the header */ -#cmakedefine HAVE_SNPRINTF_DECL 1 - /* Define if you have a snprintf() which supports positional arguments (defined in the unix98 standard) */ #cmakedefine HAVE_UNIX98_PRINTF 1 @@ -1005,9 +1002,6 @@ /* Define if you have vsnprintf() */ #cmakedefine HAVE_VSNPRINTF 1 -/* Define if you have vsnprintf() declaration in the header */ -#cmakedefine HAVE_VSNPRINTF_DECL 1 - /* Define if you have a _broken_ vsnprintf() declaration in the header, * with 'char*' for the 3rd parameter instead of 'const char*' */ #cmakedefine HAVE_BROKEN_VSNPRINTF_DECL 1 @@ -1019,9 +1013,6 @@ /* Define if you have vsscanf() */ #cmakedefine HAVE_VSSCANF 1 -/* Define if you have vsscanf() declaration in the header */ -#cmakedefine HAVE_VSSCANF_DECL 1 - /* Define if you have usleep() */ #cmakedefine HAVE_USLEEP 1 diff --git a/configure b/configure index bc4d1db12f..f0afe1c6bf 100755 --- a/configure +++ b/configure @@ -34294,17 +34294,61 @@ done fi -for ac_func in snprintf vsnprintf vsscanf -do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" -if eval test \"x\$"$as_ac_var"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 + + for wx_func in snprintf vsnprintf vsscanf + do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $wx_func" >&5 +$as_echo_n "checking for $wx_func... " >&6; } +if eval \${wx_cv_func_$wx_func+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + + + $ac_includes_default + +int +main () +{ + + #ifndef $wx_func + &$wx_func; + #endif + + + ; + return 0; +} + _ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval wx_cv_func_$wx_func=yes +else + eval wx_cv_func_$wx_func=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext fi -done +eval ac_res=\$wx_cv_func_$wx_func + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval test \$wx_cv_func_$wx_func = yes + then + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$wx_func" | $as_tr_cpp` 1 +_ACEOF + + + else + : + + fi + done ac_ext=cpp @@ -34313,106 +34357,13 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -if test "$ac_cv_func_vsnprintf" = "yes"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for vsnprintf declaration" >&5 -$as_echo_n "checking for vsnprintf declaration... " >&6; } -if ${wx_cv_func_vsnprintf_decl+:} false; then : - $as_echo_n "(cached) " >&6 -else - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #include - #include - -int -main () -{ - - char *buf; - va_list ap; - vsnprintf(buf, 10u, "%s", ap); - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - wx_cv_func_vsnprintf_decl=yes -else - wx_cv_func_vsnprintf_decl=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_vsnprintf_decl" >&5 -$as_echo "$wx_cv_func_vsnprintf_decl" >&6; } - - if test "$wx_cv_func_vsnprintf_decl" = "yes"; then - $as_echo "#define HAVE_VSNPRINTF_DECL 1" >>confdefs.h - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if vsnprintf declaration is broken" >&5 +if test "$wx_cv_func_vsnprintf" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if vsnprintf declaration is broken" >&5 $as_echo_n "checking if vsnprintf declaration is broken... " >&6; } if ${wx_cv_func_broken_vsnprintf_decl+:} false; then : $as_echo_n "(cached) " >&6 else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #include - #include - #ifdef __MSL__ - #if __MSL__ >= 0x6000 - namespace std {} - using namespace std; - #endif - #endif - -int -main () -{ - - char *buf; - va_list ap; - const char *fmt = "%s"; - vsnprintf(buf, 10u, fmt, ap); - - ; - return 0; -} -_ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - wx_cv_func_broken_vsnprintf_decl=no -else - wx_cv_func_broken_vsnprintf_decl=yes - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_broken_vsnprintf_decl" >&5 -$as_echo "$wx_cv_func_broken_vsnprintf_decl" >&6; } - - if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then - $as_echo "#define HAVE_BROKEN_VSNPRINTF_DECL 1" >>confdefs.h - - fi - fi -fi - -if test "$ac_cv_func_snprintf" = "yes"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for snprintf declaration" >&5 -$as_echo_n "checking for snprintf declaration... " >&6; } -if ${wx_cv_func_snprintf_decl+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -34430,30 +34381,34 @@ main () { char *buf; - snprintf(buf, 10u, "%s", "wx"); + va_list ap; + const char *fmt = "%s"; + vsnprintf(buf, 10u, fmt, ap); ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : - wx_cv_func_snprintf_decl=yes + wx_cv_func_broken_vsnprintf_decl=no else - wx_cv_func_snprintf_decl=no + wx_cv_func_broken_vsnprintf_decl=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_snprintf_decl" >&5 -$as_echo "$wx_cv_func_snprintf_decl" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_broken_vsnprintf_decl" >&5 +$as_echo "$wx_cv_func_broken_vsnprintf_decl" >&6; } - if test "$wx_cv_func_snprintf_decl" = "yes"; then - $as_echo "#define HAVE_SNPRINTF_DECL 1" >>confdefs.h + if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then + $as_echo "#define HAVE_BROKEN_VSNPRINTF_DECL 1" >>confdefs.h fi +fi +if test "$wx_cv_func_snprintf" = "yes"; then if test "$wxUSE_PRINTF_POS_PARAMS" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking if snprintf supports positional arguments" >&5 @@ -34509,10 +34464,10 @@ $as_echo "$wx_cv_func_snprintf_pos_params" >&6; } fi fi -if test "$ac_cv_func_vsscanf" = "yes"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for vsscanf declaration" >&5 -$as_echo_n "checking for vsscanf declaration... " >&6; } -if ${wx_cv_func_vsscanf_decl+:} false; then : +if test "$wx_cv_func_vsscanf" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if vsscanf() declaration is broken" >&5 +$as_echo_n "checking if vsscanf() declaration is broken... " >&6; } +if ${wx_cv_func_broken_vsscanf_decl+:} false; then : $as_echo_n "(cached) " >&6 else @@ -34532,7 +34487,7 @@ int main () { - char *buf; + const char *buf; va_list args; vsscanf(buf, "%s", args); @@ -34540,53 +34495,6 @@ main () return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : - wx_cv_func_vsscanf_decl=yes -else - wx_cv_func_vsscanf_decl=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_vsscanf_decl" >&5 -$as_echo "$wx_cv_func_vsscanf_decl" >&6; } - - if test "$wx_cv_func_vsscanf_decl" = "yes"; then - $as_echo "#define HAVE_VSSCANF_DECL 1" >>confdefs.h - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if vsscanf() declaration is broken" >&5 -$as_echo_n "checking if vsscanf() declaration is broken... " >&6; } -if ${wx_cv_func_broken_vsscanf_decl+:} false; then : - $as_echo_n "(cached) " >&6 -else - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #include - #include - #ifdef __MSL__ - #if __MSL__ >= 0x6000 - namespace std {} - using namespace std; - #endif - #endif - -int -main () -{ - - const char *buf; - va_list args; - vsscanf(buf, "%s", args); - - ; - return 0; -} -_ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : wx_cv_func_broken_vsscanf_decl=no else @@ -34600,10 +34508,9 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $wx_cv_func_broken_vsscanf_decl" >&5 $as_echo "$wx_cv_func_broken_vsscanf_decl" >&6; } - if test "$wx_cv_func_broken_vsscanf_decl" = "yes"; then - $as_echo "#define HAVE_BROKEN_VSSCANF_DECL 1" >>confdefs.h + if test "$wx_cv_func_broken_vsscanf_decl" = "yes"; then + $as_echo "#define HAVE_BROKEN_VSSCANF_DECL 1" >>confdefs.h - fi fi fi ac_ext=c diff --git a/configure.in b/configure.in index 5c144b25f3..7e8f5c4db8 100644 --- a/configure.in +++ b/configure.in @@ -4272,81 +4272,14 @@ AC_CHECK_TYPES([mbstate_t], [], [#include ]) -dnl check for vsnprintf() -- a safe version of vsprintf()) -dnl -dnl the trouble here is that on some systems (e.g. HP-UX 10) this function is -dnl present in libc but not in the system headers and so AC_CHECK_FUNCS (which, -dnl stupidly, provides a dummy function declaration inside its extension) -dnl succeeds, even with C++ compiler, but the compilation of wxWidgets fails -dnl -dnl so we first check if the function is in the library -dnl -dnl FIXME: replace this mess with WX_CHECK_FUNCS() -AC_CHECK_FUNCS(snprintf vsnprintf vsscanf) +dnl Check for vararg functions that should be available in stdio.h +WX_CHECK_FUNCS(snprintf vsnprintf vsscanf) AC_LANG_PUSH(C++) -if test "$ac_cv_func_vsnprintf" = "yes"; then - dnl yes it is -- now check if it is in the headers - AC_CACHE_CHECK([for vsnprintf declaration], wx_cv_func_vsnprintf_decl, - [ - dnl our troubles are not over: HP-UX 11 prototypes vsnprintf() as - dnl taking "char *" and not "const char *" so test for this too - AC_TRY_COMPILE( - [ - #include - #include - ], - [ - char *buf; - va_list ap; - vsnprintf(buf, 10u, "%s", ap); - ], - wx_cv_func_vsnprintf_decl=yes, - wx_cv_func_vsnprintf_decl=no - ) - ] - ) - - if test "$wx_cv_func_vsnprintf_decl" = "yes"; then - AC_DEFINE(HAVE_VSNPRINTF_DECL) - - dnl we know there is a vsnprintf declaration, but some old headers - dnl may have one taking a "char *" format instead of "const char *" - AC_CACHE_CHECK([if vsnprintf declaration is broken], wx_cv_func_broken_vsnprintf_decl, - [ - AC_TRY_COMPILE( - [ - #include - #include - #ifdef __MSL__ - #if __MSL__ >= 0x6000 - namespace std {} - using namespace std; - #endif - #endif - ], - [ - char *buf; - va_list ap; - const char *fmt = "%s"; - vsnprintf(buf, 10u, fmt, ap); - ], - wx_cv_func_broken_vsnprintf_decl=no, - wx_cv_func_broken_vsnprintf_decl=yes - ) - ] - ) - - if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then - AC_DEFINE(HAVE_BROKEN_VSNPRINTF_DECL) - fi - fi -fi - -dnl the same as above but for snprintf() now: it's not present in at least AIX -dnl 4.2 headers -if test "$ac_cv_func_snprintf" = "yes"; then - AC_CACHE_CHECK([for snprintf declaration], wx_cv_func_snprintf_decl, +if test "$wx_cv_func_vsnprintf" = "yes"; then + dnl we know there is a vsnprintf declaration, but some old headers + dnl may have one taking a "char *" format instead of "const char *" + AC_CACHE_CHECK([if vsnprintf declaration is broken], wx_cv_func_broken_vsnprintf_decl, [ AC_TRY_COMPILE( [ @@ -4361,18 +4294,22 @@ if test "$ac_cv_func_snprintf" = "yes"; then ], [ char *buf; - snprintf(buf, 10u, "%s", "wx"); + va_list ap; + const char *fmt = "%s"; + vsnprintf(buf, 10u, fmt, ap); ], - wx_cv_func_snprintf_decl=yes, - wx_cv_func_snprintf_decl=no + wx_cv_func_broken_vsnprintf_decl=no, + wx_cv_func_broken_vsnprintf_decl=yes ) ] ) - if test "$wx_cv_func_snprintf_decl" = "yes"; then - AC_DEFINE(HAVE_SNPRINTF_DECL) + if test "$wx_cv_func_broken_vsnprintf_decl" = "yes"; then + AC_DEFINE(HAVE_BROKEN_VSNPRINTF_DECL) fi +fi +if test "$wx_cv_func_snprintf" = "yes"; then if test "$wxUSE_PRINTF_POS_PARAMS" = "yes"; then dnl check if snprintf() has support for positional arguments @@ -4412,10 +4349,11 @@ define HAVE_UNIX98_PRINTF as 1 in setup.h if it is available.]) fi fi -dnl the same as above but for vsscanf() now: it's not present in at least -dnl Solaris 9 headers for gcc-3.4 (due to fixinclude's processing of stdio.h) -if test "$ac_cv_func_vsscanf" = "yes"; then - AC_CACHE_CHECK([for vsscanf declaration], wx_cv_func_vsscanf_decl, +if test "$wx_cv_func_vsscanf" = "yes"; then + dnl we know there is a vsscanf() declaration, but it can be broken by + dnl declaring vsscanf() as taking a non-const first argument (this + dnl happens at least under HP-UX 11.31, see #15638). + AC_CACHE_CHECK([if vsscanf() declaration is broken], wx_cv_func_broken_vsscanf_decl, [ AC_TRY_COMPILE( [ @@ -4429,49 +4367,18 @@ if test "$ac_cv_func_vsscanf" = "yes"; then #endif ], [ - char *buf; + const char *buf; va_list args; vsscanf(buf, "%s", args); ], - wx_cv_func_vsscanf_decl=yes, - wx_cv_func_vsscanf_decl=no + wx_cv_func_broken_vsscanf_decl=no, + wx_cv_func_broken_vsscanf_decl=yes ) ] ) - if test "$wx_cv_func_vsscanf_decl" = "yes"; then - AC_DEFINE(HAVE_VSSCANF_DECL) - - dnl we know there is a vsscanf() declaration, but it can be broken by - dnl declaring vsscanf() as taking a non-const first argument (this - dnl happens at least under HP-UX 11.31, see #15638). - AC_CACHE_CHECK([if vsscanf() declaration is broken], wx_cv_func_broken_vsscanf_decl, - [ - AC_TRY_COMPILE( - [ - #include - #include - #ifdef __MSL__ - #if __MSL__ >= 0x6000 - namespace std {} - using namespace std; - #endif - #endif - ], - [ - const char *buf; - va_list args; - vsscanf(buf, "%s", args); - ], - wx_cv_func_broken_vsscanf_decl=no, - wx_cv_func_broken_vsscanf_decl=yes - ) - ] - ) - - if test "$wx_cv_func_broken_vsscanf_decl" = "yes"; then - AC_DEFINE(HAVE_BROKEN_VSSCANF_DECL) - fi + if test "$wx_cv_func_broken_vsscanf_decl" = "yes"; then + AC_DEFINE(HAVE_BROKEN_VSSCANF_DECL) fi fi AC_LANG_POP() diff --git a/include/wx/osx/config_xcode.h b/include/wx/osx/config_xcode.h index 6ed3453877..b7db09a333 100644 --- a/include/wx/osx/config_xcode.h +++ b/include/wx/osx/config_xcode.h @@ -52,7 +52,6 @@ #define HAVE_PTHREAD_CANCEL 1 #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 #define HAVE_SNPRINTF 1 -#define HAVE_SNPRINTF_DECL 1 #define HAVE_UNIX98_PRINTF 1 #define HAVE_STATFS 1 #define HAVE_STATFS_DECL 1 @@ -62,9 +61,7 @@ #define HAVE_STRTOULL 1 #define HAVE_THREAD_PRIORITY_FUNCTIONS 1 #define HAVE_VSNPRINTF 1 -#define HAVE_VSNPRINTF_DECL 1 #define HAVE_VSSCANF 1 -#define HAVE_VSSCANF_DECL 1 #define HAVE_USLEEP 1 #define HAVE_WCSCASECMP 1 #define HAVE_WCSDUP 1 diff --git a/include/wx/wxcrtvararg.h b/include/wx/wxcrtvararg.h index 36aae29957..8610aed84b 100644 --- a/include/wx/wxcrtvararg.h +++ b/include/wx/wxcrtvararg.h @@ -36,33 +36,6 @@ */ #ifdef __UNIX__ -#if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL) -#ifdef __cplusplus - extern "C" -#else - extern -#endif - int vsnprintf(char *str, size_t size, const char *format, va_list ap); -#endif /* !HAVE_VSNPRINTF_DECL */ - -#if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL) -#ifdef __cplusplus - extern "C" -#else - extern -#endif - int snprintf(char *str, size_t size, const char *format, ...); -#endif /* !HAVE_SNPRINTF_DECL */ - -#if defined(HAVE_VSSCANF) && !defined(HAVE_VSSCANF_DECL) -#ifdef __cplusplus - extern "C" -#else - extern -#endif - int vsscanf(const char *str, const char *format, va_list ap); -#endif /* !HAVE_VSSCANF_DECL */ - /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the * same isn't done for snprintf below, the builtin wxSnprintf_ is used * instead since it's already a simple wrapper */ diff --git a/setup.h.in b/setup.h.in index 8d90ffcc16..dc8a214718 100644 --- a/setup.h.in +++ b/setup.h.in @@ -980,9 +980,6 @@ /* Define if you have snprintf() */ #undef HAVE_SNPRINTF -/* Define if you have snprintf() declaration in the header */ -#undef HAVE_SNPRINTF_DECL - /* Define if you have a snprintf() which supports positional arguments (defined in the unix98 standard) */ #undef HAVE_UNIX98_PRINTF @@ -1005,9 +1002,6 @@ /* Define if you have vsnprintf() */ #undef HAVE_VSNPRINTF -/* Define if you have vsnprintf() declaration in the header */ -#undef HAVE_VSNPRINTF_DECL - /* Define if you have a _broken_ vsnprintf() declaration in the header, * with 'char*' for the 3rd parameter instead of 'const char*' */ #undef HAVE_BROKEN_VSNPRINTF_DECL @@ -1019,9 +1013,6 @@ /* Define if you have vsscanf() */ #undef HAVE_VSSCANF -/* Define if you have vsscanf() declaration in the header */ -#undef HAVE_VSSCANF_DECL - /* Define if you have usleep() */ #undef HAVE_USLEEP diff --git a/setup.h_vms b/setup.h_vms index 2d9c4b0170..c8b3047212 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -1076,15 +1076,9 @@ typedef pid_t GPid; #if __CRTL_VER >= 70312000 /* Define if you have snprintf() */ #define HAVE_SNPRINTF 1 - -/* Define if you have snprintf() declaration in the header */ -#define HAVE_SNPRINTF_DECL 1 #else /* Define if you have snprintf() */ #undef HAVE_SNPRINTF - -/* Define if you have snprintf() declaration in the header */ -#undef HAVE_SNPRINTF_DECL #endif /* Define if you have a snprintf() which supports positional arguments @@ -1109,15 +1103,9 @@ typedef pid_t GPid; #if __CRTL_VER >= 70312000 /* Define if you have vsnprintf() */ #define HAVE_VSNPRINTF 1 - -/* Define if you have vsnprintf() declaration in the header */ -#define HAVE_VSNPRINTF_DECL 1 #else /* Define if you have vsnprintf() */ #undef HAVE_VSNPRINTF - -/* Define if you have vsnprintf() declaration in the header */ -#undef HAVE_VSNPRINTF_DECL #endif /* Define if you have a _broken_ vsnprintf() declaration in the header, @@ -1131,9 +1119,6 @@ typedef pid_t GPid; /* Define if you have vsscanf() */ #define HAVE_VSSCANF 1 -/* Define if you have vsscanf() declaration in the header */ -#define HAVE_VSSCANF_DECL 1 - /* Define if you have usleep() */ #define HAVE_USLEEP 1