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 570792 - Support interface properties when subclassing
Support interface properties when subclassing
Status: RESOLVED OBSOLETE
Product: gnome-perl
Classification: Bindings
Component: Glib
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtk2-perl-bugs
gtk2-perl-bugs
Depends on:
Blocks: 570793
 
 
Reported: 2009-02-06 15:23 UTC by Torsten Schoenfeld
Modified: 2021-07-05 12:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch installing properties, but they don't reach GET_PROPERTY/SET_PROPERTY (4.55 KB, patch)
2010-11-08 19:45 UTC, Kevin Ryde
none Details | Review

Description Torsten Schoenfeld 2009-02-06 15:23:17 UTC
When subclasses want to implement an interface that contains properties[1], there appear to be two options[2]:

• add new properties with matching names; or
• use g_object_class_override_property.

I think Glib::Type->register should use the second approach when it encounters a subclass which wants to implement an interface with a property and which doesn't have its own property with the same name.  This means that Perl subclasses implementing some interface will get calls to their [GS]ET_PROPERTY for these properties automatically.

When a subclass is registered which implements some interface with properties but doesn't override one of the properties, a critical warning is printed:

  GLib-GObject-CRITICAL **: Object class Switchable doesn't implement property  
  'orientation' from interface 'GtkOrientable'

In gtk+, there appear to be four interfaces with properties: GtkActivatable, GtkFileChooser, GtkOrientable, and GtkRecentChooser.

[1] <http://library.gnome.org/devel/gobject/2.19/howto-interface-properties.html>
[2] <http://library.gnome.org/devel/gobject/2.19/gobject-The-Base-Object-Type.html#g-object-interface-install-property>
Comment 1 Kevin Ryde 2010-11-08 19:45:42 UTC
Created attachment 174092 [details] [review]
patch installing properties, but they don't reach GET_PROPERTY/SET_PROPERTY

I think saying "interfaces => [ ... ]" could automatically add the interface properties.  If you're implementing an interface then that'll be usually what you want.  Worry about subtle variations later.

I wondered if it was as easy as the gobject manual suggested and you just had to g_object_class_override_property() each of the g_object_interface_list_properties().  I even threw down the attached few lines to that end.  However,

The pspec which reaches gperl_type_get_property() is the underlying one out of the interface, and its pspec->owner_type is the interface, not the class implementing the interface.  This means gperl_type_get_property() doesn't go to the class' GET_PROPERTY.

The way g_object_get_property() looks through an override to the underlying can be seen in object_get_property() of gobject.c.  I suppose someone thought that was a good idea.

I suspect this is another case of the C code being oriented towards individual class funcs such as class->get_property implicitly knowing which class they're for, rather than a generic like gperl_type_get_property().  Perhaps the property_id number could encode something to identify the actual target class.  Normally those ids are consecutive 1 to N, but I get the impression it's an arbitrary integer for use by the class in question.

Second, I see g_object_class_override_property() looks first in parent classes and then in interfaces for a property of the given name.  If a subclass has an interface with an interface property with the same name as a superclass property then g_object_class_override_property() might end up taking the superclass one as the target, not the interface.

I suppose that affects C code as well.  Unless the gobject manual has something better to say I suspect an explicit

    pspec = g_param_spec_override (name, iface_pspec);
    g_object_class_install_property (oclass, property_id, pspec);

might be necessary to ensure it's the interface one which is installed.

This sort of thing might come up if a subclass re-implements an interface already implemented in a superclass.  That's fairly common of course if a subclass wants to do things slightly differently.  Eg. I've made various subclasses redoing TreeDragSource to have different answers about draggability.  Whether there's any like that with interface properties would be another matter.
Comment 2 GNOME Infrastructure Team 2021-07-05 12:22:11 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME?utf8=%E2%9C%93&filter=perl-

Thank you for your understanding and your help.