Tk Source Code

View Ticket
Login
Ticket UUID: 3b4a9ed919bcfa0769b05add899bf79056da379d
Title: listbox test failures
Type: Bug Version: trunk
Submitter: dgp Created on: 2023-07-13 18:04:35
Subsystem: 09. [listbox] Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2023-07-18 14:40:28
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2023-07-18 14:40:28
Description:
Suspect these multiple failed tests have a common cause.
This is on a CentOS Linux / KDE system.



listbox.test


==== listbox-21.12 ListboxListVarProc, cleanup item attributes FAILED
==== Contents of test case:

    set x [list a b c d e f g]
    listbox .l -listvar x
    .l itemconfigure end -fg red
    set x [list a b c d]
    set x [list 0 1 2 3 4 5 6]
    .l itemcget end -fg

---- Result was:
#221f1e
---- Result should have been (exact matching):

==== listbox-21.12 FAILED



==== listbox-21.12a ListboxListVarProc, cleanup item attributes FAILED
==== Contents of test case:

    set x [list a b c d e f g]
    listbox .l -listvar x
    .l itemconfigure end -fg red
    set x [list a b c d]
    set x [list 0 1 2 3 4 5 6]
    .l itemcget end -fg

---- Result was:
#221f1e
---- Result should have been (exact matching):

==== listbox-21.12a FAILED



==== listbox-23.2 ConfigureListboxItem FAILED
==== Contents of test case:

    listbox .l
    .l insert end a b c d
    .l itemconfigure 0

