Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/tcl/tclListObj.c

    radeddd8 rd7d2da3  
    4646 * Tcl_NewListObj --
    4747 *
    48  *      This procedure creates a new list object from an (objc,objv) array:
    49  *      that is, each of the objc elements of the array referenced by objv
    50  *      is inserted as an element into a new Tcl object.
     48 *      This procedure is normally called when not debugging: i.e., when
     49 *      TCL_MEM_DEBUG is not defined. It creates a new list object from an
     50 *      (objc,objv) array: that is, each of the objc elements of the array
     51 *      referenced by objv is inserted as an element into a new Tcl object.
     52 *
     53 *      When TCL_MEM_DEBUG is defined, this procedure just returns the
     54 *      result of calling the debugging version Tcl_DbNewListObj.
    5155 *
    5256 * Results:
     
    6266 *----------------------------------------------------------------------
    6367 */
     68
     69#ifdef TCL_MEM_DEBUG
     70#undef Tcl_NewListObj
     71
     72Tcl_Obj *
     73Tcl_NewListObj(objc, objv)
     74    int objc;                   /* Count of objects referenced by objv. */
     75    Tcl_Obj *CONST objv[];      /* An array of pointers to Tcl objects. */
     76{
     77    return Tcl_DbNewListObj(objc, objv, "unknown", 0);
     78}
     79
     80#else /* if not TCL_MEM_DEBUG */
    6481
    6582Tcl_Obj *
     
    95112    return listPtr;
    96113}
     114#endif /* if TCL_MEM_DEBUG */
     115
     116
     117/*
     118 *----------------------------------------------------------------------
     119 *
     120 * Tcl_DbNewListObj --
     121 *
     122 *      This procedure is normally called when debugging: i.e., when
     123 *      TCL_MEM_DEBUG is defined. It creates new list objects. It is the
     124 *      same as the Tcl_NewListObj procedure above except that it calls
     125 *      Tcl_DbCkalloc directly with the file name and line number from its
     126 *      caller. This simplifies debugging since then the checkmem command
     127 *      will report the correct file name and line number when reporting
     128 *      objects that haven't been freed.
     129 *
     130 *      When TCL_MEM_DEBUG is not defined, this procedure just returns the
     131 *      result of calling Tcl_NewListObj.
     132 *
     133 * Results:
     134 *      A new list object is returned that is initialized from the object
     135 *      pointers in objv. If objc is less than or equal to zero, an empty
     136 *      object is returned. The new object's string representation
     137 *      is left NULL. The new list object has ref count 0.
     138 *
     139 * Side effects:
     140 *      The ref counts of the elements in objv are incremented since the
     141 *      resulting list now refers to them.
     142 *
     143 *----------------------------------------------------------------------
     144 */
     145
     146#ifdef TCL_MEM_DEBUG
     147
     148Tcl_Obj *
     149Tcl_DbNewListObj(objc, objv, file, line)
     150    int objc;                   /* Count of objects referenced by objv. */
     151    Tcl_Obj *CONST objv[];      /* An array of pointers to Tcl objects. */
     152    char *file;                 /* The name of the source file calling this
     153                                 * procedure; used for debugging. */
     154    int line;                   /* Line number in the source file; used
     155                                 * for debugging. */
     156{
     157    register Tcl_Obj *listPtr;
     158    register Tcl_Obj **elemPtrs;
     159    register List *listRepPtr;
     160    int i;
     161   
     162    TclDbNewObj(listPtr, file, line);
     163   
     164    if (objc > 0) {
     165        Tcl_InvalidateStringRep(listPtr);
     166       
     167        elemPtrs = (Tcl_Obj **)
     168            ckalloc((unsigned) (objc * sizeof(Tcl_Obj *)));
     169        for (i = 0;  i < objc;  i++) {
     170            elemPtrs[i] = objv[i];
     171            Tcl_IncrRefCount(elemPtrs[i]);
     172        }
     173       
     174        listRepPtr = (List *) ckalloc(sizeof(List));
     175        listRepPtr->maxElemCount = objc;
     176        listRepPtr->elemCount    = objc;
     177        listRepPtr->elements     = elemPtrs;
     178       
     179        listPtr->internalRep.otherValuePtr = (VOID *) listRepPtr;
     180        listPtr->typePtr = &tclListType;
     181    }
     182    return listPtr;
     183}
     184
     185#else /* if not TCL_MEM_DEBUG */
     186
     187Tcl_Obj *
     188Tcl_DbNewListObj(objc, objv, file, line)
     189    int objc;                   /* Count of objects referenced by objv. */
     190    Tcl_Obj *CONST objv[];      /* An array of pointers to Tcl objects. */
     191    char *file;                 /* The name of the source file calling this
     192                                 * procedure; used for debugging. */
     193    int line;                   /* Line number in the source file; used
     194                                 * for debugging. */
     195{
     196    return Tcl_NewListObj(objc, objv);
     197}
     198#endif /* TCL_MEM_DEBUG */
    97199
    98200
Note: See TracChangeset for help on using the changeset viewer.