aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-08 15:28:25 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-08 15:28:25 -0200
commite663a24ab03a54fa221c20a793812e5c5ffdf94f (patch)
tree8fbd40f779f0eed29d46f26c07e1234fd5df8bae /lgc.c
parent40f823ec907fd725617e37199199b3ed424bd88c (diff)
downloadlua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.gz
lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.bz2
lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.zip
more freedom in handling memory-allocation errors (not all allocations
automatically raise an error), which allows fixing a bug when resizing a table.
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/lgc.c b/lgc.c
index f893e122..8d28d3bf 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.240 2017/11/30 15:37:16 roberto Exp roberto $ 2** $Id: lgc.c,v 2.241 2017/12/01 17:38:49 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -816,18 +816,13 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p) {
816*/ 816*/
817 817
818/* 818/*
819** If possible, shrink string table (protected from memory errors). 819** If possible, shrink string table.
820*/ 820*/
821static void shrinkstrtable (lua_State *L, void *ud) {
822 luaS_resize(L, *cast(int*, ud) / 2);
823}
824
825
826static void checkSizes (lua_State *L, global_State *g) { 821static void checkSizes (lua_State *L, global_State *g) {
827 if (!g->gcemergency) { 822 if (!g->gcemergency) {
828 l_mem olddebt = g->GCdebt; 823 l_mem olddebt = g->GCdebt;
829 if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ 824 if (g->strt.nuse < g->strt.size / 4) /* string table too big? */
830 luaD_rawrunprotected(L, &shrinkstrtable, &g->strt.size); 825 luaS_resize(L, g->strt.size / 2);
831 g->GCestimate += g->GCdebt - olddebt; /* correct estimate */ 826 g->GCestimate += g->GCdebt - olddebt; /* correct estimate */
832 } 827 }
833} 828}