diff options
| author | ruki <[email protected]> | 2023-05-05 00:24:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-05-05 00:24:25 +0800 |
| commit | 4efc89f7b422d7b22c9ef76a68aff51bcb95c8c3 (patch) | |
| tree | 6c57e3b58e61dee2d1235972828ad9fed3591855 /core/src/xmake/engine.c | |
| parent | 67ac27c751ea9b7c706bdd221a78a216f74e2109 (diff) | |
add memory hook
Diffstat (limited to 'core/src/xmake/engine.c')
| -rw-r--r-- | core/src/xmake/engine.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index a68de8c12..8b24984de 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -50,6 +50,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ + +// proc/self #if defined(TB_CONFIG_OS_LINUX) # define XM_PROC_SELF_FILE "/proc/self/exe" #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) @@ -62,6 +64,9 @@ # endif #endif +// hook lua memory allocator +#define XM_HOOK_LUA_MEMALLOC (0) + /* ////////////////////////////////////////////////////////////////////////////////////// * types */ @@ -1034,6 +1039,17 @@ static tb_void_t xm_engine_init_signal(xm_engine_t* engine) #endif } +#if XM_HOOK_LUA_MEMALLOC +static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) +{ +// tb_trace_i("data: %p, osize: %d nsize: %d", data, (int)osize, (int)nsize); + if (nsize == 0 && data) tb_free(data); + else if (!data) return tb_malloc((tb_size_t)nsize); + else return tb_ralloc(data, (tb_size_t)nsize); + return tb_null; +} +#endif + /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ @@ -1055,6 +1071,11 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c engine->lua = luaL_newstate(); tb_assert_and_check_break(engine->lua); +#if XM_HOOK_LUA_MEMALLOC + // hook lua memmory + lua_setallocf(engine->lua, xm_engine_lua_realloc, engine->lua); +#endif + // open lua libraries luaL_openlibs(engine->lua); |
