Repository navigation
[ffigen] Test C++ class pointers in more situations - #3745
Manar-Elhabbal7 wants to merge 19 commits into
Conversation
1139e04 to
8f93645
Compare
|
Hello @liamappelbe PTAL |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3745 +/- ##
==========================================
- Coverage 86.19% 85.46% -0.74%
==========================================
Files 324 324
Lines 21135 21081 -54
==========================================
- Hits 18218 18017 -201
- Misses 2917 3064 +147
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
I think the test failures are not related to my code changes? This show is related to Mac and Windows |
For the mac failures, you made a lot of changes to things outside pure C++ support. I wouldn't be surprised if you did accidentally break an ObjC test. Your changes to global.dart look directly related to the mac failures. Not sure what's going on with the windows failures, you might need to investigate. |
Yeah, Thanks alot @liamappelbe for the review i read the log and fixed it . it should now work well |
liamappelbe
left a comment
There was a problem hiding this comment.
Can you summarize the changes you had to make in code_generator/ in the PR description? From the PR description, readers would assume you only added more tests. You'll also need a changelog entry for those changes.
| int id; | ||
| }; | ||
|
|
||
| extern "C" { |
There was a problem hiding this comment.
Why are these cases all in extern "C"? C++ mode is supposed to support generating bindings for raw C++ functions, outside extern "C".
There was a problem hiding this comment.
good point. I tested removing extern "C", but the tests fail with undefined symbol: createAnimalPointer.
Without using extern "C", the Cpp compiler mangles the top-level function names. While ffigen generates wrapper glue for Cpp class methods, it doesn't generate glue for standalone top-level Cpp functions so dart will not find them at runtime
There was a problem hiding this comment.
Ok. That's a bug we should fix too, but let's defer that to a later PR. Filed #3820
done |
|
windows bot failures are unrelated. |
liamappelbe
left a comment
There was a problem hiding this comment.
Looks pretty good. Just some minor comments.
Can you also add tests to memory_edge_cases_test.dart or somewhere else to test that the new flows (struct fields, top level function args and returns, globals) have correct memory management?
|
I think it better to make squash to the commits , once i am sure everything works as expected I will do :) |
Summary of Changes
1. Code Generator (
code_generator/)compound.dart): Added support for C++ class pointers in struct fields by generating private storage fields (_field) and public Dart getters/setters that convert between the Dart wrapper class and the native pointer. Updated$allocateto accept the wrapper type.global.dart,type.dart,objc_*.dart): Added agenerateRelease()hook so global variable setters only emit release code for types that require it (Objective-C). This prevents incorrect release calls for C++ pointers while maintaining proper cleanup for Objective-C blocks and objects.2. Tests (
test/native_cpp_test/)Animal*) support in:AnimalOwner)globalAnimal)Fixes: #3489