Skip to content

Retain and autorelease associated objects properly #331

Merged
davidchisnall merged 3 commits intomasterfrom
associate-retain-getter
Mar 16, 2025
Merged

Retain and autorelease associated objects properly #331
davidchisnall merged 3 commits intomasterfrom
associate-retain-getter

Conversation

@hmelder
Copy link
Copy Markdown
Member

@hmelder hmelder commented Mar 15, 2025

Apple's objc4 runtime expands the policy bits into the following
subcategories:

enum {
    OBJC_ASSOCIATION_SETTER_ASSIGN      = 0,
    OBJC_ASSOCIATION_SETTER_RETAIN      = 1,
    OBJC_ASSOCIATION_SETTER_COPY        = 3,
    OBJC_ASSOCIATION_GETTER_READ        = (0 << 8),
    OBJC_ASSOCIATION_GETTER_RETAIN      = (1 << 8),
    OBJC_ASSOCIATION_GETTER_AUTORELEASE = (2 << 8)
};

where

OBJC_ASSOCIATION_ASSIGN = 0
OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1
OBJC_ASSOCIATION_COPY_NONATOMIC = 3
OBJC_ASSOCIATION_RETAIN = 01401
OBJC_ASSOCIATION_COPY = 01403 // No idea why this is in octal

This means that on OBJC_ASSOCIATION_{RETAIN, COPY} and the
NONATOMIC counterpart, we need to retain and autorelease the associated
object before returning it in objc_getAssociatedObject.

hmelder added 2 commits March 15, 2025 12:42
Apple's objc4 runtime expands the policy bits into the following
subcategories:

```
enum {
    OBJC_ASSOCIATION_SETTER_ASSIGN      = 0,
    OBJC_ASSOCIATION_SETTER_RETAIN      = 1,
    OBJC_ASSOCIATION_SETTER_COPY        = 3,
    OBJC_ASSOCIATION_GETTER_READ        = (0 << 8),
    OBJC_ASSOCIATION_GETTER_RETAIN      = (1 << 8),
    OBJC_ASSOCIATION_GETTER_AUTORELEASE = (2 << 8)
};
```

where

OBJC_ASSOCIATION_ASSIGN = 0
OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1
OBJC_ASSOCIATION_COPY_NONATOMIC = 3
OBJC_ASSOCIATION_RETAIN = 01401
OBJC_ASSOCIATION_COPY = 01403

This means that on OBJC_ASSOCIATION_{RETAIN, COPY} and the
NONATOMIC counterpart, we need to retain and autorelease the associated
object before returning it in objc_getAssociatedObject.
@hmelder hmelder changed the title Associate retain getter Retain and autorelease associated objects properly Mar 15, 2025
@hmelder hmelder mentioned this pull request Mar 15, 2025
@hmelder hmelder assigned hmelder and unassigned hmelder Mar 15, 2025
@hmelder hmelder requested a review from davidchisnall March 15, 2025 05:49
@davidchisnall
Copy link
Copy Markdown
Member

The FreeBSD CI needs version bumping, can you add that s9 we can merge with clean CI?

@hmelder
Copy link
Copy Markdown
Member Author

hmelder commented Mar 16, 2025

Do you know why libcxxrt_freebsd freebsd_instance:family/freebsd-13-3 and libcxxrt_freebsd freebsd_instance:family/freebsd-14-0 are still expected despite being deleted in .cirrus.yaml?

@davidchisnall
Copy link
Copy Markdown
Member

Yes, the GitHub branch things are different.

@davidchisnall
Copy link
Copy Markdown
Member

Looks like I can’t add them to the branch protection rules until the PR is merged.

@hmelder hmelder force-pushed the associate-retain-getter branch from 6c74c7c to 28ab03a Compare March 16, 2025 15:48
@hmelder
Copy link
Copy Markdown
Member Author

hmelder commented Mar 16, 2025

Looks like I can’t add them to the branch protection rules until the PR is merged.

And we cannot merge the PR without the being green. But it still waits for libcxxrt_freebsd freebsd_instance:family/freebsd-13-3.

@davidchisnall davidchisnall merged commit 1a0f5ac into master Mar 16, 2025
91 checks passed
@davidchisnall davidchisnall deleted the associate-retain-getter branch March 16, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants