ngspice: keep the ngspice DLL handle as an automatic variable
This commit is contained in:
parent
d3f23a62ec
commit
a8ef222517
|
@ -29,7 +29,6 @@
|
||||||
#include <common.h> // LOCALE_IO
|
#include <common.h> // LOCALE_IO
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/dynlib.h>
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -44,7 +43,6 @@ NGSPICE::NGSPICE()
|
||||||
|
|
||||||
NGSPICE::~NGSPICE()
|
NGSPICE::~NGSPICE()
|
||||||
{
|
{
|
||||||
delete m_dll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,25 +277,28 @@ void NGSPICE::init_dll()
|
||||||
|
|
||||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
|
|
||||||
|
if( m_dll.IsLoaded() ) // enable force reload
|
||||||
|
m_dll.Unload();
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
m_dll = new wxDynamicLibrary( "libngspice-0.dll" );
|
m_dll.Load( "libngspice-0.dll" );
|
||||||
#else
|
#else
|
||||||
m_dll = new wxDynamicLibrary( wxDynamicLibrary::CanonicalizeName( "ngspice" ) );
|
m_dll.Load( wxDynamicLibrary::CanonicalizeName( "ngspice" ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( !m_dll || !m_dll->IsLoaded() )
|
if( !m_dll.IsLoaded() )
|
||||||
throw std::runtime_error( "Missing ngspice shared library" );
|
throw std::runtime_error( "Missing ngspice shared library" );
|
||||||
|
|
||||||
m_error = false;
|
m_error = false;
|
||||||
|
|
||||||
// Obtain function pointers
|
// Obtain function pointers
|
||||||
m_ngSpice_Init = (ngSpice_Init) m_dll->GetSymbol( "ngSpice_Init" );
|
m_ngSpice_Init = (ngSpice_Init) m_dll.GetSymbol( "ngSpice_Init" );
|
||||||
m_ngSpice_Circ = (ngSpice_Circ) m_dll->GetSymbol( "ngSpice_Circ" );
|
m_ngSpice_Circ = (ngSpice_Circ) m_dll.GetSymbol( "ngSpice_Circ" );
|
||||||
m_ngSpice_Command = (ngSpice_Command) m_dll->GetSymbol( "ngSpice_Command" );
|
m_ngSpice_Command = (ngSpice_Command) m_dll.GetSymbol( "ngSpice_Command" );
|
||||||
m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll->GetSymbol( "ngGet_Vec_Info" );
|
m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll.GetSymbol( "ngGet_Vec_Info" );
|
||||||
m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll->GetSymbol( "ngSpice_AllPlots" );
|
m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll.GetSymbol( "ngSpice_AllPlots" );
|
||||||
m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll->GetSymbol( "ngSpice_AllVecs" );
|
m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll.GetSymbol( "ngSpice_AllVecs" );
|
||||||
m_ngSpice_Running = (ngSpice_Running) m_dll->GetSymbol( "ngSpice_running" ); // it is not a typo
|
m_ngSpice_Running = (ngSpice_Running) m_dll.GetSymbol( "ngSpice_running" ); // it is not a typo
|
||||||
|
|
||||||
m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
||||||
|
|
||||||
|
@ -460,7 +461,6 @@ void NGSPICE::validate()
|
||||||
{
|
{
|
||||||
if( m_error )
|
if( m_error )
|
||||||
{
|
{
|
||||||
delete m_dll;
|
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
init_dll();
|
init_dll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "spice_simulator.h"
|
#include "spice_simulator.h"
|
||||||
|
|
||||||
|
#include <wx/dynlib.h>
|
||||||
#include <ngspice/sharedspice.h>
|
#include <ngspice/sharedspice.h>
|
||||||
|
|
||||||
class wxDynamicLibrary;
|
class wxDynamicLibrary;
|
||||||
|
@ -101,7 +102,7 @@ private:
|
||||||
ngSpice_AllVecs m_ngSpice_AllVecs;
|
ngSpice_AllVecs m_ngSpice_AllVecs;
|
||||||
ngSpice_Running m_ngSpice_Running;
|
ngSpice_Running m_ngSpice_Running;
|
||||||
|
|
||||||
wxDynamicLibrary* m_dll;
|
wxDynamicLibrary m_dll;
|
||||||
|
|
||||||
///> Executes commands from a file
|
///> Executes commands from a file
|
||||||
bool loadSpinit( const std::string& aFileName );
|
bool loadSpinit( const std::string& aFileName );
|
||||||
|
|
Loading…
Reference in New Issue