mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Make GncQuotes::check() a private function, returning nothing
At the same time do an explicit reinstantiation of quotes_cached at first use to work around what seems to be a race condition between static instantiation and binreloc.
This commit is contained in:
parent
32df095d4f
commit
9d62755b4a
@ -36,8 +36,14 @@ extern "C" {
|
||||
namespace bp = boost::process;
|
||||
|
||||
static GncQuotes quotes_cached;
|
||||
static bool quotes_initialized = false;
|
||||
|
||||
bool
|
||||
GncQuotes::GncQuotes()
|
||||
{
|
||||
check();
|
||||
}
|
||||
|
||||
void
|
||||
GncQuotes::check (void)
|
||||
{
|
||||
m_version.clear();
|
||||
@ -74,12 +80,8 @@ GncQuotes::check (void)
|
||||
m_error_msg = e.what();
|
||||
};
|
||||
|
||||
auto success = (m_cmd_result == 0);
|
||||
|
||||
if (success)
|
||||
if (m_cmd_result == 0)
|
||||
std::sort (m_sources.begin(), m_sources.end());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
GList*
|
||||
@ -95,5 +97,16 @@ GncQuotes::sources_as_glist()
|
||||
|
||||
const GncQuotes& gnc_get_quotes_instance()
|
||||
{
|
||||
// The GncQuotes constructor runs check to test if Finance::Quote is properly installed
|
||||
// However due to a race condition the instantiation of the static quotes_cached
|
||||
// may or may not happen before binreloc has run. If binreloc didn't run, this will
|
||||
// try to run gnc-fq-check from the hard-coded install dir. This will fail in all
|
||||
// cases where binreloc is relevant (Windows, macOS or run from builddir).
|
||||
// To catch this, explicitly reinstantiate quotes_cached at first use.
|
||||
if (!quotes_initialized)
|
||||
{
|
||||
quotes_cached = GncQuotes();
|
||||
quotes_initialized = true;
|
||||
}
|
||||
return quotes_cached;
|
||||
}
|
||||
|
@ -36,10 +36,8 @@ const std::string not_found = std::string ("Not Found");
|
||||
class GncQuotes
|
||||
{
|
||||
public:
|
||||
bool check (void);
|
||||
|
||||
// Constructor - check for presence of Finance::Quote and import version and quote sources
|
||||
GncQuotes() { check(); }
|
||||
GncQuotes();
|
||||
|
||||
// Function to check if Finance::Quote is properly installed
|
||||
const int cmd_result() noexcept { return m_cmd_result; }
|
||||
@ -47,7 +45,10 @@ public:
|
||||
const std::string& version() noexcept { return m_version.empty() ? not_found : m_version; }
|
||||
const QuoteSources& sources() noexcept { return m_sources; }
|
||||
GList* sources_as_glist ();
|
||||
|
||||
private:
|
||||
void check (void);
|
||||
|
||||
std::string m_version;
|
||||
QuoteSources m_sources;
|
||||
int m_cmd_result;
|
||||
|
Loading…
Reference in New Issue
Block a user