ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, ccall, new CCodeConstant ("0")));
} else if (property_type is StructValueType) {
ccode.add_declaration (get_ccode_name (property_type), new CCodeVariableDeclarator ("old_value"));
- get_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("old_value")));
-
- var get_expr = new CCodeCommaExpression ();
- get_expr.append_expression (get_call);
- get_expr.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("old_value")));
-
+ if (property_type.nullable) {
+ ccode.add_assignment (new CCodeIdentifier ("old_value"), get_call);
+ } else {
+ get_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("old_value")));
+ ccode.add_expression (get_call);
+ }
var equalfunc = generate_struct_equal_function ((Struct) property_type.data_type);
var ccall = new CCodeFunctionCall (new CCodeIdentifier (equalfunc));
ccall.add_argument (new CCodeIdentifier ("value"));
- ccall.add_argument (get_expr);
+ if (property_type.nullable) {
+ ccall.add_argument (new CCodeIdentifier ("old_value"));
+ } else {
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("old_value")));
+ }
ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, ccall, new CCodeConstant ("TRUE")));
} else {
ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, get_call, new CCodeIdentifier ("value")));
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)) {
objects/property-read-only-write.test \
objects/property-construct-only-write.test \
objects/property-construct-only-write-foreign.test \
+ objects/property-gboxed-nullable.vala \
objects/property-static.vala \
objects/regex.vala \
objects/signals.vala \
--- /dev/null
+public struct Bar {
+ public string s;
+}
+
+public class Foo : Object {
+ public Bar? bar { get; construct set; }
+
+ public Foo (Bar? bar) {
+ Object (bar: bar);
+ }
+}
+
+public class Faz : Object {
+ [NoAccessorMethod]
+ public Bar? baz { owned get; set; }
+}
+
+void main () {
+ {
+ var foo = new Foo (null);
+ assert (foo.bar == null);
+ }
+ {
+ Bar bar = { "foo" };
+ var foo = (Foo) Object.@new (typeof (Foo), "bar", bar);
+ assert (foo.bar == bar);
+ assert (foo.bar.s == "foo");
+ foo.bar = null;
+ assert (foo.bar == null);
+ }
+ {
+ Bar bar = { "foo" };
+ var foo = (Foo) Object.@new (typeof (Foo), "bar", null);
+ assert (foo.bar == null);
+ foo.bar = bar;
+ assert (foo.bar == bar);
+ }
+ {
+ Bar bar = { "foo" };
+ var faz = new Faz ();
+ assert (faz.baz == null);
+ faz.baz = bar;
+ assert (faz.baz == bar);
+ assert (faz.baz.s == "foo");
+ faz.baz = null;
+ assert (faz.baz == null);
+ }
+}
public bool is_gobject_property_type (DataType property_type) {
var st = property_type.data_type as Struct;
- if (st != null && (!st.get_attribute_bool ("CCode", "has_type_id", true) || property_type.nullable)) {
- return false;
+ if (st != null) {
+ if (st.get_attribute_bool ("CCode", "has_type_id", true)) {
+ // Allow GType-based struct types
+ } else if (property_type.nullable) {
+ return false;
+ }
}
if (property_type is ArrayType && ((ArrayType) property_type).element_type.data_type != string_type.data_type) {