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

[perl #77362] Assigning glob to lvalue causes stringification

Thread Next
Father Chrysostomos
August 22, 2010 12:24
[perl #77362] Assigning glob to lvalue causes stringification
Message ID:
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #77362]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This doesn’t work:

sub{ $_[0] = *_:: }->($a{b});
use Devel::Peek;
Dump $a{b};
$a{b} = *_::;
Dump $a{b}

It 5.8.x and earlier, the $_[0] assignment caused an error. (Can't upgrade....)

In 5.10.0 and later, the glob is stringified and assigned to $a{b}.

I was poring over sv_setsv_flags, and read it six times trying to understand it, until I realised it didn’t make sense to me because it was buggy. I still don’t understand it well enough to fix this.

Take this bit, for instance:
    case SVt_PVGV:
	if (isGV_with_GP(sstr) && dtype <= SVt_PVGV) {
	    glob_assign_glob(dstr, sstr, dtype);

Should that SVt_PVGV be changed to SVt_PVLV, or would that have strange side-effects? (This same logic occurs in several other places in the same function.)

And this bit, a little lower:
	if (stype == SVt_PVLV)
	    SvUPGRADE(dstr, SVt_PVNV);
	    SvUPGRADE(dstr, (svtype)stype);

Why would an SVt_PVLV require the LHS to be SVt_PVNV and not something else?

Near the bottom:
	if (isGV_with_GP(sstr)) {
	    /* This stringification rule for globs is spread in 3 places.
	       This feels bad. FIXME.  */
	    const U32 wasfake = sflags & SVf_FAKE;

	    /* FAKE globs can get coerced, so need to turn this off
	       temporarily if it is on.  */
	    gv_efullname3(dstr, MUTABLE_GV(sstr), "*");
	    SvFLAGS(sstr) |= wasfake;

When is a glob ever supposed to be stringified when assigned to something? If I’m reading the code correctly, this is only reached when a glob is assigned to an SVt_PVLV (which causes this bug) or an SVt_PVIO (how can that ever happen?). Is this code really supposed to be reached?

A note to anyone fixing this: When this is fixed, if the lvalue points to a stash element whose names ends with :: then the assignment may necessitate a call to MRO_INVALIDATE_ISA, mro_package_moved, or whatever it ends up being called. My first patch for bug #75176 (which is unfinished) will add that macro or function.

This perlbug was built using Perl 5.10.1 - Thu Sep 24 18:07:44 PDT 2009
It is being executed now by  Perl 5.13.2 - Tue Jun 22 20:22:10 PDT 2010.

Site configuration information for perl 5.13.2:

Configured by sprout at Tue Jun 22 20:22:10 PDT 2010.

Summary of my perl5 (revision 5 version 13 subversion 2 patch v5.13.2-3-gd1e2db0) configuration:
  Snapshot of: d1e2db0bdd4dafee37208f600f4d1e6be23b2189
    osname=darwin, osvers=10.4.0, archname=darwin-thread-multi-2level
    uname='darwin pint.local 10.4.0 darwin kernel version 10.4.0: fri apr 23 18:28:53 pdt 2010; root:xnu-1504.7.4~1release_i386 i386 '
    config_args='-de -Dusedevel -Duseithreads'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5659)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, 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'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches:

@INC for perl 5.13.2:

Environment for perl 5.13.2:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (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