Add realloc locking calls for ngspice42.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/15941
This commit is contained in:
parent
482aff3f0b
commit
e59612d56c
|
@ -63,6 +63,8 @@ NGSPICE::NGSPICE() :
|
|||
m_ngSpice_AllPlots( nullptr ),
|
||||
m_ngSpice_AllVecs( nullptr ),
|
||||
m_ngSpice_Running( nullptr ),
|
||||
m_ngSpice_LockRealloc( nullptr ),
|
||||
m_ngSpice_UnlockRealloc( nullptr ),
|
||||
m_error( false )
|
||||
{
|
||||
init_dll();
|
||||
|
@ -122,6 +124,7 @@ std::vector<COMPLEX> NGSPICE::GetComplexVector( const std::string& aName, int aM
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<COMPLEX> data;
|
||||
NGSPICE_LOCK_REALLOC lock( this );
|
||||
|
||||
if( aMaxLen == 0 )
|
||||
return data;
|
||||
|
@ -149,8 +152,9 @@ std::vector<COMPLEX> NGSPICE::GetComplexVector( const std::string& aName, int aM
|
|||
|
||||
std::vector<double> NGSPICE::GetRealVector( const std::string& aName, int aMaxLen )
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
NGSPICE_LOCK_REALLOC lock( this );
|
||||
|
||||
if( aMaxLen == 0 )
|
||||
return data;
|
||||
|
@ -181,8 +185,9 @@ std::vector<double> NGSPICE::GetRealVector( const std::string& aName, int aMaxLe
|
|||
|
||||
std::vector<double> NGSPICE::GetImaginaryVector( const std::string& aName, int aMaxLen )
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
NGSPICE_LOCK_REALLOC lock( this );
|
||||
|
||||
if( aMaxLen == 0 )
|
||||
return data;
|
||||
|
@ -205,8 +210,9 @@ std::vector<double> NGSPICE::GetImaginaryVector( const std::string& aName, int a
|
|||
|
||||
std::vector<double> NGSPICE::GetGainVector( const std::string& aName, int aMaxLen )
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
NGSPICE_LOCK_REALLOC lock( this );
|
||||
|
||||
if( aMaxLen == 0 )
|
||||
return data;
|
||||
|
@ -234,8 +240,9 @@ std::vector<double> NGSPICE::GetGainVector( const std::string& aName, int aMaxLe
|
|||
|
||||
std::vector<double> NGSPICE::GetPhaseVector( const std::string& aName, int aMaxLen )
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
std::vector<double> data;
|
||||
NGSPICE_LOCK_REALLOC lock( this );
|
||||
|
||||
if( aMaxLen == 0 )
|
||||
return data;
|
||||
|
@ -486,6 +493,13 @@ void NGSPICE::init_dll()
|
|||
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
|
||||
|
||||
{
|
||||
wxLogNull doNotLog; // disable logging so we don't get warnings on pre-ngspice42 dlls
|
||||
|
||||
m_ngSpice_LockRealloc = (ngSpice_LockRealloc) m_dll.GetSymbol( "ngSpice_LockRealloc" );
|
||||
m_ngSpice_UnlockRealloc = (ngSpice_UnlockRealloc) m_dll.GetSymbol( "ngSpice_UnlockRealloc" );
|
||||
}
|
||||
|
||||
m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, nullptr, nullptr,
|
||||
&cbBGThreadRunning, this );
|
||||
|
||||
|
|
|
@ -110,8 +110,6 @@ public:
|
|||
void Clean() override final;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
// Performs DLL initialization, obtains function pointers
|
||||
void init_dll();
|
||||
|
||||
|
@ -125,19 +123,42 @@ private:
|
|||
typedef char** ( *ngSpice_AllPlots )( void );
|
||||
typedef char** ( *ngSpice_AllVecs )( char* plotname );
|
||||
typedef bool ( *ngSpice_Running )( void );
|
||||
typedef int ( *ngSpice_LockRealloc )( void );
|
||||
typedef int ( *ngSpice_UnlockRealloc )( void );
|
||||
|
||||
///< Handle to DLL functions
|
||||
ngSpice_Init m_ngSpice_Init;
|
||||
ngSpice_Circ m_ngSpice_Circ;
|
||||
ngSpice_Command m_ngSpice_Command;
|
||||
ngGet_Vec_Info m_ngGet_Vec_Info;
|
||||
ngSpice_CurPlot m_ngSpice_CurPlot;
|
||||
ngSpice_AllPlots m_ngSpice_AllPlots;
|
||||
ngSpice_AllVecs m_ngSpice_AllVecs;
|
||||
ngSpice_Running m_ngSpice_Running;
|
||||
ngSpice_Init m_ngSpice_Init;
|
||||
ngSpice_Circ m_ngSpice_Circ;
|
||||
ngSpice_Command m_ngSpice_Command;
|
||||
ngGet_Vec_Info m_ngGet_Vec_Info;
|
||||
ngSpice_CurPlot m_ngSpice_CurPlot;
|
||||
ngSpice_AllPlots m_ngSpice_AllPlots;
|
||||
ngSpice_AllVecs m_ngSpice_AllVecs;
|
||||
ngSpice_Running m_ngSpice_Running;
|
||||
ngSpice_LockRealloc m_ngSpice_LockRealloc;
|
||||
ngSpice_UnlockRealloc m_ngSpice_UnlockRealloc;
|
||||
|
||||
wxDynamicLibrary m_dll;
|
||||
|
||||
class NGSPICE_LOCK_REALLOC
|
||||
{
|
||||
public:
|
||||
NGSPICE_LOCK_REALLOC( NGSPICE* ngspice ) :
|
||||
m_ngspice( ngspice )
|
||||
{
|
||||
if( m_ngspice->m_ngSpice_LockRealloc )
|
||||
m_ngspice->m_ngSpice_LockRealloc();
|
||||
};
|
||||
|
||||
~NGSPICE_LOCK_REALLOC()
|
||||
{
|
||||
if( m_ngspice->m_ngSpice_UnlockRealloc )
|
||||
m_ngspice->m_ngSpice_UnlockRealloc();
|
||||
};
|
||||
|
||||
private:
|
||||
NGSPICE* m_ngspice;
|
||||
};
|
||||
|
||||
///< Execute commands from a file
|
||||
bool loadSpinit( const std::string& aFileName );
|
||||
|
|
Loading…
Reference in New Issue