[issue3439] create a numbits() method for int and long types

STINNER Victor report at bugs.python.org
Fri Dec 12 19:03:15 CET 2008


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

> - why do you use PyLong_FromSize_t rather than PyInt_FromSize_t?

I choosed to use consistent result type. But now I would prefer int :-) I see 
that PyInt_FromSize_t() returns a long if the value doesn't fit in an int. So 
it's correct.

> - isn't the if (ndigits == 0) check redundant?

I'm paranoid: if _PyLong_NumBits() fails but the number is zero, the function 
may crash. But this case is impossible: _PyLong_NumBits() can only fails with 
an OverflowError.

Can you fix these two issues (use PyInt_FromSize_t and remove the if)?

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3439>
_______________________________________


More information about the Python-bugs-list mailing list