This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients fredrikj, loewis, mark.dickinson, rhettinger
Date 2008-08-14.09:22:48
SpamBayes Score 4.176675e-07
Marked as misclassified No
Message-id <1218705770.99.0.974276521649.issue3439@psf.upfronthosting.co.za>
In-reply-to
Content
With the patch, the following code causes a
non-keyboard-interruptible interpreter hang.

>>> from sys import maxint
>>> (-maxint-1).numbits()

[... interpreter hang ...]

The culprit is, of course, the statement

if (n < 0)
    n = -n;

in int_numbits: LONG_MIN is negated to itself (this may
even be undefined behaviour according to the C standards).

The patch also needs documentation, and that documentation
should clearly spell out what happens for zero and for
negative numbers.  It's not at all clear that everyone
will expect (0).numbits() to be 0, though I agree that this
is probably the most useful definition in practice.

One could make a case for (0).numbits() raising ValueError:
for some algorithms, what one wants is an integer k such
that 2**(k-1) <= abs(n) < 2**k; when n == 0 no such
integer exists.

Other than those two things, I think the patch looks fine.
History
Date User Action Args
2008-08-14 09:22:51mark.dickinsonsetrecipients: + mark.dickinson, loewis, rhettinger, fredrikj
2008-08-14 09:22:50mark.dickinsonsetmessageid: <1218705770.99.0.974276521649.issue3439@psf.upfronthosting.co.za>
2008-08-14 09:22:50mark.dickinsonlinkissue3439 messages
2008-08-14 09:22:48mark.dickinsoncreate