From 2fc6b55dae7a120b4272ca0e9c356d1f96053bd9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 31 Oct 2018 16:25:29 -0300 Subject: Removed resource-related "emergency collections" New to-be-closed variables is a better way to ensure the proper release of resources. --- liolib.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'liolib.c') diff --git a/liolib.c b/liolib.c index 5881b029..b2a2fec8 100644 --- a/liolib.c +++ b/liolib.c @@ -246,22 +246,9 @@ static LStream *newfile (lua_State *L) { } -/* -** Equivalent to 'fopen', but if it fails due to a lack of resources -** (see 'luaL_resourcetryagain'), do an "emergency" garbage collection -** to try to close some files and then tries to open the file again. -*/ -static FILE *trytoopen (lua_State *L, const char *path, const char *mode) { - FILE *f = fopen(path, mode); - if (f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ - f = fopen(path, mode); /* try to open again */ - return f; -} - - static void opencheck (lua_State *L, const char *fname, const char *mode) { LStream *p = newfile(L); - p->f = trytoopen(L, fname, mode); + p->f = fopen(fname, mode); if (p->f == NULL) luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); } @@ -273,7 +260,7 @@ static int io_open (lua_State *L) { LStream *p = newfile(L); const char *md = mode; /* to traverse/check mode */ luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); - p->f = trytoopen(L, filename, mode); + p->f = fopen(filename, mode); return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; } @@ -292,8 +279,6 @@ static int io_popen (lua_State *L) { const char *mode = luaL_optstring(L, 2, "r"); LStream *p = newprefile(L); p->f = l_popen(L, filename, mode); - if (p->f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ - p->f = l_popen(L, filename, mode); /* try to open again */ p->closef = &io_pclose; return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; } @@ -302,8 +287,6 @@ static int io_popen (lua_State *L) { static int io_tmpfile (lua_State *L) { LStream *p = newfile(L); p->f = tmpfile(); - if (p->f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ - p->f = tmpfile(); /* try to open again */ return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; } -- cgit v1.2.3-55-g6feb