From 6c3e363cb0a4e24844a2f7bd671e8378d374d04f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Dec 2013 13:36:23 +0000 Subject: [PATCH] Work around wrong vsscanf() declaration under HP-UX. Under this system vsscanf() is declared as taking a non-const char* as first argument which prevented our code using it from compiling. Wrap it in wxCRT_VsscanfA() adding the necessary const_cast<> to fix this. Closes #15638. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- configure | 48 ++++++++++++++++++++++++++++++++++++++++ configure.in | 31 ++++++++++++++++++++++++++ docs/changes.txt | 1 + include/wx/wxcrtvararg.h | 12 +++++++++- setup.h.in | 4 ++++ setup.h_vms | 4 ++++ 6 files changed, 99 insertions(+), 1 deletion(-) diff --git a/configure b/configure index cb7aac94e2..cf24750812 100755 --- a/configure +++ b/configure @@ -29995,6 +29995,54 @@ $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 + wx_cv_func_broken_vsscanf_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_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 + + fi fi fi ac_ext=c diff --git a/configure.in b/configure.in index 81a343fc73..f1d73ae613 100644 --- a/configure.in +++ b/configure.in @@ -4236,6 +4236,37 @@ if test "$ac_cv_func_vsscanf" = "yes"; then 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 fi fi AC_LANG_POP() diff --git a/docs/changes.txt b/docs/changes.txt index 134c7ab1ea..90c27e6c19 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -578,6 +578,7 @@ All: - Fix wxSocket::WaitForAccept() in non-main thread (Hajo Kirchhoff). - Fix memory overallocation in wxVector::reserve() (Nigel Paton). +- Fix the build under HP-UX (tested under 11.31). All (GUI): diff --git a/include/wx/wxcrtvararg.h b/include/wx/wxcrtvararg.h index c3a306be85..08d6981e26 100644 --- a/include/wx/wxcrtvararg.h +++ b/include/wx/wxcrtvararg.h @@ -238,7 +238,17 @@ #define wxCRT_ScanfA scanf #define wxCRT_SscanfA sscanf #define wxCRT_FscanfA fscanf -#define wxCRT_VsscanfA vsscanf + +/* vsscanf() may have a wrong declaration with non-const first parameter, fix + * this by wrapping it if necessary. */ +#if defined __cplusplus && defined HAVE_BROKEN_VSSCANF_DECL + inline int wxCRT_VsscanfA(const char *str, const char *format, va_list ap) + { + return vsscanf(const_cast(str), format, ap); + } +#else + #define wxCRT_VsscanfA vsscanf +#endif #if defined(wxNEED_WPRINTF) int wxCRT_ScanfW(const wchar_t *format, ...); diff --git a/setup.h.in b/setup.h.in index 0e66ca3637..9530999bea 100644 --- a/setup.h.in +++ b/setup.h.in @@ -1001,6 +1001,10 @@ * with 'char*' for the 3rd parameter instead of 'const char*' */ #undef HAVE_BROKEN_VSNPRINTF_DECL +/* Define if you have a _broken_ vsscanf() declaration in the header, + * with 'char*' for the 1st parameter instead of 'const char*' */ +#undef HAVE_BROKEN_VSSCANF_DECL + /* Define if you have vsscanf() */ #undef HAVE_VSSCANF diff --git a/setup.h_vms b/setup.h_vms index 182b018306..70955eb41c 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -1107,6 +1107,10 @@ typedef pid_t GPid; * with 'char*' for the 3rd parameter instead of 'const char*' */ #undef HAVE_BROKEN_VSNPRINTF_DECL +/* Define if you have a _broken_ vsscanf() declaration in the header, + * with 'char*' for the 1st parameter instead of 'const char*' */ +#undef HAVE_BROKEN_VSSCANF_DECL + /* Define if you have vsscanf() */ #define HAVE_VSSCANF 1