.
D 2004-01-28T14:37:17
J assignee hobbs
J cmimetype text/plain
J comment testing\sa\sreferences\ssupport\sfor\sTcl\sI'm\sdeveloping\n(that\swill\sbe\nthe\ssubject\sof\sanother\scomunication),\sI\sdiscovered\sa\nbug\sthat\nis\svery\scommon\sin\slanguages\simplementations\susing\nreference\scounts.\n\nThe\sproblem\sis\sthat\swhen\sa\sreference\sof\san\sobject\sdrops\nto\szero,\nthe\sTcl_DecrRefCount()\scalls\sTcl_FreeObj()\sin\sorder\sto\nfree\sthe\nobject\sinternal\srepresentation,\sstring,\sand\sstorage\nallocation.\nIf\sthat\sobject\sis\sable\sto\stake\sreferences\sto\sother\nobjects,\sbefore\nto\sfree\sthe\sobject,\sall\sthe\sreferenced\sobjects\sgets\nRefDecremented(),\nand\sthis\scan\sresult\sin\sa\snew\s(recursive)\sinvocation\sof\nTcl_FreeObj().\n\nThat's\show\sit\sshould\sbe\sin\stheory,\sbut\swith\sdeeply\nnested\sdata\nstructures,\sfor\sexample\slists\scontaining\slists\ncontaining\slists\s(...)\nthe\sresult\sis\sa\sdeep\srecursion\sof\sTcl_FreeObj(),\sand\nonce\sthe\sC\nstack\sis\sterminated,\sa\ssegmentation\sfault.\n\nThe\sfollowing\scode\swill\scrash\sTcl\son\smany\soperating\ssystems\nand\smany\sarchs:\n\nset\sx\sfoobar\ntime\s{lset\sx\s0\s[list\s$x\s2]}\s20000\nset\sx\s{}\n\nIf\sthis\sis\snot\sable\sto\scrash\syour\sbox,\stry\swith\sa\svalue\na\sbit\nbigger\sthan\s20000.\n\nAnother\sway\sto\scrash\sTcl\sis\sto\ssubstitute\sthe\s"set\sx\n{}"\sfinal\ncommand\swith\s"string\slength\s$x".\sBecause\sthe\slist\s->\sstring\nconversion\salso\sis\sa\srecursive\scall.\n\nOf\scourse\sthe\s'free'\sproblem\sis\smuch\ssevere\sthan\sthe\sstring\nconversion\sone,\sbut\sfortunatelly\sthe\sfix\sis\sgeneral\sand\nquite\nsimple.\n\nTo\sfix\sthis\sproblem\sTcl\sshould\s"lazy\sfree"\sobjects.\nInstead\sto\sreally\nfree\sthe\sobject,\sTcl_FreeObj()\sshould\sjust\sput\sthe\nobject's\spointer\nin\sa\sToFree\slist,\sthen\sfree\sthat\slist\sonly\swhen\nTcl_FreeObj()\sis\nnot\scalled\srecursively\s(an\salternative\sis\sto\scall\sa\nTcl_FreeCycle()\nwhen\sthere\sis\ssome\sallocation\saction,\sand\son\slow\smemory).\n\nI\sdid\sa\ssimple\simplementation\sfor\sTcl\sHEAD\s(attached\sto\nthis\semail).\nSeems\sto\swork\swell\sbut\sshould\sbe\smodified\sto\ssupport\nthreads\nand\sthe\sTcl\scoding\sstyle.\n\nRegards,\nSalvatore\sSanfilippo
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 41.\sMemory\sAllocation
J title Tcl\sinterpreter\sdoes\snot\slazy-free\sobjects.
J type Bug
K 886231ffffffffffffffffffffffffffffffffff
U nobody
Z 8381a8e99b7e5c46fb2958d76a4b2ba2