---- Result was:
{-background background Background {} #d6d2d0} {-bg -background} {-fg -foreground} {-foreground foreground Foreground {} #221f1e} {-selectbackground selectBackground Foreground {} #43ace8} {-selectforeground selectForeground Background {} #ffffff}
---- Result should have been (exact matching):
{-background background Background {} {}} {-bg -background} {-fg -foreground} {-foreground foreground Foreground {} {}} {-selectbackground selectBackground Foreground {} {}} {-selectforeground selectForeground Background {} {}}
==== listbox-23.2 FAILED



==== listbox-23.3 ConfigureListboxItem, itemco shortcut FAILED
==== Contents of test case:

    listbox .l
    .l insert end a b c d
    .l itemco 0 -background

---- Result was:
-background background Background {} #d6d2d0
---- Result should have been (exact matching):
-background background Background {} {}
==== listbox-23.3 FAILED



==== listbox-24.1 itemcget FAILED
==== Contents of test case:

    listbox .l
    .l insert end a b c d
    .l itemcget 0 -fg

---- Result was:
#221f1e
---- Result should have been (exact matching):

==== listbox-24.1 FAILED



==== listbox-25.1 listbox item configurations and widget based deletions FAILED
==== Contents of test case:

    listbox .l
    .l insert end a
    .l itemconfigure 0 -fg red
    .l delete 0 end
    .l insert end a
    .l itemcget 0 -fg

---- Result was:
#221f1e
---- Result should have been (exact matching):

==== listbox-25.1 FAILED



==== listbox-25.2 listbox item configurations and widget based inserts FAILED
==== Contents of test case:

    listbox .l
    .l insert end a b c
    .l itemconfigure 0 -fg red
    .l insert 0 1 2 3 4
    list [.l itemcget 0 -fg] [.l itemcget 4 -fg]

---- Result was:
{#221f1e} red
---- Result should have been (exact matching):
{} red
==== listbox-25.2 FAILED
User Comments: jan.nijtmans added on 2023-07-18 14:40:28:

Fixed [a8a2df12a9258d42|here]


jan.nijtmans added on 2023-07-18 12:59:20:

> Should support for TK_OPTION_DONT_SET_DEFAULT be removed completely (from the code and the man page) then?

Well, the documentation for TK_OPTION_DONT_SET_DEFAULT is misleading now. It is currently still used in tkText.c, which has tricky code synchronizing between TkSharedText and TkText regarding the "undo", "maxUndo" and "autoSeparators" options. See: https://core.tcl-lang.org/tk/file?name=generic/tkText.h&ln=794-805&ci=a78761240fb69cc1. So, I could imagine real situations where you want to hack the initialization .... ;-). We should continue to support it, but - in my view - TK_OPTION_NULL_OK should be preferable if it does the job.


fvogel added on 2023-07-18 12:33:38:
Thanks, I think I understand better now.

Should support for TK_OPTION_DONT_SET_DEFAULT be removed completely (from the code and the man page) then?

fvogel added on 2023-07-18 12:33:37:
Thanks, I think I understand better now.

Should support for TK_OPTION_DONT_SET_DEFAULT be removed completely (from the code and the man page) then?

jan.nijtmans added on 2023-07-18 06:52:23:

> What wrong behavior of the listbox are we trying to fix with, basically?

    % listbox .l
    % .l insert 0 xxx
    % .l itemconfig 0 -background
    -background background Background {} {}
This tells us that "background" is the corresponding option database entry, which is not the reality: the option database is not expected to be used at all. Also it tells us that the default is NULL, but if you look at the table the default should be DEF_LISTBOX_BG_MONO == "WHITE". This strange behavior is caused by the TK_OPTION_DONT_SET_DEFAULT flag.


jan.nijtmans added on 2023-07-18 06:36:35:

See also: https://core.tcl-lang.org/tk/info/2049429


jan.nijtmans added on 2023-07-18 06:33:03:

The change in tkTextTag.c is actually a follow-up to this change.


jan.nijtmans added on 2023-07-18 06:19:17:

OK, let me explain. The option TK_OPTION_DONT_SET_DEFAULT is a hack for option types which didn't support TK_OPTION_NULL_OK. Now all options support TK_OPTION_NULL_OK, so this flag should no longer be necessary.

The effect of TK_OPTION_DONT_SET_DEFAULT was to skip initialization. It means that the option is initialized with NULL. But ... the problem is, if TK_OPTION_DONT_SET_DEFAULT is not combined with TK_OPTION_NULL_OK, the option can never be reset to NULL again using Tcl code, which is illogical. Therefore TK_OPTION_DONT_SET_DEFAULT should be replaced with TK_OPTION_NULL_OK.

Skipping initialization has also the side-effect of not accessing the option database. The same effect can be arranged by setting the dbName and dbClass fields to NULL.

So - hopefully - with this explanation, the consequenses are not unforseen any more.


fvogel added on 2023-07-18 05:25:30:

I see your proposal but I don't like it very much. What's the advantage of it?

Thinking further I believe option 2. I proposed below is the right one. What's the problem of reverting [cf8b1ea76723cfaf] since it now appears that what is said in its commit comment "TK_OPTION_DONT_SET_DEFAULT is no longer needed in combination with TK_OPTION_NULL_OK, if the default is NULL." is incorrect? I think we are not chasing out all TK_OPTION_DONT_SET_DEFAULT occurrences in the code, isn't it? What's the gain in removing TK_OPTION_DONT_SET_DEFAULT? What wrong behavior of the listbox are we trying to fix with, basically?

And BTW [cf8b1ea76723cfaf] didn't change the listbox only.

And I hope there are no other removals of TK_OPTION_DONT_SET_DEFAULT (in other commits) with unforeseen consequences. We became aware of the listbox issue thanks to the test suite running in KDE in a user system (Github actions did not reveal the problem with xvfb), which is kind of luck.


jan.nijtmans added on 2023-07-17 22:11:24:

Or ... [779d9403a3619a05]

This reverts to the old behavior (no option database usage, and NULL initialization), but not by using the TK_OPTION_DONT_SET_DEFAULT flag, but just by not specifying those initialization values.

It depends on whether we want the option database to influence the list items individually or the Listbox as a whole only. I am doubting we really want that.


fvogel added on 2023-07-17 20:20:09:

The change in [cf8b1ea76723cfaf] indeed has the side effect of now reading the options database to set an initial value to the option.

I think we can either 1. change the expected tests results (e.g. for listbox-21.12 to [option get .l foreground Listbox]), or 2. revert [cf8b1ea76723cfaf]. I tend to think that 1. is better. Opinions?


fvogel added on 2023-07-14 15:28:14:

Specifically, on my system:

francois@debian:~/Documents/tcltk/fossil/tk$ xrdb -query | grep Listbox
*Listbox.activeBackground:      #fcfcfc
*Listbox.activeForeground:      #232627
*Listbox.background:    #fcfcfc
*Listbox.foreground:    #232627
*Listbox.highlightBackground:   #fcfcfc
*Listbox.highlightColor:        #232627
*Listbox.selectBackground:      #3daee9
*Listbox.selectForeground:      #fcfcfc

The result I get in the listbox tests is #232627 (not the same as dgp, but same cause obviously).


fvogel added on 2023-07-14 15:24:00:
I don't have a ~/.Xdefaults file.

However, <code>xrdb -query | grep Listbox</code> indeed spits the color the test gets. There must be defaults set somewhere in KDE that Tk gets (I didn't set these KDE defaults).

jan.nijtmans added on 2023-07-14 15:12:14:

Could this be related to an .Xdefaults file present?

The effect of the TK_OPTION_DONT_SET_DEFAULT is that it disables initialization of the variable, which also disables reading the option database.


fvogel added on 2023-07-14 15:02:39:
I can see the failures on Linux Debian 11 with KDE indeed.

Using xvfb (as is happening at Github actions) the tests do pass.

dgp added on 2023-07-13 19:04:18:
Bisecting places the blame here:

https://core.tcl-lang.org/tk/info/cf8b1ea76723cfaf