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

Re: Bug with vec() and bitwise OR? #1952

Closed
p5pRT opened this issue May 9, 2000 · 5 comments
Closed

Re: Bug with vec() and bitwise OR? #1952

p5pRT opened this issue May 9, 2000 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 9, 2000

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

Searchable as RT3223$

@p5pRT
Copy link
Author

p5pRT commented May 9, 2000

From rmb1@cise.npl.co.uk

Hey all,

The following snippet just appeared on c.l.p.misc, and I think it unveils a
bug (at least on 5.005_03)​:

\#\!/usr/bin/perl \-w

use strict;
my $x = my $y = my $z = 0;

vec\($x\, 0\, 1\) = 1;
vec\($y\, 1\, 1\) = 1;

$z = $x | $y;

print "$x $y $z\\n";
\_\_END\_\_

The above prints​:

1 2 0

The values of $x and $y are fine, but $z should be 3, no?
If you explicitly set $x to 1 and $y to 2 (without using vec()), then you
get the expected result for $z.

Anybody with a good explanation? I don't have 5.6 handy. Anybody can try it
there?

% perl -we 'for (qw(0 "0" "@​" "A" ""), q(" ")) { my $x = eval $_; die if $@​; vec($x,0,1)=1; print qq($_ => "$x", ), ($x == 1 ? "yes" : "no"), "\n"; }'
0 => "1", no
"0" => "1", yes
Argument "A" isn't numeric in eq at -e line 1.
"@​" => "A", no
Argument "A" isn't numeric in eq at -e line 1.
"A" => "A", no
Argument "^A" isn't numeric in eq at -e line 1.
"" => "", no
Argument "!" isn't numeric in eq at -e line 1.
" " => "!", no

It appears that after C<$x = 0; vec($x,0,1)=1;>,
  $x is numeric (no warning)
  is not numerically equal to 1,
  but is the string "1".

Robin

@p5pRT
Copy link
Author

p5pRT commented May 11, 2000

From [Unknown Contact. See original ticket]

I have a patch for this​:

Hey all,

The following snippet just appeared on c.l.p.misc, and I think it unveils a
bug (at least on 5.005_03)​:

\#\!/usr/bin/perl \-w

use strict;
my $x = my $y = my $z = 0;

vec\($x\, 0\, 1\) = 1;
vec\($y\, 1\, 1\) = 1;

$z = $x | $y;

print "$x $y $z\\n";
\_\_END\_\_

The above prints​:

1 2 0

The values of $x and $y are fine, but $z should be 3, no?
If you explicitly set $x to 1 and $y to 2 (without using vec()), then you
get the expected result for $z.

Anybody with a good explanation? I don't have 5.6 handy. Anybody can try it
there?

% perl -we 'for (qw(0 "0" "@​" "A" ""), q(" ")) { my $x = eval $_; die if $@​; vec($x,0,1)=1; print qq($_ => "$x", ), ($x == 1 ? "yes" : "no"), "\n"; }'
0 => "1", no
"0" => "1", yes
Argument "A" isn't numeric in eq at -e line 1.
"@​" => "A", no
Argument "A" isn't numeric in eq at -e line 1.
"A" => "A", no
Argument "^A" isn't numeric in eq at -e line 1.
"" => "", no
Argument "!" isn't numeric in eq at -e line 1.
" " => "!", no

It appears that after C<$x = 0; vec($x,0,1)=1;>,
$x is numeric (no warning)
is not numerically equal to 1,
but is the string "1".

Robin

Perl-Friends​: To unsubscribe, mail <perl-friends-unsubscribe@​perlsupport.com>

With my patch the original script prints "1 2 3" and my script print "yes".

Robin

--- doop.c 2000/05/11 12​:55​:39 1.1
+++ doop.c 2000/05/11 13​:30​:41 1.2
@​@​ -897,6 +897,7 @​@​
  }
#endif
  }
+ SvNIOK_off(targ); /* see t/op/vec.t test 16 */
  SvSETMAGIC(targ);
}

Patch​:
--- t/op/vec.t 2000/05/11 13​:18​:33 1.1
+++ t/op/vec.t 2000/05/11 13​:30​:41 1.2
@​@​ -4,5 +4,5 @​@​

-print "1..15\n";
+print "1..16\n";

print vec($foo,0,1) == 0 ? "ok 1\n" : "not ok 1\n";
print length($foo) == 0 ? "ok 2\n" : "not ok 2\n";
@​@​ -24,4 +24,6 @​@​
vec($Vec, 0, 32) = 0xbaddacab;
print $Vec eq "\xba\xdd\xac\xab" ? "ok 14\n" : "not ok 14\n";
print vec($Vec, 0, 32) == 3135089835 ? "ok 15\n" : "not ok 15\n";
+vec($foo = 0,0,1) = 1; # ensure $foo forgets its original numerical value
+print $foo == 1 ? "ok 16\n" : "not ok 16\n";

End of patch

@p5pRT
Copy link
Author

p5pRT commented May 11, 2000

From @tamias

On Thu, May 11, 2000 at 03​:35​:41PM +0100, Robin Barker wrote​:

--- doop.c 2000/05/11 12​:55​:39 1.1
+++ doop.c 2000/05/11 13​:30​:41 1.2
@​@​ -897,6 +897,7 @​@​
}
#endif
}
+ SvNIOK_off(targ); /* see t/op/vec.t test 16 */

That comment won't make sense if the tests are changed around. It would be
better to put a real comment here.

 SvSETMAGIC\(targ\);

}

Ronald

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2002

From rmb1@cise.npl.co.uk

Fixed by patch supplied by Robin Barker,
the additional test (t/op/vec.t #16) is still in the test suite.

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2002

rmb1@cise.npl.co.uk - 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