Manual Pages for UNIX Darwin command on man Tcl_SetObjResult
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_SetObjResult

TclSetResult(3) Tcl Library Procedures TclSetResult(3)

NAME

TclSetObjResult, TclGetObjResult, TclSetResult, TclGetStringResult,

TclAppendResult, TclAppendResultVA, TclAppendElement, TclResetRe-

sult, TclFreeResult - manipulate Tcl result

SYNOPSIS

##iinncclluuddee <>

TTccllSSeettOObbjjRReessuulltt(interp, objPtr) TclObj * TTccllGGeettOObbjjRReessuulltt(interp) TTccllSSeettRReessuulltt(interp, string, freeProc) CONST char * TTccllGGeettSSttrriinnggRReessuulltt(interp) TTccllAAppppeennddRReessuulltt(interp, string, string, ... , ((cchhaarr **)) NNUULLLL) TTccllAAppppeennddRReessuullttVVAA(interp, argList) TTccllAAppppeennddEElleemmeenntt(interp, string) TTccllRReesseettRReessuulltt(interp) TTccllFFrreeeeRReessuulltt(interp) AARRGGUUMMEENNTTSS TclInterp *interp (out) Interpreter whose result is to be modified or read. TclObj *objPtr (in) Object value to become result for interp. char *string (in) String value to become result for interp or to be appended to the existing result. TclFreeProc *freeProc (in) Address of procedure to call to release storage at string, or TTCCLLSSTTAATTIICC, TTCCLLDDYYNNAAMMIICC, or TTCCLLVVOOLLAATTIILLEE. valist argList (in) An argument list which must have been initialised using TTCCLLVVAARRAARRGGSSSSTTAARRTT, and cleared using vvaaeenndd.

DESCRIPTION

The procedures described here are utilities for manipulating the result value in a Tcl interpreter. The interpreter result may be either a Tcl object or a string. For example, TTccllSSeettOObbjjRReessuulltt and TTccllSSeettRReessuulltt set the interpreter result to, respectively, an object and a string.

Similarly, TTccllGGeettOObbjjRReessuulltt and TTccllGGeettSSttrriinnggRReessuulltt return the inter-

preter result as an object and as a string. The procedures always keep the string and object forms of the interpreter result consistent. For example, if TTccllSSeettOObbjjRReessuulltt is called to set the result to an object, then TTccllGGeettSSttrriinnggRReessuulltt is called, it will return the object's string value. TTccllSSeettOObbjjRReessuulltt arranges for objPtr to be the result for interp, replacing any existing result. The result is left pointing to the object referenced by objPtr. objPtr's reference count is incremented since there is now a new reference to it from interp. The reference count for any old result object is decremented and the old result object is freed if no references to it remain. TTccllGGeettOObbjjRReessuulltt returns the result for interp as an object. The object's reference count is not incremented; if the caller needs to

retain a long-term pointer to the object they should use TTccllIInnccrrRReeff-

CCoouunntt to increment its reference count in order to keep it from being freed too early or accidently changed. TTccllSSeettRReessuulltt arranges for string to be the result for the current Tcl

command in interp, replacing any existing result. The freeProc argu-

ment specifies how to manage the storage for the string argument; it is discussed in the section TTHHEE TTCCLLFFRREEEEPPRROOCC AARRGGUUMMEENNTT TTOO TTCCLLSSEETTRREESSUULLTT below. If string is NNUULLLL, then freeProc is ignored and TTccllSSeettRReessuulltt

re-initializes interp's result to point to an empty string.

TTccllGGeettSSttrriinnggRReessuulltt returns the result for interp as an string. If the result was set to an object by a TTccllSSeettOObbjjRReessuulltt call, the object form will be converted to a string and returned. If the object's string

representation contains null bytes, this conversion will lose informa-

tion. For this reason, programmers are encouraged to write their code to use the new object API procedures and to call TTccllGGeettOObbjjRReessuulltt instead. TTccllRReesseettRReessuulltt clears the result for interp and leaves the result in its normal empty initialized state. If the result is an object, its reference count is decremented and the result is left pointing to an unshared object representing an empty string. If the result is a dynamically allocated string, its memory is free*d and the result is left as a empty string. TTccllRReesseettRReessuulltt also clears the error state managed by TTccllAAddddEErrrroorrIInnffoo, TTccllAAddddOObbjjEErrrroorrIInnffoo, and TTccllSSeettEErrrroorrCCooddee. OOLLDD SSTTRRIINNGG PPRROOCCEEDDUURREESS Use of the following procedures is deprecated since they manipulate the Tcl result as a string. Procedures such as TTccllSSeettOObbjjRReessuulltt that manipulate the result as an object can be significantly more efficient. TTccllAAppppeennddRReessuulltt makes it easy to build up Tcl results in pieces. It takes each of its string arguments and appends them in order to the

