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

Blessed glob returned from function loses blessing #395

Closed
p5pRT opened this issue Aug 18, 1999 · 4 comments
Closed

Blessed glob returned from function loses blessing #395

p5pRT opened this issue Aug 18, 1999 · 4 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Aug 18, 1999

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

Searchable as RT1230$

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 18, 1999

From @mjdominus

I create a blessed glob in a function and return it to the caller.
The glob that the caller gets is a copy and is not blessed.

Demo program​:

-----------------BEGIN PROGRAM---------------------------------------------
my $z = mkglob();
print "2​: $z\n";
print "2​: ", ref(\$z), "\n";
print "2​: ", (\$z)->can('can'), "\n";

sub mkglob {
  my $glob = do {local *G};
  bless \$glob => 'Snonk!';
  print "1​: $glob\n";
  print "1​: ", ref(\$glob), "\n";
  print "1​: ", (\$glob)->can('can'), "\n";
  $glob;
}

-----------------END PROGRAM ---------------------------------------------

The `ref' call inside the function (labelled `1​:') yields `Snonk!'
because the glob is blessed. The ->can call succeeds, because \$glob
is a reference to a blessed glob.

However, the `ref' call outside the function (labelled `2​:') yields
`GLOB' because $z is not blessed, even though it should have been
copied from $glob. The `can' call aborts with a fatal error because
\$z is a reference to an unblessed object.

Using Devel​::Peek, you can see that the glob is actually copied on
return, and the blessing is not part of the data that is copied.

This behavior persists from at least 5.005_02 until at least 5.00557.

Perl Info


This perlbug was built using Perl 5.00502 - Sun Oct 18 04:25:09 CDT 1998
It is being executed now by  Perl 5.00556 - Wed May 19 22:26:34 EDT 1999.

Site configuration information for perl 5.00502:

Configured by root at Sun Oct 18 04:25:09 CDT 1998.

Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
  Platform:
    osname=linux, osvers=2.0.35, archname=i586-linux
    uname='linux darkstar 2.0.35 #10 tue oct 13 18:04:13 cdt 1998 i586 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.7.2.3
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    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
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.5.4.46, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00502:
    /usr/lib/perl5/5.00502/i586-linux
    /usr/lib/perl5/5.00502
    /usr/lib/perl5/site_perl/5.005/i586-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00502:
    HOME=/home/mjd
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/lib:/usr/lib:/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/mjd/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/sbin:/usr/sbin:/usr/local/bin/X11:/usr/local/bin/mh:/data/mysql/bin:/home/mjd/TPI/bin:/usr/local/mysql/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 18, 1999

From @mjdominus

I create a blessed glob in a function and return it to the caller.
The glob that the caller gets is a copy and is not blessed.

The problem may be in the assignment operation, not the function
return value return. The following program illutrates the same
problem with no function call​:

  my $glob = *X;
  bless \$glob => 'Snonk!';
  print "1​: $glob\n";
  print "1​: ", ref(\$glob), "\n";
  print "1​: ", (\$glob)->can('can'), "\n";
  my $g2 = $glob;
  print "2​: $g2\n";
  print "2​: ", ref(\$g2), "\n";
  print "2​: ", (\$g2)->can('can'), "\n";

1 similar comment
@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 18, 1999

From @mjdominus

I create a blessed glob in a function and return it to the caller.
The glob that the caller gets is a copy and is not blessed.

The problem may be in the assignment operation, not the function
return value return. The following program illutrates the same
problem with no function call​:

  my $glob = *X;
  bless \$glob => 'Snonk!';
  print "1​: $glob\n";
  print "1​: ", ref(\$glob), "\n";
  print "1​: ", (\$glob)->can('can'), "\n";
  my $g2 = $glob;
  print "2​: $g2\n";
  print "2​: ", ref(\$g2), "\n";
  print "2​: ", (\$g2)->can('can'), "\n";

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 18, 1999

From @gbarr

But this is tru for any type, eg replace with

  my $scalar = "value"; bless \$scalar, ...
  my @​arr = (1); bless \@​arr, ...
  my %hash = (1,2); bless \%hash, ...

and you will see the same result. ie that the bless-ing is not
copied over.

On Wed, Aug 18, 1999 at 01​:27​:42PM -0400, Mark-Jason Dominus wrote​:

I create a blessed glob in a function and return it to the caller.
The glob that the caller gets is a copy and is not blessed.

The problem may be in the assignment operation, not the function
return value return. The following program illutrates the same
problem with no function call​:

my $glob = *X;
bless \$glob => 'Snonk!';
print "1​: $glob\n";
print "1​: ", ref(\$glob), "\n";
print "1​: ", (\$glob)->can('can'), "\n";
my $g2 = $glob;
print "2​: $g2\n";
print "2​: ", ref(\$g2), "\n";
print "2​: ", (\$g2)->can('can'), "\n";

--
Since you're clearly mad as a mongoose, I'll bid you good-day.
  -- Edmund to Captain Rum : Black Adder II "Potato"

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.