Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
d571e523
Commit
d571e523
authored
Jun 01, 2018
by
Mark OLESEN
Browse files
ENH: detect excess tokens for "libs" entry (issue
#762
)
- this addresses issue
#843
parent
511b3562
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C
View file @
d571e523
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -79,104 +79,92 @@ Foam::dlLibraryTable::~dlLibraryTable()
bool
Foam
::
dlLibraryTable
::
open
(
const
fileName
&
functionL
ibName
,
const
fileName
&
l
ibName
,
const
bool
verbose
)
{
if
(
functionL
ibName
.
size
())
if
(
l
ibName
.
empty
())
{
void
*
functionLibPtr
=
dlOpen
(
fileName
(
functionLibName
).
expand
(),
verbose
);
return
false
;
}
if
(
debug
)
{
InfoInFunction
<<
"Opened "
<<
functionLibName
<<
" resulting in handle "
<<
uintptr_t
(
functionLibPtr
)
<<
endl
;
}
void
*
ptr
=
dlOpen
(
fileName
(
libName
).
expand
(),
verbose
);
if
(
!
functionLibPtr
)
{
if
(
verbose
)
{
WarningInFunction
<<
"could not load "
<<
functionLibName
<<
endl
;
}
if
(
debug
)
{
InfoInFunction
<<
"Opened "
<<
libName
<<
" resulting in handle "
<<
uintptr_t
(
ptr
)
<<
endl
;
}
return
false
;
}
else
{
libPtrs_
.
append
(
functionLibPtr
);
libNames_
.
append
(
functionLibName
);
return
true
;
}
if
(
ptr
)
{
libPtrs_
.
append
(
ptr
);
libNames_
.
append
(
libName
);
return
true
;
}
else
if
(
verbose
)
{
return
false
;
WarningInFunction
<<
"could not load "
<<
libName
<<
endl
;
}
return
false
;
}
bool
Foam
::
dlLibraryTable
::
close
(
const
fileName
&
functionL
ibName
,
const
fileName
&
l
ibName
,
const
bool
verbose
)
{
label
index
=
-
1
;
forAllReverse
(
libNames_
,
i
)
{
if
(
libName
s_
[
i
]
==
functionL
ibName
)
if
(
libName
==
l
ibName
s_
[
i
]
)
{
index
=
i
;
break
;
}
}
if
(
index
!
=
-
1
)
if
(
index
=
=
-
1
)
{
if
(
debug
)
{
InfoInFunction
<<
"Closing "
<<
functionLibName
<<
" with handle "
<<
uintptr_t
(
libPtrs_
[
index
])
<<
endl
;
}
return
false
;
}
bool
ok
=
dlClose
(
libPtrs_
[
index
]);
if
(
debug
)
{
InfoInFunction
<<
"Closing "
<<
libName
<<
" with handle "
<<
uintptr_t
(
libPtrs_
[
index
])
<<
endl
;
}
libPtrs_
[
index
]
=
nullptr
;
libNames_
[
index
]
=
fileName
::
null
;
const
bool
ok
=
dlClose
(
libPtrs_
[
index
]);
if
(
!
ok
)
{
if
(
verbose
)
{
WarningInFunction
<<
"could not close "
<<
functionLibName
<<
endl
;
}
return
false
;
}
libPtrs_
[
index
]
=
nullptr
;
libNames_
[
index
].
clear
();
return
true
;
if
(
!
ok
&&
verbose
)
{
WarningInFunction
<<
"could not close "
<<
libName
<<
endl
;
}
return
false
;
return
ok
;
}
void
*
Foam
::
dlLibraryTable
::
findLibrary
(
const
fileName
&
functionL
ibName
)
void
*
Foam
::
dlLibraryTable
::
findLibrary
(
const
fileName
&
l
ibName
)
{
label
index
=
-
1
;
forAllReverse
(
libNames_
,
i
)
{
if
(
libName
s_
[
i
]
==
functionL
ibName
)
if
(
libName
==
l
ibName
s_
[
i
]
)
{
index
=
i
;
break
;
...
...
@@ -187,6 +175,7 @@ void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
{
return
libPtrs_
[
index
];
}
return
nullptr
;
}
...
...
@@ -197,23 +186,20 @@ bool Foam::dlLibraryTable::open
const
word
&
libsEntry
)
{
if
(
dict
.
found
(
libsEntry
))
{
fileNameList
libNames
(
dict
.
lookup
(
libsEntry
));
fileNameList
libNames
;
dict
.
readIfPresent
(
libsEntry
,
libNames
);
bool
all
Open
ed
=
!
libNames
.
empty
()
;
label
n
Open
=
0
;
forAll
(
libNames
,
i
)
for
(
const
fileName
&
libName
:
libNames
)
{
if
(
dlLibraryTable
::
open
(
libName
))
{
allOpened
=
dlLibraryTable
::
open
(
libNames
[
i
])
&&
all
Open
ed
;
++
n
Open
;
}
return
allOpened
;
}
else
{
return
false
;
}
return
nOpen
&&
nOpen
==
libNames
.
size
();
}
...
...
src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H
View file @
d571e523
...
...
@@ -49,13 +49,15 @@ namespace Foam
class
dlLibraryTable
{
// Private
Member Functions
// Private
data
DynamicList
<
void
*>
libPtrs_
;
DynamicList
<
fileName
>
libNames_
;
// Private Member Functions
//- No copy construct
dlLibraryTable
(
const
dlLibraryTable
&
)
=
delete
;
...
...
@@ -73,9 +75,9 @@ public:
//- Construct null
dlLibraryTable
();
//-
Construct from dictionary and name of
'libs' entry
giving
//
the libraries to load
dlLibraryTable
(
const
dictionary
&
,
const
word
&
);
//-
Open all libraries listed in the
'libs
Entry
' entry
in the
//
- given dictionary.
dlLibraryTable
(
const
dictionary
&
dict
,
const
word
&
libsEntry
);
//- Destructor
...
...
@@ -85,25 +87,25 @@ public:
// Member Functions
//- Open the named library, optionally with warnings if problems occur
bool
open
(
const
fileName
&
n
ame
,
const
bool
verbose
=
true
);
bool
open
(
const
fileName
&
libN
ame
,
const
bool
verbose
=
true
);
//- Close the named library, optionally with warnings if problems occur
bool
close
(
const
fileName
&
n
ame
,
const
bool
verbose
=
true
);
bool
close
(
const
fileName
&
libN
ame
,
const
bool
verbose
=
true
);
//- Find the handle of the named library
void
*
findLibrary
(
const
fileName
&
n
ame
);
void
*
findLibrary
(
const
fileName
&
libN
ame
);
//- Open all
the
libraries listed in the 'libsEntry' entry in the
//
given dictionary
if present
bool
open
(
const
dictionary
&
,
const
word
&
libsEntry
);
//- Open all libraries listed in the 'libsEntry' entry in the
//
-
given dictionary
.
bool
open
(
const
dictionary
&
dict
,
const
word
&
libsEntry
);
//- Open all
the
libraries listed in the 'libsEntry' entry in the
//
given dictionary
if present
and check the additions
//
to the given constructor table
//- Open all libraries listed in the 'libsEntry' entry in the
//
-
given dictionary and check the additions
//
-
to the given constructor table
template
<
class
TablePtr
>
bool
open
(
const
dictionary
&
,
const
dictionary
&
dict
,
const
word
&
libsEntry
,
const
TablePtr
&
tablePtr
);
...
...
src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTableTemplates.C
View file @
d571e523
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -37,47 +37,36 @@ bool Foam::dlLibraryTable::open
const
TablePtr
&
tablePtr
)
{
if
(
dict
.
found
(
libsEntry
))
{
fileNameList
libNames
(
dict
.
lookup
(
libsEntry
));
bool
allOpened
=
(
libNames
.
size
()
>
0
);
fileNameList
libNames
;
dict
.
readIfPresent
(
libsEntry
,
libNames
);
forAll
(
libNames
,
i
)
{
const
fileName
&
libName
=
libNames
[
i
];
label
nOpen
=
0
;
label
nEntries
=
0
;
if
(
tablePtr
)
{
nEntries
=
tablePtr
->
size
();
}
for
(
const
fileName
&
libName
:
libNames
)
{
const
label
nEntries
=
(
tablePtr
?
tablePtr
->
size
()
:
0
);
bool
opened
=
dlLibraryTable
::
open
(
libName
);
allOpened
=
opened
&&
allOpened
;
if
(
dlLibraryTable
::
open
(
libName
))
{
++
nOpen
;
if
(
!
opened
)
{
WarningInFunction
<<
"Could not open library "
<<
libName
<<
endl
<<
endl
;
}
else
if
(
debug
&&
(
!
tablePtr
||
tablePtr
->
size
()
<=
nEntries
))
if
(
debug
&&
(
!
tablePtr
||
tablePtr
->
size
()
<=
nEntries
))
{
WarningInFunction
<<
"library "
<<
libName
<<
" did not introduce any new entries"
<<
end
l
<<
endl
;
<<
n
l
<<
endl
;
}
}
return
allOpened
;
}
els
e
{
return
false
;
else
{
WarningInFunction
<<
"Could not open library "
<<
libNam
e
<<
nl
<<
endl
;
}
}
return
nOpen
&&
nOpen
==
libNames
.
size
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment