Skip to content

Commit 9b36b2d

Browse files
committed
gio: DataInputStream::read_line_async() can return None slices
Fixes #1802
1 parent bffc595 commit 9b36b2d

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

gio/src/data_input_stream.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
1111
fn read_line<P: IsA<Cancellable>>(
1212
&self,
1313
cancellable: Option<&P>,
14-
) -> Result<glib::collections::Slice<u8>, glib::Error> {
14+
) -> Result<Option<glib::collections::Slice<u8>>, glib::Error> {
1515
unsafe {
1616
let mut length = mem::MaybeUninit::uninit();
1717
let mut error = ptr::null_mut();
@@ -21,9 +21,13 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
2121
cancellable.map(|p| p.as_ref()).to_glib_none().0,
2222
&mut error,
2323
);
24-
let length = length.assume_init();
2524
if error.is_null() {
26-
Ok(FromGlibContainer::from_glib_full_num(ret, length))
25+
if ret.is_null() {
26+
Ok(None)
27+
} else {
28+
let length = length.assume_init();
29+
Ok(Some(FromGlibContainer::from_glib_full_num(ret, length)))
30+
}
2731
} else {
2832
Err(from_glib_full(error))
2933
}
@@ -33,7 +37,7 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
3337
#[doc(alias = "g_data_input_stream_read_line_async")]
3438
fn read_line_async<
3539
P: IsA<Cancellable>,
36-
Q: FnOnce(Result<glib::collections::Slice<u8>, glib::Error>) + 'static,
40+
Q: FnOnce(Result<Option<glib::collections::Slice<u8>>, glib::Error>) + 'static,
3741
>(
3842
&self,
3943
io_priority: glib::Priority,
@@ -53,7 +57,7 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
5357
let user_data: Box_<glib::thread_guard::ThreadGuard<Q>> =
5458
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
5559
unsafe extern "C" fn read_line_async_trampoline<
56-
Q: FnOnce(Result<glib::collections::Slice<u8>, glib::Error>) + 'static,
60+
Q: FnOnce(Result<Option<glib::collections::Slice<u8>>, glib::Error>) + 'static,
5761
>(
5862
_source_object: *mut glib::gobject_ffi::GObject,
5963
res: *mut ffi::GAsyncResult,
@@ -67,9 +71,13 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
6771
length.as_mut_ptr(),
6872
&mut error,
6973
);
70-
let length = length.assume_init();
7174
let result = if error.is_null() {
72-
Ok(FromGlibContainer::from_glib_full_num(ret, length))
75+
if ret.is_null() {
76+
Ok(None)
77+
} else {
78+
let length = length.assume_init();
79+
Ok(Some(FromGlibContainer::from_glib_full_num(ret, length)))
80+
}
7381
} else {
7482
Err(from_glib_full(error))
7583
};
@@ -95,8 +103,9 @@ pub trait DataInputStreamExtManual: IsA<DataInputStream> + 'static {
95103
io_priority: glib::Priority,
96104
) -> Pin<
97105
Box_<
98-
dyn std::future::Future<Output = Result<glib::collections::Slice<u8>, glib::Error>>
99-
+ 'static,
106+
dyn std::future::Future<
107+
Output = Result<Option<glib::collections::Slice<u8>>, glib::Error>,
108+
> + 'static,
100109
>,
101110
> {
102111
Box_::pin(crate::GioFuture::new(

0 commit comments

Comments
 (0)