[Python-Dev] 32 bit to 64 bit migration of C-API(Python)

Nick Coghlan ncoghlan at gmail.com
Sun Jan 27 07:16:40 CET 2013


On Sun, Jan 27, 2013 at 3:42 PM, abhishek goswami
<zeal_goswami at yahoo.com> wrote:
> Hi,
> I am working in Python-C ApI (Integrated Project). The Project has migrated
> to 64 bit machine from 32 bit machine. Every thing was working fine in 32
> bit machine.
> But we getting following error in 64 bit machine.
> " Python int too large to convert to C long".

Hi Abhishek,

python-dev is for the development *of* CPython, rather than
development *with* CPython (including the C API). More appropriate
places for this question are the general python-list mailing list or
the C API special interest group.

However, from the sounds of it, you are running into trouble with the
fact that on a 64-bit machine, Python stores many internal values as
"Py_ssize_t" (which is always 8 bytes on a 64 bit machine), rather
than a C int or long. PEP 353 [1] describes the background for this
change, which allows Python containers to exploit the full size of the
address space on 64-bit systems.

C API functions that may be of interest in that context include:
http://docs.python.org/2/c-api/number.html#PyNumber_AsSsize_t
http://docs.python.org/2/c-api/int.html#PyInt_FromSsize_t
http://docs.python.org/2/c-api/int.html#PyInt_AsSsize_t
http://docs.python.org/2/c-api/long.html#PyLong_FromSsize_t
http://docs.python.org/2/c-api/long.html#PyLong_AsSsize_t
As well as the "n" format character for argument processing
http://docs.python.org/2/c-api/arg.html#parsing-arguments-and-building-values

[1] http://www.python.org/dev/peps/pep-0353/

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list