This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Devin Jeanpierre
Recipients Devin Jeanpierre
Date 2013-04-29.20:57:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1367269025.02.0.400879045482.issue17870@psf.upfronthosting.co.za>
In-reply-to
Content
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 base 1
    snprintf(i_buf, repsize, "%ij", (intmax_t) myinteger);
    return PyLong_FromString(i_buf, NULL, 10);

Does this not seem absurd?

PyLong_FromIntMax_t(myinteger) would be great. Or maybe even better would be PyLong_FromBytes(&myinteger, sizeof(myinteger)) ?

This is problematic because many things that can interact with the Python C-API do not use the C types like "long long" or "int". Instead they might use the equivalents of intptr_t and int32_t, which are more reliably sized.
History
Date User Action Args
2013-04-29 20:57:05Devin Jeanpierresetrecipients: + Devin Jeanpierre
2013-04-29 20:57:05Devin Jeanpierresetmessageid: <1367269025.02.0.400879045482.issue17870@psf.upfronthosting.co.za>
2013-04-29 20:57:04Devin Jeanpierrelinkissue17870 messages
2013-04-29 20:57:04Devin Jeanpierrecreate