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

Use wrapper type for CFUUID #4032

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

killercup
Copy link
Contributor

This no longer exposes CGDisplayCreateUUIDFromDisplayID and instead offers a new CfUuid type that can be created from a display ID and also cleans itself up on drop.

Closes #4031


  • Tested on all platforms changed
    • Tested examples on macOS 15.1.1
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@killercup killercup requested a review from madsmtm as a code owner December 4, 2024 15:35
@killercup
Copy link
Contributor Author

Saw #4031 randomly and thought I'd take stab at it. I'm not sure this is releasing the right thing but it seems to work without issues. Please someone double check :)

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

I think such wrappers actually already exist? Use core_foundation::uuid::CFUUID and CFUUID::wrap_under_create_rule?

@madsmtm madsmtm added B - bug Dang, that shouldn't have happened DS - macos labels Dec 4, 2024
@madsmtm
Copy link
Member

madsmtm commented Dec 4, 2024

Also, I was a bit unsure, but read the docs on ARC does seem to suggest that since the function contains Create in the name, it should definitely be released afterwards.

@killercup
Copy link
Contributor Author

I think such wrappers actually already exist? Use core_foundation::uuid::CFUUID and CFUUID::wrap_under_create_rule?

Oh nice, didn't know about this! Also took me look into the source to confirm it calls release :) It doesn't seem to derive Hash, PartialOrd, and Ord, though… I can try to get this added upstream but I'm not even sure if treating these UUIDs as Ord makes sense?

@madsmtm
Copy link
Member

madsmtm commented Dec 6, 2024

UUIDs are definitely Ord. But I think you can use CFUUIDGetUUIDBytes to get the actual values of the UUID, and then compare that instead?

@madsmtm
Copy link
Member

madsmtm commented Dec 8, 2024

But I'd also be fine with converting them to a pointer, and implementing Ord by comparing the pointer addresses (that's what we're currently doing).

This no longer exposes `CGDisplayCreateUUIDFromDisplayID` and instead
offers a new `CfUuid` type that can be created from a display ID and
also cleans itself up on drop.

Closes rust-windowing#4031
@killercup
Copy link
Contributor Author

Sorry, had other stuff going on. I've updated it to compare/hash/sort by UUID bytes. It's not the most concise but does the job.

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Looks good, only a small nit

@@ -133,15 +134,43 @@ impl VideoModeHandle {
#[derive(Clone)]
pub struct MonitorHandle(CGDirectDisplayID);

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct MonitorUuid([u8; 16]);
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need this, you can just use [u8; 16] (or if you really want, type MonitorUuid = [u8; 16]).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I usually go for explicit newtypes, and even had an implementation where this had From<CFUUIDBytes> but I didn't want to overdo it. I'll swap it for the type alias :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - macos
Development

Successfully merging this pull request may close these issues.

CGDisplayCreateUUIDFromDisplayID may be leaking?
2 participants