Skip to content
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

macOS: Use objc2-foundation #107

Merged
merged 1 commit into from
May 15, 2024
Merged

macOS: Use objc2-foundation #107

merged 1 commit into from
May 15, 2024

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented May 15, 2024

The objc2 project is the successor to objc and cocoa, and contains automatically generated bindings to the Foundation framework (and many other frameworks), while ensuring that memory management rules are upheld.

This allows trash to get rid of a bunch of complex unsafe code and error cases that can't happen (most of these are cases where the APIs are documented to not return NULL).

Comment on lines -105 to -107
// WARNING: I don't know why but if we try to call release on the url, it sometimes
// crashes with SIGSEGV, so we instead don't try to release the url
// let url = OwnedObject { ptr: url };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason is that fileURLWithPath: returns an autoreleased instance, as documented in the memory management rules. objc2 handles these details for you.

src/macos.rs Show resolved Hide resolved
src/macos.rs Show resolved Hide resolved
@madsmtm
Copy link
Contributor Author

madsmtm commented May 15, 2024

Not sure why the Windows build failed, but I don't think it's my fault?

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

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

This is fantastic, thanks so much!

The new version is indeed much simpler, and I for one am happy to offload that work to a crate that knows what it is doing.

This comes at the cost of another dependency, maybe increasing compile times, but I think it's even if that's the case, it's a price worth paying.

And indeed, the Windows failure is spurious, probably indicating that some memory corruption is happening there, but who knows.

@Byron Byron merged commit 46585ce into Byron:master May 15, 2024
4 checks passed
@madsmtm madsmtm deleted the objc2 branch May 15, 2024 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants