Skip to content

Commit

Permalink
Merge pull request #1385 from gtk-rs/bilelmoussaoui/move_Fix
Browse files Browse the repository at this point in the history
analysis: Handle move configuration in Ext trait
  • Loading branch information
sdroege authored Oct 18, 2022
2 parents 0f78aff + 5336a75 commit 2da186b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/analysis/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Bounds {
&bound_type,
*par.nullable,
par.instance_parameter,
par.move_,
));
if r#async && (par.name == "callback" || par.name.ends_with("_callback")) {
let func_name = func.c_identifier.as_ref().unwrap();
Expand Down Expand Up @@ -182,7 +183,12 @@ impl Bounds {
}
} else if par.instance_parameter {
if let Some(bound_type) = Bounds::type_for(env, par.typ) {
ret = Some(Bounds::get_to_glib_extra(&bound_type, *par.nullable, true));
ret = Some(Bounds::get_to_glib_extra(
&bound_type,
*par.nullable,
true,
par.move_,
));
}
}

Expand Down Expand Up @@ -214,12 +220,15 @@ impl Bounds {
bound_type: &BoundType,
nullable: bool,
instance_parameter: bool,
move_: bool,
) -> String {
use self::BoundType::*;
match bound_type {
AsRef(_) if nullable => ".as_ref().map(|p| p.as_ref())".to_owned(),
AsRef(_) if move_ => ".upcast()".to_owned(),
AsRef(_) => ".as_ref()".to_owned(),
IsA(_) if nullable && !instance_parameter => ".map(|p| p.as_ref())".to_owned(),
IsA(_) if move_ => ".upcast()".to_owned(),
IsA(_) => ".as_ref()".to_owned(),
_ => String::new(),
}
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/function_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn analyze(
if async_func && async_param_to_remove(&par.name) {
add_rust_parameter = false;
}

let move_ = configured_parameters.iter().any(|p| p.move_);
let mut array_par = configured_parameters.iter().find_map(|cp| {
cp.length_of
.as_ref()
Expand All @@ -245,6 +245,7 @@ pub fn analyze(
&bound_type,
*array_par.nullable,
array_par.instance_parameter,
move_,
))
.into();
}
Expand Down Expand Up @@ -296,7 +297,7 @@ pub fn analyze(
user_data_index: par.closure,
destroy_index: par.destroy,
try_from_glib: try_from_glib.clone(),
move_: configured_parameters.iter().any(|p| p.move_),
move_,
};
parameters.c_parameters.push(c_par);

Expand Down

0 comments on commit 2da186b

Please sign in to comment.