-
Notifications
You must be signed in to change notification settings - Fork 58
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
ffi: linux support. ci: add build + integration test to CI. #144
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Without this fix, the Linux build segfaults when calling `readBarcode(s)` or `encodeBarcode`. I did some investigation in gdb and it's not totally clear what's going on. The `param` arg usually looks corrupted -- maybe there's some calling convention mismatch though that seems unlikely. More likely, the pointer backing the value returned from e.g. `toEncodeBarcodeParams` is getting freed immediately; maybe dart has some new short-liveness scope rule. Anyway passing the params as a basic owned pointer works.
Adds a `unique_dart_ptr` smart pointer that can safely take ownership of and free Dart-allocated pointers.
The backing memory behind `EncodeResult::text` is free'd when `EncodeBarcodeParams` is dropped, causing use-after-free when Dart tries to UTF-8 encode the text later on.
`dart_allocator` is a `std::allocator` impl that can: (1) safely allocate memory in C++ that is later freed inside the Dart VM (2) safely free memory in C++ that was earlier allocated inside the Dart VM Returning allocated memory to Dart or freeing memory allocated from within Dart in C++ must be done _very carefully_. For this to be safe, both C++ and Dart must use the same allocator on each side. Since C++ may use a different allocator for `new`/`free`/other std types: * Manage all memory from/to dart using `dart_allocator` (in `dart_alloc.h`). * Avoid returning memory from `new` to Dart. * Avoid freeing memory from Dart with `delete`.
cc @khoren93 |
Hey @phlip9 Thanks for the great work on fixing up the native glue code and adding Linux support. The PR has been merged! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey again! Back with another pass at fixing up the native glue code. I recently needed to run our app on a Linux machine and encountered a crash with
flutter_zxing
whenever it calledencodeBarcode
. With this PR, I can now confidently runflutter_zxing
on Linux w/o issues!Overview
This PR:
flutter build
andflutter test integration_test
Github CI workflows running across android, iOS, macOS, and linux. Windows build fails to compile though.dart_free
. Memory freed in Dart from C++ must be allocated withdart_malloc
.noexcept
.I recommend reviewing by commit.