forked from ctypesgen/ctypesgen
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify ptrdiff getter, move tasks out of actual preamble
- Loading branch information
Showing
2 changed files
with
7 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,11 @@ | ||
# TODO | ||
# - add c_ptrdiff_t only on as-needed basis | ||
# - Avoid ctypes glob import (pollutes namespace) | ||
|
||
import ctypes | ||
from ctypes import * # noqa: F401, F403 | ||
|
||
def _get_ptrdiff_t(): | ||
|
||
int_types = (ctypes.c_int16, ctypes.c_int32) | ||
int_types = [ctypes.c_int16, ctypes.c_int32] | ||
# 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"): | ||
# Some builds of ctypes apparently do not have ctypes.c_int64 | ||
# defined; it's a pretty good bet that these builds do not | ||
# have 64-bit pointers. | ||
int_types += (ctypes.c_int64,) | ||
|
||
c_ptrdiff_t = None | ||
for t in int_types: | ||
if ctypes.sizeof(t) == ctypes.sizeof(ctypes.c_size_t): | ||
c_ptrdiff_t = t | ||
|
||
return c_ptrdiff_t | ||
int_types.append(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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters