diff --git a/src/codegen/object.rs b/src/codegen/object.rs index 8a3c22e56..b2d8bb653 100644 --- a/src/codegen/object.rs +++ b/src/codegen/object.rs @@ -348,9 +348,29 @@ fn generate_builder(w: &mut dyn Write, env: &Env, analysis: &analysis::object::I )?; writeln!(w, "#[must_use = \"The builder must be built to be used\"]")?; writeln!(w, "pub struct {}Builder {{", analysis.name)?; + + let tid_int = env + .library + .find_type(0, "*.gint") + .expect("No fundamental type *.gint"); + + let glib_ns_id = env + .library + .find_namespace("GLib") + .expect("Missing `GLib` namespace in add_glib_priority!"); + let priority_id = env + .library + .find_type(glib_ns_id, "Priority") + .expect("No Priority type"); + for (builder_props, super_tid) in &analysis.builder_properties { for property in builder_props { - match RustType::try_new(env, property.typ) { + let property_type = if property.name.ends_with("priority") && property.typ == tid_int { + priority_id + } else { + property.typ + }; + match RustType::try_new(env, property_type) { Ok(type_string) => { let type_string = match type_string.as_str() { s if nameutil::is_gstring(s) => "String", @@ -364,7 +384,7 @@ fn generate_builder(w: &mut dyn Write, env: &Env, analysis: &analysis::object::I } else { library::ParameterDirection::Out }; - let mut param_type = RustType::builder(env, property.typ) + let mut param_type = RustType::builder(env, property_type) .direction(direction) .ref_mode(property.set_in_ref_mode) .try_build() diff --git a/src/custom_type_glib_priority.rs b/src/custom_type_glib_priority.rs index ce4b7a988..75f1f88a5 100644 --- a/src/custom_type_glib_priority.rs +++ b/src/custom_type_glib_priority.rs @@ -43,14 +43,16 @@ struct ReplaceToPriority { impl FunctionsMutVisitor for ReplaceToPriority { fn visit_function_mut(&mut self, func: &mut Function) -> bool { - if !func.name.ends_with("_async") { - return true; - } for par in &mut func.parameters { if par.typ == self.tid_int && par.name.ends_with("priority") { par.typ = self.tid_priority; } } + if func.ret.typ == self.tid_int + && (func.ret.name.ends_with("priority") || func.name.ends_with("priority")) + { + func.ret.typ = self.tid_priority; + } true } } diff --git a/src/visitors.rs b/src/visitors.rs index b20fbdc18..f1b8afcea 100644 --- a/src/visitors.rs +++ b/src/visitors.rs @@ -13,6 +13,12 @@ impl Namespace { return false; } } + // Replace types in global functions as well + for func in self.functions.iter_mut() { + if !visitor.visit_function_mut(func) { + return false; + } + } true } }