Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.93k stars 552 forks source link

scalar untie doesn't always work #6528

Closed p5pRT closed 21 years ago

p5pRT commented 21 years ago

Migrated from rt.perl.org#22290 (status was 'resolved')

Searchable as RT22290$

p5pRT commented 21 years ago

From @muir

Created by @muir

---------- begin program ---------- #!/usr/bin/perl -I.

my $x = 7; tie $x\, 'Overlay'\, 8; print "tied x = $x.\n"; untie $x; print "untied x = $x.\n";

package Overlay;

sub TIESCALAR {   my $pkg = shift;   my $y = shift;   return bless \$y\, $pkg; }

sub FETCH {   my $self = shift;   return "\<$$self>"; }

sub STORE { } ---------- end program ----------

In the above program\, the untie only partially works. After the untie\, tied($x) no longer returns anything however\, if I access $x\, the value I get is "\<8>" instead of the "7" it should have reverted to.

If I add UNTIE or DESTROY methods to Overlay\, they are called.

If I drop the 'print "tied x = $x.\n";' line then $x remains at "7".

Perl Info ``` Flags: category=core severity=high Site configuration information for perl v5.8.0: Configured by muir at Wed Dec 18 00:21:13 PST 2002. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=freebsd, osvers=4.7-release, archname=i386-freebsd uname='freebsd charm.idiom.com 4.7-release freebsd 4.7-release #4: thu oct 10 22:04:24 pdt 2002 muir@charm.idiom.com:charmbuildobjcharmbuildsrcsyscharm i386 ' config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.0/mach -Dprivlib=/usr/local/lib/perl5/5.8.0 -Dman3dir=/usr/local/lib/perl5/5.8.0/man/man3 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.0/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.0 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -Ui_gdbm -Dusemymalloc=n' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include', optimize='-O -pipe -m486 -mcpu=i686 -march=pentiumpro ', cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.4 20020320 [FreeBSD]', 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='cc', ldflags ='-Wl,-E -L/usr/local/lib' libpth=/usr/lib /usr/local/lib libs=-lgdbm -lm -lc -lcrypt -lutil perllibs=-lm -lc -lcrypt -lutil libc=, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /usr/local/lib/perl5/site_perl/5.8.0/mach /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.0/BSDPAN /usr/local/lib/perl5/5.8.0/mach /usr/local/lib/perl5/5.8.0 . Environment for perl v5.8.0: HOME=/home/muir LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=.:/home/muir/bin/charm:/home/muir/bin:/home/muir/bin/share:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/shbin:/usr/local/sbin:/usr/local/bin:/usr/local/ptybin:/usr/X11R6/bin:/usr/bin/X11:/usr/local/tex/bin:/usr/ucb:/usr/bin:/bin:/etc:/usr/etc:/usr/games:/lib:/usr/lib:/usr/local/java/bin:/usr/lib/uucp:/usr/openwin/bin:/usr/openwin/bin/xview:/usr/openwin/demo:/usr/adm:/home/muir/tmp PERL_BADLANG (unset) SHELL=/usr/local/bin/tcsh ```
p5pRT commented 21 years ago

From @gbarr

On Fri\, May 23\, 2003 at 04​:36​:47AM -0000\, David Muir Sharnoff wrote​:

---------- begin program ---------- #!/usr/bin/perl -I.

my $x = 7; tie $x\, 'Overlay'\, 8; print "tied x = $x.\n"; untie $x; print "untied x = $x.\n";

package Overlay;

sub TIESCALAR { my $pkg = shift; my $y = shift; return bless \$y\, $pkg; }

sub FETCH { my $self = shift; return "\<$$self>"; }

sub STORE { } ---------- end program ----------

In the above program\, the untie only partially works. After the untie\, tied($x) no longer returns anything however\, if I access $x\, the value I get is "\<8>" instead of the "7" it should have reverted to.

There is nothing in the documentation to say that it should be reverted to its old value.

If I add UNTIE or DESTROY methods to Overlay\, they are called.

If I drop the 'print "tied x = $x.\n";' line then $x remains at "7".

Thats because when FETCH is called perl needs somewhere to place the result before actually using it. In the case of a tied SCALAR it uses the scalar that is tied. So there is now way that the old value can be reverted to. After untie\, a scalar will always hold the last value that was fetched or set.

Graham.

p5pRT commented 21 years ago

From @muir

* There is nothing in the documentation to say that it should * be reverted to its old value. * * > If I add UNTIE or DESTROY methods to Overlay\, they are called. * > * > If I drop the 'print "tied x = $x.\n";' line then $x remains at "7". * * Thats because when FETCH is called perl needs somewhere to place the * result before actually using it. In the case of a tied SCALAR it uses the * scalar that is tied. So there is now way that the old value can be * reverted to. After untie\, a scalar will always hold the last value * that was fetched or set. *

Okay\, I can live with that. Please close this bug out.

I think I've got a couple more related to TIESCALAR\, but I'll submit 'em separately when I've got good test cases.

Thank you for the prompt response!

-Dave

p5pRT commented 21 years ago

@rspier - Status changed from 'new' to 'resolved'