GNOME Bugzilla – Bug 638434
Interfaces unsafely assume abstract functions are implemented
Last modified: 2018-05-22 13:50:24 UTC
valac generates interface virtual function wrappers like the following: properties ---------- gint interface_get_foo (FolksExtendedInfo* self) { return INTERFACE_GET_INTERFACE (self)->get_foo (self); } void interface_set_foo (FolksExtendedInfo* self, gint value) { INTERFACE_GET_INTERFACE (self)->set_foo (self, value); } methods ------- gint interface_bar (Interface* self) { return INTERFACE_GET_INTERFACE (self)->bar (self); } If 'foo' is a property or bar() is a method added to the interface after an implementing class implements the interface, accessing the property or calling the method on the old class will cause a segfault and otherwise put the client program in a very bad state. This situation can easily happen if a library exposes an interface which is implemented by a third-party library (which won't necessarily be up-to-date with the latest interface version), breaking backward compatibility in a very fragile way.
You can use abstract instead of virtual.
(In reply to comment #1) > You can use abstract instead of virtual. Sorry, the functions are literally 'abstract' in Vala. I was referring to the C interface functions as 'virtual', since that's more common terminology in that context. I'll update the bug title.
*** Bug 779887 has been marked as a duplicate of this bug. ***
Using: if (INTERFACE_GET_INTERFACE (self)->get_foo (self) != NULL) return INTERFACE_GET_INTERFACE (self)->get_foo (self); return -1; But this code should mutate based on return type.
While bug 779887 might be a dup of this, the difference I was trying to explain is that the vfunc may not exist at all. So even doing ->get_foo is a source error in C.
-- 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/vala/issues/153.