Kaydet (Commit) 2d5dd9a9 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

sb140: sb140: #i116981# clean up memory upon exit

üst e700031c
...@@ -122,8 +122,8 @@ extern "C" { ...@@ -122,8 +122,8 @@ extern "C" {
If it is never called, a the filename executable.ini (win) If it is never called, a the filename executable.ini (win)
or execuablerc (unx) is assumed. or execuablerc (unx) is assumed.
@param pName Name of the inifile with path but WITHOUT @param pName URL of the ini file; must not be null, must not be the empty
suffix (.ini or rc) string
*/ */
void SAL_CALL rtl_bootstrap_setIniFileName( rtl_uString *pName ) void SAL_CALL rtl_bootstrap_setIniFileName( rtl_uString *pName )
SAL_THROW_EXTERN_C(); SAL_THROW_EXTERN_C();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove // MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sal.hxx" #include "precompiled_sal.hxx"
#include "boost/noncopyable.hpp"
#include "rtl/bootstrap.h" #include "rtl/bootstrap.h"
#include "rtl/bootstrap.hxx" #include "rtl/bootstrap.hxx"
#include <osl/diagnose.h> #include <osl/diagnose.h>
...@@ -50,13 +51,16 @@ ...@@ -50,13 +51,16 @@
#include "macro.hxx" #include "macro.hxx"
#include <boost/unordered_map.hpp> #include <algorithm>
#include <list> #include <map>
#include <memory>
#include <utility>
#define MY_STRING_(x) # x #define MY_STRING_(x) # x
#define MY_STRING(x) MY_STRING_(x) #define MY_STRING(x) MY_STRING_(x)
//---------------------------------------------------------------------------- extern "C" oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl(
rtl_uString ** ppFileURL) SAL_THROW_EXTERN_C();
using osl::DirectoryItem; using osl::DirectoryItem;
using osl::FileStatus; using osl::FileStatus;
...@@ -121,127 +125,100 @@ rtl::OUString recursivelyExpandMacros( ...@@ -121,127 +125,100 @@ rtl::OUString recursivelyExpandMacros(
return expandMacros(file, text, mode, &link); return expandMacros(file, text, mode, &link);
} }
} class ParameterMap: private boost::noncopyable {
public:
bool get(rtl::OUString const & key, rtl::OUString * value) const;
//---------------------------------------------------------------------------- protected:
ParameterMap() {}
struct rtl_bootstrap_NameValue ~ParameterMap() {}
{
OUString sName;
OUString sValue;
inline rtl_bootstrap_NameValue() SAL_THROW( () )
{}
inline rtl_bootstrap_NameValue(
OUString const & name, OUString const & value ) SAL_THROW( () )
: sName( name ),
sValue( value )
{}
};
typedef std::list< typedef std::map< rtl::OUString, rtl::OUString > Map;
rtl_bootstrap_NameValue,
rtl::Allocator< rtl_bootstrap_NameValue >
> NameValueList;
bool find( Map map_;
NameValueList const & list, rtl::OUString const & key, };
rtl::OUString * value)
{ bool ParameterMap::get(rtl::OUString const & key, rtl::OUString * value) const {
OSL_ASSERT(value != NULL); OSL_ASSERT(value != 0);
for (NameValueList::const_iterator i(list.begin()); i != list.end(); ++i) { Map::const_iterator i(map_.find(key));
if (i->sName == key) { if (i == map_.end()) {
*value = i->sValue; return false;
return true; } else {
} *value = i->second;
return true;
} }
return false;
} }
namespace { class ExplicitParameterMap: public ParameterMap {
struct rtl_bootstrap_set_list : public:
public rtl::Static< NameValueList, rtl_bootstrap_set_list > {}; bool get(rtl::OUString const & key, rtl::OUString * value) const;
}
//---------------------------------------------------------------------------- void set(rtl::OUString const & key, rtl::OUString const & value);
static sal_Bool getFromCommandLineArgs( private:
rtl::OUString const & key, rtl::OUString * value ) mutable osl::Mutex mutex_;
};
bool ExplicitParameterMap::get(rtl::OUString const & key, rtl::OUString * value)
const
{ {
OSL_ASSERT(value != NULL); osl::MutexGuard g(mutex_);
static NameValueList *pNameValueList = 0; return ParameterMap::get(key, value);
if( ! pNameValueList ) }
{
static NameValueList nameValueList;
sal_Int32 nArgCount = osl_getCommandArgCount(); void ExplicitParameterMap::set(
for(sal_Int32 i = 0; i < nArgCount; ++ i) rtl::OUString const & key, rtl::OUString const & value)
{ {
rtl_uString *pArg = 0; osl::MutexGuard g(mutex_);
osl_getCommandArg( i, &pArg ); map_[key] = value;
if( ('-' == pArg->buffer[0] || '/' == pArg->buffer[0] ) && }
'e' == pArg->buffer[1] &&
'n' == pArg->buffer[2] &&
'v' == pArg->buffer[3] &&
':' == pArg->buffer[4] )
{
sal_Int32 nIndex = rtl_ustr_indexOfChar( pArg->buffer, '=' );
if( nIndex >= 0 )
{
rtl_bootstrap_NameValue nameValue; struct ExplicitParameters:
nameValue.sName = OUString( &(pArg->buffer[5]), nIndex - 5 ); public rtl::Static< ExplicitParameterMap, ExplicitParameters >
nameValue.sValue = OUString( &(pArg->buffer[nIndex+1]) ); {};
if( i == nArgCount-1 &&
nameValue.sValue.getLength() &&
nameValue.sValue[nameValue.sValue.getLength()-1] == 13 )
{
// avoid the 13 linefeed for the last argument,
// when the executable is started from a script,
// that was edited on windows
nameValue.sValue = nameValue.sValue.copy(0,nameValue.sValue.getLength()-1);
}
nameValueList.push_back( nameValue );
}
}
rtl_uString_release( pArg );
}
pNameValueList = &nameValueList;
}
sal_Bool found = sal_False; class CommandLineParameterMap: public ParameterMap {
public:
CommandLineParameterMap();
};
for( NameValueList::iterator ii = pNameValueList->begin() ; CommandLineParameterMap::CommandLineParameterMap() {
ii != pNameValueList->end() ; sal_uInt32 n = osl_getCommandArgCount();
++ii ) for (sal_uInt32 i = 0; i != n; ++i) {
{ rtl::OUString s;
if( (*ii).sName.equals(key) ) osl_getCommandArg(i, &s.pData);
{ static char const PREFIX[] = "-env:";
*value = (*ii).sValue; if (s.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(PREFIX))) {
found = sal_True; sal_Int32 j = s.indexOf('=', RTL_CONSTASCII_LENGTH(PREFIX));
break; rtl::OUString k(
s.copy(
RTL_CONSTASCII_LENGTH(PREFIX),
((j < 0 ? s.getLength() : j) -
RTL_CONSTASCII_LENGTH(PREFIX))));
if (j < 0) {
map_.erase(s.copy(RTL_CONSTASCII_LENGTH(PREFIX)));
} else {
map_[
s.copy(
RTL_CONSTASCII_LENGTH(PREFIX),
j - RTL_CONSTASCII_LENGTH(PREFIX))] =
s.copy(j + 1);
}
} }
} }
return found;
} }
//---------------------------------------------------------------------------- struct CommandLineParameters:
public rtl::Static< CommandLineParameterMap, CommandLineParameters >
extern "C" oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( {};
rtl_uString ** ppFileURL) SAL_THROW_EXTERN_C();
inline void getExecutableFile_Impl (rtl_uString ** ppFileURL)
{
osl_bootstrap_getExecutableFile_Impl (ppFileURL);
} }
//----------------------------------------------------------------------------
static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL) static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL)
{ {
OUString fileName; OUString fileName;
getExecutableFile_Impl (&(fileName.pData)); osl_bootstrap_getExecutableFile_Impl (&(fileName.pData));
sal_Int32 nDirEnd = fileName.lastIndexOf('/'); sal_Int32 nDirEnd = fileName.lastIndexOf('/');
OSL_ENSURE(nDirEnd >= 0, "Cannot locate executable directory"); OSL_ENSURE(nDirEnd >= 0, "Cannot locate executable directory");
...@@ -249,51 +226,6 @@ static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL) ...@@ -249,51 +226,6 @@ static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL)
rtl_uString_newFromStr_WithLength(ppDirURL,fileName.getStr(),nDirEnd); rtl_uString_newFromStr_WithLength(ppDirURL,fileName.getStr(),nDirEnd);
} }
//----------------------------------------------------------------------------
static OUString & getIniFileName_Impl()
{
static OUString *pStaticName = 0;
if( ! pStaticName )
{
OUString fileName;
if(getFromCommandLineArgs(
OUString(RTL_CONSTASCII_USTRINGPARAM("INIFILENAME")), &fileName))
{
resolvePathnameUrl(&fileName);
}
else
{
getExecutableFile_Impl (&(fileName.pData));
// get rid of a potential executable extension
OUString progExt (RTL_CONSTASCII_USTRINGPARAM(".bin"));
if(fileName.getLength() > progExt.getLength()
&& fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt))
fileName = fileName.copy(0, fileName.getLength() - progExt.getLength());
progExt = OUString(RTL_CONSTASCII_USTRINGPARAM(".exe"));
if(fileName.getLength() > progExt.getLength()
&& fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt))
fileName = fileName.copy(0, fileName.getLength() - progExt.getLength());
// append config file suffix
fileName += OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE("")));
}
static OUString theFileName;
if(fileName.getLength())
theFileName = fileName;
pStaticName = &theFileName;
}
return *pStaticName;
}
//----------------------------------------------------------------------------
static inline bool path_exists( OUString const & path ) static inline bool path_exists( OUString const & path )
{ {
DirectoryItem dirItem; DirectoryItem dirItem;
...@@ -312,21 +244,11 @@ inline void EnsureNoFinalSlash (rtl::OUString & url) ...@@ -312,21 +244,11 @@ inline void EnsureNoFinalSlash (rtl::OUString & url)
} }
} }
struct Bootstrap_Impl struct Bootstrap_Impl: private ParameterMap
{ {
sal_Int32 _nRefCount;
Bootstrap_Impl * _base_ini;
NameValueList _nameValueList;
OUString _iniName; OUString _iniName;
explicit Bootstrap_Impl (OUString const & rIniName); explicit Bootstrap_Impl (OUString const & rIniName);
~Bootstrap_Impl();
static void * operator new (std::size_t n) SAL_THROW(())
{ return rtl_allocateMemory (sal_uInt32(n)); }
static void operator delete (void * p , std::size_t) SAL_THROW(())
{ rtl_freeMemory (p); }
bool getValue( bool getValue(
rtl::OUString const & key, rtl_uString ** value, rtl::OUString const & key, rtl_uString ** value,
...@@ -347,25 +269,8 @@ struct Bootstrap_Impl ...@@ -347,25 +269,8 @@ struct Bootstrap_Impl
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
: _nRefCount( 0 ), : _iniName (rIniName)
_base_ini( 0 ),
_iniName (rIniName)
{ {
OUString base_ini( getIniFileName_Impl() );
// normalize path
FileStatus status( osl_FileStatus_Mask_FileURL );
DirectoryItem dirItem;
if (DirectoryItem::E_None == DirectoryItem::get( base_ini, dirItem ) &&
DirectoryItem::E_None == dirItem.getFileStatus( status ))
{
base_ini = status.getFileURL();
if (! rIniName.equals( base_ini ))
{
_base_ini = static_cast< Bootstrap_Impl * >(
rtl_bootstrap_args_open( base_ini.pData ) );
}
}
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
OString sFile = OUStringToOString(_iniName, RTL_TEXTENCODING_ASCII_US); OString sFile = OUStringToOString(_iniName, RTL_TEXTENCODING_ASCII_US);
OSL_TRACE(__FILE__" -- Bootstrap_Impl() - %s\n", sFile.getStr()); OSL_TRACE(__FILE__" -- Bootstrap_Impl() - %s\n", sFile.getStr());
...@@ -383,21 +288,20 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) ...@@ -383,21 +288,20 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
sal_Int32 nIndex = line.indexOf('='); sal_Int32 nIndex = line.indexOf('=');
if (nIndex >= 1) if (nIndex >= 1)
{ {
struct rtl_bootstrap_NameValue nameValue; rtl::OUString sName = OStringToOUString(
nameValue.sName = OStringToOUString(
line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US ); line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
nameValue.sValue = OStringToOUString( rtl::OUString sValue = OStringToOUString(
line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 ); line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
OString name_tmp = OUStringToOString(nameValue.sName, RTL_TEXTENCODING_ASCII_US); OString name_tmp = OUStringToOString(sName, RTL_TEXTENCODING_ASCII_US);
OString value_tmp = OUStringToOString(nameValue.sValue, RTL_TEXTENCODING_UTF8); OString value_tmp = OUStringToOString(sValue, RTL_TEXTENCODING_UTF8);
OSL_TRACE( OSL_TRACE(
__FILE__" -- pushing: name=%s value=%s\n", __FILE__" -- pushing: name=%s value=%s\n",
name_tmp.getStr(), value_tmp.getStr() ); name_tmp.getStr(), value_tmp.getStr() );
#endif /* OSL_DEBUG_LEVEL > 1 */ #endif /* OSL_DEBUG_LEVEL > 1 */
_nameValueList.push_back(nameValue); map_[sName] = sValue;
} }
} }
osl_closeFile(handle); osl_closeFile(handle);
...@@ -411,60 +315,128 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) ...@@ -411,60 +315,128 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
#endif /* OSL_DEBUG_LEVEL > 1 */ #endif /* OSL_DEBUG_LEVEL > 1 */
} }
//---------------------------------------------------------------------------- namespace {
Bootstrap_Impl::~Bootstrap_Impl() class BootstrapMap: private boost::noncopyable {
{ public:
if (_base_ini != 0) BootstrapMap();
rtl_bootstrap_args_close( _base_ini );
}
//---------------------------------------------------------------------------- ~BootstrapMap();
namespace { Bootstrap_Impl * getIni(rtl::OUString const & uri, bool alwaysCreate);
Bootstrap_Impl * get_static_bootstrap_handle() SAL_THROW(()) void setBaseIniUri(rtl::OUString const & uri);
Bootstrap_Impl * getBaseIni();
Bootstrap_Impl * getFundamentalIni();
private:
typedef std::map< rtl::OUString, Bootstrap_Impl * > Map;
osl::Mutex mutex_;
Map map_;
rtl::OUString baseIniUri_;
Bootstrap_Impl * baseIni_;
bool hasFundamentalIni_;
Bootstrap_Impl * fundamentalIni_;
};
BootstrapMap::BootstrapMap():
baseIni_(0), hasFundamentalIni_(false), fundamentalIni_(0)
{}
BootstrapMap::~BootstrapMap() {
for (Map::iterator i(map_.begin()); i != map_.end(); ++i) {
delete i->second;
}
}
Bootstrap_Impl * BootstrapMap::getIni(
rtl::OUString const & uri, bool alwaysCreate)
{ {
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); rtl::OUString normUri; // normalize URI if possible
static Bootstrap_Impl * s_handle = 0; DirectoryItem dirItem;
if (s_handle == 0) FileStatus status(osl_FileStatus_Mask_FileURL);
if (DirectoryItem::get(uri, dirItem) == DirectoryItem::E_None &&
dirItem.getFileStatus(status) == DirectoryItem::E_None)
{ {
OUString iniName (getIniFileName_Impl()); normUri = status.getFileURL();
s_handle = static_cast< Bootstrap_Impl * >( } else if (alwaysCreate) {
rtl_bootstrap_args_open( iniName.pData ) ); normUri = uri;
if (s_handle == 0) } else {
{ return 0;
Bootstrap_Impl * that = new Bootstrap_Impl( iniName ); }
++that->_nRefCount; osl::MutexGuard g(mutex_);
s_handle = that; Map::iterator i(map_.find(normUri));
if (i == map_.end()) {
std::auto_ptr< Bootstrap_Impl > b(new Bootstrap_Impl(normUri));
std::pair< Map::iterator, bool > ins(
map_.insert(Map::value_type(normUri, b.get())));
b.release();
OSL_ASSERT(ins.second);
i = ins.first;
}
return i->second;
}
void BootstrapMap::setBaseIniUri(rtl::OUString const & uri) {
OSL_ASSERT(uri.getLength() != 0);
osl::MutexGuard g(mutex_);
OSL_ASSERT(baseIniUri_.getLength() == 0 && baseIni_ == 0);
baseIniUri_ = uri;
}
Bootstrap_Impl * BootstrapMap::getBaseIni() {
osl::MutexGuard g(mutex_);
if (baseIni_ == 0) {
rtl::OUString uri;
if (baseIniUri_.getLength() == 0) {
if (CommandLineParameters::get().get(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INIFILENAME")),
&uri))
{
resolvePathnameUrl(&uri);
} else {
osl_bootstrap_getExecutableFile_Impl(&uri.pData);
static char const BIN_EXT[] = ".bin";
static char const EXE_EXT[] = ".bin";
if (uri.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(BIN_EXT))) {
uri = uri.copy(
0, uri.getLength() - RTL_CONSTASCII_LENGTH(BIN_EXT));
} else if (uri.endsWithAsciiL(
RTL_CONSTASCII_STRINGPARAM(EXE_EXT))) {
uri = uri.copy(
0, uri.getLength() - RTL_CONSTASCII_LENGTH(EXE_EXT));
}
uri += rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE("")));
}
} else {
uri = baseIniUri_;
} }
baseIni_ = getIni(uri, true);
} }
return s_handle; return baseIni_;
} }
struct FundamentalIniData { Bootstrap_Impl * BootstrapMap::getFundamentalIni() {
rtlBootstrapHandle ini; osl::MutexGuard g(mutex_);
if (!hasFundamentalIni_) {
FundamentalIniData() { rtl::OUString uri;
OUString uri; fundamentalIni_ =
ini = (getBaseIni()->getValue(
((static_cast< Bootstrap_Impl * >(get_static_bootstrap_handle())-> rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")),
getValue( &uri.pData, 0, LOOKUP_MODE_NORMAL, false, 0) &&
rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")),
&uri.pData, 0, LOOKUP_MODE_NORMAL, false, 0)) &&
resolvePathnameUrl(&uri)) resolvePathnameUrl(&uri))
? rtl_bootstrap_args_open(uri.pData) : NULL; ? getIni(uri, false) : 0;
hasFundamentalIni_ = true;
} }
return fundamentalIni_;
}
~FundamentalIniData() { rtl_bootstrap_args_close(ini); } struct BootstrapMapSingleton:
public rtl::Static< BootstrapMap, BootstrapMapSingleton >
private:
FundamentalIniData(FundamentalIniData &); // not defined
void operator =(FundamentalIniData &); // not defined
};
struct FundamentalIni: public rtl::Static< FundamentalIniData, FundamentalIni >
{}; {};
} }
...@@ -527,18 +499,16 @@ bool Bootstrap_Impl::getValue( ...@@ -527,18 +499,16 @@ bool Bootstrap_Impl::getValue(
getExecutableDirectory_Impl(value); getExecutableDirectory_Impl(value);
return true; return true;
} }
if (_base_ini != NULL && Bootstrap_Impl * b = BootstrapMapSingleton::get().getBaseIni();
_base_ini->getDirectValue(key, value, mode, requestStack)) if (b != this && b->getDirectValue(key, value, mode, requestStack)) {
{
return true; return true;
} }
if (!override && getDirectValue(key, value, mode, requestStack)) { if (!override && getDirectValue(key, value, mode, requestStack)) {
return true; return true;
} }
if (mode == LOOKUP_MODE_NORMAL) { if (mode == LOOKUP_MODE_NORMAL) {
FundamentalIniData const & d = FundamentalIni::get(); b = BootstrapMapSingleton::get().getFundamentalIni();
Bootstrap_Impl const * b = static_cast<Bootstrap_Impl const *>(d.ini); if (b != 0 && b != this &&
if (b != NULL && b != this &&
b->getDirectValue(key, value, mode, requestStack)) b->getDirectValue(key, value, mode, requestStack))
{ {
return true; return true;
...@@ -557,7 +527,7 @@ bool Bootstrap_Impl::getDirectValue( ...@@ -557,7 +527,7 @@ bool Bootstrap_Impl::getDirectValue(
ExpandRequestLink const * requestStack) const ExpandRequestLink const * requestStack) const
{ {
rtl::OUString v; rtl::OUString v;
if (find(_nameValueList, key, &v)) { if (get(key, &v)) {
expandValue(value, v, mode, this, key, requestStack); expandValue(value, v, mode, this, key, requestStack);
return true; return true;
} else { } else {
...@@ -570,12 +540,8 @@ bool Bootstrap_Impl::getAmbienceValue( ...@@ -570,12 +540,8 @@ bool Bootstrap_Impl::getAmbienceValue(
ExpandRequestLink const * requestStack) const ExpandRequestLink const * requestStack) const
{ {
rtl::OUString v; rtl::OUString v;
bool f; if (ExplicitParameters::get().get(key, &v) ||
{ CommandLineParameters::get().get(key, &v) ||
osl::MutexGuard g(osl::Mutex::getGlobalMutex());
f = find(rtl_bootstrap_set_list::get(), key, &v);
}
if (f || getFromCommandLineArgs(key, &v) ||
osl_getEnvironment(key.pData, &v.pData) == osl_Process_E_None) osl_getEnvironment(key.pData, &v.pData) == osl_Process_E_None)
{ {
expandValue(value, v, mode, NULL, key, requestStack); expandValue(value, v, mode, NULL, key, requestStack);
...@@ -601,131 +567,20 @@ void Bootstrap_Impl::expandValue( ...@@ -601,131 +567,20 @@ void Bootstrap_Impl::expandValue(
requestFile, requestKey, requestStack)).pData); requestFile, requestKey, requestStack)).pData);
} }
namespace {
struct bootstrap_map {
typedef boost::unordered_map<
rtl::OUString, Bootstrap_Impl *,
rtl::OUStringHash, std::equal_to< rtl::OUString >,
rtl::Allocator< OUString > > t;
// get and release must only be called properly synchronized via some mutex
// (e.g., osl::Mutex::getGlobalMutex()):
static t * get() {
if (m_map == NULL) {
m_map = new t;
}
return m_map;
}
static void release() {
if (m_map != NULL && m_map->empty()) {
delete m_map;
m_map = NULL;
}
}
private:
bootstrap_map(); // not defined
static t * m_map;
};
bootstrap_map::t * bootstrap_map::m_map = NULL;
}
//----------------------------------------------------------------------------
rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open ( rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open (
rtl_uString * pIniName rtl_uString * pIniName
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
OUString iniName( pIniName ); return BootstrapMapSingleton::get().getIni(rtl::OUString(pIniName), false);
// normalize path
FileStatus status( osl_FileStatus_Mask_FileURL );
DirectoryItem dirItem;
if (DirectoryItem::E_None != DirectoryItem::get( iniName, dirItem ) ||
DirectoryItem::E_None != dirItem.getFileStatus( status ))
{
return 0;
}
iniName = status.getFileURL();
Bootstrap_Impl * that;
osl::ResettableMutexGuard guard( osl::Mutex::getGlobalMutex() );
bootstrap_map::t* p_bootstrap_map = bootstrap_map::get();
bootstrap_map::t::const_iterator iFind( p_bootstrap_map->find( iniName ) );
if (iFind == p_bootstrap_map->end())
{
bootstrap_map::release();
guard.clear();
that = new Bootstrap_Impl( iniName );
guard.reset();
p_bootstrap_map = bootstrap_map::get();
iFind = p_bootstrap_map->find( iniName );
if (iFind == p_bootstrap_map->end())
{
++that->_nRefCount;
::std::pair< bootstrap_map::t::iterator, bool > insertion(
p_bootstrap_map->insert(
bootstrap_map::t::value_type( iniName, that ) ) );
OSL_ASSERT( insertion.second );
}
else
{
Bootstrap_Impl * obsolete = that;
that = iFind->second;
++that->_nRefCount;
guard.clear();
delete obsolete;
}
}
else
{
that = iFind->second;
++that->_nRefCount;
}
return static_cast< rtlBootstrapHandle >( that );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void SAL_CALL rtl_bootstrap_args_close ( void SAL_CALL rtl_bootstrap_args_close (
rtlBootstrapHandle handle rtlBootstrapHandle
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
if (handle == 0) // do nothing; the BootstrapMap::map_ just keeps growing for now
return;
Bootstrap_Impl * that = static_cast< Bootstrap_Impl * >( handle );
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
bootstrap_map::t* p_bootstrap_map = bootstrap_map::get();
OSL_ASSERT(
p_bootstrap_map->find( that->_iniName )->second == that );
--that->_nRefCount;
if (that->_nRefCount == 0)
{
::std::size_t nLeaking = 8; // only hold up to 8 files statically
#if OSL_DEBUG_LEVEL == 1 // nonpro
nLeaking = 0;
#elif OSL_DEBUG_LEVEL > 1 // debug
nLeaking = 1;
#endif /* OSL_DEBUG_LEVEL */
if (p_bootstrap_map->size() > nLeaking)
{
::std::size_t erased = p_bootstrap_map->erase( that->_iniName );
if (erased != 1) {
OSL_ASSERT( false );
}
delete that;
}
bootstrap_map::release();
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -737,18 +592,11 @@ sal_Bool SAL_CALL rtl_bootstrap_get_from_handle( ...@@ -737,18 +592,11 @@ sal_Bool SAL_CALL rtl_bootstrap_get_from_handle(
rtl_uString * pDefault rtl_uString * pDefault
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); return
(handle == 0
sal_Bool found = sal_False; ? BootstrapMapSingleton::get().getBaseIni()
if(ppValue && pName) : static_cast< Bootstrap_Impl * >(handle))->
{ getValue(pName, ppValue, pDefault, LOOKUP_MODE_NORMAL, false, 0);
if (handle == 0)
handle = get_static_bootstrap_handle();
found = static_cast< Bootstrap_Impl * >( handle )->getValue(
pName, ppValue, pDefault, LOOKUP_MODE_NORMAL, false, NULL );
}
return found;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -758,19 +606,12 @@ void SAL_CALL rtl_bootstrap_get_iniName_from_handle ( ...@@ -758,19 +606,12 @@ void SAL_CALL rtl_bootstrap_get_iniName_from_handle (
rtl_uString ** ppIniName rtl_uString ** ppIniName
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
if(ppIniName) rtl_uString_assign(
{ ppIniName,
if(handle) ((handle == 0
{ ? BootstrapMapSingleton::get().getBaseIni()
Bootstrap_Impl * pImpl = static_cast<Bootstrap_Impl*>(handle); : static_cast<Bootstrap_Impl*>(handle))->
rtl_uString_assign(ppIniName, pImpl->_iniName.pData); _iniName.pData));
}
else
{
const OUString & iniName = getIniFileName_Impl();
rtl_uString_assign(ppIniName, iniName.pData);
}
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -779,9 +620,7 @@ void SAL_CALL rtl_bootstrap_setIniFileName ( ...@@ -779,9 +620,7 @@ void SAL_CALL rtl_bootstrap_setIniFileName (
rtl_uString * pName rtl_uString * pName
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); BootstrapMapSingleton::get().setBaseIniUri(rtl::OUString(pName));
OUString & file = getIniFileName_Impl();
file = pName;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -802,32 +641,7 @@ void SAL_CALL rtl_bootstrap_set ( ...@@ -802,32 +641,7 @@ void SAL_CALL rtl_bootstrap_set (
rtl_uString * pValue rtl_uString * pValue
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
const OUString name( pName ); ExplicitParameters::get().set(rtl::OUString(pName), rtl::OUString(pValue));
const OUString value( pValue );
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
NameValueList& r_rtl_bootstrap_set_list = rtl_bootstrap_set_list::get();
NameValueList::iterator iPos( r_rtl_bootstrap_set_list.begin() );
NameValueList::iterator iEnd( r_rtl_bootstrap_set_list.end() );
for ( ; iPos != iEnd; ++iPos )
{
if (iPos->sName.equals( name ))
{
iPos->sValue = value;
return;
}
}
#if OSL_DEBUG_LEVEL > 1
OString cstr_name( OUStringToOString( name, RTL_TEXTENCODING_ASCII_US ) );
OString cstr_value( OUStringToOString( value, RTL_TEXTENCODING_ASCII_US ) );
OSL_TRACE(
"bootstrap.cxx: explicitly setting: name=%s value=%s\n",
cstr_name.getStr(), cstr_value.getStr() );
#endif /* OSL_DEBUG_LEVEL > 1 */
r_rtl_bootstrap_set_list.push_back( rtl_bootstrap_NameValue( name, value ) );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -837,13 +651,14 @@ void SAL_CALL rtl_bootstrap_expandMacros_from_handle ( ...@@ -837,13 +651,14 @@ void SAL_CALL rtl_bootstrap_expandMacros_from_handle (
rtl_uString ** macro rtl_uString ** macro
) SAL_THROW_EXTERN_C() ) SAL_THROW_EXTERN_C()
{ {
if (handle == NULL) { rtl::OUString expanded(
handle = get_static_bootstrap_handle(); expandMacros(
} (handle == 0
OUString expanded( expandMacros( static_cast< Bootstrap_Impl * >( handle ), ? BootstrapMapSingleton::get().getBaseIni()
* reinterpret_cast< OUString const * >( macro ), : static_cast< Bootstrap_Impl * >(handle)),
LOOKUP_MODE_NORMAL, NULL ) ); *reinterpret_cast< OUString const * >(macro), LOOKUP_MODE_NORMAL,
rtl_uString_assign( macro, expanded.pData ); 0));
rtl_uString_assign(macro, expanded.pData);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -909,7 +724,7 @@ rtl::OUString lookup( ...@@ -909,7 +724,7 @@ rtl::OUString lookup(
rtl::OUString const & key, ExpandRequestLink const * requestStack) rtl::OUString const & key, ExpandRequestLink const * requestStack)
{ {
rtl::OUString v; rtl::OUString v;
(file == NULL ? get_static_bootstrap_handle() : file)->getValue( (file == 0 ? BootstrapMapSingleton::get().getBaseIni() : file)->getValue(
key, &v.pData, NULL, mode, override, requestStack); key, &v.pData, NULL, mode, override, requestStack);
return v; return v;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment