Skip to content

dart:ffi remove Pointer.offsetBy #35883

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

Closed
dcharkes opened this issue Feb 7, 2019 · 5 comments
Closed

dart:ffi remove Pointer.offsetBy #35883

dcharkes opened this issue Feb 7, 2019 · 5 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi type-design
Milestone

Comments

@dcharkes
Copy link
Contributor

dcharkes commented Feb 7, 2019

C++ uses the size of the type when doing pointer arithmetic, we support this with Pointer.elementAt(). It only works for Pointer<T> where T has a size. This is the preferred way of using an array of elements.

Pointer.offsetBy() enables taking arbitrary offsets (in bytes) on any Pointer. This is not the preferred way, possibly we can leave it out completely.

@dcharkes dcharkes added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Feb 7, 2019
@sjindel-google
Copy link
Contributor

We will remove it.

@dcharkes
Copy link
Contributor Author

We'll change offsetBy to _offsetBy after the Structs API revamp has landed (it's references in the frontend, so it will conflict when changed).

@sjindel-google
Copy link
Contributor

What was the reasoning to remove it?

@dcharkes
Copy link
Contributor Author

I think the reasoning was that using offsetBy is error-prone (creating unaligned pointers). If people wanted to do that, they should explicitly convert to Pointer<Uint8> with casting, do the pointer arithmetic, and cast back to the original pointer.

We could even provide that in package:ffi as an add on (which users would import manually):

extension PointerArithmetic<T extends NativeType> on Pointer<T> {
  Pointer<T> offsetBy(int numBytes) => cast<Uint8>().elementAt(numBytes).cast();
}

@dcharkes dcharkes added this to the D26 Release milestone Sep 30, 2019
@dcharkes
Copy link
Contributor Author

dcharkes commented Oct 7, 2019

We'll remove it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi type-design
Projects
None yet
Development

No branches or pull requests

2 participants