mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
2a7813049e
* Wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Do not use ccache if ccache defined in CMAKE_CXX_COMPILER_LAUNCHER * wip * wip * wip * wip * wip * wip * wip * Config: Allow multiple dictionaries_config * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * clean * wip * clean * clean * wip * clean * clean * wip * wip * clean * clean * clean * clean * clean * Requested changes * Reqested changes * Requested changes * Requested changes * Requested changes * Requested changes * requested changes * Requested changes * Requested changes * requested changes * Requested changes * fix * Requested changes * Requested changes * fix * Requested changes * Requested changes
44 lines
896 B
C++
44 lines
896 B
C++
#include "SharedLibrary.h"
|
|
#include <string>
|
|
#include <dlfcn.h>
|
|
#include <boost/core/noncopyable.hpp>
|
|
#include "Exception.h"
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int CANNOT_DLOPEN;
|
|
extern const int CANNOT_DLSYM;
|
|
}
|
|
|
|
SharedLibrary::SharedLibrary(const std::string & path)
|
|
{
|
|
handle = dlopen(path.c_str(), RTLD_LAZY);
|
|
if (!handle)
|
|
throw Exception(std::string("Cannot dlopen: ") + dlerror(), ErrorCodes::CANNOT_DLOPEN);
|
|
}
|
|
|
|
SharedLibrary::~SharedLibrary()
|
|
{
|
|
if (handle && dlclose(handle))
|
|
std::terminate();
|
|
}
|
|
|
|
void * SharedLibrary::getImpl(const std::string & name, bool no_throw)
|
|
{
|
|
dlerror();
|
|
|
|
auto res = dlsym(handle, name.c_str());
|
|
|
|
if (char * error = dlerror())
|
|
{
|
|
if (no_throw)
|
|
return nullptr;
|
|
throw Exception(std::string("Cannot dlsym: ") + error, ErrorCodes::CANNOT_DLSYM);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|