Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upto_i32 shortcut for CFNumber #254
Merged
Conversation
core-foundation/src/number.rs
Outdated
| pub fn to_u32(&self) -> Option<u32> { | ||
| unsafe { | ||
| let mut value: u32 = 0; | ||
| let ok = CFNumberGetValue(self.0, kCFNumberIntType, mem::transmute(&mut value)); |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 14, 2018
Member
I think you want kCFNumberSInt32Type and cast the resulting i32 to u32. Otherwise I'm worried that the resulting number might be different sizes on 32 vs. 64 bit architectures.
This comment has been minimized.
This comment has been minimized.
core-foundation-sys/src/number.rs
Outdated
| @@ -27,7 +27,7 @@ pub static kCFNumberFloat32Type: CFNumberType = 5; | |||
| pub static kCFNumberFloat64Type: CFNumberType = 6; | |||
| // static kCFNumberCharType: CFNumberType = 7; | |||
| // static kCFNumberShortType: CFNumberType = 8; | |||
| // static kCFNumberIntType: CFNumberType = 9; | |||
| pub static kCFNumberIntType: CFNumberType = 9; | |||
This comment has been minimized.
This comment has been minimized.
core-foundation/src/number.rs
Outdated
| unsafe { | ||
| let number_ref = CFNumberCreate( | ||
| kCFAllocatorDefault, | ||
| kCFNumberIntType, |
This comment has been minimized.
This comment has been minimized.
|
CoreFoundation doesn't support a u32 type. Why do you need to add it? |
|
I did some digging and found I am able to use the SInt32Type for the APIs I'm working with. As such, I've removed the u32-related code and left the to_i32 shortcut. Thanks for the feedback! |
|
@bors-servo r+ |
|
|
bors-servo
added a commit
that referenced
this pull request
Sep 24, 2018
to_i32 shortcut for CFNumber kCFNumberIntType is needed in some iokit APIs. Please let me know if you think anything is missing. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/254) <!-- Reviewable:end -->
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
sibsibsib commentedSep 13, 2018
•
edited by larsbergstrom
kCFNumberIntType is needed in some iokit APIs.
Please let me know if you think anything is missing.
This change is