Skip to content

Commit c08b0cb

Browse files
committed
preamble/ptrdiff: order int types by likeliness
We are most likely on a platform that uses 64-bit pointers. Expectably, 16-bit pointers are not a realistic target for ctypesgen, but retain it anyways to be C standard correct. Note, the point of this template is to achieve universal bindings. If bindings were target platform specific, the ptrdiff_t constant pulled in from stddef.h would be fine.
1 parent b5f75d5 commit c08b0cb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ctypesgen/printer_python/preamble.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from ctypes import * # noqa: F401, F403
33

44
def _get_ptrdiff_t():
5-
int_types = [ctypes.c_int16, ctypes.c_int32]
5+
int_types = [ctypes.c_int32, ctypes.c_int16]
66
# Some builds of ctypes do not provide c_int64. Assumably, this means the platform doesn't have 64-bit pointers.
77
if hasattr(ctypes, "c_int64"):
8-
int_types.append(ctypes.c_int64)
8+
int_types.insert(0, ctypes.c_int64)
99
return next((t for t in int_types if sizeof(t) == sizeof(c_size_t)), None)
1010

1111
c_ptrdiff_t = _get_ptrdiff_t()

0 commit comments

Comments
 (0)