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

[perl #119927] say TIED does not localize $\ as it claims

Thread Previous
From:
Ricardo SIGNES
Date:
September 21, 2013 05:47
Subject:
[perl #119927] say TIED does not localize $\ as it claims
Message ID:
rt-3.6.HEAD-1873-1379742423-339.119927-75-0@perl.org
# New Ticket Created by  Ricardo SIGNES 
# Please include the string:  [perl #119927]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119927 >


This is a bug report for perl from rjbs@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.


-----------------------------------------------------------------
[Please describe your issue here]


According to perlfunc, say is:

  Just like "print", but implicitly appends a newline.  "say LIST" is
  simply an abbreviation for "{ local $\ = "\n"; print LIST }".

In the past, though, $\ was not updated.  This was #49264

  https://rt.perl.org/rt3/Ticket/Display.html?id=49264

It seems that the code to fix that, though, only restores $\ *if it was
defined* first.  If $\ was undef, then it remains "\n" after the say, with
irritating consequences.

Here is a demonstration:

  #!perl
  use strict;
  use warnings;
  use feature 'say';

  use Symbol;

  package TiedHandle {
    sub TIEHANDLE {
      my ($class, $arg) = @_;
      return bless {} => $class;
    }

    sub PRINT {
      my ($self, @output) = @_;
      no warnings 'uninitialized';
      printf "# inside say,  \$\\ is U+%04x\n", ord($\);
      return 1;
    }
  }

  my $fh_B = Symbol::gensym;
  tie *$fh_B, 'TiedHandle';

  print "$]\n";
  {
    no warnings 'uninitialized';
    printf "# outside say, \$\\ is U+%04x\n", ord($\);
    say   $fh_B "foo"; # do say before print to detect bug
    printf "# outside say, \$\\ is U+%04x\n", ord($\);
  }

  {
    no warnings 'uninitialized';
    $\ = "!";
    printf "# outside say, \$\\ is U+%04x\n", ord($\);
    say   $fh_B "foo"; # do say before print to detect bug
    printf "# outside say, \$\\ is U+%04x\n", ord($\);
  }

This was fixed in 5.18.0, but not on purpose, as far as I can tell, because it
was fixed by:

  commit 4bac9ae47b5ad7845a24e26b0e95609805de688a
  Author: Chip Salzenberg <chip@pobox.com>
  Date:   Fri Jun 22 15:18:18 2012 -0700

      Magic flags harmonization.

So, the question is:  do we want to backport a fix to 5.16.x?

Either way, I will add a test to t/op/tiehandle.t to assert that this behaves
correctly with an uninitialized $\.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl 5.16.3:

Configured by rjbs at Mon Mar 11 12:31:36 EDT 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
   
  Platform:
    osname=darwin, osvers=12.2.1, archname=darwin-2level
    uname='darwin walrus.local 12.2.1 darwin kernel version 12.2.1: thu oct 18 16:32:48 pdt 2012; root:xnu-2050.20.9~2release_x86_64 x86_64 '
    config_args='-de -Dprefix=/Users/rjbs/perl5/perlbrew/perls/16.3 -Aeval:scriptdir=/Users/rjbs/perl5/perlbrew/perls/16.3/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    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.57))', 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=false, libperl=libperl.a
    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.16.3:
    /Users/rjbs/.perlbrew/libs/16.3@std/lib/perl5/darwin-2level
    /Users/rjbs/.perlbrew/libs/16.3@std/lib/perl5
    /Users/rjbs/perl5/perlbrew/perls/16.3/lib/site_perl/5.16.3/darwin-2level
    /Users/rjbs/perl5/perlbrew/perls/16.3/lib/site_perl/5.16.3
    /Users/rjbs/perl5/perlbrew/perls/16.3/lib/5.16.3/darwin-2level
    /Users/rjbs/perl5/perlbrew/perls/16.3/lib/5.16.3
    .

---
Environment for perl 5.16.3:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/rjbs
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/rjbs/.perlbrew/libs/16.3@std/bin:/Users/rjbs/perl5/perlbrew/bin:/Users/rjbs/perl5/perlbrew/perls/16.3/bin:/Users/rjbs/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/rjbs/code/hla
    PERL5LIB=/Users/rjbs/.perlbrew/libs/16.3@std/lib/perl5
    PERLBREW_BASHRC_VERSION=0.63
    PERLBREW_HOME=/Users/rjbs/.perlbrew
    PERLBREW_LIB=std
    PERLBREW_MANPATH=/Users/rjbs/.perlbrew/libs/16.3@std/man:/Users/rjbs/perl5/perlbrew/perls/16.3/man
    PERLBREW_PATH=/Users/rjbs/.perlbrew/libs/16.3@std/bin:/Users/rjbs/perl5/perlbrew/bin:/Users/rjbs/perl5/perlbrew/perls/16.3/bin
    PERLBREW_PERL=16.3
    PERLBREW_ROOT=/Users/rjbs/perl5/perlbrew
    PERLBREW_VERSION=0.63
    PERLDOC=-n/opt/local/bin/groff
    PERL_AUTOINSTALL=--skipdeps
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=/Users/rjbs/.perlbrew/libs/16.3@std
    PERL_MAILERS=sendmail:/Users/rjbs/bin/sendmail
    PERL_MB_OPT=--install_base /Users/rjbs/.perlbrew/libs/16.3@std
    PERL_MM_OPT=INSTALL_BASE=/Users/rjbs/.perlbrew/libs/16.3@std
    SHELL=/opt/local/bin/zsh


Thread Previous


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