[Python-3000] C API for ints and strings

Nicholas Bastin nick.bastin at gmail.com
Sat Sep 8 19:41:10 CEST 2007


On 9/8/07, Guido van Rossum <guido at python.org> wrote:
> On 9/8/07, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote:
> > I see that PyInt_* functions are aliases for PyLong_*. Which ones
> > should I use for the long term? There are no PyInt equivalents of
> > PyLong_FromLongLong nor PyLong_AsLongLong.
>
> Use PyLong for now. Eventually we may rename them all; then we'll
> provide a renaming tool or macros.
>
> > Why is _PyLong_FitsInLong private?
>
> I don't know; perhaps because it doesn't always give the best answer.
>
> > In order to convert a Python3 int to
> > another numeric representation, I would like to check if it fits in a C
> > long, and convert via a string only if it does not. Should I use
> > PyLong_AsLong + PyErr_Occurred?
>
> I think either is fine. _PyLong_FitsInLong() will only get better over time. :-)

Speaking of PyLong, and its' minor awkwardness to work with in C (you
either have to convert to another multiple-precision type through a
string, or use Python's arithmetic operators directly), was there any
thought given to using something like GPM's mpz_t as the backing data
type?

--
Nick


More information about the Python-3000 mailing list