Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-08-17
23:48 • Ticket [2055782fff] Crash in namespace inscope status still Closed with 4 ... artifact: 2d4cf2f362 user: lars_h
21:17 • Closed ticket [2055782fff]. artifact: 4d52f795e8 user: msofer
11:37 • New ticket [2055782fff]. artifact: 6e533f6d47 user: lars_h

Crash in [namespace inscope]

Closed / Fixed2055782fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-08-17 11:37:10
Calling [namespace inscope] with an empty script argument crashes Tcl 8.5 (both .0 and .4 tested), but appears to work in previous versions (two 8.4 and one 8.3 tested).

Compare

% info pa
8.5.4
% namespace inscope tcl {} HistInfo
alloc: invalid block: 0xebc70: 0 2
Abort
[hexley:Tcl/build/tcl] lars% uname -a
Darwin hexley.local 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc

to

% info pa
8.4.16
% namespace inscope tcl {} HistInfo
     1  info pa
     2  namespace inscope tcl {} HistInfo
% 

Why would anyone want to do this, then? It turns out that

interp alias {} ::foo {} namespace inscope ::foo ""

is a fairly good emulation of

namespace eval ::foo {
   namespace export *
   namespace ensemble create
}

which works also in older Tcl versions.
(The emulation can be further improved by using an auxiliary interpreter, but that's probably more trouble than it's worth.)
msoferplain2008-08-17 21:17:46
Logged In: YES 
user_id=148712
Originator: NO

My commit of 2007-10-28 turned Tcl_ConcatObj from reader to hairy monster (see [Bug 1447328]), exposing "unsafe" Tcl_Obj handling in NamespaceInscopeCommand().

That is a bug in the commit, as Tcl_ConcatObj() is documented to be a reader. This is just a symptom of [Bug 1447328], now fixed in CVS.
lars_hplain2008-08-17 23:48:19
Logged In: YES 
user_id=938835
Originator: YES

Pasting in msofer's 2008-08-17 comment in [Bug 1447328], since 
it is a bit clearer than what he wrote here (crash reported here is not 
a symptom of what is reported in that bug, but a symptom of a new 
bug introduced by the fix to the old one).

(Begin quote)
Oops ...this turned Tcl_ConcatObj from reader to hairy monster, see [Bug
2055782]. This is against the documented behaviour. This only happens when
concat'ing one or more empty objs with a single list.

Additionally Tcl_ConcatObj() would corrupt its input when: all things to
be concat'ed were either empties or canonical lists, and at least 2 were
not empty, and the first one was unshared. In that case it would add the
new elements in place, hence modifying its input. THIS IS VERY BAD!

Fixed now in 8-5-branch and HEAD.
(End quote.)

The remark about empties or canonical lists suggests that a work-around 
is to use a noncanonical empty list as script argument, e.g.

namespace inscope tcl " " HistInfo

Testing confirms that it avoids the crash. Unfortunately it also leads to 
shimmering (of all arguments), so it's probably not worth bothering about;
should anyway use ensembles in 8.5.
Log in (anonymous is fine) to add a comment.