Message247565
A Python int larger than a C int but smaller than a C long is silently truncated to int when passed to a ctypes function without C type information attached.
Ints longer than C long fail with an OverflowError; I believe the same should happen for numbers that don't fit in a C int.
Reproducer (for 64-bit systems):
from ctypes import cdll, ArgumentError
libc = cdll.LoadLibrary("libc.so.6")
# Silently truncated
libc.printf(b"%x\n", 0x1234567890)
try:
# OverflowError raised
libc.printf(b"%x\n", 2 ** 64)
except ArgumentError as e:
print(e)
see callproc.c, function ConvParam, after the PyLong_Check. |
|
Date |
User |
Action |
Args |
2015-07-29 12:11:26 | petr.viktorin | set | recipients:
+ petr.viktorin |
2015-07-29 12:11:26 | petr.viktorin | set | messageid: <1438171886.06.0.632497745661.issue24747@psf.upfronthosting.co.za> |
2015-07-29 12:11:25 | petr.viktorin | link | issue24747 messages |
2015-07-29 12:11:24 | petr.viktorin | create | |
|