diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-20 19:20:36 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-20 19:20:36 -0200 |
| commit | 8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490 (patch) | |
| tree | 13d09f704662cafa2597e77c92611b468e4741c9 /table.c | |
| parent | fe8338335dfb4bf37e6b164cb55bfcc94ec6563d (diff) | |
| download | lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.tar.gz lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.tar.bz2 lua-8cb8594a3bcfdc1447aebfcd0ac85db9af5ca490.zip | |
better control of integer types and their limits
Diffstat (limited to 'table.c')
| -rw-r--r-- | table.c | 31 |
1 files changed, 16 insertions, 15 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.23 1994/11/23 14:31:11 roberto Stab roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.24 1994/12/16 15:55:04 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| @@ -17,8 +17,6 @@ char *rcs_table="$Id: table.c,v 2.23 1994/11/23 14:31:11 roberto Stab roberto $" | |||
| 17 | #include "fallback.h" | 17 | #include "fallback.h" |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define MAX_WORD 0xFFFD | ||
| 21 | |||
| 22 | #define BUFFER_BLOCK 256 | 20 | #define BUFFER_BLOCK 256 |
| 23 | 21 | ||
| 24 | Symbol *lua_table; | 22 | Symbol *lua_table; |
| @@ -47,7 +45,7 @@ static void getglobal (void); | |||
| 47 | */ | 45 | */ |
| 48 | static void lua_initsymbol (void) | 46 | static void lua_initsymbol (void) |
| 49 | { | 47 | { |
| 50 | int n; | 48 | Word n; |
| 51 | lua_maxsymbol = BUFFER_BLOCK; | 49 | lua_maxsymbol = BUFFER_BLOCK; |
| 52 | lua_table = newvector(lua_maxsymbol, Symbol); | 50 | lua_table = newvector(lua_maxsymbol, Symbol); |
| 53 | n = luaI_findsymbolbyname("next"); | 51 | n = luaI_findsymbolbyname("next"); |
| @@ -88,9 +86,8 @@ void lua_initconstant (void) | |||
| 88 | /* | 86 | /* |
| 89 | ** Given a name, search it at symbol table and return its index. If not | 87 | ** Given a name, search it at symbol table and return its index. If not |
| 90 | ** found, allocate it. | 88 | ** found, allocate it. |
| 91 | ** On error, return -1. | ||
| 92 | */ | 89 | */ |
| 93 | int luaI_findsymbol (TreeNode *t) | 90 | Word luaI_findsymbol (TreeNode *t) |
| 94 | { | 91 | { |
| 95 | if (lua_table == NULL) | 92 | if (lua_table == NULL) |
| 96 | lua_initsymbol(); | 93 | lua_initsymbol(); |
| @@ -98,9 +95,11 @@ int luaI_findsymbol (TreeNode *t) | |||
| 98 | { | 95 | { |
| 99 | if (lua_ntable == lua_maxsymbol) | 96 | if (lua_ntable == lua_maxsymbol) |
| 100 | { | 97 | { |
| 101 | lua_maxsymbol *= 2; | 98 | if (lua_maxsymbol >= MAX_WORD) |
| 102 | if (lua_maxsymbol > MAX_WORD) | ||
| 103 | lua_error("symbol table overflow"); | 99 | lua_error("symbol table overflow"); |
| 100 | lua_maxsymbol *= 2; | ||
| 101 | if (lua_maxsymbol >= MAX_WORD) | ||
| 102 | lua_maxsymbol = MAX_WORD; | ||
| 104 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); | 103 | lua_table = growvector(lua_table, lua_maxsymbol, Symbol); |
| 105 | } | 104 | } |
| 106 | t->varindex = lua_ntable; | 105 | t->varindex = lua_ntable; |
| @@ -111,7 +110,7 @@ int luaI_findsymbol (TreeNode *t) | |||
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | int luaI_findsymbolbyname (char *name) | 113 | Word luaI_findsymbolbyname (char *name) |
| 115 | { | 114 | { |
| 116 | return luaI_findsymbol(lua_constcreate(name)); | 115 | return luaI_findsymbol(lua_constcreate(name)); |
| 117 | } | 116 | } |
| @@ -122,7 +121,7 @@ int luaI_findsymbolbyname (char *name) | |||
| 122 | ** found, allocate it. | 121 | ** found, allocate it. |
| 123 | ** On error, return -1. | 122 | ** On error, return -1. |
| 124 | */ | 123 | */ |
| 125 | int luaI_findconstant (TreeNode *t) | 124 | Word luaI_findconstant (TreeNode *t) |
| 126 | { | 125 | { |
| 127 | if (lua_constant == NULL) | 126 | if (lua_constant == NULL) |
| 128 | lua_initconstant(); | 127 | lua_initconstant(); |
| @@ -130,9 +129,11 @@ int luaI_findconstant (TreeNode *t) | |||
| 130 | { | 129 | { |
| 131 | if (lua_nconstant == lua_maxconstant) | 130 | if (lua_nconstant == lua_maxconstant) |
| 132 | { | 131 | { |
| 133 | lua_maxconstant *= 2; | 132 | if (lua_maxconstant >= MAX_WORD) |
| 134 | if (lua_maxconstant > MAX_WORD) | ||
| 135 | lua_error("constant table overflow"); | 133 | lua_error("constant table overflow"); |
| 134 | lua_maxconstant *= 2; | ||
| 135 | if (lua_maxconstant >= MAX_WORD) | ||
| 136 | lua_maxconstant = MAX_WORD; | ||
| 136 | lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); | 137 | lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *); |
| 137 | } | 138 | } |
| 138 | t->constindex = lua_nconstant; | 139 | t->constindex = lua_nconstant; |
| @@ -172,9 +173,9 @@ void lua_markobject (Object *o) | |||
| 172 | */ | 173 | */ |
| 173 | void lua_pack (void) | 174 | void lua_pack (void) |
| 174 | { | 175 | { |
| 175 | static int block = GARBAGE_BLOCK; /* when garbage collector will be called */ | 176 | static Word block = GARBAGE_BLOCK; /* when garbage collector will be called */ |
| 176 | static int nentity = 0; /* counter of new entities (strings and arrays) */ | 177 | static Word nentity = 0; /* counter of new entities (strings and arrays) */ |
| 177 | int recovered = 0; | 178 | Word recovered = 0; |
| 178 | if (nentity++ < block) return; | 179 | if (nentity++ < block) return; |
| 179 | lua_travstack(lua_markobject); /* mark stack objects */ | 180 | lua_travstack(lua_markobject); /* mark stack objects */ |
| 180 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ | 181 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
