Skip to content

Commit

Permalink
Support finish-func annotation
Browse files Browse the repository at this point in the history
To get the correct name of the finish function if any.

Fixes: gtk-rs#1561
  • Loading branch information
A6GibKm committed Jun 2, 2024
1 parent 4ba6dc1 commit bc62e79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/analysis/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ impl Bounds {
));
if r#async && (par.name == "callback" || par.name.ends_with("_callback")) {
let func_name = func.c_identifier.as_ref().unwrap();
let finish_func_name = finish_function_name(func_name);
let finish_func_name = if let Some(finish_func_name) = &func.finish_func {
finish_func_name.to_string()
} else {
finish_function_name(func_name)
};
if let Some(function) = find_function(env, &finish_func_name) {
// FIXME: This should work completely based on the analysis of the finish()
// function but that a) happens afterwards and b) is
Expand Down
6 changes: 5 additions & 1 deletion src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,11 @@ fn analyze_async(
// Checks for /*Ignored*/ or other error comments
*commented |= callback_type.contains("/*");
let func_name = func.c_identifier.as_ref().unwrap();
let finish_func_name = finish_function_name(func_name);
let finish_func_name = if let Some(finish_func_name) = &func.finish_func {
finish_func_name.to_string()
} else {
finish_function_name(func_name)
};
let mut output_params = vec![];
let mut ffi_ret = None;
if let Some(function) = find_function(env, &finish_func_name) {
Expand Down
1 change: 1 addition & 0 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ pub struct Function {
pub doc_deprecated: Option<String>,
pub get_property: Option<String>,
pub set_property: Option<String>,
pub finish_func: Option<String>,
}

#[derive(Debug)]
Expand Down
10 changes: 10 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ impl Library {
doc_deprecated,
get_property: None,
set_property: None,
finish_func: None,
})
} else {
Err(parser.fail("Missing <return-value> element"))
Expand Down Expand Up @@ -1022,6 +1023,14 @@ impl Library {
let deprecated_version = self.read_deprecated_version(parser, ns_id, elem)?;
let mut gtk_get_property = None;
let mut gtk_set_property = None;
let finish_func = c_identifier.and_then(|c_identifier| {
elem.attr("finish-func").map(|finish_func_name| {
format!(
"{}{finish_func_name}",
c_identifier.strip_suffix(&fn_name).unwrap()
)
})
});

let mut params = Vec::new();
let mut ret = None;
Expand Down Expand Up @@ -1113,6 +1122,7 @@ impl Library {
doc_deprecated,
get_property,
set_property,
finish_func,
})
} else {
Err(parser.fail_with_position(
Expand Down

0 comments on commit bc62e79

Please sign in to comment.