Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 4344176

Browse files
Merge pull request #333 from sdroege/ref-thread-default
Mark MainContext::ref_thread_default() as non-nullable with regards t…
2 parents 6206222 + cc29863 commit 4344176

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

Gir.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ concurrency = "send+sync"
363363
[object.function.return]
364364
nullable = false
365365

366+
[[object.function]]
367+
name = "ref_thread_default"
368+
[object.function.return]
369+
nullable = false
370+
366371
[[object]]
367372
name = "GLib.MainLoop"
368373
status = "generate"

src/auto/main_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl MainContext {
136136
}
137137
}
138138

139-
pub fn ref_thread_default() -> Option<MainContext> {
139+
pub fn ref_thread_default() -> MainContext {
140140
unsafe {
141141
from_glib_full(ffi::g_main_context_ref_thread_default())
142142
}

src/main_context_futures.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ impl TaskSource {
212212
from_glib_none(glib_ffi::g_source_get_context(mut_override(source)))
213213
};
214214

215+
assert!(executor.is_owner(), "Polling futures only allowed if the thread is owning the MainContext");
216+
215217
// Clone that we store in the task local data so that
216218
// it can be retrieved as needed
217219
executor.push_thread_default();

src/source_futures.rs

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,20 @@ where
5252

5353
if let Some(create_source) = create_source.take() {
5454
let main_context = MainContext::ref_thread_default();
55-
match main_context {
56-
None => panic!("Polled from an Executor not backed by a GLib main context"),
57-
Some(ref main_context) => {
58-
assert!(main_context.is_owner(), "Spawning futures only allowed if the thread is owning the MainContext");
59-
60-
// Channel for sending back the Source result to our future here.
61-
//
62-
// In theory we could directly continue polling the
63-
// corresponding task from the Source callback,
64-
// however this would break at the very least
65-
// the g_main_current_source() API.
66-
let (send, recv) = oneshot::channel();
67-
68-
let s = create_source(send);
69-
70-
s.attach(Some(main_context));
71-
*source = Some((s, recv));
72-
}
73-
}
55+
assert!(main_context.is_owner(), "Spawning futures only allowed if the thread is owning the MainContext");
56+
57+
// Channel for sending back the Source result to our future here.
58+
//
59+
// In theory we could directly continue polling the
60+
// corresponding task from the Source callback,
61+
// however this would break at the very least
62+
// the g_main_current_source() API.
63+
let (send, recv) = oneshot::channel();
64+
65+
let s = create_source(send);
66+
67+
s.attach(Some(&main_context));
68+
*source = Some((s, recv));
7469
}
7570

7671
// At this point we must have a receiver
@@ -224,25 +219,20 @@ where
224219

225220
if let Some(create_source) = create_source.take() {
226221
let main_context = MainContext::ref_thread_default();
227-
match main_context {
228-
None => panic!("Polled from an Executor not backed by a GLib main context"),
229-
Some(ref main_context) => {
230-
assert!(main_context.is_owner(), "Spawning futures only allowed if the thread is owning the MainContext");
231-
232-
// Channel for sending back the Source result to our future here.
233-
//
234-
// In theory we could directly continue polling the
235-
// corresponding task from the Source callback,
236-
// however this would break at the very least
237-
// the g_main_current_source() API.
238-
let (send, recv) = mpsc::unbounded();
239-
240-
let s = create_source(send);
241-
242-
s.attach(Some(main_context));
243-
*source = Some((s, recv));
244-
}
245-
}
222+
assert!(main_context.is_owner(), "Spawning futures only allowed if the thread is owning the MainContext");
223+
224+
// Channel for sending back the Source result to our future here.
225+
//
226+
// In theory we could directly continue polling the
227+
// corresponding task from the Source callback,
228+
// however this would break at the very least
229+
// the g_main_current_source() API.
230+
let (send, recv) = mpsc::unbounded();
231+
232+
let s = create_source(send);
233+
234+
s.attach(Some(&main_context));
235+
*source = Some((s, recv));
246236
}
247237

248238
// At this point we must have a receiver

0 commit comments

Comments
 (0)