]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use g_object_notify_by_pspec() to notify property-changes
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 11 Apr 2017 12:42:46 +0000 (14:42 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 17 Apr 2017 08:58:45 +0000 (10:58 +0200)
codegen/valaccodebasemodule.vala
codegen/valagtypemodule.vala

index 8a95c6431d7bdc39a32fe86adc0f22e5d2938d69..3e51c96a295c40457846c5ecce5281063d10e266 100644 (file)
@@ -1787,9 +1787,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        if (is_gobject_property (prop) &&
                            prop.notify &&
                            (acc.writable || acc.construction)) {
-                               var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify"));
+                               var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify_by_pspec"));
                                notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GObject *"));
-                               notify_call.add_argument (get_property_canonical_cconstant (prop));
+                               notify_call.add_argument (get_param_spec_cexpression (prop));
 
                                var get_accessor = prop.get_accessor;
                                if (get_accessor != null && get_accessor.automatic_body) {
@@ -6614,7 +6614,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return false;
        }
 
-       public virtual CCodeFunctionCall get_param_spec (Property prop) {
+       public virtual CCodeExpression get_param_spec_cexpression (Property prop) {
+               return new CCodeFunctionCall (new CCodeIdentifier (""));
+       }
+
+       public virtual CCodeExpression get_param_spec (Property prop) {
                return new CCodeFunctionCall (new CCodeIdentifier (""));
        }
 
index 86a6474a176c18a9196c49295c3c54480620182a..6d0f0d2ebfee8e2c631ab2b63aa451111727cea6 100644 (file)
@@ -522,7 +522,6 @@ public class Vala.GTypeModule : GErrorModule {
                                string macro = "(G_TYPE_CLASS_GET_PRIVATE (klass, %s, %sClassPrivate))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
                                decl_space.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_CLASS_PRIVATE(klass)".printf (get_ccode_upper_case_name (cl, null)), macro));
                        }
-                       decl_space.add_type_member_declaration (prop_enum);
                } else {
                        if (cl.has_private_fields) {
                                Report.error (cl.source_reference, "Private fields not supported in compact classes");
@@ -563,10 +562,19 @@ public class Vala.GTypeModule : GErrorModule {
                instance_init_context = new EmitContext (cl);
                instance_finalize_context = new EmitContext (cl);
 
-
                generate_class_struct_declaration (cl, cfile);
                generate_class_private_declaration (cl, cfile);
 
+               var last_prop = "%s_LAST_PROPERTY".printf (get_ccode_upper_case_name (cl));
+               if (is_gtypeinstance) {
+                       cfile.add_type_declaration (prop_enum);
+
+                       var prop_array_decl = new CCodeDeclaration ("GParamSpec*");
+                       prop_array_decl.modifiers |= CCodeModifiers.STATIC;
+                       prop_array_decl.add_declarator (new CCodeVariableDeclarator ("%s_properties".printf (get_ccode_lower_case_name (cl)), null, new CCodeDeclaratorSuffix.with_array (new CCodeIdentifier (last_prop))));
+                       cfile.add_type_declaration (prop_array_decl);
+               }
+
                if (!cl.is_internal_symbol ()) {
                        generate_class_struct_declaration (cl, header_file);
                }
@@ -619,6 +627,8 @@ public class Vala.GTypeModule : GErrorModule {
                                pop_context ();
                        }
 
+                       prop_enum.add_value (new CCodeEnumValue (last_prop));
+
                        if (cl.get_signals ().size > 0) {
                                var last_signal = "%s_LAST_SIGNAL".printf (get_ccode_upper_case_name (cl));
                                signal_enum.add_value (new CCodeEnumValue (last_signal));
@@ -1719,7 +1729,15 @@ public class Vala.GTypeModule : GErrorModule {
                cfile.add_function (instance_finalize_context.ccode);
        }
 
-       public override CCodeFunctionCall get_param_spec (Property prop) {
+       public override CCodeExpression get_param_spec_cexpression (Property prop) {
+               var cl = (TypeSymbol) prop.parent_symbol;
+               var prop_array = new CCodeIdentifier ("%s_properties".printf (get_ccode_lower_case_name (cl)));
+               var prop_enum_value = new CCodeIdentifier (get_ccode_upper_case_name (prop));
+
+               return new CCodeElementAccess (prop_array, prop_enum_value);
+       }
+
+       public override CCodeExpression get_param_spec (Property prop) {
                var cspec = new CCodeFunctionCall ();
                cspec.add_argument (get_property_canonical_cconstant (prop));
                cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
@@ -1900,7 +1918,11 @@ public class Vala.GTypeModule : GErrorModule {
                }
                cspec.add_argument (new CCodeConstant (pflags));
 
-               return cspec;
+               if (prop.parent_symbol is Interface) {
+                       return cspec;
+               } else {
+                       return new CCodeAssignment (get_param_spec_cexpression (prop), cspec);
+               }
        }
 
        public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {