Skip to content
Tcl Source Code Artifact [8a967c449e]
Login

Artifact [8a967c449e]

Artifact 8a967c449e44ada87b556dde53983dd9007dde4f:

Ticket change [8a967c449e] - Ticket [3418547fffffffff|3418547fff] <i>cmd literal sharing vs. cmd resolvers</i> status still Closed with 8 other changes by dgp on 2016-07-15 15:47:27.
D 2016-07-15T15:47:27.637
J assignee dgp
J closedate 2457585.15795824
J closer dgp
J comment When\stesting\sour\sTcl's\sper-interp\sresolvers,\sin\sparticular\sfor\r\nresolving\scommands,\sagainst\s8.6b2\s(and\sthe\scurrent\r\ntrunk,\sas\sof\s20111004),\swe\sfound\san\sunwanted\sinteraction\sbetween\r\n"global"\sCmdName\sobj\ssharing\s(i.e.\scmd\sliterals)\sand\sthe\scmd\sresolver\r\ninfrastructure.\r\n\r\nIn\sshort:\sUsing\scommand\sresolvers\scan\seasily\slead\sto\ssituations\sin\r\nwhich\sCmdName\sobjs\sare\seffectively\sshared\sbetween\sBC-compiled\sscripts\r\n(procs,\s[namespace\seval])\sfor\sthe\sscope\sof\sa\sgiven\snamespace\s(global\r\nand\snon-global\sNS\salike)\swhile\stheir\scommand\sreferences\sturn\sout\r\nobsolete.\sAn\sinvalidation\sof\sthe\sCmdName\sobjs\sintrep\s(ResolvedCmdName)\r\nis\snot\sperformed.\sThe\somission\sof\sthe\sinvalidation\sis\sdue\sto\sseveral\r\nreasons,\sdepending\son\sthe\sBC\scompilation/execution\scontext.\sFor\r\ninstance,\sfor\sinstantly\scompiled\sscripts\s([namespace\seval])\swe\shit\r\nTclSetCmdNameObj()\swhich\ssimply\sreturns\swithout\stouching\s(existing)\sCmdName\r\nobj\sintreps.\r\n\r\nA\scondensed\sexample:\r\n\r\nConsider\sa\scmd\sresolver\swhich\sbinds\s"z"\sto\s::y\swhen\s"z"\sis\sbeing\r\nresolved\sin\sthe\scontext\sof\sthe\sproc\s::x\s(and\sin\sthis\sscope\sonly):\r\n\s\r\nproc\s::y\s{}\s{\sreturn\sY\s};\s#\sthe\sresolver-specific\sresolution\starget\r\n\s\s\r\nproc\s::x\s{}\s{\r\n\s\s\s\sz;\s#\sthe\stcl\sword\sbeing\sturned\sinto\sa\sCmdName\sobj\sand\sshared\sas\scmd\sliteral\safter\shaving\sbeen\sBC-compiled\r\n\s\s}\r\n\r\nThis\scmd\sresolution\sis\sperformed\sduring\sBC\scompilation\sof\s::x.\sThe\scmd\r\n(::y)\sreturn\sby\sthe\scmd\sresolver\sis\sreferenced\sby\sthe\sintrep\sof\sa\r\nCmdName\sobj\s"z"\sfor\sthe\sNS\sscope\sof\sthe\s[namespace\scurrent]\sduring\r\ncompilation\s("::").\sNext\stime,\sa\sscript\sis\scompiled\sin\sthis\ssharing\r\ncontext,\sthis\swill\swork\s(unexpectedly?):\r\n\r\nnamespace\seval\s::\s{\r\n\s\s\s\sz;\s#\sreturns\s"Y"?!\r\n}\r\n\r\nHowever,\swhen\srequesting\sa\sdifferent\scmd\sto\sbecome\savailable\sunder\sthe\r\ntoken\s"z",\se.g.,\s::ns1::z:\r\n\s\s\r\nnamespace\seval\s::ns1\s{\r\n\s\s\s\sproc\sz\s{}\s{\sreturn\sZ\s}\r\n\s\s\s\snamespace\sexport\sz\r\n\s\s}\r\n\s\s\r\n...\sby\se.g.\s[namespace\simport]'ing,\sthis\swon't\sshow\sany\seffect\son\sthe\sshared\scmd\sliteral:\r\n\r\n\snamespace\seval\s::\s{\r\n\s\s\s\snamespace\simport\s::ns1::z\r\n\s\s\s\sz;\s#\sstill\sreturns\s"Y",\sthough\sexpecting\s"Z"\r\n\s\s}\r\n\s\r\nOne\scan\salter\sthis\s(mis-)behaviour\sat\svarious\sspots,\sfor\sinstance,\sby\r\ncausing\sthe\scompiled\sscript\sto\somit\scmd\sliteral\ssharing\sfor\sthe\sgiven\r\ntoken\s"z":\r\n\r\n\snamespace\seval\s::\s{\r\n\s\s\s\sproc\sz\s{}\s{\sreturn\sZ\s}\r\n\s\s\s\sz;\s#\syields\s"Z",\sas\sexpected\r\n\s\s}\r\n\r\nThis\s"works"\ssimply\sbecause\sthere\sis\sno\scmdname\sobj\semitted.\sChanging\r\nthe\sscript\sback\sto\susing\sa\squalified\stoken\s"::z"\sgives\sus\sthe\sunwanted\r\nbehavior\sagain:\r\n\r\n\snamespace\seval\s::\s{\r\n\s\s\s\sproc\s::z\s{}\s{\sreturn\sZ\s}\r\n\s\s\s\sz;\s#\syields\s"Y",\snot\s"Z"\r\n\s\s}\r\n\r\n(This\sexample\sis\scontained\sas\sa\stcltest\s(plus\scomments)\slit-1.1\sby\sthe\spatch\sattached)\r\n\r\nIn\sour\sreading,\scmd\sresolvers\sare\scapable\sof\scausing\syet\sanother\sform\r\nof\s"command\sshadowing"\sat\sthe\slevel\sof\scmd\sliterals,\sgiven\sthe\r\naggressive\scmd\sliteral\ssharing\sin\sTcl\s8.6.\sCommand\sresolution\sthrough\r\ncmd\sresolvers\sin\sTcl_FindCommand\s&\sfriends\sgives\sbirth\sto\scmd\sliterals\r\nwhich\ssilently\s"import"\scommands\sfrom\salien\scontexts\s(resolver\r\nspecific)\sinto\sa\snamespace\scontext\swithout\s"registering"\sthe\scommands\r\nin\sa\smanner\sto\smake\sthem\svisible\sto\sthe\svarious\sinvalidation\r\nroutines.\sCommand\sepochs\sdo\snot\scome\sinto\splay\seither\sbecause\sthe\r\n"resolver-imported"\scommand\smight\ssimply\snot\sbe\stouched\sitself\sor\r\nintrep\sinvalidation\sis\snever\striggered\r\n(TclSetCmdNameObj()).\sNS-specific\sinvalidation\s(cmdRefEpoch)\ssimply\r\ndoes\snot\sapply\sbecause\sliterals\sare\snot\spart\sof\sany\sinvalidation\r\nscheme,\se.g.,\sTclResetShadowedCmdRefs,\sNS\spath\sinvalidation\setc.\sFrom\r\nwithin\sthe\scmd\sresolvers,\sthere\sis\sno\sway\sof\sinterfering\s(in\sour\r\nunderstanding).\r\n\r\nThe\spatch\sattached\sto\sthis\sbug\sreport\sfeatures\sthe\sfollowing:\r\n\r\na)\sA\sminimal\sinfrastructure\sfor\stesting\sresolvers\s(tclTest.c):\r\n[testinterpresolver\sup|down]\r\n\r\nb)\sA\scollection\s(resolvers.test)\sof\scharacteristic\stcltests\swhich\sshow\r\nthe\sissue\sin\svarious\ssettings\s([namespace\simport],\s[interp\salias],\r\n[interp\sexpose],\s[proc]).\sSee\stcltest\slit-1.1\sfor\sa\sstep-by-step\r\nexplanation\sof\sa\sprototypical\sscenario\r\n\r\nc)\sFinally,\sa\ssuggested\spatch\saround\sa\snewly\sintroduced\r\nTclInvalidateCmdLiteral()\shelper.\sWhile\sthis\shelper\saddresses\sthe\r\nissue\ssufficiently\sas\sindicated\sby\sthe\stcltest\scollection,\sthere\smight\scertainly\r\nbe\salternative\sstrategies.\sThe\sprimary\spurpose\sof\sthis\spatch\sis\sto\r\npoint\syou\sinto\sthe\sright\sdirection.\sTclInvalidateCmdLiteral()\ssimply\r\nqueries\sthe\sliteral\stables\sfor\scandidates\susing\sthe\sTcl_CreateLiteral\r\nAPI\sand,\sif\sfound,\sresets\sthe\sintrep\safter\scritical\soperations\ssuch\r\nas\se.g.\s[namespace\simport].\r\n\r\nd)\sIncluded\sis\salso\sa\stcltest\scovering\s(the\sunrelated)\sbug\s#3383616\r\n\r\nStefan\sSobernig\r\nGustaf\sNeumann
J icomment \r\nFate\sbrings\sme\shere\sagain.\r\n\r\nThis\sbug\sreport\swas\sabout\sa\sreal\sand\sdifficult\sproblem\r\nwith\sa\sstill\sunder-specified\sextension\smechanism,\sand\r\nI\sbelieve\sthe\sremedy\swe've\sbeen\sliving\swith\swas\soffered\r\nup\sin\sgood\sfaith\sand\shas\sbeen\seffective\senough\sfor\r\npeople\sto\smove\sforward.\r\n\r\nBut\sit's\sjust\swrong.\r\n\r\nMy\ssuspicions\sare\sraised\sbecause\sthe\sTclInvalidateCmdLiteral()\r\nroutine\sthat\simplements\sthe\scorrective\s*only*\spatches\sup\r\nliterals\sthat\shave\sinvalid\sintreps.\s\sWhat\sabout\sother\r\nTcl_Obj\svalues\sthat\sare\sholding\s"cmdName"\sintreps?\s\sHow\r\nare\sthey\sto\sbe\scorrected?\r\n\r\nLooking\sat\stest\sresolver-1.1\sI\ssee\smore\strouble.\s\sThe\r\ntesting\sresolver\sthat\sis\senabled\sby\s[testinterpresolver\sup]\r\nhas\sa\svery\sspecific\sfunction.\s\sIf\sit\ssees\sthe\scommand\sname\r\n"z"\swithin\sthe\sproc\s"::x"\sand\snowhere\selse\sit\swill\sredirect\r\nthat\sto\sthe\simplementation\sof\scommand\s"::y".\s\sSo\sas\sdescribed\r\nin\sthe\stest\scomments,\r\n\r\n\s\s\s\sset\sr0\s[x]\r\n\r\nproduces\sresult\s"Y"\sbecause\sof\sthe\sredirection.\s\sIn\sstep\s2,\r\n\r\n\s\s\s\sset\sr1\s[z]\r\n\r\nThe\sredirection\shas\sbeen\scached\sas\sthe\sintrep\sof\s[z]\sso\sit\r\nis\staken\sagain,\seven\sthough\sit\sis\snot\sin\sthe\scontext\srecognized\r\nby\sthe\sresolver.\s\sThe\scomments\squestion,\sbut\saccept\sthis.\r\nThey\sshould\snot.\s\sThis\sis\sjust\swrong.\s\sThe\sresolver\sconditions\r\nare\snot\smet.\s\sThe\scorrect\sresult\sshould\sbe\s"unknown\scommand\s'z'".\r\n\r\nThe\sa\s[namespace\simport]\sis\sdone\sto\sgive\s[z]\sa\smore\scorrect\starget.\r\nBefore\sthe\sbug\sfix,\sthis\sfailed.\s\sNow\sit\ssucceeds\sbecause\seach\sthing\r\nlike\s[namespace\simport]\sthat\scould\soffer\sa\snew\starget\salso\sseeks\sout\r\nand\sclears\sany\s"cmdName"\sintreps\sin\sliterals,\sand\sin\sthis\scase\sthe\r\nimproper\sbehavior\sis\sin\sa\sliteral.\s\sWe\snow\sget\r\n\r\n\s\s\s\sset\sr2\s[z]\r\n\r\nwhich\sreturns\s"Z"\sas\swe\sexpect.\s\sAt\sthis\spoint\sthe\stest\sstops\sbefore\r\ntaking\sthe\snext\sstep\sto\ssee\sthat\sthings\sare\sstill\sbroken:\r\n\r\n\s\s\s\sset\sr3\s[x]\r\n\r\nThis\stakes\sus\sback\sto\sthe\sfirst\scase,\swhere\sunquestionably\sthe\r\nresolver\sought\sto\sbe\sin\spower,\sbut\sif\syou\stry\sit\syou\swill\ssee\r\nthat\sthe\sreturned\svalue\sis\s"Z".\s\sHere\sthe\scaching\sis\sworking\sagainst\r\nus\sagain,\sbut\sin\sthe\sopposite\sway.\s\sThe\scontext\sdistinctions\sthat\r\nthe\sinterp\sresolver\sis\smaking\suse\sof\sare\snot\sknown\sand\snot\stested\r\nin\svalidating\sthe\sintrep.\s\sIn\sgeneral,\sit's\shard\sto\ssee\show\sthey\r\ncould\sbe.
J login dgp
J mimetype text/plain
J severity Minor
K 3418547fffffffffffffffffffffffffffffffff
U dgp
Z 54b590f190e51670b21bcb300e228bf4