MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / _ptr_as_int

Function _ptr_as_int

lean_py/_runtime.py:40–53  ·  view source on GitHub ↗

Convert any ctypes pointer-like value to a raw integer. macOS ctypes has a long-standing quirk: passing a `POINTER(struct)` instance directly to a `c_void_p`-typed parameter sometimes yields a corrupted value at the C boundary (the bug is reproducible with `restype = POINTER(...)` c

(p)

Source from the content-addressed store, hash-verified

38
39
40def _ptr_as_int(p) -> int:
41 """Convert any ctypes pointer-like value to a raw integer.
42
43 macOS ctypes has a long-standing quirk: passing a `POINTER(struct)`
44 instance directly to a `c_void_p`-typed parameter sometimes yields
45 a corrupted value at the C boundary (the bug is reproducible with
46 `restype = POINTER(...)` chained into another call). Using the raw
47 integer pointer value side-steps the issue entirely.
48 """
49 if p is None:
50 return 0
51 if isinstance(p, int):
52 return p
53 return ctypes.cast(p, c_void_p).value or 0
54
55
56# ============================================================================

Callers 5

_callFunction · 0.90
_mkFunction · 0.90
lean_inc_refFunction · 0.85
lean_inc_ref_nFunction · 0.85
lean_dec_refFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected