Skip to content

Commit

Permalink
Merge pull request #1390 from sdroege/0.19-backports
Browse files Browse the repository at this point in the history
0.19 backports
  • Loading branch information
sdroege authored May 10, 2024
2 parents a7c5a9b + 32bf155 commit 66df460
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
9 changes: 6 additions & 3 deletions glib/src/main_context_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ impl<T: 'static> futures_core::FusedFuture for JoinHandle<T> {
}
}

unsafe impl<T> Send for JoinHandle<T> {}
/// Safety: We can't rely on the auto implementation because we are retrieving
/// the result as a `Box<dyn Any + 'static>` from the [`Source`]. We need to
/// rely on type erasure here, so we have to manually assert the Send bound too.
unsafe impl<T: Send> Send for JoinHandle<T> {}

// rustdoc-stripper-ignore-next
/// Variant of [`JoinHandle`] that is returned from [`MainContext::spawn_from_within`].
Expand Down Expand Up @@ -580,7 +583,7 @@ impl MainContext {
/// The given `Future` does not have to be `Send` but the closure to spawn it has to be.
///
/// This can be called only from any thread.
pub fn spawn_from_within<R: 'static, F: Future<Output = R> + 'static>(
pub fn spawn_from_within<R: Send + 'static, F: Future<Output = R> + 'static>(
&self,
func: impl FnOnce() -> F + Send + 'static,
) -> SpawnWithinJoinHandle<R> {
Expand All @@ -593,7 +596,7 @@ impl MainContext {
/// The given `Future` does not have to be `Send` but the closure to spawn it has to be.
///
/// This can be called only from any thread.
pub fn spawn_from_within_with_priority<R: 'static, F: Future<Output = R> + 'static>(
pub fn spawn_from_within_with_priority<R: Send + 'static, F: Future<Output = R> + 'static>(
&self,
priority: Priority,
func: impl FnOnce() -> F + Send + 'static,
Expand Down
27 changes: 9 additions & 18 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,10 @@ impl Object {
if !properties.is_empty() {
let klass = ObjectClass::from_type(type_)
.unwrap_or_else(|| panic!("Can't retrieve class for type '{type_}'"));
let pspecs = klass.list_properties();

for (idx, (name, value)) in properties.iter_mut().enumerate() {
let pspec = pspecs
.iter()
.find(|p| p.name() == *name)
let pspec = klass
.find_property(name)
.unwrap_or_else(|| panic!("Can't find property '{name}' for type '{type_}'"));

if (pspec.flags().contains(crate::ParamFlags::CONSTRUCT)
Expand All @@ -1469,7 +1467,7 @@ impl Object {
// FIXME: With GLib 2.74 and GParamSpecClass::value_is_valid() it is possible to
// not require mutable values here except for when LAX_VALIDATION is provided and a
// change is needed, or a GObject value needs it's GType changed.
validate_property_type(type_, true, pspec, value);
validate_property_type(type_, true, &pspec, value);

property_names.push(pspec.name().as_ptr());
property_values.push(*value.to_glib_none().0);
Expand Down Expand Up @@ -2278,17 +2276,15 @@ impl<T: ObjectType> ObjectExt for T {

#[track_caller]
fn set_properties(&self, property_values: &[(&str, &dyn ToValue)]) {
let pspecs = self.list_properties();

let params = property_values
.iter()
.map(|&(name, value)| {
let pspec = pspecs.iter().find(|p| p.name() == name).unwrap_or_else(|| {
let pspec = self.find_property(name).unwrap_or_else(|| {
panic!("Can't find property '{name}' for type '{}'", self.type_());
});

let mut value = value.to_value();
validate_property_type(self.type_(), false, pspec, &mut value);
validate_property_type(self.type_(), false, &pspec, &mut value);
(pspec.name().as_ptr(), value)
})
.collect::<smallvec::SmallVec<[_; 10]>>();
Expand All @@ -2307,20 +2303,15 @@ impl<T: ObjectType> ObjectExt for T {

#[track_caller]
fn set_properties_from_value(&self, property_values: &[(&str, Value)]) {
let pspecs = self.list_properties();

let params = property_values
.iter()
.map(|(name, value)| {
let pspec = pspecs
.iter()
.find(|p| p.name() == *name)
.unwrap_or_else(|| {
panic!("Can't find property '{name}' for type '{}'", self.type_());
});
let pspec = self.find_property(name).unwrap_or_else(|| {
panic!("Can't find property '{name}' for type '{}'", self.type_());
});

let mut value = value.clone();
validate_property_type(self.type_(), false, pspec, &mut value);
validate_property_type(self.type_(), false, &pspec, &mut value);
(pspec.name().as_ptr(), value)
})
.collect::<smallvec::SmallVec<[_; 10]>>();
Expand Down
1 change: 1 addition & 0 deletions glib/src/thread_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ impl<T> Drop for ThreadGuard<T> {
}

unsafe impl<T> Send for ThreadGuard<T> {}
unsafe impl<T> Sync for ThreadGuard<T> {}

0 comments on commit 66df460

Please sign in to comment.