-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add support for array-length for parameters and return values #387
Conversation
With #389 and this, Gtk.RecentInfo can be fully autogenerated btw. |
src/codegen/function_body_chunk.rs
Outdated
self.parameters.push(Parameter::Out { | ||
parameter: parameter.into(), | ||
parameter: parameter_ffi_call_out::Parameter::new(parameter, array_length), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space
@@ -36,12 +36,12 @@ impl ToReturnValue for analysis::return_value::Info { | |||
pub fn out_parameter_as_return_parts(analysis: &analysis::functions::Info) | |||
-> (&'static str, &'static str) { | |||
use analysis::out_parameters::Mode::*; | |||
let is_tuple = analysis.outs.len() > 1; | |||
let num_outs = analysis.outs.iter().filter(|p| p.array_length.is_none()).count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn len() now unused
Bad change in glib:key_file - missed tuple - pub fn get_string_list(&self, group_name: &str, key: &str) -> Result<(Vec<String>, usize), Error> {
+ pub fn get_string_list(&self, group_name: &str, key: &str) -> Result<Vec<String>, usize, Error> { |
..and still return usize |
src/codegen/translate_from_glib.rs
Outdated
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line
Too many long lines but code too. |
or even SkipReason: None/InArrayLen/OutArrayLen |
*Too many long lines but it not big problem as code works. |
Thanks, I'll clean this up tomorrow. For the code style, what do you think about my suggestion to just run things through rustfmt soon and then require pull requests to use the correct, automatically enforced format? |
also maybe better pass |
About rustfmt, currently it change nothing in gir or panic with 'failed to emit error: operation not supported by the terminal' pub fn generate(
w: &mut Write,
env: &Env,
prop: &ChildProperty,
in_trait: bool,
only_declaration: bool,
indent: usize,
) -> Result<()> {
try!(generate_func(
w,
env,
prop,
in_trait,
only_declaration,
indent,
true,
));
try!(generate_func(
w,
env,
prop,
in_trait,
only_declaration,
indent,
false,
));
Ok(())
} So I don't against single apply in separate PR, but IMHO it don't ready to enforce. |
For parameters and fields.
Only pointer typed array elements are supported for now. gtk-rs#376
… parameter position
The comments should all be covered now. Remaining problem is Unrelated, |
Gio generation failed, other lib changes seems fine
|
src/codegen/function.rs
Outdated
let ret_array_length = if let Some(pos) = analysis.ret.parameter.as_ref().and_then(|p| p.array_length) { | ||
// The first parameter is &self in case of methods | ||
let pos_offset = if analysis.kind == library::FunctionKind::Method { 1 } else { 0 }; | ||
analysis.parameters.iter().nth((pos + pos_offset) as usize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy warning: called .iter().nth()
on a Vec. Calling .get()
is both faster and more readable
src/codegen/function.rs
Outdated
use analysis::out_parameters::Mode; | ||
// The actual return value was inserted at position 0 | ||
let pos_offset = if analysis.outs.mode == Mode::Combined || analysis.outs.mode == Mode::Throws(true) { 1 } else { 0 }; | ||
analysis.parameters.iter().nth((pos + pos_offset) as usize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
In the outs array they are the original one, in the params array not. It might make sense to use analysis::parameter::Info instead of library::Parameter for the outs array too.
https://bugzilla.gnome.org/show_bug.cgi?id=784020 (glib) For string parameters + array length, we currently still generate wrong code it seems. For some reason it is interpreted as a - <type name="utf8" c:type="const char*"/>
+ <array length="1" zero-terminated="0" c:type="char*">
+ <type name="utf8" c:type="char"/>
+ </array> @EPashkin Any idea why, or should I research/debug? |
https://bugzilla.gnome.org/show_bug.cgi?id=784035 (bug in gobject-introspection that causes it to drop |
|
One symbol has other type name. IMHO pango_layout_set_markup accepts just text, and len need used from it. |
Ah good point. I guess we need to parse the c:type of this, or the surrounding to know for sure. Otherwise this is ambiguous.
In sys mode it seems to count the asterisks (i.e. look at the c:type instead)
What do you mean? It also has to be changed the same way as |
I mean that pango_layout_set_markup accepts not array but utf8 string and array-length attribute may be cant applied to it. Same as "set_text". |
They all accept a string, yes. Which is an array of utf8 characters, and the length argument is the number of characters in there. What you basically mean is what I wrote here https://bugzilla.gnome.org/show_bug.cgi?id=784035#c1 ? In GLib and elsewhere, string parameters with an additional length parameter for the string length already use the (array length) annotation, and conceptually it's correct. |
I meant that string |
All those functions are working with UTF8 strings, not [u8]. The markup ones just in addition require the strings to be valid Pango markup (or things will fail), just like GTK labels if you configure them to show Pango markup |
IMHO all array-related problems is solved, can I merge this, or you want add something? |
It's doing the wrong things for strings, I'd like to fix that as part of this. Otherwise the array length annotations on strings (as exist in various libraries already) cause wrong code to be generated. But you could merge it now already if you want, and I'll work on that in another pull request then. |
Ok, I wait then |
Good to merge. I discussed the string+length stuff with gobject-introspection people on IRC, and there's no way to correctly annotate that currently unless your "string" is actually an array of bytes (and not a UTF8 string), in which case it would be (array length=len) (element-type guint8). |
Thanks, @sdroege. |
I do them, you do them, ...? |
😉 |
Alright, I'll try to get to that tonight then :) |
All submitted |
#376
Only pointer arrays are currently supported, the translation trait is even called FromGlibPtrContainer. This should be changed really to also be able to handle all kinds of integer (incl. byte) arrays.