4.1 k_order_perturbation: simplifying dynamic_dll code
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3199 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
f22fa8979c
commit
5031122649
|
@ -43,8 +43,9 @@ DynamicModelDLL::DynamicModelDLL(const string &modName, const int y_length, cons
|
|||
dynamicHinstance = ::LoadLibrary(fName.c_str());
|
||||
if (dynamicHinstance == NULL)
|
||||
throw 1;
|
||||
Dynamic = (DynamicFn *) ::GetProcAddress(dynamicHinstance, "Dynamic");
|
||||
|
||||
Dynamic = (DynamicFn) ::GetProcAddress(dynamicHinstance, "Dynamic");
|
||||
if (Dynamic == NULL)
|
||||
throw 2;
|
||||
#else // Linux or Mac
|
||||
dynamicHinstance = dlopen(fName.c_str(), RTLD_NOW);
|
||||
if ((dynamicHinstance == NULL) || dlerror())
|
||||
|
@ -69,14 +70,16 @@ DynamicModelDLL::DynamicModelDLL(const string &modName, const int y_length, cons
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
throw DynareException(__FILE__, __LINE__, string("Can't load ") + fName);
|
||||
throw DynareException(__FILE__, __LINE__, string("Can't find Dynamic function in ") + fName);
|
||||
}
|
||||
}
|
||||
|
||||
DynamicModelDLL::~DynamicModelDLL()
|
||||
{
|
||||
#if defined(__CYGWIN32__) || defined(_WIN32)
|
||||
FreeLibrary(dynamicHinstance);
|
||||
bool result = FreeLibrary(dynamicHinstance);
|
||||
if (result == 0)
|
||||
throw DynareException(__FILE__, __LINE__, string("Can't free the *_dynamic DLL"));
|
||||
#else
|
||||
dlclose(dynamicHinstance);
|
||||
#endif
|
||||
|
|
|
@ -39,16 +39,10 @@
|
|||
#include "dynare_exception.h"
|
||||
|
||||
// <model>_Dynamic DLL pointer
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
typedef void *(DynamicFn)
|
||||
#else // Linux or Mac
|
||||
typedef void (*DynamicFn)
|
||||
#endif
|
||||
(double *y, double *x, int nb_row_x, double *params,
|
||||
int it_, double *residual, double *g1, double *g2, double *g3);
|
||||
|
||||
typedef void *(mexFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
|
||||
|
||||
/**
|
||||
* creates pointer to Dynamic function inside <model>_dynamic.dll
|
||||
* and handles calls to it.
|
||||
|
@ -56,16 +50,13 @@ typedef void *(mexFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, const mxArra
|
|||
class DynamicModelDLL
|
||||
{
|
||||
private:
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
DynamicFn *Dynamic; // pointer to the Dynamic function in DLL
|
||||
#else
|
||||
DynamicFn Dynamic; // pointer to the Dynamic function in DLL
|
||||
#endif
|
||||
|
||||
const int length; // tot num vars = Num of Jacobian rows
|
||||
const int jcols; // tot num var t-1, t and t+1 instances + exogs = Num of Jacobian columns
|
||||
const int nMax_lag; // no of lags
|
||||
const int nExog; // no of exogenous
|
||||
#if (defined _WIN32) || (defined __CYGWIN32__)
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
HINSTANCE dynamicHinstance; // DLL instance pointer in Windows
|
||||
#else
|
||||
void *dynamicHinstance; // and in Linux or Mac
|
||||
|
|
Loading…
Reference in New Issue