Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support BoxedInline without a get_type function #1297

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ pub fn define_auto_boxed_type(
init_function_expression: &Option<String>,
copy_into_function_expression: &Option<String>,
clear_function_expression: &Option<String>,
get_type_fn: &str,
get_type_fn: Option<&String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_type_fn: Option<&String>,
get_type_fn: Option<&str>,

derive: &[Derive],
) -> Result<()> {
let sys_crate_name = env.main_sys_crate_name();
Expand All @@ -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),
Expand All @@ -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, "}}")?;

Expand Down
31 changes: 12 additions & 19 deletions src/codegen/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analysis.glib_get_type.as_ref().map(|(ref a, _)| a),
analysis.glib_get_type.as_ref().map(|(ref a, _)| a).as_deref(),

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coercion still fails for me with as_deref()

&analysis.derives,
)?;
} else if let (Some(ref_fn), Some(unref_fn)) = (
analysis.specials.traits().get(&Type::Ref),
analysis.specials.traits().get(&Type::Unref),
Expand Down