Tcl Source Code

View Ticket
Login
Ticket UUID: 4bbb308ab26fe4aea344f1c0f744ccbef3f0543
Title: trace causes generation of string representation of "commandPrefix" argument
Type: Bug Created on: 2018-04-28 13:42:26
Submitter: pooryorick Assigned to: nobody
Subsystem: 18. Commands M-Z Severity: Minor
Priority: 5 Medium Last modified: 2024-11-21 07:40:00
Status: Open Closed by: nobody
Resolution: None Closed on:
Version:
Description:

When a pure list is passed as the commandPrefix argument, the string representation of that list is generated:

	proc p1 {list args} {
		puts [list in . p1 [::tcl::unsupported::representation $list]]
	}

	set list [list one two three]
	puts [list initial [::tcl::unsupported::representation $list]]
	set var1 {}
	trace add variable var1 read [list p1 $list]
	set list [list p1 one two three]
	set var1
	

Output:

	initial {value is a list with a refcount of 3, object pointer at 0x55f4052f7ad8, internal representation 0x55f4052db288:(nil), no string representation}
	in . p1 {value is a pure string with a refcount of 3, object pointer at 0x55f4051a8aa8, string representation "one two three"}
	

User Comments:
sebres added on 2018-04-30 10:54:02:

This going to concat by trace add (which currently does not differentiate between canonical and not-canonocal arguments):

unset -nocomplain var1
proc p1 {list args} {
  puts "in p1:\t\t[::tcl::unsupported::representation $list]"
} 
set list [list one two three]; set var1 {}
puts "init:\t\t[::tcl::unsupported::representation $list]"
trace add variable var1 read [list p1 $list]
puts "trace added:\t[::tcl::unsupported::representation $list]"
set var1
Still worse is IMHO the duplication with resulting loss of real object type (it will be to pure string inside the call of trace).

I found this several years ago and fixed already in my own branches.
I'm sure I had already a ticket for this, but can not find it anymore.

Anyway I'll push a branch next week (for >= 8.5) which closes it.


dgp added on 2018-04-30 12:04:46:
Likely related to 

https://core.tcl-lang.org/tcl/tktview?name=3485833

and the branch bug-3485833

dgp added on 2018-04-30 12:19:21:
Strictly speaking this is not a bug. String generation is a
functionally valid thing Tcl or extensions may do.

That said, it can be unwelcome, and any changes in the innards
of [trace] that reduce the necessity of string generation seem
like a good idea.