Skip to content
Tcl Source Code View Ticket
Login

View Ticket

restore Tcl 7 compatibility of Tcl_MakeSafe

Closed / Fixed655300ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 4 years ago
Descriptionplain2002-12-17 17:33:00
The docs for Tcl_MakeSafe say:

     Tcl_MakeSafe makes interp ``safe'' by removing all
 non-core
     and  core  unsafe  functionality. Note that if you
call this
     after adding some extension to an interpreter, all
traces of
     that extension will be removed from the interpreter.

It's not exactly clear to me what magical package
unloading power is claimed for Tcl_MakeSafe, but
it's clear that Tcl_MakeSafe doesn't have it.

Consider:

    Tcl_Interp *i = Tcl_CreateInterp();
    Tcl_Eval(i, "package require Tk");
    Tcl_MakeSafe(i);

At this point the Tk commands (both safe and unsafe)
will still be defined in i.
dkfplain2002-12-18 00:41:35
Logged In: YES 
user_id=79902

Does anything need safe interps that are not slaves of
full-blooded masters?  If not, the only correct way of using
this API is through Tcl_CreateSlave() and Tcl_MakeSafe would
be better not exposed at all.
dgpplain2002-12-18 00:53:48
Logged In: YES 
user_id=80530

"need" is pretty strong.  Seems wasteful to
be forced to create an unsafe master when
all one wants is a safe interp, though.

Then again, we don't really "need" safe interps;
one can always delete commands from an
interp based on one's own judgment about
safety/utility.

Agree that a public Tcl_MakeSafe()
doesn't seem like a good idea though,
since it allows any extension to mark
an interp as "safe" without any guarantee
that all unsafe stuff is removed.

Does Tcl_MakeSafe have any callers
outside of Tcl itself?
dgp Ticket [655300ffff]: 1 change [History diff]2003-04-14 11:14:58
dgpplain2003-07-16 22:41:54
Logged In: YES 
user_id=80530

any ideas for cleaning this up for 8.4.4 ?
dkfplain2003-07-17 04:05:39
Logged In: YES 
user_id=79902

I'd be tempted to make it undocumented, perhaps with a new
TclMakeSafe() in tclInt.decls in case someone is relying on
it actually being there.  I'm not sure whether we're allowed
to do that in a point release though ;^)
dkfplain2003-07-17 04:36:24
Logged In: YES 
user_id=79902

Documentation is now fixed, but leaving open as Tcl_MakeSafe
is a candidate for removal from the public API; the only
client I know of is Tcl_CreateSlave (and then only when it
is asked to create a safe slave.)
dgpplain2003-07-17 10:32:23
Logged In: YES 
user_id=80530

Interesting discussion on the
Tclers' chat and consultation
with the Tcl 7.6 source code
revealed that Tcl_MakeSafe
once behaved as documented.

Behavior changed starting with
Tcl 8, but the docs were not changed.

Seems likely the behavior change was
a bug.
dgpplain2003-07-18 22:23:30
Logged In: YES 
user_id=80530


Softened the deprecation warning
in the modified docs for 8.4.4.

I think the remaining issue
is a desire of some to restore
the Tcl 7 behavior.  Converting
to an RFE...
dgp Ticket [655300ffff]: 1 change [History diff]2003-07-18 22:24:45
dgp Ticket [655300ffff]: 1 change [History diff]2003-07-18 22:26:59
jan.nijtmans Ticket [655300ffff]: 6 changes [History diff]2022-04-05 07:02:08
jan.nijtmanswiki2022-09-26 11:03:36

Handled by TIP #624. Tcl_MakeSafe will be gone in Tcl 9.0, so no worries any more.

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