⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setresult.3

📁 linux系统下的音频通信
💻 3
字号:
'\"'\" Copyright (c) 1989-1993 The Regents of the University of California.'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) SetResult.3 1.23 97/06/26 14:05:57'\" .so man.macros.TH Tcl_SetResult 3 7.5 Tcl "Tcl Library Procedures".BS.SH NAMETcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sp\fBTcl_SetObjResult\fR(\fIinterp, objPtr\fR).spTcl_Obj *\fBTcl_GetObjResult\fR(\fIinterp\fR).sp\fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR).spchar *\fBTcl_GetStringResult\fR(\fIinterp\fR).sp\fBTcl_AppendResult\fR(\fIinterp, string, string, ... , \fB(char *) NULL\fR).sp\fBTcl_AppendElement\fR(\fIinterp, string\fR).sp\fBTcl_ResetResult\fR(\fIinterp\fR).sp\fBTcl_FreeResult\fR(\fIinterp\fR).SH ARGUMENTS.AS Tcl_FreeProc freeProc.AP Tcl_Interp *interp outInterpreter whose result is to be modified or read..AP Tcl_Obj *objPtr inObject value to become result for \fIinterp\fR..AP char *string inString value to become result for \fIinterp\fR or to beappended to the existing result..AP Tcl_FreeProc *freeProc inAddress of procedure to call to release storage at\fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or\fBTCL_VOLATILE\fR..BE.SH DESCRIPTION.PPThe procedures described here are utilities for manipulating theresult value in a Tcl interpreter.The interpreter result may be either a Tcl object or a string.For example, \fBTcl_SetObjResult\fR and \fBTcl_SetResult\fRset the interpreter result to, respectively, an object and a string.Similarly, \fBTcl_GetObjResult\fR and \fBTcl_GetStringResult\fRreturn the interpreter result as an object and as a string.The procedures always keep the string and object formsof the interpreter result consistent.For example, if \fBTcl_SetObjResult\fR is called to setthe result to an object,then \fBTcl_GetStringResult\fR is called,it will return the object's string value..PP\fBTcl_SetObjResult\fRarranges for \fIobjPtr\fR to be the result for \fIinterp\fR,replacing any existing result.The result is left pointing to the objectreferenced by \fIobjPtr\fR.\fIobjPtr\fR's reference count is incrementedsince there is now a new reference to it from \fIinterp\fR.The reference count for any old result objectis decremented and the old result object is freed if noreferences to it remain..PP\fBTcl_GetObjResult\fR returns the result for \fIinterp\fR as an object.The object's reference count is not incremented;if the caller needs to retain a long-term pointer to the objectthey should use \fBTcl_IncrRefCount\fR to increment its reference countin order to keep it from being freed too early or accidently changed..PP\fBTcl_SetResult\fRarranges for \fIstring\fR to be the result for the current Tclcommand in \fIinterp\fR, replacing any existing result.The \fIfreeProc\fR argument specifies how to manage the storagefor the \fIstring\fR argument;it is discussed in the section\fBTHE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT\fR below.If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignoredand \fBTcl_SetResult\fRre-initializes \fIinterp\fR's result to point to an empty string..PP\fBTcl_GetStringResult\fR returns the result for \fIinterp\fR as an string.If the result was set to an object by a \fBTcl_SetObjResult\fR 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 information.For this reason, programmers are encouraged towrite their code to use the new object API proceduresand to call \fBTcl_GetObjResult\fR instead..PP\fBTcl_ResetResult\fR clears the result for \fIinterp\fRand leaves the result in its normal empty initialized state.If the result is an object,its reference count is decremented and the result is leftpointing to an unshared object representing an empty string.If the result is a dynamically allocated string, its memory is free*dand the result is left as a empty string.\fBTcl_ResetResult\fR also clears the error state managed by\fBTcl_AddErrorInfo\fR, \fBTcl_AddObjErrorInfo\fR,and \fBTcl_SetErrorCode\fR..SH OLD STRING PROCEDURES.PPUse of the following procedures is deprecatedsince they manipulate the Tcl result as a string.Procedures such as \fBTcl_SetObjResult\fRthat manipulate the result as an objectcan be significantly more efficient..PP\fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.It takes each of its \fIstring\fR arguments and appends them in orderto the current result associated with \fIinterp\fR.If the result is in its initialized empty state (e.g. a command procedurewas just invoked or \fBTcl_ResetResult\fR was just called),then \fBTcl_AppendResult\fR sets the result to the concatenation ofits \fIstring\fR arguments.\fBTcl_AppendResult\fR may be called repeatedly as additional piecesof the result are produced.\fBTcl_AppendResult\fR takes care of all thestorage management issues associated with managing \fIinterp\fR'sresult, such as allocating a larger result area if necessary.It also converts the current interpreter result from an objectto a string, if necessary, before appending the argument strings.Any number of \fIstring\fR arguments may be passed in a singlecall; the last argument in the list must be a NULL pointer..PP\fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR inthat it allows results to be built up in pieces.However, \fBTcl_AppendElement\fR takes only a single \fIstring\fRargument and it appends that argument to the current resultas a proper Tcl list element.\fBTcl_AppendElement\fR adds backslashes or braces if necessaryto ensure that \fIinterp\fR's result can be parsed as a list and that\fIstring\fR will be extracted as a single element.Under normal conditions, \fBTcl_AppendElement\fR will add a spacecharacter to \fIinterp\fR's result just before adding the newlist element, so that the list elements in the result are properlyseparated.However if the new list element is the first in a list or sub-list(i.e. \fIinterp\fR's current result is empty, or consists of thesingle character ``{'', or ends in the characters `` {'') then nospace is added..PP\fBTcl_FreeResult\fR performs part of the workof \fBTcl_ResetResult\fR.It frees up the memory associated with \fIinterp\fR's result.It also sets \fIinterp->freeProc\fR to zero, but doesn'tchange \fIinterp->result\fR or clear error state.\fBTcl_FreeResult\fR is most commonly used when a procedureis about to replace one result value with another..SH DIRECT ACCESS TO INTERP->RESULT IS DEPRECATED.PPIt used to be legal for programs todirectly read and write \fIinterp->result\fRto manipulate the interpreter result.Direct access to \fIinterp->result\fR is now strongly deprecatedbecause it can make the result's string and object forms inconsistent.Programs should always read the resultusing the procedures \fBTcl_GetObjResult\fR or \fBTcl_GetStringResult\fR,and write the result using \fBTcl_SetObjResult\fR or \fBTcl_SetResult\fR..SH THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT.PP\fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how the Tcl system is to manage the storage for the \fIstring\fR argument.If \fBTcl_SetResult\fR or \fBTcl_SetObjResult\fR are calledat a time when \fIinterp\fR holds a string result,they do whatever is necessary to dispose of the old string result(see the \fBTcl_Interp\fR manual entry for details on this)..PPIf \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fRrefers to an area of static storage that is guaranteed not to bemodified until at least the next call to \fBTcl_Eval\fR.If \fIfreeProc\fRis \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a callto \fBTcl_Alloc\fR and is now the property of the Tcl system.\fBTcl_SetResult\fR will arrange for the string's storage to bereleased by calling \fBTcl_Free\fR when it is no longer needed.If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fRpoints to an area of memory that is likely to be overwritten when\fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).In this case \fBTcl_SetResult\fR will make a copy of the string indynamically allocated storage and arrange for the copy to be theresult for the current Tcl command..PPIf \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,\fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the addressof 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 willcall \fIfreeProc\fR. \fIFreeProc\fR should have arguments andresult that match the type \fBTcl_FreeProc\fR:.CStypedef void Tcl_FreeProc(char *\fIblockPtr\fR);.CEWhen \fIfreeProc\fR is called, its \fIblockPtr\fR will be set tothe value of \fIstring\fR passed to \fBTcl_SetResult\fR..SH "SEE ALSO"Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp.SH KEYWORDSappend, command, element, list, object, result, return value, interpreter

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -