-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: ctypes callbacks crash on macOS ARM64 #112
Copy link
Copy link
Open
Labels
aigenAI-generated contentAI-generated content
Description
Created by Claude Opus 4 during discussion with @metaist.
Problem
ctypes callbacks crash with "Bus error: 10" on macOS ARM64 when using Cosmopolitan Python. This affects all Python versions, not just 3.14.
Reproduction:
import ctypes
CFUNC = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int)
def py_callback(x):
return x * 2
cb = CFUNC(py_callback) # Bus error hereRoot Cause
Cosmopolitan's ffi_closure_alloc implementation has issues on macOS ARM64. The function is used internally by ctypes to create callable wrappers around Python functions.
Related
- Python 3.14 added a warmup call to
ffi_closure_allocduring_ctypesmodule init (cpython#128485), which causedimport ctypesto hang. This was fixed in fix: ctypes callbacks crash on macOS ARM64 #112 by removing the warmup code. - The underlying
ffi_closure_allocissue remains and affects callback creation on all Python versions.
Impact
- Basic ctypes usage works (c_int, Structure, Array, etc.)
- Loading C libraries via ctypes does not work (expected - no dlopen)
- Creating Python callbacks for C code does not work on macOS ARM64
Workaround
Avoid using ctypes.CFUNCTYPE callbacks on macOS ARM64. Use alternative approaches like:
- Pre-compiled C extensions via cosmoext
- Pure Python implementations
Notes
- This may be a Cosmopolitan libffi bug that should be reported upstream
- Linux x86_64 behavior is untested for this specific issue
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
aigenAI-generated contentAI-generated content