Seth Woolley's Man Viewer

Tcl_GetObjResult(3) - Tcl_AppendElement, Tcl_AppendResult, Tcl_AppendResultVA, Tcl_FreeResult, Tcl_GetObjResult, Tcl_GetStringResult, Tcl_ResetResult, Tcl_SetObjResult, Tcl_SetResult - manipulate Tcl result - man 3 Tcl_GetObjResult

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Tcl_SetResult(3)            Tcl Library Procedures            Tcl_SetResult(3)



______________________________________________________________________________

NAME
       Tcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult,
       Tcl_AppendResult, Tcl_AppendResultVA,  Tcl_AppendElement,  Tcl_ResetRe-
       sult, Tcl_FreeResult - manipulate Tcl result

SYNOPSIS
       #include <tcl.h>

       Tcl_SetObjResult(interp, objPtr)

       Tcl_Obj *
       Tcl_GetObjResult(interp)

       Tcl_SetResult(interp, string(3,n), freeProc)

       CONST char *
       Tcl_GetStringResult(interp)

       Tcl_AppendResult(interp, string(3,n), string(3,n), ... , (char *) NULL)

       Tcl_AppendResultVA(interp, argList)

       Tcl_AppendElement(interp, string(3,n))

       Tcl_ResetResult(interp)

       Tcl_FreeResult(interp)

ARGUMENTS
       Tcl_Interp     *interp    (out)     Interpreter  whose  result is to be
                                           modified or read.

       Tcl_Obj        *objPtr    (in(1,8))      Object value to become  result  for
                                           interp.

       char           *string(3,n)    (in(1,8))      String  value  to become result for
                                           interp or to  be  appended  to  the
                                           existing result.

       Tcl_FreeProc   *freeProc  (in(1,8))      Address  of  procedure  to  call to
                                           release  storage  at   string(3,n),   or
                                           TCL_STATIC,     TCL_DYNAMIC,     or
                                           TCL_VOLATILE.

       va_list        argList    (in(1,8))      An argument list  which  must  have
                                           been        initialised       using
                                           TCL_VARARGS_START,   and    cleared
                                           using va_end.
_________________________________________________________________


DESCRIPTION
       The procedures described here are utilities for manipulating the result
       value in(1,8) a Tcl interpreter.  The interpreter result may be either a Tcl
       object  or  a  string.  For example, Tcl_SetObjResult and Tcl_SetResult
       set(7,n,1 builtins) the interpreter result to, respectively, an object  and  a  string.
       Similarly,  Tcl_GetObjResult  and Tcl_GetStringResult return the inter-
       preter result as an object and as a string.  The procedures always keep
       the  string(3,n) and object forms of the interpreter result consistent.  For
       example, if(3,n) Tcl_SetObjResult is called to set(7,n,1 builtins) the result to an  object,
       then  Tcl_GetStringResult is called, it will return the object's string(3,n)
       value.

       Tcl_SetObjResult 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(3,n) no references to it remain.

       Tcl_GetObjResult  returns  the  result  for  interp  as an object.  The
       object's reference count is not incremented; if(3,n)  the  caller  needs  to
       retain  a  long-term pointer to the object they should use Tcl_IncrRef-
       Count to increment its reference count in(1,8) order to keep it  from  being
       freed too early or accidently changed.

       Tcl_SetResult  arranges for string(3,n) to be the result for the current Tcl
       command in(1,8) interp, replacing any existing result.  The  freeProc  argu-
       ment specifies how to manage the storage for the string(3,n) argument; it is
       discussed in(1,8) the section THE  TCL_FREEPROC  ARGUMENT  TO  TCL_SETRESULT
       below.   If  string(3,n) is NULL, then freeProc is ignored and Tcl_SetResult
       re-initializes interp's result to point to an empty string.

       Tcl_GetStringResult returns the result for interp as an string.  If the
       result was set(7,n,1 builtins) to an object by a Tcl_SetObjResult call, the object form
       will be converted to a string(3,n) and returned.   If  the  object's  string(3,n)
       representation  contains null bytes, this conversion will lose informa-
       tion.  For this reason, programmers are encouraged to write(1,2) their  code
       to  use  the  new  object  API  procedures and to call Tcl_GetObjResult
       instead.

       Tcl_ResetResult clears the result for interp and leaves the  result  in(1,8)
       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(3,n), its memory is free*d and  the  result  is
       left  as  a  empty string.  Tcl_ResetResult also clears the error(8,n) state
       managed by Tcl_AddErrorInfo, Tcl_AddObjErrorInfo, and Tcl_SetErrorCode.


OLD STRING PROCEDURES
       Use of the following procedures is deprecated since they manipulate the
       Tcl result as a  string.   Procedures  such  as  Tcl_SetObjResult  that
       manipulate the result as an object can be significantly more efficient.

       Tcl_AppendResult makes it easy to build up Tcl results in(1,8)  pieces.   It
       takes  each  of  its  string(3,n) arguments and appends them in(1,8) order to the
       current result associated with interp.  If the result is  in(1,8)  its  ini-
       tialized  empty  state  (e.g.  a  command procedure was just invoked or
       Tcl_ResetResult was just called), then Tcl_AppendResult sets the result
       to  the concatenation of its string(3,n) arguments.  Tcl_AppendResult may be
       called repeatedly as additional pieces  of  the  result  are  produced.
       Tcl_AppendResult  takes care of all the storage management issues asso-
       ciated with managing interp's  result,  such  as  allocating  a  larger
       result  area  if(3,n)  necessary.   It also converts the current interpreter
       result from an object to a string(3,n), if(3,n) necessary, before  appending  the
       argument  strings.   Any  number of string(3,n) arguments may be passed in(1,8) a
       single call; the last argument in(1,8) the list must be a NULL pointer.

       Tcl_AppendResultVA is the same as Tcl_AppendResult except that  instead
       of taking a variable number of arguments it takes an argument list.

       Tcl_AppendElement  is  similar  to  Tcl_AppendResult  in(1,8) that it allows
       results to be built up in(1,8)  pieces.   However,  Tcl_AppendElement  takes
       only  a single string(3,n) argument and it appends that argument to the cur-
       rent result as a proper Tcl list element.  Tcl_AppendElement adds back-
       slashes  or  braces  if(3,n) necessary to ensure that interp's result can be
       parsed as a list and that string(3,n) will be extracted as a single element.
       Under  normal  conditions, Tcl_AppendElement will add a space character
       to interp's result just before adding the new list element, so that the
       list elements in(1,8) the result are properly separated.  However if(3,n) the new
       list element is the first in(1,8) a list or sub-list (i.e. interp's  current
       result  is empty, or consists of the single character ``{'', or ends in(1,8)
       the characters `` {'') then no space is added.

       Tcl_FreeResult performs part of the work of Tcl_ResetResult.  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(1,3x,3x clrtobot)
       error(8,n)  state.  Tcl_FreeResult is most commonly used when a procedure is
       about to replace one result value with another.


DIRECT ACCESS TO INTERP->RESULT IS DEPRECATED
       It  used  to  be  legal  for  programs  to  directly  read(2,n,1 builtins)  and   write(1,2)
       interp->result  to manipulate the interpreter result.  Direct access(2,5) to
       interp->result is now strongly  deprecated  because  it  can  make  the
       result's  string(3,n) and object forms inconsistent.  Programs should always
       read(2,n,1 builtins) the result  using  the  procedures  Tcl_GetObjResult  or  Tcl_Get-
       StringResult, and write(1,2) the result using Tcl_SetObjResult or Tcl_SetRe-
       sult.


THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT
       Tcl_SetResult's freeProc argument specifies how the Tcl  system  is  to
       manage  the  storage  for  the  string(3,n)  argument.   If Tcl_SetResult or
       Tcl_SetObjResult are called at  a  time(1,2,n)  when  interp  holds  a  string(3,n)
       result,  they  do  whatever  is  necessary to dispose of the old string(3,n)
       result (see the Tcl_Interp manual entry for details on this).

       If freeProc is TCL_STATIC it means that string(3,n) refers  to  an  area  of
       static storage that is guaranteed not to be modified until at least the
       next call to Tcl_Eval.  If freeProc is TCL_DYNAMIC it means that string(3,n)
       was  allocated  with a call to Tcl_Alloc and is now the property of the
       Tcl system.  Tcl_SetResult will arrange for the string(3,n)'s storage to  be
       released  by calling Tcl_Free when it is no longer needed.  If freeProc
       is TCL_VOLATILE it means that string(3,n) points to an area of  memory  that
       is  likely to be overwritten when Tcl_SetResult returns (e.g. it points
       to something in(1,8) a stack frame).  In this case Tcl_SetResult will make a
       copy of the string(3,n) in(1,8) 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  TCL_STATIC,  TCL_DYNAMIC,  and
       TCL_VOLATILE,  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(3,n), it will call  freeProc.  FreeProc  should  have  arguments  and
       result that match the type Tcl_FreeProc:
              typedef void Tcl_FreeProc(char *blockPtr);
       When  freeProc  is  called,  its  blockPtr  will be set(7,n,1 builtins) to the value of
       string(3,n) passed to Tcl_SetResult.


SEE ALSO
       Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp


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



Tcl                                   8.0                     Tcl_SetResult(3)

References for this manual (incoming links)