Skip to content

Commit 557cf98

Browse files
committed
Add CoreFoundation inline functions
Replaces servo/core-foundation-rs#618.
1 parent 576190c commit 557cf98

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

crates/objc2/src/topics/about_generated/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
103103
* Added a few compatibility aliases to help with migrating from the
104104
`core-foundation` crate.
105105
* Added support for using `dispatch2` types in framework crates.
106+
* Marked some CoreFoundation types as thread-safe.
107+
* Added a few missing inline functions:
108+
- `CFUserNotificationCheckBoxChecked`
109+
- `CFUserNotificationSecureTextField`
110+
- `CFUserNotificationPopUpSelection`
111+
* Added `CFRange::new`.
106112

107113
### Changed
108114
* Made `CFArray`, `CFBag`, `CFBinaryHeap`, `CFDictionary`, `CFSet` and their

framework-crates/objc2-core-foundation/src/base.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ use core::fmt;
4545
use core::hash;
4646
use core::marker::{PhantomData, PhantomPinned};
4747

48-
use crate::CFComparisonResult;
49-
use crate::CFGetRetainCount;
50-
use crate::ConcreteType;
51-
use crate::{CFEqual, CFHash, Type};
48+
use crate::{CFComparisonResult, CFEqual, CFGetRetainCount, CFHash, CFRange, ConcreteType, Type};
5249

5350
/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftypeid?language=objc)
5451
pub type CFTypeID = usize;
@@ -248,3 +245,11 @@ impl From<CFComparisonResult> for Ordering {
248245
}
249246
}
250247
}
248+
249+
impl CFRange {
250+
/// Create a new [`CFRange`].
251+
#[doc(alias = "CFRangeMake")]
252+
pub fn new(location: CFIndex, length: CFIndex) -> Self {
253+
Self { location, length }
254+
}
255+
}

framework-crates/objc2-core-foundation/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ mod thread_safety;
4848
#[cfg(feature = "CFTimeZone")]
4949
mod timezone;
5050
mod type_traits;
51+
#[cfg(all(feature = "CFBase", feature = "CFUserNotification"))]
52+
mod user_notification;
5153
#[cfg(feature = "CFUUID")]
5254
mod uuid;
5355

@@ -63,6 +65,8 @@ pub use self::generated::*;
6365
pub use self::geometry::*;
6466
pub use self::retained::CFRetained;
6567
pub use self::type_traits::{ConcreteType, Type};
68+
#[cfg(all(feature = "CFBase", feature = "CFUserNotification"))]
69+
pub use self::user_notification::*;
6670

6771
// This is not exposed publicly, so the only way to use this in types with
6872
// generics is to use it through the default type (e.g. the user should write
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![allow(non_snake_case)]
2+
use crate::{CFIndex, CFOptionFlags};
3+
4+
pub extern "C" fn CFUserNotificationCheckBoxChecked(i: CFIndex) -> CFOptionFlags {
5+
(1usize << (8 + i)) as CFOptionFlags
6+
}
7+
8+
pub extern "C" fn CFUserNotificationSecureTextField(i: CFIndex) -> CFOptionFlags {
9+
(1usize << (16 + i)) as CFOptionFlags
10+
}
11+
12+
pub extern "C" fn CFUserNotificationPopUpSelection(n: CFIndex) -> CFOptionFlags {
13+
(n << 24) as CFOptionFlags
14+
}

framework-crates/objc2-core-foundation/translation-config.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ typedef.CFIndex.skipped = true
6666
fn.CFAutorelease.skipped = true
6767
fn.CFRetain.skipped = true
6868
fn.CFRelease.skipped = true
69-
fn.CFMakeCollectable.skipped = true
69+
fn.CFMakeCollectable.skipped = true # Simply returns the argument on macOS 10.12 or later
7070

7171
# Dependent on target endianness
72+
fn.CFSwapInt16.skipped = true
73+
fn.CFSwapInt32.skipped = true
74+
fn.CFSwapInt64.skipped = true
7275
fn.CFByteOrderGetCurrent.skipped = true
7376
fn.CFSwapInt16BigToHost.skipped = true
7477
fn.CFSwapInt32BigToHost.skipped = true
@@ -91,6 +94,12 @@ fn.CFConvertFloatSwappedToHost.skipped = true
9194
fn.CFConvertDoubleHostToSwapped.skipped = true
9295
fn.CFConvertDoubleSwappedToHost.skipped = true
9396

97+
# Custom-defined inline functions
98+
fn.CFRangeMake.skipped = true
99+
fn.CFUserNotificationCheckBoxChecked.skipped = true
100+
fn.CFUserNotificationSecureTextField.skipped = true
101+
fn.CFUserNotificationPopUpSelection.skipped = true
102+
94103
##
95104
## Safety
96105
##

0 commit comments

Comments
 (0)