summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lmem.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2014-04-02 20:46:06 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2014-04-02 20:46:06 +0200
commitbfd0179042b0b02fb88748d54e56e7e208bb117f (patch)
tree42d5fd51574054caaf673420fca1ec962d62d2f2 /apps/plugins/lua/lmem.c
parent36378988ad4059982742f05f5eb50580b456840a (diff)
downloadrockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.zip
rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.gz
rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.bz2
rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.xz
Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and application builds. I checked only a few random native builds unfortunately. Sorry for inconvenience.
Diffstat (limited to 'apps/plugins/lua/lmem.c')
-rw-r--r--apps/plugins/lua/lmem.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/apps/plugins/lua/lmem.c b/apps/plugins/lua/lmem.c
index ee343e3..ae7d8c9 100644
--- a/apps/plugins/lua/lmem.c
+++ b/apps/plugins/lua/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.84.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -14,7 +14,6 @@
#include "ldebug.h"
#include "ldo.h"
-#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
@@ -26,11 +25,12 @@
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
** (`osize' is the old size, `nsize' is the new size)
**
-** * frealloc(ud, NULL, x, s) creates a new block of size `s' (no
-** matter 'x').
+** Lua ensures that (ptr == NULL) iff (osize == 0).
+**
+** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
**
** * frealloc(ud, p, x, 0) frees the block `p'
-** (in this specific case, frealloc must return NULL);
+** (in this specific case, frealloc must return NULL).
** particularly, frealloc(ud, NULL, 0, 0) does nothing
** (which is equivalent to free(NULL) in ANSI C)
**
@@ -44,12 +44,12 @@
void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
- int limit, const char *what) {
+ int limit, const char *errormsg) {
void *newblock;
int newsize;
if (*size >= limit/2) { /* cannot double it? */
if (*size >= limit) /* cannot grow even a little? */
- luaG_runerror(L, "too many %s (limit is %d)", what, limit);
+ luaG_runerror(L, errormsg);
newsize = limit; /* still have at least one free place */
}
else {
@@ -63,8 +63,9 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
}
-l_noret luaM_toobig (lua_State *L) {
+void *luaM_toobig (lua_State *L) {
luaG_runerror(L, "memory allocation error: block too big");
+ return NULL; /* to avoid warnings */
}
@@ -73,27 +74,13 @@ l_noret luaM_toobig (lua_State *L) {
** generic allocation routine.
*/
void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
- void *newblock;
global_State *g = G(L);
- size_t realosize = (block) ? osize : 0;
- lua_assert((realosize == 0) == (block == NULL));
-#if defined(HARDMEMTESTS)
- if (nsize > realosize && g->gcrunning)
- luaC_fullgc(L, 1); /* force a GC whenever possible */
-#endif
- newblock = (*g->frealloc)(g->ud, block, osize, nsize);
- if (newblock == NULL && nsize > 0) {
- api_check(L, nsize > realosize,
- "realloc cannot fail when shrinking a block");
- if (g->gcrunning) {
- luaC_fullgc(L, 1); /* try to free some memory... */
- newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
- }
- if (newblock == NULL)
- luaD_throw(L, LUA_ERRMEM);
- }
- lua_assert((nsize == 0) == (newblock == NULL));
- g->GCdebt = (g->GCdebt + nsize) - realosize;
- return newblock;
+ lua_assert((osize == 0) == (block == NULL));
+ block = (*g->frealloc)(g->ud, block, osize, nsize);
+ if (block == NULL && nsize > 0)
+ luaD_throw(L, LUA_ERRMEM);
+ lua_assert((nsize == 0) == (block == NULL));
+ g->totalbytes = (g->totalbytes - osize) + nsize;
+ return block;
}