Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

ObjC static functions #633

Merged
merged 12 commits into from
Nov 2, 2023
Merged

ObjC static functions #633

merged 12 commits into from
Nov 2, 2023

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Oct 31, 2023

Use Dart wrapper objects when passing args or receiving results from ObjC static functions.

For ref counting, we assume functions do not return a retained reference by default (so we have to retain it ourselves). We also parse the function annotations, and if we see a NS_RETURNS_RETAINED, then the function is returning a retained reference, so we don't have to manually retain it in that case.

Fixes dart-lang/native#496, dart-lang/native#308

@liamappelbe liamappelbe marked this pull request as ready for review November 1, 2023 04:45
@liamappelbe liamappelbe changed the title WIP: ObjC static functions ObjC static functions Nov 1, 2023
Copy link
Contributor

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

Thanks @liamappelbe!


@end

StaticFuncTestObj* staticFuncOfObject(StaticFuncTestObj* a) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these (the actual functions used in the test) up, and the helper object down? Or does ObjC require an ordering?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Just need to have the interface decl above them I think.

calloc.free(gcNow);
}

Pointer<Int32> staticFuncOfObjectRefCountTest(Allocator alloc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this only has one call site, is this because of scoping that it's in a separate function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I use the function scoping and doGC() to ensure that all the wrapper objects are collected.

@liamappelbe liamappelbe merged commit 14f0e40 into main Nov 2, 2023
6 checks passed
@liamappelbe liamappelbe deleted the objcstaticfunc branch November 2, 2023 02:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

C-style functions consuming Objective-C classes should allow the Objective-C class to be passed
2 participants