mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: library functions using std::string
This commit is contained in:
@ -45,10 +45,11 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
//! \cond fileScope
|
||||
static inline void writeEntryIfPresent
|
||||
(
|
||||
@ -70,8 +71,11 @@ static inline void writeEntryIfPresent
|
||||
}
|
||||
}
|
||||
//! \endcond
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict)
|
||||
{
|
||||
@ -88,111 +92,113 @@ void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict)
|
||||
void* Foam::codedBase::loadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const std::string& funcName,
|
||||
const dynamicCodeContext& context
|
||||
) const
|
||||
{
|
||||
// Avoid compilation by loading an existing library
|
||||
|
||||
void* lib =
|
||||
void* handle =
|
||||
(
|
||||
!libPath.empty() && libs().open(libPath, false)
|
||||
? libs().findLibrary(libPath)
|
||||
: nullptr
|
||||
);
|
||||
|
||||
if (!lib)
|
||||
if (!handle)
|
||||
{
|
||||
return lib;
|
||||
return handle;
|
||||
}
|
||||
|
||||
// verify the loaded version and unload if needed
|
||||
// Verify the loaded version and unload if needed
|
||||
|
||||
// provision for manual execution of code after loading
|
||||
if (dlSymFound(lib, globalFuncName))
|
||||
{
|
||||
loaderFunctionType function =
|
||||
reinterpret_cast<loaderFunctionType>
|
||||
(
|
||||
dlSym(lib, globalFuncName)
|
||||
);
|
||||
// Manual execution of code after loading.
|
||||
// This is mandatory for codedBase.
|
||||
|
||||
if (function)
|
||||
void* rawSymbol = dlSymFind(handle, funcName);
|
||||
|
||||
if (rawSymbol)
|
||||
{
|
||||
(*function)(true); // force load
|
||||
loaderType fun = reinterpret_cast<loaderType>(rawSymbol);
|
||||
|
||||
if (fun)
|
||||
{
|
||||
(*fun)(true); // force load
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(context.dict())
|
||||
<< "Failed looking up symbol " << globalFuncName
|
||||
<< nl << "from " << libPath << exit(FatalIOError);
|
||||
<< "Failed symbol lookup " << funcName.c_str() << nl
|
||||
<< "from " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(context.dict())
|
||||
<< "Failed looking up symbol " << globalFuncName << nl
|
||||
<< "from " << libPath << exit(FatalIOError);
|
||||
<< "Failed symbol lookup " << funcName.c_str() << nl
|
||||
<< "from " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
|
||||
lib = nullptr;
|
||||
handle = nullptr;
|
||||
if (!libs().close(libPath, false))
|
||||
{
|
||||
FatalIOErrorInFunction(context.dict())
|
||||
<< "Failed unloading library "
|
||||
<< libPath
|
||||
<< "Failed unloading library " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
return lib;
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedBase::unloadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const std::string& funcName,
|
||||
const dynamicCodeContext& context
|
||||
) const
|
||||
{
|
||||
|
||||
void* lib =
|
||||
void* handle =
|
||||
(
|
||||
!libPath.empty() && libs().open(libPath, false)
|
||||
? libs().findLibrary(libPath)
|
||||
: nullptr
|
||||
);
|
||||
|
||||
if (!lib)
|
||||
if (!handle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// provision for manual execution of code before unloading
|
||||
if (dlSymFound(lib, globalFuncName))
|
||||
{
|
||||
loaderFunctionType function =
|
||||
reinterpret_cast<loaderFunctionType>
|
||||
(
|
||||
dlSym(lib, globalFuncName)
|
||||
);
|
||||
// Manual execution of code before unloading.
|
||||
// This is mandatory for codedBase.
|
||||
|
||||
if (function)
|
||||
void* rawSymbol = dlSymFind(handle, funcName);
|
||||
|
||||
if (rawSymbol)
|
||||
{
|
||||
(*function)(false); // force unload
|
||||
loaderType fun = reinterpret_cast<loaderType>(rawSymbol);
|
||||
|
||||
if (fun)
|
||||
{
|
||||
(*fun)(false); // force unload
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(context.dict())
|
||||
<< "Failed looking up symbol " << globalFuncName << nl
|
||||
<< "from " << libPath << exit(FatalIOError);
|
||||
<< "Failed symbol lookup " << funcName.c_str() << nl
|
||||
<< "from " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (!libs().close(libPath, false))
|
||||
{
|
||||
FatalIOErrorInFunction(context.dict())
|
||||
<< "Failed unloading library " << libPath
|
||||
<< "Failed unloading library " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,24 +75,28 @@ class codedBase
|
||||
mutable fileName oldLibPath_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
// Data Types
|
||||
|
||||
//- Global loader/unloader function type
|
||||
typedef void (*loaderFunctionType)(bool);
|
||||
// Called with true on load, false on unload.
|
||||
typedef void (*loaderType)(bool);
|
||||
|
||||
//- Load specified library and execute globalFuncName(true)
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Load specified library and execute funcName(true)
|
||||
void* loadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const std::string& funcName,
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
//- Execute globalFuncName(false) and unload specified library
|
||||
//- Execute funcName(false) and unload specified library
|
||||
void unloadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const std::string& funcName,
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
|
||||
@ -143,8 +143,10 @@ void Foam::dlLibraryTable::clear(bool verbose)
|
||||
if (ptr == nullptr)
|
||||
{
|
||||
libNames_[i].clear();
|
||||
continue;
|
||||
}
|
||||
else if (Foam::dlClose(ptr))
|
||||
|
||||
if (Foam::dlClose(ptr))
|
||||
{
|
||||
DebugInFunction
|
||||
<< "Closed [" << i << "] " << libNames_[i]
|
||||
|
||||
Reference in New Issue
Block a user