Posted to tcl by sebres at Thu May 02 10:14:15 GMT 2019view raw
- // http://core.tcl.tk/tdom/info/a858a6ac777f3639
- // splitTCObjCmd, let objc = 5, then nrArg == 3
- // so set and incr evalStub[0 .. 2]
- // splitTclImpl, overwrites evalStub[2]
- // splitTclImplFree, decr evalStub[0 .. 2], but evalStub[2] is another object here now.
- ---------------------------------------------------------
- static int
- splitTclImpl (
- Tcl_Interp *interp,
- void *constraintData,
- char *text
- )
- {
- ...
- // nrArg == 3
- // ************************************************************************************************
- tcdata->evalStub[tcdata->nrArg-1] = Tcl_NewStringObj(text, -1); // ** OVERWRITES evalStub[2] **
- // with new object (incr/decr)
- // ************************************************************************************************
- ...
- }
- static void
- splitTclImplFree (
- void *constraintData
- )
- {
- ...
- // nrArg == 3
- for (i = 0; i < tcdata->nrArg-1; i++) { // i iter 0 .. 2
- Tcl_DecrRefCount (tcdata->evalStub[i]); // decr evalStub[0 .. 2]
- }
- ...
- }
- static int
- splitTCObjCmd (
- ClientData clientData,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *const objv[]
- )
- {
- ...
- case m_tcl:
- sc->constraint = splitTclImpl;
- sc->freeData = splitTclImplFree;
- tcdata = TMALLOC (splitTclTCData);
- // let objc = 5
- tcdata->nrArg = objc - 2; // nrArg == 3
- tcdata->evalStub = MALLOC (sizeof (Tcl_Obj*) * (objc-1)); // alloc 4
- for (i = 2; i < objc; i++) { // i iter 2 .. 4
- tcdata->evalStub[i-2] = objv[i]; // set evalStub[0 .. 2] <= objv[2 .. 4]
- Tcl_IncrRefCount (tcdata->evalStub[i-2]); // incr evalStub[0 .. 2]
- }
- tcdata->sdata = sdata;
- tcdata->cp = cp;
- sc->constraintData = tcdata;
- ...
- }