develooper Front page | perl.perl5.porters | Postings from June 2010

[perl #75780] PerlIO::via calls the CLOSE callback too late

Eric Brine
June 16, 2010 02:03
[perl #75780] PerlIO::via calls the CLOSE callback too late
Message ID:
# New Ticket Created by  "Eric Brine" 
# Please include the string:  [perl #75780]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.12.0.

[Please describe your issue here]

PerlIO::via calls the CLOSE callback too late.

Say you have a handle with the following PerlIO layers:

    - utf8
    - encoding(UTF-8)
    - via(Mine)
    - perlio
    - unix

The close callbacks are called in this order:

    1 utf8
    2 encoding(UTF-8)
    3 via
    4 perlio
    5 unix
    6 Mine   <-- !!

This limits what PerlIO::via::Mine::CLOSE can do. For example,
PerlIO-via-EscStatus wants to write something to the handle as it is being
closed, but can't.

The close functions should be called in this order:

    1 utf8
    2 encoding(UTF-8)
    3 via
    4 Mine   <--
    5 perlio
    6 unix

There are 32 PerlIO::via modules on CPAN. 27 don't define a CLOSE handler.
What follows is a breakdown of the others:

PerlIO-via-SeqIO has a buggy CLOSE, no matter when it's called. (Calls
close() on the handle being closed.)
PerlIO-via-gzip has a buggy CLOSE, no matter when it's called. (Calls
close() on the handle being closed.)

PerlIO-via-ToFirePHP doesn't care when its CLOSE is called.
PerlIO-via-symlink doesn't care when its CLOSE is called.

PerlIO-via-EscStatus wants to write to the handle when it's being closed,
but it can't with the current behaviour.

 PerlIOVia_close(pTHX_ PerlIO * f)
     PerlIOVia *s = PerlIOSelf(f, PerlIOVia);
-    IV code = PerlIOBase_close(aTHX_ f);
     SV *result =
         PerlIOVia_method(aTHX_ f, MYMethod(CLOSE), G_SCALAR, Nullsv);
+    IV code = PerlIOBase_close(aTHX_ f);
     if (result && SvIV(result) != 0)
         code = SvIV(result);
     PerlIOBase(f)->flags &= ~(PERLIO_F_RDBUF | PERLIO_F_WRBUF);
     return code;

[Please do not change anything below this line]
Site configuration information for perl 5.12.0:

Configured by eric at Tue May  4 17:51:08 EDT 2010.

Summary of my perl5 (revision 5 version 12 subversion 0) configuration:

    osname=linux, osvers=2.6.26-2-686, archname=i686-linux
    uname='linux fmdev10 2.6.26-2-686 #1 smp tue mar 9 17:35:51 utc 2010
i686 gnulinux '
    config_args='-de -Dprefix=/home/eric/usr/perlbrew/perls/perl-5.12.0'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib

Locally applied patches:

@INC for perl 5.12.0:


Environment for perl 5.12.0:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About