[breaking change] Add an nullable nativeFree
getter to Allocator
#55571
Labels
area-vm
Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
breaking-change-request
This tracks requests for feedback on breaking changes
library-ffi
Change Intent
Add a nullable
nativeFree
getter toAllocator
to ease working with native finalizers.Justification
This would simplify the API for adding native finalizers. The
allocator
argument can be defaulted to e.g.malloc
, and methods using this allocator could attach native finalizers to the objects allocated usingallocator.nativeFree
if it's notnull
.For example:
Impact
We provide some allocators in
package:ffi
, but a search here on GitHub shows that not many people implementAllocator
themselves.Older versions of
package:ffi
will stop working on newer SDKs, and we don't have a way of retroactively adding an SDK upper bound to those versions.Most people should just be able to update their
package:ffi
, but apps that have pinned their deps might see compile errors.Mitigation
package:ffi
'sMallocAllocator
andCallocAllocator
already havenativeFree
getters.We can safely add
Pointer<NativeFinalizerFunction>? get nativeFree => null
to all the existingAllocator
subclasses that have a no-opfree
likeArena
.Alternatives Considered
We could introduce a
NativeFreeableAllocator implements Allocator
that has anativeFree
getter, and this was the original design for this PR: dart-archive/ffi#203However @lrhn raised some issues with this design here and here.
Change Timeline
No response
Associated CLs
No response
The text was updated successfully, but these errors were encountered: