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 finish-func annotation #1570

Merged
merged 3 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 {
A6GibKm marked this conversation as resolved.
Show resolved Hide resolved
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
13 changes: 9 additions & 4 deletions src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,10 @@ fn analyze_function(
) -> Info {
let ns_id = type_tid.map_or(MAIN_NAMESPACE, |t| t.ns_id);
let type_tid = type_tid.unwrap_or_default();
let r#async = func.parameters.iter().any(|parameter| {
parameter.scope == ParameterScope::Async && parameter.c_type == "GAsyncReadyCallback"
});
let r#async = func.finish_func.is_some()
|| func.parameters.iter().any(|parameter| {
parameter.scope == ParameterScope::Async && parameter.c_type == "GAsyncReadyCallback"
});
let has_callback_parameter = !r#async
&& func
.parameters
Expand Down Expand Up @@ -984,7 +985,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
3 changes: 3 additions & 0 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ pub struct Function {
pub doc_deprecated: Option<String>,
pub get_property: Option<String>,
pub set_property: Option<String>,
pub finish_func: Option<String>,
pub async_func: Option<String>,
pub sync_func: Option<String>,
}

#[derive(Debug)]
Expand Down
16 changes: 16 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ impl Library {
doc_deprecated,
get_property: None,
set_property: None,
finish_func: None,
async_func: None,
sync_func: None,
})
} else {
Err(parser.fail("Missing <return-value> element"))
Expand Down Expand Up @@ -1022,6 +1025,16 @@ 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 async_func = elem.attr("async-func").map(ToString::to_string);
let sync_func = elem.attr("sync-func").map(ToString::to_string);

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