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

[perl #119943] RFE: localized state of $_ should carry across goto ⊂

Thread Previous | Thread Next
Linda Walsh
September 22, 2013 18:44
[perl #119943] RFE: localized state of $_ should carry across goto ⊂
Message ID:
# New Ticket Created by  Linda Walsh 
# Please include the string:  [perl #119943]
# 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.16.2.

[Please describe your issue here]

Am proposing a language change (enabled with some pragma like
'goto_forwards_local'), that would allow variables localized
in 1 sub, that forward control via 'goto' to another sub, to
have 'local' variables propagated in the same way arguments
on the call stack are.

Rationale: Various perl commands take a combination of operands.
'_' is sometimes used as an assumed operand in some of these.
If one wishes to pass _ as an assumed operand, and not disturb
the global '_' (which may be read-only and unable to be assigned to),
one needs to localize it.  When the current function ends, this
localization "pops off" as the function exits.

However there is a the case of "goto &sub", that allows passing
control to a peer function to "finish the current sub's work".  I
submit that it should, at least optionally (or, except for the possibilty
of unknown/unlikely edge cases, default to) pass any localized
variables to the parallel sub (target of the &goto).

It appears, currently, that sub-localized variables, unlike a sub's
parameter state on the call stack, are not passed laterally to targets
of a &goto.  I'm not sure how this is useful, *if* the target of 
the &goto is a common "suffix" body for multiply named subs. 

A simple, use case for using multiple names with a common body of
'&goto' code would be for the multiple names to be taken as names in
a hash that would be passed to a common accessor sub, used in lieu 
of each accessor sub needing to incorporate validity checks
(range, type, etc) as well as get/set behaviors.  

The change involves when a localized var is restored to its previous
state -- before the 'goto' or after.  Conceptually, in the above
described usage, having the localization state track the stack's state
and popping off when the call-context is popped, makes more sense
than the current behavior.

However, on the possibility, that I'm simply (likely) not thinking of
a case where one would "&goto" another sub, that is complete unrelated
to the current sub and this would not be desired (or expected), I
would think that, at least initially, the behavior would only be 
activated with a pragma.

Is there a reason why localized vars aren't kept across a &goto and 
not popped until an "end-of-sub" is encountered?


[Please do not change anything below this line]
This perlbug was built using Perl 5.16.2 - Fri Feb 15 01:17:37 UTC 2013
It is being executed now by  Perl 5.16.2 - Fri Feb 15 01:12:05 UTC 2013.

Site configuration information for perl 5.16.2:

Configured by abuild at Fri Feb 15 01:12:05 UTC 2013.

Summary of my perl5 (revision 5 version 16 subversion 2) configuration:
    osname=linux, osvers=3.4.6-2.10-default, archname=x86_64-linux-thread-multi
    uname='linux build34 3.4.6-2.10-default #1 smp thu jul 26 09:36:26 utc 2012 (641c197) x86_64 x86_64 x86_64 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Dd_dbm_open -Duseshrplib=true -Doptimize=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV -Dotherlibdirs=/usr/lib/perl5/site_perl'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.7.2 20130108 [gcc-4_7-branch revision 195012]', 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='cc', ldflags =' -L/usr/local/lib64 -fstack-protector'
    libpth=/lib64 /usr/lib64 /usr/local/lib64
    libs=-lm -ldl -lcrypt -lpthread
    perllibs=-lm -ldl -lcrypt -lpthread
    libc=/lib64/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.16.2/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64 -fstack-protector'

Locally applied patches:

@INC for perl 5.16.2:

Environment for perl 5.16.2:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL5OPT=-Mutf8 -CSA -I/home/law/bin/lib
    PERL_BADLANG (unset)

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