diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-22 12:15:13 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-22 12:15:13 -0200 |
| commit | e74b250d71c9a72758d7bb586bb906cacd8293f6 (patch) | |
| tree | bee1df3715c456e7ee1e591f0734cce34fff3195 /table.c | |
| parent | cd54c95ee179dd1578e127745354aa6a59b72eb7 (diff) | |
| download | lua-e74b250d71c9a72758d7bb586bb906cacd8293f6.tar.gz lua-e74b250d71c9a72758d7bb586bb906cacd8293f6.tar.bz2 lua-e74b250d71c9a72758d7bb586bb906cacd8293f6.zip | |
memory overflow tries a garbage collection; if it fails then exit the
program.
Diffstat (limited to 'table.c')
| -rw-r--r-- | table.c | 17 |
1 files changed, 12 insertions, 5 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.38 1995/11/03 15:30:50 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.39 1996/01/09 20:23:19 roberto Exp $"; |
| 7 | 7 | ||
| 8 | /*#include <string.h>*/ | 8 | /*#include <string.h>*/ |
| 9 | 9 | ||
| @@ -178,12 +178,9 @@ int lua_markobject (Object *o) | |||
| 178 | ** Garbage collection. | 178 | ** Garbage collection. |
| 179 | ** Delete all unused strings and arrays. | 179 | ** Delete all unused strings and arrays. |
| 180 | */ | 180 | */ |
| 181 | void lua_pack (void) | 181 | Long luaI_collectgarbage (void) |
| 182 | { | 182 | { |
| 183 | static Long block = GARBAGE_BLOCK; /* when garbage collector will be called */ | ||
| 184 | static Long nentity = 0; /* counter of new entities (strings and arrays) */ | ||
| 185 | Long recovered = 0; | 183 | Long recovered = 0; |
| 186 | if (nentity++ < block) return; | ||
| 187 | lua_travstack(lua_markobject); /* mark stack objects */ | 184 | lua_travstack(lua_markobject); /* mark stack objects */ |
| 188 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ | 185 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
| 189 | luaI_travlock(lua_markobject); /* mark locked objects */ | 186 | luaI_travlock(lua_markobject); /* mark locked objects */ |
| @@ -191,6 +188,16 @@ void lua_pack (void) | |||
| 191 | recovered += lua_strcollector(); | 188 | recovered += lua_strcollector(); |
| 192 | recovered += lua_hashcollector(); | 189 | recovered += lua_hashcollector(); |
| 193 | recovered += luaI_funccollector(); | 190 | recovered += luaI_funccollector(); |
| 191 | return recovered; | ||
| 192 | } | ||
| 193 | |||
| 194 | void lua_pack (void) | ||
| 195 | { | ||
| 196 | static Long block = GARBAGE_BLOCK; /* when garbage collector will be called */ | ||
| 197 | static Long nentity = 0; /* counter of new entities (strings and arrays) */ | ||
| 198 | Long recovered = 0; | ||
| 199 | if (nentity++ < block) return; | ||
| 200 | recovered = luaI_collectgarbage(); | ||
| 194 | nentity = 0; /* reset counter */ | 201 | nentity = 0; /* reset counter */ |
| 195 | block=(16*block-7*recovered)/12; /* adapt block size */ | 202 | block=(16*block-7*recovered)/12; /* adapt block size */ |
| 196 | if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK; | 203 | if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK; |
