mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: detect excess tokens for "libs" entry (issue #762)
- this addresses issue #843
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -79,104 +79,92 @@ Foam::dlLibraryTable::~dlLibraryTable()
|
|||||||
|
|
||||||
bool Foam::dlLibraryTable::open
|
bool Foam::dlLibraryTable::open
|
||||||
(
|
(
|
||||||
const fileName& functionLibName,
|
const fileName& libName,
|
||||||
const bool verbose
|
const bool verbose
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (functionLibName.size())
|
if (libName.empty())
|
||||||
{
|
|
||||||
void* functionLibPtr = dlOpen
|
|
||||||
(
|
|
||||||
fileName(functionLibName).expand(),
|
|
||||||
verbose
|
|
||||||
);
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
{
|
|
||||||
InfoInFunction
|
|
||||||
<< "Opened " << functionLibName
|
|
||||||
<< " resulting in handle " << uintptr_t(functionLibPtr) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!functionLibPtr)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
WarningInFunction
|
|
||||||
<< "could not load " << functionLibName
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
libPtrs_.append(functionLibPtr);
|
|
||||||
libNames_.append(functionLibName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* ptr = dlOpen(fileName(libName).expand(), verbose);
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
InfoInFunction
|
||||||
|
<< "Opened " << libName
|
||||||
|
<< " resulting in handle " << uintptr_t(ptr) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
libPtrs_.append(ptr);
|
||||||
|
libNames_.append(libName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
WarningInFunction
|
||||||
|
<< "could not load " << libName
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::dlLibraryTable::close
|
bool Foam::dlLibraryTable::close
|
||||||
(
|
(
|
||||||
const fileName& functionLibName,
|
const fileName& libName,
|
||||||
const bool verbose
|
const bool verbose
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label index = -1;
|
label index = -1;
|
||||||
forAllReverse(libNames_, i)
|
forAllReverse(libNames_, i)
|
||||||
{
|
{
|
||||||
if (libNames_[i] == functionLibName)
|
if (libName == libNames_[i])
|
||||||
{
|
{
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index != -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
if (debug)
|
return false;
|
||||||
{
|
|
||||||
InfoInFunction
|
|
||||||
<< "Closing " << functionLibName
|
|
||||||
<< " with handle " << uintptr_t(libPtrs_[index]) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok = dlClose(libPtrs_[index]);
|
|
||||||
|
|
||||||
libPtrs_[index] = nullptr;
|
|
||||||
libNames_[index] = fileName::null;
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
WarningInFunction
|
|
||||||
<< "could not close " << functionLibName
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
InfoInFunction
|
||||||
|
<< "Closing " << libName
|
||||||
|
<< " with handle " << uintptr_t(libPtrs_[index]) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool ok = dlClose(libPtrs_[index]);
|
||||||
|
|
||||||
|
libPtrs_[index] = nullptr;
|
||||||
|
libNames_[index].clear();
|
||||||
|
|
||||||
|
if (!ok && verbose)
|
||||||
|
{
|
||||||
|
WarningInFunction
|
||||||
|
<< "could not close " << libName
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
|
void* Foam::dlLibraryTable::findLibrary(const fileName& libName)
|
||||||
{
|
{
|
||||||
label index = -1;
|
label index = -1;
|
||||||
forAllReverse(libNames_, i)
|
forAllReverse(libNames_, i)
|
||||||
{
|
{
|
||||||
if (libNames_[i] == functionLibName)
|
if (libName == libNames_[i])
|
||||||
{
|
{
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
@ -187,6 +175,7 @@ void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
|
|||||||
{
|
{
|
||||||
return libPtrs_[index];
|
return libPtrs_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,23 +186,20 @@ bool Foam::dlLibraryTable::open
|
|||||||
const word& libsEntry
|
const word& libsEntry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (dict.found(libsEntry))
|
fileNameList libNames;
|
||||||
|
dict.readIfPresent(libsEntry, libNames);
|
||||||
|
|
||||||
|
label nOpen = 0;
|
||||||
|
|
||||||
|
for (const fileName& libName : libNames)
|
||||||
{
|
{
|
||||||
fileNameList libNames(dict.lookup(libsEntry));
|
if (dlLibraryTable::open(libName))
|
||||||
|
|
||||||
bool allOpened = !libNames.empty();
|
|
||||||
|
|
||||||
forAll(libNames, i)
|
|
||||||
{
|
{
|
||||||
allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
|
++nOpen;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allOpened;
|
return nOpen && nOpen == libNames.size();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -49,13 +49,15 @@ namespace Foam
|
|||||||
|
|
||||||
class dlLibraryTable
|
class dlLibraryTable
|
||||||
{
|
{
|
||||||
// Private Member Functions
|
// Private data
|
||||||
|
|
||||||
DynamicList<void*> libPtrs_;
|
DynamicList<void*> libPtrs_;
|
||||||
|
|
||||||
DynamicList<fileName> libNames_;
|
DynamicList<fileName> libNames_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
//- No copy construct
|
//- No copy construct
|
||||||
dlLibraryTable(const dlLibraryTable&) = delete;
|
dlLibraryTable(const dlLibraryTable&) = delete;
|
||||||
|
|
||||||
@ -73,9 +75,9 @@ public:
|
|||||||
//- Construct null
|
//- Construct null
|
||||||
dlLibraryTable();
|
dlLibraryTable();
|
||||||
|
|
||||||
//- Construct from dictionary and name of 'libs' entry giving
|
//- Open all libraries listed in the 'libsEntry' entry in the
|
||||||
// the libraries to load
|
//- given dictionary.
|
||||||
dlLibraryTable(const dictionary&, const word&);
|
dlLibraryTable(const dictionary& dict, const word& libsEntry);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -85,25 +87,25 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Open the named library, optionally with warnings if problems occur
|
//- Open the named library, optionally with warnings if problems occur
|
||||||
bool open(const fileName& name, const bool verbose = true);
|
bool open(const fileName& libName, const bool verbose = true);
|
||||||
|
|
||||||
//- Close the named library, optionally with warnings if problems occur
|
//- Close the named library, optionally with warnings if problems occur
|
||||||
bool close(const fileName& name, const bool verbose = true);
|
bool close(const fileName& libName, const bool verbose = true);
|
||||||
|
|
||||||
//- Find the handle of the named library
|
//- Find the handle of the named library
|
||||||
void* findLibrary(const fileName& name);
|
void* findLibrary(const fileName& libName);
|
||||||
|
|
||||||
//- Open all the libraries listed in the 'libsEntry' entry in the
|
//- Open all libraries listed in the 'libsEntry' entry in the
|
||||||
// given dictionary if present
|
//- given dictionary.
|
||||||
bool open(const dictionary&, const word& libsEntry);
|
bool open(const dictionary& dict, const word& libsEntry);
|
||||||
|
|
||||||
//- Open all the libraries listed in the 'libsEntry' entry in the
|
//- Open all libraries listed in the 'libsEntry' entry in the
|
||||||
// given dictionary if present and check the additions
|
//- given dictionary and check the additions
|
||||||
// to the given constructor table
|
//- to the given constructor table
|
||||||
template<class TablePtr>
|
template<class TablePtr>
|
||||||
bool open
|
bool open
|
||||||
(
|
(
|
||||||
const dictionary&,
|
const dictionary& dict,
|
||||||
const word& libsEntry,
|
const word& libsEntry,
|
||||||
const TablePtr& tablePtr
|
const TablePtr& tablePtr
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -37,47 +37,36 @@ bool Foam::dlLibraryTable::open
|
|||||||
const TablePtr& tablePtr
|
const TablePtr& tablePtr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (dict.found(libsEntry))
|
fileNameList libNames;
|
||||||
|
dict.readIfPresent(libsEntry, libNames);
|
||||||
|
|
||||||
|
label nOpen = 0;
|
||||||
|
|
||||||
|
for (const fileName& libName : libNames)
|
||||||
{
|
{
|
||||||
fileNameList libNames(dict.lookup(libsEntry));
|
const label nEntries = (tablePtr ? tablePtr->size() : 0);
|
||||||
|
|
||||||
bool allOpened = (libNames.size() > 0);
|
if (dlLibraryTable::open(libName))
|
||||||
|
|
||||||
forAll(libNames, i)
|
|
||||||
{
|
{
|
||||||
const fileName& libName = libNames[i];
|
++nOpen;
|
||||||
|
|
||||||
label nEntries = 0;
|
if (debug && (!tablePtr || tablePtr->size() <= nEntries))
|
||||||
|
|
||||||
if (tablePtr)
|
|
||||||
{
|
|
||||||
nEntries = tablePtr->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool opened = dlLibraryTable::open(libName);
|
|
||||||
allOpened = opened && allOpened;
|
|
||||||
|
|
||||||
if (!opened)
|
|
||||||
{
|
|
||||||
WarningInFunction
|
|
||||||
<< "Could not open library " << libName
|
|
||||||
<< endl << endl;
|
|
||||||
}
|
|
||||||
else if (debug && (!tablePtr || tablePtr->size() <= nEntries))
|
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "library " << libName
|
<< "library " << libName
|
||||||
<< " did not introduce any new entries"
|
<< " did not introduce any new entries"
|
||||||
<< endl << endl;
|
<< nl << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WarningInFunction
|
||||||
|
<< "Could not open library " << libName
|
||||||
|
<< nl << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allOpened;
|
return nOpen && nOpen == libNames.size();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user