Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vm/ffi] allocate free when adding finalizers in Dart #43038

Closed
dcharkes opened this issue Aug 13, 2020 · 1 comment
Closed

[vm/ffi] allocate free when adding finalizers in Dart #43038

dcharkes opened this issue Aug 13, 2020 · 1 comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@dcharkes
Copy link
Contributor

dcharkes commented Aug 13, 2020

We have exposed native finalizers through dart:ffi (6544c69 and 7eac9f3), which enables users to write finalizers in C/C++.

We might still want to expose finalizers in Dart as well (#35770). However, on Windows looking up free in different dynamic libraries and the DartVM results in a different free that can only be called on memory allocated with the malloc in the corresponding dynamic library.

Therefore, we use a Windows API for allocating and freeing on Windows currently in package:ffi:

void free(Pointer pointer) {
  if (Platform.isWindows) {
    if (winHeapFree(processHeap, /*flags=*/ 0, pointer) == 0) {
      throw ArgumentError("Could not free $pointer.");
    }
  } else {
    posixFree(pointer);
  }
}

However, this function does not have the same signature as malloc and free.

We should consider having a free-symbol in the DartVM that uses mimics this behavior but just has the free-signature. (The same for allocate.)

And then it might make more sense to move allocate/free to dart:ffi instead of package:ffi.

@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Aug 13, 2020
@dcharkes
Copy link
Contributor Author

We have worked around this by using CoTaskMemAlloc instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

1 participant