mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0027197: Configuration - fix compilation issues when using mingw
AIS_ColorScale, AIS_Dimension - the protected method DrawText() has been renamed to drawText() to avoid name collisions with macros. _MSC_VER/_WIN32 misuse has been fixed in several places. Header <malloc.h> is now included where alloca() is used. Draw_Window - dllimport flag has been dropped from inline methods. TKernel - mandatory dependencies Winspool.lib and Psapi.lib are now linked explicitly (instead of msvc-specific pragma syntax). CMake scripts - the option -std=c++0x has been replaced by -std=gnu++0x for mingw to allow extensions (like _wfopen() and others). The minimum Windows version has been set to _WIN32_WINNT=0x0501. Invalid options "-z defs" and "-lm" have been dropped for mingw. Flag --export-all-symbols has been added to CMAKE_SHARED_LINKER_FLAGS to workaround missing vtable symbols when using mingw. FreeType is now linked explicitly on Windows. Draw::Load() - "lib" suffix is now prepended on mingw as well. Drop redundant declaration of _TINT from OSD_WNT_1.hxx. NCollection_UtfString::FromLocale() - platform-specific code has been moved to .cxx file. Draw_BasicCommands - fixed incorrect mingw64 version macros. genproj, cbp - added workaround for process argument list limits on Windows. TKSTEP linkage is failing on this platform due to too long list of files. The list of object files to link is now stored in dedicated file which is passed to gcc. Option "-z defs" removed from CMake linker options to avoid problems when building with different configurations of VTK on Linux Some MinGW-specific compiler warnings (potentially uninitialized vars, use of NULL, parentheses in conditional expressions) are fixed (speculatively)
This commit is contained in:
@@ -272,6 +272,28 @@ void NCollection_UtfString<Type>::FromUnicode (const TypeFrom* theStringU
|
||||
strFree (anOldBuffer);
|
||||
}
|
||||
|
||||
//! Auxiliary convertion tool.
|
||||
class NCollection_UtfStringTool
|
||||
{
|
||||
public:
|
||||
//! Empty constructor.
|
||||
NCollection_UtfStringTool() : myWideBuffer (NULL) {}
|
||||
|
||||
//! Destructor for temporary resources.
|
||||
Standard_EXPORT ~NCollection_UtfStringTool();
|
||||
|
||||
//! Convert the string from current locale into UNICODE (wide characters) using system APIs.
|
||||
//! Returned pointer will be released by this tool.
|
||||
Standard_EXPORT wchar_t* FromLocale (const char* theString);
|
||||
|
||||
//! Convert the UNICODE (wide characters) string into locale using system APIs.
|
||||
Standard_EXPORT static bool ToLocale (const wchar_t* theWideString,
|
||||
char* theBuffer,
|
||||
const Standard_Integer theSizeBytes);
|
||||
private:
|
||||
wchar_t* myWideBuffer; //!< temporary variable
|
||||
};
|
||||
|
||||
// =======================================================================
|
||||
// function : FromLocale
|
||||
// purpose :
|
||||
@@ -280,34 +302,14 @@ template<typename Type> inline
|
||||
void NCollection_UtfString<Type>::FromLocale (const char* theString,
|
||||
const Standard_Integer theLength)
|
||||
{
|
||||
#if(defined(_WIN32) || defined(__WIN32__))
|
||||
// use WinAPI
|
||||
int aWideSize = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, theString, -1, NULL, 0);
|
||||
if (aWideSize <= 0)
|
||||
NCollection_UtfStringTool aConvertor;
|
||||
wchar_t* aWideBuffer = aConvertor.FromLocale (theString);
|
||||
if (aWideBuffer == NULL)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
wchar_t* aWideBuffer = new wchar_t[aWideSize + 1];
|
||||
MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, theString, -1, aWideBuffer, aWideSize);
|
||||
aWideBuffer[aWideSize] = L'\0';
|
||||
FromUnicode (aWideBuffer, theLength);
|
||||
delete[] aWideBuffer;
|
||||
#else
|
||||
// this is size in bytes but should probably be enough to store string in wide chars
|
||||
// notice that these functions are sensitive to locale set by application!
|
||||
int aMbLen = mblen (theString, MB_CUR_MAX);
|
||||
if (aMbLen <= 0)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
wchar_t* aWideBuffer = new wchar_t[aMbLen + 1];
|
||||
mbstowcs (aWideBuffer, theString, aMbLen);
|
||||
aWideBuffer[aMbLen] = L'\0';
|
||||
FromUnicode (aWideBuffer, theLength);
|
||||
delete[] aWideBuffer;
|
||||
#endif
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -319,17 +321,7 @@ bool NCollection_UtfString<Type>::ToLocale (char* theBuffer,
|
||||
const Standard_Integer theSizeBytes) const
|
||||
{
|
||||
NCollection_UtfString<wchar_t> aWideCopy (myString, myLength);
|
||||
#if(defined(_WIN32) || defined(__WIN32__))
|
||||
int aMbBytes = WideCharToMultiByte (CP_ACP, 0, aWideCopy.ToCString(), -1, theBuffer, theSizeBytes, NULL, NULL);
|
||||
#else
|
||||
std::size_t aMbBytes = std::wcstombs (theBuffer, aWideCopy.ToCString(), theSizeBytes);
|
||||
#endif
|
||||
if (aMbBytes <= 0)
|
||||
{
|
||||
*theBuffer = '\0';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return NCollection_UtfStringTool::ToLocale (aWideCopy.ToCString(), theBuffer, theSizeBytes);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
Reference in New Issue
Block a user