1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-14 20:10:08 +03:00

Fixes #1791: Port Lua Bin Allocator to next:

* Bin Allocator
* Lua memory allocaton fixes
* Simulator memory leak fixes
This commit is contained in:
Damjan Adamic 2014-10-26 09:14:45 +01:00
parent 56a4cf5d26
commit c89381bae5
19 changed files with 294 additions and 13 deletions

View file

@ -954,10 +954,13 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
}
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud; (void)osize; /* not used */
if (nsize == 0) {
free(ptr);
if (ptr) { // avoid a bunch of NULL pointer free calls
// TRACE("free %p", ptr); FLUSH();
free(ptr);
}
return NULL;
}
else

View file

@ -93,6 +93,8 @@ LUALIB_API int (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);

View file

@ -205,6 +205,12 @@ static int stackinuse (lua_State *L) {
void luaD_shrinkstack (lua_State *L) {
int inuse = stackinuse(L);
int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
if ((L->stacksize - goodsize) < 40) {
//skip shrink
// TRACE("luaD_shrinkstack(skip): L->stacksize: %d, goodsize: %d", L->stacksize, goodsize);
return;
}
// TRACE("luaD_shrinkstack(): L->stacksize: %d, goodsize: %d", L->stacksize, goodsize);
if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK;
if (inuse > LUAI_MAXSTACK || /* handling stack overflow? */
goodsize >= L->stacksize) /* would grow instead of shrink? */

View file

@ -11,10 +11,10 @@
#include <stdarg.h>
#include <stddef.h>
#include <inttypes.h>
#include "luaconf.h"
#include "debug.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "2"

View file

@ -11,9 +11,9 @@
#include <limits.h>
#include <stddef.h>
#include "debug.h"
#if defined(SDCARD)
#define USE_FATFS
#endif
/*
** ==================================================================