Closed
Description
Bug report
Using ctypes with variadic functions on ARM64 macOS machines seems to improperly pass the arguments, leading to truncation.
Minimal repro:
>>> import ctypes
>>> from ctypes import util
>>> libc = ctypes.CDLL(util.find_library("c"))
>>> libc.printf(b"hello %d world\n", 128_000_000)
hello 0 world
14
This happens regardless of casting it to a ctypes.c_int
explicitly or not.
>>> libc.printf(b"hello %ld world\n", ctypes.c_int(1))
hello 0 world
14
On my regular machine (in this case an x64 Windows machine) it works as expected:
>>> import ctypes
>>> libc = ctypes.cdll.msvcrt
>>> libc.printf(b"hello %d world\n", 128_000_000)
hello 128000000 world
22
Your environment
I do not personally have a macOS machine, but I got a few others who did have a machine test for me. Their versions were as follows:
Machine 1:
Python 3.10.1, macOS 12.3.1 (21E258)
Machine 2:
Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23)
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
macOS-12.2.1-arm64-arm-64bit
Machine 3:
~ % python3 --version
Python 3.9.10
~ % sw_vers
ProductName: macOS
ProductVersion: 12.3.1
BuildVersion: 21E258
- CPython versions tested on: 3.9, 3.10
- Operating system and architecture: ARM64 Apple Silicon macOS