mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ensure that content changes in coded objects are noticed (#1293)
- for codedFunctionObject and CodedSource the main code snippets
were not included in the SHA1 calculation, which meant that many
changes would not be noticed and no new library would be compiled.
As a workaround, a dummy 'code' entry could be used solely for the
purposes of generating a SHA1, but this is easily forgotten.
We now allow tracking of the dynamicCodeContext for the coded
objects and append to the SHA1 hasher with specific entries.
This should solve the previous misbehaviour.
We additionally add information about the ordering of the code
sections. Suppose we have a coded function object (all code
segments are optional) with the following:
codeExecute "";
codeWrite #{ Info<< "Called\n"; #};
which we subsequently change to this:
codeExecute #{ Info<< "Called\n"; #};
codeWrite "";
If the code strings are simply concatenated together, the SHA1 hashes
will be identical. We thus 'salt' with their semantic locations,
choosing tags that are unlikely to occur within the code strings
themselves.
- simplify the coded templates with constexpr for the SHA1sum
information.
- Correct the CodedSource to use 'codeConstrain' instead of
'codeSetValue' for consistency with the underlying functions.
This commit is contained in:
committed by
Andrew Heather
parent
23e5d43e4e
commit
a85c55bbb5
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -28,6 +28,15 @@ Class
|
||||
|
||||
Description
|
||||
Base class for function objects and boundary conditions using dynamic code
|
||||
that provides methods for managing loading/unloading/updating
|
||||
of a dynamic library. For these purposes, it uses a dynamicCodeContext
|
||||
object to maintain information about the state.
|
||||
|
||||
For simple coded objects, the default state management is sufficient.
|
||||
When there are more complicated code segements
|
||||
(eg, functionObjects::codedFunctionObject), the state management
|
||||
must also register these elements as well, starting with an initial
|
||||
setCodeContext() call and followed by append() to register each element.
|
||||
|
||||
SourceFiles
|
||||
codedBase.C
|
||||
@ -38,16 +47,16 @@ SourceFiles
|
||||
#define codedBase_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "dynamicCodeContext.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward Declarations
|
||||
class Ostream;
|
||||
class dynamicCode;
|
||||
class dynamicCodeContext;
|
||||
class dlLibraryTable;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -56,11 +65,15 @@ class dlLibraryTable;
|
||||
|
||||
class codedBase
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- The code context
|
||||
dynamicCodeContext context_;
|
||||
|
||||
//- Previously loaded library
|
||||
mutable fileName oldLibPath_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Global loader/unloader function type
|
||||
@ -71,7 +84,7 @@ class codedBase
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const dictionary& contextDict
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
//- Execute globalFuncName(false) and unload specified library
|
||||
@ -79,11 +92,15 @@ class codedBase
|
||||
(
|
||||
const fileName& libPath,
|
||||
const string& globalFuncName,
|
||||
const dictionary& contextDict
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
//- Create library based on the dynamicCodeContext
|
||||
void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
|
||||
void createLibrary
|
||||
(
|
||||
dynamicCode& dynCode,
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
//- No copy construct
|
||||
codedBase(const codedBase&) = delete;
|
||||
@ -95,22 +112,45 @@ class codedBase
|
||||
protected:
|
||||
|
||||
//- Write code-dictionary contents
|
||||
static void writeCodeDict(Ostream&, const dictionary&);
|
||||
static void writeCodeDict(Ostream& os, const dictionary& dict);
|
||||
|
||||
//- Update library as required
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set code context from a dictionary
|
||||
void setCodeContext(const dictionary& dict);
|
||||
|
||||
//- Add content to SHA1 hashing
|
||||
void append(const std::string& str);
|
||||
|
||||
|
||||
//- Update library as required, using the given context
|
||||
void updateLibrary
|
||||
(
|
||||
const word& name
|
||||
const word& name,
|
||||
const dynamicCodeContext& context
|
||||
) const;
|
||||
|
||||
//- Update library as required, using the given code dictionary
|
||||
//- to use for the context
|
||||
void updateLibrary
|
||||
(
|
||||
const word& name,
|
||||
const dictionary& dict
|
||||
) const;
|
||||
|
||||
//- Update library as required, using the predefined context
|
||||
//- or use the codeDict() to generate one
|
||||
void updateLibrary(const word& name) const;
|
||||
|
||||
//- Get the loaded dynamic libraries
|
||||
virtual dlLibraryTable& libs() const = 0;
|
||||
|
||||
//- Adapt the context for the current object
|
||||
virtual void prepare
|
||||
(
|
||||
dynamicCode&,
|
||||
const dynamicCodeContext&
|
||||
dynamicCode& dynCode,
|
||||
const dynamicCodeContext& context
|
||||
) const = 0;
|
||||
|
||||
// Return a description (type + name) for the output
|
||||
@ -132,11 +172,11 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
codedBase();
|
||||
codedBase() = default;
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~codedBase();
|
||||
virtual ~codedBase() = default;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user