Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-06-03
08:35 • Ticket [1e95cbaf89] Evaluating something starting with a # fails to treat it as ... artifact: e23817853c user: dkf
2009-07-29
19:51 • Ticket [489537ffff] string rep of list: should quote '#' status stil... artifact: db5a5598b2 user: dkf
2008-11-21
21:26 • Ticket [489537ffff]: 8 changes artifact: 195872184b user: dkf
2003-09-04
23:46 • Ticket [489537ffff]: 1 change artifact: 0d1821ab2d user: dgp
23:43 • Closed ticket [489537ffff]. artifact: 4ec383d332 user: dgp
2003-08-10
05:44 • Ticket [489537ffff]: 4 changes artifact: 270c4277b2 user: dgp
2003-08-09
02:58 • Ticket [489537ffff]: 4 changes artifact: 6cad733931 user: dgp
02:57 • Add attachment 489537-fix.patch to ticket [489537ffff] artifact: 6454867853 user: dgp
02:57 • Ticket [489537ffff] string rep of list: should quote '#' status stil... artifact: 946b484c52 user: dgp
2003-07-24
23:01 • Ticket [489537ffff]: 4 changes artifact: b0f6569940 user: dgp
23:01 • Add attachment 489537-test.patch to ticket [489537ffffffffff|489537ffff... artifact: e536faa215 user: dgp
23:01 • Ticket [489537ffff] string rep of list: should quote '#' status stil... artifact: 06275dc053 user: dgp
23:00 • Ticket [489537ffff]: 4 changes artifact: ab620d40c4 user: dgp
22:59 • Ticket [489537ffff]: 4 changes artifact: cb6c880974 user: dgp
21:12 • Ticket [489537ffff]: 4 changes artifact: 5412573021 user: dkf
07:35 • Ticket [489537ffff]: 4 changes artifact: d199a2b705 user: dgp
07:35 • Ticket [489537ffff]: 4 changes artifact: 7b7e155a71 user: dgp
2003-07-23
04:24 • Ticket [489537ffff]: 4 changes artifact: 4a32460d6a user: dgp
00:00 • Ticket [489537ffff]: 4 changes artifact: 8274f96be5 user: dgp
2003-03-06
00:40 • Ticket [489537ffff]: 4 changes artifact: 74e3c0e949 user: hobbs
2003-03-05
13:41 • Ticket [489537ffff]: 5 changes artifact: 33fa5792cb user: dgp
2002-03-01
02:52 • Ticket [489537ffff]: 4 changes artifact: 07613ef230 user: hobbs
02:46 • Add attachment liststring2.patch to ticket [489537ffffffffff|489537ffff... artifact: 2c20a6a6ab user: msofer
02:46 • Ticket [489537ffff] string rep of list: should quote '#' status stil... artifact: 6b17cdaba4 user: msofer
02:42 • Ticket [489537ffff]: 4 changes artifact: d582134cb4 user: msofer
02:28 • Ticket [489537ffff]: 4 changes artifact: cd8aa5addc user: dgp
00:50 • Ticket [489537ffff]: 4 changes artifact: bea46052db user: msofer
2001-12-08
00:05 • Ticket [489537ffff]: 4 changes artifact: 40d02c1f9a user: dgp
2001-12-06
17:00 • Ticket [489537ffff]: 5 changes artifact: 1132c33cd7 user: dkf
05:21 • Ticket [489537ffff]: 4 changes artifact: d74ce2fdb8 user: dgp
05:07 • Ticket [489537ffff]: 4 changes artifact: 6c0af22e1b user: hobbs
04:13 • Ticket [489537ffff]: 4 changes artifact: 24020b446d user: dgp
04:10 • Ticket [489537ffff]: 5 changes artifact: 52f7e41bb6 user: hobbs
03:56 • Ticket [489537ffff]: 4 changes artifact: 1129b5a24a user: dgp
03:56 • Add attachment liststring.patch to ticket [489537ffff] artifact: 6648fcc88c user: dgp
2001-12-05
20:56 • New ticket [489537ffff] string rep of list: should quote '#'. artifact: b8f173b5fd user: dgp

string rep of list: should quote '#'

Closed489537ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 17 years ago
Descriptionplain2001-12-05 20:56:52
Kudos to Joe English for catching this one,
and Donal Fellows for analyzing the right
solution.

list(n) says:
     list ?arg arg ...?

Braces and backslashes get added as necessary,...
so that eval may be used to execute the resulting 
list, with arg1 comprising the command's name and
the other args comprising its arguments.

However, in an interacive tclsh:

% proc # {} {puts !}
% set cmd [list #]
#
% eval $cmd
%

A patch is attached that offers one fix with
changes to Tcl_{Scan|Convert}CountedElement.
It is overkill in that it quotes leading '#'
in all list elements when it is only needed
for the first list element, but in those
routines, the ordinal of the element is not
known.  Perhaps an additional flag value could
be added if more sophistication is wanted, limiting
the quoting to the first element.

Two part.test tests were updated, and tests
based on the demo above was added to util.test.
dgpplain2001-12-06 03:56:54
File Added - 14214: liststring.patch
hobbsplain2001-12-06 04:10:51
Logged In: YES 
user_id=72656

This is not correct for most cases, where the # is really 
meant to be a quote and has no command associated with it.  
This is only valid for the rare cases where the initial #-
starting element has a command of the same name.
dgpplain2001-12-06 04:13:04
Logged In: YES 
user_id=80530

Example?
hobbsplain2001-12-06 05:07:59
Logged In: YES 
user_id=72656

The patch changes semantics to the following:
   [list #foo a b c] == {\#foo a b c}
by placing the \ in front of the #.  This means
that #foo will now be seen as a command, but when
it is not (in most cases # will be for comments),
then you will throw an error, no?
dgpplain2001-12-06 05:21:22
Logged In: YES 
user_id=80530

With the patch:

% list #foo a b c
{#foo} a b c

Does that answer the question?  No error thrown,
but yes the string rep changes. That's the point.

Each list has multiple valid string reps.  The
guarantees of list(n) are met by the string rep
after the patch, but not before.
dkfplain2001-12-06 17:00:37
Logged In: YES 
user_id=79902

This is a *vevry* long-standing bug, since it was there in
Tcl 7.4 (which is the oldest version I've got hanging about
here) and it definitely should be resolved the way described
as the alternative is to put a special case into the list(n)
manpage. Which would be deeply blecherous.
dgpplain2001-12-08 00:05:26
Logged In: YES 
user_id=80530

If the current patch is accepted, many tests in the
Tk test suite will fail.  The first example
is test button-7.2.  It expects the result to be:

.b1 #543210 {} {}

but after the patch the result will actually be:

.b1 {#543210} {} {}

Possible remedies:

  1) Just update all the relevant tests to expect the new
     string rep.  (Create expected value with [list])
  2) Make a more sohpisticated patch that will only
     quote leading '#' in the first element of a list.
  3) Make these tests compare their results as lists,
     rather than as strings, adding a new type of
     comparison to tcltest if necessary.
msoferplain2002-03-01 00:50:44
File Added - 18577: liststring2.patch

Logged In: YES 
user_id=148712

A second patch: this will only quote '#' if it is the first
element of the list: A new flag TCL_QUOTE_HASH is added to
the interface of Tcl_Convert(Counted)Element.
dgpplain2002-03-01 02:28:53
Logged In: YES 
user_id=80530

The new patch works and passes both Tcl and Tk
test suites.  Haven't gone looking for ways to
break it yet.
msoferplain2002-03-01 02:42:17
File Deleted - 18577: 



File Added - 18583: liststring2.patch

Logged In: YES 
user_id=148712

Adding a comment to the patch (thanks don!)
msoferplain2002-03-01 02:46:40
File Deleted - 18583: 



File Added - 18584: liststring2.patch
hobbsplain2002-03-01 02:52:44
Logged In: YES 
user_id=72656

I would like to make sure that this is logically worked 
over before commiting.  It may be that the tests that would 
break don't exist, as it seems like a subtle change that 
might have ramifications.
dgpplain2003-03-05 13:41:57
Logged In: YES 
user_id=80530


opinion on making this fix in 8.5a0 ?
hobbsplain2003-03-06 00:40:46
Logged In: YES 
user_id=72656

I think it requires a TIP.
dgpplain2003-07-23 00:00:33
Logged In: YES 
user_id=80530


Because [eval] has pure-list optimizations,
this bug now appears as a shimmering
inconsistency.  Consider this demo script

# FILE: demo.tcl
set cmdName [lindex $argv 0]
proc $cmdName {} {puts Success!}
set command [list $cmdName]
puts "Eval \[$command]" ;# comment this out
eval $command

Correct behavior is for the script
to write Success! to stdout.  As written
above, this fails for an argument that
begins with the # character.   However,
if you comment out the indicated [puts],
then we avoid string-rep generation,
and the script works correctly for all
arguments.

Seems we should be able to correct
a shimmering inconsistency without
a TIP.  Anyone relying on the 
buggy behavior should have been
caught by the pure-list optimizations
in eval by now.
dgpplain2003-07-23 04:24:02
File Added - 56550: 489537.patch

Logged In: YES 
user_id=80530


New patch 489537.patch is
same as liststring2.patch
except it adds two more tests
to util.test that force string rep
generation to illustrate the
shimmering problem.
dgpplain2003-07-24 07:35:34
Logged In: YES 
user_id=80530


Here's a completely new patch
(replaces previous 489537.patch)
that I think is better than all.

1) Does not change the public API (no TIP needed!)
2) Does not disturb the Tk test suite.
3) By default, chooses safe quoting.
4) Leaves open door for a TIP exposing to
     extensions the power to ask for less 
     quoting of hashes when it is known safe.
