[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Small issue with lfs compiled under mingw
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Mon, 08 Aug 2011 16:30:38 +0200
On 28/07/2011 0.00, Lorenzo Donati wrote:
Hi all!
Some time ago I compiled lfs using mingw "by hand" (the distro came with
a makefile for VC only, so I concocted one) and put lfs.dll in my cpath
for using other libraries that required it - never had problems with it.
Lately I'm cleaning-up my (ugly) makefiles and I rewrote the one for
building lfs, enabling more warnings and performing the test script.
Now I have some issues:
1. compiling lfs.c gives some warnings.
2. running test.lua fails with an assertion.
Probably I've tracked down the problem [2] and found a solution, but I'd
like to have a feedback from more expert C folks.
First a test that fails on my system:
----------------------------------------
lfs = require 'lfs'
-- "mydir" is an existing dir with two files "a" and "b" in it.
iter, dir = assert( lfs.dir( dirname ) )
dir:close()
print( dir:next() or "<no ret val>" ) --> .
print( dir:next() or "<no ret val>" ) --> ..
print( dir:next() or "<no ret val>" ) --> a
print( dir:next() or "<no ret val>" ) --> b
print( dir:next() or "<no ret val>" ) --> <no ret val>
print( dir:next() or "<no ret val>" ) -- *** ERROR! ***
----------------------------------------
That is, the dir object can be used for iteration although it has been
closed just after creation.
Let's try with this one:
----------------------------------------
lfs = require 'lfs'
iter, dir = assert( lfs.dir( dirname ) )
print( dir:next() or "<no ret val>" ) --> .
dir:close()
print( dir:next() or "<no ret val>" ) -- *** ERROR! ***
----------------------------------------
That is, the dir object is actually invalidated as expected.
Therefore it seems that for dir:close to work it is necessary to call
dir:next at least once, which is weird.
Analyzing the source I found a possible solution (patch attached), but I
don't know if it could break something else.
With that patch applied the test.lua file of lfs distro passes without
raising any assertion.
Any comment appreciated.
TIA
-- Lorenzo
diff --git b/src/lfs.c a/src/lfs.c
index f46cfed..18255a2 100644
--- b/src/lfs.c
+++ a/src/lfs.c
@@ -455,8 +455,9 @@ static int dir_iter (lua_State *L) {
static int dir_close (lua_State *L) {
dir_data *d = (dir_data *)lua_touserdata (L, 1);
#ifdef _WIN32
- if (!d->closed && d->hFile) {
- _findclose (d->hFile);
+ if (!d->closed ) {
+ if( d->hFile )
+ _findclose (d->hFile);
d->closed = 1;
}
#else