aboutsummaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/lmem.c b/lmem.c
index f41d92d5..79a3e335 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.33 2000/06/12 13:52:05 roberto Exp roberto $ 2** $Id: lmem.c,v 1.34 2000/06/26 19:28:31 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11 11
12#include "lua.h" 12#include "lua.h"
13 13
14#include "ldo.h"
14#include "lmem.h" 15#include "lmem.h"
15#include "lobject.h" 16#include "lobject.h"
16#include "lstate.h" 17#include "lstate.h"
@@ -36,6 +37,7 @@
36 37
37 38
38#include <assert.h> 39#include <assert.h>
40#include <limits.h>
39#include <string.h> 41#include <string.h>
40 42
41#undef realloc 43#undef realloc
@@ -59,6 +61,7 @@ union L_U { double d; char *s; long l; };
59unsigned long memdebug_numblocks = 0; 61unsigned long memdebug_numblocks = 0;
60unsigned long memdebug_total = 0; 62unsigned long memdebug_total = 0;
61unsigned long memdebug_maxmem = 0; 63unsigned long memdebug_maxmem = 0;
64unsigned long memdebug_memlimit = LONG_MAX;
62 65
63 66
64static void *checkblock (void *block) { 67static void *checkblock (void *block) {
@@ -88,6 +91,8 @@ static void *debug_realloc (void *block, size_t size) {
88 freeblock(block); 91 freeblock(block);
89 return NULL; 92 return NULL;
90 } 93 }
94 else if (memdebug_total+size > memdebug_memlimit)
95 return NULL; /* to test memory allocation errors */
91 else { 96 else {
92 size_t realsize = HEADER+size+MARKSIZE; 97 size_t realsize = HEADER+size+MARKSIZE;
93 char *newblock = (char *)(malloc)(realsize); /* alloc a new block */ 98 char *newblock = (char *)(malloc)(realsize); /* alloc a new block */
@@ -139,8 +144,11 @@ void *luaM_realloc (lua_State *L, void *block, lint32 size) {
139 else if (size >= MAX_SIZET) 144 else if (size >= MAX_SIZET)
140 lua_error(L, "memory allocation error: block too big"); 145 lua_error(L, "memory allocation error: block too big");
141 block = realloc(block, size); 146 block = realloc(block, size);
142 if (block == NULL) 147 if (block == NULL) {
143 lua_error(L, memEM); 148 if (L)
149 luaD_breakrun(L, LUA_ERRMEM); /* break run without error message */
150 else return NULL; /* error before creating state! */
151 }
144 return block; 152 return block;
145} 153}
146 154