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 /lauxlib.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 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 43 |
1 files changed, 0 insertions, 43 deletions
@@ -290,49 +290,6 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { | |||
290 | /* }====================================================== */ | 290 | /* }====================================================== */ |
291 | 291 | ||
292 | 292 | ||
293 | /* | ||
294 | ** {====================================================== | ||
295 | ** 'luaL_resourcetryagain' | ||
296 | ** This function uses 'errno' to check whether the last error was | ||
297 | ** related to lack of resources (e.g., not enough memory or too many | ||
298 | ** open files). If so, the function performs a full garbage collection | ||
299 | ** to try to release resources, and then it returns 1 to signal to | ||
300 | ** the caller that it is worth trying again the failed operation. | ||
301 | ** Otherwise, it returns 0. Because error codes are not ANSI C, the | ||
302 | ** code must handle any combination of error codes that are defined. | ||
303 | ** ======================================================= | ||
304 | */ | ||
305 | |||
306 | LUALIB_API int luaL_resourcetryagain (lua_State *L) { | ||
307 | |||
308 | /* these are the resource-related errors in Linux */ | ||
309 | #if defined(EMFILE) || defined(ENFILE) || defined(ENOMEM) | ||
310 | |||
311 | #if !defined(EMFILE) /* too many open files in the process */ | ||
312 | #define EMFILE -1 /* if not defined, use an impossible value */ | ||
313 | #endif | ||
314 | |||
315 | #if !defined(ENFILE) /* too many open files in the system */ | ||
316 | #define ENFILE -1 | ||
317 | #endif | ||
318 | |||
319 | #if !defined(ENOMEM) /* not enough memory */ | ||
320 | #define ENOMEM -1 | ||
321 | #endif | ||
322 | |||
323 | if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) { | ||
324 | lua_gc(L, LUA_GCCOLLECT); /* try to release resources with a full GC */ | ||
325 | return 1; /* signal to try again the creation */ | ||
326 | } | ||
327 | |||
328 | #endif | ||
329 | |||
330 | return 0; /* else, asume errors are not due to lack of resources */ | ||
331 | |||
332 | } | ||
333 | |||
334 | /* }====================================================== */ | ||
335 | |||
336 | 293 | ||
337 | /* | 294 | /* |
338 | ** {====================================================== | 295 | ** {====================================================== |