aboutsummaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
commit2b5bc5d1a81579a76c13e638de2592e2c39c73f0 (patch)
tree8294278f9fbd2565d3a2cd11642fed41982824bd /table.c
parent94686ce58554a80374eeff115ee5b87c184ed173 (diff)
downloadlua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.gz
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.bz2
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.zip
new module for memory allocation
Diffstat (limited to 'table.c')
-rw-r--r--table.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/table.c b/table.c
index d37b7b03..e52fcd4a 100644
--- a/table.c
+++ b/table.c
@@ -3,11 +3,11 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.17 1994/11/14 21:40:14 roberto Exp $"; 6char *rcs_table="$Id: table.c,v 2.18 1994/11/16 16:03:48 roberto Exp roberto $";
7 7
8#include <stdlib.h>
9#include <string.h> 8#include <string.h>
10 9
10#include "mem.h"
11#include "opcode.h" 11#include "opcode.h"
12#include "tree.h" 12#include "tree.h"
13#include "hash.h" 13#include "hash.h"
@@ -16,7 +16,6 @@ char *rcs_table="$Id: table.c,v 2.17 1994/11/14 21:40:14 roberto Exp $";
16#include "lua.h" 16#include "lua.h"
17#include "fallback.h" 17#include "fallback.h"
18 18
19#define streq(s1,s2) (s1[0]==s2[0]&&strcmp(s1+1,s2+1)==0)
20 19
21#define BUFFER_BLOCK 256 20#define BUFFER_BLOCK 256
22 21
@@ -50,9 +49,7 @@ static void lua_initsymbol (void)
50{ 49{
51 int n; 50 int n;
52 lua_maxsymbol = BUFFER_BLOCK; 51 lua_maxsymbol = BUFFER_BLOCK;
53 lua_table = (Symbol *) calloc(lua_maxsymbol, sizeof(Symbol)); 52 lua_table = newvector(lua_maxsymbol, Symbol);
54 if (lua_table == NULL)
55 lua_error ("symbol table: not enough memory");
56 n = luaI_findsymbolbyname("next"); 53 n = luaI_findsymbolbyname("next");
57 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; 54 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next;
58 n = luaI_findsymbolbyname("nextvar"); 55 n = luaI_findsymbolbyname("nextvar");
@@ -80,9 +77,7 @@ static void lua_initsymbol (void)
80void lua_initconstant (void) 77void lua_initconstant (void)
81{ 78{
82 lua_maxconstant = BUFFER_BLOCK; 79 lua_maxconstant = BUFFER_BLOCK;
83 lua_constant = (char **) calloc(lua_maxconstant, sizeof(char *)); 80 lua_constant = newvector(lua_maxconstant, char *);
84 if (lua_constant == NULL)
85 lua_error ("constant table: not enough memory");
86} 81}
87 82
88 83
@@ -102,9 +97,7 @@ int luaI_findsymbol (TreeNode *t)
102 lua_maxsymbol *= 2; 97 lua_maxsymbol *= 2;
103 if (lua_maxsymbol > MAX_WORD) 98 if (lua_maxsymbol > MAX_WORD)
104 lua_error("symbol table overflow"); 99 lua_error("symbol table overflow");
105 lua_table = (Symbol *)realloc(lua_table, lua_maxsymbol*sizeof(Symbol)); 100 lua_table = growvector(lua_table, lua_maxsymbol, Symbol);
106 if (lua_table == NULL)
107 lua_error ("symbol table: not enough memory");
108 } 101 }
109 t->varindex = lua_ntable; 102 t->varindex = lua_ntable;
110 s_tag(lua_ntable) = LUA_T_NIL; 103 s_tag(lua_ntable) = LUA_T_NIL;
@@ -136,9 +129,7 @@ int luaI_findconstant (TreeNode *t)
136 lua_maxconstant *= 2; 129 lua_maxconstant *= 2;
137 if (lua_maxconstant > MAX_WORD) 130 if (lua_maxconstant > MAX_WORD)
138 lua_error("constant table overflow"); 131 lua_error("constant table overflow");
139 lua_constant = (char**)realloc(lua_constant,lua_maxconstant*sizeof(char*)); 132 lua_constant = growvector(lua_constant, lua_maxconstant, char*);
140 if (lua_constant == NULL)
141 lua_error ("constant table: not enough memory");
142 } 133 }
143 t->constindex = lua_nconstant; 134 t->constindex = lua_nconstant;
144 lua_constant[lua_nconstant] = t->str; 135 lua_constant[lua_nconstant] = t->str;
@@ -202,7 +193,6 @@ void lua_pack (void)
202char *lua_createstring (char *s) 193char *lua_createstring (char *s)
203{ 194{
204 if (s == NULL) return NULL; 195 if (s == NULL) return NULL;
205
206 return lua_strcreate(s); 196 return lua_strcreate(s);
207} 197}
208 198
@@ -226,7 +216,7 @@ char *lua_addfile (char *fn)
226*/ 216*/
227int lua_delfile (void) 217int lua_delfile (void)
228{ 218{
229 free(lua_file[--lua_nfile]); 219 luaI_free(lua_file[--lua_nfile]);
230 return 1; 220 return 1;
231} 221}
232 222