[capi-sig] Fw: 32 bit to 64 bit migration of C-API(Python)

Hrvoje Niksic hniksic at xemacs.org
Mon Jan 28 19:28:14 CET 2013

abhishek goswami <zeal_goswami at yahoo.com> writes:

> 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".
> When I start debug the code and found that we are using long variable
> which has size of 8 bit in C code. If I  replace long to int32_t
> variable in C and all long value
> become garbage[...]

I find it hard to follow your debugging efforts from this point.

It is clear that you are getting the error in 64-bit builds.  The next
thing one would do is try to figure out where the error comes from.
After all, the overflow exception is hardly magic, it is raised in
exactly one place in Python source code, the PyLong_AsLong function, in
the case when the Python integer is too large to fit in a C long.

Changing the type from long to int32_t and other things you are trying
will not fix the bug.  Your problem is the number that is too large to
fit in a long in the first place -- find where it's coming from and fix
it.  For example, you can examine the stack trace and see which Python
integer of value outside [2**63, 2**63) is attempted to be converted to
long.  If your project calls PyLong_AsLong, annotate all calls to that
function with prints that show the repr of the value passed.  Formats
like "%d" are also suspicious.  If all else fails, rebuild Python with
-g and put a breakpoint on the line of PyLong_AsLong that handles the

More information about the capi-sig mailing list