Skip to content

Commit

Permalink
preamble/ptrdiff: order int types by likeliness
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mara004 committed Feb 3, 2024
1 parent b5f75d5 commit c08b0cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ctypesgen/printer_python/preamble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from ctypes import * # noqa: F401, F403

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

c_ptrdiff_t = _get_ptrdiff_t()

0 comments on commit c08b0cb

Please sign in to comment.