diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 18:41:37 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 18:41:37 -0200 |
commit | ff7f7694548a210cd41458538ebd4bd7bb817ddf (patch) | |
tree | 9e6a07dfa0ef7b21054f17ac44fd0bcda11a2dd5 /table.c | |
parent | 8a0521fa529ce5091877683bc6f235ff8de7185b (diff) | |
download | lua-ff7f7694548a210cd41458538ebd4bd7bb817ddf.tar.gz lua-ff7f7694548a210cd41458538ebd4bd7bb817ddf.tar.bz2 lua-ff7f7694548a210cd41458538ebd4bd7bb817ddf.zip |
small changes in error recovery
Diffstat (limited to 'table.c')
-rw-r--r-- | table.c | 55 |
1 files changed, 13 insertions, 42 deletions
@@ -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.13 1994/11/08 20:07:54 roberto Exp $"; | 6 | char *rcs_table="$Id: table.c,v 2.14 1994/11/09 18:11:47 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -50,10 +50,7 @@ static void lua_initsymbol (void) | |||
50 | lua_maxsymbol = BUFFER_BLOCK; | 50 | lua_maxsymbol = BUFFER_BLOCK; |
51 | lua_table = (Symbol *) calloc(lua_maxsymbol, sizeof(Symbol)); | 51 | lua_table = (Symbol *) calloc(lua_maxsymbol, sizeof(Symbol)); |
52 | if (lua_table == NULL) | 52 | if (lua_table == NULL) |
53 | { | 53 | lua_error ("symbol table: not enough memory"); |
54 | lua_error ("symbol table: not enough memory"); | ||
55 | return; | ||
56 | } | ||
57 | n = lua_findsymbol("next"); | 54 | n = lua_findsymbol("next"); |
58 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; | 55 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; |
59 | n = lua_findsymbol("nextvar"); | 56 | n = lua_findsymbol("nextvar"); |
@@ -98,27 +95,16 @@ int lua_findsymbol (char *s) | |||
98 | if (lua_table == NULL) | 95 | if (lua_table == NULL) |
99 | lua_initsymbol(); | 96 | lua_initsymbol(); |
100 | n = lua_varcreate(s); | 97 | n = lua_varcreate(s); |
101 | if (n == NULL) | ||
102 | { | ||
103 | lua_error ("create symbol: not enough memory"); | ||
104 | return -1; | ||
105 | } | ||
106 | if (indexstring(n) == UNMARKED_STRING) | 98 | if (indexstring(n) == UNMARKED_STRING) |
107 | { | 99 | { |
108 | if (lua_ntable == lua_maxsymbol) | 100 | if (lua_ntable == lua_maxsymbol) |
109 | { | 101 | { |
110 | lua_maxsymbol *= 2; | 102 | lua_maxsymbol *= 2; |
111 | if (lua_maxsymbol > MAX_WORD) | 103 | if (lua_maxsymbol > MAX_WORD) |
112 | { | 104 | lua_error("symbol table overflow"); |
113 | lua_error("symbol table overflow"); | ||
114 | return -1; | ||
115 | } | ||
116 | lua_table = (Symbol *)realloc(lua_table, lua_maxsymbol*sizeof(Symbol)); | 105 | lua_table = (Symbol *)realloc(lua_table, lua_maxsymbol*sizeof(Symbol)); |
117 | if (lua_table == NULL) | 106 | if (lua_table == NULL) |
118 | { | 107 | lua_error ("symbol table: not enough memory"); |
119 | lua_error ("symbol table: not enough memory"); | ||
120 | return -1; | ||
121 | } | ||
122 | } | 108 | } |
123 | indexstring(n) = lua_ntable; | 109 | indexstring(n) = lua_ntable; |
124 | s_tag(lua_ntable) = LUA_T_NIL; | 110 | s_tag(lua_ntable) = LUA_T_NIL; |
@@ -139,27 +125,16 @@ int lua_findconstant (char *s) | |||
139 | if (lua_constant == NULL) | 125 | if (lua_constant == NULL) |
140 | lua_initconstant(); | 126 | lua_initconstant(); |
141 | n = lua_constcreate(s); | 127 | n = lua_constcreate(s); |
142 | if (n == NULL) | ||
143 | { | ||
144 | lua_error ("create constant: not enough memory"); | ||
145 | return -1; | ||
146 | } | ||
147 | if (indexstring(n) == UNMARKED_STRING) | 128 | if (indexstring(n) == UNMARKED_STRING) |
148 | { | 129 | { |
149 | if (lua_nconstant == lua_maxconstant) | 130 | if (lua_nconstant == lua_maxconstant) |
150 | { | 131 | { |
151 | lua_maxconstant *= 2; | 132 | lua_maxconstant *= 2; |
152 | if (lua_maxconstant > MAX_WORD) | 133 | if (lua_maxconstant > MAX_WORD) |
153 | { | 134 | lua_error("constant table overflow"); |
154 | lua_error("constant table overflow"); | ||
155 | return -1; | ||
156 | } | ||
157 | lua_constant = (char**)realloc(lua_constant,lua_maxconstant*sizeof(char*)); | 135 | lua_constant = (char**)realloc(lua_constant,lua_maxconstant*sizeof(char*)); |
158 | if (lua_constant == NULL) | 136 | if (lua_constant == NULL) |
159 | { | 137 | lua_error ("constant table: not enough memory"); |
160 | lua_error ("constant table: not enough memory"); | ||
161 | return -1; | ||
162 | } | ||
163 | } | 138 | } |
164 | indexstring(n) = lua_nconstant; | 139 | indexstring(n) = lua_nconstant; |
165 | lua_constant[lua_nconstant] = n; | 140 | lua_constant[lua_nconstant] = n; |
@@ -267,22 +242,18 @@ void lua_nextvar (void) | |||
267 | char *varname, *next; | 242 | char *varname, *next; |
268 | lua_Object o = lua_getparam(1); | 243 | lua_Object o = lua_getparam(1); |
269 | if (o == 0) | 244 | if (o == 0) |
270 | { lua_error ("too few arguments to function `nextvar'"); return; } | 245 | lua_error ("too few arguments to function `nextvar'"); |
271 | if (lua_getparam(2) != NULL) | 246 | if (lua_getparam(2) != NULL) |
272 | { lua_error ("too many arguments to function `nextvar'"); return; } | 247 | lua_error ("too many arguments to function `nextvar'"); |
273 | if (lua_isnil(o)) | 248 | if (lua_isnil(o)) |
274 | { | 249 | varname = NULL; |
275 | varname = NULL; | ||
276 | } | ||
277 | else if (!lua_isstring(o)) | 250 | else if (!lua_isstring(o)) |
278 | { | ||
279 | lua_error ("incorrect argument to function `nextvar'"); | ||
280 | return; | ||
281 | } | ||
282 | else | ||
283 | { | 251 | { |
284 | varname = lua_getstring(o); | 252 | lua_error ("incorrect argument to function `nextvar'"); |
253 | return; /* to avoid warnings */ | ||
285 | } | 254 | } |
255 | else | ||
256 | varname = lua_getstring(o); | ||
286 | next = lua_varnext(varname); | 257 | next = lua_varnext(varname); |
287 | if (next == NULL) | 258 | if (next == NULL) |
288 | { | 259 | { |