From 4303be8a4c343ad9085c2857cabc8e55f3bac525 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 28 Nov 2010 02:23:05 +0100 Subject: Changing the hashmap in LuaTask to a true C++ map. --- include/LuaTask.h | 6 +++--- lib/LuaTask.cc | 16 +++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/LuaTask.h b/include/LuaTask.h index 3695dcb..ae18d40 100644 --- a/include/LuaTask.h +++ b/include/LuaTask.h @@ -21,7 +21,7 @@ #define __LUATASK_H__ #include -#include +#include #include #include @@ -50,12 +50,12 @@ class LuaTask : public Task { String task; bool destroy_VM; - static htab * h; + static std::map h; }; class LuaTaskMan : public LuaObject { public: static void pushstatics(Lua *) throw (GeneralException); -}; +}; #endif diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index ef1abf7..b475c5b 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -30,7 +30,7 @@ #include #endif -htab * LuaTask::h = hcreate(1); +std::map LuaTask::h; LuaTask::LuaTask(Lua * __L, const String & _cmd, bool _destroy_VM) : L(__L), cmd(_cmd), nargs(0), c(0), b(0), destroy_VM(_destroy_VM) { LuaTask * top = gettop(); @@ -62,21 +62,11 @@ LuaTask::~LuaTask() { } LuaTask * LuaTask::gettop() { - if (!hfind(h, (Uint8 *) &L, sizeof(L))) { - hadd(h, (Uint8 *) &L, sizeof(L), 0); - } - - return (LuaTask *) hstuff(h); + return h[L]; } void LuaTask::settop(LuaTask * v) { - if (!hfind(h, (Uint8 *) &L, sizeof(L))) - return; - if (v) { - hstuff(h) = v; - } else { - hdel(h); - } + h[L] = v; } String LuaTask::GetName() { -- cgit v1.2.3 From c02c5e3c43d1a0a87b541f106f7527abea934696 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 28 Nov 2010 09:28:18 +0100 Subject: Workarounding String::strdup's issue on truncated sizes. --- lib/String.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/String.cc b/lib/String.cc index 14195f6..28a3fff 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -276,8 +276,10 @@ String String::extract(size_t from, ssize_t to) const { char * String::strdup(size_t from, ssize_t to) const { char * r; - r = Base::strdup(to_charp(from, to)); - + r = Base::strdup(to_charp(from, -1)); + to -= from; + if ((to >= 0) && (to < (siz - from))) + r[to] = 0; return r; } -- cgit v1.2.3 From 52688e09827ad6d30f21a58e673a9d8499dc8b89 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 28 Nov 2010 19:07:20 +0100 Subject: Small adjustment to the strdup call; the to includes the last character. --- lib/String.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/String.cc b/lib/String.cc index 28a3fff..7300365 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -279,7 +279,7 @@ char * String::strdup(size_t from, ssize_t to) const { r = Base::strdup(to_charp(from, -1)); to -= from; if ((to >= 0) && (to < (siz - from))) - r[to] = 0; + r[to + 1] = 0; return r; } -- cgit v1.2.3 From 06613bc6d84de84c7500e03d219ae011729821f5 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 29 Nov 2010 05:27:11 +0100 Subject: Making the ajax dumping system a little bit more robust. --- lib/ajaxlib.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ajaxlib.lua b/lib/ajaxlib.lua index e51d74f..7a8a395 100644 --- a/lib/ajaxlib.lua +++ b/lib/ajaxlib.lua @@ -33,6 +33,18 @@ function ajax_escape(str) return generic_escape(str, ajax_replacements) end +local function toajax(val) + local t = type(val) + + if t == "nil" or t == "function" or t == "table" then + return "" + elseif t == "boolean" then + return v and "1" or "0" + else + return val + end +end + function ajax_dump_table(t, out) local k, v, vk, vv @@ -43,7 +55,7 @@ function ajax_dump_table(t, out) for k, v in pairs(t) do out:write(k) for vk, vv in pairs(v) do - out:write("|" .. ajax_escape(vk) .. "=" .. ajax_escape(vv)) + out:write("|" .. ajax_escape(toajax(vk)) .. "=" .. ajax_escape(toajax(vv))) end out:write("\n") end -- cgit v1.2.3 From 6a21ca020d59a4ccae4452773695aae23017f19b Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 29 Nov 2010 06:27:29 +0100 Subject: Having a slightly better atomic support in the domain ids. --- lib/LuaHttp.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index a88c77c..7d4c091 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -25,6 +25,7 @@ #include "Base85.h" #include "HashFunction.h" #include "RandISAAC.h" +#include "Atomic.h" class LuaDomain : public Domain { public: @@ -435,8 +436,8 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } LuaDomain::LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) { - id = max_id++; /***FIXME***/ - + id = Atomic::Increment(&max_id); + L->push(DOMAIN_REGISTRY); L->gettable(LUA_REGISTRYINDEX); L->push((lua_Number) id); -- cgit v1.2.3 From c9e876553534f55da53f30b846a9ec61ad8e0275 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 29 Nov 2010 09:57:20 +0100 Subject: Revert "Having a slightly better atomic support in the domain ids." This reverts commit 6a21ca020d59a4ccae4452773695aae23017f19b. --- lib/LuaHttp.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 7d4c091..a88c77c 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -25,7 +25,6 @@ #include "Base85.h" #include "HashFunction.h" #include "RandISAAC.h" -#include "Atomic.h" class LuaDomain : public Domain { public: @@ -436,8 +435,8 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } LuaDomain::LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) { - id = Atomic::Increment(&max_id); - + id = max_id++; /***FIXME***/ + L->push(DOMAIN_REGISTRY); L->gettable(LUA_REGISTRYINDEX); L->push((lua_Number) id); -- cgit v1.2.3 From c7f53415c7dc0445ae58a790fc5bf51725a66d9c Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 29 Nov 2010 10:29:12 +0100 Subject: Making it so the [] operator doesn't crash if reading out of bounds - gcc is stupid for not calling the proper operator here. --- lib/String.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/String.cc b/lib/String.cc index 7300365..47315b6 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -388,9 +388,10 @@ const char & String::operator[](size_t i) const { } char & String::operator[](size_t i) throw (GeneralException) { - + static char zero; if (i >= siz) { - throw GeneralException("operator[] on String out of bounds"); + zero = 0; + return zero; } else { return str[i]; } -- cgit v1.2.3 From c99762a8980e691bab478f67b56b3fde56694e86 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 29 Nov 2010 10:29:38 +0100 Subject: Making it so the count operator in dblib returns a number and not a string. --- lib/dblib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dblib.lua b/lib/dblib.lua index 271d5a1..64ce880 100644 --- a/lib/dblib.lua +++ b/lib/dblib.lua @@ -759,7 +759,7 @@ END; count = function(t) _luadb.iselect(true, t, {"COUNT(*) AS count"}) local row = t:nextrow() - return row.count or row.COUNT + return ((row.count or row.COUNT) or 0) + 0 end, gselect = function(t, ...) -- cgit v1.2.3