Skip Menu |

This queue is for tickets about the Class-Accessor-Fast-XS CPAN distribution.

Report information
The Basics
Id: 45594
Status: resolved
Priority: 0/
Queue: Class-Accessor-Fast-XS

People
Owner: RUZ [...] cpan.org
Requestors: SREZIC [...] cpan.org
srezic [...] iconmobile.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.02
Fixed in: (no value)



Subject: Different behaviour with read-only accessors
Class::Accessor::Fast::XS does not behave like Class::Accessor::Fast if a ro accessor is defined, and the hash key does not exist. In this case the module croaks with "couldn't store value in hash". See the attached sample script. I think this should be either corrected (don't croak, just return undef in the XS function) or at least documented (currently the docs say that the two modules behave the same). Regards, Slaven
Subject: acc.pl
#!/usr/bin/perl use strict; use warnings; { package Slow; use base 'Class::Accessor::Fast'; __PACKAGE__->mk_ro_accessors(qw(foo)); sub new { bless {}, shift } } { package Fast; use base 'Class::Accessor::Fast::XS'; __PACKAGE__->mk_ro_accessors(qw(foo)); sub new { bless {}, shift } } warn Slow->new->foo; warn Fast->new->foo; __END__ Output is: Use of uninitialized value in warn at /tmp/acc.pl line 20. Warning: something's wrong at /tmp/acc.pl line 20. couldn't store value in hash at /tmp/acc.pl line 21. (script terminates here)
CC: Slaven Rezic <srezic [...] iconmobile.com>
Subject: [PATCH] * fix for https://rt.cpan.org/Ticket/Display.html?id=45594
Date: Thu, 30 Apr 2009 15:54:52 +0200
To: bug-Class-Accessor-Fast-XS [...] rt.cpan.org
From: Slaven Rezic <srezic [...] iconmobile.com>
--- MANIFEST | 1 + XS.xs | 2 +- lib/Class/Accessor/Fast/XS.pm | 2 +- t/ro.t | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100755 t/ro.t diff --git a/MANIFEST b/MANIFEST index 80fcc80..6353aed 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,6 +8,7 @@ t/aliases.t t/bench.pl t/bestpractice.t t/no-aliasing.t +t/ro.t t/README XS.xs META.yml Module meta-data (added by MakeMaker) diff --git a/XS.xs b/XS.xs index b803d58..b17dde7 100644 --- a/XS.xs +++ b/XS.xs @@ -25,7 +25,7 @@ _xs_ro_accessor(self, ...) if ( he = hv_fetch_ent((HV *)SvRV(self), readfrom.key, 0, readfrom.hash) ) PUSHs(HeVAL(he)); else - croak("couldn't store value in hash"); + XSRETURN_UNDEF; void _xs_wo_accessor(self, ...) diff --git a/lib/Class/Accessor/Fast/XS.pm b/lib/Class/Accessor/Fast/XS.pm index 087ecbd..ce1e4f3 100644 --- a/lib/Class/Accessor/Fast/XS.pm +++ b/lib/Class/Accessor/Fast/XS.pm @@ -31,7 +31,7 @@ use strict; use warnings; use base qw(Class::Accessor::Fast); -our $VERSION = '0.02'; +our $VERSION = '0.03'; use XSLoader; XSLoader::load( __PACKAGE__, $VERSION ); diff --git a/t/ro.t b/t/ro.t new file mode 100755 index 0000000..7e65db8 --- /dev/null +++ b/t/ro.t @@ -0,0 +1,21 @@ +#!perl +use strict; +use Test::More tests => 2; + +{ + package Slow; + use base 'Class::Accessor::Fast'; + __PACKAGE__->mk_ro_accessors(qw(foo)); + sub new { bless {}, shift } +} + +{ + package Fast; + use base 'Class::Accessor::Fast::XS'; + __PACKAGE__->mk_ro_accessors(qw(foo)); + sub new { bless {}, shift } +} + +is(Slow->new->foo, undef); +is(Fast->new->foo, undef); + -- 1.6.2.1
Subject: Re: [rt.cpan.org #45595] [PATCH] * fix for https://rt.cpan.org/Ticket/Display.html?id=45594
Date: Thu, 30 Apr 2009 20:59:38 +0400
To: bug-Class-Accessor-Fast-XS [...] rt.cpan.org
From: Ruslan Zakirov <ruslan.zakirov [...] gmail.com>
Thanks, I'll look into it pretty soon and release a new version. On Thu, Apr 30, 2009 at 5:56 PM, Slaven Rezic via RT <bug-Class-Accessor-Fast-XS@rt.cpan.org> wrote: Show quoted text
> Thu Apr 30 09:56:23 2009: Request 45595 was acted upon. > Transaction: Ticket created by srezic@iconmobile.com >       Queue: Class-Accessor-Fast-XS >     Subject: [PATCH] * fix for https://rt.cpan.org/Ticket/Display.html?id=45594 >   Broken in: (no value) >    Severity: (no value) >       Owner: Nobody >  Requestors: srezic@iconmobile.com >      Status: new >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=45595 > > > > --- >  MANIFEST                      |    1 + >  XS.xs                         |    2 +- >  lib/Class/Accessor/Fast/XS.pm |    2 +- >  t/ro.t                        |   21 +++++++++++++++++++++ >  4 files changed, 24 insertions(+), 2 deletions(-) >  create mode 100755 t/ro.t > > diff --git a/MANIFEST b/MANIFEST > index 80fcc80..6353aed 100644 > --- a/MANIFEST > +++ b/MANIFEST > @@ -8,6 +8,7 @@ t/aliases.t >  t/bench.pl >  t/bestpractice.t >  t/no-aliasing.t > +t/ro.t >  t/README >  XS.xs >  META.yml                                 Module meta-data (added by MakeMaker) > diff --git a/XS.xs b/XS.xs > index b803d58..b17dde7 100644 > --- a/XS.xs > +++ b/XS.xs > @@ -25,7 +25,7 @@ _xs_ro_accessor(self, ...) >     if ( he = hv_fetch_ent((HV *)SvRV(self), readfrom.key, 0, readfrom.hash) ) >         PUSHs(HeVAL(he)); >     else > -        croak("couldn't store value in hash"); > +       XSRETURN_UNDEF; > >  void >  _xs_wo_accessor(self, ...) > diff --git a/lib/Class/Accessor/Fast/XS.pm b/lib/Class/Accessor/Fast/XS.pm > index 087ecbd..ce1e4f3 100644 > --- a/lib/Class/Accessor/Fast/XS.pm > +++ b/lib/Class/Accessor/Fast/XS.pm > @@ -31,7 +31,7 @@ use strict; >  use warnings; >  use base qw(Class::Accessor::Fast); > > -our $VERSION = '0.02'; > +our $VERSION = '0.03'; > >  use XSLoader; >  XSLoader::load( __PACKAGE__, $VERSION ); > diff --git a/t/ro.t b/t/ro.t > new file mode 100755 > index 0000000..7e65db8 > --- /dev/null > +++ b/t/ro.t > @@ -0,0 +1,21 @@ > +#!perl > +use strict; > +use Test::More tests => 2; > + > +{ > +    package Slow; > +    use base 'Class::Accessor::Fast'; > +    __PACKAGE__->mk_ro_accessors(qw(foo)); > +    sub new { bless {}, shift } > +} > + > +{ > +    package Fast; > +    use base 'Class::Accessor::Fast::XS'; > +    __PACKAGE__->mk_ro_accessors(qw(foo)); > +    sub new { bless {}, shift } > +} > + > +is(Slow->new->foo, undef); > +is(Fast->new->foo, undef); > + > -- > 1.6.2.1 > > >
-- Best regards, Ruslan.
Thank you. CAF::XS is on its way to the CPAN. -- Best regards, Ruslan.