1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-08 18:40:55 +03:00
occt/src/Standard/Standard_CLocaleSentry.cxx
kgv 7c65581dd3 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)
2016-03-04 07:31:05 +03:00

126 lines
3.4 KiB
C++

// Created on: 2013-01-17
// Created by: Kirill GAVRILOV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Standard_CLocaleSentry.hxx>
#include <Standard_TypeDef.hxx>
#include <cstring>
#if !defined(__ANDROID__)
namespace
{
//! CLocalePtr - static object representing C locale
class CLocalePtr
{
public:
CLocalePtr()
#ifdef HAVE_XLOCALE_H
: myLocale (newlocale (LC_ALL_MASK, "C", NULL))
#elif defined(_WIN32) && !defined(__MINGW32__)
: myLocale (_create_locale (LC_ALL, "C"))
#else
: myLocale (NULL)
#endif
{}
~CLocalePtr()
{
#ifdef HAVE_XLOCALE_H
freelocale (myLocale);
#elif defined(_WIN32) && !defined(__MINGW32__)
_free_locale (myLocale);
#endif
}
public:
Standard_CLocaleSentry::clocale_t myLocale;
};
static CLocalePtr theCLocale;
}
// =======================================================================
// function : GetCLocale
// purpose :
// =======================================================================
Standard_CLocaleSentry::clocale_t Standard_CLocaleSentry::GetCLocale()
{
return theCLocale.myLocale;
}
// =======================================================================
// function : Standard_CLocaleSentry
// purpose :
// =======================================================================
Standard_CLocaleSentry::Standard_CLocaleSentry()
#ifdef HAVE_XLOCALE_H
: myPrevLocale (uselocale (theCLocale.myLocale)) // switch to C locale within this thread only using xlocale API
#else
: myPrevLocale (setlocale (LC_ALL, 0))
#if defined(_MSC_VER) && (_MSC_VER > 1400)
, myPrevTLocaleState (_configthreadlocale (_ENABLE_PER_THREAD_LOCALE))
#endif
#endif
{
#if !defined(HAVE_XLOCALE_H)
const char* aPrevLocale = (const char* )myPrevLocale;
if (myPrevLocale == NULL
|| (aPrevLocale[0] == 'C' && aPrevLocale[1] == '\0'))
{
myPrevLocale = NULL; // already C locale
return;
}
// copy string as following setlocale calls may invalidate returned pointer
Standard_Size aLen = std::strlen (aPrevLocale) + 1;
myPrevLocale = new char[aLen];
memcpy (myPrevLocale, aPrevLocale, aLen);
setlocale (LC_ALL, "C");
#endif
}
// =======================================================================
// function : ~Standard_CLocaleSentry
// purpose :
// =======================================================================
Standard_CLocaleSentry::~Standard_CLocaleSentry()
{
#if defined(HAVE_XLOCALE_H)
uselocale ((locale_t )myPrevLocale);
#else
if (myPrevLocale != NULL)
{
const char* aPrevLocale = (const char* )myPrevLocale;
setlocale (LC_ALL, aPrevLocale);
delete[] aPrevLocale;
}
#if defined(_MSC_VER) && (_MSC_VER > 1400)
if (myPrevTLocaleState != _ENABLE_PER_THREAD_LOCALE)
{
_configthreadlocale (myPrevTLocaleState);
}
#endif
#endif
}
#endif // __ANDROID__