mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 14:20:10 +01:00
backport SharedLibrary changes from 1.4.2-p1
This commit is contained in:
@@ -63,28 +63,60 @@ namespace Poco {
|
||||
|
||||
class Foundation_API SharedLibrary: private SharedLibraryImpl
|
||||
/// The SharedLibrary class dynamically
|
||||
/// loads shared libraries at run-time.
|
||||
/// loads shared libraries at run-time.
|
||||
{
|
||||
public:
|
||||
SharedLibrary();
|
||||
/// Creates a SharedLibrary object.
|
||||
|
||||
SharedLibrary(const std::string& path);
|
||||
/// Creates a SharedLibrary object and loads a library
|
||||
/// from the given path.
|
||||
enum Flags
|
||||
{
|
||||
SHLIB_GLOBAL = 1,
|
||||
/// On platforms that use dlopen(), use RTLD_GLOBAL. This is the default
|
||||
/// if no flags are given.
|
||||
///
|
||||
/// This flag is ignored on platforms that do not use dlopen().
|
||||
|
||||
virtual ~SharedLibrary();
|
||||
/// Destroys the SharedLibrary. The actual library
|
||||
/// remains loaded.
|
||||
SHLIB_LOCAL = 2
|
||||
/// On platforms that use dlopen(), use RTLD_LOCAL instead of RTLD_GLOBAL.
|
||||
///
|
||||
/// Note that if this flag is specified, RTTI (including dynamic_cast and throw) will
|
||||
/// not work for types defined in the shared library with GCC and possibly other
|
||||
/// compilers as well. See http://gcc.gnu.org/faq.html#dso for more information.
|
||||
///
|
||||
/// This flag is ignored on platforms that do not use dlopen().
|
||||
};
|
||||
|
||||
SharedLibrary();
|
||||
/// Creates a SharedLibrary object.
|
||||
|
||||
SharedLibrary(const std::string& path);
|
||||
/// Creates a SharedLibrary object and loads a library
|
||||
/// from the given path.
|
||||
|
||||
SharedLibrary(const std::string& path, int flags);
|
||||
/// Creates a SharedLibrary object and loads a library
|
||||
/// from the given path, using the given flags.
|
||||
/// See the Flags enumeration for valid values.
|
||||
|
||||
virtual ~SharedLibrary();
|
||||
/// Destroys the SharedLibrary. The actual library
|
||||
/// remains loaded.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads a shared library from the given path.
|
||||
/// Throws a LibraryAlreadyLoadedException if
|
||||
/// a library has already been loaded.
|
||||
/// Throws a LibraryLoadException if the library
|
||||
/// cannot be loaded.
|
||||
/// Throws a LibraryAlreadyLoadedException if
|
||||
/// a library has already been loaded.
|
||||
/// Throws a LibraryLoadException if the library
|
||||
/// cannot be loaded.
|
||||
|
||||
void unload();
|
||||
void load(const std::string& path, int flags);
|
||||
/// Loads a shared library from the given path,
|
||||
/// using the given flags. See the Flags enumeration
|
||||
/// for valid values.
|
||||
/// Throws a LibraryAlreadyLoadedException if
|
||||
/// a library has already been loaded.
|
||||
/// Throws a LibraryLoadException if the library
|
||||
/// cannot be loaded.
|
||||
|
||||
void unload();
|
||||
/// Unloads a shared library.
|
||||
|
||||
bool isLoaded() const;
|
||||
|
||||
@@ -51,12 +51,12 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -50,12 +50,18 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
enum Flags
|
||||
{
|
||||
SHLIB_GLOBAL_IMPL = 1,
|
||||
SHLIB_LOCAL_IMPL = 2
|
||||
};
|
||||
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -51,12 +51,12 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
const std::string& getPathImpl() const;
|
||||
static std::string suffixImpl();
|
||||
|
||||
|
||||
@@ -63,7 +63,13 @@ SharedLibrary::SharedLibrary()
|
||||
|
||||
SharedLibrary::SharedLibrary(const std::string& path)
|
||||
{
|
||||
loadImpl(path);
|
||||
loadImpl(path, 0);
|
||||
}
|
||||
|
||||
|
||||
SharedLibrary::SharedLibrary(const std::string& path, int flags)
|
||||
{
|
||||
loadImpl(path, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +80,13 @@ SharedLibrary::~SharedLibrary()
|
||||
|
||||
void SharedLibrary::load(const std::string& path)
|
||||
{
|
||||
loadImpl(path);
|
||||
loadImpl(path, 0);
|
||||
}
|
||||
|
||||
|
||||
void SharedLibrary::load(const std::string& path, int flags)
|
||||
{
|
||||
loadImpl(path, flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,9 +55,9 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle) throw LibraryAlreadyLoadedException(path);
|
||||
_handle = shl_load(path.c_str(), BIND_DEFERRED, 0);
|
||||
|
||||
@@ -62,16 +62,17 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int flags)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle) throw LibraryAlreadyLoadedException(path);
|
||||
int flags = RTLD_LAZY | RTLD_GLOBAL;
|
||||
#if defined(RTLD_DEEPBIND)
|
||||
flags |= RTLD_DEEPBIND;
|
||||
#endif
|
||||
_handle = dlopen(path.c_str(), flags);
|
||||
int realFlags = RTLD_LAZY;
|
||||
if (flags & SHLIB_LOCAL_IMPL)
|
||||
realFlags |= RTLD_LOCAL;
|
||||
else
|
||||
realFlags |= RTLD_GLOBAL;
|
||||
_handle = dlopen(path.c_str(), realFlags);
|
||||
if (!_handle)
|
||||
{
|
||||
const char* err = dlerror();
|
||||
|
||||
@@ -59,9 +59,9 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_path.empty()) throw LibraryAlreadyLoadedException(path);
|
||||
_path = path;
|
||||
|
||||
@@ -82,9 +82,9 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_moduleId) throw LibraryAlreadyLoadedException(path);
|
||||
int fd = open(const_cast<char*>(path.c_str()), O_RDONLY, 0);
|
||||
|
||||
@@ -56,17 +56,17 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle) throw LibraryAlreadyLoadedException(_path);
|
||||
DWORD flags(0);
|
||||
Path p(path);
|
||||
if (p.isAbsolute()) flags |= LOAD_WITH_ALTERED_SEARCH_PATH;
|
||||
_handle = LoadLibraryExA(path.c_str(), 0, flags);
|
||||
if (!_handle) throw LibraryLoadException(path);
|
||||
_path = path;
|
||||
if (_handle) throw LibraryAlreadyLoadedException(_path);
|
||||
DWORD flags(0);
|
||||
Path p(path);
|
||||
if (p.isAbsolute()) flags |= LOAD_WITH_ALTERED_SEARCH_PATH;
|
||||
_handle = LoadLibraryExA(path.c_str(), 0, flags);
|
||||
if (!_handle) throw LibraryLoadException(path);
|
||||
_path = path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,21 +57,21 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle) throw LibraryAlreadyLoadedException(_path);
|
||||
DWORD flags(0);
|
||||
if (_handle) throw LibraryAlreadyLoadedException(_path);
|
||||
DWORD flags(0);
|
||||
#if !defined(_WIN32_WCE)
|
||||
Path p(path);
|
||||
if (p.isAbsolute()) flags |= LOAD_WITH_ALTERED_SEARCH_PATH;
|
||||
Path p(path);
|
||||
if (p.isAbsolute()) flags |= LOAD_WITH_ALTERED_SEARCH_PATH;
|
||||
#endif
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
_handle = LoadLibraryExW(upath.c_str(), 0, flags);
|
||||
if (!_handle) throw LibraryLoadException(path);
|
||||
_path = path;
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
_handle = LoadLibraryExW(upath.c_str(), 0, flags);
|
||||
if (!_handle) throw LibraryLoadException(path);
|
||||
_path = path;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,17 +98,17 @@ void* SharedLibraryImpl::findSymbolImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle)
|
||||
{
|
||||
if (_handle)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
std::wstring uname;
|
||||
UnicodeConverter::toUTF16(name, uname);
|
||||
return (void*) GetProcAddressW((HMODULE) _handle, uname.c_str());
|
||||
std::wstring uname;
|
||||
UnicodeConverter::toUTF16(name, uname);
|
||||
return (void*) GetProcAddressW((HMODULE) _handle, uname.c_str());
|
||||
#else
|
||||
return (void*) GetProcAddress((HMODULE) _handle, name.c_str());
|
||||
return (void*) GetProcAddress((HMODULE) _handle, name.c_str());
|
||||
#endif
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user