diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-21 15:55:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-21 15:55:02 -0300 |
commit | 7a35f23c1688e3e24781c780e121bbdc0e4b53e1 (patch) | |
tree | b3de8cfb741848e579385f4751f95fdc37d3a5d3 | |
parent | 9284742a11b92dfe4ef011b963240cfa588515cd (diff) | |
download | lua-7a35f23c1688e3e24781c780e121bbdc0e4b53e1.tar.gz lua-7a35f23c1688e3e24781c780e121bbdc0e4b53e1.tar.bz2 lua-7a35f23c1688e3e24781c780e121bbdc0e4b53e1.zip |
a simplification about memory error messages.
-rw-r--r-- | func.c | 3 | ||||
-rw-r--r-- | luamem.c | 29 | ||||
-rw-r--r-- | luamem.h | 15 | ||||
-rw-r--r-- | opcode.c | 4 | ||||
-rw-r--r-- | table.c | 7 |
5 files changed, 21 insertions, 37 deletions
@@ -102,8 +102,7 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined) | |||
102 | void luaI_registerlocalvar (TaggedString *varname, int line) | 102 | void luaI_registerlocalvar (TaggedString *varname, int line) |
103 | { | 103 | { |
104 | if (numcurrvars >= maxcurrvars) | 104 | if (numcurrvars >= maxcurrvars) |
105 | maxcurrvars = growvector(&currvars, maxcurrvars, LocVar, | 105 | maxcurrvars = growvector(&currvars, maxcurrvars, LocVar, "", MAX_WORD); |
106 | lockEM, MAX_WORD); | ||
107 | currvars[numcurrvars].varname = varname; | 106 | currvars[numcurrvars].varname = varname; |
108 | currvars[numcurrvars].line = line; | 107 | currvars[numcurrvars].line = line; |
109 | numcurrvars++; | 108 | numcurrvars++; |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mem = "$Id: mem.c,v 1.9 1996/03/14 15:55:49 roberto Exp roberto $"; | 6 | char *rcs_mem = "$Id: mem.c,v 1.10 1996/03/21 16:31:32 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -14,27 +14,8 @@ char *rcs_mem = "$Id: mem.c,v 1.9 1996/03/14 15:55:49 roberto Exp roberto $"; | |||
14 | #include "table.h" | 14 | #include "table.h" |
15 | 15 | ||
16 | 16 | ||
17 | char *luaI_memerrormsg[NUMERRMSG] = { | 17 | #define mem_error() lua_error(memEM) |
18 | "code size overflow", | 18 | |
19 | "symbol table overflow", | ||
20 | "constant table overflow", | ||
21 | "stack size overflow", | ||
22 | "lex buffer overflow", | ||
23 | "lock table overflow" | ||
24 | }; | ||
25 | |||
26 | |||
27 | static void mem_error (void) | ||
28 | { | ||
29 | Long recovered = luaI_collectgarbage(); /* try to collect garbage */ | ||
30 | if (recovered) | ||
31 | lua_error("not enough memory"); | ||
32 | else | ||
33 | { /* if there is no garbage then must exit */ | ||
34 | fprintf(stderr, "lua error: memory overflow - unable to recover\n"); | ||
35 | exit(1); | ||
36 | } | ||
37 | } | ||
38 | 19 | ||
39 | void luaI_free (void *block) | 20 | void luaI_free (void *block) |
40 | { | 21 | { |
@@ -66,10 +47,10 @@ void *luaI_realloc (void *oldblock, unsigned long size) | |||
66 | 47 | ||
67 | 48 | ||
68 | int luaI_growvector (void **block, unsigned long nelems, int size, | 49 | int luaI_growvector (void **block, unsigned long nelems, int size, |
69 | enum memerrormsg errormsg, unsigned long limit) | 50 | char *errormsg, unsigned long limit) |
70 | { | 51 | { |
71 | if (nelems >= limit) | 52 | if (nelems >= limit) |
72 | lua_error(luaI_memerrormsg[errormsg]); | 53 | lua_error(errormsg); |
73 | nelems = (nelems == 0) ? 20 : nelems*2; | 54 | nelems = (nelems == 0) ? 20 : nelems*2; |
74 | if (nelems > limit) | 55 | if (nelems > limit) |
75 | nelems = limit; | 56 | nelems = limit; |
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** mem.c | 2 | ** mem.c |
3 | ** memory manager for lua | 3 | ** memory manager for lua |
4 | ** $Id: mem.h,v 1.4 1996/03/14 15:55:49 roberto Exp roberto $ | 4 | ** $Id: mem.h,v 1.5 1996/03/21 16:31:32 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef mem_h | 7 | #ifndef mem_h |
@@ -13,9 +13,14 @@ | |||
13 | 13 | ||
14 | 14 | ||
15 | /* memory error messages */ | 15 | /* memory error messages */ |
16 | #define NUMERRMSG 6 | 16 | #define codeEM "code size overflow" |
17 | enum memerrormsg {codeEM, symbolEM, constantEM, stackEM, lexEM, lockEM}; | 17 | #define symbolEM "symbol table overflow" |
18 | extern char *luaI_memerrormsg[]; | 18 | #define constantEM "constant table overflow" |
19 | #define stackEM "stack size overflow" | ||
20 | #define lexEM "lex buffer overflow" | ||
21 | #define lockEM "lock table overflow" | ||
22 | #define tableEM "table overflow" | ||
23 | #define memEM "not enough memory" | ||
19 | 24 | ||
20 | 25 | ||
21 | void luaI_free (void *block); | 26 | void luaI_free (void *block); |
@@ -23,7 +28,7 @@ void *luaI_malloc (unsigned long size); | |||
23 | void *luaI_realloc (void *oldblock, unsigned long size); | 28 | void *luaI_realloc (void *oldblock, unsigned long size); |
24 | void *luaI_buffer (unsigned long size); | 29 | void *luaI_buffer (unsigned long size); |
25 | int luaI_growvector (void **block, unsigned long nelems, int size, | 30 | int luaI_growvector (void **block, unsigned long nelems, int size, |
26 | enum memerrormsg errormsg, unsigned long limit); | 31 | char *errormsg, unsigned long limit); |
27 | 32 | ||
28 | #define new(s) ((s *)luaI_malloc(sizeof(s))) | 33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) |
29 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) | 34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.63 1996/03/20 17:05:44 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.64 1996/03/21 16:31:32 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -102,7 +102,7 @@ static void growstack (void) | |||
102 | if (stacksize >= limit) | 102 | if (stacksize >= limit) |
103 | { | 103 | { |
104 | limit = stacksize; | 104 | limit = stacksize; |
105 | lua_error(luaI_memerrormsg[stackEM]); | 105 | lua_error(stackEM); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -3,7 +3,7 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.49 1996/03/14 15:57:19 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.50 1996/03/21 16:31:32 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include "mem.h" | 8 | #include "mem.h" |
9 | #include "opcode.h" | 9 | #include "opcode.h" |
@@ -75,12 +75,11 @@ void luaI_initsymbol (void) | |||
75 | */ | 75 | */ |
76 | void luaI_initconstant (void) | 76 | void luaI_initconstant (void) |
77 | { | 77 | { |
78 | int i; | ||
79 | lua_maxconstant = BUFFER_BLOCK; | 78 | lua_maxconstant = BUFFER_BLOCK; |
80 | lua_constant = newvector(lua_maxconstant, TaggedString *); | 79 | lua_constant = newvector(lua_maxconstant, TaggedString *); |
81 | /* pre-register mem error messages, to avoid loop when error arises */ | 80 | /* pre-register mem error messages, to avoid loop when error arises */ |
82 | for (i=0; i<NUMERRMSG; i++) | 81 | luaI_findconstantbyname(tableEM); |
83 | luaI_findconstantbyname(luaI_memerrormsg[i]); | 82 | luaI_findconstantbyname(memEM); |
84 | } | 83 | } |
85 | 84 | ||
86 | 85 | ||