From 397905ef8694ec716a51acebc993bb625340d388 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 7 Aug 2000 15:39:16 -0300 Subject: [PATCH] (much) better handling of memory alloction errors --- ldo.h | 3 ++- lmem.h | 6 ++---- lstate.h | 9 ++++++--- lua.h | 14 +++++++++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ldo.h b/ldo.h index 67d3f5fc..0e91c7c8 100644 --- a/ldo.h +++ b/ldo.h @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 1.20 2000/04/14 18:12:35 roberto Exp $ +** $Id: ldo.h,v 1.21 2000/06/28 20:21:06 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -25,6 +25,7 @@ void luaD_openstack (lua_State *L, StkId pos); void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook); void luaD_call (lua_State *L, StkId func, int nResults); void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); +void luaD_breakrun (lua_State *L, int errcode); int luaD_protectedrun (lua_State *L); void luaD_checkstack (lua_State *L, int n); diff --git a/lmem.h b/lmem.h index 55e2feab..f1630238 100644 --- a/lmem.h +++ b/lmem.h @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.13 2000/03/16 20:35:07 roberto Exp roberto $ +** $Id: lmem.h,v 1.14 2000/05/24 13:54:49 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -13,9 +13,6 @@ #include "llimits.h" #include "lua.h" -/* memory error message */ -#define memEM "not enough memory" - void *luaM_realloc (lua_State *L, void *oldblock, lint32 size); void *luaM_growaux (lua_State *L, void *block, size_t nelems, int inc, size_t size, const char *errormsg, @@ -37,6 +34,7 @@ void *luaM_growaux (lua_State *L, void *block, size_t nelems, extern unsigned long memdebug_numblocks; extern unsigned long memdebug_total; extern unsigned long memdebug_maxmem; +extern unsigned long memdebug_memlimit; #endif diff --git a/lstate.h b/lstate.h index 36cecb0b..70bc4600 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 1.33 2000/05/10 16:33:20 roberto Exp roberto $ +** $Id: lstate.h,v 1.34 2000/05/24 13:54:49 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -19,11 +19,14 @@ typedef TObject *StkId; /* index to stack elements */ /* -** `jmp_buf' may be an array, so it is better to make sure it has an -** address (and not that it *is* an address...) +** chain list of long jumps */ struct lua_longjmp { jmp_buf b; + struct lua_longjmp *previous; + volatile int status; /* error code */ + StkId base; + int numCblocks; }; diff --git a/lua.h b/lua.h index b6bd9305..f5d2e0ce 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.54 2000/05/26 19:17:57 roberto Exp roberto $ +** $Id: lua.h,v 1.55 2000/06/30 19:17:08 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** e-mail: lua@tecgraf.puc-rio.br @@ -30,6 +30,14 @@ #define LUA_ANYTAG (-1) + +/* error code for lua_do* */ +#define LUA_ERRFILE 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRRUN 1 +#define LUA_ERRMEM 4 + + typedef struct lua_State lua_State; typedef void (*lua_CFunction) (lua_State *L); @@ -58,7 +66,7 @@ int lua_dostring (lua_State *L, const char *str); int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name); /* Out: returns */ int lua_callfunction (lua_State *L, lua_Object f); - /* In: parameters; Out: returns */ + /* In: arguments; Out: returns */ void lua_beginblock (lua_State *L); void lua_endblock (lua_State *L); @@ -111,7 +119,7 @@ lua_Object lua_rawget (lua_State *L); /* In: table, index */ int lua_tag (lua_State *L, lua_Object obj); int lua_next (lua_State *L, lua_Object o, int i); - /* Out: ref, value */ + /* Out: index, value */ int lua_ref (lua_State *L, int lock); /* In: value */ lua_Object lua_getref (lua_State *L, int ref);