Message188103
| 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:05 | Devin Jeanpierre | set | recipients:
+ Devin Jeanpierre |
| 2013年04月29日 20:57:05 | Devin Jeanpierre | set | messageid: <1367269025.02.0.400879045482.issue17870@psf.upfronthosting.co.za> |
| 2013年04月29日 20:57:04 | Devin Jeanpierre | link | issue17870 messages |
| 2013年04月29日 20:57:04 | Devin Jeanpierre | create |
|