Page URL: https://www.dartlang.org/articles/server/native-extensions
Page source: https://github.com/dart-lang/site-www/tree/master/src/_articles/server/native-extensions.md
Description of issue: wrappedRandomArray implements an old version of the Dart_NativeMessageHandler function typedef. Specifically, it expects a second argument reply_port_id, which was removed by https://github.com/dart-lang/sdk/commit/2f27215203f521960d0dbcee0a674fef96312a0b (see specific line)
The example code needs to be edited to conform to the latest API; specifically, it must send a reply port for use by the native message handler, perhaps among the elements of the array message.
It turned out that there were quite a few other issues with the sample code, including, among other things:
random_array, called as randomArray).Type enum moved out of Dart_CObject thus making accesses like Dart_CObject::kArray need to change to Dart_CObject_kArray in global scope, etc.)I ended up copying and pasting the sample code and getting it running on my box. I now have something that runs, but I still have some outstanding questions about my changes that I'd like to look into. Once I'm done with that I can make a pull request with suggested changes to resolve this issue if you want.
Thanks very much, @ianwarnold. We'd done a quick review of this page and thought it was mostly valid, but obviously we didn't test the source code.
We'd _love_ to get your source files so we can auto-include the code and get CI testing for it (static analysis, at least; maybe real tests). We have infrastructure for this, but it's not trivial to get set up to use it, so unless you're really into infrastructure, I'd be happy to incorporate your code.
/cc @whesse @a-siva
@kwalrath I don't think I've the time to look into setting up considerable infrastructure right now, so for the time being here's a repository with the updated code:
https://github.com/ianwarnold/dart_native_example
I tried to be minimally invasive in my changes to the sample as written before, although this might've resulted in things no longer being idiomatic uses of the new API; I'm not sure. I guess I'm saying obviously that you should feel free to make any changes you see fit. In particular I do have one TODO in there that I wasn't sure if/how I wanted to resolve (sample_extension.cpp:101).
Thanks.
This is very helpful. Thanks, @ianwarnold!
@a-siva Would it be possible to get someone to review the code in https://github.com/ianwarnold/dart_native_example, perhaps creating a PR/issue (or commenting here) about any changes that should be made?
Ok will do.
@a-siva could this be done soon?
It looks like we'll remove this page in favor of the dart:ffi API, which is described in https://dart.dev/guides/libraries/c-interop.
@ianwarnold thanks very much for the report and the source code. You caught us when the old way was being deprecated, and the new way wasn't working yet. :/
Most helpful comment
Ok will do.