--- embedaddon/lighttpd/src/mod_magnet_cache.c 2014/06/15 20:20:06 1.1.1.2 +++ embedaddon/lighttpd/src/mod_magnet_cache.c 2016/11/02 10:35:00 1.1.1.3 @@ -1,3 +1,5 @@ +#include "first.h" + #include "mod_magnet_cache.h" #include "stat_cache.h" @@ -68,6 +70,7 @@ lua_State *script_cache_get_script(server *srv, connec /* oops, the script failed last time */ if (lua_gettop(sc->L) == 0) break; + force_assert(lua_gettop(sc->L) == 1); if (HANDLER_ERROR == stat_cache_get_entry(srv, con, sc->name, &sce)) { lua_pop(sc->L, 1); /* pop the old function */ @@ -81,7 +84,6 @@ lua_State *script_cache_get_script(server *srv, connec } force_assert(lua_isfunction(sc->L, -1)); - lua_pushvalue(sc->L, -1); /* copy the function-reference */ return sc->L; } @@ -104,7 +106,7 @@ lua_State *script_cache_get_script(server *srv, connec cache->ptr[cache->used++] = sc; - buffer_copy_string_buffer(sc->name, name); + buffer_copy_buffer(sc->name, name); sc->L = luaL_newstate(); luaL_openlibs(sc->L); @@ -114,22 +116,14 @@ lua_State *script_cache_get_script(server *srv, connec if (0 != luaL_loadfile(sc->L, name->ptr)) { /* oops, an error, return it */ - return sc->L; } if (HANDLER_GO_ON == stat_cache_get_entry(srv, con, sc->name, &sce)) { - buffer_copy_string_buffer(sc->etag, sce->etag); + buffer_copy_buffer(sc->etag, sce->etag); } - /** - * pcall() needs the function on the stack - * - * as pcall() will pop the script from the stack when done, we have to - * duplicate it here - */ force_assert(lua_isfunction(sc->L, -1)); - lua_pushvalue(sc->L, -1); /* copy the function-reference */ return sc->L; }