Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-07-24
18:15 • Ticket [1904432fff] Tcl_DeleteCommandFromToken and NULL token status still O... artifact: c8cd1e6eff user: dkf
2008-03-12
02:58 • Ticket [1904432fff]: 4 changes artifact: d940055aed user: dgp
02:52 • Ticket [1904432fff]: 4 changes artifact: f0b3baeb4a user: dgp
02:47 • Ticket [1904432fff]: 7 changes artifact: 0b57484a82 user: dgp
2008-02-29
04:39 • New ticket [1904432fff]. artifact: 10996932a3 user: nobody

Tcl_DeleteCommandFromToken and NULL token

Open1904432fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 10 years ago
Descriptionplain2008-02-29 04:39:31
I create a command with Tcl_CreateObjCommand and register a delete procedure. Creation of the object and deletion of the object work fine. However, if the object is deleted a second time, I get segfaults. The only way for this to happen is if the object's delete procedure is being called, which shouldn't be happening. After the initial call to Tcl_DeleteCommandFromToken, any subsequent call to Tcl_GetCommandFromObj for that object should have returned NULL, and Tcl_DeleteCommandFromToken, being called with a NULL token, should have returned -1.

The following code does not work as intended when an attempt is made to delete an object more than once.

Tcl_DeleteCommandFromToken(interp, Tcl_GetCommandFromObj(interp, objv[i]));

The following code is required for this to work:

if ((token = Tcl_GetCommandFromObj(interp, objv[i]))) { 
   Tcl_DeleteCommandFromToken(interp, token);
}

I believe that the desired result for Tcl_DeleteCommandFromToken, when called with a NULL token, should be to return -1, per the documentation.
dgpplain2008-03-12 02:47:25
data_type - 360894

Logged In: YES 
user_id=80530
Originator: NO


I think you've misread the documentation.

"If  the  command  corresponding  to token has already been deleted from
interp then Tcl_DeleteCommand does nothing and returns -1; otherwise it
returns 0."

But you are not passing a token value of
an already deleted command.  You are passing
the value NULL.  And NULL values lead to crashes.

There may be a convenience case to be made for
changing this, but that's a feature request, not
a bug.
dgpplain2008-03-12 02:52:31
Logged In: YES 
user_id=80530
Originator: NO


Curious that the docs report the value -1
will be returned for tokens not registered
in the interp, but I can't see any way the
routine ever does that.  There may be a bug
here after all.
dgpplain2008-03-12 02:58:07
Logged In: YES 
user_id=80530
Originator: NO


As long as the sources have been in CVS
(around 8.0p2), I can't see any evidence
the T_DCFT() routine ever returned -1.

T_DCFT() was new in Tcl 8.0.  Were these
docs ever right?
dkfhtml2016-07-24 18:15:56

Might be worth fixing this according to the principle of Do Nothing, Gracefully.

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