uplevel needlessly reconstructs internal rep from string
Closed / Fixed223217ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-11-23 01:42:20
When processing the Uplevel command, TCL needlessly recreates the relevant command (the one passed as an argument to uplevel) from the string representation. Here are the details: Start interactive tcl and give the simple command "put 7". Here "put" is a unique prefix of "puts". This causes us to call the unknown command, which eventually calls "uplevel puts 7". In Tcl_UplevelObjCmd, line 581 of tclProc.c, we set: optLevel = TclGetString(objv[1]) This call seems intended to see if first argument, objv[1], is an integer giving the level to use. However, the syntax of uplevel allows us to omit this argument, in which case objv[1] is actually a list containing objects representing the command we wish to execute. As a side effect, this call sets the string representation of the list object, which will be significant later. On line 604 we call Tcl_EvalObjEx, passing the list object (which is now objv[0] as a result of the increment on line 590, where result was 0). In Tcl_EvalObjEx, we decide whether to execute the command and arguments as a vector of Tcl_Objs (line 2575 of tclBasic.c) or by converting the list object to a string and passing that (line 2580). For some reason (perhaps a good one, I don't know) if objPtr (which is in this case a list) already has a string representation we use that. This happens even though the object representation is perfectly valid. As a result, we needlessly reinterpret the string. Why is this a problem? 1. Inefficiency of having to reinterpret the string. 2. There may be cases where it is impossible to reconstruct an internal representation from a string. This is my real concern. Consider the common case of an extension module which registers its own Tcl_TypeObj. The internal representation is a pointer to a C++ class instance and I define a freeInternalRepProc callback to free my instance when the Tcl_Obj's reference count goes to 0. I can certainly provide a function to get a string representation of the pointer value. I can also reconstruct the pointer value from the string rep, but how do I know that the instance hasn't been deleted already? Does TCL really require the ability to reconstruct an internal rep from a string (for better reasons than in the case reported above)? If so, where and why?
dkf Closed ticket [223217ffff].
[History diff]2000-11-23 21:22:13
dgp Ticket [223217ffff]: 3 changes
[History diff]2001-04-05 08:09:40
Log in (anonymous is fine) to add a comment.