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

Not parsing/handling array specific GIR fields (length parameter position, zero-terminated) #376

Closed
sdroege opened this issue May 22, 2017 · 6 comments

Comments

@sdroege
Copy link
Member

sdroege commented May 22, 2017

See e.g. https://wiki.gnome.org/action/show/Projects/GObjectIntrospection/Annotations#Array_length for an example with parameter position (the GIR does not contain the parameter name but its position).

@sdroege
Copy link
Member Author

sdroege commented May 22, 2017

I'm not sure how to get this information from src/parser.rs to analysis/codegenerator. Would I just parse them and store them in the library::Parameter type as additional fields of types Option / Option, and then pass those through the different layers?

For the length parameter position it would then be needed in the code generator to handle two cases:

  1. Normal parameter (e.g. fn f(length: u32, arr: &[Something])). The length parameter would have to be removed from the generated function, and instead pass arr.len() to the C function
  2. Out parameters, which I would have to research how that is handled at all currently

For the zero-terminated parameter, it only affects the code generator inside the function body and it needs to make sure to

  1. For normal parameters to add a ptr::null() at the end before passing it to the C function
  2. For out parameters to get the length by looking for a terminating ptr::is_null() in the array

@EPashkin
Copy link
Member

IMHO normal to store length in library::Parameter as len_position: Option<int>.
You right about input parameters. Note: for direct arrays we always add last element in https://github.com/gtk-rs/glib/blob/master/src/translate.rs#L459-L474.
About out/return parameters:
in cases when size returned we use from_glib_(none|container|full)_num in manual code,
for NULL-ended we have https://github.com/gtk-rs/glib/blob/master/src/translate.rs#L856-L866

@sdroege
Copy link
Member Author

sdroege commented May 22, 2017

Thanks for the pointers. The problem with all these is that they always require copying, which is not always required. But I guess that's for a later time then. Let's first make it work automatically at all ;)

@sdroege
Copy link
Member Author

sdroege commented May 26, 2017

While implementing all that, should probably also add a mapping for C arrays of gchar/guchar/guint8 and similar.

@EPashkin
Copy link
Member

Yes, that would be great

@sdroege
Copy link
Member Author

sdroege commented May 28, 2017

Still working on this btw, just busy with other things at the same time and this requires some minor code reorganization so that function_body_chunk can get all the information where it's needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants