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

Incorrect binding of lexicals #798

Closed
p5pRT opened this issue Oct 29, 1999 · 7 comments
Closed

Incorrect binding of lexicals #798

p5pRT opened this issue Oct 29, 1999 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 29, 1999

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

Searchable as RT1725$

@p5pRT
Copy link
Author

p5pRT commented Oct 29, 1999

From mjtg@cus.cam.ac.uk

*********************
#!/usr/local/bin/perl -w

use strict;

package X;

sub new {
  my $class = shift;

  my $obj = {
  X => 1,
  Y => 2,
  EQN => '$x * $y * $t',
  };
  return bless $obj, $class;
}

{
  my ($x, $y);
  sub calculate {
  my $obj = shift;

  unless (defined $x) { # <---- AAA
  $x = $obj->{X}; # <---- BBB
  $y = $obj->{Y};
  }

  my $t = shift;

# print "$x $y\n";

  my $z = eval $obj->{EQN};
  return $z;
  }
}

package main;

my $x = new X;
my $z = $x->calculate(3);

print "Z is $z.\n";
***********************

Now, running the above program generates the following​:

Use of uninitialized value at (eval 1) line 1.
Use of uninitialized value at (eval 1) line 1.
Z is 0.

Bug shows in both 5.005_03 and 5.0065_62.

Running under the debugger, we see at points AAA and BBB that $x and $y
refer to different variables​:

X​::calculate(-​:21)​: unless (defined $x) {
  DB<1> x \$x, \$y
0 SCALAR(0x1aba98)
  -> undef
1 SCALAR(0x1cbc50)
  -> undef
  DB<2> s
X​::calculate(-​:22)​: $x = $obj->{X};
  DB<2> x \$x, \$y
0 SCALAR(0xdd678)
  -> undef
1 SCALAR(0xdd690)
  -> undef
  DB<3>

So the binding of lexicals has got confused in some way.

Mike Guy

% ./perl -V
Summary of my perl5 (revision 5.0 version 5 subversion 62) configuration​:
  Platform​:
  osname=sunos, osvers=4.1.3, archname=sun4-sunos
  uname='sunos nmg1.csi. 4.1.3 1 sun4c '
  config_args='-Doptimise=-O -Uusethreads -des'
  hint=previous, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  use64bits=undef usemultiplicity=undef
  Compiler​:
  cc='gcc', optimize='-O', gccversion=2.7.2.3
  cppflags='-I/usr/local/include'
  ccflags ='-I/usr/local/include'
  stdchar='unsigned char', d_stdstdio=define, usevfork=true
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
  alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries​:
  ld='ld', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/ucblib
  libs=-ldbm -ldl -lm -lc -lposix
  libc=/lib/libc.so.1.8, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
  cccdlflags='-fpic', lddlflags='-assert nodefinitions -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Locally applied patches​:
  perldoc.temp
  install.w
  Built under sunos
  Compiled at Oct 27 1999 01​:31​:39
  @​INC​:
  /home/mjtg/perl5.005_62a/lib
  /home/mjtg/perl5.005_62a/lib
  /home/mjtg/perl5.005_62a/lib/site_perl
  .

@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2000

From [Unknown Contact. See original ticket]

This seems to still be an issue @​8101.

-spp

Ala Qumsieh <aqumsieh@​matrox.com> reports in c.l.p.misc that the
following program gives incorrect output​:

*********************
#!/usr/local/bin/perl -w

use strict;

package X;

sub new {
  my $class = shift;

  my $obj = {
  X => 1,
  Y => 2,
  EQN => '$x * $y * $t',
  };
  return bless $obj, $class;
}

{
  my ($x, $y);
  sub calculate {
  my $obj = shift;

  unless (defined $x) { # <---- AAA
  $x = $obj->{X}; # <---- BBB
  $y = $obj->{Y};
  }

  my $t = shift;

# print "$x $y\n";

  my $z = eval $obj->{EQN};
  return $z;
  }
}

package main;

my $x = new X;
my $z = $x->calculate(3);

print "Z is $z.\n";
***********************

Now, running the above program generates the following​:

Use of uninitialized value at (eval 1) line 1.
Use of uninitialized value at (eval 1) line 1.
Z is 0.

Bug shows in both 5.005_03 and 5.0065_62.

Running under the debugger, we see at points AAA and BBB that $x and $y
refer to different variables​:

X​::calculate(-​:21)​: unless (defined $x) {
  DB<1> x \$x, \$y
0 SCALAR(0x1aba98)
  -> undef
1 SCALAR(0x1cbc50)
  -> undef
  DB<2> s
X​::calculate(-​:22)​: $x = $obj->{X};
  DB<2> x \$x, \$y
0 SCALAR(0xdd678)
  -> undef
1 SCALAR(0xdd690)
  -> undef
  DB<3>

So the binding of lexicals has got confused in some way.

Mike Guy

@p5pRT
Copy link
Author

p5pRT commented Feb 19, 2002

From The RT System itself

$ ./perl -w -Ilib ../t.pl
Use of uninitialized value in multiplication (*) at (eval 1) line 1.
Use of uninitialized value in multiplication (*) at (eval 1) line 1.
Z is 0.

@p5pRT
Copy link
Author

p5pRT commented Feb 19, 2002

From The RT System itself

use strict;
use warnings;

package X;

sub new {
  my $class = shift;

  my $obj = {
  X => 1,
  Y => 2,
  EQN => '$x * $y * $t',
  };
  return bless $obj, $class;
}

{
  my ($x, $y);
  sub calculate {
  my $obj = shift;

  unless (defined $x) { # <---- AAA
  $x = $obj->{X}; # <---- BBB
  $y = $obj->{Y};
  }

  my $t = shift;

# print "$x $y\n";

  my $z = eval $obj->{EQN};
  return $z;
  }
}

package main;

my $x = new X;
my $z = $x->calculate(3);

print "Z is $z.\n";

@p5pRT
Copy link
Author

p5pRT commented Aug 7, 2002

From @gbarr

This is still present in 5.8.0

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2002

From @iabyn

Fixed by patch #18223 in bleedperl.

@p5pRT p5pRT closed this as completed Dec 8, 2002
@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2002

@iabyn - Status changed from 'open' 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