aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2013-02-18 21:01:15 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-18 21:04:22 (GMT)
commit4ea546a91e7188ad6a95931637b7b928abd38342 (patch)
tree4bfc84d34b2beba3a293320c1a02a4540488e323
parent2eacf0ee090f5f6280f69a96d370928260b24877 (diff)
downloadfluxbox_pavel-4ea546a91e7188ad6a95931637b7b928abd38342.zip
fluxbox_pavel-4ea546a91e7188ad6a95931637b7b928abd38342.tar.bz2
Fix unspecified construction order of Lua::s_init_functions
-rw-r--r--src/FbTk/LuaUtil.cc23
-rw-r--r--src/FbTk/LuaUtil.hh15
2 files changed, 24 insertions, 14 deletions
diff --git a/src/FbTk/LuaUtil.cc b/src/FbTk/LuaUtil.cc
index 700ef1a..8f382e8 100644
--- a/src/FbTk/LuaUtil.cc
+++ b/src/FbTk/LuaUtil.cc
@@ -57,9 +57,26 @@ namespace {
57 return 0; 57 return 0;
58 } 58 }
59 59
60 struct AutoVector: public std::vector<Lua::InitFunction *> {
61 ~AutoVector() {
62 for(iterator it = begin(); it != end(); ++it)
63 delete *it;
64 }
65 };
66 typedef AutoVector InitFunctions;
67
68 InitFunctions *s_init_functions;
60} // anonymous namespace 69} // anonymous namespace
61 70
62Lua::InitFunctions Lua::s_init_functions; 71void Lua::doRegisterInitFunction(std::auto_ptr<InitFunction> fn) {
72 struct InitHelper {
73 InitHelper() { s_init_functions = new InitFunctions; }
74 ~InitHelper() { delete s_init_functions; }
75 };
76 static InitHelper helper;
77
78 s_init_functions->push_back(fn.release());
79}
63 80
64Lua::Lua() { 81Lua::Lua() {
65 checkstack(1); 82 checkstack(1);
@@ -73,8 +90,8 @@ Lua::Lua() {
73 90
74 makeReadOnly(lua::GLOBALSINDEX, true); 91 makeReadOnly(lua::GLOBALSINDEX, true);
75 92
76 InitFunctions::const_iterator it_end = s_init_functions.end(); 93 InitFunctions::const_iterator it_end = s_init_functions->end();
77 for(InitFunctions::const_iterator it = s_init_functions.begin(); it != it_end; ++it) 94 for(InitFunctions::const_iterator it = s_init_functions->begin(); it != it_end; ++it)
78 (**it)(*this); 95 (**it)(*this);
79} 96}
80 97
diff --git a/src/FbTk/LuaUtil.hh b/src/FbTk/LuaUtil.hh
index d013ed9..12a687e 100644
--- a/src/FbTk/LuaUtil.hh
+++ b/src/FbTk/LuaUtil.hh
@@ -53,9 +53,11 @@ public:
53 */ 53 */
54 void readOnlySet(int index); 54 void readOnlySet(int index);
55 55
56 typedef Slot<void, Lua &> InitFunction;
57
56 template<typename Functor> 58 template<typename Functor>
57 static void registerInitFunction(const Functor &fn) { 59 static void registerInitFunction(const Functor &fn) {
58 s_init_functions.push_back(new SlotImpl<Functor, void, Lua &>(fn)); 60 doRegisterInitFunction(std::auto_ptr<InitFunction>(new SlotImpl<Functor, void, Lua &>(fn)));
59 } 61 }
60 62
61 class RegisterInitFunction { 63 class RegisterInitFunction {
@@ -67,16 +69,7 @@ public:
67 }; 69 };
68 70
69private: 71private:
70 typedef Slot<void, Lua &> InitFunction; 72 static void doRegisterInitFunction(std::auto_ptr<InitFunction> fn);
71 struct AutoVector: public std::vector<InitFunction *> {
72 ~AutoVector() {
73 for(iterator it = begin(); it != end(); ++it)
74 delete *it;
75 }
76 };
77 typedef AutoVector InitFunctions;
78
79 static InitFunctions s_init_functions;
80}; 73};
81 74
82} // namespace FbTk 75} // namespace FbTk