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 loewis
Recipients benjamin.peterson, loewis, pitrou
Date 2008-06-29.17:43:29
SpamBayes Score 0.0024171425
Marked as misclassified No
Message-id <1214761411.95.0.0747772507398.issue3236@psf.upfronthosting.co.za>
In-reply-to
Content
For the old int type, implementing this was trivial, as the conversion
converted into a C long, then called PyInt_FromLong.

For long, it's much more tricky, as no C type can be used to store the
intermediate result. So instead, PyLong_FromString already allocates a
sufficiently-sized long object (based on the number of digits of the
input string), and then fills that object.

Depending on what precisely the complaint of this report is about, one
solution could be to check after the conversion whether the result has
only one digit, and if so, whether it is a small integer, and if so,
convert it to a long, discard it, and use PyLong_FromLong.

If the complaint is that it unnecessarily allocates memory in the first
place, I don't think anything should be done about that - the allocation
is really necessary.

In any case, I think PyLong_FromString should also call long_normalize
before returning the result.
History
Date User Action Args
2008-06-29 17:43:32loewissetspambayes_score: 0.00241714 -> 0.0024171425
recipients: + loewis, pitrou, benjamin.peterson
2008-06-29 17:43:31loewissetspambayes_score: 0.00241714 -> 0.00241714
messageid: <1214761411.95.0.0747772507398.issue3236@psf.upfronthosting.co.za>
2008-06-29 17:43:31loewislinkissue3236 messages
2008-06-29 17:43:29loewiscreate