Skip to content

Commit 0dc4bd3

Browse files
authored
Merge pull request #820 from cgwalters/fix-cancellable
Move `g_cancellable_set_error_if_cancelled()` to manual
2 parents 6e08a3a + c166b6a commit 0dc4bd3

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

gio/Gir.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ manual_traits = ["CancellableExtManual"]
398398
name = "cancelled"
399399
# Racy, use 'connect' and 'disconnect' instead
400400
ignore = true
401+
[[object.function]]
402+
name = "set_error_if_cancelled"
403+
manual = true
401404

402405
[[object]]
403406
name = "Gio.CharsetConverter"

gio/src/auto/cancellable.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use glib::object::IsA;
66
use glib::translate::*;
77
use std::fmt;
8-
use std::ptr;
98

109
glib::wrapper! {
1110
#[doc(alias = "GCancellable")]
@@ -62,9 +61,6 @@ pub trait CancellableExt: 'static {
6261

6362
#[doc(alias = "g_cancellable_release_fd")]
6463
fn release_fd(&self);
65-
66-
#[doc(alias = "g_cancellable_set_error_if_cancelled")]
67-
fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
6864
}
6965

7066
impl<O: IsA<Cancellable>> CancellableExt for O {
@@ -107,22 +103,6 @@ impl<O: IsA<Cancellable>> CancellableExt for O {
107103
ffi::g_cancellable_release_fd(self.as_ref().to_glib_none().0);
108104
}
109105
}
110-
111-
fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
112-
unsafe {
113-
let mut error = ptr::null_mut();
114-
let is_ok = ffi::g_cancellable_set_error_if_cancelled(
115-
self.as_ref().to_glib_none().0,
116-
&mut error,
117-
);
118-
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
119-
if error.is_null() {
120-
Ok(())
121-
} else {
122-
Err(from_glib_full(error))
123-
}
124-
}
125-
}
126106
}
127107

128108
impl fmt::Display for Cancellable {

gio/src/cancellable.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub trait CancellableExtManual {
7575
/// Returns a `Future` that completes when the cancellable becomes cancelled. Completes
7676
/// immediately if the cancellable is already cancelled.
7777
fn future(&self) -> std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
78+
// rustdoc-stripper-ignore-next
79+
/// Set an error if the cancellable is already cancelled.
80+
#[doc(alias = "g_cancellable_set_error_if_cancelled")]
81+
fn set_error_if_cancelled(&self) -> Result<(), glib::Error>;
7882
}
7983

8084
impl<O: IsA<Cancellable>> CancellableExtManual for O {
@@ -136,6 +140,24 @@ impl<O: IsA<Cancellable>> CancellableExtManual for O {
136140
}
137141
})
138142
}
143+
144+
fn set_error_if_cancelled(&self) -> Result<(), glib::Error> {
145+
unsafe {
146+
let mut error = std::ptr::null_mut();
147+
let is_ok = ffi::g_cancellable_set_error_if_cancelled(
148+
self.as_ref().to_glib_none().0,
149+
&mut error,
150+
);
151+
// Here's the special case, this function has an inverted
152+
// return value for the error case.
153+
assert_eq!(is_ok == glib::ffi::GFALSE, error.is_null());
154+
if error.is_null() {
155+
Ok(())
156+
} else {
157+
Err(from_glib_full(error))
158+
}
159+
}
160+
}
139161
}
140162

141163
#[cfg(test)]
@@ -158,6 +180,13 @@ mod tests {
158180
c.disconnect_cancelled(id.unwrap());
159181
}
160182

183+
#[test]
184+
fn cancellable_error_if_cancelled() {
185+
let c = Cancellable::new();
186+
c.cancel();
187+
assert!(c.set_error_if_cancelled().is_err());
188+
}
189+
161190
#[test]
162191
fn cancellable_future() {
163192
let c = Cancellable::new();

gio/src/subclass/async_initable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use glib::subclass::prelude::*;
99

1010
use std::ptr;
1111

12-
use crate::prelude::CancellableExt;
1312
use crate::prelude::CancellableExtManual;
1413
use crate::AsyncInitable;
1514
use crate::AsyncResult;

0 commit comments

Comments
 (0)