more freedom in handling memory-allocation errors (not all allocations

automatically raise an error), which allows fixing a bug when resizing
a table.
This commit is contained in:
Roberto Ierusalimschy
2017-12-08 15:28:25 -02:00
parent 40f823ec90
commit e663a24ab0
8 changed files with 139 additions and 98 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.58 2017/12/01 16:40:29 roberto Exp roberto $
** $Id: lstring.c,v 2.59 2017/12/07 18:59:52 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -70,12 +70,15 @@ unsigned int luaS_hashlongstr (TString *ts) {
/*
** Resizes the string table.
** Resize the string table. If allocation fails, keep the current size.
** (This can degrade performance, but any size should work correctly.)
*/
void luaS_resize (lua_State *L, int newsize) {
int i;
TString **newhash = luaM_newvector(L, newsize, TString *);
stringtable *tb = &G(L)->strt;
if (newhash == NULL) /* allocation failed? */
return; /* leave hash as it is */
for (i = 0; i < newsize; i++) /* initialize new hash array */
newhash[i] = NULL;
for (i = 0; i < tb->size; i++) { /* rehash all elements into new array */