GNOME Bugzilla – Bug 564425
Creation of GtkSourceStyle objects assigns wrong values to "xxx-set" properties
Last modified: 2021-07-05 11:02:26 UTC
Please describe the problem: Attempting to construct a GtkSourceStyle object via g_object_new with (say) bold=true results in an object where bold=true but bold-set=false. Explicitly setting bold-set=true has no effect either. Documentation is inexplicit about whether it is necessary to set bold-set=true also, but it seems from the code that this is not needed. Steps to reproduce: See attached test case Actual results: Output is 1 0 / 1 0 Expected results: Expected 1 1 / 1 1 Does this happen every time? Yes Other information: gtksourcestyle.c line 189 reads: #define UNSET_MASK(style,name) (style)->mask &= (GTK_SOURCE_STYLE_USE_##name) Comparing with the previous line, I suspect it should read #define UNSET_MASK(style,name) (style)->mask &= ~(GTK_SOURCE_STYLE_USE_##name) but don't have time to set up the build and test this. The documentation for g_object_new says that it sets all parameters not explicitly mentioned to their default values. You'll know better than me what effect that might have, with or without the patch I've suggested. GtkSourceStyleManager doesn't set the properties via g_object_new, because "nobody will know the difference". Ha! With best wishes, -- Mike
Created attachment 124608 [details] Test case
This is my third bug in three days. Do I get bonus points? Or should I take a day off tomorrow? Best wishes, -- Mike
You do get half a gazillion bonus points. Please don't stop there.
I did try the proposed patch: it changes the results of the test to 1 0 / 1 1. In other words, it now works to set both "bold" and "bold-set" explicitly on construction, but setting just "bold" leaves "bold-set" as false, despite the code that aims to set "bold-set" as a side-effect of setting "bold". My guess is that if "bold-set" is not set explicitly, then setting "bold" makes it 1, and then g_new_object sets it back to 0. It seems that the plan to set "bold-set" implicitly will not work in the face of the gobject convention of setting all properties that are not mentioned in the g_new_object call to their default values. A print statement at the top of gtk_source_style_set_property confirms that this is what is happening. The next step I leave to you! Perhaps the simplest move would be to nuke the implicit setting code, and document that "bold-set" etc. must be set explicitly. -- Mike
In point of fact, this interface is currently useless, as there's nothing you can actually do with a SourceStyle after you've created it. It's only people like me -- implementing a language binding for Objective Caml -- who will ever call this constructor, and then only from unit tests! -- Mike
You are right, it's some piece of shitty code. UNSET_MASK is buggy, the whole thing is buggy. I kind of fixed it, i.e. I made g_object_new(GTK_TYPE_SOURCE_STYLE, "bold", TRUE, NULL) work. But "bold-set" won't do anything anymore, it prints a warning instead (it has to stay WRITABLE for compatibility).
Oops, it's still broken. This interface just can't work. CONSTRUCT just isn't a right thing to use here. I am reverting the last commit, and leave this bug to rot for a while.
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/gtksourceview/-/issues/ Thank you for your understanding and your help.