Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2018-11-28
15:14 • Ticket [4402cfa58c] Improper ensemble intrep usage status still Closed with ... artifact: 8b92c0fd96 user: dkf
11:17 • Ticket [4402cfa58c]: 6 changes artifact: b6d1865532 user: dkf
2018-11-27
20:58 • Ticket [4402cfa58c]: 4 changes artifact: 0974249610 user: dgp
20:55 • Ticket [4402cfa58c]: 5 changes artifact: 1513c6cc2e user: dgp
2016-07-01
20:18
[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharin... check-in: 64cb01c415 user: dgp tags: trunk
20:14 • Closed ticket [4402cfa58c]: Improper ensemble intrep usage plus 7 other chan... artifact: 8b2dc8d008 user: dgp
20:14
[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharin... check-in: 080020d874 user: dgp tags: core-8-6-branch
18:54
[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharin... check-in: 326a8bf33e user: dgp tags: dgp-ecr
2016-05-20
16:32 • Ticket [4402cfa58c] Improper ensemble intrep usage status still Open with 3 ... artifact: c602a8fa47 user: dgp
15:41 • Ticket [4402cfa58c]: 3 changes artifact: 9becc0b538 user: dgp
15:36 • Ticket [4402cfa58c]: 3 changes artifact: af71c113b3 user: dgp
15:23 • Ticket [4402cfa58c]: 3 changes artifact: d836b3ab79 user: dgp
2016-05-18
17:25 • Ticket [4402cfa58c]: 3 changes artifact: ea30d43453 user: dgp
17:19 • Ticket [4402cfa58c]: 3 changes artifact: 045cc77054 user: dgp
17:19 • Ticket [4402cfa58c]: 3 changes artifact: 7c1aab3812 user: dgp
2016-04-01
03:42 • Ticket [4402cfa58c]: 3 changes artifact: 8d9ab49650 user: dgp
03:37 • Ticket [4402cfa58c]: 4 changes artifact: c42f011af0 user: dgp
03:06 • New ticket [4402cfa58c]. artifact: f5d7c006cf user: dgp

Improper ensemble intrep usage

Closed / Fixed4402cfa58cc1a1651d132a060e1587c7269fdabfCreated 11 years agoUpdated 8 years ago
Descriptionplain2016-04-01 03:06:07
Demo script:

proc bar {ev} {}
proc bingo {xx} {}
namespace ensemble create -command launch -map {foo bar event bingo}
catch {launch foo} m; puts $m
catch {launch ev} m; puts $m
catch {launch foo} m; puts $m

Output:

wrong # args: should be "launch foo ev"
wrong # args: should be "launch event xx"
wrong # args: should be "launch foo event"


The final line of output should be:

wrong # args: should be "launch foo ev"
Referenced by3
  • 64cb01c415[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharing. check-in2016-07-01 20:18:47
  • 080020d874[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharing. Valgrind is not happy with this commit. Likely suspect is the removal of the nsPtr field and checking against it. dkf tried to warn me. check-in2016-07-01 20:14:14
  • 326a8bf33e[4402cfa58c] Rework the spell check machinery into something that will not be foiled by value sharing. check-in2016-07-01 18:54:36
dgpplain2016-04-01 03:37:40
Revised original comment for greater clarity
dgpplain2016-04-01 03:42:58
The first {launch foo} is handled correctly.

The {launch ev} is also handled correctly, but
has the side effect of storing an intrep in the "ev"
value which keeps a record of both the target
command prefix in the ensemble ("bingo") and
the expanded full name of the subcommand
when it was triggered by an abbreviation ("event").
The full name of the subcommand is used in
the error message, even though the script used
only the abbreviated form.

The final {launch foo} gets things wrong.  When
an error message is crafted this time and it's time
to append the string "ev" as part of the usage,
that value still has the magic intrep, and the
expanded string is pulled into the error message
even though that's not correct in this context.

All of this is in Tcl_WrongNumArgs().
dgpplain2016-05-18 17:19:28
This bug centers about an ObjType that caches a lookup.

When it needs to use that lookup, though, the data needed
to verify that the lookup remains valid are out of scope.
dgp Ticket [4402cfa58c]: 3 changes [History diff]2016-05-18 17:19:54
dgpplain2016-05-18 17:25:52
The "interp" argument to Tcl_WrongNumArgs()
is the only one that even possibly might contain
a path to finding out whether we're in the midst
of invoking the ensemble/subcommand that's
cached in the value, so that the substitution is
proper.
dgpplain2016-05-20 15:23:33
Related failure:

% proc target {one two} {}
% namespace ensemble create -command e2 -map {s2 target}
::e2
% namespace ensemble create -command e1 -map {s1 e2} -parameters foo
::e1
% e1 s2 s1 arg
wrong # args: should be "e1 s2 s1 one two"
% e1 [string tolower S] [string tolower S] arg
wrong # args: should be "e1 s2 s1 one two"

BUT ...

% e1 s s arg
wrong # args: should be "e1 s2 s2 one two"

Literal sharing plus failure to confirm context
produces wrong error message.
dgpplain2016-05-20 15:36:43
Try to follow that bad advice:

% e1 s2 s2 1 2
unknown or ambiguous subcommand "s2": must be s1
dgpplain2016-05-20 15:41:10
Even with proper context checking, with
literal sharing it appears that the best
we could hope for would be:

wrong # args: should be "e1 s2 s one two"

Then at least a second pass would get there:

% e1 s2 s arg
wrong # args: should be "e1 s2 s1 one two"

Seems that the approach just isn't right in
the first place, though.

If we want spell-check corrections to the
expansions of unambiguous prefixes, wouldn't
it be simpler and more reliable  to overwrite
elements of the sourceObjs array directly?
dgpplain2016-05-20 16:32:26
Problem with that idea is that
the objv (thus sourceObjs) array
is const.  Given that, and the potential
for value sharing, appears we're stuck.

What a mess.
dgpplain2016-07-01 20:14:39
Fixed for Tcl 8.6.6+
dgpplain2018-11-27 20:55:42
I'm told by dkf that a Coverity scan is unhappy with
the bug fix for this ticket.

That is not too surprising. Upon review, the code is
a horror of type abuse in order to improvise a scheme
to store the information needed to fix the bug in a
struct that has no space for it.

If there's an alternative set of casts to make Coverity
accept the code, I have no objection to changing to them.
It's not as if there's any way to make this code type-correct.
It's intentionally an abuse in order to stuff more things
into the interp->ensembleRewrite without any changes that
would resize the Interp struct in the middle.
dgpplain2018-11-27 20:58:16
Be sure to note the tests namespace-50.[67] that demonstrate
the bug fixed by these code changes.
dkfhtml2018-11-28 11:17:19

Seeing this bug report and its tests is very useful. I'll have a think about a better way to do the code (and yes, I can see why it is a horror anyway).

dkfhtml2018-11-28 15:14:05

That should improve it, making it clearer that we are just stuffing things into tmp for transport, not that those are the real types involved.

Log in (anonymous is fine) to add a comment.