Skip to content

Commit

Permalink
special_functions: Only override to_string nullability if not trusted
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Dec 5, 2020
1 parent e79d8fd commit b2ce127
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/analysis/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option<Info> {
}
}

let specials = special_functions::extract(&mut functions, type_);
let specials = special_functions::extract(&mut functions, type_, obj);

special_functions::analyze_imports(&specials, imports);

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn new(env: &Env, obj: &GObject, imports: &mut Imports) -> Option<Info> {
}
}

let specials = special_functions::extract(&mut functions, type_);
let specials = special_functions::extract(&mut functions, type_, obj);

special_functions::analyze_imports(&specials, imports);

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
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
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn new(env: &Env, obj: &GObject) -> Option<Info> {
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,
Expand Down
13 changes: 8 additions & 5 deletions src/analysis/special_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
functions::{Info as FuncInfo, Visibility},
imports::Imports,
},
config::GObject,
library::{Type as LibType, TypeId},
version::Version,
};
Expand Down Expand Up @@ -58,7 +59,7 @@ pub struct Info {

pub type Infos = BTreeMap<Type, Info>;

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_);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -106,7 +109,7 @@ fn update_func(func: &mut FuncInfo, type_: Type, parent_type: &LibType) -> bool
true
}

pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType) -> Infos {
pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType, obj: &GObject) -> Infos {
let mut specials = Infos::new();
let mut has_copy = false;
let mut has_free = false;
Expand All @@ -118,7 +121,7 @@ pub fn extract(functions: &mut Vec<FuncInfo>, 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" {
Expand Down Expand Up @@ -156,7 +159,7 @@ pub fn extract(functions: &mut Vec<FuncInfo>, 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 {
Expand Down

0 comments on commit b2ce127

Please sign in to comment.