-
Notifications
You must be signed in to change notification settings - Fork 33
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 more comprehensive support for primitive value type parameters #795
Conversation
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.
This is some hard topic. Let's start with some trivial fixes which are my comments left on the code.
Before getting into the details let me state that I did not take a detailed look into the code. But this was not strictly necessary as you probably missed one point:
Out / InOut parameters can return null
and thus be nullable. The use case use case you are describing is called optional.
See the GI documentation for further explanation.
In general the generator currently does not know about the optional
attribute. But I assume it is not needed currently. Or at least could be part of another PR?
I created a new branch based on yours which updates the unit tests in a way that I think we need to be able to prove that inout / out parameters are working correctly.
What do you think?
...ration/Generator/Renderer/Public/ParameterToNativeExpression/Converter/PrimitiveValueType.cs
Outdated
Show resolved
Hide resolved
74c0e65
to
8a4a5ef
Compare
b0f7e8c
to
7c300f1
Compare
Updated with the style changes, and to read the Parameters that are both nullable and optional are skipped since this would require extra handling, and this doesn't actually occur for any functions currently. |
….g. directions of inout or out - Don't generate public bindings for primitive value pointer types that have a direction of 'in'. The occurrences of this in the gir files were all actually treating the pointer as an array, but didn't mark it as such in the documentation (e.g. gdk_pango_layout_get_clip_region) - Translate inout and out parameters to 'ref' and 'out' parameters in C#. - Optional out parameters are just exposed as (non-nullable) out parameters in C#. In C the meaning of this is "ignore the output value", so in C# I think the idiomatic equivalent is to just have the user do `out var _` if they want to ignore it. - Optional inout parameters are similarly exposed as a non-nullable ref parameter for simplicity - The caller-allocates and transfer flags should not be used for primitive types (https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/446) - With these changes, Pango.Layout.GetLogAttrs() is now generated but encountered an error with record arrays that have direction=out. This is skipped for now, to be handled with bug #763
7c300f1
to
a0b3103
Compare
I think this covers all of the possible cases for primitive value types, with the main addition being support for functions with
inout
orout
primitive value parametersDon't generate public bindings for primitive value pointer types that have a direction of
in
. Many occurrences of this in the gir files were actually treating the pointer as an array, but didn't mark it as such in the documentation (e.g.gdk_pango_layout_get_clip_region()
), so I don't think we can safely generate public bindings for this case.Translate
inout
andout
parameters to 'ref' and 'out' parameters in C#.out
parameters are just exposed as non-nullableout
parameters in C#. In C the meaning of null is "ignore the output value", so in C# I think the idiomatic equivalent is to just have the user doout var _
if they want to ignore it. Anout int?
parameter doesn't really make sense with what the native function is doing.inout
parameters are similarly exposed as a non-nullableref
parameter. I'm less sure about this - it could perhaps be aref int?
parameter, but this case only occurs forgst_init()
currently.caller-allocates
andtransfer
flags seem to be meaningless and are inconsistently used by the native functions. I didn't find any occurrences of native functions allocating or freeing a primitive value type pointerWith these changes,
Pango.Layout.GetLogAttrs()
was now being generated but encountered a compile error with record arrays that have direction=out, since the generated code doesn't work at all in that case. This is skipped for now, to be handled with bug Verify handling of out and inout array parameters #763