Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression->Built-in->Extern #74

Closed
rakhimov opened this issue Oct 18, 2014 · 1 comment
Closed

Expression->Built-in->Extern #74

rakhimov opened this issue Oct 18, 2014 · 1 comment

Comments

@rakhimov
Copy link
Owner

Implement external functions if other than already-defined functions needed for analysis.

@rakhimov rakhimov reopened this Oct 18, 2014
@rakhimov rakhimov added this to the v0.16.0 milestone Aug 21, 2017
rakhimov added a commit that referenced this issue Aug 21, 2017
This is a modified version of the schema
to allow specification of the extern library and function signature.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
This class provides a wrapper
to handle loading dynamic libraries at runtime
and querying symbols from libraries.

The cross-platform code relies on Boost DLL library
available since 1.61.
Unfortunately, since Ubuntu 16.04 has only 1.58 Boost version,
dynamic loading is implemented using native Linux/POSIX API.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
Basic smoke tests are provided to check
if the dynamic library loading works on the given platform.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
This class abstracts extern functions loaded from libraries.
The generic interface specifies
the return and argument types at compile-time.
The arguments are expected to be supplied by expressions.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
This class completes the 'extern-function' facilities
to call any numeric function from external libraries.
At API-level,
it is now possible to assign any library function for Expressions.
For example, basic event probability can be described
by some external library function
performing Markov chain analysis at mission time.

The major drawback of this approach is that external functions
cannot supply validation information for their input,
so they may fail upon evaluation.
In other word, validation is not guaranteed and up to the library user.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
The path format is validated before passing it to the library loader.
The path must be a file path.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
Initializer constructs and registers
all ExternLibrary elements in a model.
The dynamic library from all input files must be processed
before extracting and referencing extern functions.

Validation:
    - Duplicate libraries
    - Invalid path format
    - IOError loading the library (not-found)

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
This hides the type complexity of ExternExpression
by moving the expression construction responsibility
to ExternFunction concrete types.
The base ExternFunction<void> provides polymorphic interface
for these purposes,
which also allows storage of ExternFunction objects in containers.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
The implementation follows
the MEF proposal for "define-extern-function".
This allows any extern C function to be declared in the MEF XML
and used later in Expression.

The downside is exponential explosion of possible function-interfaces
with respect to allowed parameter types and numbers.
In particular, the implementation relies on
C++ template meta-programming,
which heavily slows the build times
and increases build memory consumption.

The binary size does not increase much with the current implementation.

Validation:
    - Duplicate declarations
    - Empty return type
    - Invalid number of parameters exceeding the maximum number
    - Undefined extern library to lookup the symbol
    - Undefined extern-function symbol in the reference library

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
This completes the application of 'extern-function' in expressions.
Upon application of the extern function to arguments,
a new expression representing the result operation is created.

Validation:
    - Invalid number of arguments
    - Undefined extern function

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
Simple fault tree analysis with extern function
as a basic event probability
initialized from a MEF XML input file.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
The report warning-section contains unused elements
including external libraries and functions
defined in the XML input.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
Extern library and function features allow
execution of arbitrary code from arbitrary libraries.
This is unsafe
and should be allowed only for trusted input and libraries.
By default, the dynamic library loading with XML is disabled.
This can only be enabled at command-line (``--allow-extern``) or API.
No XML input should be able to subvert and enable this feature.

Issue #74
rakhimov added a commit that referenced this issue Aug 21, 2017
The note about implementation of the proposal
is added to opsa-support docs.

Issue #74
@rakhimov
Copy link
Owner Author

The proposal open-psa/mef#53 has been implemented.
Extern function & library facilities support dynamic libraries and C functions
working with numeric types (double, int).
This gives complete freedom to users to use any external library functions with the MEF XML input.
Moreover, if optimization is important, now complex expressions built over MEF expressions
can be replaced with compiled C functions,
which would provide at least 10x better performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant