BUGFIX: Mess in dlTables and use of OSspecific
This commit is contained in:
parent
6ffa6e9cb4
commit
58290b37f5
4 changed files with 61 additions and 75 deletions
|
@ -1277,11 +1277,9 @@ void* dlOpen(const fileName& libName, const bool check)
|
|||
<< " : LoadLibrary of " << libName << endl;
|
||||
}
|
||||
|
||||
const char* dllExt = ".dll";
|
||||
// Replace extension with .dll
|
||||
string winLibName(libName.lessExt() + ".dll");
|
||||
|
||||
// Assume libName is of the form, lib<name>.so
|
||||
string winLibName(libName);
|
||||
winLibName.replace(".so", dllExt);
|
||||
void* handle = ::LoadLibrary(winLibName.c_str());
|
||||
|
||||
if (NULL == handle)
|
||||
|
|
|
@ -1167,6 +1167,38 @@ void* Foam::dlOpen(const fileName& lib, const bool check)
|
|||
}
|
||||
void* handle = ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
|
||||
#ifdef darwin
|
||||
// If failing to load under OS X, let's try some obvious variations
|
||||
// before giving up completely
|
||||
fileName osxFileName(lib);
|
||||
|
||||
if (!handle && lib.ext() == "so")
|
||||
{
|
||||
osxFileName = lib.lessExt() + ".dylib";
|
||||
handle = ::dlopen(osxFileName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
|
||||
// If unsuccessful, which might be the case under Mac OSX 10.11 (El
|
||||
// Capitan) with System Integrity Protection (SIP) enabled, let's try
|
||||
// building a full path using well-known environment variables. This is
|
||||
// the last resort, unless you provide the full pathname yourself.
|
||||
if (!handle)
|
||||
{
|
||||
fileName l_LIBBIN_Name = getEnv("FOAM_LIBBIN")/osxFileName;
|
||||
handle = ::dlopen(l_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
if (!handle)
|
||||
{
|
||||
fileName l_SITE_LIBBIN_Name = getEnv("FOAM_SITE_LIBBIN")/osxFileName;
|
||||
handle = ::dlopen(l_SITE_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
if (!handle)
|
||||
{
|
||||
fileName l_USER_LIBBIN_Name = getEnv("FOAM_USER_LIBBIN")/osxFileName;
|
||||
handle = ::dlopen(l_USER_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!handle && check)
|
||||
{
|
||||
WarningInFunction
|
||||
|
|
|
@ -26,7 +26,6 @@ License
|
|||
#include "dlLibraryTable.H"
|
||||
#include "OSspecific.H"
|
||||
#include "int.H"
|
||||
#include <dlfcn.h>
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -35,8 +34,6 @@ namespace Foam
|
|||
defineTypeNameAndDebug(dlLibraryTable, 0);
|
||||
}
|
||||
|
||||
Foam::dlLibraryTable Foam::dlLibraryTable::loadedLibraries;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -62,6 +59,12 @@ Foam::dlLibraryTable::~dlLibraryTable()
|
|||
{
|
||||
if (libPtrs_[i])
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Closing " << libNames_[i]
|
||||
<< " with handle " << uintptr_t(libPtrs_[i]) << endl;
|
||||
}
|
||||
dlClose(libPtrs_[i]);
|
||||
}
|
||||
}
|
||||
|
@ -78,76 +81,32 @@ bool Foam::dlLibraryTable::open
|
|||
{
|
||||
if (functionLibName.size())
|
||||
{
|
||||
void* functionLibPtr =
|
||||
dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
void* functionLibPtr = dlOpen(functionLibName, verbose);
|
||||
|
||||
#ifdef darwin
|
||||
// If failing to load under OS X, let's try some obvious variations
|
||||
// before giving up completely
|
||||
fileName osxFileName(functionLibName);
|
||||
|
||||
if(!functionLibPtr && functionLibName.ext()=="so")
|
||||
if (debug)
|
||||
{
|
||||
osxFileName=functionLibName.lessExt()+".dylib";
|
||||
|
||||
functionLibPtr =
|
||||
dlopen(osxFileName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
InfoInFunction
|
||||
<< "Opened " << functionLibName
|
||||
<< " resulting in handle " << uintptr_t(functionLibPtr) << endl;
|
||||
}
|
||||
|
||||
// If unsuccessful, which might be the case under Mac OSX 10.11 (El
|
||||
// Capitan) with System Integrity Protection (SIP) enabled, let's try
|
||||
// building a full path using well-known environment variables. This is
|
||||
// the last resort, unless you provide the full pathname yourself.
|
||||
if (!functionLibPtr)
|
||||
{
|
||||
fileName l_LIBBIN_Name =
|
||||
getEnv("FOAM_LIBBIN")/osxFileName;
|
||||
functionLibPtr =
|
||||
dlopen(l_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
if (!functionLibPtr)
|
||||
if (verbose)
|
||||
{
|
||||
fileName l_SITE_LIBBIN_Name =
|
||||
getEnv("FOAM_SITE_LIBBIN")/osxFileName;
|
||||
functionLibPtr =
|
||||
dlopen(l_SITE_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
if (!functionLibPtr)
|
||||
{
|
||||
fileName l_USER_LIBBIN_Name =
|
||||
getEnv("FOAM_USER_LIBBIN")/osxFileName;
|
||||
functionLibPtr =
|
||||
dlopen(l_USER_LIBBIN_Name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
#elif defined mingw
|
||||
if(!functionLibPtr && functionLibName.ext()=="so") {
|
||||
fileName lName=functionLibName.lessExt()+".dll";
|
||||
functionLibPtr =
|
||||
dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
#endif
|
||||
if (!functionLibPtr)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"dlLibraryTable::open(const fileName& functionLibName)"
|
||||
) << "could not load " << dlerror()
|
||||
WarningInFunction
|
||||
<< "could not load " << functionLibName
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!loadedLibraries.found(functionLibPtr))
|
||||
{
|
||||
loadedLibraries.insert(functionLibPtr, functionLibName);
|
||||
libPtrs_.append(functionLibPtr);
|
||||
libNames_.append(functionLibName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -174,6 +133,13 @@ bool Foam::dlLibraryTable::close
|
|||
|
||||
if (index != -1)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Closing " << functionLibName
|
||||
<< " with handle " << uintptr_t(libPtrs_[index]) << endl;
|
||||
}
|
||||
|
||||
bool ok = dlClose(libPtrs_[index]);
|
||||
|
||||
libPtrs_[index] = NULL;
|
||||
|
|
|
@ -37,8 +37,6 @@ SourceFiles
|
|||
|
||||
#include "label.H"
|
||||
#include "DynamicList.H"
|
||||
#include "Hash.H"
|
||||
#include "HashTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -50,8 +48,6 @@ namespace Foam
|
|||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class dlLibraryTable
|
||||
:
|
||||
public HashTable<fileName, void*, Hash<void*> >
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
|
@ -72,12 +68,6 @@ public:
|
|||
// Declare name of the class and its debug switch
|
||||
ClassName("dlLibraryTable");
|
||||
|
||||
// Static data members
|
||||
|
||||
//- Static data someStaticData
|
||||
static dlLibraryTable loadedLibraries;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
|
|
Reference in a new issue