35 #define EXT_SO "dylib"
55std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(
nullptr);
91bool 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);
167void* Foam::dlLibraryTable::openLibrary
179 void* ptr =
Foam::dlOpen(fileName(libName).expand(), msg);
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];
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A helper class for outputting values to Ostream.
void resize(const label len)
Adjust allocated size of list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
A table of dynamically loaded libraries.
const UList< void * > & pointers() const
Pointers to the libraries in use. Access with caution.
static bool unloadHook(void *handle, const std::string &funcName, const bool verbose=false, const std::string &context="")
label size() const
The number of libraries loaded by the table.
static dlLibraryTable & libs()
Table of global libraries.
bool empty() const
True if there are no libraries loaded by the table.
List< fileName > loaded() const
Names of the libraries in use.
~dlLibraryTable()
Destructor. Closes all libraries loaded by the table.
const UList< fileName > & names() const
Names of the libraries in use, or requested.
static bool loadHook(void *handle, const std::string &funcName, const bool verbose=false, const std::string &context="")
void * findLibrary(const fileName &libName)
Find the handle of the named library.
static word fullname(word libName)
Library fullname, prefix with 'lib', suffix with '.so'.
void clear()
Clears the table, without attempting to close the libraries.
static word basename(const fileName &libPath)
Library basename without leading 'lib' or trailing '.so'.
static int dlcloseOnTerminate
Use dlclose() when clearing the dlLibraryTable.
dlLibraryTable()=default
Default construct.
A class for handling file names.
static std::string nameLessExt(const std::string &str)
Return basename, without extension.
bool removeStart(const std::string &text)
Remove the given text from the start of the string.
@ BEGIN_LIST
Begin list [isseparator].
@ END_LIST
End list [isseparator].
bool append() const noexcept
True if output format uses an append mode.
A class for handling words, derived from Foam::string.
word ext() const
Return file name extension (part after last .)
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
bool dlClose(void *handle)
Close a dlopened library using handle. Return true if successful.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void * dlSymFind(void *handle, const std::string &symbol, bool required=false)
Look for symbol in a dlopened library.
OSstream Serr
OSstream wrapped stderr (std::cerr)
void * dlOpen(const fileName &libName, const bool check=true)
Open a shared library and return handle to library.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
static constexpr char close
static constexpr char open