* libs/core: Made luci.util.strip_bytecode forward-compatible to upcoming OpenWRT...
[project/luci.git] / libs / core / luasrc / util.lua
index 5168560..76e382b 100644 (file)
@@ -87,9 +87,9 @@ end
 
 -- Checks whether a table has an object "value" in it
 function contains(table, value)
-       for k,v in pairs(table) do
+       for k, v in pairs(table) do
                if value == v then
-                       return true
+                       return k
                end
        end
        return false
@@ -234,7 +234,7 @@ function strip_bytecode(dump)
                                offset = offset + size + subint(dump, offset, size)
                        elseif t == 3 then
                                offset = offset + num
-                       elseif t == 254 then
+                       elseif t == 254 or t == 9 then
                                offset = offset + lnum
                        end
                end
@@ -281,16 +281,9 @@ function threadlocal()
                        rawset(self, thread, {})
                end
                rawget(self, thread)[key] = value
-               
-               -- Avoid memory leaks by removing abandoned stores
-               for k, v in pairs(self) do
-                       if type(k) == "thread" and coroutine.status(k) == "dead" then
-                               rawset(self, k, nil)
-                       end
-               end
        end
        
-       setmetatable(tbl, {__index = get, __newindex = set})
+       setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"})
        
        return tbl
 end
@@ -404,6 +397,7 @@ end
 local performResume, handleReturnValue
 local oldpcall, oldxpcall = pcall, xpcall
 coxpt = {}
+setmetatable(coxpt, {__mode = "kv"})
 
 function handleReturnValue(err, co, status, ...)
     if not status then
@@ -429,6 +423,7 @@ function coxpcall(f, err, ...)
     end
     local c = coroutine.running()
     coxpt[co] = coxpt[c] or c or 0
+    
     return performResume(err, co, ...)
 end