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 770401 - docs: Add type checking for GObject properties in tutorial
docs: Add type checking for GObject properties in tutorial
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: docs
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-08-25 16:08 UTC by Philip Withnall
Modified: 2018-05-24 19:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
docs: Add type checking for GObject properties in tutorial (5.86 KB, patch)
2016-08-25 16:08 UTC, Philip Withnall
needs-work Details | Review

Description Philip Withnall 2016-08-25 16:08:40 UTC
Trivial patch attached.
Comment 1 Philip Withnall 2016-08-25 16:08:44 UTC
Created attachment 334157 [details] [review]
docs: Add type checking for GObject properties in tutorial

This improves the behaviour of the code snippets with -Wswitch-enum to
enable more compile-time checks for property names.
Comment 2 Emmanuele Bassi (:ebassi) 2016-08-25 16:27:15 UTC
Review of attachment 334157 [details] [review]:

::: docs/reference/gobject/tut_gobject.xml
@@ +470,3 @@
   PROP_FILENAME = 1,
   PROP_ZOOM_LEVEL,
+  /*< private >*/

No need.

::: docs/reference/gobject/tut_howto.xml
@@ +340,3 @@
   PROP_FILENAME = 1,
   PROP_ZOOM_LEVEL,
+  /*< private >*/

No need for this.

@@ +341,3 @@
   PROP_ZOOM_LEVEL,
+  /*< private >*/
+  LAST_PROP = PROP_ZOOM_LEVEL,

Why the rename? N_PROPERTIES is perfectly cromulent, and it's more appropriate to read when declaring the obj_properties GParamSpec array.

@@ +1248,3 @@
   PROP_AUTOSAVE_FREQUENCY = 1,
+  /*< private >*/
+  LAST_PROP = PROP_AUTOSAVE_FREQUENCY,

Same as above.

@@ +1259,3 @@
   ViewerFile *file = VIEWER_FILE (object);
 
+  switch ((ViewerFileProperty) prop_id)

Still think it kinda sucks.

BTW, if we're using an explicit type for property ids and compiler warnings, then we should drop the:

  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);

fragment.

@@ +1279,3 @@
   ViewerFile *file = VIEWER_FILE (object);
 
+  switch ((ViewerFileProperty) prop_id)

Same as above.

::: gobject/gobject.c
@@ +613,3 @@
+ *   PROP_FOO = 1,
+ *   PROP_BAR,
+ *   /<!-- -->*< private >*<!-- -->/

This is pointless: the whole typedef is private to the implementation.

The only reason why we use the "/*< private >*/" annotation is for public enumeration types that are annotated by gtk-doc stanzas.

@@ +1229,3 @@
  *   {
+ *     PROP_FOO = 1,
+ *     /<!-- -->*< private >*<!-- -->/

Same as above.
Comment 3 Philip Withnall 2016-08-25 19:56:43 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #2)
> Review of attachment 334157 [details] [review] [review]:
> 
> ::: docs/reference/gobject/tut_gobject.xml
> @@ +470,3 @@
>    PROP_FILENAME = 1,
>    PROP_ZOOM_LEVEL,
> +  /*&lt; private &gt;*/
> 
> No need.

True.

> @@ +341,3 @@
>    PROP_ZOOM_LEVEL,
> +  /*&lt; private &gt;*/
> +  LAST_PROP = PROP_ZOOM_LEVEL,
> 
> Why the rename? N_PROPERTIES is perfectly cromulent, and it's more
> appropriate to read when declaring the obj_properties GParamSpec array.

LAST_PROP is not the same as N_PROPERTIES; it’s N_PROPERTIES-1. This is necessary to avoid a warning from -Wswitch-enums about not handling N_PROPERTIES in the switch in get_property()/set_property(). gcc handily avoids emitting that warning for enum members which alias another.

> @@ +1259,3 @@
>    ViewerFile *file = VIEWER_FILE (object);
>  
> +  switch ((ViewerFileProperty) prop_id)
> 
> Still think it kinda sucks.

What? This is, like, the least sucky bit of the patch.

> BTW, if we're using an explicit type for property ids and compiler warnings,
> then we should drop the:
> 
>   default:
>     G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
> 
> fragment.

I kind of agree, but that then falls foul of -Wswitch-default.
Comment 4 Philip Withnall 2017-01-07 23:52:19 UTC
Ping?
Comment 5 GNOME Infrastructure Team 2018-05-24 19:03:38 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1195.