<i>new macro TclFreeIfRefCountZero</i> status still Open with 4 other changes
by
.
D 2013-01-03T15:38:09
J icomment >\sCode\swritten\sfor\sone\spattern\scannot\sbe\sconverted\sto\sthe\sother\n>\sby\smacro\nLet's\srecord\shere\swhy\snot.\sDividing\sthe\sAPI\sin\s"comsumers"\n(like\sTcl_SetObjResult,\sTcl_ListObjAppendObj,\nTcl_SetVar2Ex)\sand\s"producers"\s(like\sTcl_NewIntObj,\nTcl_GetVar2Ex,\sTcl_GetObjResult),\slet's\sassume\swe\nchange\sthe\scontract:\s"producers"\swill\seither\sreturn\na\snew\sobject\swith\srefcount\s1,\seither\sincrement\sthe\nrefcount\sof\san\salready\sexisting\sobject\sand\sreturn\sthat.\n"consumers"\sno\slonger\sincrement\sthe\srefcount\sfrom\nthe\sobject\sthey\sreceive.\sThat\swould\spretty\swell\nkeep\sexisting\sextension\scode\sunchanged...\sIs\sit?\n\nOne\sexample\n\s\s\s\sTcl_Obj\s*resultObj\s=\sTcl_NewIntObj(123);\n\s\s\s\sTcl_IncrRefCount(resultObj);\n\s\s\s\sprintf("%s",\sTcl_GetString(resultObj));\n\s\s\s\sTcl_DecrRefCount(resultObj);\nThis\scode\sworks\sfine\sin\sTcl8,\sbut\swould\slead\nto\sa\smemory\sleak\sin\sTcl9.\sRemove\sthe\nTcl_IncrRefCount,\sand\sit\swill\swork\sin\sboth.\n\n\s\s\s\sTcl_Obj\s*resultObj\s=\sTcl_NewIntObj(123);\n\s\s\s\sTcl_SetVar2Ex(interp,\s......,\sresultObj);\n\s\s\s\sTcl_SetObjResult(interp,\sresultObj);\nThis\sworks\sin\sTcl8,\sbut\swith\sa\schanged\scontract\nan\sadditional\sTcl_IncrRefCount\sshould\sbe\sdone.\nIt's\sa\spretty\scommon\spattern:\sreturning\sthe\ssame\nobject\sthat\sis\soperated\son.\sOr,\smaybe,\sa\nTCL_NEWREF\sflag\scould\sbe\sadded\nto\sTcl_SetVar2Ex,\swhich\smakes\sit\sdo\sthe\sincrement\nas\sbefore.\sThen\s-\sat\sleast\s-\scode\scan\sbe\swritten\swith\nis\susable\sin\sboth\sTcl8\sand\sTcl9.\sBut\swhere\sis\sthe\sgain?\n\nHowever\s-\sstill\s-\sthe\sgain\sis\squestionable\shere,\sI\sagree\nwith\sdkf\son\sthat.\sI\scould\simagine\sthat\sTcl\sone\sday\sis\nrewritten\sto\slet\sTcl_Obj's\sbe\sshared\samong\sthreads,\sthen\nhaving\sa\srefcount\sof\s0\sis\sdangerous,\sany\sthread\scould\nclean\sit\sup\sat\swill,\sthat\scould\sbe\sa\sgood\sreason\sfor\nchanging\sthe\scontract\sas\ssuggested.\nOr\smaybe\swhen\sTcl\sswitches\sto\suse\sgarbage\scollection\sin\nstead\sof\srefcounting.\sBut\sfor\sTcl9\sI\sdon't\ssee\sthat\shappening,\nbecause\sit\shas\sa\slot\sof\sother\sdangerous\simplications.\sAnd\nwhen\sit\shappens,\sthe\scontract\scan\sbe\schanged\salong\swith\sit.\n
J login nijtmans
J mimetype text/plain
J username nijtmans
K 3598875fffffffffffffffffffffffffffffffff
U nijtmans
Z 5807c043ce87491cea2b656e7598fb5f