Skip to content

[vm/ffi] Disallow adding finalizers to Pointer #45071

@dcharkes

Description

@dcharkes

We should disallow Pointer in Dart_NewWeakPersistentHandle and Dart_NewFinalizableHandle.

  1. Pointers do not have identity. We might want to optimize them to just be integers later.

  2. Also the nested structs and inline arrays representation does not keep original pointers alive:

class Foo extends Struct {
  external Bar bar;
}
class Bar extends Struct {
  Int32()
  external int a;
}

void main(){
  Pointer<Foo> fooPointer = calloc();
  // Attach native finalizer to `fooPointer` using `Dart_NewWeakPersistentHandle` or `Dart_NewFinalizableHandle`.
  Foo foo = fooPointer.ref;
  Bar bar = foo.bar;
  // GC
  bar.a; // undefined behavior.
}

This is a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions