Skip to content
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

'C interop using dart:ffi' page mention package:ffi #3084

Open
Tracked by #5475
dcharkes opened this issue Mar 19, 2021 · 7 comments
Open
Tracked by #5475

'C interop using dart:ffi' page mention package:ffi #3084

dcharkes opened this issue Mar 19, 2021 · 7 comments
Assignees
Labels
a.libraries Relating to the Dart standard libraries. act.question Relates to issues that writers need SME help dev.ffi Relates to foreign function interface to integrate native code with Dart dev.interop Relates to use of native code as part of your Dart app e1-hours Can complete in < 8 hours of normal, not dedicated, work fix.examples Adds or changes example p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged

Comments

@dcharkes
Copy link
Contributor

We should get package:ffi mentioned (utf conversions, memory management) on https://dart.dev/guides/libraries/c-interop.

cc @mit-mit

@mit-mit
Copy link
Member

mit-mit commented Mar 19, 2021

+1

@kwalrath kwalrath added e0-minutes Can complete in < 60 minutes of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible. e1-hours Can complete in < 8 hours of normal, not dedicated, work labels Mar 19, 2021
@kwalrath
Copy link
Contributor

kwalrath commented Mar 19, 2021

There are a couple of different approaches we could take, depending on how much we want to emphasize package:ffi:

  1. Add package:ffi (and maybe package:ffigen?) to the first paragraph, and link to its docs from the second paragraph. Maybe add (or link to) examples of using it.

  2. Treat it like we do package:ffigen, where's it's covered only in a separate section.

We should also add package:ffi to https://dart.dev/guides/libraries/useful-libraries#packages-that-correspond-to-sdk-libraries, and dart:ffi to https://dart.dev/guides/libraries.

@mit-mit
Copy link
Member

mit-mit commented Mar 22, 2021

In practice, I'd think that anyone writing FFI code will be using the package. So I'd just add some example of using it for utf conversions and freeing memory.

@kwalrath
Copy link
Contributor

Where's some good sample code we can use?

@dcharkes
Copy link
Contributor Author

The samples repo contains code, but misses some memory management.

https://github.com/dart-lang/samples/blob/master/ffi/structs/structs.dart#L65-L69

Here's a version of reverse with memory management:

void main(List<String> arguments) {
  final dylib = DynamicLibrary.open('some/path/to/a/dynamic/library');

  final hello = 'Hello'.toNativeUtf8();
  final reverse = dylib.lookupFunction<Void Function(Pointer<Utf8>),
      void Function(Pointer<Utf8>)>('reverse');
  reverse(hello);
  print(hello.toDartString());
  malloc.free(hello);
}

@atsansone atsansone added a.libraries Relating to the Dart standard libraries. fix.examples Adds or changes example dev.ffi Relates to foreign function interface to integrate native code with Dart st.triage.ltw Indicates Lead Tech Writer has triaged labels Apr 6, 2023
@atsansone
Copy link
Contributor

@dcharkes : I'm having difficulty finding information on package:ffi that's not dart:ffi. Did something change between when this issue was filed and now? Should I close this?

@atsansone atsansone added the act.question Relates to issues that writers need SME help label Apr 12, 2023
@dcharkes
Copy link
Contributor Author

I'm having difficulty finding information on package:ffi that's not dart:ffi.

The API documentation for package:ffi is here: https://pub.dev/documentation/ffi/latest/ffi/ffi-library.html

Did something change between when this issue was filed and now? Should I close this?

No and no, package:ffi is not yet mentioned on https://dart.dev/guides/libraries/c-interop.

@atsansone atsansone added the dev.interop Relates to use of native code as part of your Dart app label Apr 29, 2023
@atsansone atsansone removed the e0-minutes Can complete in < 60 minutes of normal, not dedicated, work label Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.libraries Relating to the Dart standard libraries. act.question Relates to issues that writers need SME help dev.ffi Relates to foreign function interface to integrate native code with Dart dev.interop Relates to use of native code as part of your Dart app e1-hours Can complete in < 8 hours of normal, not dedicated, work fix.examples Adds or changes example p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged
Projects
None yet
Development

No branches or pull requests

4 participants