Tk Source Code

View Ticket
Login
Ticket UUID: 280189e35df677311b241e8d537b3b3325f89a6d
Title: Duplicate interp names with [tk appname], and empty interp list with [winfo interps]
Type: Bug Version: 8.6.16 through 9.1a0
Submitter: erikleunissen Created on: 2025-08-13 11:14:49
Subsystem: 99. Other Assigned To: nobody
Priority: 5 Medium Severity: Severe
Status: Open Last Modified: 2025-09-03 08:30:41
Resolution: None Closed By: nobody
    Closed on:
Description:
The "tk appname" command is advertised as preventing duplicate interp names. From
the manual page:

    tk appname ?newName?
	...
	If newName is specified, then the name of the application is changed to newName.
	If the given name is already in use, then a suffix of the form “ #2” or “ #3”
	is appended in order to make the name unique.
	...

The script below demonstrates a case where the advertised mechanism doesn't
prevent duplicate names. Also it shows that [winfo interps] can be made to output
an empty list, which can never be true because any call to [winfo interps] must
come from some interpeter.

The incorrect behaviour was observed with Linux, as well as Windows. No test
was conducted with macOS.

Linux output:
--
State before child exit:
winfo interps: |foo|
tk appname parent: foo
tk appname child: foo

State after child exit:
winfo interps: ||
--

Windows output:
--
State before child exit:
winfo interps: ||
tk appname parent: foo
tk appname child: foo

State after child exit:
winfo interps: ||
--

Note that there is a small difference between the incorrect behaviours under
Linux and Windows w.r.t. the output of [winfo interps] before exiting the child:
- under Linux a single interp "foo" is reported.
- under Windows an empty list is reported.
Both are incorrect because there are two interps at that time.

Tk versions 8.6.16 up through 9.1a0, and current trunk are affected.

--- script for reproducing the issue (also attached as file "exercise.tcl") ---

package require Tk
tk appname foo
set fd [open "|[info nameofexecutable]" r+]
puts $fd "package require Tk; tk appname foo"; flush $fd
puts $fd {puts [tk appname]; flush stdout}; flush $fd
set appname_child [gets $fd]
puts "State before child exit:\nwinfo interps: |[winfo interps]|\ntk appname parent: [tk appname]\ntk appname child: $appname_child"
puts $fd exit; flush $fd
close $fd
puts "\nState after child exit:\nwinfo interps: |[winfo interps]|"

---
User Comments: erikleunissen added on 2025-09-03 08:30:41:
The output in the previous post is correct indeed.

marc_culler (claiming to be Marc Culler) added on 2025-09-03 02:40:18:
The mac_send branch implements sending to an interpreter in a different
process.  So I thought I should run the test script using that branch.
This is what I get:

  State before child exit:
  winfo interps: |foo {foo #2}|
  tk appname parent: foo
  tk appname child: foo #2

  State after child exit:
  winfo interps: |foo|

I think that is correct.

erikleunissen added on 2025-08-14 10:33:53:
Simplified the reproducible script, and uploaded corresponding file "exercise.tcl". Also added observed output to the initial post.

Attachments: