develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #120202] Tie::Handle appends extra copies of $\ to output

Thread Next
From:
Anno Siegel
Date:
October 13, 2013 08:02
Subject:
[perl #120202] Tie::Handle appends extra copies of $\ to output
Message ID:
rt-3.6.HEAD-26210-1381637516-989.120202-75-0@perl.org
# New Ticket Created by  Anno Siegel 
# Please include the string:  [perl #120202]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=120202 >



This is a bug report for perl from anno5@mac.com,
generated with the help of perlbug 1.39 running under perl 5.18.1.


-----------------------------------------------------------------

The following code demonstrates the problem:

    use Tie::Handle;

    my $out = do { no warnings 'once'; \ local *HANDLE };
    tie *$out, 'Tie::StdHandle', '>&', \ *STDOUT or die;

    $\ = "haha\n";
    print $out "hihi\n";

which prints

    hihi
    haha
    haha

The string in $\ has been added twice, once explicitly by
Tie::Handle::PRINT and another time implicitly by the use of
(CORE::) print in Tie::StdHandle::WRITE.

The bug also affects the use of say() with tied handles where a spurious
newline is added by the same effect.

In my understanding, WRITE should never add anything to its output,
so the fix could be simply


--- lib/Tie/StdHandle_orig.pm	2013-10-13 04:04:53.000000000 +0200
+++ lib/Tie/StdHandle.pm	2013-10-13 04:23:40.000000000 +0200
@@ -64,6 +64,7 @@ sub GETC     { getc($_[0]) }
 sub WRITE
 {
  my $fh = $_[0];
+ local $\;
  print $fh substr($_[1],0,$_[2])
 }
 
Regards, Anno
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
    module=Tie::Handle
---
Site configuration information for perl 5.18.1:

Configured by anno at Sun Oct 13 03:15:53 CEST 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration:
   
  Platform:
    osname=darwin, osvers=12.5.0, archname=darwin-multi-2level
    uname='darwin radom 12.5.0 darwin kernel version 12.5.0: sun sep 29 13:33:47 pdt 2013; root:xnu-2050.48.12~1release_x86_64 x86_64 '
    config_args='-des -Duseshrplib -Dusemultiplicity'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include',
    optimize='-O3',
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=true, libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.18.1:
    /Users/anno/lib/perl5
    /usr/local/lib/perl5/site_perl/5.18.1/darwin-multi-2level
    /usr/local/lib/perl5/site_perl/5.18.1
    /usr/local/lib/perl5/5.18.1/darwin-multi-2level
    /usr/local/lib/perl5/5.18.1
    /usr/local/lib/perl5/site_perl/5.18.0/darwin-multi-2level
    /usr/local/lib/perl5/site_perl/5.18.0
    /usr/local/lib/perl5/site_perl/5.16.1
    /usr/local/lib/perl5/site_perl/5.16.0
    /usr/local/lib/perl5/site_perl/5.14.2
    /usr/local/lib/perl5/site_perl/5.14.1
    /usr/local/lib/perl5/site_perl/5.14.0
    /usr/local/lib/perl5/site_perl/5.12.3
    /usr/local/lib/perl5/site_perl/5.12.1
    /usr/local/lib/perl5/site_perl/5.12.0
    /usr/local/lib/perl5/site_perl/5.10.1
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl 5.18.1:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/anno
    LANG=de_DE.UTF-8
    LANGUAGE (unset)
    LC_CTYPE=de_DE.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/anno/perl5/perlbrew/bin:/Users/anno/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/opt/local/bin:/opt/local/sbin:/Users/anno/bin/gmp_factorlib:/usr/local/git/bin:/usr/local/pgsql/bin
    PERL5LIB=/Users/anno/lib/perl5
    PERLBREW_BASHRC_VERSION=0.42
    PERLBREW_HOME=/Users/anno/.perlbrew
    PERLBREW_LIB=
    PERLBREW_MANPATH=
    PERLBREW_PATH=/Users/anno/perl5/perlbrew/bin
    PERLBREW_PERL=
    PERLBREW_ROOT=/Users/anno/perl5/perlbrew
    PERLBREW_VERSION=0.44
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=
    PERL_MB_OPT=
    PERL_MM_OPT=
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About