diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-05-06 14:48:25 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-05-06 15:10:28 +0200 |
commit | 3af1cfb3bf6b1d3d4a8116382e6eda702f7335bf (patch) | |
tree | c823b0fa5871ea024824b0f85f1317ac912bdc01 /codegen/valagobjectmodule.vala | |
parent | 23a8257eafbcce0280dd26fe011fdb66dc1b684d (diff) | |
download | vala-3af1cfb3bf6b1d3d4a8116382e6eda702f7335bf.tar.gz |
codegen: Support GObject properties with nullable GType-based struct type
Fixes https://gitlab.gnome.org/GNOME/vala/issues/792
Diffstat (limited to 'codegen/valagobjectmodule.vala')
-rw-r--r-- | codegen/valagobjectmodule.vala | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala index 8ad676ab9..8c31c924f 100644 --- a/codegen/valagobjectmodule.vala +++ b/codegen/valagobjectmodule.vala @@ -233,21 +233,26 @@ public class Vala.GObjectModule : GTypeModule { ccode.add_case (new CCodeIdentifier ("%s_PROPERTY".printf (get_ccode_upper_case_name (prop)))); if (prop.property_type.is_real_struct_type ()) { - var st = prop.property_type.data_type as Struct; - ccode.open_block (); - ccode.add_declaration (get_ccode_name (st), new CCodeVariableDeclarator ("boxed")); + ccode.add_declaration (get_ccode_name (prop.property_type), new CCodeVariableDeclarator ("boxed")); ccall = new CCodeFunctionCall (cfunc); ccall.add_argument (cself); - var boxed_addr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("boxed")); - ccall.add_argument (boxed_addr); - ccode.add_expression (ccall); + if (prop.property_type.nullable) { + ccode.add_assignment (new CCodeIdentifier ("boxed"), ccall); + } else { + ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("boxed"))); + ccode.add_expression (ccall); + } var csetcall = new CCodeFunctionCall (); csetcall.call = get_value_setter_function (prop.property_type); csetcall.add_argument (new CCodeIdentifier ("value")); - csetcall.add_argument (boxed_addr); + if (prop.property_type.nullable) { + csetcall.add_argument (new CCodeIdentifier ("boxed")); + } else { + csetcall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("boxed"))); + } add_guarded_expression (prop, csetcall); if (requires_destroy (prop.get_accessor.value_type)) { |