-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specifically CFTypeID, CFOptionFlags, CFHashCode and CFIndex, these can (and should) all be isize/usize instead of c_long/c_ulong. Part of #556.
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// The header `CoreFoundation/CFBase.h` contains: | ||
// | ||
// #if defined(__WIN64__) && !defined(__LLP64__) | ||
// #define __LLP64__ 1 | ||
// #endif | ||
// | ||
// #if __LLP64__ | ||
// typedef unsigned long long CFTypeID; | ||
// typedef unsigned long long CFOptionFlags; | ||
// typedef unsigned long long CFHashCode; | ||
// typedef signed long long CFIndex; | ||
// #else | ||
// typedef unsigned long CFTypeID; | ||
// typedef unsigned long CFOptionFlags; | ||
// typedef unsigned long CFHashCode; | ||
// typedef signed long CFIndex; | ||
// #endif | ||
// | ||
// Looking at the corresponding Rust definitions for longs: | ||
// <https://doc.rust-lang.org/1.83.0/src/core/ffi/mod.rs.html#168-179> | ||
// cfg_if! { | ||
// if #[cfg(all(target_pointer_width = "64", not(windows)))] { | ||
// pub type c_long = i64; | ||
// pub type c_ulong = u64; | ||
// } else { | ||
// // The minimal size of `long` in the C standard is 32 bits | ||
// pub type c_long = i32; | ||
// pub type c_ulong = u32; | ||
// } | ||
// } | ||
// <https://doc.rust-lang.org/1.83.0/src/core/ffi/mod.rs.html#65-66> | ||
// pub type c_longlong = i64; | ||
// pub type c_ulonglong = u64; | ||
// | ||
// It becomes easy to convince ourselves that combined, these amount to making | ||
// these types be 32-bit on systems with 32-bit pointers and 64-bit on systems | ||
// with 64-bit pointers. | ||
// | ||
// That means we can use `isize`/`usize`, which is more ergonomic. | ||
|
||
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftypeid?language=objc) | ||
pub type CFTypeID = usize; | ||
|
||
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfoptionflags?language=objc) | ||
pub type CFOptionFlags = usize; | ||
|
||
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfhashcode?language=objc) | ||
pub type CFHashCode = usize; | ||
|
||
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfindex?language=objc) | ||
pub type CFIndex = isize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters