[issue17870] Hard to create python longs from arbitrary C integers

2013-04-29 Thread STINNER Victor
STINNER Victor added the comment: "PyLong_FromVoidPtr works for uintptr_t, but not intptr_t." Ok correct. You should use something like: PyObject* PyLong_FromIntptr_t(intptr_t value) { if (sizeof(intptr_t) == sizeof(long)) return PyLong_FromLong(value); else { assert(siz

[issue17870] Hard to create python longs from arbitrary C integers

2013-04-29 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: PyLong_FromVoidPtr works for uintptr_t, but not intptr_t. -- ___ Python tracker ___ ___ Python-bug

[issue17870] Hard to create python longs from arbitrary C integers

2013-04-29 Thread STINNER Victor
STINNER Victor added the comment: Did you try PyLong_FromVoidPtr()? -- nosy: +haypo ___ Python tracker ___ ___ Python-bugs-list mailin

[issue17870] Hard to create python longs from arbitrary C integers

2013-04-29 Thread Devin Jeanpierre
New submission from Devin Jeanpierre: As far as I can tell, the only safe and correct way to convert a (for example) intptr_t to a python long is something akin to the following: size_t repsize = sizeof(intmax_t)*8 + 2; char i_buf[repsize]; // enough to fit base 2 with sign, let alone b