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

Code blessed where it shouldn't. #2027

Open
p5pRT opened this issue May 30, 2000 · 5 comments
Open

Code blessed where it shouldn't. #2027

p5pRT opened this issue May 30, 2000 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 30, 2000

Migrated from rt.perl.org#3305 (status was 'open')

Searchable as RT3305$

@p5pRT
Copy link
Author

p5pRT commented May 30, 2000

From abigail@arenanetworks.com

Created by abigail@arena-i.com

Consider the following code​:

  #!/opt/perl/bin/perl -w

  use strict;

  sub new {
  my ($class, $code) = @​_;
  print $code, "\n";
  bless $code => $class; # 1)
  }

  for my $i (1 .. 2) {
  main -> new (sub {}); # 2)
  }

  __END__

This will print something like​:

  CODE(0x816454c)
  main=CODE(0x816454c)

that is, the second time new () is called, the code ref is already
blessed in a package. Note that it will print "CODE(0x816454c)"
twice if we outcomment line 1), or if we make the call to new()
with a closure, for instance by changing line 2) to

  main -> new (sub {$i});

While one can say it might not really matter that $code is already
blessed into package as you can still invoke it, and in the example
it's being reblessed anyone, it brings havoc to ones code if one does
type checking on the arguments, and have the code die() if the second
argument isn't a code reference; checked by comparing "CODE" and the
result of 'ref'.

Abigail

Perl Info

Flags:
    category=core
    severity=high

This perlbug was built using Perl v5.6.0 - Thu Mar 23 19:51:19 EST 2000
It is being executed now by  Perl v5.6.0 - Fri Mar 24 17:24:48 EST 2000.

Site configuration information for perl v5.6.0:

Configured by abigail at Fri Mar 24 17:24:48 EST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.7, archname=i86pc-solaris-64int
    uname='sunos newyork 5.7 generic_106542-07 i86pc i386 i86pc '
    config_args='-d -Dprefix=/opt/perl -Uinstallusrbinperl -Doptimize=-g -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=define use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-g', gccversion=2.95.1 19990816 (release)
    cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include'
    ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /home/abigail/Perl
    /home/abigail/Sybase
    /opt/perl/lib/5.6.0/i86pc-solaris-64int
    /opt/perl/lib/5.6.0
    /opt/perl/lib/site_perl/5.6.0/i86pc-solaris-64int
    /opt/perl/lib/site_perl/5.6.0
    /opt/perl/lib/site_perl
    .


Environment for perl v5.6.0:
    HOME=/home/abigail
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/home/abigail/Lib:/usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/abigail/bin:/usr/local/bin:/usr/local/X11/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/games:/usr/ccs/bin:/usr/openwin/bin:/opt/Acrobat4/bin:/opt/cvs/bin:/opt/perl/bin
    PERL5LIB=/home/abigail/Perl:/home/abigail/Sybase
    PERLDIR=/opt/perl
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Aug 2, 2008

From p5p@spam.wizbit.be

The reason why this is happening is discussed in #3306.

(Not exactly the same problem but related.)

@demerphq
Copy link
Collaborator

FWIW, I dont get the reference to #3306 mentioned in this thread. It doesn't seem to be related at all.

This bug is still present in the blead perl.

I would describe it differently than is done in this ticket. Because the code block is empty we are "optimizing" it to use the same CODE block each time. But that is wrong. Consider a different version of this code:

perl -le'sub A::DESTROY { print "A::DESTROY" } sub B::DESTROY { print "B::DESTROY" } sub mb { bless $_[0], $_[1] } for my $class ("A".."B") { push @ret, mb(sub{},$class) } print for @ret'
B=CODE(0x5610790e6c08)
B=CODE(0x5610790e6c08)
B::DESTROY

so we arent getting distinct sub{}'s here, we are getting one. This code should output A::DESTROY, B::DESTROY. Simple statement: this optimization is broken.

@haarg
Copy link
Contributor

haarg commented Feb 11, 2023

That's a mis-link from the RT to GitHub migration. The actual link is #2028, which seems to have been closed by mistake.

@demerphq
Copy link
Collaborator

Thank you @haarg. Can you tell me how you found that?

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

5 participants