develooper Front page | perl.perl5.porters | Postings from March 2018

Re: [perl #132415] _MEM_WRAP_NEEDS_RUNTIME_CHECK (malloc wrapping)in handy.h broken

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 6, 2018 13:08
Subject:
Re: [perl #132415] _MEM_WRAP_NEEDS_RUNTIME_CHECK (malloc wrapping)in handy.h broken
Message ID:
20180306130812.GE3216@iabyn.com
On Sat, Nov 11, 2017 at 04:57:27AM -0800, l.mai@web.de via RT wrote:
> On Tue, 07 Nov 2017 16:31:51 -0800, mauke- wrote:
> > 
> > In handy.h there is this piece of code:
> > 
> > #  define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
> >     (8 * sizeof(n) + sizeof(t) > sizeof(MEM_SIZE))
> > 
> > A comment claims:
> > 
> > * It's mathematically equivalent to
> > *    max(n) * sizeof(t) > MEM_SIZE_MAX
> > 
> > This is false because _MEM_WRAP_NEEDS_RUNTIME_CHECK currently always
> > returns
> > true (it's broken).
> > 
> > It was lasted touched in commit
> > 004073bac990d90244eb463f435c52d4040b36df
> > "Simplify _MEM_WRAP_NEEDS_RUNTIME_CHECK()".
> > 
> > The old version was:
> > 
> > #  define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
> >     (  sizeof(MEM_SIZE) < sizeof(n) \
> >     || sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))
> 
> I have now reverted this commit in 445198b9b50e1018da1c98005a88bdf15c964f23.
> 
> I believe the new version could have been fixed by changing
> 
>     (8 * sizeof(n) + sizeof(t) > sizeof(MEM_SIZE))
> 
> to
> 
>     (8 * sizeof(n) + ILOG2(sizeof(t)) > 8 * sizeof(MEM_SIZE))
> 
> but then I'd have to define a macro to compute the integer log base 2 (rounded up) of sizeof(t) at compile time. This is possible but annoying (64 separate comparisons). It's also the opposite of a simplification.
> 
> So unless we really need to do that, I'd rather not.

I belatedly agree with your analysis. I clearly had a brain fart that
day. I'll close the ticket.

-- 
A walk of a thousand miles begins with a single step...
then continues for another 1,999,999 or so.

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