From d8f1cca16ea9a682127bb328c8bdfbfb4ded3412 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 20 Sep 2005 14:55:10 -0300 Subject: [PATCH] new function 'lua_setallocf' --- lapi.c | 16 ++++++++++++++-- ltests.c | 3 ++- lua.h | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lapi.c b/lapi.c index 65711ca0..16f469da 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.48 2005/09/01 17:42:22 roberto Exp roberto $ +** $Id: lapi.c,v 2.49 2005/09/14 17:44:48 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -992,8 +992,20 @@ LUA_API void lua_concat (lua_State *L, int n) { LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); if (ud) *ud = G(L)->ud; - return G(L)->frealloc; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); } diff --git a/ltests.c b/ltests.c index 7530b7f9..70a66ce0 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.30 2005/08/26 17:36:32 roberto Exp roberto $ +** $Id: ltests.c,v 2.31 2005/09/14 17:48:57 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -1124,6 +1124,7 @@ int luaB_opentests (lua_State *L) { void *ud; lua_assert(lua_getallocf(L, &ud) == debug_realloc); lua_assert(ud == cast(void *, &memcontrol)); + lua_setallocf(L, lua_getallocf(L, NULL), ud); lua_state = L; /* keep first state to be opened */ luaL_register(L, "T", tests_funcs); return 0; diff --git a/lua.h b/lua.h index aa969ae0..0bd97084 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.211 2005/08/12 13:34:15 roberto Exp roberto $ +** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -239,6 +239,7 @@ LUA_API int (lua_next) (lua_State *L, int idx); LUA_API void (lua_concat) (lua_State *L, int n); LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);