mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: dlLibraryTable: guarantee dlclose order opposite of dlopen order
This commit is contained in:
@ -35,8 +35,6 @@ defineTypeNameAndDebug(Foam::dlLibraryTable, 0);
|
|||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::dlLibraryTable::dlLibraryTable()
|
Foam::dlLibraryTable::dlLibraryTable()
|
||||||
:
|
|
||||||
HashTable<fileName, void*, Hash<void*> >()
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -45,8 +43,6 @@ Foam::dlLibraryTable::dlLibraryTable
|
|||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const word& libsEntry
|
const word& libsEntry
|
||||||
)
|
)
|
||||||
:
|
|
||||||
HashTable<fileName, void*, Hash<void*> >()
|
|
||||||
{
|
{
|
||||||
open(dict, libsEntry);
|
open(dict, libsEntry);
|
||||||
}
|
}
|
||||||
@ -56,17 +52,18 @@ Foam::dlLibraryTable::dlLibraryTable
|
|||||||
|
|
||||||
Foam::dlLibraryTable::~dlLibraryTable()
|
Foam::dlLibraryTable::~dlLibraryTable()
|
||||||
{
|
{
|
||||||
forAllConstIter(dlLibraryTable, *this, iter)
|
forAllReverse(libPtrs_, i)
|
||||||
|
{
|
||||||
|
if (libPtrs_[i])
|
||||||
{
|
{
|
||||||
// bug in dlclose - does not call static destructors of
|
|
||||||
// loaded library when actually unloading the library.
|
|
||||||
// See https://bugzilla.novell.com/show_bug.cgi?id=680125 and 657627.
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "dlLibraryTable::~dlLibraryTable() : closing " << iter()
|
Info<< "dlLibraryTable::~dlLibraryTable() : closing "
|
||||||
<< " with handle " << long(iter.key()) << endl;
|
<< libNames_[i]
|
||||||
|
<< " with handle " << long(libPtrs_[i]) << endl;
|
||||||
|
}
|
||||||
|
dlClose(libPtrs_[i]);
|
||||||
}
|
}
|
||||||
dlClose(iter.key());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +92,7 @@ bool Foam::dlLibraryTable::open
|
|||||||
{
|
{
|
||||||
WarningIn
|
WarningIn
|
||||||
(
|
(
|
||||||
"dlLibraryTable::open(const fileName&)"
|
"dlLibraryTable::open(const fileName&, const bool)"
|
||||||
) << "could not load " << functionLibName
|
) << "could not load " << functionLibName
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
@ -104,7 +101,9 @@ bool Foam::dlLibraryTable::open
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return insert(functionLibPtr, functionLibName);
|
libPtrs_.append(functionLibPtr);
|
||||||
|
libNames_.append(functionLibName);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -120,18 +119,30 @@ bool Foam::dlLibraryTable::close
|
|||||||
const bool verbose
|
const bool verbose
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
void* libPtr = findLibrary(functionLibName);
|
label index = -1;
|
||||||
if (libPtr)
|
forAllReverse(libNames_, i)
|
||||||
|
{
|
||||||
|
if (libNames_[i] == functionLibName)
|
||||||
|
{
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "dlLibraryTable::close : closing " << functionLibName
|
Info<< "dlLibraryTable::close : closing " << functionLibName
|
||||||
<< " with handle " << long(libPtr) << endl;
|
<< " with handle " << long(libPtrs_[index]) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
erase(libPtr);
|
bool ok = dlClose(libPtrs_[index]);
|
||||||
|
|
||||||
if (!dlClose(libPtr))
|
libPtrs_[index] = NULL;
|
||||||
|
libNames_[index] = fileName::null;
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
@ -153,13 +164,20 @@ bool Foam::dlLibraryTable::close
|
|||||||
|
|
||||||
void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
|
void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
|
||||||
{
|
{
|
||||||
forAllConstIter(dlLibraryTable, *this, iter)
|
label index = -1;
|
||||||
|
forAllReverse(libNames_, i)
|
||||||
{
|
{
|
||||||
if (iter() == functionLibName)
|
if (libNames_[i] == functionLibName)
|
||||||
{
|
{
|
||||||
return iter.key();
|
index = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
return libPtrs_[index];
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,8 +36,7 @@ SourceFiles
|
|||||||
#define dlLibraryTable_H
|
#define dlLibraryTable_H
|
||||||
|
|
||||||
#include "label.H"
|
#include "label.H"
|
||||||
#include "Hash.H"
|
#include "DynamicList.H"
|
||||||
#include "HashTable.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -49,11 +48,14 @@ namespace Foam
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class dlLibraryTable
|
class dlLibraryTable
|
||||||
:
|
|
||||||
public HashTable<fileName, void*, Hash<void*> >
|
|
||||||
{
|
{
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
|
DynamicList<void*> libPtrs_;
|
||||||
|
|
||||||
|
DynamicList<fileName> libNames_;
|
||||||
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
dlLibraryTable(const dlLibraryTable&);
|
dlLibraryTable(const dlLibraryTable&);
|
||||||
|
|
||||||
|
|||||||
@ -62,8 +62,8 @@ bool Foam::dlLibraryTable::open
|
|||||||
WarningIn
|
WarningIn
|
||||||
(
|
(
|
||||||
"dlLibraryTable::open"
|
"dlLibraryTable::open"
|
||||||
"(const dictionary& dict, const word& libsEntry, "
|
"(const dictionary&, const word&, "
|
||||||
"const TablePtr tablePtr)"
|
"const TablePtr&)"
|
||||||
) << "library " << libName
|
) << "library " << libName
|
||||||
<< " did not introduce any new entries"
|
<< " did not introduce any new entries"
|
||||||
<< endl << endl;
|
<< endl << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user