[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua bug - loadfile gets stdin confused
- From: "David Burgess" <dburgess@...>
- Date: Tue, 17 Apr 2007 14:12:06 +1000
if closing stdin/stderr/stdout I would have thought the friendly
thing to do would be to assign it to NULL,
This solves the problem on many systems.
On 4/17/07, David Manura <firstname.lastname@example.org> wrote:
The following code demonstrates what seems to be a bug in Lua 5.1.2. It affects
at least Win32.
io.input():close() -- breaks it
--io.input(io.open("NUL")) -- unbreaks it
loadfile("1.lua") -- does not close file!
-- culprit in lauxlib.c:luaL_loadfile:
-- if (lf.f != stdin) fclose(lf.f);
collectgarbage() -- no help
-- file 1.lua is locked here on win32!
-- (e.g. can't save in Wordpad (write.exe))
os.execute("notepad") -- pause to allow user to test above
If you close io.input() and open another file (not even used as io.input), then
loadfile() will not properly close the file it opens. The problem it seems is
the file opened == stdin.
Here's a related example in C:
FILE * f;
f = fopen("tmp1", "w");
if (f == stdin) printf("same\n"); /* prints "same" */
On Win32 (both VC2005 and GCC), this prints "same", and lhf reports it also does
so on macosx. On at least two Linux systems with GCC it prints nothing.
There might be other places in the Lua code affected by similar issues (where
stdin, stdout, and stderr are used).