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 779955 - Property setters not executed if new value matches current value
Property setters not executed if new value matches current value
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Objects
0.35.x
Other Linux
: Normal blocker
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-03-12 21:31 UTC by Michael Catanzaro
Modified: 2017-03-12 21:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Property equality check can't be applied to non-automatic-bodies (2.07 KB, patch)
2017-03-12 21:35 UTC, Rico Tzschichholz
committed Details | Review

Description Michael Catanzaro 2017-03-12 21:31:41 UTC
This is a regression from bug #631267. In vala master, property setters are not executed if the new value of the property matches the current value. This is harmless if properties are just wrappers around private fields, but it breaks badly if properties try to do anything more complicated. For example, consider this property in sudoku-view.vala:

    public int value
    {
        get { return game.board [row, col]; }
        set
        {
            if (is_fixed)
            {
                string text = "%d".printf (game.board [row, col]);
                layout = create_pango_layout (text);
                layout.set_font_description (style.font_desc);
                if (game.mode == GameMode.PLAY)
                    return;
            }
            if (value == 0)
            {
                string text = "";
                layout = create_pango_layout (text);
                layout.set_font_description (style.font_desc);
                if (game.board [row, col] != 0)
                    game.remove (row, col);
                if (game.mode == GameMode.PLAY)
                    return;
            }
            if (value == game.board [row, col])
            {
                string text = "%d".printf (value);
                layout = create_pango_layout (text);
                layout.set_font_description (style.font_desc);
                return;
            }
            game.insert (row, col, value);
        }
    }

With vala 0.34.6, the generated function begins with the following (correct) code (debug #lines removed for readability):

void sudoku_cell_view_set_value (SudokuCellView* self, gint value) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gint _tmp16_ = 0;
	gint _tmp34_ = 0;
	SudokuGame* _tmp35_ = NULL;
	SudokuBoard* _tmp36_ = NULL;
	gint _tmp37_ = 0;
	gint _tmp38_ = 0;
	gint _tmp39_ = 0;
	SudokuGame* _tmp48_ = NULL;
	gint _tmp49_ = 0;
	gint _tmp50_ = 0;
	gint _tmp51_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = sudoku_cell_view_get_is_fixed (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {

With 0.35.7.21-9a8b1, the generated function begins with the following (incorrect) code:

void sudoku_cell_view_set_value (SudokuCellView* self, gint value) {
	g_return_if_fail (self != NULL);
	if (sudoku_cell_view_get_value (self) != value) {
		gboolean _tmp0_;
		gboolean _tmp1_;
		gint _tmp16_;
		gint _tmp34_;
		SudokuGame* _tmp35_;
		SudokuBoard* _tmp36_;
		gint _tmp37_;
		gint _tmp38_;
		gint _tmp39_;
		SudokuGame* _tmp48_;
		gint _tmp49_;
		gint _tmp50_;
		gint _tmp51_;
		_tmp0_ = sudoku_cell_view_get_is_fixed (self);
		_tmp1_ = _tmp0_;
		if (_tmp1_) {

The problem is the Vala code expects the property setter to be executed always, but this no longer occurs. I think the new check at the top of the function should only be used to set some boolean that could then be used later on to decide whether to emit g_object_notify().
Comment 1 Rico Tzschichholz 2017-03-12 21:35:41 UTC
Created attachment 347774 [details] [review]
codegen: Property equality check can't be applied to non-automatic-bodies

This is check was introduced with 64b9bfc1bc0abfed45ad07a8ebaef8a5f167f848
Comment 2 Rico Tzschichholz 2017-03-12 21:40:38 UTC
Attachment 347774 [details] pushed as 04489bc - codegen: Property equality check can't be applied to non-automatic-bodies