From e8639b90ad5a929f08ee019b4c4fd30620298df8 Mon Sep 17 00:00:00 2001 From: Karel Tuma Date: Fri, 31 Oct 2008 19:44:53 +0100 Subject: [PATCH] use lua_mem(L, +-size) to track your additional userdata sizes. keep it balanced or you'll mess gc. --- src/lapi.c | 13 ++++++++++++- src/lua.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lapi.c b/src/lapi.c index 3c59614..bb823be 100644 --- a/src/lapi.c +++ b/src/lapi.c @@ -473,6 +473,11 @@ LUA_API const char *lua_resizestring(lua_State *L, const char *s, size_t l) return (void *)(ts+1); } +LUA_API void lua_freestring(lua_State *L, const char *s) +{ + TString *ts = (void *)( s + sizeof(TString)); + luaM_freemem(L, ts, (ts->tsv.len+1)*sizeof(char)+sizeof(TString)); +} LUA_API void lua_pushstring (lua_State *L, const char *s) { if (s == NULL) @@ -1056,7 +1061,13 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { return u + 1; } - +LUA_API size_t lua_mem(lua_State *L, ssize_t adj) +{ + global_State *g = G(L); + size_t old = g->totalbytes; + g->totalbytes += adj; + return old; +} LUA_API void lua_pushuserdata(lua_State *L, void *p) { diff --git a/src/lua.h b/src/lua.h index 5aa9988..28534a7 100644 --- a/src/lua.h +++ b/src/lua.h @@ -165,6 +165,7 @@ LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); LUA_API void (lua_pushlstring) (lua_State *L, const char *s, ssize_t l); LUA_API const char *(lua_preparestring) (lua_State *L, size_t len); LUA_API const char *(lua_resizestring) (lua_State *L, const char *s, size_t l); +LUA_API void lua_freestring(lua_State *L, const char *s); LUA_API void (lua_pushstring) (lua_State *L, const char *s); LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, va_list argp); @@ -239,6 +240,8 @@ LUA_API int (lua_gc) (lua_State *L, int what, int data); ** miscellaneous functions */ +LUA_API size_t (lua_mem) (lua_State *L, ssize_t adj); + LUA_API int (lua_error) (lua_State *L); LUA_API int (lua_next) (lua_State *L, int idx); -- 2.11.4.GIT