After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787551 - Factor out some duplicated code in GParamSpec validation
Factor out some duplicated code in GParamSpec validation
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-09-11 15:08 UTC by Federico Mena Quintero
Modified: 2017-09-11 20:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GObjectClass: Validate installing property/properties in the same way (2.27 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
GObjectClass: extract class type and parent type at the beginning (2.04 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
validate_and_install_class_property(): Factor out function to add a new property to a class (6.07 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
install_property_internal(): Propagate failure when installing duplicated properties (3.10 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
g_object_interface_install_property(): Do interface-specific validations first (1.01 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
validate_and_install_property(): Validate presence of get/set_property methods last (1.61 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
validate_and_install_property(): Check pspec-specific fields in the same order as g_object_interface_install_property() (1.18 KB, patch)
2017-09-11 16:26 UTC, Federico Mena Quintero
committed Details | Review
validate_pspec_to_install(): Factor out function to validate a GParamSpec (3.06 KB, patch)
2017-09-11 16:27 UTC, Federico Mena Quintero
committed Details | Review

Description Federico Mena Quintero 2017-09-11 15:08:10 UTC
There is some duplicated code among

  g_object_class_install_property()
  g_object_class_install_properties()
  g_object_interface_install_property()

where they validate the GParamSpec and whether the class has all the required methods.

I'll attach a patch set that takes care of this.
Comment 1 Federico Mena Quintero 2017-09-11 16:26:18 UTC
Created attachment 359540 [details] [review]
GObjectClass: Validate installing property/properties in the same way

Then we'll be able to factor out duplicated code.
Comment 2 Federico Mena Quintero 2017-09-11 16:26:27 UTC
Created attachment 359541 [details] [review]
GObjectClass: extract class type and parent type at the beginning
Comment 3 Federico Mena Quintero 2017-09-11 16:26:34 UTC
Created attachment 359542 [details] [review]
validate_and_install_class_property(): Factor out function to add a new property to a class

This was duplicated between g_object_class_install_property() and
g_object_class_install_properties().
Comment 4 Federico Mena Quintero 2017-09-11 16:26:40 UTC
Created attachment 359543 [details] [review]
install_property_internal(): Propagate failure when installing duplicated properties
Comment 5 Federico Mena Quintero 2017-09-11 16:26:45 UTC
Created attachment 359544 [details] [review]
g_object_interface_install_property(): Do interface-specific validations first
Comment 6 Federico Mena Quintero 2017-09-11 16:26:50 UTC
Created attachment 359545 [details] [review]
validate_and_install_property(): Validate presence of get/set_property methods last
Comment 7 Federico Mena Quintero 2017-09-11 16:26:56 UTC
Created attachment 359546 [details] [review]
validate_and_install_property(): Check pspec-specific fields in the same order as g_object_interface_install_property()
Comment 8 Federico Mena Quintero 2017-09-11 16:27:02 UTC
Created attachment 359547 [details] [review]
validate_pspec_to_install(): Factor out function to validate a GParamSpec

This was duplicated also in g_object_interface_install_property().

Now, validations specific to classes happen in
validate_and_install_class_property() - specifically, the checks for
the presence of the get_property() and set_property() methods.
Comment 9 Matthias Clasen 2017-09-11 16:30:49 UTC
Review of attachment 359540 [details] [review]:

looks good to me
Comment 10 Matthias Clasen 2017-09-11 16:31:45 UTC
Review of attachment 359541 [details] [review]:

sure
Comment 11 Matthias Clasen 2017-09-11 16:34:54 UTC
Review of attachment 359542 [details] [review]:

ok
Comment 12 Matthias Clasen 2017-09-11 16:36:32 UTC
Review of attachment 359543 [details] [review]:

not sure there's much to be won here - pretty much all of these errors just mean 'this code is busted'. But anyway...
Comment 13 Matthias Clasen 2017-09-11 16:37:07 UTC
Review of attachment 359544 [details] [review]:

right
Comment 14 Matthias Clasen 2017-09-11 16:37:47 UTC
Review of attachment 359545 [details] [review]:

ok
Comment 15 Matthias Clasen 2017-09-11 16:38:18 UTC
Review of attachment 359546 [details] [review]:

ok
Comment 16 Matthias Clasen 2017-09-11 16:39:35 UTC
Review of attachment 359547 [details] [review]:

::: gobject/gobject.c
@@ +559,3 @@
+      return FALSE;
+    }
+

Loose the {} here, to match glib/gtk+ style

@@ +768,3 @@
+    {
+      return;
+    }

same here
Comment 17 Philip Withnall 2017-09-11 17:06:44 UTC
These all look good to me too. Thanks for the patches!
Comment 18 Federico Mena Quintero 2017-09-11 17:47:55 UTC
Pushed everything after removing the braces around single-line returns.  Thanks!

About the validation - I wanted to prevent the class->* from being modified if the property didn't actually get inserted because it was in error.