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 540483 - method attributes are not inherited
method attributes are not inherited
Status: RESOLVED INCOMPLETE
Product: vala
Classification: Core
Component: Objects
0.3.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-27 12:22 UTC by sam
Modified: 2010-11-24 21:31 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description sam 2008-06-27 12:22:04 UTC
If a virtual method has this modifier:
[CCcode (instance_pos = -1)]

The [CCode] attributes aren't being inherited with override methods and
aren't being checked as possible warnings either, see this sample code:

public class PhoneDialer : Gtk.Object {
  construct {
    GLib.Signal.connect(this.widgets.button_undo, "clicked",
(GLib.Callback) on_button_undo_clicked, this);
  }
 
  [CCode (instance_pos = -1)]
  public virtual void on_button_undo_clicked (Gtk.Widget widget) { }
}

public class GladePhoneUI : PhoneDialer {
    [CCode (instance_pos = -1)]
    public override void on_button_undo_clicked (Gtk.Widget widget) {
        widgets.dialer_entry.backspace();
    }
}

If I remove the CCode in the subclass, then the virtual method is
invoked wrongly, with scrambled arguments, as we see by looking at the C
code below.

At a first look it seems as though the override method should inherit at
least some of the CCode attributes of the method they override.

A closer look shows something else, because two types of methods are
generated for virtual and overridden methos:

In the generated C, virtual methods have an entry method; like this,
which dispatches to the actual method.

void phone_dialer_on_button_undo_clicked (GtkWidget* widget,
PhoneDialer* self) {
    PHONE_DIALER_GET_CLASS (self)->on_button_undo_clicked (widget, self);
}

and then actual methods like this:
static void phone_dialer_real_on_button_undo_clicked (GtkWidget* widget,
PhoneDialer* self) {
    g_return_if_fail (IS_PHONE_DIALER (self));
    g_return_if_fail (GTK_IS_WIDGET (widget));
}
and this, in the subclass, without a matching instance_pos
static void glade_phone_ui_real_on_button_undo_clicked (PhoneDialer*
base, GtkWidget* widget) {
    GladePhoneUI * self;
    self = GLADE_PHONE_UI (base);
    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_signal_emit_by_name (G_OBJECT (PHONE_DIALER
(self)->widgets->dialer_entry), "backspace");
}

We see that the last function (above) has the arguments the wrong way
around because I had removed the instance_pos.

But in fact it is only the entry method that needs to take into account
instance_pos when ordering it's declared arguments.
The inner "real" methods can be "normal" without any strange calling
conventions, and the entry dispatching method could "know" this.

And so I'm really suggesting that for virtual methods, instance_pos only
apply to the wrapper and not to the real functions at all.
It would be illegal to specify instance_pos on override methods, and they could only be specified on virtual methods.

(Unless the subclass overridden method is implemented by an existing C function, is that possible?)

Consistency should at least be enforced across all overriddings of the method.
Comment 1 Felipe Besoaín Pino 2010-09-28 18:29:11 UTC
This bug was reported against a version which is not supported any more. Developers are no longer working on this version so there will not be any bug fixes for it.
Can you please check again if the issue you reported here still happens in a recent version of GNOME and update this report by adding a comment and adjusting the 'Version' field?

Again thank you for reporting this and sorry that it could not be fixed for the version you originally used here.

Without feedback this report will be closed as INCOMPLETE after 6 weeks.
Comment 2 sam 2010-09-28 20:59:50 UTC
I think it would be simpler to ask on the mailing list whether or not for virtual methods, instance_pos only apply to the wrapper and not to the real function.

If it does, then the bug is fixed, if it doesn't then the bug is not fixed.

I don't have a vala build or my project to check against.
Comment 3 sam 2010-09-28 21:22:20 UTC
In any case, Jurgen should know if he plans to do this or has done it (or not).
Comment 4 Tobias Mueller 2010-11-24 21:31:31 UTC
Closing this bug report as no further information has been provided. Please feel free to reopen this bug if you can provide the information asked for.
Thanks!