Steve Hay wrote: > Jarkko Hietaniemi wrote: >>> refcnt_dec: fd 4: 0 <= 0 >>> >>> I'm guessing that the file was opened (inc refcnt to 1), then closed >>> (dec refcnt to 0) and then some attempt was made within PerlIO to >>> close it again (triggering the croak)? >> >> That would make it, yes. Maybe fire up a debugger and set a breakpoint >> to the croak() in PerlIOUnix_refcnt_dec()? Compare the stack trace with >> the one if coming from a (Perl-level) close()? > > Here's the call stack at the point where my test.pl croaks: > > > perl59.dll!PerlIOUnix_refcnt_dec(int fd=3) Line 2355 C > perl59.dll!PerlIOStdio_close(interpreter * my_perl=0x00254224, > _PerlIO * * f=0x0025d70c) Line 3115 + 0x9 bytes C > perl59.dll!PerlIOBase_close(interpreter * my_perl=0x00254224, > _PerlIO * * f=0x01823f94) Line 2157 + 0x10 bytes C [...] > > If I change my test.pl to say > > open(*FH, '<', 'MANIFEST'); > > instead of > > fopen(*FH, 'MANIFEST', 'r'); > > then it now runs without croaking. The call stack at the equivalent > point is now this: > > > perl59.dll!PerlIOUnix_refcnt_dec(int fd=3) Line 2355 C > perl59.dll!PerlIOUnix_close(interpreter * my_perl=0x00254224, > _PerlIO * * f=0x01824334) Line 2717 + 0x9 bytes C > perl59.dll!PerlIOBase_close(interpreter * my_perl=0x00254224, > _PerlIO * * f=0x01823f94) Line 2157 + 0x10 bytes C [...] > > This is identical except that PerlIOBase_close() line 2157 calls > PerlIOUnix_close() instead of PerlIOStdio_close(). Why would this be? This might be because Foo::_fopen() set the filehandle into "binary mode" and yet the IoIFP(io) being PerlIO_close()'d contains two layers--crlf and stdio. That doesn't seem correct to me. The IoIFP(io) being PerlIO_close()'d in the open() case contains only one layer--unix. If I change my test.pl to say open(*FH, '<:stdio:crlf', 'MANIFEST'); then I get an IoIFP(io) with the same two layers as happens with the Foo::_fopen() case and now the call stack is the same, going into PerlIOStdio_close() rather than PerlIOUnix_close(). However, the program still runs OK without croaking. So that difference alone is obviously not what causes my Foo::_fopen() code to croak. -- ------------------------------------------------ Radan Computational Ltd. The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.Thread Previous | Thread Next