develooper Front page | perl.perl5.porters | Postings from May 2013

Re: Build failed in Jenkins: perl5 #2285

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
May 7, 2013 09:08
Subject:
Re: Build failed in Jenkins: perl5 #2285
Message ID:
20130507090757.GJ3729@plum.flirble.org
On Tue, May 07, 2013 at 11:02:08AM +0200, demerphq wrote:
> On 7 May 2013 10:55, Nicholas Clark <nick@ccl4.org> wrote:

> >> Can anybody replicate this?
> >
> > Util.xs: In function 'void XS_Hash__Util_hash_traversal_mask(CV*)':
> > Util.xs:94: error: invalid conversion from 'const HV*' to 'HV*'
> > Util.xs:94: error:   initializing argument 1 of 'void Perl_hv_rand_set(HV*, U32)'
> > make[1]: *** [Util.o] Error 1
> > make[1]: Leaving directory `/home/nick/Perl/perl/ext/Hash-Util'
> > Unsuccessful make(ext/Hash-Util): code=512 at make_ext.pl line 490.
> > make: *** [lib/auto/Hash/Util/Util.so] Error 2
> >
> > It's passing a const HV* pointer to a function taking HV*
> >
> >     if (SvROK(rhv) && SvTYPE(SvRV(rhv))==SVt_PVHV && !SvMAGICAL(SvRV(rhv))) {
> >         const HV * const hv = (const HV *) SvRV(rhv);
> >         if (items>1) {
> >             hv_rand_set(hv, SvUV(ST(1)));
> >
> >
> > I don't know if the right fix is to change that line from 'const HV * const hv'
> > or to change Perl_hv_rand_set to take a const HV * parameter.
> 
> Thanks a lot, I eventually figured that out from one of Georges smoke
> reports which made it easier to see.
> 
> I was just doing a local build/test on the former. I see no reason not
> to use the latter, do you perchance know which is "better"?

I *think* that

a) having const pointers is better than non-const pointers
   but only if the 'const' is telling the truth
   (because it gives the compiler more opportunities at the call site)
b) In this case one can't make Perl_hv_rand_set() take a const HV *,
   because it calls Perl_hv_iterinit(), and *that* potentially modifies
   the (top level) HV struct.

So that leaves only one possible answer :-)
The one you're already doing.

(And yes, this means that I've thought a bit further since my previous e-mail)

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About