Fix locale in NGSPICE methods using LOCALE_IO instead of setlocale.
More information: https://lists.launchpad.net/kicad-developers/msg25763.html
This commit is contained in:
parent
00b9ac7cc3
commit
43d93682a2
|
@ -26,6 +26,8 @@
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
#include "spice_reporter.h"
|
#include "spice_reporter.h"
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -52,10 +54,9 @@ void NGSPICE::Init()
|
||||||
|
|
||||||
vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
|
vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<COMPLEX> data;
|
vector<COMPLEX> data;
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
if( vi )
|
if( vi )
|
||||||
{
|
{
|
||||||
|
@ -80,10 +81,9 @@ vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
|
||||||
|
|
||||||
vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
|
vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<double> data;
|
vector<double> data;
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
if( vi )
|
if( vi )
|
||||||
{
|
{
|
||||||
|
@ -113,11 +113,9 @@ vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
|
||||||
|
|
||||||
vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
|
vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<double> data;
|
vector<double> data;
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
if( vi )
|
if( vi )
|
||||||
{
|
{
|
||||||
|
@ -139,11 +137,9 @@ vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
|
||||||
|
|
||||||
vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
|
vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<double> data;
|
vector<double> data;
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
if( vi )
|
if( vi )
|
||||||
{
|
{
|
||||||
|
@ -168,11 +164,9 @@ vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
|
||||||
|
|
||||||
vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
|
vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<double> data;
|
vector<double> data;
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
if( vi )
|
if( vi )
|
||||||
{
|
{
|
||||||
|
@ -197,6 +191,7 @@ vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
|
||||||
|
|
||||||
bool NGSPICE::LoadNetlist( const string& aNetlist )
|
bool NGSPICE::LoadNetlist( const string& aNetlist )
|
||||||
{
|
{
|
||||||
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
vector<char*> lines;
|
vector<char*> lines;
|
||||||
stringstream ss( aNetlist );
|
stringstream ss( aNetlist );
|
||||||
|
|
||||||
|
@ -209,9 +204,7 @@ bool NGSPICE::LoadNetlist( const string& aNetlist )
|
||||||
|
|
||||||
lines.push_back( nullptr );
|
lines.push_back( nullptr );
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
|
||||||
ngSpice_Circ( lines.data() );
|
ngSpice_Circ( lines.data() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
for( auto line : lines )
|
for( auto line : lines )
|
||||||
delete line;
|
delete line;
|
||||||
|
@ -222,36 +215,29 @@ bool NGSPICE::LoadNetlist( const string& aNetlist )
|
||||||
|
|
||||||
bool NGSPICE::Run()
|
bool NGSPICE::Run()
|
||||||
{
|
{
|
||||||
setlocale( LC_ALL, "C" );
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
bool rv = Command( "bg_run" ); // bg_* commands execute in a separate thread
|
return Command( "bg_run" ); // bg_* commands execute in a separate thread
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NGSPICE::Stop()
|
bool NGSPICE::Stop()
|
||||||
{
|
{
|
||||||
setlocale( LC_ALL, "C" );
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
bool rv = Command( "bg_halt" ); // bg_* commands execute in a separate thread
|
return Command( "bg_halt" ); // bg_* commands execute in a separate thread
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NGSPICE::IsRunning()
|
bool NGSPICE::IsRunning()
|
||||||
{
|
{
|
||||||
setlocale( LC_ALL, "C" );
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
bool rv = ngSpice_running();
|
return ngSpice_running();
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NGSPICE::Command( const string& aCmd )
|
bool NGSPICE::Command( const string& aCmd )
|
||||||
{
|
{
|
||||||
setlocale( LC_ALL, "C" );
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
ngSpice_Command( (char*) aCmd.c_str() );
|
ngSpice_Command( (char*) aCmd.c_str() );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -286,12 +272,11 @@ void NGSPICE::init()
|
||||||
{
|
{
|
||||||
m_error = false;
|
m_error = false;
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||||
ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
||||||
|
|
||||||
// Workaround to avoid hang ups on certain errors
|
// Workaround to avoid hang ups on certain errors
|
||||||
Command( "unset interactive" );
|
Command( "unset interactive" );
|
||||||
setlocale( LC_ALL, "" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue