Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b60d652413554f17e597c3679b812f9fee020299
Ticket: 223217ffffffffffffffffffffffffffffffffff
uplevel needlessly reconstructs internal rep from string
User & Date: jgreene on 2000-11-23 01:42:20
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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?
    
    
  4. foundin changed to: "obsolete: 8.3.2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "jgreene"
  9. subsystem changed to: "81. Bundled Packages"
  10. title changed to:
    uplevel needlessly reconstructs internal rep from string
    
  11. type changed to: "Bug"