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 786931 - rnc/rng files specify "class" as mandatory for objects, but the parser treats it as optional
rnc/rng files specify "class" as mandatory for objects, but the parser treats...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
unspecified
Other All
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks:
 
 
Reported: 2017-08-28 17:17 UTC by Debarshi Ray
Modified: 2017-09-25 13:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkBuilder: Enforce "class" as a mandatory attribute for <object> (3.15 KB, patch)
2017-09-18 16:30 UTC, Debarshi Ray
none Details | Review
GtkBuilder: Enforce "class" as a mandatory attribute for <object> (3.47 KB, patch)
2017-09-18 16:35 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-08-28 17:17:02 UTC
gtkbuilder.rnc says:

object = element object {
  attribute id { xsd:ID } ?,
  attribute class { text },
  attribute type-func { text } ?,
  attribute constructor { text } ?,
  (property | signal | child | ANY) *
}

However, the parser uses G_MARKUP_COLLECT_OPTIONAL when looking for the "class" attribute.

Apart from the aesthetics of it, enforcing "class" as a mandatory attribute for "object":s is a nice idea because it can help Vala [1]. For GTK+ template classes, the Vala compiler ensures that all [GtkChild] class members in Vala have a matching XML object with the right type. However, it doesn't know about "type-func". So, if only the "type-func" attribute is used, then it will fail to compile because it won't know about the XML object. See vala/codegen/valagtkmodule.vala

It seems easier to fix this in GtkBuilder than to teach valac to get the type from the "type-func". But I know little about Vala, so I might be wrong.

Since this will break existing run-time behaviour, it can only be done in master, and not fit for gtk3. Although, note that "class" attributes are vastly more common than "type-func", so breakage should be minimum.

[1] https://bugs.webkit.org/show_bug.cgi?id=175937#c16
Comment 1 Matthias Clasen 2017-08-28 17:31:27 UTC
Just to be clear, the suggestion is to make the GtkBuilder parser throw and error if class is missing ? Thats fine with me. Will you write a patch ?
Comment 2 Debarshi Ray 2017-08-28 18:51:06 UTC
(In reply to Matthias Clasen from comment #1)
> Just to be clear, the suggestion is to make the GtkBuilder parser throw and
> error if class is missing ? Thats fine with me. Will you write a patch ?

Yes and yes. I have a rough patch ready but got stuck with libepoxy-1.4.3 not working with mesa-17.0.x [1]. Will finish it tomorrow.

[1] https://bugs.gentoo.org/show_bug.cgi?id=623926
Comment 3 Debarshi Ray 2017-09-18 16:30:33 UTC
Created attachment 359999 [details] [review]
GtkBuilder: Enforce "class" as a mandatory attribute for <object>
Comment 4 Debarshi Ray 2017-09-18 16:35:12 UTC
Created attachment 360000 [details] [review]
GtkBuilder: Enforce "class" as a mandatory attribute for <object>
Comment 5 Matthias Clasen 2017-09-25 13:03:06 UTC
Review of attachment 360000 [details] [review]:

looks good to me
Comment 6 Debarshi Ray 2017-09-25 13:27:40 UTC
Comment on attachment 360000 [details] [review]
GtkBuilder: Enforce "class" as a mandatory attribute for <object>

Thanks for the review. Pushed to master.