From d3df9b430c7a29783a5dfbdbec0694a803102b37 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Thu, 9 Jan 2014 20:41:19 +0000 Subject: [PATCH] Fixed compilation with wx 3.0 STL build which doesn't auto cast wxString to const wxChar* --- .svn-revision | 2 +- docs/Changelog | 2 ++ src/AsyncDNS.cpp | 4 ++-- src/AsyncDNS.h | 3 +-- src/DirectoryTreeCtrl.cpp | 2 +- src/IP2Country.cpp | 3 ++- src/PlatformSpecific.cpp | 2 +- src/SafeFile.cpp | 2 +- src/amule.cpp | 2 +- src/libs/common/MuleDebug.cpp | 2 +- src/libs/common/Path.cpp | 6 +++--- src/libs/common/StringFunctions.h | 17 +++++++++++------ src/libs/common/TextFile.cpp | 2 +- src/utils/aLinkCreator/src/ed2khash.cpp | 19 ++----------------- 14 files changed, 30 insertions(+), 38 deletions(-) diff --git a/.svn-revision b/.svn-revision index 0b17c6a3..3e8acb54 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10831 +10832 diff --git a/docs/Changelog b/docs/Changelog index 7f792259..90cc1872 100644 --- a/docs/Changelog +++ b/docs/Changelog @@ -25,6 +25,8 @@ Version 2.4.0 - The river knows. * Boost Asio can now be used as networking layer instead of wxWidgets * Fixed memory leak when AICH hashing already known files * New download links for server list and nodes.dat (with gav616 and xosevp) + * Projects for Visual Studio 2013 (which is now the preferred Win32 compiler) + * Fixed build with wx 3.0 (including STL build) -------------------------------------------------------------------------------- diff --git a/src/AsyncDNS.cpp b/src/AsyncDNS.cpp index 34b11346..c0c08d72 100644 --- a/src/AsyncDNS.cpp +++ b/src/AsyncDNS.cpp @@ -31,11 +31,11 @@ #include "Logger.h" -CAsyncDNS::CAsyncDNS(const wxChar* ipName, DnsSolveType type, wxEvtHandler* handler, void* socket) +CAsyncDNS::CAsyncDNS(const wxString& ipName, DnsSolveType type, wxEvtHandler* handler, void* socket) : wxThread(wxTHREAD_DETACHED) { m_type = type; - m_ipName = ipName; + m_ipName = ipName.wc_str(); // make a deep copy to to circument the thread-unsafe wxString reference counting m_socket = socket; m_handler = handler; } diff --git a/src/AsyncDNS.h b/src/AsyncDNS.h index d453e703..acf61aeb 100644 --- a/src/AsyncDNS.h +++ b/src/AsyncDNS.h @@ -49,8 +49,7 @@ enum DnsSolveType { class CAsyncDNS : public wxThread { public: - /** Note: wxChar* is used to circument the thread-unsafe wxString reference counting. */ - CAsyncDNS(const wxChar* ipName, DnsSolveType type, wxEvtHandler* handler, void* socket = NULL); + CAsyncDNS(const wxString& ipName, DnsSolveType type, wxEvtHandler* handler, void* socket = NULL); virtual ExitCode Entry(); private: diff --git a/src/DirectoryTreeCtrl.cpp b/src/DirectoryTreeCtrl.cpp index 151e4565..d4f1cba5 100644 --- a/src/DirectoryTreeCtrl.cpp +++ b/src/DirectoryTreeCtrl.cpp @@ -118,7 +118,7 @@ void CDirectoryTreeCtrl::Init() continue; } wxString driveStr = CFormat(wxT("%c:")) % drive; - uint32 type = GetDriveType(driveStr + wxT("\\")); + uint32 type = GetDriveType((driveStr + wxT("\\")).wc_str()); // skip removable/undefined drives, share only fixed or remote drives if ((type == 3 || type == 4) // fixed drive / remote drive diff --git a/src/IP2Country.cpp b/src/IP2Country.cpp index e8e26c24..24563daa 100644 --- a/src/IP2Country.cpp +++ b/src/IP2Country.cpp @@ -119,8 +119,9 @@ void CIP2Country::DownloadFinished(uint32 result) wxString newDat = m_DataBasePath + wxT(".download"); // Try to unpack the file, might be an archive + wxWCharBuffer dataBaseName = m_DataBaseName.wc_str(); const wxChar* geoip_files[] = { - m_DataBaseName, + dataBaseName, NULL }; diff --git a/src/PlatformSpecific.cpp b/src/PlatformSpecific.cpp index 312b4fb7..a39474eb 100644 --- a/src/PlatformSpecific.cpp +++ b/src/PlatformSpecific.cpp @@ -158,7 +158,7 @@ int PlatformSpecific::GetMaxConnections() static PlatformSpecific::EFSType doGetFilesystemType(const CPath& path) { - wxWritableWCharBuffer pathRaw(path.GetRaw()); + wxWritableWCharBuffer pathRaw(path.GetRaw().wchar_str()); LPWSTR volume = pathRaw; if (!PathStripToRootW(volume)) { return PlatformSpecific::fsOther; diff --git a/src/SafeFile.cpp b/src/SafeFile.cpp index aa408a12..064f2fe6 100644 --- a/src/SafeFile.cpp +++ b/src/SafeFile.cpp @@ -330,7 +330,7 @@ void CFileDataIO::WriteString(const wxString& str, EUtf8Str eEncode, uint8 SizeL } default: { // Non UTF-8 strings are saved as Latin-1 - wxCharBuffer s1 = wxConvISO8859_1.cWC2MB(str); + wxCharBuffer s1 = str.mb_str(wxConvISO8859_1); WriteStringCore(s1, utf8strNone, SizeLen); } } diff --git a/src/amule.cpp b/src/amule.cpp index 8aa222ee..c92f033e 100644 --- a/src/amule.cpp +++ b/src/amule.cpp @@ -1088,7 +1088,7 @@ void CamuleApp::OnAssertFailure(const wxChar* file, int line, if (msg) { s << wxT(" : ") << msg; } - _wassert(s, file, line); + _wassert(s.wc_str(), file, line); #else // Abort, allows gdb to catch the assertion raise( SIGABRT ); diff --git a/src/libs/common/MuleDebug.cpp b/src/libs/common/MuleDebug.cpp index 3710602d..e6c22795 100644 --- a/src/libs/common/MuleDebug.cpp +++ b/src/libs/common/MuleDebug.cpp @@ -580,7 +580,7 @@ void print_backtrace(unsigned n) wxString trace = get_backtrace(n); // This is because the string is ansi anyway, and the conv classes are very slow - fprintf(stderr, "%s\n", (const char*)unicode2char(trace.c_str())); + fprintf(stderr, "%s\n", (const char*)unicode2char(trace)); } // File_checked_for_headers diff --git a/src/libs/common/Path.cpp b/src/libs/common/Path.cpp index 89c39777..1274847d 100644 --- a/src/libs/common/Path.cpp +++ b/src/libs/common/Path.cpp @@ -254,7 +254,7 @@ CPath::CPath(const wxString& filename) m_filesystem = DeepCopy(filename); m_printable = m_filesystem; #else - fn = wxConvUTF8.cWC2MB(filename); + fn = filename.utf8_str(); m_filesystem = wxConvFile.cMB2WC(fn); // There's no need to try to unmangle the filename here. @@ -276,7 +276,7 @@ CPath::CPath(const CPath& other) CPath CPath::FromUniv(const wxString& path) { - wxCharBuffer fn = wxConvISO8859_1.cWC2MB(path); + wxCharBuffer fn = path.mb_str(wxConvISO8859_1); return CPath(wxConvFile.cMB2WC(fn)); @@ -289,7 +289,7 @@ wxString CPath::ToUniv(const CPath& path) // as a raw bytestream (which is what ISO8859-1 amounts // to), we can always recreate the on-disk filename, as // if we had read it using wx functions. - wxCharBuffer fn = wxConvFile.cWC2MB(path.m_filesystem); + wxCharBuffer fn = path.m_filesystem.mb_str(wxConvFile); return wxConvISO8859_1.cMB2WC(fn); } diff --git a/src/libs/common/StringFunctions.h b/src/libs/common/StringFunctions.h index 7bc10341..3b06002a 100644 --- a/src/libs/common/StringFunctions.h +++ b/src/libs/common/StringFunctions.h @@ -47,10 +47,10 @@ enum EUtf8Str * * Please, DO NOT store pointers returned by unicode2char(), because they * get free'ed as soon as the return value of cWX2MB gets out of scope. - * If you need to store a pointer, use a buffer of type wxWX2MBbuf: + * If you need to store a pointer, use a buffer of type wxCharBuffer: * and then cast it to a char pointer, e.g.: * - * const wxWX2MBbuf buf(unicode2char(aWxString)); + * const wxCharBuffer buf(unicode2char(aWxString)); * * --- Now you can freely use buf as if it were a (const char *) --- * @@ -59,31 +59,36 @@ enum EUtf8Str * * The cast in printf is necessary because variable number of parameter * functions have no type for these parameters, so the automatic casting - * of wxWX2MBbuf to (const char *) is not performed. + * of wxCharBuffer to (const char *) is not performed. * * --- don't worry about memory allocation, memory will be --- * --- free'ed when buf gets out of scope, i.e., upon return --- * - * wxMB2WXbuf, wxWX2MBbuf are always the appropriate return type, + * wxWCharBuffer, wxCharBuffer are always the appropriate return type, * either (wxChar *) or (wxWCharBuffer) * * Use the simplified names Unicode2CharBuf and Char2UnicodeBuf, and * do not declare these names const or the compiler will complain about * a double const. */ -typedef const wxWX2MBbuf Unicode2CharBuf; -typedef const wxMB2WXbuf Char2UnicodeBuf; +typedef const wxCharBuffer Unicode2CharBuf; +typedef const wxWCharBuffer Char2UnicodeBuf; Unicode2CharBuf unicode2char(const wxChar* x); +Unicode2CharBuf unicode2char(const Char2UnicodeBuf& x); +inline Unicode2CharBuf unicode2char(const wxString& x) { return unicode2char(x.wc_str()); } inline Char2UnicodeBuf char2unicode(const char* x) { return wxConvLocal.cMB2WX(x); } inline Unicode2CharBuf unicode2UTF8(const wxChar* x) { return wxConvUTF8.cWX2MB(x); } +inline Unicode2CharBuf unicode2UTF8(const Char2UnicodeBuf& x) { return wxConvUTF8.cWX2MB(x); } +inline Unicode2CharBuf unicode2UTF8(const wxString& x) { return x.utf8_str(); } inline Char2UnicodeBuf UTF82unicode(const char* x) { return wxConvUTF8.cMB2WX(x); } inline const wxCharBuffer char2UTF8(const char *x) { return unicode2UTF8(char2unicode(x)); } inline const wxCharBuffer UTF82char(const char *x) { return unicode2char(UTF82unicode(x)); } inline Unicode2CharBuf filename2char(const wxChar* x) { return wxConvFile.cWC2MB(x); } +inline Unicode2CharBuf filename2char(const wxString& x) { return x.mb_str(wxConvFile); } inline Char2UnicodeBuf char2filename(const char* x) { return wxConvFile.cMB2WC(x); } diff --git a/src/libs/common/TextFile.cpp b/src/libs/common/TextFile.cpp index 5c6e9493..f269f88f 100644 --- a/src/libs/common/TextFile.cpp +++ b/src/libs/common/TextFile.cpp @@ -186,7 +186,7 @@ bool CTextFile::WriteLine(const wxString& line, const wxMBConv& conv) result = wxTextBuffer::GetEOL() + result; } - wxCharBuffer strBuffer = conv.cWC2MB(result); + wxCharBuffer strBuffer = result.mb_str(conv); if (strBuffer) { const size_t length = strlen(strBuffer); diff --git a/src/utils/aLinkCreator/src/ed2khash.cpp b/src/utils/aLinkCreator/src/ed2khash.cpp index 96ff687a..b012fbd2 100644 --- a/src/utils/aLinkCreator/src/ed2khash.cpp +++ b/src/utils/aLinkCreator/src/ed2khash.cpp @@ -33,22 +33,6 @@ #include "ed2khash.h" -// efe, sorry for that, i have not enough time to do the right thing now, but -// please, create a file called like unicodestuff.h and put this. Include in -// alcc.c and here. And remove this stupid comment :) -//----------------------------------------------------------------------------- -// efe, this can be put in a separete include file, if you want to reuse -static wxCSConv aMuleConv(wxS("iso8859-1")); -#ifdef wxUSE_UNICODE - #define unicode2char(x) (const char*) aMuleConv.cWX2MB(x) - #define char2unicode(x) aMuleConv.cMB2WX(x) -#else - #define unicode2char(x) x.c_str() - #define char2unicode(x) x -#endif -//----------------------------------------------------------------------------- - - /// Constructor Ed2kHash::Ed2kHash():MD4() { @@ -70,7 +54,8 @@ bool Ed2kHash::SetED2KHashFromFile(const wxFileName& filename, MD4Hook hook) wxFFile file(filename.GetFullPath(), wxT("rbS")); if (! file.IsOpened()) { - wxLogError (_("Unable to open %s"),unicode2char(filename.GetFullPath())); + // This doesn't make much sense to me, but it is what it was before and actually works. + wxLogError(_("Unable to open %s"), ((const char*)filename.GetFullPath().mb_str(wxConvISO8859_1))); return (false); } else -- 2.11.4.GIT