Python/C: unsigned Py_BuildValue, PyInt_FromLong

Mike C. Fletcher mcfletch at rogers.com
Wed Feb 25 15:48:18 EST 2004


You're likely looking for:

    PyLong_FromUnsignedLong
    http://www.python.org/doc/2.3.3/api/longObjects.html

Unsigned ints can be longer than Python 32-bit signed integers, so 
either do a check for the high-bit being set and use 
PyLong_FromUnsignedLong for that case and PyInt_FromLong otherwise, or 
just always use PyLong_FromUnsignedLong and eat the slight performance 
penalty of having longs everywhere.

HTH,
Mike

Christian Vogel wrote:

>Hi comp.lang.python readers,
>
>are there routines to create a Python integer from unsigned C-integers?
>
>I only could find Py_BuildValue[1] and PyInt_FromLong[2] which both only use
>signed c-integers. Is there another way I overlooked?
>
>[1]: http://www.python.org/doc/2.3.3/api/arg-parsing.html
>        ParseValue knows "k" for unsigned long, BuildValue doesn't.
>
>[2]: http://www.python.org/doc/2.3.3/api/intObjects.html
>        PyInt_FromLong only uses a signed integer.
>
>        Chris
>  
>
 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/






More information about the Python-list mailing list