Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 46c8ff16b80fc2144fecf0a63a1d5dadfae3c6bf
Ticket: 575194ffffffffffffffffffffffffffffffffff
Wasteful code in compile
User & Date: pspjuth on 2002-06-28 20:56:25
Changes

  1. assignee changed to: "msofer"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    In compile code (e.g. tclCompCmds.c) the combo
    TclEmitPush and TclRegisterLiteral is rather common.
    Typically:
    
    TclEmitPush(TclRegisterLiteral(envPtr,
            valueTokenPtr[1].start, valueTokenPtr[1].size,
            /*onHeap*/ 0), envPtr);
    
    However, TclEmitPush is a macro which uses its first
    argument eight times and passes it at least three times,
    which makes the above statement rather wasteful.
    
    This is normally not any danger since TclRegisterLiteral
    can be called repeatedly without anything changing, if
    onHeap is 0 which is the normal case.
    With onHeap = 1, it becomes disaster since the
    successive calls deallocates the string. A naughty
    trap for an innocent coder who likes to copy code
    nearby :-)
    
    So, either a big warning sign should be placed on
    TclEmitPush and every use of the combo should be
    rewritten so the literal index is stored in a var first:
    
    objIndex = TclRegisterLiteral(envPtr,
            valueTokenPtr[1].start, valueTokenPtr[1].size,
            /*onHeap*/ 0);
    TclEmitPush(objIndex, envPtr);
    
    or, maybe TclEmitPush can be recoded to something
    better, like a function or e.g.:
    
    #define TclEmitPush(objIndex, envPtr) \
        { register int __objIndex__ = (objIndex); \
        if ((__objIndex__) <= 255) { \
    TclEmitInstInt1(INST_PUSH1, (__objIndex__),\
    (envPtr)); \
        } else { \
    TclEmitInstInt4(INST_PUSH4, (__objIndex__),\
    (envPtr)); \
        } \
        }
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "pspjuth"
  9. subsystem changed to: "47. Bytecode Compiler"
  10. title changed to: "Wasteful code in compile"
  11. type changed to: "Bug"