Skip to content

[vm/ffi] asTypedList for Pointer<T extends AbiSpecificInteger> #54119

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

Open
dcharkes opened this issue Nov 21, 2023 · 0 comments
Open

[vm/ffi] asTypedList for Pointer<T extends AbiSpecificInteger> #54119

dcharkes opened this issue Nov 21, 2023 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi P3 A lower priority bug or feature request triaged Issue has been triaged by sub team

Comments

@dcharkes
Copy link
Contributor

Once #44589 is addressed, there is a question about how to provide a Dart API to users which has a size_t* in C.

For uint32_t*, the Dart API can be Uint32List. But for a type that is architecture dependent, we require runtime polymorphism at the moment. We could make the API return List<int> and take List<int> and try to cast, but polymorphism makes code slow.

We probably also don't want to introduce a SizeList, IntptrList, UintptrList to dart:typed_data. We introduced AbiSpecificInteger to dart:ffi to avoid hardcoding every possible type. Would it be possible to introduce a AbiSpecificTypedData<AbiSpecificInteger> to dart:typed_data or dart:ffi maybe?

Use case in ICU4X:

 class SizeList extends ffi.Struct {
  external ffi.Pointer<ffi.Size> _bytes;

  @ffi.Size()
  external int _length;

  // ignore: unused_element
  SizeList get _asDart => this;  // Return type Uint32List or Uint64List from dart:typed_data.

https://github.com/unicode-org/icu4x/blob/1c0b95ef95d869841fec45ed0e7b107b47c8afad/ffi/capi/dart/package/lib/src/lib.g.dart#L137-L144

Thanks @robertbastian for reporting!

Any thoughts @mkustermann @mraleph @lrhn ?

@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Nov 21, 2023
@a-siva a-siva added P3 A lower priority bug or feature request triaged Issue has been triaged by sub team labels Nov 30, 2023
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 P3 A lower priority bug or feature request triaged Issue has been triaged by sub team
Projects
None yet
Development

No branches or pull requests

2 participants