diff --git a/src/analysis/enums.rs b/src/analysis/enums.rs index 9a1dc3dde..ace41d290 100644 --- a/src/analysis/enums.rs +++ b/src/analysis/enums.rs @@ -107,7 +107,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option { } } - let specials = special_functions::extract(&mut functions, type_); + let specials = special_functions::extract(&mut functions, type_, obj); special_functions::analyze_imports(&specials, imports); diff --git a/src/analysis/flags.rs b/src/analysis/flags.rs index 8b8dff119..e04f73698 100644 --- a/src/analysis/flags.rs +++ b/src/analysis/flags.rs @@ -101,7 +101,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option { } } - let specials = special_functions::extract(&mut functions, type_); + let specials = special_functions::extract(&mut functions, type_, obj); special_functions::analyze_imports(&specials, imports); diff --git a/src/analysis/object.rs b/src/analysis/object.rs index 317bae192..dc66d22e8 100644 --- a/src/analysis/object.rs +++ b/src/analysis/object.rs @@ -88,7 +88,7 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option Some(&mut signatures), Some(deps), ); - let mut specials = special_functions::extract(&mut functions, type_); + let mut specials = special_functions::extract(&mut functions, type_, obj); // `copy` will duplicate an object while `clone` just adds a reference special_functions::unhide(&mut functions, &specials, special_functions::Type::Copy); // these are all automatically derived on objects and compare by pointer. If such functions diff --git a/src/analysis/record.rs b/src/analysis/record.rs index 7b9264d66..9adc46504 100644 --- a/src/analysis/record.rs +++ b/src/analysis/record.rs @@ -92,7 +92,7 @@ pub fn new(env: &Env, obj: &GObject) -> Option { None, None, ); - let specials = special_functions::extract(&mut functions, type_); + let specials = special_functions::extract(&mut functions, type_, obj); let (version, deprecated_version) = info_base::versions( env, diff --git a/src/analysis/special_functions.rs b/src/analysis/special_functions.rs index cefbd9e06..e81a8b2dc 100644 --- a/src/analysis/special_functions.rs +++ b/src/analysis/special_functions.rs @@ -3,6 +3,7 @@ use crate::{ functions::{Info as FuncInfo, Visibility}, imports::Imports, }, + config::GObject, library::{Type as LibType, TypeId}, version::Version, }; @@ -58,7 +59,7 @@ pub struct Info { pub type Infos = BTreeMap; -fn update_func(func: &mut FuncInfo, type_: Type, parent_type: &LibType) -> bool { +fn update_func(func: &mut FuncInfo, type_: Type, parent_type: &LibType, obj: &GObject) -> bool { if func.visibility != Visibility::Comment { func.visibility = visibility(type_); } @@ -86,7 +87,9 @@ fn update_func(func: &mut FuncInfo, type_: Type, parent_type: &LibType) -> bool // As to not change old code behaviour, assume non-nullability outside // enums and flags only. Function inside enums and flags have been // appropriately marked in Gir. - if !matches!(parent_type, LibType::Enumeration(_) | LibType::Bitfield(_)) { + if !obj.trust_return_value_nullability + && !matches!(parent_type, LibType::Enumeration(_) | LibType::Bitfield(_)) + { if let Some(par) = func.ret.parameter.as_mut() { *par.nullable = false; } @@ -106,7 +109,7 @@ fn update_func(func: &mut FuncInfo, type_: Type, parent_type: &LibType) -> bool true } -pub fn extract(functions: &mut Vec, parent_type: &LibType) -> Infos { +pub fn extract(functions: &mut Vec, parent_type: &LibType, obj: &GObject) -> Infos { let mut specials = Infos::new(); let mut has_copy = false; let mut has_free = false; @@ -118,7 +121,7 @@ pub fn extract(functions: &mut Vec, parent_type: &LibType) -> Infos { destroy = Some((func.glib_name.clone(), pos)); continue; } - if !update_func(func, type_, parent_type) { + if !update_func(func, type_, parent_type, obj) { continue; } if func.name == "copy" { @@ -156,7 +159,7 @@ pub fn extract(functions: &mut Vec, parent_type: &LibType) -> Infos { if let Some((glib_name, pos)) = destroy { let ty_ = Type::from_str("destroy").unwrap(); let func = &mut functions[pos]; - update_func(func, ty_, parent_type); + update_func(func, ty_, parent_type, obj); specials.insert( ty_, Info {