forked from enlightenment/efl
edje - fix edje lua usage for lua 5.2 to not go crazy on memory allocs
this fixes T323 - this is a change in lua 5.2 that makes osize encode the type of data being allocated where 5.1 didn't do it and the math was thus screwed as a result. comments in the diff. cherry-pick me!
This commit is contained in:
parent
2373e1f636
commit
27eed1bc4e
|
@ -205,14 +205,34 @@ static const luaL_Reg _elua_libs[] =
|
||||||
static void *
|
static void *
|
||||||
_elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
_elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
||||||
{
|
{
|
||||||
|
size_t dif;
|
||||||
Edje_Lua_Alloc *ela = ud;
|
Edje_Lua_Alloc *ela = ud;
|
||||||
void *ptr2;
|
void *ptr2;
|
||||||
|
|
||||||
ela->cur += nsize - osize;
|
// in lua 5.2 osize encodes the type of data allocted if ptr is NULL
|
||||||
|
// LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, or LUA_TTHREAD
|
||||||
|
if (ptr == NULL) osize = 0;
|
||||||
|
|
||||||
|
if (nsize > osize)
|
||||||
|
{
|
||||||
|
dif = nsize - osize;
|
||||||
|
ela->cur += dif;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dif = osize - nsize;
|
||||||
|
if (ela->cur < dif)
|
||||||
|
{
|
||||||
|
ERR("Lua allloc cur size %i < diff %i\n", (int)ela->cur, (int)dif);
|
||||||
|
dif = ela->cur;
|
||||||
|
}
|
||||||
|
ela->cur -= dif;
|
||||||
|
}
|
||||||
|
|
||||||
if (ela->cur > ela->max)
|
if (ela->cur > ela->max)
|
||||||
{
|
{
|
||||||
ERR("Lua memory limit of %zu bytes reached (%zu allocated)",
|
ERR("Lua memory limit of %i bytes reached (%i allocated)",
|
||||||
ela->max, ela->cur);
|
(int)ela->max, (int)ela->cur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (nsize == 0)
|
if (nsize == 0)
|
||||||
|
@ -220,11 +240,11 @@ _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
ptr2 = realloc(ptr, nsize + 4);
|
||||||
ptr2 = realloc(ptr, nsize);
|
|
||||||
if (ptr2) return ptr2;
|
if (ptr2) return ptr2;
|
||||||
ERR("Lua cannot re-allocate %zu bytes", nsize);
|
|
||||||
return ptr2;
|
ERR("Lua cannot re-allocate %i bytes", (int)nsize);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue