Skip Menu |

This queue is for tickets about the version CPAN distribution.

Report information
The Basics
Id: 88495
Status: resolved
Priority: 0/
Queue: version

People
Owner: Nobody in particular
Requestors: 'spro^^*%*^6ut# [...] &$%*c
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.9905



Subject: Incorrect string comparison in XS_version_new
package foo; @ISA = version; warn ref foo->new; # prints foo package ver; @ISA = version; warn ref ver->new; # prints version This comparison is incorrect; if ( strnNE(classname,"version", len) ) /* inherited new() */ It only checks as many characters as are in the subclass’s name. It should probably check len != 7 || ....
On Sun Sep 08 02:34:04 2013, SPROUT wrote: Show quoted text
> package foo; > @ISA = version; > warn ref foo->new; # prints foo > > package ver; > @ISA = version; > warn ref ver->new; # prints version > > This comparison is incorrect; > > if ( strnNE(classname,"version", len) ) /* inherited new() */ > > It only checks as many characters as are in the subclass’s name. It > should probably check len != 7 || ....
XS_version_qv appears to have the same problem, but I haven’t tested it.
On Sun Sep 08 02:34:04 2013, SPROUT wrote: Show quoted text
> package foo; > @ISA = version; > warn ref foo->new; # prints foo > > package ver; > @ISA = version; > warn ref ver->new; # prints version > > This comparison is incorrect; > > if ( strnNE(classname,"version", len) ) /* inherited new() */
Not in the CPAN release; that code was added here: commit ed1db70e12244166baee8553bcdfe1e16a620f19 Author: Brian Fraser <fraserbn@gmail.com> Date: Thu Jul 7 05:57:57 2011 -0300 universal.c: VERSION UTF8 cleanup The CPAN release does this instead: if ( strcmp(classname,"version::vxs") != 0 ) /* inherited new() */ which may not be UTF8 aware, but also doesn't need to be, I don't think. Can you even have class names in UTF8? Show quoted text
> It only checks as many characters as are in the subclass’s name. It > should probably check len != 7 || ....
However, that works as designed; the object ref SHOULD be the subclass, not the base class. The whole purpose of that block is to rebless the object into the correct subclass. I don't see a problem (other than people patching the core Perl version code without bothering to tell me). John
On Sun Sep 08 21:58:13 2013, JPEACOCK wrote: Show quoted text
> On Sun Sep 08 02:34:04 2013, SPROUT wrote:
> > package foo; > > @ISA = version; > > warn ref foo->new; # prints foo > > > > package ver; > > @ISA = version; > > warn ref ver->new; # prints version > > > > This comparison is incorrect; > > > > if ( strnNE(classname,"version", len) ) /* inherited new() */
> > Not in the CPAN release; that code was added here: > > commit ed1db70e12244166baee8553bcdfe1e16a620f19 > Author: Brian Fraser <fraserbn@gmail.com> > Date: Thu Jul 7 05:57:57 2011 -0300 > > universal.c: VERSION UTF8 cleanup > > The CPAN release does this instead: > > if ( strcmp(classname,"version::vxs") != 0 ) /* inherited new() */ > > which may not be UTF8 aware, but also doesn't need to be, I don't > think. Can you even have class names in UTF8?
Yes, you can. Though ideally this routine shouldn’t be looking up the stash by name if it got the stash from the object. It should just use the stash as-is. That might cause this to crash, though: #!perl -w bless \$_, "Foo"; eval 'bless \$Foo::bar, "Bar"'; sub Bar::DESTROY { (\$_)->version'new } undef *Foo::; bless \$_; I don’t think you need to worry about that. :-) (And I’m about to fix the flaw in sv_bless that allows an object to be blessed into a stash that is in the middle of being freed.) Show quoted text
>
> > It only checks as many characters as are in the subclass’s name. It > > should probably check len != 7 || ....
> > However, that works as designed; the object ref SHOULD be the > subclass, not the base class. The whole purpose of that block is to > rebless the object into the correct subclass. > > I don't see a problem (other than people patching the core Perl > version code without bothering to tell me).
That’s my fault. What do you think of my proposal in ticket #88458? It’s not obvious which routines are supposed to have CPAN as upstream and which are supposed to have the perl core upstream, as the version-specific stuff is in util.c and universal.c along with other core stuff. It’s very confusing. Ideally, there would be a single .c file in the version distribution that can just be dropped straight into blead. You would have to create XSUBs using the ‘bare bones’ method. But I think it’s quite doable.
Fixed in 0.9905