From: Christian P. <cp...@us...> - 2004-12-26 14:51:00
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10867/src/System Modified Files: SharedLib.ltdl.cpp Log Message: Some fixes. Removed lt_handle_map(). Added support for SharedLibCache. Index: SharedLib.ltdl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.ltdl.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- SharedLib.ltdl.cpp 26 Dec 2004 14:38:09 -0000 1.7 +++ SharedLib.ltdl.cpp 26 Dec 2004 14:50:52 -0000 1.8 @@ -41,16 +41,7 @@ } int ltdl_init_placeholder = (ltdl_init(),0); -typedef unsigned long handle_type; -typedef std::map<handle_type,lt_dlhandle> lt_handle_map_t; - struct ltdl_sharing_context {}; // marker class -lt_handle_map_t & -lt_handle_map() -{ - typedef ::P::Phoenix< lt_handle_map_t, ltdl_sharing_context > PHX; - return PHX::instance(); -} int BindMode2Flags(SharedLib::BindMode mode) { // ltdl doesn't use dlopen() flags @@ -61,7 +52,7 @@ { void operator()(lt_dlhandle handle) { - lt_dlclose((handle); + lt_dlclose(handle); } }; @@ -89,7 +80,7 @@ SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) : _handle(0) { - Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); + Cache& cache = shared_lib_cache<lt_dlhandle, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); // see if we can get it from the handle cache ... @@ -99,11 +90,10 @@ lt_dlhandle h = lt_dlopen(name.c_str() /** BindMode2Flags(mode) */ ); if( h ) { - _handle = reinterpret_cast<handle_type>( static_cast<void *>( h ) ); - lt_handle_map().insert( std::make_pair( _handle, h ) ); + _handle = (unsigned long)h; // add it to the handle cache - cache.add(name, _handle); + cache.add(name, h); } else { @@ -113,19 +103,12 @@ } else { - _handle = i->second; + _handle = (unsigned long)i->second; } } SharedLib::~SharedLib() throw() { - lt_handle_map_t::iterator it = lt_handle_map().find( _handle ); - if( lt_handle_map().end() != it ) - { - // CERR << "~SharedLib() erasing a handle: " << _handle << "\n"; -// lt_dlclose((*it).second); - lt_handle_map().erase( it ); - } } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) @@ -134,12 +117,8 @@ { throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); } - lt_handle_map_t::iterator it = lt_handle_map().find( _handle ); - if( lt_handle_map().end() == it ) - { - throw RuntimeError( "DLL handle is invalid.", P_SOURCEINFO ); - } - lt_dlhandle lth = (*it).second; + + lt_dlhandle lth = (lt_dlhandle)_handle; void* addr = lt_dlsym( lth, symbol); if(!addr) { |