all repos — fluxbox @ de4dfdad163abaff265adde0af4ff48e7424d7af

custom fork of the fluxbox windowmanager

fix static management of CommandParser, sf.net 1474444
simonb simonb
commit

de4dfdad163abaff265adde0af4ff48e7424d7af

parent

1028f4cb51ea998f475ec9ffc61aac164d0ca793

3 files changed, 24 insertions(+), 3 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,6 +1,9 @@

(Format: Year/Month/Day) Changes for 0.9.16: *06/04/22: + * static CommandParser could be used after destruction (Simon) + Fixes sf.net #1474444, segfault when DISPLAY not set + CommmandParser.hh/cc * Minor cosmetic changes, thanks Semushin Slava (php-coder AT ngs ru) main.cc Screen.cc util/startfluxbox.in * First draft of new docs in docs/asciidoc (Mathias)
M src/CommandParser.ccsrc/CommandParser.cc

@@ -32,6 +32,9 @@ using std::vector;

using FbTk::StringUtil::removeFirstWhitespace; using FbTk::StringUtil::toLower; + +CommandParser *CommandParser::s_singleton = 0; + CommandFactory::CommandFactory() { }

@@ -39,15 +42,24 @@

CommandFactory::~CommandFactory() { // remove all associations with this factory CommandParser::instance().removeAssociation(*this); + } void CommandFactory::addCommand(const string &command_name) { CommandParser::instance().associateCommand(command_name, *this); } +// ensure it is singleton +CommandParser::CommandParser() { + if (s_singleton != 0) + throw std::string("CommandParser currently meant ot be singleton"); +} + CommandParser &CommandParser::instance() { - static CommandParser singleton; - return singleton; + if (s_singleton == 0) + s_singleton = new CommandParser(); + + return *s_singleton; } FbTk::Command *CommandParser::parseLine(const string &line) {

@@ -105,4 +117,7 @@ while (!commands.empty()) {

m_commandfactorys.erase(commands.back()); commands.pop_back(); } + + if (m_commandfactorys.empty()) + delete s_singleton; }
M src/CommandParser.hhsrc/CommandParser.hh

@@ -54,6 +54,8 @@

/// @return parses and returns a command matching the line FbTk::Command *parseLine(const std::string &line); + CommandParser(); + /// @return instance of command parser static CommandParser &instance(); /// @return map of factorys

@@ -71,7 +73,8 @@ FbTk::Command *toCommand(const std::string &command,

const std::string &arguments); CommandFactoryMap m_commandfactorys; ///< a string to factory map - + + static CommandParser *s_singleton; }; #endif // COMMANDPARSER_HH