diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-31 16:25:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-31 16:25:29 -0300 |
commit | 2fc6b55dae7a120b4272ca0e9c356d1f96053bd9 (patch) | |
tree | 073360734518f75a4f5621d87a4b47bc4642452a /liolib.c | |
parent | 947a372f5860a76fcafb4a2845abc322e440d6fc (diff) | |
download | lua-2fc6b55dae7a120b4272ca0e9c356d1f96053bd9.tar.gz lua-2fc6b55dae7a120b4272ca0e9c356d1f96053bd9.tar.bz2 lua-2fc6b55dae7a120b4272ca0e9c356d1f96053bd9.zip |
Removed resource-related "emergency collections"
New to-be-closed variables is a better way to ensure the proper release
of resources.
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 21 |
1 files changed, 2 insertions, 19 deletions
@@ -246,22 +246,9 @@ static LStream *newfile (lua_State *L) { | |||
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
249 | /* | ||
250 | ** Equivalent to 'fopen', but if it fails due to a lack of resources | ||
251 | ** (see 'luaL_resourcetryagain'), do an "emergency" garbage collection | ||
252 | ** to try to close some files and then tries to open the file again. | ||
253 | */ | ||
254 | static FILE *trytoopen (lua_State *L, const char *path, const char *mode) { | ||
255 | FILE *f = fopen(path, mode); | ||
256 | if (f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ | ||
257 | f = fopen(path, mode); /* try to open again */ | ||
258 | return f; | ||
259 | } | ||
260 | |||
261 | |||
262 | static void opencheck (lua_State *L, const char *fname, const char *mode) { | 249 | static void opencheck (lua_State *L, const char *fname, const char *mode) { |
263 | LStream *p = newfile(L); | 250 | LStream *p = newfile(L); |
264 | p->f = trytoopen(L, fname, mode); | 251 | p->f = fopen(fname, mode); |
265 | if (p->f == NULL) | 252 | if (p->f == NULL) |
266 | luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); | 253 | luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); |
267 | } | 254 | } |
@@ -273,7 +260,7 @@ static int io_open (lua_State *L) { | |||
273 | LStream *p = newfile(L); | 260 | LStream *p = newfile(L); |
274 | const char *md = mode; /* to traverse/check mode */ | 261 | const char *md = mode; /* to traverse/check mode */ |
275 | luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); | 262 | luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); |
276 | p->f = trytoopen(L, filename, mode); | 263 | p->f = fopen(filename, mode); |
277 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; | 264 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |
278 | } | 265 | } |
279 | 266 | ||
@@ -292,8 +279,6 @@ static int io_popen (lua_State *L) { | |||
292 | const char *mode = luaL_optstring(L, 2, "r"); | 279 | const char *mode = luaL_optstring(L, 2, "r"); |
293 | LStream *p = newprefile(L); | 280 | LStream *p = newprefile(L); |
294 | p->f = l_popen(L, filename, mode); | 281 | p->f = l_popen(L, filename, mode); |
295 | if (p->f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ | ||
296 | p->f = l_popen(L, filename, mode); /* try to open again */ | ||
297 | p->closef = &io_pclose; | 282 | p->closef = &io_pclose; |
298 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; | 283 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |
299 | } | 284 | } |
@@ -302,8 +287,6 @@ static int io_popen (lua_State *L) { | |||
302 | static int io_tmpfile (lua_State *L) { | 287 | static int io_tmpfile (lua_State *L) { |
303 | LStream *p = newfile(L); | 288 | LStream *p = newfile(L); |
304 | p->f = tmpfile(); | 289 | p->f = tmpfile(); |
305 | if (p->f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ | ||
306 | p->f = tmpfile(); /* try to open again */ | ||
307 | return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; | 290 | return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; |
308 | } | 291 | } |
309 | 292 | ||