Added "emergency collection" to 'io.tmpfile' and 'os.tmpname'

These operations also can give errors for lack of resources, so they
also will try "emergency collections" in case of resource errors.
Because there are now two libraries with that kind of handling,
'resourcetryagain' was moved to the auxiliary library to be shared
by the libraries.
This commit is contained in:
Roberto Ierusalimschy
2018-07-27 15:50:53 -03:00
parent aa4c5cf190
commit 3d838f635c
5 changed files with 71 additions and 50 deletions

View File

@@ -166,6 +166,8 @@ static int os_tmpname (lua_State *L) {
char buff[LUA_TMPNAMBUFSIZE];
int err;
lua_tmpnam(buff, err);
if (err && luaL_resourcetryagain(L)) /* resource failure? */
lua_tmpnam(buff, err); /* try again */
if (err)
return luaL_error(L, "unable to generate a unique filename");
lua_pushstring(L, buff);