5) Corrects several more callers of
    Tcl_Convert*Element()
6) Adds many more tests for bugs when 
     those callers are not patched.

Please review.
dgpplain2003-07-24 07:35:35
File Deleted - 56550: 



File Added - 56681: 489537.patch
dkfplain2003-07-24 21:12:33
Logged In: YES 
user_id=79902

I'd feel happier if the addition of TCL_DONT_QUOTE_HASH
didn't rearrange the positions of the internal
Tcl_ConvertElement flags.  No reason why that value has to
occupy a contiguous bit with TCL_DONT_USE_BRACES...

Apart from that, there ought to be an extra dict test like
this (or maybe with the result the other way round):
test dict-2.8 {dict create command - #-quoting in string
rep} {
    dict create # #comment ## ##comment
} {{#} #comment ## ##comment}

Minor issues aside, looks excellent to me.
dgpplain2003-07-24 22:59:59
Logged In: YES 
user_id=80530


updated to address those
comments.  Now in the form
of two patches, one that adds
tests to the test suite that demo
the bug.  And a second that
contains the fix.

Here's the fix patch...
dgpplain2003-07-24 23:00:00
File Deleted - 56681: 



File Added - 56746: 489537-fix.patch
dgpplain2003-07-24 23:01:26
Logged In: YES 
user_id=80530

...and here's the test patch,
that I am committing to HEAD.
dgpplain2003-07-24 23:01:27
File Added - 56747: 489537-test.patch
dgpplain2003-08-09 02:57:59
File Added - 58219: 489537-fix.patch

Logged In: YES 
user_id=80530


Updated fix patch that implements
draft TIP.
dgpplain2003-08-09 02:58:00
File Deleted - 56746:
dgpplain2003-08-10 05:44:18
Logged In: YES 
user_id=80530


The attached file 489537-fix.patch
is the prototype implementation
of TIP 148.
dgpplain2003-09-04 23:43:41
Logged In: YES 
user_id=80530


TIP 148 Accepted.  Patch committed
to HEAD (8.5a0).
dgp Ticket [489537ffff]: 1 change [History diff]2003-09-04 23:46:20
dkfplain2008-11-21 21:26:58
data_type - 210894
dkfplain2009-07-29 19:51:30
IP - Comment Removed: 130.88.1.31
Log in (anonymous is fine) to add a comment.

Attachments: