◐ Shell
clean mode source ↗

Message 188111 - Python tracker

"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(sizeof(intptr_t) <= sizeof(PY_LONG_LONG));
        return PyLong_FromLongLong((PY_LONG_LONG)value);
    }
}

The "if (sizeof(intptr_t) == sizeof(long))" should be optimized by your compiler.

I don't know if Python should provide such function. What is your use case for intptr_t?

It looks like intptr_t is only really used in the implementation of os.spawnv() and os.spawnve(). Extract:

#if SIZEOF_LONG == SIZEOF_VOID_P
        return Py_BuildValue("l", (long) spawnval);
#else
        return Py_BuildValue("L", (PY_LONG_LONG) spawnval);
#endif