Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-10-26
08:23 • Closed ticket [218505ffff]: The interface to Tcl_EvalObjv is not that great ... artifact: a30cdf8185 user: welch
01:01 • New ticket [218505ffff]. artifact: 7075431269 user: nobody

The interface to Tcl_EvalObjv is not that great

Closed / Fixed218505ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:01:25
OriginalBugID: 739 Bug
Version: 8.1a2
SubmitDate: '1998-10-15'
LastModified: '1999-02-01'
Severity: MED
Status: Released
Submitter: welch
ChangedBy: stanton
OS: All
OSVersion: NA
Machine: NA
FixedDate: '1999-02-01'
FixedInVersion: 8.1b1
ClosedDate: '2000-10-25'


    The current (public CVS 8.1 snapshot) implementation of Tcl_EvalObjv() in

generic/tclParse.c is optimized for use by internal Eval family of routines.

Yet it is a "public" API entry point, and as such should be optimized for

the needs of extension writers.


    The most likely use of Tcl_EvalObjv by extension writers is likely along

the lines of my (long ago) "leval" proposal: basically one or more of the

extension commands constructs a new command from some of its arguments, but

instead of being passed as a string to the traditional Tcl_Eval(), the command

is directly evaluated with the specified objc/objv[].


    So far so good and the Tcl_EvalObjv() API supports this, but it

does not generate stack trace information for the generated command, and

requires the caller to supply the command source string for command traces

(and again but outside Tcl_EvalObjv for stack traces in errorInfo).


    Also the extension writer does not know when the string is actually needed,

since it is only used for command traces and error traces, neither of which

typically happen.  So he ends up computing (if he is careful enough to supply

a non-empty source string) strings which largely go unused.


    This seems (to me at least) to be an unnecessary burden.  The caller

has no source string, because as an extension writer, he was not parsing

commands, just constructing argument lists.  And the intent for bypassing

"eval" is to avoid the overhead (and possible information loss) when

converting all the arguments to strings and back.


    To make the extension writers job easy I propose that the string

generation for command traces and stack traces be part of Tcl_EvalObjv()

and the "command" and "numBytes" arguments be dropped from the public API.


    The original function can be renamed to EvalObjv() and become static

in tclParse.c, or if one day needed in other modules, can be renamed

to TclEvalObjv() and declared in tclInt.h.


    Attached is an implementation (in the form of a patch).  It also completely

incidentally adds a missing "}" in the var.test file.


    Given the new Tcl_EvalObjv() it is trivial to "objectify" "lsort -command"

(the Syd Polk patch), or to implement "leval" where apart from performance

and lossy float conversion the following are equivalent:


A.  leval arg1 arg2 ... arg2


B.  set cmd {}

    foreach arg [concat arg1 arg2 ... argn] {

lappend cmd $arg

    }

    eval $cmd




I trust Viktor's argument here.  It makes sense to me.
This procedure could be quite useful, and now is the time to adjust its API.
The patch is  in the patch database.
welch Closed ticket [218505ffff]. [History diff]2000-10-26 08:23:18
Log in (anonymous is fine) to add a comment.