Large integers from C

Phil Mayers p.mayers at ic.ac.uk
Wed Feb 20 17:30:39 CET 2002


All,

I need to create Large (>300 bit) python Long's from C. I don't need (and
in fact, don't want) to use the features of the (apparently obselete?)
mpz module, or gmpy, or whatever. I simply want to say:

val = PyLong_FromOctets(char *v, int vlen);

...where v is a MSB- or LSB-first octet string, base 256. This function
or an equivalent appears to be completely lacking from the Python C
interface.

I just know someone is going to say "return the octet string and do this:

intval = reduce(lambda x,y: (x<<8)+ord(y), strval)

I've tried, and this was too slow (the whole point of the C module being
to speed this up).

Any ideas?

Cheers,
Phil



More information about the Python-list mailing list