Skip to content

Commit 100c52f

Browse files
committed
Fix the pointer size determination.
1 parent 07ea52a commit 100c52f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Lib/test/audit-tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ def test_ctypes_call_function():
311311

312312
with TestHook() as hook:
313313
_ctypes.call_function(ctypes._memmove_addr, (0, 0, 0))
314-
assert ("ctypes.call_function", (ctypes._memmove_addr, (0, 0, 0))) in hook.seen
314+
assert ("ctypes.call_function", (ctypes._memmove_addr, (0, 0, 0))) in hook.seen, f"{ctypes._memmove_addr=} {hook.seen=}"
315315

316316
ctypes.CFUNCTYPE(ctypes.c_voidp)(ctypes._memset_addr)(1, 0, 0)
317-
assert ("ctypes.call_function", (ctypes._memset_addr, (1, 0, 0))) in hook.seen
317+
assert ("ctypes.call_function", (ctypes._memset_addr, (1, 0, 0))) in hook.seen, f"{ctypes._memset_addr=} {hook.seen=}"
318318

319319
with TestHook() as hook:
320320
ctypes.cast(ctypes.c_voidp(0), ctypes.POINTER(ctypes.c_char))

Modules/_ctypes/callproc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,17 @@ PyObject *_ctypes_callproc(ctypes_state *st,
11991199
PyObject *retval = NULL;
12001200

12011201
// Both call_function and call_cdeclfunction call us:
1202+
#if SIZEOF_VOID_P == SIZEOF_LONG
1203+
if (PySys_Audit("ctypes.call_function", "kO",
1204+
(unsigned long)pProc, argtuple) < 0) {
1205+
#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
12021206
if (PySys_Audit("ctypes.call_function", "KO",
12031207
(unsigned long long)pProc, argtuple) < 0) {
1208+
#else
1209+
# warning "unexpected pointer size, you may see odd values in audit hooks"
1210+
if (PySys_Audit("ctypes.call_function", "nO",
1211+
(Py_ssize_t)pProc, argtuple) < 0) {
1212+
#endif
12041213
return NULL;
12051214
}
12061215

0 commit comments

Comments
 (0)