Repository navigation
recipe: cffi 2.1.1 with working ffi.callback() on iOS - #129
Merged
Merged
Conversation
cffi only uses libffi's closure API on Apple when Apple's own ffi.h defines FFI_AVAILABLE_APPLE; with our upstream libffi it falls back to a W+X mmap that iOS refuses, so every ffi.callback() raised MemoryError and variadic calls returned garbage on arm64. ios-ffi-closure-alloc.patch enables libffi's trampoline-table closures on iOS (upstream python-cffi #265, unreleased). 2.1.1 rather than a 2.0.0 rebuild: PyPI ships official cffi 2.1.1 iOS wheels (cp313-cp315) without the fix, and they outrank 2.0.0. Build 1 wins the tie. soundfile: file-object reads now work on iOS, so the MemoryError tripwire test goes and the README stops calling the limit permanent.
dist-test renamed only cp-tagged wheels, so a rebuilt flet-lib* at an already published version and build number could lose to its published copy in the device test. Android's loop also missed abi3; both loops now match cpXY-cpXY, cpXY-abi3 and py3-none.
ffi.callback() on iOS
ubuntu-latest will move to 26.04. The Android lane (NDK builds, KVM emulator) runs there, so that move would change every recipe's CI at once and look like recipe breakage. Pin it, like macOS is pinned to macos-26, and bump on purpose.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
cffi2.1.1 withffi.callback()working on iOS, plus two CI fixes: testing rebuiltflet-lib*wheels, and pinned Ubuntu runners.Why
On iOS every
ffi.callback()raisedMemoryError: Cannot allocate write+execute memory for ffi.callback(), and variadic ABI-mode calls returned garbage on arm64. cffi uses libffi's closure API on Apple only whenFFI_AVAILABLE_APPLEis defined, which only Apple's own macOSffi.hdoes. With the upstream libffi our iOS builds use, cffi falls back to its own allocator, which maps writable+executable memory, and iOS refuses. libffi itself needs no such memory there (arm64 uses trampoline tables, which is why CPython's ctypes callbacks work).Upstream fixed this in python-cffi/cffi#265, merged but not in any release yet.
Changes
recipes/cffi: 2.1.1, build 1, newios-ffi-closure-alloc.patchenablingffi_closure_alloc/ffi_prep_closure_loc/ffi_prep_cif_varunderTARGET_OS_IPHONE(Android's preprocessed source is byte-identical).mobile.patchregenerated for 2.1.1, no behaviour change.TARGET_OS_IPHONEvariant rather than #265 verbatim: forge's non-interactivepatchreverse-applies a hunk it sees as already present, so a future bump to a release containing #265 would silently remove the fix. This variant lands as dead code instead. Drop it once a release includes #265.qsort), a callback from a native thread, 3000 closures allocated and freed, and a variadicsnprintf. Four of five fail on the old wheels.recipes/soundfile: file-object reads (sf.read(io.BytesIO(...))) now work on iOS. Removed the test asserting the iOSMemoryError, dropped the iOS skip, updated README, example README and a comment.dist-test/now bumpspy3-none(build.shflet-lib*) wheels to build 9999 too, and Android's loop also matchesabi3. Before, a rebuiltflet-lib*at an already-published version and build number could lose to its published copy in the device test.ubuntu-24.04(whatubuntu-latestresolves to today).ubuntu-latestwill move to 26.04, which would change the Android lane (NDK builds, KVM emulator) for every recipe at once; macOS is already pinned tomacos-26.Validation
packages=cffi:,soundfile:,prebuild_recipes=cffi): all green on the fork. Note soundfile's iOS tests need the new cffi, so they only pass when cffi is built in the same run or published.MemoryErrorandsnprintfreturns garbage on forge 2.0.0-1 and PyPI 2.1.1; all pass with this build.Consumer notes
Apps get working
ffi.callback()on iOS automatically once cffi 2.1.1-1 is on pypi.flet.dev; for soundfile that means in-memory reads work on both platforms. Details:recipes/soundfile/README.md.