summaryrefslogtreecommitdiff
path: root/sal/rtl/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-09-09 10:51:20 +0200
committerStephan Bergmann <sbergman@redhat.com>2011-09-09 17:46:36 +0200
commit2d5dd9a9604aeb5fd4e347d7a46acc11da9985a5 (patch)
treeb360825e609e424ca4ecd96901167558f3d5ec80 /sal/rtl/source
parente700031cc4f60f62d862940cd40de73e32f9104b (diff)
sb140: sb140: #i116981# clean up memory upon exit
Diffstat (limited to 'sal/rtl/source')
-rw-r--r--sal/rtl/source/bootstrap.cxx635
1 files changed, 225 insertions, 410 deletions
diff --git a/sal/rtl/source/bootstrap.cxx b/sal/rtl/source/bootstrap.cxx
index 6e3836b08356..e4eadf8ee1c9 100644
--- a/sal/rtl/source/bootstrap.cxx
+++ b/sal/rtl/source/bootstrap.cxx
@@ -29,6 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sal.hxx"
+#include "boost/noncopyable.hpp"
#include "rtl/bootstrap.h"
#include "rtl/bootstrap.hxx"
#include <osl/diagnose.h>
@@ -50,13 +51,16 @@
#include "macro.hxx"
-#include <boost/unordered_map.hpp>
-#include <list>
+#include <algorithm>
+#include <map>
+#include <memory>
+#include <utility>
#define MY_STRING_(x) # 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::FileStatus;
@@ -121,127 +125,100 @@ rtl::OUString recursivelyExpandMacros(
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
-{
- 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 )
- {}
-};
+ ~ParameterMap() {}
-typedef std::list<
- rtl_bootstrap_NameValue,
- rtl::Allocator< rtl_bootstrap_NameValue >
-> NameValueList;
+ typedef std::map< rtl::OUString, rtl::OUString > Map;
-bool find(
- NameValueList const & list, rtl::OUString const & key,
- rtl::OUString * value)
-{
- OSL_ASSERT(value != NULL);
- for (NameValueList::const_iterator i(list.begin()); i != list.end(); ++i) {
- if (i->sName == key) {
- *value = i->sValue;
- return true;
- }
+ Map map_;
+};
+
+bool ParameterMap::get(rtl::OUString const & key, rtl::OUString * value) const {
+ OSL_ASSERT(value != 0);
+ Map::const_iterator i(map_.find(key));
+ if (i == map_.end()) {
+ return false;
+ } else {
+ *value = i->second;
+ return true;
}
- return false;
}
-namespace {
- struct rtl_bootstrap_set_list :
- public rtl::Static< NameValueList, rtl_bootstrap_set_list > {};
-}
+class ExplicitParameterMap: public ParameterMap {
+public:
+ bool get(rtl::OUString const & key, rtl::OUString * value) const;
-//----------------------------------------------------------------------------
+ void set(rtl::OUString const & key, rtl::OUString const & value);
-static sal_Bool getFromCommandLineArgs(
- rtl::OUString const & key, rtl::OUString * value )
+private:
+ mutable osl::Mutex mutex_;
+};
+
+bool ExplicitParameterMap::get(rtl::OUString const & key, rtl::OUString * value)
+ const
{
- OSL_ASSERT(value != NULL);
- static NameValueList *pNameValueList = 0;
- if( ! pNameValueList )
- {
- static NameValueList nameValueList;
+ osl::MutexGuard g(mutex_);
+ return ParameterMap::get(key, value);
+}
- sal_Int32 nArgCount = osl_getCommandArgCount();
- for(sal_Int32 i = 0; i < nArgCount; ++ i)
- {
- rtl_uString *pArg = 0;
- osl_getCommandArg( i, &pArg );
- 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 )
- {
+void ExplicitParameterMap::set(
+ rtl::OUString const & key, rtl::OUString const & value)
+{
+ osl::MutexGuard g(mutex_);
+ map_[key] = value;
+}
- rtl_bootstrap_NameValue nameValue;
- nameValue.sName = OUString( &(pArg->buffer[5]), nIndex - 5 );
- 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;
- }
+struct ExplicitParameters:
+ public rtl::Static< ExplicitParameterMap, ExplicitParameters >
+{};
- sal_Bool found = sal_False;
+class CommandLineParameterMap: public ParameterMap {
+public:
+ CommandLineParameterMap();
+};
- for( NameValueList::iterator ii = pNameValueList->begin() ;
- ii != pNameValueList->end() ;
- ++ii )
- {
- if( (*ii).sName.equals(key) )
- {
- *value = (*ii).sValue;
- found = sal_True;
- break;
+CommandLineParameterMap::CommandLineParameterMap() {
+ sal_uInt32 n = osl_getCommandArgCount();
+ for (sal_uInt32 i = 0; i != n; ++i) {
+ rtl::OUString s;
+ osl_getCommandArg(i, &s.pData);
+ static char const PREFIX[] = "-env:";
+ if (s.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(PREFIX))) {
+ sal_Int32 j = s.indexOf('=', RTL_CONSTASCII_LENGTH(PREFIX));
+ 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;
}
-//----------------------------------------------------------------------------
-
-extern "C" oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl (
- rtl_uString ** ppFileURL) SAL_THROW_EXTERN_C();
+struct CommandLineParameters:
+ public rtl::Static< CommandLineParameterMap, CommandLineParameters >
+{};
-inline void getExecutableFile_Impl (rtl_uString ** ppFileURL)
-{
- osl_bootstrap_getExecutableFile_Impl (ppFileURL);
}
-//----------------------------------------------------------------------------
-
static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL)
{
OUString fileName;
- getExecutableFile_Impl (&(fileName.pData));
+ osl_bootstrap_getExecutableFile_Impl (&(fileName.pData));
sal_Int32 nDirEnd = fileName.lastIndexOf('/');
OSL_ENSURE(nDirEnd >= 0, "Cannot locate executable directory");
@@ -249,51 +226,6 @@ static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL)
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 )
{
DirectoryItem dirItem;
@@ -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;
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(
rtl::OUString const & key, rtl_uString ** value,
@@ -347,25 +269,8 @@ struct Bootstrap_Impl
//----------------------------------------------------------------------------
Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
- : _nRefCount( 0 ),
- _base_ini( 0 ),
- _iniName (rIniName)
+ : _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
OString sFile = OUStringToOString(_iniName, RTL_TEXTENCODING_ASCII_US);
OSL_TRACE(__FILE__" -- Bootstrap_Impl() - %s\n", sFile.getStr());
@@ -383,21 +288,20 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
sal_Int32 nIndex = line.indexOf('=');
if (nIndex >= 1)
{
- struct rtl_bootstrap_NameValue nameValue;
- nameValue.sName = OStringToOUString(
+ rtl::OUString sName = OStringToOUString(
line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
- nameValue.sValue = OStringToOUString(
+ rtl::OUString sValue = OStringToOUString(
line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
#if OSL_DEBUG_LEVEL > 1
- OString name_tmp = OUStringToOString(nameValue.sName, RTL_TEXTENCODING_ASCII_US);
- OString value_tmp = OUStringToOString(nameValue.sValue, RTL_TEXTENCODING_UTF8);
+ OString name_tmp = OUStringToOString(sName, RTL_TEXTENCODING_ASCII_US);
+ OString value_tmp = OUStringToOString(sValue, RTL_TEXTENCODING_UTF8);
OSL_TRACE(
__FILE__" -- pushing: name=%s value=%s\n",
name_tmp.getStr(), value_tmp.getStr() );
#endif /* OSL_DEBUG_LEVEL > 1 */
- _nameValueList.push_back(nameValue);
+ map_[sName] = sValue;
}
}
osl_closeFile(handle);
@@ -411,60 +315,128 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName )
#endif /* OSL_DEBUG_LEVEL > 1 */
}
-//----------------------------------------------------------------------------
+namespace {
-Bootstrap_Impl::~Bootstrap_Impl()
-{
- if (_base_ini != 0)
- rtl_bootstrap_args_close( _base_ini );
-}
+class BootstrapMap: private boost::noncopyable {
+public:
+ BootstrapMap();
-//----------------------------------------------------------------------------
+ ~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() );
- static Bootstrap_Impl * s_handle = 0;
- if (s_handle == 0)
+ rtl::OUString normUri; // normalize URI if possible
+ DirectoryItem dirItem;
+ FileStatus status(osl_FileStatus_Mask_FileURL);
+ if (DirectoryItem::get(uri, dirItem) == DirectoryItem::E_None &&
+ dirItem.getFileStatus(status) == DirectoryItem::E_None)
{
- OUString iniName (getIniFileName_Impl());
- s_handle = static_cast< Bootstrap_Impl * >(
- rtl_bootstrap_args_open( iniName.pData ) );
- if (s_handle == 0)
- {
- Bootstrap_Impl * that = new Bootstrap_Impl( iniName );
- ++that->_nRefCount;
- s_handle = that;
+ normUri = status.getFileURL();
+ } else if (alwaysCreate) {
+ normUri = uri;
+ } else {
+ return 0;
+ }
+ osl::MutexGuard g(mutex_);
+ 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 {
- rtlBootstrapHandle ini;
-
- FundamentalIniData() {
- OUString uri;
- ini =
- ((static_cast< Bootstrap_Impl * >(get_static_bootstrap_handle())->
- getValue(
- rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")),
- &uri.pData, 0, LOOKUP_MODE_NORMAL, false, 0)) &&
+Bootstrap_Impl * BootstrapMap::getFundamentalIni() {
+ osl::MutexGuard g(mutex_);
+ if (!hasFundamentalIni_) {
+ rtl::OUString uri;
+ fundamentalIni_ =
+ (getBaseIni()->getValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")),
+ &uri.pData, 0, LOOKUP_MODE_NORMAL, false, 0) &&
resolvePathnameUrl(&uri))
- ? rtl_bootstrap_args_open(uri.pData) : NULL;
+ ? getIni(uri, false) : 0;
+ hasFundamentalIni_ = true;
}
+ return fundamentalIni_;
+}
- ~FundamentalIniData() { rtl_bootstrap_args_close(ini); }
-
-private:
- FundamentalIniData(FundamentalIniData &); // not defined
- void operator =(FundamentalIniData &); // not defined
-};
-
-struct FundamentalIni: public rtl::Static< FundamentalIniData, FundamentalIni >
+struct BootstrapMapSingleton:
+ public rtl::Static< BootstrapMap, BootstrapMapSingleton >
{};
}
@@ -527,18 +499,16 @@ bool Bootstrap_Impl::getValue(
getExecutableDirectory_Impl(value);
return true;
}
- if (_base_ini != NULL &&
- _base_ini->getDirectValue(key, value, mode, requestStack))
- {
+ Bootstrap_Impl * b = BootstrapMapSingleton::get().getBaseIni();
+ if (b != this && b->getDirectValue(key, value, mode, requestStack)) {
return true;
}
if (!override && getDirectValue(key, value, mode, requestStack)) {
return true;
}
if (mode == LOOKUP_MODE_NORMAL) {
- FundamentalIniData const & d = FundamentalIni::get();
- Bootstrap_Impl const * b = static_cast<Bootstrap_Impl const *>(d.ini);
- if (b != NULL && b != this &&
+ b = BootstrapMapSingleton::get().getFundamentalIni();
+ if (b != 0 && b != this &&
b->getDirectValue(key, value, mode, requestStack))
{
return true;
@@ -557,7 +527,7 @@ bool Bootstrap_Impl::getDirectValue(
ExpandRequestLink const * requestStack) const
{
rtl::OUString v;
- if (find(_nameValueList, key, &v)) {
+ if (get(key, &v)) {
expandValue(value, v, mode, this, key, requestStack);
return true;
} else {
@@ -570,12 +540,8 @@ bool Bootstrap_Impl::getAmbienceValue(
ExpandRequestLink const * requestStack) const
{
rtl::OUString v;
- bool f;
- {
- osl::MutexGuard g(osl::Mutex::getGlobalMutex());
- f = find(rtl_bootstrap_set_list::get(), key, &v);
- }
- if (f || getFromCommandLineArgs(key, &v) ||
+ if (ExplicitParameters::get().get(key, &v) ||
+ CommandLineParameters::get().get(key, &v) ||
osl_getEnvironment(key.pData, &v.pData) == osl_Process_E_None)
{
expandValue(value, v, mode, NULL, key, requestStack);
@@ -601,131 +567,20 @@ void Bootstrap_Impl::expandValue(
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 (
rtl_uString * pIniName
) SAL_THROW_EXTERN_C()
{
- OUString iniName( pIniName );
-
- // 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 );
+ return BootstrapMapSingleton::get().getIni(rtl::OUString(pIniName), false);
}
//----------------------------------------------------------------------------
void SAL_CALL rtl_bootstrap_args_close (
- rtlBootstrapHandle handle
+ rtlBootstrapHandle
) SAL_THROW_EXTERN_C()
{
- if (handle == 0)
- 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();
- }
+ // do nothing; the BootstrapMap::map_ just keeps growing for now
}
//----------------------------------------------------------------------------
@@ -737,18 +592,11 @@ sal_Bool SAL_CALL rtl_bootstrap_get_from_handle(
rtl_uString * pDefault
) SAL_THROW_EXTERN_C()
{
- osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
-
- sal_Bool found = sal_False;
- if(ppValue && pName)
- {
- 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;
+ return
+ (handle == 0
+ ? BootstrapMapSingleton::get().getBaseIni()
+ : static_cast< Bootstrap_Impl * >(handle))->
+ getValue(pName, ppValue, pDefault, LOOKUP_MODE_NORMAL, false, 0);
}
//----------------------------------------------------------------------------
@@ -758,19 +606,12 @@ void SAL_CALL rtl_bootstrap_get_iniName_from_handle (
rtl_uString ** ppIniName
) SAL_THROW_EXTERN_C()
{
- if(ppIniName)
- {
- if(handle)
- {
- Bootstrap_Impl * pImpl = static_cast<Bootstrap_Impl*>(handle);
- rtl_uString_assign(ppIniName, pImpl->_iniName.pData);
- }
- else
- {
- const OUString & iniName = getIniFileName_Impl();
- rtl_uString_assign(ppIniName, iniName.pData);
- }
- }
+ rtl_uString_assign(
+ ppIniName,
+ ((handle == 0
+ ? BootstrapMapSingleton::get().getBaseIni()
+ : static_cast<Bootstrap_Impl*>(handle))->
+ _iniName.pData));
}
//----------------------------------------------------------------------------
@@ -779,9 +620,7 @@ void SAL_CALL rtl_bootstrap_setIniFileName (
rtl_uString * pName
) SAL_THROW_EXTERN_C()
{
- osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
- OUString & file = getIniFileName_Impl();
- file = pName;
+ BootstrapMapSingleton::get().setBaseIniUri(rtl::OUString(pName));
}
//----------------------------------------------------------------------------
@@ -802,32 +641,7 @@ void SAL_CALL rtl_bootstrap_set (
rtl_uString * pValue
) SAL_THROW_EXTERN_C()
{
- const OUString name( pName );
- 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 ) );
+ ExplicitParameters::get().set(rtl::OUString(pName), rtl::OUString(pValue));
}
//----------------------------------------------------------------------------
@@ -837,13 +651,14 @@ void SAL_CALL rtl_bootstrap_expandMacros_from_handle (
rtl_uString ** macro
) SAL_THROW_EXTERN_C()
{
- if (handle == NULL) {
- handle = get_static_bootstrap_handle();
- }
- OUString expanded( expandMacros( static_cast< Bootstrap_Impl * >( handle ),
- * reinterpret_cast< OUString const * >( macro ),
- LOOKUP_MODE_NORMAL, NULL ) );
- rtl_uString_assign( macro, expanded.pData );
+ rtl::OUString expanded(
+ expandMacros(
+ (handle == 0
+ ? BootstrapMapSingleton::get().getBaseIni()
+ : static_cast< Bootstrap_Impl * >(handle)),
+ *reinterpret_cast< OUString const * >(macro), LOOKUP_MODE_NORMAL,
+ 0));
+ rtl_uString_assign(macro, expanded.pData);
}
//----------------------------------------------------------------------------
@@ -909,7 +724,7 @@ rtl::OUString lookup(
rtl::OUString const & key, ExpandRequestLink const * requestStack)
{
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);
return v;
}