Skip to content

Commit c352e6a

Browse files
committed
Automatically handle some Dispatch CStr conversions
1 parent 57b2596 commit c352e6a

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

crates/dispatch2/src/queue.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ impl DispatchQueue {
7373
pub fn new(label: &str, queue_attribute: Option<&DispatchQueueAttr>) -> DispatchRetained<Self> {
7474
let label = CString::new(label).expect("Invalid label!");
7575

76-
// SAFETY: The label is a valid C string.
77-
unsafe { Self::__new(label.as_ptr(), queue_attribute) }
76+
Self::__new(Some(&label), queue_attribute)
7877
}
7978

8079
/// Create a new [`DispatchQueue`] with a given target [`DispatchQueue`].
@@ -85,8 +84,8 @@ impl DispatchQueue {
8584
) -> DispatchRetained<Self> {
8685
let label = CString::new(label).expect("Invalid label!");
8786

88-
// SAFETY: The label is a valid C string.
89-
unsafe { Self::__new_with_target(label.as_ptr(), queue_attribute, target) }
87+
// SAFETY: `target` queue TODO.
88+
unsafe { Self::__new_with_target(Some(&label), queue_attribute, target) }
9089
}
9190

9291
/// Return a system-defined global concurrent [`DispatchQueue`] with the priority derived from [GlobalQueueIdentifier].

crates/dispatch2/src/workloop.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ impl DispatchWorkloop {
1717
pub fn new(label: &str, inactive: bool) -> DispatchRetained<Self> {
1818
let label = CString::new(label).expect("Invalid label!");
1919

20-
// Safety: label can only be valid.
21-
unsafe {
22-
if inactive {
23-
DispatchWorkloop::__new_inactive(label.as_ptr())
24-
} else {
25-
DispatchWorkloop::__new(label.as_ptr())
26-
}
20+
if inactive {
21+
DispatchWorkloop::__new_inactive(Some(&label))
22+
} else {
23+
DispatchWorkloop::__new(Some(&label))
2724
}
2825
}
2926
}

crates/dispatch2/translation-config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ fn.dispatch_queue_create_with_target.renamed = "__new_with_target"
228228
fn.dispatch_workloop_create.renamed = "__new"
229229
fn.dispatch_workloop_create_inactive.renamed = "__new_inactive"
230230

231+
fn.dispatch_queue_create.arguments.0.bounds = "null-terminated"
232+
fn.dispatch_queue_create_with_target.arguments.0.bounds = "null-terminated"
233+
fn.dispatch_workloop_create.arguments.0.bounds = "null-terminated"
234+
fn.dispatch_workloop_create_inactive.arguments.0.bounds = "null-terminated"
235+
231236
##
232237
## Safety + API
233238
##

generated

0 commit comments

Comments
 (0)