diff --git a/lualib-src/lua-sharedata.c b/lualib-src/lua-sharedata.c index 6ef10f0a..e7a27c57 100644 --- a/lualib-src/lua-sharedata.c +++ b/lualib-src/lua-sharedata.c @@ -376,6 +376,7 @@ pconv(lua_State *L) { static void convert_stringmap(struct context *ctx, struct table *tbl) { lua_State *L = ctx->L; + lua_checkstack(L, ctx->string_index + LUA_MINSTACK); lua_settop(L, ctx->string_index + 1); lua_pushvalue(L, 1); struct state * s = lua_newuserdata(L, sizeof(*s)); diff --git a/service-src/service_snlua.c b/service-src/service_snlua.c index 89e607f6..b839b117 100644 --- a/service-src/service_snlua.c +++ b/service-src/service_snlua.c @@ -12,6 +12,7 @@ struct snlua { lua_State * L; struct skynet_context * ctx; + FILE *f; }; // LUA_CACHELIB may defined in patched lua for shared proto @@ -143,17 +144,35 @@ snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args) { return 0; } +static void * +lalloc(void *ud, void *ptr, size_t osize, size_t nsize) { + struct snlua * l = ud; + if (l->f) { + fprintf(l->f, "%p %d %d\n", ptr, (int)osize, (int)nsize); + } + if (nsize == 0) { + skynet_free(ptr); + return NULL; + } else { + return skynet_realloc(ptr, nsize); + } +} + struct snlua * snlua_create(void) { struct snlua * l = skynet_malloc(sizeof(*l)); memset(l,0,sizeof(*l)); - l->L = lua_newstate(skynet_lalloc, NULL); + char tmp[L_tmpnam]; + l->f = fopen(tmpnam(tmp),"wb"); +// printf("%s\n", tmp); + l->L = lua_newstate(lalloc, l); return l; } void snlua_release(struct snlua *l) { lua_close(l->L); + fclose(l->f); skynet_free(l); } diff --git a/skynet-src/malloc_hook.c b/skynet-src/malloc_hook.c index d9ad6f32..3cff09fa 100644 --- a/skynet-src/malloc_hook.c +++ b/skynet-src/malloc_hook.c @@ -218,6 +218,7 @@ skynet_strdup(const char *str) { void * skynet_lalloc(void *ud, void *ptr, size_t osize, size_t nsize) { + printf("%p osize = %d nsize = %d\n", ptr, (int)osize, (int)nsize); if (nsize == 0) { skynet_free(ptr); return NULL;