diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-16 15:39:16 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-16 15:39:16 -0200 |
commit | 2b5bc5d1a81579a76c13e638de2592e2c39c73f0 (patch) | |
tree | 8294278f9fbd2565d3a2cd11642fed41982824bd /hash.c | |
parent | 94686ce58554a80374eeff115ee5b87c184ed173 (diff) | |
download | lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.gz lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.bz2 lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.zip |
new module for memory allocation
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 24 |
1 files changed, 6 insertions, 18 deletions
@@ -3,11 +3,9 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.15 1994/11/10 17:36:54 roberto Exp $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.16 1994/11/14 18:41:15 roberto Exp roberto $"; |
7 | |||
8 | #include <string.h> | ||
9 | #include <stdlib.h> | ||
10 | 7 | ||
8 | #include "mem.h" | ||
11 | #include "opcode.h" | 9 | #include "opcode.h" |
12 | #include "hash.h" | 10 | #include "hash.h" |
13 | #include "inout.h" | 11 | #include "inout.h" |
@@ -16,9 +14,6 @@ char *rcs_hash="$Id: hash.c,v 2.15 1994/11/10 17:36:54 roberto Exp $"; | |||
16 | 14 | ||
17 | #define streq(s1,s2) (s1 == s2 || (*(s1) == *(s2) && strcmp(s1,s2)==0)) | 15 | #define streq(s1,s2) (s1 == s2 || (*(s1) == *(s2) && strcmp(s1,s2)==0)) |
18 | 16 | ||
19 | #define new(s) ((s *)malloc(sizeof(s))) | ||
20 | #define newvector(n,s) ((s *)calloc(n,sizeof(s))) | ||
21 | |||
22 | #define nhash(t) ((t)->nhash) | 17 | #define nhash(t) ((t)->nhash) |
23 | #define nuse(t) ((t)->nuse) | 18 | #define nuse(t) ((t)->nuse) |
24 | #define markarray(t) ((t)->mark) | 19 | #define markarray(t) ((t)->mark) |
@@ -117,8 +112,6 @@ static Node *hashnodecreate (int nhash) | |||
117 | { | 112 | { |
118 | int i; | 113 | int i; |
119 | Node *v = newvector (nhash, Node); | 114 | Node *v = newvector (nhash, Node); |
120 | if (v == NULL) | ||
121 | lua_error ("not enough memory"); | ||
122 | for (i=0; i<nhash; i++) | 115 | for (i=0; i<nhash; i++) |
123 | tag(ref(&v[i])) = LUA_T_NIL; | 116 | tag(ref(&v[i])) = LUA_T_NIL; |
124 | return v; | 117 | return v; |
@@ -129,14 +122,9 @@ static Node *hashnodecreate (int nhash) | |||
129 | */ | 122 | */ |
130 | static Hash *hashcreate (int nhash) | 123 | static Hash *hashcreate (int nhash) |
131 | { | 124 | { |
132 | Hash *t = new (Hash); | 125 | Hash *t = new(Hash); |
133 | if (t == NULL) | ||
134 | lua_error ("not enough memory"); | ||
135 | nhash = redimension((int)((float)nhash/REHASH_LIMIT)); | 126 | nhash = redimension((int)((float)nhash/REHASH_LIMIT)); |
136 | |||
137 | nodevector(t) = hashnodecreate(nhash); | 127 | nodevector(t) = hashnodecreate(nhash); |
138 | if (nodevector(t) == NULL) | ||
139 | lua_error ("not enough memory"); | ||
140 | nhash(t) = nhash; | 128 | nhash(t) = nhash; |
141 | nuse(t) = 0; | 129 | nuse(t) = 0; |
142 | markarray(t) = 0; | 130 | markarray(t) = 0; |
@@ -148,8 +136,8 @@ static Hash *hashcreate (int nhash) | |||
148 | */ | 136 | */ |
149 | static void hashdelete (Hash *t) | 137 | static void hashdelete (Hash *t) |
150 | { | 138 | { |
151 | free (nodevector(t)); | 139 | luaI_free (nodevector(t)); |
152 | free(t); | 140 | luaI_free(t); |
153 | } | 141 | } |
154 | 142 | ||
155 | 143 | ||
@@ -253,7 +241,7 @@ static void rehash (Hash *t) | |||
253 | if (tag(ref(n)) != LUA_T_NIL && tag(val(n)) != LUA_T_NIL) | 241 | if (tag(ref(n)) != LUA_T_NIL && tag(val(n)) != LUA_T_NIL) |
254 | *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */ | 242 | *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */ |
255 | } | 243 | } |
256 | free(vold); | 244 | luaI_free(vold); |
257 | } | 245 | } |
258 | 246 | ||
259 | /* | 247 | /* |