.
D 2001-12-17T22:06:29
J assignee dkf
J cmimetype text/plain
J comment -\sTcl\sVersion:\s8.x+;\n-\sOS:\sSolaris\s5.x\s(Any);\n-\sCompiler:\sSun\sCC\s6.0\sUpd\s1;\n-\sProblem\sbehavior:\nTcl\smay\sfreely\sconvert\sthe\stype\sof\sobjects.\s\nForeach\scommand\sstores\sthe\spointers\sto\sobjects\sof\sloop\s\nvariables\sat\sthe\sbegin\sof\sthe\sloop:\n\s\sfor\s(i\s=\s0;\s\si\s<\snumLists;\s\si++)\s{\n\s\s\s\s\sresult\s=\sTcl_ListObjGetElements(interp,\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sargObjv[1+i*2],\n\s\s\s\s\s\s&varcList[i],\s&varvList[i]);\n->\sVar\slist\sis\sin\svarvList.\nLater\sit\sonly\schecks\sif\sthe\svariable\slist\sobject\shas\nthe\slist\stype:\s\n\s\s\s\s\sif\s(argObjv[1+i*2]->typePtr\s!=\s&tclListType)\s\n\s\s\s\s\s\s\s\s\sresult\s=\sTcl_ListObjGetElements(interp,\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sargObjv[1+i*2],\n->\sconditionally\srecreates\sthe\slist\nand\sif\sthe\stype\sis\s"list",\sit\sconsiders\sthe\slist\ncorrect.\sNow\ssuppose\sthe\sloop\sbody\scalls\sthe\nfunction\swith\sthe\ssame\sname\sas\sthe\sloop\svariable.\nThis\swill\sconvert\sthe\svar\slist\nobject\sto\s"cmdName"\stype\sand\slose\sthe\spointers\sto\sall\nloop\svariable\sobjects.\sThen,\sin\srecursion,\swe\swil\nrecreate\sthe\svar\slist\sconversting\s"cmdName"\sto\s"list".\nAfter\sreturn\sfrom\srecursion\sto\sthe\sfirst\sloop\swe\swill\nhave\sthe\scorrect\slist\sbut\swith\sanother\sobjects.\s\nAfter\schecking\s\sthe\stype\sof\svar\slist\sobject\s(it\sis\n"list"\nnow)\swe'll\scontinue\nto\suse\sstored\spointers\s(varvlist)\sand\swill\scrash\son\sthe\nsecond\s\siteration.\sYou\swill\snot\scrash\sif\snobody\sused\nthat\sfreed\smemory,\sbut\sit\sdoes\snot\schange\sanything.\n\s\s\sIt's\sa\sreal\scritical\sbug\sfor\sus.\sTo\sfix\sit\sI\smade\nthe\ssecond\slist\sparsing\s(Tcl_ListObjGetElements)\nunconditional.\n\s\s\sShort\stestcase\s(I\sknow\sit\smight\sbe\sshorter):\n--------------\nproc\sinst\s{args}\s{\n}\n\nproc\sSomething\s{}\s{\n\s\s\s\sinst\n}\n\nproc\sTest\s{level}\s{\n\s\s\s\sincr\slevel\n\n\s\s\s\sputs\s"Test:\slevel\s=\s$level"\n\n\s\s\s\s#inst\s"a"\n\s\s\s\sSomething\s;#\syou\smay\scall\sinst\sdirectly\n\n\s\s\s\sif\s{$level\s==\s1}\s{\nset\sinstlist\s{1\s2}\n\s\s\s\s}\selse\s{\nset\sinstlist\s{}\n\s\s\s\s}\n\s\s\s\sputs\s"instlist\s=\s/$instlist/"\n\n\s\s\s\sforeach\sinst\s$instlist\s{\nputs\s"inst\s=\s/$inst/"\nTest\s$level\n\s\s\s\s}\n}\n\nTest\s0\n--------------------\nRegards,\nYevgen\sRyazanov
J foundin obsolete:\s8.3
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 16.\sCommands\sA-H
J title foreach\scrashes\sin\srecursion
J type Bug
K 494348ffffffffffffffffffffffffffffffffff
U nobody
Z a81f7c0aeb1ef12eb9a3f87d9f940bd9