Subject: | Scalars not copied when setting |
Hi Steffen,
I've run into a strange bug when using this module that doesn't happen
with a pure-Perl accessor module. I think the problem is that the XS
code doesn't make a copy of scalars, and stores the original variable.
See the attached test script.
Output:
foo:
SV = PV(0x801d08) at 0x8017e8
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x334690 "foo"\0
CUR = 3
LEN = 4
pp->[0]:
SV = PV(0x801d5c) at 0x801770
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x320d90 "foo"\0
CUR = 3
LEN = 4
xs->[0]:
SV = PV(0x801d08) at 0x8017e8
REFCNT = 2
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x334690 "foo"\0
CUR = 3
LEN = 4
Subject: | cxsa-bug.pl |
#!/usr/bin/perl
use strict;
use Devel::Peek;
my $pp = PP->new;
my $xs = XS->new;
my $foo = 'foo';
warn "foo:\n";
Dump $foo;
$pp->acc($foo);
$xs->acc($foo);
warn "pp->[0]:\n";
Dump $pp->[0];
warn "xs->[0]:\n";
Dump $xs->[0];
package PP;
sub new {
my $class = shift;
return bless [], $class;
}
sub acc {
return $_[0]->[0] if @_ == 1;
return $_[0]->[0] = $_[1] if @_ == 2;
}
1;
package XS;
sub new {
my $class = shift;
return bless [], $class;
}
use Class::XSAccessor::Array
accessors => {
acc => 0,
};
1;