Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning object to weakened copy after cloning #6987

Closed
p5pRT opened this issue Dec 15, 2003 · 3 comments
Closed

Assigning object to weakened copy after cloning #6987

p5pRT opened this issue Dec 15, 2003 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 15, 2003

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

Searchable as RT24663$

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2003

From @lizmat

The following program​:

=================================================================
use threads;
use Scalar​::Util qw(weaken);
my $object = Foo->new;

my $ref = $object;
weaken( $ref );

threads->new( sub { $ref = $object } )->join; # $ref = $object causes problems
warn "thread ended\n";

package Foo;
sub new { bless {},shift }
sub DESTROY { warn "DESTROY called in ".(threads->tid)." with $_[0]\n" }

produces the following output in threaded Perls of 5.8.1 and higher
(including recent 5.8.3 to be snapshots and 5.9.0)​:

=================================================================
DESTROY called in 0 with Foo=HASH(0x815bf38)
panic​: magic_killbackrefs at filename line 9.
DESTROY called in 1 with Foo=HASH(0x8229124)
Attempt to free unreferenced scalar​: SV 0x8229130 during global destruction.
DESTROY called in 0 with Foo=HASH(0x8141c0c)
Scalars leaked​: 3

Please note that this _only_ happens if you assign the (a clone of) the
original object to the weakened reference. Note that the error message
occurs in the line with "warn" and that the warning is not displayed.

If you assign anything else to the weakened reference, such as "undef",
you get​:

=================================================================
DESTROY called in 1 with Foo=HASH(0x82290f4)
Attempt to free unreferenced scalar​: SV 0x8229100 during global destruction.
thread ended
DESTROY called in 0 with Foo=HASH(0x8141c0c)

which, apart from the unreferenced scalar warning, is more in line with
what you would expect.

This problem occurs both under Linux as well as Mac OS X. The system
information below has no relation whatsoever with the versions of Perl
used for testing this phenomenon.

Perl Info

Flags:
     category=core
     severity=medium

This perlbug was built using Perl v5.8.2 - Mon Dec  1 15:29:15 CET 2003
It is being executed now by  Perl v5.8.2 - Fri Nov  7 22:43:01 CET 2003.

Site configuration information for perl v5.8.2:

Configured by liz at Fri Nov  7 22:43:01 CET 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
   Platform:
     osname=darwin, osvers=6.8, archname=darwin
     uname='darwin lyzibook.local. 6.8 darwin kernel version 6.8: wed 
sep 10 15:20:55 pdt 2003; root:xnuxnu-344.49.obj~2release_ppc power 
macintosh powerpc '
     config_args='-de'
     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 ='-pipe -fno-common -DPERL_DARWIN 
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include',
     optimize='-O3',
     cppflags='-no-cpp-precomp -pipe -fno-common -DPERL_DARWIN 
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
     ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, 
Off_t='off_t', lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -flat_namespace -L/usr/local/lib'
     libpth=/usr/local/lib /usr/lib
     libs=-lm -lc
     perllibs=-lm -lc
     libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags=' -flat_namespace -bundle -undefined 
suppress -L/usr/local/lib'

Locally applied patches:
     MAINT21829


@INC for perl v5.8.2:
     /usr/local/lib/perl5/5.8.2/darwin
     /usr/local/lib/perl5/5.8.2
     /usr/local/lib/perl5/site_perl/5.8.2/darwin
     /usr/local/lib/perl5/site_perl/5.8.2
     /usr/local/lib/perl5/site_perl/5.8.1/darwin
     /usr/local/lib/perl5/site_perl/5.8.1
     /usr/local/lib/perl5/site_perl
     .


Environment for perl v5.8.2:
     DYLD_LIBRARY_PATH (unset)
     HOME=/Users/liz
     LANG=en
     LANGUAGE (unset)
     LC_ALL=C
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
     PERL_BADLANG (unset)
     SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2004

From @schwern

I can confirm the bug in 5.8.1 RC3 and it appears to have been fixed in
5.8.6 and bleadperl.

@p5pRT p5pRT closed this as completed Dec 13, 2004
@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2004

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant