diff --git a/src/codegen/general.rs b/src/codegen/general.rs index 21901c905..4d8853e55 100644 --- a/src/codegen/general.rs +++ b/src/codegen/general.rs @@ -377,7 +377,7 @@ pub fn define_auto_boxed_type( init_function_expression: &Option, copy_into_function_expression: &Option, clear_function_expression: &Option, - get_type_fn: &str, + get_type_fn: Option<&str>, derive: &[Derive], ) -> Result<()> { let sys_crate_name = env.main_sys_crate_name(); @@ -394,22 +394,24 @@ pub fn define_auto_boxed_type( )?; writeln!(w)?; writeln!(w, "\tmatch fn {{")?; - writeln!( - w, - "\t\tcopy => |ptr| {}({}::{}(), ptr as *mut _) as *mut {}::{},", - use_glib_type(env, "gobject_ffi::g_boxed_copy"), - sys_crate_name, - get_type_fn, - sys_crate_name, - glib_name - )?; - writeln!( - w, - "\t\tfree => |ptr| {}({}::{}(), ptr as *mut _),", - use_glib_type(env, "gobject_ffi::g_boxed_free"), - sys_crate_name, - get_type_fn - )?; + if let Some(get_type_fn) = get_type_fn { + writeln!( + w, + "\t\tcopy => |ptr| {}({}::{}(), ptr as *mut _) as *mut {}::{},", + use_glib_type(env, "gobject_ffi::g_boxed_copy"), + sys_crate_name, + get_type_fn, + sys_crate_name, + glib_name + )?; + writeln!( + w, + "\t\tfree => |ptr| {}({}::{}(), ptr as *mut _),", + use_glib_type(env, "gobject_ffi::g_boxed_free"), + sys_crate_name, + get_type_fn + )?; + } if let ( Some(init_function_expression), @@ -424,8 +426,9 @@ pub fn define_auto_boxed_type( writeln!(w, "\t\tcopy_into => {},", copy_into_function_expression,)?; writeln!(w, "\t\tclear => {},", clear_function_expression,)?; } - - writeln!(w, "\t\ttype_ => || {}::{}(),", sys_crate_name, get_type_fn)?; + if let Some(get_type_fn) = get_type_fn { + writeln!(w, "\t\ttype_ => || {}::{}(),", sys_crate_name, get_type_fn)?; + } writeln!(w, "\t}}")?; writeln!(w, "}}")?; diff --git a/src/codegen/record.rs b/src/codegen/record.rs index c975db297..75ab54cae 100644 --- a/src/codegen/record.rs +++ b/src/codegen/record.rs @@ -14,25 +14,18 @@ pub fn generate(w: &mut dyn Write, env: &Env, analysis: &analysis::record::Info) general::uses(w, env, &analysis.imports, type_.version)?; if RecordType::of(env.type_(analysis.type_id).maybe_ref().unwrap()) == RecordType::AutoBoxed { - if let Some((ref glib_get_type, _)) = analysis.glib_get_type { - general::define_auto_boxed_type( - w, - env, - &analysis.name, - &type_.c_type, - analysis.boxed_inline, - &analysis.init_function_expression, - &analysis.copy_into_function_expression, - &analysis.clear_function_expression, - glib_get_type, - &analysis.derives, - )?; - } else { - panic!( - "Record {} has record_boxed=true but don't have glib:get_type function", - analysis.name - ); - } + general::define_auto_boxed_type( + w, + env, + &analysis.name, + &type_.c_type, + analysis.boxed_inline, + &analysis.init_function_expression, + &analysis.copy_into_function_expression, + &analysis.clear_function_expression, + analysis.glib_get_type.as_ref().map(|(ref a, _)| a.as_str()), + &analysis.derives, + )?; } else if let (Some(ref_fn), Some(unref_fn)) = ( analysis.specials.traits().get(&Type::Ref), analysis.specials.traits().get(&Type::Unref),