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.
  • Loading branch information
A6GibKm committed Jun 1, 2024
1 parent 1ebe20c commit 2823917
Show file tree
Hide file tree
Showing 4 changed files with 14 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 {
format!("{}{finish_func_name}", func_name.strip_suffix(&func.name).unwrap())
} 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 @@ -978,7 +978,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 {
format!("{}{finish_func_name}", func_name.strip_suffix(&func.name).unwrap())
} 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 @@ -551,6 +551,7 @@ pub struct Function {
pub deprecated_version: Option<Version>,
pub doc: Option<String>,
pub doc_deprecated: Option<String>,
pub finish_func: Option<String>,
}

#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ impl Library {
deprecated_version,
doc,
doc_deprecated,
finish_func: None,
})
} else {
Err(parser.fail("Missing <return-value> element"))
Expand Down Expand Up @@ -1017,6 +1018,7 @@ impl Library {
let is_method = kind == FunctionKind::Method;
let version = self.read_version(parser, ns_id, elem)?;
let deprecated_version = self.read_deprecated_version(parser, ns_id, elem)?;
let finish_func = elem.attr("finish-func").map(ToString::to_string);

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

0 comments on commit 2823917

Please sign in to comment.