summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r--apps/plugins/lua/lauxlib.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index 2e4b3b1e3c..acd7e0e636 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -13,7 +13,6 @@
13#include <string.h> 13#include <string.h>
14#include "lstring.h" /* ROCKLUA ADDED */ 14#include "lstring.h" /* ROCKLUA ADDED */
15 15
16
17/* This file uses only the official API of Lua. 16/* This file uses only the official API of Lua.
18** Any function declared here could be written as an application function. 17** Any function declared here could be written as an application function.
19** Note ** luaS_newlloc breaks this guarantee ROCKLUA ADDED 18** Note ** luaS_newlloc breaks this guarantee ROCKLUA ADDED
@@ -34,7 +33,9 @@
34#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ 33#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
35 lua_gettop(L) + (i) + 1) 34 lua_gettop(L) + (i) + 1)
36 35
37 36#ifndef LUA_OOM
37 #define LUA_OOM(L) {}
38#endif
38/* 39/*
39** {====================================================== 40** {======================================================
40** Error-report functions 41** Error-report functions
@@ -756,14 +757,30 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {
756 757
757 758
758static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { 759static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
759 (void)ud; 760 (void) osize;
760 (void)osize; 761 lua_State *L = (lua_State *)ud;
762 void *nptr;
763
761 if (nsize == 0) { 764 if (nsize == 0) {
762 free(ptr); 765 free(ptr);
763 return NULL; 766 return NULL;
764 } 767 }
765 else 768
766 return realloc(ptr, nsize); 769 nptr = realloc(ptr, nsize);
770 if (nptr == NULL) {
771 if(L != NULL)
772 {
773 luaC_fullgc(L); /* emergency full collection. */
774 nptr = realloc(ptr, nsize); /* try allocation again */
775 }
776
777 if (nptr == NULL) {
778 LUA_OOM(L); /* if defined.. signal OOM condition */
779 nptr = realloc(ptr, nsize); /* try allocation again */
780 }
781 }
782
783 return nptr;
767} 784}
768 785
769 786
@@ -779,6 +796,7 @@ static int panic (lua_State *L) {
779 796
780LUALIB_API lua_State *luaL_newstate (void) { 797LUALIB_API lua_State *luaL_newstate (void) {
781 lua_State *L = lua_newstate(l_alloc, NULL); 798 lua_State *L = lua_newstate(l_alloc, NULL);
799 lua_setallocf(L, l_alloc, L); /* allocator needs lua_State. */
782 if (L) lua_atpanic(L, &panic); 800 if (L) lua_atpanic(L, &panic);
783 return L; 801 return L;
784} 802}