develooper Front page | perl.perl5.porters | Postings from March 2008

[perl #51408] prototypes sneakily break :lvalue subs

Thread Next
l . mai @ web . de
March 4, 2008 09:03
[perl #51408] prototypes sneakily break :lvalue subs
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #51408]
# 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.35 running under perl v5.10.0.

[Please enter your report here]


First, an unrelated (but unexpected, to me) observation:
Function return values don't have the read-only bit set, so ...

  sub f { 42 }
  sub g { $_[0] = 1 }

... compiles and runs just fine, with no visible effect.

My real problem is related to lvalue subroutines and prototypes.
Consider the following code:

  sub f :lvalue { $_ }

With this, I'd expect to be able to use f() anywhere I can use $_,
modulo weird things like indirect object syntax. But code like ...

  my $ref = \f();
  $$ref = 1;

... works and sets $_ to 1. Let's combine this with pass-by-alias:

  sub f :lvalue { $_ }
  sub g { $_[0] = 1 }

This code binds g's $_[0] to $_ and sets $_ to 1, as expected.

  sub f :lvalue { $_ }
  sub g ($) { $_[0] = 1 }

This code does nothing. The ($) prototype on g causes $_ to be
passed by (temporary) value, and (per our initial observation)
this kind of thing silently fails. g($_) works as expected, though,
so there's something weird going on.
Apparently the perl compiler simply inserts scalar()s in calls to
g. This works fine for simple variables but breaks lvalue subs.


  ${\$_} = 1;   # ok
  ${\f()} = 1;  # ok

  ${\scalar($_)} = 1;  # ok
  ${\scalar f()} = 1;  # no effect

I think the inconsistency in the last case is a bug in how lvalue
subs work.

[Please do not change anything below this line]
This perlbug was built using Perl v5.8.8 - Wed Mar 22 20:53:12 CET 2006
It is being executed now by  Perl v5.10.0 - Wed Dec 19 19:01:35 CET 2007.

Site configuration information for perl v5.10.0:

Configured by mauke at Wed Dec 19 19:01:35 CET 2007.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
    osname=linux, osvers=2.6.22-gentoo-r9, archname=i686-linux
    uname='linux nora 2.6.22-gentoo-r9 #3 preempt sat nov 3 22:12:09 cet 2007 i686 amd athlon(tm) 64 processor 3200+ authenticamd gnulinux '
    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='gcc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -march=native -fomit-frame-pointer',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='4.2.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', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -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 -march=native -fomit-frame-pointer -L/usr/local/lib'

Locally applied patches:
    SAFEARGV0 - disable magic open in <ARGV>
    METHQUAL0 - allow qualified method calls without a valid object
    UNWARN0 - disable stupid warnings for print and qw

@INC for perl v5.10.0:

Environment for perl v5.10.0:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About