Skip to content

[vm/ffi] Pointer<T extends Struct> should expose an Iterable #46560

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
safasofuoglu opened this issue Jul 3, 2021 · 3 comments
Open

[vm/ffi] Pointer<T extends Struct> should expose an Iterable #46560

safasofuoglu opened this issue Jul 3, 2021 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@safasofuoglu
Copy link

safasofuoglu commented Jul 3, 2021

Having a struct definition, a pointer and an item count, it felt convenient to work with an iterator instead of elementAt and ref calls. I started with:

class NativeArray<T extends Struct> implements UnmodifiableListView<T> {
  Pointer<T> pointer;

  NativeArray(this.pointer, this.length);

  @override
  T get first {
    return pointer.elementAt(0);
  }
  ...
}

However, for the elementAt call, the compiler says T must be a compile-time constant.

Can this be made possible on userland? If not, would you consider implementing it on the sdk?

@dcharkes

@safasofuoglu safasofuoglu changed the title ffi: Implement NativeArray<T> on sdk [vm/ffi] Implement NativeArray<T> on sdk Jul 4, 2021
@dcharkes
Copy link
Contributor

dcharkes commented Jul 5, 2021

Can this be made possible on userland? If not, would you consider implementing it on the sdk?

No, we disallow unbound type arguments (see the documentation of .ref) for performance reasons.

On Pointers to integers one can use asTypedList to get an iterator. But on Pointer<T extends Struct> we have nothing yet.

(Cross reference other missing iterator in the API: #45508)

@dcharkes dcharkes changed the title [vm/ffi] Implement NativeArray<T> on sdk [vm/ffi] Pointer<T extends Struct> should expose an Iterable Jul 5, 2021
@safasofuoglu
Copy link
Author

Thanks @dcharkes , #45508 looks good.

@dcharkes
Copy link
Contributor

dcharkes commented Jul 5, 2021

Well, we still need to implement this.

@dcharkes dcharkes reopened this Jul 5, 2021
@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi labels Jul 5, 2021
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. and removed area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Feb 18, 2025
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

3 participants