Go to the documentation of this file.
35 #define EXT_SO "dylib"
55 std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(
nullptr);
91 bool Foam::dlLibraryTable::functionHook
95 const std::string& funcName,
97 const std::string& context
100 if (!handle || funcName.empty())
114 loaderType fun =
reinterpret_cast<loaderType
>(symbol);
129 <<
"Failed symbol lookup " << funcName.c_str() <<
nl;
131 if (!context.empty())
133 err <<
"from " << context.c_str() <<
nl;
144 const std::string& funcName,
146 const std::string& context
149 return functionHook(
true, handle, funcName, verbose, context);
156 const std::string& funcName,
158 const std::string& context
161 return functionHook(
false, handle, funcName, verbose, context);
167 void* Foam::dlLibraryTable::openLibrary
182 <<
"Opened " << libName
189 os <<
"Could not load " << libName <<
nl << msg.c_str() <<
endl;
210 std::initializer_list<fileName> libNames,
220 const word& libsEntry,
234 const word& libsEntry,
258 for (
const void* ptr : libPtrs_)
274 for (
const void* ptr : libPtrs_)
301 void* ptr = libPtrs_[i];
302 const fileName& libName = libNames_[i];
304 if (ptr !=
nullptr && !libName.empty())
306 list[nLoaded] = libName;
323 void* ptr = libPtrs_[i];
327 libNames_[i].clear();
334 <<
"Closed [" << i <<
"] " << libNames_[i]
337 libPtrs_[i] =
nullptr;
338 libNames_[i].clear();
347 <<
"Failed closing " << libNames_[i]
355 if (nLoaded && nLoaded != libPtrs_.size())
361 if (libPtrs_[i] !=
nullptr)
365 libPtrs_[nLoaded] = libPtrs_[i];
366 libNames_[nLoaded] = std::move(libNames_[i]);
374 libPtrs_.resize(nLoaded);
375 libNames_.resize(nLoaded);
381 if (libName.empty() || libNames_.found(libName))
386 libPtrs_.append(
nullptr);
387 libNames_.append(libName);
397 for (
const fileName& libName : libNames)
416 void* ptr = libPtrs_[i];
417 const fileName& libName = libNames_[i];
419 if (ptr ==
nullptr && !libName.empty())
423 ptr = openLibrary(libName, verbose);
432 libNames_[i].clear();
437 return nOpen && nOpen == nCand;
448 void* ptr = openLibrary(libName, verbose);
452 libPtrs_.append(ptr);
453 libNames_.append(libName);
466 decltype(libNames.
size()) nOpen = 0;
468 for (
const fileName& libName : libNames)
470 const label index = libNames_.find(libName);
472 if (index >= 0 && libPtrs_[index] !=
nullptr)
483 return nOpen && nOpen == libNames.size();
489 std::initializer_list<fileName> libNames,
493 decltype(libNames.size()) nOpen = 0;
495 for (
const fileName& libName : libNames)
497 const label index = libNames_.find(libName);
499 if (index >= 0 && libPtrs_[index] !=
nullptr)
510 return nOpen && nOpen == libNames.size();
520 const label index = libNames_.rfind(libName);
522 if (index < 0 || libName.empty())
527 void* ptr = libPtrs_[index];
531 libNames_[index].clear();
536 <<
"Closing " << libName
541 libPtrs_[index] =
nullptr;
542 libNames_[index].clear();
553 for (label idx = 0; (idx = libPtrs_.find(ptr, idx)) >= 0; ++idx)
556 libPtrs_[idx] =
nullptr;
557 libNames_[idx].clear();
563 <<
"Could not close " << libName <<
endl;
572 const label index = libNames_.rfind(libName);
574 if (index < 0 || libName.empty())
579 return libPtrs_[index];
585 const word& libsEntry,
602 const word& libsEntry
624 const void* ptr = tbl.
pointers()[i];
List< fileName > loaded() const
Names of the libraries in use.
const UList< void * > & pointers() const
Pointers to the libraries in use. Access with caution.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A table of dynamically loaded libraries.
void * findLibrary(const fileName &libName)
Find the handle of the named library.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static std::string nameLessExt(const std::string &str)
Return basename, without extension.
A class for handling words, derived from Foam::string.
A helper class for outputting values to Ostream.
A class for handling file names.
void close(bool verbose=true)
void resize(const label len)
Adjust allocated size of list.
static word basename(const fileName &libPath)
Library basename without leading 'lib' or trailing '.so'.
Ostream & endl(Ostream &os)
Add newline and flush stream.
OSstream Serr
OSstream wrapped stderr (std::cerr)
word ext() const
Return file name extension (part after last .)
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
bool empty() const
True if there are no libraries loaded by the table.
static bool unloadHook(void *handle, const std::string &funcName, const bool verbose=false, const std::string &context="")
#define forAll(list, i)
Loop across all elements in list.
bool append(const fileName &libName)
Add to the list of names, but do not yet open.
void * dlSymFind(void *handle, const std::string &symbol, bool required=false)
Look for symbol in a dlopened library.
#define DebugInFunction
Report an information message using Foam::Info.
const UList< fileName > & names() const
Names of the libraries in use, or requested.
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
OBJstream os(runTime.globalPath()/outputName)
bool open(bool verbose=true)
static int dlcloseOnTerminate
Use dlclose() when clearing the dlLibraryTable.
static dlLibraryTable & libs()
Table of global libraries.
static word fullname(word libName)
Library fullname, prefix with 'lib', suffix with '.so'.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool dlClose(void *handle)
Close a dlopened library using handle. Return true if successful.
static bool loadHook(void *handle, const std::string &funcName, const bool verbose=false, const std::string &context="")
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
bool removeStart(const std::string &text)
Remove the given text from the start of the string.
label size() const
The number of libraries loaded by the table.
void size(const label n)
Older name for setAddressableSize.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void clear()
Clears the table, without attempting to close the libraries.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Begin list [isseparator].
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
dlLibraryTable()=default
Default construct.
void * dlOpen(const fileName &libName, const bool check=true)
Open a shared library and return handle to library.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
~dlLibraryTable()
Destructor. Closes all libraries loaded by the table.