Tcl Source Code

Hex Artifact Content
Login

Artifact 5b8626372bfa0b4f698cccc6d2f1f0bca8f5860b7f8b07625f226516e9daa891:


0000: 2f 2a 0a 20 2a 20 74 63 6c 4c 69 73 74 4f 62 6a  /*. * tclListObj
0010: 2e 63 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73  .c --. *. *.This
0020: 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 73 20 66   file contains f
0030: 75 6e 63 74 69 6f 6e 73 20 74 68 61 74 20 69 6d  unctions that im
0040: 70 6c 65 6d 65 6e 74 20 74 68 65 20 54 63 6c 20  plement the Tcl 
0050: 6c 69 73 74 20 6f 62 6a 65 63 74 20 74 79 70 65  list object type
0060: 2e 0a 20 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68  .. *. * Copyrigh
0070: 74 20 28 63 29 20 31 39 39 35 2d 31 39 39 37 20  t (c) 1995-1997 
0080: 53 75 6e 20 4d 69 63 72 6f 73 79 73 74 65 6d 73  Sun Microsystems
0090: 2c 20 49 6e 63 2e 0a 20 2a 20 43 6f 70 79 72 69  , Inc.. * Copyri
00a0: 67 68 74 20 28 63 29 20 31 39 39 38 20 62 79 20  ght (c) 1998 by 
00b0: 53 63 72 69 70 74 69 63 73 20 43 6f 72 70 6f 72  Scriptics Corpor
00c0: 61 74 69 6f 6e 2e 0a 20 2a 20 43 6f 70 79 72 69  ation.. * Copyri
00d0: 67 68 74 20 28 63 29 20 32 30 30 31 20 62 79 20  ght (c) 2001 by 
00e0: 4b 65 76 69 6e 20 42 2e 20 4b 65 6e 6e 79 2e 20  Kevin B. Kenny. 
00f0: 20 41 6c 6c 20 72 69 67 68 74 73 20 72 65 73 65   All rights rese
0100: 72 76 65 64 2e 0a 20 2a 0a 20 2a 20 53 65 65 20  rved.. *. * See 
0110: 74 68 65 20 66 69 6c 65 20 22 6c 69 63 65 6e 73  the file "licens
0120: 65 2e 74 65 72 6d 73 22 20 66 6f 72 20 69 6e 66  e.terms" for inf
0130: 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 75 73 61 67  ormation on usag
0140: 65 20 61 6e 64 20 72 65 64 69 73 74 72 69 62 75  e and redistribu
0150: 74 69 6f 6e 20 6f 66 0a 20 2a 20 74 68 69 73 20  tion of. * this 
0160: 66 69 6c 65 2c 20 61 6e 64 20 66 6f 72 20 61 20  file, and for a 
0170: 44 49 53 43 4c 41 49 4d 45 52 20 4f 46 20 41 4c  DISCLAIMER OF AL
0180: 4c 20 57 41 52 52 41 4e 54 49 45 53 2e 0a 20 2a  L WARRANTIES.. *
0190: 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 74 63 6c  /..#include "tcl
01a0: 49 6e 74 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  Int.h".#include 
01b0: 3c 61 73 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 20  <assert.h>../*. 
01c0: 2a 20 50 72 6f 74 6f 74 79 70 65 73 20 66 6f 72  * Prototypes for
01d0: 20 66 75 6e 63 74 69 6f 6e 73 20 64 65 66 69 6e   functions defin
01e0: 65 64 20 6c 61 74 65 72 20 69 6e 20 74 68 69 73  ed later in this
01f0: 20 66 69 6c 65 3a 0a 20 2a 2f 0a 0a 73 74 61 74   file:. */..stat
0200: 69 63 20 4c 69 73 74 20 2a 09 09 41 74 74 65 6d  ic List *..Attem
0210: 70 74 4e 65 77 4c 69 73 74 28 54 63 6c 5f 49 6e  ptNewList(Tcl_In
0220: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e  terp *interp, in
0230: 74 20 6f 62 6a 63 2c 0a 09 09 09 20 20 20 20 54  t objc,....    T
0240: 63 6c 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20 6f 62  cl_Obj *const ob
0250: 6a 76 5b 5d 29 3b 0a 73 74 61 74 69 63 20 4c 69  jv[]);.static Li
0260: 73 74 20 2a 09 09 4e 65 77 4c 69 73 74 49 6e 74  st *..NewListInt
0270: 52 65 70 28 69 6e 74 20 6f 62 6a 63 2c 20 54 63  Rep(int objc, Tc
0280: 6c 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20 6f 62 6a  l_Obj *const obj
0290: 76 5b 5d 2c 20 69 6e 74 20 70 29 3b 0a 73 74 61  v[], int p);.sta
02a0: 74 69 63 20 76 6f 69 64 09 09 44 75 70 4c 69 73  tic void..DupLis
02b0: 74 49 6e 74 65 72 6e 61 6c 52 65 70 28 54 63 6c  tInternalRep(Tcl
02c0: 5f 4f 62 6a 20 2a 73 72 63 50 74 72 2c 20 54 63  _Obj *srcPtr, Tc
02d0: 6c 5f 4f 62 6a 20 2a 63 6f 70 79 50 74 72 29 3b  l_Obj *copyPtr);
02e0: 0a 73 74 61 74 69 63 20 76 6f 69 64 09 09 46 72  .static void..Fr
02f0: 65 65 4c 69 73 74 49 6e 74 65 72 6e 61 6c 52 65  eeListInternalRe
0300: 70 28 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50  p(Tcl_Obj *listP
0310: 74 72 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 09  tr);.static int.
0320: 09 53 65 74 4c 69 73 74 46 72 6f 6d 41 6e 79 28  .SetListFromAny(
0330: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65  Tcl_Interp *inte
0340: 72 70 2c 20 54 63 6c 5f 4f 62 6a 20 2a 6f 62 6a  rp, Tcl_Obj *obj
0350: 50 74 72 29 3b 0a 73 74 61 74 69 63 20 76 6f 69  Ptr);.static voi
0360: 64 09 09 55 70 64 61 74 65 53 74 72 69 6e 67 4f  d..UpdateStringO
0370: 66 4c 69 73 74 28 54 63 6c 5f 4f 62 6a 20 2a 6c  fList(Tcl_Obj *l
0380: 69 73 74 50 74 72 29 3b 0a 0a 2f 2a 0a 20 2a 20  istPtr);../*. * 
0390: 54 68 65 20 73 74 72 75 63 74 75 72 65 20 62 65  The structure be
03a0: 6c 6f 77 20 64 65 66 69 6e 65 73 20 74 68 65 20  low defines the 
03b0: 6c 69 73 74 20 54 63 6c 20 6f 62 6a 65 63 74 20  list Tcl object 
03c0: 74 79 70 65 20 62 79 20 6d 65 61 6e 73 20 6f 66  type by means of
03d0: 20 66 75 6e 63 74 69 6f 6e 73 0a 20 2a 20 74 68   functions. * th
03e0: 61 74 20 63 61 6e 20 62 65 20 69 6e 76 6f 6b 65  at can be invoke
03f0: 64 20 62 79 20 67 65 6e 65 72 69 63 20 6f 62 6a  d by generic obj
0400: 65 63 74 20 63 6f 64 65 2e 0a 20 2a 0a 20 2a 20  ect code.. *. * 
0410: 54 68 65 20 69 6e 74 65 72 6e 61 6c 20 72 65 70  The internal rep
0420: 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61  resentation of a
0430: 20 6c 69 73 74 20 6f 62 6a 65 63 74 20 69 73 20   list object is 
0440: 61 20 74 77 6f 2d 70 6f 69 6e 74 65 72 0a 20 2a  a two-pointer. *
0450: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e   representation.
0460: 20 54 68 65 20 66 69 72 73 74 20 70 6f 69 6e 74   The first point
0470: 65 72 20 64 65 73 69 67 6e 61 74 65 73 20 61 20  er designates a 
0480: 4c 69 73 74 20 73 74 72 75 63 74 75 72 65 20 74  List structure t
0490: 68 61 74 20 63 6f 6e 74 61 69 6e 73 0a 20 2a 20  hat contains. * 
04a0: 61 6e 20 61 72 72 61 79 20 6f 66 20 70 6f 69 6e  an array of poin
04b0: 74 65 72 73 20 74 6f 20 74 68 65 20 65 6c 65 6d  ters to the elem
04c0: 65 6e 74 20 6f 62 6a 65 63 74 73 2c 20 74 6f 67  ent objects, tog
04d0: 65 74 68 65 72 20 77 69 74 68 20 69 6e 74 65 67  ether with integ
04e0: 65 72 73 20 74 68 61 74 0a 20 2a 20 72 65 70 72  ers that. * repr
04f0: 65 73 65 6e 74 20 74 68 65 20 63 75 72 72 65 6e  esent the curren
0500: 74 20 65 6c 65 6d 65 6e 74 20 63 6f 75 6e 74 20  t element count 
0510: 61 6e 64 20 74 68 65 20 61 6c 6c 6f 63 61 74 65  and the allocate
0520: 64 20 73 69 7a 65 20 6f 66 20 74 68 65 20 61 72  d size of the ar
0530: 72 61 79 2e 0a 20 2a 20 54 68 65 20 73 65 63 6f  ray.. * The seco
0540: 6e 64 20 70 6f 69 6e 74 65 72 20 69 73 20 6e 6f  nd pointer is no
0550: 72 6d 61 6c 6c 79 20 4e 55 4c 4c 3b 20 64 75 72  rmally NULL; dur
0560: 69 6e 67 20 65 78 65 63 75 74 69 6f 6e 20 6f 66  ing execution of
0570: 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e 20 74 68   functions in th
0580: 69 73 0a 20 2a 20 66 69 6c 65 20 74 68 61 74 20  is. * file that 
0590: 6f 70 65 72 61 74 65 20 6f 6e 20 6e 65 73 74 65  operate on neste
05a0: 64 20 73 75 62 6c 69 73 74 73 2c 20 69 74 20 69  d sublists, it i
05b0: 73 20 6f 63 63 61 73 69 6f 6e 61 6c 6c 79 20 75  s occasionally u
05c0: 73 65 64 20 61 73 20 77 6f 72 6b 69 6e 67 0a 20  sed as working. 
05d0: 2a 20 73 74 6f 72 61 67 65 20 74 6f 20 61 76 6f  * storage to avo
05e0: 69 64 20 61 6e 20 61 75 78 69 6c 69 61 72 79 20  id an auxiliary 
05f0: 73 74 61 63 6b 2e 0a 20 2a 2f 0a 0a 63 6f 6e 73  stack.. */..cons
0600: 74 20 54 63 6c 5f 4f 62 6a 54 79 70 65 20 74 63  t Tcl_ObjType tc
0610: 6c 4c 69 73 74 54 79 70 65 20 3d 20 7b 0a 20 20  lListType = {.  
0620: 20 20 22 6c 69 73 74 22 2c 09 09 09 2f 2a 20 6e    "list",.../* n
0630: 61 6d 65 20 2a 2f 0a 20 20 20 20 46 72 65 65 4c  ame */.    FreeL
0640: 69 73 74 49 6e 74 65 72 6e 61 6c 52 65 70 2c 09  istInternalRep,.
0650: 2f 2a 20 66 72 65 65 49 6e 74 52 65 70 50 72 6f  /* freeIntRepPro
0660: 63 20 2a 2f 0a 20 20 20 20 44 75 70 4c 69 73 74  c */.    DupList
0670: 49 6e 74 65 72 6e 61 6c 52 65 70 2c 09 09 2f 2a  InternalRep,../*
0680: 20 64 75 70 49 6e 74 52 65 70 50 72 6f 63 20 2a   dupIntRepProc *
0690: 2f 0a 20 20 20 20 55 70 64 61 74 65 53 74 72 69  /.    UpdateStri
06a0: 6e 67 4f 66 4c 69 73 74 2c 09 09 2f 2a 20 75 70  ngOfList,../* up
06b0: 64 61 74 65 53 74 72 69 6e 67 50 72 6f 63 20 2a  dateStringProc *
06c0: 2f 0a 20 20 20 20 53 65 74 4c 69 73 74 46 72 6f  /.    SetListFro
06d0: 6d 41 6e 79 09 09 2f 2a 20 73 65 74 46 72 6f 6d  mAny../* setFrom
06e0: 41 6e 79 50 72 6f 63 20 2a 2f 0a 7d 3b 0a 0a 2f  AnyProc */.};../
06f0: 2a 20 4d 61 63 72 6f 73 20 74 6f 20 6d 61 6e 69  * Macros to mani
0700: 70 75 6c 61 74 65 20 74 68 65 20 4c 69 73 74 20  pulate the List 
0710: 69 6e 74 65 72 6e 61 6c 20 72 65 70 20 2a 2f 0a  internal rep */.
0720: 0a 23 64 65 66 69 6e 65 20 4c 69 73 74 53 65 74  .#define ListSet
0730: 49 6e 74 52 65 70 28 6f 62 6a 50 74 72 2c 20 6c  IntRep(objPtr, l
0740: 69 73 74 52 65 70 50 74 72 29 09 09 09 09 5c 0a  istRepPtr)....\.
0750: 20 20 20 20 64 6f 20 7b 09 09 09 09 09 09 09 09      do {........
0760: 5c 0a 09 54 63 6c 5f 4f 62 6a 49 6e 74 52 65 70  \..Tcl_ObjIntRep
0770: 20 69 72 3b 09 09 09 09 09 09 5c 0a 09 69 72 2e   ir;......\..ir.
0780: 74 77 6f 50 74 72 56 61 6c 75 65 2e 70 74 72 31  twoPtrValue.ptr1
0790: 20 3d 20 28 6c 69 73 74 52 65 70 50 74 72 29 3b   = (listRepPtr);
07a0: 09 09 09 09 5c 0a 09 69 72 2e 74 77 6f 50 74 72  ....\..ir.twoPtr
07b0: 56 61 6c 75 65 2e 70 74 72 32 20 3d 20 4e 55 4c  Value.ptr2 = NUL
07c0: 4c 3b 09 09 09 09 09 5c 0a 09 28 6c 69 73 74 52  L;.....\..(listR
07d0: 65 70 50 74 72 29 2d 3e 72 65 66 43 6f 75 6e 74  epPtr)->refCount
07e0: 2b 2b 3b 09 09 09 09 09 5c 0a 09 54 63 6c 5f 53  ++;.....\..Tcl_S
07f0: 74 6f 72 65 49 6e 74 52 65 70 28 28 6f 62 6a 50  toreIntRep((objP
0800: 74 72 29 2c 20 26 74 63 6c 4c 69 73 74 54 79 70  tr), &tclListTyp
0810: 65 2c 20 26 69 72 29 3b 09 09 09 5c 0a 20 20 20  e, &ir);...\.   
0820: 20 7d 20 77 68 69 6c 65 20 28 30 29 0a 0a 23 64   } while (0)..#d
0830: 65 66 69 6e 65 20 4c 69 73 74 47 65 74 49 6e 74  efine ListGetInt
0840: 52 65 70 28 6f 62 6a 50 74 72 2c 20 6c 69 73 74  Rep(objPtr, list
0850: 52 65 70 50 74 72 29 09 09 09 09 5c 0a 20 20 20  RepPtr)....\.   
0860: 20 64 6f 20 7b 09 09 09 09 09 09 09 09 5c 0a 09   do {........\..
0870: 63 6f 6e 73 74 20 54 63 6c 5f 4f 62 6a 49 6e 74  const Tcl_ObjInt
0880: 52 65 70 20 2a 69 72 50 74 72 3b 09 09 09 09 09  Rep *irPtr;.....
0890: 5c 0a 09 69 72 50 74 72 20 3d 20 54 63 6c 46 65  \..irPtr = TclFe
08a0: 74 63 68 49 6e 74 52 65 70 28 28 6f 62 6a 50 74  tchIntRep((objPt
08b0: 72 29 2c 20 26 74 63 6c 4c 69 73 74 54 79 70 65  r), &tclListType
08c0: 29 3b 09 09 5c 0a 09 28 6c 69 73 74 52 65 70 50  );..\..(listRepP
08d0: 74 72 29 20 3d 20 69 72 50 74 72 20 3f 20 28 4c  tr) = irPtr ? (L
08e0: 69 73 74 20 2a 29 69 72 50 74 72 2d 3e 74 77 6f  ist *)irPtr->two
08f0: 50 74 72 56 61 6c 75 65 2e 70 74 72 31 20 3a 20  PtrValue.ptr1 : 
0900: 4e 55 4c 4c 3b 09 09 5c 0a 20 20 20 20 7d 20 77  NULL;..\.    } w
0910: 68 69 6c 65 20 28 30 29 0a 0a 23 64 65 66 69 6e  hile (0)..#defin
0920: 65 20 4c 69 73 74 52 65 73 65 74 49 6e 74 52 65  e ListResetIntRe
0930: 70 28 6f 62 6a 50 74 72 2c 20 6c 69 73 74 52 65  p(objPtr, listRe
0940: 70 50 74 72 29 20 5c 0a 20 20 20 20 54 63 6c 46  pPtr) \.    TclF
0950: 65 74 63 68 49 6e 74 52 65 70 28 28 6f 62 6a 50  etchIntRep((objP
0960: 74 72 29 2c 20 26 74 63 6c 4c 69 73 74 54 79 70  tr), &tclListTyp
0970: 65 29 2d 3e 74 77 6f 50 74 72 56 61 6c 75 65 2e  e)->twoPtrValue.
0980: 70 74 72 31 20 3d 20 28 6c 69 73 74 52 65 70 50  ptr1 = (listRepP
0990: 74 72 29 0a 0a 23 69 66 6e 64 65 66 20 54 43 4c  tr)..#ifndef TCL
09a0: 5f 4d 49 4e 5f 45 4c 45 4d 45 4e 54 5f 47 52 4f  _MIN_ELEMENT_GRO
09b0: 57 54 48 0a 23 64 65 66 69 6e 65 20 54 43 4c 5f  WTH.#define TCL_
09c0: 4d 49 4e 5f 45 4c 45 4d 45 4e 54 5f 47 52 4f 57  MIN_ELEMENT_GROW
09d0: 54 48 20 54 43 4c 5f 4d 49 4e 5f 47 52 4f 57 54  TH TCL_MIN_GROWT
09e0: 48 2f 73 69 7a 65 6f 66 28 54 63 6c 5f 4f 62 6a  H/sizeof(Tcl_Obj
09f0: 20 2a 29 0a 23 65 6e 64 69 66 0a 0c 0a 2f 2a 0a   *).#endif.../*.
0a00: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
0a10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a40: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 4e  --------. *. * N
0a50: 65 77 4c 69 73 74 49 6e 74 52 65 70 20 2d 2d 0a  ewListIntRep --.
0a60: 20 2a 0a 20 2a 09 43 72 65 61 74 65 73 20 61 20   *. *.Creates a 
0a70: 6c 69 73 74 20 69 6e 74 65 72 6e 61 6c 20 72 65  list internal re
0a80: 70 20 77 69 74 68 20 73 70 61 63 65 20 66 6f 72  p with space for
0a90: 20 6f 62 6a 63 20 65 6c 65 6d 65 6e 74 73 2e 20   objc elements. 
0aa0: 20 6f 62 6a 63 0a 20 2a 09 6d 75 73 74 20 62 65   objc. *.must be
0ab0: 20 3e 20 30 2e 20 20 49 66 20 6f 62 6a 76 21 3d   > 0.  If objv!=
0ac0: 4e 55 4c 4c 2c 20 69 6e 69 74 69 61 6c 69 7a 65  NULL, initialize
0ad0: 73 20 77 69 74 68 20 74 68 65 20 66 69 72 73 74  s with the first
0ae0: 20 6f 62 6a 63 20 76 61 6c 75 65 73 0a 20 2a 09   objc values. *.
0af0: 69 6e 20 74 68 61 74 20 61 72 72 61 79 2e 20 20  in that array.  
0b00: 49 66 20 6f 62 6a 76 3d 3d 4e 55 4c 4c 2c 20 69  If objv==NULL, i
0b10: 6e 69 74 61 6c 69 7a 65 20 6c 69 73 74 20 69 6e  nitalize list in
0b20: 74 65 72 6e 61 6c 20 72 65 70 20 74 6f 20 68 61  ternal rep to ha
0b30: 76 65 0a 20 2a 09 30 20 65 6c 65 6d 65 6e 74 73  ve. *.0 elements
0b40: 2c 20 77 69 74 68 20 73 70 61 63 65 20 74 6f 20  , with space to 
0b50: 61 64 64 20 6f 62 6a 63 20 6d 6f 72 65 2e 20 20  add objc more.  
0b60: 46 6c 61 67 20 76 61 6c 75 65 20 22 70 22 20 69  Flag value "p" i
0b70: 6e 64 69 63 61 74 65 73 0a 20 2a 09 68 6f 77 20  ndicates. *.how 
0b80: 74 6f 20 62 65 68 61 76 65 20 6f 6e 20 66 61 69  to behave on fai
0b90: 6c 75 72 65 2e 0a 20 2a 0a 20 2a 20 52 65 73 75  lure.. *. * Resu
0ba0: 6c 74 73 3a 0a 20 2a 09 41 20 6e 65 77 20 4c 69  lts:. *.A new Li
0bb0: 73 74 20 73 74 72 75 63 74 20 77 69 74 68 20 72  st struct with r
0bc0: 65 66 43 6f 75 6e 74 20 30 20 69 73 20 72 65 74  efCount 0 is ret
0bd0: 75 72 6e 65 64 2e 20 49 66 20 73 6f 6d 65 20 66  urned. If some f
0be0: 61 69 6c 75 72 65 0a 20 2a 09 70 72 65 76 65 6e  ailure. *.preven
0bf0: 74 73 20 74 68 69 73 20 74 68 65 6e 20 69 66 20  ts this then if 
0c00: 70 3d 30 2c 20 4e 55 4c 4c 20 69 73 20 72 65 74  p=0, NULL is ret
0c10: 75 72 6e 65 64 20 61 6e 64 20 6f 74 68 65 72 77  urned and otherw
0c20: 69 73 65 20 74 68 65 0a 20 2a 09 72 6f 75 74 69  ise the. *.routi
0c30: 6e 65 20 70 61 6e 69 63 73 2e 0a 20 2a 0a 20 2a  ne panics.. *. *
0c40: 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20   Side effects:. 
0c50: 2a 09 54 68 65 20 72 65 66 20 63 6f 75 6e 74 73  *.The ref counts
0c60: 20 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e 74 73   of the elements
0c70: 20 69 6e 20 6f 62 6a 76 20 61 72 65 20 69 6e 63   in objv are inc
0c80: 72 65 6d 65 6e 74 65 64 20 73 69 6e 63 65 20 74  remented since t
0c90: 68 65 0a 20 2a 09 72 65 73 75 6c 74 69 6e 67 20  he. *.resulting 
0ca0: 6c 69 73 74 20 6e 6f 77 20 72 65 66 65 72 73 20  list now refers 
0cb0: 74 6f 20 74 68 65 6d 2e 0a 20 2a 0a 20 2a 2d 2d  to them.. *. *--
0cc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d00: 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 61 74 69 63  ----. */..static
0d10: 20 4c 69 73 74 20 2a 0a 4e 65 77 4c 69 73 74 49   List *.NewListI
0d20: 6e 74 52 65 70 28 0a 20 20 20 20 69 6e 74 20 6f  ntRep(.    int o
0d30: 62 6a 63 2c 0a 20 20 20 20 54 63 6c 5f 4f 62 6a  bjc,.    Tcl_Obj
0d40: 20 2a 63 6f 6e 73 74 20 6f 62 6a 76 5b 5d 2c 0a   *const objv[],.
0d50: 20 20 20 20 69 6e 74 20 70 29 0a 7b 0a 20 20 20      int p).{.   
0d60: 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74   List *listRepPt
0d70: 72 3b 0a 0a 20 20 20 20 69 66 20 28 6f 62 6a 63  r;..    if (objc
0d80: 20 3c 3d 20 30 29 20 7b 0a 09 54 63 6c 5f 50 61   <= 0) {..Tcl_Pa
0d90: 6e 69 63 28 22 4e 65 77 4c 69 73 74 49 6e 74 52  nic("NewListIntR
0da0: 65 70 3a 20 65 78 70 65 63 74 73 20 70 6f 73 74  ep: expects post
0db0: 69 76 65 20 65 6c 65 6d 65 6e 74 20 63 6f 75 6e  ive element coun
0dc0: 74 22 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  t");.    }..    
0dd0: 2f 2a 0a 20 20 20 20 20 2a 20 46 69 72 73 74 20  /*.     * First 
0de0: 63 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20  check to see if 
0df0: 77 65 27 64 20 6f 76 65 72 66 6c 6f 77 20 61 6e  we'd overflow an
0e00: 64 20 74 72 79 20 74 6f 20 61 6c 6c 6f 63 61 74  d try to allocat
0e10: 65 20 61 6e 20 6f 62 6a 65 63 74 0a 20 20 20 20  e an object.    
0e20: 20 2a 20 6c 61 72 67 65 72 20 74 68 61 6e 20 6f   * larger than o
0e30: 75 72 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61  ur memory alloca
0e40: 74 6f 72 20 61 6c 6c 6f 77 73 2e 20 4e 6f 74 65  tor allows. Note
0e50: 20 74 68 61 74 20 74 68 69 73 20 69 73 20 61 63   that this is ac
0e60: 74 75 61 6c 6c 79 20 61 0a 20 20 20 20 20 2a 20  tually a.     * 
0e70: 66 61 69 72 6c 79 20 73 6d 61 6c 6c 20 76 61 6c  fairly small val
0e80: 75 65 20 77 68 65 6e 20 79 6f 75 27 72 65 20 6f  ue when you're o
0e90: 6e 20 61 20 73 65 72 69 6f 75 73 20 36 34 2d 62  n a serious 64-b
0ea0: 69 74 20 6d 61 63 68 69 6e 65 2c 20 62 75 74 20  it machine, but 
0eb0: 74 68 61 74 0a 20 20 20 20 20 2a 20 72 65 71 75  that.     * requ
0ec0: 69 72 65 73 20 41 50 49 20 63 68 61 6e 67 65 73  ires API changes
0ed0: 20 74 6f 20 66 69 78 2e 20 53 65 65 20 5b 42 75   to fix. See [Bu
0ee0: 67 20 32 31 39 31 39 36 5d 20 66 6f 72 20 61 20  g 219196] for a 
0ef0: 64 69 73 63 75 73 73 69 6f 6e 2e 0a 20 20 20 20  discussion..    
0f00: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 28 73 69   */..    if ((si
0f10: 7a 65 5f 74 29 6f 62 6a 63 20 3e 20 4c 49 53 54  ze_t)objc > LIST
0f20: 5f 4d 41 58 29 20 7b 0a 09 69 66 20 28 70 29 20  _MAX) {..if (p) 
0f30: 7b 0a 09 20 20 20 20 54 63 6c 5f 50 61 6e 69 63  {..    Tcl_Panic
0f40: 28 22 6d 61 78 20 6c 65 6e 67 74 68 20 6f 66 20  ("max length of 
0f50: 61 20 54 63 6c 20 6c 69 73 74 20 28 25 64 20 65  a Tcl list (%d e
0f60: 6c 65 6d 65 6e 74 73 29 20 65 78 63 65 65 64 65  lements) exceede
0f70: 64 22 2c 0a 09 09 20 20 20 20 4c 49 53 54 5f 4d  d",...    LIST_M
0f80: 41 58 29 3b 0a 09 7d 0a 09 72 65 74 75 72 6e 20  AX);..}..return 
0f90: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  NULL;.    }..   
0fa0: 20 6c 69 73 74 52 65 70 50 74 72 20 3d 20 28 4c   listRepPtr = (L
0fb0: 69 73 74 20 2a 29 61 74 74 65 6d 70 74 63 6b 61  ist *)attemptcka
0fc0: 6c 6c 6f 63 28 4c 49 53 54 5f 53 49 5a 45 28 6f  lloc(LIST_SIZE(o
0fd0: 62 6a 63 29 29 3b 0a 20 20 20 20 69 66 20 28 6c  bjc));.    if (l
0fe0: 69 73 74 52 65 70 50 74 72 20 3d 3d 20 4e 55 4c  istRepPtr == NUL
0ff0: 4c 29 20 7b 0a 09 69 66 20 28 70 29 20 7b 0a 09  L) {..if (p) {..
1000: 20 20 20 20 54 63 6c 5f 50 61 6e 69 63 28 22 6c      Tcl_Panic("l
1010: 69 73 74 20 63 72 65 61 74 69 6f 6e 20 66 61 69  ist creation fai
1020: 6c 65 64 3a 20 75 6e 61 62 6c 65 20 74 6f 20 61  led: unable to a
1030: 6c 6c 6f 63 20 25 75 20 62 79 74 65 73 22 2c 0a  lloc %u bytes",.
1040: 09 09 20 20 20 20 4c 49 53 54 5f 53 49 5a 45 28  ..    LIST_SIZE(
1050: 6f 62 6a 63 29 29 3b 0a 09 7d 0a 09 72 65 74 75  objc));..}..retu
1060: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a  rn NULL;.    }..
1070: 20 20 20 20 6c 69 73 74 52 65 70 50 74 72 2d 3e      listRepPtr->
1080: 63 61 6e 6f 6e 69 63 61 6c 46 6c 61 67 20 3d 20  canonicalFlag = 
1090: 30 3b 0a 20 20 20 20 6c 69 73 74 52 65 70 50 74  0;.    listRepPt
10a0: 72 2d 3e 72 65 66 43 6f 75 6e 74 20 3d 20 30 3b  r->refCount = 0;
10b0: 0a 20 20 20 20 6c 69 73 74 52 65 70 50 74 72 2d  .    listRepPtr-
10c0: 3e 6d 61 78 45 6c 65 6d 43 6f 75 6e 74 20 3d 20  >maxElemCount = 
10d0: 6f 62 6a 63 3b 0a 0a 20 20 20 20 69 66 20 28 6f  objc;..    if (o
10e0: 62 6a 76 29 20 7b 0a 09 54 63 6c 5f 4f 62 6a 20  bjv) {..Tcl_Obj 
10f0: 2a 2a 65 6c 65 6d 50 74 72 73 3b 0a 09 69 6e 74  **elemPtrs;..int
1100: 20 69 3b 0a 0a 09 6c 69 73 74 52 65 70 50 74 72   i;...listRepPtr
1110: 2d 3e 65 6c 65 6d 43 6f 75 6e 74 20 3d 20 6f 62  ->elemCount = ob
1120: 6a 63 3b 0a 09 65 6c 65 6d 50 74 72 73 20 3d 20  jc;..elemPtrs = 
1130: 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65  &listRepPtr->ele
1140: 6d 65 6e 74 73 3b 0a 09 66 6f 72 20 28 69 20 3d  ments;..for (i =
1150: 20 30 3b 20 20 69 20 3c 20 6f 62 6a 63 3b 20 20   0;  i < objc;  
1160: 69 2b 2b 29 20 7b 0a 09 20 20 20 20 65 6c 65 6d  i++) {..    elem
1170: 50 74 72 73 5b 69 5d 20 3d 20 6f 62 6a 76 5b 69  Ptrs[i] = objv[i
1180: 5d 3b 0a 09 20 20 20 20 54 63 6c 5f 49 6e 63 72  ];..    Tcl_Incr
1190: 52 65 66 43 6f 75 6e 74 28 65 6c 65 6d 50 74 72  RefCount(elemPtr
11a0: 73 5b 69 5d 29 3b 0a 09 7d 0a 20 20 20 20 7d 20  s[i]);..}.    } 
11b0: 65 6c 73 65 20 7b 0a 09 6c 69 73 74 52 65 70 50  else {..listRepP
11c0: 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 20 3d 20  tr->elemCount = 
11d0: 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74  0;.    }.    ret
11e0: 75 72 6e 20 6c 69 73 74 52 65 70 50 74 72 3b 0a  urn listRepPtr;.
11f0: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d  }.../*. *-------
1200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1240: 20 2a 0a 20 2a 20 41 74 74 65 6d 70 74 4e 65 77   *. * AttemptNew
1250: 4c 69 73 74 20 2d 2d 0a 20 2a 0a 20 2a 09 43 72  List --. *. *.Cr
1260: 65 61 74 65 73 20 61 20 6c 69 73 74 20 69 6e 74  eates a list int
1270: 65 72 6e 61 6c 20 72 65 70 20 77 69 74 68 20 73  ernal rep with s
1280: 70 61 63 65 20 66 6f 72 20 6f 62 6a 63 20 65 6c  pace for objc el
1290: 65 6d 65 6e 74 73 2e 20 20 6f 62 6a 63 0a 20 2a  ements.  objc. *
12a0: 09 6d 75 73 74 20 62 65 20 3e 20 30 2e 20 20 49  .must be > 0.  I
12b0: 66 20 6f 62 6a 76 21 3d 4e 55 4c 4c 2c 20 69 6e  f objv!=NULL, in
12c0: 69 74 69 61 6c 69 7a 65 73 20 77 69 74 68 20 74  itializes with t
12d0: 68 65 20 66 69 72 73 74 20 6f 62 6a 63 20 76 61  he first objc va
12e0: 6c 75 65 73 0a 20 2a 09 69 6e 20 74 68 61 74 20  lues. *.in that 
12f0: 61 72 72 61 79 2e 20 20 49 66 20 6f 62 6a 76 3d  array.  If objv=
1300: 3d 4e 55 4c 4c 2c 20 69 6e 69 74 61 6c 69 7a 65  =NULL, initalize
1310: 20 6c 69 73 74 20 69 6e 74 65 72 6e 61 6c 20 72   list internal r
1320: 65 70 20 74 6f 20 68 61 76 65 0a 20 2a 09 30 20  ep to have. *.0 
1330: 65 6c 65 6d 65 6e 74 73 2c 20 77 69 74 68 20 73  elements, with s
1340: 70 61 63 65 20 74 6f 20 61 64 64 20 6f 62 6a 63  pace to add objc
1350: 20 6d 6f 72 65 2e 0a 20 2a 0a 20 2a 20 52 65 73   more.. *. * Res
1360: 75 6c 74 73 3a 0a 20 2a 09 41 20 6e 65 77 20 4c  ults:. *.A new L
1370: 69 73 74 20 73 74 72 75 63 74 20 77 69 74 68 20  ist struct with 
1380: 72 65 66 43 6f 75 6e 74 20 30 20 69 73 20 72 65  refCount 0 is re
1390: 74 75 72 6e 65 64 2e 20 49 66 20 73 6f 6d 65 20  turned. If some 
13a0: 66 61 69 6c 75 72 65 0a 20 2a 09 70 72 65 76 65  failure. *.preve
13b0: 6e 74 73 20 74 68 69 73 20 74 68 65 6e 20 4e 55  nts this then NU
13c0: 4c 4c 20 69 73 20 72 65 74 75 72 6e 65 64 2c 20  LL is returned, 
13d0: 61 6e 64 20 61 6e 20 65 72 72 6f 72 20 6d 65 73  and an error mes
13e0: 73 61 67 65 20 69 73 20 6c 65 66 74 0a 20 2a 09  sage is left. *.
13f0: 69 6e 20 74 68 65 20 69 6e 74 65 72 70 20 72 65  in the interp re
1400: 73 75 6c 74 2c 20 75 6e 6c 65 73 73 20 69 6e 74  sult, unless int
1410: 65 72 70 20 69 73 20 4e 55 4c 4c 2e 0a 20 2a 0a  erp is NULL.. *.
1420: 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a   * Side effects:
1430: 0a 20 2a 09 54 68 65 20 72 65 66 20 63 6f 75 6e  . *.The ref coun
1440: 74 73 20 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e  ts of the elemen
1450: 74 73 20 69 6e 20 6f 62 6a 76 20 61 72 65 20 69  ts in objv are i
1460: 6e 63 72 65 6d 65 6e 74 65 64 20 73 69 6e 63 65  ncremented since
1470: 20 74 68 65 0a 20 2a 09 72 65 73 75 6c 74 69 6e   the. *.resultin
1480: 67 20 6c 69 73 74 20 6e 6f 77 20 72 65 66 65 72  g list now refer
1490: 73 20 74 6f 20 74 68 65 6d 2e 0a 20 2a 0a 20 2a  s to them.. *. *
14a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14e0: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 61 74  ------. */..stat
14f0: 69 63 20 4c 69 73 74 20 2a 0a 41 74 74 65 6d 70  ic List *.Attemp
1500: 74 4e 65 77 4c 69 73 74 28 0a 20 20 20 20 54 63  tNewList(.    Tc
1510: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70  l_Interp *interp
1520: 2c 0a 20 20 20 20 69 6e 74 20 6f 62 6a 63 2c 0a  ,.    int objc,.
1530: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f 6e      Tcl_Obj *con
1540: 73 74 20 6f 62 6a 76 5b 5d 29 0a 7b 0a 20 20 20  st objv[]).{.   
1550: 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74   List *listRepPt
1560: 72 20 3d 20 4e 65 77 4c 69 73 74 49 6e 74 52 65  r = NewListIntRe
1570: 70 28 6f 62 6a 63 2c 20 6f 62 6a 76 2c 20 30 29  p(objc, objv, 0)
1580: 3b 0a 0a 20 20 20 20 69 66 20 28 69 6e 74 65 72  ;..    if (inter
1590: 70 20 21 3d 20 4e 55 4c 4c 20 26 26 20 6c 69 73  p != NULL && lis
15a0: 74 52 65 70 50 74 72 20 3d 3d 20 4e 55 4c 4c 29  tRepPtr == NULL)
15b0: 20 7b 0a 09 69 66 20 28 6f 62 6a 63 20 3e 20 4c   {..if (objc > L
15c0: 49 53 54 5f 4d 41 58 29 20 7b 0a 09 20 20 20 20  IST_MAX) {..    
15d0: 54 63 6c 5f 53 65 74 4f 62 6a 52 65 73 75 6c 74  Tcl_SetObjResult
15e0: 28 69 6e 74 65 72 70 2c 20 54 63 6c 5f 4f 62 6a  (interp, Tcl_Obj
15f0: 50 72 69 6e 74 66 28 0a 09 09 20 20 20 20 22 6d  Printf(...    "m
1600: 61 78 20 6c 65 6e 67 74 68 20 6f 66 20 61 20 54  ax length of a T
1610: 63 6c 20 6c 69 73 74 20 28 25 64 20 65 6c 65 6d  cl list (%d elem
1620: 65 6e 74 73 29 20 65 78 63 65 65 64 65 64 22 2c  ents) exceeded",
1630: 0a 09 09 20 20 20 20 4c 49 53 54 5f 4d 41 58 29  ...    LIST_MAX)
1640: 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20  );..} else {..  
1650: 20 20 54 63 6c 5f 53 65 74 4f 62 6a 52 65 73 75    Tcl_SetObjResu
1660: 6c 74 28 69 6e 74 65 72 70 2c 20 54 63 6c 5f 4f  lt(interp, Tcl_O
1670: 62 6a 50 72 69 6e 74 66 28 0a 09 09 20 20 20 20  bjPrintf(...    
1680: 22 6c 69 73 74 20 63 72 65 61 74 69 6f 6e 20 66  "list creation f
1690: 61 69 6c 65 64 3a 20 75 6e 61 62 6c 65 20 74 6f  ailed: unable to
16a0: 20 61 6c 6c 6f 63 20 25 75 20 62 79 74 65 73 22   alloc %u bytes"
16b0: 2c 0a 09 09 20 20 20 20 4c 49 53 54 5f 53 49 5a  ,...    LIST_SIZ
16c0: 45 28 6f 62 6a 63 29 29 29 3b 0a 09 7d 0a 09 54  E(objc)));..}..T
16d0: 63 6c 5f 53 65 74 45 72 72 6f 72 43 6f 64 65 28  cl_SetErrorCode(
16e0: 69 6e 74 65 72 70 2c 20 22 54 43 4c 22 2c 20 22  interp, "TCL", "
16f0: 4d 45 4d 4f 52 59 22 2c 20 4e 55 4c 4c 29 3b 0a  MEMORY", NULL);.
1700: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e      }.    return
1710: 20 6c 69 73 74 52 65 70 50 74 72 3b 0a 7d 0a 0c   listRepPtr;.}..
1720: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ./*. *----------
1730: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1740: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1750: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1760: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a  ------------. *.
1770: 20 2a 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62   * Tcl_NewListOb
1780: 6a 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20  j --. *. *.This 
1790: 66 75 6e 63 74 69 6f 6e 20 69 73 20 6e 6f 72 6d  function is norm
17a0: 61 6c 6c 79 20 63 61 6c 6c 65 64 20 77 68 65 6e  ally called when
17b0: 20 6e 6f 74 20 64 65 62 75 67 67 69 6e 67 3a 20   not debugging: 
17c0: 69 2e 65 2e 2c 20 77 68 65 6e 0a 20 2a 09 54 43  i.e., when. *.TC
17d0: 4c 5f 4d 45 4d 5f 44 45 42 55 47 20 69 73 20 6e  L_MEM_DEBUG is n
17e0: 6f 74 20 64 65 66 69 6e 65 64 2e 20 49 74 20 63  ot defined. It c
17f0: 72 65 61 74 65 73 20 61 20 6e 65 77 20 6c 69 73  reates a new lis
1800: 74 20 6f 62 6a 65 63 74 20 66 72 6f 6d 20 61 6e  t object from an
1810: 0a 20 2a 09 28 6f 62 6a 63 2c 6f 62 6a 76 29 20  . *.(objc,objv) 
1820: 61 72 72 61 79 3a 20 74 68 61 74 20 69 73 2c 20  array: that is, 
1830: 65 61 63 68 20 6f 66 20 74 68 65 20 6f 62 6a 63  each of the objc
1840: 20 65 6c 65 6d 65 6e 74 73 20 6f 66 20 74 68 65   elements of the
1850: 20 61 72 72 61 79 0a 20 2a 09 72 65 66 65 72 65   array. *.refere
1860: 6e 63 65 64 20 62 79 20 6f 62 6a 76 20 69 73 20  nced by objv is 
1870: 69 6e 73 65 72 74 65 64 20 61 73 20 61 6e 20 65  inserted as an e
1880: 6c 65 6d 65 6e 74 20 69 6e 74 6f 20 61 20 6e 65  lement into a ne
1890: 77 20 54 63 6c 20 6f 62 6a 65 63 74 2e 0a 20 2a  w Tcl object.. *
18a0: 0a 20 2a 09 57 68 65 6e 20 54 43 4c 5f 4d 45 4d  . *.When TCL_MEM
18b0: 5f 44 45 42 55 47 20 69 73 20 64 65 66 69 6e 65  _DEBUG is define
18c0: 64 2c 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e  d, this function
18d0: 20 6a 75 73 74 20 72 65 74 75 72 6e 73 20 74 68   just returns th
18e0: 65 20 72 65 73 75 6c 74 0a 20 2a 09 6f 66 20 63  e result. *.of c
18f0: 61 6c 6c 69 6e 67 20 74 68 65 20 64 65 62 75 67  alling the debug
1900: 67 69 6e 67 20 76 65 72 73 69 6f 6e 20 54 63 6c  ging version Tcl
1910: 5f 44 62 4e 65 77 4c 69 73 74 4f 62 6a 2e 0a 20  _DbNewListObj.. 
1920: 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a  *. * Results:. *
1930: 09 41 20 6e 65 77 20 6c 69 73 74 20 6f 62 6a 65  .A new list obje
1940: 63 74 20 69 73 20 72 65 74 75 72 6e 65 64 20 74  ct is returned t
1950: 68 61 74 20 69 73 20 69 6e 69 74 69 61 6c 69 7a  hat is initializ
1960: 65 64 20 66 72 6f 6d 20 74 68 65 20 6f 62 6a 65  ed from the obje
1970: 63 74 0a 20 2a 09 70 6f 69 6e 74 65 72 73 20 69  ct. *.pointers i
1980: 6e 20 6f 62 6a 76 2e 20 49 66 20 6f 62 6a 63 20  n objv. If objc 
1990: 69 73 20 6c 65 73 73 20 74 68 61 6e 20 6f 72 20  is less than or 
19a0: 65 71 75 61 6c 20 74 6f 20 7a 65 72 6f 2c 20 61  equal to zero, a
19b0: 6e 20 65 6d 70 74 79 0a 20 2a 09 6f 62 6a 65 63  n empty. *.objec
19c0: 74 20 69 73 20 72 65 74 75 72 6e 65 64 2e 20 54  t is returned. T
19d0: 68 65 20 6e 65 77 20 6f 62 6a 65 63 74 27 73 20  he new object's 
19e0: 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74  string represent
19f0: 61 74 69 6f 6e 20 69 73 20 6c 65 66 74 0a 20 2a  ation is left. *
1a00: 09 4e 55 4c 4c 2e 20 54 68 65 20 72 65 73 75 6c  .NULL. The resul
1a10: 74 69 6e 67 20 6e 65 77 20 6c 69 73 74 20 6f 62  ting new list ob
1a20: 6a 65 63 74 20 68 61 73 20 72 65 66 20 63 6f 75  ject has ref cou
1a30: 6e 74 20 30 2e 0a 20 2a 0a 20 2a 20 53 69 64 65  nt 0.. *. * Side
1a40: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65   effects:. *.The
1a50: 20 72 65 66 20 63 6f 75 6e 74 73 20 6f 66 20 74   ref counts of t
1a60: 68 65 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 6f  he elements in o
1a70: 62 6a 76 20 61 72 65 20 69 6e 63 72 65 6d 65 6e  bjv are incremen
1a80: 74 65 64 20 73 69 6e 63 65 20 74 68 65 0a 20 2a  ted since the. *
1a90: 09 72 65 73 75 6c 74 69 6e 67 20 6c 69 73 74 20  .resulting list 
1aa0: 6e 6f 77 20 72 65 66 65 72 73 20 74 6f 20 74 68  now refers to th
1ab0: 65 6d 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d  em.. *. *-------
1ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1b00: 20 2a 2f 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f   */..#ifdef TCL_
1b10: 4d 45 4d 5f 44 45 42 55 47 0a 23 75 6e 64 65 66  MEM_DEBUG.#undef
1b20: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 0a   Tcl_NewListObj.
1b30: 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 5f 4e  .Tcl_Obj *.Tcl_N
1b40: 65 77 4c 69 73 74 4f 62 6a 28 0a 20 20 20 20 69  ewListObj(.    i
1b50: 6e 74 20 6f 62 6a 63 2c 09 09 09 2f 2a 20 43 6f  nt objc,.../* Co
1b60: 75 6e 74 20 6f 66 20 6f 62 6a 65 63 74 73 20 72  unt of objects r
1b70: 65 66 65 72 65 6e 63 65 64 20 62 79 20 6f 62 6a  eferenced by obj
1b80: 76 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62  v. */.    Tcl_Ob
1b90: 6a 20 2a 63 6f 6e 73 74 20 6f 62 6a 76 5b 5d 29  j *const objv[])
1ba0: 09 2f 2a 20 41 6e 20 61 72 72 61 79 20 6f 66 20  ./* An array of 
1bb0: 70 6f 69 6e 74 65 72 73 20 74 6f 20 54 63 6c 20  pointers to Tcl 
1bc0: 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a 7b 0a 20 20  objects. */.{.  
1bd0: 20 20 72 65 74 75 72 6e 20 54 63 6c 5f 44 62 4e    return Tcl_DbN
1be0: 65 77 4c 69 73 74 4f 62 6a 28 6f 62 6a 63 2c 20  ewListObj(objc, 
1bf0: 6f 62 6a 76 2c 20 22 75 6e 6b 6e 6f 77 6e 22 2c  objv, "unknown",
1c00: 20 30 29 3b 0a 7d 0a 0a 23 65 6c 73 65 20 2f 2a   0);.}..#else /*
1c10: 20 69 66 20 6e 6f 74 20 54 43 4c 5f 4d 45 4d 5f   if not TCL_MEM_
1c20: 44 45 42 55 47 20 2a 2f 0a 0a 54 63 6c 5f 4f 62  DEBUG */..Tcl_Ob
1c30: 6a 20 2a 0a 54 63 6c 5f 4e 65 77 4c 69 73 74 4f  j *.Tcl_NewListO
1c40: 62 6a 28 0a 20 20 20 20 69 6e 74 20 6f 62 6a 63  bj(.    int objc
1c50: 2c 09 09 09 2f 2a 20 43 6f 75 6e 74 20 6f 66 20  ,.../* Count of 
1c60: 6f 62 6a 65 63 74 73 20 72 65 66 65 72 65 6e 63  objects referenc
1c70: 65 64 20 62 79 20 6f 62 6a 76 2e 20 2a 2f 0a 20  ed by objv. */. 
1c80: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f 6e 73     Tcl_Obj *cons
1c90: 74 20 6f 62 6a 76 5b 5d 29 09 2f 2a 20 41 6e 20  t objv[])./* An 
1ca0: 61 72 72 61 79 20 6f 66 20 70 6f 69 6e 74 65 72  array of pointer
1cb0: 73 20 74 6f 20 54 63 6c 20 6f 62 6a 65 63 74 73  s to Tcl objects
1cc0: 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c 69 73 74 20  . */.{.    List 
1cd0: 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a 20 20 20  *listRepPtr;.   
1ce0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74   Tcl_Obj *listPt
1cf0: 72 3b 0a 0a 20 20 20 20 54 63 6c 4e 65 77 4f 62  r;..    TclNewOb
1d00: 6a 28 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 20  j(listPtr);..   
1d10: 20 69 66 20 28 6f 62 6a 63 20 3c 3d 20 30 29 20   if (objc <= 0) 
1d20: 7b 0a 09 72 65 74 75 72 6e 20 6c 69 73 74 50 74  {..return listPt
1d30: 72 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  r;.    }..    /*
1d40: 0a 20 20 20 20 20 2a 20 43 72 65 61 74 65 20 74  .     * Create t
1d50: 68 65 20 69 6e 74 65 72 6e 61 6c 20 72 65 70 2e  he internal rep.
1d60: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 6c 69  .     */..    li
1d70: 73 74 52 65 70 50 74 72 20 3d 20 4e 65 77 4c 69  stRepPtr = NewLi
1d80: 73 74 49 6e 74 52 65 70 28 6f 62 6a 63 2c 20 6f  stIntRep(objc, o
1d90: 62 6a 76 2c 20 31 29 3b 0a 0a 20 20 20 20 2f 2a  bjv, 1);..    /*
1da0: 0a 20 20 20 20 20 2a 20 4e 6f 77 20 63 72 65 61  .     * Now crea
1db0: 74 65 20 74 68 65 20 6f 62 6a 65 63 74 2e 0a 20  te the object.. 
1dc0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 54 63 6c 49      */..    TclI
1dd0: 6e 76 61 6c 69 64 61 74 65 53 74 72 69 6e 67 52  nvalidateStringR
1de0: 65 70 28 6c 69 73 74 50 74 72 29 3b 0a 20 20 20  ep(listPtr);.   
1df0: 20 4c 69 73 74 53 65 74 49 6e 74 52 65 70 28 6c   ListSetIntRep(l
1e00: 69 73 74 50 74 72 2c 20 6c 69 73 74 52 65 70 50  istPtr, listRepP
1e10: 74 72 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20  tr);.    return 
1e20: 6c 69 73 74 50 74 72 3b 0a 7d 0a 23 65 6e 64 69  listPtr;.}.#endi
1e30: 66 20 2f 2a 20 69 66 20 54 43 4c 5f 4d 45 4d 5f  f /* if TCL_MEM_
1e40: 44 45 42 55 47 20 2a 2f 0a 0c 0a 2f 2a 0a 20 2a  DEBUG */.../*. *
1e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e90: 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c  ------. *. * Tcl
1ea0: 5f 44 62 4e 65 77 4c 69 73 74 4f 62 6a 20 2d 2d  _DbNewListObj --
1eb0: 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66 75 6e 63  . *. *.This func
1ec0: 74 69 6f 6e 20 69 73 20 6e 6f 72 6d 61 6c 6c 79  tion is normally
1ed0: 20 63 61 6c 6c 65 64 20 77 68 65 6e 20 64 65 62   called when deb
1ee0: 75 67 67 69 6e 67 3a 20 69 2e 65 2e 2c 20 77 68  ugging: i.e., wh
1ef0: 65 6e 0a 20 2a 09 54 43 4c 5f 4d 45 4d 5f 44 45  en. *.TCL_MEM_DE
1f00: 42 55 47 20 69 73 20 64 65 66 69 6e 65 64 2e 20  BUG is defined. 
1f10: 49 74 20 63 72 65 61 74 65 73 20 6e 65 77 20 6c  It creates new l
1f20: 69 73 74 20 6f 62 6a 65 63 74 73 2e 20 49 74 20  ist objects. It 
1f30: 69 73 20 74 68 65 20 73 61 6d 65 0a 20 2a 09 61  is the same. *.a
1f40: 73 20 74 68 65 20 54 63 6c 5f 4e 65 77 4c 69 73  s the Tcl_NewLis
1f50: 74 4f 62 6a 20 66 75 6e 63 74 69 6f 6e 20 61 62  tObj function ab
1f60: 6f 76 65 20 65 78 63 65 70 74 20 74 68 61 74 20  ove except that 
1f70: 69 74 20 63 61 6c 6c 73 0a 20 2a 09 54 63 6c 5f  it calls. *.Tcl_
1f80: 44 62 43 6b 61 6c 6c 6f 63 20 64 69 72 65 63 74  DbCkalloc direct
1f90: 6c 79 20 77 69 74 68 20 74 68 65 20 66 69 6c 65  ly with the file
1fa0: 20 6e 61 6d 65 20 61 6e 64 20 6c 69 6e 65 20 6e   name and line n
1fb0: 75 6d 62 65 72 20 66 72 6f 6d 20 69 74 73 0a 20  umber from its. 
1fc0: 2a 09 63 61 6c 6c 65 72 2e 20 54 68 69 73 20 73  *.caller. This s
1fd0: 69 6d 70 6c 69 66 69 65 73 20 64 65 62 75 67 67  implifies debugg
1fe0: 69 6e 67 20 73 69 6e 63 65 20 74 68 65 6e 20 74  ing since then t
1ff0: 68 65 20 5b 6d 65 6d 6f 72 79 20 61 63 74 69 76  he [memory activ
2000: 65 5d 0a 20 2a 09 63 6f 6d 6d 61 6e 64 20 77 69  e]. *.command wi
2010: 6c 6c 20 72 65 70 6f 72 74 20 74 68 65 20 63 6f  ll report the co
2020: 72 72 65 63 74 20 66 69 6c 65 20 6e 61 6d 65 20  rrect file name 
2030: 61 6e 64 20 6c 69 6e 65 20 6e 75 6d 62 65 72 20  and line number 
2040: 77 68 65 6e 0a 20 2a 09 72 65 70 6f 72 74 69 6e  when. *.reportin
2050: 67 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 68  g objects that h
2060: 61 76 65 6e 27 74 20 62 65 65 6e 20 66 72 65 65  aven't been free
2070: 64 2e 0a 20 2a 0a 20 2a 09 57 68 65 6e 20 54 43  d.. *. *.When TC
2080: 4c 5f 4d 45 4d 5f 44 45 42 55 47 20 69 73 20 6e  L_MEM_DEBUG is n
2090: 6f 74 20 64 65 66 69 6e 65 64 2c 20 74 68 69 73  ot defined, this
20a0: 20 66 75 6e 63 74 69 6f 6e 20 6a 75 73 74 20 72   function just r
20b0: 65 74 75 72 6e 73 20 74 68 65 0a 20 2a 09 72 65  eturns the. *.re
20c0: 73 75 6c 74 20 6f 66 20 63 61 6c 6c 69 6e 67 20  sult of calling 
20d0: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 2e 0a  Tcl_NewListObj..
20e0: 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20   *. * Results:. 
20f0: 2a 09 41 20 6e 65 77 20 6c 69 73 74 20 6f 62 6a  *.A new list obj
2100: 65 63 74 20 69 73 20 72 65 74 75 72 6e 65 64 20  ect is returned 
2110: 74 68 61 74 20 69 73 20 69 6e 69 74 69 61 6c 69  that is initiali
2120: 7a 65 64 20 66 72 6f 6d 20 74 68 65 20 6f 62 6a  zed from the obj
2130: 65 63 74 0a 20 2a 09 70 6f 69 6e 74 65 72 73 20  ect. *.pointers 
2140: 69 6e 20 6f 62 6a 76 2e 20 49 66 20 6f 62 6a 63  in objv. If objc
2150: 20 69 73 20 6c 65 73 73 20 74 68 61 6e 20 6f 72   is less than or
2160: 20 65 71 75 61 6c 20 74 6f 20 7a 65 72 6f 2c 20   equal to zero, 
2170: 61 6e 20 65 6d 70 74 79 0a 20 2a 09 6f 62 6a 65  an empty. *.obje
2180: 63 74 20 69 73 20 72 65 74 75 72 6e 65 64 2e 20  ct is returned. 
2190: 54 68 65 20 6e 65 77 20 6f 62 6a 65 63 74 27 73  The new object's
21a0: 20 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e   string represen
21b0: 74 61 74 69 6f 6e 20 69 73 20 6c 65 66 74 0a 20  tation is left. 
21c0: 2a 09 4e 55 4c 4c 2e 20 54 68 65 20 6e 65 77 20  *.NULL. The new 
21d0: 6c 69 73 74 20 6f 62 6a 65 63 74 20 68 61 73 20  list object has 
21e0: 72 65 66 20 63 6f 75 6e 74 20 30 2e 0a 20 2a 0a  ref count 0.. *.
21f0: 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a   * Side effects:
2200: 0a 20 2a 09 54 68 65 20 72 65 66 20 63 6f 75 6e  . *.The ref coun
2210: 74 73 20 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e  ts of the elemen
2220: 74 73 20 69 6e 20 6f 62 6a 76 20 61 72 65 20 69  ts in objv are i
2230: 6e 63 72 65 6d 65 6e 74 65 64 20 73 69 6e 63 65  ncremented since
2240: 20 74 68 65 0a 20 2a 09 72 65 73 75 6c 74 69 6e   the. *.resultin
2250: 67 20 6c 69 73 74 20 6e 6f 77 20 72 65 66 65 72  g list now refer
2260: 73 20 74 6f 20 74 68 65 6d 2e 0a 20 2a 0a 20 2a  s to them.. *. *
2270: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2280: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2290: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22b0: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 23 69 66 64  ------. */..#ifd
22c0: 65 66 20 54 43 4c 5f 4d 45 4d 5f 44 45 42 55 47  ef TCL_MEM_DEBUG
22d0: 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 5f  ..Tcl_Obj *.Tcl_
22e0: 44 62 4e 65 77 4c 69 73 74 4f 62 6a 28 0a 20 20  DbNewListObj(.  
22f0: 20 20 69 6e 74 20 6f 62 6a 63 2c 09 09 09 2f 2a    int objc,.../*
2300: 20 43 6f 75 6e 74 20 6f 66 20 6f 62 6a 65 63 74   Count of object
2310: 73 20 72 65 66 65 72 65 6e 63 65 64 20 62 79 20  s referenced by 
2320: 6f 62 6a 76 2e 20 2a 2f 0a 20 20 20 20 54 63 6c  objv. */.    Tcl
2330: 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20 6f 62 6a 76  _Obj *const objv
2340: 5b 5d 2c 09 2f 2a 20 41 6e 20 61 72 72 61 79 20  [],./* An array 
2350: 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 54  of pointers to T
2360: 63 6c 20 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a 20  cl objects. */. 
2370: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66     const char *f
2380: 69 6c 65 2c 09 09 2f 2a 20 54 68 65 20 6e 61 6d  ile,../* The nam
2390: 65 20 6f 66 20 74 68 65 20 73 6f 75 72 63 65 20  e of the source 
23a0: 66 69 6c 65 20 63 61 6c 6c 69 6e 67 20 74 68 69  file calling thi
23b0: 73 0a 09 09 09 09 20 2a 20 66 75 6e 63 74 69 6f  s..... * functio
23c0: 6e 3b 20 75 73 65 64 20 66 6f 72 20 64 65 62 75  n; used for debu
23d0: 67 67 69 6e 67 2e 20 2a 2f 0a 20 20 20 20 69 6e  gging. */.    in
23e0: 74 20 6c 69 6e 65 29 09 09 09 2f 2a 20 4c 69 6e  t line).../* Lin
23f0: 65 20 6e 75 6d 62 65 72 20 69 6e 20 74 68 65 20  e number in the 
2400: 73 6f 75 72 63 65 20 66 69 6c 65 3b 20 75 73 65  source file; use
2410: 64 20 66 6f 72 0a 09 09 09 09 20 2a 20 64 65 62  d for..... * deb
2420: 75 67 67 69 6e 67 2e 20 2a 2f 0a 7b 0a 20 20 20  ugging. */.{.   
2430: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74   Tcl_Obj *listPt
2440: 72 3b 0a 20 20 20 20 4c 69 73 74 20 2a 6c 69 73  r;.    List *lis
2450: 74 52 65 70 50 74 72 3b 0a 0a 20 20 20 20 54 63  tRepPtr;..    Tc
2460: 6c 44 62 4e 65 77 4f 62 6a 28 6c 69 73 74 50 74  lDbNewObj(listPt
2470: 72 2c 20 66 69 6c 65 2c 20 6c 69 6e 65 29 3b 0a  r, file, line);.
2480: 0a 20 20 20 20 69 66 20 28 6f 62 6a 63 20 3c 3d  .    if (objc <=
2490: 20 30 29 20 7b 0a 09 72 65 74 75 72 6e 20 6c 69   0) {..return li
24a0: 73 74 50 74 72 3b 0a 20 20 20 20 7d 0a 0a 20 20  stPtr;.    }..  
24b0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 72 65 61    /*.     * Crea
24c0: 74 65 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20  te the internal 
24d0: 72 65 70 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  rep..     */..  
24e0: 20 20 6c 69 73 74 52 65 70 50 74 72 20 3d 20 4e    listRepPtr = N
24f0: 65 77 4c 69 73 74 49 6e 74 52 65 70 28 6f 62 6a  ewListIntRep(obj
2500: 63 2c 20 6f 62 6a 76 2c 20 31 29 3b 0a 0a 20 20  c, objv, 1);..  
2510: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4e 6f 77 20    /*.     * Now 
2520: 63 72 65 61 74 65 20 74 68 65 20 6f 62 6a 65 63  create the objec
2530: 74 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20  t..     */..    
2540: 54 63 6c 49 6e 76 61 6c 69 64 61 74 65 53 74 72  TclInvalidateStr
2550: 69 6e 67 52 65 70 28 6c 69 73 74 50 74 72 29 3b  ingRep(listPtr);
2560: 0a 20 20 20 20 4c 69 73 74 53 65 74 49 6e 74 52  .    ListSetIntR
2570: 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74  ep(listPtr, list
2580: 52 65 70 50 74 72 29 3b 0a 0a 20 20 20 20 72 65  RepPtr);..    re
2590: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a  turn listPtr;.}.
25a0: 0a 23 65 6c 73 65 20 2f 2a 20 69 66 20 6e 6f 74  .#else /* if not
25b0: 20 54 43 4c 5f 4d 45 4d 5f 44 45 42 55 47 20 2a   TCL_MEM_DEBUG *
25c0: 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c  /..Tcl_Obj *.Tcl
25d0: 5f 44 62 4e 65 77 4c 69 73 74 4f 62 6a 28 0a 20  _DbNewListObj(. 
25e0: 20 20 20 69 6e 74 20 6f 62 6a 63 2c 09 09 09 2f     int objc,.../
25f0: 2a 20 43 6f 75 6e 74 20 6f 66 20 6f 62 6a 65 63  * Count of objec
2600: 74 73 20 72 65 66 65 72 65 6e 63 65 64 20 62 79  ts referenced by
2610: 20 6f 62 6a 76 2e 20 2a 2f 0a 20 20 20 20 54 63   objv. */.    Tc
2620: 6c 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20 6f 62 6a  l_Obj *const obj
2630: 76 5b 5d 2c 09 2f 2a 20 41 6e 20 61 72 72 61 79  v[],./* An array
2640: 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f 20   of pointers to 
2650: 54 63 6c 20 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a  Tcl objects. */.
2660: 20 20 20 20 54 43 4c 5f 55 4e 55 53 45 44 28 63      TCL_UNUSED(c
2670: 6f 6e 73 74 20 63 68 61 72 20 2a 29 20 2f 2a 66  onst char *) /*f
2680: 69 6c 65 2a 2f 2c 0a 20 20 20 20 54 43 4c 5f 55  ile*/,.    TCL_U
2690: 4e 55 53 45 44 28 69 6e 74 29 20 2f 2a 6c 69 6e  NUSED(int) /*lin
26a0: 65 2a 2f 29 0a 7b 0a 20 20 20 20 72 65 74 75 72  e*/).{.    retur
26b0: 6e 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  n Tcl_NewListObj
26c0: 28 6f 62 6a 63 2c 20 6f 62 6a 76 29 3b 0a 7d 0a  (objc, objv);.}.
26d0: 23 65 6e 64 69 66 20 2f 2a 20 54 43 4c 5f 4d 45  #endif /* TCL_ME
26e0: 4d 5f 44 45 42 55 47 20 2a 2f 0a 0c 0a 2f 2a 0a  M_DEBUG */.../*.
26f0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
2700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2710: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2720: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2730: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54  --------. *. * T
2740: 63 6c 5f 53 65 74 4c 69 73 74 4f 62 6a 20 2d 2d  cl_SetListObj --
2750: 0a 20 2a 0a 20 2a 09 4d 6f 64 69 66 79 20 61 6e  . *. *.Modify an
2760: 20 6f 62 6a 65 63 74 20 74 6f 20 62 65 20 61 20   object to be a 
2770: 6c 69 73 74 20 63 6f 6e 74 61 69 6e 69 6e 67 20  list containing 
2780: 65 61 63 68 20 6f 66 20 74 68 65 20 6f 62 6a 63  each of the objc
2790: 20 65 6c 65 6d 65 6e 74 73 20 6f 66 0a 20 2a 09   elements of. *.
27a0: 74 68 65 20 6f 62 6a 65 63 74 20 61 72 72 61 79  the object array
27b0: 20 72 65 66 65 72 65 6e 63 65 64 20 62 79 20 6f   referenced by o
27c0: 62 6a 76 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c  bjv.. *. * Resul
27d0: 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a  ts:. *.None.. *.
27e0: 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a   * Side effects:
27f0: 0a 20 2a 09 54 68 65 20 6f 62 6a 65 63 74 20 69  . *.The object i
2800: 73 20 6d 61 64 65 20 61 20 6c 69 73 74 20 6f 62  s made a list ob
2810: 6a 65 63 74 20 61 6e 64 20 69 73 20 69 6e 69 74  ject and is init
2820: 69 61 6c 69 7a 65 64 20 66 72 6f 6d 20 74 68 65  ialized from the
2830: 20 6f 62 6a 65 63 74 0a 20 2a 09 70 6f 69 6e 74   object. *.point
2840: 65 72 73 20 69 6e 20 6f 62 6a 76 2e 20 49 66 20  ers in objv. If 
2850: 6f 62 6a 63 20 69 73 20 6c 65 73 73 20 74 68 61  objc is less tha
2860: 6e 20 6f 72 20 65 71 75 61 6c 20 74 6f 20 7a 65  n or equal to ze
2870: 72 6f 2c 20 61 6e 20 65 6d 70 74 79 0a 20 2a 09  ro, an empty. *.
2880: 6f 62 6a 65 63 74 20 69 73 20 72 65 74 75 72 6e  object is return
2890: 65 64 2e 20 54 68 65 20 6e 65 77 20 6f 62 6a 65  ed. The new obje
28a0: 63 74 27 73 20 73 74 72 69 6e 67 20 72 65 70 72  ct's string repr
28b0: 65 73 65 6e 74 61 74 69 6f 6e 20 69 73 20 6c 65  esentation is le
28c0: 66 74 0a 20 2a 09 4e 55 4c 4c 2e 20 54 68 65 20  ft. *.NULL. The 
28d0: 72 65 66 20 63 6f 75 6e 74 73 20 6f 66 20 74 68  ref counts of th
28e0: 65 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 6f 62  e elements in ob
28f0: 6a 76 20 61 72 65 20 69 6e 63 72 65 6d 65 6e 74  jv are increment
2900: 65 64 20 73 69 6e 63 65 20 74 68 65 0a 20 2a 09  ed since the. *.
2910: 6c 69 73 74 20 6e 6f 77 20 72 65 66 65 72 73 20  list now refers 
2920: 74 6f 20 74 68 65 6d 2e 20 54 68 65 20 6f 62 6a  to them. The obj
2930: 65 63 74 27 73 20 6f 6c 64 20 73 74 72 69 6e 67  ect's old string
2940: 20 61 6e 64 20 69 6e 74 65 72 6e 61 6c 0a 20 2a   and internal. *
2950: 09 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 73  .representations
2960: 20 61 72 65 20 66 72 65 65 64 20 61 6e 64 20 69   are freed and i
2970: 74 73 20 74 79 70 65 20 69 73 20 73 65 74 20 4e  ts type is set N
2980: 55 4c 4c 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d  ULL.. *. *------
2990: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
29a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
29b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
29c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
29d0: 0a 20 2a 2f 0a 0a 76 6f 69 64 0a 54 63 6c 5f 53  . */..void.Tcl_S
29e0: 65 74 4c 69 73 74 4f 62 6a 28 0a 20 20 20 20 54  etListObj(.    T
29f0: 63 6c 5f 4f 62 6a 20 2a 6f 62 6a 50 74 72 2c 09  cl_Obj *objPtr,.
2a00: 09 2f 2a 20 4f 62 6a 65 63 74 20 77 68 6f 73 65  ./* Object whose
2a10: 20 69 6e 74 65 72 6e 61 6c 20 72 65 70 20 74 6f   internal rep to
2a20: 20 69 6e 69 74 2e 20 2a 2f 0a 20 20 20 20 69 6e   init. */.    in
2a30: 74 20 6f 62 6a 63 2c 09 09 09 2f 2a 20 43 6f 75  t objc,.../* Cou
2a40: 6e 74 20 6f 66 20 6f 62 6a 65 63 74 73 20 72 65  nt of objects re
2a50: 66 65 72 65 6e 63 65 64 20 62 79 20 6f 62 6a 76  ferenced by objv
2a60: 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a  . */.    Tcl_Obj
2a70: 20 2a 63 6f 6e 73 74 20 6f 62 6a 76 5b 5d 29 09   *const objv[]).
2a80: 2f 2a 20 41 6e 20 61 72 72 61 79 20 6f 66 20 70  /* An array of p
2a90: 6f 69 6e 74 65 72 73 20 74 6f 20 54 63 6c 20 6f  ointers to Tcl o
2aa0: 62 6a 65 63 74 73 2e 20 2a 2f 0a 7b 0a 20 20 20  bjects. */.{.   
2ab0: 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74   List *listRepPt
2ac0: 72 3b 0a 0a 20 20 20 20 69 66 20 28 54 63 6c 5f  r;..    if (Tcl_
2ad0: 49 73 53 68 61 72 65 64 28 6f 62 6a 50 74 72 29  IsShared(objPtr)
2ae0: 29 20 7b 0a 09 54 63 6c 5f 50 61 6e 69 63 28 22  ) {..Tcl_Panic("
2af0: 25 73 20 63 61 6c 6c 65 64 20 77 69 74 68 20 73  %s called with s
2b00: 68 61 72 65 64 20 6f 62 6a 65 63 74 22 2c 20 22  hared object", "
2b10: 54 63 6c 5f 53 65 74 4c 69 73 74 4f 62 6a 22 29  Tcl_SetListObj")
2b20: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a  ;.    }..    /*.
2b30: 20 20 20 20 20 2a 20 46 72 65 65 20 61 6e 79 20       * Free any 
2b40: 6f 6c 64 20 73 74 72 69 6e 67 20 72 65 70 20 61  old string rep a
2b50: 6e 64 20 61 6e 79 20 69 6e 74 65 72 6e 61 6c 20  nd any internal 
2b60: 72 65 70 20 66 6f 72 20 74 68 65 20 6f 6c 64 20  rep for the old 
2b70: 74 79 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20  type..     */.. 
2b80: 20 20 20 54 63 6c 46 72 65 65 49 6e 74 52 65 70     TclFreeIntRep
2b90: 28 6f 62 6a 50 74 72 29 3b 0a 20 20 20 20 54 63  (objPtr);.    Tc
2ba0: 6c 49 6e 76 61 6c 69 64 61 74 65 53 74 72 69 6e  lInvalidateStrin
2bb0: 67 52 65 70 28 6f 62 6a 50 74 72 29 3b 0a 0a 20  gRep(objPtr);.. 
2bc0: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 53 65 74     /*.     * Set
2bd0: 20 74 68 65 20 6f 62 6a 65 63 74 27 73 20 74 79   the object's ty
2be0: 70 65 20 74 6f 20 22 6c 69 73 74 22 20 61 6e 64  pe to "list" and
2bf0: 20 69 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20   initialize the 
2c00: 69 6e 74 65 72 6e 61 6c 20 72 65 70 2e 0a 20 20  internal rep..  
2c10: 20 20 20 2a 20 48 6f 77 65 76 65 72 2c 20 69 66     * However, if
2c20: 20 74 68 65 72 65 20 61 72 65 20 6e 6f 20 65 6c   there are no el
2c30: 65 6d 65 6e 74 73 20 74 6f 20 70 75 74 20 69 6e  ements to put in
2c40: 20 74 68 65 20 6c 69 73 74 2c 20 6a 75 73 74 20   the list, just 
2c50: 67 69 76 65 20 74 68 65 0a 20 20 20 20 20 2a 20  give the.     * 
2c60: 6f 62 6a 65 63 74 20 61 6e 20 65 6d 70 74 79 20  object an empty 
2c70: 73 74 72 69 6e 67 20 72 65 70 20 61 6e 64 20 61  string rep and a
2c80: 20 4e 55 4c 4c 20 74 79 70 65 2e 0a 20 20 20 20   NULL type..    
2c90: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 6f 62 6a   */..    if (obj
2ca0: 63 20 3e 20 30 29 20 7b 0a 09 6c 69 73 74 52 65  c > 0) {..listRe
2cb0: 70 50 74 72 20 3d 20 4e 65 77 4c 69 73 74 49 6e  pPtr = NewListIn
2cc0: 74 52 65 70 28 6f 62 6a 63 2c 20 6f 62 6a 76 2c  tRep(objc, objv,
2cd0: 20 31 29 3b 0a 09 4c 69 73 74 53 65 74 49 6e 74   1);..ListSetInt
2ce0: 52 65 70 28 6f 62 6a 50 74 72 2c 20 6c 69 73 74  Rep(objPtr, list
2cf0: 52 65 70 50 74 72 29 3b 0a 20 20 20 20 7d 20 65  RepPtr);.    } e
2d00: 6c 73 65 20 7b 0a 09 54 63 6c 5f 49 6e 69 74 53  lse {..Tcl_InitS
2d10: 74 72 69 6e 67 52 65 70 28 6f 62 6a 50 74 72 2c  tringRep(objPtr,
2d20: 20 4e 55 4c 4c 2c 20 30 29 3b 0a 20 20 20 20 7d   NULL, 0);.    }
2d30: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d  .}.../*. *------
2d40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d80: 0a 20 2a 0a 20 2a 20 54 63 6c 4c 69 73 74 4f 62  . *. * TclListOb
2d90: 6a 43 6f 70 79 20 2d 2d 0a 20 2a 0a 20 2a 09 4d  jCopy --. *. *.M
2da0: 61 6b 65 73 20 61 20 22 70 75 72 65 20 6c 69 73  akes a "pure lis
2db0: 74 22 20 63 6f 70 79 20 6f 66 20 61 20 6c 69 73  t" copy of a lis
2dc0: 74 20 76 61 6c 75 65 2e 20 54 68 69 73 20 70 72  t value. This pr
2dd0: 6f 76 69 64 65 73 20 66 6f 72 20 74 68 65 20 43  ovides for the C
2de0: 0a 20 2a 09 6c 65 76 65 6c 20 61 20 63 6f 75 6e  . *.level a coun
2df0: 74 65 72 70 61 72 74 20 6f 66 20 74 68 65 20 5b  terpart of the [
2e00: 6c 72 61 6e 67 65 20 24 6c 69 73 74 20 30 20 65  lrange $list 0 e
2e10: 6e 64 5d 20 63 6f 6d 6d 61 6e 64 2c 20 77 68 69  nd] command, whi
2e20: 6c 65 20 75 73 69 6e 67 0a 20 2a 09 69 6e 74 65  le using. *.inte
2e30: 72 6e 61 6c 73 20 64 65 74 61 69 6c 73 20 74 6f  rnals details to
2e40: 20 62 65 20 61 73 20 65 66 66 69 63 69 65 6e 74   be as efficient
2e50: 20 61 73 20 70 6f 73 73 69 62 6c 65 2e 0a 20 2a   as possible.. *
2e60: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09  . * Results:. *.
2e70: 4e 6f 72 6d 61 6c 6c 79 20 72 65 74 75 72 6e 73  Normally returns
2e80: 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 20   a pointer to a 
2e90: 6e 65 77 20 54 63 6c 5f 4f 62 6a 2c 20 74 68 61  new Tcl_Obj, tha
2ea0: 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 73  t contains the s
2eb0: 61 6d 65 0a 20 2a 09 6c 69 73 74 20 76 61 6c 75  ame. *.list valu
2ec0: 65 20 61 73 20 2a 6c 69 73 74 50 74 72 20 64 6f  e as *listPtr do
2ed0: 65 73 2e 20 54 68 65 20 72 65 74 75 72 6e 65 64  es. The returned
2ee0: 20 54 63 6c 5f 4f 62 6a 20 68 61 73 20 61 20 72   Tcl_Obj has a r
2ef0: 65 66 43 6f 75 6e 74 20 6f 66 0a 20 2a 09 7a 65  efCount of. *.ze
2f00: 72 6f 2e 20 49 66 20 2a 6c 69 73 74 50 74 72 20  ro. If *listPtr 
2f10: 64 6f 65 73 20 6e 6f 74 20 68 6f 6c 64 20 61 20  does not hold a 
2f20: 6c 69 73 74 2c 20 4e 55 4c 4c 20 69 73 20 72 65  list, NULL is re
2f30: 74 75 72 6e 65 64 2c 20 61 6e 64 20 69 66 0a 20  turned, and if. 
2f40: 2a 09 69 6e 74 65 72 70 20 69 73 20 6e 6f 6e 2d  *.interp is non-
2f50: 4e 55 4c 4c 2c 20 61 6e 20 65 72 72 6f 72 20 6d  NULL, an error m
2f60: 65 73 73 61 67 65 20 69 73 20 72 65 63 6f 72 64  essage is record
2f70: 65 64 20 74 68 65 72 65 2e 0a 20 2a 0a 20 2a 20  ed there.. *. * 
2f80: 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a  Side effects:. *
2f90: 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d  .None.. *. *----
2fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fe0: 2d 2d 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20  --. */..Tcl_Obj 
2ff0: 2a 0a 54 63 6c 4c 69 73 74 4f 62 6a 43 6f 70 79  *.TclListObjCopy
3000: 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65 72 70  (.    Tcl_Interp
3010: 20 2a 69 6e 74 65 72 70 2c 09 09 2f 2a 20 55 73   *interp,../* Us
3020: 65 64 20 74 6f 20 72 65 70 6f 72 74 20 65 72 72  ed to report err
3030: 6f 72 73 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 2e  ors if not NULL.
3040: 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20   */.    Tcl_Obj 
3050: 2a 6c 69 73 74 50 74 72 29 09 09 2f 2a 20 4c 69  *listPtr)../* Li
3060: 73 74 20 6f 62 6a 65 63 74 20 66 6f 72 20 77 68  st object for wh
3070: 69 63 68 20 61 6e 20 65 6c 65 6d 65 6e 74 20 61  ich an element a
3080: 72 72 61 79 20 69 73 0a 09 09 09 09 20 2a 20 74  rray is..... * t
3090: 6f 20 62 65 20 72 65 74 75 72 6e 65 64 2e 20 2a  o be returned. *
30a0: 2f 0a 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20  /.{.    Tcl_Obj 
30b0: 2a 63 6f 70 79 50 74 72 3b 0a 20 20 20 20 4c 69  *copyPtr;.    Li
30c0: 73 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a  st *listRepPtr;.
30d0: 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52  .    ListGetIntR
30e0: 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74  ep(listPtr, list
30f0: 52 65 70 50 74 72 29 3b 0a 20 20 20 20 69 66 20  RepPtr);.    if 
3100: 28 4e 55 4c 4c 20 3d 3d 20 6c 69 73 74 52 65 70  (NULL == listRep
3110: 50 74 72 29 20 7b 0a 09 69 66 20 28 53 65 74 4c  Ptr) {..if (SetL
3120: 69 73 74 46 72 6f 6d 41 6e 79 28 69 6e 74 65 72  istFromAny(inter
3130: 70 2c 20 6c 69 73 74 50 74 72 29 20 21 3d 20 54  p, listPtr) != T
3140: 43 4c 5f 4f 4b 29 20 7b 0a 09 20 20 20 20 72 65  CL_OK) {..    re
3150: 74 75 72 6e 20 4e 55 4c 4c 3b 0a 09 7d 0a 20 20  turn NULL;..}.  
3160: 20 20 7d 0a 0a 20 20 20 20 54 63 6c 4e 65 77 4f    }..    TclNewO
3170: 62 6a 28 63 6f 70 79 50 74 72 29 3b 0a 20 20 20  bj(copyPtr);.   
3180: 20 54 63 6c 49 6e 76 61 6c 69 64 61 74 65 53 74   TclInvalidateSt
3190: 72 69 6e 67 52 65 70 28 63 6f 70 79 50 74 72 29  ringRep(copyPtr)
31a0: 3b 0a 20 20 20 20 44 75 70 4c 69 73 74 49 6e 74  ;.    DupListInt
31b0: 65 72 6e 61 6c 52 65 70 28 6c 69 73 74 50 74 72  ernalRep(listPtr
31c0: 2c 20 63 6f 70 79 50 74 72 29 3b 0a 20 20 20 20  , copyPtr);.    
31d0: 72 65 74 75 72 6e 20 63 6f 70 79 50 74 72 3b 0a  return copyPtr;.
31e0: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d  }.../*. *-------
31f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
3230: 20 2a 0a 20 2a 20 54 63 6c 4c 69 73 74 4f 62 6a   *. * TclListObj
3240: 52 61 6e 67 65 20 2d 2d 0a 20 2a 0a 20 2a 09 4d  Range --. *. *.M
3250: 61 6b 65 73 20 61 20 73 6c 69 63 65 20 6f 66 20  akes a slice of 
3260: 61 20 6c 69 73 74 20 76 61 6c 75 65 2e 0a 20 2a  a list value.. *
3270: 20 20 20 20 20 20 2a 6c 69 73 74 50 74 72 20 6d        *listPtr m
3280: 75 73 74 20 62 65 20 6b 6e 6f 77 6e 20 74 6f 20  ust be known to 
3290: 62 65 20 61 20 76 61 6c 69 64 20 6c 69 73 74 2e  be a valid list.
32a0: 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a  . *. * Results:.
32b0: 20 2a 09 52 65 74 75 72 6e 73 20 61 20 70 6f 69   *.Returns a poi
32c0: 6e 74 65 72 20 74 6f 20 74 68 65 20 73 6c 69 63  nter to the slic
32d0: 65 64 20 6c 69 73 74 2e 0a 20 2a 20 20 20 20 20  ed list.. *     
32e0: 20 54 68 69 73 20 6d 61 79 20 62 65 20 61 20 6e   This may be a n
32f0: 65 77 20 6f 62 6a 65 63 74 20 6f 72 20 74 68 65  ew object or the
3300: 20 73 61 6d 65 20 6f 62 6a 65 63 74 20 69 66 20   same object if 
3310: 6e 6f 74 20 73 68 61 72 65 64 2e 0a 20 2a 0a 20  not shared.. *. 
3320: 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a  * Side effects:.
3330: 20 2a 09 54 68 65 20 70 6f 73 73 69 62 6c 65 20   *.The possible 
3340: 63 6f 6e 76 65 72 73 69 6f 6e 20 6f 66 20 74 68  conversion of th
3350: 65 20 6f 62 6a 65 63 74 20 72 65 66 65 72 65 6e  e object referen
3360: 63 65 64 20 62 79 20 6c 69 73 74 50 74 72 0a 20  ced by listPtr. 
3370: 2a 09 74 6f 20 61 20 6c 69 73 74 20 6f 62 6a 65  *.to a list obje
3380: 63 74 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d  ct.. *. *-------
3390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
33a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
33b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
33c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
33d0: 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54   */..Tcl_Obj *.T
33e0: 63 6c 4c 69 73 74 4f 62 6a 52 61 6e 67 65 28 0a  clListObjRange(.
33f0: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73      Tcl_Obj *lis
3400: 74 50 74 72 2c 09 09 2f 2a 20 4c 69 73 74 20 6f  tPtr,../* List o
3410: 62 6a 65 63 74 20 74 6f 20 74 61 6b 65 20 61 20  bject to take a 
3420: 72 61 6e 67 65 20 66 72 6f 6d 2e 20 2a 2f 0a 20  range from. */. 
3430: 20 20 20 69 6e 74 20 66 72 6f 6d 49 64 78 2c 09     int fromIdx,.
3440: 09 2f 2a 20 49 6e 64 65 78 20 6f 66 20 66 69 72  ./* Index of fir
3450: 73 74 20 65 6c 65 6d 65 6e 74 20 74 6f 20 69 6e  st element to in
3460: 63 6c 75 64 65 2e 20 2a 2f 0a 20 20 20 20 69 6e  clude. */.    in
3470: 74 20 74 6f 49 64 78 29 09 09 09 2f 2a 20 49 6e  t toIdx).../* In
3480: 64 65 78 20 6f 66 20 6c 61 73 74 20 65 6c 65 6d  dex of last elem
3490: 65 6e 74 20 74 6f 20 69 6e 63 6c 75 64 65 2e 20  ent to include. 
34a0: 2a 2f 0a 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a  */.{.    Tcl_Obj
34b0: 20 2a 2a 65 6c 65 6d 50 74 72 73 3b 0a 20 20 20   **elemPtrs;.   
34c0: 20 69 6e 74 20 6c 69 73 74 4c 65 6e 2c 20 69 2c   int listLen, i,
34d0: 20 6e 65 77 4c 65 6e 3b 0a 20 20 20 20 4c 69 73   newLen;.    Lis
34e0: 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a 0a  t *listRepPtr;..
34f0: 20 20 20 20 54 63 6c 4c 69 73 74 4f 62 6a 47 65      TclListObjGe
3500: 74 45 6c 65 6d 65 6e 74 73 28 4e 55 4c 4c 2c 20  tElements(NULL, 
3510: 6c 69 73 74 50 74 72 2c 20 26 6c 69 73 74 4c 65  listPtr, &listLe
3520: 6e 2c 20 26 65 6c 65 6d 50 74 72 73 29 3b 0a 0a  n, &elemPtrs);..
3530: 20 20 20 20 69 66 20 28 66 72 6f 6d 49 64 78 20      if (fromIdx 
3540: 3c 20 30 29 20 7b 0a 09 66 72 6f 6d 49 64 78 20  < 0) {..fromIdx 
3550: 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69  = 0;.    }.    i
3560: 66 20 28 74 6f 49 64 78 20 3e 3d 20 6c 69 73 74  f (toIdx >= list
3570: 4c 65 6e 29 20 7b 0a 09 74 6f 49 64 78 20 3d 20  Len) {..toIdx = 
3580: 6c 69 73 74 4c 65 6e 2d 31 3b 0a 20 20 20 20 7d  listLen-1;.    }
3590: 0a 20 20 20 20 69 66 20 28 66 72 6f 6d 49 64 78  .    if (fromIdx
35a0: 20 3e 20 74 6f 49 64 78 29 20 7b 0a 09 72 65 74   > toIdx) {..ret
35b0: 75 72 6e 20 54 63 6c 5f 4e 65 77 4f 62 6a 28 29  urn Tcl_NewObj()
35c0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 6e 65 77  ;.    }..    new
35d0: 4c 65 6e 20 3d 20 74 6f 49 64 78 20 2d 20 66 72  Len = toIdx - fr
35e0: 6f 6d 49 64 78 20 2b 20 31 3b 0a 0a 20 20 20 20  omIdx + 1;..    
35f0: 69 66 20 28 54 63 6c 5f 49 73 53 68 61 72 65 64  if (Tcl_IsShared
3600: 28 6c 69 73 74 50 74 72 29 20 7c 7c 0a 09 20 20  (listPtr) ||..  
3610: 20 20 28 28 4c 69 73 74 52 65 70 50 74 72 28 6c    ((ListRepPtr(l
3620: 69 73 74 50 74 72 29 2d 3e 72 65 66 43 6f 75 6e  istPtr)->refCoun
3630: 74 20 3e 20 31 29 29 29 20 7b 0a 09 72 65 74 75  t > 1))) {..retu
3640: 72 6e 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62  rn Tcl_NewListOb
3650: 6a 28 6e 65 77 4c 65 6e 2c 20 26 65 6c 65 6d 50  j(newLen, &elemP
3660: 74 72 73 5b 66 72 6f 6d 49 64 78 5d 29 3b 0a 20  trs[fromIdx]);. 
3670: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20     }..    /*.   
3680: 20 20 2a 20 49 6e 2d 70 6c 61 63 65 20 69 73 20    * In-place is 
3690: 70 6f 73 73 69 62 6c 65 2e 0a 20 20 20 20 20 2a  possible..     *
36a0: 2f 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a  /..    /*.     *
36b0: 20 45 76 65 6e 20 69 66 20 6e 6f 74 68 69 6e 67   Even if nothing
36c0: 20 62 65 6c 6f 77 20 63 61 75 73 65 20 61 6e 79   below cause any
36d0: 20 63 68 61 6e 67 65 73 2c 20 77 65 20 73 74 69   changes, we sti
36e0: 6c 6c 20 77 61 6e 74 20 74 68 65 0a 20 20 20 20  ll want the.    
36f0: 20 2a 20 73 74 72 69 6e 67 2d 63 61 6e 6f 6e 69   * string-canoni
3700: 7a 69 6e 67 20 65 66 66 65 63 74 20 6f 66 20 5b  zing effect of [
3710: 6c 72 61 6e 67 65 20 30 20 65 6e 64 5d 2e 0a 20  lrange 0 end].. 
3720: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 54 63 6c 49      */..    TclI
3730: 6e 76 61 6c 69 64 61 74 65 53 74 72 69 6e 67 52  nvalidateStringR
3740: 65 70 28 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20  ep(listPtr);..  
3750: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 44 65 6c 65    /*.     * Dele
3760: 74 65 20 65 6c 65 6d 65 6e 74 73 20 74 68 61 74  te elements that
3770: 20 73 68 6f 75 6c 64 20 6e 6f 74 20 62 65 20 69   should not be i
3780: 6e 63 6c 75 64 65 64 2e 0a 20 20 20 20 20 2a 2f  ncluded..     */
3790: 0a 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30  ..    for (i = 0
37a0: 3b 20 69 20 3c 20 66 72 6f 6d 49 64 78 3b 20 69  ; i < fromIdx; i
37b0: 2b 2b 29 20 7b 0a 09 54 63 6c 44 65 63 72 52 65  ++) {..TclDecrRe
37c0: 66 43 6f 75 6e 74 28 65 6c 65 6d 50 74 72 73 5b  fCount(elemPtrs[
37d0: 69 5d 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66  i]);.    }.    f
37e0: 6f 72 20 28 69 20 3d 20 74 6f 49 64 78 20 2b 20  or (i = toIdx + 
37f0: 31 3b 20 69 20 3c 20 6c 69 73 74 4c 65 6e 3b 20  1; i < listLen; 
3800: 69 2b 2b 29 20 7b 0a 09 54 63 6c 44 65 63 72 52  i++) {..TclDecrR
3810: 65 66 43 6f 75 6e 74 28 65 6c 65 6d 50 74 72 73  efCount(elemPtrs
3820: 5b 69 5d 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  [i]);.    }..   
3830: 20 69 66 20 28 66 72 6f 6d 49 64 78 20 3e 20 30   if (fromIdx > 0
3840: 29 20 7b 0a 09 6d 65 6d 6d 6f 76 65 28 65 6c 65  ) {..memmove(ele
3850: 6d 50 74 72 73 2c 20 26 65 6c 65 6d 50 74 72 73  mPtrs, &elemPtrs
3860: 5b 66 72 6f 6d 49 64 78 5d 2c 0a 09 09 28 73 69  [fromIdx],...(si
3870: 7a 65 5f 74 29 20 6e 65 77 4c 65 6e 20 2a 20 73  ze_t) newLen * s
3880: 69 7a 65 6f 66 28 54 63 6c 5f 4f 62 6a 2a 29 29  izeof(Tcl_Obj*))
3890: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 6c 69 73  ;.    }..    lis
38a0: 74 52 65 70 50 74 72 20 3d 20 4c 69 73 74 52 65  tRepPtr = ListRe
38b0: 70 50 74 72 28 6c 69 73 74 50 74 72 29 3b 0a 20  pPtr(listPtr);. 
38c0: 20 20 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 65     listRepPtr->e
38d0: 6c 65 6d 43 6f 75 6e 74 20 3d 20 6e 65 77 4c 65  lemCount = newLe
38e0: 6e 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 6c  n;..    return l
38f0: 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20  istPtr;.}.../*. 
3900: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *---------------
3910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3920: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3940: 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63  -------. *. * Tc
3950: 6c 5f 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 6d  l_ListObjGetElem
3960: 65 6e 74 73 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68  ents --. *. *.Th
3970: 69 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75  is function retu
3980: 72 6e 73 20 61 6e 20 28 6f 62 6a 63 2c 6f 62 6a  rns an (objc,obj
3990: 76 29 20 61 72 72 61 79 20 6f 66 20 74 68 65 20  v) array of the 
39a0: 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61 20 6c 69  elements in a li
39b0: 73 74 0a 20 2a 09 6f 62 6a 65 63 74 2e 0a 20 2a  st. *.object.. *
39c0: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09  . * Results:. *.
39d0: 54 68 65 20 72 65 74 75 72 6e 20 76 61 6c 75 65  The return value
39e0: 20 69 73 20 6e 6f 72 6d 61 6c 6c 79 20 54 43 4c   is normally TCL
39f0: 5f 4f 4b 3b 20 69 6e 20 74 68 69 73 20 63 61 73  _OK; in this cas
3a00: 65 20 2a 6f 62 6a 63 50 74 72 20 69 73 20 73 65  e *objcPtr is se
3a10: 74 20 74 6f 0a 20 2a 09 74 68 65 20 63 6f 75 6e  t to. *.the coun
3a20: 74 20 6f 66 20 6c 69 73 74 20 65 6c 65 6d 65 6e  t of list elemen
3a30: 74 73 20 61 6e 64 20 2a 6f 62 6a 76 50 74 72 20  ts and *objvPtr 
3a40: 69 73 20 73 65 74 20 74 6f 20 61 20 70 6f 69 6e  is set to a poin
3a50: 74 65 72 20 74 6f 20 61 6e 0a 20 2a 09 61 72 72  ter to an. *.arr
3a60: 61 79 20 6f 66 20 28 2a 6f 62 6a 63 50 74 72 29  ay of (*objcPtr)
3a70: 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 65 61 63   pointers to eac
3a80: 68 20 6c 69 73 74 20 65 6c 65 6d 65 6e 74 2e 20  h list element. 
3a90: 49 66 20 6c 69 73 74 50 74 72 20 64 6f 65 73 20  If listPtr does 
3aa0: 6e 6f 74 0a 20 2a 09 72 65 66 65 72 20 74 6f 20  not. *.refer to 
3ab0: 61 20 6c 69 73 74 20 6f 62 6a 65 63 74 20 61 6e  a list object an
3ac0: 64 20 74 68 65 20 6f 62 6a 65 63 74 20 63 61 6e  d the object can
3ad0: 20 6e 6f 74 20 62 65 20 63 6f 6e 76 65 72 74 65   not be converte
3ae0: 64 20 74 6f 20 6f 6e 65 2c 0a 20 2a 09 54 43 4c  d to one,. *.TCL
3af0: 5f 45 52 52 4f 52 20 69 73 20 72 65 74 75 72 6e  _ERROR is return
3b00: 65 64 20 61 6e 64 20 61 6e 20 65 72 72 6f 72 20  ed and an error 
3b10: 6d 65 73 73 61 67 65 20 77 69 6c 6c 20 62 65 20  message will be 
3b20: 6c 65 66 74 20 69 6e 20 74 68 65 0a 20 2a 09 69  left in the. *.i
3b30: 6e 74 65 72 70 72 65 74 65 72 27 73 20 72 65 73  nterpreter's res
3b40: 75 6c 74 20 69 66 20 69 6e 74 65 72 70 20 69 73  ult if interp is
3b50: 20 6e 6f 74 20 4e 55 4c 4c 2e 0a 20 2a 0a 20 2a   not NULL.. *. *
3b60: 09 54 68 65 20 6f 62 6a 65 63 74 73 20 72 65 66  .The objects ref
3b70: 65 72 65 6e 63 65 64 20 62 79 20 74 68 65 20 72  erenced by the r
3b80: 65 74 75 72 6e 65 64 20 61 72 72 61 79 20 73 68  eturned array sh
3b90: 6f 75 6c 64 20 62 65 20 74 72 65 61 74 65 64 20  ould be treated 
3ba0: 61 73 0a 20 2a 09 72 65 61 64 6f 6e 6c 79 20 61  as. *.readonly a
3bb0: 6e 64 20 74 68 65 69 72 20 72 65 66 20 63 6f 75  nd their ref cou
3bc0: 6e 74 73 20 61 72 65 20 5f 6e 6f 74 5f 20 69 6e  nts are _not_ in
3bd0: 63 72 65 6d 65 6e 74 65 64 3b 20 74 68 65 20 63  cremented; the c
3be0: 61 6c 6c 65 72 20 6d 75 73 74 0a 20 2a 09 64 6f  aller must. *.do
3bf0: 20 74 68 61 74 20 69 66 20 69 74 20 68 6f 6c 64   that if it hold
3c00: 73 20 6f 6e 20 74 6f 20 61 20 72 65 66 65 72 65  s on to a refere
3c10: 6e 63 65 2e 20 46 75 72 74 68 65 72 6d 6f 72 65  nce. Furthermore
3c20: 2c 20 74 68 65 20 70 6f 69 6e 74 65 72 20 61 6e  , the pointer an
3c30: 64 0a 20 2a 09 6c 65 6e 67 74 68 20 72 65 74 75  d. *.length retu
3c40: 72 6e 65 64 20 62 79 20 74 68 69 73 20 66 75 6e  rned by this fun
3c50: 63 74 69 6f 6e 20 6d 61 79 20 63 68 61 6e 67 65  ction may change
3c60: 20 61 73 20 73 6f 6f 6e 20 61 73 20 61 6e 79 20   as soon as any 
3c70: 66 75 6e 63 74 69 6f 6e 20 69 73 0a 20 2a 09 63  function is. *.c
3c80: 61 6c 6c 65 64 20 6f 6e 20 74 68 65 20 6c 69 73  alled on the lis
3c90: 74 20 6f 62 6a 65 63 74 3b 20 62 65 20 63 61 72  t object; be car
3ca0: 65 66 75 6c 20 61 62 6f 75 74 20 72 65 74 61 69  eful about retai
3cb0: 6e 69 6e 67 20 74 68 65 20 70 6f 69 6e 74 65 72  ning the pointer
3cc0: 20 69 6e 20 61 0a 20 2a 09 6c 6f 63 61 6c 20 64   in a. *.local d
3cd0: 61 74 61 20 73 74 72 75 63 74 75 72 65 2e 0a 20  ata structure.. 
3ce0: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74  *. * Side effect
3cf0: 73 3a 0a 20 2a 09 54 68 65 20 70 6f 73 73 69 62  s:. *.The possib
3d00: 6c 65 20 63 6f 6e 76 65 72 73 69 6f 6e 20 6f 66  le conversion of
3d10: 20 74 68 65 20 6f 62 6a 65 63 74 20 72 65 66 65   the object refe
3d20: 72 65 6e 63 65 64 20 62 79 20 6c 69 73 74 50 74  renced by listPt
3d30: 72 0a 20 2a 09 74 6f 20 61 20 6c 69 73 74 20 6f  r. *.to a list o
3d40: 62 6a 65 63 74 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d  bject.. *. *----
3d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d90: 2d 2d 0a 20 2a 2f 0a 0a 69 6e 74 0a 54 63 6c 5f  --. */..int.Tcl_
3da0: 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 6d 65 6e  ListObjGetElemen
3db0: 74 73 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65  ts(.    Tcl_Inte
3dc0: 72 70 20 2a 69 6e 74 65 72 70 2c 09 09 2f 2a 20  rp *interp,../* 
3dd0: 55 73 65 64 20 74 6f 20 72 65 70 6f 72 74 20 65  Used to report e
3de0: 72 72 6f 72 73 20 69 66 20 6e 6f 74 20 4e 55 4c  rrors if not NUL
3df0: 4c 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62  L. */.    Tcl_Ob
3e00: 6a 20 2a 6c 69 73 74 50 74 72 2c 09 2f 2a 20 4c  j *listPtr,./* L
3e10: 69 73 74 20 6f 62 6a 65 63 74 20 66 6f 72 20 77  ist object for w
3e20: 68 69 63 68 20 61 6e 20 65 6c 65 6d 65 6e 74 20  hich an element 
3e30: 61 72 72 61 79 20 69 73 0a 09 09 09 09 20 2a 20  array is..... * 
3e40: 74 6f 20 62 65 20 72 65 74 75 72 6e 65 64 2e 20  to be returned. 
3e50: 2a 2f 0a 20 20 20 20 69 6e 74 20 2a 6f 62 6a 63  */.    int *objc
3e60: 50 74 72 2c 09 09 2f 2a 20 57 68 65 72 65 20 74  Ptr,../* Where t
3e70: 6f 20 73 74 6f 72 65 20 74 68 65 20 63 6f 75 6e  o store the coun
3e80: 74 20 6f 66 20 6f 62 6a 65 63 74 73 0a 09 09 09  t of objects....
3e90: 09 20 2a 20 72 65 66 65 72 65 6e 63 65 64 20 62  . * referenced b
3ea0: 79 20 6f 62 6a 76 2e 20 2a 2f 0a 20 20 20 20 54  y objv. */.    T
3eb0: 63 6c 5f 4f 62 6a 20 2a 2a 2a 6f 62 6a 76 50 74  cl_Obj ***objvPt
3ec0: 72 29 09 09 2f 2a 20 57 68 65 72 65 20 74 6f 20  r)../* Where to 
3ed0: 73 74 6f 72 65 20 74 68 65 20 70 6f 69 6e 74 65  store the pointe
3ee0: 72 20 74 6f 20 61 6e 20 61 72 72 61 79 20 6f 66  r to an array of
3ef0: 0a 09 09 09 09 20 2a 20 70 6f 69 6e 74 65 72 73  ..... * pointers
3f00: 20 74 6f 20 74 68 65 20 6c 69 73 74 27 73 20 6f   to the list's o
3f10: 62 6a 65 63 74 73 2e 20 2a 2f 0a 7b 0a 20 20 20  bjects. */.{.   
3f20: 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74   List *listRepPt
3f30: 72 3b 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49  r;..    ListGetI
3f40: 6e 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c  ntRep(listPtr, l
3f50: 69 73 74 52 65 70 50 74 72 29 3b 0a 0a 20 20 20  istRepPtr);..   
3f60: 20 69 66 20 28 6c 69 73 74 52 65 70 50 74 72 20   if (listRepPtr 
3f70: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 69 6e 74 20  == NULL) {..int 
3f80: 72 65 73 75 6c 74 2c 20 6c 65 6e 67 74 68 3b 0a  result, length;.
3f90: 0a 09 28 76 6f 69 64 29 20 54 63 6c 5f 47 65 74  ..(void) Tcl_Get
3fa0: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 6c 69  StringFromObj(li
3fb0: 73 74 50 74 72 2c 20 26 6c 65 6e 67 74 68 29 3b  stPtr, &length);
3fc0: 0a 09 69 66 20 28 6c 65 6e 67 74 68 20 3d 3d 20  ..if (length == 
3fd0: 30 29 20 7b 0a 09 20 20 20 20 2a 6f 62 6a 63 50  0) {..    *objcP
3fe0: 74 72 20 3d 20 30 3b 0a 09 20 20 20 20 2a 6f 62  tr = 0;..    *ob
3ff0: 6a 76 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 09 20  jvPtr = NULL;.. 
4000: 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b     return TCL_OK
4010: 3b 0a 09 7d 0a 09 72 65 73 75 6c 74 20 3d 20 53  ;..}..result = S
4020: 65 74 4c 69 73 74 46 72 6f 6d 41 6e 79 28 69 6e  etListFromAny(in
4030: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 29 3b 0a  terp, listPtr);.
4040: 09 69 66 20 28 72 65 73 75 6c 74 20 21 3d 20 54  .if (result != T
4050: 43 4c 5f 4f 4b 29 20 7b 0a 09 20 20 20 20 72 65  CL_OK) {..    re
4060: 74 75 72 6e 20 72 65 73 75 6c 74 3b 0a 09 7d 0a  turn result;..}.
4070: 09 4c 69 73 74 47 65 74 49 6e 74 52 65 70 28 6c  .ListGetIntRep(l
4080: 69 73 74 50 74 72 2c 20 6c 69 73 74 52 65 70 50  istPtr, listRepP
4090: 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 2a  tr);.    }.    *
40a0: 6f 62 6a 63 50 74 72 20 3d 20 6c 69 73 74 52 65  objcPtr = listRe
40b0: 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 3b  pPtr->elemCount;
40c0: 0a 20 20 20 20 2a 6f 62 6a 76 50 74 72 20 3d 20  .    *objvPtr = 
40d0: 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65  &listRepPtr->ele
40e0: 6d 65 6e 74 73 3b 0a 20 20 20 20 72 65 74 75 72  ments;.    retur
40f0: 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a 2f 2a  n TCL_OK;.}.../*
4100: 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *-------------
4110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20  ---------. *. * 
4150: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
4160: 64 4c 69 73 74 20 2d 2d 0a 20 2a 0a 20 2a 09 54  dList --. *. *.T
4170: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 61 70 70  his function app
4180: 65 6e 64 73 20 74 68 65 20 65 6c 65 6d 65 6e 74  ends the element
4190: 73 20 69 6e 20 74 68 65 20 6c 69 73 74 20 76 61  s in the list va
41a0: 6c 75 65 20 72 65 66 65 72 65 6e 63 65 64 20 62  lue referenced b
41b0: 79 0a 20 2a 09 65 6c 65 6d 4c 69 73 74 50 74 72  y. *.elemListPtr
41c0: 20 74 6f 20 74 68 65 20 6c 69 73 74 20 76 61 6c   to the list val
41d0: 75 65 20 72 65 66 65 72 65 6e 63 65 64 20 62 79  ue referenced by
41e0: 20 6c 69 73 74 50 74 72 2e 0a 20 2a 0a 20 2a 20   listPtr.. *. * 
41f0: 52 65 73 75 6c 74 73 3a 0a 20 2a 09 54 68 65 20  Results:. *.The 
4200: 72 65 74 75 72 6e 20 76 61 6c 75 65 20 69 73 20  return value is 
4210: 6e 6f 72 6d 61 6c 6c 79 20 54 43 4c 5f 4f 4b 2e  normally TCL_OK.
4220: 20 49 66 20 6c 69 73 74 50 74 72 20 6f 72 20 65   If listPtr or e
4230: 6c 65 6d 4c 69 73 74 50 74 72 20 64 6f 20 6e 6f  lemListPtr do no
4240: 74 0a 20 2a 09 72 65 66 65 72 20 74 6f 20 6c 69  t. *.refer to li
4250: 73 74 20 76 61 6c 75 65 73 2c 20 54 43 4c 5f 45  st values, TCL_E
4260: 52 52 4f 52 20 69 73 20 72 65 74 75 72 6e 65 64  RROR is returned
4270: 20 61 6e 64 20 61 6e 20 65 72 72 6f 72 20 6d 65   and an error me
4280: 73 73 61 67 65 20 69 73 0a 20 2a 09 6c 65 66 74  ssage is. *.left
4290: 20 69 6e 20 74 68 65 20 69 6e 74 65 72 70 72 65   in the interpre
42a0: 74 65 72 27 73 20 72 65 73 75 6c 74 20 69 66 20  ter's result if 
42b0: 69 6e 74 65 72 70 20 69 73 20 6e 6f 74 20 4e 55  interp is not NU
42c0: 4c 4c 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65  LL.. *. * Side e
42d0: 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20 72  ffects:. *.The r
42e0: 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 73 20  eference counts 
42f0: 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e 74 73 20  of the elements 
4300: 69 6e 20 65 6c 65 6d 4c 69 73 74 50 74 72 20 61  in elemListPtr a
4310: 72 65 20 69 6e 63 72 65 6d 65 6e 74 65 64 0a 20  re incremented. 
4320: 2a 09 73 69 6e 63 65 20 74 68 65 20 6c 69 73 74  *.since the list
4330: 20 6e 6f 77 20 72 65 66 65 72 73 20 74 6f 20 74   now refers to t
4340: 68 65 6d 2e 20 6c 69 73 74 50 74 72 20 61 6e 64  hem. listPtr and
4350: 20 65 6c 65 6d 4c 69 73 74 50 74 72 20 61 72 65   elemListPtr are
4360: 0a 20 2a 09 63 6f 6e 76 65 72 74 65 64 2c 20 69  . *.converted, i
4370: 66 20 6e 65 63 65 73 73 61 72 79 2c 20 74 6f 20  f necessary, to 
4380: 6c 69 73 74 20 6f 62 6a 65 63 74 73 2e 20 41 6c  list objects. Al
4390: 73 6f 2c 20 61 70 70 65 6e 64 69 6e 67 20 74 68  so, appending th
43a0: 65 20 6e 65 77 0a 20 2a 09 65 6c 65 6d 65 6e 74  e new. *.element
43b0: 73 20 6d 61 79 20 63 61 75 73 65 20 6c 69 73 74  s may cause list
43c0: 4f 62 6a 27 73 20 61 72 72 61 79 20 6f 66 20 65  Obj's array of e
43d0: 6c 65 6d 65 6e 74 20 70 6f 69 6e 74 65 72 73 20  lement pointers 
43e0: 74 6f 20 67 72 6f 77 2e 0a 20 2a 09 6c 69 73 74  to grow.. *.list
43f0: 50 74 72 27 73 20 6f 6c 64 20 73 74 72 69 6e 67  Ptr's old string
4400: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2c   representation,
4410: 20 69 66 20 61 6e 79 2c 20 69 73 20 69 6e 76 61   if any, is inva
4420: 6c 69 64 61 74 65 64 2e 0a 20 2a 0a 20 2a 2d 2d  lidated.. *. *--
4430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4470: 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 69 6e 74 0a 54 63  ----. */..int.Tc
4480: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 4c  l_ListObjAppendL
4490: 69 73 74 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74  ist(.    Tcl_Int
44a0: 65 72 70 20 2a 69 6e 74 65 72 70 2c 09 09 2f 2a  erp *interp,../*
44b0: 20 55 73 65 64 20 74 6f 20 72 65 70 6f 72 74 20   Used to report 
44c0: 65 72 72 6f 72 73 20 69 66 20 6e 6f 74 20 4e 55  errors if not NU
44d0: 4c 4c 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f  LL. */.    Tcl_O
44e0: 62 6a 20 2a 6c 69 73 74 50 74 72 2c 09 2f 2a 20  bj *listPtr,./* 
44f0: 4c 69 73 74 20 6f 62 6a 65 63 74 20 74 6f 20 61  List object to a
4500: 70 70 65 6e 64 20 65 6c 65 6d 65 6e 74 73 20 74  ppend elements t
4510: 6f 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62  o. */.    Tcl_Ob
4520: 6a 20 2a 65 6c 65 6d 4c 69 73 74 50 74 72 29 09  j *elemListPtr).
4530: 2f 2a 20 4c 69 73 74 20 6f 62 6a 20 77 69 74 68  /* List obj with
4540: 20 65 6c 65 6d 65 6e 74 73 20 74 6f 20 61 70 70   elements to app
4550: 65 6e 64 2e 20 2a 2f 0a 7b 0a 20 20 20 20 69 6e  end. */.{.    in
4560: 74 20 6f 62 6a 63 3b 0a 20 20 20 20 54 63 6c 5f  t objc;.    Tcl_
4570: 4f 62 6a 20 2a 2a 6f 62 6a 76 3b 0a 0a 20 20 20  Obj **objv;..   
4580: 20 69 66 20 28 54 63 6c 5f 49 73 53 68 61 72 65   if (Tcl_IsShare
4590: 64 28 6c 69 73 74 50 74 72 29 29 20 7b 0a 09 54  d(listPtr)) {..T
45a0: 63 6c 5f 50 61 6e 69 63 28 22 25 73 20 63 61 6c  cl_Panic("%s cal
45b0: 6c 65 64 20 77 69 74 68 20 73 68 61 72 65 64 20  led with shared 
45c0: 6f 62 6a 65 63 74 22 2c 20 22 54 63 6c 5f 4c 69  object", "Tcl_Li
45d0: 73 74 4f 62 6a 41 70 70 65 6e 64 4c 69 73 74 22  stObjAppendList"
45e0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  );.    }..    /*
45f0: 0a 20 20 20 20 20 2a 20 50 75 6c 6c 20 74 68 65  .     * Pull the
4600: 20 65 6c 65 6d 65 6e 74 73 20 74 6f 20 61 70 70   elements to app
4610: 65 6e 64 20 66 72 6f 6d 20 65 6c 65 6d 4c 69 73  end from elemLis
4620: 74 50 74 72 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20  tPtr..     */.. 
4630: 20 20 20 69 66 20 28 54 43 4c 5f 4f 4b 20 21 3d     if (TCL_OK !=
4640: 20 54 63 6c 4c 69 73 74 4f 62 6a 47 65 74 45 6c   TclListObjGetEl
4650: 65 6d 65 6e 74 73 28 69 6e 74 65 72 70 2c 20 65  ements(interp, e
4660: 6c 65 6d 4c 69 73 74 50 74 72 2c 20 26 6f 62 6a  lemListPtr, &obj
4670: 63 2c 20 26 6f 62 6a 76 29 29 20 7b 0a 09 72 65  c, &objv)) {..re
4680: 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a  turn TCL_ERROR;.
4690: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20      }..    /*.  
46a0: 20 20 20 2a 20 49 6e 73 65 72 74 20 74 68 65 20     * Insert the 
46b0: 6e 65 77 20 65 6c 65 6d 65 6e 74 73 20 73 74 61  new elements sta
46c0: 72 74 69 6e 67 20 61 66 74 65 72 20 74 68 65 20  rting after the 
46d0: 6c 69 73 74 73 27 73 20 6c 61 73 74 20 65 6c 65  lists's last ele
46e0: 6d 65 6e 74 2e 0a 20 20 20 20 20 2a 20 44 65 6c  ment..     * Del
46f0: 65 74 65 20 7a 65 72 6f 20 65 78 69 73 74 69 6e  ete zero existin
4700: 67 20 65 6c 65 6d 65 6e 74 73 2e 0a 20 20 20 20  g elements..    
4710: 20 2a 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20   */..    return 
4720: 54 63 6c 5f 4c 69 73 74 4f 62 6a 52 65 70 6c 61  Tcl_ListObjRepla
4730: 63 65 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  ce(interp, listP
4740: 74 72 2c 20 4c 49 53 54 5f 4d 41 58 2c 20 30 2c  tr, LIST_MAX, 0,
4750: 20 6f 62 6a 63 2c 20 6f 62 6a 76 29 3b 0a 7d 0a   objc, objv);.}.
4760: 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  ../*. *---------
4770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
47a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
47b0: 0a 20 2a 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41  . * Tcl_ListObjA
47c0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 20 2d 2d 0a  ppendElement --.
47d0: 20 2a 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 74   *. *.This funct
47e0: 69 6f 6e 20 69 73 20 61 20 73 70 65 63 69 61 6c  ion is a special
47f0: 20 70 75 72 70 6f 73 65 20 76 65 72 73 69 6f 6e   purpose version
4800: 20 6f 66 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41   of Tcl_ListObjA
4810: 70 70 65 6e 64 4c 69 73 74 3a 0a 20 2a 09 69 74  ppendList:. *.it
4820: 20 61 70 70 65 6e 64 73 20 61 20 73 69 6e 67 6c   appends a singl
4830: 65 20 6f 62 6a 65 63 74 20 72 65 66 65 72 65 6e  e object referen
4840: 63 65 64 20 62 79 20 6f 62 6a 50 74 72 20 74 6f  ced by objPtr to
4850: 20 74 68 65 20 6c 69 73 74 20 6f 62 6a 65 63 74   the list object
4860: 0a 20 2a 09 72 65 66 65 72 65 6e 63 65 64 20 62  . *.referenced b
4870: 79 20 6c 69 73 74 50 74 72 2e 20 49 66 20 6c 69  y listPtr. If li
4880: 73 74 50 74 72 20 69 73 20 6e 6f 74 20 61 6c 72  stPtr is not alr
4890: 65 61 64 79 20 61 20 6c 69 73 74 20 6f 62 6a 65  eady a list obje
48a0: 63 74 2c 20 61 6e 0a 20 2a 09 61 74 74 65 6d 70  ct, an. *.attemp
48b0: 74 20 77 69 6c 6c 20 62 65 20 6d 61 64 65 20 74  t will be made t
48c0: 6f 20 63 6f 6e 76 65 72 74 20 69 74 20 74 6f 20  o convert it to 
48d0: 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c  one.. *. * Resul
48e0: 74 73 3a 0a 20 2a 09 54 68 65 20 72 65 74 75 72  ts:. *.The retur
48f0: 6e 20 76 61 6c 75 65 20 69 73 20 6e 6f 72 6d 61  n value is norma
4900: 6c 6c 79 20 54 43 4c 5f 4f 4b 3b 20 69 6e 20 74  lly TCL_OK; in t
4910: 68 69 73 20 63 61 73 65 20 6f 62 6a 50 74 72 20  his case objPtr 
4920: 69 73 20 61 64 64 65 64 20 74 6f 0a 20 2a 09 74  is added to. *.t
4930: 68 65 20 65 6e 64 20 6f 66 20 6c 69 73 74 50 74  he end of listPt
4940: 72 27 73 20 6c 69 73 74 2e 20 49 66 20 6c 69 73  r's list. If lis
4950: 74 50 74 72 20 64 6f 65 73 20 6e 6f 74 20 72 65  tPtr does not re
4960: 66 65 72 20 74 6f 20 61 20 6c 69 73 74 20 6f 62  fer to a list ob
4970: 6a 65 63 74 0a 20 2a 09 61 6e 64 20 74 68 65 20  ject. *.and the 
4980: 6f 62 6a 65 63 74 20 63 61 6e 20 6e 6f 74 20 62  object can not b
4990: 65 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 6f  e converted to o
49a0: 6e 65 2c 20 54 43 4c 5f 45 52 52 4f 52 20 69 73  ne, TCL_ERROR is
49b0: 20 72 65 74 75 72 6e 65 64 20 61 6e 64 0a 20 2a   returned and. *
49c0: 09 61 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67  .an error messag
49d0: 65 20 77 69 6c 6c 20 62 65 20 6c 65 66 74 20 69  e will be left i
49e0: 6e 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 65  n the interprete
49f0: 72 27 73 20 72 65 73 75 6c 74 20 69 66 20 69 6e  r's result if in
4a00: 74 65 72 70 20 69 73 0a 20 2a 09 6e 6f 74 20 4e  terp is. *.not N
4a10: 55 4c 4c 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20  ULL.. *. * Side 
4a20: 65 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20  effects:. *.The 
4a30: 72 65 66 20 63 6f 75 6e 74 20 6f 66 20 6f 62 6a  ref count of obj
4a40: 50 74 72 20 69 73 20 69 6e 63 72 65 6d 65 6e 74  Ptr is increment
4a50: 65 64 20 73 69 6e 63 65 20 74 68 65 20 6c 69 73  ed since the lis
4a60: 74 20 6e 6f 77 20 72 65 66 65 72 73 20 74 6f 0a  t now refers to.
4a70: 20 2a 09 69 74 2e 20 6c 69 73 74 50 74 72 20 77   *.it. listPtr w
4a80: 69 6c 6c 20 62 65 20 63 6f 6e 76 65 72 74 65 64  ill be converted
4a90: 2c 20 69 66 20 6e 65 63 65 73 73 61 72 79 2c 20  , if necessary, 
4aa0: 74 6f 20 61 20 6c 69 73 74 20 6f 62 6a 65 63 74  to a list object
4ab0: 2e 20 41 6c 73 6f 2c 0a 20 2a 09 61 70 70 65 6e  . Also,. *.appen
4ac0: 64 69 6e 67 20 74 68 65 20 6e 65 77 20 65 6c 65  ding the new ele
4ad0: 6d 65 6e 74 20 6d 61 79 20 63 61 75 73 65 20 6c  ment may cause l
4ae0: 69 73 74 4f 62 6a 27 73 20 61 72 72 61 79 20 6f  istObj's array o
4af0: 66 20 65 6c 65 6d 65 6e 74 0a 20 2a 09 70 6f 69  f element. *.poi
4b00: 6e 74 65 72 73 20 74 6f 20 67 72 6f 77 2e 20 6c  nters to grow. l
4b10: 69 73 74 50 74 72 27 73 20 6f 6c 64 20 73 74 72  istPtr's old str
4b20: 69 6e 67 20 72 65 70 72 65 73 65 6e 74 61 74 69  ing representati
4b30: 6f 6e 2c 20 69 66 20 61 6e 79 2c 20 69 73 0a 20  on, if any, is. 
4b40: 2a 09 69 6e 76 61 6c 69 64 61 74 65 64 2e 0a 20  *.invalidated.. 
4b50: 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *. *------------
4b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4b70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a  ----------. */..
4ba0: 69 6e 74 0a 54 63 6c 5f 4c 69 73 74 4f 62 6a 41  int.Tcl_ListObjA
4bb0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 0a 20 20  ppendElement(.  
4bc0: 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e    Tcl_Interp *in
4bd0: 74 65 72 70 2c 09 09 2f 2a 20 55 73 65 64 20 74  terp,../* Used t
4be0: 6f 20 72 65 70 6f 72 74 20 65 72 72 6f 72 73 20  o report errors 
4bf0: 69 66 20 6e 6f 74 20 4e 55 4c 4c 2e 20 2a 2f 0a  if not NULL. */.
4c00: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73      Tcl_Obj *lis
4c10: 74 50 74 72 2c 09 09 2f 2a 20 4c 69 73 74 20 6f  tPtr,../* List o
4c20: 62 6a 65 63 74 20 74 6f 20 61 70 70 65 6e 64 20  bject to append 
4c30: 6f 62 6a 50 74 72 20 74 6f 2e 20 2a 2f 0a 20 20  objPtr to. */.  
4c40: 20 20 54 63 6c 5f 4f 62 6a 20 2a 6f 62 6a 50 74    Tcl_Obj *objPt
4c50: 72 29 09 09 2f 2a 20 4f 62 6a 65 63 74 20 74 6f  r)../* Object to
4c60: 20 61 70 70 65 6e 64 20 74 6f 20 6c 69 73 74 50   append to listP
4c70: 74 72 27 73 20 6c 69 73 74 2e 20 2a 2f 0a 7b 0a  tr's list. */.{.
4c80: 20 20 20 20 4c 69 73 74 20 2a 6c 69 73 74 52 65      List *listRe
4c90: 70 50 74 72 2c 20 2a 6e 65 77 50 74 72 20 3d 20  pPtr, *newPtr = 
4ca0: 4e 55 4c 4c 3b 0a 20 20 20 20 69 6e 74 20 6e 75  NULL;.    int nu
4cb0: 6d 45 6c 65 6d 73 2c 20 6e 75 6d 52 65 71 75 69  mElems, numRequi
4cc0: 72 65 64 2c 20 6e 65 65 64 47 72 6f 77 2c 20 69  red, needGrow, i
4cd0: 73 53 68 61 72 65 64 2c 20 61 74 74 65 6d 70 74  sShared, attempt
4ce0: 3b 0a 0a 20 20 20 20 69 66 20 28 54 63 6c 5f 49  ;..    if (Tcl_I
4cf0: 73 53 68 61 72 65 64 28 6c 69 73 74 50 74 72 29  sShared(listPtr)
4d00: 29 20 7b 0a 09 54 63 6c 5f 50 61 6e 69 63 28 22  ) {..Tcl_Panic("
4d10: 25 73 20 63 61 6c 6c 65 64 20 77 69 74 68 20 73  %s called with s
4d20: 68 61 72 65 64 20 6f 62 6a 65 63 74 22 2c 20 22  hared object", "
4d30: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
4d40: 64 45 6c 65 6d 65 6e 74 22 29 3b 0a 20 20 20 20  dElement");.    
4d50: 7d 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e  }..    ListGetIn
4d60: 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69  tRep(listPtr, li
4d70: 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20 20 69  stRepPtr);.    i
4d80: 66 20 28 6c 69 73 74 52 65 70 50 74 72 20 3d 3d  f (listRepPtr ==
4d90: 20 4e 55 4c 4c 29 20 7b 0a 09 69 6e 74 20 72 65   NULL) {..int re
4da0: 73 75 6c 74 2c 20 6c 65 6e 67 74 68 3b 0a 0a 09  sult, length;...
4db0: 28 76 6f 69 64 29 20 54 63 6c 5f 47 65 74 53 74  (void) Tcl_GetSt
4dc0: 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 6c 69 73 74  ringFromObj(list
4dd0: 50 74 72 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09  Ptr, &length);..
4de0: 69 66 20 28 6c 65 6e 67 74 68 20 3d 3d 20 30 29  if (length == 0)
4df0: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 53 65 74 4c   {..    Tcl_SetL
4e00: 69 73 74 4f 62 6a 28 6c 69 73 74 50 74 72 2c 20  istObj(listPtr, 
4e10: 31 2c 20 26 6f 62 6a 50 74 72 29 3b 0a 09 20 20  1, &objPtr);..  
4e20: 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b    return TCL_OK;
4e30: 0a 09 7d 0a 09 72 65 73 75 6c 74 20 3d 20 53 65  ..}..result = Se
4e40: 74 4c 69 73 74 46 72 6f 6d 41 6e 79 28 69 6e 74  tListFromAny(int
4e50: 65 72 70 2c 20 6c 69 73 74 50 74 72 29 3b 0a 09  erp, listPtr);..
4e60: 69 66 20 28 72 65 73 75 6c 74 20 21 3d 20 54 43  if (result != TC
4e70: 4c 5f 4f 4b 29 20 7b 0a 09 20 20 20 20 72 65 74  L_OK) {..    ret
4e80: 75 72 6e 20 72 65 73 75 6c 74 3b 0a 09 7d 0a 09  urn result;..}..
4e90: 4c 69 73 74 47 65 74 49 6e 74 52 65 70 28 6c 69  ListGetIntRep(li
4ea0: 73 74 50 74 72 2c 20 6c 69 73 74 52 65 70 50 74  stPtr, listRepPt
4eb0: 72 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 6e  r);.    }..    n
4ec0: 75 6d 45 6c 65 6d 73 20 3d 20 6c 69 73 74 52 65  umElems = listRe
4ed0: 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 3b  pPtr->elemCount;
4ee0: 0a 20 20 20 20 6e 75 6d 52 65 71 75 69 72 65 64  .    numRequired
4ef0: 20 3d 20 6e 75 6d 45 6c 65 6d 73 20 2b 20 31 20   = numElems + 1 
4f00: 3b 0a 20 20 20 20 6e 65 65 64 47 72 6f 77 20 3d  ;.    needGrow =
4f10: 20 28 6e 75 6d 52 65 71 75 69 72 65 64 20 3e 20   (numRequired > 
4f20: 6c 69 73 74 52 65 70 50 74 72 2d 3e 6d 61 78 45  listRepPtr->maxE
4f30: 6c 65 6d 43 6f 75 6e 74 29 3b 0a 20 20 20 20 69  lemCount);.    i
4f40: 73 53 68 61 72 65 64 20 3d 20 28 6c 69 73 74 52  sShared = (listR
4f50: 65 70 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74 20  epPtr->refCount 
4f60: 3e 20 31 29 3b 0a 0a 20 20 20 20 69 66 20 28 6e  > 1);..    if (n
4f70: 75 6d 52 65 71 75 69 72 65 64 20 3e 20 4c 49 53  umRequired > LIS
4f80: 54 5f 4d 41 58 29 20 7b 0a 09 69 66 20 28 69 6e  T_MAX) {..if (in
4f90: 74 65 72 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  terp != NULL) {.
4fa0: 09 20 20 20 20 54 63 6c 5f 53 65 74 4f 62 6a 52  .    Tcl_SetObjR
4fb0: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 63  esult(interp, Tc
4fc0: 6c 5f 4f 62 6a 50 72 69 6e 74 66 28 0a 09 09 20  l_ObjPrintf(... 
4fd0: 20 20 20 22 6d 61 78 20 6c 65 6e 67 74 68 20 6f     "max length o
4fe0: 66 20 61 20 54 63 6c 20 6c 69 73 74 20 28 25 64  f a Tcl list (%d
4ff0: 20 65 6c 65 6d 65 6e 74 73 29 20 65 78 63 65 65   elements) excee
5000: 64 65 64 22 2c 0a 09 09 20 20 20 20 4c 49 53 54  ded",...    LIST
5010: 5f 4d 41 58 29 29 3b 0a 09 20 20 20 20 54 63 6c  _MAX));..    Tcl
5020: 5f 53 65 74 45 72 72 6f 72 43 6f 64 65 28 69 6e  _SetErrorCode(in
5030: 74 65 72 70 2c 20 22 54 43 4c 22 2c 20 22 4d 45  terp, "TCL", "ME
5040: 4d 4f 52 59 22 2c 20 4e 55 4c 4c 29 3b 0a 09 7d  MORY", NULL);..}
5050: 0a 09 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52  ..return TCL_ERR
5060: 4f 52 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69  OR;.    }..    i
5070: 66 20 28 6e 65 65 64 47 72 6f 77 20 26 26 20 21  f (needGrow && !
5080: 69 73 53 68 61 72 65 64 29 20 7b 0a 09 2f 2a 0a  isShared) {../*.
5090: 09 20 2a 20 4e 65 65 64 20 74 6f 20 67 72 6f 77  . * Need to grow
50a0: 20 2b 20 75 6e 73 68 61 72 65 64 20 69 6e 74 72   + unshared intr
50b0: 65 70 20 3d 3e 20 74 72 79 20 74 6f 20 72 65 61  ep => try to rea
50c0: 6c 6c 6f 63 0a 09 20 2a 2f 0a 0a 09 61 74 74 65  lloc.. */...atte
50d0: 6d 70 74 20 3d 20 32 20 2a 20 6e 75 6d 52 65 71  mpt = 2 * numReq
50e0: 75 69 72 65 64 3b 0a 09 69 66 20 28 61 74 74 65  uired;..if (atte
50f0: 6d 70 74 20 3c 3d 20 4c 49 53 54 5f 4d 41 58 29  mpt <= LIST_MAX)
5100: 20 7b 0a 09 20 20 20 20 6e 65 77 50 74 72 20 3d   {..    newPtr =
5110: 20 28 4c 69 73 74 20 2a 29 61 74 74 65 6d 70 74   (List *)attempt
5120: 63 6b 72 65 61 6c 6c 6f 63 28 6c 69 73 74 52 65  ckrealloc(listRe
5130: 70 50 74 72 2c 20 4c 49 53 54 5f 53 49 5a 45 28  pPtr, LIST_SIZE(
5140: 61 74 74 65 6d 70 74 29 29 3b 0a 09 7d 0a 09 69  attempt));..}..i
5150: 66 20 28 6e 65 77 50 74 72 20 3d 3d 20 4e 55 4c  f (newPtr == NUL
5160: 4c 29 20 7b 0a 09 20 20 20 20 61 74 74 65 6d 70  L) {..    attemp
5170: 74 20 3d 20 6e 75 6d 52 65 71 75 69 72 65 64 20  t = numRequired 
5180: 2b 20 31 20 2b 20 54 43 4c 5f 4d 49 4e 5f 45 4c  + 1 + TCL_MIN_EL
5190: 45 4d 45 4e 54 5f 47 52 4f 57 54 48 3b 0a 09 20  EMENT_GROWTH;.. 
51a0: 20 20 20 69 66 20 28 61 74 74 65 6d 70 74 20 3e     if (attempt >
51b0: 20 4c 49 53 54 5f 4d 41 58 29 20 7b 0a 09 09 61   LIST_MAX) {...a
51c0: 74 74 65 6d 70 74 20 3d 20 4c 49 53 54 5f 4d 41  ttempt = LIST_MA
51d0: 58 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 6e  X;..    }..    n
51e0: 65 77 50 74 72 20 3d 20 28 4c 69 73 74 20 2a 29  ewPtr = (List *)
51f0: 61 74 74 65 6d 70 74 63 6b 72 65 61 6c 6c 6f 63  attemptckrealloc
5200: 28 6c 69 73 74 52 65 70 50 74 72 2c 20 4c 49 53  (listRepPtr, LIS
5210: 54 5f 53 49 5a 45 28 61 74 74 65 6d 70 74 29 29  T_SIZE(attempt))
5220: 3b 0a 09 7d 0a 09 69 66 20 28 6e 65 77 50 74 72  ;..}..if (newPtr
5230: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20   == NULL) {..   
5240: 20 61 74 74 65 6d 70 74 20 3d 20 6e 75 6d 52 65   attempt = numRe
5250: 71 75 69 72 65 64 3b 0a 09 20 20 20 20 6e 65 77  quired;..    new
5260: 50 74 72 20 3d 20 28 4c 69 73 74 20 2a 29 61 74  Ptr = (List *)at
5270: 74 65 6d 70 74 63 6b 72 65 61 6c 6c 6f 63 28 6c  temptckrealloc(l
5280: 69 73 74 52 65 70 50 74 72 2c 20 4c 49 53 54 5f  istRepPtr, LIST_
5290: 53 49 5a 45 28 61 74 74 65 6d 70 74 29 29 3b 0a  SIZE(attempt));.
52a0: 09 7d 0a 09 69 66 20 28 6e 65 77 50 74 72 29 20  .}..if (newPtr) 
52b0: 7b 0a 09 20 20 20 20 6c 69 73 74 52 65 70 50 74  {..    listRepPt
52c0: 72 20 3d 20 6e 65 77 50 74 72 3b 0a 09 20 20 20  r = newPtr;..   
52d0: 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 6d 61 78   listRepPtr->max
52e0: 45 6c 65 6d 43 6f 75 6e 74 20 3d 20 61 74 74 65  ElemCount = atte
52f0: 6d 70 74 3b 0a 09 20 20 20 20 6e 65 65 64 47 72  mpt;..    needGr
5300: 6f 77 20 3d 20 30 3b 0a 09 7d 0a 20 20 20 20 7d  ow = 0;..}.    }
5310: 0a 20 20 20 20 69 66 20 28 69 73 53 68 61 72 65  .    if (isShare
5320: 64 20 7c 7c 20 6e 65 65 64 47 72 6f 77 29 20 7b  d || needGrow) {
5330: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 2a 64 73 74 2c  ..Tcl_Obj **dst,
5340: 20 2a 2a 73 72 63 20 3d 20 26 6c 69 73 74 52 65   **src = &listRe
5350: 70 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a  pPtr->elements;.
5360: 0a 09 2f 2a 0a 09 20 2a 20 45 69 74 68 65 72 20  ../*.. * Either 
5370: 77 65 20 68 61 76 65 20 61 20 73 68 61 72 65 64  we have a shared
5380: 20 69 6e 74 72 65 70 20 61 6e 64 20 77 65 20 6d   intrep and we m
5390: 75 73 74 20 63 6f 70 79 20 74 6f 20 77 72 69 74  ust copy to writ
53a0: 65 2c 20 6f 72 20 77 65 0a 09 20 2a 20 6e 65 65  e, or we.. * nee
53b0: 64 20 74 6f 20 67 72 6f 77 20 61 6e 64 20 72 65  d to grow and re
53c0: 61 6c 6c 6f 63 20 61 74 74 65 6d 70 74 73 20 66  alloc attempts f
53d0: 61 69 6c 65 64 2e 20 20 41 74 74 65 6d 70 74 20  ailed.  Attempt 
53e0: 69 6e 74 72 65 70 20 63 6f 70 79 2e 0a 09 20 2a  intrep copy... *
53f0: 2f 0a 0a 09 61 74 74 65 6d 70 74 20 3d 20 32 20  /...attempt = 2 
5400: 2a 20 6e 75 6d 52 65 71 75 69 72 65 64 3b 0a 09  * numRequired;..
5410: 6e 65 77 50 74 72 20 3d 20 41 74 74 65 6d 70 74  newPtr = Attempt
5420: 4e 65 77 4c 69 73 74 28 4e 55 4c 4c 2c 20 61 74  NewList(NULL, at
5430: 74 65 6d 70 74 2c 20 4e 55 4c 4c 29 3b 0a 09 69  tempt, NULL);..i
5440: 66 20 28 6e 65 77 50 74 72 20 3d 3d 20 4e 55 4c  f (newPtr == NUL
5450: 4c 29 20 7b 0a 09 20 20 20 20 61 74 74 65 6d 70  L) {..    attemp
5460: 74 20 3d 20 6e 75 6d 52 65 71 75 69 72 65 64 20  t = numRequired 
5470: 2b 20 31 20 2b 20 54 43 4c 5f 4d 49 4e 5f 45 4c  + 1 + TCL_MIN_EL
5480: 45 4d 45 4e 54 5f 47 52 4f 57 54 48 3b 0a 09 20  EMENT_GROWTH;.. 
5490: 20 20 20 69 66 20 28 61 74 74 65 6d 70 74 20 3e     if (attempt >
54a0: 20 4c 49 53 54 5f 4d 41 58 29 20 7b 0a 09 09 61   LIST_MAX) {...a
54b0: 74 74 65 6d 70 74 20 3d 20 4c 49 53 54 5f 4d 41  ttempt = LIST_MA
54c0: 58 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 6e  X;..    }..    n
54d0: 65 77 50 74 72 20 3d 20 41 74 74 65 6d 70 74 4e  ewPtr = AttemptN
54e0: 65 77 4c 69 73 74 28 4e 55 4c 4c 2c 20 61 74 74  ewList(NULL, att
54f0: 65 6d 70 74 2c 20 4e 55 4c 4c 29 3b 0a 09 7d 0a  empt, NULL);..}.
5500: 09 69 66 20 28 6e 65 77 50 74 72 20 3d 3d 20 4e  .if (newPtr == N
5510: 55 4c 4c 29 20 7b 0a 09 20 20 20 20 61 74 74 65  ULL) {..    atte
5520: 6d 70 74 20 3d 20 6e 75 6d 52 65 71 75 69 72 65  mpt = numRequire
5530: 64 3b 0a 09 20 20 20 20 6e 65 77 50 74 72 20 3d  d;..    newPtr =
5540: 20 41 74 74 65 6d 70 74 4e 65 77 4c 69 73 74 28   AttemptNewList(
5550: 69 6e 74 65 72 70 2c 20 61 74 74 65 6d 70 74 2c  interp, attempt,
5560: 20 4e 55 4c 4c 29 3b 0a 09 7d 0a 09 69 66 20 28   NULL);..}..if (
5570: 6e 65 77 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20  newPtr == NULL) 
5580: 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20  {..    /*..     
5590: 2a 20 41 6c 6c 20 67 72 6f 77 74 68 20 61 74 74  * All growth att
55a0: 65 6d 70 74 73 20 66 61 69 6c 65 64 3b 20 74 68  empts failed; th
55b0: 72 6f 77 20 74 68 65 20 65 72 72 6f 72 2e 0a 09  row the error...
55c0: 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 72 65       */...    re
55d0: 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a  turn TCL_ERROR;.
55e0: 09 7d 0a 0a 09 64 73 74 20 3d 20 26 6e 65 77 50  .}...dst = &newP
55f0: 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a 09 6e  tr->elements;..n
5600: 65 77 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74 2b  ewPtr->refCount+
5610: 2b 3b 0a 09 6e 65 77 50 74 72 2d 3e 63 61 6e 6f  +;..newPtr->cano
5620: 6e 69 63 61 6c 46 6c 61 67 20 3d 20 6c 69 73 74  nicalFlag = list
5630: 52 65 70 50 74 72 2d 3e 63 61 6e 6f 6e 69 63 61  RepPtr->canonica
5640: 6c 46 6c 61 67 3b 0a 09 6e 65 77 50 74 72 2d 3e  lFlag;..newPtr->
5650: 65 6c 65 6d 43 6f 75 6e 74 20 3d 20 6c 69 73 74  elemCount = list
5660: 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e  RepPtr->elemCoun
5670: 74 3b 0a 0a 09 69 66 20 28 69 73 53 68 61 72 65  t;...if (isShare
5680: 64 29 20 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20  d) {..    /*..  
5690: 20 20 20 2a 20 54 68 65 20 6f 72 69 67 69 6e 61     * The origina
56a0: 6c 20 69 6e 74 72 65 70 20 6d 75 73 74 20 72 65  l intrep must re
56b0: 6d 61 69 6e 20 75 6e 64 69 73 74 75 72 62 65 64  main undisturbed
56c0: 2e 20 20 43 6f 70 79 20 69 6e 74 6f 20 74 68 65  .  Copy into the
56d0: 20 6e 65 77 0a 09 20 20 20 20 20 2a 20 6f 6e 65   new..     * one
56e0: 20 61 6e 64 20 62 75 6d 70 20 72 65 66 63 6f 75   and bump refcou
56f0: 6e 74 73 0a 09 20 20 20 20 20 2a 2f 0a 09 20 20  nts..     */..  
5700: 20 20 77 68 69 6c 65 20 28 6e 75 6d 45 6c 65 6d    while (numElem
5710: 73 2d 2d 29 20 7b 0a 09 09 2a 64 73 74 20 3d 20  s--) {...*dst = 
5720: 2a 73 72 63 2b 2b 3b 0a 09 09 54 63 6c 5f 49 6e  *src++;...Tcl_In
5730: 63 72 52 65 66 43 6f 75 6e 74 28 2a 64 73 74 2b  crRefCount(*dst+
5740: 2b 29 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20  +);..    }..    
5750: 6c 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66 43  listRepPtr->refC
5760: 6f 75 6e 74 2d 2d 3b 0a 09 7d 20 65 6c 73 65 20  ount--;..} else 
5770: 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20  {..    /*..     
5780: 2a 20 4f 6c 64 20 69 6e 74 72 65 70 20 74 6f 20  * Old intrep to 
5790: 62 65 20 66 72 65 65 64 2c 20 72 65 2d 75 73 65  be freed, re-use
57a0: 20 72 65 66 43 6f 75 6e 74 73 2e 0a 09 20 20 20   refCounts...   
57b0: 20 20 2a 2f 0a 0a 09 20 20 20 20 6d 65 6d 63 70    */...    memcp
57c0: 79 28 64 73 74 2c 20 73 72 63 2c 20 6e 75 6d 45  y(dst, src, numE
57d0: 6c 65 6d 73 20 2a 20 73 69 7a 65 6f 66 28 54 63  lems * sizeof(Tc
57e0: 6c 5f 4f 62 6a 20 2a 29 29 3b 0a 09 20 20 20 20  l_Obj *));..    
57f0: 63 6b 66 72 65 65 28 6c 69 73 74 52 65 70 50 74  ckfree(listRepPt
5800: 72 29 3b 0a 09 7d 0a 09 6c 69 73 74 52 65 70 50  r);..}..listRepP
5810: 74 72 20 3d 20 6e 65 77 50 74 72 3b 0a 20 20 20  tr = newPtr;.   
5820: 20 7d 0a 20 20 20 20 4c 69 73 74 52 65 73 65 74   }.    ListReset
5830: 49 6e 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20  IntRep(listPtr, 
5840: 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20  listRepPtr);.   
5850: 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66   listRepPtr->ref
5860: 43 6f 75 6e 74 2b 2b 3b 0a 20 20 20 20 54 63 6c  Count++;.    Tcl
5870: 46 72 65 65 49 6e 74 52 65 70 28 6c 69 73 74 50  FreeIntRep(listP
5880: 74 72 29 3b 0a 20 20 20 20 4c 69 73 74 53 65 74  tr);.    ListSet
5890: 49 6e 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20  IntRep(listPtr, 
58a0: 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20  listRepPtr);.   
58b0: 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66   listRepPtr->ref
58c0: 43 6f 75 6e 74 2d 2d 3b 0a 0a 20 20 20 20 2f 2a  Count--;..    /*
58d0: 0a 20 20 20 20 20 2a 20 41 64 64 20 6f 62 6a 50  .     * Add objP
58e0: 74 72 20 74 6f 20 74 68 65 20 65 6e 64 20 6f 66  tr to the end of
58f0: 20 6c 69 73 74 50 74 72 27 73 20 61 72 72 61 79   listPtr's array
5900: 20 6f 66 20 65 6c 65 6d 65 6e 74 20 70 6f 69 6e   of element poin
5910: 74 65 72 73 2e 20 49 6e 63 72 65 6d 65 6e 74 0a  ters. Increment.
5920: 20 20 20 20 20 2a 20 74 68 65 20 72 65 66 20 63       * the ref c
5930: 6f 75 6e 74 20 66 6f 72 20 74 68 65 20 28 6e 6f  ount for the (no
5940: 77 20 73 68 61 72 65 64 29 20 6f 62 6a 50 74 72  w shared) objPtr
5950: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 2a  ..     */..    *
5960: 28 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c  (&listRepPtr->el
5970: 65 6d 65 6e 74 73 20 2b 20 6c 69 73 74 52 65 70  ements + listRep
5980: 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 29 20  Ptr->elemCount) 
5990: 3d 20 6f 62 6a 50 74 72 3b 0a 20 20 20 20 54 63  = objPtr;.    Tc
59a0: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f  l_IncrRefCount(o
59b0: 62 6a 50 74 72 29 3b 0a 20 20 20 20 6c 69 73 74  bjPtr);.    list
59c0: 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e  RepPtr->elemCoun
59d0: 74 2b 2b 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20  t++;..    /*.   
59e0: 20 20 2a 20 49 6e 76 61 6c 69 64 61 74 65 20 61    * Invalidate a
59f0: 6e 79 20 6f 6c 64 20 73 74 72 69 6e 67 20 72 65  ny old string re
5a00: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 73 69 6e  presentation sin
5a10: 63 65 20 74 68 65 20 6c 69 73 74 27 73 20 69 6e  ce the list's in
5a20: 74 65 72 6e 61 6c 0a 20 20 20 20 20 2a 20 72 65  ternal.     * re
5a30: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 68 61 73  presentation has
5a40: 20 63 68 61 6e 67 65 64 2e 0a 20 20 20 20 20 2a   changed..     *
5a50: 2f 0a 0a 20 20 20 20 54 63 6c 49 6e 76 61 6c 69  /..    TclInvali
5a60: 64 61 74 65 53 74 72 69 6e 67 52 65 70 28 6c 69  dateStringRep(li
5a70: 73 74 50 74 72 29 3b 0a 20 20 20 20 72 65 74 75  stPtr);.    retu
5a80: 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a 2f  rn TCL_OK;.}.../
5a90: 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *. *------------
5aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a  ----------. *. *
5ae0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 49 6e 64 65   Tcl_ListObjInde
5af0: 78 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20  x --. *. *.This 
5b00: 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 6e 73  function returns
5b10: 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68   a pointer to th
5b20: 65 20 69 6e 64 65 78 27 74 68 20 6f 62 6a 65 63  e index'th objec
5b30: 74 20 66 72 6f 6d 20 74 68 65 20 6c 69 73 74 0a  t from the list.
5b40: 20 2a 09 72 65 66 65 72 65 6e 63 65 64 20 62 79   *.referenced by
5b50: 20 6c 69 73 74 50 74 72 2e 20 54 68 65 20 66 69   listPtr. The fi
5b60: 72 73 74 20 65 6c 65 6d 65 6e 74 20 68 61 73 20  rst element has 
5b70: 69 6e 64 65 78 20 30 2e 20 49 66 20 69 6e 64 65  index 0. If inde
5b80: 78 20 69 73 0a 20 2a 09 6e 65 67 61 74 69 76 65  x is. *.negative
5b90: 20 6f 72 20 67 72 65 61 74 65 72 20 74 68 61 6e   or greater than
5ba0: 20 6f 72 20 65 71 75 61 6c 20 74 6f 20 74 68 65   or equal to the
5bb0: 20 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65   number of eleme
5bc0: 6e 74 73 20 69 6e 20 74 68 65 0a 20 2a 09 6c 69  nts in the. *.li
5bd0: 73 74 2c 20 61 20 4e 55 4c 4c 20 69 73 20 72 65  st, a NULL is re
5be0: 74 75 72 6e 65 64 2e 20 49 66 20 6c 69 73 74 50  turned. If listP
5bf0: 74 72 20 69 73 20 6e 6f 74 20 61 20 6c 69 73 74  tr is not a list
5c00: 20 6f 62 6a 65 63 74 2c 20 61 6e 20 61 74 74 65   object, an atte
5c10: 6d 70 74 0a 20 2a 09 77 69 6c 6c 20 62 65 20 6d  mpt. *.will be m
5c20: 61 64 65 20 74 6f 20 63 6f 6e 76 65 72 74 20 69  ade to convert i
5c30: 74 20 74 6f 20 61 20 6c 69 73 74 2e 0a 20 2a 0a  t to a list.. *.
5c40: 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 54   * Results:. *.T
5c50: 68 65 20 72 65 74 75 72 6e 20 76 61 6c 75 65 20  he return value 
5c60: 69 73 20 6e 6f 72 6d 61 6c 6c 79 20 54 43 4c 5f  is normally TCL_
5c70: 4f 4b 3b 20 69 6e 20 74 68 69 73 20 63 61 73 65  OK; in this case
5c80: 20 6f 62 6a 50 74 72 50 74 72 20 69 73 20 73 65   objPtrPtr is se
5c90: 74 20 74 6f 0a 20 2a 09 74 68 65 20 54 63 6c 5f  t to. *.the Tcl_
5ca0: 4f 62 6a 20 70 6f 69 6e 74 65 72 20 66 6f 72 20  Obj pointer for 
5cb0: 74 68 65 20 69 6e 64 65 78 27 74 68 20 6c 69 73  the index'th lis
5cc0: 74 20 65 6c 65 6d 65 6e 74 20 6f 72 20 4e 55 4c  t element or NUL
5cd0: 4c 20 69 66 20 69 6e 64 65 78 20 69 73 0a 20 2a  L if index is. *
5ce0: 09 6f 75 74 20 6f 66 20 72 61 6e 67 65 2e 20 54  .out of range. T
5cf0: 68 69 73 20 6f 62 6a 65 63 74 20 73 68 6f 75 6c  his object shoul
5d00: 64 20 62 65 20 74 72 65 61 74 65 64 20 61 73 20  d be treated as 
5d10: 72 65 61 64 6f 6e 6c 79 20 61 6e 64 20 69 74 73  readonly and its
5d20: 20 72 65 66 0a 20 2a 09 63 6f 75 6e 74 20 69 73   ref. *.count is
5d30: 20 5f 6e 6f 74 5f 20 69 6e 63 72 65 6d 65 6e 74   _not_ increment
5d40: 65 64 3b 20 74 68 65 20 63 61 6c 6c 65 72 20 6d  ed; the caller m
5d50: 75 73 74 20 64 6f 20 74 68 61 74 20 69 66 20 69  ust do that if i
5d60: 74 20 68 6f 6c 64 73 20 6f 6e 20 74 6f 0a 20 2a  t holds on to. *
5d70: 09 74 68 65 20 72 65 66 65 72 65 6e 63 65 2e 20  .the reference. 
5d80: 49 66 20 6c 69 73 74 50 74 72 20 64 6f 65 73 20  If listPtr does 
5d90: 6e 6f 74 20 72 65 66 65 72 20 74 6f 20 61 20 6c  not refer to a l
5da0: 69 73 74 20 61 6e 64 20 63 61 6e 27 74 20 62 65  ist and can't be
5db0: 0a 20 2a 09 63 6f 6e 76 65 72 74 65 64 20 74 6f  . *.converted to
5dc0: 20 6f 6e 65 2c 20 54 43 4c 5f 45 52 52 4f 52 20   one, TCL_ERROR 
5dd0: 69 73 20 72 65 74 75 72 6e 65 64 20 61 6e 64 20  is returned and 
5de0: 61 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65  an error message
5df0: 20 69 73 20 6c 65 66 74 0a 20 2a 09 69 6e 20 74   is left. *.in t
5e00: 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 27 73  he interpreter's
5e10: 20 72 65 73 75 6c 74 20 69 66 20 69 6e 74 65 72   result if inter
5e20: 70 20 69 73 20 6e 6f 74 20 4e 55 4c 4c 2e 0a 20  p is not NULL.. 
5e30: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74  *. * Side effect
5e40: 73 3a 0a 20 2a 09 6c 69 73 74 50 74 72 20 77 69  s:. *.listPtr wi
5e50: 6c 6c 20 62 65 20 63 6f 6e 76 65 72 74 65 64 2c  ll be converted,
5e60: 20 69 66 20 6e 65 63 65 73 73 61 72 79 2c 20 74   if necessary, t
5e70: 6f 20 61 20 6c 69 73 74 20 6f 62 6a 65 63 74 2e  o a list object.
5e80: 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *. *----------
5e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5ec0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f  ------------. */
5ed0: 0a 0a 69 6e 74 0a 54 63 6c 5f 4c 69 73 74 4f 62  ..int.Tcl_ListOb
5ee0: 6a 49 6e 64 65 78 28 0a 20 20 20 20 54 63 6c 5f  jIndex(.    Tcl_
5ef0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 09  Interp *interp,.
5f00: 09 2f 2a 20 55 73 65 64 20 74 6f 20 72 65 70 6f  ./* Used to repo
5f10: 72 74 20 65 72 72 6f 72 73 20 69 66 20 6e 6f 74  rt errors if not
5f20: 20 4e 55 4c 4c 2e 20 2a 2f 0a 20 20 20 20 54 63   NULL. */.    Tc
5f30: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 2c 09  l_Obj *listPtr,.
5f40: 2f 2a 20 4c 69 73 74 20 6f 62 6a 65 63 74 20 74  /* List object t
5f50: 6f 20 69 6e 64 65 78 20 69 6e 74 6f 2e 20 2a 2f  o index into. */
5f60: 0a 20 20 20 20 69 6e 74 20 69 6e 64 65 78 2c 09  .    int index,.
5f70: 09 2f 2a 20 49 6e 64 65 78 20 6f 66 20 65 6c 65  ./* Index of ele
5f80: 6d 65 6e 74 20 74 6f 20 72 65 74 75 72 6e 2e 20  ment to return. 
5f90: 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a  */.    Tcl_Obj *
5fa0: 2a 6f 62 6a 50 74 72 50 74 72 29 09 2f 2a 20 54  *objPtrPtr)./* T
5fb0: 68 65 20 72 65 73 75 6c 74 69 6e 67 20 54 63 6c  he resulting Tcl
5fc0: 5f 4f 62 6a 2a 20 69 73 20 73 74 6f 72 65 64 20  _Obj* is stored 
5fd0: 68 65 72 65 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c  here. */.{.    L
5fe0: 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b  ist *listRepPtr;
5ff0: 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74  ..    ListGetInt
6000: 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73  Rep(listPtr, lis
6010: 74 52 65 70 50 74 72 29 3b 0a 20 20 20 20 69 66  tRepPtr);.    if
6020: 20 28 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20   (listRepPtr == 
6030: 4e 55 4c 4c 29 20 7b 0a 09 69 6e 74 20 72 65 73  NULL) {..int res
6040: 75 6c 74 2c 20 6c 65 6e 67 74 68 3b 0a 0a 09 28  ult, length;...(
6050: 76 6f 69 64 29 20 54 63 6c 5f 47 65 74 53 74 72  void) Tcl_GetStr
6060: 69 6e 67 46 72 6f 6d 4f 62 6a 28 6c 69 73 74 50  ingFromObj(listP
6070: 74 72 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09 69  tr, &length);..i
6080: 66 20 28 6c 65 6e 67 74 68 20 3d 3d 20 30 29 20  f (length == 0) 
6090: 7b 0a 09 20 20 20 20 2a 6f 62 6a 50 74 72 50 74  {..    *objPtrPt
60a0: 72 20 3d 20 4e 55 4c 4c 3b 0a 09 20 20 20 20 72  r = NULL;..    r
60b0: 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 09 7d  eturn TCL_OK;..}
60c0: 0a 09 72 65 73 75 6c 74 20 3d 20 53 65 74 4c 69  ..result = SetLi
60d0: 73 74 46 72 6f 6d 41 6e 79 28 69 6e 74 65 72 70  stFromAny(interp
60e0: 2c 20 6c 69 73 74 50 74 72 29 3b 0a 09 69 66 20  , listPtr);..if 
60f0: 28 72 65 73 75 6c 74 20 21 3d 20 54 43 4c 5f 4f  (result != TCL_O
6100: 4b 29 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e  K) {..    return
6110: 20 72 65 73 75 6c 74 3b 0a 09 7d 0a 09 4c 69 73   result;..}..Lis
6120: 74 47 65 74 49 6e 74 52 65 70 28 6c 69 73 74 50  tGetIntRep(listP
6130: 74 72 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b  tr, listRepPtr);
6140: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28  .    }..    if (
6150: 28 69 6e 64 65 78 20 3c 20 30 29 20 7c 7c 20 28  (index < 0) || (
6160: 69 6e 64 65 78 20 3e 3d 20 6c 69 73 74 52 65 70  index >= listRep
6170: 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 29 29  Ptr->elemCount))
6180: 20 7b 0a 09 2a 6f 62 6a 50 74 72 50 74 72 20 3d   {..*objPtrPtr =
6190: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 20 65 6c 73   NULL;.    } els
61a0: 65 20 7b 0a 09 2a 6f 62 6a 50 74 72 50 74 72 20  e {..*objPtrPtr 
61b0: 3d 20 28 26 6c 69 73 74 52 65 70 50 74 72 2d 3e  = (&listRepPtr->
61c0: 65 6c 65 6d 65 6e 74 73 29 5b 69 6e 64 65 78 5d  elements)[index]
61d0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 74  ;.    }..    ret
61e0: 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a  urn TCL_OK;.}...
61f0: 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  /*. *-----------
6200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20  -----------. *. 
6240: 2a 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 4c 65 6e  * Tcl_ListObjLen
6250: 67 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69  gth --. *. *.Thi
6260: 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72  s function retur
6270: 6e 73 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66  ns the number of
6280: 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61 20 6c   elements in a l
6290: 69 73 74 20 6f 62 6a 65 63 74 2e 20 49 66 20 74  ist object. If t
62a0: 68 65 0a 20 2a 09 6f 62 6a 65 63 74 20 69 73 20  he. *.object is 
62b0: 6e 6f 74 20 61 6c 72 65 61 64 79 20 61 20 6c 69  not already a li
62c0: 73 74 20 6f 62 6a 65 63 74 2c 20 61 6e 20 61 74  st object, an at
62d0: 74 65 6d 70 74 20 77 69 6c 6c 20 62 65 20 6d 61  tempt will be ma
62e0: 64 65 20 74 6f 0a 20 2a 09 63 6f 6e 76 65 72 74  de to. *.convert
62f0: 20 69 74 20 74 6f 20 6f 6e 65 2e 0a 20 2a 0a 20   it to one.. *. 
6300: 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 54 68  * Results:. *.Th
6310: 65 20 72 65 74 75 72 6e 20 76 61 6c 75 65 20 69  e return value i
6320: 73 20 6e 6f 72 6d 61 6c 6c 79 20 54 43 4c 5f 4f  s normally TCL_O
6330: 4b 3b 20 69 6e 20 74 68 69 73 20 63 61 73 65 20  K; in this case 
6340: 2a 69 6e 74 50 74 72 20 77 69 6c 6c 20 62 65 20  *intPtr will be 
6350: 73 65 74 0a 20 2a 09 74 6f 20 74 68 65 20 69 6e  set. *.to the in
6360: 74 65 67 65 72 20 63 6f 75 6e 74 20 6f 66 20 6c  teger count of l
6370: 69 73 74 20 65 6c 65 6d 65 6e 74 73 2e 20 49 66  ist elements. If
6380: 20 6c 69 73 74 50 74 72 20 64 6f 65 73 20 6e 6f   listPtr does no
6390: 74 20 72 65 66 65 72 20 74 6f 20 61 0a 20 2a 09  t refer to a. *.
63a0: 6c 69 73 74 20 6f 62 6a 65 63 74 20 61 6e 64 20  list object and 
63b0: 74 68 65 20 6f 62 6a 65 63 74 20 63 61 6e 20 6e  the object can n
63c0: 6f 74 20 62 65 20 63 6f 6e 76 65 72 74 65 64 20  ot be converted 
63d0: 74 6f 20 6f 6e 65 2c 20 54 43 4c 5f 45 52 52 4f  to one, TCL_ERRO
63e0: 52 20 69 73 0a 20 2a 09 72 65 74 75 72 6e 65 64  R is. *.returned
63f0: 20 61 6e 64 20 61 6e 20 65 72 72 6f 72 20 6d 65   and an error me
6400: 73 73 61 67 65 20 77 69 6c 6c 20 62 65 20 6c 65  ssage will be le
6410: 66 74 20 69 6e 20 74 68 65 20 69 6e 74 65 72 70  ft in the interp
6420: 72 65 74 65 72 27 73 20 72 65 73 75 6c 74 0a 20  reter's result. 
6430: 2a 09 69 66 20 69 6e 74 65 72 70 20 69 73 20 6e  *.if interp is n
6440: 6f 74 20 4e 55 4c 4c 2e 0a 20 2a 0a 20 2a 20 53  ot NULL.. *. * S
6450: 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09  ide effects:. *.
6460: 54 68 65 20 70 6f 73 73 69 62 6c 65 20 63 6f 6e  The possible con
6470: 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 61  version of the a
6480: 72 67 75 6d 65 6e 74 20 6f 62 6a 65 63 74 20 74  rgument object t
6490: 6f 20 61 20 6c 69 73 74 20 6f 62 6a 65 63 74 2e  o a list object.
64a0: 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *. *----------
64b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
64c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
64d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
64e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f  ------------. */
64f0: 0a 0a 69 6e 74 0a 54 63 6c 5f 4c 69 73 74 4f 62  ..int.Tcl_ListOb
6500: 6a 4c 65 6e 67 74 68 28 0a 20 20 20 20 54 63 6c  jLength(.    Tcl
6510: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
6520: 09 09 2f 2a 20 55 73 65 64 20 74 6f 20 72 65 70  ../* Used to rep
6530: 6f 72 74 20 65 72 72 6f 72 73 20 69 66 20 6e 6f  ort errors if no
6540: 74 20 4e 55 4c 4c 2e 20 2a 2f 0a 20 20 20 20 54  t NULL. */.    T
6550: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 2c  cl_Obj *listPtr,
6560: 09 2f 2a 20 4c 69 73 74 20 6f 62 6a 65 63 74 20  ./* List object 
6570: 77 68 6f 73 65 20 23 65 6c 65 6d 65 6e 74 73 20  whose #elements 
6580: 74 6f 20 72 65 74 75 72 6e 2e 20 2a 2f 0a 20 20  to return. */.  
6590: 20 20 69 6e 74 20 2a 69 6e 74 50 74 72 29 09 2f    int *intPtr)./
65a0: 2a 20 54 68 65 20 72 65 73 75 6c 74 69 6e 67 20  * The resulting 
65b0: 69 6e 74 20 69 73 20 73 74 6f 72 65 64 20 68 65  int is stored he
65c0: 72 65 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c 69 73  re. */.{.    Lis
65d0: 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a 0a  t *listRepPtr;..
65e0: 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65      ListGetIntRe
65f0: 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52  p(listPtr, listR
6600: 65 70 50 74 72 29 3b 0a 20 20 20 20 69 66 20 28  epPtr);.    if (
6610: 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20 4e 55  listRepPtr == NU
6620: 4c 4c 29 20 7b 0a 09 69 6e 74 20 72 65 73 75 6c  LL) {..int resul
6630: 74 2c 20 6c 65 6e 67 74 68 3b 0a 0a 09 28 76 6f  t, length;...(vo
6640: 69 64 29 20 54 63 6c 5f 47 65 74 53 74 72 69 6e  id) Tcl_GetStrin
6650: 67 46 72 6f 6d 4f 62 6a 28 6c 69 73 74 50 74 72  gFromObj(listPtr
6660: 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09 69 66 20  , &length);..if 
6670: 28 6c 65 6e 67 74 68 20 3d 3d 20 30 29 20 7b 0a  (length == 0) {.
6680: 09 20 20 20 20 2a 69 6e 74 50 74 72 20 3d 20 30  .    *intPtr = 0
6690: 3b 0a 09 20 20 20 20 72 65 74 75 72 6e 20 54 43  ;..    return TC
66a0: 4c 5f 4f 4b 3b 0a 09 7d 0a 09 72 65 73 75 6c 74  L_OK;..}..result
66b0: 20 3d 20 53 65 74 4c 69 73 74 46 72 6f 6d 41 6e   = SetListFromAn
66c0: 79 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  y(interp, listPt
66d0: 72 29 3b 0a 09 69 66 20 28 72 65 73 75 6c 74 20  r);..if (result 
66e0: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 20 20  != TCL_OK) {..  
66f0: 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 3b    return result;
6700: 0a 09 7d 0a 09 4c 69 73 74 47 65 74 49 6e 74 52  ..}..ListGetIntR
6710: 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74  ep(listPtr, list
6720: 52 65 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 0a  RepPtr);.    }..
6730: 20 20 20 20 2a 69 6e 74 50 74 72 20 3d 20 6c 69      *intPtr = li
6740: 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43 6f  stRepPtr->elemCo
6750: 75 6e 74 3b 0a 20 20 20 20 72 65 74 75 72 6e 20  unt;.    return 
6760: 54 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a 2f 2a 0a 20  TCL_OK;.}.../*. 
6770: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *---------------
6780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
67a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
67b0: 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63  -------. *. * Tc
67c0: 6c 5f 4c 69 73 74 4f 62 6a 52 65 70 6c 61 63 65  l_ListObjReplace
67d0: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66   --. *. *.This f
67e0: 75 6e 63 74 69 6f 6e 20 72 65 70 6c 61 63 65 73  unction replaces
67f0: 20 7a 65 72 6f 20 6f 72 20 6d 6f 72 65 20 65 6c   zero or more el
6800: 65 6d 65 6e 74 73 20 6f 66 20 74 68 65 20 6c 69  ements of the li
6810: 73 74 20 72 65 66 65 72 65 6e 63 65 64 20 62 79  st referenced by
6820: 0a 20 2a 09 6c 69 73 74 50 74 72 20 77 69 74 68  . *.listPtr with
6830: 20 74 68 65 20 6f 62 6a 65 63 74 73 20 66 72 6f   the objects fro
6840: 6d 20 61 6e 20 28 6f 62 6a 63 2c 6f 62 6a 76 29  m an (objc,objv)
6850: 20 61 72 72 61 79 2e 20 54 68 65 20 6f 62 6a 63   array. The objc
6860: 20 65 6c 65 6d 65 6e 74 73 0a 20 2a 09 6f 66 20   elements. *.of 
6870: 74 68 65 20 61 72 72 61 79 20 72 65 66 65 72 65  the array refere
6880: 6e 63 65 64 20 62 79 20 6f 62 6a 76 20 72 65 70  nced by objv rep
6890: 6c 61 63 65 20 74 68 65 20 63 6f 75 6e 74 20 65  lace the count e
68a0: 6c 65 6d 65 6e 74 73 20 69 6e 20 6c 69 73 74 50  lements in listP
68b0: 74 72 0a 20 2a 09 73 74 61 72 74 69 6e 67 20 61  tr. *.starting a
68c0: 74 20 66 69 72 73 74 2e 0a 20 2a 0a 20 2a 09 49  t first.. *. *.I
68d0: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 66  f the argument f
68e0: 69 72 73 74 20 69 73 20 7a 65 72 6f 20 6f 72 20  irst is zero or 
68f0: 6e 65 67 61 74 69 76 65 2c 20 69 74 20 72 65 66  negative, it ref
6900: 65 72 73 20 74 6f 20 74 68 65 20 66 69 72 73 74  ers to the first
6910: 0a 20 2a 09 65 6c 65 6d 65 6e 74 2e 20 49 66 20  . *.element. If 
6920: 66 69 72 73 74 20 69 73 20 67 72 65 61 74 65 72  first is greater
6930: 20 74 68 61 6e 20 6f 72 20 65 71 75 61 6c 20 74   than or equal t
6940: 6f 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20  o the number of 
6950: 65 6c 65 6d 65 6e 74 73 0a 20 2a 09 69 6e 20 74  elements. *.in t
6960: 68 65 20 6c 69 73 74 2c 20 74 68 65 6e 20 6e 6f  he list, then no
6970: 20 65 6c 65 6d 65 6e 74 73 20 61 72 65 20 64 65   elements are de
6980: 6c 65 74 65 64 3b 20 74 68 65 20 6e 65 77 20 65  leted; the new e
6990: 6c 65 6d 65 6e 74 73 20 61 72 65 0a 20 2a 09 61  lements are. *.a
69a0: 70 70 65 6e 64 65 64 20 74 6f 20 74 68 65 20 6c  ppended to the l
69b0: 69 73 74 2e 20 43 6f 75 6e 74 20 67 69 76 65 73  ist. Count gives
69c0: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 65   the number of e
69d0: 6c 65 6d 65 6e 74 73 20 74 6f 20 72 65 70 6c 61  lements to repla
69e0: 63 65 2e 0a 20 2a 09 49 66 20 63 6f 75 6e 74 20  ce.. *.If count 
69f0: 69 73 20 7a 65 72 6f 20 6f 72 20 6e 65 67 61 74  is zero or negat
6a00: 69 76 65 20 74 68 65 6e 20 6e 6f 20 65 6c 65 6d  ive then no elem
6a10: 65 6e 74 73 20 61 72 65 20 64 65 6c 65 74 65 64  ents are deleted
6a20: 3b 20 74 68 65 20 6e 65 77 0a 20 2a 09 65 6c 65  ; the new. *.ele
6a30: 6d 65 6e 74 73 20 61 72 65 20 73 69 6d 70 6c 79  ments are simply
6a40: 20 69 6e 73 65 72 74 65 64 20 62 65 66 6f 72 65   inserted before
6a50: 20 66 69 72 73 74 2e 0a 20 2a 0a 20 2a 09 54 68   first.. *. *.Th
6a60: 65 20 61 72 67 75 6d 65 6e 74 20 6f 62 6a 76 20  e argument objv 
6a70: 72 65 66 65 72 73 20 74 6f 20 61 6e 20 61 72 72  refers to an arr
6a80: 61 79 20 6f 66 20 6f 62 6a 63 20 70 6f 69 6e 74  ay of objc point
6a90: 65 72 73 20 74 6f 20 74 68 65 20 6e 65 77 0a 20  ers to the new. 
6aa0: 2a 09 65 6c 65 6d 65 6e 74 73 20 74 6f 20 62 65  *.elements to be
6ab0: 20 61 64 64 65 64 20 74 6f 20 6c 69 73 74 50 74   added to listPt
6ac0: 72 20 69 6e 20 70 6c 61 63 65 20 6f 66 20 74 68  r in place of th
6ad0: 6f 73 65 20 74 68 61 74 20 77 65 72 65 20 64 65  ose that were de
6ae0: 6c 65 74 65 64 2e 0a 20 2a 09 49 66 20 6f 62 6a  leted.. *.If obj
6af0: 76 20 69 73 20 4e 55 4c 4c 2c 20 6e 6f 20 6e 65  v is NULL, no ne
6b00: 77 20 65 6c 65 6d 65 6e 74 73 20 61 72 65 20 61  w elements are a
6b10: 64 64 65 64 2e 20 49 66 20 6c 69 73 74 50 74 72  dded. If listPtr
6b20: 20 69 73 20 6e 6f 74 20 61 20 6c 69 73 74 0a 20   is not a list. 
6b30: 2a 09 6f 62 6a 65 63 74 2c 20 61 6e 20 61 74 74  *.object, an att
6b40: 65 6d 70 74 20 77 69 6c 6c 20 62 65 20 6d 61 64  empt will be mad
6b50: 65 20 74 6f 20 63 6f 6e 76 65 72 74 20 69 74 20  e to convert it 
6b60: 74 6f 20 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 52 65  to one.. *. * Re
6b70: 73 75 6c 74 73 3a 0a 20 2a 09 54 68 65 20 72 65  sults:. *.The re
6b80: 74 75 72 6e 20 76 61 6c 75 65 20 69 73 20 6e 6f  turn value is no
6b90: 72 6d 61 6c 6c 79 20 54 43 4c 5f 4f 4b 2e 20 49  rmally TCL_OK. I
6ba0: 66 20 6c 69 73 74 50 74 72 20 64 6f 65 73 20 6e  f listPtr does n
6bb0: 6f 74 20 72 65 66 65 72 20 74 6f 20 61 0a 20 2a  ot refer to a. *
6bc0: 09 6c 69 73 74 20 6f 62 6a 65 63 74 20 61 6e 64  .list object and
6bd0: 20 63 61 6e 20 6e 6f 74 20 62 65 20 63 6f 6e 76   can not be conv
6be0: 65 72 74 65 64 20 74 6f 20 6f 6e 65 2c 20 54 43  erted to one, TC
6bf0: 4c 5f 45 52 52 4f 52 20 69 73 20 72 65 74 75 72  L_ERROR is retur
6c00: 6e 65 64 20 61 6e 64 0a 20 2a 09 61 6e 20 65 72  ned and. *.an er
6c10: 72 6f 72 20 6d 65 73 73 61 67 65 20 77 69 6c 6c  ror message will
6c20: 20 62 65 20 6c 65 66 74 20 69 6e 20 74 68 65 20   be left in the 
6c30: 69 6e 74 65 72 70 72 65 74 65 72 27 73 20 72 65  interpreter's re
6c40: 73 75 6c 74 20 69 66 20 69 6e 74 65 72 70 20 69  sult if interp i
6c50: 73 0a 20 2a 09 6e 6f 74 20 4e 55 4c 4c 2e 0a 20  s. *.not NULL.. 
6c60: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74  *. * Side effect
6c70: 73 3a 0a 20 2a 09 54 68 65 20 72 65 66 20 63 6f  s:. *.The ref co
6c80: 75 6e 74 73 20 6f 66 20 74 68 65 20 6f 62 6a 63  unts of the objc
6c90: 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 6f 62 6a   elements in obj
6ca0: 76 20 61 72 65 20 69 6e 63 72 65 6d 65 6e 74 65  v are incremente
6cb0: 64 20 73 69 6e 63 65 20 74 68 65 0a 20 2a 09 72  d since the. *.r
6cc0: 65 73 75 6c 74 69 6e 67 20 6c 69 73 74 20 6e 6f  esulting list no
6cd0: 77 20 72 65 66 65 72 73 20 74 6f 20 74 68 65 6d  w refers to them
6ce0: 2e 20 53 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65  . Similarly, the
6cf0: 20 72 65 66 20 63 6f 75 6e 74 73 20 66 6f 72 0a   ref counts for.
6d00: 20 2a 09 72 65 70 6c 61 63 65 64 20 6f 62 6a 65   *.replaced obje
6d10: 63 74 73 20 61 72 65 20 64 65 63 72 65 6d 65 6e  cts are decremen
6d20: 74 65 64 2e 20 6c 69 73 74 50 74 72 20 69 73 20  ted. listPtr is 
6d30: 63 6f 6e 76 65 72 74 65 64 2c 20 69 66 20 6e 65  converted, if ne
6d40: 63 65 73 73 61 72 79 2c 0a 20 2a 09 74 6f 20 61  cessary,. *.to a
6d50: 20 6c 69 73 74 20 6f 62 6a 65 63 74 2e 20 6c 69   list object. li
6d60: 73 74 50 74 72 27 73 20 6f 6c 64 20 73 74 72 69  stPtr's old stri
6d70: 6e 67 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f  ng representatio
6d80: 6e 2c 20 69 66 20 61 6e 79 2c 20 69 73 0a 20 2a  n, if any, is. *
6d90: 09 66 72 65 65 64 2e 0a 20 2a 0a 20 2a 2d 2d 2d  .freed.. *. *---
6da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6de0: 2d 2d 2d 0a 20 2a 2f 0a 0a 69 6e 74 0a 54 63 6c  ---. */..int.Tcl
6df0: 5f 4c 69 73 74 4f 62 6a 52 65 70 6c 61 63 65 28  _ListObjReplace(
6e00: 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65 72 70 20  .    Tcl_Interp 
6e10: 2a 69 6e 74 65 72 70 2c 09 09 2f 2a 20 55 73 65  *interp,../* Use
6e20: 64 20 66 6f 72 20 65 72 72 6f 72 20 72 65 70 6f  d for error repo
6e30: 72 74 69 6e 67 20 69 66 20 6e 6f 74 20 4e 55 4c  rting if not NUL
6e40: 4c 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62  L. */.    Tcl_Ob
6e50: 6a 20 2a 6c 69 73 74 50 74 72 2c 09 09 2f 2a 20  j *listPtr,../* 
6e60: 4c 69 73 74 20 6f 62 6a 65 63 74 20 77 68 6f 73  List object whos
6e70: 65 20 65 6c 65 6d 65 6e 74 73 20 74 6f 20 72 65  e elements to re
6e80: 70 6c 61 63 65 2e 20 2a 2f 0a 20 20 20 20 69 6e  place. */.    in
6e90: 74 20 66 69 72 73 74 2c 09 09 09 2f 2a 20 49 6e  t first,.../* In
6ea0: 64 65 78 20 6f 66 20 66 69 72 73 74 20 65 6c 65  dex of first ele
6eb0: 6d 65 6e 74 20 74 6f 20 72 65 70 6c 61 63 65 2e  ment to replace.
6ec0: 20 2a 2f 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e   */.    int coun
6ed0: 74 2c 09 09 09 2f 2a 20 4e 75 6d 62 65 72 20 6f  t,.../* Number o
6ee0: 66 20 65 6c 65 6d 65 6e 74 73 20 74 6f 20 72 65  f elements to re
6ef0: 70 6c 61 63 65 2e 20 2a 2f 0a 20 20 20 20 69 6e  place. */.    in
6f00: 74 20 6f 62 6a 63 2c 09 09 09 2f 2a 20 4e 75 6d  t objc,.../* Num
6f10: 62 65 72 20 6f 66 20 6f 62 6a 65 63 74 73 20 74  ber of objects t
6f20: 6f 20 69 6e 73 65 72 74 2e 20 2a 2f 0a 20 20 20  o insert. */.   
6f30: 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20   Tcl_Obj *const 
6f40: 6f 62 6a 76 5b 5d 29 09 2f 2a 20 41 6e 20 61 72  objv[])./* An ar
6f50: 72 61 79 20 6f 66 20 6f 62 6a 63 20 70 6f 69 6e  ray of objc poin
6f60: 74 65 72 73 20 74 6f 20 54 63 6c 20 6f 62 6a 65  ters to Tcl obje
6f70: 63 74 73 20 74 6f 0a 09 09 09 09 20 2a 20 69 6e  cts to..... * in
6f80: 73 65 72 74 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c  sert. */.{.    L
6f90: 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b  ist *listRepPtr;
6fa0: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 2a 65  .    Tcl_Obj **e
6fb0: 6c 65 6d 50 74 72 73 3b 0a 20 20 20 20 69 6e 74  lemPtrs;.    int
6fc0: 20 6e 65 65 64 47 72 6f 77 2c 20 6e 75 6d 45 6c   needGrow, numEl
6fd0: 65 6d 73 2c 20 6e 75 6d 52 65 71 75 69 72 65 64  ems, numRequired
6fe0: 2c 20 6e 75 6d 41 66 74 65 72 4c 61 73 74 2c 20  , numAfterLast, 
6ff0: 73 74 61 72 74 2c 20 69 2c 20 6a 2c 20 69 73 53  start, i, j, isS
7000: 68 61 72 65 64 3b 0a 0a 20 20 20 20 69 66 20 28  hared;..    if (
7010: 54 63 6c 5f 49 73 53 68 61 72 65 64 28 6c 69 73  Tcl_IsShared(lis
7020: 74 50 74 72 29 29 20 7b 0a 09 54 63 6c 5f 50 61  tPtr)) {..Tcl_Pa
7030: 6e 69 63 28 22 25 73 20 63 61 6c 6c 65 64 20 77  nic("%s called w
7040: 69 74 68 20 73 68 61 72 65 64 20 6f 62 6a 65 63  ith shared objec
7050: 74 22 2c 20 22 54 63 6c 5f 4c 69 73 74 4f 62 6a  t", "Tcl_ListObj
7060: 52 65 70 6c 61 63 65 22 29 3b 0a 20 20 20 20 7d  Replace");.    }
7070: 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74  ..    ListGetInt
7080: 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73  Rep(listPtr, lis
7090: 74 52 65 70 50 74 72 29 3b 0a 20 20 20 20 69 66  tRepPtr);.    if
70a0: 20 28 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20   (listRepPtr == 
70b0: 4e 55 4c 4c 29 20 7b 0a 09 69 6e 74 20 6c 65 6e  NULL) {..int len
70c0: 67 74 68 3b 0a 0a 09 28 76 6f 69 64 29 20 54 63  gth;...(void) Tc
70d0: 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f  l_GetStringFromO
70e0: 62 6a 28 6c 69 73 74 50 74 72 2c 20 26 6c 65 6e  bj(listPtr, &len
70f0: 67 74 68 29 3b 0a 09 69 66 20 28 6c 65 6e 67 74  gth);..if (lengt
7100: 68 20 3d 3d 20 30 29 20 7b 0a 09 20 20 20 20 69  h == 0) {..    i
7110: 66 20 28 6f 62 6a 63 20 3d 3d 20 30 29 20 7b 0a  f (objc == 0) {.
7120: 09 09 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b  ..return TCL_OK;
7130: 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 54 63 6c  ..    }..    Tcl
7140: 5f 53 65 74 4c 69 73 74 4f 62 6a 28 6c 69 73 74  _SetListObj(list
7150: 50 74 72 2c 20 6f 62 6a 63 2c 20 4e 55 4c 4c 29  Ptr, objc, NULL)
7160: 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20  ;..} else {..   
7170: 20 69 6e 74 20 72 65 73 75 6c 74 20 3d 20 53 65   int result = Se
7180: 74 4c 69 73 74 46 72 6f 6d 41 6e 79 28 69 6e 74  tListFromAny(int
7190: 65 72 70 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a  erp, listPtr);..
71a0: 09 20 20 20 20 69 66 20 28 72 65 73 75 6c 74 20  .    if (result 
71b0: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 72  != TCL_OK) {...r
71c0: 65 74 75 72 6e 20 72 65 73 75 6c 74 3b 0a 09 20  eturn result;.. 
71d0: 20 20 20 7d 0a 09 7d 0a 09 4c 69 73 74 47 65 74     }..}..ListGet
71e0: 49 6e 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20  IntRep(listPtr, 
71f0: 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20  listRepPtr);.   
7200: 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20   }..    /*.     
7210: 2a 20 4e 6f 74 65 20 74 68 61 74 20 77 68 65 6e  * Note that when
7220: 20 63 6f 75 6e 74 20 3d 3d 20 30 20 61 6e 64 20   count == 0 and 
7230: 6f 62 6a 63 20 3d 3d 20 30 2c 20 74 68 69 73 20  objc == 0, this 
7240: 72 6f 75 74 69 6e 65 20 69 73 20 6c 6f 67 69 63  routine is logic
7250: 61 6c 6c 79 20 61 0a 20 20 20 20 20 2a 20 6e 6f  ally a.     * no
7260: 2d 6f 70 2c 20 72 65 6d 6f 76 69 6e 67 20 61 6e  -op, removing an
7270: 64 20 61 64 64 69 6e 67 20 6e 6f 20 65 6c 65 6d  d adding no elem
7280: 65 6e 74 73 20 74 6f 20 74 68 65 20 6c 69 73 74  ents to the list
7290: 2e 20 48 6f 77 65 76 65 72 2c 20 62 79 20 66 6c  . However, by fl
72a0: 6f 77 69 6e 67 0a 20 20 20 20 20 2a 20 74 68 72  owing.     * thr
72b0: 6f 75 67 68 20 74 68 69 73 20 72 6f 75 74 69 6e  ough this routin
72c0: 65 20 61 6e 79 77 61 79 2c 20 77 65 20 67 65 74  e anyway, we get
72d0: 20 74 68 65 20 69 6d 70 6f 72 74 61 6e 74 20 73   the important s
72e0: 69 64 65 20 65 66 66 65 63 74 20 74 68 61 74 20  ide effect that 
72f0: 74 68 65 0a 20 20 20 20 20 2a 20 72 65 73 75 6c  the.     * resul
7300: 74 69 6e 67 20 6c 69 73 74 50 74 72 20 69 73 20  ting listPtr is 
7310: 61 20 6c 69 73 74 20 69 6e 20 63 61 6e 6f 6e 63  a list in canonc
7320: 69 61 6c 20 66 6f 72 6d 2e 20 54 68 69 73 20 69  ial form. This i
7330: 73 20 69 6d 70 6f 72 74 61 6e 74 2e 0a 20 20 20  s important..   
7340: 20 20 2a 20 52 65 73 69 73 74 20 61 6e 79 20 74    * Resist any t
7350: 65 6d 70 74 61 74 69 6f 6e 20 74 6f 20 6f 70 74  emptation to opt
7360: 69 6d 69 7a 65 20 74 68 69 73 20 63 61 73 65 2e  imize this case.
7370: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 65 6c  .     */..    el
7380: 65 6d 50 74 72 73 20 3d 20 26 6c 69 73 74 52 65  emPtrs = &listRe
7390: 70 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a  pPtr->elements;.
73a0: 20 20 20 20 6e 75 6d 45 6c 65 6d 73 20 3d 20 6c      numElems = l
73b0: 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43  istRepPtr->elemC
73c0: 6f 75 6e 74 3b 0a 0a 20 20 20 20 69 66 20 28 66  ount;..    if (f
73d0: 69 72 73 74 20 3c 20 30 29 20 7b 0a 09 66 69 72  irst < 0) {..fir
73e0: 73 74 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20  st = 0;.    }.  
73f0: 20 20 69 66 20 28 66 69 72 73 74 20 3e 3d 20 6e    if (first >= n
7400: 75 6d 45 6c 65 6d 73 29 20 7b 0a 09 66 69 72 73  umElems) {..firs
7410: 74 20 3d 20 6e 75 6d 45 6c 65 6d 73 3b 09 2f 2a  t = numElems;./*
7420: 20 53 6f 20 77 65 27 6c 6c 20 69 6e 73 65 72 74   So we'll insert
7430: 20 61 66 74 65 72 20 6c 61 73 74 20 65 6c 65 6d   after last elem
7440: 65 6e 74 2e 20 2a 2f 0a 20 20 20 20 7d 0a 20 20  ent. */.    }.  
7450: 20 20 69 66 20 28 63 6f 75 6e 74 20 3c 20 30 29    if (count < 0)
7460: 20 7b 0a 09 63 6f 75 6e 74 20 3d 20 30 3b 0a 20   {..count = 0;. 
7470: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 66 69     } else if (fi
7480: 72 73 74 20 3e 20 49 4e 54 5f 4d 41 58 20 2d 20  rst > INT_MAX - 
7490: 63 6f 75 6e 74 20 2f 2a 20 48 61 6e 64 6c 65 20  count /* Handle 
74a0: 69 6e 74 65 67 65 72 20 6f 76 65 72 66 6c 6f 77  integer overflow
74b0: 20 2a 2f 0a 09 20 20 20 20 7c 7c 20 6e 75 6d 45   */..    || numE
74c0: 6c 65 6d 73 20 3c 20 66 69 72 73 74 2b 63 6f 75  lems < first+cou
74d0: 6e 74 29 20 7b 0a 0a 09 63 6f 75 6e 74 20 3d 20  nt) {...count = 
74e0: 6e 75 6d 45 6c 65 6d 73 20 2d 20 66 69 72 73 74  numElems - first
74f0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20  ;.    }..    if 
7500: 28 6f 62 6a 63 20 3e 20 4c 49 53 54 5f 4d 41 58  (objc > LIST_MAX
7510: 20 2d 20 28 6e 75 6d 45 6c 65 6d 73 20 2d 20 63   - (numElems - c
7520: 6f 75 6e 74 29 29 20 7b 0a 09 69 66 20 28 69 6e  ount)) {..if (in
7530: 74 65 72 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  terp != NULL) {.
7540: 09 20 20 20 20 54 63 6c 5f 53 65 74 4f 62 6a 52  .    Tcl_SetObjR
7550: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 63  esult(interp, Tc
7560: 6c 5f 4f 62 6a 50 72 69 6e 74 66 28 0a 09 09 20  l_ObjPrintf(... 
7570: 20 20 20 22 6d 61 78 20 6c 65 6e 67 74 68 20 6f     "max length o
7580: 66 20 61 20 54 63 6c 20 6c 69 73 74 20 28 25 64  f a Tcl list (%d
7590: 20 65 6c 65 6d 65 6e 74 73 29 20 65 78 63 65 65   elements) excee
75a0: 64 65 64 22 2c 0a 09 09 20 20 20 20 4c 49 53 54  ded",...    LIST
75b0: 5f 4d 41 58 29 29 3b 0a 09 7d 0a 09 72 65 74 75  _MAX));..}..retu
75c0: 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 20 20  rn TCL_ERROR;.  
75d0: 20 20 7d 0a 20 20 20 20 69 73 53 68 61 72 65 64    }.    isShared
75e0: 20 3d 20 28 6c 69 73 74 52 65 70 50 74 72 2d 3e   = (listRepPtr->
75f0: 72 65 66 43 6f 75 6e 74 20 3e 20 31 29 3b 0a 20  refCount > 1);. 
7600: 20 20 20 6e 75 6d 52 65 71 75 69 72 65 64 20 3d     numRequired =
7610: 20 6e 75 6d 45 6c 65 6d 73 20 2d 20 63 6f 75 6e   numElems - coun
7620: 74 20 2b 20 6f 62 6a 63 3b 20 2f 2a 20 4b 6e 6f  t + objc; /* Kno
7630: 77 6e 20 3c 3d 20 4c 49 53 54 5f 4d 41 58 20 2a  wn <= LIST_MAX *
7640: 2f 0a 20 20 20 20 6e 65 65 64 47 72 6f 77 20 3d  /.    needGrow =
7650: 20 6e 75 6d 52 65 71 75 69 72 65 64 20 3e 20 6c   numRequired > l
7660: 69 73 74 52 65 70 50 74 72 2d 3e 6d 61 78 45 6c  istRepPtr->maxEl
7670: 65 6d 43 6f 75 6e 74 3b 0a 0a 20 20 20 20 66 6f  emCount;..    fo
7680: 72 20 28 69 20 3d 20 30 3b 20 20 69 20 3c 20 6f  r (i = 0;  i < o
7690: 62 6a 63 3b 20 20 69 2b 2b 29 20 7b 0a 09 54 63  bjc;  i++) {..Tc
76a0: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f  l_IncrRefCount(o
76b0: 62 6a 76 5b 69 5d 29 3b 0a 20 20 20 20 7d 0a 0a  bjv[i]);.    }..
76c0: 20 20 20 20 69 66 20 28 6e 65 65 64 47 72 6f 77      if (needGrow
76d0: 20 26 26 20 21 69 73 53 68 61 72 65 64 29 20 7b   && !isShared) {
76e0: 0a 09 2f 2a 20 54 72 79 20 74 6f 20 75 73 65 20  ../* Try to use 
76f0: 72 65 61 6c 6c 6f 63 20 2a 2f 0a 09 4c 69 73 74  realloc */..List
7700: 20 2a 6e 65 77 50 74 72 20 3d 20 4e 55 4c 4c 3b   *newPtr = NULL;
7710: 0a 09 69 6e 74 20 61 74 74 65 6d 70 74 20 3d 20  ..int attempt = 
7720: 32 20 2a 20 6e 75 6d 52 65 71 75 69 72 65 64 3b  2 * numRequired;
7730: 0a 09 69 66 20 28 61 74 74 65 6d 70 74 20 3c 3d  ..if (attempt <=
7740: 20 4c 49 53 54 5f 4d 41 58 29 20 7b 0a 09 20 20   LIST_MAX) {..  
7750: 20 20 6e 65 77 50 74 72 20 3d 20 28 4c 69 73 74    newPtr = (List
7760: 20 2a 29 61 74 74 65 6d 70 74 63 6b 72 65 61 6c   *)attemptckreal
7770: 6c 6f 63 28 6c 69 73 74 52 65 70 50 74 72 2c 20  loc(listRepPtr, 
7780: 4c 49 53 54 5f 53 49 5a 45 28 61 74 74 65 6d 70  LIST_SIZE(attemp
7790: 74 29 29 3b 0a 09 7d 0a 09 69 66 20 28 6e 65 77  t));..}..if (new
77a0: 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09  Ptr == NULL) {..
77b0: 20 20 20 20 61 74 74 65 6d 70 74 20 3d 20 6e 75      attempt = nu
77c0: 6d 52 65 71 75 69 72 65 64 20 2b 20 31 20 2b 20  mRequired + 1 + 
77d0: 54 43 4c 5f 4d 49 4e 5f 45 4c 45 4d 45 4e 54 5f  TCL_MIN_ELEMENT_
77e0: 47 52 4f 57 54 48 3b 0a 09 20 20 20 20 69 66 20  GROWTH;..    if 
77f0: 28 61 74 74 65 6d 70 74 20 3e 20 4c 49 53 54 5f  (attempt > LIST_
7800: 4d 41 58 29 20 7b 0a 09 09 61 74 74 65 6d 70 74  MAX) {...attempt
7810: 20 3d 20 4c 49 53 54 5f 4d 41 58 3b 0a 09 20 20   = LIST_MAX;..  
7820: 20 20 7d 0a 09 20 20 20 20 6e 65 77 50 74 72 20    }..    newPtr 
7830: 3d 20 28 4c 69 73 74 20 2a 29 61 74 74 65 6d 70  = (List *)attemp
7840: 74 63 6b 72 65 61 6c 6c 6f 63 28 6c 69 73 74 52  tckrealloc(listR
7850: 65 70 50 74 72 2c 20 4c 49 53 54 5f 53 49 5a 45  epPtr, LIST_SIZE
7860: 28 61 74 74 65 6d 70 74 29 29 3b 0a 09 7d 0a 09  (attempt));..}..
7870: 69 66 20 28 6e 65 77 50 74 72 20 3d 3d 20 4e 55  if (newPtr == NU
7880: 4c 4c 29 20 7b 0a 09 20 20 20 20 61 74 74 65 6d  LL) {..    attem
7890: 70 74 20 3d 20 6e 75 6d 52 65 71 75 69 72 65 64  pt = numRequired
78a0: 3b 0a 09 20 20 20 20 6e 65 77 50 74 72 20 3d 20  ;..    newPtr = 
78b0: 28 4c 69 73 74 20 2a 29 61 74 74 65 6d 70 74 63  (List *)attemptc
78c0: 6b 72 65 61 6c 6c 6f 63 28 6c 69 73 74 52 65 70  krealloc(listRep
78d0: 50 74 72 2c 20 4c 49 53 54 5f 53 49 5a 45 28 61  Ptr, LIST_SIZE(a
78e0: 74 74 65 6d 70 74 29 29 3b 0a 09 7d 0a 09 69 66  ttempt));..}..if
78f0: 20 28 6e 65 77 50 74 72 29 20 7b 0a 09 20 20 20   (newPtr) {..   
7900: 20 6c 69 73 74 52 65 70 50 74 72 20 3d 20 6e 65   listRepPtr = ne
7910: 77 50 74 72 3b 0a 09 20 20 20 20 4c 69 73 74 52  wPtr;..    ListR
7920: 65 73 65 74 49 6e 74 52 65 70 28 6c 69 73 74 50  esetIntRep(listP
7930: 74 72 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b  tr, listRepPtr);
7940: 0a 09 20 20 20 20 65 6c 65 6d 50 74 72 73 20 3d  ..    elemPtrs =
7950: 20 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c   &listRepPtr->el
7960: 65 6d 65 6e 74 73 3b 0a 09 20 20 20 20 6c 69 73  ements;..    lis
7970: 74 52 65 70 50 74 72 2d 3e 6d 61 78 45 6c 65 6d  tRepPtr->maxElem
7980: 43 6f 75 6e 74 20 3d 20 61 74 74 65 6d 70 74 3b  Count = attempt;
7990: 0a 09 20 20 20 20 6e 65 65 64 47 72 6f 77 20 3d  ..    needGrow =
79a0: 20 6e 75 6d 52 65 71 75 69 72 65 64 20 3e 20 6c   numRequired > l
79b0: 69 73 74 52 65 70 50 74 72 2d 3e 6d 61 78 45 6c  istRepPtr->maxEl
79c0: 65 6d 43 6f 75 6e 74 3b 0a 09 7d 0a 20 20 20 20  emCount;..}.    
79d0: 7d 0a 20 20 20 20 69 66 20 28 21 6e 65 65 64 47  }.    if (!needG
79e0: 72 6f 77 20 26 26 20 21 69 73 53 68 61 72 65 64  row && !isShared
79f0: 29 20 7b 0a 09 69 6e 74 20 73 68 69 66 74 3b 0a  ) {..int shift;.
7a00: 0a 09 2f 2a 0a 09 20 2a 20 43 61 6e 20 75 73 65  ../*.. * Can use
7a10: 20 74 68 65 20 63 75 72 72 65 6e 74 20 4c 69 73   the current Lis
7a20: 74 20 73 74 72 75 63 74 2e 20 46 69 72 73 74 20  t struct. First 
7a30: 22 64 65 6c 65 74 65 22 20 63 6f 75 6e 74 20 65  "delete" count e
7a40: 6c 65 6d 65 6e 74 73 0a 09 20 2a 20 73 74 61 72  lements.. * star
7a50: 74 69 6e 67 20 61 74 20 66 69 72 73 74 2e 0a 09  ting at first...
7a60: 20 2a 2f 0a 0a 09 66 6f 72 20 28 6a 20 3d 20 66   */...for (j = f
7a70: 69 72 73 74 3b 20 20 6a 20 3c 20 66 69 72 73 74  irst;  j < first
7a80: 20 2b 20 63 6f 75 6e 74 3b 20 20 6a 2b 2b 29 20   + count;  j++) 
7a90: 7b 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a  {..    Tcl_Obj *
7aa0: 76 69 63 74 69 6d 50 74 72 20 3d 20 65 6c 65 6d  victimPtr = elem
7ab0: 50 74 72 73 5b 6a 5d 3b 0a 0a 09 20 20 20 20 54  Ptrs[j];...    T
7ac0: 63 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 76  clDecrRefCount(v
7ad0: 69 63 74 69 6d 50 74 72 29 3b 0a 09 7d 0a 0a 09  ictimPtr);..}...
7ae0: 2f 2a 0a 09 20 2a 20 53 68 69 66 74 20 74 68 65  /*.. * Shift the
7af0: 20 65 6c 65 6d 65 6e 74 73 20 61 66 74 65 72 20   elements after 
7b00: 74 68 65 20 6c 61 73 74 20 6f 6e 65 20 72 65 6d  the last one rem
7b10: 6f 76 65 64 20 74 6f 20 74 68 65 69 72 20 6e 65  oved to their ne
7b20: 77 0a 09 20 2a 20 6c 6f 63 61 74 69 6f 6e 73 2e  w.. * locations.
7b30: 0a 09 20 2a 2f 0a 0a 09 73 74 61 72 74 20 3d 20  .. */...start = 
7b40: 66 69 72 73 74 20 2b 20 63 6f 75 6e 74 3b 0a 09  first + count;..
7b50: 6e 75 6d 41 66 74 65 72 4c 61 73 74 20 3d 20 6e  numAfterLast = n
7b60: 75 6d 45 6c 65 6d 73 20 2d 20 73 74 61 72 74 3b  umElems - start;
7b70: 0a 09 73 68 69 66 74 20 3d 20 6f 62 6a 63 20 2d  ..shift = objc -
7b80: 20 63 6f 75 6e 74 3b 09 2f 2a 20 6e 75 6d 4e 65   count;./* numNe
7b90: 77 45 6c 65 6d 73 20 2d 20 6e 75 6d 44 65 6c 65  wElems - numDele
7ba0: 74 65 64 20 2a 2f 0a 09 69 66 20 28 28 6e 75 6d  ted */..if ((num
7bb0: 41 66 74 65 72 4c 61 73 74 20 3e 20 30 29 20 26  AfterLast > 0) &
7bc0: 26 20 28 73 68 69 66 74 20 21 3d 20 30 29 29 20  & (shift != 0)) 
7bd0: 7b 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a  {..    Tcl_Obj *
7be0: 2a 73 72 63 20 3d 20 65 6c 65 6d 50 74 72 73 20  *src = elemPtrs 
7bf0: 2b 20 73 74 61 72 74 3b 0a 0a 09 20 20 20 20 6d  + start;...    m
7c00: 65 6d 6d 6f 76 65 28 73 72 63 2b 73 68 69 66 74  emmove(src+shift
7c10: 2c 20 73 72 63 2c 20 28 73 69 7a 65 5f 74 29 20  , src, (size_t) 
7c20: 6e 75 6d 41 66 74 65 72 4c 61 73 74 20 2a 20 73  numAfterLast * s
7c30: 69 7a 65 6f 66 28 54 63 6c 5f 4f 62 6a 2a 29 29  izeof(Tcl_Obj*))
7c40: 3b 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20  ;..}.    } else 
7c50: 7b 0a 09 2f 2a 0a 09 20 2a 20 43 61 6e 6e 6f 74  {../*.. * Cannot
7c60: 20 75 73 65 20 74 68 65 20 63 75 72 72 65 6e 74   use the current
7c70: 20 4c 69 73 74 20 73 74 72 75 63 74 3b 20 69 74   List struct; it
7c80: 20 69 73 20 73 68 61 72 65 64 2c 20 74 6f 6f 20   is shared, too 
7c90: 73 6d 61 6c 6c 2c 20 6f 72 0a 09 20 2a 20 62 6f  small, or.. * bo
7ca0: 74 68 2e 20 41 6c 6c 6f 63 61 74 65 20 61 20 6e  th. Allocate a n
7cb0: 65 77 20 73 74 72 75 63 74 20 61 6e 64 20 69 6e  ew struct and in
7cc0: 73 65 72 74 20 65 6c 65 6d 65 6e 74 73 20 69 6e  sert elements in
7cd0: 74 6f 20 69 74 2e 0a 09 20 2a 2f 0a 0a 09 4c 69  to it... */...Li
7ce0: 73 74 20 2a 6f 6c 64 4c 69 73 74 52 65 70 50 74  st *oldListRepPt
7cf0: 72 20 3d 20 6c 69 73 74 52 65 70 50 74 72 3b 0a  r = listRepPtr;.
7d00: 09 54 63 6c 5f 4f 62 6a 20 2a 2a 6f 6c 64 50 74  .Tcl_Obj **oldPt
7d10: 72 73 20 3d 20 65 6c 65 6d 50 74 72 73 3b 0a 09  rs = elemPtrs;..
7d20: 69 6e 74 20 6e 65 77 4d 61 78 3b 0a 0a 09 69 66  int newMax;...if
7d30: 20 28 6e 65 65 64 47 72 6f 77 29 20 7b 0a 09 20   (needGrow) {.. 
7d40: 20 20 20 6e 65 77 4d 61 78 20 3d 20 32 20 2a 20     newMax = 2 * 
7d50: 6e 75 6d 52 65 71 75 69 72 65 64 3b 0a 09 7d 20  numRequired;..} 
7d60: 65 6c 73 65 20 7b 0a 09 20 20 20 20 6e 65 77 4d  else {..    newM
7d70: 61 78 20 3d 20 6c 69 73 74 52 65 70 50 74 72 2d  ax = listRepPtr-
7d80: 3e 6d 61 78 45 6c 65 6d 43 6f 75 6e 74 3b 0a 09  >maxElemCount;..
7d90: 7d 0a 0a 09 6c 69 73 74 52 65 70 50 74 72 20 3d  }...listRepPtr =
7da0: 20 41 74 74 65 6d 70 74 4e 65 77 4c 69 73 74 28   AttemptNewList(
7db0: 4e 55 4c 4c 2c 20 6e 65 77 4d 61 78 2c 20 4e 55  NULL, newMax, NU
7dc0: 4c 4c 29 3b 0a 09 69 66 20 28 6c 69 73 74 52 65  LL);..if (listRe
7dd0: 70 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  pPtr == NULL) {.
7de0: 09 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 6e  .    unsigned in
7df0: 74 20 6c 69 6d 69 74 20 3d 20 4c 49 53 54 5f 4d  t limit = LIST_M
7e00: 41 58 20 2d 20 6e 75 6d 52 65 71 75 69 72 65 64  AX - numRequired
7e10: 3b 0a 09 20 20 20 20 75 6e 73 69 67 6e 65 64 20  ;..    unsigned 
7e20: 69 6e 74 20 65 78 74 72 61 20 3d 20 6e 75 6d 52  int extra = numR
7e30: 65 71 75 69 72 65 64 20 2d 20 6e 75 6d 45 6c 65  equired - numEle
7e40: 6d 73 0a 09 09 20 20 20 20 2b 20 54 43 4c 5f 4d  ms...    + TCL_M
7e50: 49 4e 5f 45 4c 45 4d 45 4e 54 5f 47 52 4f 57 54  IN_ELEMENT_GROWT
7e60: 48 3b 0a 09 20 20 20 20 69 6e 74 20 67 72 6f 77  H;..    int grow
7e70: 74 68 20 3d 20 28 69 6e 74 29 20 28 28 65 78 74  th = (int) ((ext
7e80: 72 61 20 3e 20 6c 69 6d 69 74 29 20 3f 20 6c 69  ra > limit) ? li
7e90: 6d 69 74 20 3a 20 65 78 74 72 61 29 3b 0a 0a 09  mit : extra);...
7ea0: 20 20 20 20 6c 69 73 74 52 65 70 50 74 72 20 3d      listRepPtr =
7eb0: 20 41 74 74 65 6d 70 74 4e 65 77 4c 69 73 74 28   AttemptNewList(
7ec0: 4e 55 4c 4c 2c 20 6e 75 6d 52 65 71 75 69 72 65  NULL, numRequire
7ed0: 64 20 2b 20 67 72 6f 77 74 68 2c 20 4e 55 4c 4c  d + growth, NULL
7ee0: 29 3b 0a 09 20 20 20 20 69 66 20 28 6c 69 73 74  );..    if (list
7ef0: 52 65 70 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20  RepPtr == NULL) 
7f00: 7b 0a 09 09 6c 69 73 74 52 65 70 50 74 72 20 3d  {...listRepPtr =
7f10: 20 41 74 74 65 6d 70 74 4e 65 77 4c 69 73 74 28   AttemptNewList(
7f20: 69 6e 74 65 72 70 2c 20 6e 75 6d 52 65 71 75 69  interp, numRequi
7f30: 72 65 64 2c 20 4e 55 4c 4c 29 3b 0a 09 09 69 66  red, NULL);...if
7f40: 20 28 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20   (listRepPtr == 
7f50: 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 20 20 66 6f  NULL) {...    fo
7f60: 72 20 28 69 20 3d 20 30 3b 20 20 69 20 3c 20 6f  r (i = 0;  i < o
7f70: 62 6a 63 3b 20 20 69 2b 2b 29 20 7b 0a 09 09 09  bjc;  i++) {....
7f80: 2f 2a 20 53 65 65 20 62 75 67 20 33 35 39 38 35  /* See bug 35985
7f90: 38 30 20 2a 2f 0a 23 69 66 20 54 43 4c 5f 4d 41  80 */.#if TCL_MA
7fa0: 4a 4f 52 5f 56 45 52 53 49 4f 4e 20 3e 20 38 0a  JOR_VERSION > 8.
7fb0: 09 09 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f  ...Tcl_DecrRefCo
7fc0: 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 23 65  unt(objv[i]);.#e
7fd0: 6c 73 65 0a 09 09 09 6f 62 6a 76 5b 69 5d 2d 3e  lse....objv[i]->
7fe0: 72 65 66 43 6f 75 6e 74 2d 2d 3b 0a 23 65 6e 64  refCount--;.#end
7ff0: 69 66 0a 09 09 20 20 20 20 7d 0a 09 09 20 20 20  if...    }...   
8000: 20 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f   return TCL_ERRO
8010: 52 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d  R;...}..    }..}
8020: 0a 0a 09 4c 69 73 74 52 65 73 65 74 49 6e 74 52  ...ListResetIntR
8030: 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74  ep(listPtr, list
8040: 52 65 70 50 74 72 29 3b 0a 09 6c 69 73 74 52 65  RepPtr);..listRe
8050: 70 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74 2b 2b  pPtr->refCount++
8060: 3b 0a 0a 09 65 6c 65 6d 50 74 72 73 20 3d 20 26  ;...elemPtrs = &
8070: 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d  listRepPtr->elem
8080: 65 6e 74 73 3b 0a 0a 09 69 66 20 28 69 73 53 68  ents;...if (isSh
8090: 61 72 65 64 29 20 7b 0a 09 20 20 20 20 2f 2a 0a  ared) {..    /*.
80a0: 09 20 20 20 20 20 2a 20 54 68 65 20 6f 6c 64 20  .     * The old 
80b0: 73 74 72 75 63 74 20 77 69 6c 6c 20 72 65 6d 61  struct will rema
80c0: 69 6e 20 69 6e 20 70 6c 61 63 65 3b 20 6e 65 65  in in place; nee
80d0: 64 20 6e 65 77 20 72 65 66 43 6f 75 6e 74 73 20  d new refCounts 
80e0: 66 6f 72 20 74 68 65 0a 09 20 20 20 20 20 2a 20  for the..     * 
80f0: 6e 65 77 20 4c 69 73 74 20 73 74 72 75 63 74 20  new List struct 
8100: 72 65 66 65 72 65 6e 63 65 73 2e 20 43 6f 70 79  references. Copy
8110: 20 6f 76 65 72 20 6f 6e 6c 79 20 74 68 65 20 73   over only the s
8120: 75 72 76 69 76 69 6e 67 0a 09 20 20 20 20 20 2a  urviving..     *
8130: 20 65 6c 65 6d 65 6e 74 73 2e 0a 09 20 20 20 20   elements...    
8140: 20 2a 2f 0a 0a 09 20 20 20 20 66 6f 72 20 28 69   */...    for (i
8150: 3d 30 3b 20 69 20 3c 20 66 69 72 73 74 3b 20 69  =0; i < first; i
8160: 2b 2b 29 20 7b 0a 09 09 65 6c 65 6d 50 74 72 73  ++) {...elemPtrs
8170: 5b 69 5d 20 3d 20 6f 6c 64 50 74 72 73 5b 69 5d  [i] = oldPtrs[i]
8180: 3b 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43  ;...Tcl_IncrRefC
8190: 6f 75 6e 74 28 65 6c 65 6d 50 74 72 73 5b 69 5d  ount(elemPtrs[i]
81a0: 29 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 66  );..    }..    f
81b0: 6f 72 20 28 69 20 3d 20 66 69 72 73 74 20 2b 20  or (i = first + 
81c0: 63 6f 75 6e 74 2c 20 6a 20 3d 20 66 69 72 73 74  count, j = first
81d0: 20 2b 20 6f 62 6a 63 3b 0a 09 09 20 20 20 20 6a   + objc;...    j
81e0: 20 3c 20 6e 75 6d 52 65 71 75 69 72 65 64 3b 20   < numRequired; 
81f0: 69 2b 2b 2c 20 6a 2b 2b 29 20 7b 0a 09 09 65 6c  i++, j++) {...el
8200: 65 6d 50 74 72 73 5b 6a 5d 20 3d 20 6f 6c 64 50  emPtrs[j] = oldP
8210: 74 72 73 5b 69 5d 3b 0a 09 09 54 63 6c 5f 49 6e  trs[i];...Tcl_In
8220: 63 72 52 65 66 43 6f 75 6e 74 28 65 6c 65 6d 50  crRefCount(elemP
8230: 74 72 73 5b 6a 5d 29 3b 0a 09 20 20 20 20 7d 0a  trs[j]);..    }.
8240: 0a 09 20 20 20 20 6f 6c 64 4c 69 73 74 52 65 70  ..    oldListRep
8250: 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74 2d 2d 3b  Ptr->refCount--;
8260: 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20  ..} else {..    
8270: 2f 2a 0a 09 20 20 20 20 20 2a 20 54 68 65 20 6f  /*..     * The o
8280: 6c 64 20 73 74 72 75 63 74 20 77 69 6c 6c 20 62  ld struct will b
8290: 65 20 72 65 6d 6f 76 65 64 3b 20 75 73 65 20 69  e removed; use i
82a0: 74 73 20 69 6e 68 65 72 69 74 65 64 20 72 65 66  ts inherited ref
82b0: 43 6f 75 6e 74 73 2e 0a 09 20 20 20 20 20 2a 2f  Counts...     */
82c0: 0a 0a 09 20 20 20 20 69 66 20 28 66 69 72 73 74  ...    if (first
82d0: 20 3e 20 30 29 20 7b 0a 09 09 6d 65 6d 63 70 79   > 0) {...memcpy
82e0: 28 65 6c 65 6d 50 74 72 73 2c 20 6f 6c 64 50 74  (elemPtrs, oldPt
82f0: 72 73 2c 20 66 69 72 73 74 20 2a 20 73 69 7a 65  rs, first * size
8300: 6f 66 28 54 63 6c 5f 4f 62 6a 20 2a 29 29 3b 0a  of(Tcl_Obj *));.
8310: 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 2f 2a 0a  .    }...    /*.
8320: 09 20 20 20 20 20 2a 20 22 44 65 6c 65 74 65 22  .     * "Delete"
8330: 20 63 6f 75 6e 74 20 65 6c 65 6d 65 6e 74 73 20   count elements 
8340: 73 74 61 72 74 69 6e 67 20 61 74 20 66 69 72 73  starting at firs
8350: 74 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20  t...     */...  
8360: 20 20 66 6f 72 20 28 6a 20 3d 20 66 69 72 73 74    for (j = first
8370: 3b 20 20 6a 20 3c 20 66 69 72 73 74 20 2b 20 63  ;  j < first + c
8380: 6f 75 6e 74 3b 20 20 6a 2b 2b 29 20 7b 0a 09 09  ount;  j++) {...
8390: 54 63 6c 5f 4f 62 6a 20 2a 76 69 63 74 69 6d 50  Tcl_Obj *victimP
83a0: 74 72 20 3d 20 6f 6c 64 50 74 72 73 5b 6a 5d 3b  tr = oldPtrs[j];
83b0: 0a 0a 09 09 54 63 6c 44 65 63 72 52 65 66 43 6f  ....TclDecrRefCo
83c0: 75 6e 74 28 76 69 63 74 69 6d 50 74 72 29 3b 0a  unt(victimPtr);.
83d0: 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 2f 2a 0a  .    }...    /*.
83e0: 09 20 20 20 20 20 2a 20 43 6f 70 79 20 74 68 65  .     * Copy the
83f0: 20 65 6c 65 6d 65 6e 74 73 20 61 66 74 65 72 20   elements after 
8400: 74 68 65 20 6c 61 73 74 20 6f 6e 65 20 72 65 6d  the last one rem
8410: 6f 76 65 64 2c 20 73 68 69 66 74 65 64 20 74 6f  oved, shifted to
8420: 20 74 68 65 69 72 0a 09 20 20 20 20 20 2a 20 6e   their..     * n
8430: 65 77 20 6c 6f 63 61 74 69 6f 6e 73 2e 0a 09 20  ew locations... 
8440: 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 73 74 61      */...    sta
8450: 72 74 20 3d 20 66 69 72 73 74 20 2b 20 63 6f 75  rt = first + cou
8460: 6e 74 3b 0a 09 20 20 20 20 6e 75 6d 41 66 74 65  nt;..    numAfte
8470: 72 4c 61 73 74 20 3d 20 6e 75 6d 45 6c 65 6d 73  rLast = numElems
8480: 20 2d 20 73 74 61 72 74 3b 0a 09 20 20 20 20 69   - start;..    i
8490: 66 20 28 6e 75 6d 41 66 74 65 72 4c 61 73 74 20  f (numAfterLast 
84a0: 3e 20 30 29 20 7b 0a 09 09 6d 65 6d 63 70 79 28  > 0) {...memcpy(
84b0: 65 6c 65 6d 50 74 72 73 20 2b 20 66 69 72 73 74  elemPtrs + first
84c0: 20 2b 20 6f 62 6a 63 2c 20 6f 6c 64 50 74 72 73   + objc, oldPtrs
84d0: 20 2b 20 73 74 61 72 74 2c 0a 09 09 09 28 73 69   + start,....(si
84e0: 7a 65 5f 74 29 20 6e 75 6d 41 66 74 65 72 4c 61  ze_t) numAfterLa
84f0: 73 74 20 2a 20 73 69 7a 65 6f 66 28 54 63 6c 5f  st * sizeof(Tcl_
8500: 4f 62 6a 20 2a 29 29 3b 0a 09 20 20 20 20 7d 0a  Obj *));..    }.
8510: 0a 09 20 20 20 20 63 6b 66 72 65 65 28 6f 6c 64  ..    ckfree(old
8520: 4c 69 73 74 52 65 70 50 74 72 29 3b 0a 09 7d 0a  ListRepPtr);..}.
8530: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20      }..    /*.  
8540: 20 20 20 2a 20 49 6e 73 65 72 74 20 74 68 65 20     * Insert the 
8550: 6e 65 77 20 65 6c 65 6d 65 6e 74 73 20 69 6e 74  new elements int
8560: 6f 20 65 6c 65 6d 50 74 72 73 20 62 65 66 6f 72  o elemPtrs befor
8570: 65 20 22 66 69 72 73 74 22 2e 0a 20 20 20 20 20  e "first"..     
8580: 2a 2f 0a 0a 20 20 20 20 66 6f 72 20 28 69 3d 30  */..    for (i=0
8590: 2c 6a 3d 66 69 72 73 74 20 3b 20 69 3c 6f 62 6a  ,j=first ; i<obj
85a0: 63 20 3b 20 69 2b 2b 2c 6a 2b 2b 29 20 7b 0a 09  c ; i++,j++) {..
85b0: 65 6c 65 6d 50 74 72 73 5b 6a 5d 20 3d 20 6f 62  elemPtrs[j] = ob
85c0: 6a 76 5b 69 5d 3b 0a 20 20 20 20 7d 0a 0a 20 20  jv[i];.    }..  
85d0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 70 64 61    /*.     * Upda
85e0: 74 65 20 74 68 65 20 63 6f 75 6e 74 20 6f 66 20  te the count of 
85f0: 65 6c 65 6d 65 6e 74 73 2e 0a 20 20 20 20 20 2a  elements..     *
8600: 2f 0a 0a 20 20 20 20 6c 69 73 74 52 65 70 50 74  /..    listRepPt
8610: 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 20 3d 20 6e  r->elemCount = n
8620: 75 6d 52 65 71 75 69 72 65 64 3b 0a 0a 20 20 20  umRequired;..   
8630: 20 2f 2a 0a 20 20 20 20 20 2a 20 49 6e 76 61 6c   /*.     * Inval
8640: 69 64 61 74 65 20 61 6e 64 20 66 72 65 65 20 61  idate and free a
8650: 6e 79 20 6f 6c 64 20 72 65 70 72 65 73 65 6e 74  ny old represent
8660: 61 74 69 6f 6e 73 20 74 68 61 74 20 6d 61 79 20  ations that may 
8670: 6e 6f 74 20 61 67 72 65 65 0a 20 20 20 20 20 2a  not agree.     *
8680: 20 77 69 74 68 20 74 68 65 20 72 65 76 69 73 65   with the revise
8690: 64 20 6c 69 73 74 27 73 20 69 6e 74 65 72 6e 61  d list's interna
86a0: 6c 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  l representation
86b0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 6c  ..     */..    l
86c0: 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66 43 6f  istRepPtr->refCo
86d0: 75 6e 74 2b 2b 3b 0a 20 20 20 20 54 63 6c 46 72  unt++;.    TclFr
86e0: 65 65 49 6e 74 52 65 70 28 6c 69 73 74 50 74 72  eeIntRep(listPtr
86f0: 29 3b 0a 20 20 20 20 4c 69 73 74 53 65 74 49 6e  );.    ListSetIn
8700: 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69  tRep(listPtr, li
8710: 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20 20 6c  stRepPtr);.    l
8720: 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66 43 6f  istRepPtr->refCo
8730: 75 6e 74 2d 2d 3b 0a 0a 20 20 20 20 54 63 6c 49  unt--;..    TclI
8740: 6e 76 61 6c 69 64 61 74 65 53 74 72 69 6e 67 52  nvalidateStringR
8750: 65 70 28 6c 69 73 74 50 74 72 29 3b 0a 20 20 20  ep(listPtr);.   
8760: 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a   return TCL_OK;.
8770: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d  }.../*. *-------
8780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
87a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
87b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
87c0: 20 2a 0a 20 2a 20 54 63 6c 4c 69 6e 64 65 78 4c   *. * TclLindexL
87d0: 69 73 74 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69  ist --. *. *.Thi
87e0: 73 20 70 72 6f 63 65 64 75 72 65 20 68 61 6e 64  s procedure hand
87f0: 6c 65 73 20 74 68 65 20 27 6c 69 6e 64 65 78 27  les the 'lindex'
8800: 20 63 6f 6d 6d 61 6e 64 20 77 68 65 6e 20 6f 62   command when ob
8810: 6a 63 3d 3d 33 2e 0a 20 2a 0a 20 2a 20 52 65 73  jc==3.. *. * Res
8820: 75 6c 74 73 3a 0a 20 2a 09 52 65 74 75 72 6e 73  ults:. *.Returns
8830: 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68   a pointer to th
8840: 65 20 6f 62 6a 65 63 74 20 65 78 74 72 61 63 74  e object extract
8850: 65 64 2c 20 6f 72 20 4e 55 4c 4c 20 69 66 20 61  ed, or NULL if a
8860: 6e 20 65 72 72 6f 72 0a 20 2a 09 6f 63 63 75 72  n error. *.occur
8870: 72 65 64 2e 20 54 68 65 20 72 65 74 75 72 6e 65  red. The returne
8880: 64 20 6f 62 6a 65 63 74 20 61 6c 72 65 61 64 79  d object already
8890: 20 69 6e 63 6c 75 64 65 73 20 6f 6e 65 20 72 65   includes one re
88a0: 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 20 66 6f  ference count fo
88b0: 72 0a 20 2a 09 74 68 65 20 70 6f 69 6e 74 65 72  r. *.the pointer
88c0: 20 72 65 74 75 72 6e 65 64 2e 0a 20 2a 0a 20 2a   returned.. *. *
88d0: 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20   Side effects:. 
88e0: 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 4e 6f  *.None.. *. * No
88f0: 74 65 73 3a 0a 20 2a 09 54 68 69 73 20 70 72 6f  tes:. *.This pro
8900: 63 65 64 75 72 65 20 69 73 20 69 6d 70 6c 65 6d  cedure is implem
8910: 65 6e 74 65 64 20 65 6e 74 69 72 65 6c 79 20 61  ented entirely a
8920: 73 20 61 20 77 72 61 70 70 65 72 20 61 72 6f 75  s a wrapper arou
8930: 6e 64 0a 20 2a 09 54 63 6c 4c 69 6e 64 65 78 46  nd. *.TclLindexF
8940: 6c 61 74 2e 20 41 6c 6c 20 69 74 20 64 6f 65 73  lat. All it does
8950: 20 69 73 20 72 65 63 6f 6e 66 69 67 75 72 65 20   is reconfigure 
8960: 74 68 65 20 61 72 67 75 6d 65 6e 74 20 66 6f 72  the argument for
8970: 6d 61 74 20 69 6e 74 6f 20 74 68 65 0a 20 2a 09  mat into the. *.
8980: 66 6f 72 6d 20 72 65 71 75 69 72 65 64 20 62 79  form required by
8990: 20 54 63 6c 4c 69 6e 64 65 78 46 6c 61 74 2c 20   TclLindexFlat, 
89a0: 77 68 69 6c 65 20 74 61 6b 69 6e 67 20 63 61 72  while taking car
89b0: 65 20 74 6f 20 6d 61 6e 61 67 65 20 73 68 69 6d  e to manage shim
89c0: 6d 65 72 69 6e 67 0a 20 2a 09 69 6e 20 73 75 63  mering. *.in suc
89d0: 68 20 61 20 77 61 79 20 74 68 61 74 20 77 65 20  h a way that we 
89e0: 74 65 6e 64 20 74 6f 20 6b 65 65 70 20 74 68 65  tend to keep the
89f0: 20 6d 6f 73 74 20 75 73 65 66 75 6c 20 69 6e 74   most useful int
8a00: 72 65 70 73 20 61 6e 64 2f 6f 72 0a 20 2a 09 61  reps and/or. *.a
8a10: 76 6f 69 64 20 74 68 65 20 6d 6f 73 74 20 65 78  void the most ex
8a20: 70 65 6e 73 69 76 65 20 63 6f 6e 76 65 72 73 69  pensive conversi
8a30: 6f 6e 73 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d  ons.. *. *------
8a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a80: 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a  . */..Tcl_Obj *.
8a90: 54 63 6c 4c 69 6e 64 65 78 4c 69 73 74 28 0a 20  TclLindexList(. 
8aa0: 20 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69     Tcl_Interp *i
8ab0: 6e 74 65 72 70 2c 09 09 2f 2a 20 54 63 6c 20 69  nterp,../* Tcl i
8ac0: 6e 74 65 72 70 72 65 74 65 72 2e 20 2a 2f 0a 20  nterpreter. */. 
8ad0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74     Tcl_Obj *list
8ae0: 50 74 72 2c 09 09 2f 2a 20 4c 69 73 74 20 62 65  Ptr,../* List be
8af0: 69 6e 67 20 75 6e 70 61 63 6b 65 64 2e 20 2a 2f  ing unpacked. */
8b00: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 61 72  .    Tcl_Obj *ar
8b10: 67 50 74 72 29 09 09 2f 2a 20 49 6e 64 65 78 20  gPtr)../* Index 
8b20: 6f 72 20 69 6e 64 65 78 20 6c 69 73 74 2e 20 2a  or index list. *
8b30: 2f 0a 7b 0a 0a 20 20 20 20 69 6e 74 20 69 6e 64  /.{..    int ind
8b40: 65 78 3b 09 09 09 2f 2a 20 49 6e 64 65 78 20 69  ex;.../* Index i
8b50: 6e 74 6f 20 74 68 65 20 6c 69 73 74 2e 20 2a 2f  nto the list. */
8b60: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 69 6e  .    Tcl_Obj *in
8b70: 64 65 78 4c 69 73 74 43 6f 70 79 3b 0a 20 20 20  dexListCopy;.   
8b80: 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74   List *listRepPt
8b90: 72 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20  r;..    /*.     
8ba0: 2a 20 44 65 74 65 72 6d 69 6e 65 20 77 68 65 74  * Determine whet
8bb0: 68 65 72 20 61 72 67 50 74 72 20 64 65 73 69 67  her argPtr desig
8bc0: 6e 61 74 65 73 20 61 20 6c 69 73 74 20 6f 72 20  nates a list or 
8bd0: 61 20 73 69 6e 67 6c 65 20 69 6e 64 65 78 2e 20  a single index. 
8be0: 57 65 20 68 61 76 65 0a 20 20 20 20 20 2a 20 74  We have.     * t
8bf0: 6f 20 62 65 20 63 61 72 65 66 75 6c 20 61 62 6f  o be careful abo
8c00: 75 74 20 74 68 65 20 6f 72 64 65 72 20 6f 66 20  ut the order of 
8c10: 74 68 65 20 63 68 65 63 6b 73 20 74 6f 20 61 76  the checks to av
8c20: 6f 69 64 20 72 65 70 65 61 74 65 64 0a 20 20 20  oid repeated.   
8c30: 20 20 2a 20 73 68 69 6d 6d 65 72 69 6e 67 3b 20    * shimmering; 
8c40: 73 65 65 20 54 49 50 23 32 32 20 61 6e 64 20 54  see TIP#22 and T
8c50: 49 50 23 33 33 20 66 6f 72 20 74 68 65 20 64 65  IP#33 for the de
8c60: 74 61 69 6c 73 2e 0a 20 20 20 20 20 2a 2f 0a 0a  tails..     */..
8c70: 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65      ListGetIntRe
8c80: 70 28 61 72 67 50 74 72 2c 20 6c 69 73 74 52 65  p(argPtr, listRe
8c90: 70 50 74 72 29 3b 0a 20 20 20 20 69 66 20 28 28  pPtr);.    if ((
8ca0: 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20 4e 55  listRepPtr == NU
8cb0: 4c 4c 29 0a 09 20 20 20 20 26 26 20 54 63 6c 47  LL)..    && TclG
8cc0: 65 74 49 6e 74 46 6f 72 49 6e 64 65 78 4d 28 4e  etIntForIndexM(N
8cd0: 55 4c 4c 20 2c 20 61 72 67 50 74 72 2c 20 30 2c  ULL , argPtr, 0,
8ce0: 20 30 2c 20 26 69 6e 64 65 78 29 20 3d 3d 20 54   0, &index) == T
8cf0: 43 4c 5f 4f 4b 29 20 7b 0a 09 2f 2a 0a 09 20 2a  CL_OK) {../*.. *
8d00: 20 61 72 67 50 74 72 20 64 65 73 69 67 6e 61 74   argPtr designat
8d10: 65 73 20 61 20 73 69 6e 67 6c 65 20 69 6e 64 65  es a single inde
8d20: 78 2e 0a 09 20 2a 2f 0a 0a 09 72 65 74 75 72 6e  x... */...return
8d30: 20 54 63 6c 4c 69 6e 64 65 78 46 6c 61 74 28 69   TclLindexFlat(i
8d40: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
8d50: 31 2c 20 26 61 72 67 50 74 72 29 3b 0a 20 20 20  1, &argPtr);.   
8d60: 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20   }..    /*.     
8d70: 2a 20 48 65 72 65 20 77 65 20 6d 61 6b 65 20 61  * Here we make a
8d80: 20 70 72 69 76 61 74 65 20 63 6f 70 79 20 6f 66   private copy of
8d90: 20 74 68 65 20 69 6e 64 65 78 20 6c 69 73 74 20   the index list 
8da0: 61 72 67 75 6d 65 6e 74 20 74 6f 20 61 76 6f 69  argument to avoi
8db0: 64 20 61 6e 79 0a 20 20 20 20 20 2a 20 73 68 69  d any.     * shi
8dc0: 6d 6d 65 72 69 6e 67 20 69 73 73 75 65 73 20 74  mmering issues t
8dd0: 68 61 74 20 6d 69 67 68 74 20 69 6e 76 61 6c 69  hat might invali
8de0: 64 61 74 65 20 74 68 65 20 69 6e 64 69 63 65 73  date the indices
8df0: 20 61 72 72 61 79 20 62 65 6c 6f 77 20 77 68 69   array below whi
8e00: 6c 65 0a 20 20 20 20 20 2a 20 77 65 20 61 72 65  le.     * we are
8e10: 20 73 74 69 6c 6c 20 75 73 69 6e 67 20 69 74 2e   still using it.
8e20: 20 54 68 69 73 20 69 73 20 70 72 6f 62 61 62 6c   This is probabl
8e30: 79 20 75 6e 6e 65 63 65 73 73 61 72 79 2e 20 49  y unnecessary. I
8e40: 74 20 64 6f 65 73 20 6e 6f 74 20 61 70 70 65 61  t does not appea
8e50: 72 0a 20 20 20 20 20 2a 20 74 68 61 74 20 61 6e  r.     * that an
8e60: 79 20 64 61 6d 61 67 69 6e 67 20 73 68 69 6d 6d  y damaging shimm
8e70: 65 72 69 6e 67 20 69 73 20 70 6f 73 73 69 62 6c  ering is possibl
8e80: 65 2c 20 61 6e 64 20 6e 6f 20 74 65 73 74 20 68  e, and no test h
8e90: 61 73 20 62 65 65 6e 20 64 65 76 69 73 65 64 0a  as been devised.
8ea0: 20 20 20 20 20 2a 20 74 6f 20 73 68 6f 77 20 61       * to show a
8eb0: 6e 79 20 65 72 72 6f 72 20 77 68 65 6e 20 74 68  ny error when th
8ec0: 69 73 20 70 72 69 76 61 74 65 20 63 6f 70 79 20  is private copy 
8ed0: 69 73 20 6e 6f 74 20 6d 61 64 65 2e 20 42 75 74  is not made. But
8ee0: 20 69 74 27 73 20 63 68 65 61 70 2c 0a 20 20 20   it's cheap,.   
8ef0: 20 20 2a 20 61 6e 64 20 69 74 20 6f 66 66 65 72    * and it offer
8f00: 73 20 73 6f 6d 65 20 66 75 74 75 72 65 2d 70 72  s some future-pr
8f10: 6f 6f 66 69 6e 67 20 69 6e 73 75 72 61 6e 63 65  oofing insurance
8f20: 20 69 6e 20 63 61 73 65 20 74 68 65 20 54 63 6c   in case the Tcl
8f30: 4c 69 6e 64 65 78 46 6c 61 74 0a 20 20 20 20 20  LindexFlat.     
8f40: 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e  * implementation
8f50: 20 63 68 61 6e 67 65 73 20 69 6e 20 73 6f 6d 65   changes in some
8f60: 20 75 6e 65 78 70 65 63 74 65 64 20 77 61 79 2c   unexpected way,
8f70: 20 6f 72 20 73 6f 6d 65 20 6e 65 77 20 66 6f 72   or some new for
8f80: 6d 20 6f 66 0a 20 20 20 20 20 2a 20 74 72 61 63  m of.     * trac
8f90: 65 20 6f 72 20 63 61 6c 6c 62 61 63 6b 20 70 65  e or callback pe
8fa0: 72 6d 69 74 73 20 74 68 69 6e 67 73 20 74 6f 20  rmits things to 
8fb0: 68 61 70 70 65 6e 20 74 68 61 74 20 74 68 65 20  happen that the 
8fc0: 63 75 72 72 65 6e 74 0a 20 20 20 20 20 2a 20 69  current.     * i
8fd0: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 64 6f  mplementation do
8fe0: 65 73 20 6e 6f 74 2e 0a 20 20 20 20 20 2a 2f 0a  es not..     */.
8ff0: 0a 20 20 20 20 69 6e 64 65 78 4c 69 73 74 43 6f  .    indexListCo
9000: 70 79 20 3d 20 54 63 6c 4c 69 73 74 4f 62 6a 43  py = TclListObjC
9010: 6f 70 79 28 4e 55 4c 4c 2c 20 61 72 67 50 74 72  opy(NULL, argPtr
9020: 29 3b 0a 20 20 20 20 69 66 20 28 69 6e 64 65 78  );.    if (index
9030: 4c 69 73 74 43 6f 70 79 20 3d 3d 20 4e 55 4c 4c  ListCopy == NULL
9040: 29 20 7b 0a 09 2f 2a 0a 09 20 2a 20 61 72 67 50  ) {../*.. * argP
9050: 74 72 20 64 65 73 69 67 6e 61 74 65 73 20 73 6f  tr designates so
9060: 6d 65 74 68 69 6e 67 20 74 68 61 74 20 69 73 20  mething that is 
9070: 6e 65 69 74 68 65 72 20 61 6e 20 69 6e 64 65 78  neither an index
9080: 20 6e 6f 72 20 61 0a 09 20 2a 20 77 65 6c 6c 2d   nor a.. * well-
9090: 66 6f 72 6d 65 64 20 6c 69 73 74 2e 20 52 65 70  formed list. Rep
90a0: 6f 72 74 20 74 68 65 20 65 72 72 6f 72 20 76 69  ort the error vi
90b0: 61 20 54 63 6c 4c 69 6e 64 65 78 46 6c 61 74 2e  a TclLindexFlat.
90c0: 0a 09 20 2a 2f 0a 0a 09 72 65 74 75 72 6e 20 54  .. */...return T
90d0: 63 6c 4c 69 6e 64 65 78 46 6c 61 74 28 69 6e 74  clLindexFlat(int
90e0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 31 2c  erp, listPtr, 1,
90f0: 20 26 61 72 67 50 74 72 29 3b 0a 20 20 20 20 7d   &argPtr);.    }
9100: 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74  ..    ListGetInt
9110: 52 65 70 28 69 6e 64 65 78 4c 69 73 74 43 6f 70  Rep(indexListCop
9120: 79 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b 0a  y, listRepPtr);.
9130: 0a 20 20 20 20 61 73 73 65 72 74 28 6c 69 73 74  .    assert(list
9140: 52 65 70 50 74 72 20 21 3d 20 4e 55 4c 4c 29 3b  RepPtr != NULL);
9150: 0a 0a 20 20 20 20 6c 69 73 74 50 74 72 20 3d 20  ..    listPtr = 
9160: 54 63 6c 4c 69 6e 64 65 78 46 6c 61 74 28 69 6e  TclLindexFlat(in
9170: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 6c  terp, listPtr, l
9180: 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43  istRepPtr->elemC
9190: 6f 75 6e 74 2c 0a 09 09 26 6c 69 73 74 52 65 70  ount,...&listRep
91a0: 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 29 3b 0a  Ptr->elements);.
91b0: 20 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66 43      Tcl_DecrRefC
91c0: 6f 75 6e 74 28 69 6e 64 65 78 4c 69 73 74 43 6f  ount(indexListCo
91d0: 70 79 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20  py);.    return 
91e0: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a  listPtr;.}.../*.
91f0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
9200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9230: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54  --------. *. * T
9240: 63 6c 4c 69 6e 64 65 78 46 6c 61 74 20 2d 2d 0a  clLindexFlat --.
9250: 20 2a 0a 20 2a 09 54 68 69 73 20 70 72 6f 63 65   *. *.This proce
9260: 64 75 72 65 20 69 73 20 74 68 65 20 63 6f 72 65  dure is the core
9270: 20 6f 66 20 74 68 65 20 27 6c 69 6e 64 65 78 27   of the 'lindex'
9280: 20 63 6f 6d 6d 61 6e 64 2c 20 77 69 74 68 20 61   command, with a
9290: 6c 6c 20 69 6e 64 65 78 0a 20 2a 09 61 72 67 75  ll index. *.argu
92a0: 6d 65 6e 74 73 20 70 72 65 73 65 6e 74 65 64 20  ments presented 
92b0: 61 73 20 61 20 66 6c 61 74 20 6c 69 73 74 2e 0a  as a flat list..
92c0: 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20   *. * Results:. 
92d0: 2a 09 52 65 74 75 72 6e 73 20 61 20 70 6f 69 6e  *.Returns a poin
92e0: 74 65 72 20 74 6f 20 74 68 65 20 6f 62 6a 65 63  ter to the objec
92f0: 74 20 65 78 74 72 61 63 74 65 64 2c 20 6f 72 20  t extracted, or 
9300: 4e 55 4c 4c 20 69 66 20 61 6e 20 65 72 72 6f 72  NULL if an error
9310: 0a 20 2a 09 6f 63 63 75 72 72 65 64 2e 20 54 68  . *.occurred. Th
9320: 65 20 72 65 74 75 72 6e 65 64 20 6f 62 6a 65 63  e returned objec
9330: 74 20 61 6c 72 65 61 64 79 20 69 6e 63 6c 75 64  t already includ
9340: 65 73 20 6f 6e 65 20 72 65 66 65 72 65 6e 63 65  es one reference
9350: 20 63 6f 75 6e 74 20 66 6f 72 0a 20 2a 09 74 68   count for. *.th
9360: 65 20 70 6f 69 6e 74 65 72 20 72 65 74 75 72 6e  e pointer return
9370: 65 64 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65  ed.. *. * Side e
9380: 66 66 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e  ffects:. *.None.
9390: 0a 20 2a 0a 20 2a 20 4e 6f 74 65 73 3a 0a 20 2a  . *. * Notes:. *
93a0: 09 54 68 65 20 72 65 66 65 72 65 6e 63 65 20 63  .The reference c
93b0: 6f 75 6e 74 20 6f 66 20 74 68 65 20 72 65 74 75  ount of the retu
93c0: 72 6e 65 64 20 6f 62 6a 65 63 74 20 69 6e 63 6c  rned object incl
93d0: 75 64 65 73 20 6f 6e 65 20 72 65 66 65 72 65 6e  udes one referen
93e0: 63 65 0a 20 2a 09 63 6f 72 72 65 73 70 6f 6e 64  ce. *.correspond
93f0: 69 6e 67 20 74 6f 20 74 68 65 20 70 6f 69 6e 74  ing to the point
9400: 65 72 20 72 65 74 75 72 6e 65 64 2e 20 54 68 75  er returned. Thu
9410: 73 2c 20 74 68 65 20 63 61 6c 6c 69 6e 67 20 63  s, the calling c
9420: 6f 64 65 20 77 69 6c 6c 0a 20 2a 09 75 73 75 61  ode will. *.usua
9430: 6c 6c 79 20 64 6f 20 73 6f 6d 65 74 68 69 6e 67  lly do something
9440: 20 6c 69 6b 65 3a 0a 20 2a 09 09 54 63 6c 5f 53   like:. *..Tcl_S
9450: 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65  etObjResult(inte
9460: 72 70 2c 20 72 65 73 75 6c 74 29 3b 0a 20 2a 09  rp, result);. *.
9470: 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e  .Tcl_DecrRefCoun
9480: 74 28 72 65 73 75 6c 74 29 3b 0a 20 2a 0a 20 2a  t(result);. *. *
9490: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
94a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
94b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
94c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
94d0: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 54 63 6c 5f  ------. */..Tcl_
94e0: 4f 62 6a 20 2a 0a 54 63 6c 4c 69 6e 64 65 78 46  Obj *.TclLindexF
94f0: 6c 61 74 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74  lat(.    Tcl_Int
9500: 65 72 70 20 2a 69 6e 74 65 72 70 2c 09 09 2f 2a  erp *interp,../*
9510: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72   Tcl interpreter
9520: 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a  . */.    Tcl_Obj
9530: 20 2a 6c 69 73 74 50 74 72 2c 09 09 2f 2a 20 54   *listPtr,../* T
9540: 63 6c 20 6f 62 6a 65 63 74 20 72 65 70 72 65 73  cl object repres
9550: 65 6e 74 69 6e 67 20 74 68 65 20 6c 69 73 74 2e  enting the list.
9560: 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 6e 64 65   */.    int inde
9570: 78 43 6f 75 6e 74 2c 09 09 2f 2a 20 43 6f 75 6e  xCount,../* Coun
9580: 74 20 6f 66 20 69 6e 64 69 63 65 73 2e 20 2a 2f  t of indices. */
9590: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f  .    Tcl_Obj *co
95a0: 6e 73 74 20 69 6e 64 65 78 41 72 72 61 79 5b 5d  nst indexArray[]
95b0: 29 2f 2a 20 41 72 72 61 79 20 6f 66 20 70 6f 69  )/* Array of poi
95c0: 6e 74 65 72 73 20 74 6f 20 54 63 6c 20 6f 62 6a  nters to Tcl obj
95d0: 65 63 74 73 20 74 68 61 74 0a 09 09 09 09 20 2a  ects that..... *
95e0: 20 72 65 70 72 65 73 65 6e 74 20 74 68 65 20 69   represent the i
95f0: 6e 64 69 63 65 73 20 69 6e 20 74 68 65 20 6c 69  ndices in the li
9600: 73 74 2e 20 2a 2f 0a 7b 0a 20 20 20 20 69 6e 74  st. */.{.    int
9610: 20 69 3b 0a 0a 20 20 20 20 54 63 6c 5f 49 6e 63   i;..    Tcl_Inc
9620: 72 52 65 66 43 6f 75 6e 74 28 6c 69 73 74 50 74  rRefCount(listPt
9630: 72 29 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 3d  r);..    for (i=
9640: 30 20 3b 20 69 3c 69 6e 64 65 78 43 6f 75 6e 74  0 ; i<indexCount
9650: 20 26 26 20 6c 69 73 74 50 74 72 20 3b 20 69 2b   && listPtr ; i+
9660: 2b 29 20 7b 0a 09 69 6e 74 20 69 6e 64 65 78 2c  +) {..int index,
9670: 20 6c 69 73 74 4c 65 6e 20 3d 20 30 3b 0a 09 54   listLen = 0;..T
9680: 63 6c 5f 4f 62 6a 20 2a 2a 65 6c 65 6d 50 74 72  cl_Obj **elemPtr
9690: 73 20 3d 20 4e 55 4c 4c 2c 20 2a 73 75 62 6c 69  s = NULL, *subli
96a0: 73 74 43 6f 70 79 3b 0a 0a 09 2f 2a 0a 09 20 2a  stCopy;.../*.. *
96b0: 20 48 65 72 65 20 77 65 20 6d 61 6b 65 20 61 20   Here we make a 
96c0: 70 72 69 76 61 74 65 20 63 6f 70 79 20 6f 66 20  private copy of 
96d0: 74 68 65 20 63 75 72 72 65 6e 74 20 73 75 62 6c  the current subl
96e0: 69 73 74 2c 20 73 6f 20 77 65 20 61 76 6f 69 64  ist, so we avoid
96f0: 20 61 6e 79 0a 09 20 2a 20 73 68 69 6d 6d 65 72   any.. * shimmer
9700: 69 6e 67 20 69 73 73 75 65 73 20 74 68 61 74 20  ing issues that 
9710: 6d 69 67 68 74 20 69 6e 76 61 6c 69 64 61 74 65  might invalidate
9720: 20 74 68 65 20 65 6c 65 6d 50 74 72 20 61 72 72   the elemPtr arr
9730: 61 79 20 62 65 6c 6f 77 0a 09 20 2a 20 77 68 69  ay below.. * whi
9740: 6c 65 20 77 65 20 61 72 65 20 73 74 69 6c 6c 20  le we are still 
9750: 75 73 69 6e 67 20 69 74 2e 20 53 65 65 20 74 65  using it. See te
9760: 73 74 20 6c 69 6e 64 65 78 2d 38 2e 34 2e 0a 09  st lindex-8.4...
9770: 20 2a 2f 0a 0a 09 73 75 62 6c 69 73 74 43 6f 70   */...sublistCop
9780: 79 20 3d 20 54 63 6c 4c 69 73 74 4f 62 6a 43 6f  y = TclListObjCo
9790: 70 79 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  py(interp, listP
97a0: 74 72 29 3b 0a 09 54 63 6c 5f 44 65 63 72 52 65  tr);..Tcl_DecrRe
97b0: 66 43 6f 75 6e 74 28 6c 69 73 74 50 74 72 29 3b  fCount(listPtr);
97c0: 0a 09 6c 69 73 74 50 74 72 20 3d 20 4e 55 4c 4c  ..listPtr = NULL
97d0: 3b 0a 0a 09 69 66 20 28 73 75 62 6c 69 73 74 43  ;...if (sublistC
97e0: 6f 70 79 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09  opy == NULL) {..
97f0: 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 54      /*..     * T
9800: 68 65 20 73 75 62 6c 69 73 74 20 69 73 20 6e 6f  he sublist is no
9810: 74 20 61 20 6c 69 73 74 20 61 74 20 61 6c 6c 20  t a list at all 
9820: 3d 3e 20 65 72 72 6f 72 2e 0a 09 20 20 20 20 20  => error...     
9830: 2a 2f 0a 0a 09 20 20 20 20 62 72 65 61 6b 3b 0a  */...    break;.
9840: 09 7d 0a 09 54 63 6c 4c 69 73 74 4f 62 6a 47 65  .}..TclListObjGe
9850: 74 45 6c 65 6d 65 6e 74 73 28 4e 55 4c 4c 2c 20  tElements(NULL, 
9860: 73 75 62 6c 69 73 74 43 6f 70 79 2c 20 26 6c 69  sublistCopy, &li
9870: 73 74 4c 65 6e 2c 20 26 65 6c 65 6d 50 74 72 73  stLen, &elemPtrs
9880: 29 3b 0a 0a 09 69 66 20 28 54 63 6c 47 65 74 49  );...if (TclGetI
9890: 6e 74 46 6f 72 49 6e 64 65 78 4d 28 69 6e 74 65  ntForIndexM(inte
98a0: 72 70 2c 20 69 6e 64 65 78 41 72 72 61 79 5b 69  rp, indexArray[i
98b0: 5d 2c 20 2f 2a 65 6e 64 56 61 6c 75 65 2a 2f 20  ], /*endValue*/ 
98c0: 6c 69 73 74 4c 65 6e 2d 31 2c 0a 09 09 30 2c 20  listLen-1,...0, 
98d0: 26 69 6e 64 65 78 29 20 3d 3d 20 54 43 4c 5f 4f  &index) == TCL_O
98e0: 4b 29 20 7b 0a 09 20 20 20 20 69 66 20 28 69 6e  K) {..    if (in
98f0: 64 65 78 3c 30 20 7c 7c 20 69 6e 64 65 78 3e 3d  dex<0 || index>=
9900: 6c 69 73 74 4c 65 6e 29 20 7b 0a 09 09 2f 2a 0a  listLen) {.../*.
9910: 09 09 20 2a 20 49 6e 64 65 78 20 69 73 20 6f 75  .. * Index is ou
9920: 74 20 6f 66 20 72 61 6e 67 65 2e 20 42 72 65 61  t of range. Brea
9930: 6b 20 6f 75 74 20 6f 66 20 6c 6f 6f 70 20 77 69  k out of loop wi
9940: 74 68 20 65 6d 70 74 79 20 72 65 73 75 6c 74 2e  th empty result.
9950: 0a 09 09 20 2a 20 46 69 72 73 74 20 63 68 65 63  ... * First chec
9960: 6b 20 72 65 6d 61 69 6e 69 6e 67 20 69 6e 64 69  k remaining indi
9970: 63 65 73 20 66 6f 72 20 76 61 6c 69 64 69 74 79  ces for validity
9980: 0a 09 09 20 2a 2f 0a 0a 09 09 77 68 69 6c 65 20  ... */....while 
9990: 28 2b 2b 69 20 3c 20 69 6e 64 65 78 43 6f 75 6e  (++i < indexCoun
99a0: 74 29 20 7b 0a 09 09 20 20 20 20 69 66 20 28 54  t) {...    if (T
99b0: 63 6c 47 65 74 49 6e 74 46 6f 72 49 6e 64 65 78  clGetIntForIndex
99c0: 4d 28 69 6e 74 65 72 70 2c 20 69 6e 64 65 78 41  M(interp, indexA
99d0: 72 72 61 79 5b 69 5d 2c 20 2d 31 2c 20 30 2c 20  rray[i], -1, 0, 
99e0: 26 69 6e 64 65 78 29 0a 09 09 09 21 3d 20 54 43  &index)....!= TC
99f0: 4c 5f 4f 4b 29 20 7b 0a 09 09 09 54 63 6c 5f 44  L_OK) {....Tcl_D
9a00: 65 63 72 52 65 66 43 6f 75 6e 74 28 73 75 62 6c  ecrRefCount(subl
9a10: 69 73 74 43 6f 70 79 29 3b 0a 09 09 09 72 65 74  istCopy);....ret
9a20: 75 72 6e 20 4e 55 4c 4c 3b 0a 09 09 20 20 20 20  urn NULL;...    
9a30: 7d 0a 09 09 7d 0a 09 09 6c 69 73 74 50 74 72 20  }...}...listPtr 
9a40: 3d 20 54 63 6c 5f 4e 65 77 4f 62 6a 28 29 3b 0a  = Tcl_NewObj();.
9a50: 09 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09  .    } else {...
9a60: 2f 2a 0a 09 09 20 2a 20 45 78 74 72 61 63 74 20  /*... * Extract 
9a70: 74 68 65 20 70 6f 69 6e 74 65 72 20 74 6f 20 74  the pointer to t
9a80: 68 65 20 61 70 70 72 6f 70 72 69 61 74 65 20 65  he appropriate e
9a90: 6c 65 6d 65 6e 74 2e 0a 09 09 20 2a 2f 0a 0a 09  lement.... */...
9aa0: 09 6c 69 73 74 50 74 72 20 3d 20 65 6c 65 6d 50  .listPtr = elemP
9ab0: 74 72 73 5b 69 6e 64 65 78 5d 3b 0a 09 20 20 20  trs[index];..   
9ac0: 20 7d 0a 09 20 20 20 20 54 63 6c 5f 49 6e 63 72   }..    Tcl_Incr
9ad0: 52 65 66 43 6f 75 6e 74 28 6c 69 73 74 50 74 72  RefCount(listPtr
9ae0: 29 3b 0a 09 7d 0a 09 54 63 6c 5f 44 65 63 72 52  );..}..Tcl_DecrR
9af0: 65 66 43 6f 75 6e 74 28 73 75 62 6c 69 73 74 43  efCount(sublistC
9b00: 6f 70 79 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  opy);.    }..   
9b10: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b   return listPtr;
9b20: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d  .}.../*. *------
9b30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9b40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9b70: 0a 20 2a 0a 20 2a 20 54 63 6c 4c 73 65 74 4c 69  . *. * TclLsetLi
9b80: 73 74 20 2d 2d 0a 20 2a 0a 20 2a 09 43 6f 72 65  st --. *. *.Core
9b90: 20 6f 66 20 74 68 65 20 27 6c 73 65 74 27 20 63   of the 'lset' c
9ba0: 6f 6d 6d 61 6e 64 20 77 68 65 6e 20 6f 62 6a 63  ommand when objc
9bb0: 20 3d 3d 20 34 2e 20 4f 62 6a 76 5b 32 5d 20 6d   == 4. Objv[2] m
9bc0: 61 79 20 62 65 20 65 69 74 68 65 72 20 61 0a 20  ay be either a. 
9bd0: 2a 09 73 63 61 6c 61 72 20 69 6e 64 65 78 20 6f  *.scalar index o
9be0: 72 20 61 20 6c 69 73 74 20 6f 66 20 69 6e 64 69  r a list of indi
9bf0: 63 65 73 2e 0a 20 2a 20 20 20 20 20 20 49 74 20  ces.. *      It 
9c00: 61 6c 73 6f 20 68 61 6e 64 6c 65 73 20 27 6c 70  also handles 'lp
9c10: 6f 70 27 20 77 68 65 6e 20 67 69 76 65 6e 20 61  op' when given a
9c20: 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 0a 20 2a 0a   NULL value.. *.
9c30: 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 52   * Results:. *.R
9c40: 65 74 75 72 6e 73 20 74 68 65 20 6e 65 77 20 76  eturns the new v
9c50: 61 6c 75 65 20 6f 66 20 74 68 65 20 6c 69 73 74  alue of the list
9c60: 20 76 61 72 69 61 62 6c 65 2c 20 6f 72 20 4e 55   variable, or NU
9c70: 4c 4c 20 69 66 20 74 68 65 72 65 20 77 61 73 20  LL if there was 
9c80: 61 6e 0a 20 2a 09 65 72 72 6f 72 2e 20 54 68 65  an. *.error. The
9c90: 20 72 65 74 75 72 6e 65 64 20 6f 62 6a 65 63 74   returned object
9ca0: 20 69 6e 63 6c 75 64 65 73 20 6f 6e 65 20 72 65   includes one re
9cb0: 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 20 66 6f  ference count fo
9cc0: 72 20 74 68 65 0a 20 2a 09 70 6f 69 6e 74 65 72  r the. *.pointer
9cd0: 20 72 65 74 75 72 6e 65 64 2e 0a 20 2a 0a 20 2a   returned.. *. *
9ce0: 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20   Side effects:. 
9cf0: 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 4e 6f  *.None.. *. * No
9d00: 74 65 73 3a 0a 20 2a 09 54 68 69 73 20 70 72 6f  tes:. *.This pro
9d10: 63 65 64 75 72 65 20 69 73 20 69 6d 70 6c 65 6d  cedure is implem
9d20: 65 6e 74 65 64 20 65 6e 74 69 72 65 6c 79 20 61  ented entirely a
9d30: 73 20 61 20 77 72 61 70 70 65 72 20 61 72 6f 75  s a wrapper arou
9d40: 6e 64 0a 20 2a 09 54 63 6c 4c 73 65 74 46 6c 61  nd. *.TclLsetFla
9d50: 74 2e 20 41 6c 6c 20 69 74 20 64 6f 65 73 20 69  t. All it does i
9d60: 73 20 72 65 63 6f 6e 66 69 67 75 72 65 20 74 68  s reconfigure th
9d70: 65 20 61 72 67 75 6d 65 6e 74 20 66 6f 72 6d 61  e argument forma
9d80: 74 20 69 6e 74 6f 20 74 68 65 0a 20 2a 09 66 6f  t into the. *.fo
9d90: 72 6d 20 72 65 71 75 69 72 65 64 20 62 79 20 54  rm required by T
9da0: 63 6c 4c 73 65 74 46 6c 61 74 2c 20 77 68 69 6c  clLsetFlat, whil
9db0: 65 20 74 61 6b 69 6e 67 20 63 61 72 65 20 74 6f  e taking care to
9dc0: 20 6d 61 6e 61 67 65 20 73 68 69 6d 6d 65 72 69   manage shimmeri
9dd0: 6e 67 0a 20 2a 09 69 6e 20 73 75 63 68 20 61 20  ng. *.in such a 
9de0: 77 61 79 20 74 68 61 74 20 77 65 20 74 65 6e 64  way that we tend
9df0: 20 74 6f 20 6b 65 65 70 20 74 68 65 20 6d 6f 73   to keep the mos
9e00: 74 20 75 73 65 66 75 6c 20 69 6e 74 72 65 70 73  t useful intreps
9e10: 20 61 6e 64 2f 6f 72 0a 20 2a 09 61 76 6f 69 64   and/or. *.avoid
9e20: 20 74 68 65 20 6d 6f 73 74 20 65 78 70 65 6e 73   the most expens
9e30: 69 76 65 20 63 6f 6e 76 65 72 73 69 6f 6e 73 2e  ive conversions.
9e40: 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *. *----------
9e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9e70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f  ------------. */
9e90: 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 4c  ..Tcl_Obj *.TclL
9ea0: 73 65 74 4c 69 73 74 28 0a 20 20 20 20 54 63 6c  setList(.    Tcl
9eb0: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
9ec0: 09 09 2f 2a 20 54 63 6c 20 69 6e 74 65 72 70 72  ../* Tcl interpr
9ed0: 65 74 65 72 2e 20 2a 2f 0a 20 20 20 20 54 63 6c  eter. */.    Tcl
9ee0: 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 2c 09 09  _Obj *listPtr,..
9ef0: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 74 68  /* Pointer to th
9f00: 65 20 6c 69 73 74 20 62 65 69 6e 67 20 6d 6f 64  e list being mod
9f10: 69 66 69 65 64 2e 20 2a 2f 0a 20 20 20 20 54 63  ified. */.    Tc
9f20: 6c 5f 4f 62 6a 20 2a 69 6e 64 65 78 41 72 67 50  l_Obj *indexArgP
9f30: 74 72 2c 09 2f 2a 20 49 6e 64 65 78 20 6f 72 20  tr,./* Index or 
9f40: 69 6e 64 65 78 2d 6c 69 73 74 20 61 72 67 20 74  index-list arg t
9f50: 6f 20 27 6c 73 65 74 27 2e 20 2a 2f 0a 20 20 20  o 'lset'. */.   
9f60: 20 54 63 6c 5f 4f 62 6a 20 2a 76 61 6c 75 65 50   Tcl_Obj *valueP
9f70: 74 72 29 09 09 2f 2a 20 56 61 6c 75 65 20 61 72  tr)../* Value ar
9f80: 67 20 74 6f 20 27 6c 73 65 74 27 20 6f 72 20 4e  g to 'lset' or N
9f90: 55 4c 4c 20 74 6f 20 27 6c 70 6f 70 27 2e 20 2a  ULL to 'lpop'. *
9fa0: 2f 0a 7b 0a 20 20 20 20 69 6e 74 20 69 6e 64 65  /.{.    int inde
9fb0: 78 43 6f 75 6e 74 20 3d 20 30 3b 09 09 2f 2a 20  xCount = 0;../* 
9fc0: 4e 75 6d 62 65 72 20 6f 66 20 69 6e 64 69 63 65  Number of indice
9fd0: 73 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 6c  s in the index l
9fe0: 69 73 74 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f  ist. */.    Tcl_
9ff0: 4f 62 6a 20 2a 2a 69 6e 64 69 63 65 73 20 3d 20  Obj **indices = 
a000: 4e 55 4c 4c 3b 09 2f 2a 20 56 65 63 74 6f 72 20  NULL;./* Vector 
a010: 6f 66 20 69 6e 64 69 63 65 73 20 69 6e 20 74 68  of indices in th
a020: 65 20 69 6e 64 65 78 20 6c 69 73 74 2e 20 2a 2f  e index list. */
a030: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65  .    Tcl_Obj *re
a040: 74 56 61 6c 75 65 50 74 72 3b 09 2f 2a 20 50 6f  tValuePtr;./* Po
a050: 69 6e 74 65 72 20 74 6f 20 74 68 65 20 6c 69 73  inter to the lis
a060: 74 20 74 6f 20 62 65 20 72 65 74 75 72 6e 65 64  t to be returned
a070: 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 6e 64  . */.    int ind
a080: 65 78 3b 09 09 09 2f 2a 20 43 75 72 72 65 6e 74  ex;.../* Current
a090: 20 69 6e 64 65 78 20 69 6e 20 74 68 65 20 6c 69   index in the li
a0a0: 73 74 20 2d 20 64 69 73 63 61 72 64 65 64 2e 20  st - discarded. 
a0b0: 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a  */.    Tcl_Obj *
a0c0: 69 6e 64 65 78 4c 69 73 74 43 6f 70 79 3b 0a 20  indexListCopy;. 
a0d0: 20 20 20 4c 69 73 74 20 2a 6c 69 73 74 52 65 70     List *listRep
a0e0: 50 74 72 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20  Ptr;..    /*.   
a0f0: 20 20 2a 20 44 65 74 65 72 6d 69 6e 65 20 77 68    * Determine wh
a100: 65 74 68 65 72 20 74 68 65 20 69 6e 64 65 78 20  ether the index 
a110: 61 72 67 20 64 65 73 69 67 6e 61 74 65 73 20 61  arg designates a
a120: 20 6c 69 73 74 20 6f 72 20 61 20 73 69 6e 67 6c   list or a singl
a130: 65 20 69 6e 64 65 78 2e 0a 20 20 20 20 20 2a 20  e index..     * 
a140: 57 65 20 68 61 76 65 20 74 6f 20 62 65 20 63 61  We have to be ca
a150: 72 65 66 75 6c 20 61 62 6f 75 74 20 74 68 65 20  reful about the 
a160: 6f 72 64 65 72 20 6f 66 20 74 68 65 20 63 68 65  order of the che
a170: 63 6b 73 20 74 6f 20 61 76 6f 69 64 20 72 65 70  cks to avoid rep
a180: 65 61 74 65 64 0a 20 20 20 20 20 2a 20 73 68 69  eated.     * shi
a190: 6d 6d 65 72 69 6e 67 3b 20 73 65 65 20 54 49 50  mmering; see TIP
a1a0: 20 23 32 32 20 61 6e 64 20 23 32 33 20 66 6f 72   #22 and #23 for
a1b0: 20 64 65 74 61 69 6c 73 2e 0a 20 20 20 20 20 2a   details..     *
a1c0: 2f 0a 0a 20 20 20 20 4c 69 73 74 47 65 74 49 6e  /..    ListGetIn
a1d0: 74 52 65 70 28 69 6e 64 65 78 41 72 67 50 74 72  tRep(indexArgPtr
a1e0: 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 20  , listRepPtr);. 
a1f0: 20 20 20 69 66 20 28 6c 69 73 74 52 65 70 50 74     if (listRepPt
a200: 72 20 3d 3d 20 4e 55 4c 4c 0a 09 20 20 20 20 26  r == NULL..    &
a210: 26 20 54 63 6c 47 65 74 49 6e 74 46 6f 72 49 6e  & TclGetIntForIn
a220: 64 65 78 4d 28 4e 55 4c 4c 2c 20 69 6e 64 65 78  dexM(NULL, index
a230: 41 72 67 50 74 72 2c 20 30 2c 20 30 2c 20 26 69  ArgPtr, 0, 0, &i
a240: 6e 64 65 78 29 20 3d 3d 20 54 43 4c 5f 4f 4b 29  ndex) == TCL_OK)
a250: 20 7b 0a 09 2f 2a 0a 09 20 2a 20 69 6e 64 65 78   {../*.. * index
a260: 41 72 67 50 74 72 20 64 65 73 69 67 6e 61 74 65  ArgPtr designate
a270: 73 20 61 20 73 69 6e 67 6c 65 20 69 6e 64 65 78  s a single index
a280: 2e 0a 09 20 2a 2f 0a 0a 09 72 65 74 75 72 6e 20  ... */...return 
a290: 54 63 6c 4c 73 65 74 46 6c 61 74 28 69 6e 74 65  TclLsetFlat(inte
a2a0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 31 2c 20  rp, listPtr, 1, 
a2b0: 26 69 6e 64 65 78 41 72 67 50 74 72 2c 20 76 61  &indexArgPtr, va
a2c0: 6c 75 65 50 74 72 29 3b 0a 0a 20 20 20 20 7d 0a  luePtr);..    }.
a2d0: 0a 20 20 20 20 69 6e 64 65 78 4c 69 73 74 43 6f  .    indexListCo
a2e0: 70 79 20 3d 20 54 63 6c 4c 69 73 74 4f 62 6a 43  py = TclListObjC
a2f0: 6f 70 79 28 4e 55 4c 4c 2c 20 69 6e 64 65 78 41  opy(NULL, indexA
a300: 72 67 50 74 72 29 3b 0a 20 20 20 20 69 66 20 28  rgPtr);.    if (
a310: 69 6e 64 65 78 4c 69 73 74 43 6f 70 79 20 3d 3d  indexListCopy ==
a320: 20 4e 55 4c 4c 29 20 7b 0a 09 2f 2a 0a 09 20 2a   NULL) {../*.. *
a330: 20 69 6e 64 65 78 41 72 67 50 74 72 20 64 65 73   indexArgPtr des
a340: 69 67 6e 61 74 65 73 20 73 6f 6d 65 74 68 69 6e  ignates somethin
a350: 67 20 74 68 61 74 20 69 73 20 6e 65 69 74 68 65  g that is neithe
a360: 72 20 61 6e 20 69 6e 64 65 78 20 6e 6f 72 20 61  r an index nor a
a370: 0a 09 20 2a 20 77 65 6c 6c 20 66 6f 72 6d 65 64  .. * well formed
a380: 20 6c 69 73 74 2e 20 52 65 70 6f 72 74 20 74 68   list. Report th
a390: 65 20 65 72 72 6f 72 20 76 69 61 20 54 63 6c 4c  e error via TclL
a3a0: 73 65 74 46 6c 61 74 2e 0a 09 20 2a 2f 0a 0a 09  setFlat... */...
a3b0: 72 65 74 75 72 6e 20 54 63 6c 4c 73 65 74 46 6c  return TclLsetFl
a3c0: 61 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  at(interp, listP
a3d0: 74 72 2c 20 31 2c 20 26 69 6e 64 65 78 41 72 67  tr, 1, &indexArg
a3e0: 50 74 72 2c 20 76 61 6c 75 65 50 74 72 29 3b 0a  Ptr, valuePtr);.
a3f0: 20 20 20 20 7d 0a 20 20 20 20 54 63 6c 4c 69 73      }.    TclLis
a400: 74 4f 62 6a 47 65 74 45 6c 65 6d 65 6e 74 73 28  tObjGetElements(
a410: 4e 55 4c 4c 2c 20 69 6e 64 65 78 41 72 67 50 74  NULL, indexArgPt
a420: 72 2c 20 26 69 6e 64 65 78 43 6f 75 6e 74 2c 20  r, &indexCount, 
a430: 26 69 6e 64 69 63 65 73 29 3b 0a 0a 20 20 20 20  &indices);..    
a440: 2f 2a 0a 20 20 20 20 20 2a 20 4c 65 74 20 54 63  /*.     * Let Tc
a450: 6c 4c 73 65 74 46 6c 61 74 20 68 61 6e 64 6c 65  lLsetFlat handle
a460: 20 74 68 65 20 61 63 74 75 61 6c 20 6c 73 65 74   the actual lset
a470: 27 74 69 6e 67 2e 0a 20 20 20 20 20 2a 2f 0a 0a  'ting..     */..
a480: 20 20 20 20 72 65 74 56 61 6c 75 65 50 74 72 20      retValuePtr 
a490: 3d 20 54 63 6c 4c 73 65 74 46 6c 61 74 28 69 6e  = TclLsetFlat(in
a4a0: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 69  terp, listPtr, i
a4b0: 6e 64 65 78 43 6f 75 6e 74 2c 20 69 6e 64 69 63  ndexCount, indic
a4c0: 65 73 2c 20 76 61 6c 75 65 50 74 72 29 3b 0a 0a  es, valuePtr);..
a4d0: 20 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66 43      Tcl_DecrRefC
a4e0: 6f 75 6e 74 28 69 6e 64 65 78 4c 69 73 74 43 6f  ount(indexListCo
a4f0: 70 79 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20  py);.    return 
a500: 72 65 74 56 61 6c 75 65 50 74 72 3b 0a 7d 0a 0c  retValuePtr;.}..
a510: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ./*. *----------
a520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a  ------------. *.
a560: 20 2a 20 54 63 6c 4c 73 65 74 46 6c 61 74 20 2d   * TclLsetFlat -
a570: 2d 0a 20 2a 0a 20 2a 09 43 6f 72 65 20 65 6e 67  -. *. *.Core eng
a580: 69 6e 65 20 6f 66 20 74 68 65 20 27 6c 73 65 74  ine of the 'lset
a590: 27 20 63 6f 6d 6d 61 6e 64 2e 0a 20 2a 20 20 20  ' command.. *   
a5a0: 20 20 20 49 74 20 61 6c 73 6f 20 68 61 6e 64 6c     It also handl
a5b0: 65 73 20 27 6c 70 6f 70 27 20 77 68 65 6e 20 67  es 'lpop' when g
a5c0: 69 76 65 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75  iven a NULL valu
a5d0: 65 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73  e.. *. * Results
a5e0: 3a 0a 20 2a 09 52 65 74 75 72 6e 73 20 74 68 65  :. *.Returns the
a5f0: 20 6e 65 77 20 76 61 6c 75 65 20 6f 66 20 74 68   new value of th
a600: 65 20 6c 69 73 74 20 76 61 72 69 61 62 6c 65 2c  e list variable,
a610: 20 6f 72 20 4e 55 4c 4c 20 69 66 20 61 6e 20 65   or NULL if an e
a620: 72 72 6f 72 0a 20 2a 09 6f 63 63 75 72 72 65 64  rror. *.occurred
a630: 2e 20 54 68 65 20 72 65 74 75 72 6e 65 64 20 6f  . The returned o
a640: 62 6a 65 63 74 20 69 6e 63 6c 75 64 65 73 20 6f  bject includes o
a650: 6e 65 20 72 65 66 65 72 65 6e 63 65 20 63 6f 75  ne reference cou
a660: 6e 74 20 66 6f 72 20 74 68 65 0a 20 2a 09 70 6f  nt for the. *.po
a670: 69 6e 74 65 72 20 72 65 74 75 72 6e 65 64 2e 0a  inter returned..
a680: 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63   *. * Side effec
a690: 74 73 3a 0a 20 2a 09 4f 6e 20 65 6e 74 72 79 2c  ts:. *.On entry,
a6a0: 20 74 68 65 20 72 65 66 65 72 65 6e 63 65 20 63   the reference c
a6b0: 6f 75 6e 74 20 6f 66 20 74 68 65 20 76 61 72 69  ount of the vari
a6c0: 61 62 6c 65 20 76 61 6c 75 65 20 64 6f 65 73 20  able value does 
a6d0: 6e 6f 74 20 72 65 66 6c 65 63 74 0a 20 2a 09 61  not reflect. *.a
a6e0: 6e 79 20 72 65 66 65 72 65 6e 63 65 73 20 68 65  ny references he
a6f0: 6c 64 20 6f 6e 20 74 68 65 20 73 74 61 63 6b 2e  ld on the stack.
a700: 20 54 68 65 20 66 69 72 73 74 20 61 63 74 69 6f   The first actio
a710: 6e 20 6f 66 20 74 68 69 73 20 66 75 6e 63 74 69  n of this functi
a720: 6f 6e 20 69 73 0a 20 2a 09 74 6f 20 64 65 74 65  on is. *.to dete
a730: 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 74 68  rmine whether th
a740: 65 20 6f 62 6a 65 63 74 20 69 73 20 73 68 61 72  e object is shar
a750: 65 64 2c 20 61 6e 64 20 74 6f 20 64 75 70 6c 69  ed, and to dupli
a760: 63 61 74 65 20 69 74 20 69 66 20 69 74 0a 20 2a  cate it if it. *
a770: 09 69 73 2e 20 54 68 65 20 72 65 66 65 72 65 6e  .is. The referen
a780: 63 65 20 63 6f 75 6e 74 20 6f 66 20 74 68 65 20  ce count of the 
a790: 64 75 70 6c 69 63 61 74 65 20 69 73 20 69 6e 63  duplicate is inc
a7a0: 72 65 6d 65 6e 74 65 64 2e 20 41 74 20 74 68 69  remented. At thi
a7b0: 73 0a 20 2a 09 70 6f 69 6e 74 2c 20 74 68 65 20  s. *.point, the 
a7c0: 72 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 20  reference count 
a7d0: 77 69 6c 6c 20 62 65 20 31 20 66 6f 72 20 65 69  will be 1 for ei
a7e0: 74 68 65 72 20 63 61 73 65 2c 20 73 6f 20 74 68  ther case, so th
a7f0: 61 74 20 74 68 65 0a 20 2a 09 6f 62 6a 65 63 74  at the. *.object
a800: 20 77 69 6c 6c 20 61 70 70 65 61 72 20 74 6f 20   will appear to 
a810: 62 65 20 75 6e 73 68 61 72 65 64 2e 0a 20 2a 0a  be unshared.. *.
a820: 20 2a 09 49 66 20 61 6e 20 65 72 72 6f 72 20 6f   *.If an error o
a830: 63 63 75 72 73 2c 20 61 6e 64 20 74 68 65 20 6f  ccurs, and the o
a840: 62 6a 65 63 74 20 68 61 73 20 62 65 65 6e 20 64  bject has been d
a850: 75 70 6c 69 63 61 74 65 64 2c 20 74 68 65 20 72  uplicated, the r
a860: 65 66 65 72 65 6e 63 65 0a 20 2a 09 63 6f 75 6e  eference. *.coun
a870: 74 20 6f 6e 20 74 68 65 20 64 75 70 6c 69 63 61  t on the duplica
a880: 74 65 20 69 73 20 64 65 63 72 65 6d 65 6e 74 65  te is decremente
a890: 64 20 73 6f 20 74 68 61 74 20 69 74 20 69 73 20  d so that it is 
a8a0: 6e 6f 77 20 30 3a 20 74 68 69 73 0a 20 2a 09 64  now 0: this. *.d
a8b0: 69 73 6d 69 73 73 65 73 20 61 6e 79 20 6d 65 6d  ismisses any mem
a8c0: 6f 72 79 20 74 68 61 74 20 77 61 73 20 61 6c 6c  ory that was all
a8d0: 6f 63 61 74 65 64 20 62 79 20 74 68 69 73 20 66  ocated by this f
a8e0: 75 6e 63 74 69 6f 6e 2e 0a 20 2a 0a 20 2a 09 49  unction.. *. *.I
a8f0: 66 20 6e 6f 20 65 72 72 6f 72 20 6f 63 63 75 72  f no error occur
a900: 73 2c 20 74 68 65 20 72 65 66 65 72 65 6e 63 65  s, the reference
a910: 20 63 6f 75 6e 74 20 6f 66 20 74 68 65 20 6f 72   count of the or
a920: 69 67 69 6e 61 6c 20 6f 62 6a 65 63 74 20 69 73  iginal object is
a930: 0a 20 2a 09 69 6e 63 72 65 6d 65 6e 74 65 64 20  . *.incremented 
a940: 69 66 20 74 68 65 20 6f 62 6a 65 63 74 20 68 61  if the object ha
a950: 73 20 6e 6f 74 20 62 65 65 6e 20 64 75 70 6c 69  s not been dupli
a960: 63 61 74 65 64 2c 20 61 6e 64 20 6e 6f 74 68 69  cated, and nothi
a970: 6e 67 20 69 73 20 64 6f 6e 65 0a 20 2a 09 74 6f  ng is done. *.to
a980: 20 61 20 72 65 66 65 72 65 6e 63 65 20 63 6f 75   a reference cou
a990: 6e 74 20 6f 66 20 74 68 65 20 64 75 70 6c 69 63  nt of the duplic
a9a0: 61 74 65 2e 20 4e 6f 77 20 74 68 65 20 72 65 66  ate. Now the ref
a9b0: 65 72 65 6e 63 65 20 63 6f 75 6e 74 20 6f 66 20  erence count of 
a9c0: 61 6e 0a 20 2a 09 75 6e 64 75 70 6c 69 63 61 74  an. *.unduplicat
a9d0: 65 64 20 6f 62 6a 65 63 74 20 69 73 20 32 20 28  ed object is 2 (
a9e0: 74 68 65 20 72 65 74 75 72 6e 65 64 20 70 6f 69  the returned poi
a9f0: 6e 74 65 72 2c 20 70 6c 75 73 20 74 68 65 20 6f  nter, plus the o
aa00: 6e 65 20 73 74 6f 72 65 64 20 69 6e 0a 20 2a 09  ne stored in. *.
aa10: 74 68 65 20 76 61 72 69 61 62 6c 65 29 2e 20 54  the variable). T
aa20: 68 65 20 72 65 66 65 72 65 6e 63 65 20 63 6f 75  he reference cou
aa30: 6e 74 20 6f 66 20 61 20 64 75 70 6c 69 63 61 74  nt of a duplicat
aa40: 65 20 6f 62 6a 65 63 74 20 69 73 20 31 2c 0a 20  e object is 1,. 
aa50: 2a 09 72 65 66 6c 65 63 74 69 6e 67 20 74 68 61  *.reflecting tha
aa60: 74 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 70  t the returned p
aa70: 6f 69 6e 74 65 72 20 69 73 20 74 68 65 20 6f 6e  ointer is the on
aa80: 6c 79 20 61 63 74 69 76 65 20 72 65 66 65 72 65  ly active refere
aa90: 6e 63 65 2e 20 54 68 65 0a 20 2a 09 63 61 6c 6c  nce. The. *.call
aaa0: 65 72 20 69 73 20 65 78 70 65 63 74 65 64 20 74  er is expected t
aab0: 6f 20 73 74 6f 72 65 20 74 68 65 20 72 65 74 75  o store the retu
aac0: 72 6e 65 64 20 76 61 6c 75 65 20 62 61 63 6b 20  rned value back 
aad0: 69 6e 20 74 68 65 20 76 61 72 69 61 62 6c 65 0a  in the variable.
aae0: 20 2a 09 61 6e 64 20 64 65 63 72 65 6d 65 6e 74   *.and decrement
aaf0: 20 69 74 73 20 72 65 66 65 72 65 6e 63 65 20 63   its reference c
ab00: 6f 75 6e 74 2e 20 28 49 4e 53 54 5f 53 54 4f 52  ount. (INST_STOR
ab10: 45 5f 2a 20 64 6f 65 73 20 65 78 61 63 74 6c 79  E_* does exactly
ab20: 20 74 68 69 73 2e 29 0a 20 2a 0a 20 2a 09 53 75   this.). *. *.Su
ab30: 72 67 65 72 79 20 69 73 20 70 65 72 66 6f 72 6d  rgery is perform
ab40: 65 64 20 6f 6e 20 74 68 65 20 75 6e 73 68 61 72  ed on the unshar
ab50: 65 64 20 6c 69 73 74 20 76 61 6c 75 65 20 74 6f  ed list value to
ab60: 20 70 72 6f 64 75 63 65 20 74 68 65 20 72 65 73   produce the res
ab70: 75 6c 74 2e 0a 20 2a 09 54 63 6c 4c 73 65 74 46  ult.. *.TclLsetF
ab80: 6c 61 74 20 6d 61 69 6e 74 61 69 6e 73 20 61 20  lat maintains a 
ab90: 6c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 54  linked list of T
aba0: 63 6c 5f 4f 62 6a 27 73 20 77 68 6f 73 65 20 73  cl_Obj's whose s
abb0: 74 72 69 6e 67 0a 20 2a 09 72 65 70 72 65 73 65  tring. *.represe
abc0: 6e 74 61 74 69 6f 6e 73 20 6d 75 73 74 20 62 65  ntations must be
abd0: 20 73 70 6f 69 6c 74 20 62 79 20 74 68 72 65 61   spoilt by threa
abe0: 64 69 6e 67 20 76 69 61 20 27 70 74 72 32 27 20  ding via 'ptr2' 
abf0: 6f 66 20 74 68 65 0a 20 2a 09 74 77 6f 2d 70 6f  of the. *.two-po
ac00: 69 6e 74 65 72 20 69 6e 74 65 72 6e 61 6c 20 72  inter internal r
ac10: 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e 20 4f  epresentation. O
ac20: 6e 20 65 6e 74 72 79 20 74 6f 20 54 63 6c 4c 73  n entry to TclLs
ac30: 65 74 46 6c 61 74 2c 20 74 68 65 0a 20 2a 09 76  etFlat, the. *.v
ac40: 61 6c 75 65 73 20 6f 66 20 27 70 74 72 32 27 20  alues of 'ptr2' 
ac50: 61 72 65 20 69 6d 6d 61 74 65 72 69 61 6c 3b 20  are immaterial; 
ac60: 6f 6e 20 65 78 69 74 2c 20 74 68 65 20 27 70 74  on exit, the 'pt
ac70: 72 32 27 20 66 69 65 6c 64 20 6f 66 20 61 6e 79  r2' field of any
ac80: 0a 20 2a 09 54 63 6c 5f 4f 62 6a 20 74 68 61 74  . *.Tcl_Obj that
ac90: 20 68 61 73 20 62 65 65 6e 20 6d 6f 64 69 66 69   has been modifi
aca0: 65 64 20 69 73 20 73 65 74 20 74 6f 20 4e 55 4c  ed is set to NUL
acb0: 4c 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d  L.. *. *--------
acc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
acd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ace0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
acf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20  --------------. 
ad00: 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63  */..Tcl_Obj *.Tc
ad10: 6c 4c 73 65 74 46 6c 61 74 28 0a 20 20 20 20 54  lLsetFlat(.    T
ad20: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
ad30: 70 2c 09 09 2f 2a 20 54 63 6c 20 69 6e 74 65 72  p,../* Tcl inter
ad40: 70 72 65 74 65 72 2e 20 2a 2f 0a 20 20 20 20 54  preter. */.    T
ad50: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 2c  cl_Obj *listPtr,
ad60: 09 09 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20  ../* Pointer to 
ad70: 74 68 65 20 6c 69 73 74 20 62 65 69 6e 67 20 6d  the list being m
ad80: 6f 64 69 66 69 65 64 2e 20 2a 2f 0a 20 20 20 20  odified. */.    
ad90: 69 6e 74 20 69 6e 64 65 78 43 6f 75 6e 74 2c 09  int indexCount,.
ada0: 09 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 69 6e  ./* Number of in
adb0: 64 65 78 20 61 72 67 73 2e 20 2a 2f 0a 20 20 20  dex args. */.   
adc0: 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20   Tcl_Obj *const 
add0: 69 6e 64 65 78 41 72 72 61 79 5b 5d 2c 0a 09 09  indexArray[],...
ade0: 09 09 2f 2a 20 49 6e 64 65 78 20 61 72 67 73 2e  ../* Index args.
adf0: 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20   */.    Tcl_Obj 
ae00: 2a 76 61 6c 75 65 50 74 72 29 09 09 2f 2a 20 56  *valuePtr)../* V
ae10: 61 6c 75 65 20 61 72 67 20 74 6f 20 27 6c 73 65  alue arg to 'lse
ae20: 74 27 20 6f 72 20 4e 55 4c 4c 20 74 6f 20 27 6c  t' or NULL to 'l
ae30: 70 6f 70 27 2e 20 2a 2f 0a 7b 0a 20 20 20 20 69  pop'. */.{.    i
ae40: 6e 74 20 69 6e 64 65 78 2c 20 72 65 73 75 6c 74  nt index, result
ae50: 2c 20 6c 65 6e 3b 0a 20 20 20 20 54 63 6c 5f 4f  , len;.    Tcl_O
ae60: 62 6a 20 2a 73 75 62 4c 69 73 74 50 74 72 2c 20  bj *subListPtr, 
ae70: 2a 72 65 74 56 61 6c 75 65 50 74 72 2c 20 2a 63  *retValuePtr, *c
ae80: 68 61 69 6e 50 74 72 3b 0a 20 20 20 20 54 63 6c  hainPtr;.    Tcl
ae90: 5f 4f 62 6a 49 6e 74 52 65 70 20 2a 69 72 50 74  _ObjIntRep *irPt
aea0: 72 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20  r;..    /*.     
aeb0: 2a 20 49 66 20 74 68 65 72 65 20 61 72 65 20 6e  * If there are n
aec0: 6f 20 69 6e 64 69 63 65 73 2c 20 73 69 6d 70 6c  o indices, simpl
aed0: 79 20 72 65 74 75 72 6e 20 74 68 65 20 6e 65 77  y return the new
aee0: 20 76 61 6c 75 65 2e 20 20 28 57 69 74 68 6f 75   value.  (Withou
aef0: 74 0a 20 20 20 20 20 2a 20 69 6e 64 69 63 65 73  t.     * indices
af00: 2c 20 5b 6c 73 65 74 5d 20 69 73 20 61 20 73 79  , [lset] is a sy
af10: 6e 6f 6e 79 6d 20 66 6f 72 20 5b 73 65 74 5d 2e  nonym for [set].
af20: 0a 20 20 20 20 20 2a 20 5b 6c 70 6f 70 5d 20 64  .     * [lpop] d
af30: 6f 65 73 20 6e 6f 74 20 75 73 65 20 74 68 69 73  oes not use this
af40: 20 62 75 74 20 70 72 6f 74 65 63 74 20 66 6f 72   but protect for
af50: 20 4e 55 4c 4c 20 76 61 6c 75 65 50 74 72 20 6a   NULL valuePtr j
af60: 75 73 74 20 69 6e 20 63 61 73 65 2e 0a 20 20 20  ust in case..   
af70: 20 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 69 6e    */..    if (in
af80: 64 65 78 43 6f 75 6e 74 20 3d 3d 20 30 29 20 7b  dexCount == 0) {
af90: 0a 09 69 66 20 28 76 61 6c 75 65 50 74 72 20 21  ..if (valuePtr !
afa0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54  = NULL) {..    T
afb0: 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28  cl_IncrRefCount(
afc0: 76 61 6c 75 65 50 74 72 29 3b 0a 09 7d 0a 09 72  valuePtr);..}..r
afd0: 65 74 75 72 6e 20 76 61 6c 75 65 50 74 72 3b 0a  eturn valuePtr;.
afe0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20      }..    /*.  
aff0: 20 20 20 2a 20 49 66 20 74 68 65 20 6c 69 73 74     * If the list
b000: 20 69 73 20 73 68 61 72 65 64 2c 20 6d 61 6b 65   is shared, make
b010: 20 61 20 63 6f 70 79 20 77 65 20 63 61 6e 20 6d   a copy we can m
b020: 6f 64 69 66 79 20 28 63 6f 70 79 2d 6f 6e 2d 77  odify (copy-on-w
b030: 72 69 74 65 29 2e 20 20 57 65 0a 20 20 20 20 20  rite).  We.     
b040: 2a 20 75 73 65 20 54 63 6c 5f 44 75 70 6c 69 63  * use Tcl_Duplic
b050: 61 74 65 4f 62 6a 28 29 20 69 6e 73 74 65 61 64  ateObj() instead
b060: 20 6f 66 20 54 63 6c 4c 69 73 74 4f 62 6a 43 6f   of TclListObjCo
b070: 70 79 28 29 20 66 6f 72 20 61 20 66 65 77 20 72  py() for a few r
b080: 65 61 73 6f 6e 73 3a 0a 20 20 20 20 20 2a 20 31  easons:.     * 1
b090: 29 20 77 65 20 68 61 76 65 20 6e 6f 74 20 79 65  ) we have not ye
b0a0: 74 20 63 6f 6e 66 69 72 6d 65 64 20 6c 69 73 74  t confirmed list
b0b0: 50 74 72 20 69 73 20 61 63 74 75 61 6c 6c 79 20  Ptr is actually 
b0c0: 61 20 6c 69 73 74 3b 20 32 29 20 57 65 20 6d 61  a list; 2) We ma
b0d0: 6b 65 20 61 0a 20 20 20 20 20 2a 20 76 65 72 62  ke a.     * verb
b0e0: 61 74 69 6d 20 63 6f 70 79 20 6f 66 20 61 6e 79  atim copy of any
b0f0: 20 65 78 69 73 74 69 6e 67 20 73 74 72 69 6e 67   existing string
b100: 20 72 65 70 2c 20 61 6e 64 20 77 68 65 6e 20 77   rep, and when w
b110: 65 20 63 6f 6d 62 69 6e 65 20 74 68 61 74 20 77  e combine that w
b120: 69 74 68 0a 20 20 20 20 20 2a 20 74 68 65 20 64  ith.     * the d
b130: 65 6c 61 79 65 64 20 69 6e 76 61 6c 69 64 61 74  elayed invalidat
b140: 69 6f 6e 20 6f 66 20 73 74 72 69 6e 67 20 72 65  ion of string re
b150: 70 73 20 6f 66 20 6d 6f 64 69 66 69 65 64 20 54  ps of modified T
b160: 63 6c 5f 4f 62 6a 27 73 0a 20 20 20 20 20 2a 20  cl_Obj's.     * 
b170: 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 65 6c 6f  implemented belo
b180: 77 2c 20 74 68 65 20 6f 75 74 63 6f 6d 65 20 69  w, the outcome i
b190: 73 20 74 68 61 74 20 61 6e 79 20 65 72 72 6f 72  s that any error
b1a0: 20 63 6f 6e 64 69 74 69 6f 6e 20 74 68 61 74 20   condition that 
b1b0: 63 61 75 73 65 73 0a 20 20 20 20 20 2a 20 74 68  causes.     * th
b1c0: 69 73 20 72 6f 75 74 69 6e 65 20 74 6f 20 72 65  is routine to re
b1d0: 74 75 72 6e 20 4e 55 4c 4c 2c 20 77 69 6c 6c 20  turn NULL, will 
b1e0: 6c 65 61 76 65 20 74 68 65 20 73 74 72 69 6e 67  leave the string
b1f0: 20 72 65 70 20 6f 66 20 6c 69 73 74 50 74 72 20   rep of listPtr 
b200: 61 6e 64 0a 20 20 20 20 20 2a 20 61 6c 6c 20 65  and.     * all e
b210: 6c 65 6d 65 6e 74 73 20 74 6f 20 62 65 20 75 6e  lements to be un
b220: 63 68 61 6e 67 65 64 2e 0a 20 20 20 20 20 2a 2f  changed..     */
b230: 0a 0a 20 20 20 20 73 75 62 4c 69 73 74 50 74 72  ..    subListPtr
b240: 20 3d 20 54 63 6c 5f 49 73 53 68 61 72 65 64 28   = Tcl_IsShared(
b250: 6c 69 73 74 50 74 72 29 20 3f 20 54 63 6c 5f 44  listPtr) ? Tcl_D
b260: 75 70 6c 69 63 61 74 65 4f 62 6a 28 6c 69 73 74  uplicateObj(list
b270: 50 74 72 29 20 3a 20 6c 69 73 74 50 74 72 3b 0a  Ptr) : listPtr;.
b280: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 41  .    /*.     * A
b290: 6e 63 68 6f 72 20 74 68 65 20 6c 69 6e 6b 65 64  nchor the linked
b2a0: 20 6c 69 73 74 20 6f 66 20 54 63 6c 5f 4f 62 6a   list of Tcl_Obj
b2b0: 27 73 20 77 68 6f 73 65 20 73 74 72 69 6e 67 20  's whose string 
b2c0: 72 65 70 73 20 6d 75 73 74 20 62 65 0a 20 20 20  reps must be.   
b2d0: 20 20 2a 20 69 6e 76 61 6c 69 64 61 74 65 64 20    * invalidated 
b2e0: 69 66 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e  if the operation
b2f0: 20 73 75 63 63 65 65 64 73 2e 0a 20 20 20 20 20   succeeds..     
b300: 2a 2f 0a 0a 20 20 20 20 72 65 74 56 61 6c 75 65  */..    retValue
b310: 50 74 72 20 3d 20 73 75 62 4c 69 73 74 50 74 72  Ptr = subListPtr
b320: 3b 0a 20 20 20 20 63 68 61 69 6e 50 74 72 20 3d  ;.    chainPtr =
b330: 20 4e 55 4c 4c 3b 0a 20 20 20 20 72 65 73 75 6c   NULL;.    resul
b340: 74 20 3d 20 54 43 4c 5f 4f 4b 3b 0a 0a 20 20 20  t = TCL_OK;..   
b350: 20 2f 2a 0a 20 20 20 20 20 2a 20 4c 6f 6f 70 20   /*.     * Loop 
b360: 74 68 72 6f 75 67 68 20 61 6c 6c 20 74 68 65 20  through all the 
b370: 69 6e 64 65 78 20 61 72 67 75 6d 65 6e 74 73 2c  index arguments,
b380: 20 61 6e 64 20 66 6f 72 20 65 61 63 68 20 6f 6e   and for each on
b390: 65 20 64 69 76 65 20 69 6e 74 6f 20 74 68 65 0a  e dive into the.
b3a0: 20 20 20 20 20 2a 20 61 70 70 72 6f 70 72 69 61       * appropria
b3b0: 74 65 20 73 75 62 6c 69 73 74 2e 0a 20 20 20 20  te sublist..    
b3c0: 20 2a 2f 0a 0a 20 20 20 20 64 6f 20 7b 0a 09 69   */..    do {..i
b3d0: 6e 74 20 65 6c 65 6d 43 6f 75 6e 74 3b 0a 09 54  nt elemCount;..T
b3e0: 63 6c 5f 4f 62 6a 20 2a 70 61 72 65 6e 74 4c 69  cl_Obj *parentLi
b3f0: 73 74 2c 20 2a 2a 65 6c 65 6d 50 74 72 73 3b 0a  st, **elemPtrs;.
b400: 0a 09 2f 2a 0a 09 20 2a 20 43 68 65 63 6b 20 66  ../*.. * Check f
b410: 6f 72 20 74 68 65 20 70 6f 73 73 69 62 6c 65 20  or the possible 
b420: 65 72 72 6f 72 20 63 6f 6e 64 69 74 69 6f 6e 73  error conditions
b430: 2e 2e 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 54  ..... */...if (T
b440: 63 6c 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 6d  clListObjGetElem
b450: 65 6e 74 73 28 69 6e 74 65 72 70 2c 20 73 75 62  ents(interp, sub
b460: 4c 69 73 74 50 74 72 2c 20 26 65 6c 65 6d 43 6f  ListPtr, &elemCo
b470: 75 6e 74 2c 20 26 65 6c 65 6d 50 74 72 73 29 0a  unt, &elemPtrs).
b480: 09 09 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09  ..!= TCL_OK) {..
b490: 20 20 20 20 2f 2a 20 2e 2e 2e 74 68 65 20 73 75      /* ...the su
b4a0: 62 6c 69 73 74 20 77 65 27 72 65 20 69 6e 64 65  blist we're inde
b4b0: 78 69 6e 67 20 69 6e 74 6f 20 69 73 6e 27 74 20  xing into isn't 
b4c0: 61 20 6c 69 73 74 20 61 74 20 61 6c 6c 2e 20 2a  a list at all. *
b4d0: 2f 0a 09 20 20 20 20 72 65 73 75 6c 74 20 3d 20  /..    result = 
b4e0: 54 43 4c 5f 45 52 52 4f 52 3b 0a 09 20 20 20 20  TCL_ERROR;..    
b4f0: 62 72 65 61 6b 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09  break;..}.../*..
b500: 20 2a 20 57 41 52 4e 49 4e 47 3a 20 74 68 65 20   * WARNING: the 
b510: 6d 61 63 72 6f 20 54 63 6c 47 65 74 49 6e 74 46  macro TclGetIntF
b520: 6f 72 49 6e 64 65 78 4d 20 69 73 20 6e 6f 74 20  orIndexM is not 
b530: 73 61 66 65 20 66 6f 72 0a 09 20 2a 20 70 6f 73  safe for.. * pos
b540: 74 2d 69 6e 63 72 65 6d 65 6e 74 73 2c 20 61 76  t-increments, av
b550: 6f 69 64 20 27 2a 69 6e 64 65 78 41 72 72 61 79  oid '*indexArray
b560: 2b 2b 27 20 68 65 72 65 2e 0a 09 20 2a 2f 0a 0a  ++' here... */..
b570: 09 69 66 20 28 54 63 6c 47 65 74 49 6e 74 46 6f  .if (TclGetIntFo
b580: 72 49 6e 64 65 78 4d 28 69 6e 74 65 72 70 2c 20  rIndexM(interp, 
b590: 2a 69 6e 64 65 78 41 72 72 61 79 2c 20 65 6c 65  *indexArray, ele
b5a0: 6d 43 6f 75 6e 74 20 2d 20 31 2c 20 30 2c 20 26  mCount - 1, 0, &
b5b0: 69 6e 64 65 78 29 0a 09 09 21 3d 20 54 43 4c 5f  index)...!= TCL_
b5c0: 4f 4b 29 20 20 7b 0a 09 20 20 20 20 2f 2a 20 2e  OK)  {..    /* .
b5d0: 2e 2e 74 68 65 20 69 6e 64 65 78 20 77 65 27 72  ..the index we'r
b5e0: 65 20 74 72 79 69 6e 67 20 74 6f 20 75 73 65 20  e trying to use 
b5f0: 69 73 6e 27 74 20 61 6e 20 69 6e 64 65 78 20 61  isn't an index a
b600: 74 20 61 6c 6c 2e 20 2a 2f 0a 09 20 20 20 20 72  t all. */..    r
b610: 65 73 75 6c 74 20 3d 20 54 43 4c 5f 45 52 52 4f  esult = TCL_ERRO
b620: 52 3b 0a 09 20 20 20 20 69 6e 64 65 78 41 72 72  R;..    indexArr
b630: 61 79 2b 2b 3b 0a 09 20 20 20 20 62 72 65 61 6b  ay++;..    break
b640: 3b 0a 09 7d 0a 09 69 6e 64 65 78 41 72 72 61 79  ;..}..indexArray
b650: 2b 2b 3b 0a 0a 09 69 66 20 28 69 6e 64 65 78 20  ++;...if (index 
b660: 3c 20 30 20 7c 7c 20 69 6e 64 65 78 20 3e 20 65  < 0 || index > e
b670: 6c 65 6d 43 6f 75 6e 74 0a 09 09 7c 7c 20 28 76  lemCount...|| (v
b680: 61 6c 75 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 20  aluePtr == NULL 
b690: 26 26 20 69 6e 64 65 78 20 3e 3d 20 65 6c 65 6d  && index >= elem
b6a0: 43 6f 75 6e 74 29 29 20 7b 0a 09 20 20 20 20 2f  Count)) {..    /
b6b0: 2a 20 2e 2e 2e 74 68 65 20 69 6e 64 65 78 20 70  * ...the index p
b6c0: 6f 69 6e 74 73 20 6f 75 74 73 69 64 65 20 74 68  oints outside th
b6d0: 65 20 73 75 62 6c 69 73 74 2e 20 2a 2f 0a 09 20  e sublist. */.. 
b6e0: 20 20 20 69 66 20 28 69 6e 74 65 72 70 20 21 3d     if (interp !=
b6f0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 54 63 6c 5f 53   NULL) {...Tcl_S
b700: 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65  etObjResult(inte
b710: 72 70 2c 20 54 63 6c 5f 4f 62 6a 50 72 69 6e 74  rp, Tcl_ObjPrint
b720: 66 28 0a 09 09 09 22 69 6e 64 65 78 20 5c 22 25  f(...."index \"%
b730: 73 5c 22 20 6f 75 74 20 6f 66 20 72 61 6e 67 65  s\" out of range
b740: 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67  ", Tcl_GetString
b750: 28 69 6e 64 65 78 41 72 72 61 79 5b 2d 31 5d 29  (indexArray[-1])
b760: 29 29 3b 0a 09 09 54 63 6c 5f 53 65 74 45 72 72  ));...Tcl_SetErr
b770: 6f 72 43 6f 64 65 28 69 6e 74 65 72 70 2c 20 22  orCode(interp, "
b780: 54 43 4c 22 2c 20 22 56 41 4c 55 45 22 2c 20 22  TCL", "VALUE", "
b790: 49 4e 44 45 58 22 0a 09 09 09 22 4f 55 54 4f 46  INDEX"...."OUTOF
b7a0: 52 41 4e 47 45 22 2c 20 4e 55 4c 4c 29 3b 0a 09  RANGE", NULL);..
b7b0: 20 20 20 20 7d 0a 09 20 20 20 20 72 65 73 75 6c      }..    resul
b7c0: 74 20 3d 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 09  t = TCL_ERROR;..
b7d0: 20 20 20 20 62 72 65 61 6b 3b 0a 09 7d 0a 0a 09      break;..}...
b7e0: 2f 2a 0a 09 20 2a 20 4e 6f 20 65 72 72 6f 72 20  /*.. * No error 
b7f0: 63 6f 6e 64 69 74 69 6f 6e 73 2e 20 20 41 73 20  conditions.  As 
b800: 6c 6f 6e 67 20 61 73 20 77 65 27 72 65 20 6e 6f  long as we're no
b810: 74 20 79 65 74 20 6f 6e 20 74 68 65 20 6c 61 73  t yet on the las
b820: 74 20 69 6e 64 65 78 2c 0a 09 20 2a 20 64 65 74  t index,.. * det
b830: 65 72 6d 69 6e 65 20 74 68 65 20 6e 65 78 74 20  ermine the next 
b840: 73 75 62 6c 69 73 74 20 66 6f 72 20 74 68 65 20  sublist for the 
b850: 6e 65 78 74 20 70 61 73 73 20 74 68 72 6f 75 67  next pass throug
b860: 68 20 74 68 65 20 6c 6f 6f 70 2c 20 61 6e 64 0a  h the loop, and.
b870: 09 20 2a 20 74 61 6b 65 20 73 74 65 70 73 20 74  . * take steps t
b880: 6f 20 6d 61 6b 65 20 73 75 72 65 20 69 74 20 69  o make sure it i
b890: 73 20 61 6e 20 75 6e 73 68 61 72 65 64 20 63 6f  s an unshared co
b8a0: 70 79 2c 20 61 73 20 77 65 20 69 6e 74 65 6e 64  py, as we intend
b8b0: 20 74 6f 0a 09 20 2a 20 6d 6f 64 69 66 79 20 69   to.. * modify i
b8c0: 74 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 2d 2d  t... */...if (--
b8d0: 69 6e 64 65 78 43 6f 75 6e 74 29 20 7b 0a 09 20  indexCount) {.. 
b8e0: 20 20 20 70 61 72 65 6e 74 4c 69 73 74 20 3d 20     parentList = 
b8f0: 73 75 62 4c 69 73 74 50 74 72 3b 0a 09 20 20 20  subListPtr;..   
b900: 20 69 66 20 28 69 6e 64 65 78 20 3d 3d 20 65 6c   if (index == el
b910: 65 6d 43 6f 75 6e 74 29 20 7b 0a 09 09 73 75 62  emCount) {...sub
b920: 4c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65  ListPtr = Tcl_Ne
b930: 77 4f 62 6a 28 29 3b 0a 09 20 20 20 20 7d 20 65  wObj();..    } e
b940: 6c 73 65 20 7b 0a 09 09 73 75 62 4c 69 73 74 50  lse {...subListP
b950: 74 72 20 3d 20 65 6c 65 6d 50 74 72 73 5b 69 6e  tr = elemPtrs[in
b960: 64 65 78 5d 3b 0a 09 20 20 20 20 7d 0a 09 20 20  dex];..    }..  
b970: 20 20 69 66 20 28 54 63 6c 5f 49 73 53 68 61 72    if (Tcl_IsShar
b980: 65 64 28 73 75 62 4c 69 73 74 50 74 72 29 29 20  ed(subListPtr)) 
b990: 7b 0a 09 09 73 75 62 4c 69 73 74 50 74 72 20 3d  {...subListPtr =
b9a0: 20 54 63 6c 5f 44 75 70 6c 69 63 61 74 65 4f 62   Tcl_DuplicateOb
b9b0: 6a 28 73 75 62 4c 69 73 74 50 74 72 29 3b 0a 09  j(subListPtr);..
b9c0: 20 20 20 20 7d 0a 0a 09 20 20 20 20 2f 2a 0a 09      }...    /*..
b9d0: 20 20 20 20 20 2a 20 52 65 70 6c 61 63 65 20 74       * Replace t
b9e0: 68 65 20 6f 72 69 67 69 6e 61 6c 20 65 6c 65 6d  he original elem
b9f0: 50 74 72 5b 69 6e 64 65 78 5d 20 69 6e 20 70 61  Ptr[index] in pa
ba00: 72 65 6e 74 4c 69 73 74 20 77 69 74 68 20 61 20  rentList with a 
ba10: 63 6f 70 79 0a 09 20 20 20 20 20 2a 20 77 65 20  copy..     * we 
ba20: 6b 6e 6f 77 20 74 6f 20 62 65 20 75 6e 73 68 61  know to be unsha
ba30: 72 65 64 2e 20 20 54 68 69 73 20 63 61 6c 6c 20  red.  This call 
ba40: 77 69 6c 6c 20 61 6c 73 6f 20 64 65 61 6c 20 77  will also deal w
ba50: 69 74 68 20 74 68 65 0a 09 20 20 20 20 20 2a 20  ith the..     * 
ba60: 73 69 74 75 61 74 69 6f 6e 20 77 68 65 72 65 20  situation where 
ba70: 70 61 72 65 6e 74 4c 69 73 74 20 73 68 61 72 65  parentList share
ba80: 73 20 69 74 73 20 69 6e 74 72 65 70 20 77 69 74  s its intrep wit
ba90: 68 20 6f 74 68 65 72 0a 09 20 20 20 20 20 2a 20  h other..     * 
baa0: 54 63 6c 5f 4f 62 6a 27 73 2e 20 20 44 65 61 6c  Tcl_Obj's.  Deal
bab0: 69 6e 67 20 77 69 74 68 20 74 68 65 20 73 68 61  ing with the sha
bac0: 72 65 64 20 69 6e 74 72 65 70 20 63 61 73 65 20  red intrep case 
bad0: 63 61 6e 20 63 61 75 73 65 0a 09 20 20 20 20 20  can cause..     
bae0: 2a 20 73 75 62 4c 69 73 74 50 74 72 20 74 6f 20  * subListPtr to 
baf0: 62 65 63 6f 6d 65 20 73 68 61 72 65 64 20 61 67  become shared ag
bb00: 61 69 6e 2c 20 73 6f 20 64 65 74 65 63 74 20 74  ain, so detect t
bb10: 68 61 74 20 63 61 73 65 20 61 6e 64 20 6d 61 6b  hat case and mak
bb20: 65 0a 09 20 20 20 20 20 2a 20 61 6e 64 20 73 74  e..     * and st
bb30: 6f 72 65 20 61 6e 6f 74 68 65 72 20 63 6f 70 79  ore another copy
bb40: 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20  ...     */...   
bb50: 20 69 66 20 28 69 6e 64 65 78 20 3d 3d 20 65 6c   if (index == el
bb60: 65 6d 43 6f 75 6e 74 29 20 7b 0a 09 09 54 63 6c  emCount) {...Tcl
bb70: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
bb80: 65 6d 65 6e 74 28 4e 55 4c 4c 2c 20 70 61 72 65  ement(NULL, pare
bb90: 6e 74 4c 69 73 74 2c 20 73 75 62 4c 69 73 74 50  ntList, subListP
bba0: 74 72 29 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65  tr);..    } else
bbb0: 20 7b 0a 09 09 54 63 6c 4c 69 73 74 4f 62 6a 53   {...TclListObjS
bbc0: 65 74 45 6c 65 6d 65 6e 74 28 4e 55 4c 4c 2c 20  etElement(NULL, 
bbd0: 70 61 72 65 6e 74 4c 69 73 74 2c 20 69 6e 64 65  parentList, inde
bbe0: 78 2c 20 73 75 62 4c 69 73 74 50 74 72 29 3b 0a  x, subListPtr);.
bbf0: 09 20 20 20 20 7d 0a 09 20 20 20 20 69 66 20 28  .    }..    if (
bc00: 54 63 6c 5f 49 73 53 68 61 72 65 64 28 73 75 62  Tcl_IsShared(sub
bc10: 4c 69 73 74 50 74 72 29 29 20 7b 0a 09 09 73 75  ListPtr)) {...su
bc20: 62 4c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 44  bListPtr = Tcl_D
bc30: 75 70 6c 69 63 61 74 65 4f 62 6a 28 73 75 62 4c  uplicateObj(subL
bc40: 69 73 74 50 74 72 29 3b 0a 09 09 54 63 6c 4c 69  istPtr);...TclLi
bc50: 73 74 4f 62 6a 53 65 74 45 6c 65 6d 65 6e 74 28  stObjSetElement(
bc60: 4e 55 4c 4c 2c 20 70 61 72 65 6e 74 4c 69 73 74  NULL, parentList
bc70: 2c 20 69 6e 64 65 78 2c 20 73 75 62 4c 69 73 74  , index, subList
bc80: 50 74 72 29 3b 0a 09 20 20 20 20 7d 0a 0a 09 20  Ptr);..    }... 
bc90: 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 54 68     /*..     * Th
bca0: 65 20 54 63 6c 4c 69 73 74 4f 62 6a 53 65 74 45  e TclListObjSetE
bcb0: 6c 65 6d 65 6e 74 28 29 20 63 61 6c 6c 73 20 64  lement() calls d
bcc0: 6f 20 6e 6f 74 20 73 70 6f 69 6c 20 74 68 65 20  o not spoil the 
bcd0: 73 74 72 69 6e 67 20 72 65 70 20 6f 66 0a 09 20  string rep of.. 
bce0: 20 20 20 20 2a 20 70 61 72 65 6e 74 4c 69 73 74      * parentList
bcf0: 2c 20 61 6e 64 20 74 68 61 74 27 73 20 66 69 6e  , and that's fin
bd00: 65 20 66 6f 72 20 6e 6f 77 2c 20 73 69 6e 63 65  e for now, since
bd10: 20 61 6c 6c 20 77 65 27 76 65 20 64 6f 6e 65 20   all we've done 
bd20: 73 6f 0a 09 20 20 20 20 20 2a 20 66 61 72 20 69  so..     * far i
bd30: 73 20 72 65 70 6c 61 63 65 20 61 20 6c 69 73 74  s replace a list
bd40: 20 65 6c 65 6d 65 6e 74 20 77 69 74 68 20 61 6e   element with an
bd50: 20 75 6e 73 68 61 72 65 64 20 63 6f 70 79 2e 20   unshared copy. 
bd60: 20 54 68 65 20 6c 69 73 74 0a 09 20 20 20 20 20   The list..     
bd70: 2a 20 76 61 6c 75 65 20 72 65 6d 61 69 6e 73 20  * value remains 
bd80: 74 68 65 20 73 61 6d 65 2c 20 73 6f 20 74 68 65  the same, so the
bd90: 20 73 74 72 69 6e 67 20 72 65 70 2e 20 69 73 20   string rep. is 
bda0: 73 74 69 6c 6c 20 76 61 6c 69 64 2c 20 61 6e 64  still valid, and
bdb0: 0a 09 20 20 20 20 20 2a 20 75 6e 63 68 61 6e 67  ..     * unchang
bdc0: 65 64 2c 20 77 68 69 63 68 20 69 73 20 67 6f 6f  ed, which is goo
bdd0: 64 20 62 65 63 61 75 73 65 20 69 66 20 74 68 69  d because if thi
bde0: 73 20 77 68 6f 6c 65 20 72 6f 75 74 69 6e 65 20  s whole routine 
bdf0: 72 65 74 75 72 6e 73 0a 09 20 20 20 20 20 2a 20  returns..     * 
be00: 4e 55 4c 4c 2c 20 77 65 27 64 20 6c 69 6b 65 20  NULL, we'd like 
be10: 74 6f 20 6c 65 61 76 65 20 6e 6f 20 63 68 61 6e  to leave no chan
be20: 67 65 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20  ge to the value 
be30: 6f 66 20 74 68 65 20 6c 73 65 74 0a 09 20 20 20  of the lset..   
be40: 20 20 2a 20 76 61 72 69 61 62 6c 65 2e 20 20 4c    * variable.  L
be50: 61 74 65 72 20 6f 6e 2c 20 77 68 65 6e 20 77 65  ater on, when we
be60: 20 73 65 74 20 76 61 6c 75 65 50 74 72 20 69 6e   set valuePtr in
be70: 20 69 74 73 20 70 72 6f 70 65 72 20 70 6c 61 63   its proper plac
be80: 65 2c 0a 09 20 20 20 20 20 2a 20 74 68 65 6e 20  e,..     * then 
be90: 61 6c 6c 20 63 6f 6e 74 61 69 6e 69 6e 67 20 6c  all containing l
bea0: 69 73 74 73 20 77 69 6c 6c 20 68 61 76 65 20 74  ists will have t
beb0: 68 65 69 72 20 76 61 6c 75 65 73 20 63 68 61 6e  heir values chan
bec0: 67 65 64 2c 20 61 6e 64 0a 09 20 20 20 20 20 2a  ged, and..     *
bed0: 20 77 69 6c 6c 20 6e 65 65 64 20 74 68 65 69 72   will need their
bee0: 20 73 74 72 69 6e 67 20 72 65 70 73 20 73 70 6f   string reps spo
bef0: 69 6c 65 64 2e 20 20 57 65 20 6d 61 69 6e 74 61  iled.  We mainta
bf00: 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 61 6c 6c  in a list of all
bf10: 0a 09 20 20 20 20 20 2a 20 74 68 6f 73 65 20 54  ..     * those T
bf20: 63 6c 5f 4f 62 6a 27 73 20 28 76 69 61 20 61 20  cl_Obj's (via a 
bf30: 6c 69 74 74 6c 65 20 69 6e 74 72 65 70 20 73 75  little intrep su
bf40: 72 67 65 72 79 29 20 73 6f 20 77 65 20 63 61 6e  rgery) so we can
bf50: 20 73 70 6f 69 6c 0a 09 20 20 20 20 20 2a 20 74   spoil..     * t
bf60: 68 65 6d 20 61 74 20 74 68 61 74 20 74 69 6d 65  hem at that time
bf70: 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20  ...     */...   
bf80: 20 69 72 50 74 72 20 3d 20 54 63 6c 46 65 74 63   irPtr = TclFetc
bf90: 68 49 6e 74 52 65 70 28 70 61 72 65 6e 74 4c 69  hIntRep(parentLi
bfa0: 73 74 2c 20 26 74 63 6c 4c 69 73 74 54 79 70 65  st, &tclListType
bfb0: 29 3b 0a 09 20 20 20 20 69 72 50 74 72 2d 3e 74  );..    irPtr->t
bfc0: 77 6f 50 74 72 56 61 6c 75 65 2e 70 74 72 32 20  woPtrValue.ptr2 
bfd0: 3d 20 63 68 61 69 6e 50 74 72 3b 0a 09 20 20 20  = chainPtr;..   
bfe0: 20 63 68 61 69 6e 50 74 72 20 3d 20 70 61 72 65   chainPtr = pare
bff0: 6e 74 4c 69 73 74 3b 0a 09 7d 0a 20 20 20 20 7d  ntList;..}.    }
c000: 20 77 68 69 6c 65 20 28 69 6e 64 65 78 43 6f 75   while (indexCou
c010: 6e 74 20 3e 20 30 29 3b 0a 0a 20 20 20 20 2f 2a  nt > 0);..    /*
c020: 0a 20 20 20 20 20 2a 20 45 69 74 68 65 72 20 77  .     * Either w
c030: 65 27 76 65 20 64 65 74 65 63 74 65 64 20 61 6e  e've detected an
c040: 64 20 65 72 72 6f 72 20 63 6f 6e 64 69 74 69 6f  d error conditio
c050: 6e 2c 20 61 6e 64 20 65 78 69 74 65 64 20 74 68  n, and exited th
c060: 65 20 6c 6f 6f 70 20 77 69 74 68 0a 20 20 20 20  e loop with.    
c070: 20 2a 20 72 65 73 75 6c 74 20 3d 3d 20 54 43 4c   * result == TCL
c080: 5f 45 52 52 4f 52 2c 20 6f 72 20 77 65 27 76 65  _ERROR, or we've
c090: 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 72 65   successfully re
c0a0: 61 63 68 65 64 20 74 68 65 20 6c 61 73 74 20 69  ached the last i
c0b0: 6e 64 65 78 2c 20 61 6e 64 0a 20 20 20 20 20 2a  ndex, and.     *
c0c0: 20 77 65 27 72 65 20 72 65 61 64 79 20 74 6f 20   we're ready to 
c0d0: 73 74 6f 72 65 20 76 61 6c 75 65 50 74 72 2e 20  store valuePtr. 
c0e0: 20 49 6e 20 65 69 74 68 65 72 20 63 61 73 65 2c   In either case,
c0f0: 20 77 65 20 6e 65 65 64 20 74 6f 20 63 6c 65 61   we need to clea
c100: 6e 20 75 70 20 6f 75 72 0a 20 20 20 20 20 2a 20  n up our.     * 
c110: 73 74 72 69 6e 67 20 73 70 6f 69 6c 69 6e 67 20  string spoiling 
c120: 6c 69 73 74 20 6f 66 20 54 63 6c 5f 4f 62 6a 27  list of Tcl_Obj'
c130: 73 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20  s..     */..    
c140: 77 68 69 6c 65 20 28 63 68 61 69 6e 50 74 72 29  while (chainPtr)
c150: 20 7b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 6f 62 6a   {..Tcl_Obj *obj
c160: 50 74 72 20 3d 20 63 68 61 69 6e 50 74 72 3b 0a  Ptr = chainPtr;.
c170: 09 4c 69 73 74 20 2a 6c 69 73 74 52 65 70 50 74  .List *listRepPt
c180: 72 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 43 6c 65 61  r;.../*.. * Clea
c190: 72 20 61 77 61 79 20 6f 75 72 20 69 6e 74 72 65  r away our intre
c1a0: 70 20 73 75 72 67 65 72 79 20 6d 65 73 73 2e 0a  p surgery mess..
c1b0: 09 20 2a 2f 0a 0a 09 69 72 50 74 72 20 3d 20 54  . */...irPtr = T
c1c0: 63 6c 46 65 74 63 68 49 6e 74 52 65 70 28 6f 62  clFetchIntRep(ob
c1d0: 6a 50 74 72 2c 20 26 74 63 6c 4c 69 73 74 54 79  jPtr, &tclListTy
c1e0: 70 65 29 3b 0a 09 6c 69 73 74 52 65 70 50 74 72  pe);..listRepPtr
c1f0: 20 3d 20 28 4c 69 73 74 20 2a 29 69 72 50 74 72   = (List *)irPtr
c200: 2d 3e 74 77 6f 50 74 72 56 61 6c 75 65 2e 70 74  ->twoPtrValue.pt
c210: 72 31 3b 0a 09 63 68 61 69 6e 50 74 72 20 3d 20  r1;..chainPtr = 
c220: 28 54 63 6c 5f 4f 62 6a 20 2a 29 69 72 50 74 72  (Tcl_Obj *)irPtr
c230: 2d 3e 74 77 6f 50 74 72 56 61 6c 75 65 2e 70 74  ->twoPtrValue.pt
c240: 72 32 3b 0a 0a 09 69 66 20 28 72 65 73 75 6c 74  r2;...if (result
c250: 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 0a 09   == TCL_OK) {...
c260: 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 57      /*..     * W
c270: 65 27 72 65 20 67 6f 69 6e 67 20 74 6f 20 73 74  e're going to st
c280: 6f 72 65 20 76 61 6c 75 65 50 74 72 2c 20 73 6f  ore valuePtr, so
c290: 20 73 70 6f 69 6c 20 73 74 72 69 6e 67 20 72 65   spoil string re
c2a0: 70 73 20 6f 66 20 61 6c 6c 0a 09 20 20 20 20 20  ps of all..     
c2b0: 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 20 6c 69 73  * containing lis
c2c0: 74 73 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20  ts...     */... 
c2d0: 20 20 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 72     listRepPtr->r
c2e0: 65 66 43 6f 75 6e 74 2b 2b 3b 0a 09 20 20 20 20  efCount++;..    
c2f0: 54 63 6c 46 72 65 65 49 6e 74 52 65 70 28 6f 62  TclFreeIntRep(ob
c300: 6a 50 74 72 29 3b 0a 09 20 20 20 20 4c 69 73 74  jPtr);..    List
c310: 53 65 74 49 6e 74 52 65 70 28 6f 62 6a 50 74 72  SetIntRep(objPtr
c320: 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 09  , listRepPtr);..
c330: 20 20 20 20 6c 69 73 74 52 65 70 50 74 72 2d 3e      listRepPtr->
c340: 72 65 66 43 6f 75 6e 74 2d 2d 3b 0a 0a 09 20 20  refCount--;...  
c350: 20 20 54 63 6c 49 6e 76 61 6c 69 64 61 74 65 53    TclInvalidateS
c360: 74 72 69 6e 67 52 65 70 28 6f 62 6a 50 74 72 29  tringRep(objPtr)
c370: 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20  ;..} else {..   
c380: 20 69 72 50 74 72 2d 3e 74 77 6f 50 74 72 56 61   irPtr->twoPtrVa
c390: 6c 75 65 2e 70 74 72 32 20 3d 20 4e 55 4c 4c 3b  lue.ptr2 = NULL;
c3a0: 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69  ..}.    }..    i
c3b0: 66 20 28 72 65 73 75 6c 74 20 21 3d 20 54 43 4c  f (result != TCL
c3c0: 5f 4f 4b 29 20 7b 0a 09 2f 2a 0a 09 20 2a 20 45  _OK) {../*.. * E
c3d0: 72 72 6f 72 20 72 65 74 75 72 6e 3b 20 6d 65 73  rror return; mes
c3e0: 73 61 67 65 20 69 73 20 61 6c 72 65 61 64 79 20  sage is already 
c3f0: 69 6e 20 69 6e 74 65 72 70 2e 20 43 6c 65 61 6e  in interp. Clean
c400: 20 75 70 20 61 6e 79 20 65 78 63 65 73 73 0a 09   up any excess..
c410: 20 2a 20 6d 65 6d 6f 72 79 2e 0a 09 20 2a 2f 0a   * memory... */.
c420: 0a 09 69 66 20 28 72 65 74 56 61 6c 75 65 50 74  ..if (retValuePt
c430: 72 20 21 3d 20 6c 69 73 74 50 74 72 29 20 7b 0a  r != listPtr) {.
c440: 09 20 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66  .    Tcl_DecrRef
c450: 43 6f 75 6e 74 28 72 65 74 56 61 6c 75 65 50 74  Count(retValuePt
c460: 72 29 3b 0a 09 7d 0a 09 72 65 74 75 72 6e 20 4e  r);..}..return N
c470: 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  ULL;.    }..    
c480: 2f 2a 0a 20 20 20 20 20 2a 20 53 74 6f 72 65 20  /*.     * Store 
c490: 76 61 6c 75 65 50 74 72 20 69 6e 20 70 72 6f 70  valuePtr in prop
c4a0: 65 72 20 73 75 62 6c 69 73 74 20 61 6e 64 20 72  er sublist and r
c4b0: 65 74 75 72 6e 2e 20 54 68 65 20 2d 31 20 69 73  eturn. The -1 is
c4c0: 20 74 6f 20 61 76 6f 69 64 20 61 0a 20 20 20 20   to avoid a.    
c4d0: 20 2a 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e   * compiler warn
c4e0: 69 6e 67 20 28 6e 6f 74 20 61 20 70 72 6f 62 6c  ing (not a probl
c4f0: 65 6d 20 62 65 63 61 75 73 65 20 77 65 20 63 68  em because we ch
c500: 65 63 6b 65 64 20 74 68 61 74 20 77 65 20 68 61  ecked that we ha
c510: 76 65 20 61 0a 20 20 20 20 20 2a 20 70 72 6f 70  ve a.     * prop
c520: 65 72 20 6c 69 73 74 20 2d 20 6f 72 20 73 6f 6d  er list - or som
c530: 65 74 68 69 6e 67 20 63 6f 6e 76 65 72 74 69 62  ething convertib
c540: 6c 65 20 74 6f 20 6f 6e 65 20 2d 20 61 62 6f 76  le to one - abov
c550: 65 29 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20  e)..     */..   
c560: 20 6c 65 6e 20 3d 20 2d 31 3b 0a 20 20 20 20 54   len = -1;.    T
c570: 63 6c 4c 69 73 74 4f 62 6a 4c 65 6e 67 74 68 28  clListObjLength(
c580: 4e 55 4c 4c 2c 20 73 75 62 4c 69 73 74 50 74 72  NULL, subListPtr
c590: 2c 20 26 6c 65 6e 29 3b 0a 20 20 20 20 69 66 20  , &len);.    if 
c5a0: 28 76 61 6c 75 65 50 74 72 20 3d 3d 20 4e 55 4c  (valuePtr == NUL
c5b0: 4c 29 20 7b 0a 09 54 63 6c 5f 4c 69 73 74 4f 62  L) {..Tcl_ListOb
c5c0: 6a 52 65 70 6c 61 63 65 28 4e 55 4c 4c 2c 20 73  jReplace(NULL, s
c5d0: 75 62 4c 69 73 74 50 74 72 2c 20 69 6e 64 65 78  ubListPtr, index
c5e0: 2c 20 31 2c 20 30 2c 20 4e 55 4c 4c 29 3b 0a 20  , 1, 0, NULL);. 
c5f0: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 69 6e     } else if (in
c600: 64 65 78 20 3d 3d 20 6c 65 6e 29 20 7b 0a 09 54  dex == len) {..T
c610: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
c620: 45 6c 65 6d 65 6e 74 28 4e 55 4c 4c 2c 20 73 75  Element(NULL, su
c630: 62 4c 69 73 74 50 74 72 2c 20 76 61 6c 75 65 50  bListPtr, valueP
c640: 74 72 29 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  tr);.    } else 
c650: 7b 0a 09 54 63 6c 4c 69 73 74 4f 62 6a 53 65 74  {..TclListObjSet
c660: 45 6c 65 6d 65 6e 74 28 4e 55 4c 4c 2c 20 73 75  Element(NULL, su
c670: 62 4c 69 73 74 50 74 72 2c 20 69 6e 64 65 78 2c  bListPtr, index,
c680: 20 76 61 6c 75 65 50 74 72 29 3b 0a 09 54 63 6c   valuePtr);..Tcl
c690: 49 6e 76 61 6c 69 64 61 74 65 53 74 72 69 6e 67  InvalidateString
c6a0: 52 65 70 28 73 75 62 4c 69 73 74 50 74 72 29 3b  Rep(subListPtr);
c6b0: 0a 20 20 20 20 7d 0a 20 20 20 20 54 63 6c 5f 49  .    }.    Tcl_I
c6c0: 6e 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 56  ncrRefCount(retV
c6d0: 61 6c 75 65 50 74 72 29 3b 0a 20 20 20 20 72 65  aluePtr);.    re
c6e0: 74 75 72 6e 20 72 65 74 56 61 6c 75 65 50 74 72  turn retValuePtr
c6f0: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d  ;.}.../*. *-----
c700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
c710: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
c720: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
c730: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
c740: 2d 0a 20 2a 0a 20 2a 20 54 63 6c 4c 69 73 74 4f  -. *. * TclListO
c750: 62 6a 53 65 74 45 6c 65 6d 65 6e 74 20 2d 2d 0a  bjSetElement --.
c760: 20 2a 0a 20 2a 09 53 65 74 20 61 20 73 69 6e 67   *. *.Set a sing
c770: 6c 65 20 65 6c 65 6d 65 6e 74 20 6f 66 20 61 20  le element of a 
c780: 6c 69 73 74 20 74 6f 20 61 20 73 70 65 63 69 66  list to a specif
c790: 69 65 64 20 76 61 6c 75 65 0a 20 2a 0a 20 2a 20  ied value. *. * 
c7a0: 52 65 73 75 6c 74 73 3a 0a 20 2a 09 54 68 65 20  Results:. *.The 
c7b0: 72 65 74 75 72 6e 20 76 61 6c 75 65 20 69 73 20  return value is 
c7c0: 6e 6f 72 6d 61 6c 6c 79 20 54 43 4c 5f 4f 4b 2e  normally TCL_OK.
c7d0: 20 49 66 20 6c 69 73 74 50 74 72 20 64 6f 65 73   If listPtr does
c7e0: 20 6e 6f 74 20 72 65 66 65 72 20 74 6f 20 61 0a   not refer to a.
c7f0: 20 2a 09 6c 69 73 74 20 6f 62 6a 65 63 74 20 61   *.list object a
c800: 6e 64 20 63 61 6e 6e 6f 74 20 62 65 20 63 6f 6e  nd cannot be con
c810: 76 65 72 74 65 64 20 74 6f 20 6f 6e 65 2c 20 54  verted to one, T
c820: 43 4c 5f 45 52 52 4f 52 20 69 73 20 72 65 74 75  CL_ERROR is retu
c830: 72 6e 65 64 20 61 6e 64 0a 20 2a 09 61 6e 20 65  rned and. *.an e
c840: 72 72 6f 72 20 6d 65 73 73 61 67 65 20 77 69 6c  rror message wil
c850: 6c 20 62 65 20 6c 65 66 74 20 69 6e 20 74 68 65  l be left in the
c860: 20 69 6e 74 65 72 70 72 65 74 65 72 20 72 65 73   interpreter res
c870: 75 6c 74 20 69 66 20 69 6e 74 65 72 70 20 69 73  ult if interp is
c880: 0a 20 2a 09 6e 6f 74 20 4e 55 4c 4c 2e 20 53 69  . *.not NULL. Si
c890: 6d 69 6c 61 72 6c 79 2c 20 69 66 20 69 6e 64 65  milarly, if inde
c8a0: 78 20 64 65 73 69 67 6e 61 74 65 73 20 61 6e 20  x designates an 
c8b0: 65 6c 65 6d 65 6e 74 20 6f 75 74 73 69 64 65 20  element outside 
c8c0: 74 68 65 20 72 61 6e 67 65 0a 20 2a 09 5b 30 2e  the range. *.[0.
c8d0: 2e 6c 69 73 74 4c 65 6e 67 74 68 2d 31 5d 2c 20  .listLength-1], 
c8e0: 77 68 65 72 65 20 6c 69 73 74 4c 65 6e 67 74 68  where listLength
c8f0: 20 69 73 20 74 68 65 20 63 6f 75 6e 74 20 6f 66   is the count of
c900: 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 74 68 65   elements in the
c910: 0a 20 2a 09 6c 69 73 74 20 6f 62 6a 65 63 74 20  . *.list object 
c920: 64 65 73 69 67 6e 61 74 65 64 20 62 79 20 6c 69  designated by li
c930: 73 74 50 74 72 2c 20 54 43 4c 5f 45 52 52 4f 52  stPtr, TCL_ERROR
c940: 20 69 73 20 72 65 74 75 72 6e 65 64 20 61 6e 64   is returned and
c950: 20 61 6e 20 65 72 72 6f 72 0a 20 2a 09 6d 65 73   an error. *.mes
c960: 73 61 67 65 20 69 73 20 6c 65 66 74 20 69 6e 20  sage is left in 
c970: 74 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 20  the interpreter 
c980: 72 65 73 75 6c 74 2e 0a 20 2a 0a 20 2a 20 53 69  result.. *. * Si
c990: 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 54  de effects:. *.T
c9a0: 63 6c 5f 50 61 6e 69 63 20 69 66 20 6c 69 73 74  cl_Panic if list
c9b0: 50 74 72 20 64 65 73 69 67 6e 61 74 65 73 20 61  Ptr designates a
c9c0: 20 73 68 61 72 65 64 20 6f 62 6a 65 63 74 2e 20   shared object. 
c9d0: 4f 74 68 65 72 77 69 73 65 2c 20 61 74 74 65 6d  Otherwise, attem
c9e0: 70 74 73 0a 20 2a 09 74 6f 20 63 6f 6e 76 65 72  pts. *.to conver
c9f0: 74 20 69 74 20 74 6f 20 61 20 6c 69 73 74 20 77  t it to a list w
ca00: 69 74 68 20 61 20 6e 6f 6e 2d 73 68 61 72 65 64  ith a non-shared
ca10: 20 69 6e 74 65 72 6e 61 6c 20 72 65 70 2e 20 44   internal rep. D
ca20: 65 63 72 65 6d 65 6e 74 73 20 74 68 65 0a 20 2a  ecrements the. *
ca30: 09 72 65 66 20 63 6f 75 6e 74 20 6f 66 20 74 68  .ref count of th
ca40: 65 20 6f 62 6a 65 63 74 20 61 74 20 74 68 65 20  e object at the 
ca50: 73 70 65 63 69 66 69 65 64 20 69 6e 64 65 78 20  specified index 
ca60: 77 69 74 68 69 6e 20 74 68 65 20 6c 69 73 74 2c  within the list,
ca70: 0a 20 2a 09 72 65 70 6c 61 63 65 73 20 77 69 74  . *.replaces wit
ca80: 68 20 74 68 65 20 6f 62 6a 65 63 74 20 64 65 73  h the object des
ca90: 69 67 6e 61 74 65 64 20 62 79 20 76 61 6c 75 65  ignated by value
caa0: 50 74 72 2c 20 61 6e 64 20 69 6e 63 72 65 6d 65  Ptr, and increme
cab0: 6e 74 73 20 74 68 65 0a 20 2a 09 72 65 66 20 63  nts the. *.ref c
cac0: 6f 75 6e 74 20 6f 66 20 74 68 65 20 72 65 70 6c  ount of the repl
cad0: 61 63 65 6d 65 6e 74 20 6f 62 6a 65 63 74 2e 0a  acement object..
cae0: 20 2a 0a 20 2a 09 49 74 20 69 73 20 74 68 65 20   *. *.It is the 
caf0: 63 61 6c 6c 65 72 27 73 20 72 65 73 70 6f 6e 73  caller's respons
cb00: 69 62 69 6c 69 74 79 20 74 6f 20 69 6e 76 61 6c  ibility to inval
cb10: 69 64 61 74 65 20 74 68 65 20 73 74 72 69 6e 67  idate the string
cb20: 0a 20 2a 09 72 65 70 72 65 73 65 6e 74 61 74 69  . *.representati
cb30: 6f 6e 20 6f 66 20 74 68 65 20 6f 62 6a 65 63 74  on of the object
cb40: 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  .. *. *---------
cb50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
cb60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
cb70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
cb80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
cb90: 2f 0a 0a 69 6e 74 0a 54 63 6c 4c 69 73 74 4f 62  /..int.TclListOb
cba0: 6a 53 65 74 45 6c 65 6d 65 6e 74 28 0a 20 20 20  jSetElement(.   
cbb0: 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74   Tcl_Interp *int
cbc0: 65 72 70 2c 09 09 2f 2a 20 54 63 6c 20 69 6e 74  erp,../* Tcl int
cbd0: 65 72 70 72 65 74 65 72 3b 20 75 73 65 64 20 66  erpreter; used f
cbe0: 6f 72 20 65 72 72 6f 72 20 72 65 70 6f 72 74 69  or error reporti
cbf0: 6e 67 0a 09 09 09 09 20 2a 20 69 66 20 6e 6f 74  ng..... * if not
cc00: 20 4e 55 4c 4c 2e 20 2a 2f 0a 20 20 20 20 54 63   NULL. */.    Tc
cc10: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 2c 09  l_Obj *listPtr,.
cc20: 09 2f 2a 20 4c 69 73 74 20 6f 62 6a 65 63 74 20  ./* List object 
cc30: 69 6e 20 77 68 69 63 68 20 65 6c 65 6d 65 6e 74  in which element
cc40: 20 73 68 6f 75 6c 64 20 62 65 0a 09 09 09 09 20   should be..... 
cc50: 2a 20 73 74 6f 72 65 64 2e 20 2a 2f 0a 20 20 20  * stored. */.   
cc60: 20 69 6e 74 20 69 6e 64 65 78 2c 09 09 09 2f 2a   int index,.../*
cc70: 20 49 6e 64 65 78 20 6f 66 20 65 6c 65 6d 65 6e   Index of elemen
cc80: 74 20 74 6f 20 73 74 6f 72 65 2e 20 2a 2f 0a 20  t to store. */. 
cc90: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 76 61 6c 75     Tcl_Obj *valu
cca0: 65 50 74 72 29 09 09 2f 2a 20 54 63 6c 20 6f 62  ePtr)../* Tcl ob
ccb0: 6a 65 63 74 20 74 6f 20 73 74 6f 72 65 20 69 6e  ject to store in
ccc0: 20 74 68 65 20 64 65 73 69 67 6e 61 74 65 64 20   the designated 
ccd0: 6c 69 73 74 0a 09 09 09 09 20 2a 20 65 6c 65 6d  list..... * elem
cce0: 65 6e 74 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c 69  ent. */.{.    Li
ccf0: 73 74 20 2a 6c 69 73 74 52 65 70 50 74 72 3b 09  st *listRepPtr;.
cd00: 09 2f 2a 20 49 6e 74 65 72 6e 61 6c 20 72 65 70  ./* Internal rep
cd10: 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74  resentation of t
cd20: 68 65 20 6c 69 73 74 20 62 65 69 6e 67 0a 09 09  he list being...
cd30: 09 09 20 2a 20 6d 6f 64 69 66 69 65 64 2e 20 2a  .. * modified. *
cd40: 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 2a  /.    Tcl_Obj **
cd50: 65 6c 65 6d 50 74 72 73 3b 09 09 2f 2a 20 50 6f  elemPtrs;../* Po
cd60: 69 6e 74 65 72 73 20 74 6f 20 65 6c 65 6d 65 6e  inters to elemen
cd70: 74 73 20 6f 66 20 74 68 65 20 6c 69 73 74 2e 20  ts of the list. 
cd80: 2a 2f 0a 20 20 20 20 69 6e 74 20 65 6c 65 6d 43  */.    int elemC
cd90: 6f 75 6e 74 3b 09 09 2f 2a 20 4e 75 6d 62 65 72  ount;../* Number
cda0: 20 6f 66 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20   of elements in 
cdb0: 74 68 65 20 6c 69 73 74 2e 20 2a 2f 0a 0a 20 20  the list. */..  
cdc0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 45 6e 73 75    /*.     * Ensu
cdd0: 72 65 20 74 68 61 74 20 74 68 65 20 6c 69 73 74  re that the list
cde0: 50 74 72 20 70 61 72 61 6d 65 74 65 72 20 64 65  Ptr parameter de
cdf0: 73 69 67 6e 61 74 65 73 20 61 6e 20 75 6e 73 68  signates an unsh
ce00: 61 72 65 64 20 6c 69 73 74 2e 0a 20 20 20 20 20  ared list..     
ce10: 2a 2f 0a 0a 20 20 20 20 69 66 20 28 54 63 6c 5f  */..    if (Tcl_
ce20: 49 73 53 68 61 72 65 64 28 6c 69 73 74 50 74 72  IsShared(listPtr
ce30: 29 29 20 7b 0a 09 54 63 6c 5f 50 61 6e 69 63 28  )) {..Tcl_Panic(
ce40: 22 25 73 20 63 61 6c 6c 65 64 20 77 69 74 68 20  "%s called with 
ce50: 73 68 61 72 65 64 20 6f 62 6a 65 63 74 22 2c 20  shared object", 
ce60: 22 54 63 6c 4c 69 73 74 4f 62 6a 53 65 74 45 6c  "TclListObjSetEl
ce70: 65 6d 65 6e 74 22 29 3b 0a 20 20 20 20 7d 0a 0a  ement");.    }..
ce80: 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65      ListGetIntRe
ce90: 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52  p(listPtr, listR
cea0: 65 70 50 74 72 29 3b 0a 20 20 20 20 69 66 20 28  epPtr);.    if (
ceb0: 6c 69 73 74 52 65 70 50 74 72 20 3d 3d 20 4e 55  listRepPtr == NU
cec0: 4c 4c 29 20 7b 0a 09 69 6e 74 20 72 65 73 75 6c  LL) {..int resul
ced0: 74 2c 20 6c 65 6e 67 74 68 3b 0a 0a 09 28 76 6f  t, length;...(vo
cee0: 69 64 29 20 54 63 6c 5f 47 65 74 53 74 72 69 6e  id) Tcl_GetStrin
cef0: 67 46 72 6f 6d 4f 62 6a 28 6c 69 73 74 50 74 72  gFromObj(listPtr
cf00: 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09 69 66 20  , &length);..if 
cf10: 28 6c 65 6e 67 74 68 20 3d 3d 20 30 29 20 7b 0a  (length == 0) {.
cf20: 09 20 20 20 20 69 66 20 28 69 6e 74 65 72 70 20  .    if (interp 
cf30: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 54 63 6c  != NULL) {...Tcl
cf40: 5f 53 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e  _SetObjResult(in
cf50: 74 65 72 70 2c 20 54 63 6c 5f 4f 62 6a 50 72 69  terp, Tcl_ObjPri
cf60: 6e 74 66 28 0a 09 09 09 22 69 6e 64 65 78 20 5c  ntf(...."index \
cf70: 22 25 64 5c 22 20 6f 75 74 20 6f 66 20 72 61 6e  "%d\" out of ran
cf80: 67 65 22 2c 20 69 6e 64 65 78 29 29 3b 0a 09 09  ge", index));...
cf90: 54 63 6c 5f 53 65 74 45 72 72 6f 72 43 6f 64 65  Tcl_SetErrorCode
cfa0: 28 69 6e 74 65 72 70 2c 20 22 54 43 4c 22 2c 20  (interp, "TCL", 
cfb0: 22 56 41 4c 55 45 22 2c 20 22 49 4e 44 45 58 22  "VALUE", "INDEX"
cfc0: 2c 0a 09 09 09 22 4f 55 54 4f 46 52 41 4e 47 45  ,...."OUTOFRANGE
cfd0: 22 2c 20 4e 55 4c 4c 29 3b 0a 09 20 20 20 20 7d  ", NULL);..    }
cfe0: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c  ..    return TCL
cff0: 5f 45 52 52 4f 52 3b 0a 09 7d 0a 09 72 65 73 75  _ERROR;..}..resu
d000: 6c 74 20 3d 20 53 65 74 4c 69 73 74 46 72 6f 6d  lt = SetListFrom
d010: 41 6e 79 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  Any(interp, list
d020: 50 74 72 29 3b 0a 09 69 66 20 28 72 65 73 75 6c  Ptr);..if (resul
d030: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09  t != TCL_OK) {..
d040: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c      return resul
d050: 74 3b 0a 09 7d 0a 09 4c 69 73 74 47 65 74 49 6e  t;..}..ListGetIn
d060: 74 52 65 70 28 6c 69 73 74 50 74 72 2c 20 6c 69  tRep(listPtr, li
d070: 73 74 52 65 70 50 74 72 29 3b 0a 20 20 20 20 7d  stRepPtr);.    }
d080: 0a 0a 20 20 20 20 65 6c 65 6d 43 6f 75 6e 74 20  ..    elemCount 
d090: 3d 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c  = listRepPtr->el
d0a0: 65 6d 43 6f 75 6e 74 3b 0a 0a 20 20 20 20 2f 2a  emCount;..    /*
d0b0: 0a 20 20 20 20 20 2a 20 45 6e 73 75 72 65 20 74  .     * Ensure t
d0c0: 68 61 74 20 74 68 65 20 69 6e 64 65 78 20 69 73  hat the index is
d0d0: 20 69 6e 20 62 6f 75 6e 64 73 2e 0a 20 20 20 20   in bounds..    
d0e0: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 69 6e 64   */..    if (ind
d0f0: 65 78 3c 30 20 7c 7c 20 69 6e 64 65 78 3e 3d 65  ex<0 || index>=e
d100: 6c 65 6d 43 6f 75 6e 74 29 20 7b 0a 09 69 66 20  lemCount) {..if 
d110: 28 69 6e 74 65 72 70 20 21 3d 20 4e 55 4c 4c 29  (interp != NULL)
d120: 20 7b 0a 09 09 54 63 6c 5f 53 65 74 4f 62 6a 52   {...Tcl_SetObjR
d130: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 63  esult(interp, Tc
d140: 6c 5f 4f 62 6a 50 72 69 6e 74 66 28 0a 09 09 09  l_ObjPrintf(....
d150: 22 69 6e 64 65 78 20 5c 22 25 64 5c 22 20 6f 75  "index \"%d\" ou
d160: 74 20 6f 66 20 72 61 6e 67 65 22 2c 20 69 6e 64  t of range", ind
d170: 65 78 29 29 3b 0a 09 20 20 20 20 54 63 6c 5f 53  ex));..    Tcl_S
d180: 65 74 45 72 72 6f 72 43 6f 64 65 28 69 6e 74 65  etErrorCode(inte
d190: 72 70 2c 20 22 54 43 4c 22 2c 20 22 56 41 4c 55  rp, "TCL", "VALU
d1a0: 45 22 2c 20 22 49 4e 44 45 58 22 2c 0a 09 09 20  E", "INDEX",... 
d1b0: 20 20 20 22 4f 55 54 4f 46 52 41 4e 47 45 22 2c     "OUTOFRANGE",
d1c0: 20 4e 55 4c 4c 29 3b 0a 09 7d 0a 09 72 65 74 75   NULL);..}..retu
d1d0: 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 20 20  rn TCL_ERROR;.  
d1e0: 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20    }..    /*.    
d1f0: 20 2a 20 49 66 20 74 68 65 20 69 6e 74 65 72 6e   * If the intern
d200: 61 6c 20 72 65 70 20 69 73 20 73 68 61 72 65 64  al rep is shared
d210: 2c 20 72 65 70 6c 61 63 65 20 69 74 20 77 69 74  , replace it wit
d220: 68 20 61 6e 20 75 6e 73 68 61 72 65 64 20 63 6f  h an unshared co
d230: 70 79 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20  py..     */..   
d240: 20 69 66 20 28 6c 69 73 74 52 65 70 50 74 72 2d   if (listRepPtr-
d250: 3e 72 65 66 43 6f 75 6e 74 20 3e 20 31 29 20 7b  >refCount > 1) {
d260: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 2a 64 73 74 2c  ..Tcl_Obj **dst,
d270: 20 2a 2a 73 72 63 20 3d 20 26 6c 69 73 74 52 65   **src = &listRe
d280: 70 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a  pPtr->elements;.
d290: 09 4c 69 73 74 20 2a 6e 65 77 50 74 72 20 3d 20  .List *newPtr = 
d2a0: 41 74 74 65 6d 70 74 4e 65 77 4c 69 73 74 28 4e  AttemptNewList(N
d2b0: 55 4c 4c 2c 20 6c 69 73 74 52 65 70 50 74 72 2d  ULL, listRepPtr-
d2c0: 3e 6d 61 78 45 6c 65 6d 43 6f 75 6e 74 2c 20 4e  >maxElemCount, N
d2d0: 55 4c 4c 29 3b 0a 0a 09 69 66 20 28 6e 65 77 50  ULL);...if (newP
d2e0: 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20  tr == NULL) {.. 
d2f0: 20 20 20 6e 65 77 50 74 72 20 3d 20 41 74 74 65     newPtr = Atte
d300: 6d 70 74 4e 65 77 4c 69 73 74 28 69 6e 74 65 72  mptNewList(inter
d310: 70 2c 20 65 6c 65 6d 43 6f 75 6e 74 2c 20 4e 55  p, elemCount, NU
d320: 4c 4c 29 3b 0a 09 20 20 20 20 69 66 20 28 6e 65  LL);..    if (ne
d330: 77 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  wPtr == NULL) {.
d340: 09 09 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52  ..return TCL_ERR
d350: 4f 52 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 6e  OR;..    }..}..n
d360: 65 77 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74 2b  ewPtr->refCount+
d370: 2b 3b 0a 09 6e 65 77 50 74 72 2d 3e 65 6c 65 6d  +;..newPtr->elem
d380: 43 6f 75 6e 74 20 3d 20 65 6c 65 6d 43 6f 75 6e  Count = elemCoun
d390: 74 3b 0a 09 6e 65 77 50 74 72 2d 3e 63 61 6e 6f  t;..newPtr->cano
d3a0: 6e 69 63 61 6c 46 6c 61 67 20 3d 20 6c 69 73 74  nicalFlag = list
d3b0: 52 65 70 50 74 72 2d 3e 63 61 6e 6f 6e 69 63 61  RepPtr->canonica
d3c0: 6c 46 6c 61 67 3b 0a 0a 09 64 73 74 20 3d 20 26  lFlag;...dst = &
d3d0: 6e 65 77 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73  newPtr->elements
d3e0: 3b 0a 09 77 68 69 6c 65 20 28 65 6c 65 6d 43 6f  ;..while (elemCo
d3f0: 75 6e 74 2d 2d 29 20 7b 0a 09 20 20 20 20 2a 64  unt--) {..    *d
d400: 73 74 20 3d 20 2a 73 72 63 2b 2b 3b 0a 09 20 20  st = *src++;..  
d410: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75    Tcl_IncrRefCou
d420: 6e 74 28 2a 64 73 74 2b 2b 29 3b 0a 09 7d 0a 0a  nt(*dst++);..}..
d430: 09 6c 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66  .listRepPtr->ref
d440: 43 6f 75 6e 74 2d 2d 3b 0a 0a 09 6c 69 73 74 52  Count--;...listR
d450: 65 70 50 74 72 20 3d 20 6e 65 77 50 74 72 3b 0a  epPtr = newPtr;.
d460: 09 4c 69 73 74 52 65 73 65 74 49 6e 74 52 65 70  .ListResetIntRep
d470: 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52 65  (listPtr, listRe
d480: 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20  pPtr);.    }.   
d490: 20 65 6c 65 6d 50 74 72 73 20 3d 20 26 6c 69 73   elemPtrs = &lis
d4a0: 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d 65 6e 74  tRepPtr->element
d4b0: 73 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20  s;..    /*.     
d4c0: 2a 20 41 64 64 20 61 20 72 65 66 65 72 65 6e 63  * Add a referenc
d4d0: 65 20 74 6f 20 74 68 65 20 6e 65 77 20 6c 69 73  e to the new lis
d4e0: 74 20 65 6c 65 6d 65 6e 74 2e 0a 20 20 20 20 20  t element..     
d4f0: 2a 2f 0a 0a 20 20 20 20 54 63 6c 5f 49 6e 63 72  */..    Tcl_Incr
d500: 52 65 66 43 6f 75 6e 74 28 76 61 6c 75 65 50 74  RefCount(valuePt
d510: 72 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20  r);..    /*.    
d520: 20 2a 20 52 65 6d 6f 76 65 20 61 20 72 65 66 65   * Remove a refe
d530: 72 65 6e 63 65 20 66 72 6f 6d 20 74 68 65 20 6f  rence from the o
d540: 6c 64 20 6c 69 73 74 20 65 6c 65 6d 65 6e 74 2e  ld list element.
d550: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 54 63  .     */..    Tc
d560: 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74 28 65  l_DecrRefCount(e
d570: 6c 65 6d 50 74 72 73 5b 69 6e 64 65 78 5d 29 3b  lemPtrs[index]);
d580: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20  ..    /*.     * 
d590: 53 74 61 73 68 20 74 68 65 20 6e 65 77 20 6f 62  Stash the new ob
d5a0: 6a 65 63 74 20 69 6e 20 74 68 65 20 6c 69 73 74  ject in the list
d5b0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 65  ..     */..    e
d5c0: 6c 65 6d 50 74 72 73 5b 69 6e 64 65 78 5d 20 3d  lemPtrs[index] =
d5d0: 20 76 61 6c 75 65 50 74 72 3b 0a 0a 20 20 20 20   valuePtr;..    
d5e0: 2f 2a 0a 20 20 20 20 20 2a 20 49 6e 76 61 6c 69  /*.     * Invali
d5f0: 64 61 74 65 20 6f 75 74 64 61 74 65 64 20 69 6e  date outdated in
d600: 74 72 65 70 73 2e 0a 20 20 20 20 20 2a 2f 0a 0a  treps..     */..
d610: 20 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65      ListGetIntRe
d620: 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52  p(listPtr, listR
d630: 65 70 50 74 72 29 3b 0a 20 20 20 20 6c 69 73 74  epPtr);.    list
d640: 52 65 70 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74  RepPtr->refCount
d650: 2b 2b 3b 0a 20 20 20 20 54 63 6c 46 72 65 65 49  ++;.    TclFreeI
d660: 6e 74 52 65 70 28 6c 69 73 74 50 74 72 29 3b 0a  ntRep(listPtr);.
d670: 20 20 20 20 4c 69 73 74 53 65 74 49 6e 74 52 65      ListSetIntRe
d680: 70 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52  p(listPtr, listR
d690: 65 70 50 74 72 29 3b 0a 20 20 20 20 6c 69 73 74  epPtr);.    list
d6a0: 52 65 70 50 74 72 2d 3e 72 65 66 43 6f 75 6e 74  RepPtr->refCount
d6b0: 2d 2d 3b 0a 0a 20 20 20 20 54 63 6c 49 6e 76 61  --;..    TclInva
d6c0: 6c 69 64 61 74 65 53 74 72 69 6e 67 52 65 70 28  lidateStringRep(
d6d0: 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 20 20 72  listPtr);..    r
d6e0: 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a  eturn TCL_OK;.}.
d6f0: 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  ../*. *---------
d700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d710: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d720: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d730: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
d740: 0a 20 2a 20 46 72 65 65 4c 69 73 74 49 6e 74 65  . * FreeListInte
d750: 72 6e 61 6c 52 65 70 20 2d 2d 0a 20 2a 0a 20 2a  rnalRep --. *. *
d760: 09 44 65 61 6c 6c 6f 63 61 74 65 20 74 68 65 20  .Deallocate the 
d770: 73 74 6f 72 61 67 65 20 61 73 73 6f 63 69 61 74  storage associat
d780: 65 64 20 77 69 74 68 20 61 20 6c 69 73 74 20 6f  ed with a list o
d790: 62 6a 65 63 74 27 73 20 69 6e 74 65 72 6e 61 6c  bject's internal
d7a0: 0a 20 2a 09 72 65 70 72 65 73 65 6e 74 61 74 69  . *.representati
d7b0: 6f 6e 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74  on.. *. * Result
d7c0: 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20  s:. *.None.. *. 
d7d0: 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a  * Side effects:.
d7e0: 20 2a 09 46 72 65 65 73 20 6c 69 73 74 50 74 72   *.Frees listPtr
d7f0: 27 73 20 4c 69 73 74 2a 20 69 6e 74 65 72 6e 61  's List* interna
d800: 6c 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  l representation
d810: 2c 20 69 66 20 6e 6f 20 6c 6f 6e 67 65 72 20 73  , if no longer s
d820: 68 61 72 65 64 2e 0a 20 2a 09 4d 61 79 20 64 65  hared.. *.May de
d830: 63 72 65 6d 65 6e 74 20 74 68 65 20 72 65 66 20  crement the ref 
d840: 63 6f 75 6e 74 73 20 6f 66 20 65 6c 65 6d 65 6e  counts of elemen
d850: 74 20 6f 62 6a 65 63 74 73 2c 20 77 68 69 63 68  t objects, which
d860: 20 6d 61 79 20 66 72 65 65 20 74 68 65 6d 2e 0a   may free them..
d870: 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *. *-----------
d880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d890: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d8a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
d8b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a  -----------. */.
d8c0: 0a 73 74 61 74 69 63 20 76 6f 69 64 0a 46 72 65  .static void.Fre
d8d0: 65 4c 69 73 74 49 6e 74 65 72 6e 61 6c 52 65 70  eListInternalRep
d8e0: 28 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c  (.    Tcl_Obj *l
d8f0: 69 73 74 50 74 72 29 09 09 2f 2a 20 4c 69 73 74  istPtr)../* List
d900: 20 6f 62 6a 65 63 74 20 77 69 74 68 20 69 6e 74   object with int
d910: 65 72 6e 61 6c 20 72 65 70 20 74 6f 20 66 72 65  ernal rep to fre
d920: 65 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c 69 73 74  e. */.{.    List
d930: 20 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a 0a 20   *listRepPtr;.. 
d940: 20 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65 70     ListGetIntRep
d950: 28 6c 69 73 74 50 74 72 2c 20 6c 69 73 74 52 65  (listPtr, listRe
d960: 70 50 74 72 29 3b 0a 20 20 20 20 61 73 73 65 72  pPtr);.    asser
d970: 74 28 6c 69 73 74 52 65 70 50 74 72 20 21 3d 20  t(listRepPtr != 
d980: 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28  NULL);..    if (
d990: 6c 69 73 74 52 65 70 50 74 72 2d 3e 72 65 66 43  listRepPtr->refC
d9a0: 6f 75 6e 74 2d 2d 20 3c 3d 20 31 29 20 7b 0a 09  ount-- <= 1) {..
d9b0: 54 63 6c 5f 4f 62 6a 20 2a 2a 65 6c 65 6d 50 74  Tcl_Obj **elemPt
d9c0: 72 73 20 3d 20 26 6c 69 73 74 52 65 70 50 74 72  rs = &listRepPtr
d9d0: 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a 09 69 6e 74  ->elements;..int
d9e0: 20 69 2c 20 6e 75 6d 45 6c 65 6d 73 20 3d 20 6c   i, numElems = l
d9f0: 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43  istRepPtr->elemC
da00: 6f 75 6e 74 3b 0a 0a 09 66 6f 72 20 28 69 20 3d  ount;...for (i =
da10: 20 30 3b 20 20 69 20 3c 20 6e 75 6d 45 6c 65 6d   0;  i < numElem
da20: 73 3b 20 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20  s;  i++) {..    
da30: 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74  Tcl_DecrRefCount
da40: 28 65 6c 65 6d 50 74 72 73 5b 69 5d 29 3b 0a 09  (elemPtrs[i]);..
da50: 7d 0a 09 63 6b 66 72 65 65 28 6c 69 73 74 52 65  }..ckfree(listRe
da60: 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 7d 0a 0c  pPtr);.    }.}..
da70: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ./*. *----------
da80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
da90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
daa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a  ------------. *.
dac0: 20 2a 20 44 75 70 4c 69 73 74 49 6e 74 65 72 6e   * DupListIntern
dad0: 61 6c 52 65 70 20 2d 2d 0a 20 2a 0a 20 2a 09 49  alRep --. *. *.I
dae0: 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20 69 6e  nitialize the in
daf0: 74 65 72 6e 61 6c 20 72 65 70 72 65 73 65 6e 74  ternal represent
db00: 61 74 69 6f 6e 20 6f 66 20 61 20 6c 69 73 74 20  ation of a list 
db10: 54 63 6c 5f 4f 62 6a 20 74 6f 20 73 68 61 72 65  Tcl_Obj to share
db20: 20 74 68 65 0a 20 2a 09 69 6e 74 65 72 6e 61 6c   the. *.internal
db30: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20   representation 
db40: 6f 66 20 61 6e 20 65 78 69 73 74 69 6e 67 20 6c  of an existing l
db50: 69 73 74 20 6f 62 6a 65 63 74 2e 0a 20 2a 0a 20  ist object.. *. 
db60: 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 4e 6f  * Results:. *.No
db70: 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65  ne.. *. * Side e
db80: 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20 72  ffects:. *.The r
db90: 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 20 6f  eference count o
dba0: 66 20 74 68 65 20 4c 69 73 74 20 69 6e 74 65 72  f the List inter
dbb0: 6e 61 6c 20 72 65 70 20 69 73 20 69 6e 63 72 65  nal rep is incre
dbc0: 6d 65 6e 74 65 64 2e 0a 20 2a 0a 20 2a 2d 2d 2d  mented.. *. *---
dbd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dbe0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dbf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dc00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dc10: 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20  ---. */..static 
dc20: 76 6f 69 64 0a 44 75 70 4c 69 73 74 49 6e 74 65  void.DupListInte
dc30: 72 6e 61 6c 52 65 70 28 0a 20 20 20 20 54 63 6c  rnalRep(.    Tcl
dc40: 5f 4f 62 6a 20 2a 73 72 63 50 74 72 2c 09 09 2f  _Obj *srcPtr,../
dc50: 2a 20 4f 62 6a 65 63 74 20 77 69 74 68 20 69 6e  * Object with in
dc60: 74 65 72 6e 61 6c 20 72 65 70 20 74 6f 20 63 6f  ternal rep to co
dc70: 70 79 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f  py. */.    Tcl_O
dc80: 62 6a 20 2a 63 6f 70 79 50 74 72 29 09 09 2f 2a  bj *copyPtr)../*
dc90: 20 4f 62 6a 65 63 74 20 77 69 74 68 20 69 6e 74   Object with int
dca0: 65 72 6e 61 6c 20 72 65 70 20 74 6f 20 73 65 74  ernal rep to set
dcb0: 2e 20 2a 2f 0a 7b 0a 20 20 20 20 4c 69 73 74 20  . */.{.    List 
dcc0: 2a 6c 69 73 74 52 65 70 50 74 72 3b 0a 0a 20 20  *listRepPtr;..  
dcd0: 20 20 4c 69 73 74 47 65 74 49 6e 74 52 65 70 28    ListGetIntRep(
dce0: 73 72 63 50 74 72 2c 20 6c 69 73 74 52 65 70 50  srcPtr, listRepP
dcf0: 74 72 29 3b 0a 20 20 20 20 61 73 73 65 72 74 28  tr);.    assert(
dd00: 6c 69 73 74 52 65 70 50 74 72 20 21 3d 20 4e 55  listRepPtr != NU
dd10: 4c 4c 29 3b 0a 20 20 20 20 4c 69 73 74 53 65 74  LL);.    ListSet
dd20: 49 6e 74 52 65 70 28 63 6f 70 79 50 74 72 2c 20  IntRep(copyPtr, 
dd30: 6c 69 73 74 52 65 70 50 74 72 29 3b 0a 7d 0a 0c  listRepPtr);.}..
dd40: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ./*. *----------
dd50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dd60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dd70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
dd80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a  ------------. *.
dd90: 20 2a 20 53 65 74 4c 69 73 74 46 72 6f 6d 41 6e   * SetListFromAn
dda0: 79 20 2d 2d 0a 20 2a 0a 20 2a 09 41 74 74 65 6d  y --. *. *.Attem
ddb0: 70 74 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61  pt to generate a
ddc0: 20 6c 69 73 74 20 69 6e 74 65 72 6e 61 6c 20 66   list internal f
ddd0: 6f 72 6d 20 66 6f 72 20 74 68 65 20 54 63 6c 20  orm for the Tcl 
dde0: 6f 62 6a 65 63 74 20 22 6f 62 6a 50 74 72 22 2e  object "objPtr".
ddf0: 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a  . *. * Results:.
de00: 20 2a 09 54 68 65 20 72 65 74 75 72 6e 20 76 61   *.The return va
de10: 6c 75 65 20 69 73 20 54 43 4c 5f 4f 4b 20 6f 72  lue is TCL_OK or
de20: 20 54 43 4c 5f 45 52 52 4f 52 2e 20 49 66 20 61   TCL_ERROR. If a
de30: 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 73 20 64  n error occurs d
de40: 75 72 69 6e 67 0a 20 2a 09 63 6f 6e 76 65 72 73  uring. *.convers
de50: 69 6f 6e 2c 20 61 6e 20 65 72 72 6f 72 20 6d 65  ion, an error me
de60: 73 73 61 67 65 20 69 73 20 6c 65 66 74 20 69 6e  ssage is left in
de70: 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 65 72   the interpreter
de80: 27 73 20 72 65 73 75 6c 74 0a 20 2a 09 75 6e 6c  's result. *.unl
de90: 65 73 73 20 22 69 6e 74 65 72 70 22 20 69 73 20  ess "interp" is 
dea0: 4e 55 4c 4c 2e 0a 20 2a 0a 20 2a 20 53 69 64 65  NULL.. *. * Side
deb0: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 49 66 20   effects:. *.If 
dec0: 6e 6f 20 65 72 72 6f 72 20 6f 63 63 75 72 73 2c  no error occurs,
ded0: 20 61 20 6c 69 73 74 20 69 73 20 73 74 6f 72 65   a list is store
dee0: 64 20 61 73 20 22 6f 62 6a 50 74 72 22 73 20 69  d as "objPtr"s i
def0: 6e 74 65 72 6e 61 6c 0a 20 2a 09 72 65 70 72 65  nternal. *.repre
df00: 73 65 6e 74 61 74 69 6f 6e 2e 0a 20 2a 0a 20 2a  sentation.. *. *
df10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
df20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
df30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
df40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
df50: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 61 74  ------. */..stat
df60: 69 63 20 69 6e 74 0a 53 65 74 4c 69 73 74 46 72  ic int.SetListFr
df70: 6f 6d 41 6e 79 28 0a 20 20 20 20 54 63 6c 5f 49  omAny(.    Tcl_I
df80: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 09 09  nterp *interp,..
df90: 2f 2a 20 55 73 65 64 20 66 6f 72 20 65 72 72 6f  /* Used for erro
dfa0: 72 20 72 65 70 6f 72 74 69 6e 67 20 69 66 20 6e  r reporting if n
dfb0: 6f 74 20 4e 55 4c 4c 2e 20 2a 2f 0a 20 20 20 20  ot NULL. */.    
dfc0: 54 63 6c 5f 4f 62 6a 20 2a 6f 62 6a 50 74 72 29  Tcl_Obj *objPtr)
dfd0: 09 09 2f 2a 20 54 68 65 20 6f 62 6a 65 63 74 20  ../* The object 
dfe0: 74 6f 20 63 6f 6e 76 65 72 74 2e 20 2a 2f 0a 7b  to convert. */.{
dff0: 0a 20 20 20 20 4c 69 73 74 20 2a 6c 69 73 74 52  .    List *listR
e000: 65 70 50 74 72 3b 0a 20 20 20 20 54 63 6c 5f 4f  epPtr;.    Tcl_O
e010: 62 6a 20 2a 2a 65 6c 65 6d 50 74 72 73 3b 0a 0a  bj **elemPtrs;..
e020: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 44 69      /*.     * Di
e030: 63 74 69 6f 6e 61 72 69 65 73 20 61 72 65 20 61  ctionaries are a
e040: 20 73 70 65 63 69 61 6c 20 63 61 73 65 3b 20 74   special case; t
e050: 68 65 79 20 68 61 76 65 20 61 20 73 74 72 69 6e  hey have a strin
e060: 67 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  g representation
e070: 20 73 75 63 68 0a 20 20 20 20 20 2a 20 74 68 61   such.     * tha
e080: 74 20 2a 61 6c 6c 2a 20 76 61 6c 69 64 20 64 69  t *all* valid di
e090: 63 74 69 6f 6e 61 72 69 65 73 20 61 72 65 20 76  ctionaries are v
e0a0: 61 6c 69 64 20 6c 69 73 74 73 2e 20 48 65 6e 63  alid lists. Henc
e0b0: 65 20 77 65 20 63 61 6e 20 63 6f 6e 76 65 72 74  e we can convert
e0c0: 0a 20 20 20 20 20 2a 20 6d 6f 72 65 20 64 69 72  .     * more dir
e0d0: 65 63 74 6c 79 2e 20 4f 6e 6c 79 20 64 6f 20 74  ectly. Only do t
e0e0: 68 69 73 20 77 68 65 6e 20 74 68 65 72 65 27 73  his when there's
e0f0: 20 6e 6f 20 65 78 69 73 74 69 6e 67 20 73 74 72   no existing str
e100: 69 6e 67 20 72 65 70 3b 20 69 66 0a 20 20 20 20  ing rep; if.    
e110: 20 2a 20 74 68 65 72 65 20 69 73 2c 20 69 74 20   * there is, it 
e120: 69 73 20 74 68 65 20 73 74 72 69 6e 67 20 72 65  is the string re
e130: 70 20 74 68 61 74 27 73 20 61 75 74 68 6f 72 69  p that's authori
e140: 74 61 74 69 76 65 20 28 62 65 63 61 75 73 65 20  tative (because 
e150: 69 74 20 63 6f 75 6c 64 0a 20 20 20 20 20 2a 20  it could.     * 
e160: 64 65 73 63 72 69 62 65 20 64 75 70 6c 69 63 61  describe duplica
e170: 74 65 20 6b 65 79 73 29 2e 0a 20 20 20 20 20 2a  te keys)..     *
e180: 2f 0a 0a 20 20 20 20 69 66 20 28 21 54 63 6c 48  /..    if (!TclH
e190: 61 73 53 74 72 69 6e 67 52 65 70 28 6f 62 6a 50  asStringRep(objP
e1a0: 74 72 29 20 26 26 20 54 63 6c 48 61 73 49 6e 74  tr) && TclHasInt
e1b0: 52 65 70 28 6f 62 6a 50 74 72 2c 20 26 74 63 6c  Rep(objPtr, &tcl
e1c0: 44 69 63 74 54 79 70 65 29 29 20 7b 0a 09 54 63  DictType)) {..Tc
e1d0: 6c 5f 4f 62 6a 20 2a 6b 65 79 50 74 72 2c 20 2a  l_Obj *keyPtr, *
e1e0: 76 61 6c 75 65 50 74 72 3b 0a 09 54 63 6c 5f 44  valuePtr;..Tcl_D
e1f0: 69 63 74 53 65 61 72 63 68 20 73 65 61 72 63 68  ictSearch search
e200: 3b 0a 09 69 6e 74 20 64 6f 6e 65 2c 20 73 69 7a  ;..int done, siz
e210: 65 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 43 72 65 61  e;.../*.. * Crea
e220: 74 65 20 74 68 65 20 6e 65 77 20 6c 69 73 74 20  te the new list 
e230: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e 20  representation. 
e240: 4e 6f 74 65 20 74 68 61 74 20 77 65 20 64 6f 20  Note that we do 
e250: 6e 6f 74 20 6e 65 65 64 20 74 6f 20 64 6f 0a 09  not need to do..
e260: 20 2a 20 61 6e 79 74 68 69 6e 67 20 77 69 74 68   * anything with
e270: 20 74 68 65 20 73 74 72 69 6e 67 20 72 65 70 72   the string repr
e280: 65 73 65 6e 74 61 74 69 6f 6e 20 61 73 20 74 68  esentation as th
e290: 65 20 74 72 61 6e 73 66 6f 72 6d 61 74 69 6f 6e  e transformation
e2a0: 20 28 61 6e 64 0a 09 20 2a 20 74 68 65 20 72 65   (and.. * the re
e2b0: 76 65 72 73 65 20 62 61 63 6b 20 74 6f 20 61 20  verse back to a 
e2c0: 64 69 63 74 69 6f 6e 61 72 79 29 20 61 72 65 20  dictionary) are 
e2d0: 62 6f 74 68 20 6f 72 64 65 72 2d 70 72 65 73 65  both order-prese
e2e0: 72 76 69 6e 67 2e 20 41 6c 73 6f 0a 09 20 2a 20  rving. Also.. * 
e2f0: 6e 6f 74 65 20 74 68 61 74 20 73 69 6e 63 65 20  note that since 
e300: 77 65 20 6b 6e 6f 77 20 77 65 27 76 65 20 67 6f  we know we've go
e310: 74 20 61 20 76 61 6c 69 64 20 64 69 63 74 69 6f  t a valid dictio
e320: 6e 61 72 79 20 28 62 79 0a 09 20 2a 20 72 65 70  nary (by.. * rep
e330: 72 65 73 65 6e 74 61 74 69 6f 6e 29 20 77 65 20  resentation) we 
e340: 61 6c 73 6f 20 6b 6e 6f 77 20 74 68 61 74 20 66  also know that f
e350: 65 74 63 68 69 6e 67 20 74 68 65 20 73 69 7a 65  etching the size
e360: 20 6f 66 20 74 68 65 0a 09 20 2a 20 64 69 63 74   of the.. * dict
e370: 69 6f 6e 61 72 79 20 6f 72 20 69 74 65 72 61 74  ionary or iterat
e380: 69 6e 67 20 6f 76 65 72 20 69 74 20 77 69 6c 6c  ing over it will
e390: 20 6e 6f 74 20 66 61 69 6c 2e 0a 09 20 2a 2f 0a   not fail... */.
e3a0: 0a 09 54 63 6c 5f 44 69 63 74 4f 62 6a 53 69 7a  ..Tcl_DictObjSiz
e3b0: 65 28 4e 55 4c 4c 2c 20 6f 62 6a 50 74 72 2c 20  e(NULL, objPtr, 
e3c0: 26 73 69 7a 65 29 3b 0a 09 6c 69 73 74 52 65 70  &size);..listRep
e3d0: 50 74 72 20 3d 20 41 74 74 65 6d 70 74 4e 65 77  Ptr = AttemptNew
e3e0: 4c 69 73 74 28 69 6e 74 65 72 70 2c 20 73 69 7a  List(interp, siz
e3f0: 65 20 3e 20 30 20 3f 20 32 2a 73 69 7a 65 20 3a  e > 0 ? 2*size :
e400: 20 31 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 20 28   1, NULL);..if (
e410: 21 6c 69 73 74 52 65 70 50 74 72 29 20 7b 0a 09  !listRepPtr) {..
e420: 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 45      return TCL_E
e430: 52 52 4f 52 3b 0a 09 7d 0a 09 6c 69 73 74 52 65  RROR;..}..listRe
e440: 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e 74 20  pPtr->elemCount 
e450: 3d 20 32 20 2a 20 73 69 7a 65 3b 0a 0a 09 2f 2a  = 2 * size;.../*
e460: 0a 09 20 2a 20 50 6f 70 75 6c 61 74 65 20 74 68  .. * Populate th
e470: 65 20 6c 69 73 74 20 72 65 70 72 65 73 65 6e 74  e list represent
e480: 61 74 69 6f 6e 2e 0a 09 20 2a 2f 0a 0a 09 65 6c  ation... */...el
e490: 65 6d 50 74 72 73 20 3d 20 26 6c 69 73 74 52 65  emPtrs = &listRe
e4a0: 70 50 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a  pPtr->elements;.
e4b0: 09 54 63 6c 5f 44 69 63 74 4f 62 6a 46 69 72 73  .Tcl_DictObjFirs
e4c0: 74 28 4e 55 4c 4c 2c 20 6f 62 6a 50 74 72 2c 20  t(NULL, objPtr, 
e4d0: 26 73 65 61 72 63 68 2c 20 26 6b 65 79 50 74 72  &search, &keyPtr
e4e0: 2c 20 26 76 61 6c 75 65 50 74 72 2c 20 26 64 6f  , &valuePtr, &do
e4f0: 6e 65 29 3b 0a 09 77 68 69 6c 65 20 28 21 64 6f  ne);..while (!do
e500: 6e 65 29 20 7b 0a 09 20 20 20 20 2a 65 6c 65 6d  ne) {..    *elem
e510: 50 74 72 73 2b 2b 20 3d 20 6b 65 79 50 74 72 3b  Ptrs++ = keyPtr;
e520: 0a 09 20 20 20 20 2a 65 6c 65 6d 50 74 72 73 2b  ..    *elemPtrs+
e530: 2b 20 3d 20 76 61 6c 75 65 50 74 72 3b 0a 09 20  + = valuePtr;.. 
e540: 20 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f     Tcl_IncrRefCo
e550: 75 6e 74 28 6b 65 79 50 74 72 29 3b 0a 09 20 20  unt(keyPtr);..  
e560: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75    Tcl_IncrRefCou
e570: 6e 74 28 76 61 6c 75 65 50 74 72 29 3b 0a 09 20  nt(valuePtr);.. 
e580: 20 20 20 54 63 6c 5f 44 69 63 74 4f 62 6a 4e 65     Tcl_DictObjNe
e590: 78 74 28 26 73 65 61 72 63 68 2c 20 26 6b 65 79  xt(&search, &key
e5a0: 50 74 72 2c 20 26 76 61 6c 75 65 50 74 72 2c 20  Ptr, &valuePtr, 
e5b0: 26 64 6f 6e 65 29 3b 0a 09 7d 0a 20 20 20 20 7d  &done);..}.    }
e5c0: 20 65 6c 73 65 20 7b 0a 09 69 6e 74 20 65 73 74   else {..int est
e5d0: 43 6f 75 6e 74 2c 20 6c 65 6e 67 74 68 3b 0a 09  Count, length;..
e5e0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 6c 69 6d 69  const char *limi
e5f0: 74 2c 20 2a 6e 65 78 74 45 6c 65 6d 20 3d 20 54  t, *nextElem = T
e600: 63 6c 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f  clGetStringFromO
e610: 62 6a 28 6f 62 6a 50 74 72 2c 20 26 6c 65 6e 67  bj(objPtr, &leng
e620: 74 68 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 41 6c  th);.../*.. * Al
e630: 6c 6f 63 61 74 65 20 65 6e 6f 75 67 68 20 73 70  locate enough sp
e640: 61 63 65 20 74 6f 20 68 6f 6c 64 20 61 20 28 54  ace to hold a (T
e650: 63 6c 5f 4f 62 6a 20 2a 29 20 66 6f 72 20 65 61  cl_Obj *) for ea
e660: 63 68 0a 09 20 2a 20 28 70 6f 73 73 69 62 6c 65  ch.. * (possible
e670: 29 20 6c 69 73 74 20 65 6c 65 6d 65 6e 74 2e 0a  ) list element..
e680: 09 20 2a 2f 0a 0a 09 65 73 74 43 6f 75 6e 74 20  . */...estCount 
e690: 3d 20 54 63 6c 4d 61 78 4c 69 73 74 4c 65 6e 67  = TclMaxListLeng
e6a0: 74 68 28 6e 65 78 74 45 6c 65 6d 2c 20 6c 65 6e  th(nextElem, len
e6b0: 67 74 68 2c 20 26 6c 69 6d 69 74 29 3b 0a 09 65  gth, &limit);..e
e6c0: 73 74 43 6f 75 6e 74 20 2b 3d 20 28 65 73 74 43  stCount += (estC
e6d0: 6f 75 6e 74 20 3d 3d 20 30 29 3b 09 2f 2a 20 53  ount == 0);./* S
e6e0: 6d 61 6c 6c 65 73 74 20 6c 69 73 74 20 73 74 72  mallest list str
e6f0: 75 63 74 20 68 6f 6c 64 73 20 31 0a 09 09 09 09  uct holds 1.....
e700: 09 20 2a 20 65 6c 65 6d 65 6e 74 2e 20 2a 2f 0a  . * element. */.
e710: 09 6c 69 73 74 52 65 70 50 74 72 20 3d 20 41 74  .listRepPtr = At
e720: 74 65 6d 70 74 4e 65 77 4c 69 73 74 28 69 6e 74  temptNewList(int
e730: 65 72 70 2c 20 65 73 74 43 6f 75 6e 74 2c 20 4e  erp, estCount, N
e740: 55 4c 4c 29 3b 0a 09 69 66 20 28 6c 69 73 74 52  ULL);..if (listR
e750: 65 70 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b  epPtr == NULL) {
e760: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c  ..    return TCL
e770: 5f 45 52 52 4f 52 3b 0a 09 7d 0a 09 65 6c 65 6d  _ERROR;..}..elem
e780: 50 74 72 73 20 3d 20 26 6c 69 73 74 52 65 70 50  Ptrs = &listRepP
e790: 74 72 2d 3e 65 6c 65 6d 65 6e 74 73 3b 0a 0a 09  tr->elements;...
e7a0: 2f 2a 0a 09 20 2a 20 45 61 63 68 20 69 74 65 72  /*.. * Each iter
e7b0: 61 74 69 6f 6e 2c 20 70 61 72 73 65 20 61 6e 64  ation, parse and
e7c0: 20 73 74 6f 72 65 20 61 20 6c 69 73 74 20 65 6c   store a list el
e7d0: 65 6d 65 6e 74 2e 0a 09 20 2a 2f 0a 0a 09 77 68  ement... */...wh
e7e0: 69 6c 65 20 28 6e 65 78 74 45 6c 65 6d 20 3c 20  ile (nextElem < 
e7f0: 6c 69 6d 69 74 29 20 7b 0a 09 20 20 20 20 63 6f  limit) {..    co
e800: 6e 73 74 20 63 68 61 72 20 2a 65 6c 65 6d 53 74  nst char *elemSt
e810: 61 72 74 3b 0a 09 20 20 20 20 63 68 61 72 20 2a  art;..    char *
e820: 63 68 65 63 6b 3b 0a 09 20 20 20 20 69 6e 74 20  check;..    int 
e830: 65 6c 65 6d 53 69 7a 65 2c 20 6c 69 74 65 72 61  elemSize, litera
e840: 6c 3b 0a 0a 09 20 20 20 20 69 66 20 28 54 43 4c  l;...    if (TCL
e850: 5f 4f 4b 20 21 3d 20 54 63 6c 46 69 6e 64 45 6c  _OK != TclFindEl
e860: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6e 65  ement(interp, ne
e870: 78 74 45 6c 65 6d 2c 20 6c 69 6d 69 74 20 2d 20  xtElem, limit - 
e880: 6e 65 78 74 45 6c 65 6d 2c 0a 09 09 20 20 20 20  nextElem,...    
e890: 26 65 6c 65 6d 53 74 61 72 74 2c 20 26 6e 65 78  &elemStart, &nex
e8a0: 74 45 6c 65 6d 2c 20 26 65 6c 65 6d 53 69 7a 65  tElem, &elemSize
e8b0: 2c 20 26 6c 69 74 65 72 61 6c 29 29 20 7b 0a 09  , &literal)) {..
e8c0: 20 20 20 20 66 61 69 6c 3a 0a 09 09 77 68 69 6c      fail:...whil
e8d0: 65 20 28 2d 2d 65 6c 65 6d 50 74 72 73 20 3e 3d  e (--elemPtrs >=
e8e0: 20 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c   &listRepPtr->el
e8f0: 65 6d 65 6e 74 73 29 20 7b 0a 09 09 20 20 20 20  ements) {...    
e900: 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74  Tcl_DecrRefCount
e910: 28 2a 65 6c 65 6d 50 74 72 73 29 3b 0a 09 09 7d  (*elemPtrs);...}
e920: 0a 09 09 63 6b 66 72 65 65 28 6c 69 73 74 52 65  ...ckfree(listRe
e930: 70 50 74 72 29 3b 0a 09 09 72 65 74 75 72 6e 20  pPtr);...return 
e940: 54 43 4c 5f 45 52 52 4f 52 3b 0a 09 20 20 20 20  TCL_ERROR;..    
e950: 7d 0a 09 20 20 20 20 69 66 20 28 65 6c 65 6d 53  }..    if (elemS
e960: 74 61 72 74 20 3d 3d 20 6c 69 6d 69 74 29 20 7b  tart == limit) {
e970: 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 7d  ...break;..    }
e980: 0a 0a 09 20 20 20 20 54 63 6c 4e 65 77 4f 62 6a  ...    TclNewObj
e990: 28 2a 65 6c 65 6d 50 74 72 73 29 3b 0a 09 20 20  (*elemPtrs);..  
e9a0: 20 20 54 63 6c 49 6e 76 61 6c 69 64 61 74 65 53    TclInvalidateS
e9b0: 74 72 69 6e 67 52 65 70 28 2a 65 6c 65 6d 50 74  tringRep(*elemPt
e9c0: 72 73 29 3b 0a 09 20 20 20 20 63 68 65 63 6b 20  rs);..    check 
e9d0: 3d 20 54 63 6c 5f 49 6e 69 74 53 74 72 69 6e 67  = Tcl_InitString
e9e0: 52 65 70 28 2a 65 6c 65 6d 50 74 72 73 2c 20 6c  Rep(*elemPtrs, l
e9f0: 69 74 65 72 61 6c 20 3f 20 65 6c 65 6d 53 74 61  iteral ? elemSta
ea00: 72 74 20 3a 20 4e 55 4c 4c 2c 0a 09 09 20 20 20  rt : NULL,...   
ea10: 20 65 6c 65 6d 53 69 7a 65 29 3b 0a 09 20 20 20   elemSize);..   
ea20: 20 69 66 20 28 65 6c 65 6d 53 69 7a 65 20 26 26   if (elemSize &&
ea30: 20 63 68 65 63 6b 20 3d 3d 20 4e 55 4c 4c 29 20   check == NULL) 
ea40: 7b 0a 09 09 69 66 20 28 69 6e 74 65 72 70 29 20  {...if (interp) 
ea50: 7b 0a 09 09 20 20 20 20 54 63 6c 5f 53 65 74 4f  {...    Tcl_SetO
ea60: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c  bjResult(interp,
ea70: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
ea80: 6a 28 0a 09 09 09 20 20 20 20 22 63 61 6e 6e 6f  j(....    "canno
ea90: 74 20 63 6f 6e 73 74 72 75 63 74 20 6c 69 73 74  t construct list
eaa0: 2c 20 6f 75 74 20 6f 66 20 6d 65 6d 6f 72 79 22  , out of memory"
eab0: 2c 20 2d 31 29 29 3b 0a 09 09 20 20 20 20 54 63  , -1));...    Tc
eac0: 6c 5f 53 65 74 45 72 72 6f 72 43 6f 64 65 28 69  l_SetErrorCode(i
ead0: 6e 74 65 72 70 2c 20 22 54 43 4c 22 2c 20 22 4d  nterp, "TCL", "M
eae0: 45 4d 4f 52 59 22 2c 20 4e 55 4c 4c 29 3b 0a 09  EMORY", NULL);..
eaf0: 09 7d 0a 09 09 67 6f 74 6f 20 66 61 69 6c 3b 0a  .}...goto fail;.
eb00: 09 20 20 20 20 7d 0a 09 20 20 20 20 69 66 20 28  .    }..    if (
eb10: 21 6c 69 74 65 72 61 6c 29 20 7b 0a 09 09 54 63  !literal) {...Tc
eb20: 6c 5f 49 6e 69 74 53 74 72 69 6e 67 52 65 70 28  l_InitStringRep(
eb30: 2a 65 6c 65 6d 50 74 72 73 2c 20 4e 55 4c 4c 2c  *elemPtrs, NULL,
eb40: 0a 09 09 09 54 63 6c 43 6f 70 79 41 6e 64 43 6f  ....TclCopyAndCo
eb50: 6c 6c 61 70 73 65 28 65 6c 65 6d 53 69 7a 65 2c  llapse(elemSize,
eb60: 20 65 6c 65 6d 53 74 61 72 74 2c 20 63 68 65 63   elemStart, chec
eb70: 6b 29 29 3b 0a 09 20 20 20 20 7d 0a 0a 09 20 20  k));..    }...  
eb80: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75    Tcl_IncrRefCou
eb90: 6e 74 28 2a 65 6c 65 6d 50 74 72 73 2b 2b 29 3b  nt(*elemPtrs++);
eba0: 2f 2a 20 53 69 6e 63 65 20 6c 69 73 74 20 6e 6f  /* Since list no
ebb0: 77 20 68 6f 6c 64 73 20 72 65 66 20 74 6f 20 69  w holds ref to i
ebc0: 74 2e 20 2a 2f 0a 09 7d 0a 0a 20 09 6c 69 73 74  t. */..}.. .list
ebd0: 52 65 70 50 74 72 2d 3e 65 6c 65 6d 43 6f 75 6e  RepPtr->elemCoun
ebe0: 74 20 3d 20 65 6c 65 6d 50 74 72 73 20 2d 20 26  t = elemPtrs - &
ebf0: 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c 65 6d  listRepPtr->elem
ec00: 65 6e 74 73 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  ents;.    }..   
ec10: 20 2f 2a 0a 20 20 20 20 20 2a 20 53 74 6f 72 65   /*.     * Store
ec20: 20 74 68 65 20 6e 65 77 20 69 6e 74 65 72 6e 61   the new interna
ec30: 6c 52 65 70 2e 20 57 65 20 64 6f 20 74 68 69 73  lRep. We do this
ec40: 20 61 73 20 6c 61 74 65 0a 20 20 20 20 20 2a 20   as late.     * 
ec50: 61 73 20 70 6f 73 73 69 62 6c 65 20 74 6f 20 61  as possible to a
ec60: 6c 6c 6f 77 20 74 68 65 20 63 6f 6e 76 65 72 73  llow the convers
ec70: 69 6f 6e 20 63 6f 64 65 2c 20 69 6e 20 70 61 72  ion code, in par
ec80: 74 69 63 75 6c 61 72 0a 20 20 20 20 20 2a 20 54  ticular.     * T
ec90: 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d  cl_GetStringFrom
eca0: 4f 62 6a 2c 20 74 6f 20 75 73 65 20 74 68 65 20  Obj, to use the 
ecb0: 6f 6c 64 20 69 6e 74 65 72 6e 61 6c 52 65 70 2e  old internalRep.
ecc0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 4c 69  .     */..    Li
ecd0: 73 74 53 65 74 49 6e 74 52 65 70 28 6f 62 6a 50  stSetIntRep(objP
ece0: 74 72 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b  tr, listRepPtr);
ecf0: 0a 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f  .    return TCL_
ed00: 4f 4b 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d  OK;.}.../*. *---
ed10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ed20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ed30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ed40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ed50: 2d 2d 2d 0a 20 2a 0a 20 2a 20 55 70 64 61 74 65  ---. *. * Update
ed60: 53 74 72 69 6e 67 4f 66 4c 69 73 74 20 2d 2d 0a  StringOfList --.
ed70: 20 2a 0a 20 2a 09 55 70 64 61 74 65 20 74 68 65   *. *.Update the
ed80: 20 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e   string represen
ed90: 74 61 74 69 6f 6e 20 66 6f 72 20 61 20 6c 69 73  tation for a lis
eda0: 74 20 6f 62 6a 65 63 74 2e 20 4e 6f 74 65 3a 20  t object. Note: 
edb0: 54 68 69 73 0a 20 2a 09 66 75 6e 63 74 69 6f 6e  This. *.function
edc0: 20 64 6f 65 73 20 6e 6f 74 20 69 6e 76 61 6c 69   does not invali
edd0: 64 61 74 65 20 61 6e 20 65 78 69 73 74 69 6e 67  date an existing
ede0: 20 6f 6c 64 20 73 74 72 69 6e 67 20 72 65 70 20   old string rep 
edf0: 73 6f 20 73 74 6f 72 61 67 65 0a 20 2a 09 77 69  so storage. *.wi
ee00: 6c 6c 20 62 65 20 6c 6f 73 74 20 69 66 20 74 68  ll be lost if th
ee10: 69 73 20 68 61 73 20 6e 6f 74 20 61 6c 72 65 61  is has not alrea
ee20: 64 79 20 62 65 65 6e 20 64 6f 6e 65 2e 0a 20 2a  dy been done.. *
ee30: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09  . * Results:. *.
ee40: 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65  None.. *. * Side
ee50: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65   effects:. *.The
ee60: 20 6f 62 6a 65 63 74 27 73 20 73 74 72 69 6e 67   object's string
ee70: 20 69 73 20 73 65 74 20 74 6f 20 61 20 76 61 6c   is set to a val
ee80: 69 64 20 73 74 72 69 6e 67 20 74 68 61 74 20 72  id string that r
ee90: 65 73 75 6c 74 73 20 66 72 6f 6d 20 74 68 65 0a  esults from the.
eea0: 20 2a 09 6c 69 73 74 2d 74 6f 2d 73 74 72 69 6e   *.list-to-strin
eeb0: 67 20 63 6f 6e 76 65 72 73 69 6f 6e 2e 20 54 68  g conversion. Th
eec0: 69 73 20 73 74 72 69 6e 67 20 77 69 6c 6c 20 62  is string will b
eed0: 65 20 65 6d 70 74 79 20 69 66 20 74 68 65 20 6c  e empty if the l
eee0: 69 73 74 20 68 61 73 0a 20 2a 09 6e 6f 20 65 6c  ist has. *.no el
eef0: 65 6d 65 6e 74 73 2e 20 54 68 65 20 6c 69 73 74  ements. The list
ef00: 20 69 6e 74 65 72 6e 61 6c 20 72 65 70 72 65 73   internal repres
ef10: 65 6e 74 61 74 69 6f 6e 20 73 68 6f 75 6c 64 20  entation should 
ef20: 6e 6f 74 20 62 65 20 4e 55 4c 4c 20 61 6e 64 0a  not be NULL and.
ef30: 20 2a 09 77 65 20 61 73 73 75 6d 65 20 69 74 20   *.we assume it 
ef40: 69 73 20 6e 6f 74 20 4e 55 4c 4c 2e 0a 20 2a 0a  is not NULL.. *.
ef50: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
ef60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ef70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ef80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
ef90: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74  --------. */..st
efa0: 61 74 69 63 20 76 6f 69 64 0a 55 70 64 61 74 65  atic void.Update
efb0: 53 74 72 69 6e 67 4f 66 4c 69 73 74 28 0a 20 20  StringOfList(.  
efc0: 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50    Tcl_Obj *listP
efd0: 74 72 29 09 09 2f 2a 20 4c 69 73 74 20 6f 62 6a  tr)../* List obj
efe0: 65 63 74 20 77 69 74 68 20 73 74 72 69 6e 67 20  ect with string 
eff0: 72 65 70 20 74 6f 20 75 70 64 61 74 65 2e 20 2a  rep to update. *
f000: 2f 0a 7b 0a 23 20 20 20 64 65 66 69 6e 65 20 4c  /.{.#   define L
f010: 4f 43 41 4c 5f 53 49 5a 45 20 36 34 0a 20 20 20  OCAL_SIZE 64.   
f020: 20 63 68 61 72 20 6c 6f 63 61 6c 46 6c 61 67 73   char localFlags
f030: 5b 4c 4f 43 41 4c 5f 53 49 5a 45 5d 2c 20 2a 66  [LOCAL_SIZE], *f
f040: 6c 61 67 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20  lagPtr = NULL;. 
f050: 20 20 20 69 6e 74 20 6e 75 6d 45 6c 65 6d 73 2c     int numElems,
f060: 20 69 2c 20 6c 65 6e 67 74 68 2c 20 62 79 74 65   i, length, byte
f070: 73 4e 65 65 64 65 64 20 3d 20 30 3b 0a 20 20 20  sNeeded = 0;.   
f080: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 65 6c 65   const char *ele
f090: 6d 2c 20 2a 73 74 61 72 74 3b 0a 20 20 20 20 63  m, *start;.    c
f0a0: 68 61 72 20 2a 64 73 74 3b 0a 20 20 20 20 54 63  har *dst;.    Tc
f0b0: 6c 5f 4f 62 6a 20 2a 2a 65 6c 65 6d 50 74 72 73  l_Obj **elemPtrs
f0c0: 3b 0a 20 20 20 20 4c 69 73 74 20 2a 6c 69 73 74  ;.    List *list
f0d0: 52 65 70 50 74 72 3b 0a 0a 20 20 20 20 4c 69 73  RepPtr;..    Lis
f0e0: 74 47 65 74 49 6e 74 52 65 70 28 6c 69 73 74 50  tGetIntRep(listP
f0f0: 74 72 2c 20 6c 69 73 74 52 65 70 50 74 72 29 3b  tr, listRepPtr);
f100: 0a 0a 20 20 20 20 61 73 73 65 72 74 28 6c 69 73  ..    assert(lis
f110: 74 52 65 70 50 74 72 20 21 3d 20 4e 55 4c 4c 29  tRepPtr != NULL)
f120: 3b 0a 0a 20 20 20 20 6e 75 6d 45 6c 65 6d 73 20  ;..    numElems 
f130: 3d 20 6c 69 73 74 52 65 70 50 74 72 2d 3e 65 6c  = listRepPtr->el
f140: 65 6d 43 6f 75 6e 74 3b 0a 0a 20 20 20 20 2f 2a  emCount;..    /*
f150: 0a 20 20 20 20 20 2a 20 4d 61 72 6b 20 74 68 65  .     * Mark the
f160: 20 6c 69 73 74 20 61 73 20 62 65 69 6e 67 20 63   list as being c
f170: 61 6e 6f 6e 69 63 61 6c 3b 20 61 6c 74 68 6f 75  anonical; althou
f180: 67 68 20 69 74 20 77 69 6c 6c 20 6e 6f 77 20 68  gh it will now h
f190: 61 76 65 20 61 20 73 74 72 69 6e 67 0a 20 20 20  ave a string.   
f1a0: 20 20 2a 20 72 65 70 2c 20 69 74 20 69 73 20 6f    * rep, it is o
f1b0: 6e 65 20 77 65 20 64 65 72 69 76 65 64 20 74 68  ne we derived th
f1c0: 72 6f 75 67 68 20 70 72 6f 70 65 72 20 22 63 61  rough proper "ca
f1d0: 6e 6f 6e 69 63 61 6c 22 20 71 75 6f 74 69 6e 67  nonical" quoting
f1e0: 20 61 6e 64 20 73 6f 0a 20 20 20 20 20 2a 20 69   and so.     * i
f1f0: 74 27 73 20 6b 6e 6f 77 6e 20 74 6f 20 62 65 20  t's known to be 
f200: 66 72 65 65 20 66 72 6f 6d 20 6e 61 73 74 69 65  free from nastie
f210: 73 20 72 65 6c 61 74 69 6e 67 20 74 6f 20 5b 63  s relating to [c
f220: 6f 6e 63 61 74 5d 20 61 6e 64 20 5b 65 76 61 6c  oncat] and [eval
f230: 5d 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20  ]..     */..    
f240: 6c 69 73 74 52 65 70 50 74 72 2d 3e 63 61 6e 6f  listRepPtr->cano
f250: 6e 69 63 61 6c 46 6c 61 67 20 3d 20 31 3b 0a 0a  nicalFlag = 1;..
f260: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 48 61      /*.     * Ha
f270: 6e 64 6c 65 20 65 6d 70 74 79 20 6c 69 73 74 20  ndle empty list 
f280: 63 61 73 65 20 66 69 72 73 74 2c 20 73 6f 20 72  case first, so r
f290: 65 73 74 20 6f 66 20 74 68 65 20 72 6f 75 74 69  est of the routi
f2a0: 6e 65 20 69 73 20 73 69 6d 70 6c 65 72 2e 0a 20  ne is simpler.. 
f2b0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28      */..    if (
f2c0: 6e 75 6d 45 6c 65 6d 73 20 3d 3d 20 30 29 20 7b  numElems == 0) {
f2d0: 0a 09 54 63 6c 5f 49 6e 69 74 53 74 72 69 6e 67  ..Tcl_InitString
f2e0: 52 65 70 28 6c 69 73 74 50 74 72 2c 20 4e 55 4c  Rep(listPtr, NUL
f2f0: 4c 2c 20 30 29 3b 0a 09 72 65 74 75 72 6e 3b 0a  L, 0);..return;.
f300: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20      }..    /*.  
f310: 20 20 20 2a 20 50 61 73 73 20 31 3a 20 65 73 74     * Pass 1: est
f320: 69 6d 61 74 65 20 73 70 61 63 65 2c 20 67 61 74  imate space, gat
f330: 68 65 72 20 66 6c 61 67 73 2e 0a 20 20 20 20 20  her flags..     
f340: 2a 2f 0a 0a 20 20 20 20 69 66 20 28 6e 75 6d 45  */..    if (numE
f350: 6c 65 6d 73 20 3c 3d 20 4c 4f 43 41 4c 5f 53 49  lems <= LOCAL_SI
f360: 5a 45 29 20 7b 0a 09 66 6c 61 67 50 74 72 20 3d  ZE) {..flagPtr =
f370: 20 6c 6f 63 61 6c 46 6c 61 67 73 3b 0a 20 20 20   localFlags;.   
f380: 20 7d 20 65 6c 73 65 20 7b 0a 09 2f 2a 0a 09 20   } else {../*.. 
f390: 2a 20 57 65 20 6b 6e 6f 77 20 6e 75 6d 45 6c 65  * We know numEle
f3a0: 6d 73 20 3c 3d 20 4c 49 53 54 5f 4d 41 58 2c 20  ms <= LIST_MAX, 
f3b0: 73 6f 20 74 68 69 73 20 69 73 20 73 61 66 65 2e  so this is safe.
f3c0: 0a 09 20 2a 2f 0a 0a 09 66 6c 61 67 50 74 72 20  .. */...flagPtr 
f3d0: 3d 20 28 63 68 61 72 20 2a 29 63 6b 61 6c 6c 6f  = (char *)ckallo
f3e0: 63 28 6e 75 6d 45 6c 65 6d 73 29 3b 0a 20 20 20  c(numElems);.   
f3f0: 20 7d 0a 20 20 20 20 65 6c 65 6d 50 74 72 73 20   }.    elemPtrs 
f400: 3d 20 26 6c 69 73 74 52 65 70 50 74 72 2d 3e 65  = &listRepPtr->e
f410: 6c 65 6d 65 6e 74 73 3b 0a 20 20 20 20 66 6f 72  lements;.    for
f420: 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 6e 75 6d   (i = 0; i < num
f430: 45 6c 65 6d 73 3b 20 69 2b 2b 29 20 7b 0a 09 66  Elems; i++) {..f
f440: 6c 61 67 50 74 72 5b 69 5d 20 3d 20 28 69 20 3f  lagPtr[i] = (i ?
f450: 20 54 43 4c 5f 44 4f 4e 54 5f 51 55 4f 54 45 5f   TCL_DONT_QUOTE_
f460: 48 41 53 48 20 3a 20 30 29 3b 0a 09 65 6c 65 6d  HASH : 0);..elem
f470: 20 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 46   = TclGetStringF
f480: 72 6f 6d 4f 62 6a 28 65 6c 65 6d 50 74 72 73 5b  romObj(elemPtrs[
f490: 69 5d 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09 62  i], &length);..b
f4a0: 79 74 65 73 4e 65 65 64 65 64 20 2b 3d 20 54 63  ytesNeeded += Tc
f4b0: 6c 53 63 61 6e 45 6c 65 6d 65 6e 74 28 65 6c 65  lScanElement(ele
f4c0: 6d 2c 20 6c 65 6e 67 74 68 2c 20 66 6c 61 67 50  m, length, flagP
f4d0: 74 72 2b 69 29 3b 0a 09 69 66 20 28 62 79 74 65  tr+i);..if (byte
f4e0: 73 4e 65 65 64 65 64 20 3c 20 30 29 20 7b 0a 09  sNeeded < 0) {..
f4f0: 20 20 20 20 54 63 6c 5f 50 61 6e 69 63 28 22 6d      Tcl_Panic("m
f500: 61 78 20 73 69 7a 65 20 66 6f 72 20 61 20 54 63  ax size for a Tc
f510: 6c 20 76 61 6c 75 65 20 28 25 64 20 62 79 74 65  l value (%d byte
f520: 73 29 20 65 78 63 65 65 64 65 64 22 2c 20 49 4e  s) exceeded", IN
f530: 54 5f 4d 41 58 29 3b 0a 09 7d 0a 20 20 20 20 7d  T_MAX);..}.    }
f540: 0a 20 20 20 20 69 66 20 28 62 79 74 65 73 4e 65  .    if (bytesNe
f550: 65 64 65 64 20 3e 20 49 4e 54 5f 4d 41 58 20 2d  eded > INT_MAX -
f560: 20 6e 75 6d 45 6c 65 6d 73 20 2b 20 31 29 20 7b   numElems + 1) {
f570: 0a 09 54 63 6c 5f 50 61 6e 69 63 28 22 6d 61 78  ..Tcl_Panic("max
f580: 20 73 69 7a 65 20 66 6f 72 20 61 20 54 63 6c 20   size for a Tcl 
f590: 76 61 6c 75 65 20 28 25 64 20 62 79 74 65 73 29  value (%d bytes)
f5a0: 20 65 78 63 65 65 64 65 64 22 2c 20 49 4e 54 5f   exceeded", INT_
f5b0: 4d 41 58 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  MAX);.    }.    
f5c0: 62 79 74 65 73 4e 65 65 64 65 64 20 2b 3d 20 6e  bytesNeeded += n
f5d0: 75 6d 45 6c 65 6d 73 20 2d 20 31 3b 0a 0a 20 20  umElems - 1;..  
f5e0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 50 61 73 73    /*.     * Pass
f5f0: 20 32 3a 20 63 6f 70 79 20 69 6e 74 6f 20 73 74   2: copy into st
f600: 72 69 6e 67 20 72 65 70 20 62 75 66 66 65 72 2e  ring rep buffer.
f610: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 73 74  .     */..    st
f620: 61 72 74 20 3d 20 64 73 74 20 3d 20 54 63 6c 5f  art = dst = Tcl_
f630: 49 6e 69 74 53 74 72 69 6e 67 52 65 70 28 6c 69  InitStringRep(li
f640: 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 62 79 74  stPtr, NULL, byt
f650: 65 73 4e 65 65 64 65 64 29 3b 0a 20 20 20 20 54  esNeeded);.    T
f660: 63 6c 4f 4f 4d 28 64 73 74 2c 20 62 79 74 65 73  clOOM(dst, bytes
f670: 4e 65 65 64 65 64 29 3b 0a 20 20 20 20 66 6f 72  Needed);.    for
f680: 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 6e 75 6d   (i = 0; i < num
f690: 45 6c 65 6d 73 3b 20 69 2b 2b 29 20 7b 0a 09 66  Elems; i++) {..f
f6a0: 6c 61 67 50 74 72 5b 69 5d 20 7c 3d 20 28 69 20  lagPtr[i] |= (i 
f6b0: 3f 20 54 43 4c 5f 44 4f 4e 54 5f 51 55 4f 54 45  ? TCL_DONT_QUOTE
f6c0: 5f 48 41 53 48 20 3a 20 30 29 3b 0a 09 65 6c 65  _HASH : 0);..ele
f6d0: 6d 20 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67  m = TclGetString
f6e0: 46 72 6f 6d 4f 62 6a 28 65 6c 65 6d 50 74 72 73  FromObj(elemPtrs
f6f0: 5b 69 5d 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09  [i], &length);..
f700: 64 73 74 20 2b 3d 20 54 63 6c 43 6f 6e 76 65 72  dst += TclConver
f710: 74 45 6c 65 6d 65 6e 74 28 65 6c 65 6d 2c 20 6c  tElement(elem, l
f720: 65 6e 67 74 68 2c 20 64 73 74 2c 20 66 6c 61 67  ength, dst, flag
f730: 50 74 72 5b 69 5d 29 3b 0a 09 2a 64 73 74 2b 2b  Ptr[i]);..*dst++
f740: 20 3d 20 27 20 27 3b 0a 20 20 20 20 7d 0a 0a 20   = ' ';.    }.. 
f750: 20 20 20 2f 2a 20 53 65 74 20 74 68 65 20 73 74     /* Set the st
f760: 72 69 6e 67 20 6c 65 6e 67 74 68 20 74 6f 20 77  ring length to w
f770: 68 61 74 20 77 61 73 20 61 63 74 75 61 6c 6c 79  hat was actually
f780: 20 77 72 69 74 74 65 6e 2c 20 74 68 65 20 73 61   written, the sa
f790: 66 65 20 63 68 6f 69 63 65 20 2a 2f 0a 20 20 20  fe choice */.   
f7a0: 20 28 76 6f 69 64 29 20 54 63 6c 5f 49 6e 69 74   (void) Tcl_Init
f7b0: 53 74 72 69 6e 67 52 65 70 28 6c 69 73 74 50 74  StringRep(listPt
f7c0: 72 2c 20 4e 55 4c 4c 2c 20 64 73 74 20 2d 20 31  r, NULL, dst - 1
f7d0: 20 2d 20 73 74 61 72 74 29 3b 0a 0a 20 20 20 20   - start);..    
f7e0: 69 66 20 28 66 6c 61 67 50 74 72 20 21 3d 20 6c  if (flagPtr != l
f7f0: 6f 63 61 6c 46 6c 61 67 73 29 20 7b 0a 09 63 6b  ocalFlags) {..ck
f800: 66 72 65 65 28 66 6c 61 67 50 74 72 29 3b 0a 20  free(flagPtr);. 
f810: 20 20 20 7d 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 4c     }.}.../*. * L
f820: 6f 63 61 6c 20 56 61 72 69 61 62 6c 65 73 3a 0a  ocal Variables:.
f830: 20 2a 20 6d 6f 64 65 3a 20 63 0a 20 2a 20 63 2d   * mode: c. * c-
f840: 62 61 73 69 63 2d 6f 66 66 73 65 74 3a 20 34 0a  basic-offset: 4.
f850: 20 2a 20 66 69 6c 6c 2d 63 6f 6c 75 6d 6e 3a 20   * fill-column: 
f860: 37 38 0a 20 2a 20 45 6e 64 3a 0a 20 2a 2f 0a     78. * End:. */.