From dbc4e4dc52f75dfac86b0a765b8a527d22adbb12 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Feb 2017 00:24:11 +0100 Subject: [PATCH 1/4] Add a section with compatibility-related macros to the documentation Although WXWIN_COMPATIBILITY_x_y macros were mentioned in the backwards compatibility overview, it seems appropriate to also document them with all the other macros on the page dedicated to them. --- docs/doxygen/mainpages/const_cpp.h | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index edadff7088..802a8c7d99 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -243,6 +243,51 @@ the project that uses wxWidgets to the same value as the @c CFG variable in order for the correct @c wx/setup.h file to automatically be included for that configuration. + +@section page_cppconst_compatibility Compatibility Macros + +wxWidgets always tries to preserve source backwards compatibility, however +sometimes existing symbols may need to be removed. Except in exceedingly rare +cases, this happens in several steps: first, the symbol is marked as +deprecated, so that using it results in a warning when using the common +compilers (e.g. any non-ancient version of MSVC, gcc or clang) in some +wxWidgets release @c x.y. It can still be used, however the warnings indicate +all the places in your code which will need to be updated in the future. If +your code doesn't use any deprecated symbols or you have already fixed all +their occurrences, you may change @c WXWIN_COMPATIBILITY_x_y to 0 to ensure +they can't be used -- however its default value is still 1 at this time. + +At some point in the future, the next stable wxWidgets release @c x.y+2 changes +the default @c WXWIN_COMPATIBILITY_x_y value to 0, meaning that now the symbol +becomes unavailable by default and if you still want to be able to compile the +code using it, you need to explicitly change @c WXWIN_COMPATIBILITY_x_y to 1 +when building the library. + +And, finally, the symbol is completely removed from the library in the next +stable version after this, i.e. @c x.y+4. @c WXWIN_COMPATIBILITY_x_y itself is +removed as well at this time, as it is not useful any longer. + +According to this general rule, currently, i.e. in wxWidgets 3.2, the following +two symbols are defined: @c WXWIN_COMPATIBILITY_2_8, as 0, and @c +WXWIN_COMPATIBILITY_3_0, as 1. Please see @ref overview_backwardcompat for even +more details. + +@beginDefList +@itemdef{WXWIN_COMPATIBILITY_2_8, + defined as 0 by default meaning that symbols existing in wxWidgets 2.8 + but deprecated in 3.0 release are not available by default. It can be + changed to 1 to make them available, but it is strongly recommended to + update the code using them instead.} +@itemdef{WXWIN_COMPATIBILITY_3_0, + defined as 1 by default meaning that symbols existing in wxWidgets 3.0 + but deprecated since then are still available. It can be changed to 1 + to ensure that no deprecated symbols are used accidentally.} +@itemdef{wxDIALOG_UNIT_COMPATIBILITY, + wxMSW-specific setting which can be set to 1 to make + wxWindow::GetCharWidth() and wxWindow::GetCharHeight() more compatible + with old wxWidgets versions. Changing it is not recommended.} +@endDefList + @section page_cppconst_miscellaneous Miscellaneous @beginDefList From 3d17d9409f9c83fd89b4633071a46a96105fe801 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Feb 2017 02:24:53 +0100 Subject: [PATCH 2/4] Regenerate setup.h.in using build/update-setup-h Undo the apparently manual change to setup.h.in in 8b5387bc3da33f437a53edcb11847802b628eb70 by regenerating it. Notice that this doesn't actually change anything as wxUSE_ACCESSIBILITY will be correctly set to 1 by configure by default, but doing this avoids having unrelated changes in the future commits. --- setup.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.h.in b/setup.h.in index 0e596334db..966aad994d 100644 --- a/setup.h.in +++ b/setup.h.in @@ -545,7 +545,7 @@ #define wxUSE_DRAG_AND_DROP 0 #ifdef __WXMSW__ -#define wxUSE_ACCESSIBILITY 1 +#define wxUSE_ACCESSIBILITY 0 #else #define wxUSE_ACCESSIBILITY 0 #endif From 4cc45797a120d3ac27e5bc2c417faa03da0d016a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Feb 2017 02:27:22 +0100 Subject: [PATCH 3/4] Fix wxUSE_DC_TRANSFORM_MATRIX comment in wx/setup_inc.h Propagate the change done in 49000defcfb11b409d8935126981b14169ee62a3 to the generated include/wx/msw/setup0.h file to wx/setup_inc.h, so that this change won't be lost during future regenerations. --- include/wx/android/setup.h | 6 +++--- include/wx/gtk/setup0.h | 6 +++--- include/wx/motif/setup0.h | 6 +++--- include/wx/osx/setup0.h | 6 +++--- include/wx/setup_inc.h | 6 +++--- include/wx/univ/setup0.h | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h index 9e8c35e644..2291c62a52 100644 --- a/include/wx/android/setup.h +++ b/include/wx/android/setup.h @@ -1431,9 +1431,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/include/wx/gtk/setup0.h b/include/wx/gtk/setup0.h index d66b698478..27ef6957b5 100644 --- a/include/wx/gtk/setup0.h +++ b/include/wx/gtk/setup0.h @@ -1432,9 +1432,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/include/wx/motif/setup0.h b/include/wx/motif/setup0.h index cf922bc5a8..cc609cf02e 100644 --- a/include/wx/motif/setup0.h +++ b/include/wx/motif/setup0.h @@ -1432,9 +1432,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/include/wx/osx/setup0.h b/include/wx/osx/setup0.h index 4ba8eb2bf2..a7112dfa97 100644 --- a/include/wx/osx/setup0.h +++ b/include/wx/osx/setup0.h @@ -1433,9 +1433,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index ca8f94bd50..09063c0c7a 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -1428,9 +1428,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/include/wx/univ/setup0.h b/include/wx/univ/setup0.h index 42f75c700d..a235d4927b 100644 --- a/include/wx/univ/setup0.h +++ b/include/wx/univ/setup0.h @@ -1431,9 +1431,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 From e125c3b6573972ccfc06d228a7d5abd5306f73be Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Feb 2017 00:47:35 +0100 Subject: [PATCH 4/4] Allow disabling unsafe implicit conversions in wxString While we have to keep these conversions enabled by default, they are very dangerous as they can result in silent data loss on any system not using a locale with UTF-8 encoding, i.e. always under MSW. Allow mitigating this by defining wxNO_UNSAFE_WXSTRING_CONV when compiling the application code using the library, which makes these conversions invisible to the user code, and so can be used without recompiling the library. Also add wxUSE_UNSAFE_WXSTRING_CONV which can be set to 0 when compiling the library to disable these conversions globally for all applications using it. Closes #11830. --- configure | 36 ++++++++++++++++++++++++++++++ configure.in | 5 +++++ docs/changes.txt | 1 + docs/doxygen/mainpages/const_cpp.h | 17 ++++++++++++++ include/wx/android/setup.h | 12 ++++++++++ include/wx/chkconf.h | 8 +++++++ include/wx/gtk/setup0.h | 12 ++++++++++ include/wx/motif/setup0.h | 12 ++++++++++ include/wx/msw/setup0.h | 12 ++++++++++ include/wx/osx/setup0.h | 12 ++++++++++ include/wx/setup_inc.h | 12 ++++++++++ include/wx/string.h | 7 +++++- include/wx/univ/setup0.h | 12 ++++++++++ setup.h.in | 2 ++ 14 files changed, 159 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 2f72f2abb1..5994e3d50f 100755 --- a/configure +++ b/configure @@ -1119,6 +1119,7 @@ enable_std_containers_compat enable_std_iostreams enable_std_string enable_std_string_conv_in_wxstring +enable_unsafe_conv_in_wxstring enable_unicode enable_utf8 enable_utf8only @@ -2057,6 +2058,7 @@ Optional Features: --enable-std_iostreams use standard C++ stream classes --enable-std_string use standard C++ string classes --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString + --disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString --disable-unicode compile without Unicode support --enable-utf8 use UTF-8 representation for strings (Unix only) --enable-utf8only only support UTF-8 locales in UTF-8 build (Unix only) @@ -5469,6 +5471,35 @@ fi eval "$wx_cv_use_std_string_conv_in_wxstring" + enablestring=disable + defaultval= + if test -z "$defaultval"; then + if test x"$enablestring" = xdisable; then + defaultval=yes + else + defaultval=no + fi + fi + + # Check whether --enable-unsafe_conv_in_wxstring was given. +if test "${enable_unsafe_conv_in_wxstring+set}" = set; then : + enableval=$enable_unsafe_conv_in_wxstring; + if test "$enableval" = yes; then + wx_cv_use_unsafe_conv_in_wxstring='wxUSE_UNSAFE_WXSTRING_CONV=yes' + else + wx_cv_use_unsafe_conv_in_wxstring='wxUSE_UNSAFE_WXSTRING_CONV=no' + fi + +else + + wx_cv_use_unsafe_conv_in_wxstring='wxUSE_UNSAFE_WXSTRING_CONV=${'DEFAULT_wxUSE_UNSAFE_WXSTRING_CONV":-$defaultval}" + +fi + + + eval "$wx_cv_use_unsafe_conv_in_wxstring" + + enablestring=disable defaultval= if test -z "$defaultval"; then @@ -32527,6 +32558,11 @@ if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then fi +if test "$wxUSE_UNSAFE_WXSTRING_CONV" = "yes"; then + $as_echo "#define wxUSE_UNSAFE_WXSTRING_CONV 1" >>confdefs.h + +fi + if test "$wxUSE_STDPATHS" = "yes"; then $as_echo "#define wxUSE_STDPATHS 1" >>confdefs.h diff --git a/configure.in b/configure.in index 99e15b4784..75ba90ec7f 100644 --- a/configure.in +++ b/configure.in @@ -642,6 +642,7 @@ WX_ARG_ENABLE(std_containers_compat, [ --enable-std_containers_compat use s WX_ARG_ENABLE(std_iostreams, [ --enable-std_iostreams use standard C++ stream classes], wxUSE_STD_IOSTREAM) WX_ARG_ENABLE(std_string, [ --enable-std_string use standard C++ string classes], wxUSE_STD_STRING) WX_ARG_ENABLE(std_string_conv_in_wxstring, [ --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString], wxUSE_STD_STRING_CONV_IN_WXSTRING) +WX_ARG_DISABLE(unsafe_conv_in_wxstring, [ --disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString], wxUSE_UNSAFE_WXSTRING_CONV) WX_ARG_DISABLE(unicode, [ --disable-unicode compile without Unicode support], wxUSE_UNICODE) WX_ARG_ENABLE_PARAM(utf8, [ --enable-utf8 use UTF-8 representation for strings (Unix only)], wxUSE_UNICODE_UTF8) WX_ARG_ENABLE(utf8only, [ --enable-utf8only only support UTF-8 locales in UTF-8 build (Unix only)], wxUSE_UNICODE_UTF8_LOCALE) @@ -5665,6 +5666,10 @@ if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then AC_DEFINE(wxUSE_STD_STRING_CONV_IN_WXSTRING) fi +if test "$wxUSE_UNSAFE_WXSTRING_CONV" = "yes"; then + AC_DEFINE(wxUSE_UNSAFE_WXSTRING_CONV) +fi + if test "$wxUSE_STDPATHS" = "yes"; then AC_DEFINE(wxUSE_STDPATHS) fi diff --git a/docs/changes.txt b/docs/changes.txt index a8630936dd..124e2befb8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -69,6 +69,7 @@ INCOMPATIBLE CHANGES SINCE 3.1.0: All: - Add wxSecretStore for storing passwords using the OS-provided facilities. +- Add support for compiling application code with wxNO_UNSAFE_WXSTRING_CONV. - Add support for the micro version (third component) to OS and toolkit version functions. See wxGetOsVersion(), wxPlatformInfo, and wxAppTraits. - wxLogInfo() now logs messages if the log level is high enough, even without diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index 802a8c7d99..1756d18a82 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -286,6 +286,14 @@ more details. wxMSW-specific setting which can be set to 1 to make wxWindow::GetCharWidth() and wxWindow::GetCharHeight() more compatible with old wxWidgets versions. Changing it is not recommended.} +@itemdef{wxUSE_UNSAFE_WXSTRING_CONV, + this option determines if unsafe implicit conversions of wxString to + @c char* or @c std::string (depending on whether @c wxUSE_STL is 0 or + 1) are defined. It is set to 1 by default for compatibility reasons, + however it is recommended to set it to 0 for the new projects. See + also @c wxNO_UNSAFE_WXSTRING_CONV below for an alternative way of + disabling these unsafe conversions not requiring rebuilding the + library.} @endDefList @section page_cppconst_miscellaneous Miscellaneous @@ -326,6 +334,15 @@ more details. don't include compiler flags needed for multithreaded code generation. This implies that wxUSE_THREADS is 0 and also that other (non-wx-based) threading packages cannot be used neither.} +@itemdef{wxNO_UNSAFE_WXSTRING_CONV, + this symbol is not defined by wxWidgets itself, but can be defined by + the applications using the library to disable unsafe implicit + conversions in wxString class. This is especially useful when using + standard build of the library, e.g. installed by the system package + manager under Unix, which is compiled with @c wxUSE_UNSAFE_WXSTRING_CONV + set to 1 for compatibility reasons as @c -DwxNO_UNSAFE_WXSTRING_CONV + can be used only compiling the application code, without rebuilding the + library. Support for this option appeared in wxWidgets 3.1.1.} @itemdef{WXMAKINGDLL_XXX, used internally and defined when building the library @c XXX as a DLL; when a monolithic wxWidgets build is used only a diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h index 2291c62a52..3249bd429f 100644 --- a/include/wx/android/setup.h +++ b/include/wx/android/setup.h @@ -54,6 +54,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 2722a6b6a8..3fee662977 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -373,6 +373,14 @@ # endif #endif /* !defined(wxUSE_UNICODE) */ +#ifndef wxUSE_UNSAFE_WXSTRING_CONV +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_UNSAFE_WXSTRING_CONV must be defined, please read comment near the top of this file." +# else +# define wxUSE_UNSAFE_WXSTRING_CONV 0 +# endif +#endif /* !defined(wxUSE_UNSAFE_WXSTRING_CONV) */ + #ifndef wxUSE_URL # ifdef wxABORT_ON_CONFIG_ERROR # error "wxUSE_URL must be defined, please read comment near the top of this file." diff --git a/include/wx/gtk/setup0.h b/include/wx/gtk/setup0.h index 27ef6957b5..b99ba3ce3e 100644 --- a/include/wx/gtk/setup0.h +++ b/include/wx/gtk/setup0.h @@ -55,6 +55,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/motif/setup0.h b/include/wx/motif/setup0.h index cc609cf02e..9c9fb35f33 100644 --- a/include/wx/motif/setup0.h +++ b/include/wx/motif/setup0.h @@ -55,6 +55,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index 6b4d8bc7dc..ca1579941e 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -55,6 +55,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/osx/setup0.h b/include/wx/osx/setup0.h index a7112dfa97..4a1f5d1604 100644 --- a/include/wx/osx/setup0.h +++ b/include/wx/osx/setup0.h @@ -56,6 +56,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index 09063c0c7a..b8d5e21b32 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -51,6 +51,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/include/wx/string.h b/include/wx/string.h index 7b39add2b1..3441a7f7d6 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -1263,7 +1263,9 @@ public: // they conflict with the implicit conversions to "const char/wchar_t *" // which we use for backwards compatibility but do provide them if // explicitly requested. +#if wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) operator wxStringToStdStringRetType() const { return ToStdString(); } +#endif // wxUSE_UNSAFE_WXSTRING_CONV operator wxStringToStdWstringRetType() const { return ToStdWstring(); } #endif // wxUSE_STD_STRING_CONV_IN_WXSTRING @@ -1517,13 +1519,16 @@ public: // messages for the code which relies on implicit conversion to char* in // STL build #if !wxUSE_STD_STRING_CONV_IN_WXSTRING - operator const char*() const { return c_str(); } operator const wchar_t*() const { return c_str(); } +#if wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) + operator const char*() const { return c_str(); } // implicit conversion to untyped pointer for compatibility with previous // wxWidgets versions: this is the same as conversion to const char * so it // may fail! operator const void*() const { return c_str(); } +#endif // wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) + #endif // !wxUSE_STD_STRING_CONV_IN_WXSTRING // identical to c_str(), for MFC compatibility diff --git a/include/wx/univ/setup0.h b/include/wx/univ/setup0.h index a235d4927b..3a0f7d86e2 100644 --- a/include/wx/univ/setup0.h +++ b/include/wx/univ/setup0.h @@ -54,6 +54,18 @@ // Recommended setting: 0 #define wxDIALOG_UNIT_COMPATIBILITY 0 +// Provide unsafe implicit conversions in wxString to "const char*" or +// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). +// +// Default is 1 but only for compatibility reasons, it is recommended to set +// this to 0 because converting wxString to a narrow (non-Unicode) string may +// fail unless a locale using UTF-8 encoding is used, which is never the case +// under MSW, for example, hence such conversions can result in silent data +// loss. +// +// Recommended setting: 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 1 + // ---------------------------------------------------------------------------- // debugging settings // ---------------------------------------------------------------------------- diff --git a/setup.h.in b/setup.h.in index 966aad994d..2093812921 100644 --- a/setup.h.in +++ b/setup.h.in @@ -151,6 +151,8 @@ #define wxDIALOG_UNIT_COMPATIBILITY 0 +#define wxUSE_UNSAFE_WXSTRING_CONV 0 + #define wxUSE_ON_FATAL_EXCEPTION 0