current result associated with interp. If the result is in its ini-

tialized empty state (e.g. a command procedure was just invoked or TTccllRReesseettRReessuulltt was just called), then TTccllAAppppeennddRReessuulltt sets the result to the concatenation of its string arguments. TTccllAAppppeennddRReessuulltt may be called repeatedly as additional pieces of the result are produced.

TTccllAAppppeennddRReessuulltt takes care of all the storage management issues asso-

ciated with managing interp's result, such as allocating a larger result area if necessary. It also converts the current interpreter result from an object to a string, if necessary, before appending the argument strings. Any number of string arguments may be passed in a single call; the last argument in the list must be a NULL pointer. TTccllAAppppeennddRReessuullttVVAA is the same as TTccllAAppppeennddRReessuulltt except that instead of taking a variable number of arguments it takes an argument list. TTccllAAppppeennddEElleemmeenntt is similar to TTccllAAppppeennddRReessuulltt in that it allows results to be built up in pieces. However, TTccllAAppppeennddEElleemmeenntt takes

only a single string argument and it appends that argument to the cur-

rent result as a proper Tcl list element. TTccllAAppppeennddEElleemmeenntt adds back-

slashes or braces if necessary to ensure that interp's result can be parsed as a list and that string will be extracted as a single element. Under normal conditions, TTccllAAppppeennddEElleemmeenntt will add a space character to interp's result just before adding the new list element, so that the list elements in the result are properly separated. However if the new

list element is the first in a list or sub-list (i.e. interp's current

result is empty, or consists of the single character ``{'', or ends in the characters `` {'') then no space is added. TTccllFFrreeeeRReessuulltt performs part of the work of TTccllRReesseettRReessuulltt. It frees up the memory associated with interp's result. It also sets

interp->freeProc to zero, but doesn't change interp->result or clear

error state. TTccllFFrreeeeRReessuulltt is most commonly used when a procedure is about to replace one result value with another.

DDIIRREECCTT AACCCCEESSSS TTOO IINNTTEERRPP->>RREESSUULLTT IISS DDEEPPRREECCAATTEEDD

It used to be legal for programs to directly read and write

interp->result to manipulate the interpreter result. Direct access to

interp->result is now strongly deprecated because it can make the

result's string and object forms inconsistent. Programs should always

read the result using the procedures TTccllGGeettOObbjjRReessuulltt or TTccllGGeett-

SSttrriinnggRReessuulltt, and write the result using TTccllSSeettOObbjjRReessuulltt or TTccllSSeettRRee-

ssuulltt. TTHHEE TTCCLLFFRREEEEPPRROOCC AARRGGUUMMEENNTT TTOO TTCCLLSSEETTRREESSUULLTT TTccllSSeettRReessuulltt's freeProc argument specifies how the Tcl system is to manage the storage for the string argument. If TTccllSSeettRReessuulltt or TTccllSSeettOObbjjRReessuulltt are called at a time when interp holds a string result, they do whatever is necessary to dispose of the old string result (see the TTccllIInntteerrpp manual entry for details on this). If freeProc is TTCCLLSSTTAATTIICC it means that string refers to an area of static storage that is guaranteed not to be modified until at least the next call to TTccllEEvvaall. If freeProc is TTCCLLDDYYNNAAMMIICC it means that string was allocated with a call to TTccllAAlllloocc and is now the property of the Tcl system. TTccllSSeettRReessuulltt will arrange for the string's storage to be released by calling TTccllFFrreeee when it is no longer needed. If freeProc is TTCCLLVVOOLLAATTIILLEE it means that string points to an area of memory that is likely to be overwritten when TTccllSSeettRReessuulltt returns (e.g. it points to something in a stack frame). In this case TTccllSSeettRReessuulltt will make a copy of the string in dynamically allocated storage and arrange for the copy to be the result for the current Tcl command. If freeProc isn't one of the values TTCCLLSSTTAATTIICC, TTCCLLDDYYNNAAMMIICC, and TTCCLLVVOOLLAATTIILLEE, then it is the address of a procedure that Tcl should

call to free the string. This allows applications to use non-standard

storage allocators. When Tcl no longer needs the storage for the string, it will call freeProc. FreeProc should have arguments and result that match the type TTccllFFrreeeePPrroocc: typedef void TclFreeProc(char *blockPtr); When freeProc is called, its blockPtr will be set to the value of string passed to TTccllSSeettRReessuulltt.

SEE ALSO

TclAddErrorInfo, TclCreateObjCommand, TclSetErrorCode, TclInterp KKEEYYWWOORRDDSS

append, command, element, list, object, result, return value, inter-

preter Tcl 8.0 TclSetResult(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™