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 4 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, Option<Version>)>,
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((ref get_type_fn, _get_type_version)) = get_type_fn {
Copy link
Member

Choose a reason for hiding this comment

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

This requires a get_type function, or otherwise more changes in glib are needed

Copy link
Member

Choose a reason for hiding this comment

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

For the case of not BoxedInline but normal Boxed

Copy link
Author

Choose a reason for hiding this comment

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

So the get_type_fn here can't be None then?

Copy link
Member

Choose a reason for hiding this comment

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

Well, there won't be a copy/free function here otherwise and that won't compile without further changes in glib

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((ref get_type_fn, _get_type_version)) = 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,
Copy link
Member

Choose a reason for hiding this comment

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

maybe analysis.glib_get_type.map(|ref a,_| a) or something like that to avoid passing the version that's unneeded here ?

Copy link
Author

Choose a reason for hiding this comment

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

Ok

&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