Skip to content

[vm/ffi] Expose dart_api.h and dart_native_api.h via dart:ffi? #40607

@dcharkes

Description

@dcharkes

We could expose some symbols from dart_native_api.h and dart_api.h via dart:ffi.

This would solve two problems:

This would change the usage of dart_api.h and dart_native_api.h to manual dynamic linking passing back function pointers.

Static linking (current situation)

#include "include/dart_api.h"
#include "include/dart_native_api.h"

void SomeCode(){
  const bool result = Dart_PostCObject(send_port, &dart_object);
}

Manual dynamic linking (proposal)

// For the typedefs, but don't use the function pointers.
#include "include/dart_api.h"
#include "include/dart_native_api.h"

typedef bool (*Dart_PostCObjectType)(Dart_Port port_id, Dart_CObject* message);
Dart_PostCObjectType Dart_PostCObject_;

DART_EXPORT void RegisterDart_PostCObject(
    Dart_PostCObjectType function_pointer) {
  Dart_PostCObject_ = function_pointer;
}

void someCode(Dart_Port send_port, Dart_CObject dart_object) {
  const bool result = Dart_PostCObject_(send_port, &dart_object);
}
// dart:ffi
external Pointer<NativeFunction<...>> nativeApiDart_PostCObjectAddess();

// user code
final registerDart_PostCObject = dl.lookupFunction<
        Void Function(Pointer<NativeFunction<...>> functionPointer),
        void Function(Pointer<NativeFunction<...>> functionPointer)>(
    'RegisterDart_PostCObject');

registerDart_PostCObject(nativeApiDart_PostCObjectAddess());

cc @mkustermann @mraleph @derolf

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